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