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