Changeset 213:36f5cb12e1a2 for dwt/custom/ScrolledComposite.d
- Timestamp:
- 05/17/08 11:34:28 (8 months ago)
- Files:
-
- dwt/custom/ScrolledComposite.d (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/custom/ScrolledComposite.d
r212 r213 16 16 import dwt.DWT; 17 17 import dwt.DWTException; 18 import dwt.events.DisposeEvent; 19 import dwt.events.DisposeListener; 18 20 import dwt.graphics.Point; 19 21 import dwt.graphics.Rectangle; 20 22 import dwt.widgets.Composite; 21 23 import dwt.widgets.Control; 24 import dwt.widgets.Display; 22 25 import dwt.widgets.Event; 23 26 import dwt.widgets.Layout; 24 27 import dwt.widgets.Listener; 25 28 import dwt.widgets.ScrollBar; 29 import dwt.widgets.Shell; 26 30 import dwt.custom.ScrolledCompositeLayout; 27 31 import dwt.dwthelper.utils; … … 114 118 Control content; 115 119 Listener contentListener; 120 Listener filter; 116 121 117 122 int minHeight = 0; … … 120 125 bool expandVertical = false; 121 126 bool alwaysShowScroll = false; 127 bool showFocusedControl = false; 122 128 123 129 /** … … 177 183 } 178 184 }; 185 186 filter = new class() Listener { 187 public void handleEvent(Event event) { 188 if ( auto control = cast(Control)event.widget ) { 189 if (contains(control)) showControl(control); 190 } 191 } 192 }; 193 194 addDisposeListener(new class() DisposeListener { 195 public void widgetDisposed(DisposeEvent e) { 196 getDisplay().removeFilter(DWT.FocusIn, filter); 197 } 198 }); 179 199 } 180 200 … … 182 202 int mask = DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; 183 203 return style & mask; 204 } 205 206 bool contains(Control control) { 207 if (control is null || control.isDisposed()) return false; 208 209 Composite parent = control.getParent(); 210 while (parent !is null && !( null !is cast(Shell)parent )) { 211 if (this is parent) return true; 212 parent = parent.getParent(); 213 } 214 return false; 184 215 } 185 216 … … 276 307 //checkWidget(); 277 308 return content; 309 } 310 311 /** 312 * Returns <code>true</code> if the receiver automatically scrolls to a focused child control 313 * to make it visible. Otherwise, returns <code>false</code>. 314 * 315 * @exception DWTException <ul> 316 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 317 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 318 * </ul> 319 * 320 * @since 3.4 321 */ 322 public bool getShowFocusedControl() { 323 checkWidget(); 324 return showFocusedControl; 278 325 } 279 326 … … 587 634 } 588 635 636 /** 637 * Configure the receiver to automatically scroll to a focused child control 638 * to make it visible. 639 * 640 * If show is <code>false</code>, show a focused control is off. 641 * By default, show a focused control is off. 642 * 643 * @param show <code>true</code> to show a focused control. 644 * 645 * @exception DWTException <ul> 646 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 647 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 648 * </ul> 649 * 650 * @since 3.4 651 */ 652 public void setShowFocusedControl(bool show) { 653 checkWidget(); 654 if (showFocusedControl is show) return; 655 Display display = getDisplay(); 656 display.removeFilter(DWT.FocusIn, filter); 657 showFocusedControl = show; 658 if (!showFocusedControl) return; 659 display.addFilter(DWT.FocusIn, filter); 660 Control control = display.getFocusControl(); 661 if (contains(control)) showControl(control); 662 } 663 664 /** 665 * Scrolls the content of the receiver so that the control is visible. 666 * 667 * @param control the control to be shown 668 * 669 * @exception IllegalArgumentException <ul> 670 * <li>ERROR_NULL_ARGUMENT - if the control is null</li> 671 * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> 672 * </ul> 673 * @exception DWTException <ul> 674 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> 675 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 676 * </ul> 677 * 678 * @since 3.4 679 */ 680 public void showControl(Control control) { 681 checkWidget (); 682 if (control is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 683 if (control.isDisposed ()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 684 if (!contains(control)) DWT.error(DWT.ERROR_INVALID_ARGUMENT); 685 686 Rectangle itemRect = getDisplay().map(control.getParent(), this, control.getBounds()); 687 Rectangle area = getClientArea(); 688 Point origin = getOrigin(); 689 if (itemRect.x < 0) origin.x = Math.max(0, origin.x + itemRect.x); 690 if (itemRect.y < 0) origin.y = Math.max(0, origin.y + itemRect.y); 691 if (area.width < itemRect.x + itemRect.width) origin.x = Math.max(0, origin.x + itemRect.x + itemRect.width - area.width); 692 if (area.height < itemRect.y + itemRect.height) origin.y = Math.max(0, origin.y + itemRect.y + itemRect.height - area.height); 693 setOrigin(origin); 694 } 695 589 696 void vScroll() { 590 697 if (content is null) return;
