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