]>
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(wxApp::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 void wxApp::OnIdle(wxIdleEvent
&event
)
277 static bool s_inOnIdle
= FALSE
;
279 /* Avoid recursion (via ProcessEvent default case) */
285 /* Resend in the main thread events which have been prepared in other
287 ProcessPendingEvents();
289 // 'Garbage' collection of windows deleted with Close().
290 DeletePendingObjects();
293 // flush the logged messages if any
294 wxLog::FlushActive();
297 // Send OnIdle events to all windows
298 if ( SendIdleEvents() )
299 event
.RequestMore(TRUE
);
304 int wxApp::MainLoop()
307 m_mainLoop
= new wxEventLoop
;
309 rt
= m_mainLoop
->Run();
316 void wxApp::ExitMainLoop()
322 bool wxApp::Initialized()
324 return (wxTopLevelWindows
.GetCount() != 0);
327 bool wxApp::Pending()
329 return wxEventLoop::GetActive()->Pending();
332 void wxApp::Dispatch()
334 wxEventLoop::GetActive()->Dispatch();
337 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
340 // VS: disable long filenames under DJGPP as the very first thing,
341 // since SciTech MGL doesn't like them much...
342 wxSetEnv(wxT("LFN"), wxT("N"));
345 // must do it before calling wxAppBase::Initialize(), because fonts are
346 // needed by stock lists which are created there
347 wxTheFontsManager
= new wxFontsManager
;
349 if ( !wxAppBase::Initialize(argc
, argv
) )
352 if ( MGL_init(".", NULL
) == 0 )
354 wxLogError(_("Cannot initialize SciTech MGL!"));
356 wxAppBase::CleanUp();
362 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
368 void wxApp::CleanUp()
370 delete gs_rootWindow
;
372 wxAppBase::CleanUp();
374 // must do this after calling base class CleanUp()
375 delete wxTheFontsManager
;
376 wxTheFontsManager
= (wxFontsManager
*) NULL
;