]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/window.cpp
added constructor for compliance with wxPython
[wxWidgets.git] / src / msw / window.cpp
index 3dd8c2240ee0cfb2db9222586af92720a6d5e691..271f8f0cb8f678137cd5a277e2a63ae8c5d11e2b 100644 (file)
@@ -37,6 +37,7 @@
     #include "wx/menu.h"
     #include "wx/dc.h"
     #include "wx/dcclient.h"
+    #include "wx/dcmemory.h"
     #include "wx/utils.h"
     #include "wx/app.h"
     #include "wx/layout.h"
 // global variables
 // ---------------------------------------------------------------------------
 
-// the last Windows message we got (MT-UNSAFE)
+// the last Windows message we got (FIXME-MT)
 extern MSG s_currentMsg;
 
 #if wxUSE_MENUS_NATIVE
@@ -131,6 +132,10 @@ wxMenu *wxCurrentPopupMenu = NULL;
 
 extern const wxChar *wxCanvasClassName;
 
+// true if we had already created the std colour map, used by
+// wxGetStdColourMap() and wxWindow::OnSysColourChanged()           (FIXME-MT)
+static bool gs_hasStdCmap = FALSE;
+
 // ---------------------------------------------------------------------------
 // private functions
 // ---------------------------------------------------------------------------
@@ -320,8 +325,6 @@ wxWindowMSW::~wxWindowMSW()
 {
     m_isBeingDeleted = TRUE;
 
-    MSWDetachWindowMenu();
-
 #ifndef __WXUNIVERSAL__
     // VS: make sure there's no wxFrame with last focus set to us:
     for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
@@ -450,23 +453,18 @@ void wxWindowMSW::SetFocus()
 
     if ( !::SetFocus(hWnd) )
     {
+#if defined(__WXDEBUG__) && !defined(__WXMICROWIN__)
         // was there really an error?
-#ifndef __WXMICROWIN__
         DWORD dwRes = ::GetLastError();
-#else
-
-        DWORD dwRes = 0;
-#endif
         if ( dwRes )
         {
-            wxLogApiError(_T("SetFocus"), dwRes);
+            HWND hwndFocus = ::GetFocus();
+            if ( hwndFocus != hWnd )
+            {
+                wxLogApiError(_T("SetFocus"), dwRes);
+            }
         }
-
-        // VZ: just why does this happen sometimes?? any idea?
-#if 0
-        HWND hwndFocus = ::GetFocus();
-        wxASSERT_MSG( hwndFocus == hWnd, _T("SetFocus() didn't work?") );
-#endif // 0
+#endif // Debug
     }
 }
 
@@ -548,7 +546,7 @@ wxString wxWindowMSW::GetTitle() const
     return wxGetWindowText(GetHWND());
 }
 
-void wxWindowMSW::CaptureMouse()
+void wxWindowMSW::DoCaptureMouse()
 {
     HWND hWnd = GetHwnd();
     if ( hWnd )
@@ -557,7 +555,7 @@ void wxWindowMSW::CaptureMouse()
     }
 }
 
-void wxWindowMSW::ReleaseMouse()
+void wxWindowMSW::DoReleaseMouse()
 {
     if ( !::ReleaseCapture() )
     {
@@ -2500,8 +2498,8 @@ long wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam
             break;
 #endif // !__WXMICROWIN__
 
-            // the return value for this message is ignored
         case WM_SYSCOLORCHANGE:
+            // the return value for this message is ignored
             processed = HandleSysColorChange();
             break;
 
@@ -2687,38 +2685,6 @@ void wxWindowMSW::MSWDestroyWindow()
 {
 }
 
-void wxWindowMSW::MSWDetachWindowMenu()
-{
-#ifndef __WXUNIVERSAL__
-    if ( m_hMenu )
-    {
-        wxChar buf[1024];
-        HMENU hMenu = (HMENU)m_hMenu;
-
-        int N = ::GetMenuItemCount(hMenu);
-        for ( int i = 0; i < N; i++ )
-        {
-            if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
-            {
-                wxLogLastError(wxT("GetMenuString"));
-
-                continue;
-            }
-
-            if ( wxStrcmp(buf, _("&Window")) == 0 )
-            {
-                if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) )
-                {
-                    wxLogLastError(wxT("RemoveMenu"));
-                }
-
-                break;
-            }
-        }
-    }
-#endif // __WXUNIVERSAL__
-}
-
 bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
                                            const wxSize& size,
                                            int& x, int& y,
@@ -2867,7 +2833,7 @@ bool wxWindowMSW::MSWCreate(const wxChar *wclass,
 
     SubclassWin(m_hWnd);
 
-    SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+    SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
 
     return TRUE;
 }
@@ -3389,6 +3355,14 @@ bool wxWindowMSW::HandleQueryNewPalette()
 // Responds to colour changes: passes event on to children.
 void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& event)
 {
+    // the top level window also reset the standard colour map as it might have
+    // changed (there is no need to do it for the non top level windows as we
+    // only have to do it once)
+    if ( IsTopLevel() )
+    {
+        // FIXME-MT
+        gs_hasStdCmap = FALSE;
+    }
     wxWindowList::Node *node = GetChildren().GetFirst();
     while ( node )
     {
@@ -3421,6 +3395,72 @@ void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& event)
     }
 }
 
+extern wxCOLORMAP *wxGetStdColourMap()
+{
+    static COLORREF s_stdColours[wxSTD_COL_MAX];
+    static wxCOLORMAP s_cmap[wxSTD_COL_MAX];
+
+    if ( !gs_hasStdCmap )
+    {
+        static bool s_coloursInit = FALSE;
+
+        if ( !s_coloursInit )
+        {
+            // When a bitmap is loaded, the RGB values can change (apparently
+            // because Windows adjusts them to care for the old programs always
+            // using 0xc0c0c0 while the transparent colour for the new Windows
+            // versions is different). But we do this adjustment ourselves so
+            // we want to avoid Windows' "help" and for this we need to have a
+            // reference bitmap which can tell us what the RGB values change
+            // to.
+            wxBitmap stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
+            if ( stdColourBitmap.Ok() )
+            {
+                // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
+                wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX,
+                              _T("forgot to update wxBITMAP_STD_COLOURS!") );
+
+                wxMemoryDC memDC;
+                memDC.SelectObject(stdColourBitmap);
+
+                wxColour colour;
+                for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ )
+                {
+                    memDC.GetPixel(i, 0, &colour);
+                    s_stdColours[i] = wxColourToRGB(colour);
+                }
+            }
+            else // wxBITMAP_STD_COLOURS couldn't be loaded
+            {
+                s_stdColours[0] = RGB(000,000,000);     // black
+                s_stdColours[1] = RGB(128,128,128);     // dark grey
+                s_stdColours[2] = RGB(192,192,192);     // light grey
+                s_stdColours[3] = RGB(255,255,255);     // white
+                //s_stdColours[4] = RGB(000,000,255);     // blue
+                //s_stdColours[5] = RGB(255,000,255);     // magenta
+            }
+
+            s_coloursInit = TRUE;
+        }
+
+        gs_hasStdCmap = TRUE;
+
+        // create the colour map
+#define INIT_CMAP_ENTRY(col) \
+            s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
+            s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
+
+        INIT_CMAP_ENTRY(BTNTEXT);
+        INIT_CMAP_ENTRY(BTNSHADOW);
+        INIT_CMAP_ENTRY(BTNFACE);
+        INIT_CMAP_ENTRY(BTNHIGHLIGHT);
+
+#undef INIT_CMAP_ENTRY
+    }
+
+    return s_cmap;
+}
+
 // ---------------------------------------------------------------------------
 // painting
 // ---------------------------------------------------------------------------