// Author: Stefan Csomor
// Modified by:
// Created: 1998-01-01
-// RCS-ID: $Id: menu.cpp 54129 2008-06-11 19:30:52Z SC $
+// RCS-ID: $Id$
// Copyright: (c) Stefan Csomor
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/wxprec.h"
+#if wxUSE_MENUS
+
#include "wx/menu.h"
#ifndef WX_PRECOMP
#include "wx/app.h"
#include "wx/utils.h"
#include "wx/frame.h"
+ #include "wx/dialog.h"
#include "wx/menuitem.h"
#endif
// ============================================================================
// implementation
// ============================================================================
-static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ;
-static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win );
// Menus
m_startRadioGroup = -1;
m_allowRearrange = true;
m_noEventsMode = false;
-
+
m_peer = wxMenuImpl::Create( this, wxStripMenuCodes(m_title) );
pSubMenu->DoRearrange();
}
else
- {
+ {
if ( pItem->GetId() == idMenuTitle )
pItem->GetMenu()->Enable( idMenuTitle, false );
}
wxMenuItem* wxMenu::DoAppend(wxMenuItem *item)
{
- wxCHECK_MSG( item, NULL, _T("NULL item in wxMenu::DoAppend") );
+ wxCHECK_MSG( item, NULL, wxT("NULL item in wxMenu::DoAppend") );
bool check = false;
}
else
{
- wxFAIL_MSG( _T("where is the radio group start item?") );
+ wxFAIL_MSG( wxT("where is the radio group start item?") );
}
}
}
// Try the window the menu was popped up from
// (and up through the hierarchy)
- wxWindow *win = GetInvokingWindow();
+ wxWindow *win = GetWindow();
if ( !processed && win )
processed = win->HandleWindowEvent(event);
// other
// ---------------------------------------------------------------------------
-wxWindow *wxMenu::GetWindow() const
-{
- if ( m_invokingWindow != NULL )
- return m_invokingWindow;
- else if ( GetMenuBar() != NULL)
- return (wxWindow *) GetMenuBar()->GetFrame();
-
- return NULL;
-}
-
// 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
{
if ( !AllowRearrange() )
return;
-
+
wxMenuItem* previousItem = NULL ;
size_t pos ;
wxMenuItemList::compatibility_iterator node;
{
// next (i.e. second as we must be first) item is
// the separator to hide
- wxASSERT_MSG( pos == 0, _T("should be the menu start") );
+ wxASSERT_MSG( pos == 0, wxT("should be the menu start") );
sepToHide = next;
}
else if ( GetMenuItems().GetCount() == pos + 1 &&
// (and up through the hierarchy)
if ( !processed )
{
- const wxMenuBase *menu = this;
- while ( menu )
- {
- wxWindow *win = menu->GetInvokingWindow();
- if ( win )
- {
- processed = win->HandleWindowEvent(event);
- break;
- }
-
- menu = menu->GetParent();
- }
+ wxWindow *win = GetWindow();
+ if ( win )
+ processed = win->HandleWindowEvent(event);
}
if ( !processed && senderWindow != NULL)
if (event.GetSetEnabled())
Enable(id, event.GetEnabled());
}
+ else
+ {
+#if wxOSX_USE_CARBON
+ // these two items are also managed by the Carbon Menu Manager, therefore we must
+ // always reset them ourselves
+ UInt32 cmd = 0;
+
+ if ( id == wxApp::s_macExitMenuItemId )
+ {
+ cmd = kHICommandQuit;
+ }
+ else if (id == wxApp::s_macPreferencesMenuItemId )
+ {
+ cmd = kHICommandPreferences;
+ }
+
+ if ( cmd != 0 )
+ {
+ if ( !item->IsEnabled() || wxDialog::OSXHasModalDialogsOpen() )
+ DisableMenuCommand( NULL , cmd ) ;
+ else
+ EnableMenuCommand( NULL , cmd ) ;
+
+ }
+#endif
+ }
+
return processed;
}
}
else
{
- wxWindow *win = GetInvokingWindow();
+ wxWindow *win = GetWindow();
if (win)
{
if ( win->HandleWindowEvent(wxevent) )
{
m_eventHandler = this;
m_menuBarFrame = NULL;
- m_invokingWindow = (wxWindow*) NULL;
m_rootMenu = new wxMenu();
- wxMenu* applemenu = new wxMenu();
- applemenu->SetAllowRearrange(false);
- applemenu->Append( wxApp::s_macAboutMenuItemId, "About..." );
- applemenu->AppendSeparator();
- applemenu->Append( wxApp::s_macPreferencesMenuItemId, "Preferences..." );
- applemenu->AppendSeparator();
-
-#if ! wxOSX_USE_CARBON
- applemenu->Append( wxApp::s_macExitMenuItemId, "Quit\tCtrl+Q" );
-#endif
+ m_rootMenu->Attach(this);
- m_rootMenu->AppendSubMenu(applemenu, "\x14") ;
+ m_appleMenu = new wxMenu();
+ m_appleMenu->SetAllowRearrange(false);
+
+ // Create standard items unless the application explicitly disabled this by
+ // setting the corresponding ids to wxID_NONE: although this is not
+ // recommended, sometimes these items really don't make sense.
+ if ( wxApp::s_macAboutMenuItemId != wxID_NONE )
+ {
+ wxString aboutLabel("About");
+ if ( wxTheApp )
+ aboutLabel << ' ' << wxTheApp->GetAppDisplayName();
+ else
+ aboutLabel << "...";
+ m_appleMenu->Append( wxApp::s_macAboutMenuItemId, aboutLabel);
+ m_appleMenu->AppendSeparator();
+ }
+
+#if !wxOSX_USE_CARBON
+ if ( wxApp::s_macPreferencesMenuItemId != wxID_NONE )
+ {
+ m_appleMenu->Append( wxApp::s_macPreferencesMenuItemId,
+ "Preferences...\tCtrl+," );
+ m_appleMenu->AppendSeparator();
+ }
+
+ // Do always add "Quit" item unconditionally however, it can't be disabled.
+ m_appleMenu->Append( wxApp::s_macExitMenuItemId, "Quit\tCtrl+Q" );
+#endif // !wxOSX_USE_CARBON
+
+ m_rootMenu->AppendSubMenu(m_appleMenu, "\x14") ;
}
wxMenuBar::wxMenuBar()
{
if ( s_macInstalledMenuBar == this )
return ;
-
+
m_rootMenu->GetPeer()->MakeRoot();
+
#if 0
MenuBarHandle menubar = NULL ;
subMenu = item->GetSubMenu() ;
if (subMenu)
{
- // we don't support hierarchical menus in the help menu yet
+ UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding() );
+ MenuItemIndex position = CountMenuItems(mh);
+ ::SetMenuItemHierarchicalMenu(mh, position, MAC_WXHMENU(subMenu->GetHMenu()));
}
else
{
void wxMenuBar::EnableTop(size_t pos, bool enable)
{
wxCHECK_RET( IsAttached(), wxT("doesn't work with unattached menubars") );
-
+
m_rootMenu->FindItemByPosition( pos )->Enable(enable);
Refresh();
m_rootMenu->Remove(item);
m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
- if (m_invokingWindow)
- wxMenubarSetInvokingWindow( menu, m_invokingWindow );
-
return menuOld;
}
return false;
m_titles.Insert(title, pos);
-
- m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
- if (m_invokingWindow)
- wxMenubarSetInvokingWindow( menu, m_invokingWindow );
+ m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
return true;
}
m_rootMenu->AppendSubMenu(menu, title);
- // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables
- // adding menu later on.
- if (m_invokingWindow)
- wxMenubarSetInvokingWindow( menu, m_invokingWindow );
-
return true;
}
-static void wxMenubarUnsetInvokingWindow( wxMenu *menu )
-{
- menu->SetInvokingWindow( (wxWindow*) NULL );
- wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
-
- while (node)
- {
- wxMenuItem *menuitem = node->GetData();
- if (menuitem->IsSubMenu())
- wxMenubarUnsetInvokingWindow( menuitem->GetSubMenu() );
-
- node = node->GetNext();
- }
-}
-
-static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win )
-{
- menu->SetInvokingWindow( win );
- wxMenuItem *menuitem;
- wxMenuItemList::compatibility_iterator node = menu->GetMenuItems().GetFirst();
-
- while (node)
- {
- menuitem = node->GetData();
- if (menuitem->IsSubMenu())
- wxMenubarSetInvokingWindow( menuitem->GetSubMenu() , win );
-
- node = node->GetNext();
- }
-}
-
-void wxMenuBar::UnsetInvokingWindow()
-{
- m_invokingWindow = (wxWindow*) NULL;
- wxMenu *menu;
- wxMenuList::compatibility_iterator node = m_menus.GetFirst();
-
- while (node)
- {
- menu = node->GetData();
- wxMenubarUnsetInvokingWindow( menu );
-
- node = node->GetNext();
- }
-}
-
-void wxMenuBar::SetInvokingWindow(wxFrame *frame)
-{
- m_invokingWindow = frame;
- wxMenu *menu;
- wxMenuList::compatibility_iterator node = m_menus.GetFirst();
-
- while (node)
- {
- menu = node->GetData();
- wxMenubarSetInvokingWindow( menu, frame );
-
- node = node->GetNext();
- }
-}
-
void wxMenuBar::Detach()
{
wxMenuBarBase::Detach() ;
return item;
}
+
+#endif