]>
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 | { | |
230 | ExitMainLoop() ; | |
231 | } | |
232 | return noErr ; | |
233 | } | |
234 | ||
235 | //---------------------------------------------------------------------- | |
236 | // Support Routines linking the Mac...File Calls to the Document Manager | |
237 | //---------------------------------------------------------------------- | |
238 | ||
239 | void wxApp::MacOpenFile(const wxString & fileName ) | |
240 | { | |
241 | wxDocManager* dm = wxDocManager::GetDocumentManager() ; | |
242 | if ( dm ) | |
243 | dm->CreateDocument(fileName , wxDOC_SILENT ) ; | |
244 | } | |
245 | ||
246 | void wxApp::MacPrintFile(const wxString & fileName ) | |
247 | { | |
248 | wxDocManager* dm = wxDocManager::GetDocumentManager() ; | |
249 | if ( dm ) | |
250 | { | |
251 | wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ; | |
252 | if ( doc ) | |
253 | { | |
254 | wxView* view = doc->GetFirstView() ; | |
255 | if( view ) | |
256 | { | |
257 | wxPrintout *printout = view->OnCreatePrintout(); | |
258 | if (printout) | |
259 | { | |
260 | wxPrinter printer; | |
261 | printer.Print(view->GetFrame(), printout, TRUE); | |
262 | delete printout; | |
263 | } | |
264 | } | |
265 | if (doc->Close()) | |
266 | { | |
267 | doc->DeleteAllViews(); | |
268 | dm->RemoveDocument(doc) ; | |
269 | } | |
270 | } | |
271 | } | |
272 | } | |
273 | ||
274 | void wxApp::MacNewFile() | |
275 | { | |
276 | } | |
277 | ||
278 | //---------------------------------------------------------------------- | |
279 | // Carbon Event Handler | |
280 | //---------------------------------------------------------------------- | |
281 | ||
282 | #if TARGET_CARBON | |
283 | ||
284 | static const EventTypeSpec eventList[] = | |
285 | { | |
286 | { kEventClassCommand, kEventProcessCommand } , | |
287 | { kEventClassCommand, kEventCommandUpdateStatus } , | |
288 | ||
289 | { kEventClassMenu, kEventMenuOpening }, | |
290 | { kEventClassMenu, kEventMenuClosed }, | |
291 | ||
292 | { kEventClassApplication , kEventAppActivated } , | |
293 | { kEventClassApplication , kEventAppDeactivated } , | |
294 | // handling the quit event is not recommended by apple | |
295 | // rather using the quit apple event - which we do | |
296 | ||
297 | { kEventClassAppleEvent , kEventAppleEvent } , | |
298 | ||
299 | { kEventClassMouse , kEventMouseDown } , | |
300 | { kEventClassMouse , kEventMouseMoved } , | |
301 | { kEventClassMouse , kEventMouseUp } , | |
302 | { kEventClassMouse , kEventMouseDragged } , | |
303 | { 'WXMC' , 'WXMC' } | |
304 | } ; | |
305 | ||
306 | static pascal OSStatus | |
307 | MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
308 | { | |
309 | // FIXME: this doesn't work for multiple windows | |
310 | wxWindow *win = wxTheApp->GetTopWindow(); | |
311 | if ( win ) | |
312 | { | |
313 | // VZ: we could find the menu from its handle here by examining all | |
314 | // the menus in the menu bar recursively but knowing that neither | |
315 | // wxMSW nor wxGTK do it why bother... | |
316 | #if 0 | |
317 | MenuRef menuRef; | |
318 | ||
319 | GetEventParameter(event, | |
320 | kEventParamDirectObject, | |
321 | typeMenuRef, NULL, | |
322 | sizeof(menuRef), NULL, | |
323 | &menuRef); | |
324 | #endif // 0 | |
325 | ||
326 | wxMenuEvent wxevent(GetEventKind(event) == kEventMenuOpening | |
327 | ? wxEVT_MENU_OPEN | |
328 | : wxEVT_MENU_CLOSE); | |
329 | wxevent.SetEventObject(win); | |
330 | ||
331 | (void)win->GetEventHandler()->ProcessEvent(wxevent); | |
332 | } | |
333 | ||
334 | return eventNotHandledErr; | |
335 | } | |
336 | ||
337 | // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop | |
338 | // but have to use ReceiveNextEvent dealing with events manually, therefore we also have | |
339 | // deal with clicks in the menu bar explicitely | |
340 | ||
341 | pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ; | |
342 | ||
343 | static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
344 | { | |
345 | OSStatus result = eventNotHandledErr ; | |
346 | ||
347 | Point point ; | |
348 | UInt32 modifiers = 0; | |
349 | EventMouseButton button = 0 ; | |
350 | UInt32 click = 0 ; | |
351 | ||
352 | GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL, | |
353 | sizeof( Point ), NULL, &point ); | |
354 | GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL, | |
355 | sizeof( UInt32 ), NULL, &modifiers ); | |
356 | GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL, | |
357 | sizeof( EventMouseButton ), NULL, &button ); | |
358 | GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL, | |
359 | sizeof( UInt32 ), NULL, &click ); | |
360 | ||
361 | if ( button == 0 || GetEventKind( event ) == kEventMouseUp ) | |
362 | modifiers += btnState ; | |
363 | ||
364 | ||
365 | switch( GetEventKind(event) ) | |
366 | { | |
367 | case kEventMouseDown : | |
368 | { | |
369 | WindowRef window ; | |
370 | ||
371 | short windowPart = ::FindWindow(point, &window); | |
372 | ||
373 | if ( windowPart == inMenuBar ) | |
374 | { | |
375 | MenuSelect( point ) ; | |
376 | result = noErr ; | |
377 | } | |
378 | } | |
379 | break ; | |
380 | case kEventMouseDragged : | |
381 | case kEventMouseUp : | |
382 | { | |
383 | if ( wxTheApp->s_captureWindow ) | |
384 | wxMacWindowEventHandler( handler , event , (void*) wxTheApp->s_captureWindow->MacGetTopLevelWindow() ) ; | |
385 | } | |
386 | break ; | |
387 | case kEventMouseMoved : | |
388 | { | |
389 | wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ; | |
390 | result = noErr ; | |
391 | break ; | |
392 | } | |
393 | break ; | |
394 | } | |
395 | ||
396 | return result ; | |
397 | } | |
398 | ||
399 | static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
400 | { | |
401 | OSStatus result = eventNotHandledErr ; | |
402 | ||
403 | HICommand command ; | |
404 | ||
405 | GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL, | |
406 | sizeof( HICommand ), NULL, &command ); | |
407 | ||
408 | MenuCommand id = command.commandID ; | |
409 | if ( id == kHICommandPreferences ) | |
410 | id = wxApp::s_macPreferencesMenuItemId ; | |
411 | ||
412 | wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; | |
413 | wxMenu* menu = NULL ; | |
414 | wxMenuItem* item = NULL ; | |
415 | ||
416 | if ( mbar ) | |
417 | { | |
418 | item = mbar->FindItem( id , &menu ) ; | |
419 | // it is not 100 % sure that an menu of id 0 is really ours, safety check | |
420 | if ( id == 0 && menu != NULL && menu->GetHMenu() != command.menu.menuRef ) | |
421 | { | |
422 | item = NULL ; | |
423 | menu = NULL ; | |
424 | } | |
425 | } | |
426 | ||
427 | if ( item == NULL || menu == NULL || mbar == NULL ) | |
428 | return result ; | |
429 | ||
430 | switch( GetEventKind( event ) ) | |
431 | { | |
432 | case kEventProcessCommand : | |
433 | { | |
434 | if (item->IsCheckable()) | |
435 | { | |
436 | item->Check( !item->IsChecked() ) ; | |
437 | } | |
438 | ||
439 | menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ; | |
440 | result = noErr ; | |
441 | } | |
442 | break ; | |
443 | case kEventCommandUpdateStatus: | |
444 | // eventually trigger an updateui round | |
445 | result = noErr ; | |
446 | break ; | |
447 | default : | |
448 | break ; | |
449 | } | |
450 | ||
451 | return result ; | |
452 | } | |
453 | ||
454 | static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
455 | { | |
456 | OSStatus result = eventNotHandledErr ; | |
457 | switch ( GetEventKind( event ) ) | |
458 | { | |
459 | case kEventAppActivated : | |
460 | { | |
461 | if ( wxTheApp ) | |
462 | wxTheApp->MacResume( true ) ; | |
463 | result = noErr ; | |
464 | } | |
465 | break ; | |
466 | case kEventAppDeactivated : | |
467 | { | |
468 | if ( wxTheApp ) | |
469 | wxTheApp->MacSuspend( true ) ; | |
470 | result = noErr ; | |
471 | } | |
472 | break ; | |
473 | default : | |
474 | break ; | |
475 | } | |
476 | return result ; | |
477 | } | |
478 | ||
479 | pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
480 | { | |
481 | OSStatus result = eventNotHandledErr ; | |
482 | switch( GetEventClass( event ) ) | |
483 | { | |
484 | case kEventClassCommand : | |
485 | result = CommandEventHandler( handler , event , data ) ; | |
486 | break ; | |
487 | case kEventClassApplication : | |
488 | result = ApplicationEventHandler( handler , event , data ) ; | |
489 | break ; | |
490 | case kEventClassMenu : | |
491 | result = MenuEventHandler( handler , event , data ) ; | |
492 | break ; | |
493 | case kEventClassMouse : | |
494 | result = MouseEventHandler( handler , event , data ) ; | |
495 | break ; | |
496 | case kEventClassAppleEvent : | |
497 | { | |
498 | EventRecord rec ; | |
499 | wxMacConvertEventToRecord( event , &rec ) ; | |
500 | result = AEProcessAppleEvent( &rec ) ; | |
501 | } | |
502 | break ; | |
503 | default : | |
504 | break ; | |
505 | } | |
506 | ||
507 | return result ; | |
508 | } | |
509 | ||
510 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler ) | |
511 | ||
512 | #endif | |
513 | ||
514 | #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__) | |
515 | // we know it's there ;-) | |
516 | WXIMPORT char std::__throws_bad_alloc ; | |
517 | #endif | |
518 | ||
519 | bool wxApp::Initialize(int& argc, wxChar **argv) | |
520 | { | |
521 | int error = 0 ; | |
522 | ||
523 | // Mac-specific | |
524 | ||
525 | UMAInitToolbox( 4 ) ; | |
526 | SetEventMask( everyEvent ) ; | |
527 | UMAShowWatchCursor() ; | |
528 | ||
529 | #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) | |
530 | // open shared library resources from here since we don't have | |
531 | // __wxinitialize in Mach-O shared libraries | |
532 | wxStAppResource::OpenSharedLibraryResource(NULL); | |
533 | #endif | |
534 | ||
535 | #ifndef __DARWIN__ | |
536 | // test the minimal configuration necessary | |
537 | ||
538 | # if !TARGET_CARBON | |
539 | long theSystem ; | |
540 | long theMachine; | |
541 | ||
542 | if (Gestalt(gestaltMachineType, &theMachine) != noErr) | |
543 | { | |
544 | error = kMacSTRWrongMachine; | |
545 | } | |
546 | else if (theMachine < gestaltMacPlus) | |
547 | { | |
548 | error = kMacSTRWrongMachine; | |
549 | } | |
550 | else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr ) | |
551 | { | |
552 | error = kMacSTROldSystem ; | |
553 | } | |
554 | else if ( theSystem < 0x0860 ) | |
555 | { | |
556 | error = kMacSTROldSystem ; | |
557 | } | |
558 | else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap) | |
559 | { | |
560 | error = kMacSTRSmallSize; | |
561 | } | |
562 | # endif | |
563 | /* | |
564 | else | |
565 | { | |
566 | if ( !UMAHasAppearance() ) | |
567 | { | |
568 | error = kMacSTRNoPre8Yet ; | |
569 | } | |
570 | } | |
571 | */ | |
572 | #endif | |
573 | ||
574 | // if we encountered any problems so far, give the error code and exit immediately | |
575 | ||
576 | if ( error ) | |
577 | { | |
578 | wxStAppResource resload ; | |
579 | short itemHit; | |
580 | Str255 message; | |
581 | ||
582 | GetIndString(message, 128, error); | |
583 | UMAShowArrowCursor() ; | |
584 | ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p"); | |
585 | itemHit = Alert(128, nil); | |
586 | return FALSE ; | |
587 | } | |
588 | ||
589 | #ifndef __DARWIN__ | |
590 | # if __option(profile) | |
591 | ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ; | |
592 | # endif | |
593 | #endif | |
594 | ||
595 | #ifndef __DARWIN__ | |
596 | // now avoid exceptions thrown for new (bad_alloc) | |
597 | // FIXME CS for some changes outside wxMac does not compile anymore | |
598 | #if 0 | |
599 | std::__throws_bad_alloc = 0 ; | |
600 | #endif | |
601 | ||
602 | #endif | |
603 | ||
604 | s_macCursorRgn = ::NewRgn() ; | |
605 | ||
606 | // Mac OS X passes a process serial number command line argument when | |
607 | // the application is launched from the Finder. This argument must be | |
608 | // removed from the command line arguments before being handled by the | |
609 | // application (otherwise applications would need to handle it) | |
610 | if ( argc > 1 ) | |
611 | { | |
612 | static const wxChar *ARG_PSN = _T("-psn_"); | |
613 | if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 ) | |
614 | { | |
615 | // remove this argument | |
616 | memmove(argv, argv + 1, argc--); | |
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 | bool wxApp::Initialized() | |
1015 | { | |
1016 | if (GetTopWindow()) | |
1017 | return TRUE; | |
1018 | else | |
1019 | return FALSE; | |
1020 | } | |
1021 | ||
1022 | int wxApp::MainLoop() | |
1023 | { | |
1024 | m_keepGoing = TRUE; | |
1025 | ||
1026 | while (m_keepGoing) | |
1027 | { | |
1028 | MacDoOneEvent() ; | |
1029 | } | |
1030 | ||
1031 | return 0; | |
1032 | } | |
1033 | ||
1034 | void wxApp::ExitMainLoop() | |
1035 | { | |
1036 | m_keepGoing = FALSE; | |
1037 | } | |
1038 | ||
1039 | // Is a message/event pending? | |
1040 | bool wxApp::Pending() | |
1041 | { | |
1042 | #if TARGET_CARBON | |
1043 | return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; | |
1044 | #else | |
1045 | EventRecord event ; | |
1046 | ||
1047 | return EventAvail( everyEvent , &event ) ; | |
1048 | #endif | |
1049 | } | |
1050 | ||
1051 | // Dispatch a message. | |
1052 | void wxApp::Dispatch() | |
1053 | { | |
1054 | MacDoOneEvent() ; | |
1055 | } | |
1056 | ||
1057 | void wxApp::OnIdle(wxIdleEvent& event) | |
1058 | { | |
1059 | wxAppBase::OnIdle(event); | |
1060 | ||
1061 | // If they are pending events, we must process them: pending events are | |
1062 | // either events to the threads other than main or events posted with | |
1063 | // wxPostEvent() functions | |
1064 | wxMacProcessNotifierAndPendingEvents(); | |
1065 | ||
1066 | if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) | |
1067 | wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); | |
1068 | } | |
1069 | ||
1070 | void wxApp::WakeUpIdle() | |
1071 | { | |
1072 | wxMacWakeUp() ; | |
1073 | } | |
1074 | ||
1075 | void wxApp::Exit() | |
1076 | { | |
1077 | wxApp::CleanUp(); | |
1078 | ::ExitToShell() ; | |
1079 | } | |
1080 | ||
1081 | void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) | |
1082 | { | |
1083 | if (GetTopWindow()) | |
1084 | GetTopWindow()->Close(TRUE); | |
1085 | } | |
1086 | ||
1087 | // Default behaviour: close the application with prompts. The | |
1088 | // user can veto the close, and therefore the end session. | |
1089 | void wxApp::OnQueryEndSession(wxCloseEvent& event) | |
1090 | { | |
1091 | if (GetTopWindow()) | |
1092 | { | |
1093 | if (!GetTopWindow()->Close(!event.CanVeto())) | |
1094 | event.Veto(TRUE); | |
1095 | } | |
1096 | } | |
1097 | ||
1098 | extern "C" void wxCYield() ; | |
1099 | void wxCYield() | |
1100 | { | |
1101 | wxYield() ; | |
1102 | } | |
1103 | ||
1104 | // Yield to other processes | |
1105 | ||
1106 | bool wxApp::Yield(bool onlyIfNeeded) | |
1107 | { | |
1108 | if (s_inYield) | |
1109 | { | |
1110 | if ( !onlyIfNeeded ) | |
1111 | { | |
1112 | wxFAIL_MSG( wxT("wxYield called recursively" ) ); | |
1113 | } | |
1114 | ||
1115 | return FALSE; | |
1116 | } | |
1117 | ||
1118 | s_inYield = TRUE; | |
1119 | ||
1120 | #if wxUSE_THREADS | |
1121 | YieldToAnyThread() ; | |
1122 | #endif | |
1123 | // by definition yield should handle all non-processed events | |
1124 | #if TARGET_CARBON | |
1125 | EventRef theEvent; | |
1126 | ||
1127 | OSStatus status = noErr ; | |
1128 | do | |
1129 | { | |
1130 | s_inReceiveEvent = true ; | |
1131 | status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; | |
1132 | s_inReceiveEvent = false ; | |
1133 | ||
1134 | if ( status == eventLoopTimedOutErr ) | |
1135 | { | |
1136 | // make sure next time the event loop will trigger idle events | |
1137 | sleepTime = kEventDurationNoWait ; | |
1138 | } | |
1139 | else if ( status == eventLoopQuitErr ) | |
1140 | { | |
1141 | // according to QA1061 this may also occur when a WakeUp Process | |
1142 | // is executed | |
1143 | } | |
1144 | else | |
1145 | { | |
1146 | MacHandleOneEvent( theEvent ) ; | |
1147 | ReleaseEvent(theEvent); | |
1148 | } | |
1149 | } while( status == noErr ) ; | |
1150 | #else | |
1151 | EventRecord event ; | |
1152 | ||
1153 | // having a larger value here leads to large performance slowdowns | |
1154 | // so we cannot give background apps more processor time here | |
1155 | // we do so however having a large sleep value in the main event loop | |
1156 | sleepTime = 0 ; | |
1157 | ||
1158 | while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) | |
1159 | { | |
1160 | MacHandleModifierEvents( &event ) ; | |
1161 | MacHandleOneEvent( &event ); | |
1162 | if ( event.what != kHighLevelEvent ) | |
1163 | SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; | |
1164 | } | |
1165 | MacHandleModifierEvents( &event ) ; | |
1166 | #endif | |
1167 | ||
1168 | wxMacProcessNotifierAndPendingEvents() ; | |
1169 | s_inYield = FALSE; | |
1170 | ||
1171 | return TRUE; | |
1172 | } | |
1173 | ||
1174 | // platform specifics | |
1175 | ||
1176 | void wxApp::MacSuspend( bool convertClipboard ) | |
1177 | { | |
1178 | #if !TARGET_CARBON | |
1179 | // we have to deactive the top level windows manually | |
1180 | ||
1181 | wxWindowListNode* node = wxTopLevelWindows.GetFirst(); | |
1182 | while (node) | |
1183 | { | |
1184 | wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data(); | |
1185 | #if TARGET_CARBON | |
1186 | #if 0 // having problems right now with that | |
1187 | if (!win->HasFlag(wxSTAY_ON_TOP)) | |
1188 | #endif | |
1189 | #endif | |
1190 | win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ; | |
1191 | ||
1192 | node = node->GetNext(); | |
1193 | } | |
1194 | ||
1195 | ::HideFloatingWindows() ; | |
1196 | #endif | |
1197 | s_lastMouseDown = 0 ; | |
1198 | ||
1199 | if( convertClipboard ) | |
1200 | { | |
1201 | MacConvertPrivateToPublicScrap() ; | |
1202 | } | |
1203 | } | |
1204 | ||
1205 | extern wxList wxModalDialogs; | |
1206 | ||
1207 | void wxApp::MacResume( bool convertClipboard ) | |
1208 | { | |
1209 | s_lastMouseDown = 0 ; | |
1210 | if( convertClipboard ) | |
1211 | { | |
1212 | MacConvertPublicToPrivateScrap() ; | |
1213 | } | |
1214 | ||
1215 | #if !TARGET_CARBON | |
1216 | ::ShowFloatingWindows() ; | |
1217 | // raise modal dialogs in case a non modal window was selected to activate the app | |
1218 | ||
1219 | wxNode* node = wxModalDialogs.GetFirst(); | |
1220 | while (node) | |
1221 | { | |
1222 | wxDialog* dialog = (wxDialog *) node->GetData(); | |
1223 | dialog->Raise(); | |
1224 | ||
1225 | node = node->GetNext(); | |
1226 | } | |
1227 | #endif | |
1228 | } | |
1229 | ||
1230 | void wxApp::MacConvertPrivateToPublicScrap() | |
1231 | { | |
1232 | } | |
1233 | ||
1234 | void wxApp::MacConvertPublicToPrivateScrap() | |
1235 | { | |
1236 | } | |
1237 | ||
1238 | void wxApp::MacDoOneEvent() | |
1239 | { | |
1240 | #if TARGET_CARBON | |
1241 | EventRef theEvent; | |
1242 | ||
1243 | s_inReceiveEvent = true ; | |
1244 | OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ; | |
1245 | s_inReceiveEvent = false ; | |
1246 | if ( status == eventLoopTimedOutErr ) | |
1247 | { | |
1248 | if ( wxTheApp->ProcessIdle() ) | |
1249 | sleepTime = kEventDurationNoWait ; | |
1250 | else | |
1251 | sleepTime = kEventDurationForever ; | |
1252 | } | |
1253 | else if ( status == eventLoopQuitErr ) | |
1254 | { | |
1255 | // according to QA1061 this may also occur when a WakeUp Process | |
1256 | // is executed | |
1257 | } | |
1258 | else | |
1259 | { | |
1260 | MacHandleOneEvent( theEvent ) ; | |
1261 | ReleaseEvent(theEvent); | |
1262 | sleepTime = kEventDurationNoWait ; | |
1263 | } | |
1264 | #else | |
1265 | EventRecord event ; | |
1266 | ||
1267 | EventMask eventMask = everyEvent ; | |
1268 | ||
1269 | if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn)) | |
1270 | { | |
1271 | MacHandleModifierEvents( &event ) ; | |
1272 | MacHandleOneEvent( &event ); | |
1273 | } | |
1274 | else | |
1275 | { | |
1276 | MacHandleModifierEvents( &event ) ; | |
1277 | // idlers | |
1278 | WindowPtr window = ::FrontWindow() ; | |
1279 | if ( window ) | |
1280 | ::IdleControls( window ) ; | |
1281 | ||
1282 | if ( wxTheApp->ProcessIdle() ) | |
1283 | sleepTime = 0 ; | |
1284 | else | |
1285 | sleepTime = GetCaretTime() / 2 ; | |
1286 | } | |
1287 | if ( event.what != kHighLevelEvent ) | |
1288 | SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; | |
1289 | #endif | |
1290 | // repeaters | |
1291 | ||
1292 | DeletePendingObjects() ; | |
1293 | wxMacProcessNotifierAndPendingEvents() ; | |
1294 | } | |
1295 | ||
1296 | void wxApp::MacHandleOneEvent( WXEVENTREF evr ) | |
1297 | { | |
1298 | #if TARGET_CARBON | |
1299 | EventTargetRef theTarget; | |
1300 | theTarget = GetEventDispatcherTarget(); | |
1301 | m_macCurrentEvent = evr ; | |
1302 | SendEventToEventTarget ((EventRef) evr , theTarget); | |
1303 | #else | |
1304 | EventRecord* ev = (EventRecord*) evr ; | |
1305 | m_macCurrentEvent = ev ; | |
1306 | ||
1307 | wxApp::sm_lastMessageTime = ev->when ; | |
1308 | ||
1309 | switch (ev->what) | |
1310 | { | |
1311 | case mouseDown: | |
1312 | MacHandleMouseDownEvent( ev ) ; | |
1313 | if ( ev->modifiers & controlKey ) | |
1314 | s_lastMouseDown = 2; | |
1315 | else | |
1316 | s_lastMouseDown = 1; | |
1317 | break; | |
1318 | case mouseUp: | |
1319 | if ( s_lastMouseDown == 2 ) | |
1320 | { | |
1321 | ev->modifiers |= controlKey ; | |
1322 | } | |
1323 | else | |
1324 | { | |
1325 | ev->modifiers &= ~controlKey ; | |
1326 | } | |
1327 | MacHandleMouseUpEvent( ev ) ; | |
1328 | s_lastMouseDown = 0; | |
1329 | break; | |
1330 | case activateEvt: | |
1331 | MacHandleActivateEvent( ev ) ; | |
1332 | break; | |
1333 | case updateEvt: | |
1334 | MacHandleUpdateEvent( ev ) ; | |
1335 | break; | |
1336 | case keyDown: | |
1337 | case autoKey: | |
1338 | MacHandleKeyDownEvent( ev ) ; | |
1339 | break; | |
1340 | case keyUp: | |
1341 | MacHandleKeyUpEvent( ev ) ; | |
1342 | break; | |
1343 | case diskEvt: | |
1344 | MacHandleDiskEvent( ev ) ; | |
1345 | break; | |
1346 | case osEvt: | |
1347 | MacHandleOSEvent( ev ) ; | |
1348 | break; | |
1349 | case kHighLevelEvent: | |
1350 | MacHandleHighLevelEvent( ev ) ; | |
1351 | break; | |
1352 | default: | |
1353 | break; | |
1354 | } | |
1355 | #endif | |
1356 | wxMacProcessNotifierAndPendingEvents() ; | |
1357 | } | |
1358 | ||
1359 | #if !TARGET_CARBON | |
1360 | bool s_macIsInModalLoop = false ; | |
1361 | ||
1362 | void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) | |
1363 | { | |
1364 | EventRecord* ev = (EventRecord*) evr ; | |
1365 | if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL ) | |
1366 | { | |
1367 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
1368 | ||
1369 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1370 | event.m_controlDown = ev->modifiers & controlKey; | |
1371 | event.m_altDown = ev->modifiers & optionKey; | |
1372 | event.m_metaDown = ev->modifiers & cmdKey; | |
1373 | ||
1374 | event.m_x = ev->where.h; | |
1375 | event.m_y = ev->where.v; | |
1376 | event.m_timeStamp = ev->when; | |
1377 | wxWindow* focus = wxWindow::FindFocus() ; | |
1378 | event.SetEventObject(focus); | |
1379 | ||
1380 | if ( (ev->modifiers ^ s_lastModifiers ) & controlKey ) | |
1381 | { | |
1382 | event.m_keyCode = WXK_CONTROL ; | |
1383 | event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1384 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1385 | } | |
1386 | if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey ) | |
1387 | { | |
1388 | event.m_keyCode = WXK_SHIFT ; | |
1389 | event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1390 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1391 | } | |
1392 | if ( (ev->modifiers ^ s_lastModifiers ) & optionKey ) | |
1393 | { | |
1394 | event.m_keyCode = WXK_ALT ; | |
1395 | event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1396 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1397 | } | |
1398 | if ( ( ev->modifiers ^ s_lastModifiers ) & cmdKey ) | |
1399 | { | |
1400 | event.m_keyCode = WXK_COMMAND ; | |
1401 | event.SetEventType( ( ev->modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1402 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1403 | } | |
1404 | s_lastModifiers = ev->modifiers ; | |
1405 | } | |
1406 | } | |
1407 | ||
1408 | void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) | |
1409 | { | |
1410 | // we must avoid reentrancy problems when processing high level events eg printing | |
1411 | bool former = s_inYield ; | |
1412 | s_inYield = TRUE ; | |
1413 | EventRecord* ev = (EventRecord*) evr ; | |
1414 | ::AEProcessAppleEvent( ev ) ; | |
1415 | s_inYield = former ; | |
1416 | } | |
1417 | ||
1418 | void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) | |
1419 | { | |
1420 | EventRecord* ev = (EventRecord*) evr ; | |
1421 | wxToolTip::RemoveToolTips() ; | |
1422 | ||
1423 | WindowRef window; | |
1424 | WindowRef frontWindow = ::FrontNonFloatingWindow() ; | |
1425 | WindowAttributes frontWindowAttributes = NULL ; | |
1426 | if ( frontWindow ) | |
1427 | ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; | |
1428 | ||
1429 | short windowPart = ::FindWindow(ev->where, &window); | |
1430 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1431 | if ( wxPendingDelete.Member(win) ) | |
1432 | return ; | |
1433 | ||
1434 | BitMap screenBits; | |
1435 | GetQDGlobalsScreenBits( &screenBits ); | |
1436 | ||
1437 | switch (windowPart) | |
1438 | { | |
1439 | case inMenuBar : | |
1440 | if ( s_macIsInModalLoop ) | |
1441 | { | |
1442 | SysBeep ( 30 ) ; | |
1443 | } | |
1444 | else | |
1445 | { | |
1446 | UInt32 menuresult = MenuSelect(ev->where) ; | |
1447 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ); | |
1448 | s_lastMouseDown = 0; | |
1449 | } | |
1450 | break ; | |
1451 | case inSysWindow : | |
1452 | SystemClick( ev , window ) ; | |
1453 | s_lastMouseDown = 0; | |
1454 | break ; | |
1455 | case inDrag : | |
1456 | if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) ) | |
1457 | { | |
1458 | SysBeep ( 30 ) ; | |
1459 | } | |
1460 | else | |
1461 | { | |
1462 | DragWindow(window, ev->where, &screenBits.bounds); | |
1463 | if (win) | |
1464 | { | |
1465 | GrafPtr port ; | |
1466 | GetPort( &port ) ; | |
1467 | Point pt = { 0, 0 } ; | |
1468 | SetPortWindowPort(window) ; | |
1469 | LocalToGlobal( &pt ) ; | |
1470 | SetPort( port ) ; | |
1471 | win->SetSize( pt.h , pt.v , -1 , | |
1472 | -1 , wxSIZE_USE_EXISTING); | |
1473 | } | |
1474 | s_lastMouseDown = 0; | |
1475 | } | |
1476 | break ; | |
1477 | case inGoAway: | |
1478 | if (TrackGoAway(window, ev->where)) | |
1479 | { | |
1480 | if ( win ) | |
1481 | win->Close() ; | |
1482 | } | |
1483 | s_lastMouseDown = 0; | |
1484 | break; | |
1485 | case inGrow: | |
1486 | { | |
1487 | Rect newContentRect ; | |
1488 | Rect constraintRect ; | |
1489 | constraintRect.top = win->GetMinHeight() ; | |
1490 | if ( constraintRect.top == -1 ) | |
1491 | constraintRect.top = 0 ; | |
1492 | constraintRect.left = win->GetMinWidth() ; | |
1493 | if ( constraintRect.left == -1 ) | |
1494 | constraintRect.left = 0 ; | |
1495 | constraintRect.right = win->GetMaxWidth() ; | |
1496 | if ( constraintRect.right == -1 ) | |
1497 | constraintRect.right = 32000 ; | |
1498 | constraintRect.bottom = win->GetMaxHeight() ; | |
1499 | if ( constraintRect.bottom == -1 ) | |
1500 | constraintRect.bottom = 32000 ; | |
1501 | ||
1502 | Boolean growResult = ResizeWindow( window , ev->where , | |
1503 | &constraintRect , &newContentRect ) ; | |
1504 | if ( growResult ) | |
1505 | { | |
1506 | win->SetSize( newContentRect.left , newContentRect.top , | |
1507 | newContentRect.right - newContentRect.left , | |
1508 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); | |
1509 | } | |
1510 | s_lastMouseDown = 0; | |
1511 | } | |
1512 | break; | |
1513 | case inZoomIn: | |
1514 | case inZoomOut: | |
1515 | if (TrackBox(window, ev->where, windowPart)) | |
1516 | { | |
1517 | // TODO setup size event | |
1518 | ZoomWindow( window , windowPart , false ) ; | |
1519 | if (win) | |
1520 | { | |
1521 | Rect tempRect ; | |
1522 | GrafPtr port ; | |
1523 | GetPort( &port ) ; | |
1524 | Point pt = { 0, 0 } ; | |
1525 | SetPortWindowPort(window) ; | |
1526 | LocalToGlobal( &pt ) ; | |
1527 | SetPort( port ) ; | |
1528 | ||
1529 | GetWindowPortBounds(window, &tempRect ) ; | |
1530 | win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left , | |
1531 | tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); | |
1532 | } | |
1533 | } | |
1534 | s_lastMouseDown = 0; | |
1535 | break; | |
1536 | case inCollapseBox : | |
1537 | // TODO setup size event | |
1538 | s_lastMouseDown = 0; | |
1539 | break ; | |
1540 | ||
1541 | case inContent : | |
1542 | { | |
1543 | GrafPtr port ; | |
1544 | GetPort( &port ) ; | |
1545 | SetPortWindowPort(window) ; | |
1546 | SetPort( port ) ; | |
1547 | } | |
1548 | if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) | |
1549 | { | |
1550 | if ( s_macIsInModalLoop ) | |
1551 | { | |
1552 | SysBeep ( 30 ) ; | |
1553 | } | |
1554 | else if ( UMAIsWindowFloating( window ) ) | |
1555 | { | |
1556 | if ( win ) | |
1557 | win->MacMouseDown( ev , windowPart ) ; | |
1558 | } | |
1559 | else | |
1560 | { | |
1561 | // Activate window first | |
1562 | ::SelectWindow( window ) ; | |
1563 | ||
1564 | // Send event later | |
1565 | if ( win ) | |
1566 | win->MacMouseDown( ev , windowPart ) ; | |
1567 | } | |
1568 | } | |
1569 | else | |
1570 | { | |
1571 | if ( win ) | |
1572 | win->MacMouseDown( ev , windowPart ) ; | |
1573 | } | |
1574 | break ; | |
1575 | default: | |
1576 | break; | |
1577 | } | |
1578 | } | |
1579 | ||
1580 | void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) | |
1581 | { | |
1582 | EventRecord* ev = (EventRecord*) evr ; | |
1583 | WindowRef window; | |
1584 | ||
1585 | short windowPart = inNoWindow ; | |
1586 | if ( wxTheApp->s_captureWindow ) | |
1587 | { | |
1588 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
1589 | windowPart = inContent ; | |
1590 | } | |
1591 | else | |
1592 | { | |
1593 | windowPart = ::FindWindow(ev->where, &window) ; | |
1594 | } | |
1595 | ||
1596 | switch (windowPart) | |
1597 | { | |
1598 | case inMenuBar : | |
1599 | break ; | |
1600 | case inSysWindow : | |
1601 | break ; | |
1602 | default: | |
1603 | { | |
1604 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1605 | if ( win ) | |
1606 | win->MacMouseUp( ev , windowPart ) ; | |
1607 | } | |
1608 | break; | |
1609 | } | |
1610 | } | |
1611 | ||
1612 | #endif | |
1613 | ||
1614 | long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
1615 | long wxMacTranslateKey(unsigned char key, unsigned char code) | |
1616 | { | |
1617 | long retval = key ; | |
1618 | switch (key) | |
1619 | { | |
1620 | case kHomeCharCode : | |
1621 | retval = WXK_HOME; | |
1622 | break; | |
1623 | case kEnterCharCode : | |
1624 | retval = WXK_RETURN; | |
1625 | break; | |
1626 | case kEndCharCode : | |
1627 | retval = WXK_END; | |
1628 | break; | |
1629 | case kHelpCharCode : | |
1630 | retval = WXK_HELP; | |
1631 | break; | |
1632 | case kBackspaceCharCode : | |
1633 | retval = WXK_BACK; | |
1634 | break; | |
1635 | case kTabCharCode : | |
1636 | retval = WXK_TAB; | |
1637 | break; | |
1638 | case kPageUpCharCode : | |
1639 | retval = WXK_PAGEUP; | |
1640 | break; | |
1641 | case kPageDownCharCode : | |
1642 | retval = WXK_PAGEDOWN; | |
1643 | break; | |
1644 | case kReturnCharCode : | |
1645 | retval = WXK_RETURN; | |
1646 | break; | |
1647 | case kFunctionKeyCharCode : | |
1648 | { | |
1649 | switch( code ) | |
1650 | { | |
1651 | case 0x7a : | |
1652 | retval = WXK_F1 ; | |
1653 | break; | |
1654 | case 0x78 : | |
1655 | retval = WXK_F2 ; | |
1656 | break; | |
1657 | case 0x63 : | |
1658 | retval = WXK_F3 ; | |
1659 | break; | |
1660 | case 0x76 : | |
1661 | retval = WXK_F4 ; | |
1662 | break; | |
1663 | case 0x60 : | |
1664 | retval = WXK_F5 ; | |
1665 | break; | |
1666 | case 0x61 : | |
1667 | retval = WXK_F6 ; | |
1668 | break; | |
1669 | case 0x62: | |
1670 | retval = WXK_F7 ; | |
1671 | break; | |
1672 | case 0x64 : | |
1673 | retval = WXK_F8 ; | |
1674 | break; | |
1675 | case 0x65 : | |
1676 | retval = WXK_F9 ; | |
1677 | break; | |
1678 | case 0x6D : | |
1679 | retval = WXK_F10 ; | |
1680 | break; | |
1681 | case 0x67 : | |
1682 | retval = WXK_F11 ; | |
1683 | break; | |
1684 | case 0x6F : | |
1685 | retval = WXK_F12 ; | |
1686 | break; | |
1687 | case 0x69 : | |
1688 | retval = WXK_F13 ; | |
1689 | break; | |
1690 | case 0x6B : | |
1691 | retval = WXK_F14 ; | |
1692 | break; | |
1693 | case 0x71 : | |
1694 | retval = WXK_F15 ; | |
1695 | break; | |
1696 | } | |
1697 | } | |
1698 | break ; | |
1699 | case kEscapeCharCode : | |
1700 | retval = WXK_ESCAPE ; | |
1701 | break ; | |
1702 | case kLeftArrowCharCode : | |
1703 | retval = WXK_LEFT ; | |
1704 | break ; | |
1705 | case kRightArrowCharCode : | |
1706 | retval = WXK_RIGHT ; | |
1707 | break ; | |
1708 | case kUpArrowCharCode : | |
1709 | retval = WXK_UP ; | |
1710 | break ; | |
1711 | case kDownArrowCharCode : | |
1712 | retval = WXK_DOWN ; | |
1713 | break ; | |
1714 | case kDeleteCharCode : | |
1715 | retval = WXK_DELETE ; | |
1716 | default: | |
1717 | break ; | |
1718 | } // end switch | |
1719 | ||
1720 | return retval; | |
1721 | } | |
1722 | ||
1723 | #if !TARGET_CARBON | |
1724 | void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) | |
1725 | { | |
1726 | EventRecord* ev = (EventRecord*) evr ; | |
1727 | wxToolTip::RemoveToolTips() ; | |
1728 | ||
1729 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1730 | if ( HiWord( menuresult ) ) | |
1731 | { | |
1732 | if ( !s_macIsInModalLoop ) | |
1733 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; | |
1734 | } | |
1735 | else | |
1736 | { | |
1737 | wxWindow* focus = wxWindow::FindFocus() ; | |
1738 | ||
1739 | if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false ) | |
1740 | { | |
1741 | #if 0 | |
1742 | // we must handle control keys the other way round, otherwise text content is updated too late | |
1743 | // has not been handled -> perform default | |
1744 | wxControl* control = wxDynamicCast( focus , wxControl ) ; | |
1745 | if ( control && control->GetMacControl() != NULL ) | |
1746 | { | |
1747 | short keycode ; | |
1748 | short keychar ; | |
1749 | keychar = short(ev->message & charCodeMask); | |
1750 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
1751 | ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ; | |
1752 | } | |
1753 | #endif | |
1754 | } | |
1755 | } | |
1756 | } | |
1757 | ||
1758 | void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) | |
1759 | { | |
1760 | EventRecord* ev = (EventRecord*) evr ; | |
1761 | wxToolTip::RemoveToolTips() ; | |
1762 | ||
1763 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1764 | if ( HiWord( menuresult ) ) | |
1765 | { | |
1766 | } | |
1767 | else | |
1768 | { | |
1769 | MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ; | |
1770 | } | |
1771 | } | |
1772 | ||
1773 | #endif | |
1774 | ||
1775 | bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) | |
1776 | { | |
1777 | if ( !focus ) | |
1778 | return false ; | |
1779 | ||
1780 | short keycode ; | |
1781 | short keychar ; | |
1782 | keychar = short(keymessage & charCodeMask); | |
1783 | keycode = short(keymessage & keyCodeMask) >> 8 ; | |
1784 | ||
1785 | if ( modifiers & ( controlKey|shiftKey|optionKey ) ) | |
1786 | { | |
1787 | // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier | |
1788 | // and look at the character after | |
1789 | UInt32 state = 0; | |
1790 | UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); | |
1791 | keychar = short(keyInfo & charCodeMask); | |
1792 | keycode = short(keyInfo & keyCodeMask) >> 8 ; | |
1793 | } | |
1794 | long keyval = wxMacTranslateKey(keychar, keycode) ; | |
1795 | long realkeyval = keyval ; | |
1796 | if ( keyval == keychar ) | |
1797 | { | |
1798 | // 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) | |
1799 | realkeyval = short(keymessage & charCodeMask) ; | |
1800 | keyval = wxToupper( keyval ) ; | |
1801 | } | |
1802 | ||
1803 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
1804 | bool handled = false ; | |
1805 | event.m_shiftDown = modifiers & shiftKey; | |
1806 | event.m_controlDown = modifiers & controlKey; | |
1807 | event.m_altDown = modifiers & optionKey; | |
1808 | event.m_metaDown = modifiers & cmdKey; | |
1809 | event.m_keyCode = keyval ; | |
1810 | ||
1811 | event.m_x = wherex; | |
1812 | event.m_y = wherey; | |
1813 | event.m_timeStamp = when; | |
1814 | event.SetEventObject(focus); | |
1815 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1816 | if ( handled && event.GetSkipped() ) | |
1817 | handled = false ; | |
1818 | if ( !handled ) | |
1819 | { | |
1820 | #if wxUSE_ACCEL | |
1821 | if (!handled) | |
1822 | { | |
1823 | wxWindow *ancestor = focus; | |
1824 | while (ancestor) | |
1825 | { | |
1826 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
1827 | if (command != -1) | |
1828 | { | |
1829 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
1830 | handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
1831 | break; | |
1832 | } | |
1833 | if (ancestor->IsTopLevel()) | |
1834 | break; | |
1835 | ancestor = ancestor->GetParent(); | |
1836 | } | |
1837 | } | |
1838 | #endif // wxUSE_ACCEL | |
1839 | } | |
1840 | if (!handled) | |
1841 | { | |
1842 | event.Skip( FALSE ) ; | |
1843 | event.SetEventType( wxEVT_CHAR ) ; | |
1844 | // raw value again | |
1845 | event.m_keyCode = realkeyval ; | |
1846 | ||
1847 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1848 | if ( handled && event.GetSkipped() ) | |
1849 | handled = false ; | |
1850 | } | |
1851 | if ( !handled && | |
1852 | (keyval == WXK_TAB) && | |
1853 | // CS: copied the change below from wxGTK | |
1854 | // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may | |
1855 | // have this style, yet choose not to process this particular TAB in which | |
1856 | // case TAB must still work as a navigational character | |
1857 | #if 0 | |
1858 | (!focus->HasFlag(wxTE_PROCESS_TAB)) && | |
1859 | #endif | |
1860 | (focus->GetParent()) && | |
1861 | (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) | |
1862 | { | |
1863 | wxNavigationKeyEvent new_event; | |
1864 | new_event.SetEventObject( focus ); | |
1865 | new_event.SetDirection( !event.ShiftDown() ); | |
1866 | /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ | |
1867 | new_event.SetWindowChange( event.ControlDown() ); | |
1868 | new_event.SetCurrentFocus( focus ); | |
1869 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
1870 | if ( handled && new_event.GetSkipped() ) | |
1871 | handled = false ; | |
1872 | } | |
1873 | // backdoor handler for default return and command escape | |
1874 | if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) ) | |
1875 | { | |
1876 | // if window is not having a focus still testing for default enter or cancel | |
1877 | // TODO add the UMA version for ActiveNonFloatingWindow | |
1878 | wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; | |
1879 | if ( focus ) | |
1880 | { | |
1881 | if ( keyval == WXK_RETURN ) | |
1882 | { | |
1883 | wxButton *def = wxDynamicCast(focus->GetDefaultItem(), | |
1884 | wxButton); | |
1885 | if ( def && def->IsEnabled() ) | |
1886 | { | |
1887 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
1888 | event.SetEventObject(def); | |
1889 | def->Command(event); | |
1890 | return true ; | |
1891 | } | |
1892 | } | |
1893 | /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ | |
1894 | else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) | |
1895 | { | |
1896 | wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); | |
1897 | new_event.SetEventObject( focus ); | |
1898 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
1899 | } | |
1900 | } | |
1901 | } | |
1902 | return handled ; | |
1903 | } | |
1904 | ||
1905 | bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) | |
1906 | { | |
1907 | if ( !focus ) | |
1908 | return false ; | |
1909 | ||
1910 | short keycode ; | |
1911 | short keychar ; | |
1912 | keychar = short(keymessage & charCodeMask); | |
1913 | keycode = short(keymessage & keyCodeMask) >> 8 ; | |
1914 | if ( modifiers & ( controlKey|shiftKey|optionKey ) ) | |
1915 | { | |
1916 | // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier | |
1917 | // and look at the character after | |
1918 | UInt32 state = 0; | |
1919 | UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); | |
1920 | keychar = short(keyInfo & charCodeMask); | |
1921 | keycode = short(keyInfo & keyCodeMask) >> 8 ; | |
1922 | } | |
1923 | long keyval = wxMacTranslateKey(keychar, keycode) ; | |
1924 | ||
1925 | if ( keyval == keychar ) | |
1926 | { | |
1927 | keyval = wxToupper( keyval ) ; | |
1928 | } | |
1929 | bool handled = false ; | |
1930 | ||
1931 | wxKeyEvent event(wxEVT_KEY_UP); | |
1932 | event.m_shiftDown = modifiers & shiftKey; | |
1933 | event.m_controlDown = modifiers & controlKey; | |
1934 | event.m_altDown = modifiers & optionKey; | |
1935 | event.m_metaDown = modifiers & cmdKey; | |
1936 | event.m_keyCode = keyval ; | |
1937 | ||
1938 | event.m_x = wherex; | |
1939 | event.m_y = wherey; | |
1940 | event.m_timeStamp = when; | |
1941 | event.SetEventObject(focus); | |
1942 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1943 | ||
1944 | return handled ; | |
1945 | } | |
1946 | ||
1947 | #if !TARGET_CARBON | |
1948 | void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) | |
1949 | { | |
1950 | EventRecord* ev = (EventRecord*) evr ; | |
1951 | WindowRef window = (WindowRef) ev->message ; | |
1952 | if ( window ) | |
1953 | { | |
1954 | bool activate = (ev->modifiers & activeFlag ) ; | |
1955 | WindowClass wclass ; | |
1956 | ::GetWindowClass ( window , &wclass ) ; | |
1957 | if ( wclass == kFloatingWindowClass ) | |
1958 | { | |
1959 | // if it is a floater we activate/deactivate the front non-floating window instead | |
1960 | window = ::FrontNonFloatingWindow() ; | |
1961 | } | |
1962 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1963 | if ( win ) | |
1964 | win->MacActivate( ev->when , activate ) ; | |
1965 | } | |
1966 | } | |
1967 | ||
1968 | void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) | |
1969 | { | |
1970 | EventRecord* ev = (EventRecord*) evr ; | |
1971 | WindowRef window = (WindowRef) ev->message ; | |
1972 | wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; | |
1973 | if ( win ) | |
1974 | { | |
1975 | if ( !wxPendingDelete.Member(win) ) | |
1976 | win->MacUpdate( ev->when ) ; | |
1977 | } | |
1978 | else | |
1979 | { | |
1980 | // since there is no way of telling this foreign window to update itself | |
1981 | // we have to invalidate the update region otherwise we keep getting the same | |
1982 | // event over and over again | |
1983 | BeginUpdate( window ) ; | |
1984 | EndUpdate( window ) ; | |
1985 | } | |
1986 | } | |
1987 | ||
1988 | void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) | |
1989 | { | |
1990 | EventRecord* ev = (EventRecord*) evr ; | |
1991 | if ( HiWord( ev->message ) != noErr ) | |
1992 | { | |
1993 | OSErr err ; | |
1994 | Point point ; | |
1995 | SetPt( &point , 100 , 100 ) ; | |
1996 | ||
1997 | err = DIBadMount( point , ev->message ) ; | |
1998 | wxASSERT( err == noErr ) ; | |
1999 | } | |
2000 | } | |
2001 | ||
2002 | void wxApp::MacHandleOSEvent( WXEVENTREF evr ) | |
2003 | { | |
2004 | EventRecord* ev = (EventRecord*) evr ; | |
2005 | switch( ( ev->message & osEvtMessageMask ) >> 24 ) | |
2006 | { | |
2007 | case suspendResumeMessage : | |
2008 | { | |
2009 | bool isResuming = ev->message & resumeFlag ; | |
2010 | bool convertClipboard = ev->message & convertClipboardFlag ; | |
2011 | ||
2012 | bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; | |
2013 | if ( isResuming ) | |
2014 | { | |
2015 | WindowRef oldFrontWindow = NULL ; | |
2016 | WindowRef newFrontWindow = NULL ; | |
2017 | ||
2018 | // in case we don't take care of activating ourselves, we have to synchronize | |
2019 | // our idea of the active window with the process manager's - which it already activated | |
2020 | ||
2021 | if ( !doesActivate ) | |
2022 | oldFrontWindow = ::FrontNonFloatingWindow() ; | |
2023 | ||
2024 | MacResume( convertClipboard ) ; | |
2025 | ||
2026 | newFrontWindow = ::FrontNonFloatingWindow() ; | |
2027 | ||
2028 | if ( oldFrontWindow ) | |
2029 | { | |
2030 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; | |
2031 | if ( win ) | |
2032 | win->MacActivate( ev->when , false ) ; | |
2033 | } | |
2034 | if ( newFrontWindow ) | |
2035 | { | |
2036 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; | |
2037 | if ( win ) | |
2038 | win->MacActivate( ev->when , true ) ; | |
2039 | } | |
2040 | } | |
2041 | else | |
2042 | { | |
2043 | MacSuspend( convertClipboard ) ; | |
2044 | } | |
2045 | } | |
2046 | break ; | |
2047 | case mouseMovedMessage : | |
2048 | { | |
2049 | WindowRef window; | |
2050 | ||
2051 | wxWindow* currentMouseWindow = NULL ; | |
2052 | ||
2053 | if (s_captureWindow ) | |
2054 | { | |
2055 | currentMouseWindow = s_captureWindow ; | |
2056 | } | |
2057 | else | |
2058 | { | |
2059 | wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , | |
2060 | ¤tMouseWindow ) ; | |
2061 | } | |
2062 | ||
2063 | if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) | |
2064 | { | |
2065 | wxMouseEvent event ; | |
2066 | ||
2067 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
2068 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
2069 | ||
2070 | event.m_leftDown = isDown && !controlDown; | |
2071 | event.m_middleDown = FALSE; | |
2072 | event.m_rightDown = isDown && controlDown; | |
2073 | event.m_shiftDown = ev->modifiers & shiftKey; | |
2074 | event.m_controlDown = ev->modifiers & controlKey; | |
2075 | event.m_altDown = ev->modifiers & optionKey; | |
2076 | event.m_metaDown = ev->modifiers & cmdKey; | |
2077 | event.m_x = ev->where.h; | |
2078 | event.m_y = ev->where.v; | |
2079 | event.m_timeStamp = ev->when; | |
2080 | event.SetEventObject(this); | |
2081 | ||
2082 | if ( wxWindow::s_lastMouseWindow ) | |
2083 | { | |
2084 | wxMouseEvent eventleave(event); | |
2085 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
2086 | wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
2087 | eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; | |
2088 | ||
2089 | wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); | |
2090 | } | |
2091 | if ( currentMouseWindow ) | |
2092 | { | |
2093 | wxMouseEvent evententer(event); | |
2094 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
2095 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
2096 | evententer.SetEventObject( currentMouseWindow ) ; | |
2097 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
2098 | } | |
2099 | wxWindow::s_lastMouseWindow = currentMouseWindow ; | |
2100 | } | |
2101 | ||
2102 | short windowPart = inNoWindow ; | |
2103 | ||
2104 | if ( s_captureWindow ) | |
2105 | { | |
2106 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
2107 | windowPart = inContent ; | |
2108 | } | |
2109 | else | |
2110 | { | |
2111 | windowPart = ::FindWindow(ev->where, &window); | |
2112 | } | |
2113 | ||
2114 | switch (windowPart) | |
2115 | { | |
2116 | case inContent : | |
2117 | { | |
2118 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
2119 | if ( win ) | |
2120 | win->MacMouseMoved( ev , windowPart ) ; | |
2121 | else | |
2122 | { | |
2123 | if ( wxIsBusy() ) | |
2124 | { | |
2125 | } | |
2126 | else | |
2127 | UMAShowArrowCursor(); | |
2128 | } | |
2129 | } | |
2130 | break; | |
2131 | default : | |
2132 | { | |
2133 | if ( wxIsBusy() ) | |
2134 | { | |
2135 | } | |
2136 | else | |
2137 | UMAShowArrowCursor(); | |
2138 | } | |
2139 | break ; | |
2140 | } | |
2141 | } | |
2142 | break ; | |
2143 | ||
2144 | } | |
2145 | } | |
2146 | #else | |
2147 | ||
2148 | void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp) | |
2149 | { | |
2150 | WindowRef window; | |
2151 | ||
2152 | wxWindow* currentMouseWindow = NULL ; | |
2153 | ||
2154 | if (s_captureWindow ) | |
2155 | { | |
2156 | currentMouseWindow = s_captureWindow ; | |
2157 | } | |
2158 | else | |
2159 | { | |
2160 | wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , ¤tMouseWindow ) ; | |
2161 | } | |
2162 | ||
2163 | if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) | |
2164 | { | |
2165 | wxMouseEvent event ; | |
2166 | ||
2167 | bool isDown = !(modifiers & btnState) ; // 1 is for up | |
2168 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
2169 | ||
2170 | event.m_leftDown = isDown && !controlDown; | |
2171 | ||
2172 | event.m_middleDown = FALSE; | |
2173 | event.m_rightDown = isDown && controlDown; | |
2174 | ||
2175 | event.m_shiftDown = modifiers & shiftKey; | |
2176 | event.m_controlDown = modifiers & controlKey; | |
2177 | event.m_altDown = modifiers & optionKey; | |
2178 | event.m_metaDown = modifiers & cmdKey; | |
2179 | ||
2180 | event.m_x = x; | |
2181 | event.m_y = y; | |
2182 | event.m_timeStamp = timestamp; | |
2183 | ||
2184 | if ( wxWindow::s_lastMouseWindow ) | |
2185 | { | |
2186 | wxMouseEvent eventleave(event); | |
2187 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
2188 | wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
2189 | eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; | |
2190 | ||
2191 | #if wxUSE_TOOLTIPS | |
2192 | wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave); | |
2193 | #endif // wxUSE_TOOLTIPS | |
2194 | wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); | |
2195 | } | |
2196 | if ( currentMouseWindow ) | |
2197 | { | |
2198 | wxMouseEvent evententer(event); | |
2199 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
2200 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
2201 | evententer.SetEventObject( currentMouseWindow ) ; | |
2202 | #if wxUSE_TOOLTIPS | |
2203 | wxToolTip::RelayEvent( currentMouseWindow , evententer); | |
2204 | #endif // wxUSE_TOOLTIPS | |
2205 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
2206 | } | |
2207 | wxWindow::s_lastMouseWindow = currentMouseWindow ; | |
2208 | } | |
2209 | ||
2210 | short windowPart = inNoWindow ; | |
2211 | ||
2212 | if ( s_captureWindow ) | |
2213 | { | |
2214 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
2215 | windowPart = inContent ; | |
2216 | } | |
2217 | else | |
2218 | { | |
2219 | Point pt= { y , x } ; | |
2220 | windowPart = ::FindWindow(pt , &window); | |
2221 | } | |
2222 | ||
2223 | switch (windowPart) | |
2224 | { | |
2225 | case inContent : | |
2226 | { | |
2227 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
2228 | if ( win ) | |
2229 | win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ; | |
2230 | else | |
2231 | { | |
2232 | if ( wxIsBusy() ) | |
2233 | { | |
2234 | } | |
2235 | else | |
2236 | UMAShowArrowCursor(); | |
2237 | } | |
2238 | } | |
2239 | break; | |
2240 | default : | |
2241 | { | |
2242 | if ( wxIsBusy() ) | |
2243 | { | |
2244 | } | |
2245 | else | |
2246 | UMAShowArrowCursor(); | |
2247 | } | |
2248 | break ; | |
2249 | } | |
2250 | } | |
2251 | #endif | |
2252 | ||
2253 | void wxApp::MacHandleMenuCommand( wxUint32 id ) | |
2254 | { | |
2255 | wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; | |
2256 | wxFrame* frame = mbar->GetFrame(); | |
2257 | wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") ); | |
2258 | if ( frame ) | |
2259 | { | |
2260 | frame->ProcessCommand(id); | |
2261 | } | |
2262 | } | |
2263 | ||
2264 | #if !TARGET_CARBON | |
2265 | void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) | |
2266 | { | |
2267 | if (macMenuId == 0) | |
2268 | return; // no menu item selected | |
2269 | ||
2270 | if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1) | |
2271 | { | |
2272 | #if ! TARGET_CARBON | |
2273 | Str255 deskAccessoryName ; | |
2274 | GrafPtr savedPort ; | |
2275 | ||
2276 | GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName); | |
2277 | GetPort(&savedPort); | |
2278 | OpenDeskAcc(deskAccessoryName); | |
2279 | SetPort(savedPort); | |
2280 | #endif | |
2281 | } | |
2282 | else | |
2283 | { | |
2284 | MenuCommand id ; | |
2285 | GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ; | |
2286 | MacHandleMenuCommand( id ) ; | |
2287 | } | |
2288 | HiliteMenu(0); | |
2289 | } | |
2290 | #endif |