From ae53c98c9f71acb0876846b9c5b1e56adfdb6186 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karsten=20Ball=C3=BCder?= Date: Thu, 17 Jun 1999 14:08:00 +0000 Subject: [PATCH] Implemented tearoff menus, please see my posting to wxwin-developers. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 6 ++++++ include/wx/gdicmn.h | 3 +++ include/wx/gtk/choice.h | 3 --- include/wx/gtk/menu.h | 14 ++++++++++++-- include/wx/gtk1/choice.h | 3 --- include/wx/gtk1/menu.h | 14 ++++++++++++-- samples/minimal/minimal.cpp | 4 ++-- src/gtk/app.cpp | 5 +++-- src/gtk/cursor.cpp | 1 + src/gtk/menu.cpp | 26 +++++++++++++++++++++----- src/gtk1/app.cpp | 5 +++-- src/gtk1/cursor.cpp | 1 + src/gtk1/menu.cpp | 26 +++++++++++++++++++++----- 13 files changed, 85 insertions(+), 26 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index ae8cc520a5..1cc239db8b 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -618,7 +618,13 @@ enum wxOrientation */ // use native docking #define wxMB_DOCKABLE 0x0001 +// make all menus tearoff menus, even if not set on per-menu basis +#define wxMB_TEAROFF 0x0002 +/* + * wxMenu style flags + */ +#define wxMENU_TEAROFF 0x0001 /* * Apply to all panel items diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index a3f585fd2d..78d36bd920 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -100,6 +100,9 @@ enum wxStockCursor wxCURSOR_WAIT, wxCURSOR_WATCH, wxCURSOR_BLANK, +#ifdef __WXGTK__ + wxCURSOR_DEFAULT, // standard X11 cursor +#endif #ifdef __X__ // Not yet implemented for Windows wxCURSOR_CROSS_REVERSE, diff --git a/include/wx/gtk/choice.h b/include/wx/gtk/choice.h index 796d625f4b..acd0324c00 100644 --- a/include/wx/gtk/choice.h +++ b/include/wx/gtk/choice.h @@ -16,8 +16,6 @@ #include "wx/defs.h" -#if wxUSE_CHOICE - #include "wx/object.h" #include "wx/list.h" #include "wx/control.h" @@ -99,6 +97,5 @@ public: void ApplyWidgetStyle(); }; -#endif #endif // __GTKCHOICEH__ diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index f09ee3bc04..3638cee90e 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -100,6 +100,7 @@ public: GtkItemFactory *m_factory; wxList m_menus; GtkWidget *m_menubar; + long m_style; }; //----------------------------------------------------------------------------- @@ -112,7 +113,9 @@ class wxMenu : public wxEvtHandler public: wxMenu( const wxString& title = wxEmptyString, - const wxFunction func = (wxFunction) NULL ); + const wxFunction func = (wxFunction) NULL, + long style = 0); + wxMenu( long style ); ~wxMenu(); // operations @@ -182,7 +185,13 @@ public: GtkAccelGroup *m_accel; GtkItemFactory *m_factory; -private: + // used by wxMenuBar + inline long GetStyle(void) const { return m_style; } + private: + // common code for both constructors: + void Init( const wxString& title, + const wxFunction func, + long style); wxString m_title; wxList m_items; @@ -190,6 +199,7 @@ private: wxFunction m_callback; wxEvtHandler *m_eventHandler; void *m_clientData; + long m_style; }; #endif // __GTKMENUH__ diff --git a/include/wx/gtk1/choice.h b/include/wx/gtk1/choice.h index 796d625f4b..acd0324c00 100644 --- a/include/wx/gtk1/choice.h +++ b/include/wx/gtk1/choice.h @@ -16,8 +16,6 @@ #include "wx/defs.h" -#if wxUSE_CHOICE - #include "wx/object.h" #include "wx/list.h" #include "wx/control.h" @@ -99,6 +97,5 @@ public: void ApplyWidgetStyle(); }; -#endif #endif // __GTKCHOICEH__ diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index f09ee3bc04..3638cee90e 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -100,6 +100,7 @@ public: GtkItemFactory *m_factory; wxList m_menus; GtkWidget *m_menubar; + long m_style; }; //----------------------------------------------------------------------------- @@ -112,7 +113,9 @@ class wxMenu : public wxEvtHandler public: wxMenu( const wxString& title = wxEmptyString, - const wxFunction func = (wxFunction) NULL ); + const wxFunction func = (wxFunction) NULL, + long style = 0); + wxMenu( long style ); ~wxMenu(); // operations @@ -182,7 +185,13 @@ public: GtkAccelGroup *m_accel; GtkItemFactory *m_factory; -private: + // used by wxMenuBar + inline long GetStyle(void) const { return m_style; } + private: + // common code for both constructors: + void Init( const wxString& title, + const wxFunction func, + long style); wxString m_title; wxList m_items; @@ -190,6 +199,7 @@ private: wxFunction m_callback; wxEvtHandler *m_eventHandler; void *m_clientData; + long m_style; }; #endif // __GTKMENUH__ diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp index 8db65d0ad9..945e2d8dc8 100644 --- a/samples/minimal/minimal.cpp +++ b/samples/minimal/minimal.cpp @@ -149,14 +149,14 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) SetIcon(wxICON(mondrian)); // create a menu bar - wxMenu *menuFile = new wxMenu; + wxMenu *menuFile = new wxMenu("File",NULL,wxMENU_TEAROFF); menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); menuFile->AppendSeparator(); menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); // now append the freshly created menu to the menu bar... - wxMenuBar *menuBar = new wxMenuBar; + wxMenuBar *menuBar = new wxMenuBar(); menuBar->Append(menuFile, "&File"); // ... and attach this menu bar to the frame diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 1dd8ad95af..2b96d69033 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -44,6 +44,8 @@ // global data //----------------------------------------------------------------------------- +extern wxCursor g_globalCursor; + wxApp *wxTheApp = (wxApp *) NULL; wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL; @@ -575,8 +577,7 @@ bool wxApp::Initialize() wxImage::InitStandardHandlers(); - /* no global cursor under X - g_globalCursor = new wxCursor; */ + g_globalCursor = wxCursor(wxCURSOR_DEFAULT); wxModule::RegisterModules(); if (!wxModule::InitializeModules()) return FALSE; diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 2277c0aee4..9e96423d55 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -64,6 +64,7 @@ wxCursor::wxCursor( int cursorId ) GdkCursorType gdk_cur = GDK_LEFT_PTR; switch (cursorId) { + case wxCURSOR_DEFAULT: gdk_cur = GDK_X_CURSOR; break; case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break; case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break; case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break; diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index e2b79dbf82..a267b1bab8 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -37,7 +37,8 @@ wxMenuBar::wxMenuBar( long style ) { /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; - + m_style = style; + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); m_menus.DeleteContents( TRUE ); @@ -69,7 +70,8 @@ wxMenuBar::wxMenuBar() { /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; - + m_style = 0; + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); m_menus.DeleteContents( TRUE ); @@ -216,7 +218,9 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) NULL; entry.callback_action = 0; - entry.item_type = ""; + entry.item_type = (m_style & wxMB_TEAROFF || menu->GetStyle() & + wxMENU_TEAROFF) ? + "" : ""; gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ @@ -632,11 +636,23 @@ bool wxMenuItem::IsChecked() const IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) -wxMenu::wxMenu( const wxString& title, const wxFunction func ) +wxMenu::wxMenu( const wxString& title, const wxFunction func, long style ) +{ + Init(title, func, style); +} + +wxMenu::wxMenu(long style) +{ + Init(wxEmptyString, (wxFunction) NULL, style); +} + +void +wxMenu::Init( const wxString& title, const wxFunction func, long style ) { m_title = title; m_items.DeleteContents( TRUE ); m_invokingWindow = (wxWindow *) NULL; + m_style = style; #if (GTK_MINOR_VERSION > 0) m_accel = gtk_accel_group_new(); @@ -829,7 +845,7 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri entry.path = buf; entry.callback = (GtkItemFactoryCallback) 0; entry.callback_action = 0; - entry.item_type = ""; + entry.item_type = (m_style & wxMENU_TEAROFF) ? "" : ""; gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index 1dd8ad95af..2b96d69033 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -44,6 +44,8 @@ // global data //----------------------------------------------------------------------------- +extern wxCursor g_globalCursor; + wxApp *wxTheApp = (wxApp *) NULL; wxAppInitializerFunction wxApp::m_appInitFn = (wxAppInitializerFunction) NULL; @@ -575,8 +577,7 @@ bool wxApp::Initialize() wxImage::InitStandardHandlers(); - /* no global cursor under X - g_globalCursor = new wxCursor; */ + g_globalCursor = wxCursor(wxCURSOR_DEFAULT); wxModule::RegisterModules(); if (!wxModule::InitializeModules()) return FALSE; diff --git a/src/gtk1/cursor.cpp b/src/gtk1/cursor.cpp index 2277c0aee4..9e96423d55 100644 --- a/src/gtk1/cursor.cpp +++ b/src/gtk1/cursor.cpp @@ -64,6 +64,7 @@ wxCursor::wxCursor( int cursorId ) GdkCursorType gdk_cur = GDK_LEFT_PTR; switch (cursorId) { + case wxCURSOR_DEFAULT: gdk_cur = GDK_X_CURSOR; break; case wxCURSOR_HAND: gdk_cur = GDK_HAND1; break; case wxCURSOR_CROSS: gdk_cur = GDK_CROSSHAIR; break; case wxCURSOR_SIZEWE: gdk_cur = GDK_SB_H_DOUBLE_ARROW; break; diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index e2b79dbf82..a267b1bab8 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -37,7 +37,8 @@ wxMenuBar::wxMenuBar( long style ) { /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; - + m_style = style; + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, style, "menu" ); m_menus.DeleteContents( TRUE ); @@ -69,7 +70,8 @@ wxMenuBar::wxMenuBar() { /* the parent window is known after wxFrame::SetMenu() */ m_needParent = FALSE; - + m_style = 0; + PreCreation( (wxWindow *) NULL, -1, wxDefaultPosition, wxDefaultSize, 0, "menu" ); m_menus.DeleteContents( TRUE ); @@ -216,7 +218,9 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title ) entry.accelerator = (gchar*) NULL; entry.callback = (GtkItemFactoryCallback) NULL; entry.callback_action = 0; - entry.item_type = ""; + entry.item_type = (m_style & wxMB_TEAROFF || menu->GetStyle() & + wxMENU_TEAROFF) ? + "" : ""; gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ @@ -632,11 +636,23 @@ bool wxMenuItem::IsChecked() const IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) -wxMenu::wxMenu( const wxString& title, const wxFunction func ) +wxMenu::wxMenu( const wxString& title, const wxFunction func, long style ) +{ + Init(title, func, style); +} + +wxMenu::wxMenu(long style) +{ + Init(wxEmptyString, (wxFunction) NULL, style); +} + +void +wxMenu::Init( const wxString& title, const wxFunction func, long style ) { m_title = title; m_items.DeleteContents( TRUE ); m_invokingWindow = (wxWindow *) NULL; + m_style = style; #if (GTK_MINOR_VERSION > 0) m_accel = gtk_accel_group_new(); @@ -829,7 +845,7 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri entry.path = buf; entry.callback = (GtkItemFactoryCallback) 0; entry.callback_action = 0; - entry.item_type = ""; + entry.item_type = (m_style & wxMENU_TEAROFF) ? "" : ""; gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ -- 2.45.2