1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/appcmn.cpp
3 // Purpose: wxAppConsole and wxAppBase methods common to all platforms
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation "appbase.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
36 #include "wx/msgdlg.h"
39 #include "wx/apptrait.h"
41 #include "wx/fontmap.h"
42 #endif // wxUSE_FONTMAP
43 #include "wx/msgout.h"
44 #include "wx/thread.h"
47 // ============================================================================
48 // wxAppBase implementation
49 // ============================================================================
51 // ----------------------------------------------------------------------------
52 // initialization and termination
53 // ----------------------------------------------------------------------------
55 wxAppBase::wxAppBase()
57 m_topWindow
= (wxWindow
*)NULL
;
58 m_useBestVisual
= FALSE
;
61 // We don't want to exit the app if the user code shows a dialog from its
62 // OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
63 // to Yes initially as this dialog would be the last top level window.
64 // OTOH, if we set it to No initially we'll have to overwrite it with Yes
65 // when we enter our OnRun() because we do want the default behaviour from
66 // then on. But this would be a problem if the user code calls
67 // SetExitOnFrameDelete(FALSE) from OnInit().
69 // So we use the special "Later" value which is such that
70 // GetExitOnFrameDelete() returns FALSE for it but which we know we can
71 // safely (i.e. without losing the effect of the users SetExitOnFrameDelete
72 // call) overwrite in OnRun()
73 m_exitOnFrameDelete
= Later
;
76 wxAppBase::~wxAppBase()
78 // this destructor is required for Darwin
81 bool wxAppBase::OnInitGui()
83 #ifdef __WXUNIVERSAL__
84 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
86 #endif // __WXUNIVERSAL__
91 int wxAppBase::OnRun()
93 // see the comment in ctor: if the initial value hasn't been changed, use
94 // the default Yes from now on
95 if ( m_exitOnFrameDelete
== Later
)
97 m_exitOnFrameDelete
= Yes
;
99 //else: it has been changed, assume the user knows what he is doing
104 void wxAppBase::Exit()
109 wxAppTraits
*wxAppBase::CreateTraits()
111 return wxAppTraits::CreateGUI();
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 void wxAppBase::SetActive(bool active
, wxWindow
* WXUNUSED(lastFocus
))
120 if ( active
== m_isActive
)
125 wxActivateEvent
event(wxEVT_ACTIVATE_APP
, active
);
126 event
.SetEventObject(this);
128 (void)ProcessEvent(event
);
131 // ----------------------------------------------------------------------------
132 // wxGUIAppTraitsBase
133 // ----------------------------------------------------------------------------
137 wxLog
*wxGUIAppTraitsBase::CreateLogTarget()
144 wxMessageOutput
*wxGUIAppTraitsBase::CreateMessageOutput()
146 // The standard way of printing help on command line arguments (app --help)
147 // is (according to common practice):
148 // - console apps: to stderr (on any platform)
149 // - GUI apps: stderr on Unix platforms (!)
150 // message box under Windows and others
152 return new wxMessageOutputStderr
;
154 // wxMessageOutputMessageBox doesn't work under Motif
156 return new wxMessageOutputLog
;
158 return new wxMessageOutputMessageBox
;
160 #endif // __UNIX__/!__UNIX__
165 wxFontMapper
*wxGUIAppTraitsBase::CreateFontMapper()
167 return new wxFontMapper
;
170 #endif // wxUSE_FONTMAP
174 bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString
& msg
)
176 // under MSW we prefer to use the base class version using ::MessageBox()
177 // even if wxMessageBox() is available because it has less chances to
178 // double fault our app than our wxMessageBox()
179 #if defined(__WXMSW__) || !wxUSE_MSGDLG
180 return wxAppTraitsBase::ShowAssertDialog(msg
);
181 #else // wxUSE_MSGDLG
182 // this message is intentionally not translated -- it is for
184 wxString
msgDlg(msg
);
185 msgDlg
+= wxT("\nDo you want to stop the program?\n")
186 wxT("You can also choose [Cancel] to suppress ")
187 wxT("further warnings.");
189 switch ( wxMessageBox(msgDlg
, wxT("wxWindows Debug Alert"),
190 wxYES_NO
| wxCANCEL
| wxICON_STOP
) )
200 //case wxNO: nothing to do
204 #endif // !wxUSE_MSGDLG/wxUSE_MSGDLG
207 #endif // __WXDEBUG__
209 bool wxGUIAppTraitsBase::HasStderr()
211 // we consider that under Unix stderr always goes somewhere, even if the
212 // user doesn't always see it under GUI desktops
220 void wxGUIAppTraitsBase::ScheduleForDestroy(wxObject
*object
)
222 if ( !wxPendingDelete
.Member(object
) )
223 wxPendingDelete
.Append(object
);
226 void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject
*object
)
228 wxPendingDelete
.DeleteObject(object
);
231 // ----------------------------------------------------------------------------
233 // ----------------------------------------------------------------------------
235 wxAppTraits
*wxAppTraitsBase::CreateGUI()
237 return new wxGUIAppTraits
;