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