]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/app.cpp
Added wxFrameBase::OnMenuOpen, and wxUSE_IDLEMENUUPDATES in platform.h
[wxWidgets.git] / src / mac / carbon / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: app.cpp
3 // Purpose: wxApp
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "app.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/window.h"
19 #include "wx/frame.h"
20 #include "wx/button.h"
21 #include "wx/app.h"
22 #include "wx/utils.h"
23 #include "wx/gdicmn.h"
24 #include "wx/pen.h"
25 #include "wx/brush.h"
26 #include "wx/cursor.h"
27 #include "wx/intl.h"
28 #include "wx/icon.h"
29 #include "wx/palette.h"
30 #include "wx/dc.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
33 #include "wx/log.h"
34 #include "wx/module.h"
35 #include "wx/memory.h"
36 #include "wx/tooltip.h"
37 #include "wx/textctrl.h"
38 #include "wx/menu.h"
39 #include "wx/docview.h"
40
41 #include <string.h>
42
43 // mac
44
45 #ifndef __DARWIN__
46 #if __option(profile)
47 #include <profiler.h>
48 #endif
49 #endif
50
51 #include "apprsrc.h"
52
53 #include "wx/mac/uma.h"
54 #include "wx/mac/macnotfy.h"
55
56 #ifdef __DARWIN__
57 # include <CoreServices/CoreServices.h>
58 # if defined(WXMAKINGDLL)
59 # include <mach-o/dyld.h>
60 # endif
61 #else
62 # include <Sound.h>
63 # include <Threads.h>
64 # include <ToolUtils.h>
65 # include <DiskInit.h>
66 # include <Devices.h>
67 #endif
68
69 extern wxList wxPendingDelete;
70 extern wxList *wxWinMacWindowList;
71 extern wxList *wxWinMacControlList;
72
73 // statics for implementation
74
75 static bool s_inYield = FALSE;
76 static bool s_inOnIdle = FALSE;
77
78 #if TARGET_CARBON
79 static bool s_inReceiveEvent = FALSE ;
80 static EventTime sleepTime = kEventDurationNoWait ;
81 #else
82 static long sleepTime = 0 ;
83 #endif
84
85 #if !USE_SHARED_LIBRARY
86 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
87 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
88 EVT_IDLE(wxApp::OnIdle)
89 EVT_END_SESSION(wxApp::OnEndSession)
90 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
91 END_EVENT_TABLE()
92 #endif
93
94
95 const short kMacMinHeap = (29 * 1024) ;
96 // platform specific static variables
97
98 const short kwxMacMenuBarResource = 1 ;
99 const short kwxMacAppleMenuId = 1 ;
100
101 WXHRGN wxApp::s_macCursorRgn = NULL;
102 wxWindow* wxApp::s_captureWindow = NULL ;
103 int wxApp::s_lastMouseDown = 0 ;
104 long wxApp::sm_lastMessageTime = 0;
105 long wxApp::s_lastModifiers = 0 ;
106
107
108 bool wxApp::s_macDefaultEncodingIsPC = true ;
109 bool wxApp::s_macSupportPCMenuShortcuts = true ;
110 long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
111 long wxApp::s_macPreferencesMenuItemId = 0 ;
112 long wxApp::s_macExitMenuItemId = wxID_EXIT ;
113 wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ;
114
115 //----------------------------------------------------------------------
116 // Core Apple Event Support
117 //----------------------------------------------------------------------
118
119 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
120 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
121 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
122 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
123
124 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
125 {
126 return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
127 }
128
129 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
130 {
131 return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
132 }
133
134 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
135 {
136 return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
137 }
138
139 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
140 {
141 return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
142 }
143
144 // AEODoc Calls MacOpenFile on each of the files passed
145
146 short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
147 {
148 AEDescList docList;
149 AEKeyword keywd;
150 DescType returnedType;
151 Size actualSize;
152 long itemsInList;
153 FSSpec theSpec;
154 OSErr err;
155 short i;
156 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
157 if (err != noErr)
158 return err;
159
160 err = AECountItems(&docList, &itemsInList);
161 if (err != noErr)
162 return err;
163
164 ProcessSerialNumber PSN ;
165 PSN.highLongOfPSN = 0 ;
166 PSN.lowLongOfPSN = kCurrentProcess ;
167 SetFrontProcess( &PSN ) ;
168
169 for (i = 1; i <= itemsInList; i++) {
170 AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
171 (Ptr) & theSpec, sizeof(theSpec), &actualSize);
172 wxString fName = wxMacFSSpec2MacFilename(&theSpec);
173 MacOpenFile(fName);
174 }
175 return noErr;
176 }
177
178 // AEPDoc Calls MacPrintFile on each of the files passed
179
180 short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply))
181 {
182 AEDescList docList;
183 AEKeyword keywd;
184 DescType returnedType;
185 Size actualSize;
186 long itemsInList;
187 FSSpec theSpec;
188 OSErr err;
189 short i;
190 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
191 if (err != noErr)
192 return err;
193
194 err = AECountItems(&docList, &itemsInList);
195 if (err != noErr)
196 return err;
197
198 ProcessSerialNumber PSN ;
199 PSN.highLongOfPSN = 0 ;
200 PSN.lowLongOfPSN = kCurrentProcess ;
201 SetFrontProcess( &PSN ) ;
202
203 for (i = 1; i <= itemsInList; i++) {
204 AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
205 (Ptr) & theSpec, sizeof(theSpec), &actualSize);
206 wxString fName = wxMacFSSpec2MacFilename(&theSpec);
207 MacPrintFile(fName);
208 }
209 return noErr;
210 }
211
212 // AEOApp calls MacNewFile
213
214 short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
215 {
216 MacNewFile() ;
217 return noErr ;
218 }
219
220 // AEQuit attempts to quit the application
221
222 short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
223 {
224 /* wxWindow* win = GetTopWindow() ;
225 if ( win )
226 {
227 win->Close(TRUE ) ;
228 }
229 else
230 */
231 {
232 ExitMainLoop() ;
233 }
234 return noErr ;
235 }
236
237 //----------------------------------------------------------------------
238 // Support Routines linking the Mac...File Calls to the Document Manager
239 //----------------------------------------------------------------------
240
241 void wxApp::MacOpenFile(const wxString & fileName )
242 {
243 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
244 if ( dm )
245 dm->CreateDocument(fileName , wxDOC_SILENT ) ;
246 }
247
248 void wxApp::MacPrintFile(const wxString & fileName )
249 {
250 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
251 if ( dm )
252 {
253 wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ;
254 if ( doc )
255 {
256 wxView* view = doc->GetFirstView() ;
257 if( view )
258 {
259 wxPrintout *printout = view->OnCreatePrintout();
260 if (printout)
261 {
262 wxPrinter printer;
263 printer.Print(view->GetFrame(), printout, TRUE);
264 delete printout;
265 }
266 }
267 if (doc->Close())
268 {
269 doc->DeleteAllViews();
270 dm->RemoveDocument(doc) ;
271 }
272 }
273 }
274 }
275
276 void wxApp::MacNewFile()
277 {
278 }
279
280 //----------------------------------------------------------------------
281 // Carbon Event Handler
282 //----------------------------------------------------------------------
283
284 #if TARGET_CARBON
285
286 static const EventTypeSpec eventList[] =
287 {
288 { kEventClassCommand, kEventProcessCommand } ,
289 { kEventClassCommand, kEventCommandUpdateStatus } ,
290
291 { kEventClassApplication , kEventAppActivated } ,
292 { kEventClassApplication , kEventAppDeactivated } ,
293 // handling the quit event is not recommended by apple
294 // rather using the quit apple event - which we do
295
296 { kEventClassAppleEvent , kEventAppleEvent } ,
297
298 { kEventClassMouse , kEventMouseDown } ,
299 { 'WXMC' , 'WXMC' }
300 } ;
301
302 static pascal OSStatus MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
303 {
304 return eventNotHandledErr ;
305 }
306
307 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
308 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
309 // deal with clicks in the menu bar explicitely
310
311 static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
312 {
313 OSStatus result = eventNotHandledErr ;
314
315 switch( GetEventKind(event) )
316 {
317 case kEventMouseDown :
318 {
319 Point point ;
320 WindowRef window ;
321
322 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
323 sizeof( Point ), NULL, &point );
324 short windowPart = ::FindWindow(point, &window);
325
326 if ( windowPart == inMenuBar )
327 {
328 MenuSelect( point ) ;
329 result = noErr ;
330 }
331 }
332 break ;
333 }
334
335 return result ;
336 }
337
338 static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
339 {
340 OSStatus result = eventNotHandledErr ;
341
342 HICommand command ;
343
344 GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL,
345 sizeof( HICommand ), NULL, &command );
346
347 MenuCommand id = command.commandID ;
348 if ( id == kHICommandPreferences )
349 id = wxApp::s_macPreferencesMenuItemId ;
350
351 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
352 wxMenu* menu = NULL ;
353 wxMenuItem* item = NULL ;
354
355 if ( mbar )
356 item = mbar->FindItem( id , &menu ) ;
357
358 if ( item == NULL || menu == NULL || mbar == NULL )
359 return result ;
360
361 switch( GetEventKind( event ) )
362 {
363 case kEventProcessCommand :
364 {
365 if (item->IsCheckable())
366 {
367 item->Check( !item->IsChecked() ) ;
368 }
369
370 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
371 result = noErr ;
372 }
373 break ;
374 case kEventCommandUpdateStatus:
375 // eventually trigger an updateui round
376 result = noErr ;
377 break ;
378 default :
379 break ;
380 }
381
382 return result ;
383 }
384
385 static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
386 {
387 OSStatus result = eventNotHandledErr ;
388 switch ( GetEventKind( event ) )
389 {
390 case kEventAppActivated :
391 {
392 if ( wxTheApp )
393 wxTheApp->MacResume( true ) ;
394 result = noErr ;
395 }
396 break ;
397 case kEventAppDeactivated :
398 {
399 if ( wxTheApp )
400 wxTheApp->MacSuspend( true ) ;
401 result = noErr ;
402 }
403 break ;
404 default :
405 break ;
406 }
407 return result ;
408 }
409
410 pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
411 {
412 OSStatus result = eventNotHandledErr ;
413 switch( GetEventClass( event ) )
414 {
415 case kEventClassCommand :
416 result = CommandEventHandler( handler , event , data ) ;
417 break ;
418 case kEventClassApplication :
419 result = ApplicationEventHandler( handler , event , data ) ;
420 break ;
421 case kEventClassMenu :
422 result = MenuEventHandler( handler , event , data ) ;
423 break ;
424 case kEventClassMouse :
425 result = MouseEventHandler( handler , event , data ) ;
426 break ;
427 case kEventClassAppleEvent :
428 {
429 EventRecord rec ;
430 wxMacConvertEventToRecord( event , &rec ) ;
431 result = AEProcessAppleEvent( &rec ) ;
432 }
433 break ;
434 default :
435 break ;
436 }
437
438 return result ;
439 }
440
441 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )
442
443 #endif
444
445 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
446 // we know it's there ;-)
447 WXIMPORT char std::__throws_bad_alloc ;
448 #endif
449
450 bool wxApp::Initialize(int& argc, wxChar **argv)
451 {
452 int error = 0 ;
453
454 // Mac-specific
455
456 UMAInitToolbox( 4 ) ;
457 SetEventMask( everyEvent ) ;
458 UMAShowWatchCursor() ;
459
460 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
461 // open shared library resources from here since we don't have
462 // __wxinitialize in Mach-O shared libraries
463 wxStAppResource::OpenSharedLibraryResource(NULL);
464 #endif
465
466 #ifndef __DARWIN__
467 // test the minimal configuration necessary
468
469 # if !TARGET_CARBON
470 long theSystem ;
471 long theMachine;
472
473 if (Gestalt(gestaltMachineType, &theMachine) != noErr)
474 {
475 error = kMacSTRWrongMachine;
476 }
477 else if (theMachine < gestaltMacPlus)
478 {
479 error = kMacSTRWrongMachine;
480 }
481 else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
482 {
483 error = kMacSTROldSystem ;
484 }
485 else if ( theSystem < 0x0860 )
486 {
487 error = kMacSTROldSystem ;
488 }
489 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
490 {
491 error = kMacSTRSmallSize;
492 }
493 # endif
494 /*
495 else
496 {
497 if ( !UMAHasAppearance() )
498 {
499 error = kMacSTRNoPre8Yet ;
500 }
501 }
502 */
503 #endif
504
505 // if we encountered any problems so far, give the error code and exit immediately
506
507 if ( error )
508 {
509 wxStAppResource resload ;
510 short itemHit;
511 Str255 message;
512
513 GetIndString(message, 128, error);
514 UMAShowArrowCursor() ;
515 ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");
516 itemHit = Alert(128, nil);
517 return FALSE ;
518 }
519
520 #ifndef __DARWIN__
521 # if __option(profile)
522 ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ;
523 # endif
524 #endif
525
526 #ifndef __DARWIN__
527 // now avoid exceptions thrown for new (bad_alloc)
528 // FIXME CS for some changes outside wxMac does not compile anymore
529 #if 0
530 std::__throws_bad_alloc = 0 ;
531 #endif
532
533 #endif
534 wxMacSetupConverters() ;
535
536 s_macCursorRgn = ::NewRgn() ;
537
538 // Mac OS X passes a process serial number command line argument when
539 // the application is launched from the Finder. This argument must be
540 // removed from the command line arguments before being handled by the
541 // application (otherwise applications would need to handle it)
542 if ( argc > 1 )
543 {
544 static const wxChar *ARG_PSN = _T("-psn_");
545 if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 )
546 {
547 // remove this argument
548 memmove(argv, argv + 1, argc--);
549 }
550 }
551
552 if ( !wxAppBase::Initialize(argc, argv) )
553 return false;
554
555 wxWinMacWindowList = new wxList(wxKEY_INTEGER);
556 wxWinMacControlList = new wxList(wxKEY_INTEGER);
557
558 wxMacCreateNotifierTable() ;
559
560 UMAShowArrowCursor() ;
561
562 return true;
563 }
564
565 bool wxApp::OnInitGui()
566 {
567 if( !wxAppBase::OnInitGui() )
568 return false ;
569
570 #if TARGET_CARBON
571 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
572
573 InstallApplicationEventHandler(
574 GetwxAppEventHandlerUPP(),
575 GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler));
576 #endif
577
578 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
579 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
580 NewAEEventHandlerUPP(AEHandleODoc) ,
581 0 , FALSE ) ;
582 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
583 NewAEEventHandlerUPP(AEHandleOApp) ,
584 0 , FALSE ) ;
585 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
586 NewAEEventHandlerUPP(AEHandlePDoc) ,
587 0 , FALSE ) ;
588 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
589 NewAEEventHandlerUPP(AEHandleQuit) ,
590 0 , FALSE ) ;
591 #else
592 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
593 NewAEEventHandlerProc(AEHandleODoc) ,
594 0 , FALSE ) ;
595 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
596 NewAEEventHandlerProc(AEHandleOApp) ,
597 0 , FALSE ) ;
598 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
599 NewAEEventHandlerProc(AEHandlePDoc) ,
600 0 , FALSE ) ;
601 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
602 NewAEEventHandlerProc(AEHandleQuit) ,
603 0 , FALSE ) ;
604 #endif
605
606 return TRUE ;
607 }
608
609 void wxApp::CleanUp()
610 {
611 wxToolTip::RemoveToolTips() ;
612
613 // One last chance for pending objects to be cleaned up
614 wxTheApp->DeletePendingObjects();
615
616 wxMacDestroyNotifierTable() ;
617
618 delete wxWinMacWindowList ;
619 wxWinMacWindowList = NULL;
620
621 delete wxWinMacControlList ;
622 wxWinMacControlList = NULL;
623
624 #ifndef __DARWIN__
625 # if __option(profile)
626 ProfilerDump( (StringPtr)"\papp.prof" ) ;
627 ProfilerTerm() ;
628 # endif
629 #endif
630
631 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
632 // close shared library resources from here since we don't have
633 // __wxterminate in Mach-O shared libraries
634 wxStAppResource::CloseSharedLibraryResource();
635 #endif
636 wxMacCleanupConverters() ;
637
638 UMACleanupToolbox() ;
639 if (s_macCursorRgn) {
640 ::DisposeRgn((RgnHandle)s_macCursorRgn);
641 }
642
643 #if 0
644 TerminateAE() ;
645 #endif
646
647 wxAppBase::CleanUp();
648 }
649
650 //----------------------------------------------------------------------
651 // misc initialization stuff
652 //----------------------------------------------------------------------
653
654 // extern variable for shared library resource id
655 // need to be able to find it with NSLookupAndBindSymbol
656 short gSharedLibraryResource = kResFileNotOpened ;
657
658 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
659 CFBundleRef gSharedLibraryBundle = NULL;
660 #endif /* WXMAKINGDLL && __DARWIN__ */
661
662 wxStAppResource::wxStAppResource()
663 {
664 m_currentRefNum = CurResFile() ;
665 if ( gSharedLibraryResource != kResFileNotOpened )
666 {
667 UseResFile( gSharedLibraryResource ) ;
668 }
669 }
670
671 wxStAppResource::~wxStAppResource()
672 {
673 if ( m_currentRefNum != kResFileNotOpened )
674 {
675 UseResFile( m_currentRefNum ) ;
676 }
677 }
678
679 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
680 {
681 gSharedLibraryResource = kResFileNotOpened;
682
683 #ifdef WXMAKINGDLL
684 if ( initBlock != NULL ) {
685 const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
686 FSSpec *fileSpec = NULL;
687
688 if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
689 fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;
690 }
691 else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {
692 fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;
693 }
694
695 if (fileSpec != NULL) {
696 gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm);
697 }
698 }
699 else {
700 #ifdef __DARWIN__
701 // Open the shared library resource file if it is not yet open
702 NSSymbol theSymbol;
703 NSModule theModule;
704 const char *theLibPath;
705
706 gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
707 if (gSharedLibraryBundle != NULL) {
708 // wxWindows has been bundled into a framework
709 // load the framework resources
710
711 gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
712 }
713 else {
714 // wxWindows is a simple dynamic shared library
715 // load the resources from the data fork of a separate resource file
716 char *theResPath;
717 char *theName;
718 char *theExt;
719 FSRef theResRef;
720 OSErr theErr = noErr;
721
722 // get the library path
723 theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
724 theModule = NSModuleForSymbol(theSymbol);
725 theLibPath = NSLibraryNameForModule(theModule);
726
727 // if we call wxLogDebug from here then, as wxTheApp hasn't been
728 // created yet when we're called from wxApp::Initialize(), wxLog
729 // is going to create a default stderr-based log target instead of
730 // the expected normal GUI one -- don't do it, if we really want
731 // to see this message just use fprintf() here
732 #if 0
733 wxLogDebug( wxT("wxMac library installation name is '%s'"),
734 theLibPath );
735 #endif
736
737 // allocate copy to replace .dylib.* extension with .rsrc
738 theResPath = strdup(theLibPath);
739 if (theResPath != NULL) {
740 theName = strrchr(theResPath, '/');
741 if (theName == NULL) {
742 // no directory elements in path
743 theName = theResPath;
744 }
745 // find ".dylib" shared library extension
746 theExt = strstr(theName, ".dylib");
747 // overwrite extension with ".rsrc"
748 strcpy(theExt, ".rsrc");
749
750 #if 0
751 wxLogDebug( wxT("wxMac resources file name is '%s'"),
752 theResPath );
753 #endif
754
755 theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false);
756 if (theErr != noErr) {
757 // try in current directory (using name only)
758 theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false);
759 }
760
761 // open the resource file
762 if (theErr == noErr) {
763 theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
764 &gSharedLibraryResource);
765 }
766 if (theErr != noErr) {
767 #ifdef __WXDEBUG__
768 fprintf(stderr,
769 wxT("unable to open wxMac resource file '%s'\n"),
770 theResPath );
771 #endif // __WXDEBUG__
772 }
773
774 // free duplicated resource file path
775 free(theResPath);
776 }
777 }
778 #endif /* __DARWIN__ */
779 }
780 #endif /* WXMAKINGDLL */
781 }
782
783 void wxStAppResource::CloseSharedLibraryResource()
784 {
785 #ifdef WXMAKINGDLL
786 // Close the shared library resource file
787 if (gSharedLibraryResource != kResFileNotOpened) {
788 #ifdef __DARWIN__
789 if (gSharedLibraryBundle != NULL) {
790 CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
791 gSharedLibraryResource);
792 gSharedLibraryBundle = NULL;
793 }
794 else
795 #endif /* __DARWIN__ */
796 {
797 CloseResFile(gSharedLibraryResource);
798 }
799 gSharedLibraryResource = kResFileNotOpened;
800 }
801 #endif /* WXMAKINGDLL */
802 }
803
804 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
805
806 // for shared libraries we have to manually get the correct resource
807 // ref num upon initializing and releasing when terminating, therefore
808 // the __wxinitialize and __wxterminate must be used
809
810 extern "C" {
811 void __sinit(void); /* (generated by linker) */
812 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
813 pascal void __terminate(void);
814 }
815
816 pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
817 {
818 wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
819 return __initialize( theInitBlock ) ;
820 }
821
822 pascal void __wxterminate(void)
823 {
824 wxStAppResource::CloseSharedLibraryResource() ;
825 __terminate() ;
826 }
827
828 #endif /* WXMAKINGDLL && !__DARWIN__ */
829
830 #if TARGET_CARBON
831
832 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
833 {
834 bool converted = ConvertEventRefToEventRecord( event,rec) ;
835 OSStatus err = noErr ;
836 if ( !converted )
837 {
838 switch( GetEventClass( event ) )
839 {
840 case kEventClassKeyboard :
841 {
842 converted = true ;
843 switch( GetEventKind(event) )
844 {
845 case kEventRawKeyDown :
846 rec->what = keyDown ;
847 break ;
848 case kEventRawKeyRepeat :
849 rec->what = autoKey ;
850 break ;
851 case kEventRawKeyUp :
852 rec->what = keyUp ;
853 break ;
854 case kEventRawKeyModifiersChanged :
855 rec->what = nullEvent ;
856 break ;
857 default :
858 converted = false ;
859 break ;
860 }
861 if ( converted )
862 {
863 UInt32 keyCode ;
864 unsigned char charCode ;
865 UInt32 modifiers ;
866 GetMouse( &rec->where) ;
867
868 err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
869 err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
870 err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
871 rec->modifiers = modifiers ;
872 rec->message = (keyCode << 8 ) + charCode ;
873 }
874 }
875 break ;
876 case kEventClassTextInput :
877 {
878 switch( GetEventKind( event ) )
879 {
880 case kEventTextInputUnicodeForKeyEvent :
881 {
882 EventRef rawEvent ;
883 err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
884 converted = true ;
885 {
886 UInt32 keyCode ;
887 unsigned char charCode ;
888 UInt32 modifiers ;
889 GetMouse( &rec->where) ;
890 rec->what = keyDown ;
891 err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
892 err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
893 err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
894 rec->modifiers = modifiers ;
895 rec->message = (keyCode << 8 ) + charCode ;
896 }
897 }
898 break ;
899 default :
900 break ;
901 }
902 }
903 break ;
904 }
905 }
906
907 return converted ;
908 }
909
910 /*
911 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
912 {
913 OSStatus result = eventNotHandledErr ;
914
915 EventRecord rec ;
916 switch ( GetEventClass( event ) )
917 {
918 case kEventClassKeyboard :
919 if ( wxMacConvertEventToRecord( event , &rec ) )
920 {
921 wxTheApp->MacHandleModifierEvents( &rec ) ;
922 wxTheApp->MacHandleOneEvent( &rec ) ;
923 result = noErr ;
924 }
925 break ;
926 case kEventClassTextInput :
927 if ( wxMacConvertEventToRecord( event , &rec ) )
928 {
929 wxTheApp->MacHandleModifierEvents( &rec ) ;
930 wxTheApp->MacHandleOneEvent( &rec ) ;
931 result = noErr ;
932 }
933 break ;
934 default :
935 break ;
936 }
937 return result ;
938 }
939 */
940 #endif
941
942 wxApp::wxApp()
943 {
944 m_topWindow = NULL;
945 wxTheApp = this;
946
947 argc = 0;
948 argv = NULL;
949
950 m_printMode = wxPRINT_WINDOWS;
951 m_auto3D = TRUE;
952 }
953
954 bool wxApp::Initialized()
955 {
956 if (GetTopWindow())
957 return TRUE;
958 else
959 return FALSE;
960 }
961
962 int wxApp::MainLoop()
963 {
964 m_keepGoing = TRUE;
965
966 while (m_keepGoing)
967 {
968 MacDoOneEvent() ;
969 }
970
971 return 0;
972 }
973
974 // Returns TRUE if more time is needed.
975 bool wxApp::ProcessIdle()
976 {
977 wxIdleEvent event;
978 event.SetEventObject(this);
979 ProcessEvent(event);
980
981 wxUpdateUIEvent::ResetUpdateTime();
982
983 return event.MoreRequested();
984 }
985
986 void wxApp::ExitMainLoop()
987 {
988 m_keepGoing = FALSE;
989 }
990
991 // Is a message/event pending?
992 bool wxApp::Pending()
993 {
994 #if TARGET_CARBON
995 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
996 #else
997 EventRecord event ;
998
999 return EventAvail( everyEvent , &event ) ;
1000 #endif
1001 }
1002
1003 // Dispatch a message.
1004 void wxApp::Dispatch()
1005 {
1006 MacDoOneEvent() ;
1007 }
1008
1009 void wxApp::OnIdle(wxIdleEvent& event)
1010 {
1011 // Avoid recursion (via ProcessEvent default case)
1012 if ( s_inOnIdle )
1013 return;
1014
1015
1016 s_inOnIdle = TRUE;
1017
1018 // 'Garbage' collection of windows deleted with Close().
1019 DeletePendingObjects();
1020
1021 // flush the logged messages if any
1022 wxLog *pLog = wxLog::GetActiveTarget();
1023 if ( pLog != NULL && pLog->HasPendingMessages() )
1024 pLog->Flush();
1025
1026 // Send OnIdle events to all windows
1027 bool needMore = SendIdleEvents();
1028
1029 if (needMore)
1030 event.RequestMore(TRUE);
1031
1032 // If they are pending events, we must process them: pending events are
1033 // either events to the threads other than main or events posted with
1034 // wxPostEvent() functions
1035 wxMacProcessNotifierAndPendingEvents();
1036
1037 s_inOnIdle = FALSE;
1038 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1039 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1040 }
1041
1042 void wxApp::WakeUpIdle()
1043 {
1044 wxMacWakeUp() ;
1045 }
1046
1047 // Send idle event to all top-level windows
1048 bool wxApp::SendIdleEvents()
1049 {
1050 bool needMore = FALSE;
1051 wxWindowListNode* node = wxTopLevelWindows.GetFirst();
1052 while (node)
1053 {
1054 wxWindow* win = node->GetData();
1055 if (SendIdleEvents(win))
1056 needMore = TRUE;
1057
1058 node = node->GetNext();
1059 }
1060 return needMore;
1061 }
1062
1063 // Send idle event to window and all subwindows
1064 bool wxApp::SendIdleEvents(wxWindow* win)
1065 {
1066 bool needMore = FALSE;
1067
1068 wxIdleEvent event;
1069 event.SetEventObject(win);
1070 win->ProcessEvent(event);
1071
1072 if (event.MoreRequested())
1073 needMore = TRUE;
1074
1075 wxWindowListNode* node = win->GetChildren().GetFirst();
1076 while (node)
1077 {
1078 wxWindow* win = node->GetData();
1079 if (SendIdleEvents(win))
1080 needMore = TRUE;
1081
1082 node = node->GetNext();
1083 }
1084 return needMore ;
1085 }
1086
1087 void wxApp::Exit()
1088 {
1089 wxApp::CleanUp();
1090 ::ExitToShell() ;
1091 }
1092
1093 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1094 {
1095 if (GetTopWindow())
1096 GetTopWindow()->Close(TRUE);
1097 }
1098
1099 // Default behaviour: close the application with prompts. The
1100 // user can veto the close, and therefore the end session.
1101 void wxApp::OnQueryEndSession(wxCloseEvent& event)
1102 {
1103 if (GetTopWindow())
1104 {
1105 if (!GetTopWindow()->Close(!event.CanVeto()))
1106 event.Veto(TRUE);
1107 }
1108 }
1109
1110 extern "C" void wxCYield() ;
1111 void wxCYield()
1112 {
1113 wxYield() ;
1114 }
1115
1116 // Yield to other processes
1117
1118 bool wxApp::Yield(bool onlyIfNeeded)
1119 {
1120 if (s_inYield)
1121 {
1122 if ( !onlyIfNeeded )
1123 {
1124 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1125 }
1126
1127 return FALSE;
1128 }
1129
1130 s_inYield = TRUE;
1131
1132 #if wxUSE_THREADS
1133 YieldToAnyThread() ;
1134 #endif
1135 // by definition yield should handle all non-processed events
1136 #if TARGET_CARBON
1137 EventRef theEvent;
1138
1139 OSStatus status = noErr ;
1140 do
1141 {
1142 s_inReceiveEvent = true ;
1143 status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
1144 s_inReceiveEvent = false ;
1145
1146 if ( status == eventLoopTimedOutErr )
1147 {
1148 // make sure next time the event loop will trigger idle events
1149 sleepTime = kEventDurationNoWait ;
1150 }
1151 else if ( status == eventLoopQuitErr )
1152 {
1153 // according to QA1061 this may also occur when a WakeUp Process
1154 // is executed
1155 }
1156 else
1157 {
1158 MacHandleOneEvent( theEvent ) ;
1159 ReleaseEvent(theEvent);
1160 }
1161 } while( status == noErr ) ;
1162 #else
1163 EventRecord event ;
1164
1165 // having a larger value here leads to large performance slowdowns
1166 // so we cannot give background apps more processor time here
1167 // we do so however having a large sleep value in the main event loop
1168 sleepTime = 0 ;
1169
1170 while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
1171 {
1172 MacHandleModifierEvents( &event ) ;
1173 MacHandleOneEvent( &event );
1174 if ( event.what != kHighLevelEvent )
1175 SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
1176 }
1177 MacHandleModifierEvents( &event ) ;
1178 #endif
1179
1180 wxMacProcessNotifierAndPendingEvents() ;
1181 s_inYield = FALSE;
1182
1183 return TRUE;
1184 }
1185
1186 // platform specifics
1187
1188 void wxApp::MacSuspend( bool convertClipboard )
1189 {
1190 #if !TARGET_CARBON
1191 // we have to deactive the top level windows manually
1192
1193 wxWindowListNode* node = wxTopLevelWindows.GetFirst();
1194 while (node)
1195 {
1196 wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
1197 #if TARGET_CARBON
1198 #if 0 // having problems right now with that
1199 if (!win->HasFlag(wxSTAY_ON_TOP))
1200 #endif
1201 #endif
1202 win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
1203
1204 node = node->GetNext();
1205 }
1206
1207 ::HideFloatingWindows() ;
1208 #endif
1209 s_lastMouseDown = 0 ;
1210
1211 if( convertClipboard )
1212 {
1213 MacConvertPrivateToPublicScrap() ;
1214 }
1215 }
1216
1217 extern wxList wxModalDialogs;
1218
1219 void wxApp::MacResume( bool convertClipboard )
1220 {
1221 s_lastMouseDown = 0 ;
1222 if( convertClipboard )
1223 {
1224 MacConvertPublicToPrivateScrap() ;
1225 }
1226
1227 #if !TARGET_CARBON
1228 ::ShowFloatingWindows() ;
1229 // raise modal dialogs in case a non modal window was selected to activate the app
1230
1231 wxNode* node = wxModalDialogs.GetFirst();
1232 while (node)
1233 {
1234 wxDialog* dialog = (wxDialog *) node->GetData();
1235 dialog->Raise();
1236
1237 node = node->GetNext();
1238 }
1239 #endif
1240 }
1241
1242 void wxApp::MacConvertPrivateToPublicScrap()
1243 {
1244 }
1245
1246 void wxApp::MacConvertPublicToPrivateScrap()
1247 {
1248 }
1249
1250 void wxApp::MacDoOneEvent()
1251 {
1252 #if TARGET_CARBON
1253 EventRef theEvent;
1254
1255 s_inReceiveEvent = true ;
1256 OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
1257 s_inReceiveEvent = false ;
1258 if ( status == eventLoopTimedOutErr )
1259 {
1260 if ( wxTheApp->ProcessIdle() )
1261 sleepTime = kEventDurationNoWait ;
1262 else
1263 sleepTime = kEventDurationForever ;
1264 }
1265 else if ( status == eventLoopQuitErr )
1266 {
1267 // according to QA1061 this may also occur when a WakeUp Process
1268 // is executed
1269 }
1270 else
1271 {
1272 MacHandleOneEvent( theEvent ) ;
1273 ReleaseEvent(theEvent);
1274 sleepTime = kEventDurationNoWait ;
1275 }
1276 #else
1277 EventRecord event ;
1278
1279 EventMask eventMask = everyEvent ;
1280
1281 if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn))
1282 {
1283 MacHandleModifierEvents( &event ) ;
1284 MacHandleOneEvent( &event );
1285 }
1286 else
1287 {
1288 MacHandleModifierEvents( &event ) ;
1289 // idlers
1290 WindowPtr window = ::FrontWindow() ;
1291 if ( window )
1292 ::IdleControls( window ) ;
1293
1294 if ( wxTheApp->ProcessIdle() )
1295 sleepTime = 0 ;
1296 else
1297 sleepTime = GetCaretTime() / 2 ;
1298 }
1299 if ( event.what != kHighLevelEvent )
1300 SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
1301 #endif
1302 // repeaters
1303
1304 DeletePendingObjects() ;
1305 wxMacProcessNotifierAndPendingEvents() ;
1306 }
1307
1308 void wxApp::MacHandleOneEvent( WXEVENTREF evr )
1309 {
1310 #if TARGET_CARBON
1311 EventTargetRef theTarget;
1312 theTarget = GetEventDispatcherTarget();
1313 m_macCurrentEvent = evr ;
1314 SendEventToEventTarget ((EventRef) evr , theTarget);
1315 #else
1316 EventRecord* ev = (EventRecord*) evr ;
1317 m_macCurrentEvent = ev ;
1318
1319 wxApp::sm_lastMessageTime = ev->when ;
1320
1321 switch (ev->what)
1322 {
1323 case mouseDown:
1324 MacHandleMouseDownEvent( ev ) ;
1325 if ( ev->modifiers & controlKey )
1326 s_lastMouseDown = 2;
1327 else
1328 s_lastMouseDown = 1;
1329 break;
1330 case mouseUp:
1331 if ( s_lastMouseDown == 2 )
1332 {
1333 ev->modifiers |= controlKey ;
1334 }
1335 else
1336 {
1337 ev->modifiers &= ~controlKey ;
1338 }
1339 MacHandleMouseUpEvent( ev ) ;
1340 s_lastMouseDown = 0;
1341 break;
1342 case activateEvt:
1343 MacHandleActivateEvent( ev ) ;
1344 break;
1345 case updateEvt:
1346 MacHandleUpdateEvent( ev ) ;
1347 break;
1348 case keyDown:
1349 case autoKey:
1350 MacHandleKeyDownEvent( ev ) ;
1351 break;
1352 case keyUp:
1353 MacHandleKeyUpEvent( ev ) ;
1354 break;
1355 case diskEvt:
1356 MacHandleDiskEvent( ev ) ;
1357 break;
1358 case osEvt:
1359 MacHandleOSEvent( ev ) ;
1360 break;
1361 case kHighLevelEvent:
1362 MacHandleHighLevelEvent( ev ) ;
1363 break;
1364 default:
1365 break;
1366 }
1367 #endif
1368 wxMacProcessNotifierAndPendingEvents() ;
1369 }
1370
1371 #if !TARGET_CARBON
1372 bool s_macIsInModalLoop = false ;
1373
1374 void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
1375 {
1376 EventRecord* ev = (EventRecord*) evr ;
1377 if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL )
1378 {
1379 wxKeyEvent event(wxEVT_KEY_DOWN);
1380
1381 event.m_shiftDown = ev->modifiers & shiftKey;
1382 event.m_controlDown = ev->modifiers & controlKey;
1383 event.m_altDown = ev->modifiers & optionKey;
1384 event.m_metaDown = ev->modifiers & cmdKey;
1385
1386 event.m_x = ev->where.h;
1387 event.m_y = ev->where.v;
1388 event.m_timeStamp = ev->when;
1389 wxWindow* focus = wxWindow::FindFocus() ;
1390 event.SetEventObject(focus);
1391
1392 if ( (ev->modifiers ^ s_lastModifiers ) & controlKey )
1393 {
1394 event.m_keyCode = WXK_CONTROL ;
1395 event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1396 focus->GetEventHandler()->ProcessEvent( event ) ;
1397 }
1398 if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey )
1399 {
1400 event.m_keyCode = WXK_SHIFT ;
1401 event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1402 focus->GetEventHandler()->ProcessEvent( event ) ;
1403 }
1404 if ( (ev->modifiers ^ s_lastModifiers ) & optionKey )
1405 {
1406 event.m_keyCode = WXK_ALT ;
1407 event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1408 focus->GetEventHandler()->ProcessEvent( event ) ;
1409 }
1410 s_lastModifiers = ev->modifiers ;
1411 }
1412 }
1413
1414 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
1415 {
1416 // we must avoid reentrancy problems when processing high level events eg printing
1417 bool former = s_inYield ;
1418 s_inYield = TRUE ;
1419 EventRecord* ev = (EventRecord*) evr ;
1420 ::AEProcessAppleEvent( ev ) ;
1421 s_inYield = former ;
1422 }
1423
1424 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
1425 {
1426 EventRecord* ev = (EventRecord*) evr ;
1427 wxToolTip::RemoveToolTips() ;
1428
1429 WindowRef window;
1430 WindowRef frontWindow = ::FrontNonFloatingWindow() ;
1431 WindowAttributes frontWindowAttributes = NULL ;
1432 if ( frontWindow )
1433 ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
1434
1435 short windowPart = ::FindWindow(ev->where, &window);
1436 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1437 if ( wxPendingDelete.Member(win) )
1438 return ;
1439
1440 BitMap screenBits;
1441 GetQDGlobalsScreenBits( &screenBits );
1442
1443 switch (windowPart)
1444 {
1445 case inMenuBar :
1446 if ( s_macIsInModalLoop )
1447 {
1448 SysBeep ( 30 ) ;
1449 }
1450 else
1451 {
1452 UInt32 menuresult = MenuSelect(ev->where) ;
1453 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
1454 s_lastMouseDown = 0;
1455 }
1456 break ;
1457 case inSysWindow :
1458 SystemClick( ev , window ) ;
1459 s_lastMouseDown = 0;
1460 break ;
1461 case inDrag :
1462 if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
1463 {
1464 SysBeep ( 30 ) ;
1465 }
1466 else
1467 {
1468 DragWindow(window, ev->where, &screenBits.bounds);
1469 if (win)
1470 {
1471 GrafPtr port ;
1472 GetPort( &port ) ;
1473 Point pt = { 0, 0 } ;
1474 SetPortWindowPort(window) ;
1475 LocalToGlobal( &pt ) ;
1476 SetPort( port ) ;
1477 win->SetSize( pt.h , pt.v , -1 ,
1478 -1 , wxSIZE_USE_EXISTING);
1479 }
1480 s_lastMouseDown = 0;
1481 }
1482 break ;
1483 case inGoAway:
1484 if (TrackGoAway(window, ev->where))
1485 {
1486 if ( win )
1487 win->Close() ;
1488 }
1489 s_lastMouseDown = 0;
1490 break;
1491 case inGrow:
1492 {
1493 Rect newContentRect ;
1494 Rect constraintRect ;
1495 constraintRect.top = win->GetMinHeight() ;
1496 if ( constraintRect.top == -1 )
1497 constraintRect.top = 0 ;
1498 constraintRect.left = win->GetMinWidth() ;
1499 if ( constraintRect.left == -1 )
1500 constraintRect.left = 0 ;
1501 constraintRect.right = win->GetMaxWidth() ;
1502 if ( constraintRect.right == -1 )
1503 constraintRect.right = 32000 ;
1504 constraintRect.bottom = win->GetMaxHeight() ;
1505 if ( constraintRect.bottom == -1 )
1506 constraintRect.bottom = 32000 ;
1507
1508 Boolean growResult = ResizeWindow( window , ev->where ,
1509 &constraintRect , &newContentRect ) ;
1510 if ( growResult )
1511 {
1512 win->SetSize( newContentRect.left , newContentRect.top ,
1513 newContentRect.right - newContentRect.left ,
1514 newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
1515 }
1516 s_lastMouseDown = 0;
1517 }
1518 break;
1519 case inZoomIn:
1520 case inZoomOut:
1521 if (TrackBox(window, ev->where, windowPart))
1522 {
1523 // TODO setup size event
1524 ZoomWindow( window , windowPart , false ) ;
1525 if (win)
1526 {
1527 Rect tempRect ;
1528 GrafPtr port ;
1529 GetPort( &port ) ;
1530 Point pt = { 0, 0 } ;
1531 SetPortWindowPort(window) ;
1532 LocalToGlobal( &pt ) ;
1533 SetPort( port ) ;
1534
1535 GetWindowPortBounds(window, &tempRect ) ;
1536 win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left ,
1537 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
1538 }
1539 }
1540 s_lastMouseDown = 0;
1541 break;
1542 case inCollapseBox :
1543 // TODO setup size event
1544 s_lastMouseDown = 0;
1545 break ;
1546
1547 case inContent :
1548 {
1549 GrafPtr port ;
1550 GetPort( &port ) ;
1551 SetPortWindowPort(window) ;
1552 SetPort( port ) ;
1553 }
1554 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
1555 {
1556 if ( s_macIsInModalLoop )
1557 {
1558 SysBeep ( 30 ) ;
1559 }
1560 else if ( UMAIsWindowFloating( window ) )
1561 {
1562 if ( win )
1563 win->MacMouseDown( ev , windowPart ) ;
1564 }
1565 else
1566 {
1567 if ( win )
1568 win->MacMouseDown( ev , windowPart ) ;
1569 ::SelectWindow( window ) ;
1570 }
1571 }
1572 else
1573 {
1574 if ( win )
1575 win->MacMouseDown( ev , windowPart ) ;
1576 }
1577 break ;
1578 default:
1579 break;
1580 }
1581 }
1582
1583 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
1584 {
1585 EventRecord* ev = (EventRecord*) evr ;
1586 WindowRef window;
1587
1588 short windowPart = inNoWindow ;
1589 if ( wxTheApp->s_captureWindow )
1590 {
1591 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
1592 windowPart = inContent ;
1593 }
1594 else
1595 {
1596 windowPart = ::FindWindow(ev->where, &window) ;
1597 }
1598
1599 switch (windowPart)
1600 {
1601 case inMenuBar :
1602 break ;
1603 case inSysWindow :
1604 break ;
1605 default:
1606 {
1607 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1608 if ( win )
1609 win->MacMouseUp( ev , windowPart ) ;
1610 }
1611 break;
1612 }
1613 }
1614
1615 #endif
1616
1617 long wxMacTranslateKey(unsigned char key, unsigned char code) ;
1618 long wxMacTranslateKey(unsigned char key, unsigned char code)
1619 {
1620 long retval = key ;
1621 switch (key)
1622 {
1623 case kHomeCharCode :
1624 retval = WXK_HOME;
1625 break;
1626 case kEnterCharCode :
1627 retval = WXK_RETURN;
1628 break;
1629 case kEndCharCode :
1630 retval = WXK_END;
1631 break;
1632 case kHelpCharCode :
1633 retval = WXK_HELP;
1634 break;
1635 case kBackspaceCharCode :
1636 retval = WXK_BACK;
1637 break;
1638 case kTabCharCode :
1639 retval = WXK_TAB;
1640 break;
1641 case kPageUpCharCode :
1642 retval = WXK_PAGEUP;
1643 break;
1644 case kPageDownCharCode :
1645 retval = WXK_PAGEDOWN;
1646 break;
1647 case kReturnCharCode :
1648 retval = WXK_RETURN;
1649 break;
1650 case kFunctionKeyCharCode :
1651 {
1652 switch( code )
1653 {
1654 case 0x7a :
1655 retval = WXK_F1 ;
1656 break;
1657 case 0x78 :
1658 retval = WXK_F2 ;
1659 break;
1660 case 0x63 :
1661 retval = WXK_F3 ;
1662 break;
1663 case 0x76 :
1664 retval = WXK_F4 ;
1665 break;
1666 case 0x60 :
1667 retval = WXK_F5 ;
1668 break;
1669 case 0x61 :
1670 retval = WXK_F6 ;
1671 break;
1672 case 0x62:
1673 retval = WXK_F7 ;
1674 break;
1675 case 0x64 :
1676 retval = WXK_F8 ;
1677 break;
1678 case 0x65 :
1679 retval = WXK_F9 ;
1680 break;
1681 case 0x6D :
1682 retval = WXK_F10 ;
1683 break;
1684 case 0x67 :
1685 retval = WXK_F11 ;
1686 break;
1687 case 0x6F :
1688 retval = WXK_F12 ;
1689 break;
1690 case 0x69 :
1691 retval = WXK_F13 ;
1692 break;
1693 case 0x6B :
1694 retval = WXK_F14 ;
1695 break;
1696 case 0x71 :
1697 retval = WXK_F15 ;
1698 break;
1699 }
1700 }
1701 break ;
1702 case kEscapeCharCode :
1703 retval = WXK_ESCAPE ;
1704 break ;
1705 case kLeftArrowCharCode :
1706 retval = WXK_LEFT ;
1707 break ;
1708 case kRightArrowCharCode :
1709 retval = WXK_RIGHT ;
1710 break ;
1711 case kUpArrowCharCode :
1712 retval = WXK_UP ;
1713 break ;
1714 case kDownArrowCharCode :
1715 retval = WXK_DOWN ;
1716 break ;
1717 case kDeleteCharCode :
1718 retval = WXK_DELETE ;
1719 default:
1720 break ;
1721 } // end switch
1722
1723 return retval;
1724 }
1725
1726 #if !TARGET_CARBON
1727 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
1728 {
1729 EventRecord* ev = (EventRecord*) evr ;
1730 wxToolTip::RemoveToolTips() ;
1731
1732 UInt32 menuresult = UMAMenuEvent(ev) ;
1733 if ( HiWord( menuresult ) )
1734 {
1735 if ( !s_macIsInModalLoop )
1736 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
1737 }
1738 else
1739 {
1740 wxWindow* focus = wxWindow::FindFocus() ;
1741
1742 if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )
1743 {
1744 // has not been handled -> perform default
1745 wxControl* control = wxDynamicCast( focus , wxControl ) ;
1746 if ( control && control->GetMacControl() != NULL )
1747 {
1748 short keycode ;
1749 short keychar ;
1750 keychar = short(ev->message & charCodeMask);
1751 keycode = short(ev->message & keyCodeMask) >> 8 ;
1752 ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;
1753 }
1754 }
1755 }
1756 }
1757
1758 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
1759 {
1760 EventRecord* ev = (EventRecord*) evr ;
1761 wxToolTip::RemoveToolTips() ;
1762
1763 UInt32 menuresult = UMAMenuEvent(ev) ;
1764 if ( HiWord( menuresult ) )
1765 {
1766 }
1767 else
1768 {
1769 MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
1770 }
1771 }
1772
1773 #endif
1774
1775 bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1776 {
1777 if ( !focus )
1778 return false ;
1779
1780 short keycode ;
1781 short keychar ;
1782 keychar = short(keymessage & charCodeMask);
1783 keycode = short(keymessage & keyCodeMask) >> 8 ;
1784
1785 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1786 {
1787 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1788 // and look at the character after
1789 UInt32 state = 0;
1790 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1791 keychar = short(keyInfo & charCodeMask);
1792 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1793 }
1794 long keyval = wxMacTranslateKey(keychar, keycode) ;
1795 long realkeyval = keyval ;
1796 if ( keyval == keychar )
1797 {
1798 // 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)
1799 realkeyval = short(keymessage & charCodeMask) ;
1800 keyval = wxToupper( keyval ) ;
1801 }
1802
1803 wxKeyEvent event(wxEVT_KEY_DOWN);
1804 bool handled = false ;
1805 event.m_shiftDown = modifiers & shiftKey;
1806 event.m_controlDown = modifiers & controlKey;
1807 event.m_altDown = modifiers & optionKey;
1808 event.m_metaDown = modifiers & cmdKey;
1809 event.m_keyCode = keyval ;
1810
1811 event.m_x = wherex;
1812 event.m_y = wherey;
1813 event.m_timeStamp = when;
1814 event.SetEventObject(focus);
1815 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1816 if ( handled && event.GetSkipped() )
1817 handled = false ;
1818 if ( !handled )
1819 {
1820 #if wxUSE_ACCEL
1821 if (!handled)
1822 {
1823 wxWindow *ancestor = focus;
1824 while (ancestor)
1825 {
1826 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1827 if (command != -1)
1828 {
1829 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1830 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1831 break;
1832 }
1833 if (ancestor->IsTopLevel())
1834 break;
1835 ancestor = ancestor->GetParent();
1836 }
1837 }
1838 #endif // wxUSE_ACCEL
1839 }
1840 if (!handled)
1841 {
1842 event.Skip( FALSE ) ;
1843 event.SetEventType( wxEVT_CHAR ) ;
1844 // raw value again
1845 event.m_keyCode = realkeyval ;
1846
1847 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1848 if ( handled && event.GetSkipped() )
1849 handled = false ;
1850 }
1851 if ( !handled &&
1852 (keyval == WXK_TAB) &&
1853 // CS: copied the change below from wxGTK
1854 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1855 // have this style, yet choose not to process this particular TAB in which
1856 // case TAB must still work as a navigational character
1857 #if 0
1858 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
1859 #endif
1860 (focus->GetParent()) &&
1861 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1862 {
1863 wxNavigationKeyEvent new_event;
1864 new_event.SetEventObject( focus );
1865 new_event.SetDirection( !event.ShiftDown() );
1866 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1867 new_event.SetWindowChange( event.ControlDown() );
1868 new_event.SetCurrentFocus( focus );
1869 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1870 if ( handled && new_event.GetSkipped() )
1871 handled = false ;
1872 }
1873 // backdoor handler for default return and command escape
1874 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
1875 {
1876 // if window is not having a focus still testing for default enter or cancel
1877 // TODO add the UMA version for ActiveNonFloatingWindow
1878 wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1879 if ( focus )
1880 {
1881 if ( keyval == WXK_RETURN )
1882 {
1883 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
1884 wxButton);
1885 if ( def && def->IsEnabled() )
1886 {
1887 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1888 event.SetEventObject(def);
1889 def->Command(event);
1890 return true ;
1891 }
1892 }
1893 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1894 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
1895 {
1896 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1897 new_event.SetEventObject( focus );
1898 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1899 }
1900 }
1901 }
1902 return handled ;
1903 }
1904
1905 bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1906 {
1907 if ( !focus )
1908 return false ;
1909
1910 short keycode ;
1911 short keychar ;
1912 keychar = short(keymessage & charCodeMask);
1913 keycode = short(keymessage & keyCodeMask) >> 8 ;
1914 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1915 {
1916 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1917 // and look at the character after
1918 UInt32 state = 0;
1919 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1920 keychar = short(keyInfo & charCodeMask);
1921 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1922 }
1923 long keyval = wxMacTranslateKey(keychar, keycode) ;
1924
1925 if ( keyval == keychar )
1926 {
1927 keyval = wxToupper( keyval ) ;
1928 }
1929 bool handled = false ;
1930
1931 wxKeyEvent event(wxEVT_KEY_UP);
1932 event.m_shiftDown = modifiers & shiftKey;
1933 event.m_controlDown = modifiers & controlKey;
1934 event.m_altDown = modifiers & optionKey;
1935 event.m_metaDown = modifiers & cmdKey;
1936 event.m_keyCode = keyval ;
1937
1938 event.m_x = wherex;
1939 event.m_y = wherey;
1940 event.m_timeStamp = when;
1941 event.SetEventObject(focus);
1942 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1943
1944 return handled ;
1945 }
1946
1947 #if !TARGET_CARBON
1948 void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
1949 {
1950 EventRecord* ev = (EventRecord*) evr ;
1951 WindowRef window = (WindowRef) ev->message ;
1952 if ( window )
1953 {
1954 bool activate = (ev->modifiers & activeFlag ) ;
1955 WindowClass wclass ;
1956 ::GetWindowClass ( window , &wclass ) ;
1957 if ( wclass == kFloatingWindowClass )
1958 {
1959 // if it is a floater we activate/deactivate the front non-floating window instead
1960 window = ::FrontNonFloatingWindow() ;
1961 }
1962 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1963 if ( win )
1964 win->MacActivate( ev->when , activate ) ;
1965 }
1966 }
1967
1968 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
1969 {
1970 EventRecord* ev = (EventRecord*) evr ;
1971 WindowRef window = (WindowRef) ev->message ;
1972 wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
1973 if ( win )
1974 {
1975 if ( !wxPendingDelete.Member(win) )
1976 win->MacUpdate( ev->when ) ;
1977 }
1978 else
1979 {
1980 // since there is no way of telling this foreign window to update itself
1981 // we have to invalidate the update region otherwise we keep getting the same
1982 // event over and over again
1983 BeginUpdate( window ) ;
1984 EndUpdate( window ) ;
1985 }
1986 }
1987
1988 void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
1989 {
1990 EventRecord* ev = (EventRecord*) evr ;
1991 if ( HiWord( ev->message ) != noErr )
1992 {
1993 OSErr err ;
1994 Point point ;
1995 SetPt( &point , 100 , 100 ) ;
1996
1997 err = DIBadMount( point , ev->message ) ;
1998 wxASSERT( err == noErr ) ;
1999 }
2000 }
2001
2002 void wxApp::MacHandleOSEvent( WXEVENTREF evr )
2003 {
2004 EventRecord* ev = (EventRecord*) evr ;
2005 switch( ( ev->message & osEvtMessageMask ) >> 24 )
2006 {
2007 case suspendResumeMessage :
2008 {
2009 bool isResuming = ev->message & resumeFlag ;
2010 bool convertClipboard = ev->message & convertClipboardFlag ;
2011
2012 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
2013 if ( isResuming )
2014 {
2015 WindowRef oldFrontWindow = NULL ;
2016 WindowRef newFrontWindow = NULL ;
2017
2018 // in case we don't take care of activating ourselves, we have to synchronize
2019 // our idea of the active window with the process manager's - which it already activated
2020
2021 if ( !doesActivate )
2022 oldFrontWindow = ::FrontNonFloatingWindow() ;
2023
2024 MacResume( convertClipboard ) ;
2025
2026 newFrontWindow = ::FrontNonFloatingWindow() ;
2027
2028 if ( oldFrontWindow )
2029 {
2030 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
2031 if ( win )
2032 win->MacActivate( ev->when , false ) ;
2033 }
2034 if ( newFrontWindow )
2035 {
2036 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ;
2037 if ( win )
2038 win->MacActivate( ev->when , true ) ;
2039 }
2040 }
2041 else
2042 {
2043 MacSuspend( convertClipboard ) ;
2044 }
2045 }
2046 break ;
2047 case mouseMovedMessage :
2048 {
2049 WindowRef window;
2050
2051 wxWindow* currentMouseWindow = NULL ;
2052
2053 if (s_captureWindow )
2054 {
2055 currentMouseWindow = s_captureWindow ;
2056 }
2057 else
2058 {
2059 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
2060 &currentMouseWindow ) ;
2061 }
2062
2063 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
2064 {
2065 wxMouseEvent event ;
2066
2067 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
2068 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
2069
2070 event.m_leftDown = isDown && !controlDown;
2071 event.m_middleDown = FALSE;
2072 event.m_rightDown = isDown && controlDown;
2073 event.m_shiftDown = ev->modifiers & shiftKey;
2074 event.m_controlDown = ev->modifiers & controlKey;
2075 event.m_altDown = ev->modifiers & optionKey;
2076 event.m_metaDown = ev->modifiers & cmdKey;
2077 event.m_x = ev->where.h;
2078 event.m_y = ev->where.v;
2079 event.m_timeStamp = ev->when;
2080 event.SetEventObject(this);
2081
2082 if ( wxWindow::s_lastMouseWindow )
2083 {
2084 wxMouseEvent eventleave(event);
2085 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
2086 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
2087 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
2088
2089 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
2090 }
2091 if ( currentMouseWindow )
2092 {
2093 wxMouseEvent evententer(event);
2094 evententer.SetEventType( wxEVT_ENTER_WINDOW );
2095 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
2096 evententer.SetEventObject( currentMouseWindow ) ;
2097 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
2098 }
2099 wxWindow::s_lastMouseWindow = currentMouseWindow ;
2100 }
2101
2102 short windowPart = inNoWindow ;
2103
2104 if ( s_captureWindow )
2105 {
2106 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
2107 windowPart = inContent ;
2108 }
2109 else
2110 {
2111 windowPart = ::FindWindow(ev->where, &window);
2112 }
2113
2114 switch (windowPart)
2115 {
2116 case inContent :
2117 {
2118 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
2119 if ( win )
2120 win->MacMouseMoved( ev , windowPart ) ;
2121 else
2122 {
2123 if ( wxIsBusy() )
2124 {
2125 }
2126 else
2127 UMAShowArrowCursor();
2128 }
2129 }
2130 break;
2131 default :
2132 {
2133 if ( wxIsBusy() )
2134 {
2135 }
2136 else
2137 UMAShowArrowCursor();
2138 }
2139 break ;
2140 }
2141 }
2142 break ;
2143
2144 }
2145 }
2146 #endif
2147
2148 void wxApp::MacHandleMenuCommand( wxUint32 id )
2149 {
2150 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
2151 wxFrame* frame = mbar->GetFrame();
2152 wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") );
2153 if ( frame )
2154 {
2155 frame->ProcessCommand(id);
2156 }
2157 }
2158
2159 #if !TARGET_CARBON
2160 void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
2161 {
2162 if (macMenuId == 0)
2163 return; // no menu item selected
2164
2165 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
2166 {
2167 #if ! TARGET_CARBON
2168 Str255 deskAccessoryName ;
2169 GrafPtr savedPort ;
2170
2171 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
2172 GetPort(&savedPort);
2173 OpenDeskAcc(deskAccessoryName);
2174 SetPort(savedPort);
2175 #endif
2176 }
2177 else
2178 {
2179 MenuCommand id ;
2180 GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ;
2181 MacHandleMenuCommand( id ) ;
2182 }
2183 HiliteMenu(0);
2184 }
2185 #endif