// TODO: virtual void SetTitle(const wxString& title);
-#ifdef WXWIN_COMPATIBILITY
+#if WXWIN_COMPATIBILITY
wxMenu(const wxString& title, const wxFunction func)
: wxMenuBase(title)
{
// TODO: virtual void SetTitle(const wxString& title);
-#ifdef WXWIN_COMPATIBILITY
+#if WXWIN_COMPATIBILITY
wxMenu(const wxString& title, const wxFunction func)
: wxMenuBase(title)
{
wxFunction m_callback;
#endif // WXWIN_COMPATIBILITY
+ // unlike FindItem(), this function doesn't recurse but only looks through
+ // our direct children and also may return the index of the found child if
+ // pos != NULL
+ wxMenuItem *FindChildItem(int id, size_t *pos = NULL) const;
+
protected:
// virtuals to override in derived classes
// ---------------------------------------
// common part of all ctors
void Init(long style);
- // unlike FindItem(), this function doesn't recurse but only looks through
- // our direct children and also may return the index of the found child if
- // pos != NULL
- wxMenuItem *FindChildItem(int id, size_t *pos = NULL) const;
-
protected:
wxMenuBar *m_menuBar; // menubar we belong to or NULL
wxMenu *m_menuParent; // parent menu or NULL
--- /dev/null
+#
+# File: makefile.unx
+# Author: Julian Smart
+# Created: 1998
+# Updated:
+# Copyright: (c) 1998 Julian Smart
+#
+# "%W% %G%"
+#
+# Makefile for minimal example (UNIX).
+
+top_srcdir = @top_srcdir@
+top_builddir = ../..
+program_dir = samples/menu
+
+PROGRAM=menu
+
+OBJECTS=$(PROGRAM).o
+
+include ../../src/makeprog.env
+
void MyFrame::OnAppendMenu(wxCommandEvent& WXUNUSED(event))
{
- static s_count = 0;
+ static int s_count = 0;
wxString title;
title.Printf("Dummy menu &%d", ++s_count);
size_t count = mbar->GetMenuCount();
wxLogMessage("The label of the last menu item is '%s'",
- mbar->GetLabelTop(count - 1));
+ mbar->GetLabelTop(count - 1).c_str());
}
void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event))
if ( item )
{
wxLogMessage("The label of the last menu item is '%s'",
- item->GetLabel());
+ item->GetLabel().c_str());
}
}
if ( ppos )
{
- *ppos = item ? pos : wxNOT_FOUND;
+ *ppos = item ? pos : (size_t)wxNOT_FOUND;
}
return item;
wxMenuBar *bar = GetMenuBar();
if (!bar) return;
- wxMenuItem *item = bar->FindItemForId(id) ;
+ wxMenuItem *item = bar->FindItem(id) ;
if (item && item->IsCheckable())
{
- bar->Check(id,!bar->Checked(id)) ;
+ bar->Check(id, !bar->IsChecked(id)) ;
}
wxEvtHandler* evtHandler = GetEventHandler();
gtk_accel_group_detach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = menu->GetItems().First();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *menuitem = (wxMenuItem*)node->Data();
+ wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win );
- node = node->Next();
+ node = node->GetNext();
}
}
gtk_accel_group_attach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = menu->GetItems().First();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *menuitem = (wxMenuItem*)node->Data();
+ wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win );
- node = node->Next();
+ node = node->GetNext();
}
}
gtk_accel_group_attach( m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
wxMenubarSetInvokingWindow( menu, win );
- node = node->Next();
+ node = node->GetNext();
}
}
gtk_accel_group_detach( m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
wxMenubarUnsetInvokingWindow( menu, win );
- node = node->Next();
+ node = node->GetNext();
}
}
return res;
}
- wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *item = (wxMenuItem*)node->Data();
+ wxMenuItem *item = node->GetData();
if (item->IsSubMenu())
return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
- node = node->Next();
+ node = node->GetNext();
}
return wxNOT_FOUND;
int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
{
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
int res = FindMenuItemRecursive( menu, menuString, itemString);
- if (res != -1) return res;
- node = node->Next();
+ if (res != -1)
+ return res;
+ node = node->GetNext();
}
- return -1;
+
+ return wxNOT_FOUND;
}
// Find a wxMenuItem using its id. Recurses down into sub-menus
{
wxMenuItem* result = menu->FindChildItem(id);
- wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while ( node && result == NULL )
{
- wxMenuItem *item = (wxMenuItem*)node->Data();
+ wxMenuItem *item = node->GetData();
if (item->IsSubMenu())
{
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
}
- node = node->Next();
+ node = node->GetNext();
}
return result;
wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const
{
wxMenuItem* result = 0;
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node && result == 0)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
result = FindMenuItemByIdRecursive( menu, id );
- node = node->Next();
+ node = node->GetNext();
}
if ( menuForItem )
event.SetEventObject( menu );
event.SetInt(id );
+#if WXWIN_COMPATIBILITY
if (menu->GetCallback())
{
(void) (*(menu->GetCallback())) (*menu, event);
return;
}
+#endif // WXWIN_COMPATIBILITY
if (menu->GetEventHandler()->ProcessEvent(event))
return;
gtk_label_set( label, m_text.mb_str());
/* reparse key accel */
- guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() );
+ (void)gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() );
gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) );
}
}
wxAcceleratorEntry *wxMenuItem::GetAccel() const
{
- if ( !item.GetHotKey() )
+ if ( !GetHotKey() )
{
// nothing
return (wxAcceleratorEntry *)NULL;
// as wxGetAccelFromString() looks for TAB, insert a dummy one here
wxString label;
- label << wxT('\t') << item.GetHotKey();
+ label << wxT('\t') << GetHotKey();
return wxGetAccelFromString(label);
}
// the menu items are deleted by the base class dtor
}
-virtual bool wxMenu::DoAppend(wxMenuItem *mitem)
+bool wxMenu::DoAppend(wxMenuItem *mitem)
{
GtkWidget *menuItem;
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
wxString path( mitem->GetFactoryPath() );
- GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
+ menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
#else // GTK+ 1.0
- GtkWidget *menuItem = gtk_menu_item_new_with_label(mitem->GetText().mbc_str());
+ menuItem = gtk_menu_item_new_with_label(mitem->GetText().mbc_str());
#endif // GTK 1.2/1.0
- gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), subMenu->m_menu );
+ gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
}
else // a normal item
{
entry.path = buf;
entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
entry.callback_action = 0;
- if (checkable)
+ if ( mitem->IsCheckable() )
entry.item_type = "<CheckItem>";
else
entry.item_type = "<Item>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
wxString path( mitem->GetFactoryPath() );
- GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
+ menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
#else // GTK+ 1.0
- GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( mitem->GetText().mb_str() )
- : gtk_menu_item_new_with_label( mitem->GetText().mb_str() );
+ menuItem = checkable ? gtk_check_menu_item_new_with_label( mitem->GetText().mb_str() )
+ : gtk_menu_item_new_with_label( mitem->GetText().mb_str() );
gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
- wxNode *node = menu->GetItems().First();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *menuitem = (wxMenuItem*)node->Data();
+ wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
{
SetInvokingWindow( menuitem->GetSubMenu(), win );
}
- node = node->Next();
+
+ node = node->GetNext();
}
}
wxMenuBar *bar = GetMenuBar();
if (!bar) return;
- wxMenuItem *item = bar->FindItemForId(id) ;
+ wxMenuItem *item = bar->FindItem(id) ;
if (item && item->IsCheckable())
{
- bar->Check(id,!bar->Checked(id)) ;
+ bar->Check(id, !bar->IsChecked(id)) ;
}
wxEvtHandler* evtHandler = GetEventHandler();
gtk_accel_group_detach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = menu->GetItems().First();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *menuitem = (wxMenuItem*)node->Data();
+ wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu(), win );
- node = node->Next();
+ node = node->GetNext();
}
}
gtk_accel_group_attach( menu->m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = menu->GetItems().First();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *menuitem = (wxMenuItem*)node->Data();
+ wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarSetInvokingWindow( menuitem->GetSubMenu(), win );
- node = node->Next();
+ node = node->GetNext();
}
}
gtk_accel_group_attach( m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
wxMenubarSetInvokingWindow( menu, win );
- node = node->Next();
+ node = node->GetNext();
}
}
gtk_accel_group_detach( m_accel, GTK_OBJECT(top_frame->m_widget) );
#endif
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
wxMenubarUnsetInvokingWindow( menu, win );
- node = node->Next();
+ node = node->GetNext();
}
}
return res;
}
- wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *item = (wxMenuItem*)node->Data();
+ wxMenuItem *item = node->GetData();
if (item->IsSubMenu())
return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
- node = node->Next();
+ node = node->GetNext();
}
return wxNOT_FOUND;
int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemString ) const
{
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
int res = FindMenuItemRecursive( menu, menuString, itemString);
- if (res != -1) return res;
- node = node->Next();
+ if (res != -1)
+ return res;
+ node = node->GetNext();
}
- return -1;
+
+ return wxNOT_FOUND;
}
// Find a wxMenuItem using its id. Recurses down into sub-menus
{
wxMenuItem* result = menu->FindChildItem(id);
- wxNode *node = ((wxMenu *)menu)->GetItems().First(); // const_cast
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while ( node && result == NULL )
{
- wxMenuItem *item = (wxMenuItem*)node->Data();
+ wxMenuItem *item = node->GetData();
if (item->IsSubMenu())
{
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
}
- node = node->Next();
+ node = node->GetNext();
}
return result;
wxMenuItem* wxMenuBar::FindItem( int id, wxMenu **menuForItem ) const
{
wxMenuItem* result = 0;
- wxNode *node = m_menus.First();
+ wxMenuList::Node *node = m_menus.GetFirst();
while (node && result == 0)
{
- wxMenu *menu = (wxMenu*)node->Data();
+ wxMenu *menu = node->GetData();
result = FindMenuItemByIdRecursive( menu, id );
- node = node->Next();
+ node = node->GetNext();
}
if ( menuForItem )
event.SetEventObject( menu );
event.SetInt(id );
+#if WXWIN_COMPATIBILITY
if (menu->GetCallback())
{
(void) (*(menu->GetCallback())) (*menu, event);
return;
}
+#endif // WXWIN_COMPATIBILITY
if (menu->GetEventHandler()->ProcessEvent(event))
return;
gtk_label_set( label, m_text.mb_str());
/* reparse key accel */
- guint accel_key = gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() );
+ (void)gtk_label_parse_uline (GTK_LABEL(label), m_text.mb_str() );
gtk_accel_label_refetch( GTK_ACCEL_LABEL(label) );
}
}
wxAcceleratorEntry *wxMenuItem::GetAccel() const
{
- if ( !item.GetHotKey() )
+ if ( !GetHotKey() )
{
// nothing
return (wxAcceleratorEntry *)NULL;
// as wxGetAccelFromString() looks for TAB, insert a dummy one here
wxString label;
- label << wxT('\t') << item.GetHotKey();
+ label << wxT('\t') << GetHotKey();
return wxGetAccelFromString(label);
}
// the menu items are deleted by the base class dtor
}
-virtual bool wxMenu::DoAppend(wxMenuItem *mitem)
+bool wxMenu::DoAppend(wxMenuItem *mitem)
{
GtkWidget *menuItem;
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
wxString path( mitem->GetFactoryPath() );
- GtkWidget *menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
+ menuItem = gtk_item_factory_get_item( m_factory, path.mb_str() );
#else // GTK+ 1.0
- GtkWidget *menuItem = gtk_menu_item_new_with_label(mitem->GetText().mbc_str());
+ menuItem = gtk_menu_item_new_with_label(mitem->GetText().mbc_str());
#endif // GTK 1.2/1.0
- gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), subMenu->m_menu );
+ gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), mitem->GetSubMenu()->m_menu );
}
else // a normal item
{
entry.path = buf;
entry.callback = (GtkItemFactoryCallback) gtk_menu_clicked_callback;
entry.callback_action = 0;
- if (checkable)
+ if ( mitem->IsCheckable() )
entry.item_type = "<CheckItem>";
else
entry.item_type = "<Item>";
gtk_item_factory_create_item( m_factory, &entry, (gpointer) this, 2 ); /* what is 2 ? */
wxString path( mitem->GetFactoryPath() );
- GtkWidget *menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
+ menuItem = gtk_item_factory_get_widget( m_factory, path.mb_str() );
#else // GTK+ 1.0
- GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label( mitem->GetText().mb_str() )
- : gtk_menu_item_new_with_label( mitem->GetText().mb_str() );
+ menuItem = checkable ? gtk_check_menu_item_new_with_label( mitem->GetText().mb_str() )
+ : gtk_menu_item_new_with_label( mitem->GetText().mb_str() );
gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
- wxNode *node = menu->GetItems().First();
+ wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
while (node)
{
- wxMenuItem *menuitem = (wxMenuItem*)node->Data();
+ wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
{
SetInvokingWindow( menuitem->GetSubMenu(), win );
}
- node = node->Next();
+
+ node = node->GetNext();
}
}