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