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