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