- Cleanup DefWndDoButton function.
authorFilip Navara <filip.navara@gmail.com>
Mon, 21 Mar 2005 01:34:02 +0000 (01:34 +0000)
committerFilip Navara <filip.navara@gmail.com>
Mon, 21 Mar 2005 01:34:02 +0000 (01:34 +0000)
- Fix some loops where GetMessage was inadvertently used.

svn path=/trunk/; revision=14247

reactos/lib/user32/windows/defwnd.c
reactos/lib/user32/windows/nonclient.c

index 6d7ed4b..c04e43d 100644 (file)
@@ -317,7 +317,8 @@ DefWndStartSizeMove(HWND hWnd, WPARAM wParam, POINT *capturePoint)
     {
       while(!hittest)
        {
-         GetMessageW(&msg, NULL, 0, 0);
+         if (GetMessageW(&msg, NULL, 0, 0) <= 0)
+           break;
          switch(msg.message)
            {
            case WM_MOUSEMOVE:
@@ -572,7 +573,8 @@ DefWndDoSizeMove(HWND hwnd, WORD wParam)
     {
       int dx = 0, dy = 0;
 
-      GetMessageW(&msg, 0, 0, 0);
+      if (GetMessageW(&msg, 0, 0, 0) <= 0)
+        break;
       
       /* Exit on button-up, Return, or Esc */
       if ((msg.message == WM_LBUTTONUP) ||
index 822629b..02a3280 100644 (file)
@@ -882,79 +882,75 @@ DefWndNCHitTest(HWND hWnd, POINT Point)
 VOID
 DefWndDoButton(HWND hWnd, WPARAM wParam)
 {
-  MSG Msg;
-  BOOL InBtn, HasBtn = FALSE;
-  ULONG Btn, Style;
-  WPARAM SCMsg, CurBtn = wParam, OrigBtn = wParam;
-  HDC WindowDC = NULL;
+   MSG Msg;
+   HDC WindowDC;
+   BOOL Pressed = TRUE, OldState;
+   WPARAM SCMsg;
+   ULONG ButtonType, Style;
   
-  Style = GetWindowLongW(hWnd, GWL_STYLE);
-  switch(wParam)
-  {
-    case HTCLOSE:
-      Btn = DFCS_CAPTIONCLOSE;
-      SCMsg = SC_CLOSE;
-      HasBtn = (Style & WS_SYSMENU);
-      break;
-    case HTMINBUTTON:
-      Btn = DFCS_CAPTIONMIN;
-      SCMsg = ((Style & WS_MINIMIZE) ? SC_RESTORE : SC_MINIMIZE);
-      HasBtn = (Style & WS_MINIMIZEBOX);
-      break;
-    case HTMAXBUTTON:
-      Btn = DFCS_CAPTIONMAX;
-      SCMsg = ((Style & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE);
-      HasBtn = (Style & WS_MAXIMIZEBOX);
-      break;
-    default:
-      return;
-  }
-  
-  InBtn = HasBtn;
+   Style = GetWindowLongW(hWnd, GWL_STYLE);
+   switch (wParam)
+   {
+      case HTCLOSE:
+         if (!(Style & WS_SYSMENU))
+            return;
+         ButtonType = DFCS_CAPTIONCLOSE;
+         SCMsg = SC_CLOSE;
+         break;
+      case HTMINBUTTON:
+         if (!(Style & WS_MINIMIZEBOX))
+            return;
+         ButtonType = DFCS_CAPTIONMIN;
+         SCMsg = ((Style & WS_MINIMIZE) ? SC_RESTORE : SC_MINIMIZE);
+         break;
+      case HTMAXBUTTON:
+         if (!(Style & WS_MAXIMIZEBOX))
+            return;
+         ButtonType = DFCS_CAPTIONMAX;
+         SCMsg = ((Style & WS_MAXIMIZE) ? SC_RESTORE : SC_MAXIMIZE);
+         break;
+
+      default:
+         ASSERT(FALSE);
+         return;
+   }
   
-  SetCapture(hWnd);
+   /*
+    * FIXME: Not sure where to do this, but we must flush the pending
+    * window updates when someone clicks on the close button and at
+    * the same time the window is overlapped with another one. This
+    * looks like a good place for now...
+    */
+   UpdateWindow(hWnd);
+
+   WindowDC = GetWindowDC(hWnd);
+   UserDrawCaptionButtonWnd(hWnd, WindowDC, TRUE, ButtonType);
+
+   SetCapture(hWnd);
   
-  if(HasBtn)
-  {
-    WindowDC = GetWindowDC(hWnd);
-    UserDrawCaptionButtonWnd(hWnd, WindowDC, HasBtn , Btn);
-  }
-  
- for(;;)
-  {
-    GetMessageW(&Msg, 0, 0, 0);
-    switch(Msg.message)
-    {
-      case WM_LBUTTONUP:
-        if(InBtn)
-          goto done;
-        else
-        {
-          ReleaseCapture();
-          if (HasBtn)
-            ReleaseDC(hWnd, WindowDC);
-          return;
-        }
-      case WM_MOUSEMOVE:
-        if(HasBtn)
-        {
-          CurBtn = DefWndNCHitTest(hWnd, Msg.pt);
-          if(InBtn != (CurBtn == OrigBtn))
-          {
-            UserDrawCaptionButtonWnd( hWnd, WindowDC, (CurBtn == OrigBtn) , Btn);
-          }
-          InBtn = CurBtn == OrigBtn;
-        }
-        break;
-    }
-  }
+   for (;;)
+   {
+      if (GetMessageW(&Msg, 0, WM_MOUSEFIRST, WM_MOUSELAST) <= 0)
+         break;
+    
+      if (Msg.message == WM_LBUTTONUP)
+         break;
+
+      if (Msg.message != WM_MOUSEMOVE)
+         continue;
+
+      OldState = Pressed;
+      Pressed = (DefWndNCHitTest(hWnd, Msg.pt) == wParam);
+      if (Pressed != OldState)
+         UserDrawCaptionButtonWnd(hWnd, WindowDC, Pressed, ButtonType);
+   }
   
-done:
-  UserDrawCaptionButtonWnd( hWnd, WindowDC, FALSE , Btn);
-  ReleaseDC(hWnd, WindowDC);
-  ReleaseCapture();
-  SendMessageW(hWnd, WM_SYSCOMMAND, SCMsg, 0);
-  return;
+   if (Pressed)
+      UserDrawCaptionButtonWnd(hWnd, WindowDC, FALSE, ButtonType);
+   ReleaseCapture();
+   ReleaseDC(hWnd, WindowDC);
+   if (Pressed)
+      SendMessageW(hWnd, WM_SYSCOMMAND, SCMsg, 0);
 }