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