]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/app.cpp
Fix bug with m_current causing EVT_LIST_KEY_DOWN events not to fire in virtual 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 ) ) ||
4dd25308 497 ( helpMenuHandle != NULL && command.menu.menuRef == helpMenuHandle ) )
ead6269a
SC
498 {
499 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
500 if ( mbar )
ead6269a 501 item = mbar->FindItem( id , &itemMenu ) ;
ead6269a
SC
502 }
503 else
504 {
fb743cab 505 URefCon refCon ;
8a9858ae 506
ead6269a
SC
507 GetMenuItemRefCon( command.menu.menuRef , command.menu.menuItemIndex , &refCon ) ;
508 itemMenu = wxFindMenuFromMacMenu( command.menu.menuRef ) ;
509 if ( itemMenu != NULL )
ead6269a 510 item = (wxMenuItem*) refCon ;
ead6269a
SC
511 }
512 }
8a9858ae 513
ead6269a
SC
514 return itemMenu ;
515}
516
c5c9378c
SC
517//----------------------------------------------------------------------
518// Carbon Event Handler
519//----------------------------------------------------------------------
9779893b 520
facd6764
SC
521static const EventTypeSpec eventList[] =
522{
523 { kEventClassCommand, kEventProcessCommand } ,
524 { kEventClassCommand, kEventCommandUpdateStatus } ,
7c9955d1 525
facd6764
SC
526 { kEventClassMenu, kEventMenuOpening },
527 { kEventClassMenu, kEventMenuClosed },
528 { kEventClassMenu, kEventMenuTargetItem },
e32f4a9f 529
facd6764
SC
530 { kEventClassApplication , kEventAppActivated } ,
531 { kEventClassApplication , kEventAppDeactivated } ,
532 // handling the quit event is not recommended by apple
533 // rather using the quit apple event - which we do
7c9955d1 534
facd6764 535 { kEventClassAppleEvent , kEventAppleEvent } ,
7c9955d1 536
facd6764
SC
537 { kEventClassMouse , kEventMouseDown } ,
538 { kEventClassMouse , kEventMouseMoved } ,
539 { kEventClassMouse , kEventMouseUp } ,
540 { kEventClassMouse , kEventMouseDragged } ,
541 { 'WXMC' , 'WXMC' }
542} ;
519cb848 543
e32f4a9f 544static pascal OSStatus
facd6764 545wxMacAppMenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
902725ee 546{
dae6d730
SC
547 wxMacCarbonEvent cEvent( event ) ;
548 MenuRef menuRef = cEvent.GetParameter<MenuRef>(kEventParamDirectObject) ;
549 wxMenu* menu = wxFindMenuFromMacMenu( menuRef ) ;
902725ee 550
dae6d730 551 if ( menu )
e32f4a9f 552 {
902725ee 553 wxEventType type=0;
dae6d730
SC
554 MenuCommand cmd=0;
555 switch (GetEventKind(event))
852b1185 556 {
dae6d730
SC
557 case kEventMenuOpening:
558 type = wxEVT_MENU_OPEN;
559 break;
8a9858ae 560
dae6d730
SC
561 case kEventMenuClosed:
562 type = wxEVT_MENU_CLOSE;
563 break;
8a9858ae 564
dae6d730
SC
565 case kEventMenuTargetItem:
566 cmd = cEvent.GetParameter<MenuCommand>(kEventParamMenuCommand,typeMenuCommand) ;
902725ee 567 if (cmd != 0)
9f2bfce7 568 type = wxEVT_MENU_HIGHLIGHT;
dae6d730 569 break;
8a9858ae 570
dae6d730
SC
571 default:
572 wxFAIL_MSG(wxT("Unexpected menu event kind"));
573 break;
574 }
852b1185 575
dae6d730
SC
576 if ( type )
577 {
37a4035b 578 wxMenuEvent wxevent(type, cmd, menu);
dae6d730 579 wxevent.SetEventObject(menu);
e32f4a9f 580
dae6d730
SC
581 wxEvtHandler* handler = menu->GetEventHandler();
582 if (handler && handler->ProcessEvent(wxevent))
583 {
584 // handled
585 }
586 else
587 {
588 wxWindow *win = menu->GetInvokingWindow();
902725ee 589 if (win)
dae6d730
SC
590 win->GetEventHandler()->ProcessEvent(wxevent);
591 }
592 }
e32f4a9f 593 }
902725ee 594
e32f4a9f 595 return eventNotHandledErr;
519cb848
SC
596}
597
facd6764 598static pascal OSStatus wxMacAppCommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
15b41e90
SC
599{
600 OSStatus result = eventNotHandledErr ;
601
e40298d5 602 HICommand command ;
7c9955d1 603
dae6d730
SC
604 wxMacCarbonEvent cEvent( event ) ;
605 cEvent.GetParameter<HICommand>(kEventParamDirectObject,typeHICommand,&command) ;
902725ee 606
dae6d730 607 wxMenuItem* item = NULL ;
ead6269a
SC
608 wxMenu* itemMenu = wxFindMenuFromMacCommand( command , item ) ;
609 int id = wxMacCommandToId( command.commandID ) ;
902725ee 610
ead6269a 611 if ( item )
6567c540 612 {
ead6269a 613 wxASSERT( itemMenu != NULL ) ;
88a7a4e1 614
8a9858ae 615 switch ( cEvent.GetKind() )
6d565349 616 {
ead6269a 617 case kEventProcessCommand :
6567c540 618 {
e40298d5 619 if (item->IsCheckable())
e40298d5 620 item->Check( !item->IsChecked() ) ;
7c9955d1 621
ead6269a
SC
622 if ( itemMenu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) )
623 result = noErr ;
e40298d5 624 }
dae6d730 625 break ;
8a9858ae 626
e40298d5 627 case kEventCommandUpdateStatus:
ead6269a
SC
628 {
629 wxUpdateUIEvent event(id);
630 event.SetEventObject( itemMenu );
88a7a4e1 631
ead6269a 632 bool processed = false;
88a7a4e1 633
ead6269a
SC
634 // Try the menu's event handler
635 {
636 wxEvtHandler *handler = itemMenu->GetEventHandler();
637 if ( handler )
638 processed = handler->ProcessEvent(event);
639 }
88a7a4e1 640
8a9858ae
DS
641 // Try the window the menu was popped up from
642 // (and up through the hierarchy)
ead6269a
SC
643 if ( !processed )
644 {
645 const wxMenuBase *menu = itemMenu;
646 while ( menu )
647 {
648 wxWindow *win = menu->GetInvokingWindow();
649 if ( win )
650 {
651 processed = win->GetEventHandler()->ProcessEvent(event);
652 break;
653 }
88a7a4e1 654
ead6269a
SC
655 menu = menu->GetParent();
656 }
657 }
88a7a4e1 658
ead6269a
SC
659 if ( processed )
660 {
661 // if anything changed, update the changed attribute
662 if (event.GetSetText())
663 itemMenu->SetLabel(id, event.GetText());
664 if (event.GetSetChecked())
665 itemMenu->Check(id, event.GetChecked());
666 if (event.GetSetEnabled())
667 itemMenu->Enable(id, event.GetEnabled());
668
669 result = noErr ;
670 }
671 }
e40298d5 672 break ;
8a9858ae 673
dae6d730
SC
674 default :
675 break ;
676 }
677 }
15b41e90
SC
678 return result ;
679}
680
facd6764 681static pascal OSStatus wxMacAppApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
15b41e90
SC
682{
683 OSStatus result = eventNotHandledErr ;
e40298d5
JS
684 switch ( GetEventKind( event ) )
685 {
686 case kEventAppActivated :
8a9858ae
DS
687 if ( wxTheApp )
688 wxTheApp->SetActive( true , NULL ) ;
689 result = noErr ;
e40298d5 690 break ;
8a9858ae 691
e40298d5 692 case kEventAppDeactivated :
8a9858ae
DS
693 if ( wxTheApp )
694 wxTheApp->SetActive( false , NULL ) ;
695 result = noErr ;
e40298d5 696 break ;
8a9858ae 697
e40298d5
JS
698 default :
699 break ;
700 }
8a9858ae 701
15b41e90
SC
702 return result ;
703}
704
facd6764 705pascal OSStatus wxMacAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
15b41e90 706{
27740109
SC
707 EventRef formerEvent = (EventRef) wxTheApp->MacGetCurrentEvent() ;
708 EventHandlerCallRef formerEventHandlerCallRef = (EventHandlerCallRef) wxTheApp->MacGetCurrentEventHandlerCallRef() ;
709 wxTheApp->MacSetCurrentEvent( event , handler ) ;
710
15b41e90 711 OSStatus result = eventNotHandledErr ;
8a9858ae 712 switch ( GetEventClass( event ) )
15b41e90 713 {
e40298d5 714 case kEventClassCommand :
facd6764 715 result = wxMacAppCommandEventHandler( handler , event , data ) ;
e40298d5 716 break ;
8a9858ae 717
e40298d5 718 case kEventClassApplication :
facd6764 719 result = wxMacAppApplicationEventHandler( handler , event , data ) ;
e40298d5 720 break ;
8a9858ae 721
e40298d5 722 case kEventClassMenu :
facd6764 723 result = wxMacAppMenuEventHandler( handler , event , data ) ;
e40298d5 724 break ;
8a9858ae 725
e40298d5 726 case kEventClassMouse :
95a8b77a
SC
727 {
728 wxMacCarbonEvent cEvent( event ) ;
902725ee 729
95a8b77a
SC
730 WindowRef window ;
731 Point screenMouseLocation = cEvent.GetParameter<Point>(kEventParamMouseLocation) ;
255df092 732 ::FindWindow(screenMouseLocation, &window);
95a8b77a
SC
733 // only send this event in case it had not already been sent to a tlw, as we get
734 // double events otherwise (in case event.skip) was called
735 if ( window == NULL )
736 result = wxMacTopLevelMouseEventHandler( handler , event , NULL ) ;
737 }
e40298d5 738 break ;
8a9858ae 739
e40298d5
JS
740 case kEventClassAppleEvent :
741 {
742 EventRecord rec ;
8a9858ae 743
e40298d5
JS
744 wxMacConvertEventToRecord( event , &rec ) ;
745 result = AEProcessAppleEvent( &rec ) ;
746 }
747 break ;
8a9858ae 748
e40298d5
JS
749 default :
750 break ;
15b41e90
SC
751 }
752
27740109
SC
753 wxTheApp->MacSetCurrentEvent( formerEvent, formerEventHandlerCallRef ) ;
754
15b41e90
SC
755 return result ;
756}
757
facd6764 758DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacAppEventHandler )
15b41e90 759
e822273a 760#ifdef __WXDEBUG__
8d1147f9 761
902725ee
WS
762pascal static void wxMacAssertOutputHandler(OSType componentSignature, UInt32 options,
763 const char *assertionString, const char *exceptionLabelString,
facd6764 764 const char *errorString, const char *fileName, long lineNumber, void *value, ConstStr255Param outputMsg)
e9576ca5 765{
facd6764
SC
766 // flow into assert handling
767 wxString fileNameStr ;
768 wxString assertionStr ;
769 wxString exceptionStr ;
770 wxString errorStr ;
8a9858ae 771
facd6764
SC
772#if wxUSE_UNICODE
773 fileNameStr = wxString(fileName, wxConvLocal);
774 assertionStr = wxString(assertionString, wxConvLocal);
775 exceptionStr = wxString((exceptionLabelString!=0) ? exceptionLabelString : "", wxConvLocal) ;
776 errorStr = wxString((errorString!=0) ? errorString : "", wxConvLocal) ;
777#else
778 fileNameStr = fileName;
779 assertionStr = assertionString;
780 exceptionStr = (exceptionLabelString!=0) ? exceptionLabelString : "" ;
781 errorStr = (errorString!=0) ? errorString : "" ;
782#endif
9779893b 783
facd6764
SC
784#if 1
785 // flow into log
902725ee
WS
786 wxLogDebug( wxT("AssertMacros: %s %s %s file: %s, line: %ld (value %p)\n"),
787 assertionStr.c_str() ,
788 exceptionStr.c_str() ,
789 errorStr.c_str(),
facd6764
SC
790 fileNameStr.c_str(), lineNumber ,
791 value ) ;
792#else
793
794 wxOnAssert(fileNameStr, lineNumber , assertionStr ,
8a9858ae 795 wxString::Format( wxT("%s %s value (%p)") , exceptionStr, errorStr , value ) ) ;
facd6764
SC
796#endif
797}
798
8d1147f9
RN
799#endif //__WXDEBUG__
800
ec8565f3 801#ifdef __WXMAC_OSX__
8a9858ae
DS
802extern "C"
803{
804 // m_macEventPosted run loop source callback:
ec8565f3 805 void macPostedEventCallback(void *unused);
95e568ee
KH
806}
807
8a9858ae
DS
808void macPostedEventCallback(void *unused)
809{
810 wxTheApp->ProcessPendingEvents();
811}
ec8565f3
KH
812#endif
813
facd6764
SC
814bool wxApp::Initialize(int& argc, wxChar **argv)
815{
fbbdb7cd 816 // Mac-specific
9779893b 817
e822273a 818#ifdef __WXDEBUG__
8a9858ae 819 InstallDebugAssertOutputHandler( NewDebugAssertOutputHandlerUPP( wxMacAssertOutputHandler ) );
facd6764 820#endif
8a9858ae 821
e128397f 822 UMAInitToolbox( 4, sm_isEmbedded ) ;
fbbdb7cd 823 SetEventMask( everyEvent ) ;
8461e4c2 824 UMAShowWatchCursor() ;
8be97d65 825
f5c6eb5c 826#ifndef __DARWIN__
fbbdb7cd 827# if __option(profile)
882b0479 828 ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ;
fbbdb7cd 829# endif
9779893b 830#endif
519cb848 831
f5c6eb5c 832#ifndef __DARWIN__
ed581ee2 833 // now avoid exceptions thrown for new (bad_alloc)
e40298d5 834 // FIXME CS for some changes outside wxMac does not compile anymore
15b41e90
SC
835#if 0
836 std::__throws_bad_alloc = 0 ;
837#endif
838
03e11df5 839#endif
7c9955d1 840
05e2b077
VZ
841 // Mac OS X passes a process serial number command line argument when
842 // the application is launched from the Finder. This argument must be
843 // removed from the command line arguments before being handled by the
844 // application (otherwise applications would need to handle it)
845 if ( argc > 1 )
846 {
847 static const wxChar *ARG_PSN = _T("-psn_");
46e2a2e7 848 if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 )
05e2b077
VZ
849 {
850 // remove this argument
33f39af3
GD
851 --argc;
852 memmove(argv + 1, argv + 2, argc * sizeof(char *));
05e2b077
VZ
853 }
854 }
855
94826170
VZ
856 if ( !wxAppBase::Initialize(argc, argv) )
857 return false;
e9576ca5 858
d9d19e75
SC
859#if wxUSE_INTL
860 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
861#endif
862
e256c692
SC
863#if TARGET_API_MAC_OSX
864 // these might be the startup dirs, set them to the 'usual' dir containing the app bundle
865 wxString startupCwd = wxGetCwd() ;
6601362a 866 if ( startupCwd == wxT("/") || startupCwd.Right(15) == wxT("/Contents/MacOS") )
e256c692 867 {
e256c692
SC
868 CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle() ) ;
869 CFURLRef urlParent = CFURLCreateCopyDeletingLastPathComponent( kCFAllocatorDefault , url ) ;
870 CFRelease( url ) ;
871 CFStringRef path = CFURLCopyFileSystemPath ( urlParent , kCFURLPOSIXPathStyle ) ;
872 CFRelease( urlParent ) ;
902725ee 873 wxString cwd = wxMacCFStringHolder(path).AsString(wxLocale::GetSystemEncoding());
e256c692
SC
874 wxSetWorkingDirectory( cwd ) ;
875 }
876#endif
d9d19e75 877
376b18ea 878 wxMacCreateNotifierTable() ;
9779893b 879
ec8565f3 880#ifdef __WXMAC_OSX__
95e568ee
KH
881 /* connect posted events to common-mode run loop so that wxPostEvent events
882 are handled even while we're in the menu or on a scrollbar */
883 CFRunLoopSourceContext event_posted_context = {0};
884 event_posted_context.perform = macPostedEventCallback;
885 m_macEventPosted = CFRunLoopSourceCreate(NULL,0,&event_posted_context);
886 CFRunLoopAddSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes);
7113b61a
SC
887 // run loop takes ownership
888 CFRelease(m_macEventPosted);
ec8565f3 889#endif
95e568ee 890
376b18ea 891 UMAShowArrowCursor() ;
8461e4c2 892
94826170 893 return true;
e9576ca5
SC
894}
895
9b58521d 896AEEventHandlerUPP sODocHandler = NULL ;
947848a1 897AEEventHandlerUPP sGURLHandler = NULL ;
9b58521d
SC
898AEEventHandlerUPP sOAppHandler = NULL ;
899AEEventHandlerUPP sPDocHandler = NULL ;
900AEEventHandlerUPP sRAppHandler = NULL ;
901AEEventHandlerUPP sQuitHandler = NULL ;
902
15b41e90
SC
903bool wxApp::OnInitGui()
904{
8a9858ae 905 if ( !wxAppBase::OnInitGui() )
e40298d5 906 return false ;
7c9955d1 907
e40298d5 908 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
7c9955d1 909
e128397f
DS
910 if (!sm_isEmbedded)
911 {
912 InstallApplicationEventHandler(
facd6764 913 GetwxMacAppEventHandlerUPP(),
e128397f
DS
914 GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler));
915 }
7c9955d1 916
e128397f
DS
917 if (!sm_isEmbedded)
918 {
9b58521d 919 sODocHandler = NewAEEventHandlerUPP(AEHandleODoc) ;
947848a1 920 sGURLHandler = NewAEEventHandlerUPP(AEHandleGURL) ;
9b58521d
SC
921 sOAppHandler = NewAEEventHandlerUPP(AEHandleOApp) ;
922 sPDocHandler = NewAEEventHandlerUPP(AEHandlePDoc) ;
923 sRAppHandler = NewAEEventHandlerUPP(AEHandleRApp) ;
924 sQuitHandler = NewAEEventHandlerUPP(AEHandleQuit) ;
925
e128397f 926 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
9b58521d 927 sODocHandler , 0 , FALSE ) ;
947848a1
VZ
928 AEInstallEventHandler( kInternetEventClass, kAEGetURL,
929 sGURLHandler , 0 , FALSE ) ;
e128397f 930 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
9b58521d 931 sOAppHandler , 0 , FALSE ) ;
e128397f 932 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
9b58521d 933 sPDocHandler , 0 , FALSE ) ;
1c32ded3 934 AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,
9b58521d 935 sRAppHandler , 0 , FALSE ) ;
e128397f 936 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
9b58521d 937 sQuitHandler , 0 , FALSE ) ;
e128397f 938 }
15b41e90 939
902725ee 940 return true ;
15b41e90
SC
941}
942
e9576ca5
SC
943void wxApp::CleanUp()
944{
e3e34b26 945#if wxUSE_TOOLTIPS
12cd5f34 946 wxToolTip::RemoveToolTips() ;
e3e34b26 947#endif
2f1ae414 948
ec8565f3 949#ifdef __WXMAC_OSX__
95e568ee 950 if (m_macEventPosted)
7113b61a
SC
951 {
952 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), m_macEventPosted, kCFRunLoopCommonModes);
953 m_macEventPosted = NULL;
954 }
ec8565f3 955#endif
95e568ee 956
2f1ae414
SC
957 // One last chance for pending objects to be cleaned up
958 wxTheApp->DeletePendingObjects();
959
fbbdb7cd 960 wxMacDestroyNotifierTable() ;
84c1ffa9 961
f5c6eb5c 962#ifndef __DARWIN__
fbbdb7cd 963# if __option(profile)
ac2153a6 964 ProfilerDump( (StringPtr)"\papp.prof" ) ;
fbbdb7cd
GD
965 ProfilerTerm() ;
966# endif
3246bafd 967#endif
e9b41b24 968
8461e4c2 969 UMACleanupToolbox() ;
84c1ffa9 970
9b58521d 971 if (!sm_isEmbedded)
9b58521d 972 RemoveEventHandler( (EventHandlerRef)(wxTheApp->m_macEventHandler) );
902725ee 973
9b58521d
SC
974 if (!sm_isEmbedded)
975 {
976 AERemoveEventHandler( kCoreEventClass , kAEOpenDocuments ,
977 sODocHandler , FALSE ) ;
947848a1
VZ
978 AERemoveEventHandler( kInternetEventClass, kAEGetURL,
979 sGURLHandler , FALSE ) ;
9b58521d
SC
980 AERemoveEventHandler( kCoreEventClass , kAEOpenApplication ,
981 sOAppHandler , FALSE ) ;
982 AERemoveEventHandler( kCoreEventClass , kAEPrintDocuments ,
983 sPDocHandler , FALSE ) ;
984 AERemoveEventHandler( kCoreEventClass , kAEReopenApplication ,
985 sRAppHandler , FALSE ) ;
986 AERemoveEventHandler( kCoreEventClass , kAEQuitApplication ,
987 sQuitHandler , FALSE ) ;
902725ee 988
9b58521d 989 DisposeAEEventHandlerUPP( sODocHandler ) ;
947848a1 990 DisposeAEEventHandlerUPP( sGURLHandler ) ;
9b58521d
SC
991 DisposeAEEventHandlerUPP( sOAppHandler ) ;
992 DisposeAEEventHandlerUPP( sPDocHandler ) ;
993 DisposeAEEventHandlerUPP( sRAppHandler ) ;
994 DisposeAEEventHandlerUPP( sQuitHandler ) ;
995 }
94826170
VZ
996
997 wxAppBase::CleanUp();
e9576ca5
SC
998}
999
92b002a4 1000//----------------------------------------------------------------------
05e2b077 1001// misc initialization stuff
92b002a4
RD
1002//----------------------------------------------------------------------
1003
21870a5d 1004#if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
53fd991c 1005
ed581ee2
GD
1006// for shared libraries we have to manually get the correct resource
1007// ref num upon initializing and releasing when terminating, therefore
1008// the __wxinitialize and __wxterminate must be used
53fd991c 1009
8a9858ae
DS
1010extern "C"
1011{
1012 void __sinit(void); // (generated by linker)
fbbdb7cd
GD
1013 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
1014 pascal void __terminate(void);
53fd991c 1015}
53fd991c
SC
1016
1017pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
1018{
fbbdb7cd 1019 return __initialize( theInitBlock ) ;
53fd991c
SC
1020}
1021
1022pascal void __wxterminate(void)
1023{
53fd991c
SC
1024 __terminate() ;
1025}
ed581ee2 1026
21870a5d 1027#endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
53fd991c 1028
b4efa069
SC
1029bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
1030{
b4efa069 1031 OSStatus err = noErr ;
8a9858ae
DS
1032 bool converted = ConvertEventRefToEventRecord( event, rec) ;
1033
b4efa069
SC
1034 if ( !converted )
1035 {
8a9858ae 1036 switch ( GetEventClass( event ) )
b4efa069
SC
1037 {
1038 case kEventClassKeyboard :
1039 {
1040 converted = true ;
8a9858ae 1041 switch ( GetEventKind(event) )
b4efa069
SC
1042 {
1043 case kEventRawKeyDown :
1044 rec->what = keyDown ;
1045 break ;
8a9858ae 1046
b4efa069
SC
1047 case kEventRawKeyRepeat :
1048 rec->what = autoKey ;
1049 break ;
8a9858ae 1050
b4efa069
SC
1051 case kEventRawKeyUp :
1052 rec->what = keyUp ;
1053 break ;
8a9858ae 1054
b4efa069
SC
1055 case kEventRawKeyModifiersChanged :
1056 rec->what = nullEvent ;
1057 break ;
8a9858ae 1058
b4efa069
SC
1059 default :
1060 converted = false ;
1061 break ;
1062 }
8a9858ae 1063
b4efa069
SC
1064 if ( converted )
1065 {
1066 UInt32 keyCode ;
1067 unsigned char charCode ;
1068 UInt32 modifiers ;
fb743cab 1069#ifndef __LP64__
b4efa069 1070 GetMouse( &rec->where) ;
fb743cab 1071#endif
b4efa069
SC
1072 err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
1073 err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
1074 err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
1075 rec->modifiers = modifiers ;
1076 rec->message = (keyCode << 8 ) + charCode ;
1077 }
1078 }
1079 break ;
8a9858ae 1080
b4efa069
SC
1081 case kEventClassTextInput :
1082 {
8a9858ae 1083 switch ( GetEventKind( event ) )
b4efa069
SC
1084 {
1085 case kEventTextInputUnicodeForKeyEvent :
1086 {
1087 EventRef rawEvent ;
8a9858ae
DS
1088 err = GetEventParameter(
1089 event, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL,
1090 sizeof(rawEvent), NULL, &rawEvent ) ;
b4efa069 1091 converted = true ;
8a9858ae 1092
b4efa069 1093 {
8a9858ae 1094 UInt32 keyCode, modifiers;
b4efa069 1095 unsigned char charCode ;
fb743cab 1096#ifndef __LP64__
8a9858ae 1097
b4efa069 1098 GetMouse( &rec->where) ;
fb743cab 1099#endif
b4efa069
SC
1100 rec->what = keyDown ;
1101 err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
1102 err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
1103 err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
1104 rec->modifiers = modifiers ;
1105 rec->message = (keyCode << 8 ) + charCode ;
1106 }
1107 }
8a9858ae
DS
1108 break ;
1109
b4efa069
SC
1110 default :
1111 break ;
1112 }
1113 }
1114 break ;
8a9858ae
DS
1115
1116 default :
1117 break ;
b4efa069
SC
1118 }
1119 }
84c1ffa9 1120
b4efa069
SC
1121 return converted ;
1122}
1123
e9576ca5
SC
1124wxApp::wxApp()
1125{
ec8565f3 1126 m_printMode = wxPRINT_WINDOWS;
1ea39a03 1127
ec8565f3
KH
1128 m_macCurrentEvent = NULL ;
1129 m_macCurrentEventHandlerCallRef = NULL ;
8a9858ae 1130
ec8565f3
KH
1131#ifdef __WXMAC_OSX__
1132 m_macEventPosted = NULL ;
1133#endif
e9576ca5
SC
1134}
1135
e9576ca5
SC
1136void wxApp::OnIdle(wxIdleEvent& event)
1137{
955a9197 1138 wxAppBase::OnIdle(event);
21870a5d 1139
2f1ae414
SC
1140 // If they are pending events, we must process them: pending events are
1141 // either events to the threads other than main or events posted with
1142 // wxPostEvent() functions
1143 wxMacProcessNotifierAndPendingEvents();
1144
8a9858ae 1145 if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
3fdac2ab 1146 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
e9576ca5
SC
1147}
1148
e2478fde 1149void wxApp::WakeUpIdle()
9779893b 1150{
ec8565f3 1151#ifdef __WXMAC_OSX__
95e568ee
KH
1152 if (m_macEventPosted)
1153 {
1154 CFRunLoopSourceSignal(m_macEventPosted);
1155 }
ec8565f3 1156#endif
8a9858ae 1157
8461e4c2 1158 wxMacWakeUp() ;
9779893b
RD
1159}
1160
2f1ae414
SC
1161void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1162{
1163 if (GetTopWindow())
902725ee 1164 GetTopWindow()->Close(true);
2f1ae414
SC
1165}
1166
1167// Default behaviour: close the application with prompts. The
1168// user can veto the close, and therefore the end session.
1169void wxApp::OnQueryEndSession(wxCloseEvent& event)
1170{
1171 if (GetTopWindow())
1172 {
1173 if (!GetTopWindow()->Close(!event.CanVeto()))
902725ee 1174 event.Veto(true);
2f1ae414
SC
1175 }
1176}
1177
1178extern "C" void wxCYield() ;
1179void wxCYield()
1180{
8461e4c2 1181 wxYield() ;
2f1ae414
SC
1182}
1183
e9576ca5 1184// Yield to other processes
cb2713bf 1185
8461e4c2 1186bool wxApp::Yield(bool onlyIfNeeded)
e9576ca5 1187{
8461e4c2
VZ
1188 if (s_inYield)
1189 {
1190 if ( !onlyIfNeeded )
1191 {
1192 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1193 }
1194
902725ee 1195 return false;
8461e4c2
VZ
1196 }
1197
902725ee 1198 s_inYield = true;
cb2713bf 1199
e40298d5 1200 // by definition yield should handle all non-processed events
facd6764 1201
e40298d5
JS
1202 EventRef theEvent;
1203
1204 OSStatus status = noErr ;
8a9858ae
DS
1205
1206 while ( status == noErr )
e40298d5
JS
1207 {
1208 s_inReceiveEvent = true ;
1209 status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
1210 s_inReceiveEvent = false ;
7c9955d1 1211
e40298d5
JS
1212 if ( status == eventLoopTimedOutErr )
1213 {
1214 // make sure next time the event loop will trigger idle events
1215 sleepTime = kEventDurationNoWait ;
1216 }
1217 else if ( status == eventLoopQuitErr )
1218 {
1219 // according to QA1061 this may also occur when a WakeUp Process
1220 // is executed
1221 }
1222 else
1223 {
1224 MacHandleOneEvent( theEvent ) ;
1225 ReleaseEvent(theEvent);
1226 }
8a9858ae 1227 }
2f1ae414 1228
8461e4c2 1229 wxMacProcessNotifierAndPendingEvents() ;
902725ee 1230 s_inYield = false;
cb2713bf 1231
902725ee 1232 return true;
169935ad
SC
1233}
1234
9779893b 1235void wxApp::MacDoOneEvent()
169935ad 1236{
e40298d5 1237 EventRef theEvent;
c5c9378c 1238
e40298d5 1239 s_inReceiveEvent = true ;
8a9858ae 1240 OSStatus status = ReceiveNextEvent(0, NULL, sleepTime, true, &theEvent) ;
e40298d5 1241 s_inReceiveEvent = false ;
8a9858ae
DS
1242
1243 switch (status)
e40298d5 1244 {
f3078f07 1245 case eventLoopTimedOutErr :
8a9858ae
DS
1246 if ( wxTheApp->ProcessIdle() )
1247 sleepTime = kEventDurationNoWait ;
1248 else
1249 sleepTime = kEventDurationSecond;
1250 break;
1251
f3078f07 1252 case eventLoopQuitErr :
8a9858ae
DS
1253 // according to QA1061 this may also occur
1254 // when a WakeUp Process is executed
1255 break;
1256
1257 default:
1258 MacHandleOneEvent( theEvent ) ;
1259 ReleaseEvent( theEvent );
e40298d5 1260 sleepTime = kEventDurationNoWait ;
8a9858ae 1261 break;
e40298d5 1262 }
8461e4c2 1263 // repeaters
519cb848 1264
6264b550 1265 DeletePendingObjects() ;
8461e4c2 1266 wxMacProcessNotifierAndPendingEvents() ;
169935ad
SC
1267}
1268
8a9858ae
DS
1269// virtual
1270void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr )
e128397f 1271{
902725ee 1272 // Override to process unhandled events as you please
e128397f
DS
1273}
1274
96116866
SC
1275CFMutableArrayRef GetAutoReleaseArray()
1276{
1277 static CFMutableArrayRef array = 0;
1278 if ( array == 0)
1279 array= CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);
1280 return array;
1281}
1282
76a5e5d2 1283void wxApp::MacHandleOneEvent( WXEVENTREF evr )
169935ad 1284{
e40298d5
JS
1285 EventTargetRef theTarget;
1286 theTarget = GetEventDispatcherTarget();
c5c9378c 1287 m_macCurrentEvent = evr ;
8a9858ae
DS
1288
1289 OSStatus status = SendEventToEventTarget((EventRef) evr , theTarget);
1290 if (status == eventNotHandledErr)
e128397f 1291 MacHandleUnhandledEvent(evr);
8a9858ae 1292
8461e4c2 1293 wxMacProcessNotifierAndPendingEvents() ;
8a9858ae 1294
f8df60f2
SC
1295#if wxUSE_THREADS
1296 wxMutexGuiLeaveOrEnter();
1297#endif // wxUSE_THREADS
96116866
SC
1298
1299 CFArrayRemoveAllValues( GetAutoReleaseArray() );
1300}
1301
1302void wxApp::MacAddToAutorelease( void* cfrefobj )
1303{
1304 CFArrayAppendValue( GetAutoReleaseArray(), cfrefobj );
169935ad
SC
1305}
1306
7c551d95 1307long wxMacTranslateKey(unsigned char key, unsigned char code)
9779893b 1308{
8461e4c2 1309 long retval = key ;
9779893b 1310 switch (key)
519cb848 1311 {
12e049f6 1312 case kHomeCharCode :
902725ee
WS
1313 retval = WXK_HOME;
1314 break;
1315
12e049f6 1316 case kEnterCharCode :
902725ee
WS
1317 retval = WXK_RETURN;
1318 break;
12e049f6 1319 case kEndCharCode :
902725ee
WS
1320 retval = WXK_END;
1321 break;
1322
12e049f6 1323 case kHelpCharCode :
902725ee
WS
1324 retval = WXK_HELP;
1325 break;
1326
12e049f6 1327 case kBackspaceCharCode :
902725ee
WS
1328 retval = WXK_BACK;
1329 break;
1330
12e049f6 1331 case kTabCharCode :
902725ee
WS
1332 retval = WXK_TAB;
1333 break;
1334
12e049f6 1335 case kPageUpCharCode :
902725ee
WS
1336 retval = WXK_PAGEUP;
1337 break;
1338
12e049f6 1339 case kPageDownCharCode :
902725ee
WS
1340 retval = WXK_PAGEDOWN;
1341 break;
1342
12e049f6 1343 case kReturnCharCode :
902725ee
WS
1344 retval = WXK_RETURN;
1345 break;
1346
1347 case kFunctionKeyCharCode :
1348 {
8a9858ae 1349 switch ( code )
8461e4c2 1350 {
902725ee
WS
1351 case 0x7a :
1352 retval = WXK_F1 ;
1353 break;
8a9858ae 1354
902725ee
WS
1355 case 0x78 :
1356 retval = WXK_F2 ;
1357 break;
8a9858ae 1358
902725ee
WS
1359 case 0x63 :
1360 retval = WXK_F3 ;
1361 break;
8a9858ae 1362
902725ee
WS
1363 case 0x76 :
1364 retval = WXK_F4 ;
1365 break;
8a9858ae 1366
902725ee
WS
1367 case 0x60 :
1368 retval = WXK_F5 ;
1369 break;
8a9858ae 1370
902725ee
WS
1371 case 0x61 :
1372 retval = WXK_F6 ;
1373 break;
8a9858ae 1374
902725ee
WS
1375 case 0x62:
1376 retval = WXK_F7 ;
1377 break;
8a9858ae 1378
902725ee
WS
1379 case 0x64 :
1380 retval = WXK_F8 ;
1381 break;
8a9858ae 1382
902725ee
WS
1383 case 0x65 :
1384 retval = WXK_F9 ;
1385 break;
8a9858ae 1386
902725ee
WS
1387 case 0x6D :
1388 retval = WXK_F10 ;
1389 break;
8a9858ae 1390
902725ee
WS
1391 case 0x67 :
1392 retval = WXK_F11 ;
1393 break;
8a9858ae 1394
902725ee
WS
1395 case 0x6F :
1396 retval = WXK_F12 ;
1397 break;
8a9858ae 1398
902725ee
WS
1399 case 0x69 :
1400 retval = WXK_F13 ;
1401 break;
8a9858ae 1402
902725ee
WS
1403 case 0x6B :
1404 retval = WXK_F14 ;
1405 break;
8a9858ae 1406
902725ee
WS
1407 case 0x71 :
1408 retval = WXK_F15 ;
1409 break;
8a9858ae
DS
1410
1411 default:
1412 break;
8461e4c2 1413 }
902725ee
WS
1414 }
1415 break ;
1416
1417 case kEscapeCharCode :
1418 retval = WXK_ESCAPE ;
8461e4c2 1419 break ;
902725ee
WS
1420
1421 case kLeftArrowCharCode :
1422 retval = WXK_LEFT ;
8461e4c2 1423 break ;
902725ee
WS
1424
1425 case kRightArrowCharCode :
1426 retval = WXK_RIGHT ;
8461e4c2 1427 break ;
902725ee
WS
1428
1429 case kUpArrowCharCode :
1430 retval = WXK_UP ;
8461e4c2 1431 break ;
902725ee
WS
1432
1433 case kDownArrowCharCode :
1434 retval = WXK_DOWN ;
8461e4c2 1435 break ;
902725ee
WS
1436
1437 case kDeleteCharCode :
1438 retval = WXK_DELETE ;
8461e4c2 1439 break ;
902725ee
WS
1440
1441 default:
8461e4c2
VZ
1442 break ;
1443 } // end switch
1444
1445 return retval;
169935ad
SC
1446}
1447
facd6764 1448int wxMacKeyCodeToModifier(wxKeyCode key)
6ed892f3
RN
1449{
1450 switch (key)
1451 {
1452 case WXK_START:
15c2acd2 1453 case WXK_MENU:
6ed892f3
RN
1454 return cmdKey;
1455
1456 case WXK_SHIFT:
1457 return shiftKey;
1458
1459 case WXK_CAPITAL:
1460 return alphaLock;
1461
15c2acd2
RN
1462 case WXK_ALT:
1463 return optionKey;
6ed892f3
RN
1464
1465 case WXK_CONTROL:
1466 return controlKey;
1467
1468 default:
1469 return 0;
1470 }
1471}
1472
4cb1d3da 1473#ifndef __DARWIN__
1751226c 1474bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
6ed892f3 1475{
44353523
VZ
1476 wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key !=
1477 WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons"));
1478
6ed892f3
RN
1479//if OS X > 10.2 (i.e. 10.2.x)
1480//a known apple bug prevents the system from determining led
1481//states with GetKeys... can only determine caps lock led
902725ee 1482 return !!(GetCurrentKeyModifiers() & wxMacKeyCodeToModifier(key));
6ed892f3 1483//else
902725ee 1484// KeyMapByteArray keymap;
6ed892f3
RN
1485// GetKeys((BigEndianLong*)keymap);
1486// return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
1487}
4cb1d3da 1488#endif
6ed892f3 1489
c5c9378c 1490
7dd40b6f
RD
1491wxMouseState wxGetMouseState()
1492{
1493 wxMouseState ms;
1494
1495 wxPoint pt = wxGetMousePosition();
1496 ms.SetX(pt.x);
1497 ms.SetY(pt.y);
1498
2a2e6365 1499#if TARGET_API_MAC_OSX
7dd40b6f
RD
1500 UInt32 buttons = GetCurrentButtonState();
1501 ms.SetLeftDown( (buttons & 0x01) != 0 );
1502 ms.SetMiddleDown( (buttons & 0x04) != 0 );
1503 ms.SetRightDown( (buttons & 0x02) != 0 );
2a2e6365
SC
1504#else
1505 ms.SetLeftDown( Button() );
1506 ms.SetMiddleDown( 0 );
1507 ms.SetRightDown( 0 );
1508#endif
1509
7dd40b6f
RD
1510 UInt32 modifiers = GetCurrentKeyModifiers();
1511 ms.SetControlDown(modifiers & controlKey);
1512 ms.SetShiftDown(modifiers & shiftKey);
1513 ms.SetAltDown(modifiers & optionKey);
1514 ms.SetMetaDown(modifiers & cmdKey);
1515
1516 return ms;
1517}
1518
980ee83f 1519// TODO : once the new key/char handling is tested, move all the code to wxWindow
7dd40b6f 1520
8a9858ae 1521bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
ac2d1ca6 1522{
ba12463b
SC
1523 if ( !focus )
1524 return false ;
7c9955d1 1525
88a7a4e1 1526 bool handled;
980ee83f
SC
1527 wxKeyEvent event(wxEVT_KEY_DOWN) ;
1528 MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ;
88a7a4e1 1529
ac2d1ca6
SC
1530 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1531 if ( handled && event.GetSkipped() )
1532 handled = false ;
902725ee
WS
1533
1534#if wxUSE_ACCEL
ac2d1ca6
SC
1535 if ( !handled )
1536 {
902725ee
WS
1537 wxWindow *ancestor = focus;
1538 while (ancestor)
ac2d1ca6 1539 {
902725ee
WS
1540 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1541 if (command != -1)
ac2d1ca6 1542 {
7816e624
VZ
1543 wxEvtHandler * const handler = ancestor->GetEventHandler();
1544
902725ee 1545 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
7816e624
VZ
1546 handled = handler->ProcessEvent( command_event );
1547
1548 if ( !handled )
1549 {
1550 // accelerators can also be used with buttons, try them too
1551 command_event.SetEventType(wxEVT_COMMAND_BUTTON_CLICKED);
1552 handled = handler->ProcessEvent( command_event );
1553 }
1554
902725ee 1555 break;
8461e4c2 1556 }
8a9858ae 1557
902725ee
WS
1558 if (ancestor->IsTopLevel())
1559 break;
8a9858ae 1560
902725ee 1561 ancestor = ancestor->GetParent();
ac2d1ca6 1562 }
ac2d1ca6 1563 }
902725ee
WS
1564#endif // wxUSE_ACCEL
1565
980ee83f
SC
1566 return handled ;
1567}
e604288b 1568
980ee83f
SC
1569bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
1570{
1571 if ( !focus )
1572 return false ;
902725ee 1573
980ee83f
SC
1574 bool handled;
1575 wxKeyEvent event( wxEVT_KEY_UP ) ;
1576 MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ;
1577 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
88a7a4e1 1578
980ee83f
SC
1579 return handled ;
1580}
8a9858ae 1581
980ee83f
SC
1582bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
1583{
1584 if ( !focus )
1585 return false ;
88a7a4e1 1586
980ee83f
SC
1587 wxKeyEvent event(wxEVT_CHAR) ;
1588 MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ;
1589 long keyval = event.m_keyCode ;
ac2d1ca6 1590
980ee83f
SC
1591 bool handled = false ;
1592
1593 wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ;
88a7a4e1 1594
980ee83f
SC
1595 if (tlw)
1596 {
1597 event.SetEventType( wxEVT_CHAR_HOOK );
980ee83f 1598 handled = tlw->GetEventHandler()->ProcessEvent( event );
ac2d1ca6
SC
1599 if ( handled && event.GetSkipped() )
1600 handled = false ;
1601 }
8a9858ae 1602
980ee83f
SC
1603 if ( !handled )
1604 {
1605 event.SetEventType( wxEVT_CHAR );
1606 event.Skip( false ) ;
1607 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1608 }
88a7a4e1 1609
bdf956fb 1610 if ( !handled && (keyval == WXK_TAB) )
ac2d1ca6 1611 {
bdf956fb 1612 wxWindow* iter = focus->GetParent() ;
8a9858ae 1613 while ( iter && !handled )
bdf956fb
SC
1614 {
1615 if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
1616 {
1617 wxNavigationKeyEvent new_event;
1618 new_event.SetEventObject( focus );
1619 new_event.SetDirection( !event.ShiftDown() );
1620 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1621 new_event.SetWindowChange( event.ControlDown() );
1622 new_event.SetCurrentFocus( focus );
1623 handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
1624 if ( handled && new_event.GetSkipped() )
1625 handled = false ;
1626 }
8a9858ae 1627
bdf956fb
SC
1628 iter = iter->GetParent() ;
1629 }
ac2d1ca6 1630 }
8a9858ae 1631
ac2d1ca6
SC
1632 // backdoor handler for default return and command escape
1633 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
1634 {
8a9858ae
DS
1635 // if window is not having a focus still testing for default enter or cancel
1636 // TODO: add the UMA version for ActiveNonFloatingWindow
1637 wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1638 if ( focus )
1639 {
deda45e8 1640 if ( keyval == WXK_RETURN || keyval == WXK_NUMPAD_ENTER )
e562df9b 1641 {
6c20e8f8
VZ
1642 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(focus), wxTopLevelWindow);
1643 if ( tlw && tlw->GetDefaultItem() )
8a9858ae 1644 {
6c20e8f8
VZ
1645 wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
1646 if ( def && def->IsEnabled() )
1647 {
1648 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1649 event.SetEventObject(def);
1650 def->Command(event);
8a9858ae 1651
6c20e8f8
VZ
1652 return true ;
1653 }
8a9858ae 1654 }
e562df9b 1655 }
ac2d1ca6 1656 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
8461e4c2 1657 {
8a9858ae
DS
1658 // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs)
1659 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1660 new_event.SetEventObject( focus );
1661 handled = focus->GetEventHandler()->ProcessEvent( new_event );
8461e4c2 1662 }
8a9858ae 1663 }
8461e4c2 1664 }
ac2d1ca6 1665 return handled ;
169935ad
SC
1666}
1667
88a7a4e1 1668// This method handles common code for SendKeyDown, SendKeyUp, and SendChar events.
980ee83f 1669void wxApp::MacCreateKeyEvent( wxKeyEvent& event, wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
ac2d1ca6 1670{
8a9858ae
DS
1671 short keycode, keychar ;
1672
12e049f6
SC
1673 keychar = short(keymessage & charCodeMask);
1674 keycode = short(keymessage & keyCodeMask) >> 8 ;
980ee83f 1675 if ( !(event.GetEventType() == wxEVT_CHAR) && (modifiers & (controlKey | shiftKey | optionKey) ) )
12e049f6
SC
1676 {
1677 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1678 // and look at the character after
1679 UInt32 state = 0;
8a9858ae 1680 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey | shiftKey | optionKey))) | keycode, &state);
12e049f6 1681 keychar = short(keyInfo & charCodeMask);
12e049f6 1682 }
12e049f6 1683
8a9858ae 1684 long keyval = wxMacTranslateKey(keychar, keycode) ;
980ee83f 1685 if ( keyval == keychar && ( event.GetEventType() == wxEVT_KEY_UP || event.GetEventType() == wxEVT_KEY_DOWN ) )
7c9955d1 1686 keyval = wxToupper( keyval ) ;
84ec90e9
JS
1687
1688 // Check for NUMPAD keys
1689 if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
1690 {
8a9858ae 1691 keyval = (keyval - '0') + WXK_NUMPAD0;
84ec90e9
JS
1692 }
1693 else if (keycode >= 67 && keycode <= 81)
1694 {
1695 switch (keycode)
1696 {
1697 case 76 :
1698 keyval = WXK_NUMPAD_ENTER;
1699 break;
8a9858ae 1700
84ec90e9
JS
1701 case 81:
1702 keyval = WXK_NUMPAD_EQUAL;
1703 break;
8a9858ae 1704
84ec90e9
JS
1705 case 67:
1706 keyval = WXK_NUMPAD_MULTIPLY;
1707 break;
8a9858ae 1708
84ec90e9
JS
1709 case 75:
1710 keyval = WXK_NUMPAD_DIVIDE;
1711 break;
8a9858ae 1712
84ec90e9
JS
1713 case 78:
1714 keyval = WXK_NUMPAD_SUBTRACT;
1715 break;
8a9858ae 1716
84ec90e9
JS
1717 case 69:
1718 keyval = WXK_NUMPAD_ADD;
1719 break;
8a9858ae 1720
84ec90e9
JS
1721 case 65:
1722 keyval = WXK_NUMPAD_DECIMAL;
1723 break;
8a9858ae
DS
1724
1725 default:
1726 break;
84ec90e9
JS
1727 } // end switch
1728 }
1729
ba12463b
SC
1730 event.m_shiftDown = modifiers & shiftKey;
1731 event.m_controlDown = modifiers & controlKey;
1732 event.m_altDown = modifiers & optionKey;
1733 event.m_metaDown = modifiers & cmdKey;
ef08713a 1734 event.m_keyCode = keyval ;
2d17efa9
SC
1735#if wxUSE_UNICODE
1736 event.m_uniChar = uniChar ;
1737#endif
ba12463b 1738
84ec90e9
JS
1739 event.m_rawCode = keymessage;
1740 event.m_rawFlags = modifiers;
ba12463b
SC
1741 event.m_x = wherex;
1742 event.m_y = wherey;
687706f5 1743 event.SetTimestamp(when);
ba12463b 1744 event.SetEventObject(focus);
ac2d1ca6 1745}