git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36568
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
{
wxMenuList::compatibility_iterator menuIter = menuList.GetFirst();
{
wxMenuList::compatibility_iterator menuIter = menuList.GetFirst();
- while (pos-- > 0) menuIter = menuIter->GetNext();
+ while (pos-- > 0)
+ menuIter = menuIter->GetNext();
return menuIter->GetData() ;
}
return menuIter->GetData() ;
}
wxMenu *pSubMenu = pItem->GetSubMenu() ;
if ( pSubMenu != NULL )
{
wxMenu *pSubMenu = pItem->GetSubMenu() ;
if ( pSubMenu != NULL )
{
- wxASSERT_MSG( pSubMenu->m_hMenu != NULL , wxT("invalid submenu added"));
+ wxASSERT_MSG( pSubMenu->m_hMenu != NULL , wxT("invalid submenu added"));
pSubMenu->m_menuParent = this ;
if (wxMenuBar::MacGetInstalledMenuBar() == GetMenuBar())
pSubMenu->m_menuParent = this ;
if (wxMenuBar::MacGetInstalledMenuBar() == GetMenuBar())
pSubMenu->MacBeforeDisplay( true ) ;
pSubMenu->MacBeforeDisplay( true ) ;
- UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding() , pSubMenu->m_macMenuId);
+ UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding(), pSubMenu->m_macMenuId);
- UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding() , pos, pSubMenu->m_macMenuId);
+ UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding(), pos, pSubMenu->m_macMenuId);
+
pItem->UpdateItemBitmap() ;
pItem->UpdateItemStatus() ;
}
pItem->UpdateItemBitmap() ;
pItem->UpdateItemStatus() ;
}
pItem->UpdateItemBitmap() ;
pItem->UpdateItemStatus() ;
pItem->UpdateItemBitmap() ;
pItem->UpdateItemStatus() ;
- if ( pItem->GetId() == idMenuTitle )
- {
+ if ( pItem->GetId() == idMenuTitle )
UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , pos , false ) ;
UMAEnableMenuItem(MAC_WXHMENU(m_hMenu) , pos , false ) ;
// if we're already attached to the menubar, we must update it
if ( IsAttached() && GetMenuBar()->IsAttached() )
// if we're already attached to the menubar, we must update it
if ( IsAttached() && GetMenuBar()->IsAttached() )
}
if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) )
}
if ( !wxMenuBase::DoAppend(item) || !DoInsertOrAppend(item) )
// check the item initially
item->Check(true);
// check the item initially
item->Check(true);
{
if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos))
return item;
{
if (wxMenuBase::DoInsert(pos, item) && DoInsertOrAppend(item, pos))
return item;
}
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
}
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
// we need to find the items position in the child list
size_t pos;
wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
// we need to find the items position in the child list
size_t pos;
wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
for ( pos = 0; node; pos++ )
{
if ( node->GetData() == item )
for ( pos = 0; node; pos++ )
{
if ( node->GetData() == item )
::DeleteMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1);
if ( IsAttached() && GetMenuBar()->IsAttached() )
::DeleteMenuItem(MAC_WXHMENU(m_hMenu) , pos + 1);
if ( IsAttached() && GetMenuBar()->IsAttached() )
// otherwise, the change won't be visible
GetMenuBar()->Refresh();
// otherwise, the change won't be visible
GetMenuBar()->Refresh();
// and from internal data structures
return wxMenuBase::DoRemove(item);
// and from internal data structures
return wxMenuBase::DoRemove(item);
// Try the menu's event handler
if ( /* !processed && */ GetEventHandler())
// Try the menu's event handler
if ( /* !processed && */ GetEventHandler())
processed = GetEventHandler()->ProcessEvent(event);
processed = GetEventHandler()->ProcessEvent(event);
- // Try the window the menu was popped up from (and up through the
- // hierarchy)
+ // Try the window the menu was popped up from
+ // (and up through the hierarchy)
wxWindow *win = GetInvokingWindow();
if ( !processed && win )
processed = win->GetEventHandler()->ProcessEvent(event);
wxWindow *win = GetInvokingWindow();
if ( !processed && win )
processed = win->GetEventHandler()->ProcessEvent(event);
// ---------------------------------------------------------------------------
// other
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// other
// ---------------------------------------------------------------------------
}
// MacOS needs to know about submenus somewhere within this menu
}
// MacOS needs to know about submenus somewhere within this menu
-// before it can be displayed , also hide special menu items like preferences
-// that are handled by the OS
+// before it can be displayed, also hide special menu items
+// like preferences that are handled by the OS
void wxMenu::MacBeforeDisplay( bool isSubMenu )
{
wxMenuItem* previousItem = NULL ;
size_t pos ;
wxMenuItemList::compatibility_iterator node;
wxMenuItem *item;
void wxMenu::MacBeforeDisplay( bool isSubMenu )
{
wxMenuItem* previousItem = NULL ;
size_t pos ;
wxMenuItemList::compatibility_iterator node;
wxMenuItem *item;
for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
// what we do here is to hide the special items which are
// shown in the application menu anyhow -- it doesn't make
// sense to show them in their normal place as well
// what we do here is to hide the special items which are
// shown in the application menu anyhow -- it doesn't make
// sense to show them in their normal place as well
- #endif // TARGET_CARBON
previousItem = item ;
}
if ( isSubMenu )
::InsertMenu(MAC_WXHMENU( GetHMenu()), -1);
previousItem = item ;
}
if ( isSubMenu )
::InsertMenu(MAC_WXHMENU( GetHMenu()), -1);
// undo all changes from the MacBeforeDisplay call
void wxMenu::MacAfterDisplay( bool isSubMenu )
{
// undo all changes from the MacBeforeDisplay call
void wxMenu::MacAfterDisplay( bool isSubMenu )
{
::DeleteMenu(MacGetMenuId());
wxMenuItem* previousItem = NULL ;
::DeleteMenu(MacGetMenuId());
wxMenuItem* previousItem = NULL ;
wxMenuItemList::compatibility_iterator node;
wxMenuItem *item;
wxMenuItemList::compatibility_iterator node;
wxMenuItem *item;
for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
item = (wxMenuItem *)node->GetData();
{
// no need to undo hidings
}
{
// no need to undo hidings
}
previousItem = item ;
}
}
previousItem = item ;
}
}
wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
{
Init();
wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], long WXUNUSED(style))
{
Init();
{
if (s_macCommonMenuBar == this)
s_macCommonMenuBar = NULL;
{
if (s_macCommonMenuBar == this)
s_macCommonMenuBar = NULL;
if (s_macInstalledMenuBar == this)
{
::ClearMenuBar();
s_macInstalledMenuBar = NULL;
}
if (s_macInstalledMenuBar == this)
{
::ClearMenuBar();
s_macInstalledMenuBar = NULL;
}
}
void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect))
}
void wxMenuBar::Refresh(bool WXUNUSED(eraseBackground), const wxRect *WXUNUSED(rect))
return ;
MenuBarHandle menubar = NULL ;
return ;
MenuBarHandle menubar = NULL ;
#if TARGET_API_MAC_OSX
menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ;
#else
menubar = NewHandleClear( 12 ) ;
(*menubar)[3] = 0x0a ;
#endif
#if TARGET_API_MAC_OSX
menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ;
#else
menubar = NewHandleClear( 12 ) ;
(*menubar)[3] = 0x0a ;
#endif
::SetMenuBar( menubar ) ;
DisposeMenuBar( menubar ) ;
MenuHandle appleMenu = NULL ;
::SetMenuBar( menubar ) ;
DisposeMenuBar( menubar ) ;
MenuHandle appleMenu = NULL ;
if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr )
{
for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i )
if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr )
{
for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i )
DeleteMenuItem( mh , i ) ;
DeleteMenuItem( mh , i ) ;
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId)
{
#if TARGET_CARBON
if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId)
{
else
EnableMenuCommand( NULL , kHICommandPreferences ) ;
}
else
EnableMenuCommand( NULL , kHICommandPreferences ) ;
}
// Unlike preferences which may or may not exist, the Quit item should be always
// enabled unless it is added by the application and then disabled, otherwise
// a program would be required to add an item with wxID_EXIT in order to get the
// Unlike preferences which may or may not exist, the Quit item should be always
// enabled unless it is added by the application and then disabled, otherwise
// a program would be required to add an item with wxID_EXIT in order to get the
EnableMenuCommand( NULL , kHICommandQuit ) ;
}
#endif
EnableMenuCommand( NULL , kHICommandQuit ) ;
}
#endif
wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst();
wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst();
for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext())
{
wxMenuItemList::compatibility_iterator node;
for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext())
{
wxMenuItemList::compatibility_iterator node;
int pos ;
wxMenu* menu = menuIter->GetData() , *subMenu = NULL ;
int pos ;
wxMenu* menu = menuIter->GetData() , *subMenu = NULL ;
- if( m_titles[i] == wxT("?") || m_titles[i] == wxT("&?") || m_titles[i] == wxApp::s_macHelpMenuTitleName )
+ if ( m_titles[i] == wxT("?") || m_titles[i] == wxT("&?") || m_titles[i] == wxApp::s_macHelpMenuTitleName )
{
for (pos = 0 , node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
{
for (pos = 0 , node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
{
if ( mh == NULL )
{
MenuItemIndex firstUserHelpMenuItem ;
if ( mh == NULL )
{
MenuItemIndex firstUserHelpMenuItem ;
- if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr )
- {
- }
- else
+ if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr )
{
mh = NULL ;
break ;
}
}
}
{
mh = NULL ;
break ;
}
}
}
if ( item->IsSeparator() )
{
if ( mh )
if ( item->IsSeparator() )
{
if ( mh )
- UMAAppendMenuItem(mh, item->GetText() , wxFont::GetDefaultEncoding(), entry);
+ UMAAppendMenuItem(mh, item->GetText() , wxFont::GetDefaultEncoding(), entry);
SetMenuItemCommandID( mh , CountMenuItems(mh) , wxIdToMacCommand ( item->GetId() ) ) ;
SetMenuItemRefCon( mh , CountMenuItems(mh) , (UInt32)item ) ;
}
SetMenuItemCommandID( mh , CountMenuItems(mh) , wxIdToMacCommand ( item->GetId() ) ) ;
SetMenuItemRefCon( mh , CountMenuItems(mh) , (UInt32)item ) ;
}
::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0);
}
}
::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0);
}
}
// take care of the about menu item wherever it is
{
wxMenu* aboutMenu ;
// take care of the about menu item wherever it is
{
wxMenu* aboutMenu ;
UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ;
}
}
UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ;
}
}
if ( GetAutoWindowMenu() )
{
if ( MacGetWindowMenuHMenu() == NULL )
if ( GetAutoWindowMenu() )
{
if ( MacGetWindowMenuHMenu() == NULL )
CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ;
CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ;
InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ;
}
InsertMenu( (MenuHandle) MacGetWindowMenuHMenu() , 0 ) ;
}
::DrawMenuBar() ;
s_macInstalledMenuBar = this;
}
::DrawMenuBar() ;
s_macInstalledMenuBar = this;
}
void wxMenuBar::EnableTop(size_t pos, bool enable)
{
wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
void wxMenuBar::EnableTop(size_t pos, bool enable)
{
wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
_wxMenuAt(m_menus, pos)->MacEnableMenu( enable ) ;
Refresh();
}
_wxMenuAt(m_menus, pos)->MacEnableMenu( enable ) ;
Refresh();
}
-bool wxMenuBar::Enable( bool enable)
+bool wxMenuBar::Enable(bool enable)
{
wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") );
{
wxCHECK_MSG( IsAttached(), false, wxT("doesn't work with unattached menubars") );
size_t i;
for (i = 0; i < GetMenuCount(); i++)
size_t i;
for (i = 0; i < GetMenuCount(); i++)
m_titles[pos] = label;
if ( !IsAttached() )
m_titles[pos] = label;
if ( !IsAttached() )
_wxMenuAt(m_menus, pos)->SetTitle( label ) ;
_wxMenuAt(m_menus, pos)->SetTitle( label ) ;
// ---------------------------------------------------------------------------
// wxMenuBar construction
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// wxMenuBar construction
// ---------------------------------------------------------------------------
wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
if ( !menuOld )
return false;
wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title);
if ( !menuOld )
return false;
m_titles[pos] = title;
if ( IsAttached() )
m_titles[pos] = title;
if ( IsAttached() )
{
menuOld->MacAfterDisplay( false ) ;
::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
{
menuOld->MacAfterDisplay( false ) ;
::DeleteMenu( menuOld->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
- {
- menu->MacBeforeDisplay( false ) ;
- UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , m_font.GetEncoding() ) ;
- if ( pos == m_menus.GetCount() - 1)
- {
- ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
- }
- else
- {
- ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , _wxMenuAt(m_menus, pos+1)->MacGetMenuId() ) ;
- }
- }
+
+ menu->MacBeforeDisplay( false ) ;
+ UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , title , m_font.GetEncoding() ) ;
+ if ( pos == m_menus.GetCount() - 1)
+ ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
+ else
+ ::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , _wxMenuAt(m_menus, pos + 1)->MacGetMenuId() ) ;
if (m_invokingWindow)
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
if (m_invokingWindow)
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
if (s_macInstalledMenuBar == this)
{
menu->MacBeforeDisplay( false ) ;
if (s_macInstalledMenuBar == this)
{
menu->MacBeforeDisplay( false ) ;
if ( pos == (size_t) -1 || pos + 1 == m_menus.GetCount() )
if ( pos == (size_t) -1 || pos + 1 == m_menus.GetCount() )
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , 0 ) ;
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , _wxMenuAt(m_menus, pos+1)->MacGetMenuId() ) ;
::InsertMenu( MAC_WXHMENU(menu->GetHMenu()) , _wxMenuAt(m_menus, pos+1)->MacGetMenuId() ) ;
if (m_invokingWindow)
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
if (m_invokingWindow)
wxMenubarSetInvokingWindow( menu, m_invokingWindow );
if ( IsAttached() )
{
if (s_macInstalledMenuBar == this)
if ( IsAttached() )
{
if (s_macInstalledMenuBar == this)
::DeleteMenu( menu->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
::DeleteMenu( menu->MacGetMenuId() /* m_menus[pos]->MacGetMenuId() */ ) ;
bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
{
WXHMENU submenu = menu ? menu->GetHMenu() : 0;
bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
{
WXHMENU submenu = menu ? menu->GetHMenu() : 0;
- wxCHECK_MSG( submenu, false, wxT("can't append invalid menu to menubar") );
+ wxCHECK_MSG( submenu, false, wxT("can't append invalid menu to menubar") );
if ( !wxMenuBarBase::Append(menu, title) )
return false;
if ( !wxMenuBarBase::Append(menu, title) )
return false;
static void wxMenubarUnsetInvokingWindow( wxMenu *menu )
{
menu->SetInvokingWindow( (wxWindow*) NULL );
static void wxMenubarUnsetInvokingWindow( wxMenu *menu )
{
menu->SetInvokingWindow( (wxWindow*) NULL );
wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
while (node)
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() );
while (node)
{
wxMenuItem *menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() );
node = node->GetNext();
}
}
node = node->GetNext();
}
}
static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
{
menu->SetInvokingWindow( win );
wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
- wxMenuItem *menuitem = node->GetData();
+ menuitem = node->GetData();
if (menuitem->IsSubMenu())
wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win );
if (menuitem->IsSubMenu())
wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win );
node = node->GetNext();
}
}
node = node->GetNext();
}
}
void wxMenuBar::UnsetInvokingWindow()
{
m_invokingWindow = (wxWindow*) NULL;
void wxMenuBar::UnsetInvokingWindow()
{
m_invokingWindow = (wxWindow*) NULL;
wxMenuList::compatibility_iterator node = m_menus.GetFirst();
wxMenuList::compatibility_iterator node = m_menus.GetFirst();
- wxMenu *menu = node->GetData();
+ menu = node->GetData();
wxMenubarUnsetInvokingWindow( menu );
wxMenubarUnsetInvokingWindow( menu );
node = node->GetNext();
}
}
node = node->GetNext();
}
}
void wxMenuBar::SetInvokingWindow(wxFrame *frame)
{
m_invokingWindow = frame;
void wxMenuBar::SetInvokingWindow(wxFrame *frame)
{
m_invokingWindow = frame;
wxMenuList::compatibility_iterator node = m_menus.GetFirst();
wxMenuList::compatibility_iterator node = m_menus.GetFirst();
- wxMenu *menu = node->GetData();
+ menu = node->GetData();
wxMenubarSetInvokingWindow( menu, frame );
wxMenubarSetInvokingWindow( menu, frame );
node = node->GetNext();
}
}
node = node->GetNext();
}
}
{
wxMenuBarBase::Attach( frame ) ;
}
{
wxMenuBarBase::Attach( frame ) ;
}
// ---------------------------------------------------------------------------
// wxMenuBar searching for menu items
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
// wxMenuBar searching for menu items
// ---------------------------------------------------------------------------
wxMenuItem *item = NULL;
size_t count = GetMenuCount();
for ( size_t i = 0; !item && (i < count); i++ )
wxMenuItem *item = NULL;
size_t count = GetMenuCount();
for ( size_t i = 0; !item && (i < count); i++ )
item = _wxMenuAt(m_menus, i)->FindItem(id, itemMenu);
item = _wxMenuAt(m_menus, i)->FindItem(id, itemMenu);