1 /////////////////////////////////////////////////////////////////////////////
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/dynarray.h"
30 #include "wx/wxchar.h"
36 #include "wx/module.h"
38 #include "wx/os2/private.h"
42 #include <sys/ioctl.h>
43 #include <sys/select.h>
48 #include <sys/ioctl.h>
49 #include <sys/select.h>
56 #define select(a,b,c,d,e) bsdselect(a,b,c,d,e)
57 extern "C" int _System
bsdselect(int,
65 #include "wx/thread.h"
67 // define the array of QMSG strutures
68 WX_DECLARE_OBJARRAY(QMSG
, wxMsgArray
);
70 #include "wx/arrimpl.cpp"
72 WX_DEFINE_OBJARRAY(wxMsgArray
);
73 #endif // wxUSE_THREADS
75 #if wxUSE_WX_RESOURCES
76 #include "wx/resource.h"
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 #if wxUSE_WX_RESOURCES
271 wxInitializeResourceSystem();
274 wxBitmap::InitStandardHandlers();
277 // OS2 has to have an anchorblock
279 vHab
= WinInitialize(0);
286 // Some people may wish to use this, but
287 // probably it shouldn't be here by default.
289 // wxRedirectIOToConsole();
292 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
294 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
295 // PLEASE DO NOT ALTER THIS.
296 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
297 extern char wxDummyChar
;
298 if (wxDummyChar
) wxDummyChar
++;
301 // wxSetKeyboardHook(TRUE);
303 wxModule::RegisterModules();
304 if (!wxModule::InitializeModules())
306 RegisterWindowClasses(vHab
);
308 } // end of wxApp::Initialize
310 const char* CANTREGISTERCLASS
= " Can't register Class ";
311 // ---------------------------------------------------------------------------
312 // RegisterWindowClasses
313 // ---------------------------------------------------------------------------
315 bool wxApp::RegisterWindowClasses(
322 if (!::WinRegisterClass( vHab
325 ,CS_SIZEREDRAW
| CS_SYNCPAINT
329 vError
= ::WinGetLastError(vHab
);
330 sError
= wxPMErrorToStr(vError
);
331 wxLogLastError(sError
);
335 if (!::WinRegisterClass( vHab
336 ,wxFrameClassNameNoRedraw
342 vError
= ::WinGetLastError(vHab
);
343 sError
= wxPMErrorToStr(vError
);
344 wxLogLastError(sError
);
348 if (!::WinRegisterClass( vHab
351 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
355 vError
= ::WinGetLastError(vHab
);
356 sError
= wxPMErrorToStr(vError
);
357 wxLogLastError(sError
);
361 if (!::WinRegisterClass( vHab
362 ,wxMDIFrameClassNameNoRedraw
368 vError
= ::WinGetLastError(vHab
);
369 sError
= wxPMErrorToStr(vError
);
370 wxLogLastError(sError
);
374 if (!::WinRegisterClass( vHab
375 ,wxMDIChildFrameClassName
377 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
381 vError
= ::WinGetLastError(vHab
);
382 sError
= wxPMErrorToStr(vError
);
383 wxLogLastError(sError
);
387 if (!::WinRegisterClass( vHab
388 ,wxMDIChildFrameClassNameNoRedraw
394 vError
= ::WinGetLastError(vHab
);
395 sError
= wxPMErrorToStr(vError
);
396 wxLogLastError(sError
);
400 if (!::WinRegisterClass( vHab
403 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
407 vError
= ::WinGetLastError(vHab
);
408 sError
= wxPMErrorToStr(vError
);
409 wxLogLastError(sError
);
413 if (!::WinRegisterClass( vHab
416 ,CS_SIZEREDRAW
| CS_HITTEST
| CS_SYNCPAINT
420 vError
= ::WinGetLastError(vHab
);
421 sError
= wxPMErrorToStr(vError
);
422 wxLogLastError(sError
);
426 } // end of wxApp::RegisterWindowClasses
429 // Cleans up any wxWindows internal structures left lying around
431 void wxApp::CleanUp()
440 // Flush the logged messages if any and install a 'safer' log target: the
441 // default one (wxLogGui) can't be used after the resources are freed just
442 // below and the user suppliedo ne might be even more unsafe (using any
443 // wxWindows GUI function is unsafe starting from now)
445 wxLog::DontCreateOnDemand();
448 // This will flush the old messages if any
450 delete wxLog::SetActiveTarget(new wxLogStderr
);
454 // One last chance for pending objects to be cleaned up
456 wxTheApp
->DeletePendingObjects();
458 wxModule::CleanUpModules();
460 #if wxUSE_WX_RESOURCES
461 wxCleanUpResourceSystem();
464 wxDeleteStockObjects();
467 // Destroy all GDI lists, etc.
469 wxDeleteStockLists();
471 delete wxTheColourDatabase
;
472 wxTheColourDatabase
= NULL
;
474 wxBitmap::CleanUpHandlers();
480 // PM-SPECIFIC CLEANUP
483 // wxSetKeyboardHook(FALSE);
485 if (wxSTD_FRAME_ICON
)
486 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
487 if (wxSTD_MDICHILDFRAME_ICON
)
488 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
489 if (wxSTD_MDIPARENTFRAME_ICON
)
490 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
492 if (wxDEFAULT_FRAME_ICON
)
493 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
494 if (wxDEFAULT_MDICHILDFRAME_ICON
)
495 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
496 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
497 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
499 if ( wxDisableButtonBrush
)
501 // TODO: ::DeleteObject( wxDisableButtonBrush );
505 delete wxWinHandleList
;
507 delete wxPendingEvents
;
509 delete wxPendingEventsLocker
;
510 // If we don't do the following, we get an apparent memory leak.
511 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
514 wxClassInfo::CleanUpClasses();
516 // Delete Message queue
518 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
523 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
524 // At this point we want to check if there are any memory
525 // blocks that aren't part of the wxDebugContext itself,
526 // as a special case. Then when dumping we need to ignore
527 // wxDebugContext, too.
528 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
530 wxLogDebug(wxT("There were memory leaks."));
531 wxDebugContext::Dump();
532 wxDebugContext::PrintStatistics();
534 // wxDebugContext::SetStream(NULL, NULL);
538 // do it as the very last thing because everything else can log messages
539 delete wxLog::SetActiveTarget(NULL
);
541 } // end of wxApp::CleanUp
543 //----------------------------------------------------------------------
544 // Main wxWindows entry point
545 //----------------------------------------------------------------------
553 if (!wxApp::Initialize(vHab
))
557 // create the application object or ensure that one already exists
561 // The app may have declared a global application object, but we recommend
562 // the IMPLEMENT_APP macro is used instead, which sets an initializer
563 // function for delayed, dynamic app object construction.
564 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
565 wxT("No initializer - use IMPLEMENT_APP macro.") );
566 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
568 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
569 wxTheApp
->argc
= argc
;
572 wxTheApp
->argv
= new wxChar
*[argc
+1];
578 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
581 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
583 wxTheApp
->argv
= argv
;
586 wxString
sName(wxFileNameFromPath(argv
[0]));
588 wxStripExtension(sName
);
589 wxTheApp
->SetAppName(sName
);
593 if (!wxTheApp
->OnInitGui())
598 if (wxTheApp
->OnInit())
600 nRetValue
= wxTheApp
->OnRun();
603 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
606 // Forcibly delete the window.
607 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
608 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
610 pTopWindow
->Close(TRUE
);
611 wxTheApp
->DeletePendingObjects();
616 wxTheApp
->SetTopWindow(NULL
);
620 else // app initialization failed
622 wxLogLastError(" Gui initialization failed, exitting");
624 #if wxUSE_CONSOLEDEBUG
625 printf("wxTheApp->OnExit ");
629 #if wxUSE_CONSOLEDEBUG
630 printf("wxApp::CleanUp ");
634 #if wxUSE_CONSOLEDEBUG
635 printf("return %i ", nRetValue
);
641 bool wxApp::OnInitGui()
646 if (!wxAppBase::OnInitGui())
649 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
652 vError
= ::WinGetLastError(vHabmain
);
653 sError
= wxPMErrorToStr(vError
);
659 } // end of wxApp::OnInitGui
662 // Static member initialization
664 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
673 m_nPrintMode
= wxPRINT_WINDOWS
;
674 m_exitOnFrameDelete
= TRUE
;
677 m_maxSocketHandles
= 0;
679 m_sockCallbackInfo
= 0;
680 } // end of wxApp::wxApp
685 // Delete command-line args
690 for (i
= 0; i
< argc
; i
++)
696 } // end of wxApp::~wxApp
698 bool wxApp::Initialized()
704 } // end of wxApp::Initialized
707 // Get and process a message, returning FALSE if WM_QUIT
708 // received (and also set the flag telling the app to exit the main loop)
711 bool wxApp::DoMessage()
713 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
718 m_bKeepGoing
= FALSE
;
723 // should never happen, but let's test for it nevertheless
724 wxLogLastError("GetMessage");
729 wxASSERT_MSG( wxThread::IsMain()
730 ,wxT("only the main thread can process Windows messages")
733 static bool sbHadGuiLock
= TRUE
;
734 static wxMsgArray svSavedMessages
;
737 // If a secondary thread owns is doing GUI calls, save all messages for
738 // later processing - we can't process them right now because it will
739 // lead to recursive library calls (and we're not reentrant)
741 if (!wxGuiOwnedByMainThread())
743 sbHadGuiLock
= FALSE
;
746 // Leave out WM_COMMAND messages: too dangerous, sometimes
747 // the message will be processed twice
749 if ( !wxIsWaitingForThread() ||
750 svCurrentMsg
.msg
!= WM_COMMAND
)
752 svSavedMessages
.Add(svCurrentMsg
);
759 // Have we just regained the GUI lock? if so, post all of the saved
766 size_t nCount
= svSavedMessages
.Count();
768 for (size_t n
= 0; n
< nCount
; n
++)
770 QMSG vMsg
= svSavedMessages
[n
];
772 if ( !ProcessMessage((WXMSG
*)&vMsg
) )
774 ::WinDispatchMsg(vHabmain
, &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 m_bKeepGoing
= FALSE
;
856 bool wxApp::Pending()
858 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
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
);
884 // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
885 // popup the tooltip bubbles
887 if (pWndThis
&& (pMsg
->msg
== WM_MOUSEMOVE
))
889 wxToolTip
* pToolTip
= pWndThis
->GetToolTip();
892 pToolTip
->RelayEvent(pWxmsg
);
895 #endif // wxUSE_TOOLTIPS
898 // Pass non-system timer messages to the wxTimerProc
900 if (pMsg
->msg
== WM_TIMER
&&
901 (SHORT1FROMMP(pMsg
->mp1
) != TID_CURSOR
&&
902 SHORT1FROMMP(pMsg
->mp1
) != TID_FLASHWINDOW
&&
903 SHORT1FROMMP(pMsg
->mp1
) != TID_SCROLL
&&
904 SHORT1FROMMP(pMsg
->mp1
) != 0x0000
906 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
909 // Allow the window to prevent certain messages from being
910 // translated/processed (this is currently used by wxTextCtrl to always
911 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
913 if (pWndThis
&& !pWndThis
->OS2ShouldPreProcessMessage(pWxmsg
))
919 // For some composite controls (like a combobox), wndThis might be NULL
920 // because the subcontrol is not a wxWindow, but only the control itself
921 // is - try to catch this case
923 while (hWnd
&& !pWndThis
)
925 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
926 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
930 // Try translations first; find the youngest window with
931 // a translation table. OS/2 has case sensative accels, so
932 // this block, coded by BK, removes that and helps make them
935 if(pMsg
->msg
== WM_CHAR
)
937 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
938 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
942 // Do not process keyup events
944 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
946 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
947 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
950 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
952 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
956 if(!bRc
) // untranslated, should restore original value
957 CHARMSG(pChmsg
)->chr
= uSch
;
961 // Anyone for a non-translation message? Try youngest descendants first.
963 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
965 // if (pWnd->OS2ProcessMessage(pWxmsg))
969 } // end of wxApp::ProcessMessage
975 static bool sbInOnIdle
= FALSE
;
978 // Avoid recursion (via ProcessEvent default case)
986 // If there are pending events, we must process them: pending events
987 // are either events to the threads other than main or events posted
988 // with wxPostEvent() functions
990 ProcessPendingEvents();
993 // 'Garbage' collection of windows deleted with Close().
995 DeletePendingObjects();
999 // Flush the logged messages if any
1001 wxLog::FlushActive();
1004 #if wxUSE_DC_CACHEING
1005 // automated DC cache management: clear the cached DCs and bitmap
1006 // if it's likely that the app has finished with them, that is, we
1007 // get an idle event and we're not dragging anything.
1008 if (!::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON1
) &&
1009 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON3
) &&
1010 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON2
))
1012 #endif // wxUSE_DC_CACHEING
1015 // Send OnIdle events to all windows
1017 if (SendIdleEvents())
1020 // SendIdleEvents() returns TRUE if at least one window requested more
1023 rEvent
.RequestMore(TRUE
);
1026 } // end of wxApp::OnIdle
1028 // Send idle event to all top-level windows
1029 bool wxApp::SendIdleEvents()
1031 bool bNeedMore
= FALSE
;
1032 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1036 wxWindow
* pWin
= pNode
->GetData();
1038 if (SendIdleEvents(pWin
))
1040 pNode
= pNode
->GetNext();
1043 } // end of wxApp::SendIdleEvents
1046 // Send idle event to window and all subwindows
1048 bool wxApp::SendIdleEvents(
1052 bool bNeedMore
= FALSE
;
1055 vEvent
.SetEventObject(pWin
);
1056 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1058 if (vEvent
.MoreRequested())
1061 wxNode
* pNode
= pWin
->GetChildren().First();
1065 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1067 if (SendIdleEvents(pWin
))
1069 pNode
= pNode
->Next();
1072 } // end of wxApp::SendIdleEvents
1074 void wxApp::DeletePendingObjects()
1076 wxNode
* pNode
= wxPendingDelete
.First();
1080 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1084 if (wxPendingDelete
.Member(pObj
))
1088 // Deleting one object may have deleted other pending
1089 // objects, so start from beginning of list again.
1091 pNode
= wxPendingDelete
.First();
1093 } // end of wxApp::DeletePendingObjects
1095 void wxApp::OnEndSession(
1096 wxCloseEvent
& WXUNUSED(rEvent
))
1099 GetTopWindow()->Close(TRUE
);
1100 } // end of wxApp::OnEndSession
1103 // Default behaviour: close the application with prompts. The
1104 // user can veto the close, and therefore the end session.
1106 void wxApp::OnQueryEndSession(
1107 wxCloseEvent
& rEvent
1112 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1115 } // end of wxApp::OnQueryEndSession
1119 wxLogError(_("Fatal error: exiting"));
1125 // Yield to incoming messages
1127 bool wxApp::Yield(bool onlyIfNeeded
)
1129 static bool s_inYield
= FALSE
;
1133 if ( !onlyIfNeeded
)
1135 wxFAIL_MSG( _T("wxYield() called recursively") );
1145 // Disable log flushing from here because a call to wxYield() shouldn't
1146 // normally result in message boxes popping up &c
1153 // We want to go back to the main message loop
1154 // if we see a WM_QUIT. (?)
1156 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1159 wxMutexGuiLeaveOrEnter();
1160 #endif // wxUSE_THREADS
1161 if (!wxTheApp
->DoMessage())
1165 // If they are pending events, we must process them.
1168 wxTheApp
->ProcessPendingEvents();
1171 // Let the logs be flashed again
1178 wxIcon
wxApp::GetStdIcon(
1184 case wxICON_INFORMATION
:
1185 return wxIcon("wxICON_INFO");
1187 case wxICON_QUESTION
:
1188 return wxIcon("wxICON_QUESTION");
1190 case wxICON_EXCLAMATION
:
1191 return wxIcon("wxICON_WARNING");
1194 wxFAIL_MSG(wxT("requested non existent standard icon"));
1195 // still fall through
1198 return wxIcon("wxICON_ERROR");
1200 return wxIcon("wxICON_ERROR");
1201 } // end of wxApp::GetStdIcon
1203 int wxApp::AddSocketHandler(int handle
, int mask
,
1204 void (*callback
)(void*), void * gsock
)
1207 struct GsocketCallbackInfo
1208 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1210 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1211 if (CallbackInfo
[find
].handle
== -1)
1213 if (find
== m_maxSocketHandles
)
1215 // Allocate new memory
1216 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1217 (m_maxSocketHandles
+=10)*
1218 sizeof(struct GsocketCallbackInfo
));
1219 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1220 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1221 CallbackInfo
[find
].handle
= -1;
1222 find
= m_maxSocketHandles
- 10;
1224 CallbackInfo
[find
].proc
= callback
;
1225 CallbackInfo
[find
].type
= mask
;
1226 CallbackInfo
[find
].handle
= handle
;
1227 CallbackInfo
[find
].gsock
= gsock
;
1228 if (mask
& wxSockReadMask
)
1229 FD_SET(handle
, &m_readfds
);
1230 if (mask
& wxSockWriteMask
)
1231 FD_SET(handle
, &m_writefds
);
1232 if (handle
>= m_maxSocketNr
)
1233 m_maxSocketNr
= handle
+ 1;
1237 void wxApp::RemoveSocketHandler(int handle
)
1239 struct GsocketCallbackInfo
1240 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1241 if (handle
< m_maxSocketHandles
)
1243 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1244 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1245 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1246 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1247 CallbackInfo
[handle
].handle
= -1;
1251 //-----------------------------------------------------------------------------
1253 //-----------------------------------------------------------------------------
1258 // Send the top window a dummy message so idle handler processing will
1259 // start up again. Doing it this way ensures that the idle handler
1260 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1261 // the same for the main app thread only)
1263 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1267 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1270 // Should never happen
1272 wxLogLastError("PostMessage(WM_NULL)");
1275 } // end of wxWakeUpIdle