Clean up status bar sample.

No real changes, just:
 - Fix code which couldn't compile in USE_MDI_PARENT_FRAME case
 - Use wxMenu::AppendCheckItem() instead of Append(..., true)
 - Remove unnecessary #ifdef __WXMAC__
 - Wrap excessively long lines

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61988 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-09-21 12:59:56 +00:00
parent 0a84f928e9
commit 06a0d3eaaf

View File

@@ -2,7 +2,6 @@
// Name: statbar.cpp // Name: statbar.cpp
// Purpose: wxStatusBar sample // Purpose: wxStatusBar sample
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by:
// Created: 04.02.00 // Created: 04.02.00
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) Vadim Zeitlin // Copyright: (c) Vadim Zeitlin
@@ -144,16 +143,15 @@ private:
}; };
// Define a new frame type: this is going to be our main frame // Define a new frame type: this is going to be our main frame
#ifdef USE_MDI_PARENT_FRAME
class MyFrame : public wxMDIParentFrame
#else
class MyFrame : public wxFrame class MyFrame : public wxFrame
#endif
{ {
public: public:
// ctor(s) // ctor(s)
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
#ifdef USE_MDI_PARENT_FRAME
class MyFrame : public wxMDIParentFrame
#else
virtual ~MyFrame();
#endif
// event handlers (these functions should _not_ be virtual) // event handlers (these functions should _not_ be virtual)
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
@@ -278,7 +276,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_UPDATE_UI_RANGE(StatusBar_SetFields, StatusBar_ResetFieldsWidth, EVT_UPDATE_UI_RANGE(StatusBar_SetFields, StatusBar_ResetFieldsWidth,
MyFrame::OnUpdateForDefaultStatusbar) MyFrame::OnUpdateForDefaultStatusbar)
EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle) EVT_UPDATE_UI(StatusBar_Toggle, MyFrame::OnUpdateStatusBarToggle)
EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal, StatusBar_SetPaneStyleRaised, EVT_UPDATE_UI_RANGE(StatusBar_SetPaneStyleNormal,
StatusBar_SetPaneStyleRaised,
MyFrame::OnUpdateSetPaneStyle) MyFrame::OnUpdateSetPaneStyle)
EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip, StatusBar_SetStyleShowTips, EVT_UPDATE_UI_RANGE(StatusBar_SetStyleSizeGrip, StatusBar_SetStyleShowTips,
MyFrame::OnUpdateSetStyle) MyFrame::OnUpdateSetStyle)
@@ -337,9 +336,9 @@ bool MyApp::OnInit()
// frame constructor // frame constructor
MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
#ifdef USE_MDI_PARENT_FRAME #ifdef USE_MDI_PARENT_FRAME
: wxMDIParentFrame((wxWindow *)NULL, wxID_ANY, title, pos, size) : wxMDIParentFrame(NULL, wxID_ANY, title, pos, size)
#else #else
: wxFrame((wxWindow *)NULL, wxID_ANY, title, pos, size) : wxFrame(NULL, wxID_ANY, title, pos, size)
#endif #endif
{ {
SetIcon(wxICON(sample)); SetIcon(wxICON(sample));
@@ -347,26 +346,30 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
m_statbarPaneStyle = wxSB_NORMAL; m_statbarPaneStyle = wxSB_NORMAL;
m_field = 1; m_field = 1;
#ifdef __WXMAC__
// we need this in order to allow the about menu relocation, since ABOUT is
// not the default id of the about menu
wxApp::s_macAboutMenuItemId = StatusBar_About;
#endif
// create a menu bar // create a menu bar
wxMenu *menuFile = new wxMenu; wxMenu *menuFile = new wxMenu;
menuFile->Append(StatusBar_Quit, wxT("E&xit\tAlt-X"), wxT("Quit this program")); menuFile->Append(StatusBar_Quit, wxT("E&xit\tAlt-X"),
wxT("Quit this program"));
wxMenu *statbarMenu = new wxMenu; wxMenu *statbarMenu = new wxMenu;
wxMenu *statbarStyleMenu = new wxMenu; wxMenu *statbarStyleMenu = new wxMenu;
statbarStyleMenu->Append(StatusBar_SetStyleSizeGrip, wxT("wxSTB_SIZE_GRIP"), wxT("Toggles the wxSTB_SIZE_GRIP style"), true); statbarStyleMenu->Append(StatusBar_SetStyleSizeGrip, wxT("wxSTB_SIZE_GRIP"),
statbarStyleMenu->Append(StatusBar_SetStyleShowTips, wxT("wxSTB_SHOW_TIPS"), wxT("Toggles the wxSTB_SHOW_TIPS style"), true); wxT("Toggles the wxSTB_SIZE_GRIP style"), true);
statbarStyleMenu->Append(StatusBar_SetStyleShowTips, wxT("wxSTB_SHOW_TIPS"),
wxT("Toggles the wxSTB_SHOW_TIPS style"), true);
statbarStyleMenu->AppendSeparator(); statbarStyleMenu->AppendSeparator();
statbarStyleMenu->Append(StatusBar_SetStyleEllipsizeStart, wxT("wxSTB_ELLIPSIZE_START"), wxT("Toggles the wxSTB_ELLIPSIZE_START style"), true); statbarStyleMenu->AppendCheckItem(StatusBar_SetStyleEllipsizeStart,
statbarStyleMenu->Append(StatusBar_SetStyleEllipsizeMiddle, wxT("wxSTB_ELLIPSIZE_MIDDLE"), wxT("Toggles the wxSTB_ELLIPSIZE_MIDDLE style"), true); wxT("wxSTB_ELLIPSIZE_START"),
statbarStyleMenu->Append(StatusBar_SetStyleEllipsizeEnd, wxT("wxSTB_ELLIPSIZE_END"), wxT("Toggles the wxSTB_ELLIPSIZE_END style"), true); wxT("Toggle wxSTB_ELLIPSIZE_START style"));
statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Status bar style"), statbarStyleMenu); statbarStyleMenu->AppendCheckItem(StatusBar_SetStyleEllipsizeMiddle,
wxT("wxSTB_ELLIPSIZE_MIDDLE"),
wxT("Toggle wxSTB_ELLIPSIZE_MIDDLE style"));
statbarStyleMenu->AppendCheckItem(StatusBar_SetStyleEllipsizeEnd,
wxT("wxSTB_ELLIPSIZE_END"),
wxT("Toggle wxSTB_ELLIPSIZE_END style"));
statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Status bar style"),
statbarStyleMenu);
statbarMenu->AppendSeparator(); statbarMenu->AppendSeparator();
statbarMenu->Append(StatusBar_SetField, "Set active field &number\tCtrl-N", statbarMenu->Append(StatusBar_SetField, "Set active field &number\tCtrl-N",
@@ -382,25 +385,42 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
statbarMenu->Append(StatusBar_SetFields, wxT("&Set field count\tCtrl-C"), statbarMenu->Append(StatusBar_SetFields, wxT("&Set field count\tCtrl-C"),
wxT("Set the number of status bar fields")); wxT("Set the number of status bar fields"));
statbarMenu->Append(StatusBar_SetFont, wxT("&Set field font\tCtrl-F"), statbarMenu->Append(StatusBar_SetFont, wxT("&Set field font\tCtrl-F"),
wxT("Set the font to use for rendering status bar fields")); wxT("Set the font to use for status bar fields"));
wxMenu *statbarPaneStyleMenu = new wxMenu; wxMenu *statbarPaneStyleMenu = new wxMenu;
statbarPaneStyleMenu->Append(StatusBar_SetPaneStyleNormal, wxT("&Normal"), wxT("Sets the style of the first field to normal (sunken) look"), true); statbarPaneStyleMenu->AppendCheckItem
statbarPaneStyleMenu->Append(StatusBar_SetPaneStyleFlat, wxT("&Flat"), wxT("Sets the style of the first field to flat look"), true); (
statbarPaneStyleMenu->Append(StatusBar_SetPaneStyleRaised, wxT("&Raised"), wxT("Sets the style of the first field to raised look"), true); StatusBar_SetPaneStyleNormal,
statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Field style"), statbarPaneStyleMenu); wxT("&Normal"),
wxT("Sets the style of the first field to normal (sunken) look")
);
statbarPaneStyleMenu->AppendCheckItem
(
StatusBar_SetPaneStyleFlat,
wxT("&Flat"),
wxT("Sets the style of the first field to flat look")
);
statbarPaneStyleMenu->AppendCheckItem
(
StatusBar_SetPaneStyleRaised,
wxT("&Raised"),
wxT("Sets the style of the first field to raised look")
);
statbarMenu->Append(StatusBar_SetPaneStyle, wxT("Field style"),
statbarPaneStyleMenu);
statbarMenu->Append(StatusBar_ResetFieldsWidth, wxT("Reset field widths"), statbarMenu->Append(StatusBar_ResetFieldsWidth, wxT("Reset field widths"),
wxT("Sets all fields to the same width")); wxT("Sets all fields to the same width"));
statbarMenu->AppendSeparator(); statbarMenu->AppendSeparator();
statbarMenu->Append(StatusBar_Toggle, wxT("&Toggle Status Bar"), statbarMenu->AppendCheckItem(StatusBar_Toggle, wxT("&Toggle Status Bar"),
wxT("Toggle the status bar display"), true); wxT("Toggle the status bar display"));
statbarMenu->Append(StatusBar_Recreate, wxT("&Recreate\tCtrl-R"), statbarMenu->Append(StatusBar_Recreate, wxT("&Recreate\tCtrl-R"),
wxT("Toggle status bar format")); wxT("Toggle status bar format"));
wxMenu *helpMenu = new wxMenu; wxMenu *helpMenu = new wxMenu;
helpMenu->Append(StatusBar_About, wxT("&About...\tCtrl-A"), wxT("Show about dialog")); helpMenu->Append(StatusBar_About, wxT("&About...\tCtrl-A"),
wxT("Show about dialog"));
// now append the freshly created menu to the menu bar... // now append the freshly created menu to the menu bar...
wxMenuBar *menuBar = new wxMenuBar(); wxMenuBar *menuBar = new wxMenuBar();
@@ -416,10 +436,6 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
SetStatusText(wxT("Welcome to wxWidgets!")); SetStatusText(wxT("Welcome to wxWidgets!"));
} }
MyFrame::~MyFrame()
{
}
void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind, long style) void MyFrame::DoCreateStatusBar(MyFrame::StatusBarKind kind, long style)
{ {
wxStatusBar *statbarOld = GetStatusBar(); wxStatusBar *statbarOld = GetStatusBar();
@@ -559,7 +575,8 @@ void MyFrame::OnSetStatusFont(wxCommandEvent& WXUNUSED(event))
if (!sb) if (!sb)
return; return;
wxFont fnt = wxGetFontFromUser(this, sb->GetFont(), "Choose statusbar font"); wxFont
fnt = wxGetFontFromUser(this, sb->GetFont(), "Choose status bar font");
if (fnt.IsOk()) if (fnt.IsOk())
{ {
sb->SetFont(fnt); sb->SetFont(fnt);
@@ -633,12 +650,12 @@ void MyFrame::OnSetStatusFields(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnResetFieldsWidth(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnResetFieldsWidth(wxCommandEvent& WXUNUSED(event))
{ {
wxStatusBar *pStat = GetStatusBar(); wxStatusBar *pStat = GetStatusBar();
if (!pStat) if ( !pStat )
return; return;
int n = pStat->GetFieldsCount(); const int n = pStat->GetFieldsCount();
pStat->SetStatusWidths(n, NULL); pStat->SetStatusWidths(n, NULL);
for (int i=0; i<n; i++) for ( int i = 0; i < n; i++ )
pStat->SetStatusText("same size", i); pStat->SetStatusText("same size", i);
} }
@@ -766,7 +783,8 @@ void MyFrame::OnSetStyle(wxCommandEvent& event)
if (GetStatusBar()) if (GetStatusBar())
oldStyle = GetStatusBar()->GetWindowStyle(); oldStyle = GetStatusBar()->GetWindowStyle();
#define STB_ELLIPSIZE_MASK (wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END) #define STB_ELLIPSIZE_MASK \
(wxSTB_ELLIPSIZE_START|wxSTB_ELLIPSIZE_MIDDLE|wxSTB_ELLIPSIZE_END)
long newStyle = oldStyle; long newStyle = oldStyle;
long newStyleBit = 0; long newStyleBit = 0;
@@ -939,7 +957,9 @@ void MyStatusBar::OnSize(wxSizeEvent& event)
} }
#if wxUSE_CHECKBOX #if wxUSE_CHECKBOX
m_checkbox->SetSize(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4); wxRect rectCheck = rect;
rectCheck.Deflate(2);
m_checkbox->SetSize(rectCheck);
#endif #endif
GetFieldRect(Field_Bitmap, rect); GetFieldRect(Field_Bitmap, rect);