]> git.saurik.com Git - wxWidgets.git/commitdiff
Add test for Push/PopStatusText().
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 6 Aug 2009 00:00:47 +0000 (00:00 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 6 Aug 2009 00:00:47 +0000 (00:00 +0000)
Allow to interactively push and pop status messages for the selected field.

This shows that currently PushStatusText() is completely broken under wxMSW
as it never shows the text being pushed at all because it is "optimized" away
due to an incorrect comparison with the old value (which turns out to be the
new one)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61622 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/statbar/statbar.cpp

index 4fe50b4440853fcbcf827f37decbaf3088f7b629..ec474a05a35b5c8451b6b1780d5bcff583f447e3 100644 (file)
@@ -161,6 +161,8 @@ class MyFrame : public wxMDIParentFrame
 
     void OnSetStatusField(wxCommandEvent& event);
     void OnSetStatusText(wxCommandEvent& event);
+    void OnPushStatusText(wxCommandEvent& event);
+    void OnPopStatusText(wxCommandEvent& event);
 
     void OnResetFieldsWidth(wxCommandEvent& event);
     void OnSetStatusFields(wxCommandEvent& event);
@@ -217,6 +219,8 @@ enum
     StatusBar_SetFields = wxID_HIGHEST+1,
     StatusBar_SetField,
     StatusBar_SetText,
+    StatusBar_PushText,
+    StatusBar_PopText,
     StatusBar_SetFont,
     StatusBar_ResetFieldsWidth,
 
@@ -254,6 +258,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(StatusBar_SetFields, MyFrame::OnSetStatusFields)
     EVT_MENU(StatusBar_SetField, MyFrame::OnSetStatusField)
     EVT_MENU(StatusBar_SetText, MyFrame::OnSetStatusText)
+    EVT_MENU(StatusBar_PushText, MyFrame::OnPushStatusText)
+    EVT_MENU(StatusBar_PopText, MyFrame::OnPopStatusText)
     EVT_MENU(StatusBar_SetFont, MyFrame::OnSetStatusFont)
     EVT_MENU(StatusBar_ResetFieldsWidth, MyFrame::OnResetFieldsWidth)
     EVT_MENU(StatusBar_Recreate, MyFrame::OnRecreateStatusBar)
@@ -367,6 +373,10 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
                         "Set the number of field used by the next commands.");
     statbarMenu->Append(StatusBar_SetText, wxT("Set field &text\tCtrl-T"),
                         wxT("Set the text of the selected field."));
+    statbarMenu->Append(StatusBar_PushText, "P&ush field text\tCtrl-P",
+                        "Push a message on top the selected field.");
+    statbarMenu->Append(StatusBar_PopText, "&Pop field text\tShift-Ctrl-P",
+                        "Restore the previous contents of the selected field.");
     statbarMenu->AppendSeparator();
 
     statbarMenu->Append(StatusBar_SetFields, wxT("&Set field count\tCtrl-C"),
@@ -510,6 +520,39 @@ void MyFrame::OnSetStatusText(wxCommandEvent& WXUNUSED(event))
     sb->SetStatusText(txt, m_field);
 }
 
+// the current depth of the stack used by Push/PopStatusText()
+static int gs_depth = 0;
+
+void MyFrame::OnPushStatusText(wxCommandEvent& WXUNUSED(event))
+{
+    wxStatusBar *sb = GetStatusBar();
+    if (!sb)
+        return;
+
+    static int s_countPush = 0;
+    sb->PushStatusText(wxString::Format
+                       (
+                            "Pushed message #%d (depth = %d)",
+                            ++s_countPush, ++gs_depth
+                       ), m_field);
+}
+
+void MyFrame::OnPopStatusText(wxCommandEvent& WXUNUSED(event))
+{
+    wxStatusBar *sb = GetStatusBar();
+    if (!sb)
+        return;
+
+    if ( !gs_depth )
+    {
+        wxLogStatus("No message to pop.");
+        return;
+    }
+
+    gs_depth--;
+    sb->PopStatusText(m_field);
+}
+
 void MyFrame::OnSetStatusFont(wxCommandEvent& WXUNUSED(event))
 {
     wxStatusBar *sb = GetStatusBar();