| 1 |
/******************************************************************************* |
|---|
| 2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
|---|
| 3 |
* All rights reserved. This program and the accompanying materials |
|---|
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|---|
| 5 |
* which accompanies this distribution, and is available at |
|---|
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
|---|
| 7 |
* |
|---|
| 8 |
* Contributors: |
|---|
| 9 |
* IBM Corporation - initial API and implementation |
|---|
| 10 |
* Port to the D programming language: |
|---|
| 11 |
* Frank Benoit <benoit@tionex.de> |
|---|
| 12 |
*******************************************************************************/ |
|---|
| 13 |
module dwt.widgets.CoolItem; |
|---|
| 14 |
|
|---|
| 15 |
import dwt.widgets.Widget; |
|---|
| 16 |
import dwt.widgets.Control; |
|---|
| 17 |
import dwt.widgets.CoolBar; |
|---|
| 18 |
import dwt.widgets.Item; |
|---|
| 19 |
import dwt.widgets.TypedListener; |
|---|
| 20 |
|
|---|
| 21 |
import dwt.DWT; |
|---|
| 22 |
import dwt.DWTException; |
|---|
| 23 |
import dwt.events.SelectionEvent; |
|---|
| 24 |
import dwt.events.SelectionListener; |
|---|
| 25 |
import dwt.graphics.Point; |
|---|
| 26 |
import dwt.graphics.Rectangle; |
|---|
| 27 |
import dwt.internal.win32.OS; |
|---|
| 28 |
|
|---|
| 29 |
import dwt.dwthelper.utils; |
|---|
| 30 |
|
|---|
| 31 |
/** |
|---|
| 32 |
* Instances of this class are selectable user interface |
|---|
| 33 |
* objects that represent the dynamically positionable |
|---|
| 34 |
* areas of a <code>CoolBar</code>. |
|---|
| 35 |
* <dl> |
|---|
| 36 |
* <dt><b>Styles:</b></dt> |
|---|
| 37 |
* <dd>DROP_DOWN</dd> |
|---|
| 38 |
* <dt><b>Events:</b></dt> |
|---|
| 39 |
* <dd>Selection</dd> |
|---|
| 40 |
* </dl> |
|---|
| 41 |
* <p> |
|---|
| 42 |
* IMPORTANT: This class is <em>not</em> intended to be subclassed. |
|---|
| 43 |
* </p> |
|---|
| 44 |
* |
|---|
| 45 |
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
|---|
| 46 |
*/ |
|---|
| 47 |
|
|---|
| 48 |
public class CoolItem : Item { |
|---|
| 49 |
CoolBar parent; |
|---|
| 50 |
Control control; |
|---|
| 51 |
int id; |
|---|
| 52 |
bool ideal, minimum; |
|---|
| 53 |
|
|---|
| 54 |
/** |
|---|
| 55 |
* Constructs a new instance of this class given its parent |
|---|
| 56 |
* (which must be a <code>CoolBar</code>) and a style value |
|---|
| 57 |
* describing its behavior and appearance. The item is added |
|---|
| 58 |
* to the end of the items maintained by its parent. |
|---|
| 59 |
* <p> |
|---|
| 60 |
* The style value is either one of the style constants defined in |
|---|
| 61 |
* class <code>DWT</code> which is applicable to instances of this |
|---|
| 62 |
* class, or must be built by <em>bitwise OR</em>'ing together |
|---|
| 63 |
* (that is, using the <code>int</code> "|" operator) two or more |
|---|
| 64 |
* of those <code>DWT</code> style constants. The class description |
|---|
| 65 |
* lists the style constants that are applicable to the class. |
|---|
| 66 |
* Style bits are also inherited from superclasses. |
|---|
| 67 |
* </p> |
|---|
| 68 |
* |
|---|
| 69 |
* @param parent a composite control which will be the parent of the new instance (cannot be null) |
|---|
| 70 |
* @param style the style of control to construct |
|---|
| 71 |
* |
|---|
| 72 |
* @exception IllegalArgumentException <ul> |
|---|
| 73 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
|---|
| 74 |
* </ul> |
|---|
| 75 |
* @exception DWTException <ul> |
|---|
| 76 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
|---|
| 77 |
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
|---|
| 78 |
* </ul> |
|---|
| 79 |
* |
|---|
| 80 |
* @see DWT#DROP_DOWN |
|---|
| 81 |
* @see Widget#checkSubclass |
|---|
| 82 |
* @see Widget#getStyle |
|---|
| 83 |
*/ |
|---|
| 84 |
public this (CoolBar parent, int style) { |
|---|
| 85 |
super (parent, style); |
|---|
| 86 |
this.parent = parent; |
|---|
| 87 |
parent.createItem (this, parent.getItemCount ()); |
|---|
| 88 |
} |
|---|
| 89 |
|
|---|
| 90 |
/** |
|---|
| 91 |
* Constructs a new instance of this class given its parent |
|---|
| 92 |
* (which must be a <code>CoolBar</code>), a style value |
|---|
| 93 |
* describing its behavior and appearance, and the index |
|---|
| 94 |
* at which to place it in the items maintained by its parent. |
|---|
| 95 |
* <p> |
|---|
| 96 |
* The style value is either one of the style constants defined in |
|---|
| 97 |
* class <code>DWT</code> which is applicable to instances of this |
|---|
| 98 |
* class, or must be built by <em>bitwise OR</em>'ing together |
|---|
| 99 |
* (that is, using the <code>int</code> "|" operator) two or more |
|---|
| 100 |
* of those <code>DWT</code> style constants. The class description |
|---|
| 101 |
* lists the style constants that are applicable to the class. |
|---|
| 102 |
* Style bits are also inherited from superclasses. |
|---|
| 103 |
* </p> |
|---|
| 104 |
* |
|---|
| 105 |
* @param parent a composite control which will be the parent of the new instance (cannot be null) |
|---|
| 106 |
* @param style the style of control to construct |
|---|
| 107 |
* @param index the zero-relative index at which to store the receiver in its parent |
|---|
| 108 |
* |
|---|
| 109 |
* @exception IllegalArgumentException <ul> |
|---|
| 110 |
* <li>ERROR_NULL_ARGUMENT - if the parent is null</li> |
|---|
| 111 |
* <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> |
|---|
| 112 |
* </ul> |
|---|
| 113 |
* @exception DWTException <ul> |
|---|
| 114 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> |
|---|
| 115 |
* <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> |
|---|
| 116 |
* </ul> |
|---|
| 117 |
* |
|---|
| 118 |
* @see DWT#DROP_DOWN |
|---|
| 119 |
* @see Widget#checkSubclass |
|---|
| 120 |
* @see Widget#getStyle |
|---|
| 121 |
*/ |
|---|
| 122 |
public this (CoolBar parent, int style, int index) { |
|---|
| 123 |
super (parent, style); |
|---|
| 124 |
this.parent = parent; |
|---|
| 125 |
parent.createItem (this, index); |
|---|
| 126 |
} |
|---|
| 127 |
|
|---|
| 128 |
/** |
|---|
| 129 |
* Adds the listener to the collection of listeners that will |
|---|
| 130 |
* be notified when the control is selected by the user, by sending it one |
|---|
| 131 |
* of the messages defined in the <code>SelectionListener</code> |
|---|
| 132 |
* interface. |
|---|
| 133 |
* <p> |
|---|
| 134 |
* If <code>widgetSelected</code> is called when the mouse is over |
|---|
| 135 |
* the drop-down arrow (or 'chevron') portion of the cool item, |
|---|
| 136 |
* the event object detail field contains the value <code>DWT.ARROW</code>, |
|---|
| 137 |
* and the x and y fields in the event object represent the point at |
|---|
| 138 |
* the bottom left of the chevron, where the menu should be popped up. |
|---|
| 139 |
* <code>widgetDefaultSelected</code> is not called. |
|---|
| 140 |
* </p> |
|---|
| 141 |
* |
|---|
| 142 |
* @param listener the listener which should be notified when the control is selected by the user |
|---|
| 143 |
* |
|---|
| 144 |
* @exception IllegalArgumentException <ul> |
|---|
| 145 |
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li> |
|---|
| 146 |
* </ul> |
|---|
| 147 |
* @exception DWTException <ul> |
|---|
| 148 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 149 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 150 |
* </ul> |
|---|
| 151 |
* |
|---|
| 152 |
* @see SelectionListener |
|---|
| 153 |
* @see #removeSelectionListener |
|---|
| 154 |
* @see SelectionEvent |
|---|
| 155 |
* |
|---|
| 156 |
* @since 2.0 |
|---|
| 157 |
*/ |
|---|
| 158 |
public void addSelectionListener(SelectionListener listener) { |
|---|
| 159 |
checkWidget(); |
|---|
| 160 |
if (listener is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| 161 |
TypedListener typedListener = new TypedListener (listener); |
|---|
| 162 |
addListener (DWT.Selection,typedListener); |
|---|
| 163 |
addListener (DWT.DefaultSelection,typedListener); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
override protected void checkSubclass () { |
|---|
| 167 |
if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
|---|
| 168 |
} |
|---|
| 169 |
|
|---|
| 170 |
/** |
|---|
| 171 |
* Returns the preferred size of the receiver. |
|---|
| 172 |
* <p> |
|---|
| 173 |
* The <em>preferred size</em> of a <code>CoolItem</code> is the size that |
|---|
| 174 |
* it would best be displayed at. The width hint and height hint arguments |
|---|
| 175 |
* allow the caller to ask the instance questions such as "Given a particular |
|---|
| 176 |
* width, how high does it need to be to show all of the contents?" |
|---|
| 177 |
* To indicate that the caller does not wish to constrain a particular |
|---|
| 178 |
* dimension, the constant <code>DWT.DEFAULT</code> is passed for the hint. |
|---|
| 179 |
* </p> |
|---|
| 180 |
* |
|---|
| 181 |
* @param wHint the width hint (can be <code>DWT.DEFAULT</code>) |
|---|
| 182 |
* @param hHint the height hint (can be <code>DWT.DEFAULT</code>) |
|---|
| 183 |
* @return the preferred size |
|---|
| 184 |
* |
|---|
| 185 |
* @exception DWTException <ul> |
|---|
| 186 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 187 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 188 |
* </ul> |
|---|
| 189 |
* |
|---|
| 190 |
* @see Layout |
|---|
| 191 |
* @see #getBounds |
|---|
| 192 |
* @see #getSize |
|---|
| 193 |
* @see Control#getBorderWidth |
|---|
| 194 |
* @see Scrollable#computeTrim |
|---|
| 195 |
* @see Scrollable#getClientArea |
|---|
| 196 |
*/ |
|---|
| 197 |
public Point computeSize (int wHint, int hHint) { |
|---|
| 198 |
checkWidget (); |
|---|
| 199 |
int index = parent.indexOf (this); |
|---|
| 200 |
if (index is -1) return new Point (0, 0); |
|---|
| 201 |
int width = wHint, height = hHint; |
|---|
| 202 |
if (wHint is DWT.DEFAULT) width = 32; |
|---|
| 203 |
if (hHint is DWT.DEFAULT) height = 32; |
|---|
| 204 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 205 |
height += parent.getMargin (index); |
|---|
| 206 |
} else { |
|---|
| 207 |
width += parent.getMargin (index); |
|---|
| 208 |
} |
|---|
| 209 |
return new Point (width, height); |
|---|
| 210 |
} |
|---|
| 211 |
|
|---|
| 212 |
override void destroyWidget () { |
|---|
| 213 |
parent.destroyItem (this); |
|---|
| 214 |
releaseHandle (); |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
/** |
|---|
| 218 |
* Returns a rectangle describing the receiver's size and location |
|---|
| 219 |
* relative to its parent. |
|---|
| 220 |
* |
|---|
| 221 |
* @return the receiver's bounding rectangle |
|---|
| 222 |
* |
|---|
| 223 |
* @exception DWTException <ul> |
|---|
| 224 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 225 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 226 |
* </ul> |
|---|
| 227 |
*/ |
|---|
| 228 |
public Rectangle getBounds () { |
|---|
| 229 |
checkWidget (); |
|---|
| 230 |
int index = parent.indexOf (this); |
|---|
| 231 |
if (index is -1) return new Rectangle (0, 0, 0, 0); |
|---|
| 232 |
auto hwnd = parent.handle; |
|---|
| 233 |
RECT rect; |
|---|
| 234 |
OS.SendMessage (hwnd, OS.RB_GETRECT, index, &rect); |
|---|
| 235 |
if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| 236 |
MARGINS margins; |
|---|
| 237 |
OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, &margins); |
|---|
| 238 |
rect.left -= margins.cxLeftWidth; |
|---|
| 239 |
rect.right += margins.cxRightWidth; |
|---|
| 240 |
} |
|---|
| 241 |
if (!parent.isLastItemOfRow (index)) { |
|---|
| 242 |
rect.right += (parent.style & DWT.FLAT) is 0 ? CoolBar.SEPARATOR_WIDTH : 0; |
|---|
| 243 |
} |
|---|
| 244 |
int width = rect.right - rect.left; |
|---|
| 245 |
int height = rect.bottom - rect.top; |
|---|
| 246 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 247 |
return new Rectangle (rect.top, rect.left, height, width); |
|---|
| 248 |
} |
|---|
| 249 |
return new Rectangle (rect.left, rect.top, width, height); |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
Rectangle getClientArea () { |
|---|
| 253 |
checkWidget (); |
|---|
| 254 |
int index = parent.indexOf (this); |
|---|
| 255 |
if (index is -1) return new Rectangle (0, 0, 0, 0); |
|---|
| 256 |
auto hwnd = parent.handle; |
|---|
| 257 |
RECT insetRect; |
|---|
| 258 |
OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, &insetRect); |
|---|
| 259 |
RECT rect; |
|---|
| 260 |
OS.SendMessage (hwnd, OS.RB_GETRECT, index, &rect); |
|---|
| 261 |
int x = rect.left + insetRect.left; |
|---|
| 262 |
int y = rect.top; |
|---|
| 263 |
int width = rect.right - rect.left - insetRect.left; |
|---|
| 264 |
int height = rect.bottom - rect.top; |
|---|
| 265 |
if ((parent.style & DWT.FLAT) is 0) { |
|---|
| 266 |
y += insetRect.top; |
|---|
| 267 |
width -= insetRect.right; |
|---|
| 268 |
height -= insetRect.top + insetRect.bottom; |
|---|
| 269 |
} |
|---|
| 270 |
if (index is 0) { |
|---|
| 271 |
REBARBANDINFO rbBand; |
|---|
| 272 |
rbBand.cbSize = REBARBANDINFO.sizeof; |
|---|
| 273 |
rbBand.fMask = OS.RBBIM_HEADERSIZE; |
|---|
| 274 |
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, &rbBand); |
|---|
| 275 |
width = width - rbBand.cxHeader + 1; |
|---|
| 276 |
} |
|---|
| 277 |
return new Rectangle (x, y, Math.max (0, width), Math.max (0, height)); |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
/** |
|---|
| 281 |
* Returns the control that is associated with the receiver. |
|---|
| 282 |
* |
|---|
| 283 |
* @return the control that is contained by the receiver |
|---|
| 284 |
* |
|---|
| 285 |
* @exception DWTException <ul> |
|---|
| 286 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 287 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 288 |
* </ul> |
|---|
| 289 |
*/ |
|---|
| 290 |
public Control getControl () { |
|---|
| 291 |
checkWidget (); |
|---|
| 292 |
return control; |
|---|
| 293 |
} |
|---|
| 294 |
|
|---|
| 295 |
/** |
|---|
| 296 |
* Returns the receiver's parent, which must be a <code>CoolBar</code>. |
|---|
| 297 |
* |
|---|
| 298 |
* @return the receiver's parent |
|---|
| 299 |
* |
|---|
| 300 |
* @exception DWTException <ul> |
|---|
| 301 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 302 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 303 |
* </ul> |
|---|
| 304 |
*/ |
|---|
| 305 |
public CoolBar getParent () { |
|---|
| 306 |
checkWidget (); |
|---|
| 307 |
return parent; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
override void releaseHandle () { |
|---|
| 311 |
super.releaseHandle (); |
|---|
| 312 |
parent = null; |
|---|
| 313 |
id = -1; |
|---|
| 314 |
control = null; |
|---|
| 315 |
} |
|---|
| 316 |
|
|---|
| 317 |
/** |
|---|
| 318 |
* Sets the control that is associated with the receiver |
|---|
| 319 |
* to the argument. |
|---|
| 320 |
* |
|---|
| 321 |
* @param control the new control that will be contained by the receiver |
|---|
| 322 |
* |
|---|
| 323 |
* @exception IllegalArgumentException <ul> |
|---|
| 324 |
* <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> |
|---|
| 325 |
* <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> |
|---|
| 326 |
* </ul> |
|---|
| 327 |
* @exception DWTException <ul> |
|---|
| 328 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 329 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 330 |
* </ul> |
|---|
| 331 |
*/ |
|---|
| 332 |
public void setControl (Control control) { |
|---|
| 333 |
checkWidget (); |
|---|
| 334 |
if (control !is null) { |
|---|
| 335 |
if (control.isDisposed()) error (DWT.ERROR_INVALID_ARGUMENT); |
|---|
| 336 |
if (control.parent !is parent) error (DWT.ERROR_INVALID_PARENT); |
|---|
| 337 |
} |
|---|
| 338 |
int index = parent.indexOf (this); |
|---|
| 339 |
if (index is -1) return; |
|---|
| 340 |
if (this.control !is null && this.control.isDisposed ()) { |
|---|
| 341 |
this.control = null; |
|---|
| 342 |
} |
|---|
| 343 |
Control oldControl = this.control, newControl = control; |
|---|
| 344 |
auto hwnd = parent.handle; |
|---|
| 345 |
auto hwndChild = newControl !is null ? control.topHandle () : null; |
|---|
| 346 |
REBARBANDINFO rbBand; |
|---|
| 347 |
rbBand.cbSize = REBARBANDINFO.sizeof; |
|---|
| 348 |
rbBand.fMask = OS.RBBIM_CHILD; |
|---|
| 349 |
rbBand.hwndChild = hwndChild; |
|---|
| 350 |
this.control = newControl; |
|---|
| 351 |
|
|---|
| 352 |
/* |
|---|
| 353 |
* Feature in Windows. When Windows sets the rebar band child, |
|---|
| 354 |
* it makes the new child visible and hides the old child and |
|---|
| 355 |
* moves the new child to the top of the Z-order. The fix is |
|---|
| 356 |
* to save and restore the visibility and Z-order. |
|---|
| 357 |
*/ |
|---|
| 358 |
HWND hwndAbove; |
|---|
| 359 |
if (newControl !is null) { |
|---|
| 360 |
hwndAbove = OS.GetWindow (hwndChild, OS.GW_HWNDPREV); |
|---|
| 361 |
} |
|---|
| 362 |
bool hideNew = newControl !is null && !newControl.getVisible (); |
|---|
| 363 |
bool showOld = oldControl !is null && oldControl.getVisible (); |
|---|
| 364 |
OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, &rbBand); |
|---|
| 365 |
if (hideNew) newControl.setVisible (false); |
|---|
| 366 |
if (showOld) oldControl.setVisible (true); |
|---|
| 367 |
if (hwndAbove !is null && hwndAbove !is hwndChild) { |
|---|
| 368 |
int flags = OS.SWP_NOSIZE | OS.SWP_NOMOVE | OS.SWP_NOACTIVATE; |
|---|
| 369 |
SetWindowPos (hwndChild, hwndAbove, 0, 0, 0, 0, flags); |
|---|
| 370 |
} |
|---|
| 371 |
} |
|---|
| 372 |
|
|---|
| 373 |
/** |
|---|
| 374 |
* Returns a point describing the receiver's ideal size. |
|---|
| 375 |
* The x coordinate of the result is the ideal width of the receiver. |
|---|
| 376 |
* The y coordinate of the result is the ideal height of the receiver. |
|---|
| 377 |
* |
|---|
| 378 |
* @return the receiver's ideal size |
|---|
| 379 |
* |
|---|
| 380 |
* @exception DWTException <ul> |
|---|
| 381 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 382 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 383 |
* </ul> |
|---|
| 384 |
*/ |
|---|
| 385 |
public Point getPreferredSize () { |
|---|
| 386 |
checkWidget (); |
|---|
| 387 |
int index = parent.indexOf (this); |
|---|
| 388 |
if (index is -1) return new Point (0, 0); |
|---|
| 389 |
auto hwnd = parent.handle; |
|---|
| 390 |
REBARBANDINFO rbBand; |
|---|
| 391 |
rbBand.cbSize = REBARBANDINFO.sizeof; |
|---|
| 392 |
rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; |
|---|
| 393 |
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, &rbBand); |
|---|
| 394 |
int width = rbBand.cxIdeal + parent.getMargin (index); |
|---|
| 395 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 396 |
return new Point (rbBand.cyMaxChild, width); |
|---|
| 397 |
} |
|---|
| 398 |
return new Point (width, rbBand.cyMaxChild); |
|---|
| 399 |
} |
|---|
| 400 |
|
|---|
| 401 |
/** |
|---|
| 402 |
* Sets the receiver's ideal size to the point specified by the arguments. |
|---|
| 403 |
* |
|---|
| 404 |
* @param width the new ideal width for the receiver |
|---|
| 405 |
* @param height the new ideal height for the receiver |
|---|
| 406 |
* |
|---|
| 407 |
* @exception DWTException <ul> |
|---|
| 408 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 409 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 410 |
* </ul> |
|---|
| 411 |
*/ |
|---|
| 412 |
public void setPreferredSize (int width, int height) { |
|---|
| 413 |
checkWidget (); |
|---|
| 414 |
int index = parent.indexOf (this); |
|---|
| 415 |
if (index is -1) return; |
|---|
| 416 |
width = Math.max (0, width); |
|---|
| 417 |
height = Math.max (0, height); |
|---|
| 418 |
ideal = true; |
|---|
| 419 |
auto hwnd = parent.handle; |
|---|
| 420 |
int cxIdeal, cyMaxChild; |
|---|
| 421 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 422 |
cxIdeal = Math.max (0, height - parent.getMargin (index)); |
|---|
| 423 |
cyMaxChild = width; |
|---|
| 424 |
} else { |
|---|
| 425 |
cxIdeal = Math.max (0, width - parent.getMargin (index)); |
|---|
| 426 |
cyMaxChild = height; |
|---|
| 427 |
} |
|---|
| 428 |
REBARBANDINFO rbBand; |
|---|
| 429 |
rbBand.cbSize = REBARBANDINFO.sizeof; |
|---|
| 430 |
|
|---|
| 431 |
/* Get the child size fields first so we don't overwrite them. */ |
|---|
| 432 |
rbBand.fMask = OS.RBBIM_CHILDSIZE; |
|---|
| 433 |
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, &rbBand); |
|---|
| 434 |
|
|---|
| 435 |
/* Set the size fields we are currently modifying. */ |
|---|
| 436 |
rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; |
|---|
| 437 |
rbBand.cxIdeal = cxIdeal; |
|---|
| 438 |
rbBand.cyMaxChild = cyMaxChild; |
|---|
| 439 |
if (!minimum) rbBand.cyMinChild = cyMaxChild; |
|---|
| 440 |
OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, &rbBand); |
|---|
| 441 |
} |
|---|
| 442 |
|
|---|
| 443 |
/** |
|---|
| 444 |
* Sets the receiver's ideal size to the point specified by the argument. |
|---|
| 445 |
* |
|---|
| 446 |
* @param size the new ideal size for the receiver |
|---|
| 447 |
* |
|---|
| 448 |
* @exception IllegalArgumentException <ul> |
|---|
| 449 |
* <li>ERROR_NULL_ARGUMENT - if the point is null</li> |
|---|
| 450 |
* </ul> |
|---|
| 451 |
* @exception DWTException <ul> |
|---|
| 452 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 453 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 454 |
* </ul> |
|---|
| 455 |
*/ |
|---|
| 456 |
public void setPreferredSize (Point size) { |
|---|
| 457 |
checkWidget (); |
|---|
| 458 |
if (size is null) error(DWT.ERROR_NULL_ARGUMENT); |
|---|
| 459 |
setPreferredSize (size.x, size.y); |
|---|
| 460 |
} |
|---|
| 461 |
|
|---|
| 462 |
/** |
|---|
| 463 |
* Returns a point describing the receiver's size. The |
|---|
| 464 |
* x coordinate of the result is the width of the receiver. |
|---|
| 465 |
* The y coordinate of the result is the height of the |
|---|
| 466 |
* receiver. |
|---|
| 467 |
* |
|---|
| 468 |
* @return the receiver's size |
|---|
| 469 |
* |
|---|
| 470 |
* @exception DWTException <ul> |
|---|
| 471 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 472 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 473 |
* </ul> |
|---|
| 474 |
*/ |
|---|
| 475 |
public Point getSize() { |
|---|
| 476 |
checkWidget (); |
|---|
| 477 |
int index = parent.indexOf (this); |
|---|
| 478 |
if (index is -1) new Point (0, 0); |
|---|
| 479 |
auto hwnd = parent.handle; |
|---|
| 480 |
RECT rect; |
|---|
| 481 |
OS.SendMessage (hwnd, OS.RB_GETRECT, index, &rect); |
|---|
| 482 |
if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| 483 |
MARGINS margins; |
|---|
| 484 |
OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, &margins); |
|---|
| 485 |
rect.left -= margins.cxLeftWidth; |
|---|
| 486 |
rect.right += margins.cxRightWidth; |
|---|
| 487 |
} |
|---|
| 488 |
if (!parent.isLastItemOfRow (index)) { |
|---|
| 489 |
rect.right += (parent.style & DWT.FLAT) is 0 ? CoolBar.SEPARATOR_WIDTH : 0; |
|---|
| 490 |
} |
|---|
| 491 |
int width = rect.right - rect.left; |
|---|
| 492 |
int height = rect.bottom - rect.top; |
|---|
| 493 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 494 |
return new Point (height, width); |
|---|
| 495 |
} |
|---|
| 496 |
return new Point (width, height); |
|---|
| 497 |
} |
|---|
| 498 |
|
|---|
| 499 |
/** |
|---|
| 500 |
* Sets the receiver's size to the point specified by the arguments. |
|---|
| 501 |
* <p> |
|---|
| 502 |
* Note: Attempting to set the width or height of the |
|---|
| 503 |
* receiver to a negative number will cause that |
|---|
| 504 |
* value to be set to zero instead. |
|---|
| 505 |
* </p> |
|---|
| 506 |
* |
|---|
| 507 |
* @param width the new width for the receiver |
|---|
| 508 |
* @param height the new height for the receiver |
|---|
| 509 |
* |
|---|
| 510 |
* @exception DWTException <ul> |
|---|
| 511 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 512 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 513 |
* </ul> |
|---|
| 514 |
*/ |
|---|
| 515 |
public void setSize (int width, int height) { |
|---|
| 516 |
checkWidget (); |
|---|
| 517 |
int index = parent.indexOf (this); |
|---|
| 518 |
if (index is -1) return; |
|---|
| 519 |
width = Math.max (0, width); |
|---|
| 520 |
height = Math.max (0, height); |
|---|
| 521 |
auto hwnd = parent.handle; |
|---|
| 522 |
int cx, cyChild, cxIdeal; |
|---|
| 523 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 524 |
cx = height; |
|---|
| 525 |
cyChild = width; |
|---|
| 526 |
cxIdeal = Math.max (0, height - parent.getMargin (index)); |
|---|
| 527 |
} else { |
|---|
| 528 |
cx = width; |
|---|
| 529 |
cyChild = height; |
|---|
| 530 |
cxIdeal = Math.max (0, width - parent.getMargin (index)); |
|---|
| 531 |
} |
|---|
| 532 |
REBARBANDINFO rbBand; |
|---|
| 533 |
rbBand.cbSize = REBARBANDINFO.sizeof; |
|---|
| 534 |
|
|---|
| 535 |
/* Get the child size fields first so we don't overwrite them. */ |
|---|
| 536 |
rbBand.fMask = OS.RBBIM_CHILDSIZE | OS.RBBIM_IDEALSIZE; |
|---|
| 537 |
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, &rbBand); |
|---|
| 538 |
|
|---|
| 539 |
/* Set the size fields we are currently modifying. */ |
|---|
| 540 |
if (!ideal) rbBand.cxIdeal = cxIdeal; |
|---|
| 541 |
if (!minimum) rbBand.cyMinChild = cyChild; |
|---|
| 542 |
rbBand.cyChild = cyChild; |
|---|
| 543 |
|
|---|
| 544 |
/* |
|---|
| 545 |
* Do not set the size for the last item on the row. |
|---|
| 546 |
*/ |
|---|
| 547 |
if (!parent.isLastItemOfRow (index)) { |
|---|
| 548 |
if (OS.COMCTL32_MAJOR >= 6) { |
|---|
| 549 |
MARGINS margins; |
|---|
| 550 |
OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, &margins); |
|---|
| 551 |
cx -= margins.cxLeftWidth + margins.cxRightWidth; |
|---|
| 552 |
} |
|---|
| 553 |
int separator = (parent.style & DWT.FLAT) is 0 ? CoolBar.SEPARATOR_WIDTH : 0; |
|---|
| 554 |
rbBand.cx = cx - separator; |
|---|
| 555 |
rbBand.fMask |= OS.RBBIM_SIZE; |
|---|
| 556 |
} |
|---|
| 557 |
OS.SendMessage (hwnd, OS.RB_SETBANDINFO, index, &rbBand); |
|---|
| 558 |
} |
|---|
| 559 |
|
|---|
| 560 |
/** |
|---|
| 561 |
* Sets the receiver's size to the point specified by the argument. |
|---|
| 562 |
* <p> |
|---|
| 563 |
* Note: Attempting to set the width or height of the |
|---|
| 564 |
* receiver to a negative number will cause them to be |
|---|
| 565 |
* set to zero instead. |
|---|
| 566 |
* </p> |
|---|
| 567 |
* |
|---|
| 568 |
* @param size the new size for the receiver |
|---|
| 569 |
* |
|---|
| 570 |
* @exception IllegalArgumentException <ul> |
|---|
| 571 |
* <li>ERROR_NULL_ARGUMENT - if the point is null</li> |
|---|
| 572 |
* </ul> |
|---|
| 573 |
* @exception DWTException <ul> |
|---|
| 574 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 575 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 576 |
* </ul> |
|---|
| 577 |
*/ |
|---|
| 578 |
public void setSize (Point size) { |
|---|
| 579 |
if (size is null) error(DWT.ERROR_NULL_ARGUMENT); |
|---|
| 580 |
setSize (size.x, size.y); |
|---|
| 581 |
} |
|---|
| 582 |
|
|---|
| 583 |
/** |
|---|
| 584 |
* Returns the minimum size that the cool item can |
|---|
| 585 |
* be resized to using the cool item's gripper. |
|---|
| 586 |
* |
|---|
| 587 |
* @return a point containing the minimum width and height of the cool item, in pixels |
|---|
| 588 |
* |
|---|
| 589 |
* @exception DWTException <ul> |
|---|
| 590 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 591 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 592 |
* </ul> |
|---|
| 593 |
* |
|---|
| 594 |
* @since 2.0 |
|---|
| 595 |
*/ |
|---|
| 596 |
public Point getMinimumSize () { |
|---|
| 597 |
checkWidget (); |
|---|
| 598 |
int index = parent.indexOf (this); |
|---|
| 599 |
if (index is -1) return new Point (0, 0); |
|---|
| 600 |
auto hwnd = parent.handle; |
|---|
| 601 |
REBARBANDINFO rbBand; |
|---|
| 602 |
rbBand.cbSize = REBARBANDINFO.sizeof; |
|---|
| 603 |
rbBand.fMask = OS.RBBIM_CHILDSIZE; |
|---|
| 604 |
OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, &rbBand); |
|---|
| 605 |
if ((parent.style & DWT.VERTICAL) !is 0) { |
|---|
| 606 |
return new Point (rbBand.cyMinChild, rbBand.cxMinChild); |
|---|
| 607 |
} |
|---|
| 608 |
return new Point (rbBand.cxMinChild, rbBand.cyMinChild); |
|---|
| 609 |
} |
|---|
| 610 |
|
|---|
| 611 |
/** |
|---|
| 612 |
* Sets the minimum size that the cool item can be resized to |
|---|
| 613 |
* using the cool item's gripper, to the point specified by the arguments. |
|---|
| 614 |
* |
|---|
| 615 |
* @param width the minimum width of the cool item, in pixels |
|---|
| 616 |
* @param height the minimum height of the cool item, in pixels |
|---|
| 617 |
* |
|---|
| 618 |
* @exception DWTException <ul> |
|---|
| 619 |
* <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> |
|---|
| 620 |
* <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> |
|---|
| 621 |
* </ul> |
|---|
| 622 |
* |
|---|
| 623 |
* @since 2.0 |
|---|
| 624 |
*/ |
|---|
| 625 |
public void setMinimumSize (int width, int height) { |
|---|
| 626 |
checkWidget (); |
|---|
| 627 |
int index = parent.indexOf (this); |
|---|
| 628 |
if (index is -1) return; |
|---|
| 629 |
width = Math.max (0, width); |
|---|
| 630 |
height = Math.max (0, height); |
|---|
| 631 |
minimum = true; |
|---|
| 632 |
auto hwnd = parent.handle; |
|---|
| 633 |
int cxMinChild, cyMinChild; |
|---|
| 634 |
if ((parent |
|---|