1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "app.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
35 #include "wx/gdicmn.h"
38 #include "wx/cursor.h"
40 #include "wx/palette.h"
42 #include "wx/dialog.h"
43 #include "wx/msgdlg.h"
45 #include "wx/dynarray.h"
46 #include "wx/wxchar.h"
50 #include "wx/module.h"
52 #include "wx/msw/private.h"
55 #include "wx/thread.h"
57 // define the array of MSG strutures
58 WX_DECLARE_OBJARRAY(MSG
, wxMsgArray
);
60 #include "wx/arrimpl.cpp"
62 WX_DEFINE_OBJARRAY(wxMsgArray
);
63 #endif // wxUSE_THREADS
65 #if wxUSE_WX_RESOURCES
66 #include "wx/resource.h"
69 // OLE is used for drag-and-drop, clipboard, OLE Automation...
70 #if defined(__GNUWIN32__) || defined(__SC__) || defined(__SALFORDC__)
74 #endif // broken compilers
83 #if (defined(__WIN95__) && !defined(__GNUWIN32__)) || defined(__TWIN32__)
87 #include "wx/msw/msvcrt.h"
89 // ---------------------------------------------------------------------------
91 // ---------------------------------------------------------------------------
93 extern wxChar
*wxBuffer
;
94 extern wxChar
*wxOsVersion
;
95 extern wxList
*wxWinHandleList
;
96 extern wxList WXDLLEXPORT wxPendingDelete
;
98 extern wxList
*wxPendingEvents
;
99 extern wxCriticalSection
*wxPendingEventsLocker
;
101 extern void wxSetKeyboardHook(bool doIt
);
102 extern wxCursor
*g_globalCursor
;
104 HINSTANCE wxhInstance
= 0;
106 wxApp
*wxTheApp
= NULL
;
108 // FIXME why not const? and not static?
109 wxChar wxFrameClassName
[] = _T("wxFrameClass");
110 wxChar wxMDIFrameClassName
[] = _T("wxMDIFrameClass");
111 wxChar wxMDIChildFrameClassName
[] = _T("wxMDIChildFrameClass");
112 wxChar wxPanelClassName
[] = _T("wxPanelClass");
113 wxChar wxCanvasClassName
[] = _T("wxCanvasClass");
115 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
116 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
117 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
119 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
120 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
121 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
123 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
125 LRESULT APIENTRY
wxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
127 #if defined(__WIN95__) && !defined(__TWIN32__)
128 #define wxUSE_RICHEDIT 1
130 #define wxUSE_RICHEDIT 0
134 static HINSTANCE gs_hRichEdit
= (HINSTANCE
) NULL
;
137 // ===========================================================================
139 // ===========================================================================
141 // ---------------------------------------------------------------------------
143 // ---------------------------------------------------------------------------
145 #if !USE_SHARED_LIBRARY
146 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
148 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
149 EVT_IDLE(wxApp::OnIdle
)
150 EVT_END_SESSION(wxApp::OnEndSession
)
151 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
156 bool wxApp::Initialize()
158 // Some people may wish to use this, but
159 // probably it shouldn't be here by default.
161 // wxRedirectIOToConsole();
164 wxBuffer
= new wxChar
[1500]; // FIXME
166 wxClassInfo::InitializeClasses();
169 wxGetResource(_T("wxWindows"), _T("OsVersion"), &wxOsVersion
);
172 // I'm annoyed ... I don't know where to put this and I don't want to
173 // create a module for that as it's part of the core.
175 wxPendingEvents
= new wxList();
176 wxPendingEventsLocker
= new wxCriticalSection();
179 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
180 wxTheColourDatabase
->Initialize();
182 wxInitializeStockLists();
183 wxInitializeStockObjects();
185 #if wxUSE_WX_RESOURCES
186 wxInitializeResourceSystem();
189 wxBitmap::InitStandardHandlers();
191 #if defined(__WIN95__)
192 InitCommonControls();
195 gs_hRichEdit
= LoadLibrary(_T("RICHED32.DLL"));
197 if (gs_hRichEdit
== (HINSTANCE
) NULL
)
199 wxLogError(_("Could not initialise Rich Edit DLL"));
201 #endif // wxUSE_RICHEDIT
205 // for OLE, enlarge message queue to be as large as possible
207 while (!SetMessageQueue(iMsg
) && (iMsg
-= 8));
210 // we need to initialize OLE library
211 if ( FAILED(::OleInitialize(NULL
)) )
212 wxLogError(_("Cannot initialize OLE"));
216 if (!Ctl3dRegister(wxhInstance
))
217 wxLogError(_T("Cannot register CTL3D"));
219 Ctl3dAutoSubclass(wxhInstance
);
222 g_globalCursor
= new wxCursor
;
224 wxSTD_FRAME_ICON
= LoadIcon(wxhInstance
, _T("wxSTD_FRAME"));
225 wxSTD_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxSTD_MDIPARENTFRAME"));
226 wxSTD_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxSTD_MDICHILDFRAME"));
228 wxDEFAULT_FRAME_ICON
= LoadIcon(wxhInstance
, _T("wxDEFAULT_FRAME"));
229 wxDEFAULT_MDIPARENTFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxDEFAULT_MDIPARENTFRAME"));
230 wxDEFAULT_MDICHILDFRAME_ICON
= LoadIcon(wxhInstance
, _T("wxDEFAULT_MDICHILDFRAME"));
232 RegisterWindowClasses();
234 // Create the brush for disabling bitmap buttons
237 lb
.lbStyle
= BS_PATTERN
;
238 lb
.lbHatch
= (int)LoadBitmap( wxhInstance
, _T("wxDISABLE_BUTTON_BITMAP") );
241 wxDisableButtonBrush
= ::CreateBrushIndirect( & lb
);
242 ::DeleteObject( (HGDIOBJ
)lb
.lbHatch
);
244 //else: wxWindows resources are probably not linked in
250 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
252 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
253 // PLEASE DO NOT ALTER THIS.
254 #if defined(__VISUALC__) && !defined(WXMAKINGDLL)
255 extern char wxDummyChar
;
256 if (wxDummyChar
) wxDummyChar
++;
259 wxSetKeyboardHook(TRUE
);
261 wxModule::RegisterModules();
262 if (!wxModule::InitializeModules())
267 // ---------------------------------------------------------------------------
268 // RegisterWindowClasses
269 // ---------------------------------------------------------------------------
271 bool wxApp::RegisterWindowClasses()
275 // the fields which are common to all classes
276 wndclass
.style
= CS_HREDRAW
| CS_VREDRAW
| CS_DBLCLKS
;
277 wndclass
.lpfnWndProc
= (WNDPROC
)wxWndProc
;
278 wndclass
.cbClsExtra
= 0;
279 wndclass
.cbWndExtra
= sizeof( DWORD
); // what is this DWORD used for?
280 wndclass
.hInstance
= wxhInstance
;
281 wndclass
.hIcon
= (HICON
) NULL
;
282 wndclass
.hCursor
= ::LoadCursor((HINSTANCE
)NULL
, IDC_ARROW
);
283 wndclass
.lpszMenuName
= NULL
;
285 // Register the frame window class.
286 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_APPWORKSPACE
+ 1);
287 #ifdef _MULTIPLE_INSTANCES
288 sprintf( wxFrameClassName
,"wxFrameClass%d", wxhInstance
);
290 wndclass
.lpszClassName
= wxFrameClassName
;
292 if ( !RegisterClass(&wndclass
) )
294 wxLogLastError("RegisterClass(frame)");
299 // Register the MDI frame window class.
300 wndclass
.hbrBackground
= (HBRUSH
)NULL
; // paint MDI frame ourselves
301 wndclass
.lpszClassName
= wxMDIFrameClassName
;
303 if ( !RegisterClass(&wndclass
) )
305 wxLogLastError("RegisterClass(MDI parent)");
310 // Register the MDI child frame window class.
311 wndclass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
312 wndclass
.lpszClassName
= wxMDIChildFrameClassName
;
314 if ( !RegisterClass(&wndclass
) )
316 wxLogLastError("RegisterClass(MDI child)");
321 // Register the panel window class.
322 wndclass
.hbrBackground
= (HBRUSH
) GetStockObject( LTGRAY_BRUSH
);
323 wndclass
.lpszClassName
= wxPanelClassName
;
325 if ( !RegisterClass(&wndclass
) )
327 wxLogLastError("RegisterClass(panel)");
332 // Register the canvas and textsubwindow class name
333 wndclass
.hbrBackground
= (HBRUSH
)NULL
;
334 wndclass
.lpszClassName
= wxCanvasClassName
;
336 if ( !RegisterClass(&wndclass
) )
338 wxLogLastError("RegisterClass(canvas)");
346 // ---------------------------------------------------------------------------
347 // Convert Windows to argc, argv style
348 // ---------------------------------------------------------------------------
350 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
354 wxString
cmdLine(lpCmdLine
);
357 // Get application name
358 wxChar name
[260]; // 260 is MAX_PATH value from windef.h
359 ::GetModuleFileName(wxhInstance
, name
, WXSIZEOF(name
));
364 wxStrcpy(name
, wxFileNameFromPath(name
));
365 wxStripExtension(name
);
366 wxTheApp
->SetAppName(name
);
369 // Treat strings enclosed in double-quotes as single arguments
371 int len
= cmdLine
.Length();
375 while ((i
< len
) && wxIsspace(cmdLine
.GetChar(i
)))
380 if (cmdLine
.GetChar(i
) == _T('"')) // We found the start of a string
384 while ((i
< len
) && (cmdLine
.GetChar(i
) != _T('"')))
387 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
393 i
++; // Skip past 2nd quote
395 else // Unquoted argument
398 while ((i
< len
) && !wxIsspace(cmdLine
.GetChar(i
)))
401 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
409 wxTheApp
->argv
= new wxChar
*[count
+ 1];
410 for (i
= 0; i
< count
; i
++)
412 wxString
arg(args
[i
]);
413 wxTheApp
->argv
[i
] = copystring((const wxChar
*)arg
);
415 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
416 wxTheApp
->argc
= count
;
419 //// Cleans up any wxWindows internal structures left lying around
421 void wxApp::CleanUp()
426 // flush the logged messages if any and install a 'safer' log target: the
427 // default one (wxLogGui) can't be used after the resources are freed just
428 // below and the user suppliedo ne might be even more unsafe (using any
429 // wxWindows GUI function is unsafe starting from now)
430 wxLog::DontCreateOnDemand();
432 // this will flush the old messages if any
433 delete wxLog::SetActiveTarget(new wxLogStderr
);
436 // One last chance for pending objects to be cleaned up
437 wxTheApp
->DeletePendingObjects();
439 wxModule::CleanUpModules();
441 #if wxUSE_WX_RESOURCES
442 wxCleanUpResourceSystem();
444 // wxDefaultResourceTable->ClearTable();
447 // Indicate that the cursor can be freed, so that cursor won't be deleted
448 // by deleting the bitmap list before g_globalCursor goes out of scope
449 // (double deletion of the cursor).
450 wxSetCursor(wxNullCursor
);
451 delete g_globalCursor
;
452 g_globalCursor
= NULL
;
454 wxDeleteStockObjects();
456 // Destroy all GDI lists, etc.
457 wxDeleteStockLists();
459 delete wxTheColourDatabase
;
460 wxTheColourDatabase
= NULL
;
462 wxBitmap::CleanUpHandlers();
467 //// WINDOWS-SPECIFIC CLEANUP
469 wxSetKeyboardHook(FALSE
);
474 if (gs_hRichEdit
!= (HINSTANCE
) NULL
)
475 FreeLibrary(gs_hRichEdit
);
484 if (wxSTD_FRAME_ICON
)
485 DestroyIcon(wxSTD_FRAME_ICON
);
486 if (wxSTD_MDICHILDFRAME_ICON
)
487 DestroyIcon(wxSTD_MDICHILDFRAME_ICON
);
488 if (wxSTD_MDIPARENTFRAME_ICON
)
489 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON
);
491 if (wxDEFAULT_FRAME_ICON
)
492 DestroyIcon(wxDEFAULT_FRAME_ICON
);
493 if (wxDEFAULT_MDICHILDFRAME_ICON
)
494 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
495 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
496 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
498 if ( wxDisableButtonBrush
)
499 ::DeleteObject( wxDisableButtonBrush
);
506 Ctl3dUnregister(wxhInstance
);
510 delete wxWinHandleList
;
512 // GL: I'm annoyed ... I don't know where to put this and I don't want to
513 // create a module for that as it's part of the core.
515 delete wxPendingEvents
;
516 delete wxPendingEventsLocker
;
517 // If we don't do the following, we get an apparent memory leak.
518 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
521 wxClassInfo::CleanUpClasses();
526 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
527 // At this point we want to check if there are any memory
528 // blocks that aren't part of the wxDebugContext itself,
529 // as a special case. Then when dumping we need to ignore
530 // wxDebugContext, too.
531 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
533 wxLogDebug(_T("There were memory leaks."));
534 wxDebugContext::Dump();
535 wxDebugContext::PrintStatistics();
537 // wxDebugContext::SetStream(NULL, NULL);
541 // do it as the very last thing because everything else can log messages
542 delete wxLog::SetActiveTarget(NULL
);
546 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
548 // temporarily disable this warning which would be generated in release builds
551 #pragma warning(disable: 4715) // not all control paths return a value
554 //// Main wxWindows entry point
555 int wxEntry(WXHINSTANCE hInstance
,
556 WXHINSTANCE
WXUNUSED(hPrevInstance
),
561 // do check for memory leaks on program exit
562 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
563 // deallocated memory which may be used to simulate low-memory condition)
564 wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF
);
566 // take everything into a try-except block in release build
567 // FIXME other compilers must support Win32 SEH (structured exception
568 // handling) too, just find the appropriate keyword in their docs!
569 // Please note that it's _not_ the same as C++ exceptions!
570 #if !defined(__WXDEBUG__) && defined(__VISUALC__)
571 #define CATCH_PROGRAM_EXCEPTIONS
575 #undef CATCH_PROGRAM_EXCEPTIONS
578 wxhInstance
= (HINSTANCE
) hInstance
;
580 if (!wxApp::Initialize())
583 // create the application object or ensure that one already exists
586 // The app may have declared a global application object, but we recommend
587 // the IMPLEMENT_APP macro is used instead, which sets an initializer
588 // function for delayed, dynamic app object construction.
589 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
590 _T("No initializer - use IMPLEMENT_APP macro.") );
592 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
595 wxCHECK_MSG( wxTheApp
, 0, _T("You have to define an instance of wxApp!") );
597 // save the WinMain() parameters
598 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
599 wxTheApp
->m_nCmdShow
= nCmdShow
;
601 // GUI-specific initialisation. In fact on Windows we don't have any,
602 // but this call is provided for compatibility across platforms.
603 wxTheApp
->OnInitGui();
607 if ( wxTheApp
->OnInit() )
611 retValue
= wxTheApp
->OnRun();
614 // We want to initialize, but not run or exit immediately.
617 //else: app initialization failed, so we skipped OnRun()
619 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
622 // Forcibly delete the window.
623 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
624 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
626 topWindow
->Close(TRUE
);
627 wxTheApp
->DeletePendingObjects();
632 wxTheApp
->SetTopWindow(NULL
);
642 #ifdef CATCH_PROGRAM_EXCEPTIONS
644 __except ( EXCEPTION_EXECUTE_HANDLER
) {
647 wxTheApp->OnFatalException();
650 // using wxLog would be unsafe here
652 _("Unrecoverable program error detected: "
653 " the application will terminate."),
655 MB_APPLMODAL
| MB_ICONSTOP
| MB_OK
);
657 ::ExitProcess(3); // the same exit code as abort()
661 #endif // CATCH_PROGRAM_EXCEPTIONS
664 // restore warning state
666 #pragma warning(default: 4715) // not all control paths return a value
671 //// Entry point for DLLs
673 int wxEntry(WXHINSTANCE hInstance
)
675 wxhInstance
= (HINSTANCE
) hInstance
;
678 // The app may have declared a global application object, but we recommend
679 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
680 // for delayed, dynamic app object construction.
683 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
684 "No initializer - use IMPLEMENT_APP macro." );
686 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
689 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
692 wxTheApp
->argv
= NULL
;
694 wxTheApp
->OnInitGui();
698 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
699 if ( topWindow
&& topWindow
->GetHWND())
701 topWindow
->Show(TRUE
);
708 //// Static member initialization
710 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
716 m_wantDebugOutput
= TRUE
;
720 m_printMode
= wxPRINT_WINDOWS
;
721 m_exitOnFrameDelete
= TRUE
;
727 // Delete command-line args
729 for (i
= 0; i
< argc
; i
++)
736 bool wxApp::Initialized()
744 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
750 * Get and process a message, returning FALSE if WM_QUIT
751 * received (and also set the flag telling the app to exit the main loop)
754 bool wxApp::DoMessage()
756 BOOL rc
= ::GetMessage(&s_currentMsg
, (HWND
) NULL
, 0, 0);
766 // should never happen, but let's test for it nevertheless
767 wxLogLastError("GetMessage");
772 wxASSERT_MSG( wxThread::IsMain(),
773 _T("only the main thread can process Windows messages") );
775 static bool s_hadGuiLock
= TRUE
;
776 static wxMsgArray s_aSavedMessages
;
778 // if a secondary thread owns is doing GUI calls, save all messages for
779 // later processing - we can't process them right now because it will
780 // lead to recursive library calls (and we're not reentrant)
781 if ( !wxGuiOwnedByMainThread() )
783 s_hadGuiLock
= FALSE
;
785 // leave out WM_COMMAND messages: too dangerous, sometimes
786 // the message will be processed twice
787 if ( !wxIsWaitingForThread() ||
788 s_currentMsg
.message
!= WM_COMMAND
)
790 s_aSavedMessages
.Add(s_currentMsg
);
797 // have we just regained the GUI lock? if so, post all of the saved
800 // FIXME of course, it's not _exactly_ the same as processing the
801 // messages normally - expect some things to break...
806 size_t count
= s_aSavedMessages
.Count();
807 for ( size_t n
= 0; n
< count
; n
++ )
809 MSG
& msg
= s_aSavedMessages
[n
];
811 if ( !ProcessMessage((WXMSG
*)&msg
) )
813 ::TranslateMessage(&msg
);
814 ::DispatchMessage(&msg
);
818 s_aSavedMessages
.Empty();
821 #endif // wxUSE_THREADS
823 // Process the message
824 if ( !ProcessMessage((WXMSG
*)&s_currentMsg
) )
826 ::TranslateMessage(&s_currentMsg
);
827 ::DispatchMessage(&s_currentMsg
);
835 * Keep trying to process messages until WM_QUIT
838 * If there are messages to be processed, they will all be
839 * processed and OnIdle will not be called.
840 * When there are no more messages, OnIdle is called.
841 * If OnIdle requests more time,
842 * it will be repeatedly called so long as there are no pending messages.
843 * A 'feature' of this is that once OnIdle has decided that no more processing
844 * is required, then it won't get processing time until further messages
845 * are processed (it'll sit in DoMessage).
848 int wxApp::MainLoop()
852 while ( m_keepGoing
)
855 wxMutexGuiLeaveOrEnter();
856 #endif // wxUSE_THREADS
858 while ( !::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) &&
867 return s_currentMsg
.wParam
;
870 // Returns TRUE if more time is needed.
871 bool wxApp::ProcessIdle()
874 event
.SetEventObject(this);
877 return event
.MoreRequested();
881 void wxApp::ProcessPendingEvents()
883 wxNode
*node
= wxPendingEvents
->First();
884 wxCriticalSectionLocker
locker(*wxPendingEventsLocker
);
888 wxEvtHandler
*handler
= (wxEvtHandler
*)node
->Data();
890 handler
->ProcessPendingEvents();
893 node
= wxPendingEvents
->First();
899 void wxApp::ExitMainLoop()
904 bool wxApp::Pending()
906 return (::PeekMessage(&s_currentMsg
, 0, 0, 0, PM_NOREMOVE
) != 0);
909 void wxApp::Dispatch()
915 * Give all windows a chance to preprocess
916 * the message. Some may have accelerator tables, or have
920 bool wxApp::ProcessMessage(WXMSG
*wxmsg
)
922 MSG
*msg
= (MSG
*)wxmsg
;
923 HWND hWnd
= msg
->hwnd
;
924 wxWindow
*wndThis
= wxFindWinFromHandle((WXHWND
)hWnd
), *wnd
;
926 // Try translations first; find the youngest window with
927 // a translation table.
928 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
930 if ( wnd
->MSWTranslateMessage(wxmsg
) )
934 // Anyone for a non-translation message? Try youngest descendants first.
935 for ( wnd
= wndThis
; wnd
; wnd
= wnd
->GetParent() )
937 if ( wnd
->MSWProcessMessage(wxmsg
) )
944 void wxApp::OnIdle(wxIdleEvent
& event
)
946 static bool s_inOnIdle
= FALSE
;
948 // Avoid recursion (via ProcessEvent default case)
954 // 'Garbage' collection of windows deleted with Close().
955 DeletePendingObjects();
958 // flush the logged messages if any
959 wxLog
*pLog
= wxLog::GetActiveTarget();
960 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
964 // Send OnIdle events to all windows
965 if ( SendIdleEvents() )
967 // SendIdleEvents() returns TRUE if at least one window requested more
969 event
.RequestMore(TRUE
);
972 // If they are pending events, we must process them.
974 ProcessPendingEvents();
979 // Send idle event to all top-level windows
980 bool wxApp::SendIdleEvents()
982 bool needMore
= FALSE
;
984 wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
987 wxWindow
* win
= node
->GetData();
988 if (SendIdleEvents(win
))
990 node
= node
->GetNext();
996 // Send idle event to window and all subwindows
997 bool wxApp::SendIdleEvents(wxWindow
* win
)
999 bool needMore
= FALSE
;
1002 event
.SetEventObject(win
);
1003 win
->GetEventHandler()->ProcessEvent(event
);
1005 if (event
.MoreRequested())
1008 wxNode
* node
= win
->GetChildren().First();
1011 wxWindow
* win
= (wxWindow
*) node
->Data();
1012 if (SendIdleEvents(win
))
1015 node
= node
->Next();
1020 void wxApp::DeletePendingObjects()
1022 wxNode
*node
= wxPendingDelete
.First();
1025 wxObject
*obj
= (wxObject
*)node
->Data();
1029 if (wxPendingDelete
.Member(obj
))
1032 // Deleting one object may have deleted other pending
1033 // objects, so start from beginning of list again.
1034 node
= wxPendingDelete
.First();
1038 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1041 GetTopWindow()->Close(TRUE
);
1044 // Default behaviour: close the application with prompts. The
1045 // user can veto the close, and therefore the end session.
1046 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1050 if (!GetTopWindow()->Close(!event
.CanVeto()))
1055 wxLog
* wxApp::CreateLogTarget()
1057 return new wxLogGui
;
1060 wxWindow
* wxApp::GetTopWindow() const
1064 else if (wxTopLevelWindows
.GetCount() > 0)
1065 return wxTopLevelWindows
.GetFirst()->GetData();
1070 int wxApp::GetComCtl32Version() const
1072 // have we loaded COMCTL32 yet?
1073 HMODULE theModule
= ::GetModuleHandle(_T("COMCTL32"));
1076 // if so, then we can check for the version
1079 // InitCommonControlsEx is unique to 4.7 and later
1080 FARPROC theProc
= ::GetProcAddress(theModule
, "InitCommonControlsEx");
1083 { // not found, must be 4.00
1088 // The following symbol are unique to 4.71
1090 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
1091 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
1092 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
1093 // FlatSB_ShowScrollBar
1094 // _DrawIndirectImageList _DuplicateImageList
1096 // UninitializeFlatSB
1097 // we could check for any of these - I chose DllInstall
1098 FARPROC theProc
= ::GetProcAddress(theModule
, "DllInstall");
1101 // not found, must be 4.70
1105 { // found, must be 4.71
1115 wxLogError(_("Fatal error: exiting"));
1120 // Yield to incoming messages
1124 // We want to go back to the main message loop
1125 // if we see a WM_QUIT. (?)
1127 while (PeekMessage(&msg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1129 while (PeekMessage(&msg
, NULL
, 0, 0, PM_NOREMOVE
) && msg
.message
!= WM_QUIT
)
1132 if ( !wxTheApp
->DoMessage() )
1135 // If they are pending events, we must process them.
1137 wxTheApp
->ProcessPendingEvents();
1143 HINSTANCE
wxGetInstance()
1148 void wxSetInstance(HINSTANCE hInst
)
1150 wxhInstance
= hInst
;
1153 // For some reason, with MSVC++ 1.5, WinMain isn't linked in properly
1154 // if in a separate file. So include it here to ensure it's linked.
1155 #if (defined(__VISUALC__) && !defined(__WIN32__)) || (defined(__GNUWIN32__) && !defined(__TWIN32__))