// headers
// ----------------------------------------------------------------------------
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "menubase.h"
#endif
}
else {
// is it a function key?
- if ( current[0U] == 'f' && isdigit(current[1U]) &&
+ if ( current[0U] == 'f' && wxIsdigit(current[1U]) &&
(current.Len() == 2 ||
- (current.Len() == 3 && isdigit(current[2U]))) ) {
+ (current.Len() == 3 && wxIsdigit(current[2U]))) ) {
int n;
wxSscanf(current.c_str() + 1, wxT("%d"), &n);
void wxMenuBase::Init(long style)
{
- m_items.DeleteContents(TRUE);
-
m_menuBar = (wxMenuBar *)NULL;
m_menuParent = (wxMenu *)NULL;
m_style = style;
m_clientData = (void *)NULL;
m_eventHandler = this;
-
-#if wxUSE_MENU_CALLBACK
- m_callback = (wxFunction) NULL;
-#endif // wxUSE_MENU_CALLBACK
}
wxMenuBase::~wxMenuBase()
{
- // nothing to do, wxMenuItemList dtor will delete the menu items.
-
+ WX_CLEAR_LIST(wxMenuItemList, m_items);
+
// Actually, in GTK, the submenus have to get deleted first.
}
{
wxCHECK_MSG( item, FALSE, wxT("invalid item in wxMenu::Insert()") );
- wxMenuItemList::Node *node = m_items.Item(pos);
+ wxMenuItemList::compatibility_iterator node = m_items.Item(pos);
wxCHECK_MSG( node, FALSE, wxT("invalid index in wxMenu::Insert()") );
m_items.Insert(node, item);
wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item)
{
- wxMenuItemList::Node *node = m_items.Find(item);
+ wxMenuItemList::compatibility_iterator node = m_items.Find(item);
// if we get here, the item is valid or one of Remove() functions is broken
wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") );
// we detach the item, but we do delete the list node (i.e. don't call
// DetachNode() here!)
- node->SetData((wxMenuItem *)NULL); // to prevent it from deleting the item
- m_items.DeleteNode(node);
+ m_items.Erase(node);
// item isn't attached to anything any more
item->SetMenu((wxMenu *)NULL);
int wxMenuBase::FindItem(const wxString& text) const
{
wxString label = wxMenuItem::GetLabelFromText(text);
- for ( wxMenuItemList::Node *node = m_items.GetFirst();
+ for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
node;
node = node->GetNext() )
{
*itemMenu = NULL;
wxMenuItem *item = NULL;
- for ( wxMenuItemList::Node *node = m_items.GetFirst();
+ for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
node && !item;
node = node->GetNext() )
{
wxMenuItem *wxMenuBase::FindChildItem(int id, size_t *ppos) const
{
wxMenuItem *item = (wxMenuItem *)NULL;
- wxMenuItemList::Node *node = GetMenuItems().GetFirst();
+ wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
size_t pos;
for ( pos = 0; node; pos++ )
// find by position
wxMenuItem* wxMenuBase::FindItemByPosition(size_t position) const
{
- wxASSERT ( position > -1 && position < m_items.GetCount() );
- if ( position > -1 && position < m_items.GetCount() )
- return m_items.Item( position )->GetData();
- else
- return NULL;
+ wxCHECK_MSG( position < m_items.GetCount(), NULL,
+ _T("wxMenu::FindItemByPosition(): invalid menu index") );
+
+ return m_items.Item( position )->GetData();
}
// ----------------------------------------------------------------------------
if ( !source )
source = this;
- wxMenuItemList::Node* node = GetMenuItems().GetFirst();
+ wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
while ( node )
{
wxMenuItem* item = node->GetData();
if ( source->ProcessEvent(event) )
{
- // if anything changed, update the chanegd attribute
+ // if anything changed, update the changed attribute
if (event.GetSetText())
SetLabel(id, event.GetText());
if (event.GetSetChecked())
if ( item->GetSubMenu() )
item->GetSubMenu()->UpdateUI(source);
}
- //else: item is a separator (which don't process update UI events)
+ //else: item is a separator (which doesn't process update UI events)
node = node->GetNext();
}
bool processed = FALSE;
-#if wxUSE_MENU_CALLBACK
- // Try a callback
- if (m_callback)
- {
- (void)(*(m_callback))(*this, event);
- processed = TRUE;
- }
-#endif // wxUSE_MENU_CALLBACK
-
// Try the menu's event handler
if ( !processed )
{
wxMenuBarBase::wxMenuBarBase()
{
- // we own the menus when we get them
- m_menus.DeleteContents(TRUE);
-
// not attached yet
m_menuBarFrame = NULL;
}
wxMenuBarBase::~wxMenuBarBase()
{
- // nothing to do, the list will delete the menus because of the call to
- // DeleteContents() above
+ WX_CLEAR_LIST(wxMenuList, m_menus);
}
// ----------------------------------------------------------------------------
wxMenu *wxMenuBarBase::GetMenu(size_t pos) const
{
- wxMenuList::Node *node = m_menus.Item(pos);
+ wxMenuList::compatibility_iterator node = m_menus.Item(pos);
wxCHECK_MSG( node, NULL, wxT("bad index in wxMenuBar::GetMenu()") );
return node->GetData();
{
wxCHECK_MSG( menu, FALSE, wxT("can't insert NULL menu") );
- wxMenuList::Node *node = m_menus.Item(pos);
+ wxMenuList::compatibility_iterator node = m_menus.Item(pos);
wxCHECK_MSG( node, FALSE, wxT("bad index in wxMenuBar::Insert()") );
m_menus.Insert(node, menu);
{
wxCHECK_MSG( menu, NULL, wxT("can't insert NULL menu") );
- wxMenuList::Node *node = m_menus.Item(pos);
+ wxMenuList::compatibility_iterator node = m_menus.Item(pos);
wxCHECK_MSG( node, NULL, wxT("bad index in wxMenuBar::Replace()") );
wxMenu *menuOld = node->GetData();
wxMenu *wxMenuBarBase::Remove(size_t pos)
{
- wxMenuList::Node *node = m_menus.Item(pos);
+ wxMenuList::compatibility_iterator node = m_menus.Item(pos);
wxCHECK_MSG( node, NULL, wxT("bad index in wxMenuBar::Remove()") );
- node = m_menus.DetachNode(node);
- wxCHECK( node, NULL ); // unexpected
wxMenu *menu = node->GetData();
+ m_menus.Erase(node);
menu->Detach();
- delete node;
-
return menu;
}
*menu = NULL;
wxMenuItem *item = NULL;
- size_t count = GetMenuCount();
- for ( size_t i = 0; !item && (i < count); i++ )
+ size_t count = GetMenuCount(), i;
+ wxMenuList::const_iterator it;
+ for ( i = 0, it = m_menus.begin(); !item && (i < count); i++, it++ )
{
- item = m_menus[i]->FindItem(id, menu);
+ item = (*it)->FindItem(id, menu);
}
return item;
wxString label = wxMenuItem::GetLabelFromText(menu);
int i = 0;
- wxMenuList::Node *node;
+ wxMenuList::compatibility_iterator node;
for ( node = m_menus.GetFirst(); node; node = node->GetNext(), i++ )
{
if ( label == wxMenuItem::GetLabelFromText(GetLabelTop(i)) )