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