]>
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 | ||
4f5a3250 SC |
1273 | short windowPart = inNoWindow ; |
1274 | if ( wxTheApp->s_captureWindow ) | |
1275 | { | |
1276 | window = (WindowRef) s_captureWindow->MacGetRootWindow() ; | |
1277 | windowPart = inContent ; | |
1278 | } | |
1279 | else | |
1280 | { | |
1281 | windowPart = ::FindWindow(ev->where, &window) ; | |
1282 | } | |
8461e4c2 VZ |
1283 | |
1284 | switch (windowPart) | |
1285 | { | |
1286 | case inMenuBar : | |
1287 | break ; | |
1288 | case inSysWindow : | |
1289 | break ; | |
1290 | default: | |
1291 | { | |
a3722eeb | 1292 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1293 | if ( win ) |
1294 | win->MacMouseUp( ev , windowPart ) ; | |
1295 | } | |
1296 | break; | |
1297 | } | |
169935ad SC |
1298 | } |
1299 | ||
72055702 | 1300 | long wxMacTranslateKey(unsigned char key, unsigned char code) ; |
7c551d95 | 1301 | long wxMacTranslateKey(unsigned char key, unsigned char code) |
9779893b | 1302 | { |
8461e4c2 | 1303 | long retval = key ; |
9779893b | 1304 | switch (key) |
519cb848 | 1305 | { |
8461e4c2 VZ |
1306 | case 0x01 : |
1307 | retval = WXK_HOME; | |
1308 | break; | |
1309 | case 0x03 : | |
1310 | retval = WXK_RETURN; | |
1311 | break; | |
1312 | case 0x04 : | |
1313 | retval = WXK_END; | |
1314 | break; | |
1315 | case 0x05 : | |
1316 | retval = WXK_HELP; | |
1317 | break; | |
1318 | case 0x08 : | |
1319 | retval = WXK_BACK; | |
1320 | break; | |
1321 | case 0x09 : | |
1322 | retval = WXK_TAB; | |
1323 | break; | |
1324 | case 0x0b : | |
1325 | retval = WXK_PAGEUP; | |
1326 | break; | |
1327 | case 0x0c : | |
1328 | retval = WXK_PAGEDOWN; | |
1329 | break; | |
1330 | case 0x0d : | |
1331 | retval = WXK_RETURN; | |
1332 | break; | |
1333 | case 0x10 : | |
1334 | { | |
1335 | switch( code ) | |
1336 | { | |
1337 | case 0x7a : | |
1338 | retval = WXK_F1 ; | |
1339 | break; | |
1340 | case 0x78 : | |
1341 | retval = WXK_F2 ; | |
1342 | break; | |
1343 | case 0x63 : | |
1344 | retval = WXK_F3 ; | |
1345 | break; | |
1346 | case 0x76 : | |
1347 | retval = WXK_F4 ; | |
1348 | break; | |
1349 | case 0x60 : | |
1350 | retval = WXK_F5 ; | |
1351 | break; | |
1352 | case 0x61 : | |
1353 | retval = WXK_F6 ; | |
1354 | break; | |
1355 | case 0x62: | |
1356 | retval = WXK_F7 ; | |
1357 | break; | |
1358 | case 0x64 : | |
1359 | retval = WXK_F8 ; | |
1360 | break; | |
1361 | case 0x65 : | |
1362 | retval = WXK_F9 ; | |
1363 | break; | |
1364 | case 0x6D : | |
1365 | retval = WXK_F10 ; | |
1366 | break; | |
1367 | case 0x67 : | |
1368 | retval = WXK_F11 ; | |
1369 | break; | |
1370 | case 0x6F : | |
1371 | retval = WXK_F12 ; | |
1372 | break; | |
1373 | case 0x69 : | |
1374 | retval = WXK_F13 ; | |
1375 | break; | |
1376 | case 0x6B : | |
1377 | retval = WXK_F14 ; | |
1378 | break; | |
1379 | case 0x71 : | |
1380 | retval = WXK_F15 ; | |
1381 | break; | |
1382 | } | |
1383 | } | |
1384 | break ; | |
1385 | case 0x1b : | |
1386 | retval = WXK_ESCAPE ; | |
1387 | break ; | |
1388 | case 0x1c : | |
1389 | retval = WXK_LEFT ; | |
1390 | break ; | |
1391 | case 0x1d : | |
1392 | retval = WXK_RIGHT ; | |
1393 | break ; | |
1394 | case 0x1e : | |
1395 | retval = WXK_UP ; | |
1396 | break ; | |
1397 | case 0x1f : | |
1398 | retval = WXK_DOWN ; | |
1399 | break ; | |
1400 | case 0x7F : | |
1401 | retval = WXK_DELETE ; | |
1402 | default: | |
1403 | break ; | |
1404 | } // end switch | |
1405 | ||
1406 | return retval; | |
169935ad SC |
1407 | } |
1408 | ||
76a5e5d2 | 1409 | void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) |
169935ad | 1410 | { |
76a5e5d2 | 1411 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1412 | wxToolTip::RemoveToolTips() ; |
1413 | ||
1414 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1415 | if ( HiWord( menuresult ) ) | |
1416 | { | |
1417 | if ( !s_macIsInModalLoop ) | |
1418 | MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ; | |
1419 | } | |
1420 | else | |
1421 | { | |
1422 | short keycode ; | |
1423 | short keychar ; | |
1424 | keychar = short(ev->message & charCodeMask); | |
1425 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
e562df9b SC |
1426 | long keyval = wxMacTranslateKey(keychar, keycode) ; |
1427 | bool handled = false ; | |
8461e4c2 VZ |
1428 | wxWindow* focus = wxWindow::FindFocus() ; |
1429 | if ( focus ) | |
1430 | { | |
8461e4c2 VZ |
1431 | |
1432 | wxKeyEvent event(wxEVT_KEY_DOWN); | |
1433 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1434 | event.m_controlDown = ev->modifiers & controlKey; | |
1435 | event.m_altDown = ev->modifiers & optionKey; | |
1436 | event.m_metaDown = ev->modifiers & cmdKey; | |
1437 | event.m_keyCode = keyval; | |
1438 | event.m_x = ev->where.h; | |
1439 | event.m_y = ev->where.v; | |
1440 | event.m_timeStamp = ev->when; | |
1441 | event.SetEventObject(focus); | |
e562df9b | 1442 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; |
8461e4c2 VZ |
1443 | if ( !handled ) |
1444 | { | |
1445 | #if wxUSE_ACCEL | |
1446 | if (!handled) | |
1447 | { | |
1448 | wxWindow *ancestor = focus; | |
1449 | /* | |
1450 | while (ancestor) | |
1451 | { | |
1452 | int command = ancestor->GetAcceleratorTable()->GetCommand( event ); | |
1453 | if (command != -1) | |
1454 | { | |
1455 | wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command ); | |
1456 | handled = ancestor->GetEventHandler()->ProcessEvent( command_event ); | |
1457 | break; | |
1458 | } | |
1459 | if (ancestor->m_isFrame) | |
1460 | break; | |
1461 | ancestor = ancestor->GetParent(); | |
1462 | } | |
1463 | */ | |
1464 | } | |
1465 | #endif // wxUSE_ACCEL | |
1466 | } | |
1467 | if (!handled) | |
1468 | { | |
1469 | wxKeyEvent event(wxEVT_CHAR); | |
1470 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1471 | event.m_controlDown = ev->modifiers & controlKey; | |
1472 | event.m_altDown = ev->modifiers & optionKey; | |
1473 | event.m_metaDown = ev->modifiers & cmdKey; | |
1474 | event.m_keyCode = keyval; | |
1475 | event.m_x = ev->where.h; | |
1476 | event.m_y = ev->where.v; | |
1477 | event.m_timeStamp = ev->when; | |
1478 | event.SetEventObject(focus); | |
1479 | handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1480 | } | |
1481 | if ( !handled && | |
1482 | (keyval == WXK_TAB) && | |
1483 | (!focus->HasFlag(wxTE_PROCESS_TAB)) && | |
1484 | (focus->GetParent()) && | |
1485 | (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) ) | |
1486 | { | |
1487 | wxNavigationKeyEvent new_event; | |
1488 | new_event.SetEventObject( focus ); | |
1489 | new_event.SetDirection( !event.ShiftDown() ); | |
1490 | /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */ | |
1491 | new_event.SetWindowChange( event.ControlDown() ); | |
1492 | new_event.SetCurrentFocus( focus ); | |
1493 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
1494 | } | |
e562df9b SC |
1495 | } |
1496 | if ( !handled ) | |
1497 | { | |
1498 | // if window is not having a focus still testing for default enter or cancel | |
1499 | // TODO add the UMA version for ActiveNonFloatingWindow | |
1500 | focus = wxFindWinFromMacWindow( FrontWindow() ) ; | |
1501 | if ( focus ) | |
1502 | { | |
1503 | if ( keyval == WXK_RETURN ) | |
1504 | { | |
1505 | wxButton *def = wxDynamicCast(focus->GetDefaultItem(), | |
1506 | wxButton); | |
1507 | if ( def && def->IsEnabled() ) | |
1508 | { | |
1509 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
1510 | event.SetEventObject(def); | |
1511 | def->Command(event); | |
1512 | return ; | |
1513 | } | |
1514 | } | |
8461e4c2 | 1515 | /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */ |
e562df9b | 1516 | else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) ) |
8461e4c2 | 1517 | { |
e562df9b SC |
1518 | wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); |
1519 | new_event.SetEventObject( focus ); | |
1520 | handled = focus->GetEventHandler()->ProcessEvent( new_event ); | |
8461e4c2 | 1521 | } |
e562df9b | 1522 | } |
8461e4c2 VZ |
1523 | } |
1524 | } | |
169935ad SC |
1525 | } |
1526 | ||
76a5e5d2 | 1527 | void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) |
169935ad | 1528 | { |
76a5e5d2 | 1529 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1530 | wxToolTip::RemoveToolTips() ; |
1531 | ||
1532 | UInt32 menuresult = UMAMenuEvent(ev) ; | |
1533 | if ( HiWord( menuresult ) ) | |
1534 | { | |
1535 | } | |
1536 | else | |
1537 | { | |
1538 | short keycode ; | |
1539 | short keychar ; | |
1540 | keychar = short(ev->message & charCodeMask); | |
1541 | keycode = short(ev->message & keyCodeMask) >> 8 ; | |
1542 | ||
1543 | wxWindow* focus = wxWindow::FindFocus() ; | |
1544 | if ( focus ) | |
1545 | { | |
1546 | long keyval = wxMacTranslateKey(keychar, keycode) ; | |
1547 | ||
1548 | wxKeyEvent event(wxEVT_KEY_UP); | |
1549 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1550 | event.m_controlDown = ev->modifiers & controlKey; | |
1551 | event.m_altDown = ev->modifiers & optionKey; | |
1552 | event.m_metaDown = ev->modifiers & cmdKey; | |
1553 | event.m_keyCode = keyval; | |
1554 | event.m_x = ev->where.h; | |
1555 | event.m_y = ev->where.v; | |
1556 | event.m_timeStamp = ev->when; | |
1557 | event.SetEventObject(focus); | |
1558 | bool handled = focus->GetEventHandler()->ProcessEvent( event ) ; | |
1559 | } | |
1560 | } | |
169935ad SC |
1561 | } |
1562 | ||
76a5e5d2 | 1563 | void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) |
169935ad | 1564 | { |
76a5e5d2 | 1565 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1566 | WindowRef window = (WindowRef) ev->message ; |
1567 | if ( window ) | |
1568 | { | |
1569 | bool activate = (ev->modifiers & activeFlag ) ; | |
1570 | WindowClass wclass ; | |
72055702 | 1571 | ::GetWindowClass ( window , &wclass ) ; |
8461e4c2 VZ |
1572 | if ( wclass == kFloatingWindowClass ) |
1573 | { | |
1574 | // if it is a floater we activate/deactivate the front non-floating window instead | |
72055702 | 1575 | window = ::FrontNonFloatingWindow() ; |
8461e4c2 | 1576 | } |
a3722eeb | 1577 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1578 | if ( win ) |
1579 | win->MacActivate( ev , activate ) ; | |
1580 | } | |
169935ad SC |
1581 | } |
1582 | ||
76a5e5d2 | 1583 | void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) |
169935ad | 1584 | { |
76a5e5d2 | 1585 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 | 1586 | WindowRef window = (WindowRef) ev->message ; |
a3722eeb | 1587 | wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1588 | if ( win ) |
1589 | { | |
0a67a93b | 1590 | if ( !wxPendingDelete.Member(win) ) |
a3722eeb | 1591 | win->MacUpdate( ev->when ) ; |
8461e4c2 VZ |
1592 | } |
1593 | else | |
1594 | { | |
1595 | // since there is no way of telling this foreign window to update itself | |
1596 | // we have to invalidate the update region otherwise we keep getting the same | |
1597 | // event over and over again | |
1598 | BeginUpdate( window ) ; | |
1599 | EndUpdate( window ) ; | |
1600 | } | |
169935ad SC |
1601 | } |
1602 | ||
76a5e5d2 | 1603 | void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) |
169935ad | 1604 | { |
76a5e5d2 | 1605 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 | 1606 | if ( HiWord( ev->message ) != noErr ) |
519cb848 | 1607 | { |
2f1ae414 | 1608 | #if !TARGET_CARBON |
8461e4c2 VZ |
1609 | OSErr err ; |
1610 | Point point ; | |
1611 | SetPt( &point , 100 , 100 ) ; | |
9779893b | 1612 | |
8461e4c2 VZ |
1613 | err = DIBadMount( point , ev->message ) ; |
1614 | wxASSERT( err == noErr ) ; | |
2f1ae414 | 1615 | #endif |
8461e4c2 | 1616 | } |
169935ad SC |
1617 | } |
1618 | ||
76a5e5d2 | 1619 | void wxApp::MacHandleOSEvent( WXEVENTREF evr ) |
169935ad | 1620 | { |
76a5e5d2 | 1621 | EventRecord* ev = (EventRecord*) evr ; |
8461e4c2 VZ |
1622 | switch( ( ev->message & osEvtMessageMask ) >> 24 ) |
1623 | { | |
1624 | case suspendResumeMessage : | |
1625 | { | |
1626 | bool isResuming = ev->message & resumeFlag ; | |
5fde6fcc | 1627 | #if !TARGET_CARBON |
8461e4c2 | 1628 | bool convertClipboard = ev->message & convertClipboardFlag ; |
5fde6fcc | 1629 | #else |
8461e4c2 | 1630 | bool convertClipboard = false; |
5fde6fcc | 1631 | #endif |
8461e4c2 VZ |
1632 | bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ; |
1633 | if ( isResuming ) | |
1634 | { | |
1635 | WindowRef oldFrontWindow = NULL ; | |
1636 | WindowRef newFrontWindow = NULL ; | |
1637 | ||
1638 | // in case we don't take care of activating ourselves, we have to synchronize | |
1639 | // our idea of the active window with the process manager's - which it already activated | |
1640 | ||
1641 | if ( !doesActivate ) | |
72055702 | 1642 | oldFrontWindow = ::FrontNonFloatingWindow() ; |
8461e4c2 VZ |
1643 | |
1644 | MacResume( convertClipboard ) ; | |
1645 | ||
72055702 | 1646 | newFrontWindow = ::FrontNonFloatingWindow() ; |
8461e4c2 VZ |
1647 | |
1648 | if ( oldFrontWindow ) | |
1649 | { | |
a3722eeb | 1650 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; |
8461e4c2 VZ |
1651 | if ( win ) |
1652 | win->MacActivate( ev , false ) ; | |
1653 | } | |
1654 | if ( newFrontWindow ) | |
1655 | { | |
a3722eeb | 1656 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; |
8461e4c2 VZ |
1657 | if ( win ) |
1658 | win->MacActivate( ev , true ) ; | |
1659 | } | |
1660 | } | |
1661 | else | |
1662 | { | |
1663 | MacSuspend( convertClipboard ) ; | |
1664 | ||
1665 | // in case this suspending did close an active window, another one might | |
1666 | // have surfaced -> lets deactivate that one | |
1667 | ||
72055702 SC |
1668 | /* TODO : find out what to do on systems < 10 , perhaps FrontNonFloatingWindow |
1669 | WindowRef newActiveWindow = ::ActiveNonFloatingWindow() ; | |
8461e4c2 VZ |
1670 | if ( newActiveWindow ) |
1671 | { | |
1672 | wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ; | |
1673 | if ( win ) | |
1674 | win->MacActivate( ev , false ) ; | |
1675 | } | |
72055702 | 1676 | */ |
8461e4c2 VZ |
1677 | } |
1678 | } | |
1679 | break ; | |
1680 | case mouseMovedMessage : | |
1681 | { | |
1682 | WindowRef window; | |
1683 | ||
1684 | wxWindow* currentMouseWindow = NULL ; | |
1685 | ||
1686 | wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , | |
1687 | ¤tMouseWindow ) ; | |
8461e4c2 VZ |
1688 | if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) |
1689 | { | |
1690 | wxMouseEvent event ; | |
1691 | ||
1692 | bool isDown = !(ev->modifiers & btnState) ; // 1 is for up | |
1693 | bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse | |
1694 | ||
1695 | event.m_leftDown = isDown && !controlDown; | |
1696 | event.m_middleDown = FALSE; | |
1697 | event.m_rightDown = isDown && controlDown; | |
1698 | event.m_shiftDown = ev->modifiers & shiftKey; | |
1699 | event.m_controlDown = ev->modifiers & controlKey; | |
1700 | event.m_altDown = ev->modifiers & optionKey; | |
1701 | event.m_metaDown = ev->modifiers & cmdKey; | |
1702 | event.m_x = ev->where.h; | |
1703 | event.m_y = ev->where.v; | |
1704 | event.m_timeStamp = ev->when; | |
1705 | event.SetEventObject(this); | |
ed60b502 | 1706 | |
8461e4c2 VZ |
1707 | if ( wxWindow::s_lastMouseWindow ) |
1708 | { | |
ed60b502 RR |
1709 | wxMouseEvent eventleave(event); |
1710 | eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); | |
1711 | wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); | |
1712 | ||
8461e4c2 VZ |
1713 | wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); |
1714 | } | |
1715 | if ( currentMouseWindow ) | |
1716 | { | |
ed60b502 RR |
1717 | wxMouseEvent evententer(event); |
1718 | evententer.SetEventType( wxEVT_ENTER_WINDOW ); | |
1719 | currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); | |
1720 | ||
8461e4c2 VZ |
1721 | currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); |
1722 | } | |
1723 | wxWindow::s_lastMouseWindow = currentMouseWindow ; | |
1724 | } | |
1725 | ||
1726 | short windowPart = ::FindWindow(ev->where, &window); | |
1727 | ||
1728 | switch (windowPart) | |
1729 | { | |
1730 | // fixes for setting the cursor back from dominic mazzoni | |
1731 | case inMenuBar : | |
1732 | UMAShowArrowCursor(); | |
1733 | break ; | |
1734 | case inSysWindow : | |
1735 | UMAShowArrowCursor(); | |
1736 | break ; | |
1737 | default: | |
1738 | { | |
6264b550 RR |
1739 | // if ( s_lastMouseDown == 0 ) |
1740 | // ev->modifiers |= btnState ; | |
1741 | ||
1742 | // Calling GetNextEvent with a zero event mask will always | |
1743 | // pass back a null event. However, it fills the EventRecord | |
1744 | // with the state of the modifier keys. This is needed since | |
1745 | // the modifier state returned by WaitForNextEvent often is | |
1746 | // wrong mouse move events. The attempt above to correct this | |
1747 | // didn't always work (under OS X at least). | |
1748 | ||
1749 | EventRecord tmp; | |
1750 | ::GetNextEvent(0, &tmp); | |
1751 | ev->modifiers = tmp.modifiers; | |
1752 | ||
a3722eeb | 1753 | wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; |
8461e4c2 VZ |
1754 | if ( win ) |
1755 | win->MacMouseMoved( ev , windowPart ) ; | |
1756 | else | |
1757 | UMAShowArrowCursor(); | |
1758 | ||
1759 | } | |
1760 | break; | |
1761 | } | |
1762 | } | |
1763 | break ; | |
1764 | ||
1765 | } | |
169935ad SC |
1766 | } |
1767 | ||
519cb848 | 1768 | void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum ) |
169935ad | 1769 | { |
8461e4c2 VZ |
1770 | if (macMenuId == 0) |
1771 | return; // no menu item selected | |
1772 | ||
1773 | if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1) | |
1774 | { | |
1775 | #if ! TARGET_CARBON | |
1776 | Str255 deskAccessoryName ; | |
1777 | GrafPtr savedPort ; | |
1778 | ||
1779 | GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName); | |
1780 | GetPort(&savedPort); | |
1781 | OpenDeskAcc(deskAccessoryName); | |
1782 | SetPort(savedPort); | |
1783 | #endif | |
1784 | } | |
1785 | else | |
1786 | { | |
1787 | wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ; | |
1788 | if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() ) | |
1789 | wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ; | |
1790 | } | |
1791 | HiliteMenu(0); | |
169935ad SC |
1792 | } |
1793 | ||
519cb848 SC |
1794 | /* |
1795 | long wxApp::MacTranslateKey(char key, int mods) | |
169935ad | 1796 | { |
169935ad SC |
1797 | } |
1798 | ||
519cb848 | 1799 | void wxApp::MacAdjustCursor() |
169935ad | 1800 | { |
169935ad SC |
1801 | } |
1802 | ||
519cb848 SC |
1803 | */ |
1804 | /* | |
169935ad SC |
1805 | void |
1806 | wxApp::macAdjustCursor() | |
1807 | { | |
519cb848 | 1808 | if (ev->what != kHighLevelEvent) |
169935ad | 1809 | { |
8461e4c2 VZ |
1810 | wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow()); |
1811 | if (theMacWxFrame) | |
1812 | { | |
1813 | if (!theMacWxFrame->MacAdjustCursor(ev->where)) | |
1814 | ::SetCursor(&(qd.arrow)); | |
1815 | } | |
169935ad SC |
1816 | } |
1817 | } | |
9779893b | 1818 | */ |