]>
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 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 static bool gs_inYield
= false;
53 bool wxApp::Yield(bool onlyIfNeeded
)
59 wxFAIL_MSG( wxT("wxYield called recursively" ) );
66 if ( !wxThread::IsMain() )
68 // can't process events from other threads, MGL is thread-unsafe
71 #endif // wxUSE_THREADS
77 if ( wxEventLoop::GetActive() )
79 while (wxEventLoop::GetActive()->Pending())
80 wxEventLoop::GetActive()->Dispatch();
83 /* it's necessary to call ProcessIdle() to update the frames sizes which
84 might have been changed (it also will update other things set from
85 OnUpdateUI() which is a nice (and desired) side effect) */
86 while (wxTheApp
->ProcessIdle()) { }
96 //-----------------------------------------------------------------------------
98 //-----------------------------------------------------------------------------
100 void wxApp::WakeUpIdle()
103 if (!wxThread::IsMain())
107 while (wxTheApp
->ProcessIdle())
111 if (!wxThread::IsMain())
116 //-----------------------------------------------------------------------------
118 //-----------------------------------------------------------------------------
120 class wxRootWindow
: public wxWindow
123 wxRootWindow() : wxWindow(NULL
, wxID_ANY
)
125 SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng
));
126 SetBackgroundColour(wxTHEME_COLOUR(DESKTOP
));
128 virtual ~wxRootWindow()
130 // we don't want to delete MGL_WM's rootWnd
134 virtual bool AcceptsFocus() const { return false; }
136 DECLARE_DYNAMIC_CLASS(wxRootWindow
)
139 IMPLEMENT_DYNAMIC_CLASS(wxRootWindow
, wxWindow
)
141 static wxRootWindow
*gs_rootWindow
= NULL
;
143 //-----------------------------------------------------------------------------
144 // MGL initialization
145 //-----------------------------------------------------------------------------
147 static bool wxCreateMGL_WM(const wxVideoMode
& displayMode
)
150 int refresh
= MGL_DEFAULT_REFRESH
;
152 #if wxUSE_SYSTEM_OPTIONS
153 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
154 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
157 mode
= MGL_findMode(displayMode
.GetWidth(),
158 displayMode
.GetHeight(),
159 displayMode
.GetDepth());
162 wxLogError(_("Mode %ix%i-%i not available."),
163 displayMode
.GetWidth(),
164 displayMode
.GetHeight(),
165 displayMode
.GetDepth());
168 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
169 if ( !g_displayDC
->isValid() )
176 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
183 static void wxDestroyMGL_WM()
187 MGL_wmDestroy(g_winMng
);
197 //-----------------------------------------------------------------------------
199 //-----------------------------------------------------------------------------
201 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
203 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
204 EVT_IDLE(wxAppBase::OnIdle
)
216 wxVideoMode
wxGetDefaultDisplayMode()
221 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
222 (wxSscanf(mode
.c_str(), _T("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
224 w
= 640, h
= 480, bpp
= 16;
227 return wxVideoMode(w
, h
, bpp
);
230 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
236 if ( g_displayDC
!= NULL
)
238 // FIXME_MGL -- we currently don't allow to switch video mode
239 // more than once. This can hopefully be changed...
240 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
244 if ( !wxCreateMGL_WM(mode
) )
246 gs_rootWindow
= new wxRootWindow
;
248 m_displayMode
= mode
;
253 bool wxApp::OnInitGui()
255 if ( !wxAppBase::OnInitGui() )
259 // MGL redirects stdout and stderr to physical console, so lets redirect
260 // it to file in debug build. Do it only when WXSTDERR environment variable is set
262 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
263 freopen(redirect
.mb_str(), "wt", stderr
);
264 #endif // __WXDEBUG__
266 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
267 if ( oldLog
) delete oldLog
;
272 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
275 // VS: disable long filenames under DJGPP as the very first thing,
276 // since SciTech MGL doesn't like them much...
277 wxSetEnv(wxT("LFN"), wxT("N"));
280 // intialize MGL before creating wxFontsManager since it uses MGL funcs
281 if ( MGL_init(".", NULL
) == 0 )
283 wxLogError(_("Cannot initialize SciTech MGL!"));
287 if ( !wxAppBase::Initialize(argc
, argv
) )
294 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
300 // Modules are cleaned up after wxApp::CleanUp(), and some modules may
301 // require MGL to still be alive, e.g. the stock fonts need the fonts
302 // manager. So append this module last minute in wxApp::CleanUp() to close
303 // down MGL after all the other modules have been cleaned up.
305 struct wxMGLFinalCleanup
: public wxModule
307 bool OnInit() { return true; }
311 wxFontsManager::CleanUp();
318 void wxApp::CleanUp()
320 delete gs_rootWindow
;
322 wxAppBase::CleanUp();
324 wxModule::RegisterModule(new wxMGLFinalCleanup
);