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