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