]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/app.cpp
WXMAKINGDLL --> WXMAKINGDLL_CORE and also fixed name of resources file
[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_CORE)
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_CORE) && !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_CORE) && 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_CORE) && 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_CORE) && defined(__DARWIN__)
687 CFBundleRef gSharedLibraryBundle = NULL;
688 #endif /* WXMAKINGDLL_CORE && __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_CORE
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 wxString theResPath;
745 wxString theName;
746 FSRef theResRef;
747 OSErr theErr = noErr;
748
749 // get the library path
750 theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
751 theModule = NSModuleForSymbol(theSymbol);
752 theLibPath = NSLibraryNameForModule(theModule);
753
754 // if we call wxLogDebug from here then, as wxTheApp hasn't been
755 // created yet when we're called from wxApp::Initialize(), wxLog
756 // is going to create a default stderr-based log target instead of
757 // the expected normal GUI one -- don't do it, if we really want
758 // to see this message just use fprintf() here
759 #if 0
760 wxLogDebug( wxT("wxMac library installation name is '%s'"),
761 theLibPath );
762 #endif
763
764 // allocate copy to replace .dylib.* extension with .rsrc
765 if (theLibPath != NULL) {
766 theResPath = theLibPath;
767 // replace '_core' with '' in case of multi-lib build
768 theResPath.Replace(wxT("_core"), wxEmptyString);
769 // replace ".dylib" shared library extension with ".rsrc"
770 theResPath.Replace(wxT(".dylib"), wxT(".rsrc"));
771 // Find the begining of the filename
772 theName = theResPath.AfterLast('/');
773
774 #if 0
775 wxLogDebug( wxT("wxMac resources file name is '%s'"),
776 theResPath.mb_str() );
777 #endif
778
779 theErr = FSPathMakeRef((UInt8 *) theResPath.mb_str(), &theResRef, false);
780 if (theErr != noErr) {
781 // try in current directory (using name only)
782 theErr = FSPathMakeRef((UInt8 *) theName.mb_str(), &theResRef, false);
783 }
784
785 // open the resource file
786 if (theErr == noErr) {
787 theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
788 &gSharedLibraryResource);
789 }
790 if (theErr != noErr) {
791 #ifdef __WXDEBUG__
792 fprintf(stderr,
793 wxT("unable to open wxMac resource file '%s'\n"),
794 theResPath.mb_str() );
795 #endif // __WXDEBUG__
796 }
797
798 }
799 }
800 #endif /* __DARWIN__ */
801 }
802 #endif /* WXMAKINGDLL_CORE */
803 }
804
805 void wxStAppResource::CloseSharedLibraryResource()
806 {
807 #ifdef WXMAKINGDLL_CORE
808 // Close the shared library resource file
809 if (gSharedLibraryResource != kResFileNotOpened) {
810 #ifdef __DARWIN__
811 if (gSharedLibraryBundle != NULL) {
812 CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
813 gSharedLibraryResource);
814 gSharedLibraryBundle = NULL;
815 }
816 else
817 #endif /* __DARWIN__ */
818 {
819 CloseResFile(gSharedLibraryResource);
820 }
821 gSharedLibraryResource = kResFileNotOpened;
822 }
823 #endif /* WXMAKINGDLL_CORE */
824 }
825
826 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
827
828 // for shared libraries we have to manually get the correct resource
829 // ref num upon initializing and releasing when terminating, therefore
830 // the __wxinitialize and __wxterminate must be used
831
832 extern "C" {
833 void __sinit(void); /* (generated by linker) */
834 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
835 pascal void __terminate(void);
836 }
837
838 pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
839 {
840 wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
841 return __initialize( theInitBlock ) ;
842 }
843
844 pascal void __wxterminate(void)
845 {
846 wxStAppResource::CloseSharedLibraryResource() ;
847 __terminate() ;
848 }
849
850 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
851
852 #if TARGET_CARBON
853
854 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
855 {
856 bool converted = ConvertEventRefToEventRecord( event,rec) ;
857 OSStatus err = noErr ;
858 if ( !converted )
859 {
860 switch( GetEventClass( event ) )
861 {
862 case kEventClassKeyboard :
863 {
864 converted = true ;
865 switch( GetEventKind(event) )
866 {
867 case kEventRawKeyDown :
868 rec->what = keyDown ;
869 break ;
870 case kEventRawKeyRepeat :
871 rec->what = autoKey ;
872 break ;
873 case kEventRawKeyUp :
874 rec->what = keyUp ;
875 break ;
876 case kEventRawKeyModifiersChanged :
877 rec->what = nullEvent ;
878 break ;
879 default :
880 converted = false ;
881 break ;
882 }
883 if ( converted )
884 {
885 UInt32 keyCode ;
886 unsigned char charCode ;
887 UInt32 modifiers ;
888 GetMouse( &rec->where) ;
889
890 err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
891 err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
892 err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
893 rec->modifiers = modifiers ;
894 rec->message = (keyCode << 8 ) + charCode ;
895 }
896 }
897 break ;
898 case kEventClassTextInput :
899 {
900 switch( GetEventKind( event ) )
901 {
902 case kEventTextInputUnicodeForKeyEvent :
903 {
904 EventRef rawEvent ;
905 err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
906 converted = true ;
907 {
908 UInt32 keyCode ;
909 unsigned char charCode ;
910 UInt32 modifiers ;
911 GetMouse( &rec->where) ;
912 rec->what = keyDown ;
913 err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
914 err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
915 err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
916 rec->modifiers = modifiers ;
917 rec->message = (keyCode << 8 ) + charCode ;
918 }
919 }
920 break ;
921 default :
922 break ;
923 }
924 }
925 break ;
926 }
927 }
928
929 return converted ;
930 }
931
932 /*
933 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
934 {
935 OSStatus result = eventNotHandledErr ;
936
937 EventRecord rec ;
938 switch ( GetEventClass( event ) )
939 {
940 case kEventClassKeyboard :
941 if ( wxMacConvertEventToRecord( event , &rec ) )
942 {
943 wxTheApp->MacHandleModifierEvents( &rec ) ;
944 wxTheApp->MacHandleOneEvent( &rec ) ;
945 result = noErr ;
946 }
947 break ;
948 case kEventClassTextInput :
949 if ( wxMacConvertEventToRecord( event , &rec ) )
950 {
951 wxTheApp->MacHandleModifierEvents( &rec ) ;
952 wxTheApp->MacHandleOneEvent( &rec ) ;
953 result = noErr ;
954 }
955 break ;
956 default :
957 break ;
958 }
959 return result ;
960 }
961 */
962 #endif
963
964 wxApp::wxApp()
965 {
966 m_printMode = wxPRINT_WINDOWS;
967 m_auto3D = TRUE;
968
969 m_macCurrentEvent = NULL ;
970 m_macCurrentEventHandlerCallRef = NULL ;
971 }
972
973 bool wxApp::Initialized()
974 {
975 if (GetTopWindow())
976 return TRUE;
977 else
978 return FALSE;
979 }
980
981 int wxApp::MainLoop()
982 {
983 m_keepGoing = TRUE;
984
985 while (m_keepGoing)
986 {
987 MacDoOneEvent() ;
988 }
989
990 return 0;
991 }
992
993 void wxApp::ExitMainLoop()
994 {
995 m_keepGoing = FALSE;
996 }
997
998 // Is a message/event pending?
999 bool wxApp::Pending()
1000 {
1001 #if TARGET_CARBON
1002 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1003 #else
1004 EventRecord event ;
1005
1006 return EventAvail( everyEvent , &event ) ;
1007 #endif
1008 }
1009
1010 // Dispatch a message.
1011 void wxApp::Dispatch()
1012 {
1013 MacDoOneEvent() ;
1014 }
1015
1016 void wxApp::OnIdle(wxIdleEvent& event)
1017 {
1018 wxAppBase::OnIdle(event);
1019
1020 // If they are pending events, we must process them: pending events are
1021 // either events to the threads other than main or events posted with
1022 // wxPostEvent() functions
1023 wxMacProcessNotifierAndPendingEvents();
1024
1025 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1026 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1027 }
1028
1029 void wxApp::WakeUpIdle()
1030 {
1031 wxMacWakeUp() ;
1032 }
1033
1034 void wxApp::Exit()
1035 {
1036 wxApp::CleanUp();
1037 ::ExitToShell() ;
1038 }
1039
1040 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1041 {
1042 if (GetTopWindow())
1043 GetTopWindow()->Close(TRUE);
1044 }
1045
1046 // Default behaviour: close the application with prompts. The
1047 // user can veto the close, and therefore the end session.
1048 void wxApp::OnQueryEndSession(wxCloseEvent& event)
1049 {
1050 if (GetTopWindow())
1051 {
1052 if (!GetTopWindow()->Close(!event.CanVeto()))
1053 event.Veto(TRUE);
1054 }
1055 }
1056
1057 extern "C" void wxCYield() ;
1058 void wxCYield()
1059 {
1060 wxYield() ;
1061 }
1062
1063 // Yield to other processes
1064
1065 bool wxApp::Yield(bool onlyIfNeeded)
1066 {
1067 if (s_inYield)
1068 {
1069 if ( !onlyIfNeeded )
1070 {
1071 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1072 }
1073
1074 return FALSE;
1075 }
1076
1077 s_inYield = TRUE;
1078
1079 #if wxUSE_THREADS
1080 YieldToAnyThread() ;
1081 #endif
1082 // by definition yield should handle all non-processed events
1083 #if TARGET_CARBON
1084 EventRef theEvent;
1085
1086 OSStatus status = noErr ;
1087 do
1088 {
1089 s_inReceiveEvent = true ;
1090 status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
1091 s_inReceiveEvent = false ;
1092
1093 if ( status == eventLoopTimedOutErr )
1094 {
1095 // make sure next time the event loop will trigger idle events
1096 sleepTime = kEventDurationNoWait ;
1097 }
1098 else if ( status == eventLoopQuitErr )
1099 {
1100 // according to QA1061 this may also occur when a WakeUp Process
1101 // is executed
1102 }
1103 else
1104 {
1105 MacHandleOneEvent( theEvent ) ;
1106 ReleaseEvent(theEvent);
1107 }
1108 } while( status == noErr ) ;
1109 #else
1110 EventRecord event ;
1111
1112 // having a larger value here leads to large performance slowdowns
1113 // so we cannot give background apps more processor time here
1114 // we do so however having a large sleep value in the main event loop
1115 sleepTime = 0 ;
1116
1117 while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
1118 {
1119 MacHandleModifierEvents( &event ) ;
1120 MacHandleOneEvent( &event );
1121 if ( event.what != kHighLevelEvent )
1122 SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
1123 }
1124 MacHandleModifierEvents( &event ) ;
1125 #endif
1126
1127 wxMacProcessNotifierAndPendingEvents() ;
1128 s_inYield = FALSE;
1129
1130 return TRUE;
1131 }
1132
1133 // platform specifics
1134
1135 void wxApp::MacSuspend( bool convertClipboard )
1136 {
1137 #if !TARGET_CARBON
1138 // we have to deactive the top level windows manually
1139
1140 wxWindowListNode* node = wxTopLevelWindows.GetFirst();
1141 while (node)
1142 {
1143 wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
1144 #if TARGET_CARBON
1145 #if 0 // having problems right now with that
1146 if (!win->HasFlag(wxSTAY_ON_TOP))
1147 #endif
1148 #endif
1149 win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
1150
1151 node = node->GetNext();
1152 }
1153
1154 ::HideFloatingWindows() ;
1155 #endif
1156 s_lastMouseDown = 0 ;
1157
1158 if( convertClipboard )
1159 {
1160 MacConvertPrivateToPublicScrap() ;
1161 }
1162 }
1163
1164 extern wxList wxModalDialogs;
1165
1166 void wxApp::MacResume( bool convertClipboard )
1167 {
1168 s_lastMouseDown = 0 ;
1169 if( convertClipboard )
1170 {
1171 MacConvertPublicToPrivateScrap() ;
1172 }
1173
1174 #if !TARGET_CARBON
1175 ::ShowFloatingWindows() ;
1176 // raise modal dialogs in case a non modal window was selected to activate the app
1177
1178 wxNode* node = wxModalDialogs.GetFirst();
1179 while (node)
1180 {
1181 wxDialog* dialog = (wxDialog *) node->GetData();
1182 dialog->Raise();
1183
1184 node = node->GetNext();
1185 }
1186 #endif
1187 }
1188
1189 void wxApp::MacConvertPrivateToPublicScrap()
1190 {
1191 }
1192
1193 void wxApp::MacConvertPublicToPrivateScrap()
1194 {
1195 }
1196
1197 void wxApp::MacDoOneEvent()
1198 {
1199 #if TARGET_CARBON
1200 EventRef theEvent;
1201
1202 s_inReceiveEvent = true ;
1203 OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
1204 s_inReceiveEvent = false ;
1205 if ( status == eventLoopTimedOutErr )
1206 {
1207 if ( wxTheApp->ProcessIdle() )
1208 sleepTime = kEventDurationNoWait ;
1209 else
1210 sleepTime = kEventDurationForever ;
1211 }
1212 else if ( status == eventLoopQuitErr )
1213 {
1214 // according to QA1061 this may also occur when a WakeUp Process
1215 // is executed
1216 }
1217 else
1218 {
1219 MacHandleOneEvent( theEvent ) ;
1220 ReleaseEvent(theEvent);
1221 sleepTime = kEventDurationNoWait ;
1222 }
1223 #else
1224 EventRecord event ;
1225
1226 EventMask eventMask = everyEvent ;
1227
1228 if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn))
1229 {
1230 MacHandleModifierEvents( &event ) ;
1231 MacHandleOneEvent( &event );
1232 }
1233 else
1234 {
1235 MacHandleModifierEvents( &event ) ;
1236 // idlers
1237 WindowPtr window = ::FrontWindow() ;
1238 if ( window )
1239 ::IdleControls( window ) ;
1240
1241 if ( wxTheApp->ProcessIdle() )
1242 sleepTime = 0 ;
1243 else
1244 sleepTime = GetCaretTime() / 2 ;
1245 }
1246 if ( event.what != kHighLevelEvent )
1247 SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
1248 #endif
1249 // repeaters
1250
1251 DeletePendingObjects() ;
1252 wxMacProcessNotifierAndPendingEvents() ;
1253 }
1254
1255 void wxApp::MacHandleOneEvent( WXEVENTREF evr )
1256 {
1257 #if TARGET_CARBON
1258 EventTargetRef theTarget;
1259 theTarget = GetEventDispatcherTarget();
1260 m_macCurrentEvent = evr ;
1261 SendEventToEventTarget ((EventRef) evr , theTarget);
1262 #else
1263 EventRecord* ev = (EventRecord*) evr ;
1264 m_macCurrentEvent = ev ;
1265
1266 wxApp::sm_lastMessageTime = ev->when ;
1267
1268 switch (ev->what)
1269 {
1270 case mouseDown:
1271 MacHandleMouseDownEvent( ev ) ;
1272 if ( ev->modifiers & controlKey )
1273 s_lastMouseDown = 2;
1274 else
1275 s_lastMouseDown = 1;
1276 break;
1277 case mouseUp:
1278 if ( s_lastMouseDown == 2 )
1279 {
1280 ev->modifiers |= controlKey ;
1281 }
1282 else
1283 {
1284 ev->modifiers &= ~controlKey ;
1285 }
1286 MacHandleMouseUpEvent( ev ) ;
1287 s_lastMouseDown = 0;
1288 break;
1289 case activateEvt:
1290 MacHandleActivateEvent( ev ) ;
1291 break;
1292 case updateEvt:
1293 MacHandleUpdateEvent( ev ) ;
1294 break;
1295 case keyDown:
1296 case autoKey:
1297 MacHandleKeyDownEvent( ev ) ;
1298 break;
1299 case keyUp:
1300 MacHandleKeyUpEvent( ev ) ;
1301 break;
1302 case diskEvt:
1303 MacHandleDiskEvent( ev ) ;
1304 break;
1305 case osEvt:
1306 MacHandleOSEvent( ev ) ;
1307 break;
1308 case kHighLevelEvent:
1309 MacHandleHighLevelEvent( ev ) ;
1310 break;
1311 default:
1312 break;
1313 }
1314 #endif
1315 wxMacProcessNotifierAndPendingEvents() ;
1316 }
1317
1318 #if !TARGET_CARBON
1319 bool s_macIsInModalLoop = false ;
1320
1321 void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
1322 {
1323 EventRecord* ev = (EventRecord*) evr ;
1324 if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL )
1325 {
1326 wxKeyEvent event(wxEVT_KEY_DOWN);
1327
1328 event.m_shiftDown = ev->modifiers & shiftKey;
1329 event.m_controlDown = ev->modifiers & controlKey;
1330 event.m_altDown = ev->modifiers & optionKey;
1331 event.m_metaDown = ev->modifiers & cmdKey;
1332
1333 event.m_x = ev->where.h;
1334 event.m_y = ev->where.v;
1335 event.m_timeStamp = ev->when;
1336 wxWindow* focus = wxWindow::FindFocus() ;
1337 event.SetEventObject(focus);
1338
1339 if ( (ev->modifiers ^ s_lastModifiers ) & controlKey )
1340 {
1341 event.m_keyCode = WXK_CONTROL ;
1342 event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1343 focus->GetEventHandler()->ProcessEvent( event ) ;
1344 }
1345 if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey )
1346 {
1347 event.m_keyCode = WXK_SHIFT ;
1348 event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1349 focus->GetEventHandler()->ProcessEvent( event ) ;
1350 }
1351 if ( (ev->modifiers ^ s_lastModifiers ) & optionKey )
1352 {
1353 event.m_keyCode = WXK_ALT ;
1354 event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1355 focus->GetEventHandler()->ProcessEvent( event ) ;
1356 }
1357 if ( ev->modifiers ^ s_lastModifiers ) & cmdKey )
1358 {
1359 event.m_keyCode = WXK_COMMAND ;
1360 event.SetEventType( ( ev->modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1361 focus->GetEventHandler()->ProcessEvent( event ) ;
1362 }
1363 s_lastModifiers = ev->modifiers ;
1364 }
1365 }
1366
1367 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
1368 {
1369 // we must avoid reentrancy problems when processing high level events eg printing
1370 bool former = s_inYield ;
1371 s_inYield = TRUE ;
1372 EventRecord* ev = (EventRecord*) evr ;
1373 ::AEProcessAppleEvent( ev ) ;
1374 s_inYield = former ;
1375 }
1376
1377 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
1378 {
1379 EventRecord* ev = (EventRecord*) evr ;
1380 wxToolTip::RemoveToolTips() ;
1381
1382 WindowRef window;
1383 WindowRef frontWindow = ::FrontNonFloatingWindow() ;
1384 WindowAttributes frontWindowAttributes = NULL ;
1385 if ( frontWindow )
1386 ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
1387
1388 short windowPart = ::FindWindow(ev->where, &window);
1389 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1390 if ( wxPendingDelete.Member(win) )
1391 return ;
1392
1393 BitMap screenBits;
1394 GetQDGlobalsScreenBits( &screenBits );
1395
1396 switch (windowPart)
1397 {
1398 case inMenuBar :
1399 if ( s_macIsInModalLoop )
1400 {
1401 SysBeep ( 30 ) ;
1402 }
1403 else
1404 {
1405 UInt32 menuresult = MenuSelect(ev->where) ;
1406 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
1407 s_lastMouseDown = 0;
1408 }
1409 break ;
1410 case inSysWindow :
1411 SystemClick( ev , window ) ;
1412 s_lastMouseDown = 0;
1413 break ;
1414 case inDrag :
1415 if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
1416 {
1417 SysBeep ( 30 ) ;
1418 }
1419 else
1420 {
1421 DragWindow(window, ev->where, &screenBits.bounds);
1422 if (win)
1423 {
1424 GrafPtr port ;
1425 GetPort( &port ) ;
1426 Point pt = { 0, 0 } ;
1427 SetPortWindowPort(window) ;
1428 LocalToGlobal( &pt ) ;
1429 SetPort( port ) ;
1430 win->SetSize( pt.h , pt.v , -1 ,
1431 -1 , wxSIZE_USE_EXISTING);
1432 }
1433 s_lastMouseDown = 0;
1434 }
1435 break ;
1436 case inGoAway:
1437 if (TrackGoAway(window, ev->where))
1438 {
1439 if ( win )
1440 win->Close() ;
1441 }
1442 s_lastMouseDown = 0;
1443 break;
1444 case inGrow:
1445 {
1446 Rect newContentRect ;
1447 Rect constraintRect ;
1448 constraintRect.top = win->GetMinHeight() ;
1449 if ( constraintRect.top == -1 )
1450 constraintRect.top = 0 ;
1451 constraintRect.left = win->GetMinWidth() ;
1452 if ( constraintRect.left == -1 )
1453 constraintRect.left = 0 ;
1454 constraintRect.right = win->GetMaxWidth() ;
1455 if ( constraintRect.right == -1 )
1456 constraintRect.right = 32000 ;
1457 constraintRect.bottom = win->GetMaxHeight() ;
1458 if ( constraintRect.bottom == -1 )
1459 constraintRect.bottom = 32000 ;
1460
1461 Boolean growResult = ResizeWindow( window , ev->where ,
1462 &constraintRect , &newContentRect ) ;
1463 if ( growResult )
1464 {
1465 win->SetSize( newContentRect.left , newContentRect.top ,
1466 newContentRect.right - newContentRect.left ,
1467 newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
1468 }
1469 s_lastMouseDown = 0;
1470 }
1471 break;
1472 case inZoomIn:
1473 case inZoomOut:
1474 if (TrackBox(window, ev->where, windowPart))
1475 {
1476 // TODO setup size event
1477 ZoomWindow( window , windowPart , false ) ;
1478 if (win)
1479 {
1480 Rect tempRect ;
1481 GrafPtr port ;
1482 GetPort( &port ) ;
1483 Point pt = { 0, 0 } ;
1484 SetPortWindowPort(window) ;
1485 LocalToGlobal( &pt ) ;
1486 SetPort( port ) ;
1487
1488 GetWindowPortBounds(window, &tempRect ) ;
1489 win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left ,
1490 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
1491 }
1492 }
1493 s_lastMouseDown = 0;
1494 break;
1495 case inCollapseBox :
1496 // TODO setup size event
1497 s_lastMouseDown = 0;
1498 break ;
1499
1500 case inContent :
1501 {
1502 GrafPtr port ;
1503 GetPort( &port ) ;
1504 SetPortWindowPort(window) ;
1505 SetPort( port ) ;
1506 }
1507 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
1508 {
1509 if ( s_macIsInModalLoop )
1510 {
1511 SysBeep ( 30 ) ;
1512 }
1513 else if ( UMAIsWindowFloating( window ) )
1514 {
1515 if ( win )
1516 win->MacMouseDown( ev , windowPart ) ;
1517 }
1518 else
1519 {
1520 if ( win )
1521 win->MacMouseDown( ev , windowPart ) ;
1522 ::SelectWindow( window ) ;
1523 }
1524 }
1525 else
1526 {
1527 if ( win )
1528 win->MacMouseDown( ev , windowPart ) ;
1529 }
1530 break ;
1531 default:
1532 break;
1533 }
1534 }
1535
1536 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
1537 {
1538 EventRecord* ev = (EventRecord*) evr ;
1539 WindowRef window;
1540
1541 short windowPart = inNoWindow ;
1542 if ( wxTheApp->s_captureWindow )
1543 {
1544 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
1545 windowPart = inContent ;
1546 }
1547 else
1548 {
1549 windowPart = ::FindWindow(ev->where, &window) ;
1550 }
1551
1552 switch (windowPart)
1553 {
1554 case inMenuBar :
1555 break ;
1556 case inSysWindow :
1557 break ;
1558 default:
1559 {
1560 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1561 if ( win )
1562 win->MacMouseUp( ev , windowPart ) ;
1563 }
1564 break;
1565 }
1566 }
1567
1568 #endif
1569
1570 long wxMacTranslateKey(unsigned char key, unsigned char code) ;
1571 long wxMacTranslateKey(unsigned char key, unsigned char code)
1572 {
1573 long retval = key ;
1574 switch (key)
1575 {
1576 case kHomeCharCode :
1577 retval = WXK_HOME;
1578 break;
1579 case kEnterCharCode :
1580 retval = WXK_RETURN;
1581 break;
1582 case kEndCharCode :
1583 retval = WXK_END;
1584 break;
1585 case kHelpCharCode :
1586 retval = WXK_HELP;
1587 break;
1588 case kBackspaceCharCode :
1589 retval = WXK_BACK;
1590 break;
1591 case kTabCharCode :
1592 retval = WXK_TAB;
1593 break;
1594 case kPageUpCharCode :
1595 retval = WXK_PAGEUP;
1596 break;
1597 case kPageDownCharCode :
1598 retval = WXK_PAGEDOWN;
1599 break;
1600 case kReturnCharCode :
1601 retval = WXK_RETURN;
1602 break;
1603 case kFunctionKeyCharCode :
1604 {
1605 switch( code )
1606 {
1607 case 0x7a :
1608 retval = WXK_F1 ;
1609 break;
1610 case 0x78 :
1611 retval = WXK_F2 ;
1612 break;
1613 case 0x63 :
1614 retval = WXK_F3 ;
1615 break;
1616 case 0x76 :
1617 retval = WXK_F4 ;
1618 break;
1619 case 0x60 :
1620 retval = WXK_F5 ;
1621 break;
1622 case 0x61 :
1623 retval = WXK_F6 ;
1624 break;
1625 case 0x62:
1626 retval = WXK_F7 ;
1627 break;
1628 case 0x64 :
1629 retval = WXK_F8 ;
1630 break;
1631 case 0x65 :
1632 retval = WXK_F9 ;
1633 break;
1634 case 0x6D :
1635 retval = WXK_F10 ;
1636 break;
1637 case 0x67 :
1638 retval = WXK_F11 ;
1639 break;
1640 case 0x6F :
1641 retval = WXK_F12 ;
1642 break;
1643 case 0x69 :
1644 retval = WXK_F13 ;
1645 break;
1646 case 0x6B :
1647 retval = WXK_F14 ;
1648 break;
1649 case 0x71 :
1650 retval = WXK_F15 ;
1651 break;
1652 }
1653 }
1654 break ;
1655 case kEscapeCharCode :
1656 retval = WXK_ESCAPE ;
1657 break ;
1658 case kLeftArrowCharCode :
1659 retval = WXK_LEFT ;
1660 break ;
1661 case kRightArrowCharCode :
1662 retval = WXK_RIGHT ;
1663 break ;
1664 case kUpArrowCharCode :
1665 retval = WXK_UP ;
1666 break ;
1667 case kDownArrowCharCode :
1668 retval = WXK_DOWN ;
1669 break ;
1670 case kDeleteCharCode :
1671 retval = WXK_DELETE ;
1672 default:
1673 break ;
1674 } // end switch
1675
1676 return retval;
1677 }
1678
1679 #if !TARGET_CARBON
1680 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
1681 {
1682 EventRecord* ev = (EventRecord*) evr ;
1683 wxToolTip::RemoveToolTips() ;
1684
1685 UInt32 menuresult = UMAMenuEvent(ev) ;
1686 if ( HiWord( menuresult ) )
1687 {
1688 if ( !s_macIsInModalLoop )
1689 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
1690 }
1691 else
1692 {
1693 wxWindow* focus = wxWindow::FindFocus() ;
1694
1695 if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )
1696 {
1697 #if 0
1698 // we must handle control keys the other way round, otherwise text content is updated too late
1699 // has not been handled -> perform default
1700 wxControl* control = wxDynamicCast( focus , wxControl ) ;
1701 if ( control && control->GetMacControl() != NULL )
1702 {
1703 short keycode ;
1704 short keychar ;
1705 keychar = short(ev->message & charCodeMask);
1706 keycode = short(ev->message & keyCodeMask) >> 8 ;
1707 ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;
1708 }
1709 #endif
1710 }
1711 }
1712 }
1713
1714 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
1715 {
1716 EventRecord* ev = (EventRecord*) evr ;
1717 wxToolTip::RemoveToolTips() ;
1718
1719 UInt32 menuresult = UMAMenuEvent(ev) ;
1720 if ( HiWord( menuresult ) )
1721 {
1722 }
1723 else
1724 {
1725 MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
1726 }
1727 }
1728
1729 #endif
1730
1731 bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1732 {
1733 if ( !focus )
1734 return false ;
1735
1736 short keycode ;
1737 short keychar ;
1738 keychar = short(keymessage & charCodeMask);
1739 keycode = short(keymessage & keyCodeMask) >> 8 ;
1740
1741 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1742 {
1743 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1744 // and look at the character after
1745 UInt32 state = 0;
1746 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1747 keychar = short(keyInfo & charCodeMask);
1748 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1749 }
1750 long keyval = wxMacTranslateKey(keychar, keycode) ;
1751 long realkeyval = keyval ;
1752 if ( keyval == keychar )
1753 {
1754 // 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)
1755 realkeyval = short(keymessage & charCodeMask) ;
1756 keyval = wxToupper( keyval ) ;
1757 }
1758
1759 wxKeyEvent event(wxEVT_KEY_DOWN);
1760 bool handled = false ;
1761 event.m_shiftDown = modifiers & shiftKey;
1762 event.m_controlDown = modifiers & controlKey;
1763 event.m_altDown = modifiers & optionKey;
1764 event.m_metaDown = modifiers & cmdKey;
1765 event.m_keyCode = keyval ;
1766
1767 event.m_x = wherex;
1768 event.m_y = wherey;
1769 event.m_timeStamp = when;
1770 event.SetEventObject(focus);
1771 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1772 if ( handled && event.GetSkipped() )
1773 handled = false ;
1774 if ( !handled )
1775 {
1776 #if wxUSE_ACCEL
1777 if (!handled)
1778 {
1779 wxWindow *ancestor = focus;
1780 while (ancestor)
1781 {
1782 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1783 if (command != -1)
1784 {
1785 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1786 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1787 break;
1788 }
1789 if (ancestor->IsTopLevel())
1790 break;
1791 ancestor = ancestor->GetParent();
1792 }
1793 }
1794 #endif // wxUSE_ACCEL
1795 }
1796 if (!handled)
1797 {
1798 event.Skip( FALSE ) ;
1799 event.SetEventType( wxEVT_CHAR ) ;
1800 // raw value again
1801 event.m_keyCode = realkeyval ;
1802
1803 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1804 if ( handled && event.GetSkipped() )
1805 handled = false ;
1806 }
1807 if ( !handled &&
1808 (keyval == WXK_TAB) &&
1809 // CS: copied the change below from wxGTK
1810 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1811 // have this style, yet choose not to process this particular TAB in which
1812 // case TAB must still work as a navigational character
1813 #if 0
1814 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
1815 #endif
1816 (focus->GetParent()) &&
1817 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1818 {
1819 wxNavigationKeyEvent new_event;
1820 new_event.SetEventObject( focus );
1821 new_event.SetDirection( !event.ShiftDown() );
1822 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1823 new_event.SetWindowChange( event.ControlDown() );
1824 new_event.SetCurrentFocus( focus );
1825 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1826 if ( handled && new_event.GetSkipped() )
1827 handled = false ;
1828 }
1829 // backdoor handler for default return and command escape
1830 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
1831 {
1832 // if window is not having a focus still testing for default enter or cancel
1833 // TODO add the UMA version for ActiveNonFloatingWindow
1834 wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1835 if ( focus )
1836 {
1837 if ( keyval == WXK_RETURN )
1838 {
1839 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
1840 wxButton);
1841 if ( def && def->IsEnabled() )
1842 {
1843 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1844 event.SetEventObject(def);
1845 def->Command(event);
1846 return true ;
1847 }
1848 }
1849 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1850 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
1851 {
1852 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1853 new_event.SetEventObject( focus );
1854 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1855 }
1856 }
1857 }
1858 return handled ;
1859 }
1860
1861 bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1862 {
1863 if ( !focus )
1864 return false ;
1865
1866 short keycode ;
1867 short keychar ;
1868 keychar = short(keymessage & charCodeMask);
1869 keycode = short(keymessage & keyCodeMask) >> 8 ;
1870 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1871 {
1872 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1873 // and look at the character after
1874 UInt32 state = 0;
1875 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1876 keychar = short(keyInfo & charCodeMask);
1877 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1878 }
1879 long keyval = wxMacTranslateKey(keychar, keycode) ;
1880
1881 if ( keyval == keychar )
1882 {
1883 keyval = wxToupper( keyval ) ;
1884 }
1885 bool handled = false ;
1886
1887 wxKeyEvent event(wxEVT_KEY_UP);
1888 event.m_shiftDown = modifiers & shiftKey;
1889 event.m_controlDown = modifiers & controlKey;
1890 event.m_altDown = modifiers & optionKey;
1891 event.m_metaDown = modifiers & cmdKey;
1892 event.m_keyCode = keyval ;
1893
1894 event.m_x = wherex;
1895 event.m_y = wherey;
1896 event.m_timeStamp = when;
1897 event.SetEventObject(focus);
1898 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1899
1900 return handled ;
1901 }
1902
1903 #if !TARGET_CARBON
1904 void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
1905 {
1906 EventRecord* ev = (EventRecord*) evr ;
1907 WindowRef window = (WindowRef) ev->message ;
1908 if ( window )
1909 {
1910 bool activate = (ev->modifiers & activeFlag ) ;
1911 WindowClass wclass ;
1912 ::GetWindowClass ( window , &wclass ) ;
1913 if ( wclass == kFloatingWindowClass )
1914 {
1915 // if it is a floater we activate/deactivate the front non-floating window instead
1916 window = ::FrontNonFloatingWindow() ;
1917 }
1918 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1919 if ( win )
1920 win->MacActivate( ev->when , activate ) ;
1921 }
1922 }
1923
1924 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
1925 {
1926 EventRecord* ev = (EventRecord*) evr ;
1927 WindowRef window = (WindowRef) ev->message ;
1928 wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
1929 if ( win )
1930 {
1931 if ( !wxPendingDelete.Member(win) )
1932 win->MacUpdate( ev->when ) ;
1933 }
1934 else
1935 {
1936 // since there is no way of telling this foreign window to update itself
1937 // we have to invalidate the update region otherwise we keep getting the same
1938 // event over and over again
1939 BeginUpdate( window ) ;
1940 EndUpdate( window ) ;
1941 }
1942 }
1943
1944 void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
1945 {
1946 EventRecord* ev = (EventRecord*) evr ;
1947 if ( HiWord( ev->message ) != noErr )
1948 {
1949 OSErr err ;
1950 Point point ;
1951 SetPt( &point , 100 , 100 ) ;
1952
1953 err = DIBadMount( point , ev->message ) ;
1954 wxASSERT( err == noErr ) ;
1955 }
1956 }
1957
1958 void wxApp::MacHandleOSEvent( WXEVENTREF evr )
1959 {
1960 EventRecord* ev = (EventRecord*) evr ;
1961 switch( ( ev->message & osEvtMessageMask ) >> 24 )
1962 {
1963 case suspendResumeMessage :
1964 {
1965 bool isResuming = ev->message & resumeFlag ;
1966 bool convertClipboard = ev->message & convertClipboardFlag ;
1967
1968 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
1969 if ( isResuming )
1970 {
1971 WindowRef oldFrontWindow = NULL ;
1972 WindowRef newFrontWindow = NULL ;
1973
1974 // in case we don't take care of activating ourselves, we have to synchronize
1975 // our idea of the active window with the process manager's - which it already activated
1976
1977 if ( !doesActivate )
1978 oldFrontWindow = ::FrontNonFloatingWindow() ;
1979
1980 MacResume( convertClipboard ) ;
1981
1982 newFrontWindow = ::FrontNonFloatingWindow() ;
1983
1984 if ( oldFrontWindow )
1985 {
1986 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
1987 if ( win )
1988 win->MacActivate( ev->when , false ) ;
1989 }
1990 if ( newFrontWindow )
1991 {
1992 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ;
1993 if ( win )
1994 win->MacActivate( ev->when , true ) ;
1995 }
1996 }
1997 else
1998 {
1999 MacSuspend( convertClipboard ) ;
2000 }
2001 }
2002 break ;
2003 case mouseMovedMessage :
2004 {
2005 WindowRef window;
2006
2007 wxWindow* currentMouseWindow = NULL ;
2008
2009 if (s_captureWindow )
2010 {
2011 currentMouseWindow = s_captureWindow ;
2012 }
2013 else
2014 {
2015 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
2016 &currentMouseWindow ) ;
2017 }
2018
2019 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
2020 {
2021 wxMouseEvent event ;
2022
2023 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
2024 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
2025
2026 event.m_leftDown = isDown && !controlDown;
2027 event.m_middleDown = FALSE;
2028 event.m_rightDown = isDown && controlDown;
2029 event.m_shiftDown = ev->modifiers & shiftKey;
2030 event.m_controlDown = ev->modifiers & controlKey;
2031 event.m_altDown = ev->modifiers & optionKey;
2032 event.m_metaDown = ev->modifiers & cmdKey;
2033 event.m_x = ev->where.h;
2034 event.m_y = ev->where.v;
2035 event.m_timeStamp = ev->when;
2036 event.SetEventObject(this);
2037
2038 if ( wxWindow::s_lastMouseWindow )
2039 {
2040 wxMouseEvent eventleave(event);
2041 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
2042 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
2043 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
2044
2045 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
2046 }
2047 if ( currentMouseWindow )
2048 {
2049 wxMouseEvent evententer(event);
2050 evententer.SetEventType( wxEVT_ENTER_WINDOW );
2051 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
2052 evententer.SetEventObject( currentMouseWindow ) ;
2053 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
2054 }
2055 wxWindow::s_lastMouseWindow = currentMouseWindow ;
2056 }
2057
2058 short windowPart = inNoWindow ;
2059
2060 if ( s_captureWindow )
2061 {
2062 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
2063 windowPart = inContent ;
2064 }
2065 else
2066 {
2067 windowPart = ::FindWindow(ev->where, &window);
2068 }
2069
2070 switch (windowPart)
2071 {
2072 case inContent :
2073 {
2074 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
2075 if ( win )
2076 win->MacMouseMoved( ev , windowPart ) ;
2077 else
2078 {
2079 if ( wxIsBusy() )
2080 {
2081 }
2082 else
2083 UMAShowArrowCursor();
2084 }
2085 }
2086 break;
2087 default :
2088 {
2089 if ( wxIsBusy() )
2090 {
2091 }
2092 else
2093 UMAShowArrowCursor();
2094 }
2095 break ;
2096 }
2097 }
2098 break ;
2099
2100 }
2101 }
2102 #endif
2103
2104 void wxApp::MacHandleMenuCommand( wxUint32 id )
2105 {
2106 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
2107 wxFrame* frame = mbar->GetFrame();
2108 wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") );
2109 if ( frame )
2110 {
2111 frame->ProcessCommand(id);
2112 }
2113 }
2114
2115 #if !TARGET_CARBON
2116 void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
2117 {
2118 if (macMenuId == 0)
2119 return; // no menu item selected
2120
2121 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
2122 {
2123 #if ! TARGET_CARBON
2124 Str255 deskAccessoryName ;
2125 GrafPtr savedPort ;
2126
2127 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
2128 GetPort(&savedPort);
2129 OpenDeskAcc(deskAccessoryName);
2130 SetPort(savedPort);
2131 #endif
2132 }
2133 else
2134 {
2135 MenuCommand id ;
2136 GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ;
2137 MacHandleMenuCommand( id ) ;
2138 }
2139 HiliteMenu(0);
2140 }
2141 #endif