]>
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() )
123 wxDELETE(g_displayDC
);
127 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
134 static void wxDestroyMGL_WM()
138 MGL_wmDestroy(g_winMng
);
141 wxDELETE(g_displayDC
);
144 //-----------------------------------------------------------------------------
146 //-----------------------------------------------------------------------------
148 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
158 wxVideoMode
wxGetDefaultDisplayMode()
163 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
164 (wxSscanf(mode
.c_str(), wxT("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
166 w
= 640, h
= 480, bpp
= 16;
169 return wxVideoMode(w
, h
, bpp
);
172 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
178 if ( g_displayDC
!= NULL
)
180 // FIXME_MGL -- we currently don't allow to switch video mode
181 // more than once. This can hopefully be changed...
182 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
186 if ( !wxCreateMGL_WM(mode
) )
188 gs_rootWindow
= new wxRootWindow
;
190 m_displayMode
= mode
;
195 bool wxApp::OnInitGui()
197 if ( !wxAppBase::OnInitGui() )
200 // MGL redirects stdout and stderr to physical console, so lets redirect
201 // it to file if WXSTDERR environment variable is set to be able to see
202 // wxLogDebug() output
204 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
205 freopen(redirect
.mb_str(), "wt", stderr
);
207 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
208 if ( oldLog
) delete oldLog
;
213 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
216 // VS: disable long filenames under DJGPP as the very first thing,
217 // since SciTech MGL doesn't like them much...
218 wxSetEnv(wxT("LFN"), wxT("N"));
221 // intialize MGL before creating wxFontsManager since it uses MGL funcs
222 if ( MGL_init(".", NULL
) == 0 )
224 wxLogError(_("Cannot initialize SciTech MGL!"));
228 if ( !wxAppBase::Initialize(argc
, argv
) )
235 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
241 // Modules are cleaned up after wxApp::CleanUp(), and some modules may
242 // require MGL to still be alive, e.g. the stock fonts need the fonts
243 // manager. So append this module last minute in wxApp::CleanUp() to close
244 // down MGL after all the other modules have been cleaned up.
246 struct wxMGLFinalCleanup
: public wxModule
248 bool OnInit() { return true; }
252 wxFontsManager::CleanUp();
259 void wxApp::CleanUp()
261 delete gs_rootWindow
;
263 wxAppBase::CleanUp();
265 wxModule::RegisterModule(new wxMGLFinalCleanup
);