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