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