]>
git.saurik.com Git - wxWidgets.git/blob - src/mgl/app.cpp
1 /////////////////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "app.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
23 #include "wx/settings.h"
24 #include "wx/module.h"
25 #include "wx/evtloop.h"
27 #include "wx/dialog.h"
33 #include "wx/fontutil.h"
34 #include "wx/univ/theme.h"
35 #include "wx/univ/renderer.h"
36 #include "wx/univ/colschem.h"
37 #include "wx/sysopt.h"
38 #include "wx/mgl/private.h"
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static bool gs_inYield
= FALSE
;
56 bool wxApp::Yield(bool onlyIfNeeded
)
62 wxFAIL_MSG( wxT("wxYield called recursively" ) );
69 if ( !wxThread::IsMain() )
71 // can't process events from other threads, MGL is thread-unsafe
74 #endif // wxUSE_THREADS
80 if ( wxEventLoop::GetActive() )
82 while (wxEventLoop::GetActive()->Pending())
83 wxEventLoop::GetActive()->Dispatch();
86 /* it's necessary to call ProcessIdle() to update the frames sizes which
87 might have been changed (it also will update other things set from
88 OnUpdateUI() which is a nice (and desired) side effect) */
89 while (wxTheApp
->ProcessIdle()) { }
99 //-----------------------------------------------------------------------------
101 //-----------------------------------------------------------------------------
103 void wxApp::WakeUpIdle()
106 if (!wxThread::IsMain())
110 while (wxTheApp
->ProcessIdle())
114 if (!wxThread::IsMain())
119 //-----------------------------------------------------------------------------
121 //-----------------------------------------------------------------------------
123 class wxRootWindow
: public wxWindow
126 wxRootWindow() : wxWindow(NULL
, -1)
128 SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng
));
129 SetBackgroundColour(wxTHEME_COLOUR(DESKTOP
));
133 // we don't want to delete MGL_WM's rootWnd
137 virtual bool AcceptsFocus() const { return FALSE
; }
139 DECLARE_DYNAMIC_CLASS(wxRootWindow
)
142 IMPLEMENT_DYNAMIC_CLASS(wxRootWindow
, wxWindow
)
144 static wxRootWindow
*gs_rootWindow
= NULL
;
146 //-----------------------------------------------------------------------------
147 // MGL initialization
148 //-----------------------------------------------------------------------------
150 static bool wxCreateMGL_WM(const wxDisplayModeInfo
& displayMode
)
153 int refresh
= MGL_DEFAULT_REFRESH
;
155 #if wxUSE_SYSTEM_OPTIONS
156 if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) )
157 refresh
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh"));
160 mode
= MGL_findMode(displayMode
.GetWidth(),
161 displayMode
.GetHeight(),
162 displayMode
.GetDepth());
165 wxLogError(_("Mode %ix%i-%i not available."),
166 displayMode
.GetWidth(),
167 displayMode
.GetHeight(),
168 displayMode
.GetDepth());
171 g_displayDC
= new MGLDisplayDC(mode
, 1, refresh
);
172 if ( !g_displayDC
->isValid() )
179 g_winMng
= MGL_wmCreate(g_displayDC
->getDC());
186 static void wxDestroyMGL_WM()
190 MGL_wmDestroy(g_winMng
);
200 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
204 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
)
206 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
207 EVT_IDLE(wxAppBase::OnIdle
)
211 wxApp::wxApp() : m_mainLoop(NULL
)
219 wxDisplayModeInfo
wxGetDefaultDisplayMode()
224 if ( !wxGetEnv(wxT("WXMODE"), &mode
) ||
225 (wxSscanf(mode
.c_str(), _T("%ux%u-%u"), &w
, &h
, &bpp
) != 3) )
227 w
= 640, h
= 480, bpp
= 16;
230 return wxDisplayModeInfo(w
, h
, bpp
);
233 bool wxApp::SetDisplayMode(const wxDisplayModeInfo
& mode
)
239 if ( g_displayDC
!= NULL
)
241 // FIXME_MGL -- we currently don't allow to switch video mode
242 // more than once. This can hopefully be changed...
243 wxFAIL_MSG(wxT("Can't change display mode after intialization!"));
247 if ( !wxCreateMGL_WM(mode
) )
249 gs_rootWindow
= new wxRootWindow
;
251 m_displayMode
= mode
;
256 bool wxApp::OnInitGui()
258 if ( !wxAppBase::OnInitGui() )
262 // MGL redirects stdout and stderr to physical console, so lets redirect
263 // it to file. Do it only when WXDEBUG environment variable is set
265 if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) )
266 freopen(redirect
.mb_str(), "wt", stderr
);
269 wxLog
*oldLog
= wxLog::SetActiveTarget(new wxLogGui
);
270 if ( oldLog
) delete oldLog
;
275 int wxApp::MainLoop()
278 m_mainLoop
= new wxEventLoop
;
280 rt
= m_mainLoop
->Run();
287 void wxApp::ExitMainLoop()
293 bool wxApp::Initialized()
295 return (wxTopLevelWindows
.GetCount() != 0);
298 bool wxApp::Pending()
300 return wxEventLoop::GetActive()->Pending();
303 void wxApp::Dispatch()
305 wxEventLoop::GetActive()->Dispatch();
308 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
311 // VS: disable long filenames under DJGPP as the very first thing,
312 // since SciTech MGL doesn't like them much...
313 wxSetEnv(wxT("LFN"), wxT("N"));
316 // must do it before calling wxAppBase::Initialize(), because fonts are
317 // needed by stock lists which are created there
318 wxTheFontsManager
= new wxFontsManager
;
320 if ( !wxAppBase::Initialize(argc
, argv
) )
323 if ( MGL_init(".", NULL
) == 0 )
325 wxLogError(_("Cannot initialize SciTech MGL!"));
327 wxAppBase::CleanUp();
333 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
339 void wxApp::CleanUp()
341 delete gs_rootWindow
;
343 wxAppBase::CleanUp();
345 // must do this after calling base class CleanUp()
346 delete wxTheFontsManager
;
347 wxTheFontsManager
= (wxFontsManager
*) NULL
;