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