]>
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 wxEventLoopBase
* const eventLoop
= wxEventLoop::GetActive();
80 while (eventLoop
->Pending())
81 eventLoop
->Dispatch();
84 /* it's necessary to call ProcessIdle() to update the frames sizes which
85 might have been changed (it also will update other things set from
86 OnUpdateUI() which is a nice (and desired) side effect) */
87 while (wxTheApp
->ProcessIdle()) { }
97 //-----------------------------------------------------------------------------
99 //-----------------------------------------------------------------------------
101 void wxApp::WakeUpIdle()
104 if (!wxThread::IsMain())
108 while (wxTheApp
->ProcessIdle())
112 if (!wxThread::IsMain())
117 //-----------------------------------------------------------------------------
119 //-----------------------------------------------------------------------------
121 class wxRootWindow
: public wxWindow
124 wxRootWindow() : wxWindow(NULL
, wxID_ANY
)
126 SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng
));
127 SetBackgroundColour(wxTHEME_COLOUR(DESKTOP
));
129 virtual ~wxRootWindow()
131 // we don't want to delete MGL_WM's rootWnd
135 virtual bool AcceptsFocus() const { return false; }
137 DECLARE_DYNAMIC_CLASS(wxRootWindow
)
140 IMPLEMENT_DYNAMIC_CLASS(wxRootWindow
, wxWindow
)
142 static wxRootWindow
*gs_rootWindow
= NULL
;
144 //-----------------------------------------------------------------------------
145 // MGL initialization
146 //-----------------------------------------------------------------------------
148 static bool wxCreateMGL_WM(const wxVideoMode
& displayMode
)
151 int refresh
= MGL_DEFAULT_REFRESH
;
153 #if wxUSE_SYSTEM_OPTIONS
154 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
155 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
158 mode
= MGL_findMode(displayMode
.GetWidth(),
159 displayMode
.GetHeight(),
160 displayMode
.GetDepth());
163 wxLogError(_("Mode %ix%i-%i not available."),
164 displayMode
.GetWidth(),
165 displayMode
.GetHeight(),
166 displayMode
.GetDepth());
169 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
170 if ( !g_displayDC
->isValid() )
177 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
184 static void wxDestroyMGL_WM()
188 MGL_wmDestroy(g_winMng
);
198 //-----------------------------------------------------------------------------
200 //-----------------------------------------------------------------------------
202 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
204 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
205 EVT_IDLE(wxAppBase::OnIdle
)
217 wxVideoMode
wxGetDefaultDisplayMode()
222 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
223 (wxSscanf(mode
.c_str(), _T("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
225 w
= 640, h
= 480, bpp
= 16;
228 return wxVideoMode(w
, h
, bpp
);
231 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
237 if ( g_displayDC
!= NULL
)
239 // FIXME_MGL -- we currently don't allow to switch video mode
240 // more than once. This can hopefully be changed...
241 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
245 if ( !wxCreateMGL_WM(mode
) )
247 gs_rootWindow
= new wxRootWindow
;
249 m_displayMode
= mode
;
254 bool wxApp::OnInitGui()
256 if ( !wxAppBase::OnInitGui() )
260 // MGL redirects stdout and stderr to physical console, so lets redirect
261 // it to file in debug build. Do it only when WXSTDERR environment variable is set
263 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
264 freopen(redirect
.mb_str(), "wt", stderr
);
265 #endif // __WXDEBUG__
267 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
268 if ( oldLog
) delete oldLog
;
273 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
276 // VS: disable long filenames under DJGPP as the very first thing,
277 // since SciTech MGL doesn't like them much...
278 wxSetEnv(wxT("LFN"), wxT("N"));
281 // intialize MGL before creating wxFontsManager since it uses MGL funcs
282 if ( MGL_init(".", NULL
) == 0 )
284 wxLogError(_("Cannot initialize SciTech MGL!"));
288 if ( !wxAppBase::Initialize(argc
, argv
) )
295 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
301 // Modules are cleaned up after wxApp::CleanUp(), and some modules may
302 // require MGL to still be alive, e.g. the stock fonts need the fonts
303 // manager. So append this module last minute in wxApp::CleanUp() to close
304 // down MGL after all the other modules have been cleaned up.
306 struct wxMGLFinalCleanup
: public wxModule
308 bool OnInit() { return true; }
312 wxFontsManager::CleanUp();
319 void wxApp::CleanUp()
321 delete gs_rootWindow
;
323 wxAppBase::CleanUp();
325 wxModule::RegisterModule(new wxMGLFinalCleanup
);