]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/combobox.cpp
supporting events also for root control (needed for event handling of mouse and paint...
[wxWidgets.git] / src / msw / combobox.cpp
index ebbd7b83e88e906b38210ae1135b12d208a9af82..26ef863e24eb805e34acc969e25dfde012b45854 100644 (file)
@@ -127,7 +127,7 @@ LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
 // ---------------------------------------------------------------------------
 
 // the pointer to standard radio button wnd proc
-static WXFARPROC gs_wndprocEdit = (WXFARPROC)NULL;
+static WNDPROC gs_wndprocEdit = (WNDPROC)NULL;
 
 // ============================================================================
 // implementation
@@ -213,11 +213,12 @@ LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
     return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
 }
 
-WXHBRUSH wxComboBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSED(nCtlColor),
-                               WXUINT WXUNUSED(message),
-                               WXWPARAM WXUNUSED(wParam),
-                               WXLPARAM WXUNUSED(lParam)
-    )
+WXHBRUSH wxComboBox::OnCtlColor(WXHDC pDC,
+                                WXHWND WXUNUSED(pWnd),
+                                WXUINT WXUNUSED(nCtlColor),
+                                WXUINT WXUNUSED(message),
+                                WXWPARAM WXUNUSED(wParam),
+                                WXLPARAM WXUNUSED(lParam))
 {
     HDC hdc = (HDC)pDC;
     wxColour colBack = GetBackgroundColour();
@@ -234,9 +235,30 @@ WXHBRUSH wxComboBox::OnCtlColor(WXHDC pDC, WXHWND WXUNUSED(pWnd), WXUINT WXUNUSE
 }
 
 // ----------------------------------------------------------------------------
-// wxComboBox
+// wxComboBox callbacks
 // ----------------------------------------------------------------------------
 
+WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
+{
+    // handle WM_CTLCOLOR messages from our EDIT control to be able to set its
+    // colour correctly (to be the same as our own one)
+    switch ( nMsg )
+    {
+        // we have to handle both: one for the normal case and the other for
+        // wxCB_READONLY
+        case WM_CTLCOLOREDIT:
+        case WM_CTLCOLORSTATIC:
+            WXWORD nCtlColor;
+            WXHDC hdc;
+            WXHWND hwnd;
+            UnpackCtlColor(wParam, lParam, &nCtlColor, &hdc, &hwnd);
+
+            return (WXLRESULT)OnCtlColor(hdc, hwnd, nCtlColor, nMsg, wParam, lParam);
+    }
+
+    return wxChoice::MSWWindowProc(nMsg, wParam, lParam);
+}
+
 bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
 {
     switch ( msg )
@@ -377,19 +399,19 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
                         validator, name) )
         return FALSE;
 
-    SetValue(value);
+    // we shouldn't call SetValue() for an empty string because this would
+    // (correctly) result in an assert with a read only combobox and is useless
+    // for the other ones anyhow
+    if ( !value.empty() )
+        SetValue(value);
 
     // a (not read only) combobox is, in fact, 2 controls: the combobox itself
     // and an edit control inside it and if we want to catch events from this
     // edit control, we must subclass it as well
     if ( !(style & wxCB_READONLY) )
     {
-        gs_wndprocEdit = (WXFARPROC)::SetWindowLong
-                                      (
-                                        (HWND)GetEditHWND(),
-                                        GWL_WNDPROC,
-                                        (LPARAM)wxComboEditWndProc
-                                      );
+        gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(),
+                                         wxComboEditWndProc);
     }
 
     // and finally, show the control
@@ -559,13 +581,7 @@ void wxComboBox::SetSelection(long from, long to)
       toChar = -1;
     }
 
-    if (
-#ifdef __WIN32__
-    SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar))
-#else // Win16
-    SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar)
-#endif
-        == CB_ERR )
+    if ( SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)0, (LPARAM)MAKELONG(fromChar, toChar)) == CB_ERR )
     {
         wxLogDebug(_T("CB_SETEDITSEL failed"));
     }