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