Made tearoff menus work for gtk :-)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2958 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Karsten Ballüder
1999-07-07 09:18:34 +00:00
parent 094637f6d6
commit 2b2edbedb4
4 changed files with 624 additions and 368 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -155,8 +155,8 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
SetIcon(wxICON(mondrian)); SetIcon(wxICON(mondrian));
// create a menu bar // create a menu bar
wxMenu *menuFile = new wxMenu; // wxMenu *menuFile = new wxMenu;
// wxMenu *menuFile = new wxMenu(wxMENU_TEAROFF); wxMenu *menuFile = new wxMenu(wxMENU_TEAROFF);
menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog");
menuFile->AppendSeparator(); menuFile->AppendSeparator();

View File

@@ -211,47 +211,27 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
/* local buffer in multibyte form */ /* local buffer in multibyte form */
char buf[200]; wxString buf;
strcpy( buf, "/" ); buf << '/' << str.mb_str();
strcat( buf, str.mb_str() ); char *cbuf = new char[buf.Length()];
GtkItemFactoryEntry entry; GtkItemFactoryEntry entry;
entry.path = buf; entry.path = buf.c_str();
entry.accelerator = (gchar*) NULL; entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) NULL; entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0; entry.callback_action = 0;
entry.item_type = "<Branch>";
/*
if ((m_style & wxMB_TEAROFF) || (menu->GetStyle() & wxMENU_TEAROFF))
entry.item_type = "<Tearoff>";
else
*/
entry.item_type = "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */ /* in order to get the pointer to the item we need the item text _without_ underscores */
wxString tmp = _T("<main>/"); wxString tmp = _T("<main>/");
for ( pc = str; *pc != _T('\0'); pc++ ) for ( pc = str; *pc != _T('\0'); pc++ )
{ {
if (*pc == _T('_')) pc++; /* skip it */ if (*pc == _T('_')) pc++; /* skip it */
tmp << *pc; tmp << *pc;
} }
menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() ); menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
delete [] cbuf;
/*
if ((m_style & wxMB_TEAROFF) || (menu->GetStyle() & wxMENU_TEAROFF))
{
entry.item_type = "<Tearoff>";
tmp.Remove( 0, 6 );
tmp.Append( _T("/tearoff") );
strcpy( buf, tmp.mb_str() );
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 );
}
*/
#else #else
menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() ); menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() );
@@ -690,6 +670,23 @@ wxMenu::Init( const wxString& title, const wxFunction func, long style )
} }
m_owner = (GtkWidget*) NULL; m_owner = (GtkWidget*) NULL;
#if (GTK_MINOR_VERSION > 0)
/* Tearoffs are entries, just like separators. So if we want this
menu to be a tear-off one, we just append a tearoff entry
immediately. */
if(m_style & wxMENU_TEAROFF)
{
GtkItemFactoryEntry entry;
entry.path = "/tearoff";
entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0;
entry.item_type = "<Tearoff>";
entry.accelerator = (gchar*) NULL;
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, "<main>/tearoff" );
}
#endif
} }
wxMenu::~wxMenu() wxMenu::~wxMenu()
@@ -861,13 +858,7 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri
entry.path = buf; entry.path = buf;
entry.callback = (GtkItemFactoryCallback) 0; entry.callback = (GtkItemFactoryCallback) 0;
entry.callback_action = 0; entry.callback_action = 0;
entry.item_type = "<Branch>";
/*
if (m_style & wxMENU_TEAROFF)
entry.item_type = "<Tearoff>";
else
*/
entry.item_type = "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */

View File

@@ -211,47 +211,27 @@ void wxMenuBar::Append( wxMenu *menu, const wxString &title )
#if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0) #if (GTK_MINOR_VERSION > 0) && (GTK_MICRO_VERSION > 0)
/* local buffer in multibyte form */ /* local buffer in multibyte form */
char buf[200]; wxString buf;
strcpy( buf, "/" ); buf << '/' << str.mb_str();
strcat( buf, str.mb_str() ); char *cbuf = new char[buf.Length()];
GtkItemFactoryEntry entry; GtkItemFactoryEntry entry;
entry.path = buf; entry.path = buf.c_str();
entry.accelerator = (gchar*) NULL; entry.accelerator = (gchar*) NULL;
entry.callback = (GtkItemFactoryCallback) NULL; entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0; entry.callback_action = 0;
entry.item_type = "<Branch>";
/*
if ((m_style & wxMB_TEAROFF) || (menu->GetStyle() & wxMENU_TEAROFF))
entry.item_type = "<Tearoff>";
else
*/
entry.item_type = "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
/* in order to get the pointer to the item we need the item text _without_ underscores */ /* in order to get the pointer to the item we need the item text _without_ underscores */
wxString tmp = _T("<main>/"); wxString tmp = _T("<main>/");
for ( pc = str; *pc != _T('\0'); pc++ ) for ( pc = str; *pc != _T('\0'); pc++ )
{ {
if (*pc == _T('_')) pc++; /* skip it */ if (*pc == _T('_')) pc++; /* skip it */
tmp << *pc; tmp << *pc;
} }
menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() ); menu->m_owner = gtk_item_factory_get_item( m_factory, tmp.mb_str() );
gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu ); gtk_menu_item_set_submenu( GTK_MENU_ITEM(menu->m_owner), menu->m_menu );
delete [] cbuf;
/*
if ((m_style & wxMB_TEAROFF) || (menu->GetStyle() & wxMENU_TEAROFF))
{
entry.item_type = "<Tearoff>";
tmp.Remove( 0, 6 );
tmp.Append( _T("/tearoff") );
strcpy( buf, tmp.mb_str() );
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 );
}
*/
#else #else
menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() ); menu->m_owner = gtk_menu_item_new_with_label( str.mb_str() );
@@ -690,6 +670,23 @@ wxMenu::Init( const wxString& title, const wxFunction func, long style )
} }
m_owner = (GtkWidget*) NULL; m_owner = (GtkWidget*) NULL;
#if (GTK_MINOR_VERSION > 0)
/* Tearoffs are entries, just like separators. So if we want this
menu to be a tear-off one, we just append a tearoff entry
immediately. */
if(m_style & wxMENU_TEAROFF)
{
GtkItemFactoryEntry entry;
entry.path = "/tearoff";
entry.callback = (GtkItemFactoryCallback) NULL;
entry.callback_action = 0;
entry.item_type = "<Tearoff>";
entry.accelerator = (gchar*) NULL;
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, "<main>/tearoff" );
}
#endif
} }
wxMenu::~wxMenu() wxMenu::~wxMenu()
@@ -861,13 +858,7 @@ void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxStri
entry.path = buf; entry.path = buf;
entry.callback = (GtkItemFactoryCallback) 0; entry.callback = (GtkItemFactoryCallback) 0;
entry.callback_action = 0; entry.callback_action = 0;
entry.item_type = "<Branch>";
/*
if (m_style & wxMENU_TEAROFF)
entry.item_type = "<Tearoff>";
else
*/
entry.item_type = "<Branch>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */ gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */