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"
36 #include "wx/module.h"
38 #include "wx/os2/private.h"
42 #include <sys\ioctl.h>
43 #include <sys\select.h>
50 #endif // ndef for __EMX__
54 #define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
55 int _System
bsdselect(int,
64 #include "wx/thread.h"
66 // define the array of QMSG strutures
67 WX_DECLARE_OBJARRAY(QMSG
, wxMsgArray
);
69 #include "wx/arrimpl.cpp"
71 WX_DEFINE_OBJARRAY(wxMsgArray
);
72 #endif // wxUSE_THREADS
74 #if wxUSE_WX_RESOURCES
75 #include "wx/resource.h"
79 #include "wx/tooltip.h"
80 #endif // wxUSE_TOOLTIPS
85 // ---------------------------------------------------------------------------
87 // ---------------------------------------------------------------------------
89 extern wxChar
* wxBuffer
;
90 extern wxList
* wxWinHandleList
;
91 extern wxList WXDLLEXPORT wxPendingDelete
;
92 extern wxCursor
* g_globalCursor
;
94 HAB vHabmain
= NULLHANDLE
;
96 wxApp
* wxTheApp
= NULL
;
98 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
99 // with NR suffix - wxWindow::OS2Create() supposes this
100 wxChar wxFrameClassName
[] = wxT("wxFrameClass");
101 wxChar wxFrameClassNameNoRedraw
[] = wxT("wxFrameClassNR");
102 wxChar wxMDIFrameClassName
[] = wxT("wxMDIFrameClass");
103 wxChar wxMDIFrameClassNameNoRedraw
[] = wxT("wxMDIFrameClassNR");
104 wxChar wxMDIChildFrameClassName
[] = wxT("wxMDIChildFrameClass");
105 wxChar wxMDIChildFrameClassNameNoRedraw
[] = wxT("wxMDIChildFrameClassNR");
106 wxChar wxPanelClassName
[] = wxT("wxPanelClass");
107 wxChar wxCanvasClassName
[] = wxT("wxCanvasClass");
109 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
110 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
111 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
113 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
114 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
115 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
117 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
119 MRESULT EXPENTRY
wxWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
120 MRESULT EXPENTRY
wxFrameWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
122 // ===========================================================================
124 // ===========================================================================
126 // ---------------------------------------------------------------------------
127 // helper struct and functions for socket handling
128 // ---------------------------------------------------------------------------
130 struct GsocketCallbackInfo
{
131 void (*proc
)(void *);
137 // These defines and wrapper functions are used here and in gsockpm.c
138 #define wxSockReadMask 0x01
139 #define wxSockWriteMask 0x02
143 int wxAppAddSocketHandler(int handle
, int mask
,
144 void (*callback
)(void*), void * gsock
)
146 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
149 void wxAppRemoveSocketHandler(int handle
)
151 wxTheApp
->RemoveSocketHandler(handle
);
154 // Linkage mode problems using callbacks with extern C in a .cpp module
155 int wxAppAddSocketHandler(int handle
, int mask
,
156 void (*callback
)(void*), void * gsock
)
158 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
160 void wxAppRemoveSocketHandler(int handle
)
162 wxTheApp
->RemoveSocketHandler(handle
);
166 void wxApp::HandleSockets()
168 bool pendingEvent
= FALSE
;
170 // Check whether it's time for Gsocket operation
171 if (m_maxSocketHandles
> 0 && m_maxSocketNr
> 0)
173 fd_set readfds
= m_readfds
;
174 fd_set writefds
= m_writefds
;
175 struct timeval timeout
;
177 struct GsocketCallbackInfo
178 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
182 if ( select(m_maxSocketNr
, &readfds
, &writefds
, 0, &timeout
) > 0)
184 for (i
= m_lastUsedHandle
+ 1; i
!= m_lastUsedHandle
; i
++)
186 if (i
== m_maxSocketNr
)
188 if (FD_ISSET(i
, &readfds
))
191 for (r
= 0; r
< m_maxSocketHandles
; r
++){
192 if(CallbackInfo
[r
].handle
== i
&&
193 CallbackInfo
[r
].type
== wxSockReadMask
)
196 if (r
< m_maxSocketHandles
)
198 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
203 if (FD_ISSET(i
, &writefds
))
206 for (r
= 0; r
< m_maxSocketHandles
; r
++)
207 if(CallbackInfo
[r
].handle
== i
&&
208 CallbackInfo
[r
].type
== wxSockWriteMask
)
210 if (r
< m_maxSocketHandles
)
212 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
218 m_lastUsedHandle
= i
;
224 // ---------------------------------------------------------------------------
226 // ---------------------------------------------------------------------------
228 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
230 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
231 EVT_IDLE(wxApp::OnIdle
)
232 EVT_END_SESSION(wxApp::OnEndSession
)
233 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
239 bool wxApp::Initialize(
243 #if defined(wxUSE_CONSOLEDEBUG)
244 #if wxUSE_CONSOLEDEBUG
245 /***********************************************/
246 /* Code for using stdout debug */
247 /* To use it you mast link app as "Window" - EK*/
248 /***********************************************/
253 printf("In console\n");
255 DosGetInfoBlocks(&tib
, &pib
);
256 /* Try morphing into a PM application. */
257 // if(pib->pib_ultype == 2) /* VIO */
260 /**********************************************/
261 /**********************************************/
262 #endif //wxUSE_CONSOLEDEBUG
266 // OS2 has to have an anchorblock
268 vHab
= WinInitialize(0);
275 // Some people may wish to use this, but
276 // probably it shouldn't be here by default.
278 // wxRedirectIOToConsole();
281 wxBuffer
= new wxChar
[1500]; // FIXME; why?
283 wxClassInfo::InitializeClasses();
286 wxPendingEventsLocker
= new wxCriticalSection
;
289 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
290 wxTheColourDatabase
->Initialize();
292 wxInitializeStockLists();
293 wxInitializeStockObjects();
295 #if wxUSE_WX_RESOURCES
296 wxInitializeResourceSystem();
299 wxBitmap::InitStandardHandlers();
301 RegisterWindowClasses(vHab
);
302 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
304 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
305 // PLEASE DO NOT ALTER THIS.
306 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
307 extern char wxDummyChar
;
308 if (wxDummyChar
) wxDummyChar
++;
311 // wxSetKeyboardHook(TRUE);
313 wxModule::RegisterModules();
314 if (!wxModule::InitializeModules())
317 } // end of wxApp::Initialize
319 const char* CANTREGISTERCLASS
= " Can't register Class ";
320 // ---------------------------------------------------------------------------
321 // RegisterWindowClasses
322 // ---------------------------------------------------------------------------
324 bool wxApp::RegisterWindowClasses(
332 if (!::WinRegisterClass( vHab
335 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
| CS_CLIPCHILDREN
339 vError
= ::WinGetLastError(vHab
);
340 sError
= wxPMErrorToStr(vError
);
341 wxLogLastError(sError
);
345 if (!::WinRegisterClass( vHab
346 ,wxFrameClassNameNoRedraw
352 vError
= ::WinGetLastError(vHab
);
353 sError
= wxPMErrorToStr(vError
);
354 wxLogLastError(sError
);
358 if (!::WinRegisterClass( vHab
361 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
365 vError
= ::WinGetLastError(vHab
);
366 sError
= wxPMErrorToStr(vError
);
367 wxLogLastError(sError
);
371 if (!::WinRegisterClass( vHab
372 ,wxMDIFrameClassNameNoRedraw
378 vError
= ::WinGetLastError(vHab
);
379 sError
= wxPMErrorToStr(vError
);
380 wxLogLastError(sError
);
384 if (!::WinRegisterClass( vHab
385 ,wxMDIChildFrameClassName
387 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
391 vError
= ::WinGetLastError(vHab
);
392 sError
= wxPMErrorToStr(vError
);
393 wxLogLastError(sError
);
397 if (!::WinRegisterClass( vHab
398 ,wxMDIChildFrameClassNameNoRedraw
404 vError
= ::WinGetLastError(vHab
);
405 sError
= wxPMErrorToStr(vError
);
406 wxLogLastError(sError
);
410 if (!::WinRegisterClass( vHab
413 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
417 vError
= ::WinGetLastError(vHab
);
418 sError
= wxPMErrorToStr(vError
);
419 wxLogLastError(sError
);
423 if (!::WinRegisterClass( vHab
426 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
| CS_CLIPCHILDREN
430 vError
= ::WinGetLastError(vHab
);
431 sError
= wxPMErrorToStr(vError
);
432 wxLogLastError(sError
);
436 } // end of wxApp::RegisterWindowClasses
439 // Cleans up any wxWindows internal structures left lying around
441 void wxApp::CleanUp()
450 // Flush the logged messages if any and install a 'safer' log target: the
451 // default one (wxLogGui) can't be used after the resources are freed just
452 // below and the user suppliedo ne might be even more unsafe (using any
453 // wxWindows GUI function is unsafe starting from now)
455 wxLog::DontCreateOnDemand();
458 // This will flush the old messages if any
460 delete wxLog::SetActiveTarget(new wxLogStderr
);
464 // One last chance for pending objects to be cleaned up
466 wxTheApp
->DeletePendingObjects();
468 wxModule::CleanUpModules();
470 #if wxUSE_WX_RESOURCES
471 wxCleanUpResourceSystem();
474 wxDeleteStockObjects();
477 // Destroy all GDI lists, etc.
479 wxDeleteStockLists();
481 delete wxTheColourDatabase
;
482 wxTheColourDatabase
= NULL
;
484 wxBitmap::CleanUpHandlers();
490 // PM-SPECIFIC CLEANUP
493 // wxSetKeyboardHook(FALSE);
495 if (wxSTD_FRAME_ICON
)
496 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
497 if (wxSTD_MDICHILDFRAME_ICON
)
498 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
499 if (wxSTD_MDIPARENTFRAME_ICON
)
500 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
502 if (wxDEFAULT_FRAME_ICON
)
503 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
504 if (wxDEFAULT_MDICHILDFRAME_ICON
)
505 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
506 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
507 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
509 if ( wxDisableButtonBrush
)
511 // TODO: ::DeleteObject( wxDisableButtonBrush );
515 delete wxWinHandleList
;
517 delete wxPendingEvents
;
519 delete wxPendingEventsLocker
;
520 // If we don't do the following, we get an apparent memory leak.
521 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
524 wxClassInfo::CleanUpClasses();
526 // Delete Message queue
528 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
533 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
534 // At this point we want to check if there are any memory
535 // blocks that aren't part of the wxDebugContext itself,
536 // as a special case. Then when dumping we need to ignore
537 // wxDebugContext, too.
538 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
540 wxLogDebug(wxT("There were memory leaks."));
541 wxDebugContext::Dump();
542 wxDebugContext::PrintStatistics();
544 // wxDebugContext::SetStream(NULL, NULL);
548 // do it as the very last thing because everything else can log messages
549 delete wxLog::SetActiveTarget(NULL
);
551 } // end of wxApp::CleanUp
553 //----------------------------------------------------------------------
554 // Main wxWindows entry point
555 //----------------------------------------------------------------------
563 if (!wxApp::Initialize(vHab
))
567 // create the application object or ensure that one already exists
571 // The app may have declared a global application object, but we recommend
572 // the IMPLEMENT_APP macro is used instead, which sets an initializer
573 // function for delayed, dynamic app object construction.
574 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
575 wxT("No initializer - use IMPLEMENT_APP macro.") );
576 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
578 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
579 wxTheApp
->argc
= argc
;
582 wxTheApp
->argv
= new wxChar
*[argc
+1];
588 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
591 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
593 wxTheApp
->argv
= argv
;
596 wxString
sName(wxFileNameFromPath(argv
[0]));
598 wxStripExtension(sName
);
599 wxTheApp
->SetAppName(sName
);
603 if (!wxTheApp
->OnInitGui())
608 if (wxTheApp
->OnInit())
610 nRetValue
= wxTheApp
->OnRun();
613 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
616 // Forcibly delete the window.
617 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
618 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
620 pTopWindow
->Close(TRUE
);
621 wxTheApp
->DeletePendingObjects();
626 wxTheApp
->SetTopWindow(NULL
);
630 else // app initialization failed
632 wxLogLastError(" Gui initialization failed, exitting");
634 #if wxUSE_CONSOLEDEBUG
635 printf("wxTheApp->OnExit ");
639 #if wxUSE_CONSOLEDEBUG
640 printf("wxApp::CleanUp ");
644 #if wxUSE_CONSOLEDEBUG
645 printf("return %i ", nRetValue
);
651 bool wxApp::OnInitGui()
656 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
659 vError
= ::WinGetLastError(vHabmain
);
660 sError
= wxPMErrorToStr(vError
);
665 } // end of wxApp::OnInitGui
668 // Static member initialization
670 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
676 m_wantDebugOutput
= TRUE
;
680 m_nPrintMode
= wxPRINT_WINDOWS
;
681 m_exitOnFrameDelete
= TRUE
;
684 m_maxSocketHandles
= 0;
686 m_sockCallbackInfo
= 0;
687 } // end of wxApp::wxApp
692 // Delete command-line args
697 for (i
= 0; i
< argc
; i
++)
703 } // end of wxApp::~wxApp
705 bool wxApp::Initialized()
711 } // end of wxApp::Initialized
714 // Get and process a message, returning FALSE if WM_QUIT
715 // received (and also set the flag telling the app to exit the main loop)
718 bool wxApp::DoMessage()
720 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
725 m_bKeepGoing
= FALSE
;
730 // should never happen, but let's test for it nevertheless
731 wxLogLastError("GetMessage");
736 wxASSERT_MSG( wxThread::IsMain()
737 ,wxT("only the main thread can process Windows messages")
740 static bool sbHadGuiLock
= TRUE
;
741 static wxMsgArray svSavedMessages
;
744 // If a secondary thread owns is doing GUI calls, save all messages for
745 // later processing - we can't process them right now because it will
746 // lead to recursive library calls (and we're not reentrant)
748 if (!wxGuiOwnedByMainThread())
750 sbHadGuiLock
= FALSE
;
753 // Leave out WM_COMMAND messages: too dangerous, sometimes
754 // the message will be processed twice
756 if ( !wxIsWaitingForThread() ||
757 svCurrentMsg
.msg
!= WM_COMMAND
)
759 svSavedMessages
.Add(svCurrentMsg
);
766 // Have we just regained the GUI lock? if so, post all of the saved
773 size_t nCount
= svSavedMessages
.Count();
775 for (size_t n
= 0; n
< nCount
; n
++)
777 QMSG vMsg
= svSavedMessages
[n
];
779 if ( !ProcessMessage((WXMSG
*)&vMsg
) )
781 ::WinDispatchMsg(vHabmain
, &vMsg
);
784 svSavedMessages
.Empty();
787 #endif // wxUSE_THREADS
789 // Process the message
790 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
792 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
796 } // end of wxApp::DoMessage
798 //////////////////////////////////////////////////////////////////////////////
800 // Keep trying to process messages until WM_QUIT
803 // If there are messages to be processed, they will all be
804 // processed and OnIdle will not be called.
805 // When there are no more messages, OnIdle is called.
806 // If OnIdle requests more time,
807 // it will be repeatedly called so long as there are no pending messages.
808 // A 'feature' of this is that once OnIdle has decided that no more processing
809 // is required, then it won't get processing time until further messages
810 // are processed (it'll sit in DoMessage).
812 //////////////////////////////////////////////////////////////////////////////
813 int wxApp::MainLoop()
820 wxMutexGuiLeaveOrEnter();
821 #endif // wxUSE_THREADS
822 while (!Pending() && ProcessIdle())
834 return (int)svCurrentMsg
.mp1
;
835 } // end of wxApp::MainLoop
838 // Returns TRUE if more time is needed.
840 bool wxApp::ProcessIdle()
844 vEvent
.SetEventObject(this);
845 ProcessEvent(vEvent
);
846 return vEvent
.MoreRequested();
847 } // end of wxApp::ProcessIdle
849 void wxApp::ExitMainLoop()
851 m_bKeepGoing
= FALSE
;
854 bool wxApp::Pending()
856 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
859 void wxApp::Dispatch()
864 //////////////////////////////////////////////////////////////////////////////
866 // Give all windows a chance to preprocess
867 // the message. Some may have accelerator tables, or have
868 // MDI complications.
870 //////////////////////////////////////////////////////////////////////////////
871 bool wxApp::ProcessMessage(
875 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
876 HWND hWnd
= pMsg
->hwnd
;
877 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
882 // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
883 // popup the tooltip bubbles
885 if (pWndThis
&& (pMsg
->msg
== WM_MOUSEMOVE
))
887 wxToolTip
* pToolTip
= pWndThis
->GetToolTip();
890 pToolTip
->RelayEvent(pWxmsg
);
893 #endif // wxUSE_TOOLTIPS
896 // We must relay Timer events to wxTimer's processing function
898 if (pMsg
->msg
== WM_TIMER
)
899 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
902 // For some composite controls (like a combobox), wndThis might be NULL
903 // because the subcontrol is not a wxWindow, but only the control itself
904 // is - try to catch this case
906 while (hWnd
&& !pWndThis
)
908 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
909 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
913 // Try translations first; find the youngest window with
914 // a translation table. OS/2 has case sensative accels, so
915 // this block, coded by BK, removes that and helps make them
918 if(pMsg
->msg
== WM_CHAR
)
920 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
921 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
925 // Do not process keyup events
927 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
929 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
930 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
933 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
935 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
939 if(!bRc
) // untranslated, should restore original value
940 CHARMSG(pChmsg
)->chr
= uSch
;
944 // Anyone for a non-translation message? Try youngest descendants first.
946 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
948 // if (pWnd->OS2ProcessMessage(pWxmsg))
952 } // end of wxApp::ProcessMessage
958 static bool sbInOnIdle
= FALSE
;
961 // Avoid recursion (via ProcessEvent default case)
969 // If there are pending events, we must process them: pending events
970 // are either events to the threads other than main or events posted
971 // with wxPostEvent() functions
973 ProcessPendingEvents();
976 // 'Garbage' collection of windows deleted with Close().
978 DeletePendingObjects();
982 // Flush the logged messages if any
984 wxLog::FlushActive();
988 // Send OnIdle events to all windows
990 if (SendIdleEvents())
993 // SendIdleEvents() returns TRUE if at least one window requested more
996 rEvent
.RequestMore(TRUE
);
999 } // end of wxApp::OnIdle
1001 // Send idle event to all top-level windows
1002 bool wxApp::SendIdleEvents()
1004 bool bNeedMore
= FALSE
;
1005 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1009 wxWindow
* pWin
= pNode
->GetData();
1011 if (SendIdleEvents(pWin
))
1013 pNode
= pNode
->GetNext();
1016 } // end of wxApp::SendIdleEvents
1019 // Send idle event to window and all subwindows
1021 bool wxApp::SendIdleEvents(
1025 bool bNeedMore
= FALSE
;
1028 vEvent
.SetEventObject(pWin
);
1029 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1031 if (vEvent
.MoreRequested())
1034 wxNode
* pNode
= pWin
->GetChildren().First();
1038 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1040 if (SendIdleEvents(pWin
))
1042 pNode
= pNode
->Next();
1045 } // end of wxApp::SendIdleEvents
1047 void wxApp::DeletePendingObjects()
1049 wxNode
* pNode
= wxPendingDelete
.First();
1053 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1057 if (wxPendingDelete
.Member(pObj
))
1061 // Deleting one object may have deleted other pending
1062 // objects, so start from beginning of list again.
1064 pNode
= wxPendingDelete
.First();
1066 } // end of wxApp::DeletePendingObjects
1068 void wxApp::OnEndSession(
1069 wxCloseEvent
& WXUNUSED(rEvent
))
1072 GetTopWindow()->Close(TRUE
);
1073 } // end of wxApp::OnEndSession
1076 // Default behaviour: close the application with prompts. The
1077 // user can veto the close, and therefore the end session.
1079 void wxApp::OnQueryEndSession(
1080 wxCloseEvent
& rEvent
1085 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1088 } // end of wxApp::OnQueryEndSession
1092 wxLogError(_("Fatal error: exiting"));
1097 static bool gs_inYield
= FALSE
;
1100 // Yield to incoming messages
1108 // Disable log flushing from here because a call to wxYield() shouldn't
1109 // normally result in message boxes popping up &c
1116 // We want to go back to the main message loop
1117 // if we see a WM_QUIT. (?)
1119 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1122 wxMutexGuiLeaveOrEnter();
1123 #endif // wxUSE_THREADS
1124 if (!wxTheApp
->DoMessage())
1128 // If they are pending events, we must process them.
1131 wxTheApp
->ProcessPendingEvents();
1134 // Let the logs be flashed again
1141 // Yield to incoming messages; but fail silently if recursion is detected.
1142 bool wxYieldIfNeeded()
1150 wxIcon
wxApp::GetStdIcon(
1156 case wxICON_INFORMATION
:
1157 return wxIcon("wxICON_INFO");
1159 case wxICON_QUESTION
:
1160 return wxIcon("wxICON_QUESTION");
1162 case wxICON_EXCLAMATION
:
1163 return wxIcon("wxICON_WARNING");
1166 wxFAIL_MSG(wxT("requested non existent standard icon"));
1167 // still fall through
1170 return wxIcon("wxICON_ERROR");
1172 return wxIcon("wxICON_ERROR");
1173 } // end of wxApp::GetStdIcon
1175 int wxApp::AddSocketHandler(int handle
, int mask
,
1176 void (*callback
)(void*), void * gsock
)
1179 struct GsocketCallbackInfo
1180 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1182 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1183 if (CallbackInfo
[find
].handle
== -1)
1185 if (find
== m_maxSocketHandles
)
1187 // Allocate new memory
1188 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1189 (m_maxSocketHandles
+=10)*
1190 sizeof(struct GsocketCallbackInfo
));
1191 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1192 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1193 CallbackInfo
[find
].handle
= -1;
1194 find
= m_maxSocketHandles
- 10;
1196 CallbackInfo
[find
].proc
= callback
;
1197 CallbackInfo
[find
].type
= mask
;
1198 CallbackInfo
[find
].handle
= handle
;
1199 CallbackInfo
[find
].gsock
= gsock
;
1200 if (mask
& wxSockReadMask
)
1201 FD_SET(handle
, &m_readfds
);
1202 if (mask
& wxSockWriteMask
)
1203 FD_SET(handle
, &m_writefds
);
1204 if (handle
>= m_maxSocketNr
)
1205 m_maxSocketNr
= handle
+ 1;
1209 void wxApp::RemoveSocketHandler(int handle
)
1211 struct GsocketCallbackInfo
1212 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1213 if (handle
< m_maxSocketHandles
)
1215 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1216 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1217 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1218 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1219 CallbackInfo
[handle
].handle
= -1;
1223 //-----------------------------------------------------------------------------
1225 //-----------------------------------------------------------------------------
1230 // Send the top window a dummy message so idle handler processing will
1231 // start up again. Doing it this way ensures that the idle handler
1232 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1233 // the same for the main app thread only)
1235 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1239 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1242 // Should never happen
1244 wxLogLastError("PostMessage(WM_NULL)");
1247 } // end of wxWakeUpIdle