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