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