X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/443fbbf7ae65aca070ac4aea43742cd1fd5ef07e..de9144361243da20c90b6e40d6b8570c2cb7ec89:/samples/combo/combo.cpp diff --git a/samples/combo/combo.cpp b/samples/combo/combo.cpp index 0deae26b97..419c3e0359 100644 --- a/samples/combo/combo.cpp +++ b/samples/combo/combo.cpp @@ -45,7 +45,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 @@ -86,8 +86,6 @@ public: void OnIdle( wxIdleEvent& event ); - wxCheckBox* m_cbUseAnim; - protected: wxTextCtrl* m_logWin; wxLog* m_logOld; @@ -127,6 +125,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) @@ -378,6 +377,14 @@ public: virtual void Init() { } + virtual ~TreeCtrlComboPopup() + { + if (!m_isBeingDeleted) + { + wxMessageBox("error wxTreeCtrl::Destroy() was not called"); + } + SendDestroyEvent(); + } virtual bool Create( wxWindow* parent ) { @@ -495,129 +502,22 @@ BEGIN_EVENT_TABLE(TreeCtrlComboPopup, wxTreeCtrl) END_EVENT_TABLE() // ---------------------------------------------------------------------------- -// wxComboCtrl with custom popup animation. We use EVT_TIMER, which is quite -// safe, but requires much more can than doing it in a single function (ie. -// AnimateShow) and using combination of wxSleep and wxSafeYield. +// wxComboCtrl with custom popup animation, using wxWindow::ShowWithEffect(). // ---------------------------------------------------------------------------- -#if wxUSE_TIMER - -#define CUSTOM_COMBOBOX_ANIMATION_DURATION 200 // In milliseconds - -#include "wx/timer.h" - class wxComboCtrlWithCustomPopupAnim : public wxComboCtrl { -public: - - virtual bool AnimateShow( const wxRect& rect, int flags ) - { - MyFrame* myFrame = (MyFrame*) ::wxGetTopLevelParent(this); - - if ( !myFrame->m_cbUseAnim->GetValue() ) - return true; - - m_animStart = ::wxGetLocalTimeMillis(); - m_animRect = rect; - m_animFlags = flags; - - wxScreenDC dc; - - wxBitmap bitmap( rect.width, rect.height, -1 ); - wxMemoryDC memdc( bitmap ); - memdc.Blit( 0, 0, rect.width, rect.height, &dc, rect.x, rect.y ); - memdc.SelectObject(wxNullBitmap); - m_animBackBitmap = bitmap; - - m_animTimer.SetOwner( this, wxID_ANY ); - m_animTimer.Start( 10, wxTIMER_CONTINUOUS ); - - DoOnTimer(); - return false; - } - -private: - void OnTimerEvent( wxTimerEvent& WXUNUSED(event) ) +protected: + virtual bool AnimateShow( const wxRect& rect, int WXUNUSED(flags) ) { - DoOnTimer(); + wxWindow* win = GetPopupWindow(); + win->SetSize(rect); + win->Raise(); // This is needed + win->ShowWithEffect(wxSHOW_EFFECT_BLEND); + return true; } - - void DoOnTimer() - { - bool stopTimer = false; - - wxWindow* popup = GetPopupControl()->GetControl(); - wxScreenDC dc; - const wxRect& rect = m_animRect; - - // Popup was hidden before it was fully shown? - if ( IsPopupWindowState(Hidden) ) - { - stopTimer = true; - } - else - { - wxLongLong t = ::wxGetLocalTimeMillis(); - - int pos = (int) (t-m_animStart).GetLo(); - if ( pos < CUSTOM_COMBOBOX_ANIMATION_DURATION ) - { - // - // Actual animation happens here - // - int width = rect.width; - int height = rect.height; - - int center_x = rect.x + (width/2); - int center_y = rect.y + (height/2); - - double d_height = (double) height; - - dc.SetPen( *wxBLACK_PEN ); - dc.SetBrush( *wxTRANSPARENT_BRUSH ); - - int w = (((pos*256)/CUSTOM_COMBOBOX_ANIMATION_DURATION)*width)/256; - - double ratio = ((double)w / (double)width); - int h = (int)(d_height * ratio); - dc.DrawBitmap( m_animBackBitmap, rect.x, rect.y ); - dc.DrawRectangle( center_x - w/2, center_y - h/2, w, h ); - } - else - { - stopTimer = true; - } - } - - if ( stopTimer ) - { - dc.DrawBitmap( m_animBackBitmap, rect.x, rect.y ); - popup->Move( 0, 0 ); - m_animTimer.Stop(); - DoShowPopup( m_animRect, m_animFlags ); - } - } - - // Popup animation related - wxLongLong m_animStart; - wxTimer m_animTimer; - wxRect m_animRect; - wxBitmap m_animBackBitmap; - int m_animFlags; - - DECLARE_EVENT_TABLE() }; -BEGIN_EVENT_TABLE(wxComboCtrlWithCustomPopupAnim, wxComboCtrl) - EVT_TIMER(wxID_ANY, wxComboCtrlWithCustomPopupAnim::OnTimerEvent) -END_EVENT_TABLE() - -#else - -#define wxComboCtrlWithCustomPopupAnim wxComboCtrl - -#endif - // ---------------------------------------------------------------------------- // wxComboCtrl with entirely custom button action (opens file dialog) // ---------------------------------------------------------------------------- @@ -724,7 +624,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.")); @@ -852,14 +752,21 @@ MyFrame::MyFrame(const wxString& title) // rowSizer = new wxBoxSizer( wxHORIZONTAL ); - rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("List View wxComboCtrl:")), 1, - wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 ); + rowSizer->Add( new wxStaticText(panel, + wxID_ANY, + "List View wxComboCtrl (custom animation):"), + 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 ); rowSizer->Add( new wxStaticText(panel,wxID_ANY,wxT("Tree Ctrl wxComboCtrl:")), 1, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4 ); colSizer->Add( rowSizer, 0, wxEXPAND|wxALL, 5 ); 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. @@ -1010,16 +917,6 @@ MyFrame::MyFrame(const wxString& title) colSizer = new wxBoxSizer( wxVERTICAL ); - wxStaticBoxSizer* sbSizer = new wxStaticBoxSizer( new wxStaticBox(panel, - wxID_ANY, - wxT("Options")), - wxVERTICAL ); - - m_cbUseAnim = new wxCheckBox(panel, wxID_ANY, wxT("Custom popup animation for ListView wxComboCtrl")); - m_cbUseAnim->SetValue(true); - sbSizer->Add( m_cbUseAnim, 0, wxALL, 3 ); - - colSizer->Add( sbSizer, 0, wxEXPAND|wxALL, 3 ); colSizer->AddSpacer(8); colSizer->Add( new wxStaticText(panel, wxID_ANY, wxT("Log Messages:")), 0, wxTOP|wxLEFT, 3 ); colSizer->Add( m_logWin, 1, wxEXPAND|wxALL, 3 ); @@ -1030,7 +927,7 @@ MyFrame::MyFrame(const wxString& title) panel->SetSizer( topSizer ); topSizer->SetSizeHints( panel ); - SetSize(740,400); + Fit(); Centre(); } @@ -1050,6 +947,11 @@ void MyFrame::OnComboBoxUpdate( wxCommandEvent& event ) { wxLogDebug(wxT("EVT_TEXT(id=%i,string=\"%s\")"),event.GetId(),event.GetString().c_str()); } + else if ( event.GetEventType() == wxEVT_COMMAND_TEXT_ENTER ) + { + wxLogDebug("EVT_TEXT_ENTER(id=%i,string=\"%s\")", + event.GetId(), event.GetString().c_str()); + } } void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) ) @@ -1079,7 +981,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, @@ -1091,12 +994,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, @@ -1105,10 +1010,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 @@ -1124,7 +1031,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 ); @@ -1135,7 +1042,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, @@ -1147,12 +1055,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, @@ -1161,9 +1071,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 @@ -1179,11 +1091,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 );