Mercurial > projects > dwt-win
annotate dwt/custom/ScrolledComposite.d @ 246:fd9c62a2998e
Updater SWT 3.4M7 to 3.4
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 01 Jul 2008 10:15:59 +0200 |
parents | 36f5cb12e1a2 |
children | 349b8c12e243 |
rev | line source |
---|---|
155 | 1 /******************************************************************************* |
246 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
155 | 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.custom.ScrolledComposite; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 import dwt.DWTException; | |
213 | 18 import dwt.events.DisposeEvent; |
19 import dwt.events.DisposeListener; | |
155 | 20 import dwt.graphics.Point; |
21 import dwt.graphics.Rectangle; | |
22 import dwt.widgets.Composite; | |
23 import dwt.widgets.Control; | |
213 | 24 import dwt.widgets.Display; |
155 | 25 import dwt.widgets.Event; |
26 import dwt.widgets.Layout; | |
27 import dwt.widgets.Listener; | |
28 import dwt.widgets.ScrollBar; | |
213 | 29 import dwt.widgets.Shell; |
155 | 30 import dwt.custom.ScrolledCompositeLayout; |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
155
diff
changeset
|
31 import dwt.dwthelper.utils; |
155 | 32 |
33 /** | |
34 * A ScrolledComposite provides scrollbars and will scroll its content when the user | |
35 * uses the scrollbars. | |
36 * | |
37 * | |
38 * <p>There are two ways to use the ScrolledComposite: | |
39 * | |
40 * <p> | |
41 * 1) Set the size of the control that is being scrolled and the ScrolledComposite | |
42 * will show scrollbars when the contained control can not be fully seen. | |
43 * | |
44 * 2) The second way imitates the way a browser would work. Set the minimum size of | |
45 * the control and the ScrolledComposite will show scroll bars if the visible area is | |
46 * less than the minimum size of the control and it will expand the size of the control | |
47 * if the visible area is greater than the minimum size. This requires invoking | |
48 * both setMinWidth(), setMinHeight() and setExpandHorizontal(), setExpandVertical(). | |
49 * | |
50 * <code><pre> | |
51 * public static void main (String [] args) { | |
52 * Display display = new Display (); | |
53 * Color red = display.getSystemColor(DWT.COLOR_RED); | |
54 * Color blue = display.getSystemColor(DWT.COLOR_BLUE); | |
55 * Shell shell = new Shell (display); | |
56 * shell.setLayout(new FillLayout()); | |
57 * | |
58 * // set the size of the scrolled content - method 1 | |
59 * final ScrolledComposite sc1 = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER); | |
60 * final Composite c1 = new Composite(sc1, DWT.NONE); | |
61 * sc1.setContent(c1); | |
62 * c1.setBackground(red); | |
63 * GridLayout layout = new GridLayout(); | |
64 * layout.numColumns = 4; | |
65 * c1.setLayout(layout); | |
66 * Button b1 = new Button (c1, DWT.PUSH); | |
67 * b1.setText("first button"); | |
68 * c1.setSize(c1.computeSize(DWT.DEFAULT, DWT.DEFAULT)); | |
69 * | |
70 * // set the minimum width and height of the scrolled content - method 2 | |
71 * final ScrolledComposite sc2 = new ScrolledComposite(shell, DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER); | |
72 * sc2.setExpandHorizontal(true); | |
73 * sc2.setExpandVertical(true); | |
74 * final Composite c2 = new Composite(sc2, DWT.NONE); | |
75 * sc2.setContent(c2); | |
76 * c2.setBackground(blue); | |
77 * layout = new GridLayout(); | |
78 * layout.numColumns = 4; | |
79 * c2.setLayout(layout); | |
80 * Button b2 = new Button (c2, DWT.PUSH); | |
81 * b2.setText("first button"); | |
82 * sc2.setMinSize(c2.computeSize(DWT.DEFAULT, DWT.DEFAULT)); | |
83 * | |
84 * Button add = new Button (shell, DWT.PUSH); | |
85 * add.setText("add children"); | |
86 * final int[] index = new int[]{0}; | |
87 * add.addListener(DWT.Selection, new Listener() { | |
88 * public void handleEvent(Event e) { | |
89 * index[0]++; | |
90 * Button button = new Button(c1, DWT.PUSH); | |
91 * button.setText("button "+index[0]); | |
92 * // reset size of content so children can be seen - method 1 | |
93 * c1.setSize(c1.computeSize(DWT.DEFAULT, DWT.DEFAULT)); | |
94 * c1.layout(); | |
95 * | |
96 * button = new Button(c2, DWT.PUSH); | |
97 * button.setText("button "+index[0]); | |
98 * // reset the minimum width and height so children can be seen - method 2 | |
99 * sc2.setMinSize(c2.computeSize(DWT.DEFAULT, DWT.DEFAULT)); | |
100 * c2.layout(); | |
101 * } | |
102 * }); | |
103 * | |
104 * shell.open (); | |
105 * while (!shell.isDisposed ()) { | |
106 * if (!display.readAndDispatch ()) display.sleep (); | |
107 * } | |
108 * display.dispose (); | |
109 * } | |
110 * </pre></code> | |
111 * | |
112 * <dl> | |
113 * <dt><b>Styles:</b><dd>H_SCROLL, V_SCROLL | |
114 * </dl> | |
246 | 115 * |
116 * @see <a href="http://www.eclipse.org/swt/snippets/#scrolledcomposite">ScrolledComposite snippets</a> | |
117 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
155 | 118 */ |
119 public class ScrolledComposite : Composite { | |
120 | |
121 Control content; | |
122 Listener contentListener; | |
213 | 123 Listener filter; |
155 | 124 |
125 int minHeight = 0; | |
126 int minWidth = 0; | |
127 bool expandHorizontal = false; | |
128 bool expandVertical = false; | |
129 bool alwaysShowScroll = false; | |
213 | 130 bool showFocusedControl = false; |
155 | 131 |
132 /** | |
133 * Constructs a new instance of this class given its parent | |
134 * and a style value describing its behavior and appearance. | |
135 * <p> | |
136 * The style value is either one of the style constants defined in | |
137 * class <code>DWT</code> which is applicable to instances of this | |
138 * class, or must be built by <em>bitwise OR</em>'ing together | |
139 * (that is, using the <code>int</code> "|" operator) two or more | |
140 * of those <code>DWT</code> style constants. The class description | |
141 * lists the style constants that are applicable to the class. | |
142 * Style bits are also inherited from superclasses. | |
143 * </p> | |
144 * | |
145 * @param parent a widget which will be the parent of the new instance (cannot be null) | |
146 * @param style the style of widget to construct | |
147 * | |
148 * @exception IllegalArgumentException <ul> | |
149 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
150 * </ul> | |
151 * @exception DWTException <ul> | |
152 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
153 * </ul> | |
154 * | |
155 * @see DWT#H_SCROLL | |
156 * @see DWT#V_SCROLL | |
157 * @see #getStyle() | |
158 */ | |
159 public this(Composite parent, int style) { | |
160 super(parent, checkStyle(style)); | |
161 super.setLayout(new ScrolledCompositeLayout()); | |
162 ScrollBar hBar = getHorizontalBar (); | |
163 if (hBar !is null) { | |
164 hBar.setVisible(false); | |
165 hBar.addListener (DWT.Selection, new class() Listener { | |
166 public void handleEvent (Event e) { | |
167 hScroll(); | |
168 } | |
169 }); | |
170 } | |
171 | |
172 ScrollBar vBar = getVerticalBar (); | |
173 if (vBar !is null) { | |
174 vBar.setVisible(false); | |
175 vBar.addListener (DWT.Selection, new class() Listener { | |
176 public void handleEvent (Event e) { | |
177 vScroll(); | |
178 } | |
179 }); | |
180 } | |
181 | |
182 contentListener = new class() Listener { | |
183 public void handleEvent(Event e) { | |
184 if (e.type !is DWT.Resize) return; | |
185 layout(false); | |
186 } | |
187 }; | |
213 | 188 |
189 filter = new class() Listener { | |
190 public void handleEvent(Event event) { | |
191 if ( auto control = cast(Control)event.widget ) { | |
192 if (contains(control)) showControl(control); | |
193 } | |
194 } | |
195 }; | |
196 | |
197 addDisposeListener(new class() DisposeListener { | |
198 public void widgetDisposed(DisposeEvent e) { | |
199 getDisplay().removeFilter(DWT.FocusIn, filter); | |
200 } | |
201 }); | |
155 | 202 } |
203 | |
204 static int checkStyle (int style) { | |
205 int mask = DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; | |
206 return style & mask; | |
207 } | |
208 | |
213 | 209 bool contains(Control control) { |
210 if (control is null || control.isDisposed()) return false; | |
211 | |
212 Composite parent = control.getParent(); | |
213 while (parent !is null && !( null !is cast(Shell)parent )) { | |
214 if (this is parent) return true; | |
215 parent = parent.getParent(); | |
216 } | |
217 return false; | |
218 } | |
219 | |
155 | 220 /** |
221 * Returns the Always Show Scrollbars flag. True if the scrollbars are | |
222 * always shown even if they are not required. False if the scrollbars are only | |
223 * visible when some part of the composite needs to be scrolled to be seen. | |
224 * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the | |
225 * horizontal and vertical directions. | |
226 * | |
227 * @return the Always Show Scrollbars flag value | |
228 */ | |
229 public bool getAlwaysShowScrollBars() { | |
230 //checkWidget(); | |
231 return alwaysShowScroll; | |
232 } | |
233 | |
234 /** | |
235 * Returns <code>true</code> if the content control | |
236 * will be expanded to fill available horizontal space. | |
237 * | |
238 * @return the receiver's horizontal expansion state | |
239 * | |
240 * @exception DWTException <ul> | |
241 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
242 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
243 * </ul> | |
244 * | |
245 * @since 3.2 | |
246 */ | |
247 public bool getExpandHorizontal() { | |
248 checkWidget(); | |
249 return expandHorizontal; | |
250 } | |
251 | |
252 /** | |
253 * Returns <code>true</code> if the content control | |
254 * will be expanded to fill available vertical space. | |
255 * | |
256 * @return the receiver's vertical expansion state | |
257 * | |
258 * @exception DWTException <ul> | |
259 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
260 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
261 * </ul> | |
262 * | |
263 * @since 3.2 | |
264 */ | |
265 public bool getExpandVertical() { | |
266 checkWidget(); | |
267 return expandVertical; | |
268 } | |
269 | |
270 /** | |
271 * Returns the minimum width of the content control. | |
272 * | |
273 * @return the minimum width | |
274 * | |
275 * @exception DWTException <ul> | |
276 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
277 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
278 * </ul> | |
279 * | |
280 * @since 3.2 | |
281 */ | |
282 public int getMinWidth() { | |
283 checkWidget(); | |
284 return minWidth; | |
285 } | |
286 | |
287 /** | |
288 * Returns the minimum height of the content control. | |
289 * | |
290 * @return the minimum height | |
291 * | |
292 * @exception DWTException <ul> | |
293 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
294 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
295 * </ul> | |
296 * | |
297 * @since 3.2 | |
298 */ | |
299 public int getMinHeight() { | |
300 checkWidget(); | |
301 return minHeight; | |
302 } | |
303 | |
304 /** | |
305 * Get the content that is being scrolled. | |
306 * | |
307 * @return the control displayed in the content area | |
308 */ | |
309 public Control getContent() { | |
310 //checkWidget(); | |
311 return content; | |
312 } | |
313 | |
213 | 314 /** |
315 * Returns <code>true</code> if the receiver automatically scrolls to a focused child control | |
316 * to make it visible. Otherwise, returns <code>false</code>. | |
317 * | |
246 | 318 * @return a bool indicating whether focused child controls are automatically scrolled into the viewport |
319 * | |
213 | 320 * @exception DWTException <ul> |
321 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
322 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
323 * </ul> | |
324 * | |
325 * @since 3.4 | |
326 */ | |
327 public bool getShowFocusedControl() { | |
328 checkWidget(); | |
329 return showFocusedControl; | |
330 } | |
331 | |
155 | 332 void hScroll() { |
333 if (content is null) return; | |
334 Point location = content.getLocation (); | |
335 ScrollBar hBar = getHorizontalBar (); | |
336 int hSelection = hBar.getSelection (); | |
337 content.setLocation (-hSelection, location.y); | |
338 } | |
339 bool needHScroll(Rectangle contentRect, bool vVisible) { | |
340 ScrollBar hBar = getHorizontalBar(); | |
341 if (hBar is null) return false; | |
342 | |
343 Rectangle hostRect = getBounds(); | |
344 int border = getBorderWidth(); | |
345 hostRect.width -= 2*border; | |
346 ScrollBar vBar = getVerticalBar(); | |
347 if (vVisible && vBar !is null) hostRect.width -= vBar.getSize().x; | |
348 | |
349 if (!expandHorizontal && contentRect.width > hostRect.width) return true; | |
350 if (expandHorizontal && minWidth > hostRect.width) return true; | |
351 return false; | |
352 } | |
353 | |
354 bool needVScroll(Rectangle contentRect, bool hVisible) { | |
355 ScrollBar vBar = getVerticalBar(); | |
356 if (vBar is null) return false; | |
357 | |
358 Rectangle hostRect = getBounds(); | |
359 int border = getBorderWidth(); | |
360 hostRect.height -= 2*border; | |
361 ScrollBar hBar = getHorizontalBar(); | |
362 if (hVisible && hBar !is null) hostRect.height -= hBar.getSize().y; | |
363 | |
364 if (!expandVertical && contentRect.height > hostRect.height) return true; | |
365 if (expandVertical && minHeight > hostRect.height) return true; | |
366 return false; | |
367 } | |
368 | |
369 /** | |
370 * Return the point in the content that currently appears in the top left | |
371 * corner of the scrolled composite. | |
372 * | |
373 * @return the point in the content that currently appears in the top left | |
374 * corner of the scrolled composite. If no content has been set, this returns | |
375 * (0, 0). | |
376 * | |
377 * @exception DWTException <ul> | |
378 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
379 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
380 * </ul> | |
381 * | |
382 * @since 2.0 | |
383 */ | |
384 public Point getOrigin() { | |
385 checkWidget(); | |
386 if (content is null) return new Point(0, 0); | |
387 Point location = content.getLocation(); | |
388 return new Point(-location.x, -location.y); | |
389 } | |
390 /** | |
391 * Scrolls the content so that the specified point in the content is in the top | |
392 * left corner. If no content has been set, nothing will occur. | |
393 * | |
394 * Negative values will be ignored. Values greater than the maximum scroll | |
395 * distance will result in scrolling to the end of the scrollbar. | |
396 * | |
397 * @param origin the point on the content to appear in the top left corner | |
398 * | |
399 * @exception DWTException <ul> | |
400 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
401 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
402 * <li>ERROR_INVALID_ARGUMENT - value of origin is outside of content | |
403 * </ul> | |
404 * @since 2.0 | |
405 */ | |
406 public void setOrigin(Point origin) { | |
407 setOrigin(origin.x, origin.y); | |
408 } | |
409 /** | |
410 * Scrolls the content so that the specified point in the content is in the top | |
411 * left corner. If no content has been set, nothing will occur. | |
412 * | |
413 * Negative values will be ignored. Values greater than the maximum scroll | |
414 * distance will result in scrolling to the end of the scrollbar. | |
415 * | |
416 * @param x the x coordinate of the content to appear in the top left corner | |
417 * | |
418 * @param y the y coordinate of the content to appear in the top left corner | |
419 * | |
420 * @exception DWTException <ul> | |
421 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
422 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
423 * </ul> | |
424 * | |
425 * @since 2.0 | |
426 */ | |
427 public void setOrigin(int x, int y) { | |
428 checkWidget(); | |
429 if (content is null) return; | |
430 ScrollBar hBar = getHorizontalBar (); | |
431 if (hBar !is null) { | |
432 hBar.setSelection(x); | |
433 x = -hBar.getSelection (); | |
434 } else { | |
435 x = 0; | |
436 } | |
437 ScrollBar vBar = getVerticalBar (); | |
438 if (vBar !is null) { | |
439 vBar.setSelection(y); | |
440 y = -vBar.getSelection (); | |
441 } else { | |
442 y = 0; | |
443 } | |
444 content.setLocation(x, y); | |
445 } | |
446 /** | |
447 * Set the Always Show Scrollbars flag. True if the scrollbars are | |
448 * always shown even if they are not required. False if the scrollbars are only | |
449 * visible when some part of the composite needs to be scrolled to be seen. | |
450 * The H_SCROLL and V_SCROLL style bits are also required to enable scrollbars in the | |
451 * horizontal and vertical directions. | |
452 * | |
453 * @param show true to show the scrollbars even when not required, false to show scrollbars only when required | |
454 * | |
455 * @exception DWTException <ul> | |
456 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
457 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
458 * </ul> | |
459 */ | |
460 public void setAlwaysShowScrollBars(bool show) { | |
461 checkWidget(); | |
462 if (show is alwaysShowScroll) return; | |
463 alwaysShowScroll = show; | |
464 ScrollBar hBar = getHorizontalBar (); | |
465 if (hBar !is null && alwaysShowScroll) hBar.setVisible(true); | |
466 ScrollBar vBar = getVerticalBar (); | |
467 if (vBar !is null && alwaysShowScroll) vBar.setVisible(true); | |
468 layout(false); | |
469 } | |
470 | |
471 /** | |
472 * Set the content that will be scrolled. | |
473 * | |
474 * @param content the control to be displayed in the content area | |
475 * | |
476 * @exception DWTException <ul> | |
477 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
478 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
479 * </ul> | |
480 */ | |
481 public void setContent(Control content) { | |
482 checkWidget(); | |
483 if (this.content !is null && !this.content.isDisposed()) { | |
484 this.content.removeListener(DWT.Resize, contentListener); | |
485 this.content.setBounds(new Rectangle(-200, -200, 0, 0)); | |
486 } | |
487 | |
488 this.content = content; | |
489 ScrollBar vBar = getVerticalBar (); | |
490 ScrollBar hBar = getHorizontalBar (); | |
491 if (this.content !is null) { | |
492 if (vBar !is null) { | |
493 vBar.setMaximum (0); | |
494 vBar.setThumb (0); | |
495 vBar.setSelection(0); | |
496 } | |
497 if (hBar !is null) { | |
498 hBar.setMaximum (0); | |
499 hBar.setThumb (0); | |
500 hBar.setSelection(0); | |
501 } | |
502 content.setLocation(0, 0); | |
503 layout(false); | |
504 this.content.addListener(DWT.Resize, contentListener); | |
505 } else { | |
506 if (hBar !is null) hBar.setVisible(alwaysShowScroll); | |
507 if (vBar !is null) vBar.setVisible(alwaysShowScroll); | |
508 } | |
509 } | |
510 /** | |
511 * Configure the ScrolledComposite to resize the content object to be as wide as the | |
512 * ScrolledComposite when the width of the ScrolledComposite is greater than the | |
513 * minimum width specified in setMinWidth. If the ScrolledComposite is less than the | |
514 * minimum width, the content will not be resized and instead the horizontal scroll bar will be | |
515 * used to view the entire width. | |
516 * If expand is false, this behaviour is turned off. By default, this behaviour is turned off. | |
517 * | |
518 * @param expand true to expand the content control to fill available horizontal space | |
519 * | |
520 * @exception DWTException <ul> | |
521 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
522 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
523 * </ul> | |
524 */ | |
525 public void setExpandHorizontal(bool expand) { | |
526 checkWidget(); | |
527 if (expand is expandHorizontal) return; | |
528 expandHorizontal = expand; | |
529 layout(false); | |
530 } | |
531 /** | |
532 * Configure the ScrolledComposite to resize the content object to be as tall as the | |
533 * ScrolledComposite when the height of the ScrolledComposite is greater than the | |
534 * minimum height specified in setMinHeight. If the ScrolledComposite is less than the | |
535 * minimum height, the content will not be resized and instead the vertical scroll bar will be | |
536 * used to view the entire height. | |
537 * If expand is false, this behaviour is turned off. By default, this behaviour is turned off. | |
538 * | |
539 * @param expand true to expand the content control to fill available vertical space | |
540 * | |
541 * @exception DWTException <ul> | |
542 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
543 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
544 * </ul> | |
545 */ | |
546 public void setExpandVertical(bool expand) { | |
547 checkWidget(); | |
548 if (expand is expandVertical) return; | |
549 expandVertical = expand; | |
550 layout(false); | |
551 } | |
552 /** | |
553 * Sets the layout which is associated with the receiver to be | |
554 * the argument which may be null. | |
555 * <p> | |
556 * Note: No Layout can be set on this Control because it already | |
557 * manages the size and position of its children. | |
558 * </p> | |
559 * | |
560 * @param layout the receiver's new layout or null | |
561 * | |
562 * @exception DWTException <ul> | |
563 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
564 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
565 * </ul> | |
566 */ | |
567 public override void setLayout (Layout layout) { | |
568 checkWidget(); | |
569 return; | |
570 } | |
571 /** | |
572 * Specify the minimum height at which the ScrolledComposite will begin scrolling the | |
573 * content with the vertical scroll bar. This value is only relevant if | |
574 * setExpandVertical(true) has been set. | |
575 * | |
576 * @param height the minimum height or 0 for default height | |
577 * | |
578 * @exception DWTException <ul> | |
579 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
580 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
581 * </ul> | |
582 */ | |
583 public void setMinHeight(int height) { | |
584 setMinSize(minWidth, height); | |
585 } | |
586 /** | |
587 * Specify the minimum width and height at which the ScrolledComposite will begin scrolling the | |
588 * content with the horizontal scroll bar. This value is only relevant if | |
589 * setExpandHorizontal(true) and setExpandVertical(true) have been set. | |
590 * | |
591 * @param size the minimum size or null for the default size | |
592 * | |
593 * @exception DWTException <ul> | |
594 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
595 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
596 * </ul> | |
597 */ | |
598 public void setMinSize(Point size) { | |
599 if (size is null) { | |
600 setMinSize(0, 0); | |
601 } else { | |
602 setMinSize(size.x, size.y); | |
603 } | |
604 } | |
605 /** | |
606 * Specify the minimum width and height at which the ScrolledComposite will begin scrolling the | |
607 * content with the horizontal scroll bar. This value is only relevant if | |
608 * setExpandHorizontal(true) and setExpandVertical(true) have been set. | |
609 * | |
610 * @param width the minimum width or 0 for default width | |
611 * @param height the minimum height or 0 for default height | |
612 * | |
613 * @exception DWTException <ul> | |
614 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
615 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
616 * </ul> | |
617 */ | |
618 public void setMinSize(int width, int height) { | |
619 checkWidget(); | |
620 if (width is minWidth && height is minHeight) return; | |
621 minWidth = Math.max(0, width); | |
622 minHeight = Math.max(0, height); | |
623 layout(false); | |
624 } | |
625 /** | |
626 * Specify the minimum width at which the ScrolledComposite will begin scrolling the | |
627 * content with the horizontal scroll bar. This value is only relevant if | |
628 * setExpandHorizontal(true) has been set. | |
629 * | |
630 * @param width the minimum width or 0 for default width | |
631 * | |
632 * @exception DWTException <ul> | |
633 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
634 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
635 * </ul> | |
636 */ | |
637 public void setMinWidth(int width) { | |
638 setMinSize(width, minHeight); | |
639 } | |
640 | |
213 | 641 /** |
642 * Configure the receiver to automatically scroll to a focused child control | |
643 * to make it visible. | |
644 * | |
645 * If show is <code>false</code>, show a focused control is off. | |
646 * By default, show a focused control is off. | |
647 * | |
648 * @param show <code>true</code> to show a focused control. | |
649 * | |
650 * @exception DWTException <ul> | |
651 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
652 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
653 * </ul> | |
654 * | |
246 | 655 * @since 3.4 |
213 | 656 */ |
657 public void setShowFocusedControl(bool show) { | |
658 checkWidget(); | |
659 if (showFocusedControl is show) return; | |
660 Display display = getDisplay(); | |
661 display.removeFilter(DWT.FocusIn, filter); | |
662 showFocusedControl = show; | |
663 if (!showFocusedControl) return; | |
664 display.addFilter(DWT.FocusIn, filter); | |
665 Control control = display.getFocusControl(); | |
666 if (contains(control)) showControl(control); | |
667 } | |
668 | |
669 /** | |
670 * Scrolls the content of the receiver so that the control is visible. | |
671 * | |
672 * @param control the control to be shown | |
673 * | |
674 * @exception IllegalArgumentException <ul> | |
675 * <li>ERROR_NULL_ARGUMENT - if the control is null</li> | |
676 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> | |
677 * </ul> | |
678 * @exception DWTException <ul> | |
679 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
680 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
681 * </ul> | |
682 * | |
683 * @since 3.4 | |
684 */ | |
685 public void showControl(Control control) { | |
686 checkWidget (); | |
687 if (control is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
688 if (control.isDisposed ()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
689 if (!contains(control)) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
690 | |
691 Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds()); | |
692 Rectangle area = getClientArea(); | |
693 Point origin = getOrigin(); | |
694 if (itemRect.x < 0) origin.x = Math.max(0, origin.x + itemRect.x); | |
695 if (itemRect.y < 0) origin.y = Math.max(0, origin.y + itemRect.y); | |
696 if (area.width < itemRect.x + itemRect.width) origin.x = Math.max(0, origin.x + itemRect.x + itemRect.width - area.width); | |
697 if (area.height < itemRect.y + itemRect.height) origin.y = Math.max(0, origin.y + itemRect.y + itemRect.height - area.height); | |
698 setOrigin(origin); | |
699 } | |
700 | |
155 | 701 void vScroll() { |
702 if (content is null) return; | |
703 Point location = content.getLocation (); | |
704 ScrollBar vBar = getVerticalBar (); | |
705 int vSelection = vBar.getSelection (); | |
706 content.setLocation (location.x, -vSelection); | |
707 } | |
708 } |