Show
Ignore:
Timestamp:
05/17/08 11:34:28 (8 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Update to SWT 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/custom/ScrolledComposite.d

    r212 r213  
    1616import dwt.DWT; 
    1717import dwt.DWTException; 
     18import dwt.events.DisposeEvent; 
     19import dwt.events.DisposeListener; 
    1820import dwt.graphics.Point; 
    1921import dwt.graphics.Rectangle; 
    2022import dwt.widgets.Composite; 
    2123import dwt.widgets.Control; 
     24import dwt.widgets.Display; 
    2225import dwt.widgets.Event; 
    2326import dwt.widgets.Layout; 
    2427import dwt.widgets.Listener; 
    2528import dwt.widgets.ScrollBar; 
     29import dwt.widgets.Shell; 
    2630import dwt.custom.ScrolledCompositeLayout; 
    2731import dwt.dwthelper.utils; 
     
    114118    Control content; 
    115119    Listener contentListener; 
     120    Listener filter; 
    116121 
    117122    int minHeight = 0; 
     
    120125    bool expandVertical = false; 
    121126    bool alwaysShowScroll = false; 
     127    bool showFocusedControl = false; 
    122128 
    123129/** 
     
    177183        } 
    178184    }; 
     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    }); 
    179199} 
    180200 
     
    182202    int mask = DWT.H_SCROLL | DWT.V_SCROLL | DWT.BORDER | DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT; 
    183203    return style & mask; 
     204} 
     205 
     206bool 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; 
    184215} 
    185216 
     
    276307    //checkWidget(); 
    277308    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 */ 
     322public bool getShowFocusedControl() { 
     323    checkWidget(); 
     324    return showFocusedControl; 
    278325} 
    279326 
     
    587634} 
    588635 
     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 */ 
     652public 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 */ 
     680public 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 
    589696void vScroll() { 
    590697    if (content is null) return;