made the code more wxMSW compatible

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1998-07-23 16:02:54 +00:00
parent caac51810b
commit 96fd301f0e
2 changed files with 278 additions and 306 deletions

View File

@@ -3,7 +3,7 @@
// Purpose: // Purpose:
// Author: Robert Roebling // Author: Robert Roebling
// Created: 01/02/97 // Created: 01/02/97
// Id: // Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -14,6 +14,7 @@
#endif #endif
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/log.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenuBar // wxMenuBar
@@ -21,7 +22,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
wxMenuBar::wxMenuBar(void) wxMenuBar::wxMenuBar()
{ {
m_needParent = FALSE; // hmmm m_needParent = FALSE; // hmmm
@@ -72,7 +73,8 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_subMenu) return FindMenuItemRecursive( item->m_subMenu, menuString, itemString ); if (item->IsSubMenu())
return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
node = node->Next(); node = node->Next();
}; };
return -1; return -1;
@@ -94,15 +96,16 @@ int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemStr
// Find a wxMenuItem using its id. Recurses down into sub-menus // Find a wxMenuItem using its id. Recurses down into sub-menus
static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
{ {
wxMenuItem* result = menu->FindItemForId( id ); wxMenuItem* result = menu->FindItem(id);
wxNode *node = menu->m_items.First(); wxNode *node = menu->m_items.First();
while (node && result == 0) while ( node && result == NULL ) {
{
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_subMenu) result = FindMenuItemByIdRecursive( item->m_subMenu, id ); if ( item->IsSubMenu() )
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
node = node->Next(); node = node->Next();
}; };
return result; return result;
}; };
@@ -142,7 +145,10 @@ void gtk_menu_clicked_callback( GtkWidget *widget, gpointer data )
wxMenu *menu = (wxMenu*)data; wxMenu *menu = (wxMenu*)data;
int id = menu->FindMenuIdByMenuItem(widget); int id = menu->FindMenuIdByMenuItem(widget);
if (!menu->Enabled(id)) return; wxASSERT( id != -1 ); // should find it!
if (!menu->IsEnabled(id))
return;
wxCommandEvent event( wxEVENT_TYPE_MENU_COMMAND, id ); wxCommandEvent event( wxEVENT_TYPE_MENU_COMMAND, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
@@ -153,39 +159,43 @@ void gtk_menu_clicked_callback( GtkWidget *widget, gpointer data )
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem,wxObject) IMPLEMENT_DYNAMIC_CLASS(wxMenuItem,wxObject)
wxMenuItem::wxMenuItem(void) wxMenuItem::wxMenuItem()
{ {
m_id = 0; m_id = ID_SEPARATOR;
m_text = "";
m_isCheckMenu = FALSE; m_isCheckMenu = FALSE;
m_checked = FALSE; m_isChecked = FALSE;
m_isSubMenu = FALSE; m_isEnabled = TRUE;
m_subMenu = NULL; m_subMenu = NULL;
m_helpStr = "";
m_menuItem = NULL; m_menuItem = NULL;
}; };
void wxMenuItem::SetText(const wxString& str)
{
for ( const char *pc = str; *pc != '\0'; pc++ ) {
if ( *pc == '&' )
pc++; // skip it
m_text << *pc;
}
}
void wxMenuItem::Check( bool check ) void wxMenuItem::Check( bool check )
{ {
if ( IsCheckable() ) wxCHECK_RET( IsCheckable(), "can't check uncheckable item!" )
{
m_checked = check; m_isChecked = check;
gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check ); gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check );
} }
}
bool wxMenuItem::IsChecked() const bool wxMenuItem::IsChecked() const
{ {
if ( IsCheckable() ) wxCHECK( IsCheckable(), FALSE ); // can't get state of uncheckable item!
{
return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
}
return FALSE;
}
void wxMenuItem::Enable( bool enable ) bool bIsChecked = ((GtkCheckMenuItem*)m_menuItem)->active != 0;
{
m_isEnabled = enable; wxASSERT( bIsChecked == m_isChecked ); // consistency check
return bIsChecked;
} }
IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
@@ -198,68 +208,53 @@ wxMenu::wxMenu( const wxString &title )
m_menu = gtk_menu_new(); // Do not show! m_menu = gtk_menu_new(); // Do not show!
}; };
void wxMenu::AppendSeparator(void) void wxMenu::AppendSeparator()
{ {
wxMenuItem *mitem = new wxMenuItem(); wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = ID_SEPARATOR; mitem->SetId(ID_SEPARATOR);
mitem->m_text = "";
mitem->m_helpStr = ""; GtkWidget *menuItem = gtk_menu_item_new();
mitem->m_isCheckMenu = FALSE; gtk_menu_append( GTK_MENU(m_menu), menuItem );
mitem->m_isEnabled = TRUE; gtk_widget_show( menuItem );
mitem->m_menuItem = gtk_menu_item_new(); mitem->SetMenuItem(menuItem);
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem ); m_items.Append( mitem );
}; };
void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool checkable ) void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool checkable )
{ {
wxMenuItem *mitem = new wxMenuItem(); wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = id; mitem->SetId(id);
mitem->SetText(item);
mitem->SetHelpString(helpStr);
mitem->SetCheckable(checkable);
const char *text = mitem->GetText();
GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label(text)
: gtk_menu_item_new_with_label(text);
mitem->SetMenuItem(menuItem);
mitem->m_text = item; gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
size_t pos; GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
do { (gpointer*)this );
pos = mitem->m_text.First( '&' );
if (pos != wxString::npos) mitem->m_text.Remove( pos, 1 );
} while (pos != wxString::npos);
mitem->m_helpStr = helpStr; gtk_menu_append( GTK_MENU(m_menu), menuItem );
mitem->m_isCheckMenu = checkable; gtk_widget_show( menuItem );
mitem->m_isEnabled = TRUE;
if (checkable)
mitem->m_menuItem = gtk_check_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
else
mitem->m_menuItem = gtk_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
gtk_signal_connect( GTK_OBJECT(mitem->m_menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer*)this );
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem ); m_items.Append( mitem );
}; };
void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxString &helpStr ) void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxString &helpStr )
{ {
wxMenuItem *mitem = new wxMenuItem(); wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = id; mitem->SetId(id);
mitem->m_text = item; mitem->SetText(text);
mitem->m_isEnabled = TRUE;
size_t pos; GtkWidget *menuItem = gtk_menu_item_new_with_label(mitem->GetText());
do { mitem->SetHelpString(helpStr);
pos = mitem->m_text.First( '&' ); mitem->SetMenuItem(menuItem);
if (pos != wxString::npos) mitem->m_text.Remove( pos, 1 ); mitem->SetSubMenu(subMenu);
} while (pos != wxString::npos);
mitem->m_helpStr = helpStr; gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), subMenu->m_menu );
mitem->m_menuItem = gtk_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) ); gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem );
mitem->m_subMenu = subMenu;
gtk_menu_item_set_submenu( GTK_MENU_ITEM(mitem->m_menuItem), subMenu->m_menu );
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem ); m_items.Append( mitem );
}; };
@@ -277,77 +272,51 @@ int wxMenu::FindItem( const wxString itemString ) const
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_text == s) return item->m_id; if (item->GetText() == s)
return item->GetId();
node = node->Next(); node = node->Next();
}; };
return -1; return -1;
}; };
wxMenuItem* wxMenu::FindItemForId( int id ) const
{
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_id == id) return item;
node = node->Next();
}
return NULL;
}
void wxMenu::Check( int id, bool Flag )
{
wxMenuItem* item = FindItemForId( id );
if (item) item->Check(Flag);
};
void wxMenu::Enable( int id, bool enable ) void wxMenu::Enable( int id, bool enable )
{ {
wxNode *node = m_items.First(); wxMenuItem *item = FindItem(id);
while (node) if ( item )
{ item->Enable(enable);
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_id == id)
{
item->m_isEnabled = enable;
return;
};
node = node->Next();
};
}; };
bool wxMenu::Enabled( int id ) const bool wxMenu::IsEnabled( int id ) const
{ {
wxNode *node = m_items.First(); wxMenuItem *item = FindItem(id);
while (node) if ( item )
{ return item->IsEnabled();
wxMenuItem *item = (wxMenuItem*)node->Data(); else
if (item->m_id == id) return item->m_isEnabled; return FALSE;
node = node->Next();
}; };
void wxMenu::Check( int id, bool enable )
{
wxMenuItem *item = FindItem(id);
if ( item )
item->Check(enable);
};
bool wxMenu::IsChecked( int id ) const
{
wxMenuItem *item = FindItem(id);
if ( item )
return item->IsChecked();
else
return FALSE; return FALSE;
}; };
void wxMenu::SetLabel( int id, const wxString &label ) void wxMenu::SetLabel( int id, const wxString &label )
{ {
wxString s( label ); wxMenuItem *item = FindItem(id);
size_t pos; if ( item )
do { item->SetText(label);
pos = s.First( '&' );
if (pos != wxString::npos) s.Remove( pos, 1 );
} while (pos != wxString::npos);
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
item->m_text = s;
if (item->m_id == id)
{
gtk_label_set( GTK_LABEL( GTK_BIN(item->m_menuItem)->child ), WXSTRINGCAST(s) );
};
node = node->Next();
};
}; };
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
@@ -356,18 +325,35 @@ int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_menuItem == menuItem) return item->m_id; if (item->GetMenuItem() == menuItem)
return item->GetId();
node = node->Next(); node = node->Next();
}; };
return -1; return -1;
}; };
wxMenuItem *wxMenu::FindItem(int id) const
{
wxNode *node = m_items.First();
while (node) {
wxMenuItem *item = (wxMenuItem*)node->Data();
if ( item->GetId() == id )
return item;
node = node->Next();
};
wxLogDebug("wxMenu::FindItem: item %d not found.", id);
return NULL;
}
void wxMenu::SetInvokingWindow( wxWindow *win ) void wxMenu::SetInvokingWindow( wxWindow *win )
{ {
m_invokingWindow = win; m_invokingWindow = win;
}; };
wxWindow *wxMenu::GetInvokingWindow(void) wxWindow *wxMenu::GetInvokingWindow()
{ {
return m_invokingWindow; return m_invokingWindow;
}; };

View File

@@ -3,7 +3,7 @@
// Purpose: // Purpose:
// Author: Robert Roebling // Author: Robert Roebling
// Created: 01/02/97 // Created: 01/02/97
// Id: // Id: $Id$
// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
// Licence: wxWindows licence // Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@@ -14,6 +14,7 @@
#endif #endif
#include "wx/menu.h" #include "wx/menu.h"
#include "wx/log.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxMenuBar // wxMenuBar
@@ -21,7 +22,7 @@
IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar,wxWindow)
wxMenuBar::wxMenuBar(void) wxMenuBar::wxMenuBar()
{ {
m_needParent = FALSE; // hmmm m_needParent = FALSE; // hmmm
@@ -72,7 +73,8 @@ static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_subMenu) return FindMenuItemRecursive( item->m_subMenu, menuString, itemString ); if (item->IsSubMenu())
return FindMenuItemRecursive(item->GetSubMenu(), menuString, itemString);
node = node->Next(); node = node->Next();
}; };
return -1; return -1;
@@ -94,15 +96,16 @@ int wxMenuBar::FindMenuItem( const wxString &menuString, const wxString &itemStr
// Find a wxMenuItem using its id. Recurses down into sub-menus // Find a wxMenuItem using its id. Recurses down into sub-menus
static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id) static wxMenuItem* FindMenuItemByIdRecursive(const wxMenu* menu, int id)
{ {
wxMenuItem* result = menu->FindItemForId( id ); wxMenuItem* result = menu->FindItem(id);
wxNode *node = menu->m_items.First(); wxNode *node = menu->m_items.First();
while (node && result == 0) while ( node && result == NULL ) {
{
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_subMenu) result = FindMenuItemByIdRecursive( item->m_subMenu, id ); if ( item->IsSubMenu() )
result = FindMenuItemByIdRecursive( item->GetSubMenu(), id );
node = node->Next(); node = node->Next();
}; };
return result; return result;
}; };
@@ -142,7 +145,10 @@ void gtk_menu_clicked_callback( GtkWidget *widget, gpointer data )
wxMenu *menu = (wxMenu*)data; wxMenu *menu = (wxMenu*)data;
int id = menu->FindMenuIdByMenuItem(widget); int id = menu->FindMenuIdByMenuItem(widget);
if (!menu->Enabled(id)) return; wxASSERT( id != -1 ); // should find it!
if (!menu->IsEnabled(id))
return;
wxCommandEvent event( wxEVENT_TYPE_MENU_COMMAND, id ); wxCommandEvent event( wxEVENT_TYPE_MENU_COMMAND, id );
event.SetEventObject( menu ); event.SetEventObject( menu );
@@ -153,39 +159,43 @@ void gtk_menu_clicked_callback( GtkWidget *widget, gpointer data )
IMPLEMENT_DYNAMIC_CLASS(wxMenuItem,wxObject) IMPLEMENT_DYNAMIC_CLASS(wxMenuItem,wxObject)
wxMenuItem::wxMenuItem(void) wxMenuItem::wxMenuItem()
{ {
m_id = 0; m_id = ID_SEPARATOR;
m_text = "";
m_isCheckMenu = FALSE; m_isCheckMenu = FALSE;
m_checked = FALSE; m_isChecked = FALSE;
m_isSubMenu = FALSE; m_isEnabled = TRUE;
m_subMenu = NULL; m_subMenu = NULL;
m_helpStr = "";
m_menuItem = NULL; m_menuItem = NULL;
}; };
void wxMenuItem::SetText(const wxString& str)
{
for ( const char *pc = str; *pc != '\0'; pc++ ) {
if ( *pc == '&' )
pc++; // skip it
m_text << *pc;
}
}
void wxMenuItem::Check( bool check ) void wxMenuItem::Check( bool check )
{ {
if ( IsCheckable() ) wxCHECK_RET( IsCheckable(), "can't check uncheckable item!" )
{
m_checked = check; m_isChecked = check;
gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check ); gtk_check_menu_item_set_state( (GtkCheckMenuItem*)m_menuItem, (gint)check );
} }
}
bool wxMenuItem::IsChecked() const bool wxMenuItem::IsChecked() const
{ {
if ( IsCheckable() ) wxCHECK( IsCheckable(), FALSE ); // can't get state of uncheckable item!
{
return ((GtkCheckMenuItem*)m_menuItem)->active != 0;
}
return FALSE;
}
void wxMenuItem::Enable( bool enable ) bool bIsChecked = ((GtkCheckMenuItem*)m_menuItem)->active != 0;
{
m_isEnabled = enable; wxASSERT( bIsChecked == m_isChecked ); // consistency check
return bIsChecked;
} }
IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenu,wxEvtHandler)
@@ -198,68 +208,53 @@ wxMenu::wxMenu( const wxString &title )
m_menu = gtk_menu_new(); // Do not show! m_menu = gtk_menu_new(); // Do not show!
}; };
void wxMenu::AppendSeparator(void) void wxMenu::AppendSeparator()
{ {
wxMenuItem *mitem = new wxMenuItem(); wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = ID_SEPARATOR; mitem->SetId(ID_SEPARATOR);
mitem->m_text = "";
mitem->m_helpStr = ""; GtkWidget *menuItem = gtk_menu_item_new();
mitem->m_isCheckMenu = FALSE; gtk_menu_append( GTK_MENU(m_menu), menuItem );
mitem->m_isEnabled = TRUE; gtk_widget_show( menuItem );
mitem->m_menuItem = gtk_menu_item_new(); mitem->SetMenuItem(menuItem);
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem ); m_items.Append( mitem );
}; };
void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool checkable ) void wxMenu::Append( int id, const wxString &item, const wxString &helpStr, bool checkable )
{ {
wxMenuItem *mitem = new wxMenuItem(); wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = id; mitem->SetId(id);
mitem->SetText(item);
mitem->SetHelpString(helpStr);
mitem->SetCheckable(checkable);
const char *text = mitem->GetText();
GtkWidget *menuItem = checkable ? gtk_check_menu_item_new_with_label(text)
: gtk_menu_item_new_with_label(text);
mitem->SetMenuItem(menuItem);
mitem->m_text = item; gtk_signal_connect( GTK_OBJECT(menuItem), "activate",
size_t pos; GTK_SIGNAL_FUNC(gtk_menu_clicked_callback),
do { (gpointer*)this );
pos = mitem->m_text.First( '&' );
if (pos != wxString::npos) mitem->m_text.Remove( pos, 1 );
} while (pos != wxString::npos);
mitem->m_helpStr = helpStr; gtk_menu_append( GTK_MENU(m_menu), menuItem );
mitem->m_isCheckMenu = checkable; gtk_widget_show( menuItem );
mitem->m_isEnabled = TRUE;
if (checkable)
mitem->m_menuItem = gtk_check_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
else
mitem->m_menuItem = gtk_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) );
gtk_signal_connect( GTK_OBJECT(mitem->m_menuItem), "activate",
GTK_SIGNAL_FUNC(gtk_menu_clicked_callback), (gpointer*)this );
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem ); m_items.Append( mitem );
}; };
void wxMenu::Append( int id, const wxString &item, wxMenu *subMenu, const wxString &helpStr ) void wxMenu::Append( int id, const wxString &text, wxMenu *subMenu, const wxString &helpStr )
{ {
wxMenuItem *mitem = new wxMenuItem(); wxMenuItem *mitem = new wxMenuItem();
mitem->m_id = id; mitem->SetId(id);
mitem->m_text = item; mitem->SetText(text);
mitem->m_isEnabled = TRUE;
size_t pos; GtkWidget *menuItem = gtk_menu_item_new_with_label(mitem->GetText());
do { mitem->SetHelpString(helpStr);
pos = mitem->m_text.First( '&' ); mitem->SetMenuItem(menuItem);
if (pos != wxString::npos) mitem->m_text.Remove( pos, 1 ); mitem->SetSubMenu(subMenu);
} while (pos != wxString::npos);
mitem->m_helpStr = helpStr; gtk_menu_item_set_submenu( GTK_MENU_ITEM(menuItem), subMenu->m_menu );
mitem->m_menuItem = gtk_menu_item_new_with_label( WXSTRINGCAST(mitem->m_text) ); gtk_menu_append( GTK_MENU(m_menu), menuItem );
gtk_widget_show( menuItem );
mitem->m_subMenu = subMenu;
gtk_menu_item_set_submenu( GTK_MENU_ITEM(mitem->m_menuItem), subMenu->m_menu );
gtk_menu_append( GTK_MENU(m_menu), mitem->m_menuItem );
gtk_widget_show( mitem->m_menuItem );
m_items.Append( mitem ); m_items.Append( mitem );
}; };
@@ -277,77 +272,51 @@ int wxMenu::FindItem( const wxString itemString ) const
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_text == s) return item->m_id; if (item->GetText() == s)
return item->GetId();
node = node->Next(); node = node->Next();
}; };
return -1; return -1;
}; };
wxMenuItem* wxMenu::FindItemForId( int id ) const
{
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_id == id) return item;
node = node->Next();
}
return NULL;
}
void wxMenu::Check( int id, bool Flag )
{
wxMenuItem* item = FindItemForId( id );
if (item) item->Check(Flag);
};
void wxMenu::Enable( int id, bool enable ) void wxMenu::Enable( int id, bool enable )
{ {
wxNode *node = m_items.First(); wxMenuItem *item = FindItem(id);
while (node) if ( item )
{ item->Enable(enable);
wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_id == id)
{
item->m_isEnabled = enable;
return;
};
node = node->Next();
};
}; };
bool wxMenu::Enabled( int id ) const bool wxMenu::IsEnabled( int id ) const
{ {
wxNode *node = m_items.First(); wxMenuItem *item = FindItem(id);
while (node) if ( item )
{ return item->IsEnabled();
wxMenuItem *item = (wxMenuItem*)node->Data(); else
if (item->m_id == id) return item->m_isEnabled; return FALSE;
node = node->Next();
}; };
void wxMenu::Check( int id, bool enable )
{
wxMenuItem *item = FindItem(id);
if ( item )
item->Check(enable);
};
bool wxMenu::IsChecked( int id ) const
{
wxMenuItem *item = FindItem(id);
if ( item )
return item->IsChecked();
else
return FALSE; return FALSE;
}; };
void wxMenu::SetLabel( int id, const wxString &label ) void wxMenu::SetLabel( int id, const wxString &label )
{ {
wxString s( label ); wxMenuItem *item = FindItem(id);
size_t pos; if ( item )
do { item->SetText(label);
pos = s.First( '&' );
if (pos != wxString::npos) s.Remove( pos, 1 );
} while (pos != wxString::npos);
wxNode *node = m_items.First();
while (node)
{
wxMenuItem *item = (wxMenuItem*)node->Data();
item->m_text = s;
if (item->m_id == id)
{
gtk_label_set( GTK_LABEL( GTK_BIN(item->m_menuItem)->child ), WXSTRINGCAST(s) );
};
node = node->Next();
};
}; };
int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
@@ -356,18 +325,35 @@ int wxMenu::FindMenuIdByMenuItem( GtkWidget *menuItem ) const
while (node) while (node)
{ {
wxMenuItem *item = (wxMenuItem*)node->Data(); wxMenuItem *item = (wxMenuItem*)node->Data();
if (item->m_menuItem == menuItem) return item->m_id; if (item->GetMenuItem() == menuItem)
return item->GetId();
node = node->Next(); node = node->Next();
}; };
return -1; return -1;
}; };
wxMenuItem *wxMenu::FindItem(int id) const
{
wxNode *node = m_items.First();
while (node) {
wxMenuItem *item = (wxMenuItem*)node->Data();
if ( item->GetId() == id )
return item;
node = node->Next();
};
wxLogDebug("wxMenu::FindItem: item %d not found.", id);
return NULL;
}
void wxMenu::SetInvokingWindow( wxWindow *win ) void wxMenu::SetInvokingWindow( wxWindow *win )
{ {
m_invokingWindow = win; m_invokingWindow = win;
}; };
wxWindow *wxMenu::GetInvokingWindow(void) wxWindow *wxMenu::GetInvokingWindow()
{ {
return m_invokingWindow; return m_invokingWindow;
}; };