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