+ A combo control is a generic combobox that allows totally custom popup. In
+ addition it has other customization features. For instance, position and
+ size of the dropdown button can be changed.
+
+ @section comboctrl_custompopup Setting Custom Popup for wxComboCtrl
+
+ wxComboCtrl needs to be told somehow which control to use and this is done
+ by SetPopupControl(). However, we need something more than just a wxControl
+ in this method as, for example, we need to call
+ SetStringValue("initial text value") and wxControl doesn't have such
+ method. So we also need a wxComboPopup which is an interface which must be
+ implemented by a control to be usable as a popup.
+
+ We couldn't derive wxComboPopup from wxControl as this would make it
+ impossible to have a class deriving from a wxWidgets control and from it,
+ so instead it is just a mix-in.
+
+ Here's a minimal sample of wxListView popup:
+
+ @code
+ #include <wx/combo.h>
+ #include <wx/listctrl.h>
+
+ class wxListViewComboPopup : public wxListView, public wxComboPopup
+ {
+ public:
+ // Initialize member variables
+ virtual void Init()
+ {
+ m_value = -1;
+ }
+
+ // Create popup control
+ virtual bool Create(wxWindow* parent)
+ {
+ return wxListView::Create(parent,1,wxPoint(0,0),wxDefaultSize);
+ }
+
+ // Return pointer to the created control
+ virtual wxWindow *GetControl() { return this; }
+
+ // Translate string into a list selection
+ virtual void SetStringValue(const wxString& s)
+ {
+ int n = wxListView::FindItem(-1,s);
+ if ( n >= 0 && n < wxListView::GetItemCount() )
+ wxListView::Select(n);
+ }
+
+ // Get list selection as a string
+ virtual wxString GetStringValue() const
+ {
+ if ( m_value >= 0 )
+ return wxListView::GetItemText(m_value);
+ return wxEmptyString;
+ }
+
+ // Do mouse hot-tracking (which is typical in list popups)
+ void OnMouseMove(wxMouseEvent& event)
+ {
+ // TODO: Move selection to cursor
+ }
+
+ // On mouse left up, set the value and close the popup
+ void OnMouseClick(wxMouseEvent& WXUNUSED(event))
+ {
+ m_value = wxListView::GetFirstSelected();
+
+ // TODO: Send event as well
+
+ Dismiss();
+ }
+
+ protected:
+
+ int m_value; // current item index
+
+ private:
+ DECLARE_EVENT_TABLE()
+ };
+
+ BEGIN_EVENT_TABLE(wxListViewComboPopup, wxListView)
+ EVT_MOTION(wxListViewComboPopup::OnMouseMove)
+ EVT_LEFT_UP(wxListViewComboPopup::OnMouseClick)
+ END_EVENT_TABLE()
+ @endcode
+
+ Here's how you would create and populate it in a dialog constructor:
+
+ @code
+ wxComboCtrl* comboCtrl = new wxComboCtrl(this, wxID_ANY, wxEmptyString);
+
+ wxListViewComboPopup* popupCtrl = new wxListViewComboPopup();
+
+ comboCtrl->SetPopupControl(popupCtrl);
+
+ // Populate using wxListView methods
+ popupCtrl->InsertItem(popupCtrl->GetItemCount(), "First Item");
+ popupCtrl->InsertItem(popupCtrl->GetItemCount(), "Second Item");
+ popupCtrl->InsertItem(popupCtrl->GetItemCount(), "Third Item");
+ @endcode