fixed crash when no wx menubar is created

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25950 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor
2004-02-26 07:28:25 +00:00
parent b635e17fef
commit 9f2bfce7b2
2 changed files with 86 additions and 78 deletions

View File

@@ -335,49 +335,53 @@ static pascal OSStatus
MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{ {
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar(); wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
wxFrame* win = mbar->GetFrame();
if ( win ) if ( mbar )
{ {
// VZ: we could find the menu from its handle here by examining all wxFrame* win = mbar->GetFrame();
// the menus in the menu bar recursively but knowing that neither if ( win )
// wxMSW nor wxGTK do it why bother...
#if 0
MenuRef menuRef;
GetEventParameter(event,
kEventParamDirectObject,
typeMenuRef, NULL,
sizeof(menuRef), NULL,
&menuRef);
#endif // 0
wxEventType type=0;
MenuCommand cmd=0;
switch (GetEventKind(event))
{ {
case kEventMenuOpening:
type = wxEVT_MENU_OPEN; // VZ: we could find the menu from its handle here by examining all
break; // the menus in the menu bar recursively but knowing that neither
case kEventMenuClosed: // wxMSW nor wxGTK do it why bother...
type = wxEVT_MENU_CLOSE; #if 0
break; MenuRef menuRef;
case kEventMenuTargetItem:
type = wxEVT_MENU_HIGHLIGHT; GetEventParameter(event,
GetEventParameter(event, kEventParamMenuCommand, kEventParamDirectObject,
typeMenuCommand, NULL, typeMenuRef, NULL,
sizeof(cmd), NULL, &cmd); sizeof(menuRef), NULL,
if (cmd == 0) return eventNotHandledErr; &menuRef);
break; #endif // 0
default:
wxFAIL_MSG(wxT("Unexpected menu event kind")); wxEventType type=0;
break; MenuCommand cmd=0;
switch (GetEventKind(event))
{
case kEventMenuOpening:
type = wxEVT_MENU_OPEN;
break;
case kEventMenuClosed:
type = wxEVT_MENU_CLOSE;
break;
case kEventMenuTargetItem:
type = wxEVT_MENU_HIGHLIGHT;
GetEventParameter(event, kEventParamMenuCommand,
typeMenuCommand, NULL,
sizeof(cmd), NULL, &cmd);
if (cmd == 0) return eventNotHandledErr;
break;
default:
wxFAIL_MSG(wxT("Unexpected menu event kind"));
break;
}
wxMenuEvent wxevent(type, cmd);
wxevent.SetEventObject(win);
(void)win->GetEventHandler()->ProcessEvent(wxevent);
} }
wxMenuEvent wxevent(type, cmd);
wxevent.SetEventObject(win);
(void)win->GetEventHandler()->ProcessEvent(wxevent);
} }
return eventNotHandledErr; return eventNotHandledErr;

View File

@@ -335,49 +335,53 @@ static pascal OSStatus
MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{ {
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar(); wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
wxFrame* win = mbar->GetFrame();
if ( win ) if ( mbar )
{ {
// VZ: we could find the menu from its handle here by examining all wxFrame* win = mbar->GetFrame();
// the menus in the menu bar recursively but knowing that neither if ( win )
// wxMSW nor wxGTK do it why bother...
#if 0
MenuRef menuRef;
GetEventParameter(event,
kEventParamDirectObject,
typeMenuRef, NULL,
sizeof(menuRef), NULL,
&menuRef);
#endif // 0
wxEventType type=0;
MenuCommand cmd=0;
switch (GetEventKind(event))
{ {
case kEventMenuOpening:
type = wxEVT_MENU_OPEN; // VZ: we could find the menu from its handle here by examining all
break; // the menus in the menu bar recursively but knowing that neither
case kEventMenuClosed: // wxMSW nor wxGTK do it why bother...
type = wxEVT_MENU_CLOSE; #if 0
break; MenuRef menuRef;
case kEventMenuTargetItem:
type = wxEVT_MENU_HIGHLIGHT; GetEventParameter(event,
GetEventParameter(event, kEventParamMenuCommand, kEventParamDirectObject,
typeMenuCommand, NULL, typeMenuRef, NULL,
sizeof(cmd), NULL, &cmd); sizeof(menuRef), NULL,
if (cmd == 0) return eventNotHandledErr; &menuRef);
break; #endif // 0
default:
wxFAIL_MSG(wxT("Unexpected menu event kind")); wxEventType type=0;
break; MenuCommand cmd=0;
switch (GetEventKind(event))
{
case kEventMenuOpening:
type = wxEVT_MENU_OPEN;
break;
case kEventMenuClosed:
type = wxEVT_MENU_CLOSE;
break;
case kEventMenuTargetItem:
type = wxEVT_MENU_HIGHLIGHT;
GetEventParameter(event, kEventParamMenuCommand,
typeMenuCommand, NULL,
sizeof(cmd), NULL, &cmd);
if (cmd == 0) return eventNotHandledErr;
break;
default:
wxFAIL_MSG(wxT("Unexpected menu event kind"));
break;
}
wxMenuEvent wxevent(type, cmd);
wxevent.SetEventObject(win);
(void)win->GetEventHandler()->ProcessEvent(wxevent);
} }
wxMenuEvent wxevent(type, cmd);
wxevent.SetEventObject(win);
(void)win->GetEventHandler()->ProcessEvent(wxevent);
} }
return eventNotHandledErr; return eventNotHandledErr;