]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/combobox.cpp
compilation fix: wxcrt.h, not crt.h
[wxWidgets.git] / src / msw / combobox.cpp
index 18c6b0da34509f7c8ff9d8e8f93c2b9a92019ded..e6e3af1bd4a75652bd792d245d929a4b68debfcf 100644 (file)
 #include "wx/combobox.h"
 
 #ifndef WX_PRECOMP
+    #include "wx/msw/wrapcctl.h" // include <commctrl.h> "properly"
     #include "wx/settings.h"
     #include "wx/log.h"
     // for wxEVT_COMMAND_TEXT_ENTER
     #include "wx/textctrl.h"
     #include "wx/app.h"
+    #include "wx/brush.h"
 #endif
 
-#include "wx/brush.h"
 #include "wx/clipbrd.h"
 #include "wx/msw/private.h"
 
 #if wxUSE_TOOLTIPS
-    #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
-        #include <commctrl.h>
-    #endif
     #include "wx/tooltip.h"
 #endif // wxUSE_TOOLTIPS
 
@@ -89,7 +87,7 @@ wxBEGIN_FLAGS( wxComboBoxStyle )
 
 wxEND_FLAGS( wxComboBoxStyle )
 
-IMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxControl,"wx/combobox.h")
+IMPLEMENT_DYNAMIC_CLASS_XTI(wxComboBox, wxChoice,"wx/combobox.h")
 
 wxBEGIN_PROPERTIES_TABLE(wxComboBox)
     wxEVENT_PROPERTY( Select , wxEVT_COMMAND_COMBOBOX_SELECTED , wxCommandEvent )
@@ -110,7 +108,7 @@ wxCONSTRUCTOR_5( wxComboBox , wxWindow* , Parent , wxWindowID , Id , wxString ,
 
 #else
 
-IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxChoice)
 
 #endif
 
@@ -265,6 +263,9 @@ bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
             // when Enter is pressed
             if ( wParam == VK_RETURN )
             {
+                if (SendMessage(GetHwnd(), CB_GETDROPPEDSTATE, 0, 0))
+                    return false;
+
                 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
 
                 const int sel = GetSelection();
@@ -321,6 +322,12 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
             // CBN_EDITCHANGE below
             sel = GetSelection();
             value = GetStringSelection();
+
+            // this string is going to become the new combobox value soon but
+            // we need it to be done right now, otherwise the event handler
+            // could get a wrong value when it calls our GetValue()
+            ::SetWindowText(GetHwnd(), value);
+
             {
                 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, GetId());
                 event.SetInt(sel);
@@ -357,7 +364,31 @@ bool wxComboBox::MSWCommand(WXUINT param, WXWORD id)
 
     // skip wxChoice version as it would generate its own events for
     // CBN_SELENDOK
-    return wxControl::MSWCommand(param, id);
+    return true;
+}
+
+bool wxComboBox::MSWShouldPreProcessMessage(WXMSG *pMsg)
+{
+    // prevent command accelerators from stealing editing
+    // hotkeys when we have the focus
+    if (wxIsCtrlDown())
+    {
+        WPARAM vkey = pMsg->wParam;
+        
+        switch (vkey)
+        {
+            case 'C':
+            case 'V':
+            case 'X':
+            case VK_INSERT:
+            case VK_DELETE:
+            case VK_HOME:
+            case VK_END:
+                return false;
+        }
+    }
+    
+    return wxChoice::MSWShouldPreProcessMessage(pMsg);
 }
 
 WXHWND wxComboBox::GetEditHWND() const
@@ -411,8 +442,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
     // edit control, we must subclass it as well
     if ( !(style & wxCB_READONLY) )
     {
-        gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(),
-                                         wxComboEditWndProc);
+        gs_wndprocEdit = wxSetWindowProc((HWND)GetEditHWND(), wxComboEditWndProc);
     }
 
     // and finally, show the control
@@ -589,11 +619,13 @@ bool wxComboBox::IsEditable() const
     return !HasFlag(wxCB_READONLY);
 }
 
-void wxComboBox::SetEditable(bool WXUNUSED(editable))
+void wxComboBox::SetEditable(bool editable)
 {
-  // Can't implement in MSW?
-//  HWND hWnd = GetHwnd();
-//  SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
+    HWND hWnd = (HWND)GetEditHWND();
+    if ( !::SendMessage(hWnd, EM_SETREADONLY, !editable, 0) )
+    {
+        wxLogLastError(_T("SendMessage(EM_SETREADONLY)"));
+    }
 }
 
 void wxComboBox::SetInsertionPoint(long pos)
@@ -601,7 +633,6 @@ void wxComboBox::SetInsertionPoint(long pos)
     if ( GetWindowStyle() & wxCB_READONLY )
         return;
 
-#ifdef __WIN32__
     HWND hWnd = GetHwnd();
     ::SendMessage(hWnd, CB_SETEDITSEL, 0, MAKELPARAM(pos, pos));
     HWND hEditWnd = (HWND) GetEditHWND();
@@ -612,7 +643,6 @@ void wxComboBox::SetInsertionPoint(long pos)
         // Why is this necessary? (Copied from wxTextCtrl::SetInsertionPoint)
         SendMessage(hEditWnd, EM_REPLACESEL, 0, (LPARAM) wxEmptyString);
     }
-#endif // __WIN32__
 }
 
 void wxComboBox::SetInsertionPointEnd()