]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/app.cpp
cleanup - reformat; added (disabled) support for secondary highlight color
[wxWidgets.git] / src / mac / carbon / app.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
2996adee 12#include "wx/wxprec.h"
df06d1a4 13
03e11df5 14#include "wx/window.h"
e9576ca5 15#include "wx/frame.h"
e8566d35 16#include "wx/button.h"
e9576ca5
SC
17#include "wx/app.h"
18#include "wx/utils.h"
19#include "wx/gdicmn.h"
20#include "wx/pen.h"
21#include "wx/brush.h"
22#include "wx/cursor.h"
ed5b9811 23#include "wx/intl.h"
e9576ca5
SC
24#include "wx/icon.h"
25#include "wx/palette.h"
26#include "wx/dc.h"
27#include "wx/dialog.h"
28#include "wx/msgdlg.h"
29#include "wx/log.h"
30#include "wx/module.h"
31#include "wx/memory.h"
2f1ae414 32#include "wx/tooltip.h"
b3c406a5 33#include "wx/textctrl.h"
03e11df5 34#include "wx/menu.h"
738a6daa 35#include "wx/docview.h"
1c32ded3 36#include "wx/filename.h"
738a6daa 37
e9576ca5
SC
38#include <string.h>
39
8be97d65
SC
40// mac
41
f5c6eb5c 42#ifndef __DARWIN__
03e11df5 43 #if __option(profile)
8461e4c2 44 #include <profiler.h>
03e11df5 45 #endif
9779893b 46#endif
519cb848 47
9d331599 48// #include "apprsrc.h"
8be97d65 49
03e11df5
GD
50#include "wx/mac/uma.h"
51#include "wx/mac/macnotfy.h"
2f1ae414 52
df06d1a4
GD
53#ifdef __DARWIN__
54# include <CoreServices/CoreServices.h>
21870a5d 55# if defined(WXMAKINGDLL_CORE)
ed581ee2
GD
56# include <mach-o/dyld.h>
57# endif
df06d1a4
GD
58#else
59# include <Sound.h>
60# include <Threads.h>
61# include <ToolUtils.h>
62# include <DiskInit.h>
63# include <Devices.h>
2f1ae414 64#endif
519cb848 65
e9576ca5 66extern wxList wxPendingDelete;
facd6764 67
3fbf8e7f
SC
68// set wxMAC_USE_RAEL to 1 if RunApplicationEventLoop should be used
69// if 0 the lower level CarbonEventLoop will be used
70// on the long run RAEL should replace the low level event loop
902725ee 71// we will have to clean up event handling to make sure we don't
3fbf8e7f
SC
72// miss handling of things like pending events etc
73// perhaps we will also have to pipe events through an ueber-event-handler
74// to make sure we have one place to do all these house-keeping functions
75
76#define wxMAC_USE_RAEL 0
77
c944ce35 78#if wxUSE_THREADS
e64313ba 79extern size_t g_numberOfThreads;
8a9858ae 80#endif
e9576ca5 81
c5c9378c 82// statics for implementation
902725ee 83static bool s_inYield = false;
902725ee 84static bool s_inReceiveEvent = false ;
c5c9378c 85static EventTime sleepTime = kEventDurationNoWait ;
738a6daa 86
8a9858ae 87
e9576ca5
SC
88IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
89BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
90 EVT_IDLE(wxApp::OnIdle)
15b41e90
SC
91 EVT_END_SESSION(wxApp::OnEndSession)
92 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
e9576ca5 93END_EVENT_TABLE()
e9576ca5 94
169935ad 95
8be97d65 96// platform specific static variables
8a9858ae 97const short kMacMinHeap = (29 * 1024) ;
519cb848
SC
98const short kwxMacMenuBarResource = 1 ;
99const short kwxMacAppleMenuId = 1 ;
100
fbbdb7cd
GD
101WXHRGN wxApp::s_macCursorRgn = NULL;
102wxWindow* wxApp::s_captureWindow = NULL ;
103int wxApp::s_lastMouseDown = 0 ;
104long wxApp::sm_lastMessageTime = 0;
41d368a4
SC
105long wxApp::s_lastModifiers = 0 ;
106
fbbdb7cd
GD
107bool wxApp::s_macSupportPCMenuShortcuts = true ;
108long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
882b0479 109long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ;
2b5f62a0 110long wxApp::s_macExitMenuItemId = wxID_EXIT ;
427ff662 111wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ;
519cb848 112
8a9858ae
DS
113bool wxApp::sm_isEmbedded = false; // Normally we're not a plugin
114
15b41e90
SC
115//----------------------------------------------------------------------
116// Core Apple Event Support
117//----------------------------------------------------------------------
118
72055702
SC
119pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
120pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
121pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
122pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
1c32ded3 123pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
72055702 124
2a294857 125pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
519cb848 126{
8461e4c2 127 return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
519cb848
SC
128}
129
2a294857 130pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
519cb848 131{
8461e4c2 132 return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
519cb848
SC
133}
134
2a294857 135pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
519cb848 136{
8461e4c2 137 return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
519cb848
SC
138}
139
2a294857 140pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
519cb848 141{
8461e4c2 142 return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
519cb848
SC
143}
144
1c32ded3
SC
145pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
146{
147 return wxTheApp->MacHandleAERApp( (AppleEvent*) event , reply) ;
148}
149
15b41e90 150// AEODoc Calls MacOpenFile on each of the files passed
5ab6aab8 151
2072fbbb
SC
152short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
153{
154 AEDescList docList;
155 AEKeyword keywd;
156 DescType returnedType;
157 Size actualSize;
158 long itemsInList;
2072fbbb
SC
159 OSErr err;
160 short i;
8a9858ae 161
2072fbbb
SC
162 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
163 if (err != noErr)
164 return err;
7c9955d1 165
2072fbbb
SC
166 err = AECountItems(&docList, &itemsInList);
167 if (err != noErr)
168 return err;
7c9955d1 169
8461e4c2
VZ
170 ProcessSerialNumber PSN ;
171 PSN.highLongOfPSN = 0 ;
172 PSN.lowLongOfPSN = kCurrentProcess ;
173 SetFrontProcess( &PSN ) ;
7c9955d1 174
8a9858ae
DS
175 wxString fName ;
176 FSRef theRef ;
177
902725ee 178 for (i = 1; i <= itemsInList; i++)
a2b77260 179 {
8a9858ae
DS
180 AEGetNthPtr(
181 &docList, i, typeFSRef, &keywd, &returnedType,
182 (Ptr)&theRef, sizeof(theRef), &actualSize);
a2b77260
SC
183 fName = wxMacFSRefToPath( &theRef ) ;
184
2072fbbb
SC
185 MacOpenFile(fName);
186 }
8a9858ae 187
2072fbbb 188 return noErr;
519cb848
SC
189}
190
15b41e90
SC
191// AEPDoc Calls MacPrintFile on each of the files passed
192
2072fbbb 193short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply))
519cb848 194{
2072fbbb
SC
195 AEDescList docList;
196 AEKeyword keywd;
197 DescType returnedType;
198 Size actualSize;
199 long itemsInList;
2072fbbb
SC
200 OSErr err;
201 short i;
8a9858ae 202
2072fbbb
SC
203 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
204 if (err != noErr)
205 return err;
7c9955d1 206
2072fbbb
SC
207 err = AECountItems(&docList, &itemsInList);
208 if (err != noErr)
209 return err;
7c9955d1 210
2072fbbb
SC
211 ProcessSerialNumber PSN ;
212 PSN.highLongOfPSN = 0 ;
213 PSN.lowLongOfPSN = kCurrentProcess ;
214 SetFrontProcess( &PSN ) ;
7c9955d1 215
8a9858ae
DS
216 wxString fName ;
217 FSRef theRef ;
a2b77260 218
8a9858ae
DS
219 for (i = 1; i <= itemsInList; i++)
220 {
221 AEGetNthPtr(
222 &docList, i, typeFSRef, &keywd, &returnedType,
223 (Ptr)&theRef, sizeof(theRef), &actualSize);
a2b77260
SC
224 fName = wxMacFSRefToPath( &theRef ) ;
225
2072fbbb
SC
226 MacPrintFile(fName);
227 }
8a9858ae 228
2072fbbb 229 return noErr;
519cb848
SC
230}
231
15b41e90
SC
232// AEOApp calls MacNewFile
233
2a294857 234short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
519cb848 235{
2072fbbb 236 MacNewFile() ;
8461e4c2 237 return noErr ;
519cb848
SC
238}
239
76a60a81 240// AEQuit attempts to quit the application
15b41e90 241
2a294857 242short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
519cb848 243{
38106243 244 wxWindow* win = GetTopWindow() ;
8461e4c2
VZ
245 if ( win )
246 {
38106243
JS
247 wxCommandEvent exitEvent(wxEVT_COMMAND_MENU_SELECTED, s_macExitMenuItemId);
248 if (!win->ProcessEvent(exitEvent))
902725ee 249 win->Close(true) ;
8461e4c2 250 }
38106243 251 else
8461e4c2
VZ
252 {
253 ExitMainLoop() ;
254 }
8a9858ae 255
8461e4c2 256 return noErr ;
519cb848
SC
257}
258
1c32ded3
SC
259// AEROApp calls MacReopenApp
260
261short wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
262{
263 MacReopenApp() ;
8a9858ae 264
1c32ded3
SC
265 return noErr ;
266}
267
15b41e90
SC
268//----------------------------------------------------------------------
269// Support Routines linking the Mac...File Calls to the Document Manager
270//----------------------------------------------------------------------
271
272void wxApp::MacOpenFile(const wxString & fileName )
273{
179e085f 274#if wxUSE_DOC_VIEW_ARCHITECTURE
15b41e90
SC
275 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
276 if ( dm )
277 dm->CreateDocument(fileName , wxDOC_SILENT ) ;
179e085f 278#endif
15b41e90
SC
279}
280
179e085f 281
15b41e90
SC
282void wxApp::MacPrintFile(const wxString & fileName )
283{
179e085f
RN
284#if wxUSE_DOC_VIEW_ARCHITECTURE
285
286#if wxUSE_PRINTING_ARCHITECTURE
15b41e90
SC
287 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
288 if ( dm )
289 {
290 wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ;
291 if ( doc )
292 {
293 wxView* view = doc->GetFirstView() ;
8a9858ae 294 if ( view )
15b41e90
SC
295 {
296 wxPrintout *printout = view->OnCreatePrintout();
297 if (printout)
298 {
299 wxPrinter printer;
902725ee 300 printer.Print(view->GetFrame(), printout, true);
15b41e90
SC
301 delete printout;
302 }
303 }
8a9858ae 304
15b41e90
SC
305 if (doc->Close())
306 {
307 doc->DeleteAllViews();
308 dm->RemoveDocument(doc) ;
309 }
310 }
311 }
179e085f
RN
312#endif //print
313
314#endif //docview
15b41e90
SC
315}
316
179e085f
RN
317
318
15b41e90
SC
319void wxApp::MacNewFile()
320{
321}
322
1c32ded3
SC
323void wxApp::MacReopenApp()
324{
3f42061b
SC
325 // HIG says :
326 // if there is no open window -> create a new one
327 // if all windows are hidden -> show the first
328 // if some windows are not hidden -> do nothing
902725ee 329
3f42061b
SC
330 wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
331 if ( node == NULL )
902725ee 332 {
3f42061b
SC
333 MacNewFile() ;
334 }
335 else
336 {
3f42061b
SC
337 wxTopLevelWindow* firstIconized = NULL ;
338 while (node)
339 {
340 wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData();
8a9858ae 341 if ( !win->IsIconized() )
3f42061b
SC
342 {
343 firstIconized = NULL ;
344 break ;
345 }
346 else
347 {
348 if ( firstIconized == NULL )
349 firstIconized = win ;
350 }
8a9858ae 351
3f42061b
SC
352 node = node->GetNext();
353 }
8a9858ae 354
3f42061b
SC
355 if ( firstIconized )
356 firstIconized->Iconize( false ) ;
357 }
1c32ded3
SC
358}
359
ead6269a
SC
360//----------------------------------------------------------------------
361// Macintosh CommandID support - converting between native and wx IDs
362//----------------------------------------------------------------------
363
364// if no native match they just return the passed-in id
365
366struct IdPair
367{
368 UInt32 macId ;
369 int wxId ;
370} ;
371
372IdPair gCommandIds [] =
373{
374 { kHICommandCut , wxID_CUT } ,
375 { kHICommandCopy , wxID_COPY } ,
376 { kHICommandPaste , wxID_PASTE } ,
377 { kHICommandSelectAll , wxID_SELECTALL } ,
378 { kHICommandClear , wxID_CLEAR } ,
379 { kHICommandUndo , wxID_UNDO } ,
380 { kHICommandRedo , wxID_REDO } ,
381} ;
382
383int wxMacCommandToId( UInt32 macCommandId )
384{
385 int wxid = 0 ;
386
8a9858ae 387 switch ( macCommandId )
ead6269a 388 {
8a9858ae
DS
389 case kHICommandPreferences :
390 wxid = wxApp::s_macPreferencesMenuItemId ;
391 break ;
392
393 case kHICommandQuit :
394 wxid = wxApp::s_macExitMenuItemId ;
395 break ;
396
397 case kHICommandAbout :
398 wxid = wxApp::s_macAboutMenuItemId ;
399 break ;
400
401 default :
ead6269a 402 {
8a9858ae
DS
403 for ( size_t i = 0 ; i < WXSIZEOF(gCommandIds) ; ++i )
404 {
405 if ( gCommandIds[i].macId == macCommandId )
406 {
407 wxid = gCommandIds[i].wxId ;
408 break ;
409 }
410 }
ead6269a 411 }
8a9858ae 412 break ;
ead6269a 413 }
8a9858ae 414
ead6269a
SC
415 if ( wxid == 0 )
416 wxid = (int) macCommandId ;
8a9858ae 417
ead6269a
SC
418 return wxid ;
419}
420
421UInt32 wxIdToMacCommand( int wxId )
422{
423 UInt32 macId = 0 ;
424
425 if ( wxId == wxApp::s_macPreferencesMenuItemId )
426 macId = kHICommandPreferences ;
427 else if (wxId == wxApp::s_macExitMenuItemId)
428 macId = kHICommandQuit ;
429 else if (wxId == wxApp::s_macAboutMenuItemId)
430 macId = kHICommandAbout ;
431 else
432 {
433 for ( size_t i = 0 ; i < WXSIZEOF(gCommandIds) ; ++i )
434 {
435 if ( gCommandIds[i].wxId == wxId )
436 {
437 macId = gCommandIds[i].macId ;
438 break ;
439 }
440 }
441 }
8a9858ae 442
ead6269a
SC
443 if ( macId == 0 )
444 macId = (int) wxId ;
8a9858ae 445
ead6269a
SC
446 return macId ;
447}
448
449wxMenu* wxFindMenuFromMacCommand( const HICommand &command , wxMenuItem* &item )
450{
451 wxMenu* itemMenu = NULL ;
452 int id = 0 ;
8a9858ae 453
ead6269a 454 // for 'standard' commands which don't have a wx-menu
8a9858ae 455 if ( command.commandID == kHICommandPreferences || command.commandID == kHICommandQuit || command.commandID == kHICommandAbout )
ead6269a
SC
456 {
457 id = wxMacCommandToId( command.commandID ) ;
8a9858ae 458
ead6269a
SC
459 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
460 if ( mbar )
ead6269a 461 item = mbar->FindItem( id , &itemMenu ) ;
ead6269a
SC
462 }
463 else if ( command.commandID != 0 && command.menu.menuRef != 0 && command.menu.menuItemIndex != 0 )
464 {
465 id = wxMacCommandToId( command.commandID ) ;
466 // make sure it is one of our own menus, or of the 'synthetic' apple and help menus , otherwise don't touch
467 MenuItemIndex firstUserHelpMenuItem ;
468 static MenuHandle mh = NULL ;
469 if ( mh == NULL )
470 {
471 if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr )
ead6269a 472 mh = NULL ;
ead6269a 473 }
8a9858ae
DS
474
475 // is it part of the application or the Help menu, then look for the id directly
ead6269a
SC
476 if ( ( GetMenuHandle( kwxMacAppleMenuId ) != NULL && command.menu.menuRef == GetMenuHandle( kwxMacAppleMenuId ) ) ||
477 ( mh != NULL && command.menu.menuRef == mh ) )
478 {
479 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
480 if ( mbar )
ead6269a 481 item = mbar->FindItem( id , &itemMenu ) ;
ead6269a
SC
482 }
483 else
484 {
485 UInt32 refCon ;
8a9858ae 486
ead6269a
SC
487 GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ;
488 itemMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ;
489 if ( itemMenu != NULL )
ead6269a 490 item = (wxMenuItem*) refCon ;
ead6269a
SC
491 }
492 }
8a9858ae 493
ead6269a
SC
494 return itemMenu ;
495}
496
c5c9378c
SC
497//----------------------------------------------------------------------
498// Carbon Event Handler
499//----------------------------------------------------------------------
9779893b 500
facd6764
SC
501static const EventTypeSpec eventList[] =
502{
503 { kEventClassCommand, kEventProcessCommand } ,
504 { kEventClassCommand, kEventCommandUpdateStatus } ,
7c9955d1 505
facd6764
SC
506 { kEventClassMenu, kEventMenuOpening },
507 { kEventClassMenu, kEventMenuClosed },
508 { kEventClassMenu, kEventMenuTargetItem },
e32f4a9f 509
facd6764
SC
510 { kEventClassApplication , kEventAppActivated } ,
511 { kEventClassApplication , kEventAppDeactivated } ,
512 // handling the quit event is not recommended by apple
513 // rather using the quit apple event - which we do
7c9955d1 514
facd6764 515 { kEventClassAppleEvent , kEventAppleEvent } ,
7c9955d1 516
facd6764
SC
517 { kEventClassMouse , kEventMouseDown } ,
518 { kEventClassMouse , kEventMouseMoved } ,
519 { kEventClassMouse , kEventMouseUp } ,
520 { kEventClassMouse , kEventMouseDragged } ,
521 { 'WXMC' , 'WXMC' }
522} ;
519cb848 523
e32f4a9f 524static pascal OSStatus
facd6764 525wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
902725ee 526{
dae6d730
SC
527 wxMacCarbonEvent cEvent( event ) ;
528 MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;
529 wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;
902725ee 530
dae6d730 531 if ( menu )
e32f4a9f 532 {
902725ee 533 wxEventType type=0;
dae6d730
SC
534 MenuCommand cmd=0;
535 switch (GetEventKind(event))
852b1185 536 {
dae6d730
SC
537 case kEventMenuOpening:
538 type = wxEVT_MENU_OPEN;
539 break;
8a9858ae 540
dae6d730
SC
541 case kEventMenuClosed:
542 type = wxEVT_MENU_CLOSE;
543 break;
8a9858ae 544
dae6d730
SC
545 case kEventMenuTargetItem:
546 cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
902725ee 547 if (cmd != 0)
9f2bfce7 548 type = wxEVT_MENU_HIGHLIGHT;
dae6d730 549 break;
8a9858ae 550
dae6d730
SC
551 default:
552 wxFAIL_MSG(wxT("Unexpected menu event kind"));
553 break;
554 }
852b1185 555
dae6d730
SC
556 if ( type )
557 {
37a4035b 558 wxMenuEvent wxevent(type, cmd, menu);
dae6d730 559 wxevent.SetEventObject(menu);
e32f4a9f 560
dae6d730
SC
561 wxEvtHandler* handler = menu->GetEventHandler();
562 if (handler && handler->ProcessEvent(wxevent))
563 {
564 // handled
565 }
566 else
567 {
568 wxWindow *win = menu->GetInvokingWindow();
902725ee 569 if (win)
dae6d730
SC
570 win->GetEventHandler()->ProcessEvent(wxevent);
571 }
572 }
e32f4a9f 573 }
902725ee 574
e32f4a9f 575 return eventNotHandledErr;
519cb848
SC
576}
577
facd6764 578static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
15b41e90
SC
579{
580 OSStatus result = eventNotHandledErr ;
581
e40298d5 582 HICommand command ;
7c9955d1 583
dae6d730
SC
584 wxMacCarbonEvent cEvent( event ) ;
585 cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;
902725ee 586
dae6d730 587 wxMenuItem* item = NULL ;
ead6269a
SC
588 wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ;
589 int id = wxMacCommandToId( command.commandID ) ;
902725ee 590
ead6269a 591 if ( item )
6567c540 592 {
ead6269a 593 wxASSERT( itemMenu != NULL ) ;
6567c540 594
8a9858ae 595 switch ( cEvent.GetKind() )
6d565349 596 {
ead6269a 597 case kEventProcessCommand :
6567c540 598 {
e40298d5 599 if (item->IsCheckable())
e40298d5 600 item->Check( !item->IsChecked() ) ;
7c9955d1 601
ead6269a
SC
602 if ( itemMenu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) )
603 result = noErr ;
e40298d5 604 }
dae6d730 605 break ;
8a9858ae 606
e40298d5 607 case kEventCommandUpdateStatus:
ead6269a
SC
608 {
609 wxUpdateUIEvent event(id);
610 event.SetEventObject( itemMenu );
611
612 bool processed = false;
613
614 // Try the menu's event handler
615 {
616 wxEvtHandler *handler = itemMenu->GetEventHandler();
617 if ( handler )
618 processed = handler->ProcessEvent(event);
619 }
620
8a9858ae
DS
621 // Try the window the menu was popped up from
622 // (and up through the hierarchy)
ead6269a
SC
623 if ( !processed )
624 {
625 const wxMenuBase *menu = itemMenu;
626 while ( menu )
627 {
628 wxWindow *win = menu->GetInvokingWindow();
629 if ( win )
630 {
631 processed = win->GetEventHandler()->ProcessEvent(event);
632 break;
633 }
634
635 menu = menu->GetParent();
636 }
637 }
638
639 if ( processed )
640 {
641 // if anything changed, update the changed attribute
642 if (event.GetSetText())
643 itemMenu->SetLabel(id, event.GetText());
644 if (event.GetSetChecked())
645 itemMenu->Check(id, event.GetChecked());
646 if (event.GetSetEnabled())
647 itemMenu->Enable(id, event.GetEnabled());
648
649 result = noErr ;
650 }
651 }
e40298d5 652 break ;
8a9858ae 653
dae6d730
SC
654 default :
655 break ;
656 }
657 }
15b41e90
SC
658 return result ;
659}
660
facd6764 661static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
15b41e90
SC
662{
663 OSStatus result = eventNotHandledErr ;
e40298d5
JS
664 switch ( GetEventKind( event ) )
665 {
666 case kEventAppActivated :
8a9858ae
DS
667 if ( wxTheApp )
668 wxTheApp->SetActive( true , NULL ) ;
669 result = noErr ;
e40298d5 670 break ;
8a9858ae 671
e40298d5 672 case kEventAppDeactivated :
8a9858ae
DS
673 if ( wxTheApp )
674 wxTheApp->SetActive( false , NULL ) ;
675 result = noErr ;
e40298d5 676 break ;
8a9858ae 677
e40298d5
JS
678 default :
679 break ;
680 }
8a9858ae 681
15b41e90
SC
682 return result ;
683}
684
facd6764 685pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
15b41e90 686{
27740109
SC
687 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
688 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
689 wxTheApp->MacSetCurrentEvent( event , handler ) ;
690
15b41e90 691 OSStatus result = eventNotHandledErr ;
8a9858ae 692 switch ( GetEventClass( event ) )
15b41e90 693 {
e40298d5 694 case kEventClassCommand :
facd6764 695 result = wxMacAppCommandEventHandler( handler , event , data ) ;
e40298d5 696 break ;
8a9858ae 697
e40298d5 698 case kEventClassApplication :
facd6764 699 result = wxMacAppApplicationEventHandler( handler , event , data ) ;
e40298d5 700 break ;
8a9858ae 701
e40298d5 702 case kEventClassMenu :
facd6764 703 result = wxMacAppMenuEventHandler( handler , event , data ) ;
e40298d5 704 break ;
8a9858ae 705
e40298d5 706 case kEventClassMouse :
95a8b77a
SC
707 {
708 wxMacCarbonEvent cEvent( event ) ;
902725ee 709
95a8b77a
SC
710 WindowRef window ;
711 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
255df092 712 ::FindWindow(screenMouseLocation, &window);
95a8b77a
SC
713 // only send this event in case it had not already been sent to a tlw, as we get
714 // double events otherwise (in case event.skip) was called
715 if ( window == NULL )
716 result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
717 }
e40298d5 718 break ;
8a9858ae 719
e40298d5
JS
720 case kEventClassAppleEvent :
721 {
722 EventRecord rec ;
8a9858ae 723
e40298d5
JS
724 wxMacConvertEventToRecord( event , &rec ) ;
725 result = AEProcessAppleEvent( &rec ) ;
726 }
727 break ;
8a9858ae 728
e40298d5
JS
729 default :
730 break ;
15b41e90
SC
731 }
732
27740109
SC
733 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
734
15b41e90
SC
735 return result ;
736}
737
facd6764 738DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler )
15b41e90 739
21870a5d 740#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
53fd991c
SC
741// we know it's there ;-)
742WXIMPORT char std::__throws_bad_alloc ;
743#endif
744
e822273a 745#ifdef __WXDEBUG__
8d1147f9 746
902725ee
WS
747pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options,
748 const char *assertionString, const char *exceptionLabelString,
facd6764 749 const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg)
e9576ca5 750{
facd6764
SC
751 // flow into assert handling
752 wxString fileNameStr ;
753 wxString assertionStr ;
754 wxString exceptionStr ;
755 wxString errorStr ;
8a9858ae 756
facd6764
SC
757#if wxUSE_UNICODE
758 fileNameStr = wxString(fileName, wxConvLocal);
759 assertionStr = wxString(assertionString, wxConvLocal);
760 exceptionStr = wxString((exceptionLabelString!=0) ? exceptionLabelString : "", wxConvLocal) ;
761 errorStr = wxString((errorString!=0) ? errorString : "", wxConvLocal) ;
762#else
763 fileNameStr = fileName;
764 assertionStr = assertionString;
765 exceptionStr = (exceptionLabelString!=0) ? exceptionLabelString : "" ;
766 errorStr = (errorString!=0) ? errorString : "" ;
767#endif
9779893b 768
facd6764
SC
769#if 1
770 // flow into log
902725ee
WS
771 wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %ld (value %p)\n"),
772 assertionStr.c_str() ,
773 exceptionStr.c_str() ,
774 errorStr.c_str(),
facd6764
SC
775 fileNameStr.c_str(), lineNumber ,
776 value ) ;
777#else
778
779 wxOnAssert(fileNameStr, lineNumber , assertionStr ,
8a9858ae 780 wxString::Format( wxT("%s %s value (%p)") , exceptionStr, errorStr , value ) ) ;
facd6764
SC
781#endif
782}
783
8d1147f9
RN
784#endif //__WXDEBUG__
785
ec8565f3 786#ifdef __WXMAC_OSX__
8a9858ae
DS
787extern "C"
788{
789 // m_macEventPosted run loop source callback:
ec8565f3 790 void macPostedEventCallback(void *unused);
95e568ee
KH
791}
792
8a9858ae
DS
793void macPostedEventCallback(void *unused)
794{
795 wxTheApp->ProcessPendingEvents();
796}
ec8565f3
KH
797#endif
798
facd6764
SC
799bool wxApp::Initialize(int& argc, wxChar **argv)
800{
fbbdb7cd 801 // Mac-specific
9779893b 802
e822273a 803#ifdef __WXDEBUG__
8a9858ae 804 InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );
facd6764 805#endif
8a9858ae 806
e128397f 807 UMAInitToolbox( 4, sm_isEmbedded ) ;
fbbdb7cd 808 SetEventMask( everyEvent ) ;
8461e4c2 809 UMAShowWatchCursor() ;
8be97d65 810
f5c6eb5c 811#ifndef __DARWIN__
fbbdb7cd 812# if __option(profile)
882b0479 813 ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ;
fbbdb7cd 814# endif
9779893b 815#endif
519cb848 816
f5c6eb5c 817#ifndef __DARWIN__
ed581ee2 818 // now avoid exceptions thrown for new (bad_alloc)
e40298d5 819 // FIXME CS for some changes outside wxMac does not compile anymore
15b41e90
SC
820#if 0
821 std::__throws_bad_alloc = 0 ;
822#endif
823
03e11df5 824#endif
7c9955d1 825
8461e4c2 826 s_macCursorRgn = ::NewRgn() ;
8be97d65 827
05e2b077
VZ
828 // Mac OS X passes a process serial number command line argument when
829 // the application is launched from the Finder. This argument must be
830 // removed from the command line arguments before being handled by the
831 // application (otherwise applications would need to handle it)
832 if ( argc > 1 )
833 {
834 static const wxChar *ARG_PSN = _T("-psn_");
46e2a2e7 835 if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 )
05e2b077
VZ
836 {
837 // remove this argument
33f39af3
GD
838 --argc;
839 memmove(argv + 1, argv + 2, argc * sizeof(char *));
05e2b077
VZ
840 }
841 }
842
94826170
VZ
843 if ( !wxAppBase::Initialize(argc, argv) )
844 return false;
e9576ca5 845
d9d19e75
SC
846#if wxUSE_INTL
847 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
848#endif
849
e256c692
SC
850#if TARGET_API_MAC_OSX
851 // these might be the startup dirs, set them to the 'usual' dir containing the app bundle
852 wxString startupCwd = wxGetCwd() ;
6601362a 853 if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") )
e256c692 854 {
e256c692
SC
855 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ;
856 CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ;
857 CFRelease( url ) ;
858 CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ;
859 CFRelease( urlParent ) ;
902725ee 860 wxString cwd = wxMacCFStringHolder(path).AsString(wxLocale::GetSystemEncoding());
e256c692
SC
861 wxSetWorkingDirectory( cwd ) ;
862 }
863#endif
d9d19e75 864
376b18ea 865 wxMacCreateNotifierTable() ;
9779893b 866
ec8565f3 867#ifdef __WXMAC_OSX__
95e568ee
KH
868 /* connect posted events to common-mode run loop so that wxPostEvent events
869 are handled even while we're in the menu or on a scrollbar */
870 CFRunLoopSourceContext event_posted_context = {0};
871 event_posted_context.perform = macPostedEventCallback;
872 m_macEventPosted = CFRunLoopSourceCreate(NULL,0,&event_posted_context);
873 CFRunLoopAddSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes);
ec8565f3 874#endif
95e568ee 875
376b18ea 876 UMAShowArrowCursor() ;
8461e4c2 877
94826170 878 return true;
e9576ca5
SC
879}
880
9b58521d
SC
881AEEventHandlerUPP sODocHandler = NULL ;
882AEEventHandlerUPP sOAppHandler = NULL ;
883AEEventHandlerUPP sPDocHandler = NULL ;
884AEEventHandlerUPP sRAppHandler = NULL ;
885AEEventHandlerUPP sQuitHandler = NULL ;
886
15b41e90
SC
887bool wxApp::OnInitGui()
888{
8a9858ae 889 if ( !wxAppBase::OnInitGui() )
e40298d5 890 return false ;
7c9955d1 891
e40298d5 892 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
7c9955d1 893
e128397f
DS
894 if (!sm_isEmbedded)
895 {
896 InstallApplicationEventHandler(
facd6764 897 GetwxMacAppEventHandlerUPP(),
e128397f
DS
898 GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler));
899 }
7c9955d1 900
e128397f
DS
901 if (!sm_isEmbedded)
902 {
9b58521d
SC
903 sODocHandler = NewAEEventHandlerUPP(AEHandleODoc) ;
904 sOAppHandler = NewAEEventHandlerUPP(AEHandleOApp) ;
905 sPDocHandler = NewAEEventHandlerUPP(AEHandlePDoc) ;
906 sRAppHandler = NewAEEventHandlerUPP(AEHandleRApp) ;
907 sQuitHandler = NewAEEventHandlerUPP(AEHandleQuit) ;
908
e128397f 909 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
9b58521d 910 sODocHandler , 0 , FALSE ) ;
e128397f 911 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
9b58521d 912 sOAppHandler , 0 , FALSE ) ;
e128397f 913 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
9b58521d 914 sPDocHandler , 0 , FALSE ) ;
1c32ded3 915 AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,
9b58521d 916 sRAppHandler , 0 , FALSE ) ;
e128397f 917 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
9b58521d 918 sQuitHandler , 0 , FALSE ) ;
e128397f 919 }
15b41e90 920
902725ee 921 return true ;
15b41e90
SC
922}
923
e9576ca5
SC
924void wxApp::CleanUp()
925{
e3e34b26 926#if wxUSE_TOOLTIPS
12cd5f34 927 wxToolTip::RemoveToolTips() ;
e3e34b26 928#endif
2f1ae414 929
ec8565f3 930#ifdef __WXMAC_OSX__
95e568ee 931 if (m_macEventPosted)
95e568ee 932 CFRelease(m_macEventPosted);
95e568ee 933 m_macEventPosted = NULL;
ec8565f3 934#endif
95e568ee 935
2f1ae414
SC
936 // One last chance for pending objects to be cleaned up
937 wxTheApp->DeletePendingObjects();
938
fbbdb7cd 939 wxMacDestroyNotifierTable() ;
84c1ffa9 940
f5c6eb5c 941#ifndef __DARWIN__
fbbdb7cd 942# if __option(profile)
ac2153a6 943 ProfilerDump( (StringPtr)"\papp.prof" ) ;
fbbdb7cd
GD
944 ProfilerTerm() ;
945# endif
3246bafd 946#endif
e9b41b24 947
8461e4c2 948 UMACleanupToolbox() ;
8a9858ae 949 if (s_macCursorRgn)
76a5e5d2 950 ::DisposeRgn((RgnHandle)s_macCursorRgn);
84c1ffa9 951
9b58521d 952 if (!sm_isEmbedded)
9b58521d 953 RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) );
902725ee 954
9b58521d
SC
955 if (!sm_isEmbedded)
956 {
957 AERemoveEventHandler( kCoreEventClass , kAEOpenDocuments ,
958 sODocHandler , FALSE ) ;
959 AERemoveEventHandler( kCoreEventClass , kAEOpenApplication ,
960 sOAppHandler , FALSE ) ;
961 AERemoveEventHandler( kCoreEventClass , kAEPrintDocuments ,
962 sPDocHandler , FALSE ) ;
963 AERemoveEventHandler( kCoreEventClass , kAEReopenApplication ,
964 sRAppHandler , FALSE ) ;
965 AERemoveEventHandler( kCoreEventClass , kAEQuitApplication ,
966 sQuitHandler , FALSE ) ;
902725ee 967
9b58521d
SC
968 DisposeAEEventHandlerUPP( sODocHandler ) ;
969 DisposeAEEventHandlerUPP( sOAppHandler ) ;
970 DisposeAEEventHandlerUPP( sPDocHandler ) ;
971 DisposeAEEventHandlerUPP( sRAppHandler ) ;
972 DisposeAEEventHandlerUPP( sQuitHandler ) ;
973 }
94826170
VZ
974
975 wxAppBase::CleanUp();
e9576ca5
SC
976}
977
92b002a4 978//----------------------------------------------------------------------
05e2b077 979// misc initialization stuff
92b002a4
RD
980//----------------------------------------------------------------------
981
21870a5d 982#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
53fd991c 983
ed581ee2
GD
984// for shared libraries we have to manually get the correct resource
985// ref num upon initializing and releasing when terminating, therefore
986// the __wxinitialize and __wxterminate must be used
53fd991c 987
8a9858ae
DS
988extern "C"
989{
990 void __sinit(void); // (generated by linker)
fbbdb7cd
GD
991 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
992 pascal void __terminate(void);
53fd991c 993}
53fd991c
SC
994
995pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
996{
fbbdb7cd 997 return __initialize( theInitBlock ) ;
53fd991c
SC
998}
999
1000pascal void __wxterminate(void)
1001{
53fd991c
SC
1002 __terminate() ;
1003}
ed581ee2 1004
21870a5d 1005#endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
53fd991c 1006
b4efa069
SC
1007bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
1008{
b4efa069 1009 OSStatus err = noErr ;
8a9858ae
DS
1010 bool converted = ConvertEventRefToEventRecord( event, rec) ;
1011
b4efa069
SC
1012 if ( !converted )
1013 {
8a9858ae 1014 switch ( GetEventClass( event ) )
b4efa069
SC
1015 {
1016 case kEventClassKeyboard :
1017 {
1018 converted = true ;
8a9858ae 1019 switch ( GetEventKind(event) )
b4efa069
SC
1020 {
1021 case kEventRawKeyDown :
1022 rec->what = keyDown ;
1023 break ;
8a9858ae 1024
b4efa069
SC
1025 case kEventRawKeyRepeat :
1026 rec->what = autoKey ;
1027 break ;
8a9858ae 1028
b4efa069
SC
1029 case kEventRawKeyUp :
1030 rec->what = keyUp ;
1031 break ;
8a9858ae 1032
b4efa069
SC
1033 case kEventRawKeyModifiersChanged :
1034 rec->what = nullEvent ;
1035 break ;
8a9858ae 1036
b4efa069
SC
1037 default :
1038 converted = false ;
1039 break ;
1040 }
8a9858ae 1041
b4efa069
SC
1042 if ( converted )
1043 {
1044 UInt32 keyCode ;
1045 unsigned char charCode ;
1046 UInt32 modifiers ;
1047 GetMouse( &rec->where) ;
1048
1049 err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
1050 err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
1051 err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
1052 rec->modifiers = modifiers ;
1053 rec->message = (keyCode << 8 ) + charCode ;
1054 }
1055 }
1056 break ;
8a9858ae 1057
b4efa069
SC
1058 case kEventClassTextInput :
1059 {
8a9858ae 1060 switch ( GetEventKind( event ) )
b4efa069
SC
1061 {
1062 case kEventTextInputUnicodeForKeyEvent :
1063 {
1064 EventRef rawEvent ;
8a9858ae
DS
1065 err = GetEventParameter(
1066 event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL,
1067 sizeof(rawEvent), NULL, &rawEvent ) ;
b4efa069 1068 converted = true ;
8a9858ae 1069
b4efa069 1070 {
8a9858ae 1071 UInt32 keyCode, modifiers;
b4efa069 1072 unsigned char charCode ;
8a9858ae 1073
b4efa069
SC
1074 GetMouse( &rec->where) ;
1075 rec->what = keyDown ;
1076 err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
1077 err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
1078 err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
1079 rec->modifiers = modifiers ;
1080 rec->message = (keyCode << 8 ) + charCode ;
1081 }
1082 }
8a9858ae
DS
1083 break ;
1084
b4efa069
SC
1085 default :
1086 break ;
1087 }
1088 }
1089 break ;
8a9858ae
DS
1090
1091 default :
1092 break ;
b4efa069
SC
1093 }
1094 }
84c1ffa9 1095
b4efa069
SC
1096 return converted ;
1097}
1098
e9576ca5
SC
1099wxApp::wxApp()
1100{
ec8565f3 1101 m_printMode = wxPRINT_WINDOWS;
1ea39a03 1102
ec8565f3
KH
1103 m_macCurrentEvent = NULL ;
1104 m_macCurrentEventHandlerCallRef = NULL ;
8a9858ae 1105
ec8565f3
KH
1106#ifdef __WXMAC_OSX__
1107 m_macEventPosted = NULL ;
1108#endif
e9576ca5
SC
1109}
1110
e9576ca5
SC
1111int wxApp::MainLoop()
1112{
902725ee 1113 m_keepGoing = true;
8a9858ae 1114
3fbf8e7f
SC
1115#if wxMAC_USE_RAEL
1116 RunApplicationEventLoop() ;
1117#else
e40298d5
JS
1118 while (m_keepGoing)
1119 {
1120 MacDoOneEvent() ;
1121 }
3fbf8e7f 1122#endif
8a9858ae 1123
e40298d5 1124 return 0;
e9576ca5
SC
1125}
1126
e9576ca5
SC
1127void wxApp::ExitMainLoop()
1128{
902725ee 1129 m_keepGoing = false;
8a9858ae 1130
3fbf8e7f
SC
1131#if wxMAC_USE_RAEL
1132 QuitApplicationEventLoop() ;
1133#endif
e9576ca5
SC
1134}
1135
1136// Is a message/event pending?
1137bool wxApp::Pending()
1138{
2dd35daa
SC
1139 // without the receive event (with pull param = false ) nothing is ever reported
1140 EventRef theEvent;
8a9858ae
DS
1141
1142 ReceiveNextEvent(0, NULL, kEventDurationNoWait, false, &theEvent);
1143
902725ee 1144 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
e9576ca5
SC
1145}
1146
1147// Dispatch a message.
1bf77ee5 1148bool wxApp::Dispatch()
e9576ca5 1149{
8461e4c2 1150 MacDoOneEvent() ;
1bf77ee5
VZ
1151
1152 return true;
e9576ca5
SC
1153}
1154
1155void wxApp::OnIdle(wxIdleEvent& event)
1156{
955a9197 1157 wxAppBase::OnIdle(event);
21870a5d 1158
2f1ae414
SC
1159 // If they are pending events, we must process them: pending events are
1160 // either events to the threads other than main or events posted with
1161 // wxPostEvent() functions
1162 wxMacProcessNotifierAndPendingEvents();
1163
8a9858ae 1164 if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
3fdac2ab 1165 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
e9576ca5
SC
1166}
1167
e2478fde 1168void wxApp::WakeUpIdle()
9779893b 1169{
ec8565f3 1170#ifdef __WXMAC_OSX__
95e568ee
KH
1171 if (m_macEventPosted)
1172 {
1173 CFRunLoopSourceSignal(m_macEventPosted);
1174 }
ec8565f3 1175#endif
8a9858ae 1176
8461e4c2 1177 wxMacWakeUp() ;
9779893b
RD
1178}
1179
e2478fde 1180void wxApp::Exit()
e9576ca5 1181{
2f1ae414 1182 wxApp::CleanUp();
8461e4c2 1183 ::ExitToShell() ;
e9576ca5
SC
1184}
1185
2f1ae414
SC
1186void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1187{
1188 if (GetTopWindow())
902725ee 1189 GetTopWindow()->Close(true);
2f1ae414
SC
1190}
1191
1192// Default behaviour: close the application with prompts. The
1193// user can veto the close, and therefore the end session.
1194void wxApp::OnQueryEndSession(wxCloseEvent& event)
1195{
1196 if (GetTopWindow())
1197 {
1198 if (!GetTopWindow()->Close(!event.CanVeto()))
902725ee 1199 event.Veto(true);
2f1ae414
SC
1200 }
1201}
1202
1203extern "C" void wxCYield() ;
1204void wxCYield()
1205{
8461e4c2 1206 wxYield() ;
2f1ae414
SC
1207}
1208
e9576ca5 1209// Yield to other processes
cb2713bf 1210
8461e4c2 1211bool wxApp::Yield(bool onlyIfNeeded)
e9576ca5 1212{
8461e4c2
VZ
1213 if (s_inYield)
1214 {
1215 if ( !onlyIfNeeded )
1216 {
1217 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1218 }
1219
902725ee 1220 return false;
8461e4c2
VZ
1221 }
1222
902725ee 1223 s_inYield = true;
cb2713bf 1224
e40298d5 1225 // by definition yield should handle all non-processed events
facd6764 1226
e40298d5
JS
1227 EventRef theEvent;
1228
1229 OSStatus status = noErr ;
8a9858ae
DS
1230
1231 while ( status == noErr )
e40298d5
JS
1232 {
1233 s_inReceiveEvent = true ;
1234 status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
1235 s_inReceiveEvent = false ;
7c9955d1 1236
e40298d5
JS
1237 if ( status == eventLoopTimedOutErr )
1238 {
1239 // make sure next time the event loop will trigger idle events
1240 sleepTime = kEventDurationNoWait ;
1241 }
1242 else if ( status == eventLoopQuitErr )
1243 {
1244 // according to QA1061 this may also occur when a WakeUp Process
1245 // is executed
1246 }
1247 else
1248 {
1249 MacHandleOneEvent( theEvent ) ;
1250 ReleaseEvent(theEvent);
1251 }
8a9858ae 1252 }
2f1ae414 1253
8461e4c2 1254 wxMacProcessNotifierAndPendingEvents() ;
902725ee 1255 s_inYield = false;
cb2713bf 1256
902725ee 1257 return true;
169935ad
SC
1258}
1259
9779893b 1260void wxApp::MacDoOneEvent()
169935ad 1261{
e40298d5 1262 EventRef theEvent;
c5c9378c 1263
e40298d5 1264 s_inReceiveEvent = true ;
8a9858ae 1265 OSStatus status = ReceiveNextEvent(0, NULL, sleepTime, true, &theEvent) ;
e40298d5 1266 s_inReceiveEvent = false ;
8a9858ae
DS
1267
1268 switch (status)
e40298d5 1269 {
8a9858ae
DS
1270 case eventLoopTimedOutErr :
1271 if ( wxTheApp->ProcessIdle() )
1272 sleepTime = kEventDurationNoWait ;
1273 else
1274 sleepTime = kEventDurationSecond;
1275 break;
1276
1277 case eventLoopQuitErr :
1278 // according to QA1061 this may also occur
1279 // when a WakeUp Process is executed
1280 break;
1281
1282 default:
1283 MacHandleOneEvent( theEvent ) ;
1284 ReleaseEvent( theEvent );
e40298d5 1285 sleepTime = kEventDurationNoWait ;
8a9858ae 1286 break;
e40298d5 1287 }
8461e4c2 1288 // repeaters
519cb848 1289
6264b550 1290 DeletePendingObjects() ;
8461e4c2 1291 wxMacProcessNotifierAndPendingEvents() ;
169935ad
SC
1292}
1293
8a9858ae
DS
1294// virtual
1295void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr )
e128397f 1296{
902725ee 1297 // Override to process unhandled events as you please
e128397f
DS
1298}
1299
76a5e5d2 1300void wxApp::MacHandleOneEvent( WXEVENTREF evr )
169935ad 1301{
e40298d5
JS
1302 EventTargetRef theTarget;
1303 theTarget = GetEventDispatcherTarget();
c5c9378c 1304 m_macCurrentEvent = evr ;
8a9858ae
DS
1305
1306 OSStatus status = SendEventToEventTarget((EventRef) evr , theTarget);
1307 if (status == eventNotHandledErr)
e128397f 1308 MacHandleUnhandledEvent(evr);
8a9858ae 1309
8461e4c2 1310 wxMacProcessNotifierAndPendingEvents() ;
8a9858ae 1311
f8df60f2
SC
1312#if wxUSE_THREADS
1313 wxMutexGuiLeaveOrEnter();
1314#endif // wxUSE_THREADS
169935ad
SC
1315}
1316
72055702 1317long wxMacTranslateKey(unsigned char key, unsigned char code) ;
7c551d95 1318long wxMacTranslateKey(unsigned char key, unsigned char code)
9779893b 1319{
8461e4c2 1320 long retval = key ;
9779893b 1321 switch (key)
519cb848 1322 {
12e049f6 1323 case kHomeCharCode :
902725ee
WS
1324 retval = WXK_HOME;
1325 break;
1326
12e049f6 1327 case kEnterCharCode :
902725ee
WS
1328 retval = WXK_RETURN;
1329 break;
12e049f6 1330 case kEndCharCode :
902725ee
WS
1331 retval = WXK_END;
1332 break;
1333
12e049f6 1334 case kHelpCharCode :
902725ee
WS
1335 retval = WXK_HELP;
1336 break;
1337
12e049f6 1338 case kBackspaceCharCode :
902725ee
WS
1339 retval = WXK_BACK;
1340 break;
1341
12e049f6 1342 case kTabCharCode :
902725ee
WS
1343 retval = WXK_TAB;
1344 break;
1345
12e049f6 1346 case kPageUpCharCode :
902725ee
WS
1347 retval = WXK_PAGEUP;
1348 break;
1349
12e049f6 1350 case kPageDownCharCode :
902725ee
WS
1351 retval = WXK_PAGEDOWN;
1352 break;
1353
12e049f6 1354 case kReturnCharCode :
902725ee
WS
1355 retval = WXK_RETURN;
1356 break;
1357
1358 case kFunctionKeyCharCode :
1359 {
8a9858ae 1360 switch ( code )
8461e4c2 1361 {
902725ee
WS
1362 case 0x7a :
1363 retval = WXK_F1 ;
1364 break;
8a9858ae 1365
902725ee
WS
1366 case 0x78 :
1367 retval = WXK_F2 ;
1368 break;
8a9858ae 1369
902725ee
WS
1370 case 0x63 :
1371 retval = WXK_F3 ;
1372 break;
8a9858ae 1373
902725ee
WS
1374 case 0x76 :
1375 retval = WXK_F4 ;
1376 break;
8a9858ae 1377
902725ee
WS
1378 case 0x60 :
1379 retval = WXK_F5 ;
1380 break;
8a9858ae 1381
902725ee
WS
1382 case 0x61 :
1383 retval = WXK_F6 ;
1384 break;
8a9858ae 1385
902725ee
WS
1386 case 0x62:
1387 retval = WXK_F7 ;
1388 break;
8a9858ae 1389
902725ee
WS
1390 case 0x64 :
1391 retval = WXK_F8 ;
1392 break;
8a9858ae 1393
902725ee
WS
1394 case 0x65 :
1395 retval = WXK_F9 ;
1396 break;
8a9858ae 1397
902725ee
WS
1398 case 0x6D :
1399 retval = WXK_F10 ;
1400 break;
8a9858ae 1401
902725ee
WS
1402 case 0x67 :
1403 retval = WXK_F11 ;
1404 break;
8a9858ae 1405
902725ee
WS
1406 case 0x6F :
1407 retval = WXK_F12 ;
1408 break;
8a9858ae 1409
902725ee
WS
1410 case 0x69 :
1411 retval = WXK_F13 ;
1412 break;
8a9858ae 1413
902725ee
WS
1414 case 0x6B :
1415 retval = WXK_F14 ;
1416 break;
8a9858ae 1417
902725ee
WS
1418 case 0x71 :
1419 retval = WXK_F15 ;
1420 break;
8a9858ae
DS
1421
1422 default:
1423 break;
8461e4c2 1424 }
902725ee
WS
1425 }
1426 break ;
1427
1428 case kEscapeCharCode :
1429 retval = WXK_ESCAPE ;
8461e4c2 1430 break ;
902725ee
WS
1431
1432 case kLeftArrowCharCode :
1433 retval = WXK_LEFT ;
8461e4c2 1434 break ;
902725ee
WS
1435
1436 case kRightArrowCharCode :
1437 retval = WXK_RIGHT ;
8461e4c2 1438 break ;
902725ee
WS
1439
1440 case kUpArrowCharCode :
1441 retval = WXK_UP ;
8461e4c2 1442 break ;
902725ee
WS
1443
1444 case kDownArrowCharCode :
1445 retval = WXK_DOWN ;
8461e4c2 1446 break ;
902725ee
WS
1447
1448 case kDeleteCharCode :
1449 retval = WXK_DELETE ;
8461e4c2 1450 break ;
902725ee
WS
1451
1452 default:
8461e4c2
VZ
1453 break ;
1454 } // end switch
1455
1456 return retval;
169935ad
SC
1457}
1458
facd6764 1459int wxMacKeyCodeToModifier(wxKeyCode key)
6ed892f3
RN
1460{
1461 switch (key)
1462 {
1463 case WXK_START:
15c2acd2 1464 case WXK_MENU:
6ed892f3
RN
1465 return cmdKey;
1466
1467 case WXK_SHIFT:
1468 return shiftKey;
1469
1470 case WXK_CAPITAL:
1471 return alphaLock;
1472
15c2acd2
RN
1473 case WXK_ALT:
1474 return optionKey;
6ed892f3
RN
1475
1476 case WXK_CONTROL:
1477 return controlKey;
1478
1479 default:
1480 return 0;
1481 }
1482}
1483
4cb1d3da 1484#ifndef __DARWIN__
1751226c 1485bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
6ed892f3 1486{
44353523
VZ
1487 wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=
1488 WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));
1489
6ed892f3
RN
1490//if OS X > 10.2 (i.e. 10.2.x)
1491//a known apple bug prevents the system from determining led
1492//states with GetKeys... can only determine caps lock led
902725ee 1493 return !!(GetCurrentKeyModifiers() & wxMacKeyCodeToModifier(key));
6ed892f3 1494//else
902725ee 1495// KeyMapByteArray keymap;
6ed892f3
RN
1496// GetKeys((BigEndianLong*)keymap);
1497// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
1498}
4cb1d3da 1499#endif
6ed892f3 1500
c5c9378c 1501
7dd40b6f
RD
1502wxMouseState wxGetMouseState()
1503{
1504 wxMouseState ms;
1505
1506 wxPoint pt = wxGetMousePosition();
1507 ms.SetX(pt.x);
1508 ms.SetY(pt.y);
1509
1510 UInt32 buttons = GetCurrentButtonState();
1511 ms.SetLeftDown( (buttons & 0x01) != 0 );
1512 ms.SetMiddleDown( (buttons & 0x04) != 0 );
1513 ms.SetRightDown( (buttons & 0x02) != 0 );
1514
1515 UInt32 modifiers = GetCurrentKeyModifiers();
1516 ms.SetControlDown(modifiers & controlKey);
1517 ms.SetShiftDown(modifiers & shiftKey);
1518 ms.SetAltDown(modifiers & optionKey);
1519 ms.SetMetaDown(modifiers & cmdKey);
1520
1521 return ms;
1522}
1523
1524
8a9858ae 1525bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
ac2d1ca6 1526{
ba12463b
SC
1527 if ( !focus )
1528 return false ;
7c9955d1 1529
12e049f6
SC
1530 short keycode ;
1531 short keychar ;
1532 keychar = short(keymessage & charCodeMask);
1533 keycode = short(keymessage & keyCodeMask) >> 8 ;
7c9955d1 1534
ef08713a 1535 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
12e049f6
SC
1536 {
1537 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1538 // and look at the character after
1539 UInt32 state = 0;
ef08713a 1540 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
12e049f6 1541 keychar = short(keyInfo & charCodeMask);
12e049f6 1542 }
8a9858ae 1543
12e049f6 1544 long keyval = wxMacTranslateKey(keychar, keycode) ;
e40298d5
JS
1545 long realkeyval = keyval ;
1546 if ( keyval == keychar )
1547 {
1548 // 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)
1549 realkeyval = short(keymessage & charCodeMask) ;
1550 keyval = wxToupper( keyval ) ;
1551 }
7c9955d1 1552
84ec90e9
JS
1553 // Check for NUMPAD keys
1554 if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
1555 {
1556 keyval = keyval - '0' + WXK_NUMPAD0;
1557 }
1558 else if (keycode >= 67 && keycode <= 81)
1559 {
1560 switch (keycode)
1561 {
1562 case 76 :
1563 keyval = WXK_NUMPAD_ENTER;
1564 break;
8a9858ae 1565
84ec90e9
JS
1566 case 81:
1567 keyval = WXK_NUMPAD_EQUAL;
1568 break;
8a9858ae 1569
84ec90e9
JS
1570 case 67:
1571 keyval = WXK_NUMPAD_MULTIPLY;
1572 break;
8a9858ae 1573
84ec90e9
JS
1574 case 75:
1575 keyval = WXK_NUMPAD_DIVIDE;
1576 break;
8a9858ae 1577
84ec90e9
JS
1578 case 78:
1579 keyval = WXK_NUMPAD_SUBTRACT;
1580 break;
8a9858ae 1581
84ec90e9
JS
1582 case 69:
1583 keyval = WXK_NUMPAD_ADD;
1584 break;
8a9858ae 1585
84ec90e9
JS
1586 case 65:
1587 keyval = WXK_NUMPAD_DECIMAL;
1588 break;
8a9858ae
DS
1589
1590 default:
1591 break;
84ec90e9
JS
1592 } // end switch
1593 }
1594
ac2d1ca6 1595 wxKeyEvent event(wxEVT_KEY_DOWN);
41d368a4 1596 bool handled = false ;
ac2d1ca6
SC
1597 event.m_shiftDown = modifiers & shiftKey;
1598 event.m_controlDown = modifiers & controlKey;
1599 event.m_altDown = modifiers & optionKey;
1600 event.m_metaDown = modifiers & cmdKey;
ef08713a 1601 event.m_keyCode = keyval ;
8a9858ae 1602
2d17efa9
SC
1603#if wxUSE_UNICODE
1604 event.m_uniChar = uniChar ;
1605#endif
8a9858ae 1606
84ec90e9
JS
1607 event.m_rawCode = keymessage;
1608 event.m_rawFlags = modifiers;
ac2d1ca6
SC
1609 event.m_x = wherex;
1610 event.m_y = wherey;
687706f5 1611 event.SetTimestamp(when);
ac2d1ca6
SC
1612 event.SetEventObject(focus);
1613 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1614 if ( handled && event.GetSkipped() )
1615 handled = false ;
902725ee
WS
1616
1617#if wxUSE_ACCEL
ac2d1ca6
SC
1618 if ( !handled )
1619 {
902725ee
WS
1620 wxWindow *ancestor = focus;
1621 while (ancestor)
ac2d1ca6 1622 {
902725ee
WS
1623 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1624 if (command != -1)
ac2d1ca6 1625 {
902725ee
WS
1626 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1627 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1628 break;
8461e4c2 1629 }
8a9858ae 1630
902725ee
WS
1631 if (ancestor->IsTopLevel())
1632 break;
8a9858ae 1633
902725ee 1634 ancestor = ancestor->GetParent();
ac2d1ca6 1635 }
ac2d1ca6 1636 }
902725ee
WS
1637#endif // wxUSE_ACCEL
1638
ac2d1ca6
SC
1639 if (!handled)
1640 {
e604288b
SC
1641 wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ;
1642
1643 if (tlw)
1644 {
902725ee 1645 event.Skip( false ) ;
e604288b
SC
1646 event.SetEventType( wxEVT_CHAR_HOOK );
1647 // raw value again
1648 event.m_keyCode = realkeyval ;
1649
1650 handled = tlw->GetEventHandler()->ProcessEvent( event );
1651 if ( handled && event.GetSkipped() )
1652 handled = false ;
1653 }
1654 }
902725ee 1655
e604288b 1656 if ( !handled )
902725ee
WS
1657 {
1658 event.Skip( false ) ;
ac2d1ca6 1659 event.SetEventType( wxEVT_CHAR ) ;
8a9858ae 1660
12e049f6 1661 // raw value again
ef08713a 1662 event.m_keyCode = realkeyval ;
ac2d1ca6
SC
1663
1664 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1665 if ( handled && event.GetSkipped() )
1666 handled = false ;
1667 }
8a9858ae 1668
bdf956fb 1669 if ( !handled && (keyval == WXK_TAB) )
ac2d1ca6 1670 {
bdf956fb 1671 wxWindow* iter = focus->GetParent() ;
8a9858ae 1672 while ( iter && !handled )
bdf956fb
SC
1673 {
1674 if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
1675 {
1676 wxNavigationKeyEvent new_event;
1677 new_event.SetEventObject( focus );
1678 new_event.SetDirection( !event.ShiftDown() );
1679 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1680 new_event.SetWindowChange( event.ControlDown() );
1681 new_event.SetCurrentFocus( focus );
1682 handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
1683 if ( handled && new_event.GetSkipped() )
1684 handled = false ;
1685 }
8a9858ae 1686
bdf956fb
SC
1687 iter = iter->GetParent() ;
1688 }
ac2d1ca6 1689 }
8a9858ae 1690
ac2d1ca6
SC
1691 // backdoor handler for default return and command escape
1692 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
1693 {
8a9858ae
DS
1694 // if window is not having a focus still testing for default enter or cancel
1695 // TODO: add the UMA version for ActiveNonFloatingWindow
1696 wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1697 if ( focus )
1698 {
e562df9b
SC
1699 if ( keyval == WXK_RETURN )
1700 {
8a9858ae
DS
1701 wxButton *def = wxDynamicCast(focus->GetDefaultItem(), wxButton);
1702 if ( def && def->IsEnabled() )
1703 {
1704 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1705 event.SetEventObject(def);
1706 def->Command(event);
1707
1708 return true ;
1709 }
e562df9b 1710 }
ac2d1ca6 1711 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
8461e4c2 1712 {
8a9858ae
DS
1713 // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs)
1714 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1715 new_event.SetEventObject( focus );
1716 handled = focus->GetEventHandler()->ProcessEvent( new_event );
8461e4c2 1717 }
8a9858ae 1718 }
8461e4c2 1719 }
8a9858ae 1720
ac2d1ca6 1721 return handled ;
169935ad
SC
1722}
1723
8a9858ae 1724bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
ac2d1ca6 1725{
ba12463b
SC
1726 if ( !focus )
1727 return false ;
1728
8a9858ae
DS
1729 short keycode, keychar ;
1730
12e049f6
SC
1731 keychar = short(keymessage & charCodeMask);
1732 keycode = short(keymessage & keyCodeMask) >> 8 ;
8a9858ae 1733 if ( modifiers & (controlKey | shiftKey | optionKey) )
12e049f6
SC
1734 {
1735 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1736 // and look at the character after
1737 UInt32 state = 0;
8a9858ae 1738 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey | shiftKey | optionKey))) | keycode, &state);
12e049f6 1739 keychar = short(keyInfo & charCodeMask);
12e049f6 1740 }
12e049f6 1741
8a9858ae 1742 long keyval = wxMacTranslateKey(keychar, keycode) ;
e40298d5 1743 if ( keyval == keychar )
7c9955d1 1744 keyval = wxToupper( keyval ) ;
84ec90e9
JS
1745
1746 // Check for NUMPAD keys
1747 if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
1748 {
8a9858ae 1749 keyval = (keyval - '0') + WXK_NUMPAD0;
84ec90e9
JS
1750 }
1751 else if (keycode >= 67 && keycode <= 81)
1752 {
1753 switch (keycode)
1754 {
1755 case 76 :
1756 keyval = WXK_NUMPAD_ENTER;
1757 break;
8a9858ae 1758
84ec90e9
JS
1759 case 81:
1760 keyval = WXK_NUMPAD_EQUAL;
1761 break;
8a9858ae 1762
84ec90e9
JS
1763 case 67:
1764 keyval = WXK_NUMPAD_MULTIPLY;
1765 break;
8a9858ae 1766
84ec90e9
JS
1767 case 75:
1768 keyval = WXK_NUMPAD_DIVIDE;
1769 break;
8a9858ae 1770
84ec90e9
JS
1771 case 78:
1772 keyval = WXK_NUMPAD_SUBTRACT;
1773 break;
8a9858ae 1774
84ec90e9
JS
1775 case 69:
1776 keyval = WXK_NUMPAD_ADD;
1777 break;
8a9858ae 1778
84ec90e9
JS
1779 case 65:
1780 keyval = WXK_NUMPAD_DECIMAL;
1781 break;
8a9858ae
DS
1782
1783 default:
1784 break;
84ec90e9
JS
1785 } // end switch
1786 }
1787
ac2d1ca6 1788 bool handled = false ;
ac2d1ca6 1789
ba12463b
SC
1790 wxKeyEvent event(wxEVT_KEY_UP);
1791 event.m_shiftDown = modifiers & shiftKey;
1792 event.m_controlDown = modifiers & controlKey;
1793 event.m_altDown = modifiers & optionKey;
1794 event.m_metaDown = modifiers & cmdKey;
ef08713a 1795 event.m_keyCode = keyval ;
2d17efa9
SC
1796#if wxUSE_UNICODE
1797 event.m_uniChar = uniChar ;
1798#endif
ba12463b 1799
84ec90e9
JS
1800 event.m_rawCode = keymessage;
1801 event.m_rawFlags = modifiers;
ba12463b
SC
1802 event.m_x = wherex;
1803 event.m_y = wherey;
687706f5 1804 event.SetTimestamp(when);
ba12463b
SC
1805 event.SetEventObject(focus);
1806 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1807
ac2d1ca6
SC
1808 return handled ;
1809}