1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/appcmn.cpp
3 // Purpose: 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__)
37 #include "wx/cmdline.h"
38 #include "wx/thread.h"
39 #include "wx/confbase.h"
41 // ===========================================================================
43 // ===========================================================================
45 // ----------------------------------------------------------------------------
46 // initialization and termination
47 // ----------------------------------------------------------------------------
49 wxAppBase::wxAppBase()
51 wxTheApp
= (wxApp
*)this;
53 // VZ: what's this? is it obsolete?
54 m_wantDebugOutput
= FALSE
;
57 m_topWindow
= (wxWindow
*)NULL
;
58 m_useBestVisual
= FALSE
;
59 m_exitOnFrameDelete
= TRUE
;
65 bool wxAppBase::OnInitGui()
67 #ifdef __WXUNIVERSAL__
68 if ( !wxTheme::Get() && !wxTheme::CreateDefault() )
70 #endif // __WXUNIVERSAL__
76 int wxAppBase::OnExit()
79 // delete the config object if any (don't use Get() here, but Set()
80 // because Get() could create a new config object)
81 delete wxConfigBase::Set((wxConfigBase
*) NULL
);
82 #endif // wxUSE_CONFIG
84 #ifdef __WXUNIVERSAL__
85 delete wxTheme::Set(NULL
);
86 #endif // __WXUNIVERSAL__
91 // ---------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 void wxAppBase::ProcessPendingEvents()
97 // ensure that we're the only thread to modify the pending events list
98 wxENTER_CRIT_SECT( *wxPendingEventsLocker
);
100 if ( !wxPendingEvents
)
102 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker
);
106 // iterate until the list becomes empty
107 wxNode
*node
= wxPendingEvents
->First();
110 wxEvtHandler
*handler
= (wxEvtHandler
*)node
->Data();
113 // In ProcessPendingEvents(), new handlers might be add
114 // and we can safely leave the critical section here.
115 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker
);
116 handler
->ProcessPendingEvents();
117 wxENTER_CRIT_SECT( *wxPendingEventsLocker
);
119 node
= wxPendingEvents
->First();
122 wxLEAVE_CRIT_SECT( *wxPendingEventsLocker
);
125 // ----------------------------------------------------------------------------
127 // ----------------------------------------------------------------------------
131 void wxAppBase::SetActive(bool active
, wxWindow
* WXUNUSED(lastFocus
))
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
142 bool wxAppBase::OnInit()
144 #if wxUSE_CMDLINE_PARSER
145 wxCmdLineParser
parser(argc
, argv
);
147 OnInitCmdLine(parser
);
150 switch ( parser
.Parse() )
153 cont
= OnCmdLineHelp(parser
);
157 cont
= OnCmdLineParsed(parser
);
161 cont
= OnCmdLineError(parser
);
167 #endif // wxUSE_CMDLINE_PARSER
172 #if wxUSE_CMDLINE_PARSER
174 #define OPTION_VERBOSE _T("verbose")
175 #define OPTION_THEME _T("theme")
177 void wxAppBase::OnInitCmdLine(wxCmdLineParser
& parser
)
179 // the standard command line options
180 static const wxCmdLineEntryDesc cmdLineDesc
[] =
186 gettext_noop("show this help message"),
188 wxCMD_LINE_OPTION_HELP
196 gettext_noop("generate verbose log messages")
200 #ifdef __WXUNIVERSAL__
205 gettext_noop("specify the theme to use"),
206 wxCMD_LINE_VAL_STRING
208 #endif // __WXUNIVERSAL__
214 parser
.SetDesc(cmdLineDesc
);
217 bool wxAppBase::OnCmdLineParsed(wxCmdLineParser
& parser
)
220 if ( parser
.Found(OPTION_VERBOSE
) )
222 wxLog::SetVerbose(TRUE
);
226 #ifdef __WXUNIVERSAL__
228 if ( parser
.Found(OPTION_THEME
, &themeName
) )
230 wxTheme
*theme
= wxTheme::Create(themeName
);
233 wxLogError(_("Unsupported theme '%s'."), themeName
.c_str());
240 #endif // __WXUNIVERSAL__
245 bool wxAppBase::OnCmdLineHelp(wxCmdLineParser
& parser
)
252 bool wxAppBase::OnCmdLineError(wxCmdLineParser
& parser
)
259 #endif // wxUSE_CMDLINE_PARSER