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"
40 #if defined(__VISAGECPP__) && __IBMCPP__ < 400
41 #include <machine\endian.h>
46 #include <sys\ioctl.h>
47 #include <sys\select.h>
49 #define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
50 int _System
bsdselect(int,
59 #include "wx/thread.h"
61 // define the array of QMSG strutures
62 WX_DECLARE_OBJARRAY(QMSG
, wxMsgArray
);
64 #include "wx/arrimpl.cpp"
66 WX_DEFINE_OBJARRAY(wxMsgArray
);
67 #endif // wxUSE_THREADS
69 #if wxUSE_WX_RESOURCES
70 #include "wx/resource.h"
74 #include "wx/tooltip.h"
75 #endif // wxUSE_TOOLTIPS
80 // ---------------------------------------------------------------------------
82 // ---------------------------------------------------------------------------
84 extern wxChar
* wxBuffer
;
85 extern wxList
* wxWinHandleList
;
86 extern wxList WXDLLEXPORT wxPendingDelete
;
87 extern wxCursor
* g_globalCursor
;
89 HAB vHabmain
= NULLHANDLE
;
91 wxApp
* wxTheApp
= NULL
;
93 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
94 // with NR suffix - wxWindow::OS2Create() supposes this
95 wxChar wxFrameClassName
[] = wxT("wxFrameClass");
96 wxChar wxFrameClassNameNoRedraw
[] = wxT("wxFrameClassNR");
97 wxChar wxMDIFrameClassName
[] = wxT("wxMDIFrameClass");
98 wxChar wxMDIFrameClassNameNoRedraw
[] = wxT("wxMDIFrameClassNR");
99 wxChar wxMDIChildFrameClassName
[] = wxT("wxMDIChildFrameClass");
100 wxChar wxMDIChildFrameClassNameNoRedraw
[] = wxT("wxMDIChildFrameClassNR");
101 wxChar wxPanelClassName
[] = wxT("wxPanelClass");
102 wxChar wxCanvasClassName
[] = wxT("wxCanvasClass");
104 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
105 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
106 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
108 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
109 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
110 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
112 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
114 MRESULT EXPENTRY
wxWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
115 MRESULT EXPENTRY
wxFrameWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
117 // ===========================================================================
119 // ===========================================================================
121 // ---------------------------------------------------------------------------
122 // helper struct and functions for socket handling
123 // ---------------------------------------------------------------------------
125 struct GsocketCallbackInfo
{
126 void (*proc
)(void *);
132 // These defines and wrapper functions are used here and in gsockpm.c
133 #define wxSockReadMask 0x01
134 #define wxSockWriteMask 0x02
137 int wxAppAddSocketHandler(int handle
, int mask
,
138 void (*callback
)(void*), void * gsock
)
140 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
144 void wxAppRemoveSocketHandler(int handle
)
146 wxTheApp
->RemoveSocketHandler(handle
);
149 void wxApp::HandleSockets()
151 bool pendingEvent
= false;
153 // Check whether it's time for Gsocket operation
154 if (m_maxSocketHandles
> 0 && m_maxSocketNr
> 0)
156 fd_set readfds
= m_readfds
;
157 fd_set writefds
= m_writefds
;
158 struct timeval timeout
;
160 struct GsocketCallbackInfo
161 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
165 if ( select(m_maxSocketNr
, &readfds
, &writefds
, 0, &timeout
) > 0)
167 for (i
= m_lastUsedHandle
+ 1; i
!= m_lastUsedHandle
; i
++)
169 if (i
== m_maxSocketNr
)
171 if (FD_ISSET(i
, &readfds
))
174 for (r
= 0; r
< m_maxSocketHandles
; r
++){
175 if(CallbackInfo
[r
].handle
== i
&&
176 CallbackInfo
[r
].type
== wxSockReadMask
)
179 if (r
< m_maxSocketHandles
)
181 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
186 if (FD_ISSET(i
, &writefds
))
189 for (r
= 0; r
< m_maxSocketHandles
; r
++)
190 if(CallbackInfo
[r
].handle
== i
&&
191 CallbackInfo
[r
].type
== wxSockWriteMask
)
193 if (r
< m_maxSocketHandles
)
195 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
201 m_lastUsedHandle
= i
;
207 // ---------------------------------------------------------------------------
209 // ---------------------------------------------------------------------------
211 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
213 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
214 EVT_IDLE(wxApp::OnIdle
)
215 EVT_END_SESSION(wxApp::OnEndSession
)
216 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
222 bool wxApp::Initialize(
226 #if defined(wxUSE_CONSOLEDEBUG)
227 #if wxUSE_CONSOLEDEBUG
228 /***********************************************/
229 /* Code for using stdout debug */
230 /* To use it you mast link app as "Window" - EK*/
231 /***********************************************/
236 printf("In console\n");
238 DosGetInfoBlocks(&tib
, &pib
);
239 /* Try morphing into a PM application. */
240 // if(pib->pib_ultype == 2) /* VIO */
243 /**********************************************/
244 /**********************************************/
245 #endif //wxUSE_CONSOLEDEBUG
249 // OS2 has to have an anchorblock
251 vHab
= WinInitialize(0);
258 // Some people may wish to use this, but
259 // probably it shouldn't be here by default.
261 // wxRedirectIOToConsole();
264 wxBuffer
= new wxChar
[1500]; // FIXME; why?
266 wxClassInfo::InitializeClasses();
269 wxPendingEventsLocker
= new wxCriticalSection
;
272 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
273 wxTheColourDatabase
->Initialize();
275 wxInitializeStockLists();
276 wxInitializeStockObjects();
278 #if wxUSE_WX_RESOURCES
279 wxInitializeResourceSystem();
282 wxBitmap::InitStandardHandlers();
284 RegisterWindowClasses(vHab
);
285 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
287 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
288 // PLEASE DO NOT ALTER THIS.
289 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
290 extern char wxDummyChar
;
291 if (wxDummyChar
) wxDummyChar
++;
294 // wxSetKeyboardHook(TRUE);
296 wxModule::RegisterModules();
297 if (!wxModule::InitializeModules())
300 } // end of wxApp::Initialize
302 const char* CANTREGISTERCLASS
= " Can't register Class ";
303 // ---------------------------------------------------------------------------
304 // RegisterWindowClasses
305 // ---------------------------------------------------------------------------
307 bool wxApp::RegisterWindowClasses(
315 if (!::WinRegisterClass( vHab
318 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
| CS_CLIPCHILDREN
322 vError
= ::WinGetLastError(vHab
);
323 sError
= wxPMErrorToStr(vError
);
324 wxLogLastError(sError
);
328 if (!::WinRegisterClass( vHab
329 ,wxFrameClassNameNoRedraw
335 vError
= ::WinGetLastError(vHab
);
336 sError
= wxPMErrorToStr(vError
);
337 wxLogLastError(sError
);
341 if (!::WinRegisterClass( vHab
344 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
348 vError
= ::WinGetLastError(vHab
);
349 sError
= wxPMErrorToStr(vError
);
350 wxLogLastError(sError
);
354 if (!::WinRegisterClass( vHab
355 ,wxMDIFrameClassNameNoRedraw
361 vError
= ::WinGetLastError(vHab
);
362 sError
= wxPMErrorToStr(vError
);
363 wxLogLastError(sError
);
367 if (!::WinRegisterClass( vHab
368 ,wxMDIChildFrameClassName
370 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
374 vError
= ::WinGetLastError(vHab
);
375 sError
= wxPMErrorToStr(vError
);
376 wxLogLastError(sError
);
380 if (!::WinRegisterClass( vHab
381 ,wxMDIChildFrameClassNameNoRedraw
387 vError
= ::WinGetLastError(vHab
);
388 sError
= wxPMErrorToStr(vError
);
389 wxLogLastError(sError
);
393 if (!::WinRegisterClass( vHab
396 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
400 vError
= ::WinGetLastError(vHab
);
401 sError
= wxPMErrorToStr(vError
);
402 wxLogLastError(sError
);
406 if (!::WinRegisterClass( vHab
409 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
| CS_CLIPCHILDREN
413 vError
= ::WinGetLastError(vHab
);
414 sError
= wxPMErrorToStr(vError
);
415 wxLogLastError(sError
);
419 } // end of wxApp::RegisterWindowClasses
422 // Cleans up any wxWindows internal structures left lying around
424 void wxApp::CleanUp()
433 // Flush the logged messages if any and install a 'safer' log target: the
434 // default one (wxLogGui) can't be used after the resources are freed just
435 // below and the user suppliedo ne might be even more unsafe (using any
436 // wxWindows GUI function is unsafe starting from now)
438 wxLog::DontCreateOnDemand();
441 // This will flush the old messages if any
443 delete wxLog::SetActiveTarget(new wxLogStderr
);
447 // One last chance for pending objects to be cleaned up
449 wxTheApp
->DeletePendingObjects();
451 wxModule::CleanUpModules();
453 #if wxUSE_WX_RESOURCES
454 wxCleanUpResourceSystem();
457 wxDeleteStockObjects();
460 // Destroy all GDI lists, etc.
462 wxDeleteStockLists();
464 delete wxTheColourDatabase
;
465 wxTheColourDatabase
= NULL
;
467 wxBitmap::CleanUpHandlers();
473 // PM-SPECIFIC CLEANUP
476 // wxSetKeyboardHook(FALSE);
478 if (wxSTD_FRAME_ICON
)
479 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
480 if (wxSTD_MDICHILDFRAME_ICON
)
481 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
482 if (wxSTD_MDIPARENTFRAME_ICON
)
483 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
485 if (wxDEFAULT_FRAME_ICON
)
486 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
487 if (wxDEFAULT_MDICHILDFRAME_ICON
)
488 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
489 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
490 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
492 if ( wxDisableButtonBrush
)
494 // TODO: ::DeleteObject( wxDisableButtonBrush );
498 delete wxWinHandleList
;
500 delete wxPendingEvents
;
502 delete wxPendingEventsLocker
;
503 // If we don't do the following, we get an apparent memory leak.
504 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
507 wxClassInfo::CleanUpClasses();
509 // Delete Message queue
511 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
516 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
517 // At this point we want to check if there are any memory
518 // blocks that aren't part of the wxDebugContext itself,
519 // as a special case. Then when dumping we need to ignore
520 // wxDebugContext, too.
521 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
523 wxLogDebug(wxT("There were memory leaks."));
524 wxDebugContext::Dump();
525 wxDebugContext::PrintStatistics();
527 // wxDebugContext::SetStream(NULL, NULL);
531 // do it as the very last thing because everything else can log messages
532 delete wxLog::SetActiveTarget(NULL
);
534 } // end of wxApp::CleanUp
536 //----------------------------------------------------------------------
537 // Main wxWindows entry point
538 //----------------------------------------------------------------------
546 if (!wxApp::Initialize(vHab
))
550 // create the application object or ensure that one already exists
554 // The app may have declared a global application object, but we recommend
555 // the IMPLEMENT_APP macro is used instead, which sets an initializer
556 // function for delayed, dynamic app object construction.
557 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
558 wxT("No initializer - use IMPLEMENT_APP macro.") );
559 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
561 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
562 wxTheApp
->argc
= argc
;
565 wxTheApp
->argv
= new wxChar
*[argc
+1];
571 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
574 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
576 wxTheApp
->argv
= argv
;
579 wxString
sName(wxFileNameFromPath(argv
[0]));
581 wxStripExtension(sName
);
582 wxTheApp
->SetAppName(sName
);
586 if (!wxTheApp
->OnInitGui())
591 if (wxTheApp
->OnInit())
593 nRetValue
= wxTheApp
->OnRun();
596 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
599 // Forcibly delete the window.
600 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
601 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
603 pTopWindow
->Close(TRUE
);
604 wxTheApp
->DeletePendingObjects();
609 wxTheApp
->SetTopWindow(NULL
);
613 else // app initialization failed
615 wxLogLastError(" Gui initialization failed, exitting");
617 #if wxUSE_CONSOLEDEBUG
618 printf("wxTheApp->OnExit ");
622 #if wxUSE_CONSOLEDEBUG
623 printf("wxApp::CleanUp ");
627 #if wxUSE_CONSOLEDEBUG
628 printf("return %i ", nRetValue
);
634 bool wxApp::OnInitGui()
639 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
642 vError
= ::WinGetLastError(vHabmain
);
643 sError
= wxPMErrorToStr(vError
);
648 } // end of wxApp::OnInitGui
651 // Static member initialization
653 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
659 m_wantDebugOutput
= TRUE
;
663 m_nPrintMode
= wxPRINT_WINDOWS
;
664 m_exitOnFrameDelete
= TRUE
;
667 m_maxSocketHandles
= 0;
669 m_sockCallbackInfo
= 0;
670 } // end of wxApp::wxApp
675 // Delete command-line args
680 for (i
= 0; i
< argc
; i
++)
686 } // end of wxApp::~wxApp
688 bool wxApp::Initialized()
694 } // end of wxApp::Initialized
697 // Get and process a message, returning FALSE if WM_QUIT
698 // received (and also set the flag telling the app to exit the main loop)
701 bool wxApp::DoMessage()
703 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
708 m_bKeepGoing
= FALSE
;
713 // should never happen, but let's test for it nevertheless
714 wxLogLastError("GetMessage");
719 wxASSERT_MSG( wxThread::IsMain()
720 ,wxT("only the main thread can process Windows messages")
723 static bool sbHadGuiLock
= TRUE
;
724 static wxMsgArray svSavedMessages
;
727 // If a secondary thread owns is doing GUI calls, save all messages for
728 // later processing - we can't process them right now because it will
729 // lead to recursive library calls (and we're not reentrant)
731 if (!wxGuiOwnedByMainThread())
733 sbHadGuiLock
= FALSE
;
736 // Leave out WM_COMMAND messages: too dangerous, sometimes
737 // the message will be processed twice
739 if ( !wxIsWaitingForThread() ||
740 svCurrentMsg
.msg
!= WM_COMMAND
)
742 svSavedMessages
.Add(svCurrentMsg
);
749 // Have we just regained the GUI lock? if so, post all of the saved
756 size_t nCount
= svSavedMessages
.Count();
758 for (size_t n
= 0; n
< nCount
; n
++)
760 QMSG vMsg
= svSavedMessages
[n
];
762 if ( !ProcessMessage((WXMSG
*)&vMsg
) )
764 ::WinDispatchMsg(vHabmain
, &vMsg
);
767 svSavedMessages
.Empty();
770 #endif // wxUSE_THREADS
772 // Process the message
773 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
775 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
779 } // end of wxApp::DoMessage
781 //////////////////////////////////////////////////////////////////////////////
783 // Keep trying to process messages until WM_QUIT
786 // If there are messages to be processed, they will all be
787 // processed and OnIdle will not be called.
788 // When there are no more messages, OnIdle is called.
789 // If OnIdle requests more time,
790 // it will be repeatedly called so long as there are no pending messages.
791 // A 'feature' of this is that once OnIdle has decided that no more processing
792 // is required, then it won't get processing time until further messages
793 // are processed (it'll sit in DoMessage).
795 //////////////////////////////////////////////////////////////////////////////
796 int wxApp::MainLoop()
803 wxMutexGuiLeaveOrEnter();
804 #endif // wxUSE_THREADS
805 while (!Pending() && ProcessIdle())
817 return (int)svCurrentMsg
.mp1
;
818 } // end of wxApp::MainLoop
821 // Returns TRUE if more time is needed.
823 bool wxApp::ProcessIdle()
827 vEvent
.SetEventObject(this);
828 ProcessEvent(vEvent
);
829 return vEvent
.MoreRequested();
830 } // end of wxApp::ProcessIdle
832 void wxApp::ExitMainLoop()
834 m_bKeepGoing
= FALSE
;
837 bool wxApp::Pending()
839 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
842 void wxApp::Dispatch()
847 //////////////////////////////////////////////////////////////////////////////
849 // Give all windows a chance to preprocess
850 // the message. Some may have accelerator tables, or have
851 // MDI complications.
853 //////////////////////////////////////////////////////////////////////////////
854 bool wxApp::ProcessMessage(
858 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
859 HWND hWnd
= pMsg
->hwnd
;
860 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
865 // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
866 // popup the tooltip bubbles
868 if (pWndThis
&& (pMsg
->msg
== WM_MOUSEMOVE
))
870 wxToolTip
* pToolTip
= pWndThis
->GetToolTip();
873 pToolTip
->RelayEvent(pWxmsg
);
876 #endif // wxUSE_TOOLTIPS
879 // We must relay Timer events to wxTimer's processing function
881 if (pMsg
->msg
== WM_TIMER
)
882 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
885 // For some composite controls (like a combobox), wndThis might be NULL
886 // because the subcontrol is not a wxWindow, but only the control itself
887 // is - try to catch this case
889 while (hWnd
&& !pWndThis
)
891 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
892 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
896 // Try translations first; find the youngest window with
897 // a translation table. OS/2 has case sensative accels, so
898 // this block, coded by BK, removes that and helps make them
901 if(pMsg
->msg
== WM_CHAR
)
903 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
904 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
908 // Do not process keyup events
910 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
912 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
913 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
916 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
918 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
922 if(!bRc
) // untranslated, should restore original value
923 CHARMSG(pChmsg
)->chr
= uSch
;
927 // Anyone for a non-translation message? Try youngest descendants first.
929 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
931 // if (pWnd->OS2ProcessMessage(pWxmsg))
935 } // end of wxApp::ProcessMessage
941 static bool sbInOnIdle
= FALSE
;
944 // Avoid recursion (via ProcessEvent default case)
952 // If there are pending events, we must process them: pending events
953 // are either events to the threads other than main or events posted
954 // with wxPostEvent() functions
956 ProcessPendingEvents();
959 // 'Garbage' collection of windows deleted with Close().
961 DeletePendingObjects();
965 // Flush the logged messages if any
967 wxLog::FlushActive();
971 // Send OnIdle events to all windows
973 if (SendIdleEvents())
976 // SendIdleEvents() returns TRUE if at least one window requested more
979 rEvent
.RequestMore(TRUE
);
982 } // end of wxApp::OnIdle
984 // Send idle event to all top-level windows
985 bool wxApp::SendIdleEvents()
987 bool bNeedMore
= FALSE
;
988 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
992 wxWindow
* pWin
= pNode
->GetData();
994 if (SendIdleEvents(pWin
))
996 pNode
= pNode
->GetNext();
999 } // end of wxApp::SendIdleEvents
1002 // Send idle event to window and all subwindows
1004 bool wxApp::SendIdleEvents(
1008 bool bNeedMore
= FALSE
;
1011 vEvent
.SetEventObject(pWin
);
1012 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1014 if (vEvent
.MoreRequested())
1017 wxNode
* pNode
= pWin
->GetChildren().First();
1021 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1023 if (SendIdleEvents(pWin
))
1025 pNode
= pNode
->Next();
1028 } // end of wxApp::SendIdleEvents
1030 void wxApp::DeletePendingObjects()
1032 wxNode
* pNode
= wxPendingDelete
.First();
1036 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1040 if (wxPendingDelete
.Member(pObj
))
1044 // Deleting one object may have deleted other pending
1045 // objects, so start from beginning of list again.
1047 pNode
= wxPendingDelete
.First();
1049 } // end of wxApp::DeletePendingObjects
1051 void wxApp::OnEndSession(
1052 wxCloseEvent
& WXUNUSED(rEvent
))
1055 GetTopWindow()->Close(TRUE
);
1056 } // end of wxApp::OnEndSession
1059 // Default behaviour: close the application with prompts. The
1060 // user can veto the close, and therefore the end session.
1062 void wxApp::OnQueryEndSession(
1063 wxCloseEvent
& rEvent
1068 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1071 } // end of wxApp::OnQueryEndSession
1075 wxLogError(_("Fatal error: exiting"));
1080 static bool gs_inYield
= FALSE
;
1083 // Yield to incoming messages
1091 // Disable log flushing from here because a call to wxYield() shouldn't
1092 // normally result in message boxes popping up &c
1099 // We want to go back to the main message loop
1100 // if we see a WM_QUIT. (?)
1102 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1105 wxMutexGuiLeaveOrEnter();
1106 #endif // wxUSE_THREADS
1107 if (!wxTheApp
->DoMessage())
1111 // If they are pending events, we must process them.
1114 wxTheApp
->ProcessPendingEvents();
1117 // Let the logs be flashed again
1124 // Yield to incoming messages; but fail silently if recursion is detected.
1125 bool wxYieldIfNeeded()
1133 wxIcon
wxApp::GetStdIcon(
1139 case wxICON_INFORMATION
:
1140 return wxIcon("wxICON_INFO");
1142 case wxICON_QUESTION
:
1143 return wxIcon("wxICON_QUESTION");
1145 case wxICON_EXCLAMATION
:
1146 return wxIcon("wxICON_WARNING");
1149 wxFAIL_MSG(wxT("requested non existent standard icon"));
1150 // still fall through
1153 return wxIcon("wxICON_ERROR");
1155 return wxIcon("wxICON_ERROR");
1156 } // end of wxApp::GetStdIcon
1158 int wxApp::AddSocketHandler(int handle
, int mask
,
1159 void (*callback
)(void*), void * gsock
)
1162 struct GsocketCallbackInfo
1163 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1165 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1166 if (CallbackInfo
[find
].handle
== -1)
1168 if (find
== m_maxSocketHandles
)
1170 // Allocate new memory
1171 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1172 (m_maxSocketHandles
+=10)*
1173 sizeof(struct GsocketCallbackInfo
));
1174 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1175 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1176 CallbackInfo
[find
].handle
= -1;
1177 find
= m_maxSocketHandles
- 10;
1179 CallbackInfo
[find
].proc
= callback
;
1180 CallbackInfo
[find
].type
= mask
;
1181 CallbackInfo
[find
].handle
= handle
;
1182 CallbackInfo
[find
].gsock
= gsock
;
1183 if (mask
& wxSockReadMask
)
1184 FD_SET(handle
, &m_readfds
);
1185 if (mask
& wxSockWriteMask
)
1186 FD_SET(handle
, &m_writefds
);
1187 if (handle
>= m_maxSocketNr
)
1188 m_maxSocketNr
= handle
+ 1;
1192 void wxApp::RemoveSocketHandler(int handle
)
1194 struct GsocketCallbackInfo
1195 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1196 if (handle
< m_maxSocketHandles
)
1198 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1199 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1200 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1201 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1202 CallbackInfo
[handle
].handle
= -1;
1206 //-----------------------------------------------------------------------------
1208 //-----------------------------------------------------------------------------
1213 // Send the top window a dummy message so idle handler processing will
1214 // start up again. Doing it this way ensures that the idle handler
1215 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1216 // the same for the main app thread only)
1218 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1222 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1225 // Should never happen
1227 wxLogLastError("PostMessage(WM_NULL)");
1230 } // end of wxWakeUpIdle