Clean-up of scroll.c (2/4)

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

 



Hi,

More scroll.c cleanup

Changelog:
    scrollbar.c - add a separate handler routine for each message type

Use patch -p1 from within the top level wine directory to apply

License: X11

Andrew

--- wine-20030219/controls/scroll.c	2003-02-27 14:17:45.000000000 +0800
+++ wine/controls/scroll.c	2003-02-27 14:13:34.000000000 +0800
@@ -887,26 +887,32 @@
  *
  * Handle a keyboard event (only for SB_CTL scrollbars).
  */
-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] Varialbe 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);
 }
 
 
+
 /***********************************************************************
  *           SCROLL_HandleScrollEvent
  *
@@ -1194,64 +1200,97 @@
 }
 
 
+/*************************************************************************
+ *           SCROLL_SetScrollRange   (USER32.@)
+ *
+ *  Set scroll range returning old value of position if it has changed
+ *
+ * RETURNS
+ *
+ *  The old position if the position has changed
+ */
+static LRESULT SCROLL_SetScrollRange( 
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+INT minVal /* [in] New minimum value */,
+INT maxVal /* [in] New maximum value */,
+BOOL bRedraw /* [in] Should scrollbar be redrawn afterwards ? */)
+{
+    INT oldPos = GetScrollPos(hwnd, SB_CTL);
+
+    SetScrollRange(hwnd, SB_CTL, minVal, maxVal, bRedraw);
+    if (oldPos != GetScrollPos(hwnd, SB_CTL))
+        return oldPos;
+    else
+        return 0;
+}
+
+
 /***********************************************************************
- *           ScrollBarWndProc
+ *           SCROLL_CreateScrollBar
+ *
+ *  Create a scroll bar
  */
-static LRESULT WINAPI ScrollBarWndProc( HWND hwnd, UINT message, WPARAM 
wParam, LPARAM lParam )
+static void SCROLL_CreateScrollBar(
+HWND hwnd /* [in] Handle of window with scrollbar(s) */,
+LPCREATESTRUCTW lpCreate /* [in] The style and place of the scroll bar */)
 {
-    if (!IsWindow( hwnd )) return 0;
+    POINT pos, size;
+    LPSCROLLBAR_INFO info = SCROLL_GetScrollInfo(hwnd, SB_CTL);
+    if (!info) return;
 
-    switch(message)
+    TRACE("hwnd=%p lpCreate=%p\n", hwnd, lpCreate);
+
+    if (lpCreate->style & WS_DISABLED)
     {
-    case WM_CREATE:
-        {
-	    SCROLLBAR_INFO *infoPtr;
-            CREATESTRUCTW *lpCreat = (CREATESTRUCTW *)lParam;
+        info->flags = ESB_DISABLE_BOTH;
+        TRACE("Created WS_DISABLED scrollbar\n");
+    }
 
-	    if (!(infoPtr = SCROLL_GetScrollInfo( hwnd, SB_CTL ))) return -1;
-	    if (lpCreat->style & WS_DISABLED)
-	    {
-		TRACE("Created WS_DISABLED scrollbar\n");
-		infoPtr->flags = ESB_DISABLE_BOTH;
-	    }
+    /* copy the desired positions and size */
+    pos.x = lpCreate->x; pos.y = lpCreate->y;
+    size.x = lpCreate->cx; size.y = lpCreate->cy;
 
-	    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 );
-            }
-        }
-        if (!hUpArrow) SCROLL_LoadBitmaps();
-        TRACE("ScrollBar creation, hwnd=%p\n", hwnd );
-        return 0;
+    /* 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);
+}
+
+/***********************************************************************
+ *           ScrollBarWndProc
+ *
+ *  The routine for handling window events
+ *  
+ * RETURNS
+ *   Zero
+*/
+static LRESULT WINAPI ScrollBarWndProc(
+HWND hwnd /* [in] Handle of window whose scrollbar(s) will be affected */,
+UINT message /* [in] The windows message to be actioned */,
+WPARAM wParam /* [in] Variable input including enable state */,
+LPARAM lParam /* [in] Variable input including input point */)
+{    
+    TRACE("hwnd=%p message=%s wParam=%d lParam=%ld\n",
+        hwnd, SPY_GetMsgName(message, hwnd), wParam, lParam);
+    
+    /* handle the windows message */
+    if (IsWindow(hwnd)) switch (message)
+    {
+    case WM_CREATE:
+        SCROLL_CreateScrollBar(hwnd, (LPCREATESTRUCTW)lParam); break;
 
     case WM_ENABLE:
-        {
-	    SCROLLBAR_INFO *infoPtr;
-	    if ((infoPtr = SCROLL_GetScrollInfo( hwnd, SB_CTL )))
-	    {
-		infoPtr->flags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
-		SCROLL_RefreshScrollBar(hwnd, SB_CTL, TRUE, TRUE);
-	    }
-	}
-	return 0;
+        return EnableScrollBar(hwnd, SB_CTL,
+            wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH);
 
     case WM_LBUTTONDOWN:
         {
@@ -1272,17 +1311,11 @@
         }
         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 );
-        break;
+        SCROLL_HandleKbdEvent(hwnd, wParam, lParam); break;
 
     case WM_KEYUP:
-        ShowCaret(hwnd);
-        break;
+        ShowCaret(hwnd); break;
 
     case WM_SETFOCUS:
         {
@@ -1326,10 +1359,10 @@
         break;
 
     case WM_ERASEBKGND:
-         return 1;
+        return 1;
 
     case WM_GETDLGCODE:
-         return DLGC_WANTARROWS; /* Windows returns this value */
+        return DLGC_WANTARROWS; /* Windows returns this value */
 
     case WM_PAINT:
         {
@@ -1341,54 +1374,43 @@
                 SCROLL_DrawScrollBar( hwnd, hdc, SB_CTL, TRUE, TRUE );
             EndPaint( hwnd, &ps );
         }
-        break;
 
     case SBM_SETPOS16:
     case SBM_SETPOS:
-        return SetScrollPos( hwnd, SB_CTL, wParam, (BOOL)lParam );
+        return SetScrollPos(hwnd, SB_CTL, wParam, (BOOL)lParam);
 
     case SBM_GETPOS16:
     case SBM_GETPOS:
-        return GetScrollPos( hwnd, SB_CTL );
+        return GetScrollPos(hwnd, SB_CTL);
 
     case SBM_SETRANGE16:
-        SetScrollRange( hwnd, SB_CTL, LOWORD(lParam), HIWORD(lParam),
-                          wParam  /* FIXME: Is this correct? */ );
-        return 0;
-
+        return SetScrollRange(hwnd, SB_CTL, LOWORD(lParam),
+            HIWORD(lParam), wParam); 
+ 
     case SBM_SETRANGE:
-        {
-            INT oldPos = GetScrollPos( hwnd, SB_CTL );
-            SetScrollRange( hwnd, SB_CTL, wParam, lParam, FALSE );
-            if (oldPos != GetScrollPos( hwnd, SB_CTL )) return oldPos;
-        }
-        return 0;
+        return SCROLL_SetScrollRange(hwnd, wParam, lParam, FALSE);
 
     case SBM_GETRANGE16:
-        FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x,lp=%08lx)\n", 
wParam, lParam );
-        return 0;
+        FIXME("don't know how to handle SBM_GETRANGE16 (wp=%04x, 
lp=%08lx)\n",
+            wParam, lParam);
+        break;
 
     case SBM_GETRANGE:
-        GetScrollRange( hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam );
-        return 0;
+        GetScrollRange(hwnd, SB_CTL, (LPINT)wParam, (LPINT)lParam);
+        break;
 
     case SBM_ENABLE_ARROWS16:
     case SBM_ENABLE_ARROWS:
-        return EnableScrollBar( hwnd, SB_CTL, wParam );
+        return EnableScrollBar(hwnd, SB_CTL, wParam);
 
     case SBM_SETRANGEREDRAW:
-        {
-            INT oldPos = GetScrollPos( hwnd, SB_CTL );
-            SetScrollRange( hwnd, SB_CTL, wParam, lParam, TRUE );
-            if (oldPos != GetScrollPos( hwnd, SB_CTL )) return oldPos;
-        }
-        return 0;
+        return SCROLL_SetScrollRange(hwnd, wParam, lParam, TRUE);
 
     case SBM_SETSCROLLINFO:
-        return SetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam );
-
+        return SetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam, wParam);
+        
     case SBM_GETSCROLLINFO:
-        return GetScrollInfo( hwnd, SB_CTL, (SCROLLINFO *)lParam );
+        return GetScrollInfo(hwnd, SB_CTL, (SCROLLINFO *)lParam);
 
     case 0x00e5:
     case 0x00e7:
@@ -1399,14 +1421,14 @@
     case 0x00ee:
     case 0x00ef:
         ERR("unknown Win32 msg %04x wp=%08x lp=%08lx\n",
-		    message, wParam, lParam );
-        break;
+            message, wParam, lParam);
+        return 0; 
 
     default:
         if (message >= WM_USER)
             WARN("unknown msg %04x wp=%04x lp=%08lx\n",
-			 message, wParam, lParam );
-        return DefWindowProcW( hwnd, message, wParam, lParam );
+                message, wParam, lParam);
+        return DefWindowProcW(hwnd, message, wParam, lParam);
     }
     return 0;
 }



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

  Powered by Linux