]>
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" 
  27 #include "wx/evtloop.h" 
  28 #include "wx/module.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" 
  36 //----------------------------------------------------------------------------- 
  38 //----------------------------------------------------------------------------- 
  46 //----------------------------------------------------------------------------- 
  48 //----------------------------------------------------------------------------- 
  50 static bool gs_inYield 
= false; 
  52 bool wxApp::Yield(bool onlyIfNeeded
) 
  58             wxFAIL_MSG( wxT("wxYield called recursively" ) ); 
  65     if ( !wxThread::IsMain() ) 
  67         // can't process events from other threads, MGL is thread-unsafe 
  70 #endif // wxUSE_THREADS 
  76     if ( wxEventLoop::GetActive() ) 
  78         while (wxEventLoop::GetActive()->Pending()) 
  79             wxEventLoop::GetActive()->Dispatch(); 
  82     /* it's necessary to call ProcessIdle() to update the frames sizes which 
  83        might have been changed (it also will update other things set from 
  84        OnUpdateUI() which is a nice (and desired) side effect) */ 
  85     while (wxTheApp
->ProcessIdle()) { } 
  95 //----------------------------------------------------------------------------- 
  97 //----------------------------------------------------------------------------- 
  99 void wxApp::WakeUpIdle() 
 102     if (!wxThread::IsMain()) 
 106     while (wxTheApp
->ProcessIdle()) 
 110     if (!wxThread::IsMain()) 
 115 //----------------------------------------------------------------------------- 
 117 //----------------------------------------------------------------------------- 
 119 class wxRootWindow 
: public wxWindow
 
 122         wxRootWindow() : wxWindow(NULL
, wxID_ANY
) 
 124             SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng
)); 
 125             SetBackgroundColour(wxTHEME_COLOUR(DESKTOP
)); 
 129             // we don't want to delete MGL_WM's rootWnd 
 133         virtual bool AcceptsFocus() const { return false; } 
 135         DECLARE_DYNAMIC_CLASS(wxRootWindow
) 
 138 IMPLEMENT_DYNAMIC_CLASS(wxRootWindow
, wxWindow
) 
 140 static wxRootWindow 
*gs_rootWindow 
= NULL
; 
 142 //----------------------------------------------------------------------------- 
 143 // MGL initialization 
 144 //----------------------------------------------------------------------------- 
 146 static bool wxCreateMGL_WM(const wxVideoMode
& displayMode
) 
 149     int refresh 
= MGL_DEFAULT_REFRESH
; 
 151 #if wxUSE_SYSTEM_OPTIONS 
 152     if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) ) 
 153         refresh 
= wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh")); 
 156     mode 
= MGL_findMode(displayMode
.GetWidth(), 
 157                         displayMode
.GetHeight(), 
 158                         displayMode
.GetDepth()); 
 161         wxLogError(_("Mode %ix%i-%i not available."), 
 162                      displayMode
.GetWidth(), 
 163                      displayMode
.GetHeight(), 
 164                      displayMode
.GetDepth()); 
 167     g_displayDC 
= new MGLDisplayDC(mode
, 1, refresh
); 
 168     if ( !g_displayDC
->isValid() ) 
 175     g_winMng 
= MGL_wmCreate(g_displayDC
->getDC()); 
 182 static void wxDestroyMGL_WM() 
 186         MGL_wmDestroy(g_winMng
); 
 196 //----------------------------------------------------------------------------- 
 198 //----------------------------------------------------------------------------- 
 200 IMPLEMENT_DYNAMIC_CLASS(wxApp
,wxEvtHandler
) 
 202 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
) 
 203     EVT_IDLE(wxAppBase::OnIdle
) 
 215 wxVideoMode 
wxGetDefaultDisplayMode() 
 220     if ( !wxGetEnv(wxT("WXMODE"), &mode
) || 
 221          (wxSscanf(mode
.c_str(), _T("%ux%u-%u"), &w
, &h
, &bpp
) != 3) ) 
 223         w 
= 640, h 
= 480, bpp 
= 16; 
 226     return wxVideoMode(w
, h
, bpp
); 
 229 bool wxApp::SetDisplayMode(const wxVideoMode
& mode
) 
 235     if ( g_displayDC 
!= NULL 
) 
 237         // FIXME_MGL -- we currently don't allow to switch video mode 
 238         // more than once. This can hopefully be changed... 
 239         wxFAIL_MSG(wxT("Can't change display mode after intialization!")); 
 243     if ( !wxCreateMGL_WM(mode
) ) 
 245     gs_rootWindow 
= new wxRootWindow
; 
 247     m_displayMode 
= mode
; 
 252 bool wxApp::OnInitGui() 
 254     if ( !wxAppBase::OnInitGui() ) 
 258     // MGL redirects stdout and stderr to physical console, so lets redirect 
 259     // it to file in debug build. Do it only when WXSTDERR environment variable is set 
 261     if ( wxGetEnv(wxT("WXSTDERR"), &redirect
) ) 
 262         freopen(redirect
.mb_str(), "wt", stderr
); 
 263 #endif // __WXDEBUG__ 
 265     wxLog 
*oldLog 
= wxLog::SetActiveTarget(new wxLogGui
); 
 266     if ( oldLog 
) delete oldLog
; 
 271 bool wxApp::Initialize(int& argc
, wxChar 
**argv
) 
 274     // VS: disable long filenames under DJGPP as the very first thing, 
 275     //     since SciTech MGL doesn't like them much... 
 276     wxSetEnv(wxT("LFN"), wxT("N")); 
 279     // intialize MGL before creating wxFontsManager since it uses MGL funcs 
 280     if ( MGL_init(".", NULL
) == 0 ) 
 282         wxLogError(_("Cannot initialize SciTech MGL!")); 
 286     // must do it before calling wxAppBase::Initialize(), because fonts are 
 287     // needed by stock lists which are created there 
 288     wxTheFontsManager 
= new wxFontsManager
; 
 290     if ( !wxAppBase::Initialize(argc
, argv
) ) 
 292         delete wxTheFontsManager
; 
 293         wxTheFontsManager 
= NULL
; 
 299     wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding()); 
 305 // Modules are cleaned up after wxApp::CleanUp(), and some modules may 
 306 // require MGL to still be alive, e.g. the stock fonts need the fonts 
 307 // manager. So append this module last minute in wxApp::CleanUp() to close 
 308 // down MGL after all the other modules have been cleaned up. 
 310 struct wxMGLFinalCleanup
: public wxModule
 
 312     bool OnInit() { return true; } 
 316         delete wxTheFontsManager
; 
 317         wxTheFontsManager 
= (wxFontsManager
*) NULL
; 
 324 void wxApp::CleanUp() 
 326     delete gs_rootWindow
; 
 328     wxAppBase::CleanUp(); 
 330     wxModule::RegisterModule(new wxMGLFinalCleanup
);