// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-// composite combobox implementation by Dan "Bud" Keith bud@otsys.com
+WX_DELEGATE_TO_CONTROL_CONTAINER(wxComboBox)
+
+BEGIN_EVENT_TABLE(wxComboBox, wxControl)
+ WX_EVENT_TABLE_CONTROL_CONTAINER(wxComboBox)
+END_EVENT_TABLE()
- // Allows processing the tab key to go to the next control
- if (event.GetKeyCode() == WXK_TAB)
- {
- wxNavigationKeyEvent NavEvent;
- NavEvent.SetEventObject(this);
- NavEvent.SetDirection(true);
- NavEvent.SetWindowChange(false);
-
- // Get the parent of the combo and have it process the navigation?
- if (m_cb->GetParent()->GetEventHandler()->ProcessEvent(NavEvent))
+ // Allows processing the tab key to go to the next control
+ if (event.GetKeyCode() == WXK_TAB)
+ {
+ wxNavigationKeyEvent NavEvent;
+ NavEvent.SetEventObject(this);
+ NavEvent.SetDirection(true);
+ NavEvent.SetWindowChange(false);
+
+ // Get the parent of the combo and have it process the navigation?
+ if (m_cb->GetParent()->GetEventHandler()->ProcessEvent(NavEvent))
+ }
+
+ // send the event to the combobox class in case the user has bound EVT_CHAR
+ wxKeyEvent kevt(event);
+ kevt.SetEventObject(m_cb);
+ if (m_cb->GetEventHandler()->ProcessEvent(kevt))
+ // If the event was handled and not skipped then we're done
+ return;
+
if ( event.GetKeyCode() == WXK_RETURN )
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_cb->GetId());
if ( event.GetKeyCode() == WXK_RETURN )
{
wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_cb->GetId());
- // This will invoke the dialog default action, such
- // as the clicking the default button.
-
+ // This will invoke the dialog default action,
+ // such as the clicking the default button.
- if ( event.GetKeyCode() != WXK_RETURN )
- {
- wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_cb->GetId());
- event.SetString( GetValue() );
- event.SetEventObject( m_cb );
- m_cb->GetEventHandler()->ProcessEvent(event);
- }
+ event.SetEventObject(m_cb);
+ event.SetId(m_cb->GetId());
+ if (! m_cb->GetEventHandler()->ProcessEvent(event))
+ event.Skip();
+ }
+
+ void OnKeyDown( wxKeyEvent& event )
+ {
+ event.SetEventObject(m_cb);
+ event.SetId(m_cb->GetId());
+ if (! m_cb->GetEventHandler()->ProcessEvent(event))
+ event.Skip();
- EVT_CHAR( wxComboBoxText::OnChar)
- EVT_KEY_UP( wxComboBoxText::OnKeyUp)
+ EVT_KEY_DOWN(wxComboBoxText::OnKeyDown)
+ EVT_CHAR(wxComboBoxText::OnChar)
+ EVT_KEY_UP(wxComboBoxText::OnKeyUp)
+ EVT_TEXT(-1, wxComboBoxText::OnText)
- wxComboBoxChoice(wxComboBox *cb, int style)
- : wxChoice( cb , 1 )
+ wxComboBoxChoice( wxComboBox *cb, int style )
+ : wxChoice( cb , 1 , wxDefaultPosition , wxDefaultSize , 0 , NULL , style & (wxCB_SORT) )
virtual wxSize DoGetBestSize() const
{
wxSize sz = wxChoice::DoGetBestSize() ;
if (! m_cb->HasFlag(wxCB_READONLY) )
sz.x = GetPopupWidth() ;
virtual wxSize DoGetBestSize() const
{
wxSize sz = wxChoice::DoGetBestSize() ;
if (! m_cb->HasFlag(wxCB_READONLY) )
sz.x = GetPopupWidth() ;
// 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
// 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
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// geometry
// ----------------------------------------------------------------------------
size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
size.x += TEXTFOCUSBORDER ;
size.y += 2 * TEXTFOCUSBORDER ;
size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN;
size.x += TEXTFOCUSBORDER ;
size.y += 2 * TEXTFOCUSBORDER ;
-void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
+void wxComboBox::DoMoveWindow(int x, int y, int width, int height)
- wxControl::DoMoveWindow(x, y, width , height );
-
+ wxControl::DoMoveWindow( x, y, width , height );
+
- m_text->SetSize(TEXTFOCUSBORDER, TEXTFOCUSBORDER, wText, -1 );
+ 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);
// 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
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// operations forwarded to the subcontrols
// ----------------------------------------------------------------------------
-
-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)
+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)
chs.GetStrings(), style, validator, name );
}
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)
+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 ,
{
if ( !wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, style ,
DoSetSize(pos.x, pos.y, csize.x, csize.y);
DoSetSize(pos.x, pos.y, csize.x, csize.y);
- int s = FindString (sel);
- if (s > -1)
- {
- SetSelection (s);
- return TRUE;
- }
+ m_choice->SetString( n , s ) ;
+}
+
+bool wxComboBox::IsEditable() const
+{
+ return m_text != NULL && !HasFlag(wxCB_READONLY);
+}
+
+void wxComboBox::Undo()
+{
+ if (m_text != NULL)
+ m_text->Undo();
+}
+
+void wxComboBox::Redo()
+{
+ if (m_text != NULL)
+ m_text->Redo();
+}
+
+void wxComboBox::SelectAll()
+{
+ if (m_text != NULL)
+ m_text->SelectAll();
+}
+
+bool wxComboBox::CanCopy() const
+{
+ if (m_text != NULL)
+ return m_text->CanCopy();
- /* For consistency with other platforms, clicking in the text area does not constitute a selection
+ if (m_text != NULL)
+ return m_text->CanRedo();
+ else
+ return false;
+}
+
+wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
+{
+/*
+ For consistency with other platforms, clicking in the text area does not constitute a selection
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(GetStringSelection());
wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId );
event.SetInt(GetSelection());
event.SetEventObject(this);
event.SetString(GetStringSelection());