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
79 #if wxUSE_WX_RESOURCES
80 #include "wx/resource.h"
84 #include "wx/tooltip.h"
85 #endif // wxUSE_TOOLTIPS
90 // ---------------------------------------------------------------------------
92 // ---------------------------------------------------------------------------
94 extern wxChar
* wxBuffer
;
95 extern wxList
* wxWinHandleList
;
96 extern wxList WXDLLEXPORT wxPendingDelete
;
97 extern wxCursor
* g_globalCursor
;
99 HAB vHabmain
= NULLHANDLE
;
101 wxApp
* wxTheApp
= NULL
;
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
138 int wxAppAddSocketHandler(int handle
, int mask
,
139 void (*callback
)(void*), void * gsock
)
141 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
144 void wxAppRemoveSocketHandler(int handle
)
146 wxTheApp
->RemoveSocketHandler(handle
);
149 // Linkage mode problems using callbacks with extern C in a .cpp module
150 int wxAppAddSocketHandler(int handle
, int mask
,
151 void (*callback
)(void*), void * gsock
)
153 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
155 void wxAppRemoveSocketHandler(int handle
)
157 wxTheApp
->RemoveSocketHandler(handle
);
161 void wxApp::HandleSockets()
163 bool pendingEvent
= FALSE
;
165 // Check whether it's time for Gsocket operation
166 if (m_maxSocketHandles
> 0 && m_maxSocketNr
> 0)
168 fd_set readfds
= m_readfds
;
169 fd_set writefds
= m_writefds
;
170 struct timeval timeout
;
172 struct GsocketCallbackInfo
173 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
177 if ( select(m_maxSocketNr
, &readfds
, &writefds
, 0, &timeout
) > 0)
179 for (i
= m_lastUsedHandle
+ 1; i
!= m_lastUsedHandle
; i
++)
181 if (i
== m_maxSocketNr
)
183 if (FD_ISSET(i
, &readfds
))
186 for (r
= 0; r
< m_maxSocketHandles
; r
++){
187 if(CallbackInfo
[r
].handle
== i
&&
188 CallbackInfo
[r
].type
== wxSockReadMask
)
191 if (r
< m_maxSocketHandles
)
193 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
198 if (FD_ISSET(i
, &writefds
))
201 for (r
= 0; r
< m_maxSocketHandles
; r
++)
202 if(CallbackInfo
[r
].handle
== i
&&
203 CallbackInfo
[r
].type
== wxSockWriteMask
)
205 if (r
< m_maxSocketHandles
)
207 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
213 m_lastUsedHandle
= i
;
219 // ---------------------------------------------------------------------------
221 // ---------------------------------------------------------------------------
223 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
225 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
226 EVT_IDLE(wxApp::OnIdle
)
227 EVT_END_SESSION(wxApp::OnEndSession
)
228 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
234 bool wxApp::Initialize(
238 #if defined(wxUSE_CONSOLEDEBUG)
239 #if wxUSE_CONSOLEDEBUG
240 /***********************************************/
241 /* Code for using stdout debug */
242 /* To use it you mast link app as "Window" - EK*/
243 /***********************************************/
248 printf("In console\n");
250 DosGetInfoBlocks(&tib
, &pib
);
251 /* Try morphing into a PM application. */
252 // if(pib->pib_ultype == 2) /* VIO */
255 /**********************************************/
256 /**********************************************/
257 #endif //wxUSE_CONSOLEDEBUG
260 wxBuffer
= new wxChar
[1500]; // FIXME; why?
262 wxClassInfo::InitializeClasses();
265 wxPendingEventsLocker
= new wxCriticalSection
;
268 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
269 wxTheColourDatabase
->Initialize();
271 wxInitializeStockLists();
272 wxInitializeStockObjects();
274 #if wxUSE_WX_RESOURCES
275 wxInitializeResourceSystem();
278 wxBitmap::InitStandardHandlers();
281 // OS2 has to have an anchorblock
283 vHab
= WinInitialize(0);
290 // Some people may wish to use this, but
291 // probably it shouldn't be here by default.
293 // wxRedirectIOToConsole();
296 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
298 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
299 // PLEASE DO NOT ALTER THIS.
300 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
301 extern char wxDummyChar
;
302 if (wxDummyChar
) wxDummyChar
++;
305 // wxSetKeyboardHook(TRUE);
307 wxModule::RegisterModules();
308 if (!wxModule::InitializeModules())
310 RegisterWindowClasses(vHab
);
312 } // end of wxApp::Initialize
314 const char* CANTREGISTERCLASS
= " Can't register Class ";
315 // ---------------------------------------------------------------------------
316 // RegisterWindowClasses
317 // ---------------------------------------------------------------------------
319 bool wxApp::RegisterWindowClasses(
326 if (!::WinRegisterClass( vHab
329 ,CS_SIZEREDRAW
| CS_SYNCPAINT
333 vError
= ::WinGetLastError(vHab
);
334 sError
= wxPMErrorToStr(vError
);
335 wxLogLastError(sError
);
339 if (!::WinRegisterClass( vHab
340 ,wxFrameClassNameNoRedraw
346 vError
= ::WinGetLastError(vHab
);
347 sError
= wxPMErrorToStr(vError
);
348 wxLogLastError(sError
);
352 if (!::WinRegisterClass( vHab
355 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
359 vError
= ::WinGetLastError(vHab
);
360 sError
= wxPMErrorToStr(vError
);
361 wxLogLastError(sError
);
365 if (!::WinRegisterClass( vHab
366 ,wxMDIFrameClassNameNoRedraw
372 vError
= ::WinGetLastError(vHab
);
373 sError
= wxPMErrorToStr(vError
);
374 wxLogLastError(sError
);
378 if (!::WinRegisterClass( vHab
379 ,wxMDIChildFrameClassName
381 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
385 vError
= ::WinGetLastError(vHab
);
386 sError
= wxPMErrorToStr(vError
);
387 wxLogLastError(sError
);
391 if (!::WinRegisterClass( vHab
392 ,wxMDIChildFrameClassNameNoRedraw
398 vError
= ::WinGetLastError(vHab
);
399 sError
= wxPMErrorToStr(vError
);
400 wxLogLastError(sError
);
404 if (!::WinRegisterClass( vHab
407 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
411 vError
= ::WinGetLastError(vHab
);
412 sError
= wxPMErrorToStr(vError
);
413 wxLogLastError(sError
);
417 if (!::WinRegisterClass( vHab
420 ,CS_SIZEREDRAW
| CS_HITTEST
| CS_SYNCPAINT
424 vError
= ::WinGetLastError(vHab
);
425 sError
= wxPMErrorToStr(vError
);
426 wxLogLastError(sError
);
429 if (!::WinRegisterClass( vHab
432 ,CS_HITTEST
| CS_SYNCPAINT
436 vError
= ::WinGetLastError(vHab
);
437 sError
= wxPMErrorToStr(vError
);
438 wxLogLastError(sError
);
442 } // end of wxApp::RegisterWindowClasses
445 // Cleans up any wxWindows internal structures left lying around
447 void wxApp::CleanUp()
456 // Flush the logged messages if any and install a 'safer' log target: the
457 // default one (wxLogGui) can't be used after the resources are freed just
458 // below and the user suppliedo ne might be even more unsafe (using any
459 // wxWindows GUI function is unsafe starting from now)
461 wxLog::DontCreateOnDemand();
464 // This will flush the old messages if any
466 delete wxLog::SetActiveTarget(new wxLogStderr
);
470 // One last chance for pending objects to be cleaned up
472 wxTheApp
->DeletePendingObjects();
474 wxModule::CleanUpModules();
476 #if wxUSE_WX_RESOURCES
477 wxCleanUpResourceSystem();
480 wxDeleteStockObjects();
483 // Destroy all GDI lists, etc.
485 wxDeleteStockLists();
487 delete wxTheColourDatabase
;
488 wxTheColourDatabase
= NULL
;
490 wxBitmap::CleanUpHandlers();
496 // PM-SPECIFIC CLEANUP
499 // wxSetKeyboardHook(FALSE);
501 if (wxSTD_FRAME_ICON
)
502 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
503 if (wxSTD_MDICHILDFRAME_ICON
)
504 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
505 if (wxSTD_MDIPARENTFRAME_ICON
)
506 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
508 if (wxDEFAULT_FRAME_ICON
)
509 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
510 if (wxDEFAULT_MDICHILDFRAME_ICON
)
511 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
512 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
513 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
515 if ( wxDisableButtonBrush
)
517 // TODO: ::DeleteObject( wxDisableButtonBrush );
521 delete wxWinHandleList
;
523 delete wxPendingEvents
;
525 delete wxPendingEventsLocker
;
526 // If we don't do the following, we get an apparent memory leak.
527 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
530 wxClassInfo::CleanUpClasses();
532 // Delete Message queue
534 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
539 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
540 // At this point we want to check if there are any memory
541 // blocks that aren't part of the wxDebugContext itself,
542 // as a special case. Then when dumping we need to ignore
543 // wxDebugContext, too.
544 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
546 wxLogDebug(wxT("There were memory leaks."));
547 wxDebugContext::Dump();
548 wxDebugContext::PrintStatistics();
550 // wxDebugContext::SetStream(NULL, NULL);
554 // do it as the very last thing because everything else can log messages
555 delete wxLog::SetActiveTarget(NULL
);
557 } // end of wxApp::CleanUp
559 //----------------------------------------------------------------------
560 // Main wxWindows entry point
561 //----------------------------------------------------------------------
569 if (!wxApp::Initialize(vHab
))
573 // create the application object or ensure that one already exists
577 // The app may have declared a global application object, but we recommend
578 // the IMPLEMENT_APP macro is used instead, which sets an initializer
579 // function for delayed, dynamic app object construction.
580 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
581 wxT("No initializer - use IMPLEMENT_APP macro.") );
582 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
584 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
585 wxTheApp
->argc
= argc
;
588 wxTheApp
->argv
= new wxChar
*[argc
+1];
594 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
597 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
599 wxTheApp
->argv
= argv
;
602 wxString
sName(wxFileNameFromPath(argv
[0]));
604 wxStripExtension(sName
);
605 wxTheApp
->SetAppName(sName
);
609 if (!wxTheApp
->OnInitGui())
614 if (wxTheApp
->OnInit())
619 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
622 // Forcibly delete the window.
623 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
624 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
626 pTopWindow
->Close(TRUE
);
627 wxTheApp
->DeletePendingObjects();
632 wxTheApp
->SetTopWindow(NULL
);
636 else // app initialization failed
638 wxLogLastError(" Gui initialization failed, exitting");
640 #if wxUSE_CONSOLEDEBUG
641 printf("wxTheApp->OnExit ");
644 nRetValue
= wxTheApp
->OnExit();
645 #if wxUSE_CONSOLEDEBUG
646 printf("wxApp::CleanUp ");
650 #if wxUSE_CONSOLEDEBUG
651 printf("return %i ", nRetValue
);
657 bool wxApp::OnInitGui()
662 if (!wxAppBase::OnInitGui())
665 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
668 vError
= ::WinGetLastError(vHabmain
);
669 sError
= wxPMErrorToStr(vError
);
675 } // end of wxApp::OnInitGui
678 // Static member initialization
680 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
689 m_nPrintMode
= wxPRINT_WINDOWS
;
692 m_maxSocketHandles
= 0;
694 m_sockCallbackInfo
= 0;
695 } // end of wxApp::wxApp
700 // Delete command-line args
705 for (i
= 0; i
< argc
; i
++)
711 } // end of wxApp::~wxApp
713 bool wxApp::Initialized()
719 } // end of wxApp::Initialized
722 // Get and process a message, returning FALSE if WM_QUIT
723 // received (and also set the flag telling the app to exit the main loop)
726 bool wxApp::DoMessage()
728 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
733 m_bKeepGoing
= FALSE
;
738 // should never happen, but let's test for it nevertheless
739 wxLogLastError("GetMessage");
744 wxASSERT_MSG( wxThread::IsMain()
745 ,wxT("only the main thread can process Windows messages")
748 static bool sbHadGuiLock
= TRUE
;
749 static wxMsgArray svSavedMessages
;
752 // If a secondary thread owns is doing GUI calls, save all messages for
753 // later processing - we can't process them right now because it will
754 // lead to recursive library calls (and we're not reentrant)
756 if (!wxGuiOwnedByMainThread())
758 sbHadGuiLock
= FALSE
;
761 // Leave out WM_COMMAND messages: too dangerous, sometimes
762 // the message will be processed twice
764 if ( !wxIsWaitingForThread() ||
765 svCurrentMsg
.msg
!= WM_COMMAND
)
767 svSavedMessages
.Add(svCurrentMsg
);
774 // Have we just regained the GUI lock? if so, post all of the saved
781 size_t nCount
= svSavedMessages
.Count();
783 for (size_t n
= 0; n
< nCount
; n
++)
785 QMSG vMsg
= svSavedMessages
[n
];
787 DoMessage((WXMSG
*)&vMsg
);
789 svSavedMessages
.Empty();
792 #endif // wxUSE_THREADS
795 // Process the message
797 DoMessage((WXMSG
*)&svCurrentMsg
);
800 } // end of wxApp::DoMessage
802 void wxApp::DoMessage(
806 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
808 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
810 } // end of wxApp::DoMessage
812 //////////////////////////////////////////////////////////////////////////////
814 // Keep trying to process messages until WM_QUIT
817 // If there are messages to be processed, they will all be
818 // processed and OnIdle will not be called.
819 // When there are no more messages, OnIdle is called.
820 // If OnIdle requests more time,
821 // it will be repeatedly called so long as there are no pending messages.
822 // A 'feature' of this is that once OnIdle has decided that no more processing
823 // is required, then it won't get processing time until further messages
824 // are processed (it'll sit in DoMessage).
826 //////////////////////////////////////////////////////////////////////////////
827 int wxApp::MainLoop()
834 wxMutexGuiLeaveOrEnter();
835 #endif // wxUSE_THREADS
836 while (!Pending() && ProcessIdle())
848 return (int)svCurrentMsg
.mp1
;
849 } // end of wxApp::MainLoop
852 // Returns TRUE if more time is needed.
854 bool wxApp::ProcessIdle()
858 vEvent
.SetEventObject(this);
859 ProcessEvent(vEvent
);
860 return vEvent
.MoreRequested();
861 } // end of wxApp::ProcessIdle
863 void wxApp::ExitMainLoop()
865 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
866 } // end of wxApp::ExitMainLoop
868 bool wxApp::Pending()
870 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
871 } // end of wxApp::Pending
873 void wxApp::Dispatch()
878 //////////////////////////////////////////////////////////////////////////////
880 // Give all windows a chance to preprocess
881 // the message. Some may have accelerator tables, or have
882 // MDI complications.
884 //////////////////////////////////////////////////////////////////////////////
885 bool wxApp::ProcessMessage(
889 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
890 HWND hWnd
= pMsg
->hwnd
;
891 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
895 // Pass non-system timer messages to the wxTimerProc
897 if (pMsg
->msg
== WM_TIMER
&&
898 (SHORT1FROMMP(pMsg
->mp1
) != TID_CURSOR
&&
899 SHORT1FROMMP(pMsg
->mp1
) != TID_FLASHWINDOW
&&
900 SHORT1FROMMP(pMsg
->mp1
) != TID_SCROLL
&&
901 SHORT1FROMMP(pMsg
->mp1
) != 0x0000
903 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
906 // Allow the window to prevent certain messages from being
907 // translated/processed (this is currently used by wxTextCtrl to always
908 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
910 if (pWndThis
&& !pWndThis
->OS2ShouldPreProcessMessage(pWxmsg
))
916 // For some composite controls (like a combobox), wndThis might be NULL
917 // because the subcontrol is not a wxWindow, but only the control itself
918 // is - try to catch this case
920 while (hWnd
&& !pWndThis
)
922 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
923 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
927 // Try translations first; find the youngest window with
928 // a translation table. OS/2 has case sensative accels, so
929 // this block, coded by BK, removes that and helps make them
932 if(pMsg
->msg
== WM_CHAR
)
934 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
935 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
939 // Do not process keyup events
941 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
943 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
944 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
947 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
949 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
953 if(!bRc
) // untranslated, should restore original value
954 CHARMSG(pChmsg
)->chr
= uSch
;
958 // Anyone for a non-translation message? Try youngest descendants first.
960 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
962 // if (pWnd->OS2ProcessMessage(pWxmsg))
966 } // end of wxApp::ProcessMessage
968 bool gbInOnIdle
= FALSE
;
976 // Avoid recursion (via ProcessEvent default case)
984 // If there are pending events, we must process them: pending events
985 // are either events to the threads other than main or events posted
986 // with wxPostEvent() functions
988 ProcessPendingEvents();
991 // 'Garbage' collection of windows deleted with Close().
993 DeletePendingObjects();
997 // Flush the logged messages if any
999 wxLog::FlushActive();
1002 #if wxUSE_DC_CACHEING
1003 // automated DC cache management: clear the cached DCs and bitmap
1004 // if it's likely that the app has finished with them, that is, we
1005 // get an idle event and we're not dragging anything.
1006 if (!::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON1
) &&
1007 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON3
) &&
1008 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON2
))
1010 #endif // wxUSE_DC_CACHEING
1013 // Send OnIdle events to all windows
1015 if (SendIdleEvents())
1018 // SendIdleEvents() returns TRUE if at least one window requested more
1021 rEvent
.RequestMore(TRUE
);
1024 } // end of wxApp::OnIdle
1026 // Send idle event to all top-level windows
1027 bool wxApp::SendIdleEvents()
1029 bool bNeedMore
= FALSE
;
1030 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1034 wxWindow
* pWin
= pNode
->GetData();
1036 if (SendIdleEvents(pWin
))
1038 pNode
= pNode
->GetNext();
1041 } // end of wxApp::SendIdleEvents
1044 // Send idle event to window and all subwindows
1046 bool wxApp::SendIdleEvents(
1050 bool bNeedMore
= FALSE
;
1053 vEvent
.SetEventObject(pWin
);
1054 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1056 if (vEvent
.MoreRequested())
1059 wxNode
* pNode
= pWin
->GetChildren().First();
1063 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1065 if (SendIdleEvents(pWin
))
1067 pNode
= pNode
->Next();
1070 } // end of wxApp::SendIdleEvents
1072 void wxApp::DeletePendingObjects()
1074 wxNode
* pNode
= wxPendingDelete
.First();
1078 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1082 if (wxPendingDelete
.Member(pObj
))
1086 // Deleting one object may have deleted other pending
1087 // objects, so start from beginning of list again.
1089 pNode
= wxPendingDelete
.First();
1091 } // end of wxApp::DeletePendingObjects
1093 void wxApp::OnEndSession(
1094 wxCloseEvent
& WXUNUSED(rEvent
))
1097 GetTopWindow()->Close(TRUE
);
1098 } // end of wxApp::OnEndSession
1101 // Default behaviour: close the application with prompts. The
1102 // user can veto the close, and therefore the end session.
1104 void wxApp::OnQueryEndSession(
1105 wxCloseEvent
& rEvent
1110 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1113 } // end of wxApp::OnQueryEndSession
1117 wxLogError(_("Fatal error: exiting"));
1123 // Yield to incoming messages
1125 bool wxApp::Yield(bool onlyIfNeeded
)
1127 static bool s_inYield
= FALSE
;
1131 if ( !onlyIfNeeded
)
1133 wxFAIL_MSG( _T("wxYield() called recursively") );
1143 // Disable log flushing from here because a call to wxYield() shouldn't
1144 // normally result in message boxes popping up &c
1151 // We want to go back to the main message loop
1152 // if we see a WM_QUIT. (?)
1154 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1157 wxMutexGuiLeaveOrEnter();
1158 #endif // wxUSE_THREADS
1159 if (!wxTheApp
->DoMessage())
1163 // If they are pending events, we must process them.
1166 wxTheApp
->ProcessPendingEvents();
1169 // Let the logs be flashed again
1176 int wxApp::AddSocketHandler(int handle
, int mask
,
1177 void (*callback
)(void*), void * gsock
)
1180 struct GsocketCallbackInfo
1181 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1183 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1184 if (CallbackInfo
[find
].handle
== -1)
1186 if (find
== m_maxSocketHandles
)
1188 // Allocate new memory
1189 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1190 (m_maxSocketHandles
+=10)*
1191 sizeof(struct GsocketCallbackInfo
));
1192 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1193 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1194 CallbackInfo
[find
].handle
= -1;
1195 find
= m_maxSocketHandles
- 10;
1197 CallbackInfo
[find
].proc
= callback
;
1198 CallbackInfo
[find
].type
= mask
;
1199 CallbackInfo
[find
].handle
= handle
;
1200 CallbackInfo
[find
].gsock
= gsock
;
1201 if (mask
& wxSockReadMask
)
1202 FD_SET(handle
, &m_readfds
);
1203 if (mask
& wxSockWriteMask
)
1204 FD_SET(handle
, &m_writefds
);
1205 if (handle
>= m_maxSocketNr
)
1206 m_maxSocketNr
= handle
+ 1;
1210 void wxApp::RemoveSocketHandler(int handle
)
1212 struct GsocketCallbackInfo
1213 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1214 if (handle
< m_maxSocketHandles
)
1216 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1217 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1218 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1219 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1220 CallbackInfo
[handle
].handle
= -1;
1224 //-----------------------------------------------------------------------------
1226 //-----------------------------------------------------------------------------
1231 // Send the top window a dummy message so idle handler processing will
1232 // start up again. Doing it this way ensures that the idle handler
1233 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1234 // the same for the main app thread only)
1236 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1240 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1243 // Should never happen
1245 wxLogLastError("PostMessage(WM_NULL)");
1248 } // end of wxWakeUpIdle