1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #include "wx/gdicmn.h"
26 #include "wx/cursor.h"
28 #include "wx/palette.h"
30 #include "wx/dialog.h"
31 #include "wx/msgdlg.h"
33 #include "wx/dynarray.h"
34 #include "wx/wxchar.h"
40 #include "wx/module.h"
42 #include "wx/os2/private.h"
46 #include <sys/ioctl.h>
47 #include <sys/select.h>
52 #include <sys/ioctl.h>
53 #include <sys/select.h>
60 #define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
61 extern "C" int _System
bsdselect(int,
69 #include "wx/thread.h"
71 // define the array of QMSG strutures
72 WX_DECLARE_OBJARRAY(QMSG
, wxMsgArray
);
74 #include "wx/arrimpl.cpp"
76 WX_DEFINE_OBJARRAY(wxMsgArray
);
77 #endif // wxUSE_THREADS
80 #include "wx/tooltip.h"
81 #endif // wxUSE_TOOLTIPS
86 // ---------------------------------------------------------------------------
88 // ---------------------------------------------------------------------------
90 extern wxChar
* wxBuffer
;
91 extern wxList
* wxWinHandleList
;
92 extern wxList WXDLLEXPORT wxPendingDelete
;
93 extern wxCursor
* g_globalCursor
;
95 HAB vHabmain
= NULLHANDLE
;
97 wxApp
* wxTheApp
= NULL
;
100 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
101 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
102 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
104 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
105 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
106 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
108 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
110 MRESULT EXPENTRY
wxWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
111 MRESULT EXPENTRY
wxFrameWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
113 // ===========================================================================
115 // ===========================================================================
117 // ---------------------------------------------------------------------------
118 // helper struct and functions for socket handling
119 // ---------------------------------------------------------------------------
121 struct GsocketCallbackInfo
{
122 void (*proc
)(void *);
128 // These defines and wrapper functions are used here and in gsockpm.c
129 #define wxSockReadMask 0x01
130 #define wxSockWriteMask 0x02
134 int wxAppAddSocketHandler(int handle
, int mask
,
135 void (*callback
)(void*), void * gsock
)
137 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
140 void wxAppRemoveSocketHandler(int handle
)
142 wxTheApp
->RemoveSocketHandler(handle
);
145 // Linkage mode problems using callbacks with extern C in a .cpp module
146 int wxAppAddSocketHandler(int handle
, int mask
,
147 void (*callback
)(void*), void * gsock
)
149 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
151 void wxAppRemoveSocketHandler(int handle
)
153 wxTheApp
->RemoveSocketHandler(handle
);
157 void wxApp::HandleSockets()
159 bool pendingEvent
= FALSE
;
161 // Check whether it's time for Gsocket operation
162 if (m_maxSocketHandles
> 0 && m_maxSocketNr
> 0)
164 fd_set readfds
= m_readfds
;
165 fd_set writefds
= m_writefds
;
166 struct timeval timeout
;
168 struct GsocketCallbackInfo
169 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
173 if ( select(m_maxSocketNr
, &readfds
, &writefds
, 0, &timeout
) > 0)
175 for (i
= m_lastUsedHandle
+ 1; i
!= m_lastUsedHandle
; i
++)
177 if (i
== m_maxSocketNr
)
179 if (FD_ISSET(i
, &readfds
))
182 for (r
= 0; r
< m_maxSocketHandles
; r
++){
183 if(CallbackInfo
[r
].handle
== i
&&
184 CallbackInfo
[r
].type
== wxSockReadMask
)
187 if (r
< m_maxSocketHandles
)
189 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
194 if (FD_ISSET(i
, &writefds
))
197 for (r
= 0; r
< m_maxSocketHandles
; r
++)
198 if(CallbackInfo
[r
].handle
== i
&&
199 CallbackInfo
[r
].type
== wxSockWriteMask
)
201 if (r
< m_maxSocketHandles
)
203 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
209 m_lastUsedHandle
= i
;
215 // ---------------------------------------------------------------------------
217 // ---------------------------------------------------------------------------
219 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
221 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
222 EVT_IDLE(wxApp::OnIdle
)
223 EVT_END_SESSION(wxApp::OnEndSession
)
224 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
230 bool wxApp::Initialize(
234 #if defined(wxUSE_CONSOLEDEBUG)
235 #if wxUSE_CONSOLEDEBUG
236 /***********************************************/
237 /* Code for using stdout debug */
238 /* To use it you mast link app as "Window" - EK*/
239 /***********************************************/
244 printf("In console\n");
246 DosGetInfoBlocks(&tib
, &pib
);
247 /* Try morphing into a PM application. */
248 // if(pib->pib_ultype == 2) /* VIO */
251 /**********************************************/
252 /**********************************************/
253 #endif //wxUSE_CONSOLEDEBUG
256 wxBuffer
= new wxChar
[1500]; // FIXME; why?
258 wxClassInfo::InitializeClasses();
261 wxPendingEventsLocker
= new wxCriticalSection
;
264 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
265 wxTheColourDatabase
->Initialize();
267 wxInitializeStockLists();
268 wxInitializeStockObjects();
270 wxBitmap::InitStandardHandlers();
273 // OS2 has to have an anchorblock
275 vHab
= WinInitialize(0);
282 // Some people may wish to use this, but
283 // probably it shouldn't be here by default.
285 // wxRedirectIOToConsole();
288 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
290 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
291 // PLEASE DO NOT ALTER THIS.
292 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
293 extern char wxDummyChar
;
294 if (wxDummyChar
) wxDummyChar
++;
297 // wxSetKeyboardHook(TRUE);
299 wxModule::RegisterModules();
300 if (!wxModule::InitializeModules())
302 RegisterWindowClasses(vHab
);
304 } // end of wxApp::Initialize
306 const char* CANTREGISTERCLASS
= " Can't register Class ";
307 // ---------------------------------------------------------------------------
308 // RegisterWindowClasses
309 // ---------------------------------------------------------------------------
311 bool wxApp::RegisterWindowClasses(
318 if (!::WinRegisterClass( vHab
321 ,CS_SIZEREDRAW
| CS_SYNCPAINT
325 vError
= ::WinGetLastError(vHab
);
326 sError
= wxPMErrorToStr(vError
);
327 wxLogLastError(sError
);
331 if (!::WinRegisterClass( vHab
332 ,wxFrameClassNameNoRedraw
338 vError
= ::WinGetLastError(vHab
);
339 sError
= wxPMErrorToStr(vError
);
340 wxLogLastError(sError
);
344 if (!::WinRegisterClass( vHab
347 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
351 vError
= ::WinGetLastError(vHab
);
352 sError
= wxPMErrorToStr(vError
);
353 wxLogLastError(sError
);
357 if (!::WinRegisterClass( vHab
358 ,wxMDIFrameClassNameNoRedraw
364 vError
= ::WinGetLastError(vHab
);
365 sError
= wxPMErrorToStr(vError
);
366 wxLogLastError(sError
);
370 if (!::WinRegisterClass( vHab
371 ,wxMDIChildFrameClassName
373 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
377 vError
= ::WinGetLastError(vHab
);
378 sError
= wxPMErrorToStr(vError
);
379 wxLogLastError(sError
);
383 if (!::WinRegisterClass( vHab
384 ,wxMDIChildFrameClassNameNoRedraw
390 vError
= ::WinGetLastError(vHab
);
391 sError
= wxPMErrorToStr(vError
);
392 wxLogLastError(sError
);
396 if (!::WinRegisterClass( vHab
399 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
403 vError
= ::WinGetLastError(vHab
);
404 sError
= wxPMErrorToStr(vError
);
405 wxLogLastError(sError
);
409 if (!::WinRegisterClass( vHab
412 ,CS_SIZEREDRAW
| CS_HITTEST
| CS_SYNCPAINT
416 vError
= ::WinGetLastError(vHab
);
417 sError
= wxPMErrorToStr(vError
);
418 wxLogLastError(sError
);
421 if (!::WinRegisterClass( vHab
424 ,CS_HITTEST
| CS_SYNCPAINT
428 vError
= ::WinGetLastError(vHab
);
429 sError
= wxPMErrorToStr(vError
);
430 wxLogLastError(sError
);
434 } // end of wxApp::RegisterWindowClasses
437 // Cleans up any wxWindows internal structures left lying around
439 void wxApp::CleanUp()
448 // Flush the logged messages if any and install a 'safer' log target: the
449 // default one (wxLogGui) can't be used after the resources are freed just
450 // below and the user suppliedo ne might be even more unsafe (using any
451 // wxWindows GUI function is unsafe starting from now)
453 wxLog::DontCreateOnDemand();
456 // This will flush the old messages if any
458 delete wxLog::SetActiveTarget(new wxLogStderr
);
462 // One last chance for pending objects to be cleaned up
464 wxTheApp
->DeletePendingObjects();
466 wxModule::CleanUpModules();
468 wxDeleteStockObjects();
471 // Destroy all GDI lists, etc.
473 wxDeleteStockLists();
475 delete wxTheColourDatabase
;
476 wxTheColourDatabase
= NULL
;
478 wxBitmap::CleanUpHandlers();
484 // PM-SPECIFIC CLEANUP
487 // wxSetKeyboardHook(FALSE);
489 if (wxSTD_FRAME_ICON
)
490 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
491 if (wxSTD_MDICHILDFRAME_ICON
)
492 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
493 if (wxSTD_MDIPARENTFRAME_ICON
)
494 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
496 if (wxDEFAULT_FRAME_ICON
)
497 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
498 if (wxDEFAULT_MDICHILDFRAME_ICON
)
499 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
500 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
501 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
503 if ( wxDisableButtonBrush
)
505 // TODO: ::DeleteObject( wxDisableButtonBrush );
509 delete wxWinHandleList
;
511 delete wxPendingEvents
;
513 delete wxPendingEventsLocker
;
514 // If we don't do the following, we get an apparent memory leak.
515 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
518 wxClassInfo::CleanUpClasses();
520 // Delete Message queue
522 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
527 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
528 // At this point we want to check if there are any memory
529 // blocks that aren't part of the wxDebugContext itself,
530 // as a special case. Then when dumping we need to ignore
531 // wxDebugContext, too.
532 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
534 wxLogDebug(wxT("There were memory leaks."));
535 wxDebugContext::Dump();
536 wxDebugContext::PrintStatistics();
538 // wxDebugContext::SetStream(NULL, NULL);
542 // do it as the very last thing because everything else can log messages
543 delete wxLog::SetActiveTarget(NULL
);
545 } // end of wxApp::CleanUp
547 //----------------------------------------------------------------------
548 // Main wxWindows entry point
549 //----------------------------------------------------------------------
557 if (!wxApp::Initialize(vHab
))
561 // create the application object or ensure that one already exists
565 // The app may have declared a global application object, but we recommend
566 // the IMPLEMENT_APP macro is used instead, which sets an initializer
567 // function for delayed, dynamic app object construction.
568 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
569 wxT("No initializer - use IMPLEMENT_APP macro.") );
570 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
572 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
573 wxTheApp
->argc
= argc
;
576 wxTheApp
->argv
= new wxChar
*[argc
+1];
582 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
585 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
587 wxTheApp
->argv
= argv
;
590 wxString
sName(wxFileNameFromPath(argv
[0]));
592 wxStripExtension(sName
);
593 wxTheApp
->SetAppName(sName
);
597 if (!wxTheApp
->OnInitGui())
602 if (wxTheApp
->OnInit())
607 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
610 // Forcibly delete the window.
611 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
612 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
614 pTopWindow
->Close(TRUE
);
615 wxTheApp
->DeletePendingObjects();
620 wxTheApp
->SetTopWindow(NULL
);
624 else // app initialization failed
626 wxLogLastError(" Gui initialization failed, exitting");
628 #if wxUSE_CONSOLEDEBUG
629 printf("wxTheApp->OnExit ");
632 nRetValue
= wxTheApp
->OnExit();
633 #if wxUSE_CONSOLEDEBUG
634 printf("wxApp::CleanUp ");
638 #if wxUSE_CONSOLEDEBUG
639 printf("return %i ", nRetValue
);
645 bool wxApp::OnInitGui()
650 if (!wxAppBase::OnInitGui())
653 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
656 vError
= ::WinGetLastError(vHabmain
);
657 sError
= wxPMErrorToStr(vError
);
663 } // end of wxApp::OnInitGui
666 // Static member initialization
668 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
677 m_nPrintMode
= wxPRINT_WINDOWS
;
680 m_maxSocketHandles
= 0;
682 m_sockCallbackInfo
= 0;
683 } // end of wxApp::wxApp
688 // Delete command-line args
693 for (i
= 0; i
< argc
; i
++)
699 } // end of wxApp::~wxApp
701 bool wxApp::Initialized()
707 } // end of wxApp::Initialized
710 // Get and process a message, returning FALSE if WM_QUIT
711 // received (and also set the flag telling the app to exit the main loop)
714 bool wxApp::DoMessage()
716 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
721 m_bKeepGoing
= FALSE
;
726 // should never happen, but let's test for it nevertheless
727 wxLogLastError("GetMessage");
732 wxASSERT_MSG( wxThread::IsMain()
733 ,wxT("only the main thread can process Windows messages")
736 static bool sbHadGuiLock
= TRUE
;
737 static wxMsgArray svSavedMessages
;
740 // If a secondary thread owns is doing GUI calls, save all messages for
741 // later processing - we can't process them right now because it will
742 // lead to recursive library calls (and we're not reentrant)
744 if (!wxGuiOwnedByMainThread())
746 sbHadGuiLock
= FALSE
;
749 // Leave out WM_COMMAND messages: too dangerous, sometimes
750 // the message will be processed twice
752 if ( !wxIsWaitingForThread() ||
753 svCurrentMsg
.msg
!= WM_COMMAND
)
755 svSavedMessages
.Add(svCurrentMsg
);
762 // Have we just regained the GUI lock? if so, post all of the saved
769 size_t nCount
= svSavedMessages
.Count();
771 for (size_t n
= 0; n
< nCount
; n
++)
773 QMSG vMsg
= svSavedMessages
[n
];
775 DoMessage((WXMSG
*)&vMsg
);
777 svSavedMessages
.Empty();
780 #endif // wxUSE_THREADS
783 // Process the message
785 DoMessage((WXMSG
*)&svCurrentMsg
);
788 } // end of wxApp::DoMessage
790 void wxApp::DoMessage(
794 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
796 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
798 } // end of wxApp::DoMessage
800 //////////////////////////////////////////////////////////////////////////////
802 // Keep trying to process messages until WM_QUIT
805 // If there are messages to be processed, they will all be
806 // processed and OnIdle will not be called.
807 // When there are no more messages, OnIdle is called.
808 // If OnIdle requests more time,
809 // it will be repeatedly called so long as there are no pending messages.
810 // A 'feature' of this is that once OnIdle has decided that no more processing
811 // is required, then it won't get processing time until further messages
812 // are processed (it'll sit in DoMessage).
814 //////////////////////////////////////////////////////////////////////////////
815 int wxApp::MainLoop()
822 wxMutexGuiLeaveOrEnter();
823 #endif // wxUSE_THREADS
824 while (!Pending() && ProcessIdle())
836 return (int)svCurrentMsg
.mp1
;
837 } // end of wxApp::MainLoop
840 // Returns TRUE if more time is needed.
842 bool wxApp::ProcessIdle()
846 vEvent
.SetEventObject(this);
847 ProcessEvent(vEvent
);
848 return vEvent
.MoreRequested();
849 } // end of wxApp::ProcessIdle
851 void wxApp::ExitMainLoop()
853 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
854 } // end of wxApp::ExitMainLoop
856 bool wxApp::Pending()
858 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
859 } // end of wxApp::Pending
861 void wxApp::Dispatch()
866 //////////////////////////////////////////////////////////////////////////////
868 // Give all windows a chance to preprocess
869 // the message. Some may have accelerator tables, or have
870 // MDI complications.
872 //////////////////////////////////////////////////////////////////////////////
873 bool wxApp::ProcessMessage(
877 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
878 HWND hWnd
= pMsg
->hwnd
;
879 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
883 // Pass non-system timer messages to the wxTimerProc
885 if (pMsg
->msg
== WM_TIMER
&&
886 (SHORT1FROMMP(pMsg
->mp1
) != TID_CURSOR
&&
887 SHORT1FROMMP(pMsg
->mp1
) != TID_FLASHWINDOW
&&
888 SHORT1FROMMP(pMsg
->mp1
) != TID_SCROLL
&&
889 SHORT1FROMMP(pMsg
->mp1
) != 0x0000
891 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
894 // Allow the window to prevent certain messages from being
895 // translated/processed (this is currently used by wxTextCtrl to always
896 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
898 if (pWndThis
&& !pWndThis
->OS2ShouldPreProcessMessage(pWxmsg
))
904 // For some composite controls (like a combobox), wndThis might be NULL
905 // because the subcontrol is not a wxWindow, but only the control itself
906 // is - try to catch this case
908 while (hWnd
&& !pWndThis
)
910 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
911 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
915 // Try translations first; find the youngest window with
916 // a translation table. OS/2 has case sensative accels, so
917 // this block, coded by BK, removes that and helps make them
920 if(pMsg
->msg
== WM_CHAR
)
922 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
923 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
927 // Do not process keyup events
929 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
931 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
932 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
935 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
937 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
941 if(!bRc
) // untranslated, should restore original value
942 CHARMSG(pChmsg
)->chr
= uSch
;
946 // Anyone for a non-translation message? Try youngest descendants first.
948 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
950 // if (pWnd->OS2ProcessMessage(pWxmsg))
954 } // end of wxApp::ProcessMessage
956 bool gbInOnIdle
= FALSE
;
964 // Avoid recursion (via ProcessEvent default case)
972 // If there are pending events, we must process them: pending events
973 // are either events to the threads other than main or events posted
974 // with wxPostEvent() functions
976 ProcessPendingEvents();
979 // 'Garbage' collection of windows deleted with Close().
981 DeletePendingObjects();
985 // Flush the logged messages if any
987 wxLog::FlushActive();
990 #if wxUSE_DC_CACHEING
991 // automated DC cache management: clear the cached DCs and bitmap
992 // if it's likely that the app has finished with them, that is, we
993 // get an idle event and we're not dragging anything.
994 if (!::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON1
) &&
995 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON3
) &&
996 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON2
))
998 #endif // wxUSE_DC_CACHEING
1001 // Send OnIdle events to all windows
1003 if (SendIdleEvents())
1006 // SendIdleEvents() returns TRUE if at least one window requested more
1009 rEvent
.RequestMore(TRUE
);
1012 } // end of wxApp::OnIdle
1014 // Send idle event to all top-level windows
1015 bool wxApp::SendIdleEvents()
1017 bool bNeedMore
= FALSE
;
1018 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1022 wxWindow
* pWin
= pNode
->GetData();
1024 if (SendIdleEvents(pWin
))
1026 pNode
= pNode
->GetNext();
1029 } // end of wxApp::SendIdleEvents
1032 // Send idle event to window and all subwindows
1034 bool wxApp::SendIdleEvents(
1038 bool bNeedMore
= FALSE
;
1041 vEvent
.SetEventObject(pWin
);
1042 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1044 if (vEvent
.MoreRequested())
1047 wxNode
* pNode
= pWin
->GetChildren().First();
1051 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1053 if (SendIdleEvents(pWin
))
1055 pNode
= pNode
->Next();
1058 } // end of wxApp::SendIdleEvents
1060 void wxApp::DeletePendingObjects()
1062 wxNode
* pNode
= wxPendingDelete
.First();
1066 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1070 if (wxPendingDelete
.Member(pObj
))
1074 // Deleting one object may have deleted other pending
1075 // objects, so start from beginning of list again.
1077 pNode
= wxPendingDelete
.First();
1079 } // end of wxApp::DeletePendingObjects
1081 void wxApp::OnEndSession(
1082 wxCloseEvent
& WXUNUSED(rEvent
))
1085 GetTopWindow()->Close(TRUE
);
1086 } // end of wxApp::OnEndSession
1089 // Default behaviour: close the application with prompts. The
1090 // user can veto the close, and therefore the end session.
1092 void wxApp::OnQueryEndSession(
1093 wxCloseEvent
& rEvent
1098 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1101 } // end of wxApp::OnQueryEndSession
1105 wxLogError(_("Fatal error: exiting"));
1111 // Yield to incoming messages
1113 bool wxApp::Yield(bool onlyIfNeeded
)
1115 static bool s_inYield
= FALSE
;
1119 if ( !onlyIfNeeded
)
1121 wxFAIL_MSG( _T("wxYield() called recursively") );
1131 // Disable log flushing from here because a call to wxYield() shouldn't
1132 // normally result in message boxes popping up &c
1139 // We want to go back to the main message loop
1140 // if we see a WM_QUIT. (?)
1142 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1145 wxMutexGuiLeaveOrEnter();
1146 #endif // wxUSE_THREADS
1147 if (!wxTheApp
->DoMessage())
1151 // If they are pending events, we must process them.
1154 wxTheApp
->ProcessPendingEvents();
1157 // Let the logs be flashed again
1164 int wxApp::AddSocketHandler(int handle
, int mask
,
1165 void (*callback
)(void*), void * gsock
)
1168 struct GsocketCallbackInfo
1169 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1171 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1172 if (CallbackInfo
[find
].handle
== -1)
1174 if (find
== m_maxSocketHandles
)
1176 // Allocate new memory
1177 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1178 (m_maxSocketHandles
+=10)*
1179 sizeof(struct GsocketCallbackInfo
));
1180 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1181 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1182 CallbackInfo
[find
].handle
= -1;
1183 find
= m_maxSocketHandles
- 10;
1185 CallbackInfo
[find
].proc
= callback
;
1186 CallbackInfo
[find
].type
= mask
;
1187 CallbackInfo
[find
].handle
= handle
;
1188 CallbackInfo
[find
].gsock
= gsock
;
1189 if (mask
& wxSockReadMask
)
1190 FD_SET(handle
, &m_readfds
);
1191 if (mask
& wxSockWriteMask
)
1192 FD_SET(handle
, &m_writefds
);
1193 if (handle
>= m_maxSocketNr
)
1194 m_maxSocketNr
= handle
+ 1;
1198 void wxApp::RemoveSocketHandler(int handle
)
1200 struct GsocketCallbackInfo
1201 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1202 if (handle
< m_maxSocketHandles
)
1204 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1205 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1206 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1207 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1208 CallbackInfo
[handle
].handle
= -1;
1212 //-----------------------------------------------------------------------------
1214 //-----------------------------------------------------------------------------
1219 // Send the top window a dummy message so idle handler processing will
1220 // start up again. Doing it this way ensures that the idle handler
1221 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1222 // the same for the main app thread only)
1224 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1228 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1231 // Should never happen
1233 wxLogLastError("PostMessage(WM_NULL)");
1236 } // end of wxWakeUpIdle