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
;
99 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
100 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
101 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
103 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
104 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
105 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
107 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
109 MRESULT EXPENTRY
wxWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
110 MRESULT EXPENTRY
wxFrameWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
112 // ===========================================================================
114 // ===========================================================================
116 // ---------------------------------------------------------------------------
117 // helper struct and functions for socket handling
118 // ---------------------------------------------------------------------------
120 struct GsocketCallbackInfo
{
121 void (*proc
)(void *);
127 // These defines and wrapper functions are used here and in gsockpm.c
128 #define wxSockReadMask 0x01
129 #define wxSockWriteMask 0x02
133 int wxAppAddSocketHandler(int handle
, int mask
,
134 void (*callback
)(void*), void * gsock
)
136 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
139 void wxAppRemoveSocketHandler(int handle
)
141 wxTheApp
->RemoveSocketHandler(handle
);
144 // Linkage mode problems using callbacks with extern C in a .cpp module
145 int wxAppAddSocketHandler(int handle
, int mask
,
146 void (*callback
)(void*), void * gsock
)
148 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
150 void wxAppRemoveSocketHandler(int handle
)
152 wxTheApp
->RemoveSocketHandler(handle
);
156 void wxApp::HandleSockets()
158 bool pendingEvent
= FALSE
;
160 // Check whether it's time for Gsocket operation
161 if (m_maxSocketHandles
> 0 && m_maxSocketNr
> 0)
163 fd_set readfds
= m_readfds
;
164 fd_set writefds
= m_writefds
;
165 struct timeval timeout
;
167 struct GsocketCallbackInfo
168 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
172 if ( select(m_maxSocketNr
, &readfds
, &writefds
, 0, &timeout
) > 0)
174 for (i
= m_lastUsedHandle
+ 1; i
!= m_lastUsedHandle
; i
++)
176 if (i
== m_maxSocketNr
)
178 if (FD_ISSET(i
, &readfds
))
181 for (r
= 0; r
< m_maxSocketHandles
; r
++){
182 if(CallbackInfo
[r
].handle
== i
&&
183 CallbackInfo
[r
].type
== wxSockReadMask
)
186 if (r
< m_maxSocketHandles
)
188 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
193 if (FD_ISSET(i
, &writefds
))
196 for (r
= 0; r
< m_maxSocketHandles
; r
++)
197 if(CallbackInfo
[r
].handle
== i
&&
198 CallbackInfo
[r
].type
== wxSockWriteMask
)
200 if (r
< m_maxSocketHandles
)
202 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
208 m_lastUsedHandle
= i
;
214 // ---------------------------------------------------------------------------
216 // ---------------------------------------------------------------------------
218 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
220 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
221 EVT_IDLE(wxApp::OnIdle
)
222 EVT_END_SESSION(wxApp::OnEndSession
)
223 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
229 bool wxApp::Initialize(
233 #if defined(wxUSE_CONSOLEDEBUG)
234 #if wxUSE_CONSOLEDEBUG
235 /***********************************************/
236 /* Code for using stdout debug */
237 /* To use it you mast link app as "Window" - EK*/
238 /***********************************************/
243 printf("In console\n");
245 DosGetInfoBlocks(&tib
, &pib
);
246 /* Try morphing into a PM application. */
247 // if(pib->pib_ultype == 2) /* VIO */
250 /**********************************************/
251 /**********************************************/
252 #endif //wxUSE_CONSOLEDEBUG
255 wxBuffer
= new wxChar
[1500]; // FIXME; why?
257 wxClassInfo::InitializeClasses();
260 wxPendingEventsLocker
= new wxCriticalSection
;
263 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
264 wxTheColourDatabase
->Initialize();
266 wxInitializeStockLists();
267 wxInitializeStockObjects();
269 wxBitmap::InitStandardHandlers();
272 // OS2 has to have an anchorblock
274 vHab
= WinInitialize(0);
281 // Some people may wish to use this, but
282 // probably it shouldn't be here by default.
284 // wxRedirectIOToConsole();
287 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
289 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
290 // PLEASE DO NOT ALTER THIS.
291 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
292 extern char wxDummyChar
;
293 if (wxDummyChar
) wxDummyChar
++;
296 // wxSetKeyboardHook(TRUE);
298 wxModule::RegisterModules();
299 if (!wxModule::InitializeModules())
301 RegisterWindowClasses(vHab
);
303 } // end of wxApp::Initialize
305 const char* CANTREGISTERCLASS
= " Can't register Class ";
306 // ---------------------------------------------------------------------------
307 // RegisterWindowClasses
308 // ---------------------------------------------------------------------------
310 bool wxApp::RegisterWindowClasses(
317 if (!::WinRegisterClass( vHab
320 ,CS_SIZEREDRAW
| CS_SYNCPAINT
324 vError
= ::WinGetLastError(vHab
);
325 sError
= wxPMErrorToStr(vError
);
326 wxLogLastError(sError
);
330 if (!::WinRegisterClass( vHab
331 ,wxFrameClassNameNoRedraw
337 vError
= ::WinGetLastError(vHab
);
338 sError
= wxPMErrorToStr(vError
);
339 wxLogLastError(sError
);
343 if (!::WinRegisterClass( vHab
346 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
350 vError
= ::WinGetLastError(vHab
);
351 sError
= wxPMErrorToStr(vError
);
352 wxLogLastError(sError
);
356 if (!::WinRegisterClass( vHab
357 ,wxMDIFrameClassNameNoRedraw
363 vError
= ::WinGetLastError(vHab
);
364 sError
= wxPMErrorToStr(vError
);
365 wxLogLastError(sError
);
369 if (!::WinRegisterClass( vHab
370 ,wxMDIChildFrameClassName
372 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
376 vError
= ::WinGetLastError(vHab
);
377 sError
= wxPMErrorToStr(vError
);
378 wxLogLastError(sError
);
382 if (!::WinRegisterClass( vHab
383 ,wxMDIChildFrameClassNameNoRedraw
389 vError
= ::WinGetLastError(vHab
);
390 sError
= wxPMErrorToStr(vError
);
391 wxLogLastError(sError
);
395 if (!::WinRegisterClass( vHab
398 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
402 vError
= ::WinGetLastError(vHab
);
403 sError
= wxPMErrorToStr(vError
);
404 wxLogLastError(sError
);
408 if (!::WinRegisterClass( vHab
411 ,CS_SIZEREDRAW
| CS_HITTEST
| CS_SYNCPAINT
415 vError
= ::WinGetLastError(vHab
);
416 sError
= wxPMErrorToStr(vError
);
417 wxLogLastError(sError
);
420 if (!::WinRegisterClass( vHab
423 ,CS_HITTEST
| CS_SYNCPAINT
427 vError
= ::WinGetLastError(vHab
);
428 sError
= wxPMErrorToStr(vError
);
429 wxLogLastError(sError
);
433 } // end of wxApp::RegisterWindowClasses
436 // Cleans up any wxWindows internal structures left lying around
438 void wxApp::CleanUp()
447 // Flush the logged messages if any and install a 'safer' log target: the
448 // default one (wxLogGui) can't be used after the resources are freed just
449 // below and the user suppliedo ne might be even more unsafe (using any
450 // wxWindows GUI function is unsafe starting from now)
452 wxLog::DontCreateOnDemand();
455 // This will flush the old messages if any
457 delete wxLog::SetActiveTarget(new wxLogStderr
);
461 // One last chance for pending objects to be cleaned up
463 wxTheApp
->DeletePendingObjects();
465 wxModule::CleanUpModules();
467 wxDeleteStockObjects();
470 // Destroy all GDI lists, etc.
472 wxDeleteStockLists();
474 delete wxTheColourDatabase
;
475 wxTheColourDatabase
= NULL
;
477 wxBitmap::CleanUpHandlers();
483 // PM-SPECIFIC CLEANUP
486 // wxSetKeyboardHook(FALSE);
488 if (wxSTD_FRAME_ICON
)
489 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
490 if (wxSTD_MDICHILDFRAME_ICON
)
491 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
492 if (wxSTD_MDIPARENTFRAME_ICON
)
493 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
495 if (wxDEFAULT_FRAME_ICON
)
496 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
497 if (wxDEFAULT_MDICHILDFRAME_ICON
)
498 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
499 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
500 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
502 if ( wxDisableButtonBrush
)
504 // TODO: ::DeleteObject( wxDisableButtonBrush );
508 delete wxWinHandleList
;
510 delete wxPendingEvents
;
512 delete wxPendingEventsLocker
;
513 // If we don't do the following, we get an apparent memory leak.
514 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
517 wxClassInfo::CleanUpClasses();
519 // Delete Message queue
521 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
526 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
527 // At this point we want to check if there are any memory
528 // blocks that aren't part of the wxDebugContext itself,
529 // as a special case. Then when dumping we need to ignore
530 // wxDebugContext, too.
531 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
533 wxLogDebug(wxT("There were memory leaks."));
534 wxDebugContext::Dump();
535 wxDebugContext::PrintStatistics();
537 // wxDebugContext::SetStream(NULL, NULL);
541 // do it as the very last thing because everything else can log messages
542 delete wxLog::SetActiveTarget(NULL
);
544 } // end of wxApp::CleanUp
546 //----------------------------------------------------------------------
547 // Main wxWindows entry point
548 //----------------------------------------------------------------------
556 if (!wxApp::Initialize(vHab
))
560 // create the application object or ensure that one already exists
564 // The app may have declared a global application object, but we recommend
565 // the IMPLEMENT_APP macro is used instead, which sets an initializer
566 // function for delayed, dynamic app object construction.
567 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
568 wxT("No initializer - use IMPLEMENT_APP macro.") );
569 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
571 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
572 wxTheApp
->argc
= argc
;
575 wxTheApp
->argv
= new wxChar
*[argc
+1];
581 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
584 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
586 wxTheApp
->argv
= argv
;
589 wxString
sName(wxFileNameFromPath(argv
[0]));
591 wxStripExtension(sName
);
592 wxTheApp
->SetAppName(sName
);
596 if (!wxTheApp
->OnInitGui())
601 if (wxTheApp
->OnInit())
606 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
609 // Forcibly delete the window.
610 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
611 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
613 pTopWindow
->Close(TRUE
);
614 wxTheApp
->DeletePendingObjects();
619 wxTheApp
->SetTopWindow(NULL
);
623 else // app initialization failed
625 wxLogLastError(" Gui initialization failed, exitting");
627 #if wxUSE_CONSOLEDEBUG
628 printf("wxTheApp->OnExit ");
631 nRetValue
= wxTheApp
->OnExit();
632 #if wxUSE_CONSOLEDEBUG
633 printf("wxApp::CleanUp ");
637 #if wxUSE_CONSOLEDEBUG
638 printf("return %i ", nRetValue
);
644 bool wxApp::OnInitGui()
649 if (!wxAppBase::OnInitGui())
652 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
655 vError
= ::WinGetLastError(vHabmain
);
656 sError
= wxPMErrorToStr(vError
);
662 } // end of wxApp::OnInitGui
671 m_nPrintMode
= wxPRINT_WINDOWS
;
674 m_maxSocketHandles
= 0;
676 m_sockCallbackInfo
= 0;
677 } // end of wxApp::wxApp
682 // Delete command-line args
687 for (i
= 0; i
< argc
; i
++)
693 } // end of wxApp::~wxApp
695 bool wxApp::Initialized()
701 } // end of wxApp::Initialized
704 // Get and process a message, returning FALSE if WM_QUIT
705 // received (and also set the flag telling the app to exit the main loop)
708 bool wxApp::DoMessage()
710 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
715 m_bKeepGoing
= FALSE
;
720 // should never happen, but let's test for it nevertheless
721 wxLogLastError("GetMessage");
726 wxASSERT_MSG( wxThread::IsMain()
727 ,wxT("only the main thread can process Windows messages")
730 static bool sbHadGuiLock
= TRUE
;
731 static wxMsgArray svSavedMessages
;
734 // If a secondary thread owns is doing GUI calls, save all messages for
735 // later processing - we can't process them right now because it will
736 // lead to recursive library calls (and we're not reentrant)
738 if (!wxGuiOwnedByMainThread())
740 sbHadGuiLock
= FALSE
;
743 // Leave out WM_COMMAND messages: too dangerous, sometimes
744 // the message will be processed twice
746 if ( !wxIsWaitingForThread() ||
747 svCurrentMsg
.msg
!= WM_COMMAND
)
749 svSavedMessages
.Add(svCurrentMsg
);
756 // Have we just regained the GUI lock? if so, post all of the saved
763 size_t nCount
= svSavedMessages
.Count();
765 for (size_t n
= 0; n
< nCount
; n
++)
767 QMSG vMsg
= svSavedMessages
[n
];
769 DoMessage((WXMSG
*)&vMsg
);
771 svSavedMessages
.Empty();
774 #endif // wxUSE_THREADS
777 // Process the message
779 DoMessage((WXMSG
*)&svCurrentMsg
);
782 } // end of wxApp::DoMessage
784 void wxApp::DoMessage(
788 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
790 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
792 } // end of wxApp::DoMessage
794 //////////////////////////////////////////////////////////////////////////////
796 // Keep trying to process messages until WM_QUIT
799 // If there are messages to be processed, they will all be
800 // processed and OnIdle will not be called.
801 // When there are no more messages, OnIdle is called.
802 // If OnIdle requests more time,
803 // it will be repeatedly called so long as there are no pending messages.
804 // A 'feature' of this is that once OnIdle has decided that no more processing
805 // is required, then it won't get processing time until further messages
806 // are processed (it'll sit in DoMessage).
808 //////////////////////////////////////////////////////////////////////////////
809 int wxApp::MainLoop()
816 wxMutexGuiLeaveOrEnter();
817 #endif // wxUSE_THREADS
818 while (!Pending() && ProcessIdle())
830 return (int)svCurrentMsg
.mp1
;
831 } // end of wxApp::MainLoop
834 // Returns TRUE if more time is needed.
836 bool wxApp::ProcessIdle()
840 vEvent
.SetEventObject(this);
841 ProcessEvent(vEvent
);
842 return vEvent
.MoreRequested();
843 } // end of wxApp::ProcessIdle
845 void wxApp::ExitMainLoop()
847 ::WinPostMsg(NULL
, WM_QUIT
, 0, 0);
848 } // end of wxApp::ExitMainLoop
850 bool wxApp::Pending()
852 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
853 } // end of wxApp::Pending
855 void wxApp::Dispatch()
860 //////////////////////////////////////////////////////////////////////////////
862 // Give all windows a chance to preprocess
863 // the message. Some may have accelerator tables, or have
864 // MDI complications.
866 //////////////////////////////////////////////////////////////////////////////
867 bool wxApp::ProcessMessage(
871 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
872 HWND hWnd
= pMsg
->hwnd
;
873 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
877 // Pass non-system timer messages to the wxTimerProc
879 if (pMsg
->msg
== WM_TIMER
&&
880 (SHORT1FROMMP(pMsg
->mp1
) != TID_CURSOR
&&
881 SHORT1FROMMP(pMsg
->mp1
) != TID_FLASHWINDOW
&&
882 SHORT1FROMMP(pMsg
->mp1
) != TID_SCROLL
&&
883 SHORT1FROMMP(pMsg
->mp1
) != 0x0000
885 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
888 // Allow the window to prevent certain messages from being
889 // translated/processed (this is currently used by wxTextCtrl to always
890 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
892 if (pWndThis
&& !pWndThis
->OS2ShouldPreProcessMessage(pWxmsg
))
898 // For some composite controls (like a combobox), wndThis might be NULL
899 // because the subcontrol is not a wxWindow, but only the control itself
900 // is - try to catch this case
902 while (hWnd
&& !pWndThis
)
904 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
905 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
909 // Try translations first; find the youngest window with
910 // a translation table. OS/2 has case sensative accels, so
911 // this block, coded by BK, removes that and helps make them
914 if(pMsg
->msg
== WM_CHAR
)
916 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
917 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
921 // Do not process keyup events
923 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
925 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
926 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
929 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
931 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
935 if(!bRc
) // untranslated, should restore original value
936 CHARMSG(pChmsg
)->chr
= uSch
;
940 // Anyone for a non-translation message? Try youngest descendants first.
942 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
944 // if (pWnd->OS2ProcessMessage(pWxmsg))
948 } // end of wxApp::ProcessMessage
950 bool gbInOnIdle
= FALSE
;
958 // Avoid recursion (via ProcessEvent default case)
966 // If there are pending events, we must process them: pending events
967 // are either events to the threads other than main or events posted
968 // with wxPostEvent() functions
970 ProcessPendingEvents();
973 // 'Garbage' collection of windows deleted with Close().
975 DeletePendingObjects();
979 // Flush the logged messages if any
981 wxLog::FlushActive();
984 #if wxUSE_DC_CACHEING
985 // automated DC cache management: clear the cached DCs and bitmap
986 // if it's likely that the app has finished with them, that is, we
987 // get an idle event and we're not dragging anything.
988 if (!::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON1
) &&
989 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON3
) &&
990 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON2
))
992 #endif // wxUSE_DC_CACHEING
995 // Send OnIdle events to all windows
997 if (SendIdleEvents())
1000 // SendIdleEvents() returns TRUE if at least one window requested more
1003 rEvent
.RequestMore(TRUE
);
1006 } // end of wxApp::OnIdle
1008 // Send idle event to all top-level windows
1009 bool wxApp::SendIdleEvents()
1011 bool bNeedMore
= FALSE
;
1012 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1016 wxWindow
* pWin
= pNode
->GetData();
1018 if (SendIdleEvents(pWin
))
1020 pNode
= pNode
->GetNext();
1023 } // end of wxApp::SendIdleEvents
1026 // Send idle event to window and all subwindows
1028 bool wxApp::SendIdleEvents(
1032 bool bNeedMore
= FALSE
;
1035 vEvent
.SetEventObject(pWin
);
1036 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1038 if (vEvent
.MoreRequested())
1041 wxNode
* pNode
= pWin
->GetChildren().First();
1045 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1047 if (SendIdleEvents(pWin
))
1049 pNode
= pNode
->Next();
1052 } // end of wxApp::SendIdleEvents
1054 void wxApp::DeletePendingObjects()
1056 wxNode
* pNode
= wxPendingDelete
.First();
1060 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1064 if (wxPendingDelete
.Member(pObj
))
1068 // Deleting one object may have deleted other pending
1069 // objects, so start from beginning of list again.
1071 pNode
= wxPendingDelete
.First();
1073 } // end of wxApp::DeletePendingObjects
1075 void wxApp::OnEndSession(
1076 wxCloseEvent
& WXUNUSED(rEvent
))
1079 GetTopWindow()->Close(TRUE
);
1080 } // end of wxApp::OnEndSession
1083 // Default behaviour: close the application with prompts. The
1084 // user can veto the close, and therefore the end session.
1086 void wxApp::OnQueryEndSession(
1087 wxCloseEvent
& rEvent
1092 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1095 } // end of wxApp::OnQueryEndSession
1101 // VZ: must really exit somehow, insert appropriate OS/2 syscall (FIXME)
1102 wxAppConsole::Exit();
1106 // Yield to incoming messages
1108 bool wxApp::Yield(bool onlyIfNeeded
)
1110 static bool s_inYield
= FALSE
;
1114 if ( !onlyIfNeeded
)
1116 wxFAIL_MSG( _T("wxYield() called recursively") );
1126 // Disable log flushing from here because a call to wxYield() shouldn't
1127 // normally result in message boxes popping up &c
1134 // We want to go back to the main message loop
1135 // if we see a WM_QUIT. (?)
1137 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1140 wxMutexGuiLeaveOrEnter();
1141 #endif // wxUSE_THREADS
1142 if (!wxTheApp
->DoMessage())
1146 // If they are pending events, we must process them.
1149 wxTheApp
->ProcessPendingEvents();
1152 // Let the logs be flashed again
1159 int wxApp::AddSocketHandler(int handle
, int mask
,
1160 void (*callback
)(void*), void * gsock
)
1163 struct GsocketCallbackInfo
1164 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1166 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1167 if (CallbackInfo
[find
].handle
== -1)
1169 if (find
== m_maxSocketHandles
)
1171 // Allocate new memory
1172 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1173 (m_maxSocketHandles
+=10)*
1174 sizeof(struct GsocketCallbackInfo
));
1175 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1176 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1177 CallbackInfo
[find
].handle
= -1;
1178 find
= m_maxSocketHandles
- 10;
1180 CallbackInfo
[find
].proc
= callback
;
1181 CallbackInfo
[find
].type
= mask
;
1182 CallbackInfo
[find
].handle
= handle
;
1183 CallbackInfo
[find
].gsock
= gsock
;
1184 if (mask
& wxSockReadMask
)
1185 FD_SET(handle
, &m_readfds
);
1186 if (mask
& wxSockWriteMask
)
1187 FD_SET(handle
, &m_writefds
);
1188 if (handle
>= m_maxSocketNr
)
1189 m_maxSocketNr
= handle
+ 1;
1193 void wxApp::RemoveSocketHandler(int handle
)
1195 struct GsocketCallbackInfo
1196 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1197 if (handle
< m_maxSocketHandles
)
1199 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1200 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1201 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1202 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1203 CallbackInfo
[handle
].handle
= -1;
1207 //-----------------------------------------------------------------------------
1209 //-----------------------------------------------------------------------------
1211 void wxApp::WakeUpIdle()
1214 // Send the top window a dummy message so idle handler processing will
1215 // start up again. Doing it this way ensures that the idle handler
1216 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1217 // the same for the main app thread only)
1219 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1223 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1226 // Should never happen
1228 wxLogLastError("PostMessage(WM_NULL)");
1231 } // end of wxWakeUpIdle