Changeset 36:ceb20ad6c0f8

Show
Ignore:
Timestamp:
01/28/08 18:52:45 (1 year ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Scrollable

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/widgets/Control.d

    r35 r36  
    1313module dwt.widgets.Control; 
    1414 
    15 /+ 
    16 import dwt.widgets.Widget; 
    17 import dwt.widgets.Composite; 
    18 import dwt.widgets.Event; 
    19 import dwt.widgets.Shell; 
    20 import dwt.graphics.Drawable; 
    21 import dwt.graphics.Rectangle; 
    22 import dwt.graphics.Point; 
    23 import dwt.graphics.GCData; 
    24 import dwt.internal.win32.OS; 
    25  
    26 class Control : Widget, Drawable { 
    27     public HANDLE handle; 
    28     this(); 
    29     this( Widget, int ); 
    30 public HDC internal_new_GC (GCData data) ; 
    31 public void internal_dispose_GC (HDC hDC, GCData data) ; 
    32 public Point computeSize (int wHint, int hHint) ; 
    33 public Point computeSize (int wHint, int hHint, bool changed) ; 
    34 public Composite getParent () ; 
    35 public Object getLayoutData () ; 
    36 public int getBorderWidth () ; 
    37 public void setLayoutData (Object layoutData) ; 
    38 public void setBounds (int x, int y, int width, int height) ; 
    39 void setBounds (int x, int y, int width, int height, int flags) ; 
    40 void setBounds (int x, int y, int width, int height, int flags, bool defer) ; 
    41 public void setBounds (Rectangle rect) ; 
    42 Shell getShell(); 
    43 bool checkHandle (HWND hwnd) ; 
    44 bool translateAccelerator (MSG* msg) ; 
    45 bool translateMnemonic (Event event, Control control) ; 
    46 bool translateMnemonic (MSG* msg) ; 
    47 bool translateTraversal (MSG* msg) ; 
    48 public void update () ; 
    49 void update (bool all) ; 
    50 void updateImages () ; 
    51 int windowProc (HWND hwnd, int msg, int wParam, int lParam) ; 
    52  
    53 } 
    54 +/ 
    5515import dwt.DWT; 
    5616import dwt.DWTException; 
     
    11575 
    11676    alias Widget.dragDetect dragDetect; 
     77    alias Widget.callWindowProc callWindowProc; 
    11778 
    11879    /** 
  • dwt/widgets/Display.d

    r35 r36  
    186186    //int windowProc_; 
    187187    int threadId; 
    188     TCHAR* windowClass, windowShadowClass; 
     188    TCHAR* windowClass_, windowShadowClass; 
    189189    static int WindowClassCount; 
    190190    static const char[] WindowName = "SWT_Window"; //$NON-NLS-1$ 
     
    20062006        auto hInstance = OS.GetModuleHandle (null); 
    20072007        embeddedHwnd = OS.CreateWindowEx (0, 
    2008             windowClass
     2008            windowClass_
    20092009            null, 
    20102010            OS.WS_OVERLAPPED, 
     
    25032503 
    25042504    /* Use the character encoding for the default locale */ 
    2505     windowClass = StrToTCHARz ( WindowName ~ to!(char[])(WindowClassCount)); 
     2505    windowClass_ = StrToTCHARz ( WindowName ~ to!(char[])(WindowClassCount)); 
    25062506    windowShadowClass = StrToTCHARz ( WindowShadowName ~ to!(char[])(WindowClassCount)); 
    25072507    WindowClassCount++; 
     
    25152515    lpWndClass.style = OS.CS_BYTEALIGNWINDOW | OS.CS_DBLCLKS; 
    25162516    lpWndClass.hCursor = OS.LoadCursor (null, cast(wchar*)OS.IDC_ARROW); 
    2517     int len = strlenz( windowClass ); 
     2517    int len = strlenz( windowClass_ ); 
    25182518    int byteCount = len * TCHAR.sizeof; 
    25192519    lpWndClass.lpszClassName = cast(wchar*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 
    2520     lpWndClass.lpszClassName[ 0 .. len ] = windowClass[ 0 .. len ]; 
     2520    lpWndClass.lpszClassName[ 0 .. len ] = windowClass_[ 0 .. len ]; 
    25212521    OS.RegisterClass (&lpWndClass); 
    25222522    OS.HeapFree (hHeap, 0, lpWndClass.lpszClassName); 
     
    25332533    /* Create the message only HWND */ 
    25342534    hwndMessage = OS.CreateWindowEx (0, 
    2535         windowClass
     2535        windowClass_
    25362536        null, 
    25372537        OS.WS_OVERLAPPED, 
     
    35063506    auto hHeap = OS.GetProcessHeap (); 
    35073507    auto hInstance = OS.GetModuleHandle (null); 
    3508     OS.UnregisterClass (windowClass, hInstance); 
     3508    OS.UnregisterClass (windowClass_, hInstance); 
    35093509 
    35103510    /* Unregister the DWT drop shadow window class */ 
    35113511    OS.UnregisterClass (windowShadowClass, hInstance); 
    3512     windowClass = windowShadowClass = null; 
     3512    windowClass_ = windowShadowClass = null; 
    35133513    //windowCallback.dispose (); 
    35143514    //windowCallback = null; 
     
    45314531} 
    45324532 
    4533 
     4533char[] windowClass(){ 
     4534    return TCHARzToStr( windowClass_ ); 
     4535
     4536 
     4537
  • dwt/widgets/ScrollBar.d

    r31 r36  
    1414class ScrollBar : Widget { 
    1515    this( Widget, int ); 
     16public void setMaximum (int value) ; 
     17public void setThumb (int value) ; 
     18public int getThumb () ; 
     19public bool getEnabled () ; 
     20public int getSelection () ; 
     21public int getIncrement () ; 
     22public int getPageIncrement () ; 
     23LRESULT wmScrollChild (int wParam, int lParam) ; 
    1624} 
    1725/++ 
  • dwt/widgets/Scrollable.d

    r31 r36  
    1111module dwt.widgets.Scrollable; 
    1212 
     13import dwt.widgets.Widget; 
     14import dwt.widgets.Event; 
    1315import dwt.widgets.Control; 
     16import dwt.widgets.ScrollBar; 
    1417import dwt.widgets.Composite; 
    15 import dwt.graphics.Rectangle; 
    16  
    17 class Scrollable : Control { 
    18     this(); 
    19     this( Composite, int ); 
    20 public Rectangle computeTrim (int x, int y, int width, int height) ; 
    21 public Rectangle getClientArea () ; 
    22 } 
    23  
    24 /++ 
    2518import dwt.DWT; 
    2619import dwt.DWTException; 
    2720import dwt.graphics.Rectangle; 
    28 import dwt.internal.win32.LRESULT; 
    2921import dwt.internal.win32.OS; 
    30 import dwt.internal.win32.RECT; 
    31 import dwt.internal.win32.SCROLLINFO; 
    32 import dwt.internal.win32.TCHAR; 
     22 
     23import dwt.dwthelper.utils; 
    3324 
    3425/** 
     
    4738 */ 
    4839 
    49 public abstract class Scrollable extends Control { 
     40public abstract class Scrollable : Control { 
    5041    ScrollBar horizontalBar, verticalBar; 
    5142 
     
    5344 * Prevents uninitialized instances from being created outside the package. 
    5445 */ 
    55 Scrollable () { 
     46this () { 
    5647} 
    5748 
     
    8576 * @see Widget#getStyle 
    8677 */ 
    87 public Scrollable (Composite parent, int style) { 
     78public this (Composite parent, int style) { 
    8879    super (parent, style); 
    8980} 
    9081 
    91 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 
    92     if (handle is 0) return 0
    93     return OS.DefWindowProc (hwnd, msg, wParam, lParam); 
     82override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { 
     83    if (handle is null) return LRESULT.ZERO
     84    return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam); 
    9485} 
    9586 
     
    123114public Rectangle computeTrim (int x, int y, int width, int height) { 
    124115    checkWidget (); 
    125     int scrolledHandle = scrolledHandle (); 
    126     RECT rect = new RECT ()
    127     OS.SetRect (rect, x, y, x + width, y + height); 
    128     int bits1 = OS.GetWindowLong (scrolledHandle, OS.GWL_STYLE); 
    129     int bits2 = OS.GetWindowLong (scrolledHandle, OS.GWL_EXSTYLE); 
    130     OS.AdjustWindowRectEx (rect, bits1, false, bits2); 
     116    auto scrolledHandle_ = scrolledHandle (); 
     117    RECT rect
     118    OS.SetRect (&rect, x, y, x + width, y + height); 
     119    int bits1 = OS.GetWindowLong (scrolledHandle_, OS.GWL_STYLE); 
     120    int bits2 = OS.GetWindowLong (scrolledHandle_, OS.GWL_EXSTYLE); 
     121    OS.AdjustWindowRectEx (&rect, bits1, false, bits2); 
    131122    if (horizontalBar !is null) rect.bottom += OS.GetSystemMetrics (OS.SM_CYHSCROLL); 
    132123    if (verticalBar !is null) rect.right += OS.GetSystemMetrics (OS.SM_CXVSCROLL); 
     
    167158    checkWidget (); 
    168159    forceResize (); 
    169     RECT rect = new RECT ()
    170     int scrolledHandle = scrolledHandle (); 
    171     OS.GetClientRect (scrolledHandle, rect); 
     160    RECT rect
     161    auto scrolledHandle_ = scrolledHandle (); 
     162    OS.GetClientRect (scrolledHandle_, &rect); 
    172163    int x = rect.left, y = rect.top; 
    173164    int width = rect.right - rect.left; 
    174165    int height = rect.bottom - rect.top; 
    175     if (scrolledHandle !is handle) { 
    176         OS.GetClientRect (handle, rect); 
    177         OS.MapWindowPoints(handle, scrolledHandle, rect, 2); 
     166    if (scrolledHandle_ !is handle) { 
     167        OS.GetClientRect (handle, &rect); 
     168        OS.MapWindowPoints(handle, scrolledHandle_, cast(POINT*)&rect, 2); 
    178169        x = -rect.left; 
    179170        y = -rect.top; 
     
    226217} 
    227218 
    228 int scrolledHandle () { 
     219HANDLE scrolledHandle () { 
    229220    return handle; 
    230221} 
     
    251242} 
    252243 
    253 TCHAR windowClass () { 
    254     return display.windowClass
    255 } 
    256  
    257 int windowProc () { 
     244override char[] windowClass () { 
     245    return display.windowClass()
     246} 
     247 
     248override int windowProc () { 
    258249    return display.windowProc; 
    259250} 
    260251 
    261 LRESULT WM_HSCROLL (int wParam, int lParam) { 
     252override LRESULT WM_HSCROLL (int wParam, int lParam) { 
    262253    LRESULT result = super.WM_HSCROLL (wParam, lParam); 
    263     if (result !is null) return result; 
     254    if (result !is 0) return result; 
    264255 
    265256    /* 
     
    270261    * both. 
    271262    */ 
    272     if (horizontalBar !is null && (lParam is 0 || lParam is handle)) { 
     263    if (horizontalBar !is null && (lParam is 0 || lParam is cast(int)handle)) { 
    273264        return wmScroll (horizontalBar, (state & CANVAS) !is 0, handle, OS.WM_HSCROLL, wParam, lParam); 
    274265    } 
     
    276267} 
    277268 
    278 LRESULT WM_MOUSEWHEEL (int wParam, int lParam) { 
     269override LRESULT WM_MOUSEWHEEL (int wParam, int lParam) { 
    279270    LRESULT result = super.WM_MOUSEWHEEL (wParam, lParam); 
    280     if (result !is null) return result; 
     271    if (result !is 0) return result; 
    281272 
    282273    /* 
     
    289280        int msg = (vertical) ? OS.WM_VSCROLL : (horizontal) ? OS.WM_HSCROLL : 0; 
    290281        if (msg is 0) return result; 
    291         int [] value = new int [1]
    292         OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, value, 0); 
    293         int delta = (short) (wParam >> 16); 
     282        int value
     283        OS.SystemParametersInfo (OS.SPI_GETWHEELSCROLLLINES, 0, &value, 0); 
     284        int delta = cast(short) (wParam >> 16); 
    294285        int code = 0, count = 0; 
    295         if (value [0] is OS.WHEEL_PAGESCROLL) { 
     286        if (value is OS.WHEEL_PAGESCROLL) { 
    296287            code = delta < 0 ? OS.SB_PAGEDOWN : OS.SB_PAGEUP; 
    297288            count = Math.abs (delta / OS.WHEEL_DELTA); 
     
    301292            if (delta < OS.WHEEL_DELTA) return result; 
    302293            if (msg is OS.WM_VSCROLL) { 
    303                 count = value [0] * delta / OS.WHEEL_DELTA; 
     294                count = value * delta / OS.WHEEL_DELTA; 
    304295            } else { 
    305296                count = delta / OS.WHEEL_DELTA; 
     
    325316    int vPosition = verticalBar is null ? 0 : verticalBar.getSelection (); 
    326317    int hPosition = horizontalBar is null ? 0 : horizontalBar.getSelection (); 
    327     int code = callWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam); 
     318    LRESULT code = callWindowProc (handle, OS.WM_MOUSEWHEEL, wParam, lParam); 
    328319    if (verticalBar !is null) { 
    329320        int position = verticalBar.getSelection (); 
     
    342333        } 
    343334    } 
    344     return new LRESULT (code)
    345 } 
    346  
    347 LRESULT WM_SIZE (int wParam, int lParam) { 
    348     int code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam); 
     335    return code
     336} 
     337 
     338override LRESULT WM_SIZE (int wParam, int lParam) { 
     339    LRESULT code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam); 
    349340    super.WM_SIZE (wParam, lParam); 
    350341    // widget may be disposed at this point 
    351342    if (code is 0) return LRESULT.ZERO; 
    352     return new LRESULT (code)
    353 } 
    354  
    355 LRESULT WM_VSCROLL (int wParam, int lParam) { 
     343    return code
     344} 
     345 
     346override LRESULT WM_VSCROLL (int wParam, int lParam) { 
    356347    LRESULT result = super.WM_VSCROLL (wParam, lParam); 
    357     if (result !is null) return result; 
     348    if (result !is 0) return result; 
    358349    /* 
    359350    * Bug on WinCE.  lParam should be NULL when the message is not sent 
     
    363354    * both. 
    364355    */ 
    365     if (verticalBar !is null && (lParam is 0 || lParam is handle)) { 
     356    if (verticalBar !is null && (lParam is 0 || lParam is cast(int)handle)) { 
    366357        return wmScroll (verticalBar, (state & CANVAS) !is 0, handle, OS.WM_VSCROLL, wParam, lParam); 
    367358    } 
     
    369360} 
    370361 
    371 LRESULT wmScroll (ScrollBar bar, bool update, int hwnd, int msg, int wParam, int lParam) { 
    372     LRESULT result = null
     362LRESULT wmScroll (ScrollBar bar, bool update, HWND hwnd, int msg, int wParam, int lParam) { 
     363    LRESULT result = LRESULT.NULL
    373364    if (update) { 
    374365        int type = msg is OS.WM_HSCROLL ? OS.SB_HORZ : OS.SB_VERT; 
    375         SCROLLINFO info = new SCROLLINFO ()
     366        SCROLLINFO info
    376367        info.cbSize = SCROLLINFO.sizeof; 
    377368        info.fMask = OS.SIF_TRACKPOS | OS.SIF_POS | OS.SIF_RANGE; 
    378         OS.GetScrollInfo (hwnd, type, info); 
     369        OS.GetScrollInfo (hwnd, type, &info); 
    379370        info.fMask = OS.SIF_POS; 
    380371        int code = wParam & 0xFFFF; 
    381372        switch (code) { 
    382             case OS.SB_ENDSCROLL:  return null
     373            case OS.SB_ENDSCROLL:  return LRESULT.NULL
    383374            case OS.SB_THUMBPOSITION: 
    384375            case OS.SB_THUMBTRACK: 
     
    412403                break; 
    413404        } 
    414         OS.SetScrollInfo (hwnd, type, info, true); 
     405        OS.SetScrollInfo (hwnd, type, &info, true); 
    415406    } else { 
    416         int code = callWindowProc (hwnd, msg, wParam, lParam); 
    417         result = code is 0 ? LRESULT.ZERO : new LRESULT (code)
     407        LRESULT code = callWindowProc (hwnd, msg, wParam, lParam); 
     408        result = code is 0 ? LRESULT.ZERO : code
    418409    } 
    419410    bar.wmScrollChild (wParam, lParam); 
     
    422413 
    423414} 
    424 ++/ 
     415