X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ef344ff86223f1f0961f025c0b249c898529c095..b916f809336755620b010293637b12763f01455d:/src/mgl/app.cpp?ds=sidebyside diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index 2027810bd5..9112462198 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -18,17 +18,24 @@ #pragma hdrstop #endif + #ifndef WX_PRECOMP #include "wx/settings.h" #include "wx/module.h" #include "wx/evtloop.h" #include "wx/frame.h" #include "wx/dialog.h" + #include "wx/log.h" #include "wx/intl.h" + #include "wx/resource.h" #endif #include "wx/app.h" #include "wx/fontutil.h" +#include "wx/univ/theme.h" +#include "wx/univ/renderer.h" +#include "wx/univ/colschem.h" +#include "wx/sysopt.h" #include "wx/mgl/private.h" //----------------------------------------------------------------------------- @@ -55,8 +62,18 @@ void wxExit() static bool gs_inYield = FALSE; -bool wxYield() +bool wxApp::Yield(bool onlyIfNeeded) { + if ( gs_inYield ) + { + if ( !onlyIfNeeded ) + { + wxFAIL_MSG( wxT("wxYield called recursively" ) ); + } + + return FALSE; + } + #if wxUSE_THREADS if ( !wxThread::IsMain() ) { @@ -74,8 +91,6 @@ bool wxYield() while (wxEventLoop::GetActive()->Pending()) wxEventLoop::GetActive()->Dispatch(); } - else - MGL_wmUpdateDC(g_winMng); // FIXME_MGL -- temporary hack, please remove /* it's necessary to call ProcessIdle() to update the frames sizes which might have been changed (it also will update other things set from @@ -89,14 +104,6 @@ bool wxYield() return TRUE; } -bool wxYieldIfNeeded() -{ - if (gs_inYield) - return FALSE; - - return wxYield(); -} - //----------------------------------------------------------------------------- // wxWakeUpIdle @@ -117,6 +124,83 @@ void wxWakeUpIdle() #endif } +//----------------------------------------------------------------------------- +// Root window +//----------------------------------------------------------------------------- + +class wxRootWindow : public wxWindow +{ + public: + wxRootWindow() : wxWindow(NULL, -1) + { + SetMGLwindow_t(MGL_wmGetRootWindow(g_winMng)); + SetBackgroundColour(wxTHEME_COLOUR(DESKTOP)); + } + ~wxRootWindow() + { + // we don't want to delete MGL_WM's rootWnd + m_wnd = NULL; + } + + virtual bool AcceptsFocus() { return FALSE; } +}; + +static wxRootWindow *gs_rootWindow = NULL; + +//----------------------------------------------------------------------------- +// MGL initialization +//----------------------------------------------------------------------------- + +static bool wxCreateMGL_WM(const wxDisplayModeInfo& displayMode) +{ + int mode; + int refresh = MGL_DEFAULT_REFRESH; + +#if wxUSE_SYSTEM_OPTIONS + if ( wxSystemOptions::HasOption(wxT("mgl.screen-refresh")) ) + refresh = wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh")); +#endif + + mode = MGL_findMode(displayMode.GetWidth(), + displayMode.GetHeight(), + displayMode.GetDepth()); + if ( mode == -1 ) + { + wxLogError(_("Mode %ix%i-%i not available."), + displayMode.GetWidth(), + displayMode.GetHeight(), + displayMode.GetDepth()); + return FALSE; + } + g_displayDC = new MGLDisplayDC(mode, 1, refresh); + if ( !g_displayDC->isValid() ) + { + delete g_displayDC; + g_displayDC = NULL; + return FALSE; + } + + g_winMng = MGL_wmCreate(g_displayDC->getDC()); + if (!g_winMng) + return FALSE; + + return TRUE; +} + +static void wxDestroyMGL_WM() +{ + if ( g_winMng ) + { + MGL_wmDestroy(g_winMng); + g_winMng = NULL; + } + if ( g_displayDC ) + { + delete g_displayDC; + g_displayDC = NULL; + } +} + //----------------------------------------------------------------------------- // wxApp //----------------------------------------------------------------------------- @@ -136,18 +220,44 @@ wxApp::~wxApp() { } -bool wxApp::OnInitGui() +bool wxApp::SetDisplayMode(const wxDisplayModeInfo& mode) { - if ( MGL_init(".", NULL) == 0 ) + if ( !mode.IsOk() ) + { return FALSE; - if ( !wxCreateMGL_WM() ) + } + if ( g_displayDC != NULL ) + { + // FIXME_MGL -- we currently don't allow to switch video mode + // more than once. This can hopefully be changed... + wxFAIL_MSG(wxT("Can't change display mode after intialization!")); return FALSE; + } + + if ( !wxCreateMGL_WM(mode) ) + return FALSE; + gs_rootWindow = new wxRootWindow; + + m_displayMode = mode; - // This has to be done *after* wxCreateMGL_WM() because it initializes - // wxUniv's themes + return TRUE; +} + +bool wxApp::OnInitGui() +{ if ( !wxAppBase::OnInitGui() ) return FALSE; +#ifdef __WXDEBUG__ + // MGL redirects stdout and stderr to physical console, so lets redirect + // it to file. Do it only when WXDEBUG environment variable is set + if ( wxGetEnv(wxT("WXDEBUG"), NULL) ) + freopen("output.err", "wt", stderr); +#endif + + wxLog *oldLog = wxLog::SetActiveTarget(new wxLogGui); + if ( oldLog ) delete oldLog; + return TRUE; } @@ -177,6 +287,11 @@ void wxApp::OnIdle(wxIdleEvent &event) // 'Garbage' collection of windows deleted with Close(). DeletePendingObjects(); +#if wxUSE_LOG + // flush the logged messages if any + wxLog::FlushActive(); +#endif // wxUSE_LOG + // Send OnIdle events to all windows if ( SendIdleEvents() ) event.RequestMore(TRUE); @@ -209,12 +324,8 @@ bool wxApp::SendIdleEvents(wxWindow* win) win->GetEventHandler()->ProcessEvent(event); -#if 0 // FIXME_MGL - what the hell it is? - win->OnInternalIdle(); - if ( event.MoreRequested() ) needMore = TRUE; -#endif wxNode* node = win->GetChildren().First(); while (node) @@ -248,9 +359,7 @@ void wxApp::ExitMainLoop() bool wxApp::Initialized() { - // FIXME_MGL -- only for now because we don't have wxFrame/wxDialog yet - return TRUE; - //return (wxTopLevelWindows.GetCount() != 0); + return (wxTopLevelWindows.GetCount() != 0); } bool wxApp::Pending() @@ -281,6 +390,9 @@ void wxApp::DeletePendingObjects() bool wxApp::Initialize() { + if ( MGL_init(".", NULL) == 0 ) + return FALSE; + wxBuffer = new wxChar[BUFSIZ + 512]; wxClassInfo::InitializeClasses(); @@ -317,37 +429,14 @@ bool wxApp::Initialize() return TRUE; } -#include "info.xpm" -#include "error.xpm" -#include "question.xpm" -#include "warning.xpm" - wxIcon wxApp::GetStdIcon(int which) const { - switch(which) - { - case wxICON_INFORMATION: - return wxIcon(info_xpm); - case wxICON_QUESTION: - return wxIcon(question_xpm); - case wxICON_EXCLAMATION: - return wxIcon(warning_xpm); - default: - wxFAIL_MSG(wxT("requested non existent standard icon")); - // still fall through - case wxICON_HAND: - return wxIcon(error_xpm); - } + return wxTheme::Get()->GetRenderer()->GetStdIcon(which); } void wxApp::CleanUp() { #if wxUSE_LOG - // flush the logged messages if any - wxLog *log = wxLog::GetActiveTarget(); - if (log != NULL && log->HasPendingMessages()) - log->Flush(); - // continuing to use user defined log target is unsafe from now on because // some resources may be already unavailable, so replace it by something // more safe @@ -356,6 +445,8 @@ void wxApp::CleanUp() delete oldlog; #endif // wxUSE_LOG + delete gs_rootWindow; + wxModule::CleanUpModules(); #if wxUSE_WX_RESOURCES @@ -519,6 +610,12 @@ int wxEntry(int argc, char *argv[]) } } +#if wxUSE_LOG + // flush the logged messages if any + wxLog *log = wxLog::GetActiveTarget(); + if (log != NULL && log->HasPendingMessages()) + log->Flush(); +#endif // wxUSE_LOG retValue = wxTheApp->OnExit(); } }