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
This commit is contained in:
Karsten Ballüder 1999-06-17 14:08:00 +00:00
parent 28d52eed36
commit ae53c98c9f
13 changed files with 85 additions and 26 deletions

View File

@ -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

View File

@ -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,

View File

@ -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__

View File

@ -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__

View File

@ -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__

View File

@ -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__

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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 = "<Branch>";
entry.item_type = (m_style & wxMB_TEAROFF || menu->GetStyle() &
wxMENU_TEAROFF) ?
"<Tearoff>" : "<Branch>";
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 = "<Branch>";
entry.item_type = (m_style & wxMENU_TEAROFF) ? "<Tearoff>" : "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */

View File

@ -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;

View File

@ -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;

View File

@ -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 = "<Branch>";
entry.item_type = (m_style & wxMB_TEAROFF || menu->GetStyle() &
wxMENU_TEAROFF) ?
"<Tearoff>" : "<Branch>";
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 = "<Branch>";
entry.item_type = (m_style & wxMENU_TEAROFF) ? "<Tearoff>" : "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */