1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/dynarray.h"
30 # include "wx/wxchar.h"
35 #include "wx/module.h"
37 #include "wx/os2/private.h"
40 #include "wx/thread.h"
42 // define the array of MSG strutures
43 // TODO: WX_DECLARE_OBJARRAY(MSG, wxMsgArray);
45 #include "wx/arrimpl.cpp"
47 // TODO: WX_DEFINE_OBJARRAY(wxMsgArray);
48 #endif // wxUSE_THREADS
50 #if wxUSE_WX_RESOURCES
51 #include "wx/resource.h"
57 // ---------------------------------------------------------------------------
59 // ---------------------------------------------------------------------------
61 extern wxChar
*wxBuffer
;
62 extern wxChar
*wxOsVersion
;
63 extern wxList
*wxWinHandleList
;
64 extern wxList WXDLLEXPORT wxPendingDelete
;
66 extern wxList
*wxPendingEvents
;
67 extern wxCriticalSection
*wxPendingEventsLocker
;
69 extern void wxSetKeyboardHook(bool doIt
);
70 extern wxCursor
*g_globalCursor
;
72 HINSTANCE wxhInstance
= 0;
73 // TODO: MSG s_currentMsg;
74 wxApp
*wxTheApp
= NULL
;
76 // FIXME why not const? and not static?
78 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
79 // with NR suffix - wxWindow::MSWCreate() supposes this
80 wxChar wxFrameClassName
[] = wxT("wxFrameClass");
81 wxChar wxFrameClassNameNoRedraw
[] = wxT("wxFrameClassNR");
82 wxChar wxMDIFrameClassName
[] = wxT("wxMDIFrameClass");
83 wxChar wxMDIFrameClassNameNoRedraw
[] = wxT("wxMDIFrameClassNR");
84 wxChar wxMDIChildFrameClassName
[] = wxT("wxMDIChildFrameClass");
85 wxChar wxMDIChildFrameClassNameNoRedraw
[] = wxT("wxMDIChildFrameClassNR");
86 wxChar wxPanelClassName
[] = wxT("wxPanelClass");
87 wxChar wxCanvasClassName
[] = wxT("wxCanvasClass");
89 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
90 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
91 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
93 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
94 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
95 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
97 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
99 MRESULT
wxWndProc(HWND
, UINT
, MPARAM
, MPARAM
);
101 // ===========================================================================
103 // ===========================================================================
105 // ---------------------------------------------------------------------------
107 // ---------------------------------------------------------------------------
109 #if !USE_SHARED_LIBRARY
110 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
112 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
113 EVT_IDLE(wxApp::OnIdle
)
114 EVT_END_SESSION(wxApp::OnEndSession
)
115 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
120 bool wxApp::Initialize()
122 // Some people may wish to use this, but
123 // probably it shouldn't be here by default.
125 // wxRedirectIOToConsole();
128 wxBuffer
= new wxChar
[1500]; // FIXME
130 wxClassInfo::InitializeClasses();
133 wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion
);
136 // I'm annoyed ... I don't know where to put this and I don't want to
137 // create a module for that as it's part of the core.
139 wxPendingEvents
= new wxList();
140 wxPendingEventsLocker
= new wxCriticalSection();
143 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
144 wxTheColourDatabase
->Initialize();
146 wxInitializeStockLists();
147 wxInitializeStockObjects();
149 #if wxUSE_WX_RESOURCES
150 wxInitializeResourceSystem();
153 wxBitmap::InitStandardHandlers();
155 g_globalCursor
= new wxCursor
;
159 wxSTD_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_FRAME"));
160 wxSTD_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDIPARENTFRAME"));
161 wxSTD_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxSTD_MDICHILDFRAME"));
163 wxDEFAULT_FRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_FRAME"));
164 wxDEFAULT_MDIPARENTFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDIPARENTFRAME"));
165 wxDEFAULT_MDICHILDFRAME_ICON = LoadIcon(wxhInstance, wxT("wxDEFAULT_MDICHILDFRAME"));
167 RegisterWindowClasses();
169 // Create the brush for disabling bitmap buttons
173 lb.lbStyle = BS_PATTERN;
174 lb.lbHatch = (int)LoadBitmap( wxhInstance, wxT("wxDISABLE_BUTTON_BITMAP") );
177 wxDisableButtonBrush = ::CreateBrushIndirect( & lb );
178 ::DeleteObject( (HGDIOBJ)lb.lbHatch );
181 //else: wxWindows resources are probably not linked in
183 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
185 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
186 // PLEASE DO NOT ALTER THIS.
187 #if !defined(WXMAKINGDLL)
188 extern char wxDummyChar
;
189 if (wxDummyChar
) wxDummyChar
++;
192 wxSetKeyboardHook(TRUE
);
194 wxModule::RegisterModules();
195 if (!wxModule::InitializeModules())
200 // ---------------------------------------------------------------------------
201 // RegisterWindowClasses
202 // ---------------------------------------------------------------------------
204 // TODO we should only register classes really used by the app. For this it
205 // would be enough to just delay the class registration until an attempt
206 // to create a window of this class is made.
207 bool wxApp::RegisterWindowClasses()
213 // for each class we register one with CS_(V|H)REDRAW style and one
214 // without for windows created with wxNO_FULL_REDRAW_ON_REPAINT flag
215 static const long styleNormal = 0; // TODO: CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
216 static const long styleNoRedraw = 0; // TODO: CS_DBLCLKS;
218 // the fields which are common to all classes
219 wndclass.lpfnWndProc = (WNDPROC)wxWndProc;
220 wndclass.cbClsExtra = 0;
221 wndclass.cbWndExtra = sizeof( DWORD ); // VZ: what is this DWORD used for?
222 wndclass.hInstance = wxhInstance;
223 wndclass.hIcon = (HICON) NULL;
224 wndclass.hCursor = 0; // TODO: ::LoadCursor((HINSTANCE)NULL, IDC_ARROW);
225 wndclass.lpszMenuName = NULL;
227 // Register the frame window class.
228 wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
229 wndclass.lpszClassName = wxFrameClassName;
230 wndclass.style = styleNormal;
232 if ( !RegisterClass(&wndclass) )
234 wxLogLastError("RegisterClass(frame)");
240 wndclass.lpszClassName = wxFrameClassNameNoRedraw;
241 wndclass.style = styleNoRedraw;
243 if ( !RegisterClass(&wndclass) )
245 wxLogLastError("RegisterClass(no redraw frame)");
250 // Register the MDI frame window class.
251 wndclass.hbrBackground = (HBRUSH)NULL; // paint MDI frame ourselves
252 wndclass.lpszClassName = wxMDIFrameClassName;
253 wndclass.style = styleNormal;
255 if ( !RegisterClass(&wndclass) )
257 wxLogLastError("RegisterClass(MDI parent)");
262 // "no redraw" MDI frame
263 wndclass.lpszClassName = wxMDIFrameClassNameNoRedraw;
264 wndclass.style = styleNoRedraw;
266 if ( !RegisterClass(&wndclass) )
268 wxLogLastError("RegisterClass(no redraw MDI parent frame)");
273 // Register the MDI child frame window class.
274 wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
275 wndclass.lpszClassName = wxMDIChildFrameClassName;
276 wndclass.style = styleNormal;
278 if ( !RegisterClass(&wndclass) )
280 wxLogLastError("RegisterClass(MDI child)");
285 // "no redraw" MDI child frame
286 wndclass.lpszClassName = wxMDIChildFrameClassNameNoRedraw;
287 wndclass.style = styleNoRedraw;
289 if ( !RegisterClass(&wndclass) )
291 wxLogLastError("RegisterClass(no redraw MDI child)");
296 // Register the panel window class.
297 wndclass.hbrBackground = (HBRUSH) GetStockObject( LTGRAY_BRUSH );
298 wndclass.lpszClassName = wxPanelClassName;
299 wndclass.style = styleNormal;
301 if ( !RegisterClass(&wndclass) )
303 wxLogLastError("RegisterClass(panel)");
308 // Register the canvas and textsubwindow class name
309 wndclass.hbrBackground = (HBRUSH)NULL;
310 wndclass.lpszClassName = wxCanvasClassName;
312 if ( !RegisterClass(&wndclass) )
314 wxLogLastError("RegisterClass(canvas)");
322 // ---------------------------------------------------------------------------
323 // Convert Windows to argc, argv style
324 // ---------------------------------------------------------------------------
326 void wxApp::ConvertToStandardCommandArgs(char* lpCmdLine
)
330 wxString
cmdLine(lpCmdLine
);
333 // Get application name
334 wxChar name
[260]; // 260 is MAX_PATH value from windef.h
335 // TODO: ::GetModuleFileName(wxhInstance, name, WXSIZEOF(name));
340 wxStrcpy(name
, wxFileNameFromPath(name
));
341 wxStripExtension(name
);
342 wxTheApp
->SetAppName(name
);
345 // Treat strings enclosed in double-quotes as single arguments
347 int len
= cmdLine
.Length();
351 while ((i
< len
) && wxIsspace(cmdLine
.GetChar(i
)))
356 if (cmdLine
.GetChar(i
) == wxT('"')) // We found the start of a string
360 while ((i
< len
) && (cmdLine
.GetChar(i
) != wxT('"')))
363 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
369 i
++; // Skip past 2nd quote
371 else // Unquoted argument
374 while ((i
< len
) && !wxIsspace(cmdLine
.GetChar(i
)))
377 wxString
arg(cmdLine
.Mid(first
, (i
- first
)));
385 wxTheApp
->argv
= new wxChar
*[count
+ 1];
386 for (i
= 0; i
< count
; i
++)
388 wxString
arg(args
[i
]);
389 wxTheApp
->argv
[i
] = copystring((const wxChar
*)arg
);
391 wxTheApp
->argv
[count
] = NULL
; // argv[] is a NULL-terminated list
392 wxTheApp
->argc
= count
;
395 //// Cleans up any wxWindows internal structures left lying around
397 void wxApp::CleanUp()
402 // flush the logged messages if any and install a 'safer' log target: the
403 // default one (wxLogGui) can't be used after the resources are freed just
404 // below and the user suppliedo ne might be even more unsafe (using any
405 // wxWindows GUI function is unsafe starting from now)
406 wxLog::DontCreateOnDemand();
408 // this will flush the old messages if any
409 delete wxLog::SetActiveTarget(new wxLogStderr
);
412 // One last chance for pending objects to be cleaned up
413 wxTheApp
->DeletePendingObjects();
415 wxModule::CleanUpModules();
417 #if wxUSE_WX_RESOURCES
418 wxCleanUpResourceSystem();
420 // wxDefaultResourceTable->ClearTable();
423 // Indicate that the cursor can be freed, so that cursor won't be deleted
424 // by deleting the bitmap list before g_globalCursor goes out of scope
425 // (double deletion of the cursor).
426 wxSetCursor(wxNullCursor
);
427 delete g_globalCursor
;
428 g_globalCursor
= NULL
;
430 wxDeleteStockObjects();
432 // Destroy all GDI lists, etc.
433 wxDeleteStockLists();
435 delete wxTheColourDatabase
;
436 wxTheColourDatabase
= NULL
;
438 wxBitmap::CleanUpHandlers();
443 //// WINDOWS-SPECIFIC CLEANUP
445 wxSetKeyboardHook(FALSE
);
448 if (wxSTD_FRAME_ICON)
449 DestroyIcon(wxSTD_FRAME_ICON);
450 if (wxSTD_MDICHILDFRAME_ICON)
451 DestroyIcon(wxSTD_MDICHILDFRAME_ICON);
452 if (wxSTD_MDIPARENTFRAME_ICON)
453 DestroyIcon(wxSTD_MDIPARENTFRAME_ICON);
455 if (wxDEFAULT_FRAME_ICON)
456 DestroyIcon(wxDEFAULT_FRAME_ICON);
457 if (wxDEFAULT_MDICHILDFRAME_ICON)
458 DestroyIcon(wxDEFAULT_MDICHILDFRAME_ICON);
459 if (wxDEFAULT_MDIPARENTFRAME_ICON)
460 DestroyIcon(wxDEFAULT_MDIPARENTFRAME_ICON);
462 if ( wxDisableButtonBrush
)
464 // TODO: ::DeleteObject( wxDisableButtonBrush );
468 delete wxWinHandleList
;
470 // GL: I'm annoyed ... I don't know where to put this and I don't want to
471 // create a module for that as it's part of the core.
473 delete wxPendingEvents
;
474 delete wxPendingEventsLocker
;
475 // If we don't do the following, we get an apparent memory leak.
476 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
479 wxClassInfo::CleanUpClasses();
484 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
485 // At this point we want to check if there are any memory
486 // blocks that aren't part of the wxDebugContext itself,
487 // as a special case. Then when dumping we need to ignore
488 // wxDebugContext, too.
489 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
491 wxLogDebug(wxT("There were memory leaks."));
492 wxDebugContext::Dump();
493 wxDebugContext::PrintStatistics();
495 // wxDebugContext::SetStream(NULL, NULL);
499 // do it as the very last thing because everything else can log messages
500 delete wxLog::SetActiveTarget(NULL
);
504 #if !defined(_WINDLL) || (defined(_WINDLL) && defined(WXMAKINGDLL))
506 //// Main wxWindows entry point
507 int wxEntry(WXHINSTANCE hInstance
,
508 WXHINSTANCE
WXUNUSED(hPrevInstance
),
513 // do check for memory leaks on program exit
514 // (another useful flag is _CRTDBG_DELAY_FREE_MEM_DF which doesn't free
515 // deallocated memory which may be used to simulate low-memory condition)
516 // TODO: wxCrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
518 // take everything into a try-except block in release build
519 // FIXME other compilers must support Win32 SEH (structured exception
520 // handling) too, just find the appropriate keyword in their docs!
521 // Please note that it's _not_ the same as C++ exceptions!
523 wxhInstance
= (HINSTANCE
) hInstance
;
525 if (!wxApp::Initialize())
528 // create the application object or ensure that one already exists
531 // The app may have declared a global application object, but we recommend
532 // the IMPLEMENT_APP macro is used instead, which sets an initializer
533 // function for delayed, dynamic app object construction.
534 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
535 wxT("No initializer - use IMPLEMENT_APP macro.") );
537 wxTheApp
= (wxApp
*)(*wxApp::GetInitializerFunction()) ();
540 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
542 // save the WinMain() parameters
543 wxTheApp
->ConvertToStandardCommandArgs(lpCmdLine
);
544 wxTheApp
->m_nCmdShow
= nCmdShow
;
546 // GUI-specific initialisation. In fact on Windows we don't have any,
547 // but this call is provided for compatibility across platforms.
548 wxTheApp
->OnInitGui();
552 if ( wxTheApp
->OnInit() )
556 retValue
= wxTheApp
->OnRun();
559 // We want to initialize, but not run or exit immediately.
562 //else: app initialization failed, so we skipped OnRun()
564 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
567 // Forcibly delete the window.
568 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
569 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
571 topWindow
->Close(TRUE
);
572 wxTheApp
->DeletePendingObjects();
577 wxTheApp
->SetTopWindow(NULL
);
590 //// Entry point for DLLs
592 int wxEntry(WXHINSTANCE hInstance
)
594 wxhInstance
= (HINSTANCE
) hInstance
;
597 // The app may have declared a global application object, but we recommend
598 // the IMPLEMENT_APP macro is used instead, which sets an initializer function
599 // for delayed, dynamic app object construction.
602 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
603 "No initializer - use IMPLEMENT_APP macro." );
605 wxTheApp
= (* wxApp::GetInitializerFunction()) ();
608 wxCHECK_MSG( wxTheApp
, 0, "You have to define an instance of wxApp!" );
611 wxTheApp
->argv
= NULL
;
613 wxTheApp
->OnInitGui();
617 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
618 if ( topWindow
&& topWindow
->GetHWND())
620 topWindow
->Show(TRUE
);
627 //// Static member initialization
629 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
635 m_wantDebugOutput
= TRUE
;
639 m_printMode
= wxPRINT_WINDOWS
;
640 m_exitOnFrameDelete
= TRUE
;
646 // Delete command-line args
648 for (i
= 0; i
< argc
; i
++)
655 bool wxApp::Initialized()
663 #ifdef _WINDLL // Assume initialized if DLL (no way of telling)
669 * Get and process a message, returning FALSE if WM_QUIT
670 * received (and also set the flag telling the app to exit the main loop)
673 bool wxApp::DoMessage()
675 BOOL rc
= FALSE
; // TODO: ::GetMessage(&s_currentMsg, (HWND) NULL, 0, 0);
685 // should never happen, but let's test for it nevertheless
686 wxLogLastError("GetMessage");
691 wxASSERT_MSG( wxThread::IsMain(),
692 wxT("only the main thread can process Windows messages") );
694 static bool s_hadGuiLock
= TRUE
;
697 static wxMsgArray s_aSavedMessages;
699 // if a secondary thread owns is doing GUI calls, save all messages for
700 // later processing - we can't process them right now because it will
701 // lead to recursive library calls (and we're not reentrant)
702 if ( !wxGuiOwnedByMainThread() )
704 s_hadGuiLock = FALSE;
706 // leave out WM_COMMAND messages: too dangerous, sometimes
707 // the message will be processed twice
708 if ( !wxIsWaitingForThread() ||
709 s_currentMsg.message != WM_COMMAND )
711 s_aSavedMessages.Add(s_currentMsg);
718 // have we just regained the GUI lock? if so, post all of the saved
721 // FIXME of course, it's not _exactly_ the same as processing the
722 // messages normally - expect some things to break...
727 size_t count = s_aSavedMessages.Count();
728 for ( size_t n = 0; n < count; n++ )
730 MSG& msg = s_aSavedMessages[n];
732 if ( !ProcessMessage((WXMSG *)&msg) )
734 ::TranslateMessage(&msg);
735 ::DispatchMessage(&msg);
738 s_aSavedMessages.Empty();
742 #endif // wxUSE_THREADS
744 // Process the message
747 if ( !ProcessMessage((WXMSG *)&s_currentMsg) )
749 ::TranslateMessage(&s_currentMsg);
750 ::DispatchMessage(&s_currentMsg);
759 * Keep trying to process messages until WM_QUIT
762 * If there are messages to be processed, they will all be
763 * processed and OnIdle will not be called.
764 * When there are no more messages, OnIdle is called.
765 * If OnIdle requests more time,
766 * it will be repeatedly called so long as there are no pending messages.
767 * A 'feature' of this is that once OnIdle has decided that no more processing
768 * is required, then it won't get processing time until further messages
769 * are processed (it'll sit in DoMessage).
772 int wxApp::MainLoop()
776 while ( m_keepGoing
)
779 wxMutexGuiLeaveOrEnter();
780 #endif // wxUSE_THREADS
783 while ( !::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) &&
792 // TODO: return s_currentMsg.wParam;
796 // Returns TRUE if more time is needed.
797 bool wxApp::ProcessIdle()
800 event
.SetEventObject(this);
803 return event
.MoreRequested();
807 void wxApp::ProcessPendingEvents()
809 wxNode
*node
= wxPendingEvents
->First();
810 wxCriticalSectionLocker
locker(*wxPendingEventsLocker
);
814 wxEvtHandler
*handler
= (wxEvtHandler
*)node
->Data();
816 handler
->ProcessPendingEvents();
819 node
= wxPendingEvents
->First();
825 void wxApp::ExitMainLoop()
830 bool wxApp::Pending()
832 // TODO: return (::PeekMessage(&s_currentMsg, 0, 0, 0, PM_NOREMOVE) != 0);
836 void wxApp::Dispatch()
842 * Give all windows a chance to preprocess
843 * the message. Some may have accelerator tables, or have
847 bool wxApp::ProcessMessage(WXMSG
*wxmsg
)
851 MSG *msg = (MSG *)wxmsg;
852 HWND hWnd = msg->hwnd;
853 wxWindow *wndThis = wxFindWinFromHandle((WXHWND)hWnd), *wnd;
855 // for some composite controls (like a combobox), wndThis might be NULL
856 // because the subcontrol is not a wxWindow, but only the control itself
857 // is - try to catch this case
858 while ( hWnd && !wndThis )
860 hWnd = 0; // TODO: ::GetParent(hWnd);
861 wndThis = wxFindWinFromHandle((WXHWND)hWnd);
864 // Try translations first; find the youngest window with
865 // a translation table.
866 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
868 if ( wnd->OS2TranslateMessage(wxmsg) )
872 // Anyone for a non-translation message? Try youngest descendants first.
873 for ( wnd = wndThis; wnd; wnd = wnd->GetParent() )
875 if ( wnd->OS2ProcessMessage(wxmsg) )
882 void wxApp::OnIdle(wxIdleEvent
& event
)
884 static bool s_inOnIdle
= FALSE
;
886 // Avoid recursion (via ProcessEvent default case)
892 // 'Garbage' collection of windows deleted with Close().
893 DeletePendingObjects();
896 // flush the logged messages if any
897 wxLog
*pLog
= wxLog::GetActiveTarget();
898 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
902 // Send OnIdle events to all windows
903 if ( SendIdleEvents() )
905 // SendIdleEvents() returns TRUE if at least one window requested more
907 event
.RequestMore(TRUE
);
910 // If they are pending events, we must process them.
912 ProcessPendingEvents();
917 // Send idle event to all top-level windows
918 bool wxApp::SendIdleEvents()
920 bool needMore
= FALSE
;
922 wxWindowList::Node
* node
= wxTopLevelWindows
.GetFirst();
925 wxWindow
* win
= node
->GetData();
926 if (SendIdleEvents(win
))
928 node
= node
->GetNext();
934 // Send idle event to window and all subwindows
935 bool wxApp::SendIdleEvents(wxWindow
* win
)
937 bool needMore
= FALSE
;
940 event
.SetEventObject(win
);
941 win
->GetEventHandler()->ProcessEvent(event
);
943 if (event
.MoreRequested())
946 wxNode
* node
= win
->GetChildren().First();
949 wxWindow
* win
= (wxWindow
*) node
->Data();
950 if (SendIdleEvents(win
))
958 void wxApp::DeletePendingObjects()
960 wxNode
*node
= wxPendingDelete
.First();
963 wxObject
*obj
= (wxObject
*)node
->Data();
967 if (wxPendingDelete
.Member(obj
))
970 // Deleting one object may have deleted other pending
971 // objects, so start from beginning of list again.
972 node
= wxPendingDelete
.First();
976 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
979 GetTopWindow()->Close(TRUE
);
982 // Default behaviour: close the application with prompts. The
983 // user can veto the close, and therefore the end session.
984 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
988 if (!GetTopWindow()->Close(!event
.CanVeto()))
993 int wxApp::GetComCtl32Version() const
995 // TODO: Does OS/2 even need this method?
997 // have we loaded COMCTL32 yet?
998 HMODULE theModule = ::GetModuleHandle(wxT("COMCTL32"));
1001 // if so, then we can check for the version
1004 // InitCommonControlsEx is unique to 4.7 and later
1005 FARPROC theProc = ::GetProcAddress(theModule, "InitCommonControlsEx");
1008 { // not found, must be 4.00
1013 // The following symbol are unique to 4.71
1015 // FlatSB_EnableScrollBar FlatSB_GetScrollInfo FlatSB_GetScrollPos
1016 // FlatSB_GetScrollProp FlatSB_GetScrollRange FlatSB_SetScrollInfo
1017 // FlatSB_SetScrollPos FlatSB_SetScrollProp FlatSB_SetScrollRange
1018 // FlatSB_ShowScrollBar
1019 // _DrawIndirectImageList _DuplicateImageList
1021 // UninitializeFlatSB
1022 // we could check for any of these - I chose DllInstall
1023 FARPROC theProc = ::GetProcAddress(theModule, "DllInstall");
1026 // not found, must be 4.70
1030 { // found, must be 4.71
1042 wxLogError(_("Fatal error: exiting"));
1047 // Yield to incoming messages
1052 // We want to go back to the main message loop
1053 // if we see a WM_QUIT. (?)
1054 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1056 if (!wxTheApp
->DoMessage())
1059 // If they are pending events, we must process them.
1061 wxTheApp
->ProcessPendingEvents();
1066 wxIcon
wxApp::GetStdIcon(int which
) const
1072 case wxICON_INFORMATION:
1073 return wxIcon("wxICON_INFO");
1075 case wxICON_QUESTION:
1076 return wxIcon("wxICON_QUESTION");
1078 case wxICON_EXCLAMATION:
1079 return wxIcon("wxICON_WARNING");
1082 wxFAIL_MSG(wxT("requested non existent standard icon"));
1083 // still fall through
1086 return wxIcon("wxICON_ERROR");
1089 return wxIcon("wxICON_ERROR");
1093 HINSTANCE
wxGetInstance()
1098 void wxSetInstance(HINSTANCE hInst
)
1100 wxhInstance
= hInst
;