]> git.saurik.com Git - wxWidgets.git/blame - src/os2/app.cpp
typo fixed
[wxWidgets.git] / src / os2 / app.cpp
CommitLineData
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
DW
8// Copyright: (c) David Webster
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
15#ifndef WX_PRECOMP
16 #include "wx/frame.h"
17 #include "wx/app.h"
18 #include "wx/utils.h"
19 #include "wx/gdicmn.h"
20 #include "wx/pen.h"
21 #include "wx/brush.h"
22 #include "wx/cursor.h"
23 #include "wx/icon.h"
24 #include "wx/palette.h"
25 #include "wx/dc.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
28 #include "wx/intl.h"
29 #include "wx/dynarray.h"
cb21bd1b
SN
30 #include "wx/wxchar.h"
31 #include "wx/icon.h"
32 #include "wx/timer.h"
0e320a79
DW
33#endif
34
0e320a79
DW
35#include "wx/log.h"
36#include "wx/module.h"
d88de032
DW
37
38#include "wx/os2/private.h"
39
29d83fc1
DW
40#ifdef __EMX__
41
19193a2c
KB
42#include <sys/ioctl.h>
43#include <sys/select.h>
29d83fc1
DW
44
45#else
46
65b851bb 47#include <nerrno.h>
19193a2c
KB
48#include <sys/ioctl.h>
49#include <sys/select.h>
50#include <sys/time.h>
29d83fc1 51
19193a2c 52#endif //
29d83fc1 53
3958ae62 54#ifndef __EMX__
29d83fc1 55
3958ae62 56#define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
19193a2c
KB
57extern "C" int _System bsdselect(int,
58 struct fd_set *,
59 struct fd_set *,
60 struct fd_set *,
61 struct timeval *);
3958ae62
SN
62#endif
63
d88de032
DW
64#if wxUSE_THREADS
65 #include "wx/thread.h"
66
9ed0fac8
DW
67 // define the array of QMSG strutures
68 WX_DECLARE_OBJARRAY(QMSG, wxMsgArray);
d88de032
DW
69
70 #include "wx/arrimpl.cpp"
71
9ed0fac8 72 WX_DEFINE_OBJARRAY(wxMsgArray);
d88de032 73#endif // wxUSE_THREADS
0e320a79
DW
74
75#if wxUSE_WX_RESOURCES
d88de032 76 #include "wx/resource.h"
0e320a79
DW
77#endif
78
8df85a61
DW
79#if wxUSE_TOOLTIPS
80 #include "wx/tooltip.h"
81#endif // wxUSE_TOOLTIPS
82
0e320a79 83#include <string.h>
d88de032
DW
84#include <ctype.h>
85
86// ---------------------------------------------------------------------------
87// global variables
88// ---------------------------------------------------------------------------
89
9ed0fac8 90extern wxChar* wxBuffer;
9ed0fac8
DW
91extern wxList* wxWinHandleList;
92extern wxList WXDLLEXPORT wxPendingDelete;
9ed0fac8 93extern wxCursor* g_globalCursor;
0e320a79 94
8df85a61 95HAB vHabmain = NULLHANDLE;
9ed0fac8
DW
96QMSG svCurrentMsg;
97wxApp* wxTheApp = NULL;
d88de032
DW
98
99// NB: all "NoRedraw" classes must have the same names as the "normal" classes
13a4ea8d 100// with NR suffix - wxWindow::OS2Create() supposes this
9ed0fac8
DW
101wxChar wxFrameClassName[] = wxT("wxFrameClass");
102wxChar wxFrameClassNameNoRedraw[] = wxT("wxFrameClassNR");
103wxChar wxMDIFrameClassName[] = wxT("wxMDIFrameClass");
104wxChar wxMDIFrameClassNameNoRedraw[] = wxT("wxMDIFrameClassNR");
105wxChar wxMDIChildFrameClassName[] = wxT("wxMDIChildFrameClass");
d88de032 106wxChar wxMDIChildFrameClassNameNoRedraw[] = wxT("wxMDIChildFrameClassNR");
9ed0fac8
DW
107wxChar wxPanelClassName[] = wxT("wxPanelClass");
108wxChar wxCanvasClassName[] = wxT("wxCanvasClass");
d88de032 109
9ed0fac8
DW
110HICON wxSTD_FRAME_ICON = (HICON) NULL;
111HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
d88de032
DW
112HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
113
9ed0fac8
DW
114HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
115HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
116HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
d88de032
DW
117
118HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
119
51c1d535
DW
120MRESULT EXPENTRY wxWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2);
121MRESULT EXPENTRY wxFrameWndProc( HWND hWnd,ULONG message,MPARAM mp1,MPARAM mp2);
122
d88de032
DW
123// ===========================================================================
124// implementation
125// ===========================================================================
126
3958ae62
SN
127// ---------------------------------------------------------------------------
128// helper struct and functions for socket handling
129// ---------------------------------------------------------------------------
130
131struct GsocketCallbackInfo{
132 void (*proc)(void *);
133 int type;
134 int handle;
135 void* gsock;
136};
137
138// These defines and wrapper functions are used here and in gsockpm.c
139#define wxSockReadMask 0x01
140#define wxSockWriteMask 0x02
141
29d83fc1 142#ifdef __EMX__
3958ae62
SN
143extern "C"
144int wxAppAddSocketHandler(int handle, int mask,
29d83fc1 145 void (*callback)(void*), void * gsock)
3958ae62
SN
146{
147 return wxTheApp->AddSocketHandler(handle, mask, callback, gsock);
148}
3958ae62
SN
149extern "C"
150void wxAppRemoveSocketHandler(int handle)
151{
152 wxTheApp->RemoveSocketHandler(handle);
153}
29d83fc1
DW
154#else
155// Linkage mode problems using callbacks with extern C in a .cpp module
156int wxAppAddSocketHandler(int handle, int mask,
157 void (*callback)(void*), void * gsock)
158{
159 return wxTheApp->AddSocketHandler(handle, mask, callback, gsock);
160}
161void wxAppRemoveSocketHandler(int handle)
162{
163 wxTheApp->RemoveSocketHandler(handle);
164}
165#endif
3958ae62
SN
166
167void wxApp::HandleSockets()
168{
29d83fc1 169 bool pendingEvent = FALSE;
3958ae62
SN
170
171 // Check whether it's time for Gsocket operation
172 if (m_maxSocketHandles > 0 && m_maxSocketNr > 0)
173 {
174 fd_set readfds = m_readfds;
175 fd_set writefds = m_writefds;
176 struct timeval timeout;
177 int i;
178 struct GsocketCallbackInfo
179 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
180 int r = 0;
181 timeout.tv_sec = 0;
182 timeout.tv_usec = 0;
183 if ( select(m_maxSocketNr, &readfds, &writefds, 0, &timeout) > 0)
184 {
185 for (i = m_lastUsedHandle + 1; i != m_lastUsedHandle; i++)
186 {
187 if (i == m_maxSocketNr)
188 i = 0;
189 if (FD_ISSET(i, &readfds))
190 {
191 int r;
192 for (r = 0; r < m_maxSocketHandles; r++){
193 if(CallbackInfo[r].handle == i &&
194 CallbackInfo[r].type == wxSockReadMask)
195 break;
196 }
197 if (r < m_maxSocketHandles)
198 {
199 CallbackInfo[r].proc(CallbackInfo[r].gsock);
29d83fc1 200 pendingEvent = TRUE;
3958ae62
SN
201 wxYield();
202 }
203 }
204 if (FD_ISSET(i, &writefds))
205 {
206 int r;
207 for (r = 0; r < m_maxSocketHandles; r++)
208 if(CallbackInfo[r].handle == i &&
209 CallbackInfo[r].type == wxSockWriteMask)
210 break;
211 if (r < m_maxSocketHandles)
212 {
213 CallbackInfo[r].proc(CallbackInfo[r].gsock);
29d83fc1 214 pendingEvent = TRUE;
3958ae62
SN
215 wxYield();
216 }
217 }
218 }
219 m_lastUsedHandle = i;
220 }
221 if (pendingEvent)
222 wxYield();
223 }
224}
d88de032
DW
225// ---------------------------------------------------------------------------
226// wxApp
227// ---------------------------------------------------------------------------
228
d88de032 229 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
0e320a79 230
d88de032
DW
231 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
232 EVT_IDLE(wxApp::OnIdle)
233 EVT_END_SESSION(wxApp::OnEndSession)
234 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
235 END_EVENT_TABLE()
0e320a79 236
8df85a61
DW
237//
238// Initialize
239//
9ed0fac8
DW
240bool wxApp::Initialize(
241 HAB vHab
242)
0e320a79 243{
7e99520b
DW
244#if defined(wxUSE_CONSOLEDEBUG)
245 #if wxUSE_CONSOLEDEBUG
246/***********************************************/
247/* Code for using stdout debug */
248/* To use it you mast link app as "Window" - EK*/
249/***********************************************/
250 {
251 PPIB pib;
252 PTIB tib;
253
254 printf("In console\n");
255
256 DosGetInfoBlocks(&tib, &pib);
257/* Try morphing into a PM application. */
258// if(pib->pib_ultype == 2) /* VIO */
259 pib->pib_ultype = 3;
260 }
261/**********************************************/
262/**********************************************/
263 #endif //wxUSE_CONSOLEDEBUG
264#endif
265
914589c2
DW
266 //
267 // OS2 has to have an anchorblock
268 //
269 vHab = WinInitialize(0);
270
271 if (!vHab)
272 return FALSE;
273 else
274 vHabmain = vHab;
275
d88de032
DW
276 // Some people may wish to use this, but
277 // probably it shouldn't be here by default.
278#ifdef __WXDEBUG__
279 // wxRedirectIOToConsole();
0e320a79
DW
280#endif
281
13a4ea8d 282 wxBuffer = new wxChar[1500]; // FIXME; why?
0e320a79 283
d88de032 284 wxClassInfo::InitializeClasses();
0e320a79 285
8df85a61
DW
286#if wxUSE_THREADS
287 wxPendingEventsLocker = new wxCriticalSection;
288#endif
289
d88de032
DW
290 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
291 wxTheColourDatabase->Initialize();
292
293 wxInitializeStockLists();
294 wxInitializeStockObjects();
0e320a79
DW
295
296#if wxUSE_WX_RESOURCES
d88de032 297 wxInitializeResourceSystem();
0e320a79
DW
298#endif
299
d88de032
DW
300 wxBitmap::InitStandardHandlers();
301
9ed0fac8 302 RegisterWindowClasses(vHab);
d88de032
DW
303 wxWinHandleList = new wxList(wxKEY_INTEGER);
304
305 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
306 // PLEASE DO NOT ALTER THIS.
1b3d5e55 307#if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
d88de032
DW
308 extern char wxDummyChar;
309 if (wxDummyChar) wxDummyChar++;
310#endif
311
61243a51 312 // wxSetKeyboardHook(TRUE);
d88de032
DW
313
314 wxModule::RegisterModules();
315 if (!wxModule::InitializeModules())
316 return FALSE;
317 return TRUE;
8df85a61 318} // end of wxApp::Initialize
d88de032 319
7e99520b 320const char* CANTREGISTERCLASS = " Can't register Class ";
d88de032
DW
321// ---------------------------------------------------------------------------
322// RegisterWindowClasses
323// ---------------------------------------------------------------------------
324
9ed0fac8
DW
325bool wxApp::RegisterWindowClasses(
326 HAB vHab
327)
d88de032 328{
914589c2
DW
329 ERRORID vError = 0L;
330 wxString sError;
3b9e3455 331
f23208ca
DW
332 if (!::WinRegisterClass( vHab
333 ,wxFrameClassName
51c1d535 334 ,wxFrameWndProc
987da0d4 335 ,CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPCHILDREN
a0606634 336 ,sizeof(ULONG)
f23208ca 337 ))
d88de032 338 {
914589c2
DW
339 vError = ::WinGetLastError(vHab);
340 sError = wxPMErrorToStr(vError);
341 wxLogLastError(sError);
d88de032
DW
342 return FALSE;
343 }
344
f23208ca
DW
345 if (!::WinRegisterClass( vHab
346 ,wxFrameClassNameNoRedraw
51c1d535 347 ,wxWndProc
f23208ca 348 ,0
51c1d535 349 ,sizeof(ULONG)
f23208ca 350 ))
d88de032 351 {
914589c2
DW
352 vError = ::WinGetLastError(vHab);
353 sError = wxPMErrorToStr(vError);
354 wxLogLastError(sError);
d88de032
DW
355 return FALSE;
356 }
357
f23208ca
DW
358 if (!::WinRegisterClass( vHab
359 ,wxMDIFrameClassName
51c1d535 360 ,wxWndProc
f6bcfd97 361 ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT
51c1d535 362 ,sizeof(ULONG)
f23208ca 363 ))
d88de032 364 {
914589c2
DW
365 vError = ::WinGetLastError(vHab);
366 sError = wxPMErrorToStr(vError);
367 wxLogLastError(sError);
d88de032
DW
368 return FALSE;
369 }
0e320a79 370
f23208ca
DW
371 if (!::WinRegisterClass( vHab
372 ,wxMDIFrameClassNameNoRedraw
51c1d535 373 ,wxWndProc
f23208ca 374 ,0
51c1d535 375 ,sizeof(ULONG)
f23208ca 376 ))
d88de032 377 {
914589c2
DW
378 vError = ::WinGetLastError(vHab);
379 sError = wxPMErrorToStr(vError);
380 wxLogLastError(sError);
d88de032
DW
381 return FALSE;
382 }
383
f23208ca
DW
384 if (!::WinRegisterClass( vHab
385 ,wxMDIChildFrameClassName
51c1d535 386 ,wxWndProc
f23208ca 387 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST
51c1d535 388 ,sizeof(ULONG)
f23208ca 389 ))
d88de032 390 {
914589c2
DW
391 vError = ::WinGetLastError(vHab);
392 sError = wxPMErrorToStr(vError);
393 wxLogLastError(sError);
d88de032
DW
394 return FALSE;
395 }
396
f23208ca
DW
397 if (!::WinRegisterClass( vHab
398 ,wxMDIChildFrameClassNameNoRedraw
51c1d535 399 ,wxWndProc
f23208ca 400 ,CS_HITTEST
51c1d535 401 ,sizeof(ULONG)
f23208ca 402 ))
d88de032 403 {
914589c2
DW
404 vError = ::WinGetLastError(vHab);
405 sError = wxPMErrorToStr(vError);
406 wxLogLastError(sError);
d88de032
DW
407 return FALSE;
408 }
409
f23208ca
DW
410 if (!::WinRegisterClass( vHab
411 ,wxPanelClassName
51c1d535 412 ,wxWndProc
f23208ca 413 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT
51c1d535 414 ,sizeof(ULONG)
f23208ca 415 ))
d88de032 416 {
914589c2
DW
417 vError = ::WinGetLastError(vHab);
418 sError = wxPMErrorToStr(vError);
419 wxLogLastError(sError);
d88de032
DW
420 return FALSE;
421 }
422
f23208ca
DW
423 if (!::WinRegisterClass( vHab
424 ,wxCanvasClassName
51c1d535 425 ,wxWndProc
987da0d4 426 ,CS_SIZEREDRAW | CS_HITTEST | CS_SYNCPAINT | CS_CLIPCHILDREN
51c1d535 427 ,sizeof(ULONG)
f23208ca 428 ))
d88de032 429 {
914589c2
DW
430 vError = ::WinGetLastError(vHab);
431 sError = wxPMErrorToStr(vError);
432 wxLogLastError(sError);
d88de032
DW
433 return FALSE;
434 }
d88de032 435 return TRUE;
8df85a61 436} // end of wxApp::RegisterWindowClasses
d88de032 437
8df85a61
DW
438//
439// Cleans up any wxWindows internal structures left lying around
440//
0e320a79
DW
441void wxApp::CleanUp()
442{
8df85a61
DW
443 //
444 // COMMON CLEANUP
445 //
d88de032
DW
446
447#if wxUSE_LOG
8df85a61
DW
448
449 //
450 // Flush the logged messages if any and install a 'safer' log target: the
d88de032
DW
451 // default one (wxLogGui) can't be used after the resources are freed just
452 // below and the user suppliedo ne might be even more unsafe (using any
453 // wxWindows GUI function is unsafe starting from now)
8df85a61 454 //
d88de032
DW
455 wxLog::DontCreateOnDemand();
456
8df85a61
DW
457 //
458 // This will flush the old messages if any
459 //
d88de032
DW
460 delete wxLog::SetActiveTarget(new wxLogStderr);
461#endif // wxUSE_LOG
462
8df85a61 463 //
d88de032 464 // One last chance for pending objects to be cleaned up
8df85a61 465 //
d88de032
DW
466 wxTheApp->DeletePendingObjects();
467
468 wxModule::CleanUpModules();
0e320a79
DW
469
470#if wxUSE_WX_RESOURCES
d88de032 471 wxCleanUpResourceSystem();
d88de032 472#endif
0e320a79 473
d88de032 474 wxDeleteStockObjects();
0e320a79 475
8df85a61 476 //
d88de032 477 // Destroy all GDI lists, etc.
8df85a61 478 //
d88de032 479 wxDeleteStockLists();
0e320a79 480
d88de032
DW
481 delete wxTheColourDatabase;
482 wxTheColourDatabase = NULL;
0e320a79 483
d88de032 484 wxBitmap::CleanUpHandlers();
0e320a79 485
d88de032
DW
486 delete[] wxBuffer;
487 wxBuffer = NULL;
0e320a79 488
8df85a61
DW
489 //
490 // PM-SPECIFIC CLEANUP
491 //
0e320a79 492
61243a51 493 // wxSetKeyboardHook(FALSE);
9ed0fac8 494
d88de032 495 if (wxSTD_FRAME_ICON)
9ed0fac8 496 ::WinFreeFileIcon(wxSTD_FRAME_ICON);
d88de032 497 if (wxSTD_MDICHILDFRAME_ICON)
9ed0fac8 498 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON);
d88de032 499 if (wxSTD_MDIPARENTFRAME_ICON)
9ed0fac8 500 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON);
d88de032
DW
501
502 if (wxDEFAULT_FRAME_ICON)
9ed0fac8 503 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON);
d88de032 504 if (wxDEFAULT_MDICHILDFRAME_ICON)
9ed0fac8 505 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON);
d88de032 506 if (wxDEFAULT_MDIPARENTFRAME_ICON)
9ed0fac8
DW
507 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
508
d88de032
DW
509 if ( wxDisableButtonBrush )
510 {
511// TODO: ::DeleteObject( wxDisableButtonBrush );
512 }
513
514 if (wxWinHandleList)
515 delete wxWinHandleList;
516
d88de032 517 delete wxPendingEvents;
8df85a61 518#if wxUSE_THREADS
d88de032
DW
519 delete wxPendingEventsLocker;
520 // If we don't do the following, we get an apparent memory leak.
521 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
522#endif
0e320a79 523
d88de032 524 wxClassInfo::CleanUpClasses();
0e320a79 525
468e327a
SN
526 // Delete Message queue
527 if (wxTheApp->m_hMq)
528 ::WinDestroyMsgQueue(wxTheApp->m_hMq);
529
d88de032
DW
530 delete wxTheApp;
531 wxTheApp = NULL;
77cd51c3 532
0e320a79 533#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
d88de032
DW
534 // At this point we want to check if there are any memory
535 // blocks that aren't part of the wxDebugContext itself,
536 // as a special case. Then when dumping we need to ignore
537 // wxDebugContext, too.
538 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
539 {
540 wxLogDebug(wxT("There were memory leaks."));
541 wxDebugContext::Dump();
542 wxDebugContext::PrintStatistics();
543 }
544 // wxDebugContext::SetStream(NULL, NULL);
0e320a79 545#endif
77cd51c3 546
d88de032
DW
547#if wxUSE_LOG
548 // do it as the very last thing because everything else can log messages
549 delete wxLog::SetActiveTarget(NULL);
550#endif // wxUSE_LOG
8df85a61 551} // end of wxApp::CleanUp
0e320a79 552
7e99520b
DW
553//----------------------------------------------------------------------
554// Main wxWindows entry point
555//----------------------------------------------------------------------
9ed0fac8
DW
556int wxEntry(
557 int argc
558, char* argv[]
559)
d88de032 560{
9dea36ef 561 HAB vHab = 0;
d88de032 562
9ed0fac8
DW
563 if (!wxApp::Initialize(vHab))
564 return 0;
d88de032 565
9ed0fac8
DW
566 //
567 // create the application object or ensure that one already exists
568 //
569 if (!wxTheApp)
570 {
426d5745
DW
571 // The app may have declared a global application object, but we recommend
572 // the IMPLEMENT_APP macro is used instead, which sets an initializer
573 // function for delayed, dynamic app object construction.
574 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
575 wxT("No initializer - use IMPLEMENT_APP macro.") );
576 wxTheApp = (*wxApp::GetInitializerFunction()) ();
9ed0fac8 577 }
426d5745 578 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
9ed0fac8 579 wxTheApp->argc = argc;
d88de032 580
9ed0fac8
DW
581#if wxUSE_UNICODE
582 wxTheApp->argv = new wxChar*[argc+1];
583
584 int nArgc = 0;
585
586 while (nArgc < argc)
587 {
588 wxTheApp->argv[nArgc] = wxStrdup(wxConvLibc.cMB2WX(argv[nArgc]));
589 nArgc++;
590 }
591 wxTheApp->argv[nArgc] = (wxChar *)NULL;
592#else
593 wxTheApp->argv = argv;
594#endif
d88de032 595
9ed0fac8 596 wxString sName(wxFileNameFromPath(argv[0]));
d88de032 597
9ed0fac8
DW
598 wxStripExtension(sName);
599 wxTheApp->SetAppName(sName);
d88de032 600
9ed0fac8 601 int nRetValue = 0;
d88de032 602
9ed0fac8
DW
603 if (!wxTheApp->OnInitGui())
604 nRetValue = -1;
d88de032 605
9ed0fac8
DW
606 if (nRetValue == 0)
607 {
608 if (wxTheApp->OnInit())
d88de032 609 {
7bed7a50 610 nRetValue = wxTheApp->OnRun();
7bed7a50 611 }
51c1d535
DW
612 // Normal exit
613 wxWindow* pTopWindow = wxTheApp->GetTopWindow();
614 if (pTopWindow)
d88de032 615 {
51c1d535
DW
616 // Forcibly delete the window.
617 if (pTopWindow->IsKindOf(CLASSINFO(wxFrame)) ||
618 pTopWindow->IsKindOf(CLASSINFO(wxDialog)) )
619 {
620 pTopWindow->Close(TRUE);
621 wxTheApp->DeletePendingObjects();
622 }
623 else
624 {
625 delete pTopWindow;
626 wxTheApp->SetTopWindow(NULL);
627 }
d88de032 628 }
9ed0fac8 629 }
7e99520b
DW
630 else // app initialization failed
631 {
632 wxLogLastError(" Gui initialization failed, exitting");
633 }
634#if wxUSE_CONSOLEDEBUG
635 printf("wxTheApp->OnExit ");
636 fflush(stdout);
637#endif
9ed0fac8 638 wxTheApp->OnExit();
7e99520b
DW
639#if wxUSE_CONSOLEDEBUG
640 printf("wxApp::CleanUp ");
641 fflush(stdout);
642#endif
9ed0fac8 643 wxApp::CleanUp();
7e99520b
DW
644#if wxUSE_CONSOLEDEBUG
645 printf("return %i ", nRetValue);
646 fflush(stdout);
647#endif
9ed0fac8 648 return(nRetValue);
8df85a61 649} // end of wxEntry
77cd51c3 650
9ed0fac8 651bool wxApp::OnInitGui()
d88de032 652{
914589c2
DW
653 ERRORID vError;
654 wxString sError;
77cd51c3 655
19193a2c
KB
656 if (!wxAppBase::OnInitGui())
657 return FALSE;
658
f23208ca 659 m_hMq = ::WinCreateMsgQueue(vHabmain, 0);
914589c2
DW
660 if (!m_hMq)
661 {
662 vError = ::WinGetLastError(vHabmain);
663 sError = wxPMErrorToStr(vError);
664 wxLogDebug(sError);
665 return FALSE;
666 }
19193a2c 667
9ed0fac8 668 return TRUE;
8df85a61 669} // end of wxApp::OnInitGui
0e320a79 670
9ed0fac8
DW
671//
672// Static member initialization
673//
d88de032 674wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
0e320a79
DW
675
676wxApp::wxApp()
677{
d88de032
DW
678 m_topWindow = NULL;
679 wxTheApp = this;
680 m_wantDebugOutput = TRUE;
681
682 argc = 0;
683 argv = NULL;
9ed0fac8 684 m_nPrintMode = wxPRINT_WINDOWS;
d88de032 685 m_exitOnFrameDelete = TRUE;
9ed0fac8 686 m_bAuto3D = TRUE;
468e327a 687 m_hMq = 0;
3958ae62
SN
688 m_maxSocketHandles = 0;
689 m_maxSocketNr = 0;
690 m_sockCallbackInfo = 0;
8df85a61 691} // end of wxApp::wxApp
d88de032
DW
692
693wxApp::~wxApp()
694{
8df85a61 695 //
d88de032 696 // Delete command-line args
8df85a61 697 //
039bec17 698#if wxUSE_UNICODE
8df85a61
DW
699 int i;
700
d88de032
DW
701 for (i = 0; i < argc; i++)
702 {
703 delete[] argv[i];
704 }
705 delete[] argv;
039bec17 706#endif
8df85a61 707} // end of wxApp::~wxApp
0e320a79
DW
708
709bool wxApp::Initialized()
710{
d88de032
DW
711 if (GetTopWindow())
712 return TRUE;
713 else
714 return FALSE;
8df85a61 715} // end of wxApp::Initialized
0e320a79 716
9ed0fac8
DW
717//
718// Get and process a message, returning FALSE if WM_QUIT
719// received (and also set the flag telling the app to exit the main loop)
720//
3958ae62 721
d88de032
DW
722bool wxApp::DoMessage()
723{
468e327a 724 BOOL bRc = ::WinGetMsg(vHabmain, &svCurrentMsg, HWND(NULL), 0, 0);
9ed0fac8
DW
725
726 if (bRc == 0)
d88de032
DW
727 {
728 // got WM_QUIT
9ed0fac8 729 m_bKeepGoing = FALSE;
d88de032
DW
730 return FALSE;
731 }
9ed0fac8 732 else if (bRc == -1)
d88de032
DW
733 {
734 // should never happen, but let's test for it nevertheless
735 wxLogLastError("GetMessage");
736 }
737 else
738 {
739#if wxUSE_THREADS
9ed0fac8
DW
740 wxASSERT_MSG( wxThread::IsMain()
741 ,wxT("only the main thread can process Windows messages")
742 );
d88de032 743
9ed0fac8
DW
744 static bool sbHadGuiLock = TRUE;
745 static wxMsgArray svSavedMessages;
d88de032 746
9ed0fac8 747 //
8df85a61 748 // If a secondary thread owns is doing GUI calls, save all messages for
d88de032
DW
749 // later processing - we can't process them right now because it will
750 // lead to recursive library calls (and we're not reentrant)
9ed0fac8
DW
751 //
752 if (!wxGuiOwnedByMainThread())
d88de032 753 {
9ed0fac8 754 sbHadGuiLock = FALSE;
d88de032 755
8df85a61
DW
756 //
757 // Leave out WM_COMMAND messages: too dangerous, sometimes
d88de032 758 // the message will be processed twice
8df85a61 759 //
d88de032 760 if ( !wxIsWaitingForThread() ||
9ed0fac8 761 svCurrentMsg.msg != WM_COMMAND )
d88de032 762 {
9ed0fac8 763 svSavedMessages.Add(svCurrentMsg);
d88de032 764 }
d88de032
DW
765 return TRUE;
766 }
767 else
768 {
9ed0fac8 769 //
8df85a61 770 // Have we just regained the GUI lock? if so, post all of the saved
d88de032
DW
771 // messages
772 //
9ed0fac8 773 if (!sbHadGuiLock )
d88de032 774 {
9ed0fac8 775 sbHadGuiLock = TRUE;
d88de032 776
9ed0fac8
DW
777 size_t nCount = svSavedMessages.Count();
778
779 for (size_t n = 0; n < nCount; n++)
d88de032 780 {
9ed0fac8 781 QMSG vMsg = svSavedMessages[n];
d88de032 782
9ed0fac8 783 if ( !ProcessMessage((WXMSG *)&vMsg) )
d88de032 784 {
43543d98 785 ::WinDispatchMsg(vHabmain, &vMsg);
d88de032
DW
786 }
787 }
9ed0fac8 788 svSavedMessages.Empty();
d88de032
DW
789 }
790 }
d88de032
DW
791#endif // wxUSE_THREADS
792
3febf684 793 //
d88de032 794 // Process the message
3febf684
DW
795 //
796 DoMessage((WXMSG *)&svCurrentMsg);
d88de032 797 }
d88de032 798 return TRUE;
8df85a61 799} // end of wxApp::DoMessage
d88de032 800
3febf684
DW
801void wxApp::DoMessage(
802 WXMSG* pMsg
803)
804{
805 if (!ProcessMessage((WXMSG *)&svCurrentMsg))
806 {
807 ::WinDispatchMsg(vHabmain, (PQMSG)&svCurrentMsg);
808 }
809} // end of wxApp::DoMessage
810
9ed0fac8
DW
811//////////////////////////////////////////////////////////////////////////////
812//
813// Keep trying to process messages until WM_QUIT
814// received.
815//
816// If there are messages to be processed, they will all be
817// processed and OnIdle will not be called.
818// When there are no more messages, OnIdle is called.
819// If OnIdle requests more time,
820// it will be repeatedly called so long as there are no pending messages.
821// A 'feature' of this is that once OnIdle has decided that no more processing
822// is required, then it won't get processing time until further messages
823// are processed (it'll sit in DoMessage).
824//
825//////////////////////////////////////////////////////////////////////////////
0e320a79
DW
826int wxApp::MainLoop()
827{
9ed0fac8 828 m_bKeepGoing = TRUE;
d88de032 829
9ed0fac8 830 while (m_bKeepGoing)
d88de032
DW
831 {
832#if wxUSE_THREADS
833 wxMutexGuiLeaveOrEnter();
834#endif // wxUSE_THREADS
3958ae62 835 while (!Pending() && ProcessIdle())
5b3ed311 836 {
3958ae62
SN
837 HandleSockets();
838 wxUsleep(10000);
5b3ed311 839 }
3958ae62
SN
840 HandleSockets();
841 if (Pending())
842 DoMessage();
843 else
844 wxUsleep(10000);
845
d88de032 846 }
9ed0fac8 847 return (int)svCurrentMsg.mp1;
8df85a61 848} // end of wxApp::MainLoop
0e320a79 849
9ed0fac8 850//
0e320a79 851// Returns TRUE if more time is needed.
9ed0fac8 852//
0e320a79
DW
853bool wxApp::ProcessIdle()
854{
9ed0fac8 855 wxIdleEvent vEvent;
0e320a79 856
9ed0fac8
DW
857 vEvent.SetEventObject(this);
858 ProcessEvent(vEvent);
859 return vEvent.MoreRequested();
8df85a61 860} // end of wxApp::ProcessIdle
d88de032 861
0e320a79
DW
862void wxApp::ExitMainLoop()
863{
9ed0fac8 864 m_bKeepGoing = FALSE;
0e320a79
DW
865}
866
0e320a79
DW
867bool wxApp::Pending()
868{
43543d98 869 return (::WinPeekMsg(vHabmain, (PQMSG)&svCurrentMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) != 0);
0e320a79
DW
870}
871
0e320a79
DW
872void wxApp::Dispatch()
873{
d88de032 874 DoMessage();
0e320a79
DW
875}
876
9ed0fac8
DW
877//////////////////////////////////////////////////////////////////////////////
878//
879// Give all windows a chance to preprocess
880// the message. Some may have accelerator tables, or have
881// MDI complications.
882//
883//////////////////////////////////////////////////////////////////////////////
884bool wxApp::ProcessMessage(
885 WXMSG* pWxmsg
886)
0e320a79 887{
f6bcfd97
BP
888 QMSG* pMsg = (PQMSG)pWxmsg;
889 HWND hWnd = pMsg->hwnd;
9ed0fac8
DW
890 wxWindow* pWndThis = wxFindWinFromHandle((WXHWND)hWnd);
891 wxWindow* pWnd;
d88de032 892
8df85a61
DW
893#if wxUSE_TOOLTIPS
894 //
895 // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
896 // popup the tooltip bubbles
897 //
f6bcfd97 898 if (pWndThis && (pMsg->msg == WM_MOUSEMOVE))
8df85a61
DW
899 {
900 wxToolTip* pToolTip = pWndThis->GetToolTip();
901 if (pToolTip)
902 {
903 pToolTip->RelayEvent(pWxmsg);
904 }
905 }
906#endif // wxUSE_TOOLTIPS
907
05a8bfed
DW
908 //
909 // We must relay Timer events to wxTimer's processing function
910 //
911 if (pMsg->msg == WM_TIMER)
496fd9fb 912 wxTimerProc(NULL, 0, (int)pMsg->mp1, 0);
05a8bfed 913
9ed0fac8 914 //
8df85a61 915 // For some composite controls (like a combobox), wndThis might be NULL
d88de032
DW
916 // because the subcontrol is not a wxWindow, but only the control itself
917 // is - try to catch this case
9ed0fac8
DW
918 //
919 while (hWnd && !pWndThis)
d88de032 920 {
9ed0fac8
DW
921 hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
922 pWndThis = wxFindWinFromHandle((WXHWND)hWnd);
d88de032 923 }
0e320a79 924
f6bcfd97
BP
925 //
926 // Try translations first; find the youngest window with
f09d8a3b
DW
927 // a translation table. OS/2 has case sensative accels, so
928 // this block, coded by BK, removes that and helps make them
929 // case insensative.
f6bcfd97 930 //
f09d8a3b 931 if(pMsg->msg == WM_CHAR)
f6bcfd97 932 {
f09d8a3b
DW
933 PBYTE pChmsg = (PBYTE)&(pMsg->msg);
934 USHORT uSch = CHARMSG(pChmsg)->chr;
935 bool bRc;
936
937 //
938 // Do not process keyup events
939 //
940 if(!(CHARMSG(pChmsg)->fs & KC_KEYUP))
941 {
942 if((CHARMSG(pChmsg)->fs & (KC_ALT | KC_CTRL)) && CHARMSG(pChmsg)->chr != 0)
f1f22049 943 CHARMSG(pChmsg)->chr = (USHORT)wxToupper((UCHAR)uSch);
f09d8a3b 944
7e99520b 945
5b3ed311
DW
946 for(pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent() )
947 {
948 if((bRc = pWnd->OS2TranslateMessage(pWxmsg)) == TRUE)
949 break;
950 }
7e99520b 951
f09d8a3b
DW
952 if(!bRc) // untranslated, should restore original value
953 CHARMSG(pChmsg)->chr = uSch;
954 }
f6bcfd97 955 }
8df85a61 956 //
d88de032 957 // Anyone for a non-translation message? Try youngest descendants first.
8df85a61 958 //
e604d44b
DW
959// for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
960// {
961// if (pWnd->OS2ProcessMessage(pWxmsg))
962// return TRUE;
963// }
d88de032 964 return FALSE;
8df85a61 965} // end of wxApp::ProcessMessage
0e320a79 966
9ed0fac8
DW
967void wxApp::OnIdle(
968 wxIdleEvent& rEvent
969)
d88de032 970{
9ed0fac8 971 static bool sbInOnIdle = FALSE;
d88de032 972
9ed0fac8 973 //
d88de032 974 // Avoid recursion (via ProcessEvent default case)
9ed0fac8 975 //
5b3ed311 976 if (sbInOnIdle)
d88de032 977 return;
0e320a79 978
9ed0fac8 979 sbInOnIdle = TRUE;
0e320a79 980
8df85a61
DW
981 //
982 // If there are pending events, we must process them: pending events
983 // are either events to the threads other than main or events posted
984 // with wxPostEvent() functions
985 //
986 ProcessPendingEvents();
987
9ed0fac8 988 //
d88de032 989 // 'Garbage' collection of windows deleted with Close().
9ed0fac8 990 //
d88de032 991 DeletePendingObjects();
0e320a79 992
d88de032 993#if wxUSE_LOG
8df85a61
DW
994 //
995 // Flush the logged messages if any
996 //
997 wxLog::FlushActive();
d88de032 998#endif // wxUSE_LOG
0e320a79 999
893758d5
DW
1000#if wxUSE_DC_CACHEING
1001 // automated DC cache management: clear the cached DCs and bitmap
1002 // if it's likely that the app has finished with them, that is, we
1003 // get an idle event and we're not dragging anything.
19193a2c
KB
1004 if (!::WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) &&
1005 !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) &&
1006 !::WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
893758d5
DW
1007 wxDC::ClearCache();
1008#endif // wxUSE_DC_CACHEING
1009
8df85a61 1010 //
d88de032 1011 // Send OnIdle events to all windows
8df85a61 1012 //
9ed0fac8 1013 if (SendIdleEvents())
d88de032 1014 {
9ed0fac8 1015 //
d88de032
DW
1016 // SendIdleEvents() returns TRUE if at least one window requested more
1017 // idle events
9ed0fac8
DW
1018 //
1019 rEvent.RequestMore(TRUE);
d88de032 1020 }
9ed0fac8 1021 sbInOnIdle = FALSE;
8df85a61 1022} // end of wxApp::OnIdle
9779893b 1023
0e320a79
DW
1024// Send idle event to all top-level windows
1025bool wxApp::SendIdleEvents()
1026{
9ed0fac8
DW
1027 bool bNeedMore = FALSE;
1028 wxWindowList::Node* pNode = wxTopLevelWindows.GetFirst();
d88de032 1029
9ed0fac8 1030 while (pNode)
d88de032 1031 {
9ed0fac8 1032 wxWindow* pWin = pNode->GetData();
0e320a79 1033
9ed0fac8
DW
1034 if (SendIdleEvents(pWin))
1035 bNeedMore = TRUE;
1036 pNode = pNode->GetNext();
1037 }
1038 return bNeedMore;
8df85a61 1039} // end of wxApp::SendIdleEvents
0e320a79 1040
9ed0fac8 1041//
0e320a79 1042// Send idle event to window and all subwindows
9ed0fac8
DW
1043//
1044bool wxApp::SendIdleEvents(
1045 wxWindow* pWin
1046)
0e320a79 1047{
9ed0fac8
DW
1048 bool bNeedMore = FALSE;
1049 wxIdleEvent vEvent;
1050
1051 vEvent.SetEventObject(pWin);
1052 pWin->GetEventHandler()->ProcessEvent(vEvent);
0e320a79 1053
9ed0fac8
DW
1054 if (vEvent.MoreRequested())
1055 bNeedMore = TRUE;
0e320a79 1056
9ed0fac8 1057 wxNode* pNode = pWin->GetChildren().First();
0e320a79 1058
9ed0fac8 1059 while (pNode)
d88de032 1060 {
9ed0fac8 1061 wxWindow* pWin = (wxWindow*) pNode->Data();
0e320a79 1062
9ed0fac8
DW
1063 if (SendIdleEvents(pWin))
1064 bNeedMore = TRUE;
1065 pNode = pNode->Next();
d88de032 1066 }
9ed0fac8 1067 return bNeedMore;
8df85a61 1068} // end of wxApp::SendIdleEvents
0e320a79
DW
1069
1070void wxApp::DeletePendingObjects()
1071{
9ed0fac8
DW
1072 wxNode* pNode = wxPendingDelete.First();
1073
1074 while (pNode)
d88de032 1075 {
9ed0fac8 1076 wxObject* pObj = (wxObject *)pNode->Data();
77cd51c3 1077
9ed0fac8 1078 delete pObj;
0e320a79 1079
9ed0fac8
DW
1080 if (wxPendingDelete.Member(pObj))
1081 delete pNode;
0e320a79 1082
9ed0fac8 1083 //
d88de032
DW
1084 // Deleting one object may have deleted other pending
1085 // objects, so start from beginning of list again.
9ed0fac8
DW
1086 //
1087 pNode = wxPendingDelete.First();
d88de032 1088 }
8df85a61 1089} // end of wxApp::DeletePendingObjects
0e320a79 1090
9ed0fac8
DW
1091void wxApp::OnEndSession(
1092 wxCloseEvent& WXUNUSED(rEvent))
0e320a79 1093{
d88de032
DW
1094 if (GetTopWindow())
1095 GetTopWindow()->Close(TRUE);
8df85a61 1096} // end of wxApp::OnEndSession
0e320a79 1097
9ed0fac8 1098//
d88de032
DW
1099// Default behaviour: close the application with prompts. The
1100// user can veto the close, and therefore the end session.
9ed0fac8
DW
1101//
1102void wxApp::OnQueryEndSession(
1103 wxCloseEvent& rEvent
1104)
0e320a79 1105{
d88de032
DW
1106 if (GetTopWindow())
1107 {
9ed0fac8
DW
1108 if (!GetTopWindow()->Close(!rEvent.CanVeto()))
1109 rEvent.Veto(TRUE);
d88de032 1110 }
8df85a61 1111} // end of wxApp::OnQueryEndSession
0e320a79
DW
1112
1113void wxExit()
1114{
d88de032
DW
1115 wxLogError(_("Fatal error: exiting"));
1116
1117 wxApp::CleanUp();
ee453a16 1118} // end of wxExit
0e320a79 1119
8df85a61 1120//
d88de032 1121// Yield to incoming messages
8df85a61 1122//
8461e4c2 1123bool wxApp::Yield(bool onlyIfNeeded)
0e320a79 1124{
8461e4c2
VZ
1125 static bool s_inYield = FALSE;
1126
1127 if ( s_inYield )
1128 {
1129 if ( !onlyIfNeeded )
1130 {
1131 wxFAIL_MSG( _T("wxYield() called recursively") );
1132 }
1133
1134 return FALSE;
1135 }
1136
9dea36ef 1137 HAB vHab = 0;
dde11e60 1138 QMSG vMsg;
ee453a16 1139
8df85a61
DW
1140 //
1141 // Disable log flushing from here because a call to wxYield() shouldn't
1142 // normally result in message boxes popping up &c
1143 //
1144 wxLog::Suspend();
1145
8461e4c2 1146 s_inYield = TRUE;
8b63ae37 1147
8df85a61 1148 //
d88de032
DW
1149 // We want to go back to the main message loop
1150 // if we see a WM_QUIT. (?)
8df85a61 1151 //
dde11e60 1152 while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT)
d88de032 1153 {
8df85a61
DW
1154#if wxUSE_THREADS
1155 wxMutexGuiLeaveOrEnter();
1156#endif // wxUSE_THREADS
dde11e60 1157 if (!wxTheApp->DoMessage())
d88de032
DW
1158 break;
1159 }
8df85a61 1160 //
d88de032 1161 // If they are pending events, we must process them.
8df85a61
DW
1162 //
1163 if (wxTheApp)
1164 wxTheApp->ProcessPendingEvents();
1165
1166 //
1167 // Let the logs be flashed again
1168 //
1169 wxLog::Resume();
8461e4c2 1170 s_inYield = FALSE;
d88de032 1171 return TRUE;
8df85a61 1172} // end of wxYield
d88de032 1173
9ed0fac8
DW
1174wxIcon wxApp::GetStdIcon(
1175 int nWhich
1176) const
d88de032 1177{
9ed0fac8 1178 switch(nWhich)
d88de032
DW
1179 {
1180 case wxICON_INFORMATION:
1181 return wxIcon("wxICON_INFO");
1182
1183 case wxICON_QUESTION:
1184 return wxIcon("wxICON_QUESTION");
1185
1186 case wxICON_EXCLAMATION:
1187 return wxIcon("wxICON_WARNING");
1188
1189 default:
1190 wxFAIL_MSG(wxT("requested non existent standard icon"));
1191 // still fall through
1192
1193 case wxICON_HAND:
1194 return wxIcon("wxICON_ERROR");
1195 }
d88de032 1196 return wxIcon("wxICON_ERROR");
8df85a61
DW
1197} // end of wxApp::GetStdIcon
1198
3958ae62
SN
1199int wxApp::AddSocketHandler(int handle, int mask,
1200 void (*callback)(void*), void * gsock)
1201{
1202 int find;
1203 struct GsocketCallbackInfo
1204 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
1205
1206 for (find = 0; find < m_maxSocketHandles; find++)
1207 if (CallbackInfo[find].handle == -1)
1208 break;
1209 if (find == m_maxSocketHandles)
1210 {
1211 // Allocate new memory
1212 m_sockCallbackInfo = realloc(m_sockCallbackInfo,
1213 (m_maxSocketHandles+=10)*
1214 sizeof(struct GsocketCallbackInfo));
1215 CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
1216 for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++)
1217 CallbackInfo[find].handle = -1;
1218 find = m_maxSocketHandles - 10;
1219 }
1220 CallbackInfo[find].proc = callback;
1221 CallbackInfo[find].type = mask;
1222 CallbackInfo[find].handle = handle;
1223 CallbackInfo[find].gsock = gsock;
1224 if (mask & wxSockReadMask)
1225 FD_SET(handle, &m_readfds);
1226 if (mask & wxSockWriteMask)
1227 FD_SET(handle, &m_writefds);
1228 if (handle >= m_maxSocketNr)
1229 m_maxSocketNr = handle + 1;
1230 return find;
1231}
1232
1233void wxApp::RemoveSocketHandler(int handle)
1234{
1235 struct GsocketCallbackInfo
1236 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
1237 if (handle < m_maxSocketHandles)
1238 {
1239 if (CallbackInfo[handle].type & wxSockReadMask)
1240 FD_CLR(CallbackInfo[handle].handle, &m_readfds);
1241 if (CallbackInfo[handle].type & wxSockWriteMask)
1242 FD_CLR(CallbackInfo[handle].handle, &m_writefds);
1243 CallbackInfo[handle].handle = -1;
1244 }
1245}
1246
8df85a61
DW
1247//-----------------------------------------------------------------------------
1248// wxWakeUpIdle
1249//-----------------------------------------------------------------------------
1250
1251void wxWakeUpIdle()
1252{
1253 //
1254 // Send the top window a dummy message so idle handler processing will
1255 // start up again. Doing it this way ensures that the idle handler
1256 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1257 // the same for the main app thread only)
1258 //
1259 wxWindow* pTopWindow = wxTheApp->GetTopWindow();
1260
1261 if (pTopWindow)
1262 {
1263 if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0))
1264 {
1265 //
1266 // Should never happen
1267 //
1268 wxLogLastError("PostMessage(WM_NULL)");
1269 }
1270 }
1271} // end of wxWakeUpIdle
d88de032 1272
76990f63 1273HAB wxGetInstance()
d88de032 1274{
76990f63 1275 return vHabmain;
d88de032
DW
1276}
1277
76990f63
DW
1278void wxSetInstance(
1279 HAB vHab
1280)
d88de032 1281{
76990f63 1282 vHabmain = vHab;
0e320a79
DW
1283}
1284