]> git.saurik.com Git - wxWidgets.git/blame - src/os2/app.cpp
fixed <iostream> detection
[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
3958ae62
SN
42#include <sys\ioctl.h>
43#include <sys\select.h>
29d83fc1
DW
44
45#else
46
65b851bb 47#include <nerrno.h>
29d83fc1
DW
48#include <ioctl.h>
49#include <select.h>
50
51#endif // ndef for __EMX__
52
3958ae62 53#ifndef __EMX__
29d83fc1 54
3958ae62
SN
55#define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
56int _System bsdselect(int,
57 struct fd_set *,
58 struct fd_set *,
59 struct fd_set *,
60 struct timeval *);
29d83fc1 61
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{
3b9e3455 329 APIRET rc;
914589c2
DW
330 ERRORID vError = 0L;
331 wxString sError;
3b9e3455 332
f23208ca
DW
333 if (!::WinRegisterClass( vHab
334 ,wxFrameClassName
51c1d535
DW
335 ,wxFrameWndProc
336 ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT | CS_CLIPCHILDREN
a0606634 337 ,sizeof(ULONG)
f23208ca 338 ))
d88de032 339 {
914589c2
DW
340 vError = ::WinGetLastError(vHab);
341 sError = wxPMErrorToStr(vError);
342 wxLogLastError(sError);
d88de032
DW
343 return FALSE;
344 }
345
f23208ca
DW
346 if (!::WinRegisterClass( vHab
347 ,wxFrameClassNameNoRedraw
51c1d535 348 ,wxWndProc
f23208ca 349 ,0
51c1d535 350 ,sizeof(ULONG)
f23208ca 351 ))
d88de032 352 {
914589c2
DW
353 vError = ::WinGetLastError(vHab);
354 sError = wxPMErrorToStr(vError);
355 wxLogLastError(sError);
d88de032
DW
356 return FALSE;
357 }
358
f23208ca
DW
359 if (!::WinRegisterClass( vHab
360 ,wxMDIFrameClassName
51c1d535 361 ,wxWndProc
f6bcfd97 362 ,CS_SIZEREDRAW | CS_MOVENOTIFY | CS_SYNCPAINT
51c1d535 363 ,sizeof(ULONG)
f23208ca 364 ))
d88de032 365 {
914589c2
DW
366 vError = ::WinGetLastError(vHab);
367 sError = wxPMErrorToStr(vError);
368 wxLogLastError(sError);
d88de032
DW
369 return FALSE;
370 }
0e320a79 371
f23208ca
DW
372 if (!::WinRegisterClass( vHab
373 ,wxMDIFrameClassNameNoRedraw
51c1d535 374 ,wxWndProc
f23208ca 375 ,0
51c1d535 376 ,sizeof(ULONG)
f23208ca 377 ))
d88de032 378 {
914589c2
DW
379 vError = ::WinGetLastError(vHab);
380 sError = wxPMErrorToStr(vError);
381 wxLogLastError(sError);
d88de032
DW
382 return FALSE;
383 }
384
f23208ca
DW
385 if (!::WinRegisterClass( vHab
386 ,wxMDIChildFrameClassName
51c1d535 387 ,wxWndProc
f23208ca 388 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_SYNCPAINT | CS_HITTEST
51c1d535 389 ,sizeof(ULONG)
f23208ca 390 ))
d88de032 391 {
914589c2
DW
392 vError = ::WinGetLastError(vHab);
393 sError = wxPMErrorToStr(vError);
394 wxLogLastError(sError);
d88de032
DW
395 return FALSE;
396 }
397
f23208ca
DW
398 if (!::WinRegisterClass( vHab
399 ,wxMDIChildFrameClassNameNoRedraw
51c1d535 400 ,wxWndProc
f23208ca 401 ,CS_HITTEST
51c1d535 402 ,sizeof(ULONG)
f23208ca 403 ))
d88de032 404 {
914589c2
DW
405 vError = ::WinGetLastError(vHab);
406 sError = wxPMErrorToStr(vError);
407 wxLogLastError(sError);
d88de032
DW
408 return FALSE;
409 }
410
f23208ca
DW
411 if (!::WinRegisterClass( vHab
412 ,wxPanelClassName
51c1d535 413 ,wxWndProc
f23208ca 414 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT
51c1d535 415 ,sizeof(ULONG)
f23208ca 416 ))
d88de032 417 {
914589c2
DW
418 vError = ::WinGetLastError(vHab);
419 sError = wxPMErrorToStr(vError);
420 wxLogLastError(sError);
d88de032
DW
421 return FALSE;
422 }
423
f23208ca
DW
424 if (!::WinRegisterClass( vHab
425 ,wxCanvasClassName
51c1d535 426 ,wxWndProc
e99762c0 427 ,CS_MOVENOTIFY | CS_SIZEREDRAW | CS_HITTEST | CS_SAVEBITS | CS_SYNCPAINT | CS_CLIPCHILDREN
51c1d535 428 ,sizeof(ULONG)
f23208ca 429 ))
d88de032 430 {
914589c2
DW
431 vError = ::WinGetLastError(vHab);
432 sError = wxPMErrorToStr(vError);
433 wxLogLastError(sError);
d88de032
DW
434 return FALSE;
435 }
d88de032 436 return TRUE;
8df85a61 437} // end of wxApp::RegisterWindowClasses
d88de032 438
8df85a61
DW
439//
440// Cleans up any wxWindows internal structures left lying around
441//
0e320a79
DW
442void wxApp::CleanUp()
443{
8df85a61
DW
444 //
445 // COMMON CLEANUP
446 //
d88de032
DW
447
448#if wxUSE_LOG
8df85a61
DW
449
450 //
451 // Flush the logged messages if any and install a 'safer' log target: the
d88de032
DW
452 // default one (wxLogGui) can't be used after the resources are freed just
453 // below and the user suppliedo ne might be even more unsafe (using any
454 // wxWindows GUI function is unsafe starting from now)
8df85a61 455 //
d88de032
DW
456 wxLog::DontCreateOnDemand();
457
8df85a61
DW
458 //
459 // This will flush the old messages if any
460 //
d88de032
DW
461 delete wxLog::SetActiveTarget(new wxLogStderr);
462#endif // wxUSE_LOG
463
8df85a61 464 //
d88de032 465 // One last chance for pending objects to be cleaned up
8df85a61 466 //
d88de032
DW
467 wxTheApp->DeletePendingObjects();
468
469 wxModule::CleanUpModules();
0e320a79
DW
470
471#if wxUSE_WX_RESOURCES
d88de032 472 wxCleanUpResourceSystem();
d88de032 473#endif
0e320a79 474
d88de032 475 wxDeleteStockObjects();
0e320a79 476
8df85a61 477 //
d88de032 478 // Destroy all GDI lists, etc.
8df85a61 479 //
d88de032 480 wxDeleteStockLists();
0e320a79 481
d88de032
DW
482 delete wxTheColourDatabase;
483 wxTheColourDatabase = NULL;
0e320a79 484
d88de032 485 wxBitmap::CleanUpHandlers();
0e320a79 486
d88de032
DW
487 delete[] wxBuffer;
488 wxBuffer = NULL;
0e320a79 489
8df85a61
DW
490 //
491 // PM-SPECIFIC CLEANUP
492 //
0e320a79 493
61243a51 494 // wxSetKeyboardHook(FALSE);
9ed0fac8 495
d88de032 496 if (wxSTD_FRAME_ICON)
9ed0fac8 497 ::WinFreeFileIcon(wxSTD_FRAME_ICON);
d88de032 498 if (wxSTD_MDICHILDFRAME_ICON)
9ed0fac8 499 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON);
d88de032 500 if (wxSTD_MDIPARENTFRAME_ICON)
9ed0fac8 501 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON);
d88de032
DW
502
503 if (wxDEFAULT_FRAME_ICON)
9ed0fac8 504 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON);
d88de032 505 if (wxDEFAULT_MDICHILDFRAME_ICON)
9ed0fac8 506 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON);
d88de032 507 if (wxDEFAULT_MDIPARENTFRAME_ICON)
9ed0fac8
DW
508 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
509
d88de032
DW
510 if ( wxDisableButtonBrush )
511 {
512// TODO: ::DeleteObject( wxDisableButtonBrush );
513 }
514
515 if (wxWinHandleList)
516 delete wxWinHandleList;
517
d88de032 518 delete wxPendingEvents;
8df85a61 519#if wxUSE_THREADS
d88de032
DW
520 delete wxPendingEventsLocker;
521 // If we don't do the following, we get an apparent memory leak.
522 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
523#endif
0e320a79 524
d88de032 525 wxClassInfo::CleanUpClasses();
0e320a79 526
468e327a
SN
527 // Delete Message queue
528 if (wxTheApp->m_hMq)
529 ::WinDestroyMsgQueue(wxTheApp->m_hMq);
530
d88de032
DW
531 delete wxTheApp;
532 wxTheApp = NULL;
77cd51c3 533
0e320a79 534#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
d88de032
DW
535 // At this point we want to check if there are any memory
536 // blocks that aren't part of the wxDebugContext itself,
537 // as a special case. Then when dumping we need to ignore
538 // wxDebugContext, too.
539 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
540 {
541 wxLogDebug(wxT("There were memory leaks."));
542 wxDebugContext::Dump();
543 wxDebugContext::PrintStatistics();
544 }
545 // wxDebugContext::SetStream(NULL, NULL);
0e320a79 546#endif
77cd51c3 547
d88de032
DW
548#if wxUSE_LOG
549 // do it as the very last thing because everything else can log messages
550 delete wxLog::SetActiveTarget(NULL);
551#endif // wxUSE_LOG
8df85a61 552} // end of wxApp::CleanUp
0e320a79 553
7e99520b
DW
554//----------------------------------------------------------------------
555// Main wxWindows entry point
556//----------------------------------------------------------------------
9ed0fac8
DW
557int wxEntry(
558 int argc
559, char* argv[]
560)
d88de032 561{
9dea36ef 562 HAB vHab = 0;
d88de032 563
9ed0fac8
DW
564 if (!wxApp::Initialize(vHab))
565 return 0;
d88de032 566
9ed0fac8
DW
567 //
568 // create the application object or ensure that one already exists
569 //
570 if (!wxTheApp)
571 {
426d5745
DW
572 // The app may have declared a global application object, but we recommend
573 // the IMPLEMENT_APP macro is used instead, which sets an initializer
574 // function for delayed, dynamic app object construction.
575 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
576 wxT("No initializer - use IMPLEMENT_APP macro.") );
577 wxTheApp = (*wxApp::GetInitializerFunction()) ();
9ed0fac8 578 }
426d5745 579 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
9ed0fac8 580 wxTheApp->argc = argc;
d88de032 581
9ed0fac8
DW
582#if wxUSE_UNICODE
583 wxTheApp->argv = new wxChar*[argc+1];
584
585 int nArgc = 0;
586
587 while (nArgc < argc)
588 {
589 wxTheApp->argv[nArgc] = wxStrdup(wxConvLibc.cMB2WX(argv[nArgc]));
590 nArgc++;
591 }
592 wxTheApp->argv[nArgc] = (wxChar *)NULL;
593#else
594 wxTheApp->argv = argv;
595#endif
d88de032 596
9ed0fac8 597 wxString sName(wxFileNameFromPath(argv[0]));
d88de032 598
9ed0fac8
DW
599 wxStripExtension(sName);
600 wxTheApp->SetAppName(sName);
d88de032 601
9ed0fac8 602 int nRetValue = 0;
d88de032 603
9ed0fac8
DW
604 if (!wxTheApp->OnInitGui())
605 nRetValue = -1;
d88de032 606
9ed0fac8
DW
607 if (nRetValue == 0)
608 {
609 if (wxTheApp->OnInit())
d88de032 610 {
7bed7a50 611 nRetValue = wxTheApp->OnRun();
7bed7a50 612 }
51c1d535
DW
613 // Normal exit
614 wxWindow* pTopWindow = wxTheApp->GetTopWindow();
615 if (pTopWindow)
d88de032 616 {
51c1d535
DW
617 // Forcibly delete the window.
618 if (pTopWindow->IsKindOf(CLASSINFO(wxFrame)) ||
619 pTopWindow->IsKindOf(CLASSINFO(wxDialog)) )
620 {
621 pTopWindow->Close(TRUE);
622 wxTheApp->DeletePendingObjects();
623 }
624 else
625 {
626 delete pTopWindow;
627 wxTheApp->SetTopWindow(NULL);
628 }
d88de032 629 }
9ed0fac8 630 }
7e99520b
DW
631 else // app initialization failed
632 {
633 wxLogLastError(" Gui initialization failed, exitting");
634 }
635#if wxUSE_CONSOLEDEBUG
636 printf("wxTheApp->OnExit ");
637 fflush(stdout);
638#endif
9ed0fac8 639 wxTheApp->OnExit();
7e99520b
DW
640#if wxUSE_CONSOLEDEBUG
641 printf("wxApp::CleanUp ");
642 fflush(stdout);
643#endif
9ed0fac8 644 wxApp::CleanUp();
7e99520b
DW
645#if wxUSE_CONSOLEDEBUG
646 printf("return %i ", nRetValue);
647 fflush(stdout);
648#endif
9ed0fac8 649 return(nRetValue);
8df85a61 650} // end of wxEntry
77cd51c3 651
9ed0fac8 652bool wxApp::OnInitGui()
d88de032 653{
914589c2
DW
654 ERRORID vError;
655 wxString sError;
77cd51c3 656
f23208ca 657 m_hMq = ::WinCreateMsgQueue(vHabmain, 0);
914589c2
DW
658 if (!m_hMq)
659 {
660 vError = ::WinGetLastError(vHabmain);
661 sError = wxPMErrorToStr(vError);
662 wxLogDebug(sError);
663 return FALSE;
664 }
9ed0fac8 665 return TRUE;
8df85a61 666} // end of wxApp::OnInitGui
0e320a79 667
9ed0fac8
DW
668//
669// Static member initialization
670//
d88de032 671wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
0e320a79
DW
672
673wxApp::wxApp()
674{
d88de032
DW
675 m_topWindow = NULL;
676 wxTheApp = this;
677 m_wantDebugOutput = TRUE;
678
679 argc = 0;
680 argv = NULL;
9ed0fac8 681 m_nPrintMode = wxPRINT_WINDOWS;
d88de032 682 m_exitOnFrameDelete = TRUE;
9ed0fac8 683 m_bAuto3D = TRUE;
468e327a 684 m_hMq = 0;
3958ae62
SN
685 m_maxSocketHandles = 0;
686 m_maxSocketNr = 0;
687 m_sockCallbackInfo = 0;
8df85a61 688} // end of wxApp::wxApp
d88de032
DW
689
690wxApp::~wxApp()
691{
8df85a61 692 //
d88de032 693 // Delete command-line args
8df85a61 694 //
039bec17 695#if wxUSE_UNICODE
8df85a61
DW
696 int i;
697
d88de032
DW
698 for (i = 0; i < argc; i++)
699 {
700 delete[] argv[i];
701 }
702 delete[] argv;
039bec17 703#endif
8df85a61 704} // end of wxApp::~wxApp
0e320a79
DW
705
706bool wxApp::Initialized()
707{
d88de032
DW
708 if (GetTopWindow())
709 return TRUE;
710 else
711 return FALSE;
8df85a61 712} // end of wxApp::Initialized
0e320a79 713
9ed0fac8
DW
714//
715// Get and process a message, returning FALSE if WM_QUIT
716// received (and also set the flag telling the app to exit the main loop)
717//
3958ae62 718
d88de032
DW
719bool wxApp::DoMessage()
720{
468e327a 721 BOOL bRc = ::WinGetMsg(vHabmain, &svCurrentMsg, HWND(NULL), 0, 0);
9ed0fac8
DW
722
723 if (bRc == 0)
d88de032
DW
724 {
725 // got WM_QUIT
9ed0fac8 726 m_bKeepGoing = FALSE;
d88de032
DW
727 return FALSE;
728 }
9ed0fac8 729 else if (bRc == -1)
d88de032
DW
730 {
731 // should never happen, but let's test for it nevertheless
732 wxLogLastError("GetMessage");
733 }
734 else
735 {
736#if wxUSE_THREADS
9ed0fac8
DW
737 wxASSERT_MSG( wxThread::IsMain()
738 ,wxT("only the main thread can process Windows messages")
739 );
d88de032 740
9ed0fac8
DW
741 static bool sbHadGuiLock = TRUE;
742 static wxMsgArray svSavedMessages;
d88de032 743
9ed0fac8 744 //
8df85a61 745 // If a secondary thread owns is doing GUI calls, save all messages for
d88de032
DW
746 // later processing - we can't process them right now because it will
747 // lead to recursive library calls (and we're not reentrant)
9ed0fac8
DW
748 //
749 if (!wxGuiOwnedByMainThread())
d88de032 750 {
9ed0fac8 751 sbHadGuiLock = FALSE;
d88de032 752
8df85a61
DW
753 //
754 // Leave out WM_COMMAND messages: too dangerous, sometimes
d88de032 755 // the message will be processed twice
8df85a61 756 //
d88de032 757 if ( !wxIsWaitingForThread() ||
9ed0fac8 758 svCurrentMsg.msg != WM_COMMAND )
d88de032 759 {
9ed0fac8 760 svSavedMessages.Add(svCurrentMsg);
d88de032 761 }
d88de032
DW
762 return TRUE;
763 }
764 else
765 {
9ed0fac8 766 //
8df85a61 767 // Have we just regained the GUI lock? if so, post all of the saved
d88de032
DW
768 // messages
769 //
9ed0fac8 770 if (!sbHadGuiLock )
d88de032 771 {
9ed0fac8 772 sbHadGuiLock = TRUE;
d88de032 773
9ed0fac8
DW
774 size_t nCount = svSavedMessages.Count();
775
776 for (size_t n = 0; n < nCount; n++)
d88de032 777 {
9ed0fac8 778 QMSG vMsg = svSavedMessages[n];
d88de032 779
9ed0fac8 780 if ( !ProcessMessage((WXMSG *)&vMsg) )
d88de032 781 {
43543d98 782 ::WinDispatchMsg(vHabmain, &vMsg);
d88de032
DW
783 }
784 }
9ed0fac8 785 svSavedMessages.Empty();
d88de032
DW
786 }
787 }
d88de032
DW
788#endif // wxUSE_THREADS
789
3febf684 790 //
d88de032 791 // Process the message
3febf684
DW
792 //
793 DoMessage((WXMSG *)&svCurrentMsg);
d88de032 794 }
d88de032 795 return TRUE;
8df85a61 796} // end of wxApp::DoMessage
d88de032 797
3febf684
DW
798void wxApp::DoMessage(
799 WXMSG* pMsg
800)
801{
802 if (!ProcessMessage((WXMSG *)&svCurrentMsg))
803 {
804 ::WinDispatchMsg(vHabmain, (PQMSG)&svCurrentMsg);
805 }
806} // end of wxApp::DoMessage
807
9ed0fac8
DW
808//////////////////////////////////////////////////////////////////////////////
809//
810// Keep trying to process messages until WM_QUIT
811// received.
812//
813// If there are messages to be processed, they will all be
814// processed and OnIdle will not be called.
815// When there are no more messages, OnIdle is called.
816// If OnIdle requests more time,
817// it will be repeatedly called so long as there are no pending messages.
818// A 'feature' of this is that once OnIdle has decided that no more processing
819// is required, then it won't get processing time until further messages
820// are processed (it'll sit in DoMessage).
821//
822//////////////////////////////////////////////////////////////////////////////
0e320a79
DW
823int wxApp::MainLoop()
824{
9ed0fac8 825 m_bKeepGoing = TRUE;
d88de032 826
9ed0fac8 827 while (m_bKeepGoing)
d88de032
DW
828 {
829#if wxUSE_THREADS
830 wxMutexGuiLeaveOrEnter();
831#endif // wxUSE_THREADS
3958ae62 832 while (!Pending() && ProcessIdle())
5b3ed311 833 {
3958ae62
SN
834 HandleSockets();
835 wxUsleep(10000);
5b3ed311 836 }
3958ae62
SN
837 HandleSockets();
838 if (Pending())
839 DoMessage();
840 else
841 wxUsleep(10000);
842
d88de032 843 }
9ed0fac8 844 return (int)svCurrentMsg.mp1;
8df85a61 845} // end of wxApp::MainLoop
0e320a79 846
9ed0fac8 847//
0e320a79 848// Returns TRUE if more time is needed.
9ed0fac8 849//
0e320a79
DW
850bool wxApp::ProcessIdle()
851{
9ed0fac8 852 wxIdleEvent vEvent;
0e320a79 853
9ed0fac8
DW
854 vEvent.SetEventObject(this);
855 ProcessEvent(vEvent);
856 return vEvent.MoreRequested();
8df85a61 857} // end of wxApp::ProcessIdle
d88de032 858
0e320a79
DW
859void wxApp::ExitMainLoop()
860{
9ed0fac8 861 m_bKeepGoing = FALSE;
0e320a79
DW
862}
863
0e320a79
DW
864bool wxApp::Pending()
865{
43543d98 866 return (::WinPeekMsg(vHabmain, (PQMSG)&svCurrentMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) != 0);
0e320a79
DW
867}
868
0e320a79
DW
869void wxApp::Dispatch()
870{
d88de032 871 DoMessage();
0e320a79
DW
872}
873
9ed0fac8
DW
874//////////////////////////////////////////////////////////////////////////////
875//
876// Give all windows a chance to preprocess
877// the message. Some may have accelerator tables, or have
878// MDI complications.
879//
880//////////////////////////////////////////////////////////////////////////////
881bool wxApp::ProcessMessage(
882 WXMSG* pWxmsg
883)
0e320a79 884{
f6bcfd97
BP
885 QMSG* pMsg = (PQMSG)pWxmsg;
886 HWND hWnd = pMsg->hwnd;
9ed0fac8
DW
887 wxWindow* pWndThis = wxFindWinFromHandle((WXHWND)hWnd);
888 wxWindow* pWnd;
d88de032 889
8df85a61
DW
890#if wxUSE_TOOLTIPS
891 //
892 // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
893 // popup the tooltip bubbles
894 //
f6bcfd97 895 if (pWndThis && (pMsg->msg == WM_MOUSEMOVE))
8df85a61
DW
896 {
897 wxToolTip* pToolTip = pWndThis->GetToolTip();
898 if (pToolTip)
899 {
900 pToolTip->RelayEvent(pWxmsg);
901 }
902 }
903#endif // wxUSE_TOOLTIPS
904
05a8bfed
DW
905 //
906 // We must relay Timer events to wxTimer's processing function
907 //
908 if (pMsg->msg == WM_TIMER)
496fd9fb 909 wxTimerProc(NULL, 0, (int)pMsg->mp1, 0);
05a8bfed 910
9ed0fac8 911 //
8df85a61 912 // For some composite controls (like a combobox), wndThis might be NULL
d88de032
DW
913 // because the subcontrol is not a wxWindow, but only the control itself
914 // is - try to catch this case
9ed0fac8
DW
915 //
916 while (hWnd && !pWndThis)
d88de032 917 {
9ed0fac8
DW
918 hWnd = ::WinQueryWindow(hWnd, QW_PARENT);
919 pWndThis = wxFindWinFromHandle((WXHWND)hWnd);
d88de032 920 }
0e320a79 921
f6bcfd97
BP
922 //
923 // Try translations first; find the youngest window with
f09d8a3b
DW
924 // a translation table. OS/2 has case sensative accels, so
925 // this block, coded by BK, removes that and helps make them
926 // case insensative.
f6bcfd97 927 //
f09d8a3b 928 if(pMsg->msg == WM_CHAR)
f6bcfd97 929 {
f09d8a3b
DW
930 PBYTE pChmsg = (PBYTE)&(pMsg->msg);
931 USHORT uSch = CHARMSG(pChmsg)->chr;
932 bool bRc;
933
934 //
935 // Do not process keyup events
936 //
937 if(!(CHARMSG(pChmsg)->fs & KC_KEYUP))
938 {
939 if((CHARMSG(pChmsg)->fs & (KC_ALT | KC_CTRL)) && CHARMSG(pChmsg)->chr != 0)
f1f22049 940 CHARMSG(pChmsg)->chr = (USHORT)wxToupper((UCHAR)uSch);
f09d8a3b 941
7e99520b 942
5b3ed311
DW
943 for(pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent() )
944 {
945 if((bRc = pWnd->OS2TranslateMessage(pWxmsg)) == TRUE)
946 break;
947 }
7e99520b 948
f09d8a3b
DW
949 if(!bRc) // untranslated, should restore original value
950 CHARMSG(pChmsg)->chr = uSch;
951 }
f6bcfd97 952 }
8df85a61 953 //
d88de032 954 // Anyone for a non-translation message? Try youngest descendants first.
8df85a61 955 //
e604d44b
DW
956// for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
957// {
958// if (pWnd->OS2ProcessMessage(pWxmsg))
959// return TRUE;
960// }
d88de032 961 return FALSE;
8df85a61 962} // end of wxApp::ProcessMessage
0e320a79 963
9ed0fac8
DW
964void wxApp::OnIdle(
965 wxIdleEvent& rEvent
966)
d88de032 967{
9ed0fac8 968 static bool sbInOnIdle = FALSE;
d88de032 969
9ed0fac8 970 //
d88de032 971 // Avoid recursion (via ProcessEvent default case)
9ed0fac8 972 //
5b3ed311 973 if (sbInOnIdle)
d88de032 974 return;
0e320a79 975
9ed0fac8 976 sbInOnIdle = TRUE;
0e320a79 977
8df85a61
DW
978 //
979 // If there are pending events, we must process them: pending events
980 // are either events to the threads other than main or events posted
981 // with wxPostEvent() functions
982 //
983 ProcessPendingEvents();
984
9ed0fac8 985 //
d88de032 986 // 'Garbage' collection of windows deleted with Close().
9ed0fac8 987 //
d88de032 988 DeletePendingObjects();
0e320a79 989
d88de032 990#if wxUSE_LOG
8df85a61
DW
991 //
992 // Flush the logged messages if any
993 //
994 wxLog::FlushActive();
d88de032 995#endif // wxUSE_LOG
0e320a79 996
8df85a61 997 //
d88de032 998 // Send OnIdle events to all windows
8df85a61 999 //
9ed0fac8 1000 if (SendIdleEvents())
d88de032 1001 {
9ed0fac8 1002 //
d88de032
DW
1003 // SendIdleEvents() returns TRUE if at least one window requested more
1004 // idle events
9ed0fac8
DW
1005 //
1006 rEvent.RequestMore(TRUE);
d88de032 1007 }
9ed0fac8 1008 sbInOnIdle = FALSE;
8df85a61 1009} // end of wxApp::OnIdle
9779893b 1010
0e320a79
DW
1011// Send idle event to all top-level windows
1012bool wxApp::SendIdleEvents()
1013{
9ed0fac8
DW
1014 bool bNeedMore = FALSE;
1015 wxWindowList::Node* pNode = wxTopLevelWindows.GetFirst();
d88de032 1016
9ed0fac8 1017 while (pNode)
d88de032 1018 {
9ed0fac8 1019 wxWindow* pWin = pNode->GetData();
0e320a79 1020
9ed0fac8
DW
1021 if (SendIdleEvents(pWin))
1022 bNeedMore = TRUE;
1023 pNode = pNode->GetNext();
1024 }
1025 return bNeedMore;
8df85a61 1026} // end of wxApp::SendIdleEvents
0e320a79 1027
9ed0fac8 1028//
0e320a79 1029// Send idle event to window and all subwindows
9ed0fac8
DW
1030//
1031bool wxApp::SendIdleEvents(
1032 wxWindow* pWin
1033)
0e320a79 1034{
9ed0fac8
DW
1035 bool bNeedMore = FALSE;
1036 wxIdleEvent vEvent;
1037
1038 vEvent.SetEventObject(pWin);
1039 pWin->GetEventHandler()->ProcessEvent(vEvent);
0e320a79 1040
9ed0fac8
DW
1041 if (vEvent.MoreRequested())
1042 bNeedMore = TRUE;
0e320a79 1043
9ed0fac8 1044 wxNode* pNode = pWin->GetChildren().First();
0e320a79 1045
9ed0fac8 1046 while (pNode)
d88de032 1047 {
9ed0fac8 1048 wxWindow* pWin = (wxWindow*) pNode->Data();
0e320a79 1049
9ed0fac8
DW
1050 if (SendIdleEvents(pWin))
1051 bNeedMore = TRUE;
1052 pNode = pNode->Next();
d88de032 1053 }
9ed0fac8 1054 return bNeedMore;
8df85a61 1055} // end of wxApp::SendIdleEvents
0e320a79
DW
1056
1057void wxApp::DeletePendingObjects()
1058{
9ed0fac8
DW
1059 wxNode* pNode = wxPendingDelete.First();
1060
1061 while (pNode)
d88de032 1062 {
9ed0fac8 1063 wxObject* pObj = (wxObject *)pNode->Data();
77cd51c3 1064
9ed0fac8 1065 delete pObj;
0e320a79 1066
9ed0fac8
DW
1067 if (wxPendingDelete.Member(pObj))
1068 delete pNode;
0e320a79 1069
9ed0fac8 1070 //
d88de032
DW
1071 // Deleting one object may have deleted other pending
1072 // objects, so start from beginning of list again.
9ed0fac8
DW
1073 //
1074 pNode = wxPendingDelete.First();
d88de032 1075 }
8df85a61 1076} // end of wxApp::DeletePendingObjects
0e320a79 1077
9ed0fac8
DW
1078void wxApp::OnEndSession(
1079 wxCloseEvent& WXUNUSED(rEvent))
0e320a79 1080{
d88de032
DW
1081 if (GetTopWindow())
1082 GetTopWindow()->Close(TRUE);
8df85a61 1083} // end of wxApp::OnEndSession
0e320a79 1084
9ed0fac8 1085//
d88de032
DW
1086// Default behaviour: close the application with prompts. The
1087// user can veto the close, and therefore the end session.
9ed0fac8
DW
1088//
1089void wxApp::OnQueryEndSession(
1090 wxCloseEvent& rEvent
1091)
0e320a79 1092{
d88de032
DW
1093 if (GetTopWindow())
1094 {
9ed0fac8
DW
1095 if (!GetTopWindow()->Close(!rEvent.CanVeto()))
1096 rEvent.Veto(TRUE);
d88de032 1097 }
8df85a61 1098} // end of wxApp::OnQueryEndSession
0e320a79
DW
1099
1100void wxExit()
1101{
d88de032
DW
1102 wxLogError(_("Fatal error: exiting"));
1103
1104 wxApp::CleanUp();
ee453a16 1105} // end of wxExit
0e320a79 1106
8b63ae37
DW
1107static bool gs_inYield = FALSE;
1108
8df85a61 1109//
d88de032 1110// Yield to incoming messages
8df85a61 1111//
0e320a79
DW
1112bool wxYield()
1113{
9dea36ef 1114 HAB vHab = 0;
dde11e60 1115 QMSG vMsg;
ee453a16 1116
8df85a61
DW
1117 //
1118 // Disable log flushing from here because a call to wxYield() shouldn't
1119 // normally result in message boxes popping up &c
1120 //
1121 wxLog::Suspend();
1122
8b63ae37
DW
1123 gs_inYield = TRUE;
1124
8df85a61 1125 //
d88de032
DW
1126 // We want to go back to the main message loop
1127 // if we see a WM_QUIT. (?)
8df85a61 1128 //
dde11e60 1129 while (::WinPeekMsg(vHab, &vMsg, (HWND)NULL, 0, 0, PM_NOREMOVE) && vMsg.msg != WM_QUIT)
d88de032 1130 {
8df85a61
DW
1131#if wxUSE_THREADS
1132 wxMutexGuiLeaveOrEnter();
1133#endif // wxUSE_THREADS
dde11e60 1134 if (!wxTheApp->DoMessage())
d88de032
DW
1135 break;
1136 }
8df85a61 1137 //
d88de032 1138 // If they are pending events, we must process them.
8df85a61
DW
1139 //
1140 if (wxTheApp)
1141 wxTheApp->ProcessPendingEvents();
1142
1143 //
1144 // Let the logs be flashed again
1145 //
1146 wxLog::Resume();
8b63ae37 1147 gs_inYield = FALSE;
d88de032 1148 return TRUE;
8df85a61 1149} // end of wxYield
d88de032 1150
8b63ae37
DW
1151// Yield to incoming messages; but fail silently if recursion is detected.
1152bool wxYieldIfNeeded()
1153{
1154 if (gs_inYield)
1155 return FALSE;
29d83fc1 1156
8b63ae37
DW
1157 return wxYield();
1158}
1159
9ed0fac8
DW
1160wxIcon wxApp::GetStdIcon(
1161 int nWhich
1162) const
d88de032 1163{
9ed0fac8 1164 switch(nWhich)
d88de032
DW
1165 {
1166 case wxICON_INFORMATION:
1167 return wxIcon("wxICON_INFO");
1168
1169 case wxICON_QUESTION:
1170 return wxIcon("wxICON_QUESTION");
1171
1172 case wxICON_EXCLAMATION:
1173 return wxIcon("wxICON_WARNING");
1174
1175 default:
1176 wxFAIL_MSG(wxT("requested non existent standard icon"));
1177 // still fall through
1178
1179 case wxICON_HAND:
1180 return wxIcon("wxICON_ERROR");
1181 }
d88de032 1182 return wxIcon("wxICON_ERROR");
8df85a61
DW
1183} // end of wxApp::GetStdIcon
1184
3958ae62
SN
1185int wxApp::AddSocketHandler(int handle, int mask,
1186 void (*callback)(void*), void * gsock)
1187{
1188 int find;
1189 struct GsocketCallbackInfo
1190 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
1191
1192 for (find = 0; find < m_maxSocketHandles; find++)
1193 if (CallbackInfo[find].handle == -1)
1194 break;
1195 if (find == m_maxSocketHandles)
1196 {
1197 // Allocate new memory
1198 m_sockCallbackInfo = realloc(m_sockCallbackInfo,
1199 (m_maxSocketHandles+=10)*
1200 sizeof(struct GsocketCallbackInfo));
1201 CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
1202 for (find = m_maxSocketHandles - 10; find < m_maxSocketHandles; find++)
1203 CallbackInfo[find].handle = -1;
1204 find = m_maxSocketHandles - 10;
1205 }
1206 CallbackInfo[find].proc = callback;
1207 CallbackInfo[find].type = mask;
1208 CallbackInfo[find].handle = handle;
1209 CallbackInfo[find].gsock = gsock;
1210 if (mask & wxSockReadMask)
1211 FD_SET(handle, &m_readfds);
1212 if (mask & wxSockWriteMask)
1213 FD_SET(handle, &m_writefds);
1214 if (handle >= m_maxSocketNr)
1215 m_maxSocketNr = handle + 1;
1216 return find;
1217}
1218
1219void wxApp::RemoveSocketHandler(int handle)
1220{
1221 struct GsocketCallbackInfo
1222 *CallbackInfo = (struct GsocketCallbackInfo *)m_sockCallbackInfo;
1223 if (handle < m_maxSocketHandles)
1224 {
1225 if (CallbackInfo[handle].type & wxSockReadMask)
1226 FD_CLR(CallbackInfo[handle].handle, &m_readfds);
1227 if (CallbackInfo[handle].type & wxSockWriteMask)
1228 FD_CLR(CallbackInfo[handle].handle, &m_writefds);
1229 CallbackInfo[handle].handle = -1;
1230 }
1231}
1232
8df85a61
DW
1233//-----------------------------------------------------------------------------
1234// wxWakeUpIdle
1235//-----------------------------------------------------------------------------
1236
1237void wxWakeUpIdle()
1238{
1239 //
1240 // Send the top window a dummy message so idle handler processing will
1241 // start up again. Doing it this way ensures that the idle handler
1242 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1243 // the same for the main app thread only)
1244 //
1245 wxWindow* pTopWindow = wxTheApp->GetTopWindow();
1246
1247 if (pTopWindow)
1248 {
1249 if ( !::WinPostMsg(GetHwndOf(pTopWindow), WM_NULL, (MPARAM)0, (MPARAM)0))
1250 {
1251 //
1252 // Should never happen
1253 //
1254 wxLogLastError("PostMessage(WM_NULL)");
1255 }
1256 }
1257} // end of wxWakeUpIdle
d88de032 1258
76990f63 1259HAB wxGetInstance()
d88de032 1260{
76990f63 1261 return vHabmain;
d88de032
DW
1262}
1263
76990f63
DW
1264void wxSetInstance(
1265 HAB vHab
1266)
d88de032 1267{
76990f63 1268 vHabmain = vHab;
0e320a79
DW
1269}
1270