]> git.saurik.com Git - wxWidgets.git/blame - src/os2/app.cpp
Renamed m_clientData member variable to avoid clash with variable with same
[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"
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
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
e7445ff8 84WXDLLEXPORT_DATA(wxChar*) wxBuffer;
9ed0fac8 85extern wxCursor* g_globalCursor;
0e320a79 86
8df85a61 87HAB vHabmain = NULLHANDLE;
d88de032 88
d88de032 89
9ed0fac8
DW
90HICON wxSTD_FRAME_ICON = (HICON) NULL;
91HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
d88de032
DW
92HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
93
9ed0fac8
DW
94HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
95HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
96HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
d88de032
DW
97
98HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
99
51c1d535
DW
100MRESULT EXPENTRY wxWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2);
101MRESULT 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
111struct 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
122void 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 191bool 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 257const char* CANTREGISTERCLASS = " Can't register Class ";
d88de032
DW
258// ---------------------------------------------------------------------------
259// RegisterWindowClasses
260// ---------------------------------------------------------------------------
261
ad9835c9 262bool 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
388void 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 428bool 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
448wxApp::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
459wxApp::~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 475bool gbInOnIdle = false;
2b5f62a0 476
ad9835c9 477void 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
459073a9 487 wxAppBase::OnIdle(rEvent);
0e320a79 488
893758d5
DW
489#if wxUSE_DC_CACHEING
490 // automated DC cache management: clear the cached DCs and bitmap
491 // if it's likely that the app has finished with them, that is, we
492 // get an idle event and we're not dragging anything.
19193a2c
KB
493 if (!::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) &&
494 !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) &&
495 !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
893758d5
DW
496 wxDC::ClearCache();
497#endif // wxUSE_DC_CACHEING
498
ad9835c9 499 gbInOnIdle = false;
8df85a61 500} // end of wxApp::OnIdle
9779893b 501
9ed0fac8
DW
502void wxApp::OnEndSession(
503 wxCloseEvent& WXUNUSED(rEvent))
0e320a79 504{
d88de032 505 if (GetTopWindow())
ad9835c9 506 GetTopWindow()->Close(true);
8df85a61 507} // end of wxApp::OnEndSession
0e320a79 508
9ed0fac8 509//
d88de032
DW
510// Default behaviour: close the application with prompts. The
511// user can veto the close, and therefore the end session.
9ed0fac8 512//
ad9835c9 513void wxApp::OnQueryEndSession( wxCloseEvent& rEvent )
0e320a79 514{
d88de032
DW
515 if (GetTopWindow())
516 {
9ed0fac8 517 if (!GetTopWindow()->Close(!rEvent.CanVeto()))
ad9835c9 518 rEvent.Veto(true);
d88de032 519 }
8df85a61 520} // end of wxApp::OnQueryEndSession
0e320a79 521
8df85a61 522//
d88de032 523// Yield to incoming messages
8df85a61 524//
8461e4c2 525bool wxApp::Yield(bool onlyIfNeeded)
0e320a79 526{
ad9835c9 527 static bool s_inYield = false;
8461e4c2
VZ
528
529 if ( s_inYield )
530 {
531 if ( !onlyIfNeeded )
532 {
533 wxFAIL_MSG( _T("wxYield() called recursively") );
534 }
535
ad9835c9 536 return false;
8461e4c2
VZ
537 }
538
ad9835c9
WS
539 HAB vHab = 0;
540 QMSG vMsg;
ee453a16 541
8df85a61
DW
542 //
543 // Disable log flushing from here because a call to wxYield() shouldn't
544 // normally result in message boxes popping up &c
545 //
546 wxLog::Suspend();
547
ad9835c9 548 s_inYield = true;
8b63ae37 549
8df85a61 550 //
d88de032
DW
551 // We want to go back to the main message loop
552 // if we see a WM_QUIT. (?)
8df85a61 553 //
dde11e60 554 while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT)
d88de032 555 {
8df85a61
DW
556#if wxUSE_THREADS
557 wxMutexGuiLeaveOrEnter();
558#endif // wxUSE_THREADS
598dc9b7 559 if (!wxTheApp->Dispatch())
d88de032
DW
560 break;
561 }
8df85a61 562 //
d88de032 563 // If they are pending events, we must process them.
8df85a61
DW
564 //
565 if (wxTheApp)
566 wxTheApp->ProcessPendingEvents();
567
5c9ee6dd 568 HandleSockets();
8df85a61
DW
569 //
570 // Let the logs be flashed again
571 //
572 wxLog::Resume();
ad9835c9
WS
573 s_inYield = false;
574 return true;
8df85a61 575} // end of wxYield
d88de032 576
3958ae62
SN
577int wxApp::AddSocketHandler(int handle, int mask,
578 void (*callback)(void*), void * gsock)
579{
580 int find;
581 struct GsocketCallbackInfo
582 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
583
584 for (find = 0; find < m_maxSocketHandles; find++)
585 if (CallbackInfo[find].handle == -1)
586 break;
587 if (find == m_maxSocketHandles)
588 {
589 // Allocate new memory
590 m_sockCallbackInfo = realloc(m_sockCallbackInfo,
591 (m_maxSocketHandles+=10)*
592 sizeof(struct GsocketCallbackInfo));
593 CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
594 for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++)
595 CallbackInfo[find].handle = -1;
596 find = m_maxSocketHandles - 10;
597 }
598 CallbackInfo[find].proc = callback;
599 CallbackInfo[find].type = mask;
600 CallbackInfo[find].handle = handle;
601 CallbackInfo[find].gsock = gsock;
602 if (mask & wxSockReadMask)
603 FD_SET(handle, &m_readfds);
604 if (mask & wxSockWriteMask)
605 FD_SET(handle, &m_writefds);
606 if (handle >= m_maxSocketNr)
607 m_maxSocketNr = handle + 1;
608 return find;
609}
610
611void wxApp::RemoveSocketHandler(int handle)
612{
613 struct GsocketCallbackInfo
614 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
615 if (handle < m_maxSocketHandles)
616 {
617 if (CallbackInfo[handle].type & wxSockReadMask)
618 FD_CLR(CallbackInfo[handle].handle, &m_readfds);
619 if (CallbackInfo[handle].type & wxSockWriteMask)
620 FD_CLR(CallbackInfo[handle].handle, &m_writefds);
621 CallbackInfo[handle].handle = -1;
622 }
623}
624
8df85a61
DW
625//-----------------------------------------------------------------------------
626// wxWakeUpIdle
627//-----------------------------------------------------------------------------
628
e2478fde 629void wxApp::WakeUpIdle()
8df85a61
DW
630{
631 //
632 // Send the top window a dummy message so idle handler processing will
633 // start up again. Doing it this way ensures that the idle handler
634 // wakes up in the right thread (see also wxWakeUpMainThread() which does
635 // the same for the main app thread only)
636 //
637 wxWindow* pTopWindow = wxTheApp->GetTopWindow();
638
639 if (pTopWindow)
640 {
641 if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0))
642 {
643 //
644 // Should never happen
645 //
2173b18f 646 wxLogLastError(wxT("PostMessage(WM_NULL)"));
8df85a61
DW
647 }
648 }
649} // end of wxWakeUpIdle
d88de032 650
76990f63 651HAB wxGetInstance()
d88de032 652{
76990f63 653 return vHabmain;
d88de032
DW
654}
655
6670f564 656void wxSetInstance( HAB vHab )
d88de032 657{
76990f63 658 vHabmain = vHab;
0e320a79 659}