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