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