]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
ad9835c9 | 2 | // Name: src/os2/app.cpp |
0e320a79 | 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 | ||
d88de032 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
e4db172a WS |
15 | #include "wx/app.h" |
16 | ||
d88de032 | 17 | #ifndef WX_PRECOMP |
ad9835c9 | 18 | #include "wx/dynarray.h" |
d88de032 | 19 | #include "wx/frame.h" |
d88de032 DW |
20 | #include "wx/utils.h" |
21 | #include "wx/gdicmn.h" | |
22 | #include "wx/pen.h" | |
23 | #include "wx/brush.h" | |
24 | #include "wx/cursor.h" | |
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/intl.h" | |
cb21bd1b SN |
31 | #include "wx/wxchar.h" |
32 | #include "wx/icon.h" | |
175bb578 SN |
33 | #include "wx/stdpaths.h" |
34 | #include "wx/filename.h" | |
e4db172a | 35 | #include "wx/log.h" |
0e320a79 DW |
36 | #endif |
37 | ||
0e320a79 | 38 | #include "wx/module.h" |
d88de032 DW |
39 | |
40 | #include "wx/os2/private.h" | |
41 | ||
29d83fc1 DW |
42 | #ifdef __EMX__ |
43 | ||
19193a2c KB |
44 | #include <sys/ioctl.h> |
45 | #include <sys/select.h> | |
29d83fc1 DW |
46 | |
47 | #else | |
48 | ||
65b851bb | 49 | #include <nerrno.h> |
19193a2c KB |
50 | #include <sys/ioctl.h> |
51 | #include <sys/select.h> | |
52 | #include <sys/time.h> | |
29d83fc1 | 53 | |
19193a2c | 54 | #endif // |
29d83fc1 | 55 | |
6670f564 WS |
56 | #if defined(__WATCOMC__) |
57 | ||
58 | #include <tcpustd.h> | |
59 | ||
60 | #elif !defined(__EMX__) | |
29d83fc1 | 61 | |
3958ae62 | 62 | #define select(a,b,c,d,e) bsdselect(a,b,c,d,e) |
19193a2c KB |
63 | extern "C" int _System bsdselect(int, |
64 | struct fd_set *, | |
65 | struct fd_set *, | |
66 | struct fd_set *, | |
67 | struct timeval *); | |
3958ae62 SN |
68 | #endif |
69 | ||
d88de032 DW |
70 | #if wxUSE_THREADS |
71 | #include "wx/thread.h" | |
d88de032 | 72 | #endif // wxUSE_THREADS |
0e320a79 | 73 | |
8df85a61 DW |
74 | #if wxUSE_TOOLTIPS |
75 | #include "wx/tooltip.h" | |
76 | #endif // wxUSE_TOOLTIPS | |
77 | ||
0e320a79 | 78 | #include <string.h> |
d88de032 DW |
79 | #include <ctype.h> |
80 | ||
81 | // --------------------------------------------------------------------------- | |
82 | // global variables | |
83 | // --------------------------------------------------------------------------- | |
84 | ||
9ed0fac8 | 85 | extern wxChar* wxBuffer; |
9ed0fac8 | 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 | { | |
ad9835c9 | 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); | |
ad9835c9 | 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); | |
ad9835c9 | 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 | |
ad9835c9 | 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 | ||
2461cfa0 | 243 | wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100); |
d88de032 DW |
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 | |
ad9835c9 | 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 | ||
ad9835c9 | 264 | bool wxApp::RegisterWindowClasses( HAB vHab ) |
d88de032 | 265 | { |
ad9835c9 WS |
266 | ERRORID vError = 0L; |
267 | wxString sError; | |
3b9e3455 | 268 | |
f23208ca | 269 | if (!::WinRegisterClass( vHab |
0fba44b4 | 270 | ,(PSZ)wxFrameClassName |
51c1d535 | 271 | ,wxFrameWndProc |
f9efbe3a | 272 | ,CS_SIZEREDRAW | CS_SYNCPAINT |
a0606634 | 273 | ,sizeof(ULONG) |
f23208ca | 274 | )) |
d88de032 | 275 | { |
914589c2 DW |
276 | vError = ::WinGetLastError(vHab); |
277 | sError = wxPMErrorToStr(vError); | |
9923c37d | 278 | wxLogLastError(sError.c_str()); |
ad9835c9 | 279 | return false; |
d88de032 DW |
280 | } |
281 | ||
f23208ca | 282 | if (!::WinRegisterClass( vHab |
0fba44b4 | 283 | ,(PSZ)wxFrameClassNameNoRedraw |
51c1d535 | 284 | ,wxWndProc |
f23208ca | 285 | ,0 |
51c1d535 | 286 | ,sizeof(ULONG) |
f23208ca | 287 | )) |
d88de032 | 288 | { |
914589c2 DW |
289 | vError = ::WinGetLastError(vHab); |
290 | sError = wxPMErrorToStr(vError); | |
9923c37d | 291 | wxLogLastError(sError.c_str()); |
ad9835c9 | 292 | return false; |
d88de032 DW |
293 | } |
294 | ||
f23208ca | 295 | if (!::WinRegisterClass( vHab |
0fba44b4 | 296 | ,(PSZ)wxMDIFrameClassName |
51c1d535 | 297 | ,wxWndProc |
f6bcfd97 | 298 | ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT |
51c1d535 | 299 | ,sizeof(ULONG) |
f23208ca | 300 | )) |
d88de032 | 301 | { |
914589c2 DW |
302 | vError = ::WinGetLastError(vHab); |
303 | sError = wxPMErrorToStr(vError); | |
9923c37d | 304 | wxLogLastError(sError.c_str()); |
ad9835c9 | 305 | return false; |
d88de032 | 306 | } |
0e320a79 | 307 | |
f23208ca | 308 | if (!::WinRegisterClass( vHab |
0fba44b4 | 309 | ,(PSZ)wxMDIFrameClassNameNoRedraw |
51c1d535 | 310 | ,wxWndProc |
f23208ca | 311 | ,0 |
51c1d535 | 312 | ,sizeof(ULONG) |
f23208ca | 313 | )) |
d88de032 | 314 | { |
914589c2 DW |
315 | vError = ::WinGetLastError(vHab); |
316 | sError = wxPMErrorToStr(vError); | |
9923c37d | 317 | wxLogLastError(sError.c_str()); |
ad9835c9 | 318 | return false; |
d88de032 DW |
319 | } |
320 | ||
f23208ca | 321 | if (!::WinRegisterClass( vHab |
0fba44b4 | 322 | ,(PSZ)wxMDIChildFrameClassName |
51c1d535 | 323 | ,wxWndProc |
f23208ca | 324 | ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST |
51c1d535 | 325 | ,sizeof(ULONG) |
f23208ca | 326 | )) |
d88de032 | 327 | { |
914589c2 DW |
328 | vError = ::WinGetLastError(vHab); |
329 | sError = wxPMErrorToStr(vError); | |
9923c37d | 330 | wxLogLastError(sError.c_str()); |
ad9835c9 | 331 | return false; |
d88de032 DW |
332 | } |
333 | ||
f23208ca | 334 | if (!::WinRegisterClass( vHab |
0fba44b4 | 335 | ,(PSZ)wxMDIChildFrameClassNameNoRedraw |
51c1d535 | 336 | ,wxWndProc |
f23208ca | 337 | ,CS_HITTEST |
51c1d535 | 338 | ,sizeof(ULONG) |
f23208ca | 339 | )) |
d88de032 | 340 | { |
914589c2 DW |
341 | vError = ::WinGetLastError(vHab); |
342 | sError = wxPMErrorToStr(vError); | |
9923c37d | 343 | wxLogLastError(sError.c_str()); |
ad9835c9 | 344 | return false; |
d88de032 DW |
345 | } |
346 | ||
f23208ca | 347 | if (!::WinRegisterClass( vHab |
0fba44b4 | 348 | ,(PSZ)wxPanelClassName |
51c1d535 | 349 | ,wxWndProc |
f23208ca | 350 | ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT |
51c1d535 | 351 | ,sizeof(ULONG) |
f23208ca | 352 | )) |
d88de032 | 353 | { |
914589c2 DW |
354 | vError = ::WinGetLastError(vHab); |
355 | sError = wxPMErrorToStr(vError); | |
9923c37d | 356 | wxLogLastError(sError.c_str()); |
ad9835c9 | 357 | return false; |
d88de032 DW |
358 | } |
359 | ||
f23208ca | 360 | if (!::WinRegisterClass( vHab |
0fba44b4 | 361 | ,(PSZ)wxCanvasClassName |
51c1d535 | 362 | ,wxWndProc |
54ffa107 | 363 | ,CS_SIZEREDRAW | CS_HITTEST | CS_SYNCPAINT |
51c1d535 | 364 | ,sizeof(ULONG) |
f23208ca | 365 | )) |
d88de032 | 366 | { |
914589c2 DW |
367 | vError = ::WinGetLastError(vHab); |
368 | sError = wxPMErrorToStr(vError); | |
9923c37d | 369 | wxLogLastError(sError.c_str()); |
ad9835c9 | 370 | return false; |
d88de032 | 371 | } |
0256cfeb | 372 | if (!::WinRegisterClass( vHab |
0fba44b4 | 373 | ,(PSZ)wxCanvasClassNameNR |
0256cfeb DW |
374 | ,wxWndProc |
375 | ,CS_HITTEST | CS_SYNCPAINT | |
376 | ,sizeof(ULONG) | |
377 | )) | |
378 | { | |
379 | vError = ::WinGetLastError(vHab); | |
380 | sError = wxPMErrorToStr(vError); | |
9923c37d | 381 | wxLogLastError(sError.c_str()); |
ad9835c9 | 382 | return false; |
0256cfeb | 383 | } |
ad9835c9 | 384 | return true; |
8df85a61 | 385 | } // end of wxApp::RegisterWindowClasses |
d88de032 | 386 | |
8df85a61 | 387 | // |
77ffb593 | 388 | // Cleans up any wxWidgets internal structures left lying around |
8df85a61 | 389 | // |
0e320a79 DW |
390 | void wxApp::CleanUp() |
391 | { | |
d88de032 DW |
392 | delete[] wxBuffer; |
393 | wxBuffer = NULL; | |
0e320a79 | 394 | |
8df85a61 DW |
395 | // |
396 | // PM-SPECIFIC CLEANUP | |
397 | // | |
0e320a79 | 398 | |
ad9835c9 | 399 | // wxSetKeyboardHook(false); |
9ed0fac8 | 400 | |
d88de032 | 401 | if (wxSTD_FRAME_ICON) |
9ed0fac8 | 402 | ::WinFreeFileIcon(wxSTD_FRAME_ICON); |
d88de032 | 403 | if (wxSTD_MDICHILDFRAME_ICON) |
9ed0fac8 | 404 | ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON); |
d88de032 | 405 | if (wxSTD_MDIPARENTFRAME_ICON) |
9ed0fac8 | 406 | ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON); |
d88de032 DW |
407 | |
408 | if (wxDEFAULT_FRAME_ICON) | |
9ed0fac8 | 409 | ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON); |
d88de032 | 410 | if (wxDEFAULT_MDICHILDFRAME_ICON) |
9ed0fac8 | 411 | ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON); |
d88de032 | 412 | if (wxDEFAULT_MDIPARENTFRAME_ICON) |
9ed0fac8 DW |
413 | ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON); |
414 | ||
d88de032 DW |
415 | if ( wxDisableButtonBrush ) |
416 | { | |
417 | // TODO: ::DeleteObject( wxDisableButtonBrush ); | |
418 | } | |
419 | ||
2461cfa0 SN |
420 | delete wxWinHandleHash; |
421 | wxWinHandleHash = NULL; | |
d88de032 | 422 | |
468e327a SN |
423 | // Delete Message queue |
424 | if (wxTheApp->m_hMq) | |
425 | ::WinDestroyMsgQueue(wxTheApp->m_hMq); | |
426 | ||
94826170 | 427 | wxAppBase::CleanUp(); |
8df85a61 | 428 | } // end of wxApp::CleanUp |
0e320a79 | 429 | |
9ed0fac8 | 430 | bool wxApp::OnInitGui() |
d88de032 | 431 | { |
ad9835c9 WS |
432 | ERRORID vError; |
433 | wxString sError; | |
77cd51c3 | 434 | |
19193a2c | 435 | if (!wxAppBase::OnInitGui()) |
ad9835c9 | 436 | return false; |
19193a2c | 437 | |
f23208ca | 438 | m_hMq = ::WinCreateMsgQueue(vHabmain, 0); |
914589c2 DW |
439 | if (!m_hMq) |
440 | { | |
441 | vError = ::WinGetLastError(vHabmain); | |
442 | sError = wxPMErrorToStr(vError); | |
443 | wxLogDebug(sError); | |
ad9835c9 | 444 | return false; |
914589c2 | 445 | } |
19193a2c | 446 | |
ad9835c9 | 447 | return true; |
8df85a61 | 448 | } // end of wxApp::OnInitGui |
0e320a79 | 449 | |
0e320a79 DW |
450 | wxApp::wxApp() |
451 | { | |
d88de032 DW |
452 | argc = 0; |
453 | argv = NULL; | |
9ed0fac8 | 454 | m_nPrintMode = wxPRINT_WINDOWS; |
468e327a | 455 | m_hMq = 0; |
3958ae62 SN |
456 | m_maxSocketHandles = 0; |
457 | m_maxSocketNr = 0; | |
458 | m_sockCallbackInfo = 0; | |
8df85a61 | 459 | } // end of wxApp::wxApp |
d88de032 DW |
460 | |
461 | wxApp::~wxApp() | |
462 | { | |
8df85a61 | 463 | // |
d88de032 | 464 | // Delete command-line args |
8df85a61 | 465 | // |
039bec17 | 466 | #if wxUSE_UNICODE |
8df85a61 DW |
467 | int i; |
468 | ||
d88de032 DW |
469 | for (i = 0; i < argc; i++) |
470 | { | |
471 | delete[] argv[i]; | |
472 | } | |
473 | delete[] argv; | |
039bec17 | 474 | #endif |
8df85a61 | 475 | } // end of wxApp::~wxApp |
0e320a79 | 476 | |
ad9835c9 | 477 | bool gbInOnIdle = false; |
2b5f62a0 | 478 | |
ad9835c9 | 479 | void wxApp::OnIdle( wxIdleEvent& rEvent ) |
d88de032 | 480 | { |
9ed0fac8 | 481 | // |
d88de032 | 482 | // Avoid recursion (via ProcessEvent default case) |
9ed0fac8 | 483 | // |
2b5f62a0 | 484 | if (gbInOnIdle) |
d88de032 | 485 | return; |
0e320a79 | 486 | |
6670f564 WS |
487 | gbInOnIdle = true; |
488 | ||
459073a9 | 489 | wxAppBase::OnIdle(rEvent); |
0e320a79 | 490 | |
893758d5 DW |
491 | #if wxUSE_DC_CACHEING |
492 | // automated DC cache management: clear the cached DCs and bitmap | |
493 | // if it's likely that the app has finished with them, that is, we | |
494 | // get an idle event and we're not dragging anything. | |
19193a2c KB |
495 | if (!::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) && |
496 | !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) && | |
497 | !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2)) | |
893758d5 DW |
498 | wxDC::ClearCache(); |
499 | #endif // wxUSE_DC_CACHEING | |
500 | ||
ad9835c9 | 501 | gbInOnIdle = false; |
8df85a61 | 502 | } // end of wxApp::OnIdle |
9779893b | 503 | |
9ed0fac8 DW |
504 | void wxApp::OnEndSession( |
505 | wxCloseEvent& WXUNUSED(rEvent)) | |
0e320a79 | 506 | { |
d88de032 | 507 | if (GetTopWindow()) |
ad9835c9 | 508 | GetTopWindow()->Close(true); |
8df85a61 | 509 | } // end of wxApp::OnEndSession |
0e320a79 | 510 | |
9ed0fac8 | 511 | // |
d88de032 DW |
512 | // Default behaviour: close the application with prompts. The |
513 | // user can veto the close, and therefore the end session. | |
9ed0fac8 | 514 | // |
ad9835c9 | 515 | void wxApp::OnQueryEndSession( wxCloseEvent& rEvent ) |
0e320a79 | 516 | { |
d88de032 DW |
517 | if (GetTopWindow()) |
518 | { | |
9ed0fac8 | 519 | if (!GetTopWindow()->Close(!rEvent.CanVeto())) |
ad9835c9 | 520 | rEvent.Veto(true); |
d88de032 | 521 | } |
8df85a61 | 522 | } // end of wxApp::OnQueryEndSession |
0e320a79 | 523 | |
8df85a61 | 524 | // |
d88de032 | 525 | // Yield to incoming messages |
8df85a61 | 526 | // |
8461e4c2 | 527 | bool wxApp::Yield(bool onlyIfNeeded) |
0e320a79 | 528 | { |
ad9835c9 | 529 | static bool s_inYield = false; |
8461e4c2 VZ |
530 | |
531 | if ( s_inYield ) | |
532 | { | |
533 | if ( !onlyIfNeeded ) | |
534 | { | |
535 | wxFAIL_MSG( _T("wxYield() called recursively") ); | |
536 | } | |
537 | ||
ad9835c9 | 538 | return false; |
8461e4c2 VZ |
539 | } |
540 | ||
ad9835c9 WS |
541 | HAB vHab = 0; |
542 | QMSG vMsg; | |
ee453a16 | 543 | |
8df85a61 DW |
544 | // |
545 | // Disable log flushing from here because a call to wxYield() shouldn't | |
546 | // normally result in message boxes popping up &c | |
547 | // | |
548 | wxLog::Suspend(); | |
549 | ||
ad9835c9 | 550 | s_inYield = true; |
8b63ae37 | 551 | |
8df85a61 | 552 | // |
d88de032 DW |
553 | // We want to go back to the main message loop |
554 | // if we see a WM_QUIT. (?) | |
8df85a61 | 555 | // |
dde11e60 | 556 | while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT) |
d88de032 | 557 | { |
8df85a61 DW |
558 | #if wxUSE_THREADS |
559 | wxMutexGuiLeaveOrEnter(); | |
560 | #endif // wxUSE_THREADS | |
598dc9b7 | 561 | if (!wxTheApp->Dispatch()) |
d88de032 DW |
562 | break; |
563 | } | |
8df85a61 | 564 | // |
d88de032 | 565 | // If they are pending events, we must process them. |
8df85a61 DW |
566 | // |
567 | if (wxTheApp) | |
568 | wxTheApp->ProcessPendingEvents(); | |
569 | ||
5c9ee6dd | 570 | HandleSockets(); |
8df85a61 DW |
571 | // |
572 | // Let the logs be flashed again | |
573 | // | |
574 | wxLog::Resume(); | |
ad9835c9 WS |
575 | s_inYield = false; |
576 | return true; | |
8df85a61 | 577 | } // end of wxYield |
d88de032 | 578 | |
3958ae62 SN |
579 | int wxApp::AddSocketHandler(int handle, int mask, |
580 | void (*callback)(void*), void * gsock) | |
581 | { | |
582 | int find; | |
583 | struct GsocketCallbackInfo | |
584 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
585 | ||
586 | for (find = 0; find < m_maxSocketHandles; find++) | |
587 | if (CallbackInfo[find].handle == -1) | |
588 | break; | |
589 | if (find == m_maxSocketHandles) | |
590 | { | |
591 | // Allocate new memory | |
592 | m_sockCallbackInfo = realloc(m_sockCallbackInfo, | |
593 | (m_maxSocketHandles+=10)* | |
594 | sizeof(struct GsocketCallbackInfo)); | |
595 | CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
596 | for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++) | |
597 | CallbackInfo[find].handle = -1; | |
598 | find = m_maxSocketHandles - 10; | |
599 | } | |
600 | CallbackInfo[find].proc = callback; | |
601 | CallbackInfo[find].type = mask; | |
602 | CallbackInfo[find].handle = handle; | |
603 | CallbackInfo[find].gsock = gsock; | |
604 | if (mask & wxSockReadMask) | |
605 | FD_SET(handle, &m_readfds); | |
606 | if (mask & wxSockWriteMask) | |
607 | FD_SET(handle, &m_writefds); | |
608 | if (handle >= m_maxSocketNr) | |
609 | m_maxSocketNr = handle + 1; | |
610 | return find; | |
611 | } | |
612 | ||
613 | void wxApp::RemoveSocketHandler(int handle) | |
614 | { | |
615 | struct GsocketCallbackInfo | |
616 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
617 | if (handle < m_maxSocketHandles) | |
618 | { | |
619 | if (CallbackInfo[handle].type & wxSockReadMask) | |
620 | FD_CLR(CallbackInfo[handle].handle, &m_readfds); | |
621 | if (CallbackInfo[handle].type & wxSockWriteMask) | |
622 | FD_CLR(CallbackInfo[handle].handle, &m_writefds); | |
623 | CallbackInfo[handle].handle = -1; | |
624 | } | |
625 | } | |
626 | ||
8df85a61 DW |
627 | //----------------------------------------------------------------------------- |
628 | // wxWakeUpIdle | |
629 | //----------------------------------------------------------------------------- | |
630 | ||
e2478fde | 631 | void wxApp::WakeUpIdle() |
8df85a61 DW |
632 | { |
633 | // | |
634 | // Send the top window a dummy message so idle handler processing will | |
635 | // start up again. Doing it this way ensures that the idle handler | |
636 | // wakes up in the right thread (see also wxWakeUpMainThread() which does | |
637 | // the same for the main app thread only) | |
638 | // | |
639 | wxWindow* pTopWindow = wxTheApp->GetTopWindow(); | |
640 | ||
641 | if (pTopWindow) | |
642 | { | |
643 | if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0)) | |
644 | { | |
645 | // | |
646 | // Should never happen | |
647 | // | |
2173b18f | 648 | wxLogLastError(wxT("PostMessage(WM_NULL)")); |
8df85a61 DW |
649 | } |
650 | } | |
651 | } // end of wxWakeUpIdle | |
d88de032 | 652 | |
76990f63 | 653 | HAB wxGetInstance() |
d88de032 | 654 | { |
76990f63 | 655 | return vHabmain; |
d88de032 DW |
656 | } |
657 | ||
6670f564 | 658 | void wxSetInstance( HAB vHab ) |
d88de032 | 659 | { |
76990f63 | 660 | vHabmain = vHab; |
0e320a79 | 661 | } |