1 ///////////////////////////////////////////////////////////////////////////// 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "app.h" 
  18 #include "wx/window.h" 
  20 #include "wx/button.h" 
  23 #include "wx/gdicmn.h" 
  26 #include "wx/cursor.h" 
  29 #include "wx/palette.h" 
  31 #include "wx/dialog.h" 
  32 #include "wx/msgdlg.h" 
  34 #include "wx/module.h" 
  35 #include "wx/memory.h" 
  36 #include "wx/tooltip.h" 
  37 #include "wx/textctrl.h" 
  39 #include "wx/docview.h" 
  40 #include "wx/filename.h" 
  54 #include "wx/mac/uma.h" 
  55 #include "wx/mac/macnotfy.h" 
  58 #  include <CoreServices/CoreServices.h> 
  59 #  if defined(WXMAKINGDLL_CORE) 
  60 #    include <mach-o/dyld.h> 
  65 #  include <ToolUtils.h> 
  66 #  include <DiskInit.h> 
  70 extern wxList wxPendingDelete
; 
  71 extern wxList 
*wxWinMacWindowList
; 
  72 extern wxList 
*wxWinMacControlList
; 
  74 extern size_t g_numberOfThreads
; 
  75 #endif // wxUSE_THREADS 
  77 // statics for implementation 
  79 static bool s_inYield 
= FALSE
; 
  82 static bool s_inReceiveEvent 
= FALSE 
; 
  83 static EventTime sleepTime 
= kEventDurationNoWait 
; 
  85 static long sleepTime 
= 0 ; 
  88 #if !USE_SHARED_LIBRARY 
  89 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
) 
  90 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
) 
  91     EVT_IDLE(wxApp::OnIdle
) 
  92     EVT_END_SESSION(wxApp::OnEndSession
) 
  93     EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
) 
  98 const short    kMacMinHeap 
= (29 * 1024) ; 
  99 // platform specific static variables 
 101 const short kwxMacMenuBarResource 
= 1 ; 
 102 const short kwxMacAppleMenuId 
= 1 ; 
 104 WXHRGN    
wxApp::s_macCursorRgn 
= NULL
; 
 105 wxWindow
* wxApp::s_captureWindow 
= NULL 
; 
 106 int       wxApp::s_lastMouseDown 
= 0 ; 
 107 long      wxApp::sm_lastMessageTime 
= 0; 
 108 long      wxApp::s_lastModifiers 
= 0 ; 
 111 bool      wxApp::s_macSupportPCMenuShortcuts 
= true ; 
 112 long      wxApp::s_macAboutMenuItemId 
= wxID_ABOUT 
; 
 113 long      wxApp::s_macPreferencesMenuItemId 
= wxID_PREFERENCES 
; 
 114 long      wxApp::s_macExitMenuItemId 
= wxID_EXIT 
; 
 115 wxString  
wxApp::s_macHelpMenuTitleName 
= wxT("&Help") ; 
 117 // Normally we're not a plugin 
 118 bool      wxApp::sm_isEmbedded 
= false; 
 119 //---------------------------------------------------------------------- 
 120 // Core Apple Event Support 
 121 //---------------------------------------------------------------------- 
 123 pascal OSErr 
AEHandleODoc( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long refcon 
) ; 
 124 pascal OSErr 
AEHandleOApp( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long refcon 
) ; 
 125 pascal OSErr 
AEHandlePDoc( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long refcon 
) ; 
 126 pascal OSErr 
AEHandleQuit( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long refcon 
) ; 
 127 pascal OSErr 
AEHandleRApp( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long refcon 
) ; 
 129 pascal OSErr 
AEHandleODoc( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long WXUNUSED(refcon
) ) 
 131     return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event 
, reply
) ; 
 134 pascal OSErr 
AEHandleOApp( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long WXUNUSED(refcon
) ) 
 136     return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event 
, reply 
) ; 
 139 pascal OSErr 
AEHandlePDoc( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long WXUNUSED(refcon
) ) 
 141     return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event 
, reply 
) ; 
 144 pascal OSErr 
AEHandleQuit( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long WXUNUSED(refcon
) ) 
 146     return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event 
, reply
) ; 
 149 pascal OSErr 
AEHandleRApp( const AppleEvent 
*event 
, AppleEvent 
*reply 
, long WXUNUSED(refcon
) ) 
 151     return wxTheApp
->MacHandleAERApp( (AppleEvent
*) event 
, reply
) ; 
 154 // AEODoc Calls MacOpenFile on each of the files passed 
 156 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF 
WXUNUSED(reply
)) 
 160     DescType returnedType
; 
 166     err 
= AEGetParamDesc((AppleEvent 
*)event
, keyDirectObject
, typeAEList
,&docList
); 
 170     err 
= AECountItems(&docList
, &itemsInList
); 
 174     ProcessSerialNumber PSN 
; 
 175     PSN
.highLongOfPSN 
= 0 ; 
 176     PSN
.lowLongOfPSN 
= kCurrentProcess 
; 
 177     SetFrontProcess( &PSN 
) ; 
 179     for (i 
= 1; i 
<= itemsInList
; i
++) { 
 180         AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
, 
 181         (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
); 
 182         wxString fName 
= wxMacFSSpec2MacFilename(&theSpec
); 
 188 // AEPDoc Calls MacPrintFile on each of the files passed 
 190 short wxApp::MacHandleAEPDoc(const WXEVENTREF event 
, WXEVENTREF 
WXUNUSED(reply
)) 
 194     DescType returnedType
; 
 200     err 
= AEGetParamDesc((AppleEvent 
*)event
, keyDirectObject
, typeAEList
,&docList
); 
 204     err 
= AECountItems(&docList
, &itemsInList
); 
 208     ProcessSerialNumber PSN 
; 
 209     PSN
.highLongOfPSN 
= 0 ; 
 210     PSN
.lowLongOfPSN 
= kCurrentProcess 
; 
 211     SetFrontProcess( &PSN 
) ; 
 213     for (i 
= 1; i 
<= itemsInList
; i
++) { 
 214         AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
, 
 215         (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
); 
 216         wxString fName 
= wxMacFSSpec2MacFilename(&theSpec
); 
 222 // AEOApp calls MacNewFile 
 224 short wxApp::MacHandleAEOApp(const WXEVENTREF 
WXUNUSED(event
) , WXEVENTREF 
WXUNUSED(reply
)) 
 230 // AEQuit attempts to quit the application 
 232 short wxApp::MacHandleAEQuit(const WXEVENTREF 
WXUNUSED(event
) , WXEVENTREF 
WXUNUSED(reply
)) 
 234     wxWindow
* win 
= GetTopWindow() ; 
 237         wxCommandEvent 
exitEvent(wxEVT_COMMAND_MENU_SELECTED
, s_macExitMenuItemId
); 
 238         if (!win
->ProcessEvent(exitEvent
)) 
 248 // AEROApp calls MacReopenApp 
 250 short wxApp::MacHandleAERApp(const WXEVENTREF 
WXUNUSED(event
) , WXEVENTREF 
WXUNUSED(reply
)) 
 257 //---------------------------------------------------------------------- 
 258 // Support Routines linking the Mac...File Calls to the Document Manager 
 259 //---------------------------------------------------------------------- 
 261 void wxApp::MacOpenFile(const wxString 
& fileName 
) 
 263     wxDocManager
* dm 
= wxDocManager::GetDocumentManager() ; 
 265         dm
->CreateDocument(fileName 
, wxDOC_SILENT 
) ; 
 268 void wxApp::MacPrintFile(const wxString 
& fileName 
) 
 270     wxDocManager
* dm 
= wxDocManager::GetDocumentManager() ; 
 273         wxDocument 
*doc 
= dm
->CreateDocument(fileName 
, wxDOC_SILENT 
) ; 
 276             wxView
* view 
= doc
->GetFirstView() ; 
 279                 wxPrintout 
*printout 
= view
->OnCreatePrintout(); 
 283                     printer
.Print(view
->GetFrame(), printout
, TRUE
); 
 289                 doc
->DeleteAllViews(); 
 290                 dm
->RemoveDocument(doc
) ; 
 296 void wxApp::MacNewFile() 
 300 void wxApp::MacReopenApp() 
 302     // eventually check for open docs, if none, call MacNewFile 
 305 //---------------------------------------------------------------------- 
 306 // Carbon Event Handler 
 307 //---------------------------------------------------------------------- 
 311     static const EventTypeSpec eventList
[] = 
 313         { kEventClassCommand
, kEventProcessCommand 
} , 
 314         { kEventClassCommand
, kEventCommandUpdateStatus 
} , 
 316         { kEventClassMenu
, kEventMenuOpening 
}, 
 317         { kEventClassMenu
, kEventMenuClosed 
}, 
 318         { kEventClassMenu
, kEventMenuTargetItem 
}, 
 320         { kEventClassApplication 
, kEventAppActivated 
} , 
 321         { kEventClassApplication 
, kEventAppDeactivated 
} , 
 322         // handling the quit event is not recommended by apple 
 323         // rather using the quit apple event - which we do 
 325         { kEventClassAppleEvent 
, kEventAppleEvent 
} , 
 327         { kEventClassMouse 
, kEventMouseDown 
} , 
 328         { kEventClassMouse 
, kEventMouseMoved 
} , 
 329         { kEventClassMouse 
, kEventMouseUp 
} , 
 330         { kEventClassMouse 
, kEventMouseDragged 
} , 
 334 static pascal OSStatus
 
 335 MenuEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 337     wxMenuBar
* mbar 
= wxMenuBar::MacGetInstalledMenuBar(); 
 341         wxFrame
* win 
= mbar
->GetFrame(); 
 345             // VZ: we could find the menu from its handle here by examining all 
 346             //     the menus in the menu bar recursively but knowing that neither 
 347             //     wxMSW nor wxGTK do it why bother... 
 351             GetEventParameter(event
, 
 352                               kEventParamDirectObject
, 
 354                               sizeof(menuRef
), NULL
, 
 360             switch (GetEventKind(event
)) 
 362                 case kEventMenuOpening
: 
 363                     type 
= wxEVT_MENU_OPEN
; 
 365                 case kEventMenuClosed
: 
 366                     type 
= wxEVT_MENU_CLOSE
; 
 368                 case kEventMenuTargetItem
: 
 369                     type 
= wxEVT_MENU_HIGHLIGHT
; 
 370                     GetEventParameter(event
, kEventParamMenuCommand
, 
 371                                       typeMenuCommand
, NULL
, 
 372                                       sizeof(cmd
), NULL
, &cmd
); 
 373                     if (cmd 
== 0) return eventNotHandledErr
; 
 376                     wxFAIL_MSG(wxT("Unexpected menu event kind")); 
 380             wxMenuEvent 
wxevent(type
, cmd
); 
 381             wxevent
.SetEventObject(win
); 
 383             (void)win
->GetEventHandler()->ProcessEvent(wxevent
); 
 387     return eventNotHandledErr
; 
 390 // due to the rather low-level event API of wxWidgets, we cannot use RunApplicationEventLoop 
 391 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have 
 392 // deal with clicks in the menu bar explicitely 
 394 pascal OSStatus 
wxMacWindowEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) ; 
 396 static pascal OSStatus 
MouseEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 398     OSStatus result 
= eventNotHandledErr 
; 
 401     UInt32 modifiers 
= 0; 
 402     EventMouseButton button 
= 0 ; 
 405     GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
, 
 406         sizeof( Point 
), NULL
, &point 
); 
 407     GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 
 408         sizeof( UInt32 
), NULL
, &modifiers 
); 
 409     GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
, 
 410         sizeof( EventMouseButton 
), NULL
, &button 
); 
 411     GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
, 
 412         sizeof( UInt32 
), NULL
, &click 
); 
 414     if ( button 
== 0 || GetEventKind( event 
) == kEventMouseUp 
) 
 415         modifiers 
+= btnState 
; 
 418     switch( GetEventKind(event
) ) 
 420         case kEventMouseDown 
: 
 424             short windowPart 
= ::FindWindow(point
, &window
); 
 426             if ( windowPart 
== inMenuBar 
) 
 428                 MenuSelect( point 
) ; 
 433         case kEventMouseDragged 
: 
 436             if ( wxTheApp
->s_captureWindow 
) 
 437                 wxMacWindowEventHandler( handler 
, event 
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ; 
 440         case kEventMouseMoved 
: 
 442             wxTheApp
->MacHandleMouseMovedEvent( point
.h 
, point
.v 
, modifiers 
, EventTimeToTicks( GetEventTime( event 
) ) ) ; 
 452 static pascal OSStatus 
CommandEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 454     OSStatus result 
= eventNotHandledErr 
; 
 458     GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
, 
 459         sizeof( HICommand 
), NULL
, &command 
); 
 461     MenuCommand id 
= command
.commandID 
; 
 462     if ( id 
== kHICommandPreferences 
) 
 463         id 
= wxApp::s_macPreferencesMenuItemId 
; 
 465     wxMenuBar
* mbar 
= wxMenuBar::MacGetInstalledMenuBar() ; 
 466     wxMenu
* menu 
= NULL 
; 
 467     wxMenuItem
* item 
= NULL 
; 
 471         item 
= mbar
->FindItem( id 
, &menu 
) ; 
 472         // it is not 100 % sure that an menu of id 0 is really ours, safety check 
 473         if ( id 
== 0 && menu 
!= NULL 
&& menu
->GetHMenu() != command
.menu
.menuRef 
) 
 480     if ( item 
== NULL 
|| menu 
== NULL 
|| mbar 
== NULL 
) 
 483        switch( GetEventKind( event 
) ) 
 485            case kEventProcessCommand 
: 
 487                 if (item
->IsCheckable()) 
 489                     item
->Check( !item
->IsChecked() ) ; 
 492                 menu
->SendEvent( id 
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ; 
 496         case kEventCommandUpdateStatus
: 
 497             // eventually trigger an updateui round 
 507 static pascal OSStatus 
ApplicationEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 509     OSStatus result 
= eventNotHandledErr 
; 
 510     switch ( GetEventKind( event 
) ) 
 512         case kEventAppActivated 
: 
 515                     wxTheApp
->MacResume( true ) ; 
 519         case kEventAppDeactivated 
: 
 522                     wxTheApp
->MacSuspend( true ) ; 
 532 pascal OSStatus 
wxAppEventHandler( EventHandlerCallRef handler 
, EventRef event 
, void *data 
) 
 534     OSStatus result 
= eventNotHandledErr 
; 
 535     switch( GetEventClass( event 
) ) 
 537         case kEventClassCommand 
: 
 538             result 
= CommandEventHandler( handler 
, event 
, data 
) ; 
 540         case kEventClassApplication 
: 
 541             result 
= ApplicationEventHandler( handler 
, event 
, data 
) ; 
 543         case kEventClassMenu 
: 
 544             result 
= MenuEventHandler( handler 
, event 
, data 
) ; 
 546         case kEventClassMouse 
: 
 547             result 
= MouseEventHandler( handler 
, event 
, data 
) ; 
 549         case kEventClassAppleEvent 
: 
 552                 wxMacConvertEventToRecord( event 
, &rec 
) ; 
 553                 result 
= AEProcessAppleEvent( &rec 
) ; 
 563 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler 
) 
 567 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__) 
 568 // we know it's there ;-) 
 569 WXIMPORT 
char std::__throws_bad_alloc 
; 
 572 bool wxApp::Initialize(int& argc
, wxChar 
**argv
) 
 578     UMAInitToolbox( 4, sm_isEmbedded 
) ; 
 579     SetEventMask( everyEvent 
) ; 
 580     UMAShowWatchCursor() ; 
 582 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) 
 583     // open shared library resources from here since we don't have 
 584     //   __wxinitialize in Mach-O shared libraries 
 585     wxStAppResource::OpenSharedLibraryResource(NULL
); 
 589     // test the minimal configuration necessary 
 595     if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
) 
 597         error 
= kMacSTRWrongMachine
; 
 599     else if (theMachine 
< gestaltMacPlus
) 
 601         error 
= kMacSTRWrongMachine
; 
 603     else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr 
) 
 605         error 
= kMacSTROldSystem  
; 
 607     else if ( theSystem 
< 0x0860 ) 
 609         error 
= kMacSTROldSystem  
; 
 611     else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
) 
 613         error 
= kMacSTRSmallSize
; 
 619         if ( !UMAHasAppearance() ) 
 621             error = kMacSTRNoPre8Yet ; 
 627     // if we encountered any problems so far, give the error code and exit immediately 
 631         wxStAppResource resload 
; 
 635         GetIndString(message
, 128, error
); 
 636         UMAShowArrowCursor() ; 
 637         ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p"); 
 638         itemHit 
= Alert(128, nil
); 
 643 #  if __option(profile) 
 644     ProfilerInit( collectDetailed
, bestTimeBase 
, 40000 , 50 ) ; 
 649     // now avoid exceptions thrown for new (bad_alloc) 
 650     // FIXME CS for some changes outside wxMac does not compile anymore 
 652     std::__throws_bad_alloc 
= 0 ; 
 657     s_macCursorRgn 
= ::NewRgn() ; 
 659     // Mac OS X passes a process serial number command line argument when 
 660     // the application is launched from the Finder. This argument must be 
 661     // removed from the command line arguments before being handled by the 
 662     // application (otherwise applications would need to handle it) 
 665         static const wxChar 
*ARG_PSN 
= _T("-psn_"); 
 666         if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 ) 
 668             // remove this argument 
 670             memmove(argv 
+ 1, argv 
+ 2, argc 
* sizeof(char *)); 
 674     if ( !wxAppBase::Initialize(argc
, argv
) ) 
 678     wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); 
 682     wxWinMacWindowList 
= new wxList(wxKEY_INTEGER
); 
 683     wxWinMacControlList 
= new wxList(wxKEY_INTEGER
); 
 685     wxMacCreateNotifierTable() ; 
 687     UMAShowArrowCursor() ; 
 692 bool wxApp::OnInitGui() 
 694     if( !wxAppBase::OnInitGui() ) 
 698     InstallStandardEventHandler( GetApplicationEventTarget() ) ; 
 702         InstallApplicationEventHandler( 
 703             GetwxAppEventHandlerUPP(), 
 704             GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef 
*)&(wxTheApp
->m_macEventHandler
)); 
 710 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) 
 711         AEInstallEventHandler( kCoreEventClass 
, kAEOpenDocuments 
, 
 712                                NewAEEventHandlerUPP(AEHandleODoc
) , 
 714         AEInstallEventHandler( kCoreEventClass 
, kAEOpenApplication 
, 
 715                                NewAEEventHandlerUPP(AEHandleOApp
) , 
 717         AEInstallEventHandler( kCoreEventClass 
, kAEPrintDocuments 
, 
 718                                NewAEEventHandlerUPP(AEHandlePDoc
) , 
 720         AEInstallEventHandler( kCoreEventClass 
, kAEReopenApplication 
, 
 721                                NewAEEventHandlerUPP(AEHandleRApp
) , 
 723         AEInstallEventHandler( kCoreEventClass 
, kAEQuitApplication 
, 
 724                                NewAEEventHandlerUPP(AEHandleQuit
) , 
 727         AEInstallEventHandler( kCoreEventClass 
, kAEOpenDocuments 
, 
 728                                NewAEEventHandlerProc(AEHandleODoc
) , 
 730         AEInstallEventHandler( kCoreEventClass 
, kAEOpenApplication 
, 
 731                                NewAEEventHandlerProc(AEHandleOApp
) , 
 733         AEInstallEventHandler( kCoreEventClass 
, kAEPrintDocuments 
, 
 734                                NewAEEventHandlerProc(AEHandlePDoc
) , 
 736         AEInstallEventHandler( kCoreEventClass 
, kAEReopenApplication 
, 
 737                                NewAEEventHandlerProc(AEHandleRApp
) , 
 739         AEInstallEventHandler( kCoreEventClass 
, kAEQuitApplication 
, 
 740                                NewAEEventHandlerProc(AEHandleQuit
) , 
 748 void wxApp::CleanUp() 
 750     wxToolTip::RemoveToolTips() ; 
 752     // One last chance for pending objects to be cleaned up 
 753     wxTheApp
->DeletePendingObjects(); 
 755     wxMacDestroyNotifierTable() ; 
 757     delete wxWinMacWindowList 
; 
 758     wxWinMacWindowList 
= NULL
; 
 760     delete wxWinMacControlList 
; 
 761     wxWinMacControlList 
= NULL
; 
 764 #  if __option(profile) 
 765     ProfilerDump( (StringPtr
)"\papp.prof" ) ; 
 770 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) 
 771     // close shared library resources from here since we don't have 
 772     //   __wxterminate in Mach-O shared libraries 
 773     wxStAppResource::CloseSharedLibraryResource(); 
 776     UMACleanupToolbox() ; 
 777     if (s_macCursorRgn
) { 
 778         ::DisposeRgn((RgnHandle
)s_macCursorRgn
); 
 785     wxAppBase::CleanUp(); 
 788 //---------------------------------------------------------------------- 
 789 // misc initialization stuff 
 790 //---------------------------------------------------------------------- 
 792 // extern variable for shared library resource id 
 793 // need to be able to find it with NSLookupAndBindSymbol 
 794 short gSharedLibraryResource 
= kResFileNotOpened 
; 
 796 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) 
 797 CFBundleRef gSharedLibraryBundle 
= NULL
; 
 798 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */ 
 800 wxStAppResource::wxStAppResource() 
 802     m_currentRefNum 
= CurResFile() ; 
 803     if ( gSharedLibraryResource 
!= kResFileNotOpened 
) 
 805         UseResFile( gSharedLibraryResource 
) ; 
 809 wxStAppResource::~wxStAppResource() 
 811     if ( m_currentRefNum 
!= kResFileNotOpened 
) 
 813         UseResFile( m_currentRefNum 
) ; 
 817 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
) 
 819     gSharedLibraryResource 
= kResFileNotOpened
; 
 821 #ifdef WXMAKINGDLL_CORE 
 822     if ( initBlock 
!= NULL 
) { 
 823         const CFragInitBlock 
*theInitBlock 
= (const CFragInitBlock 
*)initBlock
; 
 824         FSSpec 
*fileSpec 
= NULL
; 
 826         if (theInitBlock
->fragLocator
.where 
== kDataForkCFragLocator
) { 
 827             fileSpec 
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
; 
 829         else if (theInitBlock
->fragLocator
.where 
== kResourceCFragLocator
) { 
 830             fileSpec 
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
; 
 833         if (fileSpec 
!= NULL
) { 
 834             gSharedLibraryResource 
=  FSpOpenResFile(fileSpec
, fsRdPerm
); 
 839         // Open the shared library resource file if it is not yet open 
 842         const char *theLibPath
; 
 844         gSharedLibraryBundle 
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets")); 
 845         if (gSharedLibraryBundle 
!= NULL
) { 
 846             // wxWidgets has been bundled into a framework 
 847             //   load the framework resources 
 849             gSharedLibraryResource 
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
); 
 852             // wxWidgets is a simple dynamic shared library 
 853             //   load the resources from the data fork of a separate resource file 
 857             OSErr  theErr 
= noErr
; 
 859             // get the library path 
 860             theSymbol 
= NSLookupAndBindSymbol("_gSharedLibraryResource"); 
 861             theModule 
= NSModuleForSymbol(theSymbol
); 
 862             theLibPath 
= NSLibraryNameForModule(theModule
); 
 864             // if we call wxLogDebug from here then, as wxTheApp hasn't been 
 865             // created yet when we're called from wxApp::Initialize(), wxLog 
 866             // is going to create a default stderr-based log target instead of 
 867             // the expected normal GUI one -- don't do it, if we really want 
 868             // to see this message just use fprintf() here 
 870             wxLogDebug( wxT("wxMac library installation name is '%s'"), 
 874             // allocate copy to replace .dylib.* extension with .rsrc 
 875             if (theLibPath 
!= NULL
) { 
 877                 theResPath 
= wxString(theLibPath
, wxConvLocal
); 
 879                 theResPath 
= wxString(theLibPath
); 
 881                 // replace '_core' with '' in case of multi-lib build 
 882                 theResPath
.Replace(wxT("_core"), wxEmptyString
); 
 883                 // replace ".dylib" shared library extension with ".rsrc" 
 884                 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc")); 
 885                 // Find the begining of the filename 
 886                 theName 
= theResPath
.AfterLast('/'); 
 889                 wxLogDebug( wxT("wxMac resources file name is '%s'"), 
 890                             theResPath
.mb_str() ); 
 893                 theErr 
= FSPathMakeRef((UInt8 
*) theResPath
.mb_str(), &theResRef
, false); 
 894                 if (theErr 
!= noErr
) { 
 895                     // try in current directory (using name only) 
 896                     theErr 
= FSPathMakeRef((UInt8 
*) theName
.mb_str(), &theResRef
, false); 
 899                 // open the resource file 
 900                 if (theErr 
== noErr
) { 
 901                     theErr 
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
, 
 902                                                  &gSharedLibraryResource
); 
 904                 if (theErr 
!= noErr
) { 
 906                     wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"), 
 907                                 theResPath
.mb_str() ); 
 908 #endif // __WXDEBUG__ 
 913 #endif /* __DARWIN__ */ 
 915 #endif /* WXMAKINGDLL_CORE */ 
 918 void wxStAppResource::CloseSharedLibraryResource() 
 920 #ifdef WXMAKINGDLL_CORE 
 921     // Close the shared library resource file 
 922     if (gSharedLibraryResource 
!= kResFileNotOpened
) { 
 924         if (gSharedLibraryBundle 
!= NULL
) { 
 925             CFBundleCloseBundleResourceMap(gSharedLibraryBundle
, 
 926                                            gSharedLibraryResource
); 
 927             gSharedLibraryBundle 
= NULL
; 
 930 #endif /* __DARWIN__ */ 
 932             CloseResFile(gSharedLibraryResource
); 
 934         gSharedLibraryResource 
= kResFileNotOpened
; 
 936 #endif /* WXMAKINGDLL_CORE */ 
 939 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__) 
 941 // for shared libraries we have to manually get the correct resource 
 942 // ref num upon initializing and releasing when terminating, therefore 
 943 // the __wxinitialize and __wxterminate must be used 
 946     void __sinit(void);    /*    (generated by linker)    */ 
 947     pascal OSErr 
__initialize(const CFragInitBlock 
*theInitBlock
); 
 948     pascal void __terminate(void); 
 951 pascal OSErr 
__wxinitialize(const CFragInitBlock 
*theInitBlock
) 
 953     wxStAppResource::OpenSharedLibraryResource( theInitBlock 
) ; 
 954     return __initialize( theInitBlock 
) ; 
 957 pascal void __wxterminate(void) 
 959     wxStAppResource::CloseSharedLibraryResource() ; 
 963 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */ 
 967 bool wxMacConvertEventToRecord( EventRef event 
, EventRecord 
*rec
) 
 969     bool converted 
= ConvertEventRefToEventRecord( event
,rec
) ; 
 970     OSStatus err 
= noErr 
; 
 973         switch( GetEventClass( event 
) ) 
 975             case kEventClassKeyboard 
: 
 978                 switch( GetEventKind(event
) ) 
 980                     case kEventRawKeyDown 
: 
 981                         rec
->what 
= keyDown 
; 
 983                     case kEventRawKeyRepeat 
: 
 984                         rec
->what 
= autoKey 
; 
 986                     case kEventRawKeyUp 
: 
 989                     case kEventRawKeyModifiersChanged 
: 
 990                         rec
->what 
= nullEvent 
; 
 999                     unsigned char charCode 
; 
1001                     GetMouse( &rec
->where
) ; 
1003                     err 
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
); 
1004                     err 
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
); 
1005                     err 
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
); 
1006                     rec
->modifiers 
= modifiers 
; 
1007                     rec
->message 
= (keyCode 
<< 8 ) + charCode 
; 
1011             case kEventClassTextInput 
: 
1013                 switch( GetEventKind( event 
) ) 
1015                     case kEventTextInputUnicodeForKeyEvent 
: 
1018                             err 
= GetEventParameter( event 
, kEventParamTextInputSendKeyboardEvent 
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent 
) ; 
1022                                 unsigned char charCode 
; 
1024                                 GetMouse( &rec
->where
) ; 
1025                                 rec
->what 
= keyDown 
; 
1026                                 err 
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
); 
1027                                 err 
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
); 
1028                                 err 
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
); 
1029                                 rec
->modifiers 
= modifiers 
; 
1030                                 rec
->message 
= (keyCode 
<< 8 ) + charCode 
; 
1046 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) 
1048     OSStatus result = eventNotHandledErr ; 
1051     switch ( GetEventClass( event ) ) 
1053         case kEventClassKeyboard : 
1054             if ( wxMacConvertEventToRecord( event , &rec ) ) 
1056                 wxTheApp->MacHandleModifierEvents( &rec ) ; 
1057                 wxTheApp->MacHandleOneEvent( &rec ) ; 
1061         case kEventClassTextInput : 
1062             if ( wxMacConvertEventToRecord( event , &rec ) ) 
1064                 wxTheApp->MacHandleModifierEvents( &rec ) ; 
1065                 wxTheApp->MacHandleOneEvent( &rec ) ; 
1079   m_printMode 
= wxPRINT_WINDOWS
; 
1082   m_macCurrentEvent 
= NULL 
; 
1084   m_macCurrentEventHandlerCallRef 
= NULL 
; 
1088 int wxApp::MainLoop() 
1100 void wxApp::ExitMainLoop() 
1102       m_keepGoing 
= FALSE
; 
1105 // Is a message/event pending? 
1106 bool wxApp::Pending() 
1109     // without the receive event (with pull param = false ) nothing is ever reported 
1111     ReceiveNextEvent (0, NULL
, kEventDurationNoWait
, false, &theEvent
); 
1112     return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;  
1116     return EventAvail( everyEvent 
, &event 
) ; 
1120 // Dispatch a message. 
1121 bool wxApp::Dispatch() 
1128 void wxApp::OnIdle(wxIdleEvent
& event
) 
1130     wxAppBase::OnIdle(event
); 
1132     // If they are pending events, we must process them: pending events are 
1133     // either events to the threads other than main or events posted with 
1134     // wxPostEvent() functions 
1135     wxMacProcessNotifierAndPendingEvents(); 
1137   if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) 
1138     wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); 
1141 void wxApp::WakeUpIdle() 
1152 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
)) 
1155         GetTopWindow()->Close(TRUE
); 
1158 // Default behaviour: close the application with prompts. The 
1159 // user can veto the close, and therefore the end session. 
1160 void wxApp::OnQueryEndSession(wxCloseEvent
& event
) 
1164         if (!GetTopWindow()->Close(!event
.CanVeto())) 
1169 extern "C" void wxCYield() ; 
1175 // Yield to other processes 
1177 bool wxApp::Yield(bool onlyIfNeeded
) 
1181         if ( !onlyIfNeeded 
) 
1183             wxFAIL_MSG( wxT("wxYield called recursively" ) ); 
1192     YieldToAnyThread() ; 
1194     // by definition yield should handle all non-processed events 
1198     OSStatus status 
= noErr 
; 
1201         s_inReceiveEvent 
= true ; 
1202         status 
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ; 
1203         s_inReceiveEvent 
= false ; 
1205         if ( status 
== eventLoopTimedOutErr 
) 
1207             // make sure next time the event loop will trigger idle events 
1208             sleepTime 
= kEventDurationNoWait 
; 
1210         else if ( status 
== eventLoopQuitErr 
) 
1212             // according to QA1061 this may also occur when a WakeUp Process 
1217             MacHandleOneEvent( theEvent 
) ; 
1218             ReleaseEvent(theEvent
); 
1220     } while( status 
== noErr 
) ; 
1224     // having a larger value here leads to large performance slowdowns 
1225     // so we cannot give background apps more processor time here 
1226     // we do so however having a large sleep value in the main event loop 
1229     while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
)) 
1231         MacHandleModifierEvents( &event 
) ; 
1232         MacHandleOneEvent( &event 
); 
1233         if ( event
.what 
!= kHighLevelEvent 
) 
1234             SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn 
, event
.where
.h 
, event
.where
.v 
,  event
.where
.h 
+ 1 , event
.where
.v 
+ 1 ) ; 
1236     MacHandleModifierEvents( &event 
) ; 
1239     wxMacProcessNotifierAndPendingEvents() ; 
1245 // platform specifics 
1247 void wxApp::MacSuspend( bool convertClipboard 
) 
1250     // we have to deactive the top level windows manually 
1252     wxWindowListNode
* node 
= wxTopLevelWindows
.GetFirst(); 
1255         wxTopLevelWindow
* win 
= (wxTopLevelWindow
*) node
->Data(); 
1257 #if 0 //  having problems right now with that 
1258         if (!win
->HasFlag(wxSTAY_ON_TOP
)) 
1261             win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when 
, false ) ; 
1263         node 
= node
->GetNext(); 
1266     ::HideFloatingWindows() ; 
1268     s_lastMouseDown 
= 0 ; 
1270     if( convertClipboard 
) 
1272         MacConvertPrivateToPublicScrap() ; 
1276 extern wxList wxModalDialogs
; 
1278 void wxApp::MacResume( bool convertClipboard 
) 
1280     s_lastMouseDown 
= 0 ; 
1281     if( convertClipboard 
) 
1283         MacConvertPublicToPrivateScrap() ; 
1287     ::ShowFloatingWindows() ; 
1288     // raise modal dialogs in case a non modal window was selected to activate the app 
1290     wxNode
* node 
= wxModalDialogs
.GetFirst(); 
1293         wxDialog
* dialog 
= (wxDialog 
*) node
->GetData(); 
1296         node 
= node
->GetNext(); 
1301 void wxApp::MacConvertPrivateToPublicScrap() 
1305 void wxApp::MacConvertPublicToPrivateScrap() 
1309 void wxApp::MacDoOneEvent() 
1314     s_inReceiveEvent 
= true ; 
1315     OSStatus status 
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ; 
1316     s_inReceiveEvent 
= false ; 
1317     if ( status 
== eventLoopTimedOutErr 
) 
1319         if ( wxTheApp
->ProcessIdle() ) 
1320             sleepTime 
= kEventDurationNoWait 
; 
1324             if (g_numberOfThreads
) 
1326                 sleepTime 
= kEventDurationNoWait
; 
1329 #endif // wxUSE_THREADS 
1331                 sleepTime 
= kEventDurationSecond
; 
1335     else if ( status 
== eventLoopQuitErr 
) 
1337         // according to QA1061 this may also occur when a WakeUp Process 
1342         MacHandleOneEvent( theEvent 
) ; 
1343         ReleaseEvent(theEvent
); 
1344         sleepTime 
= kEventDurationNoWait 
; 
1349     EventMask eventMask 
= everyEvent 
; 
1351     if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
)) 
1353         MacHandleModifierEvents( &event 
) ; 
1354         MacHandleOneEvent( &event 
); 
1358         MacHandleModifierEvents( &event 
) ; 
1360         WindowPtr window 
= ::FrontWindow() ; 
1362             ::IdleControls( window 
) ; 
1364         if ( wxTheApp
->ProcessIdle() ) 
1365             sleepTime 
= kEventDurationNoWait
; 
1369             if (g_numberOfThreads
) 
1371                 sleepTime 
= kEventDurationNoWait
; 
1374 #endif // wxUSE_THREADS 
1376                 sleepTime 
= kEventDurationSecond
; 
1380     if ( event
.what 
!= kHighLevelEvent 
) 
1381         SetRectRgn( (RgnHandle
) s_macCursorRgn 
, event
.where
.h 
, event
.where
.v 
,  event
.where
.h 
+ 1 , event
.where
.v 
+ 1 ) ; 
1385     DeletePendingObjects() ; 
1386     wxMacProcessNotifierAndPendingEvents() ; 
1389 /*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr 
) 
1391     // Override to process unhandled events as you please     
1394 void wxApp::MacHandleOneEvent( WXEVENTREF evr 
) 
1397     EventTargetRef theTarget
; 
1398     theTarget 
= GetEventDispatcherTarget(); 
1399     m_macCurrentEvent 
= evr 
; 
1400     OSStatus status 
= SendEventToEventTarget ((EventRef
) evr 
, theTarget
); 
1401     if(status 
== eventNotHandledErr
) 
1403         MacHandleUnhandledEvent(evr
); 
1406     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1407     m_macCurrentEvent 
= ev 
; 
1409     wxApp::sm_lastMessageTime 
= ev
->when 
; 
1414             MacHandleMouseDownEvent( ev 
) ; 
1415             if ( ev
->modifiers 
& controlKey 
) 
1416                 s_lastMouseDown 
= 2; 
1418                 s_lastMouseDown 
= 1; 
1421             if ( s_lastMouseDown 
== 2 ) 
1423                 ev
->modifiers 
|= controlKey 
; 
1427                 ev
->modifiers 
&= ~controlKey 
; 
1429             MacHandleMouseUpEvent( ev 
) ; 
1430             s_lastMouseDown 
= 0; 
1433             MacHandleActivateEvent( ev 
) ; 
1436             // In embedded mode we first let the UnhandledEvent function 
1437             // try to handle the update event. If we handle it ourselves 
1438             // first and then pass it on, the host's windows won't update. 
1439             MacHandleUnhandledEvent(ev
); 
1440             MacHandleUpdateEvent( ev 
) ; 
1444             MacHandleKeyDownEvent( ev 
) ; 
1447             MacHandleKeyUpEvent( ev 
) ; 
1450             MacHandleDiskEvent( ev 
) ; 
1453             MacHandleOSEvent( ev 
) ; 
1455         case kHighLevelEvent
: 
1456             MacHandleHighLevelEvent( ev 
) ; 
1462     wxMacProcessNotifierAndPendingEvents() ; 
1466 bool s_macIsInModalLoop 
= false ; 
1468 void wxApp::MacHandleModifierEvents( WXEVENTREF evr 
) 
1470     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1471     if ( ev
->modifiers 
!= s_lastModifiers 
&& wxWindow::FindFocus() != NULL 
) 
1473         wxKeyEvent 
event(wxEVT_KEY_DOWN
); 
1475         event
.m_shiftDown 
= ev
->modifiers 
& shiftKey
; 
1476         event
.m_controlDown 
= ev
->modifiers 
& controlKey
; 
1477         event
.m_altDown 
= ev
->modifiers 
& optionKey
; 
1478         event
.m_metaDown 
= ev
->modifiers 
& cmdKey
; 
1480         event
.m_x 
= ev
->where
.h
; 
1481         event
.m_y 
= ev
->where
.v
; 
1482         event
.m_timeStamp 
= ev
->when
; 
1483         wxWindow
* focus 
= wxWindow::FindFocus() ; 
1484         event
.SetEventObject(focus
); 
1486         if ( (ev
->modifiers 
^ s_lastModifiers 
) & controlKey 
) 
1488             event
.m_keyCode 
= WXK_CONTROL 
; 
1489             event
.SetEventType( ( ev
->modifiers 
& controlKey 
) ? wxEVT_KEY_DOWN 
: wxEVT_KEY_UP 
) ; 
1490             focus
->GetEventHandler()->ProcessEvent( event 
) ; 
1492         if ( (ev
->modifiers 
^ s_lastModifiers 
) & shiftKey 
) 
1494             event
.m_keyCode 
= WXK_SHIFT 
; 
1495             event
.SetEventType( ( ev
->modifiers 
& shiftKey 
) ? wxEVT_KEY_DOWN 
: wxEVT_KEY_UP 
) ; 
1496             focus
->GetEventHandler()->ProcessEvent( event 
) ; 
1498         if ( (ev
->modifiers 
^ s_lastModifiers 
) & optionKey 
) 
1500             event
.m_keyCode 
= WXK_ALT 
; 
1501             event
.SetEventType( ( ev
->modifiers 
& optionKey 
) ? wxEVT_KEY_DOWN 
: wxEVT_KEY_UP 
) ; 
1502             focus
->GetEventHandler()->ProcessEvent( event 
) ; 
1504         if ( ( ev
->modifiers 
^ s_lastModifiers 
) & cmdKey 
) 
1506             event
.m_keyCode 
= WXK_COMMAND 
; 
1507             event
.SetEventType( ( ev
->modifiers 
& cmdKey 
) ? wxEVT_KEY_DOWN 
: wxEVT_KEY_UP 
) ; 
1508             focus
->GetEventHandler()->ProcessEvent( event 
) ; 
1510         s_lastModifiers 
= ev
->modifiers 
; 
1514 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr 
) 
1516     // we must avoid reentrancy problems when processing high level events eg printing 
1517     bool former 
= s_inYield 
; 
1519     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1520     ::AEProcessAppleEvent( ev 
) ; 
1521     s_inYield 
= former 
; 
1524 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr 
) 
1526     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1527     wxToolTip::RemoveToolTips() ; 
1530     WindowRef frontWindow 
= ::FrontNonFloatingWindow() ; 
1531     WindowAttributes frontWindowAttributes 
= NULL 
; 
1533         ::GetWindowAttributes( frontWindow 
, &frontWindowAttributes 
) ; 
1535     short windowPart 
= ::FindWindow(ev
->where
, &window
); 
1536     wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
1537     if ( wxPendingDelete
.Member(win
) ) 
1541     GetQDGlobalsScreenBits( &screenBits 
); 
1546             if ( s_macIsInModalLoop 
) 
1552                 UInt32 menuresult 
= MenuSelect(ev
->where
) ; 
1553                MacHandleMenuSelect( HiWord( menuresult 
) , LoWord( menuresult 
) ); 
1554                 s_lastMouseDown 
= 0; 
1558             SystemClick( ev 
, window 
) ; 
1559             s_lastMouseDown 
= 0; 
1562             if ( window 
!= frontWindow 
&& s_macIsInModalLoop 
&& !(ev
->modifiers 
& cmdKey 
) ) 
1568                 DragWindow(window
, ev
->where
, &screenBits
.bounds
); 
1573                     Point pt 
= { 0, 0 } ; 
1574                     SetPortWindowPort(window
) ; 
1575                     LocalToGlobal( &pt 
) ; 
1577                         win
->SetSize( pt
.h 
, pt
.v 
, -1 , 
1578                             -1 , wxSIZE_USE_EXISTING
); 
1580                 s_lastMouseDown 
= 0; 
1584             if (TrackGoAway(window
, ev
->where
)) 
1589             s_lastMouseDown 
= 0; 
1593                 Rect newContentRect 
; 
1594                 Rect constraintRect 
; 
1595                 constraintRect
.top 
= win
->GetMinHeight() ; 
1596                 if ( constraintRect
.top 
== -1 ) 
1597                     constraintRect
.top  
= 0 ; 
1598                 constraintRect
.left 
= win
->GetMinWidth() ; 
1599                 if ( constraintRect
.left 
== -1 ) 
1600                     constraintRect
.left  
= 0 ; 
1601                 constraintRect
.right 
= win
->GetMaxWidth() ; 
1602                 if ( constraintRect
.right 
== -1 ) 
1603                     constraintRect
.right  
= 32000 ; 
1604                 constraintRect
.bottom 
= win
->GetMaxHeight() ; 
1605                 if ( constraintRect
.bottom 
== -1 ) 
1606                     constraintRect
.bottom 
= 32000 ; 
1608                 Boolean growResult 
= ResizeWindow( window 
, ev
->where 
, 
1609                     &constraintRect 
, &newContentRect 
) ; 
1612                     win
->SetSize( newContentRect
.left 
, newContentRect
.top 
, 
1613                         newContentRect
.right 
- newContentRect
.left 
, 
1614                         newContentRect
.bottom 
- newContentRect
.top
, wxSIZE_USE_EXISTING
); 
1616                 s_lastMouseDown 
= 0; 
1621                 if (TrackBox(window
, ev
->where
, windowPart
)) 
1623                     // TODO setup size event 
1624                     ZoomWindow( window 
, windowPart 
, false ) ; 
1630                         Point pt 
= { 0, 0 } ; 
1631                         SetPortWindowPort(window
) ; 
1632                         LocalToGlobal( &pt 
) ; 
1635                         GetWindowPortBounds(window
, &tempRect 
) ; 
1636                         win
->SetSize( pt
.h 
, pt
.v 
, tempRect
.right
-tempRect
.left 
, 
1637                             tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
); 
1640             s_lastMouseDown 
= 0; 
1642         case inCollapseBox 
: 
1643                 // TODO setup size event 
1644             s_lastMouseDown 
= 0; 
1651                     SetPortWindowPort(window
) ; 
1654                 if ( window 
!= frontWindow 
&& wxTheApp
->s_captureWindow 
== NULL 
) 
1656                     if ( s_macIsInModalLoop 
) 
1660                     else if ( UMAIsWindowFloating( window 
) ) 
1663                             win
->MacMouseDown( ev 
, windowPart 
) ; 
1667                         // Activate window first 
1668                         ::SelectWindow( window 
) ; 
1672                             win
->MacMouseDown( ev 
, windowPart 
) ; 
1678                         win
->MacMouseDown( ev 
, windowPart 
) ; 
1686 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr 
) 
1688     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1691     short windowPart 
= inNoWindow 
; 
1692     if ( wxTheApp
->s_captureWindow 
) 
1694         window 
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ; 
1695         windowPart 
= inContent 
; 
1699         windowPart 
= ::FindWindow(ev
->where
, &window
) ; 
1710                 wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
1712                     win
->MacMouseUp( ev 
, windowPart 
) ; 
1720 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ; 
1721 long wxMacTranslateKey(unsigned char key
, unsigned char code
) 
1726         case kHomeCharCode 
: 
1729         case kEnterCharCode 
: 
1730                  retval 
= WXK_RETURN
; 
1735         case kHelpCharCode 
: 
1738         case kBackspaceCharCode 
: 
1744         case kPageUpCharCode 
: 
1745                  retval 
= WXK_PAGEUP
; 
1747         case kPageDownCharCode 
: 
1748                  retval 
= WXK_PAGEDOWN
; 
1750         case kReturnCharCode 
: 
1751                  retval 
= WXK_RETURN
; 
1753             case kFunctionKeyCharCode 
: 
1805             case kEscapeCharCode 
: 
1806                 retval 
= WXK_ESCAPE 
; 
1808             case kLeftArrowCharCode 
: 
1811             case kRightArrowCharCode 
: 
1812                 retval 
= WXK_RIGHT 
; 
1814             case kUpArrowCharCode 
: 
1817             case kDownArrowCharCode 
: 
1820             case kDeleteCharCode 
: 
1821                 retval 
= WXK_DELETE 
; 
1829 int wxKeyCodeToMacModifier(wxKeyCode key
) 
1854 bool wxGetKeyState(wxKeyCode key
) //virtual key code if < 10.2.x, else see below 
1856 #if __WXMAC_CARBON__ 
1857 //TODO: Low get map... 
1858    return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key
));  
1862         return !!(BitTst(keymap
, (sizeof(KeyMap
)*8) - key
)); 
1867 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr 
) 
1869     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1870     wxToolTip::RemoveToolTips() ; 
1872     UInt32 menuresult 
= UMAMenuEvent(ev
) ; 
1873     if ( HiWord( menuresult 
) ) 
1875         if ( !s_macIsInModalLoop 
) 
1876             MacHandleMenuSelect( HiWord( menuresult 
) , LoWord( menuresult 
) ) ; 
1880          wxWindow
* focus 
= wxWindow::FindFocus() ; 
1882         if ( MacSendKeyDownEvent( focus 
, ev
->message 
, ev
->modifiers 
, ev
->when 
, ev
->where
.h 
, ev
->where
.v 
) == false ) 
1885             // we must handle control keys the other way round, otherwise text content is updated too late 
1886             // has not been handled -> perform default 
1887             wxControl
* control 
= wxDynamicCast( focus 
, wxControl 
) ; 
1888             if ( control 
&&  control
->GetMacControl() != NULL 
) 
1892                 keychar 
= short(ev
->message 
& charCodeMask
); 
1893                 keycode 
= short(ev
->message 
& keyCodeMask
) >> 8 ; 
1894                 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode 
, keychar 
, ev
->modifiers 
) ; 
1901 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr 
) 
1903     EventRecord
* ev 
= (EventRecord
*) evr 
; 
1904     wxToolTip::RemoveToolTips() ; 
1906     UInt32 menuresult 
= UMAMenuEvent(ev
) ; 
1907     if ( HiWord( menuresult 
) ) 
1912         MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message 
, ev
->modifiers 
, ev
->when 
, ev
->where
.h 
, ev
->where
.v 
) ; 
1918 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus 
, long keymessage 
, long modifiers 
, long when 
, short wherex 
, short wherey 
) 
1925     keychar 
= short(keymessage 
& charCodeMask
); 
1926     keycode 
= short(keymessage 
& keyCodeMask
) >> 8 ; 
1928     if ( modifiers 
& ( controlKey
|shiftKey
|optionKey 
) ) 
1930         // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier 
1931         // and look at the character after 
1933         UInt32 keyInfo 
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers 
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
); 
1934         keychar 
= short(keyInfo 
& charCodeMask
); 
1935         keycode 
= short(keyInfo 
& keyCodeMask
) >> 8 ; 
1937     long keyval 
= wxMacTranslateKey(keychar
, keycode
) ; 
1938     long realkeyval 
= keyval 
; 
1939     if ( keyval 
== keychar 
) 
1941         // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first) 
1942         realkeyval 
= short(keymessage 
& charCodeMask
) ; 
1943         keyval 
= wxToupper( keyval 
) ; 
1946     wxKeyEvent 
event(wxEVT_KEY_DOWN
); 
1947     bool handled 
= false ; 
1948     event
.m_shiftDown 
= modifiers 
& shiftKey
; 
1949     event
.m_controlDown 
= modifiers 
& controlKey
; 
1950     event
.m_altDown 
= modifiers 
& optionKey
; 
1951     event
.m_metaDown 
= modifiers 
& cmdKey
; 
1952     event
.m_keyCode 
= keyval 
; 
1956     event
.m_timeStamp 
= when
; 
1957     event
.SetEventObject(focus
); 
1958     handled 
= focus
->GetEventHandler()->ProcessEvent( event 
) ; 
1959     if ( handled 
&& event
.GetSkipped() ) 
1966             wxWindow 
*ancestor 
= focus
; 
1969                 int command 
= ancestor
->GetAcceleratorTable()->GetCommand( event 
); 
1972                     wxCommandEvent 
command_event( wxEVT_COMMAND_MENU_SELECTED
, command 
); 
1973                     handled 
= ancestor
->GetEventHandler()->ProcessEvent( command_event 
); 
1976                 if (ancestor
->IsTopLevel()) 
1978                 ancestor 
= ancestor
->GetParent(); 
1981 #endif // wxUSE_ACCEL 
1985         event
.Skip( FALSE 
) ; 
1986         event
.SetEventType( wxEVT_CHAR 
) ; 
1988         event
.m_keyCode 
= realkeyval 
; 
1990         handled 
= focus
->GetEventHandler()->ProcessEvent( event 
) ; 
1991         if ( handled 
&& event
.GetSkipped() ) 
1995          (keyval 
== WXK_TAB
) && 
1996 // CS: copied the change below from wxGTK 
1997 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may 
1998 //     have this style, yet choose not to process this particular TAB in which 
1999 //     case TAB must still work as a navigational character 
2001          (!focus
->HasFlag(wxTE_PROCESS_TAB
)) && 
2003          (focus
->GetParent()) && 
2004          (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) ) 
2006         wxNavigationKeyEvent new_event
; 
2007         new_event
.SetEventObject( focus 
); 
2008         new_event
.SetDirection( !event
.ShiftDown() ); 
2009         /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ 
2010         new_event
.SetWindowChange( event
.ControlDown() ); 
2011         new_event
.SetCurrentFocus( focus 
); 
2012         handled 
= focus
->GetEventHandler()->ProcessEvent( new_event 
); 
2013         if ( handled 
&& new_event
.GetSkipped() ) 
2016     // backdoor handler for default return and command escape 
2017     if ( !handled 
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) ) 
2019           // if window is not having a focus still testing for default enter or cancel 
2020           // TODO add the UMA version for ActiveNonFloatingWindow 
2021           wxWindow
* focus 
= wxFindWinFromMacWindow( (WXWindow
) FrontWindow() ) ; 
2024             if ( keyval 
== WXK_RETURN 
) 
2026                  wxButton 
*def 
= wxDynamicCast(focus
->GetDefaultItem(), 
2028                  if ( def 
&& def
->IsEnabled() ) 
2030                      wxCommandEvent 
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() ); 
2031                      event
.SetEventObject(def
); 
2032                      def
->Command(event
); 
2036             /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ 
2037             else if (keyval 
== WXK_ESCAPE 
|| (keyval 
== '.' && modifiers 
& cmdKey 
) ) 
2039                   wxCommandEvent 
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
); 
2040                   new_event
.SetEventObject( focus 
); 
2041                   handled 
= focus
->GetEventHandler()->ProcessEvent( new_event 
); 
2048 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus 
, long keymessage 
, long modifiers 
, long when 
, short wherex 
, short wherey 
) 
2055     keychar 
= short(keymessage 
& charCodeMask
); 
2056     keycode 
= short(keymessage 
& keyCodeMask
) >> 8 ; 
2057     if ( modifiers 
& ( controlKey
|shiftKey
|optionKey 
) ) 
2059         // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier 
2060         // and look at the character after 
2062         UInt32 keyInfo 
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers 
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
); 
2063         keychar 
= short(keyInfo 
& charCodeMask
); 
2064         keycode 
= short(keyInfo 
& keyCodeMask
) >> 8 ; 
2066     long keyval 
= wxMacTranslateKey(keychar
, keycode
) ; 
2068     if ( keyval 
== keychar 
) 
2070         keyval 
= wxToupper( keyval 
) ; 
2072     bool handled 
= false ; 
2074     wxKeyEvent 
event(wxEVT_KEY_UP
); 
2075     event
.m_shiftDown 
= modifiers 
& shiftKey
; 
2076     event
.m_controlDown 
= modifiers 
& controlKey
; 
2077     event
.m_altDown 
= modifiers 
& optionKey
; 
2078     event
.m_metaDown 
= modifiers 
& cmdKey
; 
2079     event
.m_keyCode 
= keyval 
; 
2083     event
.m_timeStamp 
= when
; 
2084     event
.SetEventObject(focus
); 
2085     handled 
= focus
->GetEventHandler()->ProcessEvent( event 
) ; 
2091 void wxApp::MacHandleActivateEvent( WXEVENTREF evr 
) 
2093     EventRecord
* ev 
= (EventRecord
*) evr 
; 
2094     WindowRef window 
= (WindowRef
) ev
->message 
; 
2097         bool activate 
= (ev
->modifiers 
& activeFlag 
) ; 
2098         WindowClass wclass 
; 
2099         ::GetWindowClass ( window 
, &wclass 
) ; 
2100         if ( wclass 
== kFloatingWindowClass 
) 
2102             // if it is a floater we activate/deactivate the front non-floating window instead 
2103             window 
= ::FrontNonFloatingWindow() ; 
2105         wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
2107             win
->MacActivate( ev
->when 
, activate 
) ; 
2111 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr 
) 
2113     EventRecord
* ev 
= (EventRecord
*) evr 
; 
2114     WindowRef window 
= (WindowRef
) ev
->message 
; 
2115     wxTopLevelWindowMac 
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
2118         if ( !wxPendingDelete
.Member(win
) ) 
2119             win
->MacUpdate( ev
->when 
) ; 
2123         // since there is no way of telling this foreign window to update itself 
2124         // we have to invalidate the update region otherwise we keep getting the same 
2125         // event over and over again 
2126         BeginUpdate( window 
) ; 
2127         EndUpdate( window 
) ; 
2131 void wxApp::MacHandleDiskEvent( WXEVENTREF evr 
) 
2133     EventRecord
* ev 
= (EventRecord
*) evr 
; 
2134     if ( HiWord( ev
->message 
) != noErr 
) 
2138          SetPt( &point 
, 100 , 100 ) ; 
2140           err 
= DIBadMount( point 
, ev
->message 
) ; 
2141         wxASSERT( err 
== noErr 
) ; 
2145 void wxApp::MacHandleOSEvent( WXEVENTREF evr 
) 
2147     EventRecord
* ev 
= (EventRecord
*) evr 
; 
2148     switch( ( ev
->message 
& osEvtMessageMask 
) >> 24 ) 
2150         case suspendResumeMessage 
: 
2152                 bool isResuming 
= ev
->message 
& resumeFlag 
; 
2153                 bool convertClipboard 
= ev
->message 
& convertClipboardFlag 
; 
2155                 bool doesActivate 
= UMAGetProcessModeDoesActivateOnFGSwitch() ; 
2158                     WindowRef oldFrontWindow 
= NULL 
; 
2159                     WindowRef newFrontWindow 
= NULL 
; 
2161                     // in case we don't take care of activating ourselves, we have to synchronize 
2162                     // our idea of the active window with the process manager's - which it already activated 
2164                     if ( !doesActivate 
) 
2165                         oldFrontWindow 
= ::FrontNonFloatingWindow() ; 
2167                     MacResume( convertClipboard 
) ; 
2169                     newFrontWindow 
= ::FrontNonFloatingWindow() ; 
2171                     if ( oldFrontWindow 
) 
2173                         wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) oldFrontWindow 
) ; 
2175                             win
->MacActivate( ev
->when 
, false ) ; 
2177                     if ( newFrontWindow 
) 
2179                         wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) newFrontWindow 
) ; 
2181                             win
->MacActivate( ev
->when 
, true ) ; 
2186                     MacSuspend( convertClipboard 
) ; 
2190         case mouseMovedMessage 
: 
2194                 wxWindow
* currentMouseWindow 
= NULL 
; 
2196                 if (s_captureWindow 
) 
2198                     currentMouseWindow 
= s_captureWindow 
; 
2202                     wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h 
, ev
->where
.v 
) , 
2203                                                              ¤tMouseWindow 
) ; 
2206                 if ( currentMouseWindow 
!= wxWindow::s_lastMouseWindow 
) 
2208                     wxMouseEvent event 
; 
2210                     bool isDown 
= !(ev
->modifiers 
& btnState
) ; // 1 is for up 
2211                     bool controlDown 
= ev
->modifiers 
& controlKey 
; // for simulating right mouse 
2213                     event
.m_leftDown 
= isDown 
&& !controlDown
; 
2214                     event
.m_middleDown 
= FALSE
; 
2215                     event
.m_rightDown 
= isDown 
&& controlDown
; 
2216                     event
.m_shiftDown 
= ev
->modifiers 
& shiftKey
; 
2217                     event
.m_controlDown 
= ev
->modifiers 
& controlKey
; 
2218                     event
.m_altDown 
= ev
->modifiers 
& optionKey
; 
2219                     event
.m_metaDown 
= ev
->modifiers 
& cmdKey
; 
2220                     event
.m_x 
= ev
->where
.h
; 
2221                     event
.m_y 
= ev
->where
.v
; 
2222                     event
.m_timeStamp 
= ev
->when
; 
2223                     event
.SetEventObject(this); 
2225                     if ( wxWindow::s_lastMouseWindow 
) 
2227                         wxMouseEvent 
eventleave(event
); 
2228                         eventleave
.SetEventType( wxEVT_LEAVE_WINDOW 
); 
2229                         wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y 
); 
2230                         eventleave
.SetEventObject( wxWindow::s_lastMouseWindow 
) ; 
2232                         wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
); 
2234                     if ( currentMouseWindow 
) 
2236                         wxMouseEvent 
evententer(event
); 
2237                         evententer
.SetEventType( wxEVT_ENTER_WINDOW 
); 
2238                         currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y 
); 
2239                         evententer
.SetEventObject( currentMouseWindow 
) ; 
2240                         currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
); 
2242                     wxWindow::s_lastMouseWindow 
= currentMouseWindow 
; 
2245                 short windowPart 
= inNoWindow 
; 
2247                 if ( s_captureWindow 
) 
2249                     window 
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ; 
2250                     windowPart 
= inContent 
; 
2254                     windowPart 
= ::FindWindow(ev
->where
, &window
); 
2261                             wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( (WXWindow
) window 
) ; 
2263                                 win
->MacMouseMoved( ev 
, windowPart 
) ; 
2270                                     UMAShowArrowCursor(); 
2280                                 UMAShowArrowCursor(); 
2291 void wxApp::MacHandleMouseMovedEvent(wxInt32 x 
, wxInt32 y 
,wxUint32 modifiers 
, long timestamp
) 
2295     wxWindow
* currentMouseWindow 
= NULL 
; 
2297     if (s_captureWindow 
) 
2299         currentMouseWindow 
= s_captureWindow 
; 
2303         wxWindow::MacGetWindowFromPoint( wxPoint( x
, y 
) , ¤tMouseWindow 
) ; 
2306     if ( currentMouseWindow 
!= wxWindow::s_lastMouseWindow 
) 
2308         wxMouseEvent event 
; 
2310         bool isDown 
= !(modifiers 
& btnState
) ; // 1 is for up 
2311         bool controlDown 
= modifiers 
& controlKey 
; // for simulating right mouse 
2313         event
.m_leftDown 
= isDown 
&& !controlDown
; 
2315         event
.m_middleDown 
= FALSE
; 
2316         event
.m_rightDown 
= isDown 
&& controlDown
; 
2318         event
.m_shiftDown 
= modifiers 
& shiftKey
; 
2319         event
.m_controlDown 
= modifiers 
& controlKey
; 
2320         event
.m_altDown 
= modifiers 
& optionKey
; 
2321         event
.m_metaDown 
= modifiers 
& cmdKey
; 
2325         event
.m_timeStamp 
= timestamp
; 
2327         if ( wxWindow::s_lastMouseWindow 
) 
2329             wxMouseEvent 
eventleave(event
); 
2330             eventleave
.SetEventType( wxEVT_LEAVE_WINDOW 
); 
2331             wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y 
); 
2332             eventleave
.SetEventObject( wxWindow::s_lastMouseWindow 
) ; 
2335             wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow 
, eventleave
); 
2336 #endif // wxUSE_TOOLTIPS 
2337             wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
); 
2339         if ( currentMouseWindow 
) 
2341             wxMouseEvent 
evententer(event
); 
2342             evententer
.SetEventType( wxEVT_ENTER_WINDOW 
); 
2343             currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y 
); 
2344             evententer
.SetEventObject( currentMouseWindow 
) ; 
2346             wxToolTip::RelayEvent( currentMouseWindow 
, evententer
); 
2347 #endif // wxUSE_TOOLTIPS 
2348             currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
); 
2350         wxWindow::s_lastMouseWindow 
= currentMouseWindow 
; 
2353     short windowPart 
= inNoWindow 
; 
2355     if ( s_captureWindow 
) 
2357         window 
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ; 
2358         windowPart 
= inContent 
; 
2362         Point pt
= { y 
, x 
} ; 
2363         windowPart 
= ::FindWindow(pt 
, &window
); 
2370                 wxTopLevelWindowMac
* win 
= wxFindWinFromMacWindow( window 
) ; 
2372                     win
->MacFireMouseEvent( nullEvent 
, x 
, y 
, modifiers 
, timestamp 
) ; 
2379                         UMAShowArrowCursor(); 
2389                     UMAShowArrowCursor(); 
2396 void wxApp::MacHandleMenuCommand( wxUint32 id 
) 
2398     wxMenuBar
* mbar 
= wxMenuBar::MacGetInstalledMenuBar() ; 
2399     wxFrame
* frame 
= mbar
->GetFrame(); 
2400     wxCHECK_RET( mbar 
!= NULL 
&& frame 
!= NULL
, wxT("error in menu item callback") ); 
2403         frame
->ProcessCommand(id
); 
2408 void wxApp::MacHandleMenuSelect( int macMenuId 
, int macMenuItemNum 
) 
2411          return; // no menu item selected 
2413     if (macMenuId 
== kwxMacAppleMenuId 
&& macMenuItemNum 
> 1) 
2416         Str255        deskAccessoryName 
; 
2419         GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
); 
2420         GetPort(&savedPort
); 
2421         OpenDeskAcc(deskAccessoryName
); 
2428         GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum 
, &id 
) ; 
2429         MacHandleMenuCommand( id 
) ;