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