]>
git.saurik.com Git - wxWidgets.git/blob - src/mgl/app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mgl/app.cpp
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 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
20 #include "wx/settings.h"
22 #include "wx/dialog.h"
25 #include "wx/module.h"
28 #include "wx/evtloop.h"
29 #include "wx/fontutil.h"
30 #include "wx/univ/theme.h"
31 #include "wx/univ/renderer.h"
32 #include "wx/univ/colschem.h"
33 #include "wx/sysopt.h"
34 #include "wx/mgl/private.h"
35 #include "wx/private/fontmgr.h"
37 //-----------------------------------------------------------------------------
39 //-----------------------------------------------------------------------------
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 void wxApp::WakeUpIdle()
55 if (!wxThread::IsMain())
59 while (wxTheApp
->ProcessIdle())
63 if (!wxThread::IsMain())
68 //-----------------------------------------------------------------------------
70 //-----------------------------------------------------------------------------
72 class wxRootWindow
: public wxWindow
75 wxRootWindow() : wxWindow(NULL
, wxID_ANY
)
77 SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng
));
78 SetBackgroundColour(wxTHEME_COLOUR(DESKTOP
));
80 virtual ~wxRootWindow()
82 // we don't want to delete MGL_WM's rootWnd
86 virtual bool AcceptsFocus() const { return false; }
88 DECLARE_DYNAMIC_CLASS(wxRootWindow
)
91 IMPLEMENT_DYNAMIC_CLASS(wxRootWindow
, wxWindow
)
93 static wxRootWindow
*gs_rootWindow
= NULL
;
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 static bool wxCreateMGL_WM(const wxVideoMode
& displayMode
)
102 int refresh
= MGL_DEFAULT_REFRESH
;
104 #if wxUSE_SYSTEM_OPTIONS
105 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
106 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
109 mode
= MGL_findMode(displayMode
.GetWidth(),
110 displayMode
.GetHeight(),
111 displayMode
.GetDepth());
114 wxLogError(_("Mode %ix%i-%i not available."),
115 displayMode
.GetWidth(),
116 displayMode
.GetHeight(),
117 displayMode
.GetDepth());
120 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
121 if ( !g_displayDC
->isValid() )
128 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
135 static void wxDestroyMGL_WM()
139 MGL_wmDestroy(g_winMng
);
149 //-----------------------------------------------------------------------------
151 //-----------------------------------------------------------------------------
153 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
163 wxVideoMode
wxGetDefaultDisplayMode()
168 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
169 (wxSscanf(mode
.c_str(), wxT("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
171 w
= 640, h
= 480, bpp
= 16;
174 return wxVideoMode(w
, h
, bpp
);
177 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
183 if ( g_displayDC
!= NULL
)
185 // FIXME_MGL -- we currently don't allow to switch video mode
186 // more than once. This can hopefully be changed...
187 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
191 if ( !wxCreateMGL_WM(mode
) )
193 gs_rootWindow
= new wxRootWindow
;
195 m_displayMode
= mode
;
200 bool wxApp::OnInitGui()
202 if ( !wxAppBase::OnInitGui() )
205 // MGL redirects stdout and stderr to physical console, so lets redirect
206 // it to file if WXSTDERR environment variable is set to be able to see
207 // wxLogDebug() output
209 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
210 freopen(redirect
.mb_str(), "wt", stderr
);
212 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
213 if ( oldLog
) delete oldLog
;
218 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
221 // VS: disable long filenames under DJGPP as the very first thing,
222 // since SciTech MGL doesn't like them much...
223 wxSetEnv(wxT("LFN"), wxT("N"));
226 // intialize MGL before creating wxFontsManager since it uses MGL funcs
227 if ( MGL_init(".", NULL
) == 0 )
229 wxLogError(_("Cannot initialize SciTech MGL!"));
233 if ( !wxAppBase::Initialize(argc
, argv
) )
240 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
246 // Modules are cleaned up after wxApp::CleanUp(), and some modules may
247 // require MGL to still be alive, e.g. the stock fonts need the fonts
248 // manager. So append this module last minute in wxApp::CleanUp() to close
249 // down MGL after all the other modules have been cleaned up.
251 struct wxMGLFinalCleanup
: public wxModule
253 bool OnInit() { return true; }
257 wxFontsManager::CleanUp();
264 void wxApp::CleanUp()
266 delete gs_rootWindow
;
268 wxAppBase::CleanUp();
270 wxModule::RegisterModule(new wxMGLFinalCleanup
);