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