X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6d0ce565ff6a0db2e7c6e3240ef4cf6fe7950a35..cd720353875d94cfabbbc120e6569bd08cf2d478:/src/univ/combobox.cpp diff --git a/src/univ/combobox.cpp b/src/univ/combobox.cpp index b884e8482d..e41adaa761 100644 --- a/src/univ/combobox.cpp +++ b/src/univ/combobox.cpp @@ -44,6 +44,19 @@ #include "wx/univ/inphand.h" #include "wx/univ/theme.h" +// ---------------------------------------------------------------------------- +// wxStdComboBoxInputHandler: allows the user to open/close the combo from kbd +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxStdComboBoxInputHandler : public wxStdInputHandler +{ +public: + wxStdComboBoxInputHandler(wxInputHandler *inphand); + + virtual bool HandleKey(wxInputConsumer *consumer, + const wxKeyEvent& event, + bool pressed); +}; // ---------------------------------------------------------------------------- // wxComboListBox is a listbox modified to be used as a popup window in a @@ -54,7 +67,7 @@ class wxComboListBox : public wxListBox, public wxComboPopup { public: // ctor and dtor - wxComboListBox(wxComboControlBase *combo); + wxComboListBox(); virtual ~wxComboListBox(); // implement wxComboPopup methods @@ -79,6 +92,8 @@ protected: void OnLeftUp(wxMouseEvent& event); private: + friend class wxComboBox; // it accesses our DoGetItemClientData() + DECLARE_EVENT_TABLE() }; @@ -90,8 +105,6 @@ BEGIN_EVENT_TABLE(wxComboListBox, wxListBox) EVT_LEFT_UP(wxComboListBox::OnLeftUp) END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS2(wxComboBox, wxControl, wxComboControl) - // ============================================================================ // implementation // ============================================================================ @@ -100,9 +113,7 @@ IMPLEMENT_DYNAMIC_CLASS2(wxComboBox, wxControl, wxComboControl) // wxComboListBox // ---------------------------------------------------------------------------- -wxComboListBox::wxComboListBox(wxComboControlBase *combo) - : wxListBox(), - wxComboPopup(combo) +wxComboListBox::wxComboListBox() : wxListBox(), wxComboPopup() { } @@ -111,8 +122,8 @@ bool wxComboListBox::Create(wxWindow* parent) if ( !wxListBox::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, NULL, - wxBORDER_SIMPLE | wxLB_INT_HEIGHT | - m_combo->GetWindowStyle() & wxCB_SORT ? wxLB_SORT : 0) ) + wxBORDER_SIMPLE | + ( m_combo->GetWindowStyle() & wxCB_SORT ? wxLB_SORT : 0 ) ) ) return false; // we don't react to the mouse events outside the window at all @@ -133,28 +144,12 @@ wxString wxComboListBox::GetStringValue() const void wxComboListBox::SetStringValue(const wxString& value) { if ( !value.empty() ) - wxListBox::SetStringSelection(value); - else - wxListBox::SetSelection(-1); - - /* - // PRE-GLOBAL WXCOMBOCONTROL CODE: - - // FindItem() would just find the current item for an empty string (it - // always matches), but we want to show the first one in such case - if ( value.empty() ) { - if ( GetCount() > 0 ) - { - wxListBox::SetSelection(0); - } - //else: empty listbox - nothing to do + if (FindString(value) != wxNOT_FOUND) + wxListBox::SetStringSelection(value); } - else if ( !FindItem(value) ) - { - // no match att all - } - */ + else + wxListBox::SetSelection(-1); } void wxComboListBox::OnPopup() @@ -170,7 +165,7 @@ bool wxComboListBox::PerformAction(const wxControlAction& action, { // we don't let the listbox handle this as instead of just using the // single key presses, as usual, we use the text ctrl value as prefix - // and this is done by wxComboControl itself + // and this is done by wxComboCtrl itself return true; } @@ -188,7 +183,7 @@ void wxComboListBox::OnLeftUp(wxMouseEvent& event) wxCommandEvent evt(wxEVT_COMMAND_COMBOBOX_SELECTED,m_combo->GetId()); evt.SetInt(wxListBox::GetSelection()); evt.SetEventObject(m_combo); - m_combo->ProcessEvent(evt); + m_combo->ProcessWindowEvent(evt); event.Skip(); } @@ -208,7 +203,7 @@ wxSize wxComboListBox::GetAdjustedSize(int minWidth, void wxComboBox::Init() { - m_lbox = (wxListBox *)NULL; + m_lbox = NULL; } wxComboBox::wxComboBox(wxWindow *parent, @@ -253,13 +248,13 @@ bool wxComboBox::Create(wxWindow *parent, const wxValidator& validator, const wxString& name) { - if ( !wxComboControl::Create(parent, id, value, pos, size, style, + if ( !wxComboCtrl::Create(parent, id, value, pos, size, style, validator, name) ) { return false; } - wxComboListBox *combolbox = new wxComboListBox(this); + wxComboListBox *combolbox = new wxComboListBox(); SetPopupControl(combolbox); m_lbox = combolbox; @@ -276,14 +271,22 @@ wxComboBox::~wxComboBox() // wxComboBox methods forwarded to wxTextCtrl // ---------------------------------------------------------------------------- -wxString wxComboBox::GetValue() const +wxString wxComboBox::DoGetValue() const { - return wxComboControl::GetValue(); + return GetTextCtrl() ? GetTextCtrl()->GetValue() : m_valueString; } void wxComboBox::SetValue(const wxString& value) { - wxComboControl::SetValue(value); + if ( GetTextCtrl() ) + GetTextCtrl()->SetValue(value); + else + m_valueString = value; +} + +void wxComboBox::WriteText(const wxString& value) +{ + if ( GetTextCtrl() ) GetTextCtrl()->WriteText(value); } void wxComboBox::Copy() @@ -340,6 +343,11 @@ void wxComboBox::SetSelection(long from, long to) if ( GetTextCtrl() ) GetTextCtrl()->SetSelection(from, to); } +void wxComboBox::GetSelection(long *from, long *to) const +{ + if ( GetTextCtrl() ) GetTextCtrl()->GetSelection(from, to); +} + void wxComboBox::SetEditable(bool editable) { if ( GetTextCtrl() ) GetTextCtrl()->SetEditable(editable); @@ -349,18 +357,18 @@ void wxComboBox::SetEditable(bool editable) // wxComboBox methods forwarded to wxListBox // ---------------------------------------------------------------------------- -void wxComboBox::Clear() +void wxComboBox::DoClear() { GetLBox()->Clear(); - if ( GetTextCtrl() ) GetTextCtrl()->SetValue(wxEmptyString); + SetValue(wxEmptyString); } -void wxComboBox::Delete(unsigned int n) +void wxComboBox::DoDeleteOneItem(unsigned int n) { - wxCHECK_RET( IsValid(n), _T("invalid index in wxComboBox::Delete") ); + wxCHECK_RET( IsValid(n), wxT("invalid index in wxComboBox::Delete") ); if (GetSelection() == (int)n) - if ( GetTextCtrl() ) GetTextCtrl()->SetValue(wxEmptyString); + SetValue(wxEmptyString); GetLBox()->Delete(n); } @@ -372,14 +380,14 @@ unsigned int wxComboBox::GetCount() const wxString wxComboBox::GetString(unsigned int n) const { - wxCHECK_MSG( IsValid(n), wxEmptyString, _T("invalid index in wxComboBox::GetString") ); + wxCHECK_MSG( IsValid(n), wxEmptyString, wxT("invalid index in wxComboBox::GetString") ); return GetLBox()->GetString(n); } void wxComboBox::SetString(unsigned int n, const wxString& s) { - wxCHECK_RET( IsValid(n), _T("invalid index in wxComboBox::SetString") ); + wxCHECK_RET( IsValid(n), wxT("invalid index in wxComboBox::SetString") ); GetLBox()->SetString(n, s); } @@ -391,15 +399,20 @@ int wxComboBox::FindString(const wxString& s, bool bCase) const void wxComboBox::SetSelection(int n) { - wxCHECK_RET( IsValid(n), _T("invalid index in wxComboBox::Select") ); + wxCHECK_RET( (n == wxNOT_FOUND || IsValid(n)), wxT("invalid index in wxComboBox::Select") ); GetLBox()->SetSelection(n); - if ( GetTextCtrl() ) GetTextCtrl()->SetValue(GetLBox()->GetString(n)); + + wxString str; + if ( n != wxNOT_FOUND ) + str = GetLBox()->GetString(n); + + SetText(str); } int wxComboBox::GetSelection() const { -#if 1 // FIXME:: What is the correct behavior? +#if 1 // FIXME:: What is the correct behaviour? // if the current value isn't one of the listbox strings, return -1 return GetLBox()->GetSelection(); #else @@ -410,41 +423,36 @@ int wxComboBox::GetSelection() const #endif } -int wxComboBox::DoAppend(const wxString& item) +wxString wxComboBox::GetStringSelection() const { - return GetLBox()->Append(item); + return GetLBox()->GetStringSelection(); } -int wxComboBox::DoInsert(const wxString& item, unsigned int pos) +wxClientDataType wxComboBox::GetClientDataType() const { - wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list")); - wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index")); - - if (pos == GetCount()) - return DoAppend(item); - - GetLBox()->Insert(item, pos); - return pos; + return GetLBox()->GetClientDataType(); } -void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) +void wxComboBox::SetClientDataType(wxClientDataType clientDataItemsType) { - GetLBox()->SetClientData(n, clientData); + GetLBox()->SetClientDataType(clientDataItemsType); } -void *wxComboBox::DoGetItemClientData(unsigned int n) const +int wxComboBox::DoInsertItems(const wxArrayStringsAdapter & items, + unsigned int pos, + void **clientData, wxClientDataType type) { - return GetLBox()->GetClientData(n); + return GetLBox()->DoInsertItems(items, pos, clientData, type); } -void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData) +void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) { - GetLBox()->SetClientObject(n, clientData); + GetLBox()->DoSetItemClientData(n, clientData); } -wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const +void *wxComboBox::DoGetItemClientData(unsigned int n) const { - return GetLBox()->GetClientObject(n); + return GetLBox()->DoGetItemClientData(n); } bool wxComboBox::IsEditable() const @@ -548,5 +556,12 @@ bool wxStdComboBoxInputHandler::HandleKey(wxInputConsumer *consumer, return wxStdInputHandler::HandleKey(consumer, event, pressed); } +/* static */ +wxInputHandler *wxComboBox::GetStdInputHandler(wxInputHandler *handlerDef) +{ + static wxStdComboBoxInputHandler s_handler(handlerDef); + + return &s_handler; +} #endif // wxUSE_COMBOBOX