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