+// composite combobox implementation by Dan "Bud" Keith bud@otsys.com
+
+
+static int nextPopUpMenuId = 1000 ;
+MenuHandle NewUniqueMenu()
+{
+ MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ;
+ nextPopUpMenuId++ ;
+ return handle ;
+}
+
+
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// the margin between the text control and the choice
+static const wxCoord MARGIN = 2;
+static const int POPUPWIDTH = 18;
+static const int POPUPHEIGHT = 23;
+
+
+// ----------------------------------------------------------------------------
+// wxComboBoxText: text control forwards events to combobox
+// ----------------------------------------------------------------------------
+
+class wxComboBoxText : public wxTextCtrl
+{
+public:
+ wxComboBoxText( wxComboBox * cb )
+ : wxTextCtrl( cb , 1 )
+ {
+ m_cb = cb;
+ }
+
+protected:
+ void OnTextChange( wxCommandEvent& event )
+ {
+ wxString s = GetValue();
+
+ if (!s.IsEmpty())
+ m_cb->DelegateTextChanged( s );
+
+ event.Skip();
+ }
+
+private:
+ wxComboBox *m_cb;
+
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl)
+ EVT_TEXT(-1, wxComboBoxText::OnTextChange)
+END_EVENT_TABLE()
+
+class wxComboBoxChoice : public wxChoice
+{
+public:
+ wxComboBoxChoice(wxComboBox *cb, int style)
+ : wxChoice( cb , 1 )
+ {
+ m_cb = cb;
+ }
+
+protected:
+ void OnChoice( wxCommandEvent& e )
+ {
+ wxString s = e.GetString();
+
+ m_cb->DelegateChoice( s );
+ }
+
+private:
+ wxComboBox *m_cb;
+
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
+ EVT_CHOICE(-1, wxComboBoxChoice::OnChoice)
+END_EVENT_TABLE()
+
+wxComboBox::~wxComboBox()
+{
+ // delete the controls now, don't leave them alive even though they would
+ // still be eventually deleted by our parent - but it will be too late, the
+ // user code expects them to be gone now
+ if (m_text != NULL) {
+ delete m_text;
+ m_text = NULL;
+ }
+ if (m_choice != NULL) {
+ delete m_choice;
+ m_choice = NULL;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+// geometry
+// ----------------------------------------------------------------------------
+
+wxSize wxComboBox::DoGetBestSize() const
+{
+ wxSize size = m_choice->GetBestSize();
+
+ if ( m_text != 0 )
+ {
+ wxSize sizeText = m_text->GetBestSize();
+
+ size.x = POPUPWIDTH + sizeText.x + MARGIN;
+ }
+
+ return size;
+}
+
+void wxComboBox::DoMoveWindow(int x, int y, int width, int height) {
+ height = POPUPHEIGHT;
+
+ wxControl::DoMoveWindow(x, y, width, height);
+
+ if ( m_text == 0 )
+ {
+ m_choice->SetSize(0, 0 , width, -1);
+ }
+ else
+ {
+ wxCoord wText = width - POPUPWIDTH;
+ m_text->SetSize(0, 0, wText, height);
+ m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, -1);
+ }
+}
+
+
+
+// ----------------------------------------------------------------------------
+// operations forwarded to the subcontrols
+// ----------------------------------------------------------------------------
+
+bool wxComboBox::Enable(bool enable)
+{
+ if ( !wxControl::Enable(enable) )
+ return FALSE;
+
+ return TRUE;
+}
+
+bool wxComboBox::Show(bool show)
+{
+ if ( !wxControl::Show(show) )
+ return FALSE;
+
+ return TRUE;
+}
+
+ void wxComboBox::SetFocus()
+ {
+ m_text->SetFocus();
+ }
+
+
+void wxComboBox::DelegateTextChanged( const wxString& value ) {
+}
+
+
+void wxComboBox::DelegateChoice( const wxString& value )
+{
+ SetStringSelection( value );
+}