X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce22ac4592fccaedd8324e7a8f08b510748827e4..e1efca652844273c3e8d32c7e5f442b87e455ca7:/samples/widgets/odcombobox.cpp?ds=sidebyside diff --git a/samples/widgets/odcombobox.cpp b/samples/widgets/odcombobox.cpp index ee531cfa94..419a13408a 100644 --- a/samples/widgets/odcombobox.cpp +++ b/samples/widgets/odcombobox.cpp @@ -6,7 +6,7 @@ // Created: Jul-28-2006 // Id: $Id$ // Copyright: (c) 2006 Jaakko Salli -// License: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -45,6 +45,7 @@ #include "wx/odcombo.h" +#include "itemcontainer.h" #include "widgets.h" #include "icons/odcombobox.xpm" @@ -76,7 +77,8 @@ enum ODComboPage_Delete, ODComboPage_DeleteText, ODComboPage_DeleteSel, - ODComboPage_Combo + ODComboPage_Combo, + ODComboPage_ContainerTests }; @@ -84,12 +86,15 @@ enum // ODComboboxWidgetsPage // ---------------------------------------------------------------------------- -class ODComboboxWidgetsPage : public WidgetsPage +class ODComboboxWidgetsPage : public ItemContainerWidgetsPage { public: ODComboboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist); virtual wxControl *GetWidget() const { return m_combobox; } + virtual wxTextEntryBase *GetTextEntry() const + { return m_combobox ? m_combobox->GetTextCtrl() : NULL; } + virtual wxItemContainer* GetContainer() const { return m_combobox; } virtual void RecreateWidget() { CreateCombo(); } // lazy creation of the content @@ -108,6 +113,8 @@ protected: void OnButtonAddMany(wxCommandEvent& event); void OnComboBox(wxCommandEvent& event); + void OnDropDown(wxCommandEvent& event); + void OnCloseUp(wxCommandEvent& event); void OnComboText(wxCommandEvent& event); void OnCheckOrRadioBox(wxCommandEvent& event); @@ -188,6 +195,7 @@ BEGIN_EVENT_TABLE(ODComboboxWidgetsPage, WidgetsPage) EVT_BUTTON(ODComboPage_Add, ODComboboxWidgetsPage::OnButtonAdd) EVT_BUTTON(ODComboPage_AddSeveral, ODComboboxWidgetsPage::OnButtonAddSeveral) EVT_BUTTON(ODComboPage_AddMany, ODComboboxWidgetsPage::OnButtonAddMany) + EVT_BUTTON(ODComboPage_ContainerTests, ItemContainerWidgetsPage::OnButtonTestItemContainer) EVT_TEXT_ENTER(ODComboPage_InsertText, ODComboboxWidgetsPage::OnButtonInsert) EVT_TEXT_ENTER(ODComboPage_AddText, ODComboboxWidgetsPage::OnButtonAdd) @@ -212,6 +220,8 @@ BEGIN_EVENT_TABLE(ODComboboxWidgetsPage, WidgetsPage) EVT_UPDATE_UI(ODComboPage_ChangeText, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton) EVT_UPDATE_UI(ODComboPage_DeleteSel, ODComboboxWidgetsPage::OnUpdateUIDeleteSelButton) + EVT_COMBOBOX_DROPDOWN(ODComboPage_Combo, ODComboboxWidgetsPage::OnDropDown) + EVT_COMBOBOX_CLOSEUP(ODComboPage_Combo, ODComboboxWidgetsPage::OnCloseUp) EVT_COMBOBOX(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboBox) EVT_TEXT(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboText) EVT_TEXT_ENTER(ODComboPage_Combo, ODComboboxWidgetsPage::OnComboText) @@ -290,13 +300,13 @@ public: }; -IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage, _T("OwnerDrawnCombobox"), +IMPLEMENT_WIDGETS_PAGE(ODComboboxWidgetsPage, wxT("OwnerDrawnCombobox"), GENERIC_CTRLS | WITH_ITEMS_CTRLS | COMBO_CTRLS ); ODComboboxWidgetsPage::ODComboboxWidgetsPage(WidgetsBookCtrl *book, wxImageList *imaglist) - : WidgetsPage(book, imaglist, odcombobox_xpm) + : ItemContainerWidgetsPage(book, imaglist, odcombobox_xpm) { // init everything m_chkSort = @@ -323,85 +333,88 @@ void ODComboboxWidgetsPage::CreateContent() wxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL); // left pane - style box - wxStaticBox *box = new wxStaticBox(this, wxID_ANY, _T("&Set style")); + wxStaticBox *box = new wxStaticBox(this, wxID_ANY, wxT("&Set style")); wxSizer *sizerStyle = new wxStaticBoxSizer(box, wxVERTICAL); - m_chkSort = CreateCheckBoxAndAddToSizer(sizerStyle, _T("&Sort items")); - m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerStyle, _T("&Read only")); - m_chkDclickcycles = CreateCheckBoxAndAddToSizer(sizerStyle, _T("&Double-click Cycles")); + m_chkSort = CreateCheckBoxAndAddToSizer(sizerStyle, wxT("&Sort items")); + m_chkReadonly = CreateCheckBoxAndAddToSizer(sizerStyle, wxT("&Read only")); + m_chkDclickcycles = CreateCheckBoxAndAddToSizer(sizerStyle, wxT("&Double-click Cycles")); sizerStyle->AddSpacer(4); - m_chkBitmapbutton = CreateCheckBoxAndAddToSizer(sizerStyle, _T("&Bitmap button")); - m_chkStdbutton = CreateCheckBoxAndAddToSizer(sizerStyle, _T("B&lank button background")); + m_chkBitmapbutton = CreateCheckBoxAndAddToSizer(sizerStyle, wxT("&Bitmap button")); + m_chkStdbutton = CreateCheckBoxAndAddToSizer(sizerStyle, wxT("B&lank button background")); - wxButton *btn = new wxButton(this, ODComboPage_Reset, _T("&Reset")); + wxButton *btn = new wxButton(this, ODComboPage_Reset, wxT("&Reset")); sizerStyle->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 3); sizerLeft->Add(sizerStyle, 0, wxGROW | wxALIGN_CENTRE_HORIZONTAL); // left pane - popup adjustment box - box = new wxStaticBox(this, wxID_ANY, _T("Adjust &popup")); + box = new wxStaticBox(this, wxID_ANY, wxT("Adjust &popup")); wxSizer *sizerPopupPos = new wxStaticBoxSizer(box, wxVERTICAL); - sizerRow = CreateSizerWithTextAndLabel(_T("Min. Width:"), + sizerRow = CreateSizerWithTextAndLabel(wxT("Min. Width:"), ODComboPage_PopupMinWidth, &m_textPopupMinWidth); m_textPopupMinWidth->SetValue(wxT("-1")); sizerPopupPos->Add(sizerRow, 0, wxALL | wxGROW, 5); - sizerRow = CreateSizerWithTextAndLabel(_T("Max. Height:"), + sizerRow = CreateSizerWithTextAndLabel(wxT("Max. Height:"), ODComboPage_PopupHeight, &m_textPopupHeight); m_textPopupHeight->SetValue(wxT("-1")); sizerPopupPos->Add(sizerRow, 0, wxALL | wxGROW, 5); - m_chkAlignpopupright = CreateCheckBoxAndAddToSizer(sizerPopupPos, _T("Align Right")); + m_chkAlignpopupright = CreateCheckBoxAndAddToSizer(sizerPopupPos, wxT("Align Right")); sizerLeft->Add(sizerPopupPos, 0, wxGROW | wxALIGN_CENTRE_HORIZONTAL | wxTOP, 2); // left pane - button adjustment box - box = new wxStaticBox(this, wxID_ANY, _T("Adjust &button")); + box = new wxStaticBox(this, wxID_ANY, wxT("Adjust &button")); wxSizer *sizerButtonPos = new wxStaticBoxSizer(box, wxVERTICAL); - sizerRow = CreateSizerWithTextAndLabel(_T("Width:"), + sizerRow = CreateSizerWithTextAndLabel(wxT("Width:"), ODComboPage_ButtonWidth, &m_textButtonWidth); m_textButtonWidth->SetValue(wxT("-1")); sizerButtonPos->Add(sizerRow, 0, wxALL | wxGROW, 5); - sizerRow = CreateSizerWithTextAndLabel(_T("VSpacing:"), + sizerRow = CreateSizerWithTextAndLabel(wxT("VSpacing:"), ODComboPage_ButtonSpacing, &m_textButtonSpacing); m_textButtonSpacing->SetValue(wxT("0")); sizerButtonPos->Add(sizerRow, 0, wxALL | wxGROW, 5); - sizerRow = CreateSizerWithTextAndLabel(_T("Height:"), + sizerRow = CreateSizerWithTextAndLabel(wxT("Height:"), ODComboPage_ButtonHeight, &m_textButtonHeight); m_textButtonHeight->SetValue(wxT("-1")); sizerButtonPos->Add(sizerRow, 0, wxALL | wxGROW, 5); - m_chkAlignbutleft = CreateCheckBoxAndAddToSizer(sizerButtonPos, _T("Align Left")); + m_chkAlignbutleft = CreateCheckBoxAndAddToSizer(sizerButtonPos, wxT("Align Left")); sizerLeft->Add(sizerButtonPos, 0, wxGROW | wxALIGN_CENTRE_HORIZONTAL | wxTOP, 2); // middle pane wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, - _T("&Change combobox contents")); + wxT("&Change combobox contents")); wxSizer *sizerMiddle = new wxStaticBoxSizer(box2, wxVERTICAL); - sizerRow = CreateSizerWithTextAndLabel(_T("Current selection"), + btn = new wxButton(this, ODComboPage_ContainerTests, wxT("Run &tests")); + sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); + + sizerRow = CreateSizerWithTextAndLabel(wxT("Current selection"), ODComboPage_CurText, &text); text->SetEditable(false); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); - sizerRow = CreateSizerWithTextAndLabel(_T("Insertion Point"), + sizerRow = CreateSizerWithTextAndLabel(wxT("Insertion Point"), ODComboPage_InsertionPointText, &text); text->SetEditable(false); @@ -409,39 +422,39 @@ void ODComboboxWidgetsPage::CreateContent() sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); sizerRow = CreateSizerWithTextAndButton(ODComboPage_Insert, - _T("&Insert this string"), + wxT("&Insert this string"), ODComboPage_InsertText, &m_textInsert); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); sizerRow = CreateSizerWithTextAndButton(ODComboPage_Add, - _T("&Add this string"), + wxT("&Add this string"), ODComboPage_AddText, &m_textAdd); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); - btn = new wxButton(this, ODComboPage_AddSeveral, _T("&Append a few strings")); + btn = new wxButton(this, ODComboPage_AddSeveral, wxT("&Append a few strings")); sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); - btn = new wxButton(this, ODComboPage_AddMany, _T("Append &many strings")); + btn = new wxButton(this, ODComboPage_AddMany, wxT("Append &many strings")); sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); sizerRow = CreateSizerWithTextAndButton(ODComboPage_Change, - _T("C&hange current"), + wxT("C&hange current"), ODComboPage_ChangeText, &m_textChange); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); sizerRow = CreateSizerWithTextAndButton(ODComboPage_Delete, - _T("&Delete this item"), + wxT("&Delete this item"), ODComboPage_DeleteText, &m_textDelete); sizerMiddle->Add(sizerRow, 0, wxALL | wxGROW, 5); - btn = new wxButton(this, ODComboPage_DeleteSel, _T("Delete &selection")); + btn = new wxButton(this, ODComboPage_DeleteSel, wxT("Delete &selection")); sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); - btn = new wxButton(this, ODComboPage_Clear, _T("&Clear")); + btn = new wxButton(this, ODComboPage_Clear, wxT("&Clear")); sizerMiddle->Add(btn, 0, wxALL | wxGROW, 5); // right pane @@ -464,8 +477,6 @@ void ODComboboxWidgetsPage::CreateContent() Reset(); SetSizer(sizerTop); - - sizerTop->Fit(this); } // ---------------------------------------------------------------------------- @@ -559,7 +570,7 @@ void ODComboboxWidgetsPage::OnButtonChange(wxCommandEvent& WXUNUSED(event)) #ifndef __WXGTK__ m_combobox->SetString(sel, m_textChange->GetValue()); #else - wxLogMessage(_T("Not implemented in wxGTK")); + wxLogMessage(wxT("Not implemented in wxGTK")); #endif } } @@ -598,7 +609,7 @@ void ODComboboxWidgetsPage::OnButtonInsert(wxCommandEvent& WXUNUSED(event)) if ( !m_textInsert->IsModified() ) { // update the default string - m_textInsert->SetValue(wxString::Format(_T("test item %u"), ++s_item)); + m_textInsert->SetValue(wxString::Format(wxT("test item %u"), ++s_item)); } if (m_combobox->GetSelection() >= 0) @@ -613,7 +624,7 @@ void ODComboboxWidgetsPage::OnButtonAdd(wxCommandEvent& WXUNUSED(event)) if ( !m_textAdd->IsModified() ) { // update the default string - m_textAdd->SetValue(wxString::Format(_T("test item %u"), ++s_item)); + m_textAdd->SetValue(wxString::Format(wxT("test item %u"), ++s_item)); } m_combobox->Append(s); @@ -624,15 +635,15 @@ void ODComboboxWidgetsPage::OnButtonAddMany(wxCommandEvent& WXUNUSED(event)) // "many" means 1000 here for ( unsigned int n = 0; n < 1000; n++ ) { - m_combobox->Append(wxString::Format(_T("item #%u"), n)); + m_combobox->Append(wxString::Format(wxT("item #%u"), n)); } } void ODComboboxWidgetsPage::OnButtonAddSeveral(wxCommandEvent& WXUNUSED(event)) { - m_combobox->Append(_T("First")); - m_combobox->Append(_T("another one")); - m_combobox->Append(_T("and the last (very very very very very very very very very very long) one")); + m_combobox->Append(wxT("First")); + m_combobox->Append(wxT("another one")); + m_combobox->Append(wxT("and the last (very very very very very very very very very very long) one")); } void ODComboboxWidgetsPage::OnTextPopupWidth(wxCommandEvent& WXUNUSED(event)) @@ -688,13 +699,13 @@ void ODComboboxWidgetsPage::OnTextButtonAll(wxCommandEvent& WXUNUSED(event)) void ODComboboxWidgetsPage::OnUpdateUICurText(wxUpdateUIEvent& event) { if (m_combobox) - event.SetText( wxString::Format(_T("%d"), m_combobox->GetSelection()) ); + event.SetText( wxString::Format(wxT("%d"), m_combobox->GetSelection()) ); } void ODComboboxWidgetsPage::OnUpdateUIInsertionPointText(wxUpdateUIEvent& event) { if (m_combobox) - event.SetText( wxString::Format(_T("%ld"), m_combobox->GetInsertionPoint()) ); + event.SetText( wxString::Format(wxT("%ld"), m_combobox->GetInsertionPoint()) ); } void ODComboboxWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& event) @@ -751,22 +762,26 @@ void ODComboboxWidgetsPage::OnComboText(wxCommandEvent& event) wxString s = event.GetString(); wxASSERT_MSG( s == m_combobox->GetValue(), - _T("event and combobox values should be the same") ); + wxT("event and combobox values should be the same") ); if (event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER) - wxLogMessage(_T("OwnerDrawnCombobox enter pressed (now '%s')"), s.c_str()); + { + wxLogMessage(wxT("OwnerDrawnCombobox enter pressed (now '%s')"), s.c_str()); + } else - wxLogMessage(_T("OwnerDrawnCombobox text changed (now '%s')"), s.c_str()); + { + wxLogMessage(wxT("OwnerDrawnCombobox text changed (now '%s')"), s.c_str()); + } } void ODComboboxWidgetsPage::OnComboBox(wxCommandEvent& event) { long sel = event.GetInt(); - m_textDelete->SetValue(wxString::Format(_T("%ld"), sel)); + m_textDelete->SetValue(wxString::Format(wxT("%ld"), sel)); - wxLogMessage(_T("OwnerDrawnCombobox item %ld selected"), sel); + wxLogMessage(wxT("OwnerDrawnCombobox item %ld selected"), sel); - wxLogMessage(_T("OwnerDrawnCombobox GetValue(): %s"), m_combobox->GetValue().c_str() ); + wxLogMessage(wxT("OwnerDrawnCombobox GetValue(): %s"), m_combobox->GetValue().c_str() ); } void ODComboboxWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event) @@ -833,4 +848,14 @@ wxBitmap ODComboboxWidgetsPage::CreateBitmap(const wxColour& colour) return bmp; } +void ODComboboxWidgetsPage::OnDropDown(wxCommandEvent& WXUNUSED(event)) +{ + wxLogMessage(wxT("Combobox dropped down")); +} + +void ODComboboxWidgetsPage::OnCloseUp(wxCommandEvent& WXUNUSED(event)) +{ + wxLogMessage(wxT("Combobox closed up")); +} + #endif //wxUSE_ODCOMBOBOX