]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/combo/combo.cpp
wxArrayStringProperty::m_delimiter default value was missing. Also cleaned up relevan...
[wxWidgets.git] / samples / combo / combo.cpp
index 62ed8af72eaa2c2036758fdd8246d3d31dadb873..145b15fc0fc37efcc0c1321ea0778b8017c91e17 100644 (file)
@@ -86,8 +86,6 @@ public:
     void OnIdle( wxIdleEvent& event );
 
 
     void OnIdle( wxIdleEvent& event );
 
 
-    wxCheckBox*     m_cbUseAnim;
-
 protected:
     wxTextCtrl*     m_logWin;
     wxLog*          m_logOld;
 protected:
     wxTextCtrl*     m_logWin;
     wxLog*          m_logOld;
@@ -107,15 +105,15 @@ private:
 // IDs for the controls and the menu commands
 enum
 {
 // IDs for the controls and the menu commands
 enum
 {
-    ComboControl_Compare = wxID_HIGHEST,
+    ComboCtrl_Compare = wxID_HIGHEST,
 
     // menu items
 
     // menu items
-    ComboControl_Quit = wxID_EXIT,
+    ComboCtrl_Quit = wxID_EXIT,
 
     // it is important for the id corresponding to the "About" command to have
     // this standard value as otherwise it won't be handled properly under Mac
     // (where it is special and put into the "Apple" menu)
 
     // it is important for the id corresponding to the "About" command to have
     // this standard value as otherwise it won't be handled properly under Mac
     // (where it is special and put into the "Apple" menu)
-    ComboControl_About = wxID_ABOUT
+    ComboCtrl_About = wxID_ABOUT
 };
 
 // ----------------------------------------------------------------------------
 };
 
 // ----------------------------------------------------------------------------
@@ -129,9 +127,9 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_TEXT(wxID_ANY,MyFrame::OnComboBoxUpdate)
     EVT_COMBOBOX(wxID_ANY,MyFrame::OnComboBoxUpdate)
 
     EVT_TEXT(wxID_ANY,MyFrame::OnComboBoxUpdate)
     EVT_COMBOBOX(wxID_ANY,MyFrame::OnComboBoxUpdate)
 
-    EVT_MENU(ComboControl_Compare,  MyFrame::OnShowComparison)
-    EVT_MENU(ComboControl_Quit,     MyFrame::OnQuit)
-    EVT_MENU(ComboControl_About,    MyFrame::OnAbout)
+    EVT_MENU(ComboCtrl_Compare,  MyFrame::OnShowComparison)
+    EVT_MENU(ComboCtrl_Quit,     MyFrame::OnQuit)
+    EVT_MENU(ComboCtrl_About,    MyFrame::OnAbout)
 
     EVT_IDLE(MyFrame::OnIdle)
 END_EVENT_TABLE()
 
     EVT_IDLE(MyFrame::OnIdle)
 END_EVENT_TABLE()
@@ -158,7 +156,7 @@ bool MyApp::OnInit()
         return false;
 
     // create the main application window
         return false;
 
     // create the main application window
-    MyFrame *frame = new MyFrame(_T("wxComboCtrl and wxOwnerDrawnComboBox Sample"));
+    MyFrame *frame = new MyFrame(wxT("wxComboCtrl and wxOwnerDrawnComboBox Sample"));
 
     // and show it (the frames, unlike simple controls, are not shown when
     // created initially)
 
     // and show it (the frames, unlike simple controls, are not shown when
     // created initially)
@@ -495,129 +493,22 @@ BEGIN_EVENT_TABLE(TreeCtrlComboPopup, wxTreeCtrl)
 END_EVENT_TABLE()
 
 // ----------------------------------------------------------------------------
 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
 {
 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)
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxComboCtrl with entirely custom button action (opens file dialog)
 // ----------------------------------------------------------------------------
@@ -724,17 +615,17 @@ MyFrame::MyFrame(const wxString& title)
 
     // the "About" item should be in the help menu
     wxMenu *helpMenu = new wxMenu;
 
     // the "About" item should be in the help menu
     wxMenu *helpMenu = new wxMenu;
-    helpMenu->Append(ComboControl_About, _T("&About...\tF1"), _T("Show about dialog"));
+    helpMenu->Append(ComboCtrl_About, wxT("&About...\tF1"), wxT("Show about dialog"));
 
 
-    fileMenu->Append(ComboControl_Compare, _T("&Compare against wxComboBox..."),
-        _T("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
+    fileMenu->Append(ComboCtrl_Compare, wxT("&Compare against wxComboBox..."),
+        wxT("Show some wxOwnerDrawnComboBoxes side-by-side with native wxComboBoxes."));
     fileMenu->AppendSeparator();
     fileMenu->AppendSeparator();
-    fileMenu->Append(ComboControl_Quit, _T("E&xit\tAlt-X"), _T("Quit this program"));
+    fileMenu->Append(ComboCtrl_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program"));
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar();
 
     // now append the freshly created menu to the menu bar...
     wxMenuBar *menuBar = new wxMenuBar();
-    menuBar->Append(fileMenu, _T("&File"));
-    menuBar->Append(helpMenu, _T("&Help"));
+    menuBar->Append(fileMenu, wxT("&File"));
+    menuBar->Append(helpMenu, wxT("&Help"));
 
     // ... and attach this menu bar to the frame
     SetMenuBar(menuBar);
 
     // ... and attach this menu bar to the frame
     SetMenuBar(menuBar);
@@ -743,11 +634,12 @@ MyFrame::MyFrame(const wxString& title)
     wxPanel* panel = new wxPanel(this);
 
     // Prepare log window right away since it shows EVT_TEXTs
     wxPanel* panel = new wxPanel(this);
 
     // Prepare log window right away since it shows EVT_TEXTs
-    m_logWin = new wxTextCtrl( panel, 105, wxEmptyString, wxDefaultPosition,
-                               wxSize(-1,125), wxTE_MULTILINE|wxFULL_REPAINT_ON_RESIZE );
-    m_logWin->SetEditable(false);
-    wxLogTextCtrl* logger = new wxLogTextCtrl( m_logWin );
-    m_logOld = logger->SetActiveTarget( logger );
+    m_logWin = new wxTextCtrl(panel, 105, wxEmptyString,
+                              wxDefaultPosition,
+                              wxSize(-1, 125),
+                              wxTE_MULTILINE);
+    wxLogTextCtrl* logger = new wxLogTextCtrl(m_logWin);
+    m_logOld = logger->SetActiveTarget(logger);
     logger->DisableTimestamp();
 
 
     logger->DisableTimestamp();
 
 
@@ -851,14 +743,21 @@ MyFrame::MyFrame(const wxString& title)
     //
 
     rowSizer = new wxBoxSizer( wxHORIZONTAL );
     //
 
     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,wxT("Tree Ctrl wxComboControl:")), 1,
+    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();
                    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.
     cc->Create(panel, wxID_ANY, wxEmptyString);
 
     // Make sure we use popup that allows focusing the listview.
@@ -1009,16 +908,6 @@ MyFrame::MyFrame(const wxString& title)
 
     colSizer = new wxBoxSizer( wxVERTICAL );
 
 
     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 );
     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 );
@@ -1206,14 +1095,14 @@ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
     wxMessageBox(wxString::Format(
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
 {
     wxMessageBox(wxString::Format(
-                    _T("Welcome to %s!\n")
-                    _T("\n")
-                    _T("This is the wxWidgets wxComboCtrl and wxOwnerDrawnComboBox sample\n")
-                    _T("running under %s."),
+                    wxT("Welcome to %s!\n")
+                    wxT("\n")
+                    wxT("This is the wxWidgets wxComboCtrl and wxOwnerDrawnComboBox sample\n")
+                    wxT("running under %s."),
                     wxVERSION_STRING,
                     wxGetOsDescription().c_str()
                  ),
                     wxVERSION_STRING,
                     wxGetOsDescription().c_str()
                  ),
-                 _T("About wxComboCtrl sample"),
+                 wxT("About wxComboCtrl sample"),
                  wxOK | wxICON_INFORMATION,
                  this);
 }
                  wxOK | wxICON_INFORMATION,
                  this);
 }