X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0dbe4363e45829594365f1f478cdb7540cd78ee9..6f026b5b63fe7ccb025e84509886f74772b9df13:/samples/combo/combo.cpp diff --git a/samples/combo/combo.cpp b/samples/combo/combo.cpp index d034aff241..ecf48986a6 100644 --- a/samples/combo/combo.cpp +++ b/samples/combo/combo.cpp @@ -4,7 +4,6 @@ // Author: Jaakko Salli // Modified by: // Created: Apr-30-2006 -// RCS-ID: $Id$ // Copyright: (c) Jaakko Salli // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -45,7 +44,7 @@ // the application icon (under Windows and OS/2 it is in resources and even // though we could still include the XPM here it would be unused) -#if !defined(__WXMSW__) && !defined(__WXPM__) +#ifndef wxHAS_IMAGES_IN_RESOURCES #include "../sample.xpm" #endif @@ -125,6 +124,7 @@ enum // simple menu events like this the static method is much simpler. BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_TEXT(wxID_ANY,MyFrame::OnComboBoxUpdate) + EVT_TEXT_ENTER(wxID_ANY,MyFrame::OnComboBoxUpdate) EVT_COMBOBOX(wxID_ANY,MyFrame::OnComboBoxUpdate) EVT_MENU(ComboCtrl_Compare, MyFrame::OnShowComparison) @@ -188,29 +188,29 @@ public: r.Deflate(3); r.height -= 2; - int penStyle = wxSOLID; + wxPenStyle penStyle = wxPENSTYLE_SOLID; if ( item == 1 ) - penStyle = wxTRANSPARENT; + penStyle = wxPENSTYLE_TRANSPARENT; else if ( item == 2 ) - penStyle = wxDOT; + penStyle = wxPENSTYLE_DOT; else if ( item == 3 ) - penStyle = wxLONG_DASH; + penStyle = wxPENSTYLE_LONG_DASH; else if ( item == 4 ) - penStyle = wxSHORT_DASH; + penStyle = wxPENSTYLE_SHORT_DASH; else if ( item == 5 ) - penStyle = wxDOT_DASH; + penStyle = wxPENSTYLE_DOT_DASH; else if ( item == 6 ) - penStyle = wxBDIAGONAL_HATCH; + penStyle = wxPENSTYLE_BDIAGONAL_HATCH; else if ( item == 7 ) - penStyle = wxCROSSDIAG_HATCH; + penStyle = wxPENSTYLE_CROSSDIAG_HATCH; else if ( item == 8 ) - penStyle = wxFDIAGONAL_HATCH; + penStyle = wxPENSTYLE_FDIAGONAL_HATCH; else if ( item == 9 ) - penStyle = wxCROSS_HATCH; + penStyle = wxPENSTYLE_CROSS_HATCH; else if ( item == 10 ) - penStyle = wxHORIZONTAL_HATCH; + penStyle = wxPENSTYLE_HORIZONTAL_HATCH; else if ( item == 11 ) - penStyle = wxVERTICAL_HATCH; + penStyle = wxPENSTYLE_VERTICAL_HATCH; wxPen pen( dc.GetTextForeground(), 3, penStyle ); @@ -376,6 +376,14 @@ public: virtual void Init() { } + virtual ~TreeCtrlComboPopup() + { + if (!m_isBeingDeleted) + { + wxMessageBox("error wxTreeCtrl::Destroy() was not called"); + } + SendDestroyEvent(); + } virtual bool Create( wxWindow* parent ) { @@ -615,7 +623,7 @@ MyFrame::MyFrame(const wxString& title) // the "About" item should be in the help menu wxMenu *helpMenu = new wxMenu; - helpMenu->Append(ComboCtrl_About, wxT("&About...\tF1"), wxT("Show about dialog")); + helpMenu->Append(ComboCtrl_About, wxT("&About\tF1"), wxT("Show about dialog")); fileMenu->Append(ComboCtrl_Compare, wxT("&Compare against wxComboBox..."), wxT("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes.")); @@ -753,6 +761,11 @@ MyFrame::MyFrame(const wxString& title) rowSizer = new wxBoxSizer( wxHORIZONTAL ); cc = new wxComboCtrlWithCustomPopupAnim(); + + // Let's set a custom style for the contained wxTextCtrl. We need to + // use two-step creation for it to work properly. + cc->SetTextCtrlStyle(wxTE_RIGHT); + cc->Create(panel, wxID_ANY, wxEmptyString); // Make sure we use popup that allows focusing the listview. @@ -913,7 +926,7 @@ MyFrame::MyFrame(const wxString& title) panel->SetSizer( topSizer ); topSizer->SetSizeHints( panel ); - SetSize(740,400); + Fit(); Centre(); } @@ -925,14 +938,19 @@ void MyFrame::OnComboBoxUpdate( wxCommandEvent& event ) if ( !event.GetEventObject()->IsKindOf(CLASSINFO(wxComboCtrl)) ) return; - if ( event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED ) + if ( event.GetEventType() == wxEVT_COMBOBOX ) { wxLogDebug(wxT("EVT_COMBOBOX(id=%i,selection=%i)"),event.GetId(),event.GetSelection()); } - else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED ) + else if ( event.GetEventType() == wxEVT_TEXT ) { wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event.GetId(),event.GetString().c_str()); } + else if ( event.GetEventType() == wxEVT_TEXT_ENTER ) + { + wxLogDebug("EVT_TEXT_ENTER(id=%i,string=\"%s\")", + event.GetId(), event.GetString().c_str()); + } } void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) @@ -962,7 +980,8 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) groupSizer = new wxStaticBoxSizer(new wxStaticBox(dlg,wxID_ANY,wxT(" wxOwnerDrawnComboBox ")), wxVERTICAL); - groupSizer->Add( new wxStaticText(dlg,wxID_ANY,wxT("Writable, sorted:")), 0, + groupSizer->Add( new wxStaticText(dlg, wxID_ANY, + wxT("Writable, with margins, sorted:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxEXPAND, border ); odc = new wxOwnerDrawnComboBox(dlg,wxID_ANY,wxEmptyString, @@ -974,12 +993,14 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) odc->Append(wxT("H - Appended Item")); // test sorting in append odc->SetValue(wxT("Dot Dash")); - - groupSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); + odc->SetMargins(15, 10); + groupSizer->Add( odc, 0, wxALIGN_CENTER_VERTICAL|wxALL, border ); + groupSizer->AddStretchSpacer(); // // Readonly ODComboBox - groupSizer->Add( new wxStaticText(dlg,wxID_ANY,wxT("Read-only:")), 0, + groupSizer->Add( new wxStaticText(dlg, wxID_ANY, + wxT("Read-only, big font:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, border ); odc = new wxOwnerDrawnComboBox(dlg,wxID_ANY,wxEmptyString, @@ -988,10 +1009,12 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY ); + odc->SetFont(odc->GetFont().Scale(1.5)); odc->SetValue(wxT("Dot Dash")); odc->SetText(wxT("Dot Dash (Testing SetText)")); - groupSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); + groupSizer->Add( odc, 0, wxALL, border ); + groupSizer->AddStretchSpacer(); // // Disabled ODComboBox @@ -1007,7 +1030,7 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) odc->SetValue(wxT("Dot Dash")); odc->Enable(false); - groupSizer->Add( odc, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); + groupSizer->Add( odc, 3, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); rowSizer->Add( groupSizer, 1, wxEXPAND|wxALL, border ); @@ -1018,7 +1041,8 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) // // wxComboBox // - groupSizer->Add( new wxStaticText(dlg,wxID_ANY,wxT("Writable, sorted:")), 0, + groupSizer->Add( new wxStaticText(dlg,wxID_ANY, + wxT("Writable, with margins, sorted:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT|wxEXPAND, border ); cb = new wxComboBox(dlg,wxID_ANY,wxEmptyString, @@ -1030,12 +1054,14 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) cb->Append(wxT("H - Appended Item")); // test sorting in append cb->SetValue(wxT("Dot Dash")); - - groupSizer->Add( cb, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); + cb->SetMargins(15, 10); + groupSizer->Add( cb, 0, wxALIGN_CENTER_VERTICAL|wxALL, border ); + groupSizer->AddStretchSpacer(); // // Readonly wxComboBox - groupSizer->Add( new wxStaticText(dlg,wxID_ANY,wxT("Read-only:")), 0, + groupSizer->Add( new wxStaticText(dlg, wxID_ANY, + wxT("Read-only, big font:")), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, border ); cb = new wxComboBox(dlg,wxID_ANY,wxEmptyString, @@ -1044,9 +1070,11 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) wxCB_SORT|wxCB_READONLY // wxNO_BORDER|wxCB_READONLY ); + cb->SetFont(cb->GetFont().Scale(1.5)); cb->SetValue(wxT("Dot Dash")); - groupSizer->Add( cb, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); + groupSizer->Add( cb, 0, wxALL, border ); + groupSizer->AddStretchSpacer(); // // Disabled wxComboBox @@ -1062,11 +1090,11 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) cb->SetValue(wxT("Dot Dash")); cb->Enable(false); - groupSizer->Add( cb, 1, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); + groupSizer->Add( cb, 3, wxALIGN_CENTER_VERTICAL|wxEXPAND|wxALL, border ); rowSizer->Add( groupSizer, 1, wxEXPAND|wxALL, border ); - colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, border ); + colSizer->Add( rowSizer, 1, wxEXPAND|wxALL, border ); dlg->SetSizer( colSizer ); colSizer->SetSizeHints( dlg );