+// 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->GetParent(), 1 )
+ {
+ m_cb = cb;
+ }
+
+protected:
+ void OnTextChange( wxCommandEvent& event )
+ {
+ wxString s = GetValue();
+
+ 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->GetParent(), 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 woudl
+ // still be eventually deleted by our parent - but it will be too late, the
+ // user code expects them to be gone now
+ delete m_text;
+ delete m_choice;
+}
+
+
+// ----------------------------------------------------------------------------
+// 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(x, y, width, -1);
+ }
+ else
+ {
+ wxCoord wText = width - POPUPWIDTH;
+ m_text->SetSize(x, y, wText, height);
+ m_choice->SetSize(x + wText + MARGIN, y, POPUPWIDTH, -1);
+ }
+}
+
+
+
+// ----------------------------------------------------------------------------
+// operations forwarded to the subcontrols
+// ----------------------------------------------------------------------------
+
+bool wxComboBox::Enable(bool enable)
+{
+ if ( !wxControl::Enable(enable) )
+ return FALSE;
+
+ m_choice->Enable(enable);
+
+ if ( m_text != 0 )
+ {
+ m_text->Enable(enable);
+ }
+
+ return TRUE;
+}
+
+bool wxComboBox::Show(bool show)
+{
+ if ( !wxControl::Show(show) )
+ return FALSE;
+
+ // under GTK Show() is called the first time before we are fully
+ // constructed
+ if ( m_choice )
+ {
+ m_choice->Show(show);
+ if ( m_text != 0 )
+ {
+ m_text->Show(show);
+ }
+ }
+
+ return TRUE;
+}
+
+
+void wxComboBox::DelegateTextChanged( const wxString& value ) {
+}
+
+
+void wxComboBox::DelegateChoice( const wxString& value )
+{
+ SetStringSelection( value );
+}