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
);
425 if (!::WinRegisterClass( vHab
428 ,CS_HITTEST
| CS_SYNCPAINT
432 vError
= ::WinGetLastError(vHab
);
433 sError
= wxPMErrorToStr(vError
);
434 wxLogLastError(sError
);
438 } // end of wxApp::RegisterWindowClasses
441 // Cleans up any wxWindows internal structures left lying around
443 void wxApp::CleanUp()
452 // Flush the logged messages if any and install a 'safer' log target: the
453 // default one (wxLogGui) can't be used after the resources are freed just
454 // below and the user suppliedo ne might be even more unsafe (using any
455 // wxWindows GUI function is unsafe starting from now)
457 wxLog::DontCreateOnDemand();
460 // This will flush the old messages if any
462 delete wxLog::SetActiveTarget(new wxLogStderr
);
466 // One last chance for pending objects to be cleaned up
468 wxTheApp
->DeletePendingObjects();
470 wxModule::CleanUpModules();
472 #if wxUSE_WX_RESOURCES
473 wxCleanUpResourceSystem();
476 wxDeleteStockObjects();
479 // Destroy all GDI lists, etc.
481 wxDeleteStockLists();
483 delete wxTheColourDatabase
;
484 wxTheColourDatabase
= NULL
;
486 wxBitmap::CleanUpHandlers();
492 // PM-SPECIFIC CLEANUP
495 // wxSetKeyboardHook(FALSE);
497 if (wxSTD_FRAME_ICON
)
498 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
499 if (wxSTD_MDICHILDFRAME_ICON
)
500 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
501 if (wxSTD_MDIPARENTFRAME_ICON
)
502 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
504 if (wxDEFAULT_FRAME_ICON
)
505 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
506 if (wxDEFAULT_MDICHILDFRAME_ICON
)
507 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
508 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
509 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
511 if ( wxDisableButtonBrush
)
513 // TODO: ::DeleteObject( wxDisableButtonBrush );
517 delete wxWinHandleList
;
519 delete wxPendingEvents
;
521 delete wxPendingEventsLocker
;
522 // If we don't do the following, we get an apparent memory leak.
523 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
526 wxClassInfo::CleanUpClasses();
528 // Delete Message queue
530 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
535 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
536 // At this point we want to check if there are any memory
537 // blocks that aren't part of the wxDebugContext itself,
538 // as a special case. Then when dumping we need to ignore
539 // wxDebugContext, too.
540 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
542 wxLogDebug(wxT("There were memory leaks."));
543 wxDebugContext::Dump();
544 wxDebugContext::PrintStatistics();
546 // wxDebugContext::SetStream(NULL, NULL);
550 // do it as the very last thing because everything else can log messages
551 delete wxLog::SetActiveTarget(NULL
);
553 } // end of wxApp::CleanUp
555 //----------------------------------------------------------------------
556 // Main wxWindows entry point
557 //----------------------------------------------------------------------
565 if (!wxApp::Initialize(vHab
))
569 // create the application object or ensure that one already exists
573 // The app may have declared a global application object, but we recommend
574 // the IMPLEMENT_APP macro is used instead, which sets an initializer
575 // function for delayed, dynamic app object construction.
576 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
577 wxT("No initializer - use IMPLEMENT_APP macro.") );
578 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
580 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
581 wxTheApp
->argc
= argc
;
584 wxTheApp
->argv
= new wxChar
*[argc
+1];
590 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
593 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
595 wxTheApp
->argv
= argv
;
598 wxString
sName(wxFileNameFromPath(argv
[0]));
600 wxStripExtension(sName
);
601 wxTheApp
->SetAppName(sName
);
605 if (!wxTheApp
->OnInitGui())
610 if (wxTheApp
->OnInit())
612 nRetValue
= wxTheApp
->OnRun();
615 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
618 // Forcibly delete the window.
619 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
620 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
622 pTopWindow
->Close(TRUE
);
623 wxTheApp
->DeletePendingObjects();
628 wxTheApp
->SetTopWindow(NULL
);
632 else // app initialization failed
634 wxLogLastError(" Gui initialization failed, exitting");
636 #if wxUSE_CONSOLEDEBUG
637 printf("wxTheApp->OnExit ");
641 #if wxUSE_CONSOLEDEBUG
642 printf("wxApp::CleanUp ");
646 #if wxUSE_CONSOLEDEBUG
647 printf("return %i ", nRetValue
);
653 bool wxApp::OnInitGui()
658 if (!wxAppBase::OnInitGui())
661 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
664 vError
= ::WinGetLastError(vHabmain
);
665 sError
= wxPMErrorToStr(vError
);
671 } // end of wxApp::OnInitGui
674 // Static member initialization
676 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
685 m_nPrintMode
= wxPRINT_WINDOWS
;
686 m_exitOnFrameDelete
= TRUE
;
689 m_maxSocketHandles
= 0;
691 m_sockCallbackInfo
= 0;
692 } // end of wxApp::wxApp
697 // Delete command-line args
702 for (i
= 0; i
< argc
; i
++)
708 } // end of wxApp::~wxApp
710 bool wxApp::Initialized()
716 } // end of wxApp::Initialized
719 // Get and process a message, returning FALSE if WM_QUIT
720 // received (and also set the flag telling the app to exit the main loop)
723 bool wxApp::DoMessage()
725 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
730 m_bKeepGoing
= FALSE
;
735 // should never happen, but let's test for it nevertheless
736 wxLogLastError("GetMessage");
741 wxASSERT_MSG( wxThread::IsMain()
742 ,wxT("only the main thread can process Windows messages")
745 static bool sbHadGuiLock
= TRUE
;
746 static wxMsgArray svSavedMessages
;
749 // If a secondary thread owns is doing GUI calls, save all messages for
750 // later processing - we can't process them right now because it will
751 // lead to recursive library calls (and we're not reentrant)
753 if (!wxGuiOwnedByMainThread())
755 sbHadGuiLock
= FALSE
;
758 // Leave out WM_COMMAND messages: too dangerous, sometimes
759 // the message will be processed twice
761 if ( !wxIsWaitingForThread() ||
762 svCurrentMsg
.msg
!= WM_COMMAND
)
764 svSavedMessages
.Add(svCurrentMsg
);
771 // Have we just regained the GUI lock? if so, post all of the saved
778 size_t nCount
= svSavedMessages
.Count();
780 for (size_t n
= 0; n
< nCount
; n
++)
782 QMSG vMsg
= svSavedMessages
[n
];
784 DoMessage((WXMSG
*)&vMsg
);
786 svSavedMessages
.Empty();
789 #endif // wxUSE_THREADS
792 // Process the message
794 DoMessage((WXMSG
*)&svCurrentMsg
);
797 } // end of wxApp::DoMessage
799 void wxApp::DoMessage(
803 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
805 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
807 } // end of wxApp::DoMessage
809 //////////////////////////////////////////////////////////////////////////////
811 // Keep trying to process messages until WM_QUIT
814 // If there are messages to be processed, they will all be
815 // processed and OnIdle will not be called.
816 // When there are no more messages, OnIdle is called.
817 // If OnIdle requests more time,
818 // it will be repeatedly called so long as there are no pending messages.
819 // A 'feature' of this is that once OnIdle has decided that no more processing
820 // is required, then it won't get processing time until further messages
821 // are processed (it'll sit in DoMessage).
823 //////////////////////////////////////////////////////////////////////////////
824 int wxApp::MainLoop()
831 wxMutexGuiLeaveOrEnter();
832 #endif // wxUSE_THREADS
833 while (!Pending() && ProcessIdle())
845 return (int)svCurrentMsg
.mp1
;
846 } // end of wxApp::MainLoop
849 // Returns TRUE if more time is needed.
851 bool wxApp::ProcessIdle()
855 vEvent
.SetEventObject(this);
856 ProcessEvent(vEvent
);
857 return vEvent
.MoreRequested();
858 } // end of wxApp::ProcessIdle
860 void wxApp::ExitMainLoop()
862 m_bKeepGoing
= FALSE
;
865 bool wxApp::Pending()
867 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
870 void wxApp::Dispatch()
875 //////////////////////////////////////////////////////////////////////////////
877 // Give all windows a chance to preprocess
878 // the message. Some may have accelerator tables, or have
879 // MDI complications.
881 //////////////////////////////////////////////////////////////////////////////
882 bool wxApp::ProcessMessage(
886 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
887 HWND hWnd
= pMsg
->hwnd
;
888 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
892 // Pass non-system timer messages to the wxTimerProc
894 if (pMsg
->msg
== WM_TIMER
&&
895 (SHORT1FROMMP(pMsg
->mp1
) != TID_CURSOR
&&
896 SHORT1FROMMP(pMsg
->mp1
) != TID_FLASHWINDOW
&&
897 SHORT1FROMMP(pMsg
->mp1
) != TID_SCROLL
&&
898 SHORT1FROMMP(pMsg
->mp1
) != 0x0000
900 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
903 // Allow the window to prevent certain messages from being
904 // translated/processed (this is currently used by wxTextCtrl to always
905 // grab Ctrl-C/V/X, even if they are also accelerators in some parent)
907 if (pWndThis
&& !pWndThis
->OS2ShouldPreProcessMessage(pWxmsg
))
913 // For some composite controls (like a combobox), wndThis might be NULL
914 // because the subcontrol is not a wxWindow, but only the control itself
915 // is - try to catch this case
917 while (hWnd
&& !pWndThis
)
919 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
920 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
924 // Try translations first; find the youngest window with
925 // a translation table. OS/2 has case sensative accels, so
926 // this block, coded by BK, removes that and helps make them
929 if(pMsg
->msg
== WM_CHAR
)
931 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
932 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
936 // Do not process keyup events
938 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
940 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
941 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
944 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
946 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
950 if(!bRc
) // untranslated, should restore original value
951 CHARMSG(pChmsg
)->chr
= uSch
;
955 // Anyone for a non-translation message? Try youngest descendants first.
957 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
959 // if (pWnd->OS2ProcessMessage(pWxmsg))
963 } // end of wxApp::ProcessMessage
969 static bool sbInOnIdle
= FALSE
;
972 // Avoid recursion (via ProcessEvent default case)
980 // If there are pending events, we must process them: pending events
981 // are either events to the threads other than main or events posted
982 // with wxPostEvent() functions
984 ProcessPendingEvents();
987 // 'Garbage' collection of windows deleted with Close().
989 DeletePendingObjects();
993 // Flush the logged messages if any
995 wxLog::FlushActive();
998 #if wxUSE_DC_CACHEING
999 // automated DC cache management: clear the cached DCs and bitmap
1000 // if it's likely that the app has finished with them, that is, we
1001 // get an idle event and we're not dragging anything.
1002 if (!::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON1
) &&
1003 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON3
) &&
1004 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON2
))
1006 #endif // wxUSE_DC_CACHEING
1009 // Send OnIdle events to all windows
1011 if (SendIdleEvents())
1014 // SendIdleEvents() returns TRUE if at least one window requested more
1017 rEvent
.RequestMore(TRUE
);
1020 } // end of wxApp::OnIdle
1022 // Send idle event to all top-level windows
1023 bool wxApp::SendIdleEvents()
1025 bool bNeedMore
= FALSE
;
1026 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1030 wxWindow
* pWin
= pNode
->GetData();
1032 if (SendIdleEvents(pWin
))
1034 pNode
= pNode
->GetNext();
1037 } // end of wxApp::SendIdleEvents
1040 // Send idle event to window and all subwindows
1042 bool wxApp::SendIdleEvents(
1046 bool bNeedMore
= FALSE
;
1049 vEvent
.SetEventObject(pWin
);
1050 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1052 if (vEvent
.MoreRequested())
1055 wxNode
* pNode
= pWin
->GetChildren().First();
1059 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1061 if (SendIdleEvents(pWin
))
1063 pNode
= pNode
->Next();
1066 } // end of wxApp::SendIdleEvents
1068 void wxApp::DeletePendingObjects()
1070 wxNode
* pNode
= wxPendingDelete
.First();
1074 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1078 if (wxPendingDelete
.Member(pObj
))
1082 // Deleting one object may have deleted other pending
1083 // objects, so start from beginning of list again.
1085 pNode
= wxPendingDelete
.First();
1087 } // end of wxApp::DeletePendingObjects
1089 void wxApp::OnEndSession(
1090 wxCloseEvent
& WXUNUSED(rEvent
))
1093 GetTopWindow()->Close(TRUE
);
1094 } // end of wxApp::OnEndSession
1097 // Default behaviour: close the application with prompts. The
1098 // user can veto the close, and therefore the end session.
1100 void wxApp::OnQueryEndSession(
1101 wxCloseEvent
& rEvent
1106 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1109 } // end of wxApp::OnQueryEndSession
1113 wxLogError(_("Fatal error: exiting"));
1119 // Yield to incoming messages
1121 bool wxApp::Yield(bool onlyIfNeeded
)
1123 static bool s_inYield
= FALSE
;
1127 if ( !onlyIfNeeded
)
1129 wxFAIL_MSG( _T("wxYield() called recursively") );
1139 // Disable log flushing from here because a call to wxYield() shouldn't
1140 // normally result in message boxes popping up &c
1147 // We want to go back to the main message loop
1148 // if we see a WM_QUIT. (?)
1150 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1153 wxMutexGuiLeaveOrEnter();
1154 #endif // wxUSE_THREADS
1155 if (!wxTheApp
->DoMessage())
1159 // If they are pending events, we must process them.
1162 wxTheApp
->ProcessPendingEvents();
1165 // Let the logs be flashed again
1172 int wxApp::AddSocketHandler(int handle
, int mask
,
1173 void (*callback
)(void*), void * gsock
)
1176 struct GsocketCallbackInfo
1177 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1179 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1180 if (CallbackInfo
[find
].handle
== -1)
1182 if (find
== m_maxSocketHandles
)
1184 // Allocate new memory
1185 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1186 (m_maxSocketHandles
+=10)*
1187 sizeof(struct GsocketCallbackInfo
));
1188 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1189 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1190 CallbackInfo
[find
].handle
= -1;
1191 find
= m_maxSocketHandles
- 10;
1193 CallbackInfo
[find
].proc
= callback
;
1194 CallbackInfo
[find
].type
= mask
;
1195 CallbackInfo
[find
].handle
= handle
;
1196 CallbackInfo
[find
].gsock
= gsock
;
1197 if (mask
& wxSockReadMask
)
1198 FD_SET(handle
, &m_readfds
);
1199 if (mask
& wxSockWriteMask
)
1200 FD_SET(handle
, &m_writefds
);
1201 if (handle
>= m_maxSocketNr
)
1202 m_maxSocketNr
= handle
+ 1;
1206 void wxApp::RemoveSocketHandler(int handle
)
1208 struct GsocketCallbackInfo
1209 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1210 if (handle
< m_maxSocketHandles
)
1212 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1213 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1214 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1215 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1216 CallbackInfo
[handle
].handle
= -1;
1220 //-----------------------------------------------------------------------------
1222 //-----------------------------------------------------------------------------
1227 // Send the top window a dummy message so idle handler processing will
1228 // start up again. Doing it this way ensures that the idle handler
1229 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1230 // the same for the main app thread only)
1232 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1236 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1239 // Should never happen
1241 wxLogLastError("PostMessage(WM_NULL)");
1244 } // end of wxWakeUpIdle