cleanup - reformatting, minor code rewrites

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36582 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
David Surovell
2005-12-28 06:44:35 +00:00
parent da6205f7fb
commit 8a9858aeb2

View File

@@ -77,15 +77,14 @@ extern wxList wxPendingDelete;
#if wxUSE_THREADS #if wxUSE_THREADS
extern size_t g_numberOfThreads; extern size_t g_numberOfThreads;
#endif // wxUSE_THREADS #endif
// statics for implementation // statics for implementation
static bool s_inYield = false; static bool s_inYield = false;
static bool s_inReceiveEvent = false ; static bool s_inReceiveEvent = false ;
static EventTime sleepTime = kEventDurationNoWait ; static EventTime sleepTime = kEventDurationNoWait ;
IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
EVT_IDLE(wxApp::OnIdle) EVT_IDLE(wxApp::OnIdle)
@@ -94,9 +93,8 @@ BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
END_EVENT_TABLE() END_EVENT_TABLE()
const short kMacMinHeap = (29 * 1024) ;
// platform specific static variables // platform specific static variables
const short kMacMinHeap = (29 * 1024) ;
const short kwxMacMenuBarResource = 1 ; const short kwxMacMenuBarResource = 1 ;
const short kwxMacAppleMenuId = 1 ; const short kwxMacAppleMenuId = 1 ;
@@ -106,15 +104,14 @@ int wxApp::s_lastMouseDown = 0 ;
long wxApp::sm_lastMessageTime = 0; long wxApp::sm_lastMessageTime = 0;
long wxApp::s_lastModifiers = 0 ; long wxApp::s_lastModifiers = 0 ;
bool wxApp::s_macSupportPCMenuShortcuts = true ; bool wxApp::s_macSupportPCMenuShortcuts = true ;
long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ; long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ;
long wxApp::s_macExitMenuItemId = wxID_EXIT ; long wxApp::s_macExitMenuItemId = wxID_EXIT ;
wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ; wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ;
// Normally we're not a plugin bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin
bool wxApp::sm_isEmbedded = false;
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Core Apple Event Support // Core Apple Event Support
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -161,6 +158,7 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
long itemsInList; long itemsInList;
OSErr err; OSErr err;
short i; short i;
err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList); err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
if (err != noErr) if (err != noErr)
return err; return err;
@@ -174,17 +172,19 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
PSN.lowLongOfPSN = kCurrentProcess ; PSN.lowLongOfPSN = kCurrentProcess ;
SetFrontProcess( &PSN ) ; SetFrontProcess( &PSN ) ;
wxString fName ;
FSRef theRef ;
for (i = 1; i <= itemsInList; i++) for (i = 1; i <= itemsInList; i++)
{ {
wxString fName ; AEGetNthPtr(
&docList, i, typeFSRef, &keywd, &returnedType,
FSRef theRef ; (Ptr)&theRef, sizeof(theRef), &actualSize);
AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType,
(Ptr) & theRef, sizeof(theRef), &actualSize);
fName = wxMacFSRefToPath( &theRef ) ; fName = wxMacFSRefToPath( &theRef ) ;
MacOpenFile(fName); MacOpenFile(fName);
} }
return noErr; return noErr;
} }
@@ -199,6 +199,7 @@ short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply)
long itemsInList; long itemsInList;
OSErr err; OSErr err;
short i; short i;
err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList); err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
if (err != noErr) if (err != noErr)
return err; return err;
@@ -212,16 +213,19 @@ short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply)
PSN.lowLongOfPSN = kCurrentProcess ; PSN.lowLongOfPSN = kCurrentProcess ;
SetFrontProcess( &PSN ) ; SetFrontProcess( &PSN ) ;
for (i = 1; i <= itemsInList; i++) { wxString fName ;
wxString fName ; FSRef theRef ;
FSRef theRef ; for (i = 1; i <= itemsInList; i++)
AEGetNthPtr(&docList, i, typeFSRef, &keywd, &returnedType, {
(Ptr) & theRef, sizeof(theRef), &actualSize); AEGetNthPtr(
&docList, i, typeFSRef, &keywd, &returnedType,
(Ptr)&theRef, sizeof(theRef), &actualSize);
fName = wxMacFSRefToPath( &theRef ) ; fName = wxMacFSRefToPath( &theRef ) ;
MacPrintFile(fName); MacPrintFile(fName);
} }
return noErr; return noErr;
} }
@@ -248,6 +252,7 @@ short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNU
{ {
ExitMainLoop() ; ExitMainLoop() ;
} }
return noErr ; return noErr ;
} }
@@ -256,11 +261,10 @@ short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNU
short wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) short wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
{ {
MacReopenApp() ; MacReopenApp() ;
return noErr ; return noErr ;
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Support Routines linking the Mac...File Calls to the Document Manager // Support Routines linking the Mac...File Calls to the Document Manager
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@@ -287,7 +291,7 @@ void wxApp::MacPrintFile(const wxString & fileName )
if ( doc ) if ( doc )
{ {
wxView* view = doc->GetFirstView() ; wxView* view = doc->GetFirstView() ;
if( view ) if ( view )
{ {
wxPrintout *printout = view->OnCreatePrintout(); wxPrintout *printout = view->OnCreatePrintout();
if (printout) if (printout)
@@ -297,6 +301,7 @@ void wxApp::MacPrintFile(const wxString & fileName )
delete printout; delete printout;
} }
} }
if (doc->Close()) if (doc->Close())
{ {
doc->DeleteAllViews(); doc->DeleteAllViews();
@@ -333,7 +338,7 @@ void wxApp::MacReopenApp()
while (node) while (node)
{ {
wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData(); wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData();
if ( win->IsIconized() == false ) if ( !win->IsIconized() )
{ {
firstIconized = NULL ; firstIconized = NULL ;
break ; break ;
@@ -343,8 +348,10 @@ void wxApp::MacReopenApp()
if ( firstIconized == NULL ) if ( firstIconized == NULL )
firstIconized = win ; firstIconized = win ;
} }
node = node->GetNext(); node = node->GetNext();
} }
if ( firstIconized ) if ( firstIconized )
firstIconized->Iconize( false ) ; firstIconized->Iconize( false ) ;
} }
@@ -377,32 +384,34 @@ int wxMacCommandToId( UInt32 macCommandId )
{ {
int wxid = 0 ; int wxid = 0 ;
if ( macCommandId == kHICommandPreferences || macCommandId == kHICommandQuit || macCommandId == kHICommandAbout ) switch ( macCommandId )
{ {
switch ( macCommandId ) case kHICommandPreferences :
{ wxid = wxApp::s_macPreferencesMenuItemId ;
case kHICommandPreferences : break ;
wxid = wxApp::s_macPreferencesMenuItemId ;
break ; case kHICommandQuit :
case kHICommandQuit : wxid = wxApp::s_macExitMenuItemId ;
wxid = wxApp::s_macExitMenuItemId ; break ;
break ;
case kHICommandAbout : case kHICommandAbout :
wxid = wxApp::s_macAboutMenuItemId ; wxid = wxApp::s_macAboutMenuItemId ;
break ; break ;
}
} default :
else
{
for ( size_t i = 0 ; i < WXSIZEOF(gCommandIds) ; ++i )
{
if ( gCommandIds[i].macId == macCommandId )
{ {
wxid = gCommandIds[i].wxId ; for ( size_t i = 0 ; i < WXSIZEOF(gCommandIds) ; ++i )
break ; {
if ( gCommandIds[i].macId == macCommandId )
{
wxid = gCommandIds[i].wxId ;
break ;
}
}
} }
} break ;
} }
if ( wxid == 0 ) if ( wxid == 0 )
wxid = (int) macCommandId ; wxid = (int) macCommandId ;
@@ -430,6 +439,7 @@ UInt32 wxIdToMacCommand( int wxId )
} }
} }
} }
if ( macId == 0 ) if ( macId == 0 )
macId = (int) wxId ; macId = (int) wxId ;
@@ -442,15 +452,13 @@ wxMenu* wxFindMenuFromMacCommand( const HICommand &command , wxMenuItem* &item )
int id = 0 ; int id = 0 ;
// for 'standard' commands which don't have a wx-menu // for 'standard' commands which don't have a wx-menu
if ( command.commandID == kHICommandPreferences || command.commandID == kHICommandQuit || command.commandID == kHICommandAbout ) if ( command.commandID == kHICommandPreferences || command.commandID == kHICommandQuit || command.commandID == kHICommandAbout )
{ {
id = wxMacCommandToId( command.commandID ) ; id = wxMacCommandToId( command.commandID ) ;
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
if ( mbar ) if ( mbar )
{
item = mbar->FindItem( id , &itemMenu ) ; item = mbar->FindItem( id , &itemMenu ) ;
}
} }
else if ( command.commandID != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 ) else if ( command.commandID != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 )
{ {
@@ -461,32 +469,28 @@ wxMenu* wxFindMenuFromMacCommand( const HICommand &command , wxMenuItem* &item )
if ( mh == NULL ) if ( mh == NULL )
{ {
if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr )
{
mh = NULL ; mh = NULL ;
}
} }
// is it part of the application or the help menu, then look for the id directly // is it part of the application or the Help menu, then look for the id directly
if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) || if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) ||
( mh != NULL && command.menu.menuRef == mh ) ) ( mh != NULL && command.menu.menuRef == mh ) )
{ {
wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
if ( mbar ) if ( mbar )
{
item = mbar->FindItem( id , &itemMenu ) ; item = mbar->FindItem( id , &itemMenu ) ;
}
} }
else else
{ {
UInt32 refCon ; UInt32 refCon ;
GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ; GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ;
itemMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ; itemMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ;
if ( itemMenu != NULL ) if ( itemMenu != NULL )
{
item = (wxMenuItem*) refCon ; item = (wxMenuItem*) refCon ;
}
} }
} }
return itemMenu ; return itemMenu ;
} }
@@ -533,14 +537,17 @@ wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *d
case kEventMenuOpening: case kEventMenuOpening:
type = wxEVT_MENU_OPEN; type = wxEVT_MENU_OPEN;
break; break;
case kEventMenuClosed: case kEventMenuClosed:
type = wxEVT_MENU_CLOSE; type = wxEVT_MENU_CLOSE;
break; break;
case kEventMenuTargetItem: case kEventMenuTargetItem:
cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ; cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
if (cmd != 0) if (cmd != 0)
type = wxEVT_MENU_HIGHLIGHT; type = wxEVT_MENU_HIGHLIGHT;
break; break;
default: default:
wxFAIL_MSG(wxT("Unexpected menu event kind")); wxFAIL_MSG(wxT("Unexpected menu event kind"));
break; break;
@@ -585,7 +592,7 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler
{ {
wxASSERT( itemMenu != NULL ) ; wxASSERT( itemMenu != NULL ) ;
switch( cEvent.GetKind() ) switch ( cEvent.GetKind() )
{ {
case kEventProcessCommand : case kEventProcessCommand :
{ {
@@ -596,6 +603,7 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler
result = noErr ; result = noErr ;
} }
break ; break ;
case kEventCommandUpdateStatus: case kEventCommandUpdateStatus:
{ {
wxUpdateUIEvent event(id); wxUpdateUIEvent event(id);
@@ -610,8 +618,8 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler
processed = handler->ProcessEvent(event); processed = handler->ProcessEvent(event);
} }
// Try the window the menu was popped up from (and up through the // Try the window the menu was popped up from
// hierarchy) // (and up through the hierarchy)
if ( !processed ) if ( !processed )
{ {
const wxMenuBase *menu = itemMenu; const wxMenuBase *menu = itemMenu;
@@ -642,6 +650,7 @@ static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler
} }
} }
break ; break ;
default : default :
break ; break ;
} }
@@ -655,22 +664,21 @@ static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef hand
switch ( GetEventKind( event ) ) switch ( GetEventKind( event ) )
{ {
case kEventAppActivated : case kEventAppActivated :
{ if ( wxTheApp )
if ( wxTheApp ) wxTheApp->SetActive( true , NULL ) ;
wxTheApp->SetActive( true , NULL ) ; result = noErr ;
result = noErr ;
}
break ; break ;
case kEventAppDeactivated : case kEventAppDeactivated :
{ if ( wxTheApp )
if ( wxTheApp ) wxTheApp->SetActive( false , NULL ) ;
wxTheApp->SetActive( false , NULL ) ; result = noErr ;
result = noErr ;
}
break ; break ;
default : default :
break ; break ;
} }
return result ; return result ;
} }
@@ -681,17 +689,20 @@ pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef eve
wxTheApp->MacSetCurrentEvent( event , handler ) ; wxTheApp->MacSetCurrentEvent( event , handler ) ;
OSStatus result = eventNotHandledErr ; OSStatus result = eventNotHandledErr ;
switch( GetEventClass( event ) ) switch ( GetEventClass( event ) )
{ {
case kEventClassCommand : case kEventClassCommand :
result = wxMacAppCommandEventHandler( handler , event , data ) ; result = wxMacAppCommandEventHandler( handler , event , data ) ;
break ; break ;
case kEventClassApplication : case kEventClassApplication :
result = wxMacAppApplicationEventHandler( handler , event , data ) ; result = wxMacAppApplicationEventHandler( handler , event , data ) ;
break ; break ;
case kEventClassMenu : case kEventClassMenu :
result = wxMacAppMenuEventHandler( handler , event , data ) ; result = wxMacAppMenuEventHandler( handler , event , data ) ;
break ; break ;
case kEventClassMouse : case kEventClassMouse :
{ {
wxMacCarbonEvent cEvent( event ) ; wxMacCarbonEvent cEvent( event ) ;
@@ -705,13 +716,16 @@ pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef eve
result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ; result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
} }
break ; break ;
case kEventClassAppleEvent : case kEventClassAppleEvent :
{ {
EventRecord rec ; EventRecord rec ;
wxMacConvertEventToRecord( event , &rec ) ; wxMacConvertEventToRecord( event , &rec ) ;
result = AEProcessAppleEvent( &rec ) ; result = AEProcessAppleEvent( &rec ) ;
} }
break ; break ;
default : default :
break ; break ;
} }
@@ -739,6 +753,7 @@ pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 op
wxString assertionStr ; wxString assertionStr ;
wxString exceptionStr ; wxString exceptionStr ;
wxString errorStr ; wxString errorStr ;
#if wxUSE_UNICODE #if wxUSE_UNICODE
fileNameStr = wxString(fileName, wxConvLocal); fileNameStr = wxString(fileName, wxConvLocal);
assertionStr = wxString(assertionString, wxConvLocal); assertionStr = wxString(assertionString, wxConvLocal);
@@ -762,20 +777,23 @@ pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 op
#else #else
wxOnAssert(fileNameStr, lineNumber , assertionStr , wxOnAssert(fileNameStr, lineNumber , assertionStr ,
wxString::Format( wxT("%s %s value (%p)") ,exceptionStr, errorStr , value ) ) ; wxString::Format( wxT("%s %s value (%p)") , exceptionStr, errorStr , value ) ) ;
#endif #endif
} }
#endif //__WXDEBUG__ #endif //__WXDEBUG__
#ifdef __WXMAC_OSX__ #ifdef __WXMAC_OSX__
extern "C" { extern "C"
/* m_macEventPosted run loop source callback: */ {
// m_macEventPosted run loop source callback:
void macPostedEventCallback(void *unused); void macPostedEventCallback(void *unused);
} }
void macPostedEventCallback(void *unused) { void macPostedEventCallback(void *unused)
wxTheApp->ProcessPendingEvents(); } {
wxTheApp->ProcessPendingEvents();
}
#endif #endif
bool wxApp::Initialize(int& argc, wxChar **argv) bool wxApp::Initialize(int& argc, wxChar **argv)
@@ -783,8 +801,9 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
// Mac-specific // Mac-specific
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
InstallDebugAssertOutputHandler ( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) ); InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );
#endif #endif
UMAInitToolbox( 4, sm_isEmbedded ) ; UMAInitToolbox( 4, sm_isEmbedded ) ;
SetEventMask( everyEvent ) ; SetEventMask( everyEvent ) ;
UMAShowWatchCursor() ; UMAShowWatchCursor() ;
@@ -867,7 +886,7 @@ AEEventHandlerUPP sQuitHandler = NULL ;
bool wxApp::OnInitGui() bool wxApp::OnInitGui()
{ {
if( !wxAppBase::OnInitGui() ) if ( !wxAppBase::OnInitGui() )
return false ; return false ;
InstallStandardEventHandler( GetApplicationEventTarget() ) ; InstallStandardEventHandler( GetApplicationEventTarget() ) ;
@@ -910,9 +929,7 @@ void wxApp::CleanUp()
#ifdef __WXMAC_OSX__ #ifdef __WXMAC_OSX__
if (m_macEventPosted) if (m_macEventPosted)
{
CFRelease(m_macEventPosted); CFRelease(m_macEventPosted);
}
m_macEventPosted = NULL; m_macEventPosted = NULL;
#endif #endif
@@ -929,14 +946,11 @@ void wxApp::CleanUp()
#endif #endif
UMACleanupToolbox() ; UMACleanupToolbox() ;
if (s_macCursorRgn) { if (s_macCursorRgn)
::DisposeRgn((RgnHandle)s_macCursorRgn); ::DisposeRgn((RgnHandle)s_macCursorRgn);
}
if (!sm_isEmbedded) if (!sm_isEmbedded)
{
RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) ); RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) );
}
if (!sm_isEmbedded) if (!sm_isEmbedded)
{ {
@@ -971,8 +985,9 @@ void wxApp::CleanUp()
// ref num upon initializing and releasing when terminating, therefore // ref num upon initializing and releasing when terminating, therefore
// the __wxinitialize and __wxterminate must be used // the __wxinitialize and __wxterminate must be used
extern "C" { extern "C"
void __sinit(void); /* (generated by linker) */ {
void __sinit(void); // (generated by linker)
pascal OSErr __initialize(const CFragInitBlock *theInitBlock); pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
pascal void __terminate(void); pascal void __terminate(void);
} }
@@ -991,33 +1006,39 @@ pascal void __wxterminate(void)
bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
{ {
bool converted = ConvertEventRefToEventRecord( event,rec) ;
OSStatus err = noErr ; OSStatus err = noErr ;
bool converted = ConvertEventRefToEventRecord( event, rec) ;
if ( !converted ) if ( !converted )
{ {
switch( GetEventClass( event ) ) switch ( GetEventClass( event ) )
{ {
case kEventClassKeyboard : case kEventClassKeyboard :
{ {
converted = true ; converted = true ;
switch( GetEventKind(event) ) switch ( GetEventKind(event) )
{ {
case kEventRawKeyDown : case kEventRawKeyDown :
rec->what = keyDown ; rec->what = keyDown ;
break ; break ;
case kEventRawKeyRepeat : case kEventRawKeyRepeat :
rec->what = autoKey ; rec->what = autoKey ;
break ; break ;
case kEventRawKeyUp : case kEventRawKeyUp :
rec->what = keyUp ; rec->what = keyUp ;
break ; break ;
case kEventRawKeyModifiersChanged : case kEventRawKeyModifiersChanged :
rec->what = nullEvent ; rec->what = nullEvent ;
break ; break ;
default : default :
converted = false ; converted = false ;
break ; break ;
} }
if ( converted ) if ( converted )
{ {
UInt32 keyCode ; UInt32 keyCode ;
@@ -1033,19 +1054,23 @@ bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
} }
} }
break ; break ;
case kEventClassTextInput : case kEventClassTextInput :
{ {
switch( GetEventKind( event ) ) switch ( GetEventKind( event ) )
{ {
case kEventTextInputUnicodeForKeyEvent : case kEventTextInputUnicodeForKeyEvent :
{ {
EventRef rawEvent ; EventRef rawEvent ;
err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; err = GetEventParameter(
event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL,
sizeof(rawEvent), NULL, &rawEvent ) ;
converted = true ; converted = true ;
{ {
UInt32 keyCode ; UInt32 keyCode, modifiers;
unsigned char charCode ; unsigned char charCode ;
UInt32 modifiers ;
GetMouse( &rec->where) ; GetMouse( &rec->where) ;
rec->what = keyDown ; rec->what = keyDown ;
err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
@@ -1055,12 +1080,16 @@ bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
rec->message = (keyCode << 8 ) + charCode ; rec->message = (keyCode << 8 ) + charCode ;
} }
} }
break ; break ;
default : default :
break ; break ;
} }
} }
break ; break ;
default :
break ;
} }
} }
@@ -1073,6 +1102,7 @@ wxApp::wxApp()
m_macCurrentEvent = NULL ; m_macCurrentEvent = NULL ;
m_macCurrentEventHandlerCallRef = NULL ; m_macCurrentEventHandlerCallRef = NULL ;
#ifdef __WXMAC_OSX__ #ifdef __WXMAC_OSX__
m_macEventPosted = NULL ; m_macEventPosted = NULL ;
#endif #endif
@@ -1081,6 +1111,7 @@ wxApp::wxApp()
int wxApp::MainLoop() int wxApp::MainLoop()
{ {
m_keepGoing = true; m_keepGoing = true;
#if wxMAC_USE_RAEL #if wxMAC_USE_RAEL
RunApplicationEventLoop() ; RunApplicationEventLoop() ;
#else #else
@@ -1089,12 +1120,14 @@ int wxApp::MainLoop()
MacDoOneEvent() ; MacDoOneEvent() ;
} }
#endif #endif
return 0; return 0;
} }
void wxApp::ExitMainLoop() void wxApp::ExitMainLoop()
{ {
m_keepGoing = false; m_keepGoing = false;
#if wxMAC_USE_RAEL #if wxMAC_USE_RAEL
QuitApplicationEventLoop() ; QuitApplicationEventLoop() ;
#endif #endif
@@ -1105,7 +1138,9 @@ bool wxApp::Pending()
{ {
// without the receive event (with pull param = false ) nothing is ever reported // without the receive event (with pull param = false ) nothing is ever reported
EventRef theEvent; EventRef theEvent;
ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &theEvent);
ReceiveNextEvent(0, NULL, kEventDurationNoWait, false, &theEvent);
return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
} }
@@ -1126,7 +1161,7 @@ void wxApp::OnIdle(wxIdleEvent& event)
// wxPostEvent() functions // wxPostEvent() functions
wxMacProcessNotifierAndPendingEvents(); wxMacProcessNotifierAndPendingEvents();
if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
} }
@@ -1138,6 +1173,7 @@ void wxApp::WakeUpIdle()
CFRunLoopSourceSignal(m_macEventPosted); CFRunLoopSourceSignal(m_macEventPosted);
} }
#endif #endif
wxMacWakeUp() ; wxMacWakeUp() ;
} }
@@ -1191,7 +1227,8 @@ bool wxApp::Yield(bool onlyIfNeeded)
EventRef theEvent; EventRef theEvent;
OSStatus status = noErr ; OSStatus status = noErr ;
do
while ( status == noErr )
{ {
s_inReceiveEvent = true ; s_inReceiveEvent = true ;
status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
@@ -1212,7 +1249,7 @@ bool wxApp::Yield(bool onlyIfNeeded)
MacHandleOneEvent( theEvent ) ; MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent); ReleaseEvent(theEvent);
} }
} while( status == noErr ) ; }
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
s_inYield = false; s_inYield = false;
@@ -1225,25 +1262,28 @@ void wxApp::MacDoOneEvent()
EventRef theEvent; EventRef theEvent;
s_inReceiveEvent = true ; s_inReceiveEvent = true ;
OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ; OSStatus status = ReceiveNextEvent(0, NULL, sleepTime, true, &theEvent) ;
s_inReceiveEvent = false ; s_inReceiveEvent = false ;
if ( status == eventLoopTimedOutErr )
switch (status)
{ {
if ( wxTheApp->ProcessIdle() ) case eventLoopTimedOutErr :
if ( wxTheApp->ProcessIdle() )
sleepTime = kEventDurationNoWait ;
else
sleepTime = kEventDurationSecond;
break;
case eventLoopQuitErr :
// according to QA1061 this may also occur
// when a WakeUp Process is executed
break;
default:
MacHandleOneEvent( theEvent ) ;
ReleaseEvent( theEvent );
sleepTime = kEventDurationNoWait ; sleepTime = kEventDurationNoWait ;
else break;
sleepTime = kEventDurationSecond;
}
else if ( status == eventLoopQuitErr )
{
// according to QA1061 this may also occur when a WakeUp Process
// is executed
}
else
{
MacHandleOneEvent( theEvent ) ;
ReleaseEvent(theEvent);
sleepTime = kEventDurationNoWait ;
} }
// repeaters // repeaters
@@ -1251,7 +1291,8 @@ void wxApp::MacDoOneEvent()
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
} }
/*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr ) // virtual
void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr )
{ {
// Override to process unhandled events as you please // Override to process unhandled events as you please
} }
@@ -1261,12 +1302,13 @@ void wxApp::MacHandleOneEvent( WXEVENTREF evr )
EventTargetRef theTarget; EventTargetRef theTarget;
theTarget = GetEventDispatcherTarget(); theTarget = GetEventDispatcherTarget();
m_macCurrentEvent = evr ; m_macCurrentEvent = evr ;
OSStatus status = SendEventToEventTarget ((EventRef) evr , theTarget);
if(status == eventNotHandledErr) OSStatus status = SendEventToEventTarget((EventRef) evr , theTarget);
{ if (status == eventNotHandledErr)
MacHandleUnhandledEvent(evr); MacHandleUnhandledEvent(evr);
}
wxMacProcessNotifierAndPendingEvents() ; wxMacProcessNotifierAndPendingEvents() ;
#if wxUSE_THREADS #if wxUSE_THREADS
wxMutexGuiLeaveOrEnter(); wxMutexGuiLeaveOrEnter();
#endif // wxUSE_THREADS #endif // wxUSE_THREADS
@@ -1315,53 +1357,70 @@ long wxMacTranslateKey(unsigned char key, unsigned char code)
case kFunctionKeyCharCode : case kFunctionKeyCharCode :
{ {
switch( code ) switch ( code )
{ {
case 0x7a : case 0x7a :
retval = WXK_F1 ; retval = WXK_F1 ;
break; break;
case 0x78 : case 0x78 :
retval = WXK_F2 ; retval = WXK_F2 ;
break; break;
case 0x63 : case 0x63 :
retval = WXK_F3 ; retval = WXK_F3 ;
break; break;
case 0x76 : case 0x76 :
retval = WXK_F4 ; retval = WXK_F4 ;
break; break;
case 0x60 : case 0x60 :
retval = WXK_F5 ; retval = WXK_F5 ;
break; break;
case 0x61 : case 0x61 :
retval = WXK_F6 ; retval = WXK_F6 ;
break; break;
case 0x62: case 0x62:
retval = WXK_F7 ; retval = WXK_F7 ;
break; break;
case 0x64 : case 0x64 :
retval = WXK_F8 ; retval = WXK_F8 ;
break; break;
case 0x65 : case 0x65 :
retval = WXK_F9 ; retval = WXK_F9 ;
break; break;
case 0x6D : case 0x6D :
retval = WXK_F10 ; retval = WXK_F10 ;
break; break;
case 0x67 : case 0x67 :
retval = WXK_F11 ; retval = WXK_F11 ;
break; break;
case 0x6F : case 0x6F :
retval = WXK_F12 ; retval = WXK_F12 ;
break; break;
case 0x69 : case 0x69 :
retval = WXK_F13 ; retval = WXK_F13 ;
break; break;
case 0x6B : case 0x6B :
retval = WXK_F14 ; retval = WXK_F14 ;
break; break;
case 0x71 : case 0x71 :
retval = WXK_F15 ; retval = WXK_F15 ;
break; break;
default:
break;
} }
} }
break ; break ;
@@ -1440,7 +1499,7 @@ bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
#endif #endif
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
{ {
if ( !focus ) if ( !focus )
return false ; return false ;
@@ -1458,6 +1517,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
keychar = short(keyInfo & charCodeMask); keychar = short(keyInfo & charCodeMask);
} }
long keyval = wxMacTranslateKey(keychar, keycode) ; long keyval = wxMacTranslateKey(keychar, keycode) ;
long realkeyval = keyval ; long realkeyval = keyval ;
if ( keyval == keychar ) if ( keyval == keychar )
@@ -1479,24 +1539,33 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
case 76 : case 76 :
keyval = WXK_NUMPAD_ENTER; keyval = WXK_NUMPAD_ENTER;
break; break;
case 81: case 81:
keyval = WXK_NUMPAD_EQUAL; keyval = WXK_NUMPAD_EQUAL;
break; break;
case 67: case 67:
keyval = WXK_NUMPAD_MULTIPLY; keyval = WXK_NUMPAD_MULTIPLY;
break; break;
case 75: case 75:
keyval = WXK_NUMPAD_DIVIDE; keyval = WXK_NUMPAD_DIVIDE;
break; break;
case 78: case 78:
keyval = WXK_NUMPAD_SUBTRACT; keyval = WXK_NUMPAD_SUBTRACT;
break; break;
case 69: case 69:
keyval = WXK_NUMPAD_ADD; keyval = WXK_NUMPAD_ADD;
break; break;
case 65: case 65:
keyval = WXK_NUMPAD_DECIMAL; keyval = WXK_NUMPAD_DECIMAL;
break; break;
default:
break;
} // end switch } // end switch
} }
@@ -1507,9 +1576,11 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
event.m_altDown = modifiers & optionKey; event.m_altDown = modifiers & optionKey;
event.m_metaDown = modifiers & cmdKey; event.m_metaDown = modifiers & cmdKey;
event.m_keyCode = keyval ; event.m_keyCode = keyval ;
#if wxUSE_UNICODE #if wxUSE_UNICODE
event.m_uniChar = uniChar ; event.m_uniChar = uniChar ;
#endif #endif
event.m_rawCode = keymessage; event.m_rawCode = keymessage;
event.m_rawFlags = modifiers; event.m_rawFlags = modifiers;
event.m_x = wherex; event.m_x = wherex;
@@ -1533,8 +1604,10 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
break; break;
} }
if (ancestor->IsTopLevel()) if (ancestor->IsTopLevel())
break; break;
ancestor = ancestor->GetParent(); ancestor = ancestor->GetParent();
} }
} }
@@ -1561,6 +1634,7 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
{ {
event.Skip( false ) ; event.Skip( false ) ;
event.SetEventType( wxEVT_CHAR ) ; event.SetEventType( wxEVT_CHAR ) ;
// raw value again // raw value again
event.m_keyCode = realkeyval ; event.m_keyCode = realkeyval ;
@@ -1568,10 +1642,11 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
if ( handled && event.GetSkipped() ) if ( handled && event.GetSkipped() )
handled = false ; handled = false ;
} }
if ( !handled && (keyval == WXK_TAB) ) if ( !handled && (keyval == WXK_TAB) )
{ {
wxWindow* iter = focus->GetParent() ; wxWindow* iter = focus->GetParent() ;
while( iter && !handled ) while ( iter && !handled )
{ {
if ( iter->HasFlag( wxTAB_TRAVERSAL ) ) if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
{ {
@@ -1585,69 +1660,70 @@ bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifi
if ( handled && new_event.GetSkipped() ) if ( handled && new_event.GetSkipped() )
handled = false ; handled = false ;
} }
iter = iter->GetParent() ; iter = iter->GetParent() ;
} }
} }
// backdoor handler for default return and command escape // backdoor handler for default return and command escape
if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) ) if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
{ {
// if window is not having a focus still testing for default enter or cancel // if window is not having a focus still testing for default enter or cancel
// TODO add the UMA version for ActiveNonFloatingWindow // TODO: add the UMA version for ActiveNonFloatingWindow
wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
if ( focus ) if ( focus )
{ {
if ( keyval == WXK_RETURN ) if ( keyval == WXK_RETURN )
{ {
wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxButton);
wxButton); if ( def && def->IsEnabled() )
if ( def && def->IsEnabled() ) {
{ wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); event.SetEventObject(def);
event.SetEventObject(def); def->Command(event);
def->Command(event);
return true ; return true ;
} }
} }
/* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
{ {
wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs)
new_event.SetEventObject( focus ); wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
handled = focus->GetEventHandler()->ProcessEvent( new_event ); new_event.SetEventObject( focus );
handled = focus->GetEventHandler()->ProcessEvent( new_event );
} }
} }
} }
return handled ; return handled ;
} }
bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
{ {
if ( !focus ) if ( !focus )
return false ; return false ;
short keycode ; short keycode, keychar ;
short keychar ;
keychar = short(keymessage & charCodeMask); keychar = short(keymessage & charCodeMask);
keycode = short(keymessage & keyCodeMask) >> 8 ; keycode = short(keymessage & keyCodeMask) >> 8 ;
if ( modifiers & ( controlKey|shiftKey|optionKey ) ) if ( modifiers & (controlKey | shiftKey | optionKey) )
{ {
// control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
// and look at the character after // and look at the character after
UInt32 state = 0; UInt32 state = 0;
UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey | shiftKey | optionKey))) | keycode, &state);
keychar = short(keyInfo & charCodeMask); keychar = short(keyInfo & charCodeMask);
} }
long keyval = wxMacTranslateKey(keychar, keycode) ;
long keyval = wxMacTranslateKey(keychar, keycode) ;
if ( keyval == keychar ) if ( keyval == keychar )
{
keyval = wxToupper( keyval ) ; keyval = wxToupper( keyval ) ;
}
// Check for NUMPAD keys // Check for NUMPAD keys
if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92) if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
{ {
keyval = keyval - '0' + WXK_NUMPAD0; keyval = (keyval - '0') + WXK_NUMPAD0;
} }
else if (keycode >= 67 && keycode <= 81) else if (keycode >= 67 && keycode <= 81)
{ {
@@ -1656,24 +1732,33 @@ bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifier
case 76 : case 76 :
keyval = WXK_NUMPAD_ENTER; keyval = WXK_NUMPAD_ENTER;
break; break;
case 81: case 81:
keyval = WXK_NUMPAD_EQUAL; keyval = WXK_NUMPAD_EQUAL;
break; break;
case 67: case 67:
keyval = WXK_NUMPAD_MULTIPLY; keyval = WXK_NUMPAD_MULTIPLY;
break; break;
case 75: case 75:
keyval = WXK_NUMPAD_DIVIDE; keyval = WXK_NUMPAD_DIVIDE;
break; break;
case 78: case 78:
keyval = WXK_NUMPAD_SUBTRACT; keyval = WXK_NUMPAD_SUBTRACT;
break; break;
case 69: case 69:
keyval = WXK_NUMPAD_ADD; keyval = WXK_NUMPAD_ADD;
break; break;
case 65: case 65:
keyval = WXK_NUMPAD_DECIMAL; keyval = WXK_NUMPAD_DECIMAL;
break; break;
default:
break;
} // end switch } // end switch
} }