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