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