]>
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
)
212 wxVideoMode
wxGetDefaultDisplayMode()
217 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
218 (wxSscanf(mode
.c_str(), _T("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
220 w
= 640, h
= 480, bpp
= 16;
223 return wxVideoMode(w
, h
, bpp
);
226 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
)
232 if ( g_displayDC
!= NULL
)
234 // FIXME_MGL -- we currently don't allow to switch video mode
235 // more than once. This can hopefully be changed...
236 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
240 if ( !wxCreateMGL_WM(mode
) )
242 gs_rootWindow
= new wxRootWindow
;
244 m_displayMode
= mode
;
249 bool wxApp::OnInitGui()
251 if ( !wxAppBase::OnInitGui() )
255 // MGL redirects stdout and stderr to physical console, so lets redirect
256 // it to file in debug build. Do it only when WXSTDERR environment variable is set
258 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
259 freopen(redirect
.mb_str(), "wt", stderr
);
260 #endif // __WXDEBUG__
262 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
263 if ( oldLog
) delete oldLog
;
268 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
271 // VS: disable long filenames under DJGPP as the very first thing,
272 // since SciTech MGL doesn't like them much...
273 wxSetEnv(wxT("LFN"), wxT("N"));
276 // intialize MGL before creating wxFontsManager since it uses MGL funcs
277 if ( MGL_init(".", NULL
) == 0 )
279 wxLogError(_("Cannot initialize SciTech MGL!"));
283 if ( !wxAppBase::Initialize(argc
, argv
) )
290 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
296 // Modules are cleaned up after wxApp::CleanUp(), and some modules may
297 // require MGL to still be alive, e.g. the stock fonts need the fonts
298 // manager. So append this module last minute in wxApp::CleanUp() to close
299 // down MGL after all the other modules have been cleaned up.
301 struct wxMGLFinalCleanup
: public wxModule
303 bool OnInit() { return true; }
307 wxFontsManager::CleanUp();
314 void wxApp::CleanUp()
316 delete gs_rootWindow
;
318 wxAppBase::CleanUp();
320 wxModule::RegisterModule(new wxMGLFinalCleanup
);