]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: app.cpp | |
3 | // Purpose: wxApp | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: ??/??/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
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" |
e9576ca5 | 39 | #if wxUSE_WX_RESOURCES |
df06d1a4 | 40 | # include "wx/resource.h" |
e9576ca5 SC |
41 | #endif |
42 | ||
43 | #include <string.h> | |
44 | ||
8be97d65 SC |
45 | // mac |
46 | ||
f5c6eb5c | 47 | #ifndef __DARWIN__ |
03e11df5 | 48 | #if __option(profile) |
8461e4c2 | 49 | #include <profiler.h> |
03e11df5 | 50 | #endif |
9779893b | 51 | #endif |
519cb848 | 52 | |
8be97d65 SC |
53 | #include "apprsrc.h" |
54 | ||
03e11df5 GD |
55 | #include "wx/mac/uma.h" |
56 | #include "wx/mac/macnotfy.h" | |
2f1ae414 | 57 | |
df06d1a4 GD |
58 | #ifdef __DARWIN__ |
59 | # include <CoreServices/CoreServices.h> | |
ed581ee2 GD |
60 | # if defined(WXMAKINGDLL) |
61 | # include <mach-o/dyld.h> | |
62 | # endif | |
df06d1a4 GD |
63 | #else |
64 | # include <Sound.h> | |
65 | # include <Threads.h> | |
66 | # include <ToolUtils.h> | |
67 | # include <DiskInit.h> | |
68 | # include <Devices.h> | |
2f1ae414 | 69 | #endif |
519cb848 | 70 | |
e9576ca5 SC |
71 | extern char *wxBuffer; |
72 | extern wxList wxPendingDelete; | |
519cb848 SC |
73 | extern wxList *wxWinMacWindowList; |
74 | extern wxList *wxWinMacControlList; | |
e9576ca5 | 75 | |
6418cb93 | 76 | wxApp *wxTheApp = NULL; |
e9576ca5 | 77 | |
2f1ae414 | 78 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
79 | IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) |
80 | BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) | |
81 | EVT_IDLE(wxApp::OnIdle) | |
2f1ae414 SC |
82 | EVT_END_SESSION(wxApp::OnEndSession) |
83 | EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) | |
e9576ca5 | 84 | END_EVENT_TABLE() |
2f1ae414 | 85 | #endif |
e9576ca5 | 86 | |
169935ad | 87 | |
8461e4c2 | 88 | const short kMacMinHeap = (29 * 1024) ; |
8be97d65 | 89 | // platform specific static variables |
169935ad | 90 | |
519cb848 SC |
91 | const short kwxMacMenuBarResource = 1 ; |
92 | const short kwxMacAppleMenuId = 1 ; | |
93 | ||
fbbdb7cd GD |
94 | WXHRGN wxApp::s_macCursorRgn = NULL; |
95 | wxWindow* wxApp::s_captureWindow = NULL ; | |
96 | int wxApp::s_lastMouseDown = 0 ; | |
97 | long wxApp::sm_lastMessageTime = 0; | |
519cb848 | 98 | |
fbbdb7cd GD |
99 | bool wxApp::s_macDefaultEncodingIsPC = true ; |
100 | bool wxApp::s_macSupportPCMenuShortcuts = true ; | |
101 | long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; | |
102 | wxString wxApp::s_macHelpMenuTitleName = "&Help" ; | |
519cb848 | 103 | |
72055702 SC |
104 | pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ; |
105 | pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ; | |
106 | pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ; | |
107 | pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ; | |
108 | ||
109 | ||
2a294857 | 110 | pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) ) |
519cb848 | 111 | { |
ba2928c6 | 112 | // GD: UNUSED wxApp* app = (wxApp*) refcon ; |
8461e4c2 | 113 | return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ; |
519cb848 SC |
114 | } |
115 | ||
2a294857 | 116 | pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) ) |
519cb848 | 117 | { |
ba2928c6 | 118 | // GD: UNUSED wxApp* app = (wxApp*) refcon ; |
8461e4c2 | 119 | return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ; |
519cb848 SC |
120 | } |
121 | ||
2a294857 | 122 | pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) ) |
519cb848 | 123 | { |
ba2928c6 | 124 | // GD: UNUSED wxApp* app = (wxApp*) refcon ; |
8461e4c2 | 125 | return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ; |
519cb848 SC |
126 | } |
127 | ||
2a294857 | 128 | pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) ) |
519cb848 | 129 | { |
ba2928c6 | 130 | // GD: UNUSED wxApp* app = (wxApp*) refcon ; |
8461e4c2 | 131 | return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; |
519cb848 SC |
132 | } |
133 | ||
2a294857 | 134 | short wxApp::MacHandleAEODoc(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) |
519cb848 | 135 | { |
c1fb8167 | 136 | SysBeep(40) ; |
8461e4c2 VZ |
137 | ProcessSerialNumber PSN ; |
138 | PSN.highLongOfPSN = 0 ; | |
139 | PSN.lowLongOfPSN = kCurrentProcess ; | |
140 | SetFrontProcess( &PSN ) ; | |
141 | return noErr ; | |
519cb848 SC |
142 | } |
143 | ||
2a294857 | 144 | short wxApp::MacHandleAEPDoc(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) |
519cb848 | 145 | { |
8461e4c2 | 146 | return noErr ; |
519cb848 SC |
147 | } |
148 | ||
2a294857 | 149 | short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) |
519cb848 | 150 | { |
8461e4c2 | 151 | return noErr ; |
519cb848 SC |
152 | } |
153 | ||
2a294857 | 154 | short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply)) |
519cb848 | 155 | { |
8461e4c2 VZ |
156 | wxWindow* win = GetTopWindow() ; |
157 | if ( win ) | |
158 | { | |
159 | win->Close(TRUE ) ; | |
160 | } | |
161 | else | |
162 | { | |
163 | ExitMainLoop() ; | |
164 | } | |
165 | return noErr ; | |
519cb848 SC |
166 | } |
167 | ||
df06d1a4 | 168 | char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f" |
8461e4c2 VZ |
169 | "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f" |
170 | "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf" | |
171 | "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf" | |
172 | "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf" | |
173 | "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ; | |
519cb848 | 174 | |
2f1ae414 | 175 | char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8" |
8461e4c2 VZ |
176 | "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC" |
177 | "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8" | |
178 | "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8" | |
179 | "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C" | |
180 | "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ; | |
519cb848 SC |
181 | |
182 | void wxMacConvertFromPC( const char *from , char *to , int len ) | |
183 | { | |
8461e4c2 VZ |
184 | char *c ; |
185 | if ( from == to ) | |
186 | { | |
187 | for( int i = 0 ; i < len ; ++ i ) | |
188 | { | |
189 | c = strchr( StringANSI , *from ) ; | |
190 | if ( c != NULL ) | |
191 | { | |
192 | *to = StringMac[ c - StringANSI] ; | |
193 | } | |
194 | ++to ; | |
195 | ++from ; | |
196 | } | |
197 | } | |
198 | else | |
199 | { | |
200 | for( int i = 0 ; i < len ; ++ i ) | |
201 | { | |
202 | c = strchr( StringANSI , *from ) ; | |
203 | if ( c != NULL ) | |
204 | { | |
205 | *to = StringMac[ c - StringANSI] ; | |
206 | } | |
207 | else | |
208 | { | |
209 | *to = *from ; | |
210 | } | |
211 | ++to ; | |
212 | ++from ; | |
213 | } | |
214 | } | |
519cb848 SC |
215 | } |
216 | ||
217 | void wxMacConvertToPC( const char *from , char *to , int len ) | |
218 | { | |
8461e4c2 VZ |
219 | char *c ; |
220 | if ( from == to ) | |
221 | { | |
222 | for( int i = 0 ; i < len ; ++ i ) | |
223 | { | |
224 | c = strchr( StringMac , *from ) ; | |
225 | if ( c != NULL ) | |
226 | { | |
227 | *to = StringANSI[ c - StringMac] ; | |
228 | } | |
229 | ++to ; | |
230 | ++from ; | |
231 | } | |
232 | } | |
233 | else | |
234 | { | |
235 | for( int i = 0 ; i < len ; ++ i ) | |
236 | { | |
237 | c = strchr( StringMac , *from ) ; | |
238 | if ( c != NULL ) | |
239 | { | |
240 | *to = StringANSI[ c - StringMac] ; | |
241 | } | |
242 | else | |
243 | { | |
244 | *to = *from ; | |
245 | } | |
246 | ++to ; | |
247 | ++from ; | |
248 | } | |
249 | } | |
519cb848 SC |
250 | } |
251 | ||
9779893b | 252 | void wxMacConvertFromPC( char * p ) |
519cb848 | 253 | { |
8461e4c2 VZ |
254 | char *ptr = p ; |
255 | int len = strlen ( p ) ; | |
9779893b | 256 | |
8461e4c2 | 257 | wxMacConvertFromPC( ptr , ptr , len ) ; |
519cb848 SC |
258 | } |
259 | ||
9779893b | 260 | void wxMacConvertFromPCForControls( char * p ) |
519cb848 | 261 | { |
8461e4c2 VZ |
262 | char *ptr = p ; |
263 | int len = strlen ( p ) ; | |
264 | ||
265 | wxMacConvertFromPC( ptr , ptr , len ) ; | |
ba2928c6 | 266 | for ( unsigned int i = 0 ; i < strlen ( ptr ) ; i++ ) |
8461e4c2 VZ |
267 | { |
268 | if ( ptr[i] == '&' && ptr[i]+1 != ' ' ) | |
269 | { | |
270 | memmove( &ptr[i] , &ptr[i+1] , strlen( &ptr[i+1] ) + 1) ; | |
271 | } | |
272 | } | |
519cb848 SC |
273 | } |
274 | ||
9779893b | 275 | void wxMacConvertFromPC( unsigned char *p ) |
519cb848 | 276 | { |
8461e4c2 VZ |
277 | char *ptr = (char*) p + 1 ; |
278 | int len = p[0] ; | |
9779893b | 279 | |
8461e4c2 | 280 | wxMacConvertFromPC( ptr , ptr , len ) ; |
519cb848 SC |
281 | } |
282 | ||
283 | extern char *wxBuffer ; | |
284 | ||
9779893b | 285 | wxString wxMacMakeMacStringFromPC( const char * p ) |
519cb848 | 286 | { |
8461e4c2 VZ |
287 | const char *ptr = p ; |
288 | int len = strlen ( p ) ; | |
289 | char *buf = wxBuffer ; | |
290 | ||
291 | if ( len >= BUFSIZ + 512 ) | |
292 | { | |
293 | buf = new char [len+1] ; | |
294 | } | |
295 | ||
296 | wxMacConvertFromPC( ptr , buf , len ) ; | |
297 | buf[len] = 0 ; | |
298 | wxString result( buf ) ; | |
299 | if ( buf != wxBuffer ) | |
300 | delete buf ; | |
301 | return result ; | |
519cb848 SC |
302 | } |
303 | ||
304 | ||
9779893b | 305 | void wxMacConvertToPC( char * p ) |
519cb848 | 306 | { |
8461e4c2 VZ |
307 | char *ptr = p ; |
308 | int len = strlen ( p ) ; | |
9779893b | 309 | |
8461e4c2 | 310 | wxMacConvertToPC( ptr , ptr , len ) ; |
519cb848 SC |
311 | } |
312 | ||
9779893b | 313 | void wxMacConvertToPC( unsigned char *p ) |
519cb848 | 314 | { |
8461e4c2 VZ |
315 | char *ptr = (char*) p + 1 ; |
316 | int len = p[0] ; | |
9779893b | 317 | |
8461e4c2 | 318 | wxMacConvertToPC( ptr , ptr , len ) ; |
519cb848 SC |
319 | } |
320 | ||
9779893b | 321 | wxString wxMacMakePCStringFromMac( const char * p ) |
519cb848 | 322 | { |
8461e4c2 VZ |
323 | const char *ptr = p ; |
324 | int len = strlen ( p ) ; | |
325 | char *buf = wxBuffer ; | |
326 | ||
327 | if ( len >= BUFSIZ + 512 ) | |
328 | { | |
329 | buf = new char [len+1] ; | |
330 | } | |
331 | ||
332 | wxMacConvertToPC( ptr , buf , len ) ; | |
333 | buf[len] = 0 ; | |
334 | ||
335 | wxString result( buf ) ; | |
336 | if ( buf != wxBuffer ) | |
337 | delete buf ; | |
338 | return result ; | |
519cb848 | 339 | } |
169935ad | 340 | |
8461e4c2 | 341 | wxString wxMacMakeStringFromMacString( const char* from , bool mac2pcEncoding ) |
3d2791f1 | 342 | { |
8461e4c2 VZ |
343 | if (mac2pcEncoding) |
344 | { | |
345 | return wxMacMakePCStringFromMac( from ) ; | |
346 | } | |
347 | else | |
348 | { | |
349 | return wxString( from ) ; | |
350 | } | |
3d2791f1 SC |
351 | } |
352 | ||
8461e4c2 | 353 | wxString wxMacMakeStringFromPascal( StringPtr from , bool mac2pcEncoding ) |
3d2791f1 SC |
354 | { |
355 | // this is safe since a pascal string can never be larger than 256 bytes | |
356 | char s[256] ; | |
357 | CopyPascalStringToC( from , s ) ; | |
8461e4c2 VZ |
358 | if (mac2pcEncoding) |
359 | { | |
360 | return wxMacMakePCStringFromMac( s ) ; | |
361 | } | |
362 | else | |
363 | { | |
364 | return wxString( s ) ; | |
365 | } | |
3d2791f1 SC |
366 | } |
367 | ||
8461e4c2 | 368 | void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding ) |
3d2791f1 | 369 | { |
8461e4c2 VZ |
370 | if (pc2macEncoding) |
371 | { | |
372 | CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ; | |
373 | } | |
374 | else | |
375 | { | |
376 | CopyCStringToPascal( from , to ) ; | |
377 | } | |
3d2791f1 | 378 | } |
ed581ee2 GD |
379 | |
380 | #if defined(WXMAKINGDLL) && !defined(__DARWIN__) | |
53fd991c SC |
381 | // we know it's there ;-) |
382 | WXIMPORT char std::__throws_bad_alloc ; | |
383 | #endif | |
384 | ||
e9576ca5 SC |
385 | bool wxApp::Initialize() |
386 | { | |
fbbdb7cd | 387 | int error = 0 ; |
9779893b | 388 | |
fbbdb7cd | 389 | // Mac-specific |
9779893b | 390 | |
fbbdb7cd GD |
391 | UMAInitToolbox( 4 ) ; |
392 | SetEventMask( everyEvent ) ; | |
8461e4c2 | 393 | UMAShowWatchCursor() ; |
8be97d65 | 394 | |
fbbdb7cd GD |
395 | #if defined(WXMAKINGDLL) && defined(__DARWIN__) |
396 | // open shared library resources from here since we don't have | |
397 | // __wxinitialize in Mach-O shared libraries | |
398 | wxStAppResource::OpenSharedLibraryResource(NULL); | |
399 | #endif | |
400 | ||
4114d0af | 401 | #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) |
fbbdb7cd GD |
402 | AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , |
403 | NewAEEventHandlerUPP(AEHandleODoc) , | |
03e11df5 | 404 | (long) wxTheApp , FALSE ) ; |
fbbdb7cd GD |
405 | AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , |
406 | NewAEEventHandlerUPP(AEHandleOApp) , | |
03e11df5 | 407 | (long) wxTheApp , FALSE ) ; |
fbbdb7cd GD |
408 | AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , |
409 | NewAEEventHandlerUPP(AEHandlePDoc) , | |
03e11df5 | 410 | (long) wxTheApp , FALSE ) ; |
fbbdb7cd GD |
411 | AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , |
412 | NewAEEventHandlerUPP(AEHandleQuit) , | |
03e11df5 GD |
413 | (long) wxTheApp , FALSE ) ; |
414 | #else | |
fbbdb7cd GD |
415 | AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , |
416 | NewAEEventHandlerProc(AEHandleODoc) , | |
417 | (long) wxTheApp , FALSE ) ; | |
418 | AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , | |
419 | NewAEEventHandlerProc(AEHandleOApp) , | |
420 | (long) wxTheApp , FALSE ) ; | |
421 | AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , | |
422 | NewAEEventHandlerProc(AEHandlePDoc) , | |
423 | (long) wxTheApp , FALSE ) ; | |
424 | AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , | |
425 | NewAEEventHandlerProc(AEHandleQuit) , | |
426 | (long) wxTheApp , FALSE ) ; | |
03e11df5 | 427 | #endif |
8be97d65 | 428 | |
f5c6eb5c | 429 | #ifndef __DARWIN__ |
fbbdb7cd | 430 | // test the minimal configuration necessary |
8be97d65 | 431 | |
fbbdb7cd | 432 | # if !TARGET_CARBON |
8461e4c2 VZ |
433 | long theSystem ; |
434 | long theMachine; | |
435 | ||
436 | if (Gestalt(gestaltMachineType, &theMachine) != noErr) | |
437 | { | |
438 | error = kMacSTRWrongMachine; | |
439 | } | |
440 | else if (theMachine < gestaltMacPlus) | |
441 | { | |
442 | error = kMacSTRWrongMachine; | |
443 | } | |
444 | else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr ) | |
445 | { | |
446 | error = kMacSTROldSystem ; | |
447 | } | |
72055702 | 448 | else if ( theSystem < 0x0860 ) |
8461e4c2 VZ |
449 | { |
450 | error = kMacSTROldSystem ; | |
451 | } | |
452 | else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap) | |
453 | { | |
454 | error = kMacSTRSmallSize; | |
455 | } | |
fbbdb7cd | 456 | # endif |
8461e4c2 VZ |
457 | /* |
458 | else | |
459 | { | |
460 | if ( !UMAHasAppearance() ) | |
461 | { | |
462 | error = kMacSTRNoPre8Yet ; | |
463 | } | |
464 | } | |
465 | */ | |
ed5b9811 | 466 | #endif |
8be97d65 | 467 | |
8461e4c2 | 468 | // if we encountered any problems so far, give the error code and exit immediately |
9779893b | 469 | |
169935ad | 470 | if ( error ) |
9779893b | 471 | { |
53fd991c | 472 | wxStAppResource resload ; |
8461e4c2 VZ |
473 | short itemHit; |
474 | Str255 message; | |
475 | ||
476 | GetIndString(message, 128, error); | |
477 | UMAShowArrowCursor() ; | |
478 | ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p"); | |
479 | itemHit = Alert(128, nil); | |
480 | return FALSE ; | |
9779893b | 481 | } |
519cb848 | 482 | |
f5c6eb5c | 483 | #ifndef __DARWIN__ |
fbbdb7cd | 484 | # if __option(profile) |
8461e4c2 | 485 | ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ; |
fbbdb7cd | 486 | # endif |
9779893b | 487 | #endif |
519cb848 | 488 | |
f5c6eb5c | 489 | #ifndef __DARWIN__ |
ed581ee2 GD |
490 | // now avoid exceptions thrown for new (bad_alloc) |
491 | std::__throws_bad_alloc = FALSE ; | |
03e11df5 | 492 | #endif |
9779893b | 493 | |
8461e4c2 | 494 | s_macCursorRgn = ::NewRgn() ; |
8be97d65 | 495 | |
ed581ee2 GD |
496 | wxBuffer = new char[BUFSIZ + 512]; |
497 | ||
498 | wxClassInfo::InitializeClasses(); | |
e9576ca5 | 499 | |
2f1ae414 SC |
500 | #if wxUSE_RESOURCES |
501 | // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion); | |
e9576ca5 | 502 | #endif |
e9576ca5 | 503 | |
2f1ae414 SC |
504 | #if wxUSE_THREADS |
505 | wxPendingEventsLocker = new wxCriticalSection; | |
506 | #endif | |
ed581ee2 GD |
507 | |
508 | wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING); | |
509 | wxTheColourDatabase->Initialize(); | |
e9576ca5 | 510 | |
fc0daf84 | 511 | #ifdef __WXDEBUG__ |
0a67a93b SC |
512 | #if wxUSE_LOG |
513 | // flush the logged messages if any and install a 'safer' log target: the | |
514 | // default one (wxLogGui) can't be used after the resources are freed just | |
515 | // below and the user suppliedo ne might be even more unsafe (using any | |
516 | // wxWindows GUI function is unsafe starting from now) | |
517 | wxLog::DontCreateOnDemand(); | |
518 | ||
519 | // this will flush the old messages if any | |
520 | delete wxLog::SetActiveTarget(new wxLogStderr); | |
521 | #endif // wxUSE_LOG | |
fc0daf84 | 522 | #endif |
0a67a93b | 523 | |
0a6cce3b SC |
524 | wxWinMacWindowList = new wxList(wxKEY_INTEGER); |
525 | wxWinMacControlList = new wxList(wxKEY_INTEGER); | |
526 | ||
e9576ca5 SC |
527 | wxInitializeStockLists(); |
528 | wxInitializeStockObjects(); | |
529 | ||
530 | #if wxUSE_WX_RESOURCES | |
531 | wxInitializeResourceSystem(); | |
532 | #endif | |
533 | ||
534 | wxBitmap::InitStandardHandlers(); | |
535 | ||
536 | wxModule::RegisterModules(); | |
03e11df5 | 537 | if (!wxModule::InitializeModules()) { |
519cb848 | 538 | return FALSE; |
03e11df5 | 539 | } |
e9576ca5 | 540 | |
2f1ae414 | 541 | wxMacCreateNotifierTable() ; |
9779893b | 542 | |
b4efa069 | 543 | |
2f1ae414 | 544 | UMAShowArrowCursor() ; |
8461e4c2 | 545 | |
e9576ca5 SC |
546 | return TRUE; |
547 | } | |
548 | ||
549 | void wxApp::CleanUp() | |
550 | { | |
12cd5f34 | 551 | wxToolTip::RemoveToolTips() ; |
2f1ae414 SC |
552 | #if wxUSE_LOG |
553 | // flush the logged messages if any and install a 'safer' log target: the | |
554 | // default one (wxLogGui) can't be used after the resources are freed just | |
555 | // below and the user suppliedo ne might be even more unsafe (using any | |
556 | // wxWindows GUI function is unsafe starting from now) | |
557 | wxLog::DontCreateOnDemand(); | |
558 | ||
559 | // this will flush the old messages if any | |
560 | delete wxLog::SetActiveTarget(new wxLogStderr); | |
561 | #endif // wxUSE_LOG | |
562 | ||
563 | // One last chance for pending objects to be cleaned up | |
564 | wxTheApp->DeletePendingObjects(); | |
565 | ||
fbbdb7cd | 566 | wxModule::CleanUpModules(); |
e9576ca5 SC |
567 | |
568 | #if wxUSE_WX_RESOURCES | |
fbbdb7cd | 569 | wxCleanUpResourceSystem(); |
e9576ca5 SC |
570 | #endif |
571 | ||
fbbdb7cd | 572 | wxDeleteStockObjects() ; |
e9576ca5 | 573 | |
2f1ae414 SC |
574 | // Destroy all GDI lists, etc. |
575 | wxDeleteStockLists(); | |
e9576ca5 | 576 | |
fbbdb7cd GD |
577 | delete wxTheColourDatabase; |
578 | wxTheColourDatabase = NULL; | |
e9576ca5 | 579 | |
fbbdb7cd | 580 | wxBitmap::CleanUpHandlers(); |
519cb848 | 581 | |
fbbdb7cd GD |
582 | delete[] wxBuffer; |
583 | wxBuffer = NULL; | |
12cd5f34 | 584 | |
fbbdb7cd GD |
585 | wxMacDestroyNotifierTable() ; |
586 | if (wxWinMacWindowList) { | |
587 | delete wxWinMacWindowList ; | |
588 | } | |
589 | if (wxWinMacControlList) { | |
590 | delete wxWinMacControlList ; | |
591 | } | |
2f1ae414 | 592 | delete wxPendingEvents; |
fbbdb7cd | 593 | |
2f1ae414 SC |
594 | #if wxUSE_THREADS |
595 | delete wxPendingEventsLocker; | |
596 | // If we don't do the following, we get an apparent memory leak. | |
597 | ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker(); | |
598 | #endif | |
599 | ||
fbbdb7cd | 600 | wxClassInfo::CleanUpClasses(); |
e9576ca5 | 601 | |
f5c6eb5c | 602 | #ifndef __DARWIN__ |
fbbdb7cd GD |
603 | # if __option(profile) |
604 | ProfilerDump( "\papp.prof" ) ; | |
605 | ProfilerTerm() ; | |
606 | # endif | |
9779893b | 607 | #endif |
519cb848 | 608 | |
fbbdb7cd GD |
609 | delete wxTheApp; |
610 | wxTheApp = NULL; | |
9779893b | 611 | |
e9576ca5 | 612 | #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT |
2f1ae414 SC |
613 | // At this point we want to check if there are any memory |
614 | // blocks that aren't part of the wxDebugContext itself, | |
615 | // as a special case. Then when dumping we need to ignore | |
616 | // wxDebugContext, too. | |
617 | if (wxDebugContext::CountObjectsLeft(TRUE) > 0) | |
618 | { | |
619 | wxLogDebug(wxT("There were memory leaks.")); | |
620 | wxDebugContext::Dump(); | |
621 | wxDebugContext::PrintStatistics(); | |
622 | } | |
623 | // wxDebugContext::SetStream(NULL, NULL); | |
e9576ca5 | 624 | #endif |
9779893b | 625 | |
2f1ae414 SC |
626 | #if wxUSE_LOG |
627 | // do it as the very last thing because everything else can log messages | |
628 | delete wxLog::SetActiveTarget(NULL); | |
629 | #endif // wxUSE_LOG | |
169935ad | 630 | |
fbbdb7cd GD |
631 | #if defined(WXMAKINGDLL) && defined(__DARWIN__) |
632 | // close shared library resources from here since we don't have | |
633 | // __wxterminate in Mach-O shared libraries | |
634 | wxStAppResource::CloseSharedLibraryResource(); | |
635 | #endif | |
636 | ||
8461e4c2 | 637 | UMACleanupToolbox() ; |
fbbdb7cd | 638 | if (s_macCursorRgn) { |
76a5e5d2 | 639 | ::DisposeRgn((RgnHandle)s_macCursorRgn); |
fbbdb7cd GD |
640 | } |
641 | ||
8461e4c2 VZ |
642 | #if 0 |
643 | TerminateAE() ; | |
644 | #endif | |
e9576ca5 SC |
645 | } |
646 | ||
92b002a4 RD |
647 | //---------------------------------------------------------------------- |
648 | // wxEntry | |
649 | //---------------------------------------------------------------------- | |
650 | ||
fbbdb7cd GD |
651 | // extern variable for shared library resource id |
652 | // need to be able to find it with NSLookupAndBindSymbol | |
653 | short gSharedLibraryResource = kResFileNotOpened ; | |
654 | ||
ed581ee2 | 655 | #if defined(WXMAKINGDLL) && defined(__DARWIN__) |
fbbdb7cd | 656 | CFBundleRef gSharedLibraryBundle = NULL; |
ed581ee2 | 657 | #endif /* WXMAKINGDLL && __DARWIN__ */ |
53fd991c SC |
658 | |
659 | wxStAppResource::wxStAppResource() | |
660 | { | |
fbbdb7cd GD |
661 | m_currentRefNum = CurResFile() ; |
662 | if ( gSharedLibraryResource != kResFileNotOpened ) | |
663 | { | |
664 | UseResFile( gSharedLibraryResource ) ; | |
665 | } | |
666 | } | |
667 | ||
668 | wxStAppResource::~wxStAppResource() | |
669 | { | |
670 | if ( m_currentRefNum != kResFileNotOpened ) | |
671 | { | |
672 | UseResFile( m_currentRefNum ) ; | |
673 | } | |
674 | } | |
675 | ||
676 | void wxStAppResource::OpenSharedLibraryResource(const void *initBlock) | |
677 | { | |
678 | gSharedLibraryResource = kResFileNotOpened; | |
679 | ||
680 | #ifdef WXMAKINGDLL | |
681 | if ( initBlock != NULL ) { | |
682 | const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock; | |
683 | FSSpec *fileSpec = NULL; | |
684 | ||
685 | if (theInitBlock->fragLocator.where == kDataForkCFragLocator) { | |
686 | fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec; | |
687 | } | |
688 | else if (theInitBlock->fragLocator.where == kResourceCFragLocator) { | |
689 | fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec; | |
690 | } | |
691 | ||
692 | if (fileSpec != NULL) { | |
693 | gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm); | |
694 | } | |
695 | } | |
696 | else { | |
697 | #ifdef __DARWIN__ | |
698 | // Open the shared library resource file if it is not yet open | |
ed581ee2 GD |
699 | NSSymbol theSymbol; |
700 | NSModule theModule; | |
701 | const char *theLibPath; | |
702 | ||
fbbdb7cd GD |
703 | gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows")); |
704 | if (gSharedLibraryBundle != NULL) { | |
ed581ee2 GD |
705 | // wxWindows has been bundled into a framework |
706 | // load the framework resources | |
707 | ||
fbbdb7cd | 708 | gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle); |
ed581ee2 GD |
709 | } |
710 | else { | |
711 | // wxWindows is a simple dynamic shared library | |
712 | // load the resources from the data fork of a separate resource file | |
713 | char *theResPath; | |
714 | char *theName; | |
715 | char *theExt; | |
716 | FSRef theResRef; | |
717 | OSErr theErr = noErr; | |
718 | ||
719 | // get the library path | |
fbbdb7cd | 720 | theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource"); |
ed581ee2 GD |
721 | theModule = NSModuleForSymbol(theSymbol); |
722 | theLibPath = NSLibraryNameForModule(theModule); | |
ed581ee2 GD |
723 | |
724 | // allocate copy to replace .dylib.* extension with .rsrc | |
725 | theResPath = strdup(theLibPath); | |
726 | if (theResPath != NULL) { | |
727 | theName = strrchr(theResPath, '/'); | |
728 | if (theName == NULL) { | |
729 | // no directory elements in path | |
730 | theName = theResPath; | |
731 | } | |
732 | // find ".dylib" shared library extension | |
733 | theExt = strstr(theName, ".dylib"); | |
734 | // overwrite extension with ".rsrc" | |
735 | strcpy(theExt, ".rsrc"); | |
736 | ||
737 | wxLogDebug( theResPath ); | |
738 | ||
739 | theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false); | |
740 | if (theErr != noErr) { | |
741 | // try in current directory (using name only) | |
742 | theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false); | |
743 | } | |
744 | ||
745 | // free duplicated resource file path | |
746 | free(theResPath); | |
747 | ||
748 | // open the resource file | |
749 | if (theErr == noErr) { | |
750 | theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm, | |
fbbdb7cd | 751 | &gSharedLibraryResource); |
ed581ee2 GD |
752 | } |
753 | } | |
754 | } | |
fbbdb7cd | 755 | #endif /* __DARWIN__ */ |
53fd991c | 756 | } |
fbbdb7cd | 757 | #endif /* WXMAKINGDLL */ |
53fd991c SC |
758 | } |
759 | ||
fbbdb7cd | 760 | void wxStAppResource::CloseSharedLibraryResource() |
53fd991c | 761 | { |
fbbdb7cd | 762 | #ifdef WXMAKINGDLL |
ed581ee2 | 763 | // Close the shared library resource file |
fbbdb7cd GD |
764 | if (gSharedLibraryResource != kResFileNotOpened) { |
765 | #ifdef __DARWIN__ | |
766 | if (gSharedLibraryBundle != NULL) { | |
767 | CFBundleCloseBundleResourceMap(gSharedLibraryBundle, | |
768 | gSharedLibraryResource); | |
769 | gSharedLibraryBundle = NULL; | |
ed581ee2 | 770 | } |
fbbdb7cd GD |
771 | else |
772 | #endif /* __DARWIN__ */ | |
773 | { | |
774 | CloseResFile(gSharedLibraryResource); | |
ed581ee2 | 775 | } |
fbbdb7cd GD |
776 | gSharedLibraryResource = kResFileNotOpened; |
777 | } | |
778 | #endif /* WXMAKINGDLL */ | |
53fd991c SC |
779 | } |
780 | ||
ed581ee2 | 781 | #if defined(WXMAKINGDLL) && !defined(__DARWIN__) |
53fd991c | 782 | |
ed581ee2 GD |
783 | // for shared libraries we have to manually get the correct resource |
784 | // ref num upon initializing and releasing when terminating, therefore | |
785 | // the __wxinitialize and __wxterminate must be used | |
53fd991c | 786 | |
53fd991c | 787 | extern "C" { |
fbbdb7cd GD |
788 | void __sinit(void); /* (generated by linker) */ |
789 | pascal OSErr __initialize(const CFragInitBlock *theInitBlock); | |
790 | pascal void __terminate(void); | |
53fd991c | 791 | } |
53fd991c SC |
792 | |
793 | pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock) | |
794 | { | |
fbbdb7cd GD |
795 | wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ; |
796 | return __initialize( theInitBlock ) ; | |
53fd991c SC |
797 | } |
798 | ||
799 | pascal void __wxterminate(void) | |
800 | { | |
fbbdb7cd | 801 | wxStAppResource::CloseSharedLibraryResource() ; |
53fd991c SC |
802 | __terminate() ; |
803 | } | |
ed581ee2 GD |
804 | |
805 | #endif /* WXMAKINGDLL && !__DARWIN__ */ | |
53fd991c | 806 | |
2a294857 | 807 | int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char *WXUNUSED(argv)[] ) |
92b002a4 RD |
808 | { |
809 | return wxApp::Initialize(); | |
810 | } | |
811 | ||
53fd991c | 812 | int WXDLLEXPORT wxEntryInitGui() |
92b002a4 RD |
813 | { |
814 | return wxTheApp->OnInitGui(); | |
815 | } | |
816 | ||
53fd991c | 817 | void WXDLLEXPORT wxEntryCleanup() |
92b002a4 RD |
818 | { |
819 | wxApp::CleanUp(); | |
820 | } | |
821 | ||
2f1ae414 | 822 | int wxEntry( int argc, char *argv[] , bool enterLoop ) |
e9576ca5 | 823 | { |
7c551d95 SC |
824 | #ifdef __MWERKS__ |
825 | #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT | |
826 | // This seems to be necessary since there are 'rogue' | |
827 | // objects present at this point (perhaps global objects?) | |
828 | // Setting a checkpoint will ignore them as far as the | |
829 | // memory checking facility is concerned. | |
830 | // Of course you may argue that memory allocated in globals should be | |
831 | // checked, but this is a reasonable compromise. | |
832 | wxDebugContext::SetCheckpoint(); | |
833 | #endif | |
834 | #endif | |
92b002a4 | 835 | if (!wxEntryStart(argc, argv)) { |
2f1ae414 | 836 | return 0; |
03e11df5 | 837 | } |
2f1ae414 SC |
838 | // create the application object or ensure that one already exists |
839 | if (!wxTheApp) | |
e9576ca5 | 840 | { |
2f1ae414 SC |
841 | // The app may have declared a global application object, but we recommend |
842 | // the IMPLEMENT_APP macro is used instead, which sets an initializer | |
843 | // function for delayed, dynamic app object construction. | |
844 | wxCHECK_MSG( wxApp::GetInitializerFunction(), 0, | |
845 | wxT("No initializer - use IMPLEMENT_APP macro.") ); | |
9779893b | 846 | |
2f1ae414 SC |
847 | wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) (); |
848 | } | |
9779893b | 849 | |
2f1ae414 | 850 | wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); |
e9576ca5 | 851 | |
e94e53ac GD |
852 | #ifdef __DARWIN__ |
853 | // Mac OS X passes a process serial number command line argument when | |
854 | // the application is launched from the Finder. This argument must be | |
855 | // removed from the command line arguments before being handled by the | |
856 | // application (otherwise applications would need to handle it) | |
857 | ||
858 | if (argc > 1) { | |
ed581ee2 GD |
859 | char theArg[6] = ""; |
860 | strncpy(theArg, argv[1], 5); | |
e94e53ac | 861 | |
ed581ee2 | 862 | if (strcmp(theArg, "-psn_") == 0) { |
e94e53ac GD |
863 | // assume the argument is always the only one and remove it |
864 | --argc; | |
865 | } | |
866 | } | |
867 | #else | |
89ebf1c9 | 868 | argc = 0 ; // currently we don't support files as parameters |
519cb848 | 869 | #endif |
89ebf1c9 | 870 | // we could try to get the open apple events here to adjust argc and argv better |
519cb848 | 871 | |
89ebf1c9 RR |
872 | wxTheApp->argc = argc; |
873 | wxTheApp->argv = argv; | |
9779893b | 874 | |
89ebf1c9 RR |
875 | // GUI-specific initialization, such as creating an app context. |
876 | wxEntryInitGui(); | |
9779893b | 877 | |
89ebf1c9 RR |
878 | // Here frames insert themselves automatically |
879 | // into wxTopLevelWindows by getting created | |
880 | // in OnInit(). | |
9779893b | 881 | |
89ebf1c9 | 882 | int retValue = 0; |
9779893b | 883 | |
8461e4c2 VZ |
884 | if ( wxTheApp->OnInit() ) |
885 | { | |
886 | if ( enterLoop ) | |
887 | { | |
888 | retValue = wxTheApp->OnRun(); | |
889 | } | |
890 | else | |
891 | // We want to initialize, but not run or exit immediately. | |
892 | return 1; | |
893 | } | |
894 | //else: app initialization failed, so we skipped OnRun() | |
895 | ||
896 | wxWindow *topWindow = wxTheApp->GetTopWindow(); | |
897 | if ( topWindow ) | |
898 | { | |
899 | // Forcibly delete the window. | |
900 | if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) || | |
901 | topWindow->IsKindOf(CLASSINFO(wxDialog)) ) | |
902 | { | |
903 | topWindow->Close(TRUE); | |
904 | wxTheApp->DeletePendingObjects(); | |
905 | } | |
906 | else | |
907 | { | |
908 | delete topWindow; | |
909 | wxTheApp->SetTopWindow(NULL); | |
910 | } | |
911 | } | |
912 | ||
913 | wxTheApp->OnExit(); | |
914 | ||
92b002a4 | 915 | wxEntryCleanup(); |
8461e4c2 VZ |
916 | |
917 | return retValue; | |
03e11df5 | 918 | } |
e9576ca5 | 919 | |
b4efa069 SC |
920 | #if TARGET_CARBON |
921 | ||
922 | bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) | |
923 | { | |
924 | bool converted = ConvertEventRefToEventRecord( event,rec) ; | |
925 | OSStatus err = noErr ; | |
926 | if ( !converted ) | |
927 | { | |
928 | switch( GetEventClass( event ) ) | |
929 | { | |
930 | case kEventClassKeyboard : | |
931 | { | |
932 | converted = true ; | |
933 | switch( GetEventKind(event) ) | |
934 | { | |
935 | case kEventRawKeyDown : | |
936 | rec->what = keyDown ; | |
937 | break ; | |
938 | case kEventRawKeyRepeat : | |
939 | rec->what = autoKey ; | |
940 | break ; | |
941 | case kEventRawKeyUp : | |
942 | rec->what = keyUp ; | |
943 | break ; | |
944 | case kEventRawKeyModifiersChanged : | |
945 | rec->what = nullEvent ; | |
946 | break ; | |
947 | default : | |
948 | converted = false ; | |
949 | break ; | |
950 | } | |
951 | if ( converted ) | |
952 | { | |
953 | UInt32 keyCode ; | |
954 | unsigned char charCode ; | |
955 | UInt32 modifiers ; | |
956 | GetMouse( &rec->where) ; | |
957 | ||
958 | err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); | |
959 | err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode); | |
960 | err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode); | |
961 | rec->modifiers = modifiers ; | |
962 | rec->message = (keyCode << 8 ) + charCode ; | |
963 | } | |
964 | } | |
965 | break ; | |
966 | case kEventClassTextInput : | |
967 | { | |
968 | switch( GetEventKind( event ) ) | |
969 | { | |
970 | case kEventTextInputUnicodeForKeyEvent : | |
971 | { | |
972 | EventRef rawEvent ; | |
973 | err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ; | |
974 | converted = true ; | |
975 | { | |
976 | UInt32 keyCode ; | |
977 | unsigned char charCode ; | |
978 | UInt32 modifiers ; | |
979 | GetMouse( &rec->where) ; | |
980 | rec->what = keyDown ; | |
981 | err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers); | |
982 | err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode); | |
983 | err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode); | |
984 | rec->modifiers = modifiers ; | |
985 | rec->message = (keyCode << 8 ) + charCode ; | |
986 | } | |
987 | } | |
988 | break ; | |
989 | default : | |
990 | break ; | |
991 | } | |
992 | } | |
993 | break ; | |
994 | } | |
995 | } | |
996 | ||
997 | return converted ; | |
998 | } | |
999 | ||
1000 | pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1001 | { | |
1002 | OSStatus result = eventNotHandledErr ; | |
1003 | ||
1004 | EventRecord rec ; | |
1005 | switch ( GetEventClass( event ) ) | |
1006 | { | |
1007 | case kEventClassKeyboard : | |
1008 | if ( wxMacConvertEventToRecord( event , &rec ) ) | |
1009 | { | |
1010 | wxTheApp->MacHandleOneEvent( &rec ) ; | |
1011 | result = noErr ; | |
1012 | } | |
1013 | break ; | |
1014 | case kEventClassTextInput : | |
1015 | if ( wxMacConvertEventToRecord( event , &rec ) ) | |
1016 | { | |
1017 | wxTheApp->MacHandleOneEvent( &rec ) ; | |
1018 | result = noErr ; | |
1019 | } | |
1020 | break ; | |
1021 | default : | |
1022 | break ; | |
1023 | } | |
1024 | return result ; | |
1025 | } | |
1026 | ||
1027 | #endif | |
1028 | ||
1029 | bool wxApp::OnInit() | |
1030 | { | |
1031 | if ( ! wxAppBase::OnInit() ) | |
1032 | return FALSE ; | |
1033 | ||
ac2d1ca6 | 1034 | #if 0 // TARGET_CARBON |
b4efa069 SC |
1035 | static const EventTypeSpec eventList[] = |
1036 | { | |
1037 | { kEventClassKeyboard, kEventRawKeyDown } , | |
1038 | { kEventClassKeyboard, kEventRawKeyRepeat } , | |
1039 | { kEventClassKeyboard, kEventRawKeyUp } , | |
1040 | { kEventClassKeyboard, kEventRawKeyModifiersChanged } , | |
1041 | ||
1042 | { kEventClassTextInput , kEventTextInputUnicodeForKeyEvent } , | |
1043 | } ; | |
1044 | ||
1045 | InstallApplicationEventHandler(NewEventHandlerUPP(wxMacApplicationEventHandler) | |
1046 | , WXSIZEOF(eventList), eventList, this, NULL); | |
1047 | #endif | |
1048 | return TRUE ; | |
1049 | } | |
e9576ca5 | 1050 | // Static member initialization |
2f1ae414 | 1051 | wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL; |
e9576ca5 SC |
1052 | |
1053 | wxApp::wxApp() | |
1054 | { | |
1055 | m_topWindow = NULL; | |
1056 | wxTheApp = this; | |
2f1ae414 | 1057 | |
1b21409b JS |
1058 | #if WXWIN_COMPATIBILITY_2_2 |
1059 | m_wantDebugOutput = TRUE; | |
1060 | #endif | |
2f1ae414 | 1061 | |
e9576ca5 SC |
1062 | argc = 0; |
1063 | argv = NULL; | |
519cb848 | 1064 | |
e9576ca5 | 1065 | m_printMode = wxPRINT_WINDOWS; |
e9576ca5 SC |
1066 | m_exitOnFrameDelete = TRUE; |
1067 | m_auto3D = TRUE; | |
1068 | } | |
1069 | ||
1070 | bool wxApp::Initialized() | |
1071 | { | |
519cb848 | 1072 | if (GetTopWindow()) |
e9576ca5 | 1073 | return TRUE; |
519cb848 SC |
1074 | else |
1075 | return FALSE; | |
e9576ca5 SC |
1076 | } |
1077 | ||
1078 | int wxApp::MainLoop() | |
1079 | { | |
1080 | m_keepGoing = TRUE; | |
1081 | ||
e9576ca5 SC |
1082 | while (m_keepGoing) |
1083 | { | |
8461e4c2 | 1084 | MacDoOneEvent() ; |
e9576ca5 | 1085 | } |
e9576ca5 SC |
1086 | |
1087 | return 0; | |
1088 | } | |
1089 | ||
1090 | // Returns TRUE if more time is needed. | |
1091 | bool wxApp::ProcessIdle() | |
1092 | { | |
1093 | wxIdleEvent event; | |
1094 | event.SetEventObject(this); | |
1095 | ProcessEvent(event); | |
1096 | ||
1097 | return event.MoreRequested(); | |
1098 | } | |
1099 | ||
1100 | void wxApp::ExitMainLoop() | |
1101 | { | |
1102 | m_keepGoing = FALSE; | |
1103 | } | |
1104 | ||
1105 | // Is a message/event pending? | |
1106 | bool wxApp::Pending() | |
1107 | { | |
8461e4c2 | 1108 | EventRecord event ; |
519cb848 SC |
1109 | |
1110 | return EventAvail( everyEvent , &event ) ; | |
e9576ca5 SC |
1111 | } |
1112 | ||
1113 | // Dispatch a message. | |
1114 | void wxApp::Dispatch() | |
1115 | { | |
8461e4c2 | 1116 | MacDoOneEvent() ; |
e9576ca5 SC |
1117 | } |
1118 | ||
1119 | void wxApp::OnIdle(wxIdleEvent& event) | |
1120 | { | |
2f1ae414 | 1121 | static bool s_inOnIdle = FALSE; |
e9576ca5 | 1122 | |
2f1ae414 SC |
1123 | // Avoid recursion (via ProcessEvent default case) |
1124 | if ( s_inOnIdle ) | |
1125 | return; | |
e9576ca5 | 1126 | |
2f1ae414 SC |
1127 | |
1128 | s_inOnIdle = TRUE; | |
e9576ca5 SC |
1129 | |
1130 | // 'Garbage' collection of windows deleted with Close(). | |
1131 | DeletePendingObjects(); | |
1132 | ||
1133 | // flush the logged messages if any | |
1134 | wxLog *pLog = wxLog::GetActiveTarget(); | |
1135 | if ( pLog != NULL && pLog->HasPendingMessages() ) | |
1136 | pLog->Flush(); | |
1137 | ||
1138 | // Send OnIdle events to all windows | |
1139 | bool needMore = SendIdleEvents(); | |
1140 | ||
1141 | if (needMore) | |
1142 | event.RequestMore(TRUE); | |
1143 | ||
2f1ae414 SC |
1144 | // If they are pending events, we must process them: pending events are |
1145 | // either events to the threads other than main or events posted with | |
1146 | // wxPostEvent() functions | |
1147 | wxMacProcessNotifierAndPendingEvents(); | |
1148 | ||
1149 | s_inOnIdle = FALSE; | |
e9576ca5 SC |
1150 | } |
1151 | ||
9779893b RD |
1152 | void wxWakeUpIdle() |
1153 | { | |
8461e4c2 | 1154 | wxMacWakeUp() ; |
9779893b RD |
1155 | } |
1156 | ||
e9576ca5 SC |
1157 | // Send idle event to all top-level windows |
1158 | bool wxApp::SendIdleEvents() | |
1159 | { | |
1160 | bool needMore = FALSE; | |
8461e4c2 VZ |
1161 | wxNode* node = wxTopLevelWindows.First(); |
1162 | while (node) | |
1163 | { | |
1164 | wxWindow* win = (wxWindow*) node->Data(); | |
1165 | if (SendIdleEvents(win)) | |
e9576ca5 SC |
1166 | needMore = TRUE; |
1167 | ||
8461e4c2 VZ |
1168 | node = node->Next(); |
1169 | } | |
e9576ca5 SC |
1170 | return needMore; |
1171 | } | |
1172 | ||
1173 | // Send idle event to window and all subwindows | |
1174 | bool wxApp::SendIdleEvents(wxWindow* win) | |
1175 | { | |
1176 | bool needMore = FALSE; | |
1177 | ||
8461e4c2 VZ |
1178 | wxIdleEvent event; |
1179 | event.SetEventObject(win); | |
1180 | win->ProcessEvent(event); | |
e9576ca5 SC |
1181 | |
1182 | if (event.MoreRequested()) | |
1183 | needMore = TRUE; | |
1184 | ||
8461e4c2 VZ |
1185 | wxNode* node = win->GetChildren().First(); |
1186 | while (node) | |
1187 | { | |
1188 | wxWindow* win = (wxWindow*) node->Data(); | |
1189 | if (SendIdleEvents(win)) | |
e9576ca5 SC |
1190 | needMore = TRUE; |
1191 | ||
8461e4c2 VZ |
1192 | node = node->Next(); |
1193 | } | |
e9576ca5 SC |
1194 | return needMore ; |
1195 | } | |
1196 | ||
1197 | void wxApp::DeletePendingObjects() | |
1198 | { | |
1199 | wxNode *node = wxPendingDelete.First(); | |
1200 | while (node) | |
1201 | { | |
1202 | wxObject *obj = (wxObject *)node->Data(); | |
9779893b | 1203 | |
e9576ca5 SC |
1204 | delete obj; |
1205 | ||
1206 | if (wxPendingDelete.Member(obj)) | |
1207 | delete node; | |
1208 | ||
1209 | // Deleting one object may have deleted other pending | |
1210 | // objects, so start from beginning of list again. | |
1211 | node = wxPendingDelete.First(); | |
1212 | } | |
1213 | } | |
1214 | ||
e9576ca5 SC |
1215 | void wxExit() |
1216 | { | |
2f1ae414 SC |
1217 | wxLogError(_("Fatal error: exiting")); |
1218 | ||
1219 | wxApp::CleanUp(); | |
8461e4c2 | 1220 | ::ExitToShell() ; |
e9576ca5 SC |
1221 | } |
1222 | ||
2f1ae414 SC |
1223 | void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event)) |
1224 | { | |
1225 | if (GetTopWindow()) | |
1226 | GetTopWindow()->Close(TRUE); | |
1227 | } | |
1228 | ||
1229 | // Default behaviour: close the application with prompts. The | |
1230 | // user can veto the close, and therefore the end session. | |
1231 | void wxApp::OnQueryEndSession(wxCloseEvent& event) | |
1232 | { | |
1233 | if (GetTopWindow()) | |
1234 | { | |
1235 | if (!GetTopWindow()->Close(!event.CanVeto())) | |
1236 | event.Veto(TRUE); | |
1237 | } | |
1238 | } | |
1239 | ||
1240 | extern "C" void wxCYield() ; | |
1241 | void wxCYield() | |
1242 | { | |
8461e4c2 | 1243 | wxYield() ; |
2f1ae414 SC |
1244 | } |
1245 | ||
e9576ca5 | 1246 | // Yield to other processes |
cb2713bf | 1247 | |
8461e4c2 | 1248 | bool wxApp::Yield(bool onlyIfNeeded) |
e9576ca5 | 1249 | { |
8461e4c2 VZ |
1250 | static bool s_inYield = FALSE; |
1251 | ||
1252 | if (s_inYield) | |
1253 | { | |
1254 | if ( !onlyIfNeeded ) | |
1255 | { | |
1256 | wxFAIL_MSG( wxT("wxYield called recursively" ) ); | |
1257 | } | |
1258 | ||
1259 | return FALSE; | |
1260 | } | |
1261 | ||
1262 | s_inYield = TRUE; | |
cb2713bf | 1263 | |
2f1ae414 | 1264 | #if wxUSE_THREADS |
cb2713bf | 1265 | YieldToAnyThread() ; |
2f1ae414 | 1266 | #endif |
cb2713bf | 1267 | EventRecord event ; |
2f1ae414 | 1268 | |
8461e4c2 | 1269 | long sleepTime = 1 ; //::GetCaretTime(); |
2f1ae414 | 1270 | |
76a5e5d2 | 1271 | while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) |
8461e4c2 VZ |
1272 | { |
1273 | wxTheApp->MacHandleOneEvent( &event ); | |
1274 | if ( event.what != kHighLevelEvent ) | |
76a5e5d2 | 1275 | SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; |
8461e4c2 | 1276 | } |
2f1ae414 | 1277 | |
8461e4c2 | 1278 | wxMacProcessNotifierAndPendingEvents() ; |
cb2713bf | 1279 | |
8461e4c2 | 1280 | s_inYield = FALSE; |
cb2713bf | 1281 | |
8461e4c2 | 1282 | return TRUE; |
169935ad SC |
1283 | } |
1284 | ||
9779893b | 1285 | // platform specifics |
169935ad | 1286 | |
519cb848 SC |
1287 | void wxApp::MacSuspend( bool convertClipboard ) |
1288 | { | |
1c469f7f | 1289 | // we have to deactive the top level windows manually |
8461e4c2 | 1290 | |
1c469f7f SC |
1291 | wxNode* node = wxTopLevelWindows.First(); |
1292 | while (node) | |
1293 | { | |
1294 | wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data(); | |
1295 | win->MacActivate( MacGetCurrentEvent() , false ) ; | |
8461e4c2 | 1296 | |
1c469f7f SC |
1297 | node = node->Next(); |
1298 | } | |
2a294857 GD |
1299 | |
1300 | s_lastMouseDown = 0 ; | |
1301 | if( convertClipboard ) | |
1302 | { | |
1303 | MacConvertPrivateToPublicScrap() ; | |
1304 | } | |
1305 | ||
1306 | ::HideFloatingWindows() ; | |
519cb848 SC |
1307 | } |
1308 | ||
2a294857 GD |
1309 | extern wxList wxModalDialogs; |
1310 | ||
519cb848 SC |
1311 | void wxApp::MacResume( bool convertClipboard ) |
1312 | { | |
2a294857 GD |
1313 | s_lastMouseDown = 0 ; |
1314 | if( convertClipboard ) | |
1315 | { | |
1316 | MacConvertPublicToPrivateScrap() ; | |
1317 | } | |
1318 | ||
1319 | ::ShowFloatingWindows() ; | |
1320 | ||
1321 | // raise modal dialogs in case a non modal window was selected to activate the app | |
9779893b | 1322 | |
2a294857 GD |
1323 | wxNode* node = wxModalDialogs.First(); |
1324 | while (node) | |
1325 | { | |
1326 | wxDialog* dialog = (wxDialog *) node->Data(); | |
1327 | dialog->Raise(); | |
1328 | ||
1329 | node = node->Next(); | |
1330 | } | |
519cb848 SC |
1331 | } |
1332 | ||
1333 | void wxApp::MacConvertPrivateToPublicScrap() | |
1334 | { | |
519cb848 SC |
1335 | } |
1336 | ||
1337 | void wxApp::MacConvertPublicToPrivateScrap() | |
1338 | { | |
519cb848 SC |
1339 | } |
1340 | ||
9779893b | 1341 | void wxApp::MacDoOneEvent() |
169935ad SC |
1342 | { |
1343 | EventRecord event ; | |
1344 | ||
6264b550 | 1345 | long sleepTime = 1; // GetCaretTime() / 4 ; |
169935ad | 1346 | |
76a5e5d2 | 1347 | if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) |
8461e4c2 | 1348 | { |
6264b550 | 1349 | MacHandleOneEvent( &event ); |
8461e4c2 VZ |
1350 | } |
1351 | else | |
1352 | { | |
1353 | // idlers | |
72055702 | 1354 | WindowPtr window = ::FrontWindow() ; |
8461e4c2 | 1355 | if ( window ) |
72055702 | 1356 | ::IdleControls( window ) ; |
9779893b | 1357 | |
8461e4c2 VZ |
1358 | wxTheApp->ProcessIdle() ; |
1359 | } | |
1360 | if ( event.what != kHighLevelEvent ) | |
76a5e5d2 | 1361 | SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; |
519cb848 | 1362 | |
8461e4c2 | 1363 | // repeaters |
519cb848 | 1364 | |
6264b550 | 1365 | DeletePendingObjects() ; |
8461e4c2 | 1366 | wxMacProcessNotifierAndPendingEvents() ; |
169935ad SC |
1367 | } |
1368 | ||
76a5e5d2 | 1369 | void wxApp::MacHandleOneEvent( WXEVENTREF evr ) |
169935ad | 1370 | { |
76a5e5d2 | 1371 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1372 | m_macCurrentEvent = ev ; |
1373 | ||
1374 | wxApp::sm_lastMessageTime = ev->when ; | |
1375 | ||
1376 | switch (ev->what) | |
1377 | { | |
1378 | case mouseDown: | |
1379 | MacHandleMouseDownEvent( ev ) ; | |
1380 | if ( ev->modifiers & controlKey ) | |
1381 | s_lastMouseDown = 2; | |
1382 | else | |
1383 | s_lastMouseDown = 1; | |
1384 | break; | |
1385 | case mouseUp: | |
1386 | if ( s_lastMouseDown == 2 ) | |
1387 | { | |
1388 | ev->modifiers |= controlKey ; | |
1389 | } | |
1390 | else | |
1391 | { | |
1392 | ev->modifiers &= ~controlKey ; | |
1393 | } | |
1394 | MacHandleMouseUpEvent( ev ) ; | |
1395 | s_lastMouseDown = 0; | |
1396 | break; | |
1397 | case activateEvt: | |
1398 | MacHandleActivateEvent( ev ) ; | |
1399 | break; | |
1400 | case updateEvt: | |
1401 | MacHandleUpdateEvent( ev ) ; | |
1402 | break; | |
1403 | case keyDown: | |
1404 | case autoKey: | |
1405 | MacHandleKeyDownEvent( ev ) ; | |
1406 | break; | |
1407 | case keyUp: | |
1408 | MacHandleKeyUpEvent( ev ) ; | |
1409 | break; | |
1410 | case diskEvt: | |
1411 | MacHandleDiskEvent( ev ) ; | |
1412 | break; | |
1413 | case osEvt: | |
1414 | MacHandleOSEvent( ev ) ; | |
1415 | break; | |
1416 | case kHighLevelEvent: | |
1417 | MacHandleHighLevelEvent( ev ) ; | |
1418 | break; | |
1419 | default: | |
1420 | break; | |
1421 | } | |
1422 | wxMacProcessNotifierAndPendingEvents() ; | |
169935ad SC |
1423 | } |
1424 | ||
76a5e5d2 | 1425 | void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) |
169935ad | 1426 | { |
76a5e5d2 | 1427 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 | 1428 | ::AEProcessAppleEvent( ev ) ; |
169935ad SC |
1429 | } |
1430 | ||
519cb848 SC |
1431 | bool s_macIsInModalLoop = false ; |
1432 | ||
76a5e5d2 | 1433 | void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) |
169935ad | 1434 | { |
76a5e5d2 | 1435 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 | 1436 | wxToolTip::RemoveToolTips() ; |
2f1ae414 | 1437 | |
8461e4c2 | 1438 | WindowRef window; |
72055702 | 1439 | WindowRef frontWindow = ::FrontNonFloatingWindow() ; |
8461e4c2 VZ |
1440 | WindowAttributes frontWindowAttributes = NULL ; |
1441 | if ( frontWindow ) | |
72055702 | 1442 | ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; |
9779893b | 1443 | |
8461e4c2 | 1444 | short windowPart = ::FindWindow(ev->where, &window); |
a3722eeb | 1445 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
0a67a93b SC |
1446 | if ( wxPendingDelete.Member(win) ) |
1447 | return ; | |
9779893b | 1448 | |
8461e4c2 VZ |
1449 | BitMap screenBits; |
1450 | GetQDGlobalsScreenBits( &screenBits ); | |
1451 | ||
1452 | switch (windowPart) | |
1453 | { | |
1454 | case inMenuBar : | |
1455 | if ( s_macIsInModalLoop ) | |
1456 | { | |
1457 | SysBeep ( 30 ) ; | |
1458 | } | |
1459 | else | |
1460 | { | |
1461 | UInt32 menuresult = MenuSelect(ev->where) ; | |
1462 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ); | |
1463 | s_lastMouseDown = 0; | |
1464 | } | |
1465 | break ; | |
2f1ae414 | 1466 | #if !TARGET_CARBON |
8461e4c2 VZ |
1467 | case inSysWindow : |
1468 | SystemClick( ev , window ) ; | |
1469 | s_lastMouseDown = 0; | |
1470 | break ; | |
2f1ae414 | 1471 | #endif |
8461e4c2 VZ |
1472 | case inDrag : |
1473 | if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) ) | |
1474 | { | |
1475 | SysBeep ( 30 ) ; | |
1476 | } | |
1477 | else | |
1478 | { | |
1479 | DragWindow(window, ev->where, &screenBits.bounds); | |
1480 | if (win) | |
1481 | { | |
1482 | GrafPtr port ; | |
1483 | GetPort( &port ) ; | |
1484 | Point pt = { 0, 0 } ; | |
66a09d47 | 1485 | SetPortWindowPort(window) ; |
8461e4c2 VZ |
1486 | LocalToGlobal( &pt ) ; |
1487 | SetPort( port ) ; | |
1488 | win->SetSize( pt.h , pt.v , -1 , | |
1489 | -1 , wxSIZE_USE_EXISTING); | |
1490 | } | |
1491 | s_lastMouseDown = 0; | |
1492 | } | |
1493 | break ; | |
1494 | case inGoAway: | |
1495 | if (TrackGoAway(window, ev->where)) | |
1496 | { | |
1497 | if ( win ) | |
1498 | win->Close() ; | |
1499 | } | |
1500 | s_lastMouseDown = 0; | |
1501 | break; | |
1502 | case inGrow: | |
1503 | { | |
1504 | int growResult = GrowWindow(window , ev->where, &screenBits.bounds); | |
1505 | if (growResult != 0) | |
1506 | { | |
1507 | int newWidth = LoWord(growResult); | |
1508 | int newHeight = HiWord(growResult); | |
1509 | int oldWidth, oldHeight; | |
1510 | ||
1511 | ||
1512 | if (win) | |
1513 | { | |
1514 | win->GetSize(&oldWidth, &oldHeight); | |
1515 | if (newWidth == 0) | |
1516 | newWidth = oldWidth; | |
1517 | if (newHeight == 0) | |
1518 | newHeight = oldHeight; | |
0f493093 | 1519 | win->SetSize( -1, -1 , newWidth, newHeight, wxSIZE_USE_EXISTING); |
8461e4c2 VZ |
1520 | } |
1521 | } | |
1522 | s_lastMouseDown = 0; | |
1523 | } | |
1524 | break; | |
1525 | case inZoomIn: | |
1526 | case inZoomOut: | |
1527 | if (TrackBox(window, ev->where, windowPart)) | |
1528 | { | |
1529 | // TODO setup size event | |
1530 | ZoomWindow( window , windowPart , false ) ; | |
1531 | if (win) | |
1532 | { | |
1533 | Rect tempRect ; | |
0f493093 SC |
1534 | GrafPtr port ; |
1535 | GetPort( &port ) ; | |
1536 | Point pt = { 0, 0 } ; | |
1537 | SetPortWindowPort(window) ; | |
1538 | LocalToGlobal( &pt ) ; | |
1539 | SetPort( port ) ; | |
8461e4c2 VZ |
1540 | |
1541 | GetWindowPortBounds(window, &tempRect ) ; | |
0f493093 | 1542 | win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left , |
8461e4c2 VZ |
1543 | tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING); |
1544 | } | |
1545 | } | |
1546 | s_lastMouseDown = 0; | |
1547 | break; | |
1548 | case inCollapseBox : | |
1549 | // TODO setup size event | |
1550 | s_lastMouseDown = 0; | |
1551 | break ; | |
1552 | ||
1553 | case inContent : | |
1554 | { | |
1555 | GrafPtr port ; | |
1556 | GetPort( &port ) ; | |
66a09d47 | 1557 | SetPortWindowPort(window) ; |
8461e4c2 VZ |
1558 | SetPort( port ) ; |
1559 | } | |
1560 | if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) | |
1561 | { | |
1562 | if ( s_macIsInModalLoop ) | |
1563 | { | |
1564 | SysBeep ( 30 ) ; | |
1565 | } | |
1566 | else if ( UMAIsWindowFloating( window ) ) | |
1567 | { | |
1568 | if ( win ) | |
1569 | win->MacMouseDown( ev , windowPart ) ; | |
1570 | } | |
1571 | else | |
1572 | { | |
1573 | if ( win ) | |
1574 | win->MacMouseDown( ev , windowPart ) ; | |
72055702 | 1575 | ::SelectWindow( window ) ; |
8461e4c2 VZ |
1576 | } |
1577 | } | |
1578 | else | |
1579 | { | |
1580 | if ( win ) | |
1581 | win->MacMouseDown( ev , windowPart ) ; | |
1582 | } | |
1583 | break ; | |
1584 | ||
1585 | default: | |
1586 | break; | |
1587 | } | |
169935ad SC |
1588 | } |
1589 | ||
76a5e5d2 | 1590 | void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) |
169935ad | 1591 | { |
76a5e5d2 | 1592 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1593 | WindowRef window; |
1594 | ||
4f5a3250 SC |
1595 | short windowPart = inNoWindow ; |
1596 | if ( wxTheApp->s_captureWindow ) | |
1597 | { | |
1598 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
1599 | windowPart = inContent ; | |
1600 | } | |
1601 | else | |
1602 | { | |
1603 | windowPart = ::FindWindow(ev->where, &window) ; | |
1604 | } | |
8461e4c2 VZ |
1605 | |
1606 | switch (windowPart) | |
1607 | { | |
1608 | case inMenuBar : | |
1609 | break ; | |
1610 | case inSysWindow : | |
1611 | break ; | |
1612 | default: | |
1613 | { | |
a3722eeb | 1614 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1615 | if ( win ) |
1616 | win->MacMouseUp( ev , windowPart ) ; | |
1617 | } | |
1618 | break; | |
1619 | } | |
169935ad SC |
1620 | } |
1621 | ||
72055702 | 1622 | long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
7c551d95 | 1623 | long wxMacTranslateKey(unsigned char key, unsigned char code) |
9779893b | 1624 | { |
8461e4c2 | 1625 | long retval = key ; |
9779893b | 1626 | switch (key) |
519cb848 | 1627 | { |
8461e4c2 VZ |
1628 | case 0x01 : |
1629 | retval = WXK_HOME; | |
1630 | break; | |
1631 | case 0x03 : | |
1632 | retval = WXK_RETURN; | |
1633 | break; | |
1634 | case 0x04 : | |
1635 | retval = WXK_END; | |
1636 | break; | |
1637 | case 0x05 : | |
1638 | retval = WXK_HELP; | |
1639 | break; | |
1640 | case 0x08 : | |
1641 | retval = WXK_BACK; | |
1642 | break; | |
1643 | case 0x09 : | |
1644 | retval = WXK_TAB; | |
1645 | break; | |
1646 | case 0x0b : | |
1647 | retval = WXK_PAGEUP; | |
1648 | break; | |
1649 | case 0x0c : | |
1650 | retval = WXK_PAGEDOWN; | |
1651 | break; | |
1652 | case 0x0d : | |
1653 | retval = WXK_RETURN; | |
1654 | break; | |
1655 | case 0x10 : | |
1656 | { | |
1657 | switch( code ) | |
1658 | { | |
1659 | case 0x7a : | |
1660 | retval = WXK_F1 ; | |
1661 | break; | |
1662 | case 0x78 : | |
1663 | retval = WXK_F2 ; | |
1664 | break; | |
1665 | case 0x63 : | |
1666 | retval = WXK_F3 ; | |
1667 | break; | |
1668 | case 0x76 : | |
1669 | retval = WXK_F4 ; | |
1670 | break; | |
1671 | case 0x60 : | |
1672 | retval = WXK_F5 ; | |
1673 | break; | |
1674 | case 0x61 : | |
1675 | retval = WXK_F6 ; | |
1676 | break; | |
1677 | case 0x62: | |
1678 | retval = WXK_F7 ; | |
1679 | break; | |
1680 | case 0x64 : | |
1681 | retval = WXK_F8 ; | |
1682 | break; | |
1683 | case 0x65 : | |
1684 | retval = WXK_F9 ; | |
1685 | break; | |
1686 | case 0x6D : | |
1687 | retval = WXK_F10 ; | |
1688 | break; | |
1689 | case 0x67 : | |
1690 | retval = WXK_F11 ; | |
1691 | break; | |
1692 | case 0x6F : | |
1693 | retval = WXK_F12 ; | |
1694 | break; | |
1695 | case 0x69 : | |
1696 | retval = WXK_F13 ; | |
1697 | break; | |
1698 | case 0x6B : | |
1699 | retval = WXK_F14 ; | |
1700 | break; | |
1701 | case 0x71 : | |
1702 | retval = WXK_F15 ; | |
1703 | break; | |
1704 | } | |
1705 | } | |
1706 | break ; | |
1707 | case 0x1b : | |
1708 | retval = WXK_ESCAPE ; | |
1709 | break ; | |
1710 | case 0x1c : | |
1711 | retval = WXK_LEFT ; | |
1712 | break ; | |
1713 | case 0x1d : | |
1714 | retval = WXK_RIGHT ; | |
1715 | break ; | |
1716 | case 0x1e : | |
1717 | retval = WXK_UP ; | |
1718 | break ; | |
1719 | case 0x1f : | |
1720 | retval = WXK_DOWN ; | |
1721 | break ; | |
1722 | case 0x7F : | |
1723 | retval = WXK_DELETE ; | |
1724 | default: | |
1725 | break ; | |
1726 | } // end switch | |
1727 | ||
1728 | return retval; | |
169935ad SC |
1729 | } |
1730 | ||
76a5e5d2 | 1731 | void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) |
169935ad | 1732 | { |
76a5e5d2 | 1733 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1734 | wxToolTip::RemoveToolTips() ; |
1735 | ||
1736 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1737 | if ( HiWord( menuresult ) ) | |
1738 | { | |
1739 | if ( !s_macIsInModalLoop ) | |
ac2d1ca6 | 1740 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; |
8461e4c2 VZ |
1741 | } |
1742 | else | |
1743 | { | |
1744 | short keycode ; | |
1745 | short keychar ; | |
1746 | keychar = short(ev->message & charCodeMask); | |
1747 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
e562df9b | 1748 | long keyval = wxMacTranslateKey(keychar, keycode) ; |
8461e4c2 | 1749 | wxWindow* focus = wxWindow::FindFocus() ; |
8461e4c2 | 1750 | |
ac2d1ca6 SC |
1751 | if ( MacSendKeyDownEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false ) |
1752 | { | |
1753 | // has not been handled -> perform default | |
1754 | wxControl* control = wxDynamicCast( focus , wxControl ) ; | |
1755 | if ( control && control->GetMacControl() != NULL ) | |
8461e4c2 | 1756 | { |
ac2d1ca6 SC |
1757 | ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ; |
1758 | } | |
1759 | } | |
1760 | } | |
1761 | } | |
1762 | ||
1763 | bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey ) | |
1764 | { | |
1765 | bool handled = false ; | |
1766 | // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value | |
1767 | if ( modifiers & controlKey && keyval >= 0 && keyval < 0x20 ) | |
1768 | { | |
1769 | keyval += 0x40 ; | |
1770 | } | |
1771 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
1772 | event.m_shiftDown = modifiers & shiftKey; | |
1773 | event.m_controlDown = modifiers & controlKey; | |
1774 | event.m_altDown = modifiers & optionKey; | |
1775 | event.m_metaDown = modifiers & cmdKey; | |
1776 | event.m_keyCode = keyval; | |
1777 | ||
1778 | event.m_x = wherex; | |
1779 | event.m_y = wherey; | |
1780 | event.m_timeStamp = when; | |
1781 | event.SetEventObject(focus); | |
1782 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1783 | if ( handled && event.GetSkipped() ) | |
1784 | handled = false ; | |
1785 | if ( !handled ) | |
1786 | { | |
ba2928c6 | 1787 | #if wxUSE_ACCEL |
ac2d1ca6 SC |
1788 | if (!handled) |
1789 | { | |
1790 | wxWindow *ancestor = focus; | |
1791 | while (ancestor) | |
1792 | { | |
1793 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
1794 | if (command != -1) | |
8461e4c2 | 1795 | { |
ac2d1ca6 SC |
1796 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); |
1797 | handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
1798 | break; | |
8461e4c2 | 1799 | } |
ac2d1ca6 SC |
1800 | if (ancestor->IsTopLevel()) |
1801 | break; | |
1802 | ancestor = ancestor->GetParent(); | |
8461e4c2 | 1803 | } |
ac2d1ca6 SC |
1804 | } |
1805 | #endif // wxUSE_ACCEL | |
1806 | } | |
1807 | if (!handled) | |
1808 | { | |
1809 | event.Skip( FALSE ) ; | |
1810 | event.SetEventType( wxEVT_CHAR ) ; | |
1811 | ||
1812 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1813 | if ( handled && event.GetSkipped() ) | |
1814 | handled = false ; | |
1815 | } | |
1816 | if ( !handled && | |
1817 | (keyval == WXK_TAB) && | |
35a8698b SC |
1818 | // CS: copied the change below from wxGTK |
1819 | // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may | |
1820 | // have this style, yet choose not to process this particular TAB in which | |
1821 | // case TAB must still work as a navigational character | |
1822 | #if 0 | |
ac2d1ca6 | 1823 | (!focus->HasFlag(wxTE_PROCESS_TAB)) && |
35a8698b | 1824 | #endif |
ac2d1ca6 SC |
1825 | (focus->GetParent()) && |
1826 | (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) | |
1827 | { | |
1828 | wxNavigationKeyEvent new_event; | |
1829 | new_event.SetEventObject( focus ); | |
1830 | new_event.SetDirection( !event.ShiftDown() ); | |
1831 | /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ | |
1832 | new_event.SetWindowChange( event.ControlDown() ); | |
1833 | new_event.SetCurrentFocus( focus ); | |
1834 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
1835 | if ( handled && new_event.GetSkipped() ) | |
1836 | handled = false ; | |
1837 | } | |
1838 | // backdoor handler for default return and command escape | |
1839 | if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) ) | |
1840 | { | |
1841 | // if window is not having a focus still testing for default enter or cancel | |
1842 | // TODO add the UMA version for ActiveNonFloatingWindow | |
1843 | wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ; | |
e562df9b SC |
1844 | if ( focus ) |
1845 | { | |
1846 | if ( keyval == WXK_RETURN ) | |
1847 | { | |
1848 | wxButton *def = wxDynamicCast(focus->GetDefaultItem(), | |
1849 | wxButton); | |
1850 | if ( def && def->IsEnabled() ) | |
1851 | { | |
1852 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
1853 | event.SetEventObject(def); | |
1854 | def->Command(event); | |
ac2d1ca6 | 1855 | return true ; |
e562df9b SC |
1856 | } |
1857 | } | |
8461e4c2 | 1858 | /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ |
ac2d1ca6 | 1859 | else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) ) |
8461e4c2 | 1860 | { |
e562df9b SC |
1861 | wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); |
1862 | new_event.SetEventObject( focus ); | |
1863 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
8461e4c2 | 1864 | } |
e562df9b | 1865 | } |
8461e4c2 | 1866 | } |
ac2d1ca6 | 1867 | return handled ; |
169935ad SC |
1868 | } |
1869 | ||
ac2d1ca6 | 1870 | |
76a5e5d2 | 1871 | void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) |
169935ad | 1872 | { |
76a5e5d2 | 1873 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1874 | wxToolTip::RemoveToolTips() ; |
1875 | ||
1876 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1877 | if ( HiWord( menuresult ) ) | |
1878 | { | |
1879 | } | |
1880 | else | |
1881 | { | |
1882 | short keycode ; | |
1883 | short keychar ; | |
1884 | keychar = short(ev->message & charCodeMask); | |
1885 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
ac2d1ca6 | 1886 | long keyval = wxMacTranslateKey(keychar, keycode) ; |
8461e4c2 VZ |
1887 | |
1888 | wxWindow* focus = wxWindow::FindFocus() ; | |
ac2d1ca6 SC |
1889 | bool handled = MacSendKeyUpEvent( focus , keyval , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ; |
1890 | // we don't have to do anything under classic here | |
8461e4c2 | 1891 | } |
169935ad SC |
1892 | } |
1893 | ||
ac2d1ca6 SC |
1894 | bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keyval , long modifiers , long when , short wherex , short wherey ) |
1895 | { | |
1896 | bool handled = false ; | |
1897 | // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value | |
1898 | if ( modifiers & controlKey && keyval >= 0 && keyval < 0x20 ) | |
1899 | { | |
1900 | keyval += 0x40 ; | |
1901 | } | |
1902 | if ( focus ) | |
1903 | { | |
1904 | wxKeyEvent event(wxEVT_KEY_UP); | |
1905 | event.m_shiftDown = modifiers & shiftKey; | |
1906 | event.m_controlDown = modifiers & controlKey; | |
1907 | event.m_altDown = modifiers & optionKey; | |
1908 | event.m_metaDown = modifiers & cmdKey; | |
1909 | event.m_keyCode = keyval; | |
1910 | ||
1911 | event.m_x = wherex; | |
1912 | event.m_y = wherey; | |
1913 | event.m_timeStamp = when; | |
1914 | event.SetEventObject(focus); | |
1915 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1916 | } | |
1917 | return handled ; | |
1918 | } | |
76a5e5d2 | 1919 | void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) |
169935ad | 1920 | { |
76a5e5d2 | 1921 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1922 | WindowRef window = (WindowRef) ev->message ; |
1923 | if ( window ) | |
1924 | { | |
1925 | bool activate = (ev->modifiers & activeFlag ) ; | |
1926 | WindowClass wclass ; | |
72055702 | 1927 | ::GetWindowClass ( window , &wclass ) ; |
8461e4c2 VZ |
1928 | if ( wclass == kFloatingWindowClass ) |
1929 | { | |
1930 | // if it is a floater we activate/deactivate the front non-floating window instead | |
72055702 | 1931 | window = ::FrontNonFloatingWindow() ; |
8461e4c2 | 1932 | } |
a3722eeb | 1933 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1934 | if ( win ) |
1935 | win->MacActivate( ev , activate ) ; | |
1936 | } | |
169935ad SC |
1937 | } |
1938 | ||
76a5e5d2 | 1939 | void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) |
169935ad | 1940 | { |
76a5e5d2 | 1941 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 | 1942 | WindowRef window = (WindowRef) ev->message ; |
a3722eeb | 1943 | wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1944 | if ( win ) |
1945 | { | |
0a67a93b | 1946 | if ( !wxPendingDelete.Member(win) ) |
a3722eeb | 1947 | win->MacUpdate( ev->when ) ; |
8461e4c2 VZ |
1948 | } |
1949 | else | |
1950 | { | |
1951 | // since there is no way of telling this foreign window to update itself | |
1952 | // we have to invalidate the update region otherwise we keep getting the same | |
1953 | // event over and over again | |
1954 | BeginUpdate( window ) ; | |
1955 | EndUpdate( window ) ; | |
1956 | } | |
169935ad SC |
1957 | } |
1958 | ||
76a5e5d2 | 1959 | void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) |
169935ad | 1960 | { |
76a5e5d2 | 1961 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 | 1962 | if ( HiWord( ev->message ) != noErr ) |
519cb848 | 1963 | { |
2f1ae414 | 1964 | #if !TARGET_CARBON |
8461e4c2 VZ |
1965 | OSErr err ; |
1966 | Point point ; | |
1967 | SetPt( &point , 100 , 100 ) ; | |
9779893b | 1968 | |
8461e4c2 VZ |
1969 | err = DIBadMount( point , ev->message ) ; |
1970 | wxASSERT( err == noErr ) ; | |
2f1ae414 | 1971 | #endif |
8461e4c2 | 1972 | } |
169935ad SC |
1973 | } |
1974 | ||
76a5e5d2 | 1975 | void wxApp::MacHandleOSEvent( WXEVENTREF evr ) |
169935ad | 1976 | { |
76a5e5d2 | 1977 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1978 | switch( ( ev->message & osEvtMessageMask ) >> 24 ) |
1979 | { | |
1980 | case suspendResumeMessage : | |
1981 | { | |
1982 | bool isResuming = ev->message & resumeFlag ; | |
5fde6fcc | 1983 | #if !TARGET_CARBON |
8461e4c2 | 1984 | bool convertClipboard = ev->message & convertClipboardFlag ; |
5fde6fcc | 1985 | #else |
8461e4c2 | 1986 | bool convertClipboard = false; |
5fde6fcc | 1987 | #endif |
8461e4c2 VZ |
1988 | bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; |
1989 | if ( isResuming ) | |
1990 | { | |
1991 | WindowRef oldFrontWindow = NULL ; | |
1992 | WindowRef newFrontWindow = NULL ; | |
1993 | ||
1994 | // in case we don't take care of activating ourselves, we have to synchronize | |
1995 | // our idea of the active window with the process manager's - which it already activated | |
1996 | ||
1997 | if ( !doesActivate ) | |
72055702 | 1998 | oldFrontWindow = ::FrontNonFloatingWindow() ; |
8461e4c2 VZ |
1999 | |
2000 | MacResume( convertClipboard ) ; | |
2001 | ||
72055702 | 2002 | newFrontWindow = ::FrontNonFloatingWindow() ; |
8461e4c2 VZ |
2003 | |
2004 | if ( oldFrontWindow ) | |
2005 | { | |
a3722eeb | 2006 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; |
8461e4c2 VZ |
2007 | if ( win ) |
2008 | win->MacActivate( ev , false ) ; | |
2009 | } | |
2010 | if ( newFrontWindow ) | |
2011 | { | |
a3722eeb | 2012 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; |
8461e4c2 VZ |
2013 | if ( win ) |
2014 | win->MacActivate( ev , true ) ; | |
2015 | } | |
2016 | } | |
2017 | else | |
2018 | { | |
2019 | MacSuspend( convertClipboard ) ; | |
2020 | ||
2021 | // in case this suspending did close an active window, another one might | |
2022 | // have surfaced -> lets deactivate that one | |
2023 | ||
72055702 SC |
2024 | /* TODO : find out what to do on systems < 10 , perhaps FrontNonFloatingWindow |
2025 | WindowRef newActiveWindow = ::ActiveNonFloatingWindow() ; | |
8461e4c2 VZ |
2026 | if ( newActiveWindow ) |
2027 | { | |
2028 | wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ; | |
2029 | if ( win ) | |
2030 | win->MacActivate( ev , false ) ; | |
2031 | } | |
72055702 | 2032 | */ |
8461e4c2 VZ |
2033 | } |
2034 | } | |
2035 | break ; | |
2036 | case mouseMovedMessage : | |
2037 | { | |
2038 | WindowRef window; | |
2039 | ||
2040 | wxWindow* currentMouseWindow = NULL ; | |
2041 | ||
2042 | wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , | |
2043 | ¤tMouseWindow ) ; | |
8461e4c2 VZ |
2044 | if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) |
2045 | { | |
2046 | wxMouseEvent event ; | |
2047 | ||
2048 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
2049 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
2050 | ||
2051 | event.m_leftDown = isDown && !controlDown; | |
2052 | event.m_middleDown = FALSE; | |
2053 | event.m_rightDown = isDown && controlDown; | |
2054 | event.m_shiftDown = ev->modifiers & shiftKey; | |
2055 | event.m_controlDown = ev->modifiers & controlKey; | |
2056 | event.m_altDown = ev->modifiers & optionKey; | |
2057 | event.m_metaDown = ev->modifiers & cmdKey; | |
2058 | event.m_x = ev->where.h; | |
2059 | event.m_y = ev->where.v; | |
2060 | event.m_timeStamp = ev->when; | |
2061 | event.SetEventObject(this); | |
ed60b502 | 2062 | |
8461e4c2 VZ |
2063 | if ( wxWindow::s_lastMouseWindow ) |
2064 | { | |
ed60b502 RR |
2065 | wxMouseEvent eventleave(event); |
2066 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
2067 | wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
d1bdc41d | 2068 | eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ; |
ed60b502 | 2069 | |
8461e4c2 VZ |
2070 | wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); |
2071 | } | |
2072 | if ( currentMouseWindow ) | |
2073 | { | |
ed60b502 RR |
2074 | wxMouseEvent evententer(event); |
2075 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
2076 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
d1bdc41d | 2077 | evententer.SetEventObject( currentMouseWindow ) ; |
8461e4c2 VZ |
2078 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); |
2079 | } | |
2080 | wxWindow::s_lastMouseWindow = currentMouseWindow ; | |
2081 | } | |
2082 | ||
2083 | short windowPart = ::FindWindow(ev->where, &window); | |
2084 | ||
2085 | switch (windowPart) | |
2086 | { | |
2087 | // fixes for setting the cursor back from dominic mazzoni | |
2088 | case inMenuBar : | |
2089 | UMAShowArrowCursor(); | |
2090 | break ; | |
2091 | case inSysWindow : | |
2092 | UMAShowArrowCursor(); | |
2093 | break ; | |
2094 | default: | |
2095 | { | |
6264b550 RR |
2096 | // if ( s_lastMouseDown == 0 ) |
2097 | // ev->modifiers |= btnState ; | |
2098 | ||
2099 | // Calling GetNextEvent with a zero event mask will always | |
2100 | // pass back a null event. However, it fills the EventRecord | |
2101 | // with the state of the modifier keys. This is needed since | |
2102 | // the modifier state returned by WaitForNextEvent often is | |
2103 | // wrong mouse move events. The attempt above to correct this | |
2104 | // didn't always work (under OS X at least). | |
2105 | ||
2106 | EventRecord tmp; | |
2107 | ::GetNextEvent(0, &tmp); | |
2108 | ev->modifiers = tmp.modifiers; | |
2109 | ||
a3722eeb | 2110 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
2111 | if ( win ) |
2112 | win->MacMouseMoved( ev , windowPart ) ; | |
2113 | else | |
2114 | UMAShowArrowCursor(); | |
2115 | ||
2116 | } | |
2117 | break; | |
2118 | } | |
2119 | } | |
2120 | break ; | |
2121 | ||
2122 | } | |
169935ad SC |
2123 | } |
2124 | ||
519cb848 | 2125 | void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) |
169935ad | 2126 | { |
8461e4c2 VZ |
2127 | if (macMenuId == 0) |
2128 | return; // no menu item selected | |
2129 | ||
2130 | if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1) | |
2131 | { | |
2132 | #if ! TARGET_CARBON | |
2133 | Str255 deskAccessoryName ; | |
2134 | GrafPtr savedPort ; | |
2135 | ||
2136 | GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName); | |
2137 | GetPort(&savedPort); | |
2138 | OpenDeskAcc(deskAccessoryName); | |
2139 | SetPort(savedPort); | |
2140 | #endif | |
2141 | } | |
2142 | else | |
2143 | { | |
2144 | wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ; | |
2145 | if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() ) | |
2146 | wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ; | |
2147 | } | |
2148 | HiliteMenu(0); | |
169935ad SC |
2149 | } |
2150 | ||
519cb848 SC |
2151 | /* |
2152 | long wxApp::MacTranslateKey(char key, int mods) | |
169935ad | 2153 | { |
169935ad SC |
2154 | } |
2155 | ||
519cb848 | 2156 | void wxApp::MacAdjustCursor() |
169935ad | 2157 | { |
169935ad SC |
2158 | } |
2159 | ||
519cb848 SC |
2160 | */ |
2161 | /* | |
169935ad SC |
2162 | void |
2163 | wxApp::macAdjustCursor() | |
2164 | { | |
519cb848 | 2165 | if (ev->what != kHighLevelEvent) |
169935ad | 2166 | { |
8461e4c2 VZ |
2167 | wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow()); |
2168 | if (theMacWxFrame) | |
2169 | { | |
2170 | if (!theMacWxFrame->MacAdjustCursor(ev->where)) | |
2171 | ::SetCursor(&(qd.arrow)); | |
2172 | } | |
169935ad SC |
2173 | } |
2174 | } | |
9779893b | 2175 | */ |