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
;
99 // NB: all "NoRedraw" classes must have the same names as the "normal" classes
100 // with NR suffix - wxWindow::OS2Create() supposes this
101 wxChar wxFrameClassName
[] = wxT("wxFrameClass");
102 wxChar wxFrameClassNameNoRedraw
[] = wxT("wxFrameClassNR");
103 wxChar wxMDIFrameClassName
[] = wxT("wxMDIFrameClass");
104 wxChar wxMDIFrameClassNameNoRedraw
[] = wxT("wxMDIFrameClassNR");
105 wxChar wxMDIChildFrameClassName
[] = wxT("wxMDIChildFrameClass");
106 wxChar wxMDIChildFrameClassNameNoRedraw
[] = wxT("wxMDIChildFrameClassNR");
107 wxChar wxPanelClassName
[] = wxT("wxPanelClass");
108 wxChar wxCanvasClassName
[] = wxT("wxCanvasClass");
110 HICON wxSTD_FRAME_ICON
= (HICON
) NULL
;
111 HICON wxSTD_MDICHILDFRAME_ICON
= (HICON
) NULL
;
112 HICON wxSTD_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
114 HICON wxDEFAULT_FRAME_ICON
= (HICON
) NULL
;
115 HICON wxDEFAULT_MDICHILDFRAME_ICON
= (HICON
) NULL
;
116 HICON wxDEFAULT_MDIPARENTFRAME_ICON
= (HICON
) NULL
;
118 HBRUSH wxDisableButtonBrush
= (HBRUSH
) 0;
120 MRESULT EXPENTRY
wxWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
121 MRESULT EXPENTRY
wxFrameWndProc( HWND hWnd
,ULONG message
,MPARAM mp1
,MPARAM mp2
);
123 // ===========================================================================
125 // ===========================================================================
127 // ---------------------------------------------------------------------------
128 // helper struct and functions for socket handling
129 // ---------------------------------------------------------------------------
131 struct GsocketCallbackInfo
{
132 void (*proc
)(void *);
138 // These defines and wrapper functions are used here and in gsockpm.c
139 #define wxSockReadMask 0x01
140 #define wxSockWriteMask 0x02
144 int wxAppAddSocketHandler(int handle
, int mask
,
145 void (*callback
)(void*), void * gsock
)
147 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
150 void wxAppRemoveSocketHandler(int handle
)
152 wxTheApp
->RemoveSocketHandler(handle
);
155 // Linkage mode problems using callbacks with extern C in a .cpp module
156 int wxAppAddSocketHandler(int handle
, int mask
,
157 void (*callback
)(void*), void * gsock
)
159 return wxTheApp
->AddSocketHandler(handle
, mask
, callback
, gsock
);
161 void wxAppRemoveSocketHandler(int handle
)
163 wxTheApp
->RemoveSocketHandler(handle
);
167 void wxApp::HandleSockets()
169 bool pendingEvent
= FALSE
;
171 // Check whether it's time for Gsocket operation
172 if (m_maxSocketHandles
> 0 && m_maxSocketNr
> 0)
174 fd_set readfds
= m_readfds
;
175 fd_set writefds
= m_writefds
;
176 struct timeval timeout
;
178 struct GsocketCallbackInfo
179 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
183 if ( select(m_maxSocketNr
, &readfds
, &writefds
, 0, &timeout
) > 0)
185 for (i
= m_lastUsedHandle
+ 1; i
!= m_lastUsedHandle
; i
++)
187 if (i
== m_maxSocketNr
)
189 if (FD_ISSET(i
, &readfds
))
192 for (r
= 0; r
< m_maxSocketHandles
; r
++){
193 if(CallbackInfo
[r
].handle
== i
&&
194 CallbackInfo
[r
].type
== wxSockReadMask
)
197 if (r
< m_maxSocketHandles
)
199 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
204 if (FD_ISSET(i
, &writefds
))
207 for (r
= 0; r
< m_maxSocketHandles
; r
++)
208 if(CallbackInfo
[r
].handle
== i
&&
209 CallbackInfo
[r
].type
== wxSockWriteMask
)
211 if (r
< m_maxSocketHandles
)
213 CallbackInfo
[r
].proc(CallbackInfo
[r
].gsock
);
219 m_lastUsedHandle
= i
;
225 // ---------------------------------------------------------------------------
227 // ---------------------------------------------------------------------------
229 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
231 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
232 EVT_IDLE(wxApp::OnIdle
)
233 EVT_END_SESSION(wxApp::OnEndSession
)
234 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
240 bool wxApp::Initialize(
244 #if defined(wxUSE_CONSOLEDEBUG)
245 #if wxUSE_CONSOLEDEBUG
246 /***********************************************/
247 /* Code for using stdout debug */
248 /* To use it you mast link app as "Window" - EK*/
249 /***********************************************/
254 printf("In console\n");
256 DosGetInfoBlocks(&tib
, &pib
);
257 /* Try morphing into a PM application. */
258 // if(pib->pib_ultype == 2) /* VIO */
261 /**********************************************/
262 /**********************************************/
263 #endif //wxUSE_CONSOLEDEBUG
267 // OS2 has to have an anchorblock
269 vHab
= WinInitialize(0);
276 // Some people may wish to use this, but
277 // probably it shouldn't be here by default.
279 // wxRedirectIOToConsole();
282 wxBuffer
= new wxChar
[1500]; // FIXME; why?
284 wxClassInfo::InitializeClasses();
287 wxPendingEventsLocker
= new wxCriticalSection
;
290 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
291 wxTheColourDatabase
->Initialize();
293 wxInitializeStockLists();
294 wxInitializeStockObjects();
296 #if wxUSE_WX_RESOURCES
297 wxInitializeResourceSystem();
300 wxBitmap::InitStandardHandlers();
302 RegisterWindowClasses(vHab
);
303 wxWinHandleList
= new wxList(wxKEY_INTEGER
);
305 // This is to foil optimizations in Visual C++ that throw out dummy.obj.
306 // PLEASE DO NOT ALTER THIS.
307 #if !defined(WXMAKINGDLL) && defined(__VISAGECPP__)
308 extern char wxDummyChar
;
309 if (wxDummyChar
) wxDummyChar
++;
312 // wxSetKeyboardHook(TRUE);
314 wxModule::RegisterModules();
315 if (!wxModule::InitializeModules())
318 } // end of wxApp::Initialize
320 const char* CANTREGISTERCLASS
= " Can't register Class ";
321 // ---------------------------------------------------------------------------
322 // RegisterWindowClasses
323 // ---------------------------------------------------------------------------
325 bool wxApp::RegisterWindowClasses(
332 if (!::WinRegisterClass( vHab
335 ,CS_SIZEREDRAW
| CS_SYNCPAINT
339 vError
= ::WinGetLastError(vHab
);
340 sError
= wxPMErrorToStr(vError
);
341 wxLogLastError(sError
);
345 if (!::WinRegisterClass( vHab
346 ,wxFrameClassNameNoRedraw
352 vError
= ::WinGetLastError(vHab
);
353 sError
= wxPMErrorToStr(vError
);
354 wxLogLastError(sError
);
358 if (!::WinRegisterClass( vHab
361 ,CS_SIZEREDRAW
| CS_MOVENOTIFY
| CS_SYNCPAINT
365 vError
= ::WinGetLastError(vHab
);
366 sError
= wxPMErrorToStr(vError
);
367 wxLogLastError(sError
);
371 if (!::WinRegisterClass( vHab
372 ,wxMDIFrameClassNameNoRedraw
378 vError
= ::WinGetLastError(vHab
);
379 sError
= wxPMErrorToStr(vError
);
380 wxLogLastError(sError
);
384 if (!::WinRegisterClass( vHab
385 ,wxMDIChildFrameClassName
387 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_SYNCPAINT
| CS_HITTEST
391 vError
= ::WinGetLastError(vHab
);
392 sError
= wxPMErrorToStr(vError
);
393 wxLogLastError(sError
);
397 if (!::WinRegisterClass( vHab
398 ,wxMDIChildFrameClassNameNoRedraw
404 vError
= ::WinGetLastError(vHab
);
405 sError
= wxPMErrorToStr(vError
);
406 wxLogLastError(sError
);
410 if (!::WinRegisterClass( vHab
413 ,CS_MOVENOTIFY
| CS_SIZEREDRAW
| CS_HITTEST
| CS_SAVEBITS
| CS_SYNCPAINT
417 vError
= ::WinGetLastError(vHab
);
418 sError
= wxPMErrorToStr(vError
);
419 wxLogLastError(sError
);
423 if (!::WinRegisterClass( vHab
426 ,CS_SIZEREDRAW
| CS_HITTEST
| CS_SYNCPAINT
| CS_CLIPCHILDREN
430 vError
= ::WinGetLastError(vHab
);
431 sError
= wxPMErrorToStr(vError
);
432 wxLogLastError(sError
);
436 } // end of wxApp::RegisterWindowClasses
439 // Cleans up any wxWindows internal structures left lying around
441 void wxApp::CleanUp()
450 // Flush the logged messages if any and install a 'safer' log target: the
451 // default one (wxLogGui) can't be used after the resources are freed just
452 // below and the user suppliedo ne might be even more unsafe (using any
453 // wxWindows GUI function is unsafe starting from now)
455 wxLog::DontCreateOnDemand();
458 // This will flush the old messages if any
460 delete wxLog::SetActiveTarget(new wxLogStderr
);
464 // One last chance for pending objects to be cleaned up
466 wxTheApp
->DeletePendingObjects();
468 wxModule::CleanUpModules();
470 #if wxUSE_WX_RESOURCES
471 wxCleanUpResourceSystem();
474 wxDeleteStockObjects();
477 // Destroy all GDI lists, etc.
479 wxDeleteStockLists();
481 delete wxTheColourDatabase
;
482 wxTheColourDatabase
= NULL
;
484 wxBitmap::CleanUpHandlers();
490 // PM-SPECIFIC CLEANUP
493 // wxSetKeyboardHook(FALSE);
495 if (wxSTD_FRAME_ICON
)
496 ::WinFreeFileIcon(wxSTD_FRAME_ICON
);
497 if (wxSTD_MDICHILDFRAME_ICON
)
498 ::WinFreeFileIcon(wxSTD_MDICHILDFRAME_ICON
);
499 if (wxSTD_MDIPARENTFRAME_ICON
)
500 ::WinFreeFileIcon(wxSTD_MDIPARENTFRAME_ICON
);
502 if (wxDEFAULT_FRAME_ICON
)
503 ::WinFreeFileIcon(wxDEFAULT_FRAME_ICON
);
504 if (wxDEFAULT_MDICHILDFRAME_ICON
)
505 ::WinFreeFileIcon(wxDEFAULT_MDICHILDFRAME_ICON
);
506 if (wxDEFAULT_MDIPARENTFRAME_ICON
)
507 ::WinFreeFileIcon(wxDEFAULT_MDIPARENTFRAME_ICON
);
509 if ( wxDisableButtonBrush
)
511 // TODO: ::DeleteObject( wxDisableButtonBrush );
515 delete wxWinHandleList
;
517 delete wxPendingEvents
;
519 delete wxPendingEventsLocker
;
520 // If we don't do the following, we get an apparent memory leak.
521 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
524 wxClassInfo::CleanUpClasses();
526 // Delete Message queue
528 ::WinDestroyMsgQueue(wxTheApp
->m_hMq
);
533 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
534 // At this point we want to check if there are any memory
535 // blocks that aren't part of the wxDebugContext itself,
536 // as a special case. Then when dumping we need to ignore
537 // wxDebugContext, too.
538 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
540 wxLogDebug(wxT("There were memory leaks."));
541 wxDebugContext::Dump();
542 wxDebugContext::PrintStatistics();
544 // wxDebugContext::SetStream(NULL, NULL);
548 // do it as the very last thing because everything else can log messages
549 delete wxLog::SetActiveTarget(NULL
);
551 } // end of wxApp::CleanUp
553 //----------------------------------------------------------------------
554 // Main wxWindows entry point
555 //----------------------------------------------------------------------
563 if (!wxApp::Initialize(vHab
))
567 // create the application object or ensure that one already exists
571 // The app may have declared a global application object, but we recommend
572 // the IMPLEMENT_APP macro is used instead, which sets an initializer
573 // function for delayed, dynamic app object construction.
574 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
575 wxT("No initializer - use IMPLEMENT_APP macro.") );
576 wxTheApp
= (*wxApp::GetInitializerFunction()) ();
578 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
579 wxTheApp
->argc
= argc
;
582 wxTheApp
->argv
= new wxChar
*[argc
+1];
588 wxTheApp
->argv
[nArgc
] = wxStrdup(wxConvLibc
.cMB2WX(argv
[nArgc
]));
591 wxTheApp
->argv
[nArgc
] = (wxChar
*)NULL
;
593 wxTheApp
->argv
= argv
;
596 wxString
sName(wxFileNameFromPath(argv
[0]));
598 wxStripExtension(sName
);
599 wxTheApp
->SetAppName(sName
);
603 if (!wxTheApp
->OnInitGui())
608 if (wxTheApp
->OnInit())
610 nRetValue
= wxTheApp
->OnRun();
613 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
616 // Forcibly delete the window.
617 if (pTopWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
618 pTopWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
620 pTopWindow
->Close(TRUE
);
621 wxTheApp
->DeletePendingObjects();
626 wxTheApp
->SetTopWindow(NULL
);
630 else // app initialization failed
632 wxLogLastError(" Gui initialization failed, exitting");
634 #if wxUSE_CONSOLEDEBUG
635 printf("wxTheApp->OnExit ");
639 #if wxUSE_CONSOLEDEBUG
640 printf("wxApp::CleanUp ");
644 #if wxUSE_CONSOLEDEBUG
645 printf("return %i ", nRetValue
);
651 bool wxApp::OnInitGui()
656 if (!wxAppBase::OnInitGui())
659 m_hMq
= ::WinCreateMsgQueue(vHabmain
, 0);
662 vError
= ::WinGetLastError(vHabmain
);
663 sError
= wxPMErrorToStr(vError
);
669 } // end of wxApp::OnInitGui
672 // Static member initialization
674 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
680 m_wantDebugOutput
= TRUE
;
684 m_nPrintMode
= wxPRINT_WINDOWS
;
685 m_exitOnFrameDelete
= TRUE
;
688 m_maxSocketHandles
= 0;
690 m_sockCallbackInfo
= 0;
691 } // end of wxApp::wxApp
696 // Delete command-line args
701 for (i
= 0; i
< argc
; i
++)
707 } // end of wxApp::~wxApp
709 bool wxApp::Initialized()
715 } // end of wxApp::Initialized
718 // Get and process a message, returning FALSE if WM_QUIT
719 // received (and also set the flag telling the app to exit the main loop)
722 bool wxApp::DoMessage()
724 BOOL bRc
= ::WinGetMsg(vHabmain
, &svCurrentMsg
, HWND(NULL
), 0, 0);
729 m_bKeepGoing
= FALSE
;
734 // should never happen, but let's test for it nevertheless
735 wxLogLastError("GetMessage");
740 wxASSERT_MSG( wxThread::IsMain()
741 ,wxT("only the main thread can process Windows messages")
744 static bool sbHadGuiLock
= TRUE
;
745 static wxMsgArray svSavedMessages
;
748 // If a secondary thread owns is doing GUI calls, save all messages for
749 // later processing - we can't process them right now because it will
750 // lead to recursive library calls (and we're not reentrant)
752 if (!wxGuiOwnedByMainThread())
754 sbHadGuiLock
= FALSE
;
757 // Leave out WM_COMMAND messages: too dangerous, sometimes
758 // the message will be processed twice
760 if ( !wxIsWaitingForThread() ||
761 svCurrentMsg
.msg
!= WM_COMMAND
)
763 svSavedMessages
.Add(svCurrentMsg
);
770 // Have we just regained the GUI lock? if so, post all of the saved
777 size_t nCount
= svSavedMessages
.Count();
779 for (size_t n
= 0; n
< nCount
; n
++)
781 QMSG vMsg
= svSavedMessages
[n
];
783 if ( !ProcessMessage((WXMSG
*)&vMsg
) )
785 ::WinDispatchMsg(vHabmain
, &vMsg
);
788 svSavedMessages
.Empty();
791 #endif // wxUSE_THREADS
794 // Process the message
796 DoMessage((WXMSG
*)&svCurrentMsg
);
799 } // end of wxApp::DoMessage
801 void wxApp::DoMessage(
805 if (!ProcessMessage((WXMSG
*)&svCurrentMsg
))
807 ::WinDispatchMsg(vHabmain
, (PQMSG
)&svCurrentMsg
);
809 } // end of wxApp::DoMessage
811 //////////////////////////////////////////////////////////////////////////////
813 // Keep trying to process messages until WM_QUIT
816 // If there are messages to be processed, they will all be
817 // processed and OnIdle will not be called.
818 // When there are no more messages, OnIdle is called.
819 // If OnIdle requests more time,
820 // it will be repeatedly called so long as there are no pending messages.
821 // A 'feature' of this is that once OnIdle has decided that no more processing
822 // is required, then it won't get processing time until further messages
823 // are processed (it'll sit in DoMessage).
825 //////////////////////////////////////////////////////////////////////////////
826 int wxApp::MainLoop()
833 wxMutexGuiLeaveOrEnter();
834 #endif // wxUSE_THREADS
835 while (!Pending() && ProcessIdle())
847 return (int)svCurrentMsg
.mp1
;
848 } // end of wxApp::MainLoop
851 // Returns TRUE if more time is needed.
853 bool wxApp::ProcessIdle()
857 vEvent
.SetEventObject(this);
858 ProcessEvent(vEvent
);
859 return vEvent
.MoreRequested();
860 } // end of wxApp::ProcessIdle
862 void wxApp::ExitMainLoop()
864 m_bKeepGoing
= FALSE
;
867 bool wxApp::Pending()
869 return (::WinPeekMsg(vHabmain
, (PQMSG
)&svCurrentMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) != 0);
872 void wxApp::Dispatch()
877 //////////////////////////////////////////////////////////////////////////////
879 // Give all windows a chance to preprocess
880 // the message. Some may have accelerator tables, or have
881 // MDI complications.
883 //////////////////////////////////////////////////////////////////////////////
884 bool wxApp::ProcessMessage(
888 QMSG
* pMsg
= (PQMSG
)pWxmsg
;
889 HWND hWnd
= pMsg
->hwnd
;
890 wxWindow
* pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
895 // We must relay WM_MOUSEMOVE events to the tooltip ctrl if we want it to
896 // popup the tooltip bubbles
898 if (pWndThis
&& (pMsg
->msg
== WM_MOUSEMOVE
))
900 wxToolTip
* pToolTip
= pWndThis
->GetToolTip();
903 pToolTip
->RelayEvent(pWxmsg
);
906 #endif // wxUSE_TOOLTIPS
909 // We must relay Timer events to wxTimer's processing function
911 if (pMsg
->msg
== WM_TIMER
)
912 wxTimerProc(NULL
, 0, (int)pMsg
->mp1
, 0);
915 // For some composite controls (like a combobox), wndThis might be NULL
916 // because the subcontrol is not a wxWindow, but only the control itself
917 // is - try to catch this case
919 while (hWnd
&& !pWndThis
)
921 hWnd
= ::WinQueryWindow(hWnd
, QW_PARENT
);
922 pWndThis
= wxFindWinFromHandle((WXHWND
)hWnd
);
926 // Try translations first; find the youngest window with
927 // a translation table. OS/2 has case sensative accels, so
928 // this block, coded by BK, removes that and helps make them
931 if(pMsg
->msg
== WM_CHAR
)
933 PBYTE pChmsg
= (PBYTE
)&(pMsg
->msg
);
934 USHORT uSch
= CHARMSG(pChmsg
)->chr
;
938 // Do not process keyup events
940 if(!(CHARMSG(pChmsg
)->fs
& KC_KEYUP
))
942 if((CHARMSG(pChmsg
)->fs
& (KC_ALT
| KC_CTRL
)) && CHARMSG(pChmsg
)->chr
!= 0)
943 CHARMSG(pChmsg
)->chr
= (USHORT
)wxToupper((UCHAR
)uSch
);
946 for(pWnd
= pWndThis
; pWnd
; pWnd
= pWnd
->GetParent() )
948 if((bRc
= pWnd
->OS2TranslateMessage(pWxmsg
)) == TRUE
)
952 if(!bRc
) // untranslated, should restore original value
953 CHARMSG(pChmsg
)->chr
= uSch
;
957 // Anyone for a non-translation message? Try youngest descendants first.
959 // for (pWnd = pWndThis; pWnd; pWnd = pWnd->GetParent())
961 // if (pWnd->OS2ProcessMessage(pWxmsg))
965 } // end of wxApp::ProcessMessage
971 static bool sbInOnIdle
= FALSE
;
974 // Avoid recursion (via ProcessEvent default case)
982 // If there are pending events, we must process them: pending events
983 // are either events to the threads other than main or events posted
984 // with wxPostEvent() functions
986 ProcessPendingEvents();
989 // 'Garbage' collection of windows deleted with Close().
991 DeletePendingObjects();
995 // Flush the logged messages if any
997 wxLog::FlushActive();
1000 #if wxUSE_DC_CACHEING
1001 // automated DC cache management: clear the cached DCs and bitmap
1002 // if it's likely that the app has finished with them, that is, we
1003 // get an idle event and we're not dragging anything.
1004 if (!::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON1
) &&
1005 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON3
) &&
1006 !::WinGetKeyState(HWND_DESKTOP
, VK_BUTTON2
))
1008 #endif // wxUSE_DC_CACHEING
1011 // Send OnIdle events to all windows
1013 if (SendIdleEvents())
1016 // SendIdleEvents() returns TRUE if at least one window requested more
1019 rEvent
.RequestMore(TRUE
);
1022 } // end of wxApp::OnIdle
1024 // Send idle event to all top-level windows
1025 bool wxApp::SendIdleEvents()
1027 bool bNeedMore
= FALSE
;
1028 wxWindowList::Node
* pNode
= wxTopLevelWindows
.GetFirst();
1032 wxWindow
* pWin
= pNode
->GetData();
1034 if (SendIdleEvents(pWin
))
1036 pNode
= pNode
->GetNext();
1039 } // end of wxApp::SendIdleEvents
1042 // Send idle event to window and all subwindows
1044 bool wxApp::SendIdleEvents(
1048 bool bNeedMore
= FALSE
;
1051 vEvent
.SetEventObject(pWin
);
1052 pWin
->GetEventHandler()->ProcessEvent(vEvent
);
1054 if (vEvent
.MoreRequested())
1057 wxNode
* pNode
= pWin
->GetChildren().First();
1061 wxWindow
* pWin
= (wxWindow
*) pNode
->Data();
1063 if (SendIdleEvents(pWin
))
1065 pNode
= pNode
->Next();
1068 } // end of wxApp::SendIdleEvents
1070 void wxApp::DeletePendingObjects()
1072 wxNode
* pNode
= wxPendingDelete
.First();
1076 wxObject
* pObj
= (wxObject
*)pNode
->Data();
1080 if (wxPendingDelete
.Member(pObj
))
1084 // Deleting one object may have deleted other pending
1085 // objects, so start from beginning of list again.
1087 pNode
= wxPendingDelete
.First();
1089 } // end of wxApp::DeletePendingObjects
1091 void wxApp::OnEndSession(
1092 wxCloseEvent
& WXUNUSED(rEvent
))
1095 GetTopWindow()->Close(TRUE
);
1096 } // end of wxApp::OnEndSession
1099 // Default behaviour: close the application with prompts. The
1100 // user can veto the close, and therefore the end session.
1102 void wxApp::OnQueryEndSession(
1103 wxCloseEvent
& rEvent
1108 if (!GetTopWindow()->Close(!rEvent
.CanVeto()))
1111 } // end of wxApp::OnQueryEndSession
1115 wxLogError(_("Fatal error: exiting"));
1121 // Yield to incoming messages
1123 bool wxApp::Yield(bool onlyIfNeeded
)
1125 static bool s_inYield
= FALSE
;
1129 if ( !onlyIfNeeded
)
1131 wxFAIL_MSG( _T("wxYield() called recursively") );
1141 // Disable log flushing from here because a call to wxYield() shouldn't
1142 // normally result in message boxes popping up &c
1149 // We want to go back to the main message loop
1150 // if we see a WM_QUIT. (?)
1152 while (::WinPeekMsg(vHab
, &vMsg
, (HWND
)NULL
, 0, 0, PM_NOREMOVE
) && vMsg
.msg
!= WM_QUIT
)
1155 wxMutexGuiLeaveOrEnter();
1156 #endif // wxUSE_THREADS
1157 if (!wxTheApp
->DoMessage())
1161 // If they are pending events, we must process them.
1164 wxTheApp
->ProcessPendingEvents();
1167 // Let the logs be flashed again
1174 wxIcon
wxApp::GetStdIcon(
1180 case wxICON_INFORMATION
:
1181 return wxIcon("wxICON_INFO");
1183 case wxICON_QUESTION
:
1184 return wxIcon("wxICON_QUESTION");
1186 case wxICON_EXCLAMATION
:
1187 return wxIcon("wxICON_WARNING");
1190 wxFAIL_MSG(wxT("requested non existent standard icon"));
1191 // still fall through
1194 return wxIcon("wxICON_ERROR");
1196 return wxIcon("wxICON_ERROR");
1197 } // end of wxApp::GetStdIcon
1199 int wxApp::AddSocketHandler(int handle
, int mask
,
1200 void (*callback
)(void*), void * gsock
)
1203 struct GsocketCallbackInfo
1204 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1206 for (find
= 0; find
< m_maxSocketHandles
; find
++)
1207 if (CallbackInfo
[find
].handle
== -1)
1209 if (find
== m_maxSocketHandles
)
1211 // Allocate new memory
1212 m_sockCallbackInfo
= realloc(m_sockCallbackInfo
,
1213 (m_maxSocketHandles
+=10)*
1214 sizeof(struct GsocketCallbackInfo
));
1215 CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1216 for (find
= m_maxSocketHandles
- 10; find
< m_maxSocketHandles
; find
++)
1217 CallbackInfo
[find
].handle
= -1;
1218 find
= m_maxSocketHandles
- 10;
1220 CallbackInfo
[find
].proc
= callback
;
1221 CallbackInfo
[find
].type
= mask
;
1222 CallbackInfo
[find
].handle
= handle
;
1223 CallbackInfo
[find
].gsock
= gsock
;
1224 if (mask
& wxSockReadMask
)
1225 FD_SET(handle
, &m_readfds
);
1226 if (mask
& wxSockWriteMask
)
1227 FD_SET(handle
, &m_writefds
);
1228 if (handle
>= m_maxSocketNr
)
1229 m_maxSocketNr
= handle
+ 1;
1233 void wxApp::RemoveSocketHandler(int handle
)
1235 struct GsocketCallbackInfo
1236 *CallbackInfo
= (struct GsocketCallbackInfo
*)m_sockCallbackInfo
;
1237 if (handle
< m_maxSocketHandles
)
1239 if (CallbackInfo
[handle
].type
& wxSockReadMask
)
1240 FD_CLR(CallbackInfo
[handle
].handle
, &m_readfds
);
1241 if (CallbackInfo
[handle
].type
& wxSockWriteMask
)
1242 FD_CLR(CallbackInfo
[handle
].handle
, &m_writefds
);
1243 CallbackInfo
[handle
].handle
= -1;
1247 //-----------------------------------------------------------------------------
1249 //-----------------------------------------------------------------------------
1254 // Send the top window a dummy message so idle handler processing will
1255 // start up again. Doing it this way ensures that the idle handler
1256 // wakes up in the right thread (see also wxWakeUpMainThread() which does
1257 // the same for the main app thread only)
1259 wxWindow
* pTopWindow
= wxTheApp
->GetTopWindow();
1263 if ( !::WinPostMsg(GetHwndOf(pTopWindow
), WM_NULL
, (MPARAM
)0, (MPARAM
)0))
1266 // Should never happen
1268 wxLogLastError("PostMessage(WM_NULL)");
1271 } // end of wxWakeUpIdle