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