]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: app.cpp | |
3 | // Purpose: wxApp | |
d88de032 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
d88de032 | 6 | // Created: 10/13/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
d88de032 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
272ebf16 SN |
12 | #ifdef __GNUG__ |
13 | #pragma implementation "app.h" | |
14 | #endif | |
15 | ||
d88de032 DW |
16 | // For compilers that support precompilation, includes "wx.h". |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/frame.h" | |
21 | #include "wx/app.h" | |
22 | #include "wx/utils.h" | |
23 | #include "wx/gdicmn.h" | |
24 | #include "wx/pen.h" | |
25 | #include "wx/brush.h" | |
26 | #include "wx/cursor.h" | |
27 | #include "wx/icon.h" | |
28 | #include "wx/palette.h" | |
29 | #include "wx/dc.h" | |
30 | #include "wx/dialog.h" | |
31 | #include "wx/msgdlg.h" | |
32 | #include "wx/intl.h" | |
33 | #include "wx/dynarray.h" | |
cb21bd1b SN |
34 | #include "wx/wxchar.h" |
35 | #include "wx/icon.h" | |
175bb578 SN |
36 | #include "wx/stdpaths.h" |
37 | #include "wx/filename.h" | |
0e320a79 DW |
38 | #endif |
39 | ||
0e320a79 DW |
40 | #include "wx/log.h" |
41 | #include "wx/module.h" | |
d88de032 DW |
42 | |
43 | #include "wx/os2/private.h" | |
44 | ||
29d83fc1 DW |
45 | #ifdef __EMX__ |
46 | ||
19193a2c KB |
47 | #include <sys/ioctl.h> |
48 | #include <sys/select.h> | |
29d83fc1 DW |
49 | |
50 | #else | |
51 | ||
65b851bb | 52 | #include <nerrno.h> |
19193a2c KB |
53 | #include <sys/ioctl.h> |
54 | #include <sys/select.h> | |
55 | #include <sys/time.h> | |
29d83fc1 | 56 | |
19193a2c | 57 | #endif // |
29d83fc1 | 58 | |
3958ae62 | 59 | #ifndef __EMX__ |
29d83fc1 | 60 | |
3958ae62 | 61 | #define select(a,b,c,d,e) bsdselect(a,b,c,d,e) |
19193a2c KB |
62 | extern "C" int _System bsdselect(int, |
63 | struct fd_set *, | |
64 | struct fd_set *, | |
65 | struct fd_set *, | |
66 | struct timeval *); | |
3958ae62 SN |
67 | #endif |
68 | ||
d88de032 DW |
69 | #if wxUSE_THREADS |
70 | #include "wx/thread.h" | |
d88de032 | 71 | #endif // wxUSE_THREADS |
0e320a79 | 72 | |
8df85a61 DW |
73 | #if wxUSE_TOOLTIPS |
74 | #include "wx/tooltip.h" | |
75 | #endif // wxUSE_TOOLTIPS | |
76 | ||
0e320a79 | 77 | #include <string.h> |
d88de032 DW |
78 | #include <ctype.h> |
79 | ||
80 | // --------------------------------------------------------------------------- | |
81 | // global variables | |
82 | // --------------------------------------------------------------------------- | |
83 | ||
9ed0fac8 | 84 | extern wxChar* wxBuffer; |
9ed0fac8 DW |
85 | extern wxList* wxWinHandleList; |
86 | extern wxList WXDLLEXPORT wxPendingDelete; | |
9ed0fac8 | 87 | extern wxCursor* g_globalCursor; |
0e320a79 | 88 | |
8df85a61 | 89 | HAB vHabmain = NULLHANDLE; |
d88de032 | 90 | |
d88de032 | 91 | |
9ed0fac8 DW |
92 | HICON wxSTD_FRAME_ICON = (HICON) NULL; |
93 | HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL; | |
d88de032 DW |
94 | HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL; |
95 | ||
9ed0fac8 DW |
96 | HICON wxDEFAULT_FRAME_ICON = (HICON) NULL; |
97 | HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL; | |
98 | HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL; | |
d88de032 DW |
99 | |
100 | HBRUSH wxDisableButtonBrush = (HBRUSH) 0; | |
101 | ||
51c1d535 DW |
102 | MRESULT EXPENTRY wxWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2); |
103 | MRESULT EXPENTRY wxFrameWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2); | |
104 | ||
d88de032 DW |
105 | // =========================================================================== |
106 | // implementation | |
107 | // =========================================================================== | |
108 | ||
3958ae62 SN |
109 | // --------------------------------------------------------------------------- |
110 | // helper struct and functions for socket handling | |
111 | // --------------------------------------------------------------------------- | |
112 | ||
113 | struct GsocketCallbackInfo{ | |
114 | void (*proc)(void *); | |
115 | int type; | |
116 | int handle; | |
117 | void* gsock; | |
118 | }; | |
119 | ||
621b4574 | 120 | // These defines are used here and in gsockpm.cpp |
3958ae62 SN |
121 | #define wxSockReadMask 0x01 |
122 | #define wxSockWriteMask 0x02 | |
123 | ||
3958ae62 SN |
124 | void wxApp::HandleSockets() |
125 | { | |
29d83fc1 | 126 | bool pendingEvent = FALSE; |
3958ae62 SN |
127 | |
128 | // Check whether it's time for Gsocket operation | |
129 | if (m_maxSocketHandles > 0 && m_maxSocketNr > 0) | |
130 | { | |
131 | fd_set readfds = m_readfds; | |
132 | fd_set writefds = m_writefds; | |
133 | struct timeval timeout; | |
134 | int i; | |
135 | struct GsocketCallbackInfo | |
136 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
3958ae62 SN |
137 | timeout.tv_sec = 0; |
138 | timeout.tv_usec = 0; | |
139 | if ( select(m_maxSocketNr, &readfds, &writefds, 0, &timeout) > 0) | |
140 | { | |
5c9ee6dd SN |
141 | for (i = m_lastUsedHandle + 1; i != m_lastUsedHandle; |
142 | (i < m_maxSocketNr - 1) ? i++ : (i = 0)) | |
3958ae62 | 143 | { |
3958ae62 SN |
144 | if (FD_ISSET(i, &readfds)) |
145 | { | |
146 | int r; | |
147 | for (r = 0; r < m_maxSocketHandles; r++){ | |
148 | if(CallbackInfo[r].handle == i && | |
149 | CallbackInfo[r].type == wxSockReadMask) | |
150 | break; | |
151 | } | |
152 | if (r < m_maxSocketHandles) | |
153 | { | |
154 | CallbackInfo[r].proc(CallbackInfo[r].gsock); | |
29d83fc1 | 155 | pendingEvent = TRUE; |
3958ae62 SN |
156 | } |
157 | } | |
158 | if (FD_ISSET(i, &writefds)) | |
159 | { | |
160 | int r; | |
161 | for (r = 0; r < m_maxSocketHandles; r++) | |
162 | if(CallbackInfo[r].handle == i && | |
163 | CallbackInfo[r].type == wxSockWriteMask) | |
164 | break; | |
165 | if (r < m_maxSocketHandles) | |
166 | { | |
167 | CallbackInfo[r].proc(CallbackInfo[r].gsock); | |
29d83fc1 | 168 | pendingEvent = TRUE; |
3958ae62 SN |
169 | } |
170 | } | |
171 | } | |
172 | m_lastUsedHandle = i; | |
173 | } | |
174 | if (pendingEvent) | |
5c9ee6dd | 175 | ProcessPendingEvents(); |
3958ae62 SN |
176 | } |
177 | } | |
d88de032 DW |
178 | // --------------------------------------------------------------------------- |
179 | // wxApp | |
180 | // --------------------------------------------------------------------------- | |
181 | ||
d88de032 | 182 | IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler) |
0e320a79 | 183 | |
d88de032 DW |
184 | BEGIN_EVENT_TABLE(wxApp, wxEvtHandler) |
185 | EVT_IDLE(wxApp::OnIdle) | |
186 | EVT_END_SESSION(wxApp::OnEndSession) | |
187 | EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession) | |
188 | END_EVENT_TABLE() | |
0e320a79 | 189 | |
8df85a61 DW |
190 | // |
191 | // Initialize | |
192 | // | |
05e2b077 | 193 | bool wxApp::Initialize(int& argc, wxChar **argv) |
0e320a79 | 194 | { |
94826170 VZ |
195 | if ( !wxAppBase::Initialize(argc, argv) ) |
196 | return false; | |
197 | ||
7e99520b DW |
198 | #if defined(wxUSE_CONSOLEDEBUG) |
199 | #if wxUSE_CONSOLEDEBUG | |
200 | /***********************************************/ | |
201 | /* Code for using stdout debug */ | |
202 | /* To use it you mast link app as "Window" - EK*/ | |
203 | /***********************************************/ | |
204 | { | |
205 | PPIB pib; | |
206 | PTIB tib; | |
207 | ||
208 | printf("In console\n"); | |
209 | ||
210 | DosGetInfoBlocks(&tib, &pib); | |
211 | /* Try morphing into a PM application. */ | |
212 | // if(pib->pib_ultype == 2) /* VIO */ | |
213 | pib->pib_ultype = 3; | |
214 | } | |
215 | /**********************************************/ | |
216 | /**********************************************/ | |
217 | #endif //wxUSE_CONSOLEDEBUG | |
218 | #endif | |
219 | ||
54ffa107 DW |
220 | // |
221 | // OS2 has to have an anchorblock | |
222 | // | |
94826170 | 223 | vHabmain = WinInitialize(0); |
175bb578 SN |
224 | wxFileName GetPrefix(argv[0]); |
225 | GetPrefix.MakeAbsolute(); | |
226 | wxStandardPaths::SetInstallPrefix(GetPrefix.GetPath()); | |
94826170 VZ |
227 | if (!vHabmain) |
228 | { | |
229 | // TODO: at least give some error message here... | |
230 | wxAppBase::CleanUp(); | |
54ffa107 | 231 | |
54ffa107 | 232 | return FALSE; |
94826170 VZ |
233 | } |
234 | ||
235 | wxBuffer = new wxChar[1500]; // FIXME; why? | |
54ffa107 DW |
236 | |
237 | // Some people may wish to use this, but | |
238 | // probably it shouldn't be here by default. | |
239 | #ifdef __WXDEBUG__ | |
240 | // wxRedirectIOToConsole(); | |
241 | #endif | |
242 | ||
d88de032 DW |
243 | wxWinHandleList = new wxList(wxKEY_INTEGER); |
244 | ||
245 | // This is to foil optimizations in Visual C++ that throw out dummy.obj. | |
246 | // PLEASE DO NOT ALTER THIS. | |
1b3d5e55 | 247 | #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__) |
d88de032 DW |
248 | extern char wxDummyChar; |
249 | if (wxDummyChar) wxDummyChar++; | |
250 | #endif | |
251 | ||
61243a51 | 252 | // wxSetKeyboardHook(TRUE); |
d88de032 | 253 | |
459073a9 | 254 | RegisterWindowClasses(vHabmain); |
94826170 | 255 | |
d88de032 | 256 | return TRUE; |
8df85a61 | 257 | } // end of wxApp::Initialize |
d88de032 | 258 | |
7e99520b | 259 | const char* CANTREGISTERCLASS = " Can't register Class "; |
d88de032 DW |
260 | // --------------------------------------------------------------------------- |
261 | // RegisterWindowClasses | |
262 | // --------------------------------------------------------------------------- | |
263 | ||
9ed0fac8 DW |
264 | bool wxApp::RegisterWindowClasses( |
265 | HAB vHab | |
266 | ) | |
d88de032 | 267 | { |
914589c2 DW |
268 | ERRORID vError = 0L; |
269 | wxString sError; | |
3b9e3455 | 270 | |
f23208ca DW |
271 | if (!::WinRegisterClass( vHab |
272 | ,wxFrameClassName | |
51c1d535 | 273 | ,wxFrameWndProc |
f9efbe3a | 274 | ,CS_SIZEREDRAW | CS_SYNCPAINT |
a0606634 | 275 | ,sizeof(ULONG) |
f23208ca | 276 | )) |
d88de032 | 277 | { |
914589c2 DW |
278 | vError = ::WinGetLastError(vHab); |
279 | sError = wxPMErrorToStr(vError); | |
9923c37d | 280 | wxLogLastError(sError.c_str()); |
d88de032 DW |
281 | return FALSE; |
282 | } | |
283 | ||
f23208ca DW |
284 | if (!::WinRegisterClass( vHab |
285 | ,wxFrameClassNameNoRedraw | |
51c1d535 | 286 | ,wxWndProc |
f23208ca | 287 | ,0 |
51c1d535 | 288 | ,sizeof(ULONG) |
f23208ca | 289 | )) |
d88de032 | 290 | { |
914589c2 DW |
291 | vError = ::WinGetLastError(vHab); |
292 | sError = wxPMErrorToStr(vError); | |
9923c37d | 293 | wxLogLastError(sError.c_str()); |
d88de032 DW |
294 | return FALSE; |
295 | } | |
296 | ||
f23208ca DW |
297 | if (!::WinRegisterClass( vHab |
298 | ,wxMDIFrameClassName | |
51c1d535 | 299 | ,wxWndProc |
f6bcfd97 | 300 | ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT |
51c1d535 | 301 | ,sizeof(ULONG) |
f23208ca | 302 | )) |
d88de032 | 303 | { |
914589c2 DW |
304 | vError = ::WinGetLastError(vHab); |
305 | sError = wxPMErrorToStr(vError); | |
9923c37d | 306 | wxLogLastError(sError.c_str()); |
d88de032 DW |
307 | return FALSE; |
308 | } | |
0e320a79 | 309 | |
f23208ca DW |
310 | if (!::WinRegisterClass( vHab |
311 | ,wxMDIFrameClassNameNoRedraw | |
51c1d535 | 312 | ,wxWndProc |
f23208ca | 313 | ,0 |
51c1d535 | 314 | ,sizeof(ULONG) |
f23208ca | 315 | )) |
d88de032 | 316 | { |
914589c2 DW |
317 | vError = ::WinGetLastError(vHab); |
318 | sError = wxPMErrorToStr(vError); | |
9923c37d | 319 | wxLogLastError(sError.c_str()); |
d88de032 DW |
320 | return FALSE; |
321 | } | |
322 | ||
f23208ca DW |
323 | if (!::WinRegisterClass( vHab |
324 | ,wxMDIChildFrameClassName | |
51c1d535 | 325 | ,wxWndProc |
f23208ca | 326 | ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST |
51c1d535 | 327 | ,sizeof(ULONG) |
f23208ca | 328 | )) |
d88de032 | 329 | { |
914589c2 DW |
330 | vError = ::WinGetLastError(vHab); |
331 | sError = wxPMErrorToStr(vError); | |
9923c37d | 332 | wxLogLastError(sError.c_str()); |
d88de032 DW |
333 | return FALSE; |
334 | } | |
335 | ||
f23208ca DW |
336 | if (!::WinRegisterClass( vHab |
337 | ,wxMDIChildFrameClassNameNoRedraw | |
51c1d535 | 338 | ,wxWndProc |
f23208ca | 339 | ,CS_HITTEST |
51c1d535 | 340 | ,sizeof(ULONG) |
f23208ca | 341 | )) |
d88de032 | 342 | { |
914589c2 DW |
343 | vError = ::WinGetLastError(vHab); |
344 | sError = wxPMErrorToStr(vError); | |
9923c37d | 345 | wxLogLastError(sError.c_str()); |
d88de032 DW |
346 | return FALSE; |
347 | } | |
348 | ||
f23208ca DW |
349 | if (!::WinRegisterClass( vHab |
350 | ,wxPanelClassName | |
51c1d535 | 351 | ,wxWndProc |
f23208ca | 352 | ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT |
51c1d535 | 353 | ,sizeof(ULONG) |
f23208ca | 354 | )) |
d88de032 | 355 | { |
914589c2 DW |
356 | vError = ::WinGetLastError(vHab); |
357 | sError = wxPMErrorToStr(vError); | |
9923c37d | 358 | wxLogLastError(sError.c_str()); |
d88de032 DW |
359 | return FALSE; |
360 | } | |
361 | ||
f23208ca DW |
362 | if (!::WinRegisterClass( vHab |
363 | ,wxCanvasClassName | |
51c1d535 | 364 | ,wxWndProc |
54ffa107 | 365 | ,CS_SIZEREDRAW | CS_HITTEST | CS_SYNCPAINT |
51c1d535 | 366 | ,sizeof(ULONG) |
f23208ca | 367 | )) |
d88de032 | 368 | { |
914589c2 DW |
369 | vError = ::WinGetLastError(vHab); |
370 | sError = wxPMErrorToStr(vError); | |
9923c37d | 371 | wxLogLastError(sError.c_str()); |
d88de032 DW |
372 | return FALSE; |
373 | } | |
0256cfeb DW |
374 | if (!::WinRegisterClass( vHab |
375 | ,wxCanvasClassNameNR | |
376 | ,wxWndProc | |
377 | ,CS_HITTEST | CS_SYNCPAINT | |
378 | ,sizeof(ULONG) | |
379 | )) | |
380 | { | |
381 | vError = ::WinGetLastError(vHab); | |
382 | sError = wxPMErrorToStr(vError); | |
9923c37d | 383 | wxLogLastError(sError.c_str()); |
0256cfeb DW |
384 | return FALSE; |
385 | } | |
d88de032 | 386 | return TRUE; |
8df85a61 | 387 | } // end of wxApp::RegisterWindowClasses |
d88de032 | 388 | |
8df85a61 | 389 | // |
77ffb593 | 390 | // Cleans up any wxWidgets internal structures left lying around |
8df85a61 | 391 | // |
0e320a79 DW |
392 | void wxApp::CleanUp() |
393 | { | |
d88de032 DW |
394 | delete[] wxBuffer; |
395 | wxBuffer = NULL; | |
0e320a79 | 396 | |
8df85a61 DW |
397 | // |
398 | // PM-SPECIFIC CLEANUP | |
399 | // | |
0e320a79 | 400 | |
61243a51 | 401 | // wxSetKeyboardHook(FALSE); |
9ed0fac8 | 402 | |
d88de032 | 403 | if (wxSTD_FRAME_ICON) |
9ed0fac8 | 404 | ::WinFreeFileIcon(wxSTD_FRAME_ICON); |
d88de032 | 405 | if (wxSTD_MDICHILDFRAME_ICON) |
9ed0fac8 | 406 | ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON); |
d88de032 | 407 | if (wxSTD_MDIPARENTFRAME_ICON) |
9ed0fac8 | 408 | ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON); |
d88de032 DW |
409 | |
410 | if (wxDEFAULT_FRAME_ICON) | |
9ed0fac8 | 411 | ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON); |
d88de032 | 412 | if (wxDEFAULT_MDICHILDFRAME_ICON) |
9ed0fac8 | 413 | ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON); |
d88de032 | 414 | if (wxDEFAULT_MDIPARENTFRAME_ICON) |
9ed0fac8 DW |
415 | ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON); |
416 | ||
d88de032 DW |
417 | if ( wxDisableButtonBrush ) |
418 | { | |
419 | // TODO: ::DeleteObject( wxDisableButtonBrush ); | |
420 | } | |
421 | ||
422 | if (wxWinHandleList) | |
423 | delete wxWinHandleList; | |
424 | ||
468e327a SN |
425 | // Delete Message queue |
426 | if (wxTheApp->m_hMq) | |
427 | ::WinDestroyMsgQueue(wxTheApp->m_hMq); | |
428 | ||
94826170 | 429 | wxAppBase::CleanUp(); |
8df85a61 | 430 | } // end of wxApp::CleanUp |
0e320a79 | 431 | |
9ed0fac8 | 432 | bool wxApp::OnInitGui() |
d88de032 | 433 | { |
914589c2 DW |
434 | ERRORID vError; |
435 | wxString sError; | |
77cd51c3 | 436 | |
19193a2c KB |
437 | if (!wxAppBase::OnInitGui()) |
438 | return FALSE; | |
439 | ||
f23208ca | 440 | m_hMq = ::WinCreateMsgQueue(vHabmain, 0); |
914589c2 DW |
441 | if (!m_hMq) |
442 | { | |
443 | vError = ::WinGetLastError(vHabmain); | |
444 | sError = wxPMErrorToStr(vError); | |
445 | wxLogDebug(sError); | |
446 | return FALSE; | |
447 | } | |
19193a2c | 448 | |
9ed0fac8 | 449 | return TRUE; |
8df85a61 | 450 | } // end of wxApp::OnInitGui |
0e320a79 | 451 | |
0e320a79 DW |
452 | wxApp::wxApp() |
453 | { | |
d88de032 DW |
454 | argc = 0; |
455 | argv = NULL; | |
9ed0fac8 | 456 | m_nPrintMode = wxPRINT_WINDOWS; |
468e327a | 457 | m_hMq = 0; |
3958ae62 SN |
458 | m_maxSocketHandles = 0; |
459 | m_maxSocketNr = 0; | |
460 | m_sockCallbackInfo = 0; | |
8df85a61 | 461 | } // end of wxApp::wxApp |
d88de032 DW |
462 | |
463 | wxApp::~wxApp() | |
464 | { | |
8df85a61 | 465 | // |
d88de032 | 466 | // Delete command-line args |
8df85a61 | 467 | // |
039bec17 | 468 | #if wxUSE_UNICODE |
8df85a61 DW |
469 | int i; |
470 | ||
d88de032 DW |
471 | for (i = 0; i < argc; i++) |
472 | { | |
473 | delete[] argv[i]; | |
474 | } | |
475 | delete[] argv; | |
039bec17 | 476 | #endif |
8df85a61 | 477 | } // end of wxApp::~wxApp |
0e320a79 | 478 | |
2b5f62a0 VZ |
479 | bool gbInOnIdle = FALSE; |
480 | ||
9ed0fac8 DW |
481 | void wxApp::OnIdle( |
482 | wxIdleEvent& rEvent | |
483 | ) | |
d88de032 | 484 | { |
d88de032 | 485 | |
9ed0fac8 | 486 | // |
d88de032 | 487 | // Avoid recursion (via ProcessEvent default case) |
9ed0fac8 | 488 | // |
2b5f62a0 | 489 | if (gbInOnIdle) |
d88de032 | 490 | return; |
0e320a79 | 491 | |
2b5f62a0 | 492 | gbInOnIdle = TRUE; |
955a9197 | 493 | |
459073a9 | 494 | wxAppBase::OnIdle(rEvent); |
0e320a79 | 495 | |
893758d5 DW |
496 | #if wxUSE_DC_CACHEING |
497 | // automated DC cache management: clear the cached DCs and bitmap | |
498 | // if it's likely that the app has finished with them, that is, we | |
499 | // get an idle event and we're not dragging anything. | |
19193a2c KB |
500 | if (!::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) && |
501 | !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) && | |
502 | !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2)) | |
893758d5 DW |
503 | wxDC::ClearCache(); |
504 | #endif // wxUSE_DC_CACHEING | |
505 | ||
2b5f62a0 | 506 | gbInOnIdle = FALSE; |
8df85a61 | 507 | } // end of wxApp::OnIdle |
9779893b | 508 | |
9ed0fac8 DW |
509 | void wxApp::OnEndSession( |
510 | wxCloseEvent& WXUNUSED(rEvent)) | |
0e320a79 | 511 | { |
d88de032 DW |
512 | if (GetTopWindow()) |
513 | GetTopWindow()->Close(TRUE); | |
8df85a61 | 514 | } // end of wxApp::OnEndSession |
0e320a79 | 515 | |
9ed0fac8 | 516 | // |
d88de032 DW |
517 | // Default behaviour: close the application with prompts. The |
518 | // user can veto the close, and therefore the end session. | |
9ed0fac8 DW |
519 | // |
520 | void wxApp::OnQueryEndSession( | |
521 | wxCloseEvent& rEvent | |
522 | ) | |
0e320a79 | 523 | { |
d88de032 DW |
524 | if (GetTopWindow()) |
525 | { | |
9ed0fac8 DW |
526 | if (!GetTopWindow()->Close(!rEvent.CanVeto())) |
527 | rEvent.Veto(TRUE); | |
d88de032 | 528 | } |
8df85a61 | 529 | } // end of wxApp::OnQueryEndSession |
0e320a79 | 530 | |
8df85a61 | 531 | // |
d88de032 | 532 | // Yield to incoming messages |
8df85a61 | 533 | // |
8461e4c2 | 534 | bool wxApp::Yield(bool onlyIfNeeded) |
0e320a79 | 535 | { |
8461e4c2 VZ |
536 | static bool s_inYield = FALSE; |
537 | ||
538 | if ( s_inYield ) | |
539 | { | |
540 | if ( !onlyIfNeeded ) | |
541 | { | |
542 | wxFAIL_MSG( _T("wxYield() called recursively") ); | |
543 | } | |
544 | ||
545 | return FALSE; | |
546 | } | |
547 | ||
9dea36ef | 548 | HAB vHab = 0; |
dde11e60 | 549 | QMSG vMsg; |
ee453a16 | 550 | |
8df85a61 DW |
551 | // |
552 | // Disable log flushing from here because a call to wxYield() shouldn't | |
553 | // normally result in message boxes popping up &c | |
554 | // | |
555 | wxLog::Suspend(); | |
556 | ||
8461e4c2 | 557 | s_inYield = TRUE; |
8b63ae37 | 558 | |
8df85a61 | 559 | // |
d88de032 DW |
560 | // We want to go back to the main message loop |
561 | // if we see a WM_QUIT. (?) | |
8df85a61 | 562 | // |
dde11e60 | 563 | while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT) |
d88de032 | 564 | { |
8df85a61 DW |
565 | #if wxUSE_THREADS |
566 | wxMutexGuiLeaveOrEnter(); | |
567 | #endif // wxUSE_THREADS | |
598dc9b7 | 568 | if (!wxTheApp->Dispatch()) |
d88de032 DW |
569 | break; |
570 | } | |
8df85a61 | 571 | // |
d88de032 | 572 | // If they are pending events, we must process them. |
8df85a61 DW |
573 | // |
574 | if (wxTheApp) | |
575 | wxTheApp->ProcessPendingEvents(); | |
576 | ||
5c9ee6dd | 577 | HandleSockets(); |
8df85a61 DW |
578 | // |
579 | // Let the logs be flashed again | |
580 | // | |
581 | wxLog::Resume(); | |
8461e4c2 | 582 | s_inYield = FALSE; |
d88de032 | 583 | return TRUE; |
8df85a61 | 584 | } // end of wxYield |
d88de032 | 585 | |
3958ae62 SN |
586 | int wxApp::AddSocketHandler(int handle, int mask, |
587 | void (*callback)(void*), void * gsock) | |
588 | { | |
589 | int find; | |
590 | struct GsocketCallbackInfo | |
591 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
592 | ||
593 | for (find = 0; find < m_maxSocketHandles; find++) | |
594 | if (CallbackInfo[find].handle == -1) | |
595 | break; | |
596 | if (find == m_maxSocketHandles) | |
597 | { | |
598 | // Allocate new memory | |
599 | m_sockCallbackInfo = realloc(m_sockCallbackInfo, | |
600 | (m_maxSocketHandles+=10)* | |
601 | sizeof(struct GsocketCallbackInfo)); | |
602 | CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
603 | for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++) | |
604 | CallbackInfo[find].handle = -1; | |
605 | find = m_maxSocketHandles - 10; | |
606 | } | |
607 | CallbackInfo[find].proc = callback; | |
608 | CallbackInfo[find].type = mask; | |
609 | CallbackInfo[find].handle = handle; | |
610 | CallbackInfo[find].gsock = gsock; | |
611 | if (mask & wxSockReadMask) | |
612 | FD_SET(handle, &m_readfds); | |
613 | if (mask & wxSockWriteMask) | |
614 | FD_SET(handle, &m_writefds); | |
615 | if (handle >= m_maxSocketNr) | |
616 | m_maxSocketNr = handle + 1; | |
617 | return find; | |
618 | } | |
619 | ||
620 | void wxApp::RemoveSocketHandler(int handle) | |
621 | { | |
622 | struct GsocketCallbackInfo | |
623 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
624 | if (handle < m_maxSocketHandles) | |
625 | { | |
626 | if (CallbackInfo[handle].type & wxSockReadMask) | |
627 | FD_CLR(CallbackInfo[handle].handle, &m_readfds); | |
628 | if (CallbackInfo[handle].type & wxSockWriteMask) | |
629 | FD_CLR(CallbackInfo[handle].handle, &m_writefds); | |
630 | CallbackInfo[handle].handle = -1; | |
631 | } | |
632 | } | |
633 | ||
8df85a61 DW |
634 | //----------------------------------------------------------------------------- |
635 | // wxWakeUpIdle | |
636 | //----------------------------------------------------------------------------- | |
637 | ||
e2478fde | 638 | void wxApp::WakeUpIdle() |
8df85a61 DW |
639 | { |
640 | // | |
641 | // Send the top window a dummy message so idle handler processing will | |
642 | // start up again. Doing it this way ensures that the idle handler | |
643 | // wakes up in the right thread (see also wxWakeUpMainThread() which does | |
644 | // the same for the main app thread only) | |
645 | // | |
646 | wxWindow* pTopWindow = wxTheApp->GetTopWindow(); | |
647 | ||
648 | if (pTopWindow) | |
649 | { | |
650 | if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0)) | |
651 | { | |
652 | // | |
653 | // Should never happen | |
654 | // | |
655 | wxLogLastError("PostMessage(WM_NULL)"); | |
656 | } | |
657 | } | |
658 | } // end of wxWakeUpIdle | |
d88de032 | 659 | |
76990f63 | 660 | HAB wxGetInstance() |
d88de032 | 661 | { |
76990f63 | 662 | return vHabmain; |
d88de032 DW |
663 | } |
664 | ||
76990f63 DW |
665 | void wxSetInstance( |
666 | HAB vHab | |
667 | ) | |
d88de032 | 668 | { |
76990f63 | 669 | vHabmain = vHab; |
0e320a79 DW |
670 | } |
671 |