]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxComboBox::Popup() and Dismiss() to manually show or hide its popup.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Jan 2010 01:00:45 +0000 (01:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 24 Jan 2010 01:00:45 +0000 (01:00 +0000)
Add implementations for wxMSW and wxGTK.

Closes #11506.

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

docs/changes.txt
include/wx/combobox.h
include/wx/gtk/combobox.h
include/wx/msw/combobox.h
interface/wx/combobox.h
samples/widgets/combobox.cpp
src/gtk/combobox.cpp
src/msw/combobox.cpp

index e3c5b9a2b1b7afe52ceefb9c5db889b87508ebfe..5803345543c68dbe520005315dc9053bcde6f8ff 100644 (file)
@@ -491,6 +491,7 @@ All (GUI):
 - Added wxBORDER_THEME to XRC.
 - wxGraphicsContext is now enabled by default if supported by the platform.
 - Fix building with using system libpng 1.4 (Volker Grabsch).
 - Added wxBORDER_THEME to XRC.
 - wxGraphicsContext is now enabled by default if supported by the platform.
 - Fix building with using system libpng 1.4 (Volker Grabsch).
+- Add wxComboBox::Popup() and Dismiss() methods (Igor Korot).
 
 GTK:
 
 
 GTK:
 
index 7727d64781bc6d37d96d854f558a462e7a16a065..a0245f9e23f506d2a6e1e85292cb27ce088734a3 100644 (file)
@@ -47,6 +47,9 @@ public:
     virtual int GetSelection() const = 0;
     virtual void GetSelection(long *from, long *to) const = 0;
 
     virtual int GetSelection() const = 0;
     virtual void GetSelection(long *from, long *to) const = 0;
 
+    virtual void Popup() { wxFAIL_MSG( wxT("Not implemented") ); };
+    virtual void Dismiss() { wxFAIL_MSG( wxT("Not implemented") ); };
+
     // may return value different from GetSelection() when the combobox
     // dropdown is shown and the user selected, but not yet accepted, a value
     // different from the old one in it
     // may return value different from GetSelection() when the combobox
     // dropdown is shown and the user selected, but not yet accepted, a value
     // different from the old one in it
index 39543f8baad99b0a129b9d9976054080d79ee17a..7901e540f50a66c86bbabafda7307f8dd3a8da8f 100644 (file)
@@ -88,6 +88,8 @@ public:
     {
         return wxItemContainer::GetStringSelection();
     }
     {
         return wxItemContainer::GetStringSelection();
     }
+    virtual void Popup();
+    virtual void Dismiss();
 
     virtual void Clear()
     {
 
     virtual void Clear()
     {
index 8339b4cb0c65b635f51d0414760eb607bc20e826..f656e081e80dd23cb788540a39d9a08e834b07f9 100644 (file)
@@ -82,7 +82,8 @@ public:
     virtual void SetValue(const wxString& value);
     virtual wxString GetStringSelection() const
         { return wxChoice::GetStringSelection(); }
     virtual void SetValue(const wxString& value);
     virtual wxString GetStringSelection() const
         { return wxChoice::GetStringSelection(); }
-
+    virtual void Popup() { MSWDoPopupOrDismiss(true); }
+    virtual void Dismiss() { MSWDoPopupOrDismiss(false); }
     virtual void SetSelection(int n) { wxChoice::SetSelection(n); }
     virtual void SetSelection(long from, long to)
         { wxTextEntry::SetSelection(from, to); }
     virtual void SetSelection(int n) { wxChoice::SetSelection(n); }
     virtual void SetSelection(long from, long to)
         { wxTextEntry::SetSelection(from, to); }
@@ -125,6 +126,7 @@ protected:
 #if wxUSE_TOOLTIPS
     virtual void DoSetToolTip(wxToolTip *tip);
 #endif
 #if wxUSE_TOOLTIPS
     virtual void DoSetToolTip(wxToolTip *tip);
 #endif
+    void MSWDoPopupOrDismiss(bool show);
 
     // this is the implementation of GetEditHWND() which can also be used when
     // we don't have the edit control, it simply returns NULL then
 
     // this is the implementation of GetEditHWND() which can also be used when
     // we don't have the edit control, it simply returns NULL then
index 67029f392beb81904be14ad5b0c76983d8bd049d..8baa461c5bd684112fc7e0b28a61f36b86fb9629 100644 (file)
@@ -243,5 +243,23 @@ public:
             The text to set.
     */
     virtual void SetValue(const wxString& text);
             The text to set.
     */
     virtual void SetValue(const wxString& text);
+
+    /**
+        Shows the list box portion of the combo box.
+
+        Currently only implemented in wxMSW and wxGTK.
+
+        @since 2.9.1
+    */
+    virtual void Popup();
+
+    /**
+        Hides the list box portion of the combo box.
+
+        Currently only implemented in wxMSW and wxGTK.
+
+        @since 2.9.1
+    */
+    virtual void Dismiss();
 };
 
 };
 
index e2073ba98e5259a106946337d508e8b0ac1900d6..32d3642b246fb47631c0b66f65c855bf0e3d8d03 100644 (file)
@@ -53,6 +53,8 @@
 enum
 {
     ComboPage_Reset = wxID_HIGHEST,
 enum
 {
     ComboPage_Reset = wxID_HIGHEST,
+    ComboPage_Popup,
+    ComboPage_Dismiss,
     ComboPage_SetCurrent,
     ComboPage_CurText,
     ComboPage_InsertionPointText,
     ComboPage_SetCurrent,
     ComboPage_CurText,
     ComboPage_InsertionPointText,
@@ -102,6 +104,8 @@ public:
 protected:
     // event handlers
     void OnButtonReset(wxCommandEvent& event);
 protected:
     // event handlers
     void OnButtonReset(wxCommandEvent& event);
+    void OnButtonPopup(wxCommandEvent&) { m_combobox->Popup(); }
+    void OnButtonDismiss(wxCommandEvent&) { m_combobox->Dismiss(); }
     void OnButtonChange(wxCommandEvent& event);
     void OnButtonDelete(wxCommandEvent& event);
     void OnButtonDeleteSel(wxCommandEvent& event);
     void OnButtonChange(wxCommandEvent& event);
     void OnButtonDelete(wxCommandEvent& event);
     void OnButtonDeleteSel(wxCommandEvent& event);
@@ -170,6 +174,8 @@ private:
 
 BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
     EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset)
 
 BEGIN_EVENT_TABLE(ComboboxWidgetsPage, WidgetsPage)
     EVT_BUTTON(ComboPage_Reset, ComboboxWidgetsPage::OnButtonReset)
+    EVT_BUTTON(ComboPage_Popup, ComboboxWidgetsPage::OnButtonPopup)
+    EVT_BUTTON(ComboPage_Dismiss, ComboboxWidgetsPage::OnButtonDismiss)
     EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange)
     EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete)
     EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel)
     EVT_BUTTON(ComboPage_Change, ComboboxWidgetsPage::OnButtonChange)
     EVT_BUTTON(ComboPage_Delete, ComboboxWidgetsPage::OnButtonDelete)
     EVT_BUTTON(ComboPage_DeleteSel, ComboboxWidgetsPage::OnButtonDeleteSel)
@@ -246,8 +252,7 @@ void ComboboxWidgetsPage::CreateContent()
     */
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
     */
     wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
 
-    // left pane
-    wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style"));
+    // upper left pane
 
     // should be in sync with ComboKind_XXX values
     static const wxString kinds[] =
 
     // should be in sync with ComboKind_XXX values
     static const wxString kinds[] =
@@ -262,18 +267,31 @@ void ComboboxWidgetsPage::CreateContent()
                                  WXSIZEOF(kinds), kinds,
                                  1, wxRA_SPECIFY_COLS);
 
                                  WXSIZEOF(kinds), kinds,
                                  1, wxRA_SPECIFY_COLS);
 
-    wxSizer *sizerLeft = new wxStaticBoxSizer(box, wxVERTICAL);
+    wxSizer *sizerLeftTop = new wxStaticBoxSizer(wxVERTICAL, this, "&Set style");
 
 
-    m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Sort items"));
-    m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&Read only"));
-    m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeft, wxT("&File name"));
+    m_chkSort = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&Sort items"));
+    m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&Read only"));
+    m_chkFilename = CreateCheckBoxAndAddToSizer(sizerLeftTop, wxT("&File name"));
     m_chkFilename->Disable(); // not implemented yet
 
     m_chkFilename->Disable(); // not implemented yet
 
-    sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
-    sizerLeft->Add(m_radioKind, 0, wxGROW | wxALL, 5);
+    sizerLeftTop->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
+    sizerLeftTop->Add(m_radioKind, 0, wxGROW | wxALL, 5);
 
     wxButton *btn = new wxButton(this, ComboPage_Reset, wxT("&Reset"));
 
     wxButton *btn = new wxButton(this, ComboPage_Reset, wxT("&Reset"));
-    sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
+    sizerLeftTop->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
+
+    // lower left pane
+    wxSizer *sizerLeftBottom = new wxStaticBoxSizer(wxVERTICAL, this, "&Popup");
+    sizerLeftBottom->Add(new wxButton(this, ComboPage_Popup, "&Show"),
+                         wxSizerFlags().Border().Centre());
+    sizerLeftBottom->Add(new wxButton(this, ComboPage_Dismiss, "&Hide"),
+                         wxSizerFlags().Border().Centre());
+
+
+    wxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL);
+    sizerLeft->Add(sizerLeftTop);
+    sizerLeft->AddSpacer(10);
+    sizerLeft->Add(sizerLeftBottom);
 
     // middle pane
     wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
 
     // middle pane
     wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY,
index 643a62213218e42d552cddbfe396d9e37c1707ea..3abab971457d8c0eca8b65e688ee12384f63ea01 100644 (file)
@@ -337,4 +337,13 @@ void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
     event.Enable(!wxTextEntry::IsEmpty());
 }
 
     event.Enable(!wxTextEntry::IsEmpty());
 }
 
+void wxComboBox::Popup()
+{
+     gtk_combo_box_popup( GTK_COMBO_BOX(m_widget) );
+}
+
+void wxComboBox::Dismiss()
+{
+    gtk_combo_box_popdown( GTK_COMBO_BOX(m_widget) );
+}
 #endif // wxUSE_COMBOBOX
 #endif // wxUSE_COMBOBOX
index 84b1bca018f7d2a220f8d3f8732dce093cbf0b06..9537a60acc0e509a0354fb52311325521123e4c3 100644 (file)
@@ -702,6 +702,22 @@ void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event)
     event.Enable(IsEditable() && !wxTextEntry::IsEmpty());
 }
 
     event.Enable(IsEditable() && !wxTextEntry::IsEmpty());
 }
 
+void wxComboBox::MSWDoPopupOrDismiss(bool show)
+{
+    wxASSERT_MSG( !HasFlag(wxCB_SIMPLE),
+                  wxT("can't popup/dismiss the list for simple combo box") );
+
+    // we *must* set focus to the combobox before showing or hiding the drop
+    // down as without this we get WM_LBUTTONDOWN messages with invalid HWND
+    // when hiding it (whether programmatically or manually) resulting in a
+    // crash when we pass them to IsDialogMessage()
+    //
+    // this can be seen in the combo page of the widgets sample under Windows 7
+    SetFocus();
+
+    ::SendMessage(GetHwnd(), CB_SHOWDROPDOWN, show, 0);
+}
+
 #if wxUSE_TOOLTIPS
 
 void wxComboBox::DoSetToolTip(wxToolTip *tip)
 #if wxUSE_TOOLTIPS
 
 void wxComboBox::DoSetToolTip(wxToolTip *tip)