]>
git.saurik.com Git - wxWidgets.git/blob - src/mgl/app.cpp
f8b7d3794ad800e9d7c96688f0e1eedf22b2c56e
1 /////////////////////////////////////////////////////////////////////////////
3 // Author: Vaclav Slavik
4 // based on GTK and MSW implementations
6 // Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
11 #pragma implementation "app.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
23 #include "wx/settings.h"
25 #include "wx/dialog.h"
31 #include "wx/evtloop.h"
32 #include "wx/module.h"
33 #include "wx/fontutil.h"
34 #include "wx/univ/theme.h"
35 #include "wx/univ/renderer.h"
36 #include "wx/univ/colschem.h"
37 #include "wx/sysopt.h"
38 #include "wx/mgl/private.h"
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static bool gs_inYield
= false;
56 bool wxApp::Yield(bool onlyIfNeeded
)
62 wxFAIL_MSG( wxT("wxYield called recursively" ) );
69 if ( !wxThread::IsMain() )
71 // can't process events from other threads, MGL is thread-unsafe
74 #endif // wxUSE_THREADS
80 if ( wxEventLoop::GetActive() )
82 while (wxEventLoop::GetActive()->Pending())
83 wxEventLoop::GetActive()->Dispatch();
86 /* it's necessary to call ProcessIdle() to update the frames sizes which
87 might have been changed (it also will update other things set from
88 OnUpdateUI() which is a nice (and desired) side effect) */
89 while (wxTheApp
->ProcessIdle()) { }
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
103 void wxApp::WakeUpIdle()
106 if (!wxThread::IsMain())
110 while (wxTheApp
->ProcessIdle())
114 if (!wxThread::IsMain())
119 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
123 class wxRootWindow
: public wxWindow
126 wxRootWindow() : wxWindow(NULL
, wxID_ANY
)
128 SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng
));
129 SetBackgroundColour(wxTHEME_COLOUR(DESKTOP
));
133 // we don't want to delete MGL_WM's rootWnd
137 virtual bool AcceptsFocus() const { return false; }
139 DECLARE_DYNAMIC_CLASS(wxRootWindow
)
142 IMPLEMENT_DYNAMIC_CLASS(wxRootWindow
, wxWindow
)
144 static wxRootWindow
*gs_rootWindow
= NULL
;
146 //-----------------------------------------------------------------------------
147 // MGL initialization
148 //-----------------------------------------------------------------------------
150 static bool wxCreateMGL_WM(const wxVideoMode
& displayMode
)
153 int refresh
= MGL_DEFAULT_REFRESH
;
155 #if wxUSE_SYSTEM_OPTIONS
156 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
157 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
160 mode
= MGL_findMode(displayMode
.GetWidth(),
161 displayMode
.GetHeight(),
162 displayMode
.GetDepth());
165 wxLogError(_("Mode %ix%i-%i not available."),
166 displayMode
.GetWidth(),
167 displayMode
.GetHeight(),
168 displayMode
.GetDepth());
171 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
172 if ( !g_displayDC
->isValid() )
179 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
186 static void wxDestroyMGL_WM()
190 MGL_wmDestroy(g_winMng
);
200 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
206 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
207 EVT_IDLE(wxAppBase::OnIdle
)
219 wxVideoMode
wxGetDefaultDisplayMode()
224 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
225 (wxSscanf(mode
.c_str(), _T("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
227 w
= 640, h
= 480, bpp
= 16;
230 return wxVideoMode(w
, h
, bpp
);
233 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
239 if ( g_displayDC
!= NULL
)
241 // FIXME_MGL -- we currently don't allow to switch video mode
242 // more than once. This can hopefully be changed...
243 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
247 if ( !wxCreateMGL_WM(mode
) )
249 gs_rootWindow
= new wxRootWindow
;
251 m_displayMode
= mode
;
256 bool wxApp::OnInitGui()
258 if ( !wxAppBase::OnInitGui() )
262 // MGL redirects stdout and stderr to physical console, so lets redirect
263 // it to file in debug build. Do it only when WXSTDERR environment variable is set
265 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
266 freopen(redirect
.mb_str(), "wt", stderr
);
267 #endif // __WXDEBUG__
269 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
270 if ( oldLog
) delete oldLog
;
275 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
278 // VS: disable long filenames under DJGPP as the very first thing,
279 // since SciTech MGL doesn't like them much...
280 wxSetEnv(wxT("LFN"), wxT("N"));
283 // intialize MGL before creating wxFontsManager since it uses MGL funcs
284 if ( MGL_init(".", NULL
) == 0 )
286 wxLogError(_("Cannot initialize SciTech MGL!"));
290 // must do it before calling wxAppBase::Initialize(), because fonts are
291 // needed by stock lists which are created there
292 wxTheFontsManager
= new wxFontsManager
;
294 if ( !wxAppBase::Initialize(argc
, argv
) )
296 delete wxTheFontsManager
;
297 wxTheFontsManager
= NULL
;
303 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
309 // Modules are cleaned up after wxApp::CleanUp(), and some modules may
310 // require MGL to still be alive, e.g. the stock fonts need the fonts
311 // manager. So append this module last minute in wxApp::CleanUp() to close
312 // down MGL after all the other modules have been cleaned up.
314 struct wxMGLFinalCleanup
: public wxModule
316 bool OnInit() { return true; }
320 delete wxTheFontsManager
;
321 wxTheFontsManager
= (wxFontsManager
*) NULL
;
328 void wxApp::CleanUp()
330 delete gs_rootWindow
;
332 wxAppBase::CleanUp();
334 wxModule::RegisterModule(new wxMGLFinalCleanup
);