]>
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 | wxMacSetupConverters() ; | |
604 | ||
605 | s_macCursorRgn = ::NewRgn() ; | |
606 | ||
607 | // Mac OS X passes a process serial number command line argument when | |
608 | // the application is launched from the Finder. This argument must be | |
609 | // removed from the command line arguments before being handled by the | |
610 | // application (otherwise applications would need to handle it) | |
611 | if ( argc > 1 ) | |
612 | { | |
613 | static const wxChar *ARG_PSN = _T("-psn_"); | |
614 | if ( wxStrncmp(argv[1], ARG_PSN, sizeof(ARG_PSN) - 1) == 0 ) | |
615 | { | |
616 | // remove this argument | |
617 | memmove(argv, argv + 1, argc--); | |
618 | } | |
619 | } | |
620 | ||
621 | if ( !wxAppBase::Initialize(argc, argv) ) | |
622 | return false; | |
623 | ||
624 | wxWinMacWindowList = new wxList(wxKEY_INTEGER); | |
625 | wxWinMacControlList = new wxList(wxKEY_INTEGER); | |
626 | ||
627 | wxMacCreateNotifierTable() ; | |
628 | ||
629 | UMAShowArrowCursor() ; | |
630 | ||
631 | return true; | |
632 | } | |
633 | ||
634 | bool wxApp::OnInitGui() | |
635 | { | |
636 | if( !wxAppBase::OnInitGui() ) | |
637 | return false ; | |
638 | ||
639 | #if TARGET_CARBON | |
640 | InstallStandardEventHandler( GetApplicationEventTarget() ) ; | |
641 | ||
642 | InstallApplicationEventHandler( | |
643 | GetwxAppEventHandlerUPP(), | |
644 | GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler)); | |
645 | #endif | |
646 | ||
647 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) | |
648 | AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , | |
649 | NewAEEventHandlerUPP(AEHandleODoc) , | |
650 | 0 , FALSE ) ; | |
651 | AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , | |
652 | NewAEEventHandlerUPP(AEHandleOApp) , | |
653 | 0 , FALSE ) ; | |
654 | AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , | |
655 | NewAEEventHandlerUPP(AEHandlePDoc) , | |
656 | 0 , FALSE ) ; | |
657 | AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , | |
658 | NewAEEventHandlerUPP(AEHandleQuit) , | |
659 | 0 , FALSE ) ; | |
660 | #else | |
661 | AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , | |
662 | NewAEEventHandlerProc(AEHandleODoc) , | |
663 | 0 , FALSE ) ; | |
664 | AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , | |
665 | NewAEEventHandlerProc(AEHandleOApp) , | |
666 | 0 , FALSE ) ; | |
667 | AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , | |
668 | NewAEEventHandlerProc(AEHandlePDoc) , | |
669 | 0 , FALSE ) ; | |
670 | AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , | |
671 | NewAEEventHandlerProc(AEHandleQuit) , | |
672 | 0 , FALSE ) ; | |
673 | #endif | |
674 | ||
675 | return TRUE ; | |
676 | } | |
677 | ||
678 | void wxApp::CleanUp() | |
679 | { | |
680 | wxToolTip::RemoveToolTips() ; | |
681 | ||
682 | // One last chance for pending objects to be cleaned up | |
683 | wxTheApp->DeletePendingObjects(); | |
684 | ||
685 | wxMacDestroyNotifierTable() ; | |
686 | ||
687 | delete wxWinMacWindowList ; | |
688 | wxWinMacWindowList = NULL; | |
689 | ||
690 | delete wxWinMacControlList ; | |
691 | wxWinMacControlList = NULL; | |
692 | ||
693 | #ifndef __DARWIN__ | |
694 | # if __option(profile) | |
695 | ProfilerDump( (StringPtr)"\papp.prof" ) ; | |
696 | ProfilerTerm() ; | |
697 | # endif | |
698 | #endif | |
699 | ||
700 | #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) | |
701 | // close shared library resources from here since we don't have | |
702 | // __wxterminate in Mach-O shared libraries | |
703 | wxStAppResource::CloseSharedLibraryResource(); | |
704 | #endif | |
705 | wxMacCleanupConverters() ; | |
706 | ||
707 | UMACleanupToolbox() ; | |
708 | if (s_macCursorRgn) { | |
709 | ::DisposeRgn((RgnHandle)s_macCursorRgn); | |
710 | } | |
711 | ||
712 | #if 0 | |
713 | TerminateAE() ; | |
714 | #endif | |
715 | ||
716 | wxAppBase::CleanUp(); | |
717 | } | |
718 | ||
719 | //---------------------------------------------------------------------- | |
720 | // misc initialization stuff | |
721 | //---------------------------------------------------------------------- | |
722 | ||
723 | // extern variable for shared library resource id | |
724 | // need to be able to find it with NSLookupAndBindSymbol | |
725 | short gSharedLibraryResource = kResFileNotOpened ; | |
726 | ||
727 | #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__) | |
728 | CFBundleRef gSharedLibraryBundle = NULL; | |
729 | #endif /* WXMAKINGDLL_CORE && __DARWIN__ */ | |
730 | ||
731 | wxStAppResource::wxStAppResource() | |
732 | { | |
733 | m_currentRefNum = CurResFile() ; | |
734 | if ( gSharedLibraryResource != kResFileNotOpened ) | |
735 | { | |
736 | UseResFile( gSharedLibraryResource ) ; | |
737 | } | |
738 | } | |
739 | ||
740 | wxStAppResource::~wxStAppResource() | |
741 | { | |
742 | if ( m_currentRefNum != kResFileNotOpened ) | |
743 | { | |
744 | UseResFile( m_currentRefNum ) ; | |
745 | } | |
746 | } | |
747 | ||
748 | void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) | |
749 | { | |
750 | gSharedLibraryResource = kResFileNotOpened; | |
751 | ||
752 | #ifdef WXMAKINGDLL_CORE | |
753 | if ( initBlock != NULL ) { | |
754 | const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock; | |
755 | FSSpec *fileSpec = NULL; | |
756 | ||
757 | if (theInitBlock->fragLocator.where == kDataForkCFragLocator) { | |
758 | fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec; | |
759 | } | |
760 | else if (theInitBlock->fragLocator.where == kResourceCFragLocator) { | |
761 | fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec; | |
762 | } | |
763 | ||
764 | if (fileSpec != NULL) { | |
765 | gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm); | |
766 | } | |
767 | } | |
768 | else { | |
769 | #ifdef __DARWIN__ | |
770 | // Open the shared library resource file if it is not yet open | |
771 | NSSymbol theSymbol; | |
772 | NSModule theModule; | |
773 | const char *theLibPath; | |
774 | ||
775 | gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows")); | |
776 | if (gSharedLibraryBundle != NULL) { | |
777 | // wxWindows has been bundled into a framework | |
778 | // load the framework resources | |
779 | ||
780 | gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle); | |
781 | } | |
782 | else { | |
783 | // wxWindows is a simple dynamic shared library | |
784 | // load the resources from the data fork of a separate resource file | |
785 | wxString theResPath; | |
786 | wxString theName; | |
787 | FSRef theResRef; | |
788 | OSErr theErr = noErr; | |
789 | ||
790 | // get the library path | |
791 | theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource"); | |
792 | theModule = NSModuleForSymbol(theSymbol); | |
793 | theLibPath = NSLibraryNameForModule(theModule); | |
794 | ||
795 | // if we call wxLogDebug from here then, as wxTheApp hasn't been | |
796 | // created yet when we're called from wxApp::Initialize(), wxLog | |
797 | // is going to create a default stderr-based log target instead of | |
798 | // the expected normal GUI one -- don't do it, if we really want | |
799 | // to see this message just use fprintf() here | |
800 | #if 0 | |
801 | wxLogDebug( wxT("wxMac library installation name is '%s'"), | |
802 | theLibPath ); | |
803 | #endif | |
804 | ||
805 | // allocate copy to replace .dylib.* extension with .rsrc | |
806 | if (theLibPath != NULL) { | |
807 | theResPath = theLibPath; | |
808 | // replace '_core' with '' in case of multi-lib build | |
809 | theResPath.Replace(wxT("_core"), wxEmptyString); | |
810 | // replace ".dylib" shared library extension with ".rsrc" | |
811 | theResPath.Replace(wxT(".dylib"), wxT(".rsrc")); | |
812 | // Find the begining of the filename | |
813 | theName = theResPath.AfterLast('/'); | |
814 | ||
815 | #if 0 | |
816 | wxLogDebug( wxT("wxMac resources file name is '%s'"), | |
817 | theResPath.mb_str() ); | |
818 | #endif | |
819 | ||
820 | theErr = FSPathMakeRef((UInt8 *) theResPath.mb_str(), &theResRef, false); | |
821 | if (theErr != noErr) { | |
822 | // try in current directory (using name only) | |
823 | theErr = FSPathMakeRef((UInt8 *) theName.mb_str(), &theResRef, false); | |
824 | } | |
825 | ||
826 | // open the resource file | |
827 | if (theErr == noErr) { | |
828 | theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm, | |
829 | &gSharedLibraryResource); | |
830 | } | |
831 | if (theErr != noErr) { | |
832 | #ifdef __WXDEBUG__ | |
833 | fprintf(stderr, | |
834 | wxT("unable to open wxMac resource file '%s'\n"), | |
835 | theResPath.mb_str() ); | |
836 | #endif // __WXDEBUG__ | |
837 | } | |
838 | ||
839 | } | |
840 | } | |
841 | #endif /* __DARWIN__ */ | |
842 | } | |
843 | #endif /* WXMAKINGDLL_CORE */ | |
844 | } | |
845 | ||
846 | void wxStAppResource::CloseSharedLibraryResource() | |
847 | { | |
848 | #ifdef WXMAKINGDLL_CORE | |
849 | // Close the shared library resource file | |
850 | if (gSharedLibraryResource != kResFileNotOpened) { | |
851 | #ifdef __DARWIN__ | |
852 | if (gSharedLibraryBundle != NULL) { | |
853 | CFBundleCloseBundleResourceMap(gSharedLibraryBundle, | |
854 | gSharedLibraryResource); | |
855 | gSharedLibraryBundle = NULL; | |
856 | } | |
857 | else | |
858 | #endif /* __DARWIN__ */ | |
859 | { | |
860 | CloseResFile(gSharedLibraryResource); | |
861 | } | |
862 | gSharedLibraryResource = kResFileNotOpened; | |
863 | } | |
864 | #endif /* WXMAKINGDLL_CORE */ | |
865 | } | |
866 | ||
867 | #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__) | |
868 | ||
869 | // for shared libraries we have to manually get the correct resource | |
870 | // ref num upon initializing and releasing when terminating, therefore | |
871 | // the __wxinitialize and __wxterminate must be used | |
872 | ||
873 | extern "C" { | |
874 | void __sinit(void); /* (generated by linker) */ | |
875 | pascal OSErr __initialize(const CFragInitBlock *theInitBlock); | |
876 | pascal void __terminate(void); | |
877 | } | |
878 | ||
879 | pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock) | |
880 | { | |
881 | wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ; | |
882 | return __initialize( theInitBlock ) ; | |
883 | } | |
884 | ||
885 | pascal void __wxterminate(void) | |
886 | { | |
887 | wxStAppResource::CloseSharedLibraryResource() ; | |
888 | __terminate() ; | |
889 | } | |
890 | ||
891 | #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */ | |
892 | ||
893 | #if TARGET_CARBON | |
894 | ||
895 | bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) | |
896 | { | |
897 | bool converted = ConvertEventRefToEventRecord( event,rec) ; | |
898 | OSStatus err = noErr ; | |
899 | if ( !converted ) | |
900 | { | |
901 | switch( GetEventClass( event ) ) | |
902 | { | |
903 | case kEventClassKeyboard : | |
904 | { | |
905 | converted = true ; | |
906 | switch( GetEventKind(event) ) | |
907 | { | |
908 | case kEventRawKeyDown : | |
909 | rec->what = keyDown ; | |
910 | break ; | |
911 | case kEventRawKeyRepeat : | |
912 | rec->what = autoKey ; | |
913 | break ; | |
914 | case kEventRawKeyUp : | |
915 | rec->what = keyUp ; | |
916 | break ; | |
917 | case kEventRawKeyModifiersChanged : | |
918 | rec->what = nullEvent ; | |
919 | break ; | |
920 | default : | |
921 | converted = false ; | |
922 | break ; | |
923 | } | |
924 | if ( converted ) | |
925 | { | |
926 | UInt32 keyCode ; | |
927 | unsigned char charCode ; | |
928 | UInt32 modifiers ; | |
929 | GetMouse( &rec->where) ; | |
930 | ||
931 | err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); | |
932 | err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode); | |
933 | err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode); | |
934 | rec->modifiers = modifiers ; | |
935 | rec->message = (keyCode << 8 ) + charCode ; | |
936 | } | |
937 | } | |
938 | break ; | |
939 | case kEventClassTextInput : | |
940 | { | |
941 | switch( GetEventKind( event ) ) | |
942 | { | |
943 | case kEventTextInputUnicodeForKeyEvent : | |
944 | { | |
945 | EventRef rawEvent ; | |
946 | err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; | |
947 | converted = true ; | |
948 | { | |
949 | UInt32 keyCode ; | |
950 | unsigned char charCode ; | |
951 | UInt32 modifiers ; | |
952 | GetMouse( &rec->where) ; | |
953 | rec->what = keyDown ; | |
954 | err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); | |
955 | err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode); | |
956 | err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode); | |
957 | rec->modifiers = modifiers ; | |
958 | rec->message = (keyCode << 8 ) + charCode ; | |
959 | } | |
960 | } | |
961 | break ; | |
962 | default : | |
963 | break ; | |
964 | } | |
965 | } | |
966 | break ; | |
967 | } | |
968 | } | |
969 | ||
970 | return converted ; | |
971 | } | |
972 | ||
973 | /* | |
974 | pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
975 | { | |
976 | OSStatus result = eventNotHandledErr ; | |
977 | ||
978 | EventRecord rec ; | |
979 | switch ( GetEventClass( event ) ) | |
980 | { | |
981 | case kEventClassKeyboard : | |
982 | if ( wxMacConvertEventToRecord( event , &rec ) ) | |
983 | { | |
984 | wxTheApp->MacHandleModifierEvents( &rec ) ; | |
985 | wxTheApp->MacHandleOneEvent( &rec ) ; | |
986 | result = noErr ; | |
987 | } | |
988 | break ; | |
989 | case kEventClassTextInput : | |
990 | if ( wxMacConvertEventToRecord( event , &rec ) ) | |
991 | { | |
992 | wxTheApp->MacHandleModifierEvents( &rec ) ; | |
993 | wxTheApp->MacHandleOneEvent( &rec ) ; | |
994 | result = noErr ; | |
995 | } | |
996 | break ; | |
997 | default : | |
998 | break ; | |
999 | } | |
1000 | return result ; | |
1001 | } | |
1002 | */ | |
1003 | #endif | |
1004 | ||
1005 | wxApp::wxApp() | |
1006 | { | |
1007 | m_printMode = wxPRINT_WINDOWS; | |
1008 | m_auto3D = TRUE; | |
1009 | ||
1010 | m_macCurrentEvent = NULL ; | |
1011 | #if TARGET_CARBON | |
1012 | m_macCurrentEventHandlerCallRef = NULL ; | |
1013 | #endif | |
1014 | } | |
1015 | ||
1016 | bool wxApp::Initialized() | |
1017 | { | |
1018 | if (GetTopWindow()) | |
1019 | return TRUE; | |
1020 | else | |
1021 | return FALSE; | |
1022 | } | |
1023 | ||
1024 | int wxApp::MainLoop() | |
1025 | { | |
1026 | m_keepGoing = TRUE; | |
1027 | ||
1028 | while (m_keepGoing) | |
1029 | { | |
1030 | MacDoOneEvent() ; | |
1031 | } | |
1032 | ||
1033 | return 0; | |
1034 | } | |
1035 | ||
1036 | void wxApp::ExitMainLoop() | |
1037 | { | |
1038 | m_keepGoing = FALSE; | |
1039 | } | |
1040 | ||
1041 | // Is a message/event pending? | |
1042 | bool wxApp::Pending() | |
1043 | { | |
1044 | #if TARGET_CARBON | |
1045 | return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ; | |
1046 | #else | |
1047 | EventRecord event ; | |
1048 | ||
1049 | return EventAvail( everyEvent , &event ) ; | |
1050 | #endif | |
1051 | } | |
1052 | ||
1053 | // Dispatch a message. | |
1054 | void wxApp::Dispatch() | |
1055 | { | |
1056 | MacDoOneEvent() ; | |
1057 | } | |
1058 | ||
1059 | void wxApp::OnIdle(wxIdleEvent& event) | |
1060 | { | |
1061 | wxAppBase::OnIdle(event); | |
1062 | ||
1063 | // If they are pending events, we must process them: pending events are | |
1064 | // either events to the threads other than main or events posted with | |
1065 | // wxPostEvent() functions | |
1066 | wxMacProcessNotifierAndPendingEvents(); | |
1067 | ||
1068 | if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar()) | |
1069 | wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar(); | |
1070 | } | |
1071 | ||
1072 | void wxApp::WakeUpIdle() | |
1073 | { | |
1074 | wxMacWakeUp() ; | |
1075 | } | |
1076 | ||
1077 | void wxApp::Exit() | |
1078 | { | |
1079 | wxApp::CleanUp(); | |
1080 | ::ExitToShell() ; | |
1081 | } | |
1082 | ||
1083 | void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) | |
1084 | { | |
1085 | if (GetTopWindow()) | |
1086 | GetTopWindow()->Close(TRUE); | |
1087 | } | |
1088 | ||
1089 | // Default behaviour: close the application with prompts. The | |
1090 | // user can veto the close, and therefore the end session. | |
1091 | void wxApp::OnQueryEndSession(wxCloseEvent& event) | |
1092 | { | |
1093 | if (GetTopWindow()) | |
1094 | { | |
1095 | if (!GetTopWindow()->Close(!event.CanVeto())) | |
1096 | event.Veto(TRUE); | |
1097 | } | |
1098 | } | |
1099 | ||
1100 | extern "C" void wxCYield() ; | |
1101 | void wxCYield() | |
1102 | { | |
1103 | wxYield() ; | |
1104 | } | |
1105 | ||
1106 | // Yield to other processes | |
1107 | ||
1108 | bool wxApp::Yield(bool onlyIfNeeded) | |
1109 | { | |
1110 | if (s_inYield) | |
1111 | { | |
1112 | if ( !onlyIfNeeded ) | |
1113 | { | |
1114 | wxFAIL_MSG( wxT("wxYield called recursively" ) ); | |
1115 | } | |
1116 | ||
1117 | return FALSE; | |
1118 | } | |
1119 | ||
1120 | s_inYield = TRUE; | |
1121 | ||
1122 | #if wxUSE_THREADS | |
1123 | YieldToAnyThread() ; | |
1124 | #endif | |
1125 | // by definition yield should handle all non-processed events | |
1126 | #if TARGET_CARBON | |
1127 | EventRef theEvent; | |
1128 | ||
1129 | OSStatus status = noErr ; | |
1130 | do | |
1131 | { | |
1132 | s_inReceiveEvent = true ; | |
1133 | status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ; | |
1134 | s_inReceiveEvent = false ; | |
1135 | ||
1136 | if ( status == eventLoopTimedOutErr ) | |
1137 | { | |
1138 | // make sure next time the event loop will trigger idle events | |
1139 | sleepTime = kEventDurationNoWait ; | |
1140 | } | |
1141 | else if ( status == eventLoopQuitErr ) | |
1142 | { | |
1143 | // according to QA1061 this may also occur when a WakeUp Process | |
1144 | // is executed | |
1145 | } | |
1146 | else | |
1147 | { | |
1148 | MacHandleOneEvent( theEvent ) ; | |
1149 | ReleaseEvent(theEvent); | |
1150 | } | |
1151 | } while( status == noErr ) ; | |
1152 | #else | |
1153 | EventRecord event ; | |
1154 | ||
1155 | // having a larger value here leads to large performance slowdowns | |
1156 | // so we cannot give background apps more processor time here | |
1157 | // we do so however having a large sleep value in the main event loop | |
1158 | sleepTime = 0 ; | |
1159 | ||
1160 | while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) | |
1161 | { | |
1162 | MacHandleModifierEvents( &event ) ; | |
1163 | MacHandleOneEvent( &event ); | |
1164 | if ( event.what != kHighLevelEvent ) | |
1165 | SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; | |
1166 | } | |
1167 | MacHandleModifierEvents( &event ) ; | |
1168 | #endif | |
1169 | ||
1170 | wxMacProcessNotifierAndPendingEvents() ; | |
1171 | s_inYield = FALSE; | |
1172 | ||
1173 | return TRUE; | |
1174 | } | |
1175 | ||
1176 | // platform specifics | |
1177 | ||
1178 | void wxApp::MacSuspend( bool convertClipboard ) | |
1179 | { | |
1180 | #if !TARGET_CARBON | |
1181 | // we have to deactive the top level windows manually | |
1182 | ||
1183 | wxWindowListNode* node = wxTopLevelWindows.GetFirst(); | |
1184 | while (node) | |
1185 | { | |
1186 | wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data(); | |
1187 | #if TARGET_CARBON | |
1188 | #if 0 // having problems right now with that | |
1189 | if (!win->HasFlag(wxSTAY_ON_TOP)) | |
1190 | #endif | |
1191 | #endif | |
1192 | win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ; | |
1193 | ||
1194 | node = node->GetNext(); | |
1195 | } | |
1196 | ||
1197 | ::HideFloatingWindows() ; | |
1198 | #endif | |
1199 | s_lastMouseDown = 0 ; | |
1200 | ||
1201 | if( convertClipboard ) | |
1202 | { | |
1203 | MacConvertPrivateToPublicScrap() ; | |
1204 | } | |
1205 | } | |
1206 | ||
1207 | extern wxList wxModalDialogs; | |
1208 | ||
1209 | void wxApp::MacResume( bool convertClipboard ) | |
1210 | { | |
1211 | s_lastMouseDown = 0 ; | |
1212 | if( convertClipboard ) | |
1213 | { | |
1214 | MacConvertPublicToPrivateScrap() ; | |
1215 | } | |
1216 | ||
1217 | #if !TARGET_CARBON | |
1218 | ::ShowFloatingWindows() ; | |
1219 | // raise modal dialogs in case a non modal window was selected to activate the app | |
1220 | ||
1221 | wxNode* node = wxModalDialogs.GetFirst(); | |
1222 | while (node) | |
1223 | { | |
1224 | wxDialog* dialog = (wxDialog *) node->GetData(); | |
1225 | dialog->Raise(); | |
1226 | ||
1227 | node = node->GetNext(); | |
1228 | } | |
1229 | #endif | |
1230 | } | |
1231 | ||
1232 | void wxApp::MacConvertPrivateToPublicScrap() | |
1233 | { | |
1234 | } | |
1235 | ||
1236 | void wxApp::MacConvertPublicToPrivateScrap() | |
1237 | { | |
1238 | } | |
1239 | ||
1240 | void wxApp::MacDoOneEvent() | |
1241 | { | |
1242 | #if TARGET_CARBON | |
1243 | EventRef theEvent; | |
1244 | ||
1245 | s_inReceiveEvent = true ; | |
1246 | OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ; | |
1247 | s_inReceiveEvent = false ; | |
1248 | if ( status == eventLoopTimedOutErr ) | |
1249 | { | |
1250 | if ( wxTheApp->ProcessIdle() ) | |
1251 | sleepTime = kEventDurationNoWait ; | |
1252 | else | |
1253 | sleepTime = kEventDurationForever ; | |
1254 | } | |
1255 | else if ( status == eventLoopQuitErr ) | |
1256 | { | |
1257 | // according to QA1061 this may also occur when a WakeUp Process | |
1258 | // is executed | |
1259 | } | |
1260 | else | |
1261 | { | |
1262 | MacHandleOneEvent( theEvent ) ; | |
1263 | ReleaseEvent(theEvent); | |
1264 | sleepTime = kEventDurationNoWait ; | |
1265 | } | |
1266 | #else | |
1267 | EventRecord event ; | |
1268 | ||
1269 | EventMask eventMask = everyEvent ; | |
1270 | ||
1271 | if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn)) | |
1272 | { | |
1273 | MacHandleModifierEvents( &event ) ; | |
1274 | MacHandleOneEvent( &event ); | |
1275 | } | |
1276 | else | |
1277 | { | |
1278 | MacHandleModifierEvents( &event ) ; | |
1279 | // idlers | |
1280 | WindowPtr window = ::FrontWindow() ; | |
1281 | if ( window ) | |
1282 | ::IdleControls( window ) ; | |
1283 | ||
1284 | if ( wxTheApp->ProcessIdle() ) | |
1285 | sleepTime = 0 ; | |
1286 | else | |
1287 | sleepTime = GetCaretTime() / 2 ; | |
1288 | } | |
1289 | if ( event.what != kHighLevelEvent ) | |
1290 | SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; | |
1291 | #endif | |
1292 | // repeaters | |
1293 | ||
1294 | DeletePendingObjects() ; | |
1295 | wxMacProcessNotifierAndPendingEvents() ; | |
1296 | } | |
1297 | ||
1298 | void wxApp::MacHandleOneEvent( WXEVENTREF evr ) | |
1299 | { | |
1300 | #if TARGET_CARBON | |
1301 | EventTargetRef theTarget; | |
1302 | theTarget = GetEventDispatcherTarget(); | |
1303 | m_macCurrentEvent = evr ; | |
1304 | SendEventToEventTarget ((EventRef) evr , theTarget); | |
1305 | #else | |
1306 | EventRecord* ev = (EventRecord*) evr ; | |
1307 | m_macCurrentEvent = ev ; | |
1308 | ||
1309 | wxApp::sm_lastMessageTime = ev->when ; | |
1310 | ||
1311 | switch (ev->what) | |
1312 | { | |
1313 | case mouseDown: | |
1314 | MacHandleMouseDownEvent( ev ) ; | |
1315 | if ( ev->modifiers & controlKey ) | |
1316 | s_lastMouseDown = 2; | |
1317 | else | |
1318 | s_lastMouseDown = 1; | |
1319 | break; | |
1320 | case mouseUp: | |
1321 | if ( s_lastMouseDown == 2 ) | |
1322 | { | |
1323 | ev->modifiers |= controlKey ; | |
1324 | } | |
1325 | else | |
1326 | { | |
1327 | ev->modifiers &= ~controlKey ; | |
1328 | } | |
1329 | MacHandleMouseUpEvent( ev ) ; | |
1330 | s_lastMouseDown = 0; | |
1331 | break; | |
1332 | case activateEvt: | |
1333 | MacHandleActivateEvent( ev ) ; | |
1334 | break; | |
1335 | case updateEvt: | |
1336 | MacHandleUpdateEvent( ev ) ; | |
1337 | break; | |
1338 | case keyDown: | |
1339 | case autoKey: | |
1340 | MacHandleKeyDownEvent( ev ) ; | |
1341 | break; | |
1342 | case keyUp: | |
1343 | MacHandleKeyUpEvent( ev ) ; | |
1344 | break; | |
1345 | case diskEvt: | |
1346 | MacHandleDiskEvent( ev ) ; | |
1347 | break; | |
1348 | case osEvt: | |
1349 | MacHandleOSEvent( ev ) ; | |
1350 | break; | |
1351 | case kHighLevelEvent: | |
1352 | MacHandleHighLevelEvent( ev ) ; | |
1353 | break; | |
1354 | default: | |
1355 | break; | |
1356 | } | |
1357 | #endif | |
1358 | wxMacProcessNotifierAndPendingEvents() ; | |
1359 | } | |
1360 | ||
1361 | #if !TARGET_CARBON | |
1362 | bool s_macIsInModalLoop = false ; | |
1363 | ||
1364 | void wxApp::MacHandleModifierEvents( WXEVENTREF evr ) | |
1365 | { | |
1366 | EventRecord* ev = (EventRecord*) evr ; | |
1367 | if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL ) | |
1368 | { | |
1369 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
1370 | ||
1371 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1372 | event.m_controlDown = ev->modifiers & controlKey; | |
1373 | event.m_altDown = ev->modifiers & optionKey; | |
1374 | event.m_metaDown = ev->modifiers & cmdKey; | |
1375 | ||
1376 | event.m_x = ev->where.h; | |
1377 | event.m_y = ev->where.v; | |
1378 | event.m_timeStamp = ev->when; | |
1379 | wxWindow* focus = wxWindow::FindFocus() ; | |
1380 | event.SetEventObject(focus); | |
1381 | ||
1382 | if ( (ev->modifiers ^ s_lastModifiers ) & controlKey ) | |
1383 | { | |
1384 | event.m_keyCode = WXK_CONTROL ; | |
1385 | event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1386 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1387 | } | |
1388 | if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey ) | |
1389 | { | |
1390 | event.m_keyCode = WXK_SHIFT ; | |
1391 | event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1392 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1393 | } | |
1394 | if ( (ev->modifiers ^ s_lastModifiers ) & optionKey ) | |
1395 | { | |
1396 | event.m_keyCode = WXK_ALT ; | |
1397 | event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1398 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1399 | } | |
1400 | if ( ( ev->modifiers ^ s_lastModifiers ) & cmdKey ) | |
1401 | { | |
1402 | event.m_keyCode = WXK_COMMAND ; | |
1403 | event.SetEventType( ( ev->modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ; | |
1404 | focus->GetEventHandler()->ProcessEvent( event ) ; | |
1405 | } | |
1406 | s_lastModifiers = ev->modifiers ; | |
1407 | } | |
1408 | } | |
1409 | ||
1410 | void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) | |
1411 | { | |
1412 | // we must avoid reentrancy problems when processing high level events eg printing | |
1413 | bool former = s_inYield ; | |
1414 | s_inYield = TRUE ; | |
1415 | EventRecord* ev = (EventRecord*) evr ; | |
1416 | ::AEProcessAppleEvent( ev ) ; | |
1417 | s_inYield = former ; | |
1418 | } | |
1419 | ||
1420 | void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) | |
1421 | { | |
1422 | EventRecord* ev = (EventRecord*) evr ; | |
1423 | wxToolTip::RemoveToolTips() ; | |
1424 | ||
1425 | WindowRef window; | |
1426 | WindowRef frontWindow = ::FrontNonFloatingWindow() ; | |
1427 | WindowAttributes frontWindowAttributes = NULL ; | |
1428 | if ( frontWindow ) | |
1429 | ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; | |
1430 | ||
1431 | short windowPart = ::FindWindow(ev->where, &window); | |
1432 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1433 | if ( wxPendingDelete.Member(win) ) | |
1434 | return ; | |
1435 | ||
1436 | BitMap screenBits; | |
1437 | GetQDGlobalsScreenBits( &screenBits ); | |
1438 | ||
1439 | switch (windowPart) | |
1440 | { | |
1441 | case inMenuBar : | |
1442 | if ( s_macIsInModalLoop ) | |
1443 | { | |
1444 | SysBeep ( 30 ) ; | |
1445 | } | |
1446 | else | |
1447 | { | |
1448 | UInt32 menuresult = MenuSelect(ev->where) ; | |
1449 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ); | |
1450 | s_lastMouseDown = 0; | |
1451 | } | |
1452 | break ; | |
1453 | case inSysWindow : | |
1454 | SystemClick( ev , window ) ; | |
1455 | s_lastMouseDown = 0; | |
1456 | break ; | |
1457 | case inDrag : | |
1458 | if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) ) | |
1459 | { | |
1460 | SysBeep ( 30 ) ; | |
1461 | } | |
1462 | else | |
1463 | { | |
1464 | DragWindow(window, ev->where, &screenBits.bounds); | |
1465 | if (win) | |
1466 | { | |
1467 | GrafPtr port ; | |
1468 | GetPort( &port ) ; | |
1469 | Point pt = { 0, 0 } ; | |
1470 | SetPortWindowPort(window) ; | |
1471 | LocalToGlobal( &pt ) ; | |
1472 | SetPort( port ) ; | |
1473 | win->SetSize( pt.h , pt.v , -1 , | |
1474 | -1 , wxSIZE_USE_EXISTING); | |
1475 | } | |
1476 | s_lastMouseDown = 0; | |
1477 | } | |
1478 | break ; | |
1479 | case inGoAway: | |
1480 | if (TrackGoAway(window, ev->where)) | |
1481 | { | |
1482 | if ( win ) | |
1483 | win->Close() ; | |
1484 | } | |
1485 | s_lastMouseDown = 0; | |
1486 | break; | |
1487 | case inGrow: | |
1488 | { | |
1489 | Rect newContentRect ; | |
1490 | Rect constraintRect ; | |
1491 | constraintRect.top = win->GetMinHeight() ; | |
1492 | if ( constraintRect.top == -1 ) | |
1493 | constraintRect.top = 0 ; | |
1494 | constraintRect.left = win->GetMinWidth() ; | |
1495 | if ( constraintRect.left == -1 ) | |
1496 | constraintRect.left = 0 ; | |
1497 | constraintRect.right = win->GetMaxWidth() ; | |
1498 | if ( constraintRect.right == -1 ) | |
1499 | constraintRect.right = 32000 ; | |
1500 | constraintRect.bottom = win->GetMaxHeight() ; | |
1501 | if ( constraintRect.bottom == -1 ) | |
1502 | constraintRect.bottom = 32000 ; | |
1503 | ||
1504 | Boolean growResult = ResizeWindow( window , ev->where , | |
1505 | &constraintRect , &newContentRect ) ; | |
1506 | if ( growResult ) | |
1507 | { | |
1508 | win->SetSize( newContentRect.left , newContentRect.top , | |
1509 | newContentRect.right - newContentRect.left , | |
1510 | newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING); | |
1511 | } | |
1512 | s_lastMouseDown = 0; | |
1513 | } | |
1514 | break; | |
1515 | case inZoomIn: | |
1516 | case inZoomOut: | |
1517 | if (TrackBox(window, ev->where, windowPart)) | |
1518 | { | |
1519 | // TODO setup size event | |
1520 | ZoomWindow( window , windowPart , false ) ; | |
1521 | if (win) | |
1522 | { | |
1523 | Rect tempRect ; | |
1524 | GrafPtr port ; | |
1525 | GetPort( &port ) ; | |
1526 | Point pt = { 0, 0 } ; | |
1527 | SetPortWindowPort(window) ; | |
1528 | LocalToGlobal( &pt ) ; | |
1529 | SetPort( port ) ; | |
1530 | ||
1531 | GetWindowPortBounds(window, &tempRect ) ; | |
1532 | win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left , | |
1533 | tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); | |
1534 | } | |
1535 | } | |
1536 | s_lastMouseDown = 0; | |
1537 | break; | |
1538 | case inCollapseBox : | |
1539 | // TODO setup size event | |
1540 | s_lastMouseDown = 0; | |
1541 | break ; | |
1542 | ||
1543 | case inContent : | |
1544 | { | |
1545 | GrafPtr port ; | |
1546 | GetPort( &port ) ; | |
1547 | SetPortWindowPort(window) ; | |
1548 | SetPort( port ) ; | |
1549 | } | |
1550 | if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) | |
1551 | { | |
1552 | if ( s_macIsInModalLoop ) | |
1553 | { | |
1554 | SysBeep ( 30 ) ; | |
1555 | } | |
1556 | else if ( UMAIsWindowFloating( window ) ) | |
1557 | { | |
1558 | if ( win ) | |
1559 | win->MacMouseDown( ev , windowPart ) ; | |
1560 | } | |
1561 | else | |
1562 | { | |
1563 | // Activate window first | |
1564 | ::SelectWindow( window ) ; | |
1565 | ||
1566 | // Send event later | |
1567 | if ( win ) | |
1568 | win->MacMouseDown( ev , windowPart ) ; | |
1569 | } | |
1570 | } | |
1571 | else | |
1572 | { | |
1573 | if ( win ) | |
1574 | win->MacMouseDown( ev , windowPart ) ; | |
1575 | } | |
1576 | break ; | |
1577 | default: | |
1578 | break; | |
1579 | } | |
1580 | } | |
1581 | ||
1582 | void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) | |
1583 | { | |
1584 | EventRecord* ev = (EventRecord*) evr ; | |
1585 | WindowRef window; | |
1586 | ||
1587 | short windowPart = inNoWindow ; | |
1588 | if ( wxTheApp->s_captureWindow ) | |
1589 | { | |
1590 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
1591 | windowPart = inContent ; | |
1592 | } | |
1593 | else | |
1594 | { | |
1595 | windowPart = ::FindWindow(ev->where, &window) ; | |
1596 | } | |
1597 | ||
1598 | switch (windowPart) | |
1599 | { | |
1600 | case inMenuBar : | |
1601 | break ; | |
1602 | case inSysWindow : | |
1603 | break ; | |
1604 | default: | |
1605 | { | |
1606 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1607 | if ( win ) | |
1608 | win->MacMouseUp( ev , windowPart ) ; | |
1609 | } | |
1610 | break; | |
1611 | } | |
1612 | } | |
1613 | ||
1614 | #endif | |
1615 | ||
1616 | long wxMacTranslateKey(unsigned char key, unsigned char code) ; | |
1617 | long wxMacTranslateKey(unsigned char key, unsigned char code) | |
1618 | { | |
1619 | long retval = key ; | |
1620 | switch (key) | |
1621 | { | |
1622 | case kHomeCharCode : | |
1623 | retval = WXK_HOME; | |
1624 | break; | |
1625 | case kEnterCharCode : | |
1626 | retval = WXK_RETURN; | |
1627 | break; | |
1628 | case kEndCharCode : | |
1629 | retval = WXK_END; | |
1630 | break; | |
1631 | case kHelpCharCode : | |
1632 | retval = WXK_HELP; | |
1633 | break; | |
1634 | case kBackspaceCharCode : | |
1635 | retval = WXK_BACK; | |
1636 | break; | |
1637 | case kTabCharCode : | |
1638 | retval = WXK_TAB; | |
1639 | break; | |
1640 | case kPageUpCharCode : | |
1641 | retval = WXK_PAGEUP; | |
1642 | break; | |
1643 | case kPageDownCharCode : | |
1644 | retval = WXK_PAGEDOWN; | |
1645 | break; | |
1646 | case kReturnCharCode : | |
1647 | retval = WXK_RETURN; | |
1648 | break; | |
1649 | case kFunctionKeyCharCode : | |
1650 | { | |
1651 | switch( code ) | |
1652 | { | |
1653 | case 0x7a : | |
1654 | retval = WXK_F1 ; | |
1655 | break; | |
1656 | case 0x78 : | |
1657 | retval = WXK_F2 ; | |
1658 | break; | |
1659 | case 0x63 : | |
1660 | retval = WXK_F3 ; | |
1661 | break; | |
1662 | case 0x76 : | |
1663 | retval = WXK_F4 ; | |
1664 | break; | |
1665 | case 0x60 : | |
1666 | retval = WXK_F5 ; | |
1667 | break; | |
1668 | case 0x61 : | |
1669 | retval = WXK_F6 ; | |
1670 | break; | |
1671 | case 0x62: | |
1672 | retval = WXK_F7 ; | |
1673 | break; | |
1674 | case 0x64 : | |
1675 | retval = WXK_F8 ; | |
1676 | break; | |
1677 | case 0x65 : | |
1678 | retval = WXK_F9 ; | |
1679 | break; | |
1680 | case 0x6D : | |
1681 | retval = WXK_F10 ; | |
1682 | break; | |
1683 | case 0x67 : | |
1684 | retval = WXK_F11 ; | |
1685 | break; | |
1686 | case 0x6F : | |
1687 | retval = WXK_F12 ; | |
1688 | break; | |
1689 | case 0x69 : | |
1690 | retval = WXK_F13 ; | |
1691 | break; | |
1692 | case 0x6B : | |
1693 | retval = WXK_F14 ; | |
1694 | break; | |
1695 | case 0x71 : | |
1696 | retval = WXK_F15 ; | |
1697 | break; | |
1698 | } | |
1699 | } | |
1700 | break ; | |
1701 | case kEscapeCharCode : | |
1702 | retval = WXK_ESCAPE ; | |
1703 | break ; | |
1704 | case kLeftArrowCharCode : | |
1705 | retval = WXK_LEFT ; | |
1706 | break ; | |
1707 | case kRightArrowCharCode : | |
1708 | retval = WXK_RIGHT ; | |
1709 | break ; | |
1710 | case kUpArrowCharCode : | |
1711 | retval = WXK_UP ; | |
1712 | break ; | |
1713 | case kDownArrowCharCode : | |
1714 | retval = WXK_DOWN ; | |
1715 | break ; | |
1716 | case kDeleteCharCode : | |
1717 | retval = WXK_DELETE ; | |
1718 | default: | |
1719 | break ; | |
1720 | } // end switch | |
1721 | ||
1722 | return retval; | |
1723 | } | |
1724 | ||
1725 | #if !TARGET_CARBON | |
1726 | void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) | |
1727 | { | |
1728 | EventRecord* ev = (EventRecord*) evr ; | |
1729 | wxToolTip::RemoveToolTips() ; | |
1730 | ||
1731 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1732 | if ( HiWord( menuresult ) ) | |
1733 | { | |
1734 | if ( !s_macIsInModalLoop ) | |
1735 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; | |
1736 | } | |
1737 | else | |
1738 | { | |
1739 | wxWindow* focus = wxWindow::FindFocus() ; | |
1740 | ||
1741 | if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false ) | |
1742 | { | |
1743 | #if 0 | |
1744 | // we must handle control keys the other way round, otherwise text content is updated too late | |
1745 | // has not been handled -> perform default | |
1746 | wxControl* control = wxDynamicCast( focus , wxControl ) ; | |
1747 | if ( control && control->GetMacControl() != NULL ) | |
1748 | { | |
1749 | short keycode ; | |
1750 | short keychar ; | |
1751 | keychar = short(ev->message & charCodeMask); | |
1752 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
1753 | ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ; | |
1754 | } | |
1755 | #endif | |
1756 | } | |
1757 | } | |
1758 | } | |
1759 | ||
1760 | void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) | |
1761 | { | |
1762 | EventRecord* ev = (EventRecord*) evr ; | |
1763 | wxToolTip::RemoveToolTips() ; | |
1764 | ||
1765 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1766 | if ( HiWord( menuresult ) ) | |
1767 | { | |
1768 | } | |
1769 | else | |
1770 | { | |
1771 | MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ; | |
1772 | } | |
1773 | } | |
1774 | ||
1775 | #endif | |
1776 | ||
1777 | bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) | |
1778 | { | |
1779 | if ( !focus ) | |
1780 | return false ; | |
1781 | ||
1782 | short keycode ; | |
1783 | short keychar ; | |
1784 | keychar = short(keymessage & charCodeMask); | |
1785 | keycode = short(keymessage & keyCodeMask) >> 8 ; | |
1786 | ||
1787 | if ( modifiers & ( controlKey|shiftKey|optionKey ) ) | |
1788 | { | |
1789 | // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier | |
1790 | // and look at the character after | |
1791 | UInt32 state = 0; | |
1792 | UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); | |
1793 | keychar = short(keyInfo & charCodeMask); | |
1794 | keycode = short(keyInfo & keyCodeMask) >> 8 ; | |
1795 | } | |
1796 | long keyval = wxMacTranslateKey(keychar, keycode) ; | |
1797 | long realkeyval = keyval ; | |
1798 | if ( keyval == keychar ) | |
1799 | { | |
1800 | // 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) | |
1801 | realkeyval = short(keymessage & charCodeMask) ; | |
1802 | keyval = wxToupper( keyval ) ; | |
1803 | } | |
1804 | ||
1805 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
1806 | bool handled = false ; | |
1807 | event.m_shiftDown = modifiers & shiftKey; | |
1808 | event.m_controlDown = modifiers & controlKey; | |
1809 | event.m_altDown = modifiers & optionKey; | |
1810 | event.m_metaDown = modifiers & cmdKey; | |
1811 | event.m_keyCode = keyval ; | |
1812 | ||
1813 | event.m_x = wherex; | |
1814 | event.m_y = wherey; | |
1815 | event.m_timeStamp = when; | |
1816 | event.SetEventObject(focus); | |
1817 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1818 | if ( handled && event.GetSkipped() ) | |
1819 | handled = false ; | |
1820 | if ( !handled ) | |
1821 | { | |
1822 | #if wxUSE_ACCEL | |
1823 | if (!handled) | |
1824 | { | |
1825 | wxWindow *ancestor = focus; | |
1826 | while (ancestor) | |
1827 | { | |
1828 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
1829 | if (command != -1) | |
1830 | { | |
1831 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
1832 | handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
1833 | break; | |
1834 | } | |
1835 | if (ancestor->IsTopLevel()) | |
1836 | break; | |
1837 | ancestor = ancestor->GetParent(); | |
1838 | } | |
1839 | } | |
1840 | #endif // wxUSE_ACCEL | |
1841 | } | |
1842 | if (!handled) | |
1843 | { | |
1844 | event.Skip( FALSE ) ; | |
1845 | event.SetEventType( wxEVT_CHAR ) ; | |
1846 | // raw value again | |
1847 | event.m_keyCode = realkeyval ; | |
1848 | ||
1849 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1850 | if ( handled && event.GetSkipped() ) | |
1851 | handled = false ; | |
1852 | } | |
1853 | if ( !handled && | |
1854 | (keyval == WXK_TAB) && | |
1855 | // CS: copied the change below from wxGTK | |
1856 | // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may | |
1857 | // have this style, yet choose not to process this particular TAB in which | |
1858 | // case TAB must still work as a navigational character | |
1859 | #if 0 | |
1860 | (!focus->HasFlag(wxTE_PROCESS_TAB)) && | |
1861 | #endif | |
1862 | (focus->GetParent()) && | |
1863 | (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) | |
1864 | { | |
1865 | wxNavigationKeyEvent new_event; | |
1866 | new_event.SetEventObject( focus ); | |
1867 | new_event.SetDirection( !event.ShiftDown() ); | |
1868 | /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ | |
1869 | new_event.SetWindowChange( event.ControlDown() ); | |
1870 | new_event.SetCurrentFocus( focus ); | |
1871 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
1872 | if ( handled && new_event.GetSkipped() ) | |
1873 | handled = false ; | |
1874 | } | |
1875 | // backdoor handler for default return and command escape | |
1876 | if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) ) | |
1877 | { | |
1878 | // if window is not having a focus still testing for default enter or cancel | |
1879 | // TODO add the UMA version for ActiveNonFloatingWindow | |
1880 | wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; | |
1881 | if ( focus ) | |
1882 | { | |
1883 | if ( keyval == WXK_RETURN ) | |
1884 | { | |
1885 | wxButton *def = wxDynamicCast(focus->GetDefaultItem(), | |
1886 | wxButton); | |
1887 | if ( def && def->IsEnabled() ) | |
1888 | { | |
1889 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
1890 | event.SetEventObject(def); | |
1891 | def->Command(event); | |
1892 | return true ; | |
1893 | } | |
1894 | } | |
1895 | /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ | |
1896 | else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) | |
1897 | { | |
1898 | wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); | |
1899 | new_event.SetEventObject( focus ); | |
1900 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
1901 | } | |
1902 | } | |
1903 | } | |
1904 | return handled ; | |
1905 | } | |
1906 | ||
1907 | bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey ) | |
1908 | { | |
1909 | if ( !focus ) | |
1910 | return false ; | |
1911 | ||
1912 | short keycode ; | |
1913 | short keychar ; | |
1914 | keychar = short(keymessage & charCodeMask); | |
1915 | keycode = short(keymessage & keyCodeMask) >> 8 ; | |
1916 | if ( modifiers & ( controlKey|shiftKey|optionKey ) ) | |
1917 | { | |
1918 | // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier | |
1919 | // and look at the character after | |
1920 | UInt32 state = 0; | |
1921 | UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state); | |
1922 | keychar = short(keyInfo & charCodeMask); | |
1923 | keycode = short(keyInfo & keyCodeMask) >> 8 ; | |
1924 | } | |
1925 | long keyval = wxMacTranslateKey(keychar, keycode) ; | |
1926 | ||
1927 | if ( keyval == keychar ) | |
1928 | { | |
1929 | keyval = wxToupper( keyval ) ; | |
1930 | } | |
1931 | bool handled = false ; | |
1932 | ||
1933 | wxKeyEvent event(wxEVT_KEY_UP); | |
1934 | event.m_shiftDown = modifiers & shiftKey; | |
1935 | event.m_controlDown = modifiers & controlKey; | |
1936 | event.m_altDown = modifiers & optionKey; | |
1937 | event.m_metaDown = modifiers & cmdKey; | |
1938 | event.m_keyCode = keyval ; | |
1939 | ||
1940 | event.m_x = wherex; | |
1941 | event.m_y = wherey; | |
1942 | event.m_timeStamp = when; | |
1943 | event.SetEventObject(focus); | |
1944 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1945 | ||
1946 | return handled ; | |
1947 | } | |
1948 | ||
1949 | #if !TARGET_CARBON | |
1950 | void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) | |
1951 | { | |
1952 | EventRecord* ev = (EventRecord*) evr ; | |
1953 | WindowRef window = (WindowRef) ev->message ; | |
1954 | if ( window ) | |
1955 | { | |
1956 | bool activate = (ev->modifiers & activeFlag ) ; | |
1957 | WindowClass wclass ; | |
1958 | ::GetWindowClass ( window , &wclass ) ; | |
1959 | if ( wclass == kFloatingWindowClass ) | |
1960 | { | |
1961 | // if it is a floater we activate/deactivate the front non-floating window instead | |
1962 | window = ::FrontNonFloatingWindow() ; | |
1963 | } | |
1964 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
1965 | if ( win ) | |
1966 | win->MacActivate( ev->when , activate ) ; | |
1967 | } | |
1968 | } | |
1969 | ||
1970 | void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) | |
1971 | { | |
1972 | EventRecord* ev = (EventRecord*) evr ; | |
1973 | WindowRef window = (WindowRef) ev->message ; | |
1974 | wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; | |
1975 | if ( win ) | |
1976 | { | |
1977 | if ( !wxPendingDelete.Member(win) ) | |
1978 | win->MacUpdate( ev->when ) ; | |
1979 | } | |
1980 | else | |
1981 | { | |
1982 | // since there is no way of telling this foreign window to update itself | |
1983 | // we have to invalidate the update region otherwise we keep getting the same | |
1984 | // event over and over again | |
1985 | BeginUpdate( window ) ; | |
1986 | EndUpdate( window ) ; | |
1987 | } | |
1988 | } | |
1989 | ||
1990 | void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) | |
1991 | { | |
1992 | EventRecord* ev = (EventRecord*) evr ; | |
1993 | if ( HiWord( ev->message ) != noErr ) | |
1994 | { | |
1995 | OSErr err ; | |
1996 | Point point ; | |
1997 | SetPt( &point , 100 , 100 ) ; | |
1998 | ||
1999 | err = DIBadMount( point , ev->message ) ; | |
2000 | wxASSERT( err == noErr ) ; | |
2001 | } | |
2002 | } | |
2003 | ||
2004 | void wxApp::MacHandleOSEvent( WXEVENTREF evr ) | |
2005 | { | |
2006 | EventRecord* ev = (EventRecord*) evr ; | |
2007 | switch( ( ev->message & osEvtMessageMask ) >> 24 ) | |
2008 | { | |
2009 | case suspendResumeMessage : | |
2010 | { | |
2011 | bool isResuming = ev->message & resumeFlag ; | |
2012 | bool convertClipboard = ev->message & convertClipboardFlag ; | |
2013 | ||
2014 | bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; | |
2015 | if ( isResuming ) | |
2016 | { | |
2017 | WindowRef oldFrontWindow = NULL ; | |
2018 | WindowRef newFrontWindow = NULL ; | |
2019 | ||
2020 | // in case we don't take care of activating ourselves, we have to synchronize | |
2021 | // our idea of the active window with the process manager's - which it already activated | |
2022 | ||
2023 | if ( !doesActivate ) | |
2024 | oldFrontWindow = ::FrontNonFloatingWindow() ; | |
2025 | ||
2026 | MacResume( convertClipboard ) ; | |
2027 | ||
2028 | newFrontWindow = ::FrontNonFloatingWindow() ; | |
2029 | ||
2030 | if ( oldFrontWindow ) | |
2031 | { | |
2032 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; | |
2033 | if ( win ) | |
2034 | win->MacActivate( ev->when , false ) ; | |
2035 | } | |
2036 | if ( newFrontWindow ) | |
2037 | { | |
2038 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; | |
2039 | if ( win ) | |
2040 | win->MacActivate( ev->when , true ) ; | |
2041 | } | |
2042 | } | |
2043 | else | |
2044 | { | |
2045 | MacSuspend( convertClipboard ) ; | |
2046 | } | |
2047 | } | |
2048 | break ; | |
2049 | case mouseMovedMessage : | |
2050 | { | |
2051 | WindowRef window; | |
2052 | ||
2053 | wxWindow* currentMouseWindow = NULL ; | |
2054 | ||
2055 | if (s_captureWindow ) | |
2056 | { | |
2057 | currentMouseWindow = s_captureWindow ; | |
2058 | } | |
2059 | else | |
2060 | { | |
2061 | wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , | |
2062 | ¤tMouseWindow ) ; | |
2063 | } | |
2064 | ||
2065 | if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) | |
2066 | { | |
2067 | wxMouseEvent event ; | |
2068 | ||
2069 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
2070 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
2071 | ||
2072 | event.m_leftDown = isDown && !controlDown; | |
2073 | event.m_middleDown = FALSE; | |
2074 | event.m_rightDown = isDown && controlDown; | |
2075 | event.m_shiftDown = ev->modifiers & shiftKey; | |
2076 | event.m_controlDown = ev->modifiers & controlKey; | |
2077 | event.m_altDown = ev->modifiers & optionKey; | |
2078 | event.m_metaDown = ev->modifiers & cmdKey; | |
2079 | event.m_x = ev->where.h; | |
2080 | event.m_y = ev->where.v; | |
2081 | event.m_timeStamp = ev->when; | |
2082 | event.SetEventObject(this); | |
2083 | ||
2084 | if ( wxWindow::s_lastMouseWindow ) | |
2085 | { | |
2086 | wxMouseEvent eventleave(event); | |
2087 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
2088 | wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
2089 | eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; | |
2090 | ||
2091 | wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); | |
2092 | } | |
2093 | if ( currentMouseWindow ) | |
2094 | { | |
2095 | wxMouseEvent evententer(event); | |
2096 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
2097 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
2098 | evententer.SetEventObject( currentMouseWindow ) ; | |
2099 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
2100 | } | |
2101 | wxWindow::s_lastMouseWindow = currentMouseWindow ; | |
2102 | } | |
2103 | ||
2104 | short windowPart = inNoWindow ; | |
2105 | ||
2106 | if ( s_captureWindow ) | |
2107 | { | |
2108 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
2109 | windowPart = inContent ; | |
2110 | } | |
2111 | else | |
2112 | { | |
2113 | windowPart = ::FindWindow(ev->where, &window); | |
2114 | } | |
2115 | ||
2116 | switch (windowPart) | |
2117 | { | |
2118 | case inContent : | |
2119 | { | |
2120 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
2121 | if ( win ) | |
2122 | win->MacMouseMoved( ev , windowPart ) ; | |
2123 | else | |
2124 | { | |
2125 | if ( wxIsBusy() ) | |
2126 | { | |
2127 | } | |
2128 | else | |
2129 | UMAShowArrowCursor(); | |
2130 | } | |
2131 | } | |
2132 | break; | |
2133 | default : | |
2134 | { | |
2135 | if ( wxIsBusy() ) | |
2136 | { | |
2137 | } | |
2138 | else | |
2139 | UMAShowArrowCursor(); | |
2140 | } | |
2141 | break ; | |
2142 | } | |
2143 | } | |
2144 | break ; | |
2145 | ||
2146 | } | |
2147 | } | |
2148 | #else | |
2149 | ||
2150 | void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp) | |
2151 | { | |
2152 | WindowRef window; | |
2153 | ||
2154 | wxWindow* currentMouseWindow = NULL ; | |
2155 | ||
2156 | if (s_captureWindow ) | |
2157 | { | |
2158 | currentMouseWindow = s_captureWindow ; | |
2159 | } | |
2160 | else | |
2161 | { | |
2162 | wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , ¤tMouseWindow ) ; | |
2163 | } | |
2164 | ||
2165 | if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) | |
2166 | { | |
2167 | wxMouseEvent event ; | |
2168 | ||
2169 | bool isDown = !(modifiers & btnState) ; // 1 is for up | |
2170 | bool controlDown = modifiers & controlKey ; // for simulating right mouse | |
2171 | ||
2172 | event.m_leftDown = isDown && !controlDown; | |
2173 | ||
2174 | event.m_middleDown = FALSE; | |
2175 | event.m_rightDown = isDown && controlDown; | |
2176 | ||
2177 | event.m_shiftDown = modifiers & shiftKey; | |
2178 | event.m_controlDown = modifiers & controlKey; | |
2179 | event.m_altDown = modifiers & optionKey; | |
2180 | event.m_metaDown = modifiers & cmdKey; | |
2181 | ||
2182 | event.m_x = x; | |
2183 | event.m_y = y; | |
2184 | event.m_timeStamp = timestamp; | |
2185 | ||
2186 | if ( wxWindow::s_lastMouseWindow ) | |
2187 | { | |
2188 | wxMouseEvent eventleave(event); | |
2189 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
2190 | wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
2191 | eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; | |
2192 | ||
2193 | #if wxUSE_TOOLTIPS | |
2194 | wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave); | |
2195 | #endif // wxUSE_TOOLTIPS | |
2196 | wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); | |
2197 | } | |
2198 | if ( currentMouseWindow ) | |
2199 | { | |
2200 | wxMouseEvent evententer(event); | |
2201 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
2202 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
2203 | evententer.SetEventObject( currentMouseWindow ) ; | |
2204 | #if wxUSE_TOOLTIPS | |
2205 | wxToolTip::RelayEvent( currentMouseWindow , evententer); | |
2206 | #endif // wxUSE_TOOLTIPS | |
2207 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); | |
2208 | } | |
2209 | wxWindow::s_lastMouseWindow = currentMouseWindow ; | |
2210 | } | |
2211 | ||
2212 | short windowPart = inNoWindow ; | |
2213 | ||
2214 | if ( s_captureWindow ) | |
2215 | { | |
2216 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
2217 | windowPart = inContent ; | |
2218 | } | |
2219 | else | |
2220 | { | |
2221 | Point pt= { y , x } ; | |
2222 | windowPart = ::FindWindow(pt , &window); | |
2223 | } | |
2224 | ||
2225 | switch (windowPart) | |
2226 | { | |
2227 | case inContent : | |
2228 | { | |
2229 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; | |
2230 | if ( win ) | |
2231 | win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ; | |
2232 | else | |
2233 | { | |
2234 | if ( wxIsBusy() ) | |
2235 | { | |
2236 | } | |
2237 | else | |
2238 | UMAShowArrowCursor(); | |
2239 | } | |
2240 | } | |
2241 | break; | |
2242 | default : | |
2243 | { | |
2244 | if ( wxIsBusy() ) | |
2245 | { | |
2246 | } | |
2247 | else | |
2248 | UMAShowArrowCursor(); | |
2249 | } | |
2250 | break ; | |
2251 | } | |
2252 | } | |
2253 | #endif | |
2254 | ||
2255 | void wxApp::MacHandleMenuCommand( wxUint32 id ) | |
2256 | { | |
2257 | wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ; | |
2258 | wxFrame* frame = mbar->GetFrame(); | |
2259 | wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") ); | |
2260 | if ( frame ) | |
2261 | { | |
2262 | frame->ProcessCommand(id); | |
2263 | } | |
2264 | } | |
2265 | ||
2266 | #if !TARGET_CARBON | |
2267 | void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) | |
2268 | { | |
2269 | if (macMenuId == 0) | |
2270 | return; // no menu item selected | |
2271 | ||
2272 | if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1) | |
2273 | { | |
2274 | #if ! TARGET_CARBON | |
2275 | Str255 deskAccessoryName ; | |
2276 | GrafPtr savedPort ; | |
2277 | ||
2278 | GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName); | |
2279 | GetPort(&savedPort); | |
2280 | OpenDeskAcc(deskAccessoryName); | |
2281 | SetPort(savedPort); | |
2282 | #endif | |
2283 | } | |
2284 | else | |
2285 | { | |
2286 | MenuCommand id ; | |
2287 | GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ; | |
2288 | MacHandleMenuCommand( id ) ; | |
2289 | } | |
2290 | HiliteMenu(0); | |
2291 | } | |
2292 | #endif |