More cleanup in scroll.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

This patch simplifies and moves code from the ScrollBarWndProc into the
appropriate helpers.

On a related note, shouldn't the SetScroll* functions send a message for the SB_CTL case?

Changelog:
    Move keyboard event processing from WndProc code into the existing helper
    Create a helper function for the create event and clean up code

License: X11

Andrew

--- controls/scroll.c	2003-03-06 15:02:12.000000000 +0800
+++ controls/scroll.c	2003-03-06 16:35:11.000000000 +0800
@@ -896,25 +896,32 @@
 /***********************************************************************
  *           SCROLL_HandleKbdEvent
  *
- * Handle a keyboard event (only for SB_CTL scrollbars).
+ * Handle a keyboard event (only for SB_CTL scrollbars with focus).
  */
-static void SCROLL_HandleKbdEvent( HWND hwnd, WPARAM wParam )
+static void SCROLL_HandleKbdEvent(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+WPARAM wParam /* [in] Variable input including enable state */,
+LPARAM lParam /* [in] Variable input including input point */)
 {
-    WPARAM msg;
+    TRACE("hwnd=%p wParam=%d lParam=%ld\n", hwnd, wParam, lParam);
+
+    /* hide caret on first KEYDOWN to prevent flicker */
+    if ((lParam & PFD_DOUBLEBUFFER_DONTCARE) == 0)
+        HideCaret(hwnd);
 
     switch(wParam)
     {
-    case VK_PRIOR: msg = SB_PAGEUP; break;
-    case VK_NEXT:  msg = SB_PAGEDOWN; break;
-    case VK_HOME:  msg = SB_TOP; break;
-    case VK_END:   msg = SB_BOTTOM; break;
-    case VK_UP:    msg = SB_LINEUP; break;
-    case VK_DOWN:  msg = SB_LINEDOWN; break;
+    case VK_PRIOR: wParam = SB_PAGEUP; break;
+    case VK_NEXT:  wParam = SB_PAGEDOWN; break;
+    case VK_HOME:  wParam = SB_TOP; break;
+    case VK_END:   wParam = SB_BOTTOM; break;
+    case VK_UP:    wParam = SB_LINEUP; break;
+    case VK_DOWN:  wParam = SB_LINEDOWN; break;
     default: return;
     }
-    SendMessageW( GetParent(hwnd),
-                  (GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ? WM_VSCROLL : WM_HSCROLL,
-                  msg, (LPARAM)hwnd );
+    SendMessageW(GetParent(hwnd),
+        ((GetWindowLongA( hwnd, GWL_STYLE ) & SBS_VERT) ?
+            WM_VSCROLL : WM_HSCROLL), wParam, (LPARAM)hwnd);
 }
 
 
@@ -1205,6 +1212,47 @@
 }
 
 
+/***********************************************************************
+ *           SCROLL_CreateScrollBar
+ *
+ *  Create a scroll bar
+ */
+static void SCROLL_CreateScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+LPCREATESTRUCTW lpCreate /* [in] The style and place of the scroll bar */)
+{
+    POINT pos, size;
+    LPSCROLLBAR_INFO info = SCROLL_GetScrollBarInfo(hwnd, SB_CTL);
+    if (!info) return;
+
+    TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
+
+    if (lpCreate->style & WS_DISABLED)
+    {
+        info->flags = ESB_DISABLE_BOTH;
+        TRACE("Created WS_DISABLED scrollbar\n");
+    }
+
+    /* copy the desired positions and size */
+    pos.x = lpCreate->x; pos.y = lpCreate->y;
+    size.x = lpCreate->cx; size.y = lpCreate->cy;
+
+    /* move position based on style */
+    if (lpCreate->style & SBS_RIGHTALIGN)
+        pos.x += size.x - GetSystemMetrics(SM_CXVSCROLL) - 1;
+    else if (lpCreate->style & SBS_BOTTOMALIGN)
+        pos.y += size.y - GetSystemMetrics(SM_CYHSCROLL) - 1;
+
+    /* change size based on style */
+    if (lpCreate->style & SBS_VERT)
+        size.x = GetSystemMetrics(SM_CXVSCROLL) + 1;
+    else
+        size.y = GetSystemMetrics(SM_CYHSCROLL) + 1;
+
+    MoveWindow(hwnd, pos.x, pos.y, size.x, size.y, FALSE);
+}
+
+
 /*************************************************************************
  *           SCROLL_GetScrollInfo
  *
@@ -1284,43 +1332,9 @@
     switch(message)
     {
     case WM_CREATE:
-        {
-	    SCROLLBAR_INFO *infoPtr;
-            CREATESTRUCTW *lpCreat = (CREATESTRUCTW *)lParam;
-
-	    if (!(infoPtr = SCROLL_GetScrollBarInfo( hwnd, SB_CTL ))) return -1;
-	    if (lpCreat->style & WS_DISABLED)
-	    {
-		TRACE("Created WS_DISABLED scrollbar\n");
-		infoPtr->flags = ESB_DISABLE_BOTH;
-	    }
-
-	    if (lpCreat->style & SBS_VERT)
-            {
-                if (lpCreat->style & SBS_LEFTALIGN)
-                    MoveWindow( hwnd, lpCreat->x, lpCreat->y,
-                                  GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
-                else if (lpCreat->style & SBS_RIGHTALIGN)
-                    MoveWindow( hwnd,
-                                  lpCreat->x+lpCreat->cx-GetSystemMetrics(SM_CXVSCROLL)-1,
-                                  lpCreat->y,
-                                  GetSystemMetrics(SM_CXVSCROLL)+1, lpCreat->cy, FALSE );
-            }
-            else  /* SBS_HORZ */
-            {
-                if (lpCreat->style & SBS_TOPALIGN)
-                    MoveWindow( hwnd, lpCreat->x, lpCreat->y,
-                                  lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
-                else if (lpCreat->style & SBS_BOTTOMALIGN)
-                    MoveWindow( hwnd,
-                                  lpCreat->x,
-                                  lpCreat->y+lpCreat->cy-GetSystemMetrics(SM_CYHSCROLL)-1,
-                                  lpCreat->cx, GetSystemMetrics(SM_CYHSCROLL)+1, FALSE );
-            }
-        }
+        SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam);
         if (!hUpArrow) SCROLL_LoadBitmaps();
-        TRACE("ScrollBar creation, hwnd=%p\n", hwnd );
-        return 0;
+        break;
 
     case WM_ENABLE:
         {
@@ -1352,12 +1366,8 @@
         }
         break;
 
-    /* if key event is received, the scrollbar has the focus */
     case WM_KEYDOWN:
-        /* hide caret on first KEYDOWN to prevent flicker */
-        if ((lParam & 0x40000000)==0)
-            HideCaret(hwnd);
-        SCROLL_HandleKbdEvent( hwnd, wParam );
+        SCROLL_HandleKbdEvent(hwnd, wParam, lParam);
         break;
 
     case WM_KEYUP:




[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux