#endif
#endif
-#include "apprsrc.h"
+// #include "apprsrc.h"
#include "wx/mac/uma.h"
#include "wx/mac/macnotfy.h"
extern wxList wxPendingDelete;
+// set wxMAC_USE_RAEL to 1 if RunApplicationEventLoop should be used
+// if 0 the lower level CarbonEventLoop will be used
+// on the long run RAEL should replace the low level event loop
+// we will have to clean up event handling to make sure we don't
+// miss handling of things like pending events etc
+// perhaps we will also have to pipe events through an ueber-event-handler
+// to make sure we have one place to do all these house-keeping functions
+
+#define wxMAC_USE_RAEL 0
+
#if wxUSE_THREADS
extern size_t g_numberOfThreads;
#endif // wxUSE_THREADS
void wxApp::MacReopenApp()
{
// eventually check for open docs, if none, call MacNewFile
+ wxTopLevelWindowMac* topLevelWindow = wxDynamicCast(GetTopWindow(), wxTopLevelWindowMac);
+
+ if (topLevelWindow && topLevelWindow->IsIconized())
+ topLevelWindow->Iconize(false);
}
//----------------------------------------------------------------------
static pascal OSStatus
wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
{
- wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
+ EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
+ EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
+ wxTheApp->MacSetCurrentEvent( event , handler ) ;
+
+ wxMacCarbonEvent cEvent( event ) ;
+ MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;
+ wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;
- if ( mbar )
+ if ( menu )
{
- wxFrame* win = mbar->GetFrame();
- if ( win )
+ wxEventType type=0;
+ MenuCommand cmd=0;
+ switch (GetEventKind(event))
{
-
- // VZ: we could find the menu from its handle here by examining all
- // the menus in the menu bar recursively but knowing that neither
- // 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;
- break;
- case kEventMenuClosed:
- type = wxEVT_MENU_CLOSE;
- break;
- case kEventMenuTargetItem:
+ case kEventMenuOpening:
+ type = wxEVT_MENU_OPEN;
+ break;
+ case kEventMenuClosed:
+ type = wxEVT_MENU_CLOSE;
+ break;
+ case kEventMenuTargetItem:
+ cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
+ if (cmd != 0)
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;
- }
+ break;
+ default:
+ wxFAIL_MSG(wxT("Unexpected menu event kind"));
+ break;
+ }
+ if ( type )
+ {
wxMenuEvent wxevent(type, cmd);
- wxevent.SetEventObject(win);
+ wxevent.SetEventObject(menu);
- (void)win->GetEventHandler()->ProcessEvent(wxevent);
- }
+ wxEvtHandler* handler = menu->GetEventHandler();
+ if (handler && handler->ProcessEvent(wxevent))
+ {
+ // handled
+ }
+ else
+ {
+ wxWindow *win = menu->GetInvokingWindow();
+ if (win)
+ win->GetEventHandler()->ProcessEvent(wxevent);
+ }
+ }
}
+
+ wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
return eventNotHandledErr;
}
HICommand command ;
- GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL,
- sizeof( HICommand ), NULL, &command );
-
+ wxMacCarbonEvent cEvent( event ) ;
+ cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;
+
+ wxMenuItem* item = NULL ;
MenuCommand id = command.commandID ;
+ // for items we don't really control
if ( id == kHICommandPreferences )
- id = wxApp::s_macPreferencesMenuItemId ;
-
- wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
- wxMenu* menu = NULL ;
- wxMenuItem* item = NULL ;
-
- if ( mbar )
{
- item = mbar->FindItem( id , &menu ) ;
- // it is not 100 % sure that an menu of id 0 is really ours, safety check
- if ( id == 0 && menu != NULL && menu->GetHMenu() != command.menu.menuRef )
+ id = wxApp::s_macPreferencesMenuItemId ;
+
+ wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
+ if ( mbar )
{
- item = NULL ;
- menu = NULL ;
+ wxMenu* menu = NULL ;
+ item = mbar->FindItem( id , &menu ) ;
}
}
-
- if ( item == NULL || menu == NULL || mbar == NULL )
- return result ;
-
- switch( GetEventKind( event ) )
+ else if ( id != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 )
+ {
+ GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , (UInt32*) &item ) ;
+ }
+
+ if ( item )
+ {
+ switch( cEvent.GetKind() )
{
case kEventProcessCommand :
{
item->Check( !item->IsChecked() ) ;
}
- menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
+ item->GetMenu()->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
result = noErr ;
}
- break ;
+ break ;
case kEventCommandUpdateStatus:
// eventually trigger an updateui round
result = noErr ;
break ;
- default :
- break ;
- }
-
+ default :
+ break ;
+ }
+ }
return result ;
}
result = wxMacAppMenuEventHandler( handler , event , data ) ;
break ;
case kEventClassMouse :
- result = wxMacTopLevelMouseEventHandler( handler , event , data ) ;
+ result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
break ;
case kEventClassAppleEvent :
{
#if 1
// flow into log
- wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %d (value %d)\n"),
+ wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %ld (value %p)\n"),
assertionStr.c_str() ,
exceptionStr.c_str() ,
errorStr.c_str(),
#else
wxOnAssert(fileNameStr, lineNumber , assertionStr ,
- wxString::Format( wxT("%s %s value (%d)") ,exceptionStr, errorStr , value ) ) ;
+ wxString::Format( wxT("%s %s value (%p)") ,exceptionStr, errorStr , value ) ) ;
#endif
}
NSModule theModule;
const char *theLibPath;
- gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
+ gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));
if (gSharedLibraryBundle != NULL) {
- // wxWindows has been bundled into a framework
+ // wxWidgets has been bundled into a framework
// load the framework resources
gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
}
else {
- // wxWindows is a simple dynamic shared library
+ // wxWidgets is a simple dynamic shared library
// load the resources from the data fork of a separate resource file
wxString theResPath;
wxString theName;
int wxApp::MainLoop()
{
m_keepGoing = TRUE;
-
+#if wxMAC_USE_RAEL
+ RunApplicationEventLoop() ;
+#else
while (m_keepGoing)
{
MacDoOneEvent() ;
}
-
+#endif
return 0;
}
void wxApp::ExitMainLoop()
{
- m_keepGoing = FALSE;
+ m_keepGoing = FALSE;
+#if wxMAC_USE_RAEL
+ QuitApplicationEventLoop() ;
+#endif
}
// Is a message/event pending?
s_inYield = TRUE;
-#if wxUSE_THREADS
- YieldToAnyThread() ;
-#endif
// by definition yield should handle all non-processed events
EventRef theEvent;
if ( wxTheApp->ProcessIdle() )
sleepTime = kEventDurationNoWait ;
else
- {
-#if wxUSE_THREADS
- if (g_numberOfThreads)
- {
- sleepTime = kEventDurationNoWait;
- }
- else
-#endif // wxUSE_THREADS
- {
- sleepTime = kEventDurationSecond;
- }
- }
+ sleepTime = kEventDurationSecond;
}
else if ( status == eventLoopQuitErr )
{
MacHandleUnhandledEvent(evr);
}
wxMacProcessNotifierAndPendingEvents() ;
+#if wxUSE_THREADS
+ wxMutexGuiLeaveOrEnter();
+#endif // wxUSE_THREADS
}
long wxMacTranslateKey(unsigned char key, unsigned char code) ;
if ( handled && event.GetSkipped() )
handled = false ;
}
- if ( !handled &&
- (keyval == WXK_TAB) &&
-// CS: copied the change below from wxGTK
-// VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
-// have this style, yet choose not to process this particular TAB in which
-// case TAB must still work as a navigational character
-#if 0
- (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
-#endif
- (focus->GetParent()) &&
- (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
+ if ( !handled && (keyval == WXK_TAB) )
{
- wxNavigationKeyEvent new_event;
- new_event.SetEventObject( focus );
- new_event.SetDirection( !event.ShiftDown() );
- /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
- new_event.SetWindowChange( event.ControlDown() );
- new_event.SetCurrentFocus( focus );
- handled = focus->GetEventHandler()->ProcessEvent( new_event );
- if ( handled && new_event.GetSkipped() )
- handled = false ;
+ wxWindow* iter = focus->GetParent() ;
+ while( iter && !handled )
+ {
+ if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
+ {
+ wxNavigationKeyEvent new_event;
+ new_event.SetEventObject( focus );
+ new_event.SetDirection( !event.ShiftDown() );
+ /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
+ new_event.SetWindowChange( event.ControlDown() );
+ new_event.SetCurrentFocus( focus );
+ handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
+ if ( handled && new_event.GetSkipped() )
+ handled = false ;
+ }
+ iter = iter->GetParent() ;
+ }
}
// backdoor handler for default return and command escape
if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )