]> git.saurik.com Git - wxWidgets.git/commitdiff
Forward WM_{CUT,COPY,PASTE} from edit control to wxComboBox in wxMSW too.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 1 Jul 2012 21:10:08 +0000 (21:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 1 Jul 2012 21:10:08 +0000 (21:10 +0000)
This allows us to receive wxClipboardTextEvents from wxComboBox as well.

Update the documentation to mention this.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71922 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/event.h
src/msw/combobox.cpp

index ecd376d200d6aa8f007c22c3d4c865473ff0a718..766e074b2243c2dae2ebbd050aac599f8f4e330b 100644 (file)
@@ -2159,8 +2159,8 @@ public:
     text was copied or cut.
 
     @note
-    These events are currently only generated by wxTextCtrl under GTK+.
-    They are generated by all controls under Windows.
+    These events are currently only generated by wxTextCtrl in wxGTK and wxOSX
+    but are also generated by wxComboBox without wxCB_READONLY style in wxMSW.
 
     @beginEventTable{wxClipboardTextEvent}
     @event{EVT_TEXT_COPY(id, func)}
index 03bda9b166d8e421bae13579c3c37ca323fbeb90..d9b39e7d30a6b68b0a682402d41fd806a917856e 100644 (file)
@@ -93,6 +93,36 @@ static WNDPROC gs_wndprocEdit = (WNDPROC)NULL;
 // implementation
 // ============================================================================
 
+namespace
+{
+
+// Check if the given message should be forwarded from the edit control which
+// is part of the combobox to wxComboBox itself. All messages generating the
+// events that the code using wxComboBox could be interested in must be
+// forwarded.
+bool ShouldForwardFromEditToCombo(UINT message)
+{
+    switch ( message )
+    {
+        case WM_KEYUP:
+        case WM_KEYDOWN:
+        case WM_CHAR:
+        case WM_SYSCHAR:
+        case WM_SYSKEYDOWN:
+        case WM_SYSKEYUP:
+        case WM_SETFOCUS:
+        case WM_KILLFOCUS:
+        case WM_CUT:
+        case WM_COPY:
+        case WM_PASTE:
+            return true;
+    }
+
+    return false;
+}
+
+} // anonymous namespace
+
 // ----------------------------------------------------------------------------
 // wnd proc for subclassed edit control
 // ----------------------------------------------------------------------------
@@ -105,49 +135,34 @@ LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
     HWND hwndCombo = ::GetParent(hWnd);
     wxWindow *win = wxFindWinFromHandle((WXHWND)hwndCombo);
 
-    switch ( message )
+    if ( ShouldForwardFromEditToCombo(message) )
     {
-        // forward some messages to the combobox to generate the appropriate
-        // wxEvents from them
-        case WM_KEYUP:
-        case WM_KEYDOWN:
-        case WM_CHAR:
-        case WM_SYSCHAR:
-        case WM_SYSKEYDOWN:
-        case WM_SYSKEYUP:
-        case WM_SETFOCUS:
-        case WM_KILLFOCUS:
+        wxComboBox *combo = wxDynamicCast(win, wxComboBox);
+        if ( !combo )
+        {
+            // we can get WM_KILLFOCUS while our parent is already half
+            // destroyed and hence doesn't look like a combobx any
+            // longer, check for it to avoid bogus assert failures
+            if ( !win->IsBeingDeleted() )
             {
-                wxComboBox *combo = wxDynamicCast(win, wxComboBox);
-                if ( !combo )
-                {
-                    // we can get WM_KILLFOCUS while our parent is already half
-                    // destroyed and hence doesn't look like a combobx any
-                    // longer, check for it to avoid bogus assert failures
-                    if ( !win->IsBeingDeleted() )
-                    {
-                        wxFAIL_MSG( wxT("should have combo as parent") );
-                    }
-                }
-                else if ( combo->MSWProcessEditMsg(message, wParam, lParam) )
-                {
-                    // handled by parent
-                    return 0;
-                }
+                wxFAIL_MSG( wxT("should have combo as parent") );
             }
-            break;
-
-        case WM_GETDLGCODE:
-            {
-                wxCHECK_MSG( win, 0, wxT("should have a parent") );
+        }
+        else if ( combo->MSWProcessEditMsg(message, wParam, lParam) )
+        {
+            // handled by parent
+            return 0;
+        }
+    }
+    else if ( message == WM_GETDLGCODE )
+    {
+        wxCHECK_MSG( win, 0, wxT("should have a parent") );
 
-                if ( win->GetWindowStyle() & wxTE_PROCESS_ENTER )
-                {
-                    // need to return a custom dlg code or we'll never get it
-                    return DLGC_WANTMESSAGE;
-                }
-            }
-            break;
+        if ( win->GetWindowStyle() & wxTE_PROCESS_ENTER )
+        {
+            // need to return a custom dlg code or we'll never get it
+            return DLGC_WANTMESSAGE;
+        }
     }
 
     return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
@@ -235,21 +250,16 @@ bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
                     return true;
                 }
             }
-            // fall through
+            // fall through, WM_CHAR is one of the message we should forward.
 
-        case WM_SYSCHAR:
-        case WM_SYSKEYDOWN:
-        case WM_KEYDOWN:
-        case WM_SYSKEYUP:
-        case WM_KEYUP:
-        case WM_SETFOCUS:
-        case WM_KILLFOCUS:
-        case WM_CUT:
-        case WM_COPY:
-        case WM_PASTE:
-            // For the messages above the result is not used.
-            WXLRESULT result;
-            return MSWHandleMessage(&result, msg, wParam, lParam);
+        default:
+            if ( ShouldForwardFromEditToCombo(msg) )
+            {
+                // For all the messages forward from the edit control the
+                // result is not used.
+                WXLRESULT result;
+                return MSWHandleMessage(&result, msg, wParam, lParam);
+            }
     }
 
     return false;