]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/combobox.cpp
document On{Open,Save}Document()
[wxWidgets.git] / src / msw / combobox.cpp
index 93c931c85fdc01282c2fe5dea0943b2d25a59d89..9d8e4a542d7a1740440b2989faf24b0ade5705a7 100644 (file)
@@ -205,13 +205,6 @@ LRESULT APIENTRY _EXPORT wxComboEditWndProc(HWND hWnd,
                 }
             }
             break;
-
-        case WM_CUT:
-        case WM_COPY:
-        case WM_PASTE:
-            if( win->HandleClipboardEvent( message ) )
-                return 0;
-            break;
     }
 
     return ::CallWindowProc(CASTWNDPROC gs_wndprocEdit, hWnd, message, wParam, lParam);
@@ -235,6 +228,9 @@ WXLRESULT wxComboBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
             {
                 // combobox selection sometimes spontaneously changes when its
                 // size changes, restore it to the old value if necessary
+                if ( !GetEditHWNDIfAvailable() )
+                    break;
+
                 long fromOld, toOld;
                 GetSelection(&fromOld, &toOld);
                 WXLRESULT result = wxChoice::MSWWindowProc(nMsg, wParam, lParam);
@@ -299,6 +295,11 @@ bool wxComboBox::MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
 
         case WM_KILLFOCUS:
             return HandleKillFocus((WXHWND)wParam);
+
+        case WM_CUT:
+        case WM_COPY:
+        case WM_PASTE:
+            return HandleClipboardEvent(msg);
     }
 
     return false;
@@ -391,22 +392,28 @@ bool wxComboBox::MSWShouldPreProcessMessage(WXMSG *pMsg)
     return wxChoice::MSWShouldPreProcessMessage(pMsg);
 }
 
+WXHWND wxComboBox::GetEditHWNDIfAvailable() const
+{
+    // notice that a slightly safer alternative could be to use FindWindowEx()
+    // but it's not available under WinCE so just take the first child for now
+    // to keep one version of the code for all platforms and fix it later if
+    // problems are discovered
+
+    // we assume that the only child of the combobox is the edit window
+    return (WXHWND)::GetWindow(GetHwnd(), GW_CHILD);
+}
+
 WXHWND wxComboBox::GetEditHWND() const
 {
     // this function should not be called for wxCB_READONLY controls, it is
-    // the callers responsability to check this
+    // the callers responsibility to check this
     wxASSERT_MSG( !HasFlag(wxCB_READONLY),
                   _T("read-only combobox doesn't have any edit control") );
 
-    POINT pt;
-    pt.x = pt.y = 4;
-    HWND hwndEdit = ::ChildWindowFromPoint(GetHwnd(), pt);
-    if ( !hwndEdit || hwndEdit == GetHwnd() )
-    {
-        wxFAIL_MSG(_T("combobox without edit control?"));
-    }
+    WXHWND hWndEdit = GetEditHWNDIfAvailable();
+    wxASSERT_MSG( hWndEdit, _T("combobox without edit control?") );
 
-    return (WXHWND)hwndEdit;
+    return hWndEdit;
 }
 
 // ----------------------------------------------------------------------------
@@ -502,6 +509,12 @@ WXDWORD wxComboBox::MSWGetStyle(long style, WXDWORD *exstyle) const
 // wxComboBox text control-like methods
 // ----------------------------------------------------------------------------
 
+wxString wxComboBox::GetValue() const
+{
+    return HasFlag(wxCB_READONLY) ? GetStringSelection()
+                                  : wxTextEntry::GetValue();
+}
+
 void wxComboBox::SetValue(const wxString& value)
 {
     if ( HasFlag(wxCB_READONLY) )
@@ -517,6 +530,21 @@ void wxComboBox::Clear()
         wxTextEntry::Clear();
 }
 
+void wxComboBox::GetSelection(long *from, long *to) const
+{
+    if ( !HasFlag(wxCB_READONLY) )
+    {
+        wxTextEntry::GetSelection(from, to);
+    }
+    else // text selection doesn't make sense for read only comboboxes
+    {
+        if ( from )
+            *from = -1;
+        if ( to )
+            *to = -1;
+    }
+}
+
 bool wxComboBox::IsEditable() const
 {
     return !HasFlag(wxCB_READONLY) && wxTextEntry::IsEditable();
@@ -553,15 +581,12 @@ void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event))
 
 void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event))
 {
-    long from, to;
-    GetSelection(& from, & to);
-    if (from != -1 && to != -1)
-        Remove(from, to);
+    RemoveSelection();
 }
 
 void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event))
 {
-    SetSelection(-1, -1);
+    SelectAll();
 }
 
 void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event)
@@ -581,12 +606,12 @@ void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event)
 
 void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event)
 {
-    event.Enable( CanUndo() );
+    event.Enable( IsEditable() && CanUndo() );
 }
 
 void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event)
 {
-    event.Enable( CanRedo() );
+    event.Enable( IsEditable() && CanRedo() );
 }
 
 void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
@@ -596,7 +621,7 @@ void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event)
 
 void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
 {
-    event.Enable(IsEditable() && GetLastPosition() > 0);
+    event.Enable(IsEditable() && !wxTextEntry::IsEmpty());
 }
 
 #if wxUSE_TOOLTIPS