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