-// right now we don't support editable comboboxes
-
-
-bool wxComboBox::Create(wxWindow *parent, wxWindowID id,
- const wxString& value,
- const wxPoint& pos,
- const wxSize& size,
- int n, const wxString choices[],
- long style,
- const wxValidator& validator,
- const wxString& name)
-{
- m_noStrings = n;
-
- Rect bounds ;
- Str255 title ;
-
- MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ;
-
- m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0,
- kControlPopupButtonProc , (long) this ) ;
-
- m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ;
- SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ;
- for ( int i = 0 ; i < n ; i++ )
- {
- Str255 label;
- wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false);
- AppendMenu( m_macPopUpMenuHandle , label ) ;
- }
- SetControlMinimum( m_macControl , 0 ) ;
- SetControlMaximum( m_macControl , m_noStrings) ;
- SetControlValue( m_macControl , 1 ) ;
-
- MacPostControlCreate() ;
-
- return TRUE;
+protected:
+ void OnChoice( wxCommandEvent& e )
+ {
+ wxString s = e.GetString();
+
+ m_cb->DelegateChoice( s );
+ wxCommandEvent event2(wxEVT_COMMAND_COMBOBOX_SELECTED, m_cb->GetId() );
+ event2.SetInt(m_cb->GetSelection());
+ event2.SetEventObject(m_cb);
+ event2.SetString(m_cb->GetStringSelection());
+ m_cb->ProcessCommand(event2);
+
+ // For consistency with MSW and GTK, also send a text updated event
+ // After all, the text is updated when a selection is made
+ wxCommandEvent TextEvent( wxEVT_COMMAND_TEXT_UPDATED, m_cb->GetId() );
+ TextEvent.SetString( m_cb->GetStringSelection() );
+ TextEvent.SetEventObject( m_cb );
+ m_cb->ProcessCommand( TextEvent );
+ }
+
+ virtual wxSize DoGetBestSize() const
+ {
+ wxSize sz = wxChoice::DoGetBestSize() ;
+ if (! m_cb->HasFlag(wxCB_READONLY) )
+ sz.x = GetPopupWidth() ;
+
+ return sz ;
+ }
+
+private:
+ wxComboBox *m_cb;
+
+ friend class wxComboBox;
+
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxComboBoxChoice, wxChoice)
+ EVT_CHOICE(wxID_ANY, wxComboBoxChoice::OnChoice)
+END_EVENT_TABLE()
+
+wxComboBox::~wxComboBox()
+{
+ // delete client objects
+ FreeData();
+
+ // 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
+{
+ if (!m_choice && !m_text)
+ return GetSize();
+
+ wxSize size = m_choice->GetBestSize();
+
+ if ( m_text != NULL )
+ {
+ wxSize sizeText = m_text->GetBestSize();
+ if (sizeText.y > size.y)
+ size.y = sizeText.y;
+
+ size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
+ size.x += TEXTFOCUSBORDER ;
+ size.y += 2 * TEXTFOCUSBORDER ;
+ }
+ else
+ {
+ // clipping is too tight
+ size.y += 1 ;
+ }
+
+ return size;
+}
+
+void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
+{
+ wxControl::DoMoveWindow( x, y, width , height );
+
+ if ( m_text == NULL )
+ {
+ // we might not be fully constructed yet, therefore watch out...
+ if ( m_choice )
+ m_choice->SetSize(0, 0 , width, -1);
+ }
+ else
+ {
+ wxCoord wText = width - m_choice->GetPopupWidth() - MARGIN;
+ m_text->SetSize(TEXTFOCUSBORDER, TEXTFOCUSBORDER, wText, -1);
+
+ // put it at an inset of 1 to have outer area shadows drawn as well
+ m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , TEXTFOCUSBORDER, m_choice->GetPopupWidth() , -1);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// operations forwarded to the subcontrols
+// ----------------------------------------------------------------------------
+
+bool wxComboBox::Enable(bool enable)
+{
+ if ( !wxControl::Enable(enable) )
+ return false;
+
+ if (m_text)
+ m_text->Enable(enable);
+
+ return true;
+}
+
+bool wxComboBox::Show(bool show)
+{
+ if ( !wxControl::Show(show) )
+ return false;
+
+ return true;
+}
+
+void wxComboBox::DelegateTextChanged( const wxString& value )
+{
+ SetStringSelection( value );
+}
+
+void wxComboBox::DelegateChoice( const wxString& value )
+{
+ SetStringSelection( value );
+}
+
+void wxComboBox::Init()
+{
+ m_container.SetContainerWindow(this);
+}
+
+bool wxComboBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ const wxArrayString& choices,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ wxCArrayString chs( choices );
+
+ return Create( parent, id, value, pos, size, chs.GetCount(),
+ chs.GetStrings(), style, validator, name );
+}
+
+bool wxComboBox::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxString& value,
+ const wxPoint& pos,
+ const wxSize& size,
+ int n,
+ const wxString choices[],
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
+ validator, name) )
+ {
+ return false;
+ }
+
+ m_choice = new wxComboBoxChoice(this, style );
+ wxSize csize = size;
+ if ( style & wxCB_READONLY )
+ {
+ m_text = NULL;
+ }
+ else
+ {
+ m_text = new wxComboBoxText(this);
+ if ( size.y == -1 )
+ {
+ csize.y = m_text->GetSize().y ;
+ csize.y += 2 * TEXTFOCUSBORDER ;
+ }
+ }
+
+ DoSetSize(pos.x, pos.y, csize.x, csize.y);
+
+ for ( int i = 0 ; i < n ; i++ )
+ {
+ m_choice->DoAppend( choices[ i ] );
+ }
+
+ // Needed because it is a wxControlWithItems
+ SetBestSize(size);
+ SetStringSelection(value);
+
+ return true;