]> git.saurik.com Git - wxWidgets.git/blame - src/mac/app.cpp
cosmetic fixes to font encoding names
[wxWidgets.git] / src / mac / app.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "app.h"
14#endif
15
16#include "wx/frame.h"
17#include "wx/app.h"
18#include "wx/utils.h"
19#include "wx/gdicmn.h"
20#include "wx/pen.h"
21#include "wx/brush.h"
22#include "wx/cursor.h"
23#include "wx/icon.h"
24#include "wx/palette.h"
25#include "wx/dc.h"
26#include "wx/dialog.h"
27#include "wx/msgdlg.h"
28#include "wx/log.h"
29#include "wx/module.h"
30#include "wx/memory.h"
2f1ae414 31#include "wx/tooltip.h"
e9576ca5
SC
32#if wxUSE_WX_RESOURCES
33#include "wx/resource.h"
34#endif
35
36#include <string.h>
37
8be97d65
SC
38// mac
39
519cb848
SC
40#if __option(profile)
41 #include <profiler.h>
9779893b 42#endif
519cb848 43
8be97d65
SC
44#include "apprsrc.h"
45
519cb848 46#include <wx/mac/uma.h>
2f1ae414
SC
47#include <wx/mac/macnotfy.h>
48
49#if wxUSE_SOCKETS
50#include <OpenTransport.h>
51#include <OpenTptInternet.h>
52#endif
519cb848 53
e9576ca5
SC
54extern char *wxBuffer;
55extern wxList wxPendingDelete;
519cb848
SC
56extern wxList *wxWinMacWindowList;
57extern wxList *wxWinMacControlList;
e9576ca5 58
6418cb93 59wxApp *wxTheApp = NULL;
e9576ca5 60
2f1ae414 61#if !USE_SHARED_LIBRARY
e9576ca5
SC
62IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
63BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
64 EVT_IDLE(wxApp::OnIdle)
2f1ae414
SC
65 EVT_END_SESSION(wxApp::OnEndSession)
66 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
e9576ca5 67END_EVENT_TABLE()
2f1ae414 68#endif
e9576ca5 69
169935ad 70
8be97d65
SC
71const short kMacMinHeap = (29 * 1024) ;
72// platform specific static variables
169935ad 73
519cb848
SC
74const short kwxMacMenuBarResource = 1 ;
75const short kwxMacAppleMenuId = 1 ;
76
77RgnHandle wxApp::s_macCursorRgn = NULL;
78wxWindow* wxApp::s_captureWindow = NULL ;
79int wxApp::s_lastMouseDown = 0 ;
80long wxApp::sm_lastMessageTime = 0;
81
82#ifdef __WXMAC__
83
84bool wxApp::s_macDefaultEncodingIsPC = true ;
85bool wxApp::s_macSupportPCMenuShortcuts = true ;
86long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
87wxString wxApp::s_macHelpMenuTitleName = "&Help" ;
88
2f1ae414 89pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
519cb848
SC
90{
91 wxApp* app = (wxApp*) refcon ;
92 return wxTheApp->MacHandleAEODoc( event , reply) ;
93}
94
2f1ae414 95pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
519cb848
SC
96{
97 wxApp* app = (wxApp*) refcon ;
98 return wxTheApp->MacHandleAEOApp( event , reply ) ;
99}
100
2f1ae414 101pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
519cb848
SC
102{
103 wxApp* app = (wxApp*) refcon ;
104 return wxTheApp->MacHandleAEPDoc( event , reply ) ;
105}
106
2f1ae414 107pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon )
519cb848
SC
108{
109 wxApp* app = (wxApp*) refcon ;
110 return wxTheApp->MacHandleAEQuit( event , reply) ;
111}
112
9779893b 113OSErr wxApp::MacHandleAEODoc(AppleEvent *event , AppleEvent *reply)
519cb848
SC
114{
115 ProcessSerialNumber PSN ;
116 PSN.highLongOfPSN = 0 ;
117 PSN.lowLongOfPSN = kCurrentProcess ;
118 SetFrontProcess( &PSN ) ;
119 return noErr ;
120}
121
9779893b 122OSErr wxApp::MacHandleAEPDoc(AppleEvent *event , AppleEvent *reply)
519cb848
SC
123{
124 return noErr ;
125}
126
9779893b 127OSErr wxApp::MacHandleAEOApp(AppleEvent *event , AppleEvent *reply)
519cb848
SC
128{
129 return noErr ;
130}
131
9779893b 132OSErr wxApp::MacHandleAEQuit(AppleEvent *event , AppleEvent *reply)
519cb848
SC
133{
134 wxWindow* win = GetTopWindow() ;
135 if ( win )
136 {
137 win->Close(TRUE ) ;
138 }
139 else
140 {
141 ExitMainLoop() ;
142 }
143 return noErr ;
144}
145
2f1ae414 146char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
519cb848
SC
147 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
148 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
149 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
150 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
151 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
152
2f1ae414 153char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
519cb848
SC
154 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
155 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
156 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
157 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
158 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
159
160void wxMacConvertFromPC( const char *from , char *to , int len )
161{
162 char *c ;
163 if ( from == to )
164 {
165 for( int i = 0 ; i < len ; ++ i )
166 {
167 c = strchr( StringANSI , *from ) ;
168 if ( c != NULL )
169 {
170 *to = StringMac[ c - StringANSI] ;
9779893b 171 }
519cb848
SC
172 ++to ;
173 ++from ;
174 }
175 }
176 else
177 {
178 for( int i = 0 ; i < len ; ++ i )
179 {
180 c = strchr( StringANSI , *from ) ;
181 if ( c != NULL )
182 {
183 *to = StringMac[ c - StringANSI] ;
9779893b 184 }
519cb848
SC
185 else
186 {
187 *to = *from ;
188 }
189 ++to ;
190 ++from ;
191 }
192 }
193}
194
195void wxMacConvertToPC( const char *from , char *to , int len )
196{
197 char *c ;
198 if ( from == to )
199 {
200 for( int i = 0 ; i < len ; ++ i )
201 {
202 c = strchr( StringMac , *from ) ;
203 if ( c != NULL )
204 {
205 *to = StringANSI[ c - StringMac] ;
9779893b 206 }
519cb848
SC
207 ++to ;
208 ++from ;
209 }
210 }
211 else
212 {
213 for( int i = 0 ; i < len ; ++ i )
214 {
215 c = strchr( StringMac , *from ) ;
216 if ( c != NULL )
217 {
218 *to = StringANSI[ c - StringMac] ;
9779893b 219 }
519cb848
SC
220 else
221 {
222 *to = *from ;
223 }
224 ++to ;
225 ++from ;
226 }
227 }
228}
229
9779893b 230void wxMacConvertFromPC( char * p )
519cb848
SC
231{
232 char *ptr = p ;
233 int len = strlen ( p ) ;
9779893b 234
519cb848
SC
235 wxMacConvertFromPC( ptr , ptr , len ) ;
236}
237
9779893b 238void wxMacConvertFromPCForControls( char * p )
519cb848
SC
239{
240 char *ptr = p ;
241 int len = strlen ( p ) ;
9779893b 242
519cb848
SC
243 wxMacConvertFromPC( ptr , ptr , len ) ;
244 for ( int i = 0 ; i < strlen ( ptr ) ; i++ )
245 {
246 if ( ptr[i] == '&' && ptr[i]+1 != ' ' )
247 {
248 memmove( &ptr[i] , &ptr[i+1] , strlen( &ptr[i+1] ) + 1) ;
249 }
250 }
251}
252
9779893b 253void wxMacConvertFromPC( unsigned char *p )
519cb848
SC
254{
255 char *ptr = (char*) p + 1 ;
256 int len = p[0] ;
9779893b 257
519cb848
SC
258 wxMacConvertFromPC( ptr , ptr , len ) ;
259}
260
261extern char *wxBuffer ;
262
9779893b 263wxString wxMacMakeMacStringFromPC( const char * p )
519cb848
SC
264{
265 const char *ptr = p ;
266 int len = strlen ( p ) ;
267 char *buf = wxBuffer ;
9779893b 268
519cb848
SC
269 if ( len >= BUFSIZ + 512 )
270 {
271 buf = new char [len+1] ;
272 }
273
274 wxMacConvertFromPC( ptr , buf , len ) ;
275 buf[len] = 0 ;
276 wxString result( buf ) ;
277 if ( buf != wxBuffer )
278 delete buf ;
279 return result ;
280}
281
282
9779893b 283void wxMacConvertToPC( char * p )
519cb848
SC
284{
285 char *ptr = p ;
286 int len = strlen ( p ) ;
9779893b 287
519cb848
SC
288 wxMacConvertToPC( ptr , ptr , len ) ;
289}
290
9779893b 291void wxMacConvertToPC( unsigned char *p )
519cb848
SC
292{
293 char *ptr = (char*) p + 1 ;
294 int len = p[0] ;
9779893b 295
519cb848
SC
296 wxMacConvertToPC( ptr , ptr , len ) ;
297}
298
9779893b 299wxString wxMacMakePCStringFromMac( const char * p )
519cb848
SC
300{
301 const char *ptr = p ;
302 int len = strlen ( p ) ;
303 char *buf = wxBuffer ;
9779893b 304
519cb848
SC
305 if ( len >= BUFSIZ + 512 )
306 {
307 buf = new char [len+1] ;
308 }
309
310 wxMacConvertToPC( ptr , buf , len ) ;
311 buf[len] = 0 ;
9779893b 312
519cb848
SC
313 wxString result( buf ) ;
314 if ( buf != wxBuffer )
315 delete buf ;
316 return result ;
317}
169935ad 318
519cb848 319#endif
e9576ca5
SC
320
321bool wxApp::Initialize()
322{
169935ad 323 int error = 0 ;
9779893b 324
8be97d65 325 // Mac-specific
9779893b 326
519cb848
SC
327 UMAInitToolbox( 4 ) ;
328 UMAShowWatchCursor() ;
8be97d65 329
519cb848
SC
330 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerProc(AEHandleODoc) , (long) wxTheApp , FALSE ) ;
331 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) , (long) wxTheApp , FALSE ) ;
332 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) , (long) wxTheApp , FALSE ) ;
333 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) , (long) wxTheApp , FALSE ) ;
8be97d65 334
9779893b 335
8be97d65
SC
336 // test the minimal configuration necessary
337
338 long theSystem ;
339 long theMachine;
8be97d65
SC
340
341 if (Gestalt(gestaltMachineType, &theMachine) != noErr)
342 {
343 error = kMacSTRWrongMachine;
344 }
345 else if (theMachine < gestaltMacPlus)
346 {
347 error = kMacSTRWrongMachine;
348 }
349 else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
350 {
351 error = kMacSTROldSystem ;
9779893b 352 }
519cb848 353 else if ( theSystem < 0x0750 )
8be97d65
SC
354 {
355 error = kMacSTROldSystem ;
356 }
519cb848 357 #if !TARGET_CARBON
8be97d65
SC
358 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
359 {
360 error = kMacSTRSmallSize;
361 }
519cb848
SC
362 #endif
363 /*
8be97d65
SC
364 else
365 {
519cb848 366 if ( !UMAHasAppearance() )
8be97d65 367 {
8be97d65 368 error = kMacSTRNoPre8Yet ;
519cb848 369 }
8be97d65 370 }
519cb848 371 */
8be97d65
SC
372
373 // if we encountered any problems so far, give the error code and exit immediately
9779893b 374
169935ad 375 if ( error )
9779893b 376 {
8be97d65
SC
377 short itemHit;
378 Str255 message;
519cb848 379
8be97d65 380 GetIndString(message, 128, error);
519cb848
SC
381 UMAShowArrowCursor() ;
382 ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");
383 itemHit = Alert(128, nil);
8be97d65 384 return FALSE ;
9779893b 385 }
519cb848
SC
386
387#if __option(profile)
2f1ae414 388 ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ;
9779893b 389#endif
519cb848 390
8be97d65 391 // now avoid exceptions thrown for new (bad_alloc)
9779893b 392
8be97d65 393 std::__throws_bad_alloc = FALSE ;
9779893b 394
519cb848 395 s_macCursorRgn = ::NewRgn() ;
8be97d65 396
e9576ca5
SC
397#ifdef __WXMSW__
398 wxBuffer = new char[1500];
399#else
400 wxBuffer = new char[BUFSIZ + 512];
401#endif
402
2f1ae414 403 wxClassInfo::InitializeClasses();
e9576ca5 404
2f1ae414
SC
405#if wxUSE_RESOURCES
406// wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
e9576ca5 407#endif
e9576ca5 408
2f1ae414
SC
409#if wxUSE_THREADS
410 wxPendingEventsLocker = new wxCriticalSection;
411#endif
e9576ca5
SC
412 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
413 wxTheColourDatabase->Initialize();
414
415 wxInitializeStockLists();
416 wxInitializeStockObjects();
417
418#if wxUSE_WX_RESOURCES
419 wxInitializeResourceSystem();
420#endif
421
422 wxBitmap::InitStandardHandlers();
423
424 wxModule::RegisterModules();
519cb848
SC
425 if (!wxModule::InitializeModules())
426 return FALSE;
e9576ca5 427
519cb848
SC
428 wxWinMacWindowList = new wxList(wxKEY_INTEGER);
429 wxWinMacControlList = new wxList(wxKEY_INTEGER);
430
2f1ae414 431 wxMacCreateNotifierTable() ;
9779893b 432
2f1ae414
SC
433 UMAShowArrowCursor() ;
434
e9576ca5
SC
435 return TRUE;
436}
437
438void wxApp::CleanUp()
439{
2f1ae414
SC
440#if wxUSE_LOG
441 // flush the logged messages if any and install a 'safer' log target: the
442 // default one (wxLogGui) can't be used after the resources are freed just
443 // below and the user suppliedo ne might be even more unsafe (using any
444 // wxWindows GUI function is unsafe starting from now)
445 wxLog::DontCreateOnDemand();
446
447 // this will flush the old messages if any
448 delete wxLog::SetActiveTarget(new wxLogStderr);
449#endif // wxUSE_LOG
450
451 // One last chance for pending objects to be cleaned up
452 wxTheApp->DeletePendingObjects();
453
e9576ca5
SC
454 wxModule::CleanUpModules();
455
456#if wxUSE_WX_RESOURCES
457 wxCleanUpResourceSystem();
458#endif
459
460 wxDeleteStockObjects() ;
461
2f1ae414
SC
462 // Destroy all GDI lists, etc.
463 wxDeleteStockLists();
e9576ca5
SC
464
465 delete wxTheColourDatabase;
466 wxTheColourDatabase = NULL;
467
468 wxBitmap::CleanUpHandlers();
469
470 delete[] wxBuffer;
471 wxBuffer = NULL;
472
2f1ae414 473 wxMacDestroyNotifierTable() ;
519cb848
SC
474 if (wxWinMacWindowList)
475 delete wxWinMacWindowList ;
476
2f1ae414
SC
477 delete wxPendingEvents;
478#if wxUSE_THREADS
479 delete wxPendingEventsLocker;
480 // If we don't do the following, we get an apparent memory leak.
481 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
482#endif
483
e9576ca5
SC
484 wxClassInfo::CleanUpClasses();
485
519cb848
SC
486#if __option(profile)
487 ProfilerDump( "\papp.prof" ) ;
488 ProfilerTerm() ;
9779893b 489#endif
519cb848 490
e9576ca5
SC
491 delete wxTheApp;
492 wxTheApp = NULL;
9779893b 493
e9576ca5 494#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
2f1ae414
SC
495 // At this point we want to check if there are any memory
496 // blocks that aren't part of the wxDebugContext itself,
497 // as a special case. Then when dumping we need to ignore
498 // wxDebugContext, too.
499 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
500 {
501 wxLogDebug(wxT("There were memory leaks."));
502 wxDebugContext::Dump();
503 wxDebugContext::PrintStatistics();
504 }
505 // wxDebugContext::SetStream(NULL, NULL);
e9576ca5 506#endif
9779893b 507
2f1ae414
SC
508#if wxUSE_LOG
509 // do it as the very last thing because everything else can log messages
510 delete wxLog::SetActiveTarget(NULL);
511#endif // wxUSE_LOG
169935ad 512
519cb848
SC
513 if (s_macCursorRgn)
514 ::DisposeRgn(s_macCursorRgn);
2f1ae414 515
8be97d65
SC
516 #if 0
517 TerminateAE() ;
518 #endif
e9576ca5
SC
519}
520
2f1ae414 521int wxEntry( int argc, char *argv[] , bool enterLoop )
e9576ca5 522{
7c551d95
SC
523#ifdef __MWERKS__
524#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
525 // This seems to be necessary since there are 'rogue'
526 // objects present at this point (perhaps global objects?)
527 // Setting a checkpoint will ignore them as far as the
528 // memory checking facility is concerned.
529 // Of course you may argue that memory allocated in globals should be
530 // checked, but this is a reasonable compromise.
531 wxDebugContext::SetCheckpoint();
532#endif
533#endif
2f1ae414
SC
534 if (!wxApp::Initialize())
535 return 0;
536 // create the application object or ensure that one already exists
537 if (!wxTheApp)
e9576ca5 538 {
2f1ae414
SC
539 // The app may have declared a global application object, but we recommend
540 // the IMPLEMENT_APP macro is used instead, which sets an initializer
541 // function for delayed, dynamic app object construction.
542 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
543 wxT("No initializer - use IMPLEMENT_APP macro.") );
9779893b 544
2f1ae414
SC
545 wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
546 }
9779893b 547
2f1ae414 548 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
e9576ca5 549
519cb848 550#ifdef __WXMAC__
2f1ae414 551 argc = 0 ; // currently we don't support files as parameters
519cb848
SC
552#endif
553
e9576ca5
SC
554 wxTheApp->argc = argc;
555 wxTheApp->argv = argv;
556
557 // GUI-specific initialization, such as creating an app context.
558 wxTheApp->OnInitGui();
9779893b 559
519cb848 560 // we could try to get the open apple events here to adjust argc and argv better
9779893b 561
e9576ca5
SC
562
563 // Here frames insert themselves automatically
564 // into wxTopLevelWindows by getting created
565 // in OnInit().
9779893b 566
e9576ca5 567 int retValue = 0;
9779893b 568
2f1ae414
SC
569 if ( wxTheApp->OnInit() )
570 {
571 if ( enterLoop )
572 {
573 retValue = wxTheApp->OnRun();
574 }
575 else
576 // We want to initialize, but not run or exit immediately.
577 return 1;
578 }
579 //else: app initialization failed, so we skipped OnRun()
e9576ca5 580
2f1ae414
SC
581 wxWindow *topWindow = wxTheApp->GetTopWindow();
582 if ( topWindow )
583 {
584 // Forcibly delete the window.
585 if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
586 topWindow->IsKindOf(CLASSINFO(wxDialog)) )
587 {
588 topWindow->Close(TRUE);
589 wxTheApp->DeletePendingObjects();
590 }
591 else
592 {
593 delete topWindow;
594 wxTheApp->SetTopWindow(NULL);
595 }
596 }
597
598 wxTheApp->OnExit();
599
600 wxApp::CleanUp();
601
602 return retValue;
e9576ca5
SC
603};
604
605// Static member initialization
2f1ae414 606wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
e9576ca5
SC
607
608wxApp::wxApp()
609{
610 m_topWindow = NULL;
611 wxTheApp = this;
2f1ae414 612
e9576ca5 613 m_wantDebugOutput = TRUE ;
2f1ae414 614
e9576ca5
SC
615 argc = 0;
616 argv = NULL;
519cb848 617
e9576ca5 618 m_printMode = wxPRINT_WINDOWS;
e9576ca5
SC
619 m_exitOnFrameDelete = TRUE;
620 m_auto3D = TRUE;
621}
622
623bool wxApp::Initialized()
624{
519cb848 625 if (GetTopWindow())
e9576ca5 626 return TRUE;
519cb848
SC
627 else
628 return FALSE;
e9576ca5
SC
629}
630
631int wxApp::MainLoop()
632{
633 m_keepGoing = TRUE;
634
e9576ca5
SC
635 while (m_keepGoing)
636 {
8be97d65 637 MacDoOneEvent() ;
e9576ca5 638 }
e9576ca5
SC
639
640 return 0;
641}
642
643// Returns TRUE if more time is needed.
644bool wxApp::ProcessIdle()
645{
646 wxIdleEvent event;
647 event.SetEventObject(this);
648 ProcessEvent(event);
649
650 return event.MoreRequested();
651}
652
653void wxApp::ExitMainLoop()
654{
655 m_keepGoing = FALSE;
656}
657
658// Is a message/event pending?
659bool wxApp::Pending()
660{
519cb848
SC
661 EventRecord event ;
662
663 return EventAvail( everyEvent , &event ) ;
e9576ca5
SC
664}
665
666// Dispatch a message.
667void wxApp::Dispatch()
668{
519cb848 669 MacDoOneEvent() ;
e9576ca5
SC
670}
671
672void wxApp::OnIdle(wxIdleEvent& event)
673{
2f1ae414 674 static bool s_inOnIdle = FALSE;
e9576ca5 675
2f1ae414
SC
676 // Avoid recursion (via ProcessEvent default case)
677 if ( s_inOnIdle )
678 return;
e9576ca5 679
2f1ae414
SC
680
681 s_inOnIdle = TRUE;
e9576ca5
SC
682
683 // 'Garbage' collection of windows deleted with Close().
684 DeletePendingObjects();
685
686 // flush the logged messages if any
687 wxLog *pLog = wxLog::GetActiveTarget();
688 if ( pLog != NULL && pLog->HasPendingMessages() )
689 pLog->Flush();
690
691 // Send OnIdle events to all windows
692 bool needMore = SendIdleEvents();
693
694 if (needMore)
695 event.RequestMore(TRUE);
696
2f1ae414
SC
697 // If they are pending events, we must process them: pending events are
698 // either events to the threads other than main or events posted with
699 // wxPostEvent() functions
700 wxMacProcessNotifierAndPendingEvents();
701
702 s_inOnIdle = FALSE;
e9576ca5
SC
703}
704
9779893b
RD
705void wxWakeUpIdle()
706{
2f1ae414 707 wxMacWakeUp() ;
9779893b
RD
708}
709
e9576ca5
SC
710// Send idle event to all top-level windows
711bool wxApp::SendIdleEvents()
712{
713 bool needMore = FALSE;
714 wxNode* node = wxTopLevelWindows.First();
715 while (node)
716 {
717 wxWindow* win = (wxWindow*) node->Data();
718 if (SendIdleEvents(win))
719 needMore = TRUE;
720
721 node = node->Next();
722 }
723 return needMore;
724}
725
726// Send idle event to window and all subwindows
727bool wxApp::SendIdleEvents(wxWindow* win)
728{
729 bool needMore = FALSE;
730
731 wxIdleEvent event;
732 event.SetEventObject(win);
733 win->ProcessEvent(event);
734
735 if (event.MoreRequested())
736 needMore = TRUE;
737
738 wxNode* node = win->GetChildren().First();
739 while (node)
740 {
741 wxWindow* win = (wxWindow*) node->Data();
742 if (SendIdleEvents(win))
743 needMore = TRUE;
744
745 node = node->Next();
746 }
747 return needMore ;
748}
749
750void wxApp::DeletePendingObjects()
751{
752 wxNode *node = wxPendingDelete.First();
753 while (node)
754 {
755 wxObject *obj = (wxObject *)node->Data();
9779893b 756
e9576ca5
SC
757 delete obj;
758
759 if (wxPendingDelete.Member(obj))
760 delete node;
761
762 // Deleting one object may have deleted other pending
763 // objects, so start from beginning of list again.
764 node = wxPendingDelete.First();
765 }
766}
767
2f1ae414
SC
768wxIcon
769wxApp::GetStdIcon(int which) const
e9576ca5 770{
2f1ae414
SC
771 switch(which)
772 {
773 case wxICON_INFORMATION:
774 return wxIcon("wxICON_INFO");
e9576ca5 775
2f1ae414
SC
776 case wxICON_QUESTION:
777 return wxIcon("wxICON_QUESTION");
778
779 case wxICON_EXCLAMATION:
780 return wxIcon("wxICON_WARNING");
781
782 default:
783 wxFAIL_MSG(wxT("requested non existent standard icon"));
784 // still fall through
785
786 case wxICON_HAND:
787 return wxIcon("wxICON_ERROR");
788 }
e9576ca5
SC
789}
790
791void wxExit()
792{
2f1ae414
SC
793 wxLogError(_("Fatal error: exiting"));
794
795 wxApp::CleanUp();
8be97d65 796 ::ExitToShell() ;
e9576ca5
SC
797}
798
2f1ae414
SC
799void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
800{
801 if (GetTopWindow())
802 GetTopWindow()->Close(TRUE);
803}
804
805// Default behaviour: close the application with prompts. The
806// user can veto the close, and therefore the end session.
807void wxApp::OnQueryEndSession(wxCloseEvent& event)
808{
809 if (GetTopWindow())
810 {
811 if (!GetTopWindow()->Close(!event.CanVeto()))
812 event.Veto(TRUE);
813 }
814}
815
816extern "C" void wxCYield() ;
817void wxCYield()
818{
819 wxYield() ;
820}
821
e9576ca5
SC
822// Yield to other processes
823bool wxYield()
824{
2f1ae414
SC
825#if wxUSE_THREADS
826 YieldToAnyThread() ;
827#endif
828 EventRecord event ;
829
830 long sleepTime = 0 ; //::GetCaretTime();
831
832 while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn))
833 {
834 wxTheApp->MacHandleOneEvent( &event );
835 }
836
837 wxMacProcessNotifierAndPendingEvents() ;
8be97d65 838 return TRUE;
169935ad
SC
839}
840
9779893b 841// platform specifics
169935ad 842
519cb848
SC
843void wxApp::MacSuspend( bool convertClipboard )
844{
2f1ae414
SC
845 // we have to deactive the window manually
846
847 wxWindow* window = GetTopWindow() ;
848 if ( window )
849 window->MacActivate( MacGetCurrentEvent() , false ) ;
850
519cb848 851 s_lastMouseDown = 0 ;
9779893b 852 if( convertClipboard )
519cb848
SC
853 {
854 MacConvertPrivateToPublicScrap() ;
855 }
9779893b 856
519cb848
SC
857 UMAHideFloatingWindows() ;
858}
859
860void wxApp::MacResume( bool convertClipboard )
861{
862 s_lastMouseDown = 0 ;
9779893b 863 if( convertClipboard )
519cb848
SC
864 {
865 MacConvertPublicToPrivateScrap() ;
866 }
9779893b 867
519cb848
SC
868 UMAShowFloatingWindows() ;
869}
870
871void wxApp::MacConvertPrivateToPublicScrap()
872{
519cb848
SC
873}
874
875void wxApp::MacConvertPublicToPrivateScrap()
876{
519cb848
SC
877}
878
9779893b 879void wxApp::MacDoOneEvent()
169935ad
SC
880{
881 EventRecord event ;
882
519cb848 883 long sleepTime = ::GetCaretTime();
169935ad 884
519cb848 885 if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn))
169935ad 886 {
8be97d65 887 MacHandleOneEvent( &event );
169935ad
SC
888 }
889 else
890 {
8be97d65 891 // idlers
519cb848
SC
892 WindowPtr window = UMAFrontWindow() ;
893 if ( window )
894 UMAIdleControls( window ) ;
9779893b 895
8be97d65 896 wxTheApp->ProcessIdle() ;
169935ad 897 }
519cb848
SC
898 if ( event.what != kHighLevelEvent )
899 SetRectRgn( s_macCursorRgn , event.where.h - 1 , event.where.v - 1, event.where.h + 1 , event.where.v + 1 ) ;
900
8be97d65 901 // repeaters
519cb848 902
2f1ae414 903 wxMacProcessNotifierAndPendingEvents() ;
169935ad
SC
904}
905
9779893b 906void wxApp::MacHandleOneEvent( EventRecord *ev )
169935ad 907{
519cb848 908 m_macCurrentEvent = ev ;
9779893b 909
519cb848 910 wxApp::sm_lastMessageTime = ev->when ;
9779893b 911
169935ad
SC
912 switch (ev->what)
913 {
169935ad 914 case mouseDown:
8be97d65 915 MacHandleMouseDownEvent( ev ) ;
519cb848
SC
916 if ( ev->modifiers & controlKey )
917 s_lastMouseDown = 2;
918 else
919 s_lastMouseDown = 1;
169935ad
SC
920 break;
921 case mouseUp:
519cb848
SC
922 if ( s_lastMouseDown == 2 )
923 {
924 ev->modifiers |= controlKey ;
925 }
926 else
927 {
928 ev->modifiers &= ~controlKey ;
9779893b 929 }
8be97d65 930 MacHandleMouseUpEvent( ev ) ;
519cb848 931 s_lastMouseDown = 0;
169935ad
SC
932 break;
933 case activateEvt:
8be97d65 934 MacHandleActivateEvent( ev ) ;
169935ad
SC
935 break;
936 case updateEvt:
8be97d65 937 MacHandleUpdateEvent( ev ) ;
169935ad 938 break;
519cb848
SC
939 case keyDown:
940 case autoKey:
941 MacHandleKeyDownEvent( ev ) ;
942 break;
943 case keyUp:
944 MacHandleKeyUpEvent( ev ) ;
945 break;
169935ad 946 case diskEvt:
8be97d65 947 MacHandleDiskEvent( ev ) ;
169935ad
SC
948 break;
949 case osEvt:
8be97d65 950 MacHandleOSEvent( ev ) ;
169935ad 951 break;
519cb848
SC
952 case kHighLevelEvent:
953 MacHandleHighLevelEvent( ev ) ;
954 break;
169935ad
SC
955 default:
956 break;
957 }
2f1ae414 958 wxMacProcessNotifierAndPendingEvents() ;
169935ad
SC
959}
960
8be97d65 961void wxApp::MacHandleHighLevelEvent( EventRecord *ev )
169935ad 962{
519cb848 963 ::AEProcessAppleEvent( ev ) ;
169935ad
SC
964}
965
519cb848
SC
966bool s_macIsInModalLoop = false ;
967
8be97d65 968void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
169935ad 969{
2f1ae414
SC
970 wxToolTip::RemoveToolTips() ;
971
519cb848
SC
972 WindowRef window;
973 WindowRef frontWindow = UMAFrontNonFloatingWindow() ;
974 WindowAttributes frontWindowAttributes = NULL ;
975 if ( frontWindow )
976 UMAGetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
9779893b 977
519cb848
SC
978 short windowPart = ::FindWindow(ev->where, &window);
979 wxWindow* win = wxFindWinFromMacWindow( window ) ;
9779893b 980
2f1ae414
SC
981 BitMap screenBits;
982 GetQDGlobalsScreenBits( &screenBits );
983
519cb848
SC
984 switch (windowPart)
985 {
986 case inMenuBar :
9779893b 987 if ( s_macIsInModalLoop )
519cb848
SC
988 {
989 SysBeep ( 30 ) ;
990 }
991 else
992 {
993 UInt32 menuresult = MenuSelect(ev->where) ;
994 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
995 s_lastMouseDown = 0;
996 }
997 break ;
2f1ae414 998#if !TARGET_CARBON
519cb848
SC
999 case inSysWindow :
1000 SystemClick( ev , window ) ;
1001 s_lastMouseDown = 0;
1002 break ;
2f1ae414 1003#endif
519cb848
SC
1004 case inDrag :
1005 if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
1006 {
1007 SysBeep ( 30 ) ;
1008 }
1009 else
1010 {
2f1ae414 1011 DragWindow(window, ev->where, &screenBits.bounds);
519cb848
SC
1012 if (win)
1013 {
1014 GrafPtr port ;
1015 GetPort( &port ) ;
1016 Point pt = { 0, 0 } ;
2f1ae414
SC
1017 #if TARGET_CARBON
1018 SetPort( GetWindowPort(window) ) ;
1019 #else
1020 SetPort( (window) ) ;
1021 #endif
519cb848
SC
1022 SetOrigin( 0 , 0 ) ;
1023 LocalToGlobal( &pt ) ;
1024 SetPort( port ) ;
9779893b 1025 win->SetSize( pt.h , pt.v , -1 ,
519cb848
SC
1026 -1 , wxSIZE_USE_EXISTING);
1027 }
1028 s_lastMouseDown = 0;
1029 }
1030 break ;
1031 case inGoAway:
1032 if (TrackGoAway(window, ev->where))
1033 {
1034 if ( win )
1035 win->Close() ;
1036 }
1037 s_lastMouseDown = 0;
1038 break;
1039 case inGrow:
2f1ae414 1040 int growResult = GrowWindow(window , ev->where, &screenBits.bounds);
519cb848
SC
1041 if (growResult != 0)
1042 {
1043 int newWidth = LoWord(growResult);
1044 int newHeight = HiWord(growResult);
1045 int oldWidth, oldHeight;
9779893b 1046
519cb848 1047 win->GetSize(&oldWidth, &oldHeight);
9779893b 1048 if (newWidth == 0)
519cb848 1049 newWidth = oldWidth;
9779893b 1050 if (newHeight == 0)
519cb848 1051 newHeight = oldHeight;
9779893b 1052
519cb848
SC
1053 if (win)
1054 win->SetSize( -1, -1, newWidth, newHeight, wxSIZE_USE_EXISTING);
1055 }
1056 s_lastMouseDown = 0;
1057 break;
1058 case inZoomIn:
1059 case inZoomOut:
1060 if (TrackBox(window, ev->where, windowPart))
1061 {
1062 // TODO setup size event
1063 ZoomWindow( window , windowPart , false ) ;
1064 if (win)
2f1ae414
SC
1065 {
1066 Rect tempRect ;
1067
1068 GetWindowPortBounds(window, &tempRect ) ;
1069 win->SetSize( -1, -1, tempRect.right-tempRect.left ,
1070 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
1071 }
519cb848
SC
1072 }
1073 s_lastMouseDown = 0;
1074 break;
1075 case inCollapseBox :
1076 // TODO setup size event
1077 s_lastMouseDown = 0;
1078 break ;
169935ad 1079
519cb848 1080 case inContent :
2f1ae414
SC
1081 {
1082 GrafPtr port ;
1083 GetPort( &port ) ;
1084 #if TARGET_CARBON
1085 SetPort( GetWindowPort(window) ) ;
1086 #else
1087 SetPort( (window) ) ;
1088 #endif
1089 SetOrigin( 0 , 0 ) ;
1090 SetPort( port ) ;
1091 }
519cb848
SC
1092 if ( window != frontWindow )
1093 {
9779893b 1094 if ( s_macIsInModalLoop )
519cb848
SC
1095 {
1096 SysBeep ( 30 ) ;
1097 }
1098 else if ( UMAIsWindowFloating( window ) )
1099 {
1100 if ( win )
1101 win->MacMouseDown( ev , windowPart ) ;
1102 }
1103 else
1104 {
1105 UMASelectWindow( window ) ;
1106 }
1107 }
1108 else
1109 {
1110 if ( win )
1111 win->MacMouseDown( ev , windowPart ) ;
1112 }
1113 break ;
9779893b 1114
519cb848
SC
1115 default:
1116 break;
1117 }
169935ad
SC
1118}
1119
519cb848 1120void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
169935ad 1121{
519cb848 1122 WindowRef window;
9779893b 1123
519cb848 1124 short windowPart = ::FindWindow(ev->where, &window);
9779893b 1125
519cb848
SC
1126 switch (windowPart)
1127 {
1128 case inMenuBar :
1129 break ;
1130 case inSysWindow :
1131 break ;
1132 default:
1133 {
1134 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1135 if ( win )
1136 win->MacMouseUp( ev , windowPart ) ;
1137 }
1138 break;
1139 }
169935ad
SC
1140}
1141
7c551d95 1142long wxMacTranslateKey(unsigned char key, unsigned char code)
9779893b 1143{
7c551d95 1144 long retval = key ;
9779893b 1145 switch (key)
519cb848
SC
1146 {
1147 case 0x01 :
7c551d95 1148 retval = WXK_HOME;
519cb848
SC
1149 break;
1150 case 0x03 :
7c551d95 1151 retval = WXK_RETURN;
519cb848
SC
1152 break;
1153 case 0x04 :
7c551d95 1154 retval = WXK_END;
519cb848
SC
1155 break;
1156 case 0x05 :
7c551d95 1157 retval = WXK_HELP;
519cb848
SC
1158 break;
1159 case 0x08 :
7c551d95 1160 retval = WXK_BACK;
519cb848
SC
1161 break;
1162 case 0x09 :
7c551d95 1163 retval = WXK_TAB;
519cb848
SC
1164 break;
1165 case 0x0b :
7c551d95 1166 retval = WXK_PAGEUP;
519cb848
SC
1167 break;
1168 case 0x0c :
7c551d95 1169 retval = WXK_PAGEDOWN;
519cb848
SC
1170 break;
1171 case 0x0d :
7c551d95 1172 retval = WXK_RETURN;
519cb848
SC
1173 break;
1174 case 0x10 :
169935ad 1175 {
519cb848
SC
1176 switch( code )
1177 {
1178 case 0x7a :
7c551d95 1179 retval = WXK_F1 ;
519cb848
SC
1180 break;
1181 case 0x78 :
7c551d95 1182 retval = WXK_F2 ;
519cb848
SC
1183 break;
1184 case 0x63 :
7c551d95 1185 retval = WXK_F3 ;
519cb848
SC
1186 break;
1187 case 0x76 :
7c551d95 1188 retval = WXK_F4 ;
519cb848
SC
1189 break;
1190 case 0x60 :
7c551d95 1191 retval = WXK_F5 ;
519cb848
SC
1192 break;
1193 case 0x61 :
7c551d95 1194 retval = WXK_F6 ;
519cb848
SC
1195 break;
1196 case 0x62:
7c551d95 1197 retval = WXK_F7 ;
519cb848
SC
1198 break;
1199 case 0x64 :
7c551d95 1200 retval = WXK_F8 ;
519cb848
SC
1201 break;
1202 case 0x65 :
7c551d95 1203 retval = WXK_F9 ;
519cb848
SC
1204 break;
1205 case 0x6D :
7c551d95 1206 retval = WXK_F10 ;
519cb848
SC
1207 break;
1208 case 0x67 :
7c551d95 1209 retval = WXK_F11 ;
519cb848
SC
1210 break;
1211 case 0x6F :
7c551d95 1212 retval = WXK_F12 ;
519cb848
SC
1213 break;
1214 case 0x69 :
7c551d95 1215 retval = WXK_F13 ;
519cb848
SC
1216 break;
1217 case 0x6B :
7c551d95 1218 retval = WXK_F14 ;
519cb848
SC
1219 break;
1220 case 0x71 :
7c551d95 1221 retval = WXK_F15 ;
519cb848
SC
1222 break;
1223 }
169935ad 1224 }
519cb848
SC
1225 break ;
1226 case 0x1b :
7c551d95 1227 retval = WXK_ESCAPE ;
519cb848
SC
1228 break ;
1229 case 0x1c :
7c551d95 1230 retval = WXK_LEFT ;
519cb848
SC
1231 break ;
1232 case 0x1d :
7c551d95 1233 retval = WXK_RIGHT ;
519cb848
SC
1234 break ;
1235 case 0x1e :
7c551d95 1236 retval = WXK_UP ;
519cb848
SC
1237 break ;
1238 case 0x1f :
7c551d95 1239 retval = WXK_DOWN ;
519cb848 1240 break ;
7c551d95
SC
1241 case 0x7F :
1242 retval = WXK_DELETE ;
519cb848
SC
1243 default:
1244 break ;
1245 } // end switch
9779893b 1246
7c551d95 1247 return retval;
169935ad
SC
1248}
1249
519cb848 1250void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
169935ad 1251{
2f1ae414
SC
1252 wxToolTip::RemoveToolTips() ;
1253
519cb848
SC
1254 UInt32 menuresult = UMAMenuEvent(ev) ;
1255 if ( HiWord( menuresult ) )
1256 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
169935ad
SC
1257 else
1258 {
519cb848
SC
1259 short keycode ;
1260 short keychar ;
1261 keychar = short(ev->message & charCodeMask);
9779893b
RD
1262 keycode = short(ev->message & keyCodeMask) >> 8 ;
1263
519cb848
SC
1264 wxWindow* focus = wxWindow::FindFocus() ;
1265 if ( focus )
1266 {
7c551d95
SC
1267 long keyval = wxMacTranslateKey(keychar, keycode) ;
1268
1269 wxKeyEvent event(wxEVT_KEY_DOWN);
519cb848
SC
1270 event.m_shiftDown = ev->modifiers & shiftKey;
1271 event.m_controlDown = ev->modifiers & controlKey;
1272 event.m_altDown = ev->modifiers & optionKey;
1273 event.m_metaDown = ev->modifiers & cmdKey;
7c551d95 1274 event.m_keyCode = keyval;
519cb848
SC
1275 event.m_x = ev->where.h;
1276 event.m_y = ev->where.v;
1277 event.m_timeStamp = ev->when;
1278 event.SetEventObject(focus);
7c551d95
SC
1279 bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1280 if ( !handled )
1281 {
1282 #if wxUSE_ACCEL
1283 if (!handled)
1284 {
1285 wxWindow *ancestor = focus;
1286 /*
1287 while (ancestor)
1288 {
1289 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1290 if (command != -1)
1291 {
1292 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1293 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1294 break;
1295 }
1296 if (ancestor->m_isFrame)
1297 break;
1298 ancestor = ancestor->GetParent();
1299 }
1300 */
1301 }
1302 #endif // wxUSE_ACCEL
1303 }
1304 if (!handled)
1305 {
1306 wxKeyEvent event(wxEVT_CHAR);
1307 event.m_shiftDown = ev->modifiers & shiftKey;
1308 event.m_controlDown = ev->modifiers & controlKey;
1309 event.m_altDown = ev->modifiers & optionKey;
1310 event.m_metaDown = ev->modifiers & cmdKey;
1311 event.m_keyCode = keyval;
1312 event.m_x = ev->where.h;
1313 event.m_y = ev->where.v;
1314 event.m_timeStamp = ev->when;
1315 event.SetEventObject(focus);
1316 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1317 }
1318 if ( !handled &&
1319 (keyval == WXK_TAB) &&
1320 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
1321 (focus->GetParent()) &&
1322 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1323 {
1324 wxNavigationKeyEvent new_event;
1325 new_event.SetEventObject( focus );
1326 new_event.SetDirection( !event.ShiftDown() );
1327 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1328 new_event.SetWindowChange( event.ControlDown() );
1329 new_event.SetCurrentFocus( focus );
1330 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1331 }
1332 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1333 if ( (!handled) &&
1334 (keyval == '.' && event.ControlDown() ) )
1335 {
1336 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1337 new_event.SetEventObject( focus );
1338 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1339 }
169935ad
SC
1340 }
1341 }
1342}
1343
519cb848 1344void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
169935ad 1345{
519cb848 1346 // nothing to do
169935ad
SC
1347}
1348
519cb848 1349void wxApp::MacHandleActivateEvent( EventRecord *ev )
169935ad 1350{
519cb848
SC
1351 WindowRef window = (WindowRef) ev->message ;
1352 if ( window )
169935ad 1353 {
519cb848
SC
1354 bool activate = (ev->modifiers & activeFlag ) ;
1355 WindowClass wclass ;
1356 UMAGetWindowClass ( window , &wclass ) ;
1357 if ( wclass == kFloatingWindowClass )
1358 {
1359 // if it is a floater we activate/deactivate the front non-floating window instead
1360 window = UMAFrontNonFloatingWindow() ;
1361 }
1362 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1363 if ( win )
1364 win->MacActivate( ev , activate ) ;
169935ad
SC
1365 }
1366}
1367
519cb848 1368void wxApp::MacHandleUpdateEvent( EventRecord *ev )
169935ad 1369{
519cb848
SC
1370 WindowRef window = (WindowRef) ev->message ;
1371 wxWindow * win = wxFindWinFromMacWindow( window ) ;
1372 if ( win )
169935ad 1373 {
519cb848 1374 win->MacUpdate( ev ) ;
169935ad
SC
1375 }
1376}
1377
519cb848 1378void wxApp::MacHandleDiskEvent( EventRecord *ev )
169935ad 1379{
519cb848
SC
1380 if ( HiWord( ev->message ) != noErr )
1381 {
2f1ae414 1382 #if !TARGET_CARBON
519cb848
SC
1383 OSErr err ;
1384 Point point ;
1385 SetPt( &point , 100 , 100 ) ;
9779893b 1386
2f1ae414 1387 err = DIBadMount( point , ev->message ) ;
519cb848 1388 wxASSERT( err == noErr ) ;
2f1ae414 1389#endif
169935ad 1390 }
169935ad
SC
1391}
1392
519cb848 1393void wxApp::MacHandleOSEvent( EventRecord *ev )
169935ad 1394{
519cb848 1395 switch( ( ev->message & osEvtMessageMask ) >> 24 )
169935ad 1396 {
519cb848 1397 case suspendResumeMessage :
169935ad 1398 {
519cb848
SC
1399 bool isResuming = ev->message & resumeFlag ;
1400 bool convertClipboard = ev->message & convertClipboardFlag ;
1401 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
1402 if ( isResuming )
169935ad 1403 {
519cb848
SC
1404 WindowRef oldFrontWindow = NULL ;
1405 WindowRef newFrontWindow = NULL ;
9779893b 1406
519cb848
SC
1407 // in case we don't take care of activating ourselves, we have to synchronize
1408 // our idea of the active window with the process manager's - which it already activated
9779893b 1409
519cb848
SC
1410 if ( !doesActivate )
1411 oldFrontWindow = UMAFrontNonFloatingWindow() ;
9779893b 1412
519cb848 1413 MacResume( convertClipboard ) ;
9779893b 1414
519cb848 1415 newFrontWindow = UMAFrontNonFloatingWindow() ;
9779893b 1416
519cb848
SC
1417 if ( oldFrontWindow )
1418 {
1419 wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
1420 if ( win )
1421 win->MacActivate( ev , false ) ;
1422 }
1423 if ( newFrontWindow )
1424 {
1425 wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ;
1426 if ( win )
1427 win->MacActivate( ev , true ) ;
1428 }
169935ad
SC
1429 }
1430 else
9779893b 1431 {
519cb848 1432 MacSuspend( convertClipboard ) ;
9779893b
RD
1433
1434 // in case this suspending did close an active window, another one might
519cb848 1435 // have surfaced -> lets deactivate that one
9779893b 1436
519cb848
SC
1437 WindowRef newActiveWindow = UMAGetActiveNonFloatingWindow() ;
1438 if ( newActiveWindow )
1439 {
1440 wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ;
1441 if ( win )
1442 win->MacActivate( ev , false ) ;
1443 }
169935ad
SC
1444 }
1445 }
519cb848
SC
1446 break ;
1447 case mouseMovedMessage :
169935ad 1448 {
519cb848 1449 WindowRef window;
9779893b 1450
519cb848 1451 wxWindow* currentMouseWindow = NULL ;
9779893b
RD
1452
1453 MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , &currentMouseWindow ) ;
1454
519cb848 1455 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
169935ad 1456 {
519cb848 1457 wxMouseEvent event ;
9779893b 1458
519cb848
SC
1459 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1460 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
9779893b 1461
519cb848
SC
1462 event.m_leftDown = isDown && !controlDown;
1463 event.m_middleDown = FALSE;
9779893b 1464 event.m_rightDown = isDown && controlDown;
519cb848
SC
1465 event.m_shiftDown = ev->modifiers & shiftKey;
1466 event.m_controlDown = ev->modifiers & controlKey;
1467 event.m_altDown = ev->modifiers & optionKey;
9779893b 1468 event.m_metaDown = ev->modifiers & cmdKey;
519cb848 1469 event.m_x = ev->where.h;
9779893b 1470 event.m_y = ev->where.v;
519cb848
SC
1471 event.m_timeStamp = ev->when;
1472 event.SetEventObject(this);
9779893b 1473
519cb848
SC
1474 if ( wxWindow::s_lastMouseWindow )
1475 {
1476 wxMouseEvent eventleave(event ) ;
1477 eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ;
1478 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
1479 }
1480 if ( currentMouseWindow )
1481 {
1482 wxMouseEvent evententer(event ) ;
1483 evententer.SetEventType( wxEVT_ENTER_WINDOW ) ;
1484 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
1485 }
1486 wxWindow::s_lastMouseWindow = currentMouseWindow ;
169935ad 1487 }
9779893b 1488
519cb848 1489 short windowPart = ::FindWindow(ev->where, &window);
9779893b 1490
519cb848
SC
1491 switch (windowPart)
1492 {
1493 case inMenuBar :
1494 break ;
1495 case inSysWindow :
1496 break ;
1497 default:
9779893b 1498 {
519cb848
SC
1499 if ( s_lastMouseDown == 0 )
1500 ev->modifiers |= btnState ;
1501
1502 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1503 if ( win )
1504 win->MacMouseMoved( ev , windowPart ) ;
1505 }
1506 break;
1507 }
1508 }
1509 break ;
9779893b 1510
169935ad 1511 }
169935ad
SC
1512}
1513
519cb848 1514void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
169935ad 1515{
9779893b 1516 if (macMenuId == 0)
519cb848 1517 return; // no menu item selected
9779893b
RD
1518
1519 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
169935ad 1520 {
519cb848
SC
1521 #if ! TARGET_CARBON
1522 Str255 deskAccessoryName ;
1523 GrafPtr savedPort ;
9779893b 1524
519cb848
SC
1525 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
1526 GetPort(&savedPort);
1527 OpenDeskAcc(deskAccessoryName);
1528 SetPort(savedPort);
169935ad 1529 #endif
169935ad 1530 }
519cb848 1531 else
169935ad 1532 {
519cb848 1533 wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ;
e7549107
SC
1534 if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() )
1535 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ;
9779893b
RD
1536 }
1537 HiliteMenu(0);
169935ad
SC
1538}
1539
519cb848
SC
1540/*
1541long wxApp::MacTranslateKey(char key, int mods)
169935ad 1542{
169935ad
SC
1543}
1544
519cb848 1545void wxApp::MacAdjustCursor()
169935ad 1546{
169935ad
SC
1547}
1548
519cb848
SC
1549*/
1550/*
169935ad
SC
1551void
1552wxApp::macAdjustCursor()
1553{
519cb848 1554 if (ev->what != kHighLevelEvent)
169935ad
SC
1555 {
1556 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1557 if (theMacWxFrame)
1558 {
519cb848 1559 if (!theMacWxFrame->MacAdjustCursor(ev->where))
169935ad
SC
1560 ::SetCursor(&(qd.arrow));
1561 }
1562 }
1563}
9779893b 1564*/