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__)
35 #include "wx/msgdlg.h"
38 #include "wx/apptrait.h"
40 #include "wx/fontmap.h"
41 #endif // wxUSE_FONTMAP
42 #include "wx/msgout.h"
43 #include "wx/thread.h"
46 // ============================================================================
47 // wxAppBase implementation
48 // ============================================================================
50 // ----------------------------------------------------------------------------
51 // initialization and termination
52 // ----------------------------------------------------------------------------
54 wxAppBase::wxAppBase()
56 m_topWindow
= (wxWindow
*)NULL
;
57 m_useBestVisual
= FALSE
;
60 // We don't want to exit the app if the user code shows a dialog from its
61 // OnInit() -- but this is what would happen if we set m_exitOnFrameDelete
62 // to Yes initially as this dialog would be the last top level window.
63 // OTOH, if we set it to No initially we'll have to overwrite it with Yes
64 // when we enter our OnRun() because we do want the default behaviour from
65 // then on. But this would be a problem if the user code calls
66 // SetExitOnFrameDelete(FALSE) from OnInit().
68 // So we use the special "Later" value which is such that
69 // GetExitOnFrameDelete() returns FALSE for it but which we know we can
70 // safely (i.e. without losing the effect of the users SetExitOnFrameDelete
71 // call) overwrite in OnRun()
72 m_exitOnFrameDelete
= Later
;
75 wxAppBase::~wxAppBase()
77 // this destructor is required for Darwin
80 bool wxAppBase::OnInitGui()
82 #ifdef __WXUNIVERSAL__
83 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
85 #endif // __WXUNIVERSAL__
90 int wxAppBase::OnRun()
92 // see the comment in ctor: if the initial value hasn't been changed, use
93 // the default Yes from now on
94 if ( m_exitOnFrameDelete
== Later
)
96 m_exitOnFrameDelete
= Yes
;
98 //else: it has been changed, assume the user knows what he is doing
103 void wxAppBase::Exit()
108 wxAppTraits
*wxAppBase::CreateTraits()
110 return wxAppTraits::CreateGUI();
113 // ----------------------------------------------------------------------------
115 // ----------------------------------------------------------------------------
117 void wxAppBase::SetActive(bool active
, wxWindow
* WXUNUSED(lastFocus
))
119 if ( active
== m_isActive
)
124 wxActivateEvent
event(wxEVT_ACTIVATE_APP
, active
);
125 event
.SetEventObject(this);
127 (void)ProcessEvent(event
);
130 // ----------------------------------------------------------------------------
131 // wxGUIAppTraitsBase
132 // ----------------------------------------------------------------------------
136 wxLog
*wxGUIAppTraitsBase::CreateLogTarget()
143 wxMessageOutput
*wxGUIAppTraitsBase::CreateMessageOutput()
145 // The standard way of printing help on command line arguments (app --help)
146 // is (according to common practice):
147 // - console apps: to stderr (on any platform)
148 // - GUI apps: stderr on Unix platforms (!)
149 // message box under Windows and others
151 return new wxMessageOutputStderr
;
153 // wxMessageOutputMessageBox doesn't work under Motif
155 return new wxMessageOutputLog
;
157 return new wxMessageOutputMessageBox
;
159 #endif // __UNIX__/!__UNIX__
164 wxFontMapper
*wxGUIAppTraitsBase::CreateFontMapper()
166 return new wxFontMapper
;
169 #endif // wxUSE_FONTMAP
173 bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString
& msg
)
175 // under MSW we prefer to use the base class version using ::MessageBox()
176 // even if wxMessageBox() is available because it has less chances to
177 // double fault our app than our wxMessageBox()
178 #if defined(__WXMSW__) || !wxUSE_MSGDLG
179 return wxAppTraitsBase::ShowAssertDialog(msg
);
180 #else // wxUSE_MSGDLG
181 // this message is intentionally not translated -- it is for
183 wxString
msgDlg(msg
);
184 msgDlg
+= wxT("\nDo you want to stop the program?\n")
185 wxT("You can also choose [Cancel] to suppress ")
186 wxT("further warnings.");
188 switch ( wxMessageBox(msgDlg
, wxT("wxWindows Debug Alert"),
189 wxYES_NO
| wxCANCEL
| wxICON_STOP
) )
199 //case wxNO: nothing to do
203 #endif // !wxUSE_MSGDLG/wxUSE_MSGDLG
206 #endif // __WXDEBUG__
208 bool wxGUIAppTraitsBase::HasStderr()
210 // we consider that under Unix stderr always goes somewhere, even if the
211 // user doesn't always see it under GUI desktops
219 void wxGUIAppTraitsBase::ScheduleForDestroy(wxObject
*object
)
221 if ( !wxPendingDelete
.Member(object
) )
222 wxPendingDelete
.Append(object
);
225 void wxGUIAppTraitsBase::RemoveFromPendingDelete(wxObject
*object
)
227 wxPendingDelete
.DeleteObject(object
);
230 // ----------------------------------------------------------------------------
232 // ----------------------------------------------------------------------------
234 wxAppTraits
*wxAppTraitsBase::CreateGUI()
236 return new wxGUIAppTraits
;