From 294ea16de3359844cb884baad219b40ea04fac48 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 17 Mar 2005 23:45:24 +0000 Subject: [PATCH] implemented wxMenuBar ctor taking array of menus/titles for all ports; added optional flags argument to it (patch 1162726) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32880 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/menu.tex | 6 +++--- include/wx/cocoa/menu.h | 1 + include/wx/gtk/menu.h | 4 +++- include/wx/gtk1/menu.h | 4 +++- include/wx/mac/carbon/menu.h | 2 +- include/wx/mac/classic/menu.h | 2 +- include/wx/motif/menu.h | 4 ++-- include/wx/msw/menu.h | 2 +- include/wx/os2/menu.h | 1 + include/wx/palmos/menu.h | 2 +- include/wx/univ/menu.h | 1 + src/cocoa/menu.mm | 8 ++++++++ src/gtk/menu.cpp | 36 ++++++++++++++--------------------- src/gtk1/menu.cpp | 36 ++++++++++++++--------------------- src/mac/carbon/menu.cpp | 2 +- src/mac/classic/menu.cpp | 2 +- src/motif/menu.cpp | 4 ++-- src/msw/menu.cpp | 2 +- src/os2/menu.cpp | 1 + src/palmos/menu.cpp | 2 +- src/univ/menu.cpp | 8 ++++++++ 21 files changed, 69 insertions(+), 61 deletions(-) diff --git a/docs/latex/wx/menu.tex b/docs/latex/wx/menu.tex index 6e0f65b9a9..72c93feb33 100644 --- a/docs/latex/wx/menu.tex +++ b/docs/latex/wx/menu.tex @@ -702,7 +702,7 @@ menu shortcuts may cease to work. Default constructor. -\func{}{wxMenuBar}{\param{int}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}} +\func{}{wxMenuBar}{\param{size\_t}{ n}, \param{wxMenu*}{ menus[]}, \param{const wxString }{titles[]}, \param{long }{style = 0}} Construct a menu bar from arrays of menus and titles. @@ -718,10 +718,10 @@ menu bar.} \docparam{style}{If {\tt wxMB\_DOCKABLE} the menu bar can be detached (wxGTK only).} \pythonnote{Only the default constructor is supported in wxPython. -Use wxMenuBar.Append instead.} +Use \helpref{wxMenuBar::Append}{wxmenubarappend} instead.} \perlnote{wxPerl only supports the first constructor: -use {\tt Append} instead.} +use \helpref{wxMenuBar::Append}{wxmenubarappend} instead.} \membersection{wxMenuBar::\destruct{wxMenuBar}}\label{wxmenubardtor} diff --git a/include/wx/cocoa/menu.h b/include/wx/cocoa/menu.h index e05cd49d70..965008536e 100644 --- a/include/wx/cocoa/menu.h +++ b/include/wx/cocoa/menu.h @@ -78,6 +78,7 @@ class WXDLLEXPORT wxMenuBar : public wxMenuBarBase, public wxCocoaNSMenu public: // ctors and dtor wxMenuBar(long style = 0) { Create(style); } + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0) bool Create(long style = 0); virtual ~wxMenuBar(); diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index a154a64e21..e28b4477e7 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -24,7 +24,7 @@ public: // ctors wxMenuBar(); wxMenuBar(long style); - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); virtual ~wxMenuBar(); // implement base class (pure) virtuals @@ -56,6 +56,8 @@ public: wxWindow *m_invokingWindow; private: + void Init(size_t n, wxMenu *menus[], const wxString titles[], long style); + DECLARE_DYNAMIC_CLASS(wxMenuBar) }; diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index a154a64e21..e28b4477e7 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -24,7 +24,7 @@ public: // ctors wxMenuBar(); wxMenuBar(long style); - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); virtual ~wxMenuBar(); // implement base class (pure) virtuals @@ -56,6 +56,8 @@ public: wxWindow *m_invokingWindow; private: + void Init(size_t n, wxMenu *menus[], const wxString titles[], long style); + DECLARE_DYNAMIC_CLASS(wxMenuBar) }; diff --git a/include/wx/mac/carbon/menu.h b/include/wx/mac/carbon/menu.h index 5718b3950b..112c6c19e1 100644 --- a/include/wx/mac/carbon/menu.h +++ b/include/wx/mac/carbon/menu.h @@ -108,7 +108,7 @@ public: // unused under MSW wxMenuBar(long style); // menubar takes ownership of the menus arrays but copies the titles - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); virtual ~wxMenuBar(); // menubar construction diff --git a/include/wx/mac/classic/menu.h b/include/wx/mac/classic/menu.h index 854a70d107..bc0a50125e 100644 --- a/include/wx/mac/classic/menu.h +++ b/include/wx/mac/classic/menu.h @@ -108,7 +108,7 @@ public: // unused under MSW wxMenuBar(long style); // menubar takes ownership of the menus arrays but copies the titles - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); virtual ~wxMenuBar(); // menubar construction diff --git a/include/wx/motif/menu.h b/include/wx/motif/menu.h index 85cb814dc5..b4f94426d1 100644 --- a/include/wx/motif/menu.h +++ b/include/wx/motif/menu.h @@ -117,8 +117,8 @@ class wxMenuBar : public wxMenuBarBase public: wxMenuBar() { Init(); } wxMenuBar(long WXUNUSED(style)) { Init(); } - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); - wxMenuBar(int n, wxMenu *menus[], const wxArrayString& titles); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); + wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long style = 0); virtual ~wxMenuBar(); // implement base class (pure) virtuals diff --git a/include/wx/msw/menu.h b/include/wx/msw/menu.h index 9fff22c1fa..f049ba8f41 100644 --- a/include/wx/msw/menu.h +++ b/include/wx/msw/menu.h @@ -165,7 +165,7 @@ public: // unused under MSW wxMenuBar(long style); // menubar takes ownership of the menus arrays but copies the titles - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); virtual ~wxMenuBar(); // menubar construction diff --git a/include/wx/os2/menu.h b/include/wx/os2/menu.h index b088026c21..0505afc347 100644 --- a/include/wx/os2/menu.h +++ b/include/wx/os2/menu.h @@ -194,6 +194,7 @@ public: wxMenuBar( int n ,wxMenu* vMenus[] ,const wxString sTitles[] + ,long lStyle = 0 ); virtual ~wxMenuBar(); diff --git a/include/wx/palmos/menu.h b/include/wx/palmos/menu.h index 77ab82badc..bca5475b47 100644 --- a/include/wx/palmos/menu.h +++ b/include/wx/palmos/menu.h @@ -146,7 +146,7 @@ public: wxMenuBar(long style); // menubar takes ownership of the menus arrays but copies the titles - wxMenuBar(int n, wxMenu *menus[], const wxString titles[]); + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0); virtual ~wxMenuBar(); // menubar construction diff --git a/include/wx/univ/menu.h b/include/wx/univ/menu.h index 6447a0c36a..ba7d0418b7 100644 --- a/include/wx/univ/menu.h +++ b/include/wx/univ/menu.h @@ -147,6 +147,7 @@ class WXDLLEXPORT wxMenuBar : public wxMenuBarBase public: // ctors and dtor wxMenuBar(long WXUNUSED(style) = 0) { Init(); } + wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style = 0) virtual ~wxMenuBar(); // implement base class virtuals diff --git a/src/cocoa/menu.mm b/src/cocoa/menu.mm index 529f422350..c39d49cb0b 100644 --- a/src/cocoa/menu.mm +++ b/src/cocoa/menu.mm @@ -128,6 +128,14 @@ bool wxMenuBar::Create(long style) return true; } +wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) +{ + Create(style); + + for(size_t i = 0; i < n; ++i ) + Append(menus[i], titles[i]); +} + wxMenuBar::~wxMenuBar() { [m_cocoaNSMenu release]; diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 82956da0a6..7922dd438b 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -170,7 +170,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu ) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) -wxMenuBar::wxMenuBar( long style ) +void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style) { // the parent window is known after wxFrame::SetMenu() m_needParent = FALSE; @@ -203,32 +203,24 @@ wxMenuBar::wxMenuBar( long style ) PostCreation(); ApplyWidgetStyle(); + + for (size_t i = 0; i < n; ++i ) + Append(menus[i], titles[i]); } -wxMenuBar::wxMenuBar() +wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style) { - // the parent window is known after wxFrame::SetMenu() - m_needParent = FALSE; - m_style = 0; - m_invokingWindow = (wxWindow*) NULL; - - if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || - !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("menubar") )) - { - wxFAIL_MSG( wxT("wxMenuBar creation failed") ); - return; - } - - m_menubar = gtk_menu_bar_new(); -#ifndef __WXGTK20__ - m_accel = gtk_accel_group_new(); -#endif - - m_widget = GTK_WIDGET(m_menubar); + Init(n, menus, titles, style); +} - PostCreation(); +wxMenuBar::wxMenuBar(long style) +{ + Init(0, NULL, NULL, style); +} - ApplyWidgetStyle(); +wxMenuBar::wxMenuBar() +{ + Init(0, NULL, NULL, 0); } wxMenuBar::~wxMenuBar() diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 82956da0a6..7922dd438b 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -170,7 +170,7 @@ static void gtk_menu_open_callback( GtkWidget *widget, wxMenu *menu ) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) -wxMenuBar::wxMenuBar( long style ) +void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long style) { // the parent window is known after wxFrame::SetMenu() m_needParent = FALSE; @@ -203,32 +203,24 @@ wxMenuBar::wxMenuBar( long style ) PostCreation(); ApplyWidgetStyle(); + + for (size_t i = 0; i < n; ++i ) + Append(menus[i], titles[i]); } -wxMenuBar::wxMenuBar() +wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style) { - // the parent window is known after wxFrame::SetMenu() - m_needParent = FALSE; - m_style = 0; - m_invokingWindow = (wxWindow*) NULL; - - if (!PreCreation( (wxWindow*) NULL, wxDefaultPosition, wxDefaultSize ) || - !CreateBase( (wxWindow*) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, wxT("menubar") )) - { - wxFAIL_MSG( wxT("wxMenuBar creation failed") ); - return; - } - - m_menubar = gtk_menu_bar_new(); -#ifndef __WXGTK20__ - m_accel = gtk_accel_group_new(); -#endif - - m_widget = GTK_WIDGET(m_menubar); + Init(n, menus, titles, style); +} - PostCreation(); +wxMenuBar::wxMenuBar(long style) +{ + Init(0, NULL, NULL, style); +} - ApplyWidgetStyle(); +wxMenuBar::wxMenuBar() +{ + Init(0, NULL, NULL, 0); } wxMenuBar::~wxMenuBar() diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 4761918b33..11cb225d9b 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -589,7 +589,7 @@ wxMenuBar::wxMenuBar( long WXUNUSED(style) ) } -wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) +wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) { Init(); diff --git a/src/mac/classic/menu.cpp b/src/mac/classic/menu.cpp index d846775cd6..57dfedd102 100644 --- a/src/mac/classic/menu.cpp +++ b/src/mac/classic/menu.cpp @@ -463,7 +463,7 @@ wxMenuBar::wxMenuBar( long WXUNUSED(style) ) } -wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) +wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) { Init(); diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index 271a0f5632..8868823110 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -209,7 +209,7 @@ void wxMenuBar::Init() m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } -wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxArrayString& titles) +wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxArrayString& titles, long WXUNUSED(style)) { wxASSERT( size_t(n) == titles.GetCount() ); @@ -220,7 +220,7 @@ wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxArrayString& titles) m_menus.Append(menus[i]); } -wxMenuBar::wxMenuBar(int n, wxMenu *menus[], const wxString titles[]) +wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) { Init(); diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 3f6cb15334..d92e189b24 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -697,7 +697,7 @@ wxMenuBar::wxMenuBar( long WXUNUSED(style) ) Init(); } -wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) +wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) { Init(); diff --git a/src/os2/menu.cpp b/src/os2/menu.cpp index ccb4be4251..59307fbdc3 100644 --- a/src/os2/menu.cpp +++ b/src/os2/menu.cpp @@ -697,6 +697,7 @@ wxMenuBar::wxMenuBar( int nCount , wxMenu* vMenus[] , const wxString sTitles[] +, long WXUNUSED(lStyle) ) { Init(); diff --git a/src/palmos/menu.cpp b/src/palmos/menu.cpp index de25c0492b..74c9861d41 100644 --- a/src/palmos/menu.cpp +++ b/src/palmos/menu.cpp @@ -332,7 +332,7 @@ wxMenuBar::wxMenuBar( long WXUNUSED(style) ) { } -wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[]) +wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) { } diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index acad3b9451..8e3957ddf7 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -1678,6 +1678,14 @@ void wxMenuBar::Init() m_shouldShowMenu = false; } +wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long WXUNUSED(style)) +{ + Init(); + + for (size_t i = 0; i < n; ++i ) + Append(menus[i], titles[i]); +} + void wxMenuBar::Attach(wxFrame *frame) { // maybe you really wanted to call Detach()? -- 2.45.2