]> git.saurik.com Git - wxWidgets.git/blob - src/msw/app.cpp
Compiles for Nano-X again
[wxWidgets.git] / src / msw / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: app.cpp
3 // Purpose: wxApp
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "app.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #if defined(__BORLANDC__)
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/frame.h"
33 #include "wx/app.h"
34 #include "wx/utils.h"
35 #include "wx/gdicmn.h"
36 #include "wx/pen.h"
37 #include "wx/brush.h"
38 #include "wx/cursor.h"
39 #include "wx/icon.h"
40 #include "wx/palette.h"
41 #include "wx/dc.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
44 #include "wx/intl.h"
45 #include "wx/dynarray.h"
46 #include "wx/wxchar.h"
47 #include "wx/icon.h"
48 #include "wx/log.h"
49 #endif
50
51 #include "wx/cmdline.h"
52 #include "wx/filename.h"
53 #include "wx/module.h"
54
55 #include "wx/msw/private.h"
56
57 #if wxUSE_THREADS
58 #include "wx/thread.h"
59
60 // define the array of MSG strutures
61 WX_DECLARE_OBJARRAY(MSG, wxMsgArray);
62
63 #include "wx/arrimpl.cpp"
64
65 WX_DEFINE_OBJARRAY(wxMsgArray);
66 #endif // wxUSE_THREADS
67
68 #if wxUSE_WX_RESOURCES
69 #include "wx/resource.h"
70 #endif
71
72 #if wxUSE_TOOLTIPS
73 #include "wx/tooltip.h"
74 #endif // wxUSE_TOOLTIPS
75
76 // OLE is used for drag-and-drop, clipboard, OLE Automation..., but some
77 // compilers don't support it (missing headers, libs, ...)
78 #if defined(__GNUWIN32_OLD__) || defined(__SC__) || defined(__SALFORDC__)
79 #undef wxUSE_OLE
80
81 #define wxUSE_OLE 0
82 #endif // broken compilers
83
84 #if wxUSE_OLE
85 #include <ole2.h>
86 #endif
87
88 #include <string.h>
89 #include <ctype.h>
90
91 #if defined(__WIN95__) && !((defined(__GNUWIN32_OLD__) || defined(__TWIN32__) || defined(__WXMICROWIN__)) && !defined(__CYGWIN10__))
92 #include <commctrl.h>
93 #endif
94
95 #ifndef __WXMICROWIN__
96 #include "wx/msw/msvcrt.h"
97 #endif
98
99 // ----------------------------------------------------------------------------
100 // conditional compilation
101 // ----------------------------------------------------------------------------
102
103 // The macro _WIN32_IE is defined by commctrl.h (unless it had already been
104 // defined before) and shows us what common control features are available
105 // during the compile time (it doesn't mean that they will be available during
106 // the run-time, use GetComCtl32Version() to test for them!). The possible
107 // values are:
108 //
109 // 0x0200 for comctl32.dll 4.00 shipped with Win95/NT 4.0
110 // 0x0300 4.70 IE 3.x
111 // 0x0400 4.71 IE 4.0
112 // 0x0401 4.72 IE 4.01 and Win98
113 // 0x0500 5.00 IE 5.x and NT 5.0 (Win2000)
114
115 #ifndef _WIN32_IE
116 // minimal set of features by default
117 #define _WIN32_IE 0x0200
118 #endif
119
120 #if _WIN32_IE >= 0x0300 && !defined(__MINGW32__)
121 #include <shlwapi.h>
122 #endif
123
124 // ---------------------------------------------------------------------------
125 // global variables
126 // ---------------------------------------------------------------------------
127
128 extern wxChar *wxBuffer;
129 extern wxList WXDLLEXPORT wxPendingDelete;
130 #ifndef __WXMICROWIN__
131 extern void wxSetKeyboardHook(bool doIt);
132 #endif
133
134 MSG s_currentMsg;
135 wxApp *wxTheApp = NULL;
136
137 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
138 // with NR suffix - wxWindow::MSWCreate() supposes this
139 const wxChar *wxFrameClassName = wxT("wxFrameClass");
140 const wxChar *wxFrameClassNameNoRedraw = wxT("wxFrameClassNR");
141 const wxChar *wxMDIFrameClassName = wxT("wxMDIFrameClass");
142 const wxChar *wxMDIFrameClassNameNoRedraw = wxT("wxMDIFrameClassNR");
143 const wxChar *wxMDIChildFrameClassName = wxT("wxMDIChildFrameClass");
144 const wxChar *wxMDIChildFrameClassNameNoRedraw = wxT("wxMDIChildFrameClassNR");
145 const wxChar *wxPanelClassName = wxT("wxPanelClass");
146 const wxChar *wxPanelClassNameNR = wxT("wxPanelClassNR");
147 const wxChar *wxCanvasClassName = wxT("wxCanvasClass");
148 const wxChar *wxCanvasClassNameNR = wxT("wxCanvasClassNR");
149
150 HICON wxSTD_FRAME_ICON = (HICON) NULL;
151 HICON wxSTD_MDICHILDFRAME_ICON = (HICON) NULL;
152 HICON wxSTD_MDIPARENTFRAME_ICON = (HICON) NULL;
153
154 HICON wxDEFAULT_FRAME_ICON = (HICON) NULL;
155 HICON wxDEFAULT_MDICHILDFRAME_ICON = (HICON) NULL;
156 HICON wxDEFAULT_MDIPARENTFRAME_ICON = (HICON) NULL;
157
158 HBRUSH wxDisableButtonBrush = (HBRUSH) 0;
159
160 LRESULT WXDLLEXPORT APIENTRY wxWndProc(HWND, UINT, WPARAM, LPARAM);
161
162 // FIXME wxUSE_ON_FATAL_EXCEPTION is only supported for VC++ now because it
163 // needs compiler support for Win32 SEH. Others (especially Borland)
164 // probably have it too, but I'm not sure about how it works
165 // JACS: get 'Cannot use __try in functions that require unwinding
166 // in Unicode mode, so disabling.
167 #if !defined(__VISUALC__) || defined(__WIN16__) || defined(UNICODE)
168 #undef wxUSE_ON_FATAL_EXCEPTION
169 #define wxUSE_ON_FATAL_EXCEPTION 0
170 #endif // VC++
171
172 #if wxUSE_ON_FATAL_EXCEPTION
173 static bool gs_handleExceptions = FALSE;
174 #endif
175
176 // ===========================================================================
177 // implementation
178 // ===========================================================================
179
180 // ---------------------------------------------------------------------------
181 // wxApp
182 // ---------------------------------------------------------------------------
183
184 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
185
186 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
187 EVT_IDLE(wxApp::OnIdle)
188 EVT_END_SESSION(wxApp::OnEndSession)
189 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
190 END_EVENT_TABLE()
191
192 //// Initialize
193 bool wxApp::Initialize()
194 {
195 // the first thing to do is to check if we're trying to run an Unicode
196 // program under Win9x w/o MSLU emulation layer - if so, abort right now
197 // as it has no chance to work
198 #if wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
199 if ( wxGetOsVersion() != wxWINDOWS_NT )
200 {
201 // note that we can use MessageBoxW() as it's implemented even under
202 // Win9x - OTOH, we can't use wxGetTranslation() because the file APIs
203 // used by wxLocale are not
204 ::MessageBox
205 (
206 NULL,
207 _T("This program uses Unicode and requires Windows NT/2000/XP.\nProgram aborted."),
208 _T("wxWindows Fatal Error"),
209 MB_ICONERROR | MB_OK
210 );
211
212 return FALSE;
213 }
214 #endif // wxUSE_UNICODE && !wxUSE_UNICODE_MSLU
215
216 wxBuffer = new wxChar[1500]; // FIXME
217
218 wxClassInfo::InitializeClasses();
219
220 #if wxUSE_THREADS
221 wxPendingEventsLocker = new wxCriticalSection;
222 #endif
223
224 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
225 wxTheColourDatabase->Initialize();
226
227 wxInitializeStockLists();
228 wxInitializeStockObjects();
229
230 #if wxUSE_WX_RESOURCES
231 wxInitializeResourceSystem();
232 #endif
233
234 wxBitmap::InitStandardHandlers();
235
236 #if defined(__WIN95__) && !defined(__WXMICROWIN__)
237 InitCommonControls();
238 #endif // __WIN95__
239
240 #if wxUSE_OLE || wxUSE_DRAG_AND_DROP
241
242 #ifdef __WIN16__
243 // for OLE, enlarge message queue to be as large as possible
244 int iMsg = 96;
245 while (!SetMessageQueue(iMsg) && (iMsg -= 8))
246 ;
247 #endif // Win16
248
249 #if wxUSE_OLE
250 // we need to initialize OLE library
251 if ( FAILED(::OleInitialize(NULL)) )
252 wxLogError(_("Cannot initialize OLE"));
253 #endif
254
255 #endif // wxUSE_OLE
256
257 #if wxUSE_CTL3D
258 if (!Ctl3dRegister(wxhInstance))
259 wxLogError(wxT("Cannot register CTL3D"));
260
261 Ctl3dAutoSubclass(wxhInstance);
262 #endif // wxUSE_CTL3D
263
264 // VZ: these icons are not in wx.rc anyhow (but should they?)!
265 #if 0
266 wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME"));
267 wxSTD_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDIPARENTFRAME"));
268 wxSTD_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDICHILDFRAME"));
269
270 wxDEFAULT_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_FRAME"));
271 wxDEFAULT_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDIPARENTFRAME"));
272 wxDEFAULT_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDICHILDFRAME"));
273 #endif // 0
274
275 RegisterWindowClasses();
276
277 #ifndef __WXMICROWIN__
278 // Create the brush for disabling bitmap buttons
279
280 LOGBRUSH lb;
281 lb.lbStyle = BS_PATTERN;
282 lb.lbColor = 0;
283 lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") );
284 if ( lb.lbHatch )
285 {
286 wxDisableButtonBrush = ::CreateBrushIndirect( & lb );
287 ::DeleteObject( (HGDIOBJ)lb.lbHatch );
288 }
289 //else: wxWindows resources are probably not linked in
290 #endif
291
292 #if wxUSE_PENWINDOWS
293 wxRegisterPenWin();
294 #endif
295
296 wxWinHandleHash = new wxWinHashTable(wxKEY_INTEGER, 100);
297
298 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
299 // PLEASE DO NOT ALTER THIS.
300 #if defined(__VISUALC__) && defined(__WIN16__) && !defined(WXMAKINGDLL)
301 extern char wxDummyChar;
302 if (wxDummyChar) wxDummyChar++;
303 #endif
304
305 #ifndef __WXMICROWIN__
306 wxSetKeyboardHook(TRUE);
307 #endif
308
309 wxModule::RegisterModules();
310 if (!wxModule::InitializeModules())
311 return FALSE;
312 return TRUE;
313 }
314
315 // ---------------------------------------------------------------------------
316 // RegisterWindowClasses
317 // ---------------------------------------------------------------------------
318
319 // TODO we should only register classes really used by the app. For this it
320 // would be enough to just delay the class registration until an attempt
321 // to create a window of this class is made.
322 bool wxApp::RegisterWindowClasses()
323 {
324 WNDCLASS wndclass;
325
326 // for each class we register one with CS_(V|H)REDRAW style and one
327 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
328 static const long styleNormal = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
329 static const long styleNoRedraw = CS_DBLCLKS;
330
331 // the fields which are common to all classes
332 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
333 wndclass.cbClsExtra = 0;
334 wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for?
335 wndclass.hInstance = wxhInstance;
336 wndclass.hIcon = (HICON) NULL;
337 wndclass.hCursor = ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
338 wndclass.lpszMenuName = NULL;
339
340 // Register the frame window class.
341 wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
342 wndclass.lpszClassName = wxFrameClassName;
343 wndclass.style = styleNormal;
344
345 if ( !RegisterClass(&wndclass) )
346 {
347 wxLogLastError(wxT("RegisterClass(frame)"));
348
349 return FALSE;
350 }
351
352 // "no redraw" frame
353 wndclass.lpszClassName = wxFrameClassNameNoRedraw;
354 wndclass.style = styleNoRedraw;
355
356 if ( !RegisterClass(&wndclass) )
357 {
358 wxLogLastError(wxT("RegisterClass(no redraw frame)"));
359
360 return FALSE;
361 }
362
363 // Register the MDI frame window class.
364 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
365 wndclass.lpszClassName = wxMDIFrameClassName;
366 wndclass.style = styleNormal;
367
368 if ( !RegisterClass(&wndclass) )
369 {
370 wxLogLastError(wxT("RegisterClass(MDI parent)"));
371
372 return FALSE;
373 }
374
375 // "no redraw" MDI frame
376 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
377 wndclass.style = styleNoRedraw;
378
379 if ( !RegisterClass(&wndclass) )
380 {
381 wxLogLastError(wxT("RegisterClass(no redraw MDI parent frame)"));
382
383 return FALSE;
384 }
385
386 // Register the MDI child frame window class.
387 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
388 wndclass.lpszClassName = wxMDIChildFrameClassName;
389 wndclass.style = styleNormal;
390
391 if ( !RegisterClass(&wndclass) )
392 {
393 wxLogLastError(wxT("RegisterClass(MDI child)"));
394
395 return FALSE;
396 }
397
398 // "no redraw" MDI child frame
399 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
400 wndclass.style = styleNoRedraw;
401
402 if ( !RegisterClass(&wndclass) )
403 {
404 wxLogLastError(wxT("RegisterClass(no redraw MDI child)"));
405
406 return FALSE;
407 }
408
409 // Register the panel window class.
410 wndclass.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH );
411 wndclass.lpszClassName = wxPanelClassName;
412 wndclass.style = styleNormal;
413
414 if ( !RegisterClass(&wndclass) )
415 {
416 wxLogLastError(wxT("RegisterClass(panel)"));
417
418 return FALSE;
419 }
420
421 // Register the no redraw panel window class.
422 wndclass.lpszClassName = wxPanelClassNameNR;
423 wndclass.style = styleNoRedraw;
424
425 if ( !RegisterClass(&wndclass) )
426 {
427 wxLogLastError(wxT("RegisterClass(no redraw panel)"));
428
429 return FALSE;
430 }
431
432 // Register the canvas and textsubwindow class name
433 wndclass.hbrBackground = (HBRUSH)NULL;
434 wndclass.lpszClassName = wxCanvasClassName;
435
436 if ( !RegisterClass(&wndclass) )
437 {
438 wxLogLastError(wxT("RegisterClass(canvas)"));
439
440 return FALSE;
441 }
442
443 wndclass.lpszClassName = wxCanvasClassNameNR;
444 wndclass.style = styleNoRedraw;
445 if ( !RegisterClass(&wndclass) )
446 {
447 wxLogLastError(wxT("RegisterClass(no redraw canvas)"));
448
449 return FALSE;
450 }
451
452 return TRUE;
453 }
454
455 // ---------------------------------------------------------------------------
456 // UnregisterWindowClasses
457 // ---------------------------------------------------------------------------
458
459 bool wxApp::UnregisterWindowClasses()
460 {
461 bool retval = TRUE;
462
463 #ifndef __WXMICROWIN__
464 // frame window class.
465 if ( !UnregisterClass(wxFrameClassName, wxhInstance) )
466 {
467 wxLogLastError(wxT("UnregisterClass(frame)"));
468
469 retval = FALSE;
470 }
471
472 // "no redraw" frame
473 if ( !UnregisterClass(wxFrameClassNameNoRedraw, wxhInstance) )
474 {
475 wxLogLastError(wxT("UnregisterClass(no redraw frame)"));
476
477 return FALSE;
478 }
479
480 // MDI frame window class.
481 if ( !UnregisterClass(wxMDIFrameClassName, wxhInstance) )
482 {
483 wxLogLastError(wxT("UnregisterClass(MDI parent)"));
484
485 retval = FALSE;
486 }
487
488 // "no redraw" MDI frame
489 if ( !UnregisterClass(wxMDIFrameClassNameNoRedraw, wxhInstance) )
490 {
491 wxLogLastError(wxT("UnregisterClass(no redraw MDI parent frame)"));
492
493 retval = FALSE;
494 }
495
496 // MDI child frame window class.
497 if ( !UnregisterClass(wxMDIChildFrameClassName, wxhInstance) )
498 {
499 wxLogLastError(wxT("UnregisterClass(MDI child)"));
500
501 retval = FALSE;
502 }
503
504 // "no redraw" MDI child frame
505 if ( !UnregisterClass(wxMDIChildFrameClassNameNoRedraw, wxhInstance) )
506 {
507 wxLogLastError(wxT("UnregisterClass(no redraw MDI child)"));
508
509 retval = FALSE;
510 }
511
512 // panel window class.
513 if ( !UnregisterClass(wxPanelClassName, wxhInstance) )
514 {
515 wxLogLastError(wxT("UnregisterClass(panel)"));
516
517 retval = FALSE;
518 }
519
520 // no redraw panel window class.
521 if ( !UnregisterClass(wxPanelClassNameNR, wxhInstance) )
522 {
523 wxLogLastError(wxT("UnregisterClass(no redraw panel)"));
524
525 retval = FALSE;
526 }
527
528 // canvas and textsubwindow class name
529 if ( !UnregisterClass(wxCanvasClassName, wxhInstance) )
530 {
531 wxLogLastError(wxT("UnregisterClass(canvas)"));
532
533 retval = FALSE;
534 }
535
536 if ( !UnregisterClass(wxCanvasClassNameNR, wxhInstance) )
537 {
538 wxLogLastError(wxT("UnregisterClass(no redraw canvas)"));
539
540 retval = FALSE;
541 }
542 #endif
543 // __WXMICROWIN__
544 return retval;
545 }
546
547 // ---------------------------------------------------------------------------
548 // Convert Windows to argc, argv style
549 // ---------------------------------------------------------------------------
550
551 void wxApp::ConvertToStandardCommandArgs(const char* lpCmdLine)
552 {
553 // break the command line in words
554 wxArrayString args =
555 wxCmdLineParser::ConvertStringToArgs(wxConvertMB2WX(lpCmdLine));
556
557 // +1 here for the program name
558 argc = args.GetCount() + 1;
559
560 // and +1 here for the terminating NULL
561 argv = new wxChar *[argc + 1];
562
563 argv[0] = new wxChar[260]; // 260 is MAX_PATH value from windef.h
564 ::GetModuleFileName(wxhInstance, argv[0], 260);
565
566 // also set the app name from argv[0]
567 wxString name;
568 wxFileName::SplitPath(argv[0], NULL, &name, NULL);
569
570 SetAppName(name);
571
572 // copy all the other arguments to wxApp::argv[]
573 for ( int i = 1; i < argc; i++ )
574 {
575 argv[i] = copystring(args[i - 1]);
576 }
577
578 // argv[] must be NULL-terminated
579 argv[argc] = NULL;
580 }
581
582 //// Cleans up any wxWindows internal structures left lying around
583
584 void wxApp::CleanUp()
585 {
586 //// COMMON CLEANUP
587
588 #if wxUSE_LOG
589 // flush the logged messages if any and install a 'safer' log target: the
590 // default one (wxLogGui) can't be used after the resources are freed just
591 // below and the user suppliedo ne might be even more unsafe (using any
592 // wxWindows GUI function is unsafe starting from now)
593 wxLog::DontCreateOnDemand();
594
595 // this will flush the old messages if any
596 delete wxLog::SetActiveTarget(new wxLogStderr);
597 #endif // wxUSE_LOG
598
599 // One last chance for pending objects to be cleaned up
600 wxTheApp->DeletePendingObjects();
601
602 wxModule::CleanUpModules();
603
604 #if wxUSE_WX_RESOURCES
605 wxCleanUpResourceSystem();
606
607 // wxDefaultResourceTable->ClearTable();
608 #endif
609
610 wxDeleteStockObjects();
611
612 // Destroy all GDI lists, etc.
613 wxDeleteStockLists();
614
615 delete wxTheColourDatabase;
616 wxTheColourDatabase = NULL;
617
618 wxBitmap::CleanUpHandlers();
619
620 delete[] wxBuffer;
621 wxBuffer = NULL;
622
623 //// WINDOWS-SPECIFIC CLEANUP
624
625 #ifndef __WXMICROWIN__
626 wxSetKeyboardHook(FALSE);
627 #endif
628
629 #if wxUSE_PENWINDOWS
630 wxCleanUpPenWin();
631 #endif
632
633 if (wxSTD_FRAME_ICON)
634 DestroyIcon(wxSTD_FRAME_ICON);
635 if (wxSTD_MDICHILDFRAME_ICON)
636 DestroyIcon(wxSTD_MDICHILDFRAME_ICON);
637 if (wxSTD_MDIPARENTFRAME_ICON)
638 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON);
639
640 if (wxDEFAULT_FRAME_ICON)
641 DestroyIcon(wxDEFAULT_FRAME_ICON);
642 if (wxDEFAULT_MDICHILDFRAME_ICON)
643 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON);
644 if (wxDEFAULT_MDIPARENTFRAME_ICON)
645 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
646
647 if ( wxDisableButtonBrush )
648 ::DeleteObject( wxDisableButtonBrush );
649
650 #if wxUSE_OLE
651 ::OleUninitialize();
652 #endif
653
654 #ifdef WXMAKINGDLL
655 // for an EXE the classes are unregistered when it terminates but DLL may
656 // be loaded several times (load/unload/load) into the same process in
657 // which case the registration will fail after the first time if we don't
658 // unregister the classes now
659 UnregisterWindowClasses();
660 #endif // WXMAKINGDLL
661
662 #if wxUSE_CTL3D
663 Ctl3dUnregister(wxhInstance);
664 #endif
665
666 delete wxWinHandleHash;
667
668 // GL: I'm annoyed ... I don't know where to put this and I don't want to
669 // create a module for that as it's part of the core.
670 delete wxPendingEvents;
671
672 #if wxUSE_THREADS
673 delete wxPendingEventsLocker;
674 // If we don't do the following, we get an apparent memory leak
675 #if wxUSE_VALIDATORS
676 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
677 #endif // wxUSE_VALIDATORS
678 #endif // wxUSE_THREADS
679
680 wxClassInfo::CleanUpClasses();
681
682 delete wxTheApp;
683 wxTheApp = NULL;
684
685 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
686 // At this point we want to check if there are any memory
687 // blocks that aren't part of the wxDebugContext itself,
688 // as a special case. Then when dumping we need to ignore
689 // wxDebugContext, too.
690 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
691 {
692 wxLogMessage(wxT("There were memory leaks."));
693 wxDebugContext::Dump();
694 wxDebugContext::PrintStatistics();
695 }
696 // wxDebugContext::SetStream(NULL, NULL);
697 #endif
698
699 #if wxUSE_LOG
700 // do it as the very last thing because everything else can log messages
701 delete wxLog::SetActiveTarget(NULL);
702 #endif // wxUSE_LOG
703 }
704
705 //----------------------------------------------------------------------
706 // Entry point helpers, used by wxPython
707 //----------------------------------------------------------------------
708
709 int WXDLLEXPORT wxEntryStart( int WXUNUSED(argc), char** WXUNUSED(argv) )
710 {
711 return wxApp::Initialize();
712 }
713
714 int WXDLLEXPORT wxEntryInitGui()
715 {
716 return wxTheApp->OnInitGui();
717 }
718
719 void WXDLLEXPORT wxEntryCleanup()
720 {
721 wxApp::CleanUp();
722 }
723
724
725 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
726
727 // temporarily disable this warning which would be generated in release builds
728 // because of __try
729 #ifdef __VISUALC__
730 #pragma warning(disable: 4715) // not all control paths return a value
731 #endif // Visual C++
732
733 //----------------------------------------------------------------------
734 // Main wxWindows entry point
735 //----------------------------------------------------------------------
736 int wxEntry(WXHINSTANCE hInstance,
737 WXHINSTANCE WXUNUSED(hPrevInstance),
738 char *lpCmdLine,
739 int nCmdShow,
740 bool enterLoop)
741 {
742 // do check for memory leaks on program exit
743 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
744 // deallocated memory which may be used to simulate low-memory condition)
745 #ifndef __WXMICROWIN__
746 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
747 #endif
748
749 #ifdef __MWERKS__
750 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
751 // This seems to be necessary since there are 'rogue'
752 // objects present at this point (perhaps global objects?)
753 // Setting a checkpoint will ignore them as far as the
754 // memory checking facility is concerned.
755 // Of course you may argue that memory allocated in globals should be
756 // checked, but this is a reasonable compromise.
757 wxDebugContext::SetCheckpoint();
758 #endif
759 #endif
760
761 // take everything into a try-except block to be able to call
762 // OnFatalException() if necessary
763 #if wxUSE_ON_FATAL_EXCEPTION
764 __try {
765 #endif
766 wxhInstance = (HINSTANCE) hInstance;
767
768 if (!wxEntryStart(0,0))
769 return 0;
770
771 // create the application object or ensure that one already exists
772 if (!wxTheApp)
773 {
774 // The app may have declared a global application object, but we recommend
775 // the IMPLEMENT_APP macro is used instead, which sets an initializer
776 // function for delayed, dynamic app object construction.
777 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
778 wxT("No initializer - use IMPLEMENT_APP macro.") );
779
780 wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
781 }
782
783 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
784
785 // save the WinMain() parameters
786 if (lpCmdLine) // MicroWindows passes NULL
787 wxTheApp->ConvertToStandardCommandArgs(lpCmdLine);
788 wxTheApp->m_nCmdShow = nCmdShow;
789
790 // We really don't want timestamps by default, because it means
791 // we can't simply double-click on the error message and get to that
792 // line in the source. So VC++ at least, let's have a sensible default.
793 #ifdef __VISUALC__
794 wxLog::SetTimestamp(NULL);
795 #endif
796
797 int retValue = 0;
798
799 // it is common to create a modal dialog in OnInit() (to ask/notify the
800 // user about something) but it wouldn't work if we don't change the
801 // "exit on delete last frame" flag here as when this dialog is
802 // deleted, the app would terminate (it was the last top level window
803 // as the main frame wasn't created yet!), so disable this behaviour
804 // temproarily
805 bool exitOnLastFrameDelete = wxTheApp->GetExitOnFrameDelete();
806 wxTheApp->SetExitOnFrameDelete(FALSE);
807
808 // init the app
809 retValue = wxEntryInitGui() && wxTheApp->OnInit() ? 0 : -1;
810
811 // restore the old flag value
812 wxTheApp->SetExitOnFrameDelete(exitOnLastFrameDelete);
813
814 if ( retValue == 0 )
815 {
816 if ( enterLoop )
817 {
818 // run the main loop
819 retValue = wxTheApp->OnRun();
820 }
821 else
822 {
823 // we want to initialize, but not run or exit immediately.
824 return 1;
825 }
826 }
827 //else: app initialization failed, so we skipped OnRun()
828
829 wxWindow *topWindow = wxTheApp->GetTopWindow();
830 if ( topWindow )
831 {
832 // Forcibly delete the window.
833 if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
834 topWindow->IsKindOf(CLASSINFO(wxDialog)) )
835 {
836 topWindow->Close(TRUE);
837 wxTheApp->DeletePendingObjects();
838 }
839 else
840 {
841 delete topWindow;
842 wxTheApp->SetTopWindow(NULL);
843 }
844 }
845
846 wxTheApp->OnExit();
847
848 wxEntryCleanup();
849
850 return retValue;
851
852 #if wxUSE_ON_FATAL_EXCEPTION
853 }
854 __except ( gs_handleExceptions ? EXCEPTION_EXECUTE_HANDLER
855 : EXCEPTION_CONTINUE_SEARCH ) {
856 if ( wxTheApp )
857 {
858 // give the user a chance to do something special about this
859 wxTheApp->OnFatalException();
860 }
861
862 ::ExitProcess(3); // the same exit code as abort()
863
864 // NOTREACHED
865 }
866 #endif // wxUSE_ON_FATAL_EXCEPTION
867 }
868
869 // restore warning state
870 #ifdef __VISUALC__
871 #pragma warning(default: 4715) // not all control paths return a value
872 #endif // Visual C++
873
874 #else /* _WINDLL */
875
876 //----------------------------------------------------------------------
877 // Entry point for wxWindows + the App in a DLL
878 //----------------------------------------------------------------------
879
880 int wxEntry(WXHINSTANCE hInstance)
881 {
882 wxhInstance = (HINSTANCE) hInstance;
883 wxEntryStart(0, 0);
884
885 // The app may have declared a global application object, but we recommend
886 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
887 // for delayed, dynamic app object construction.
888 if (!wxTheApp)
889 {
890 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
891 "No initializer - use IMPLEMENT_APP macro." );
892
893 wxTheApp = (* wxApp::GetInitializerFunction()) ();
894 }
895
896 wxCHECK_MSG( wxTheApp, 0, "You have to define an instance of wxApp!" );
897
898 wxTheApp->argc = 0;
899 wxTheApp->argv = NULL;
900
901 wxEntryInitGui();
902
903 wxTheApp->OnInit();
904
905 wxWindow *topWindow = wxTheApp->GetTopWindow();
906 if ( topWindow && topWindow->GetHWND())
907 {
908 topWindow->Show(TRUE);
909 }
910
911 return 1;
912 }
913 #endif // _WINDLL
914
915 //// Static member initialization
916
917 wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
918
919 wxApp::wxApp()
920 {
921 argc = 0;
922 argv = NULL;
923 m_printMode = wxPRINT_WINDOWS;
924 m_auto3D = TRUE;
925 }
926
927 wxApp::~wxApp()
928 {
929 // Delete command-line args
930 int i;
931 for (i = 0; i < argc; i++)
932 {
933 delete[] argv[i];
934 }
935 delete[] argv;
936 }
937
938 bool wxApp::Initialized()
939 {
940 #ifndef _WINDLL
941 if (GetTopWindow())
942 return TRUE;
943 else
944 return FALSE;
945 #else // Assume initialized if DLL (no way of telling)
946 return TRUE;
947 #endif
948 }
949
950 /*
951 * Get and process a message, returning FALSE if WM_QUIT
952 * received (and also set the flag telling the app to exit the main loop)
953 *
954 */
955 bool wxApp::DoMessage()
956 {
957 BOOL rc = ::GetMessage(&s_currentMsg, (HWND) NULL, 0, 0);
958 if ( rc == 0 )
959 {
960 // got WM_QUIT
961 m_keepGoing = FALSE;
962
963 return FALSE;
964 }
965 else if ( rc == -1 )
966 {
967 // should never happen, but let's test for it nevertheless
968 wxLogLastError(wxT("GetMessage"));
969 }
970 else
971 {
972 #if wxUSE_THREADS
973 wxASSERT_MSG( wxThread::IsMain(),
974 wxT("only the main thread can process Windows messages") );
975
976 static bool s_hadGuiLock = TRUE;
977 static wxMsgArray s_aSavedMessages;
978
979 // if a secondary thread owns is doing GUI calls, save all messages for
980 // later processing - we can't process them right now because it will
981 // lead to recursive library calls (and we're not reentrant)
982 if ( !wxGuiOwnedByMainThread() )
983 {
984 s_hadGuiLock = FALSE;
985
986 // leave out WM_COMMAND messages: too dangerous, sometimes
987 // the message will be processed twice
988 if ( !wxIsWaitingForThread() ||
989 s_currentMsg.message != WM_COMMAND )
990 {
991 s_aSavedMessages.Add(s_currentMsg);
992 }
993
994 return TRUE;
995 }
996 else
997 {
998 // have we just regained the GUI lock? if so, post all of the saved
999 // messages
1000 //
1001 // FIXME of course, it's not _exactly_ the same as processing the
1002 // messages normally - expect some things to break...
1003 if ( !s_hadGuiLock )
1004 {
1005 s_hadGuiLock = TRUE;
1006
1007 size_t count = s_aSavedMessages.Count();
1008 for ( size_t n = 0; n < count; n++ )
1009 {
1010 MSG& msg = s_aSavedMessages[n];
1011
1012 if ( !ProcessMessage((WXMSG *)&msg) )
1013 {
1014 ::TranslateMessage(&msg);
1015 ::DispatchMessage(&msg);
1016 }
1017 }
1018
1019 s_aSavedMessages.Empty();
1020 }
1021 }
1022 #endif // wxUSE_THREADS
1023
1024 // Process the message
1025 DoMessage((WXMSG *)&s_currentMsg);
1026 }
1027
1028 return TRUE;
1029 }
1030
1031 void wxApp::DoMessage(WXMSG *pMsg)
1032 {
1033 if ( !ProcessMessage(pMsg) )
1034 {
1035 ::TranslateMessage((MSG *)pMsg);
1036 ::DispatchMessage((MSG *)pMsg);
1037 }
1038 }
1039
1040 /*
1041 * Keep trying to process messages until WM_QUIT
1042 * received.
1043 *
1044 * If there are messages to be processed, they will all be
1045 * processed and OnIdle will not be called.
1046 * When there are no more messages, OnIdle is called.
1047 * If OnIdle requests more time,
1048 * it will be repeatedly called so long as there are no pending messages.
1049 * A 'feature' of this is that once OnIdle has decided that no more processing
1050 * is required, then it won't get processing time until further messages
1051 * are processed (it'll sit in DoMessage).
1052 */
1053
1054 int wxApp::MainLoop()
1055 {
1056 m_keepGoing = TRUE;
1057
1058 while ( m_keepGoing )
1059 {
1060 #if wxUSE_THREADS
1061 wxMutexGuiLeaveOrEnter();
1062 #endif // wxUSE_THREADS
1063
1064 while ( !Pending() && ProcessIdle() )
1065 ;
1066
1067 // a message came or no more idle processing to do
1068 DoMessage();
1069 }
1070
1071 return s_currentMsg.wParam;
1072 }
1073
1074 // Returns TRUE if more time is needed.
1075 bool wxApp::ProcessIdle()
1076 {
1077 wxIdleEvent event;
1078 event.SetEventObject(this);
1079 ProcessEvent(event);
1080
1081 return event.MoreRequested();
1082 }
1083
1084 void wxApp::ExitMainLoop()
1085 {
1086 // VZ: why not ::PostQuitMessage()?
1087 m_keepGoing = FALSE;
1088 }
1089
1090 bool wxApp::Pending()
1091 {
1092 return ::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) != 0;
1093 }
1094
1095 void wxApp::Dispatch()
1096 {
1097 DoMessage();
1098 }
1099
1100 /*
1101 * Give all windows a chance to preprocess
1102 * the message. Some may have accelerator tables, or have
1103 * MDI complications.
1104 */
1105
1106 bool wxApp::ProcessMessage(WXMSG *wxmsg)
1107 {
1108 MSG *msg = (MSG *)wxmsg;
1109 HWND hwnd = msg->hwnd;
1110 wxWindow *wndThis = wxGetWindowFromHWND((WXHWND)hwnd);
1111
1112 // this may happen if the event occured in a standard modeless dialog (the
1113 // only example of which I know of is the find/replace dialog) - then call
1114 // IsDialogMessage() to make TAB navigation in it work
1115 if ( !wndThis )
1116 {
1117 // we need to find the dialog containing this control as
1118 // IsDialogMessage() just eats all the messages (i.e. returns TRUE for
1119 // them) if we call it for the control itself
1120 while ( hwnd && ::GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD )
1121 {
1122 hwnd = ::GetParent(hwnd);
1123 }
1124
1125 return hwnd && ::IsDialogMessage(hwnd, msg) != 0;
1126 }
1127
1128 #if wxUSE_TOOLTIPS
1129 // we must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
1130 // popup the tooltip bubbles
1131 if ( (msg->message == WM_MOUSEMOVE) )
1132 {
1133 wxToolTip *tt = wndThis->GetToolTip();
1134 if ( tt )
1135 {
1136 tt->RelayEvent(wxmsg);
1137 }
1138 }
1139 #endif // wxUSE_TOOLTIPS
1140
1141 // allow the window to prevent certain messages from being
1142 // translated/processed (this is currently used by wxTextCtrl to always
1143 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
1144 if ( !wndThis->MSWShouldPreProcessMessage(wxmsg) )
1145 {
1146 return FALSE;
1147 }
1148
1149 // try translations first: the accelerators override everything
1150 wxWindow *wnd;
1151
1152 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
1153 {
1154 if ( wnd->MSWTranslateMessage(wxmsg))
1155 return TRUE;
1156
1157 // stop at first top level window, i.e. don't try to process the key
1158 // strokes originating in a dialog using the accelerators of the parent
1159 // frame - this doesn't make much sense
1160 if ( wnd->IsTopLevel() )
1161 break;
1162 }
1163
1164 // now try the other hooks (kbd navigation is handled here): we start from
1165 // wndThis->GetParent() because wndThis->MSWProcessMessage() was already
1166 // called above
1167 for ( wnd = wndThis->GetParent(); wnd; wnd = wnd->GetParent() )
1168 {
1169 if ( wnd->MSWProcessMessage(wxmsg) )
1170 return TRUE;
1171 }
1172
1173 // no special preprocessing for this message, dispatch it normally
1174 return FALSE;
1175 }
1176
1177 void wxApp::OnIdle(wxIdleEvent& event)
1178 {
1179 static bool s_inOnIdle = FALSE;
1180
1181 // Avoid recursion (via ProcessEvent default case)
1182 if ( s_inOnIdle )
1183 return;
1184
1185 s_inOnIdle = TRUE;
1186
1187 // If there are pending events, we must process them: pending events
1188 // are either events to the threads other than main or events posted
1189 // with wxPostEvent() functions
1190 // GRG: I have moved this here so that all pending events are processed
1191 // before starting to delete any objects. This behaves better (in
1192 // particular, wrt wxPostEvent) and is coherent with wxGTK's current
1193 // behaviour. Changed Feb/2000 before 2.1.14
1194 ProcessPendingEvents();
1195
1196 // 'Garbage' collection of windows deleted with Close().
1197 DeletePendingObjects();
1198
1199 #if wxUSE_LOG
1200 // flush the logged messages if any
1201 wxLog::FlushActive();
1202 #endif // wxUSE_LOG
1203
1204 #if wxUSE_DC_CACHEING
1205 // automated DC cache management: clear the cached DCs and bitmap
1206 // if it's likely that the app has finished with them, that is, we
1207 // get an idle event and we're not dragging anything.
1208 if (!::GetKeyState(MK_LBUTTON) && !::GetKeyState(MK_MBUTTON) && !::GetKeyState(MK_RBUTTON))
1209 wxDC::ClearCache();
1210 #endif // wxUSE_DC_CACHEING
1211
1212 // Send OnIdle events to all windows
1213 if ( SendIdleEvents() )
1214 {
1215 // SendIdleEvents() returns TRUE if at least one window requested more
1216 // idle events
1217 event.RequestMore(TRUE);
1218 }
1219
1220 s_inOnIdle = FALSE;
1221 }
1222
1223 // Send idle event to all top-level windows
1224 bool wxApp::SendIdleEvents()
1225 {
1226 bool needMore = FALSE;
1227
1228 wxWindowList::Node* node = wxTopLevelWindows.GetFirst();
1229 while (node)
1230 {
1231 wxWindow* win = node->GetData();
1232 if (SendIdleEvents(win))
1233 needMore = TRUE;
1234 node = node->GetNext();
1235 }
1236
1237 return needMore;
1238 }
1239
1240 // Send idle event to window and all subwindows
1241 bool wxApp::SendIdleEvents(wxWindow* win)
1242 {
1243 bool needMore = FALSE;
1244
1245 wxIdleEvent event;
1246 event.SetEventObject(win);
1247 win->GetEventHandler()->ProcessEvent(event);
1248
1249 if (event.MoreRequested())
1250 needMore = TRUE;
1251
1252 wxNode* node = win->GetChildren().First();
1253 while (node)
1254 {
1255 wxWindow* win = (wxWindow*) node->Data();
1256 if (SendIdleEvents(win))
1257 needMore = TRUE;
1258
1259 node = node->Next();
1260 }
1261 return needMore;
1262 }
1263
1264 void wxApp::DeletePendingObjects()
1265 {
1266 wxNode *node = wxPendingDelete.First();
1267 while (node)
1268 {
1269 wxObject *obj = (wxObject *)node->Data();
1270
1271 delete obj;
1272
1273 if (wxPendingDelete.Member(obj))
1274 delete node;
1275
1276 // Deleting one object may have deleted other pending
1277 // objects, so start from beginning of list again.
1278 node = wxPendingDelete.First();
1279 }
1280 }
1281
1282 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1283 {
1284 if (GetTopWindow())
1285 GetTopWindow()->Close(TRUE);
1286 }
1287
1288 // Default behaviour: close the application with prompts. The
1289 // user can veto the close, and therefore the end session.
1290 void wxApp::OnQueryEndSession(wxCloseEvent& event)
1291 {
1292 if (GetTopWindow())
1293 {
1294 if (!GetTopWindow()->Close(!event.CanVeto()))
1295 event.Veto(TRUE);
1296 }
1297 }
1298
1299 /* static */
1300 int wxApp::GetComCtl32Version()
1301 {
1302 #ifdef __WXMICROWIN__
1303 return 0;
1304 #else
1305 // cache the result
1306 static int s_verComCtl32 = -1;
1307
1308 wxCRIT_SECT_DECLARE(csComCtl32);
1309 wxCRIT_SECT_LOCKER(lock, csComCtl32);
1310
1311 if ( s_verComCtl32 == -1 )
1312 {
1313 // initally assume no comctl32.dll at all
1314 s_verComCtl32 = 0;
1315
1316 // do we have it?
1317 HMODULE hModuleComCtl32 = ::GetModuleHandle(wxT("COMCTL32"));
1318
1319 // if so, then we can check for the version
1320 if ( hModuleComCtl32 )
1321 {
1322 // try to use DllGetVersion() if available in _headers_
1323 #ifdef DLLVER_PLATFORM_WINDOWS // defined in shlwapi.h
1324 DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)
1325 ::GetProcAddress(hModuleComCtl32, "DllGetVersion");
1326 if ( pfnDllGetVersion )
1327 {
1328 DLLVERSIONINFO dvi;
1329 dvi.cbSize = sizeof(dvi);
1330
1331 HRESULT hr = (*pfnDllGetVersion)(&dvi);
1332 if ( FAILED(hr) )
1333 {
1334 wxLogApiError(_T("DllGetVersion"), hr);
1335 }
1336 else
1337 {
1338 // this is incompatible with _WIN32_IE values, but
1339 // compatible with the other values returned by
1340 // GetComCtl32Version()
1341 s_verComCtl32 = 100*dvi.dwMajorVersion +
1342 dvi.dwMinorVersion;
1343 }
1344 }
1345 #endif
1346 // DllGetVersion() unavailable either during compile or
1347 // run-time, try to guess the version otherwise
1348 if ( !s_verComCtl32 )
1349 {
1350 // InitCommonControlsEx is unique to 4.70 and later
1351 FARPROC theProc = ::GetProcAddress
1352 (
1353 hModuleComCtl32,
1354 "InitCommonControlsEx"
1355 );
1356
1357 if ( !theProc )
1358 {
1359 // not found, must be 4.00
1360 s_verComCtl32 = 400;
1361 }
1362 else
1363 {
1364 // many symbols appeared in comctl32 4.71, could use
1365 // any of them except may be DllInstall
1366 theProc = ::GetProcAddress
1367 (
1368 hModuleComCtl32,
1369 "InitializeFlatSB"
1370 );
1371 if ( !theProc )
1372 {
1373 // not found, must be 4.70
1374 s_verComCtl32 = 470;
1375 }
1376 else
1377 {
1378 // found, must be 4.71
1379 s_verComCtl32 = 471;
1380 }
1381 }
1382 }
1383 }
1384 }
1385
1386 return s_verComCtl32;
1387 #endif
1388 }
1389
1390 void wxExit()
1391 {
1392 wxLogError(_("Fatal error: exiting"));
1393
1394 wxApp::CleanUp();
1395 exit(0);
1396 }
1397
1398 // Yield to incoming messages
1399
1400 bool wxApp::Yield(bool onlyIfNeeded)
1401 {
1402 // MT-FIXME
1403 static bool s_inYield = FALSE;
1404
1405 // disable log flushing from here because a call to wxYield() shouldn't
1406 // normally result in message boxes popping up &c
1407 wxLog::Suspend();
1408
1409 if ( s_inYield )
1410 {
1411 if ( !onlyIfNeeded )
1412 {
1413 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1414 }
1415
1416 return FALSE;
1417 }
1418
1419 s_inYield = TRUE;
1420
1421 // we don't want to process WM_QUIT from here - it should be processed in
1422 // the main event loop in order to stop it
1423 MSG msg;
1424 while ( PeekMessage(&msg, (HWND)0, 0, 0, PM_NOREMOVE) &&
1425 msg.message != WM_QUIT )
1426 {
1427 #if wxUSE_THREADS
1428 wxMutexGuiLeaveOrEnter();
1429 #endif // wxUSE_THREADS
1430
1431 if ( !wxTheApp->DoMessage() )
1432 break;
1433 }
1434
1435 // if there are pending events, we must process them.
1436 ProcessPendingEvents();
1437
1438 // let the logs be flashed again
1439 wxLog::Resume();
1440
1441 s_inYield = FALSE;
1442
1443 return TRUE;
1444 }
1445
1446 bool wxHandleFatalExceptions(bool doit)
1447 {
1448 #if wxUSE_ON_FATAL_EXCEPTION
1449 // assume this can only be called from the main thread
1450 gs_handleExceptions = doit;
1451
1452 return TRUE;
1453 #else
1454 wxFAIL_MSG(_T("set wxUSE_ON_FATAL_EXCEPTION to 1 to use this function"));
1455
1456 (void)doit;
1457 return FALSE;
1458 #endif
1459 }
1460
1461 //-----------------------------------------------------------------------------
1462 // wxWakeUpIdle
1463 //-----------------------------------------------------------------------------
1464
1465 void wxWakeUpIdle()
1466 {
1467 // Send the top window a dummy message so idle handler processing will
1468 // start up again. Doing it this way ensures that the idle handler
1469 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1470 // the same for the main app thread only)
1471 wxWindow *topWindow = wxTheApp->GetTopWindow();
1472 if ( topWindow )
1473 {
1474 if ( !::PostMessage(GetHwndOf(topWindow), WM_NULL, 0, 0) )
1475 {
1476 // should never happen
1477 wxLogLastError(wxT("PostMessage(WM_NULL)"));
1478 }
1479 }
1480 }
1481
1482 //-----------------------------------------------------------------------------
1483
1484 wxIcon
1485 wxApp::GetStdIcon(int which) const
1486 {
1487 switch(which)
1488 {
1489 case wxICON_INFORMATION:
1490 return wxIcon("wxICON_INFO");
1491
1492 case wxICON_QUESTION:
1493 return wxIcon("wxICON_QUESTION");
1494
1495 case wxICON_EXCLAMATION:
1496 return wxIcon("wxICON_WARNING");
1497
1498 default:
1499 wxFAIL_MSG(wxT("requested non existent standard icon"));
1500 // still fall through
1501
1502 case wxICON_HAND:
1503 return wxIcon("wxICON_ERROR");
1504 }
1505 }
1506
1507 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1508 // if in a separate file. So include it here to ensure it's linked.
1509 #if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__) && !defined(WXMAKINGDLL))
1510 #include "main.cpp"
1511 #endif