]>
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" | |
32ba0160 | 38 | #include "wx/evtloop.h" |
f18ad9c6 | 39 | |
d88de032 DW |
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 | ||
e7445ff8 | 85 | WXDLLEXPORT_DATA(wxChar*) wxBuffer; |
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 | { | |
ad9835c9 | 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); | |
ad9835c9 | 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); | |
ad9835c9 | 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 | |
ad9835c9 | 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. | |
54ffa107 | 238 | // wxRedirectIOToConsole(); |
54ffa107 | 239 | |
2461cfa0 | 240 | wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100); |
d88de032 DW |
241 | |
242 | // This is to foil optimizations in Visual C++ that throw out dummy.obj. | |
243 | // PLEASE DO NOT ALTER THIS. | |
1b3d5e55 | 244 | #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__) |
d88de032 DW |
245 | extern char wxDummyChar; |
246 | if (wxDummyChar) wxDummyChar++; | |
247 | #endif | |
248 | ||
61243a51 | 249 | // wxSetKeyboardHook(TRUE); |
d88de032 | 250 | |
459073a9 | 251 | RegisterWindowClasses(vHabmain); |
94826170 | 252 | |
ad9835c9 | 253 | return true; |
8df85a61 | 254 | } // end of wxApp::Initialize |
d88de032 | 255 | |
7e99520b | 256 | const char* CANTREGISTERCLASS = " Can't register Class "; |
d88de032 DW |
257 | // --------------------------------------------------------------------------- |
258 | // RegisterWindowClasses | |
259 | // --------------------------------------------------------------------------- | |
260 | ||
ad9835c9 | 261 | bool wxApp::RegisterWindowClasses( HAB vHab ) |
d88de032 | 262 | { |
ad9835c9 WS |
263 | ERRORID vError = 0L; |
264 | wxString sError; | |
3b9e3455 | 265 | |
f23208ca | 266 | if (!::WinRegisterClass( vHab |
0fba44b4 | 267 | ,(PSZ)wxFrameClassName |
51c1d535 | 268 | ,wxFrameWndProc |
f9efbe3a | 269 | ,CS_SIZEREDRAW | CS_SYNCPAINT |
a0606634 | 270 | ,sizeof(ULONG) |
f23208ca | 271 | )) |
d88de032 | 272 | { |
914589c2 DW |
273 | vError = ::WinGetLastError(vHab); |
274 | sError = wxPMErrorToStr(vError); | |
9923c37d | 275 | wxLogLastError(sError.c_str()); |
ad9835c9 | 276 | return false; |
d88de032 DW |
277 | } |
278 | ||
f23208ca | 279 | if (!::WinRegisterClass( vHab |
0fba44b4 | 280 | ,(PSZ)wxFrameClassNameNoRedraw |
51c1d535 | 281 | ,wxWndProc |
f23208ca | 282 | ,0 |
51c1d535 | 283 | ,sizeof(ULONG) |
f23208ca | 284 | )) |
d88de032 | 285 | { |
914589c2 DW |
286 | vError = ::WinGetLastError(vHab); |
287 | sError = wxPMErrorToStr(vError); | |
9923c37d | 288 | wxLogLastError(sError.c_str()); |
ad9835c9 | 289 | return false; |
d88de032 DW |
290 | } |
291 | ||
f23208ca | 292 | if (!::WinRegisterClass( vHab |
0fba44b4 | 293 | ,(PSZ)wxMDIFrameClassName |
51c1d535 | 294 | ,wxWndProc |
f6bcfd97 | 295 | ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT |
51c1d535 | 296 | ,sizeof(ULONG) |
f23208ca | 297 | )) |
d88de032 | 298 | { |
914589c2 DW |
299 | vError = ::WinGetLastError(vHab); |
300 | sError = wxPMErrorToStr(vError); | |
9923c37d | 301 | wxLogLastError(sError.c_str()); |
ad9835c9 | 302 | return false; |
d88de032 | 303 | } |
0e320a79 | 304 | |
f23208ca | 305 | if (!::WinRegisterClass( vHab |
0fba44b4 | 306 | ,(PSZ)wxMDIFrameClassNameNoRedraw |
51c1d535 | 307 | ,wxWndProc |
f23208ca | 308 | ,0 |
51c1d535 | 309 | ,sizeof(ULONG) |
f23208ca | 310 | )) |
d88de032 | 311 | { |
914589c2 DW |
312 | vError = ::WinGetLastError(vHab); |
313 | sError = wxPMErrorToStr(vError); | |
9923c37d | 314 | wxLogLastError(sError.c_str()); |
ad9835c9 | 315 | return false; |
d88de032 DW |
316 | } |
317 | ||
f23208ca | 318 | if (!::WinRegisterClass( vHab |
0fba44b4 | 319 | ,(PSZ)wxMDIChildFrameClassName |
51c1d535 | 320 | ,wxWndProc |
f23208ca | 321 | ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST |
51c1d535 | 322 | ,sizeof(ULONG) |
f23208ca | 323 | )) |
d88de032 | 324 | { |
914589c2 DW |
325 | vError = ::WinGetLastError(vHab); |
326 | sError = wxPMErrorToStr(vError); | |
9923c37d | 327 | wxLogLastError(sError.c_str()); |
ad9835c9 | 328 | return false; |
d88de032 DW |
329 | } |
330 | ||
f23208ca | 331 | if (!::WinRegisterClass( vHab |
0fba44b4 | 332 | ,(PSZ)wxMDIChildFrameClassNameNoRedraw |
51c1d535 | 333 | ,wxWndProc |
f23208ca | 334 | ,CS_HITTEST |
51c1d535 | 335 | ,sizeof(ULONG) |
f23208ca | 336 | )) |
d88de032 | 337 | { |
914589c2 DW |
338 | vError = ::WinGetLastError(vHab); |
339 | sError = wxPMErrorToStr(vError); | |
9923c37d | 340 | wxLogLastError(sError.c_str()); |
ad9835c9 | 341 | return false; |
d88de032 DW |
342 | } |
343 | ||
f23208ca | 344 | if (!::WinRegisterClass( vHab |
0fba44b4 | 345 | ,(PSZ)wxPanelClassName |
51c1d535 | 346 | ,wxWndProc |
f23208ca | 347 | ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT |
51c1d535 | 348 | ,sizeof(ULONG) |
f23208ca | 349 | )) |
d88de032 | 350 | { |
914589c2 DW |
351 | vError = ::WinGetLastError(vHab); |
352 | sError = wxPMErrorToStr(vError); | |
9923c37d | 353 | wxLogLastError(sError.c_str()); |
ad9835c9 | 354 | return false; |
d88de032 DW |
355 | } |
356 | ||
f23208ca | 357 | if (!::WinRegisterClass( vHab |
0fba44b4 | 358 | ,(PSZ)wxCanvasClassName |
51c1d535 | 359 | ,wxWndProc |
54ffa107 | 360 | ,CS_SIZEREDRAW | CS_HITTEST | CS_SYNCPAINT |
51c1d535 | 361 | ,sizeof(ULONG) |
f23208ca | 362 | )) |
d88de032 | 363 | { |
914589c2 DW |
364 | vError = ::WinGetLastError(vHab); |
365 | sError = wxPMErrorToStr(vError); | |
9923c37d | 366 | wxLogLastError(sError.c_str()); |
ad9835c9 | 367 | return false; |
d88de032 | 368 | } |
0256cfeb | 369 | if (!::WinRegisterClass( vHab |
0fba44b4 | 370 | ,(PSZ)wxCanvasClassNameNR |
0256cfeb DW |
371 | ,wxWndProc |
372 | ,CS_HITTEST | CS_SYNCPAINT | |
373 | ,sizeof(ULONG) | |
374 | )) | |
375 | { | |
376 | vError = ::WinGetLastError(vHab); | |
377 | sError = wxPMErrorToStr(vError); | |
9923c37d | 378 | wxLogLastError(sError.c_str()); |
ad9835c9 | 379 | return false; |
0256cfeb | 380 | } |
ad9835c9 | 381 | return true; |
8df85a61 | 382 | } // end of wxApp::RegisterWindowClasses |
d88de032 | 383 | |
8df85a61 | 384 | // |
77ffb593 | 385 | // Cleans up any wxWidgets internal structures left lying around |
8df85a61 | 386 | // |
0e320a79 DW |
387 | void wxApp::CleanUp() |
388 | { | |
d88de032 DW |
389 | delete[] wxBuffer; |
390 | wxBuffer = NULL; | |
0e320a79 | 391 | |
8df85a61 DW |
392 | // |
393 | // PM-SPECIFIC CLEANUP | |
394 | // | |
0e320a79 | 395 | |
ad9835c9 | 396 | // wxSetKeyboardHook(false); |
9ed0fac8 | 397 | |
d88de032 | 398 | if (wxSTD_FRAME_ICON) |
9ed0fac8 | 399 | ::WinFreeFileIcon(wxSTD_FRAME_ICON); |
d88de032 | 400 | if (wxSTD_MDICHILDFRAME_ICON) |
9ed0fac8 | 401 | ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON); |
d88de032 | 402 | if (wxSTD_MDIPARENTFRAME_ICON) |
9ed0fac8 | 403 | ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON); |
d88de032 DW |
404 | |
405 | if (wxDEFAULT_FRAME_ICON) | |
9ed0fac8 | 406 | ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON); |
d88de032 | 407 | if (wxDEFAULT_MDICHILDFRAME_ICON) |
9ed0fac8 | 408 | ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON); |
d88de032 | 409 | if (wxDEFAULT_MDIPARENTFRAME_ICON) |
9ed0fac8 DW |
410 | ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON); |
411 | ||
d88de032 DW |
412 | if ( wxDisableButtonBrush ) |
413 | { | |
414 | // TODO: ::DeleteObject( wxDisableButtonBrush ); | |
415 | } | |
416 | ||
2461cfa0 SN |
417 | delete wxWinHandleHash; |
418 | wxWinHandleHash = NULL; | |
d88de032 | 419 | |
468e327a SN |
420 | // Delete Message queue |
421 | if (wxTheApp->m_hMq) | |
422 | ::WinDestroyMsgQueue(wxTheApp->m_hMq); | |
423 | ||
94826170 | 424 | wxAppBase::CleanUp(); |
8df85a61 | 425 | } // end of wxApp::CleanUp |
0e320a79 | 426 | |
9ed0fac8 | 427 | bool wxApp::OnInitGui() |
d88de032 | 428 | { |
ad9835c9 WS |
429 | ERRORID vError; |
430 | wxString sError; | |
77cd51c3 | 431 | |
19193a2c | 432 | if (!wxAppBase::OnInitGui()) |
ad9835c9 | 433 | return false; |
19193a2c | 434 | |
f23208ca | 435 | m_hMq = ::WinCreateMsgQueue(vHabmain, 0); |
914589c2 DW |
436 | if (!m_hMq) |
437 | { | |
438 | vError = ::WinGetLastError(vHabmain); | |
439 | sError = wxPMErrorToStr(vError); | |
440 | wxLogDebug(sError); | |
ad9835c9 | 441 | return false; |
914589c2 | 442 | } |
19193a2c | 443 | |
ad9835c9 | 444 | return true; |
8df85a61 | 445 | } // end of wxApp::OnInitGui |
0e320a79 | 446 | |
0e320a79 DW |
447 | wxApp::wxApp() |
448 | { | |
9ed0fac8 | 449 | m_nPrintMode = wxPRINT_WINDOWS; |
468e327a | 450 | m_hMq = 0; |
3958ae62 SN |
451 | m_maxSocketHandles = 0; |
452 | m_maxSocketNr = 0; | |
453 | m_sockCallbackInfo = 0; | |
8df85a61 | 454 | } // end of wxApp::wxApp |
d88de032 DW |
455 | |
456 | wxApp::~wxApp() | |
457 | { | |
8df85a61 | 458 | } // end of wxApp::~wxApp |
0e320a79 | 459 | |
ad9835c9 | 460 | bool gbInOnIdle = false; |
2b5f62a0 | 461 | |
4bbd8098 | 462 | void wxApp::OnIdle( wxIdleEvent& WXUNUSED(rEvent) ) |
d88de032 | 463 | { |
9ed0fac8 | 464 | // |
d88de032 | 465 | // Avoid recursion (via ProcessEvent default case) |
9ed0fac8 | 466 | // |
2b5f62a0 | 467 | if (gbInOnIdle) |
d88de032 | 468 | return; |
0e320a79 | 469 | |
6670f564 WS |
470 | gbInOnIdle = true; |
471 | ||
893758d5 DW |
472 | #if wxUSE_DC_CACHEING |
473 | // automated DC cache management: clear the cached DCs and bitmap | |
474 | // if it's likely that the app has finished with them, that is, we | |
475 | // get an idle event and we're not dragging anything. | |
19193a2c KB |
476 | if (!::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) && |
477 | !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) && | |
478 | !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2)) | |
893758d5 DW |
479 | wxDC::ClearCache(); |
480 | #endif // wxUSE_DC_CACHEING | |
481 | ||
ad9835c9 | 482 | gbInOnIdle = false; |
8df85a61 | 483 | } // end of wxApp::OnIdle |
9779893b | 484 | |
9ed0fac8 DW |
485 | void wxApp::OnEndSession( |
486 | wxCloseEvent& WXUNUSED(rEvent)) | |
0e320a79 | 487 | { |
d88de032 | 488 | if (GetTopWindow()) |
ad9835c9 | 489 | GetTopWindow()->Close(true); |
8df85a61 | 490 | } // end of wxApp::OnEndSession |
0e320a79 | 491 | |
9ed0fac8 | 492 | // |
d88de032 DW |
493 | // Default behaviour: close the application with prompts. The |
494 | // user can veto the close, and therefore the end session. | |
9ed0fac8 | 495 | // |
ad9835c9 | 496 | void wxApp::OnQueryEndSession( wxCloseEvent& rEvent ) |
0e320a79 | 497 | { |
d88de032 DW |
498 | if (GetTopWindow()) |
499 | { | |
9ed0fac8 | 500 | if (!GetTopWindow()->Close(!rEvent.CanVeto())) |
ad9835c9 | 501 | rEvent.Veto(true); |
d88de032 | 502 | } |
8df85a61 | 503 | } // end of wxApp::OnQueryEndSession |
0e320a79 | 504 | |
3958ae62 SN |
505 | int wxApp::AddSocketHandler(int handle, int mask, |
506 | void (*callback)(void*), void * gsock) | |
507 | { | |
508 | int find; | |
509 | struct GsocketCallbackInfo | |
510 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
511 | ||
512 | for (find = 0; find < m_maxSocketHandles; find++) | |
513 | if (CallbackInfo[find].handle == -1) | |
514 | break; | |
515 | if (find == m_maxSocketHandles) | |
516 | { | |
517 | // Allocate new memory | |
518 | m_sockCallbackInfo = realloc(m_sockCallbackInfo, | |
519 | (m_maxSocketHandles+=10)* | |
520 | sizeof(struct GsocketCallbackInfo)); | |
521 | CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
522 | for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++) | |
523 | CallbackInfo[find].handle = -1; | |
524 | find = m_maxSocketHandles - 10; | |
525 | } | |
526 | CallbackInfo[find].proc = callback; | |
527 | CallbackInfo[find].type = mask; | |
528 | CallbackInfo[find].handle = handle; | |
529 | CallbackInfo[find].gsock = gsock; | |
530 | if (mask & wxSockReadMask) | |
531 | FD_SET(handle, &m_readfds); | |
532 | if (mask & wxSockWriteMask) | |
533 | FD_SET(handle, &m_writefds); | |
534 | if (handle >= m_maxSocketNr) | |
535 | m_maxSocketNr = handle + 1; | |
536 | return find; | |
537 | } | |
538 | ||
539 | void wxApp::RemoveSocketHandler(int handle) | |
540 | { | |
541 | struct GsocketCallbackInfo | |
542 | *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo; | |
543 | if (handle < m_maxSocketHandles) | |
544 | { | |
545 | if (CallbackInfo[handle].type & wxSockReadMask) | |
546 | FD_CLR(CallbackInfo[handle].handle, &m_readfds); | |
547 | if (CallbackInfo[handle].type & wxSockWriteMask) | |
548 | FD_CLR(CallbackInfo[handle].handle, &m_writefds); | |
549 | CallbackInfo[handle].handle = -1; | |
550 | } | |
551 | } | |
552 | ||
8df85a61 DW |
553 | //----------------------------------------------------------------------------- |
554 | // wxWakeUpIdle | |
555 | //----------------------------------------------------------------------------- | |
556 | ||
e2478fde | 557 | void wxApp::WakeUpIdle() |
8df85a61 DW |
558 | { |
559 | // | |
560 | // Send the top window a dummy message so idle handler processing will | |
561 | // start up again. Doing it this way ensures that the idle handler | |
562 | // wakes up in the right thread (see also wxWakeUpMainThread() which does | |
563 | // the same for the main app thread only) | |
564 | // | |
565 | wxWindow* pTopWindow = wxTheApp->GetTopWindow(); | |
566 | ||
567 | if (pTopWindow) | |
568 | { | |
569 | if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0)) | |
570 | { | |
571 | // | |
572 | // Should never happen | |
573 | // | |
2173b18f | 574 | wxLogLastError(wxT("PostMessage(WM_NULL)")); |
8df85a61 DW |
575 | } |
576 | } | |
577 | } // end of wxWakeUpIdle | |
d88de032 | 578 | |
76990f63 | 579 | HAB wxGetInstance() |
d88de032 | 580 | { |
76990f63 | 581 | return vHabmain; |
d88de032 DW |
582 | } |
583 | ||
6670f564 | 584 | void wxSetInstance( HAB vHab ) |
d88de032 | 585 | { |
76990f63 | 586 | vHabmain = vHab; |
0e320a79 | 587 | } |