]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
CYGWIN socket compilation fixes
[wxWidgets.git] / src / msw / window.cpp
index 43d21ba44d0f071501891a7c2456b4d803ccedec..136e06c3c505d2e3cbec4b7a3899a58f27851520 100644 (file)
@@ -2319,30 +2319,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
             break;
 
         case WM_PRINTCLIENT:
-            // we receive this message when DrawThemeParentBackground() is
-            // called from def window proc of several controls under XP and we
-            // must draw properly themed background here
-            //
-            // note that naively I'd expect filling the client rect with the
-            // brush returned by MSWGetBgBrush() work -- but for some reason it
-            // doesn't and we have to call parents MSWPrintChild() which is
-            // supposed to call DrawThemeBackground() with appropriate params
-            //
-            // also note that in this case lParam == PRF_CLIENT but we're
-            // clearly expected to paint the background and nothing else!
-            {
-                for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
-                {
-                    if ( win->MSWPrintChild((WXHDC)wParam, (wxWindow *)this) )
-                    {
-                        processed = true;
-                        break;
-                    }
-
-                    if ( win->IsTopLevel() || win->InheritsBackgroundColour() )
-                        break;
-                }
-            }
+            processed = HandlePrintClient((WXHDC)wParam);
             break;
 
         case WM_PAINT:
@@ -3656,7 +3633,15 @@ wxWindowMSW::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
     {
         wxMenuItem *pMenuItem = (wxMenuItem *)(pMeasureStruct->itemData);
 
-        wxCHECK_MSG( pMenuItem && pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)),
+        // according to Carsten Fuchs the pointer may be NULL under XP if an
+        // MDI child frame is initially maximized, see this for more info:
+        // http://article.gmane.org/gmane.comp.lib.wxwidgets.general/27745
+        //
+        // so silently ignore it instead of asserting
+        if ( !pMenuItem )
+            return false;
+
+        wxCHECK_MSG( wxDynamicCast(pMenuItem, wxMenuItem),
                         false, _T("MSWOnMeasureItem: bad wxMenuItem pointer") );
 
         size_t w, h;
@@ -3707,13 +3692,16 @@ bool wxWindowMSW::HandleDisplayChange()
 
 #ifndef __WXMICROWIN__
 
-bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC pDC, WXHWND pWnd)
+bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush, WXHDC hDC, WXHWND hWnd)
 {
-#if wxUSE_CONTROLS
-    wxControl *item = wxDynamicCast(FindItemByHWND(pWnd, true), wxControl);
+#if !wxUSE_CONTROLS || defined(__WXUNIVERSAL__)
+    wxUnusedVar(hDC);
+    wxUnusedVar(hWnd);
+#else
+    wxControl *item = wxDynamicCast(FindItemByHWND(hWnd, true), wxControl);
 
     if ( item )
-        *brush = item->MSWControlColor(pDC);
+        *brush = item->MSWControlColor(hDC, hWnd);
     else
 #endif // wxUSE_CONTROLS
         *brush = NULL;
@@ -4003,7 +3991,7 @@ bool wxWindowMSW::DoEraseBackground(WXHDC hDC)
 }
 
 WXHBRUSH
-wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), wxWindow *child)
+wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), WXHWND hWnd)
 {
     if ( m_hasBgCol )
     {
@@ -4015,10 +4003,11 @@ wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), wxWindow *child)
         //     children because it would look wrong if a child of non
         //     transparent child would show our bg colour when the child itself
         //     does not
-        if ( child == this ||
+        wxWindow *win = wxFindWinFromHandle(hWnd);
+        if ( win == this ||
                 m_inheritBgCol ||
-                    (child->HasTransparentBackground() &&
-                        child->GetParent() == this) )
+                    (win && win->HasTransparentBackground() &&
+                        win->GetParent() == this) )
         {
             // draw children with the same colour as the parent
             wxBrush *
@@ -4031,14 +4020,14 @@ wxWindowMSW::MSWGetBgBrushForChild(WXHDC WXUNUSED(hDC), wxWindow *child)
     return 0;
 }
 
-WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, wxWindow *winToPaint)
+WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, WXHWND hWndToPaint)
 {
-    if ( !winToPaint )
-        winToPaint = this;
+    if ( !hWndToPaint )
+        hWndToPaint = GetHWND();
 
     for ( wxWindowMSW *win = this; win; win = win->GetParent() )
     {
-        WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, winToPaint);
+        WXHBRUSH hBrush = win->MSWGetBgBrushForChild(hDC, hWndToPaint);
         if ( hBrush )
             return hBrush;
 
@@ -4050,6 +4039,31 @@ WXHBRUSH wxWindowMSW::MSWGetBgBrush(WXHDC hDC, wxWindow *winToPaint)
     return 0;
 }
 
+bool wxWindowMSW::HandlePrintClient(WXHDC hDC)
+{
+    // we receive this message when DrawThemeParentBackground() is
+    // called from def window proc of several controls under XP and we
+    // must draw properly themed background here
+    //
+    // note that naively I'd expect filling the client rect with the
+    // brush returned by MSWGetBgBrush() work -- but for some reason it
+    // doesn't and we have to call parents MSWPrintChild() which is
+    // supposed to call DrawThemeBackground() with appropriate params
+    //
+    // also note that in this case lParam == PRF_CLIENT but we're
+    // clearly expected to paint the background and nothing else!
+    for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
+    {
+        if ( win->MSWPrintChild(hDC, (wxWindow *)this) )
+            return true;
+
+        if ( win->IsTopLevel() || win->InheritsBackgroundColour() )
+            break;
+    }
+
+    return false;
+}
+
 // ---------------------------------------------------------------------------
 // moving and resizing
 // ---------------------------------------------------------------------------