From d76048f514b0de4307c2490f8806bf41033bc81a Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 21 Nov 2001 00:00:12 +0000 Subject: [PATCH] - removed GDI lists from wxMGL - friendlier wxApp::SetDisplayMode - redirects stdout and stderr to files if __WXDEBUG__ - wxLog initialization and flushing fixes git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12546 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mgl/app.cpp | 46 +++++++++++++++++++++++++--------------------- src/mgl/bitmap.cpp | 20 -------------------- src/mgl/brush.cpp | 16 ---------------- src/mgl/font.cpp | 12 ------------ src/mgl/pen.cpp | 20 -------------------- src/mgl/window.cpp | 11 ++++++++--- 6 files changed, 33 insertions(+), 92 deletions(-) diff --git a/src/mgl/app.cpp b/src/mgl/app.cpp index 77a30f0220..bcb909fcc8 100644 --- a/src/mgl/app.cpp +++ b/src/mgl/app.cpp @@ -37,12 +37,6 @@ #include "wx/univ/colschem.h" #include "wx/mgl/private.h" -#define MGL_DEBUG - -#if defined(MGL_DEBUG) && !defined(__WXDEBUG__) -#undef MGL_DEBUG -#endif - //----------------------------------------------------------------------------- // Global data //----------------------------------------------------------------------------- @@ -166,14 +160,14 @@ static bool wxCreateMGL_WM(const wxDisplayModeInfo& displayMode) refresh = wxSystemOptions::GetOptionInt(wxT("mgl.screen-refresh")); #endif - mode = MGL_findMode(displayMode.GetScreenSize().x, - displayMode.GetScreenSize().y, + mode = MGL_findMode(displayMode.GetWidth(), + displayMode.GetHeight(), displayMode.GetDepth()); if ( mode == -1 ) { wxLogError(_("Mode %ix%i-%i not available."), - displayMode.GetScreenSize().x, - displayMode.GetScreenSize().y, + displayMode.GetWidth(), + displayMode.GetHeight(), displayMode.GetDepth()); return FALSE; } @@ -253,12 +247,16 @@ bool wxApp::OnInitGui() if ( !wxAppBase::OnInitGui() ) return FALSE; -#ifdef MGL_DEBUG - // That damn MGL redirects stdin and stdout to physical console - FILE *file = fopen("stderr", "wt"); - wxLog::SetActiveTarget(new wxLogStderr(file)); +#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; } @@ -288,6 +286,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); @@ -432,14 +435,7 @@ wxIcon wxApp::GetStdIcon(int which) const void wxApp::CleanUp() { - delete gs_rootWindow; - #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 @@ -448,6 +444,8 @@ void wxApp::CleanUp() delete oldlog; #endif // wxUSE_LOG + delete gs_rootWindow; + wxModule::CleanUpModules(); #if wxUSE_WX_RESOURCES @@ -611,6 +609,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(); } } diff --git a/src/mgl/bitmap.cpp b/src/mgl/bitmap.cpp index 0520051d37..12e0bbeac9 100644 --- a/src/mgl/bitmap.cpp +++ b/src/mgl/bitmap.cpp @@ -191,16 +191,9 @@ wxBitmapRefData::~wxBitmapRefData() IMPLEMENT_ABSTRACT_CLASS(wxBitmapHandler,wxObject) IMPLEMENT_DYNAMIC_CLASS(wxBitmap,wxBitmapBase) -wxBitmap::wxBitmap() -{ - if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); -} - wxBitmap::wxBitmap(int width, int height, int depth) { Create(width, height, depth); - - if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } @@ -285,8 +278,6 @@ bool wxBitmap::CreateFromXpm(const char **bits) *this = wxBitmap(img); - if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); - return TRUE; } @@ -370,15 +361,11 @@ wxImage wxBitmap::ConvertToImage() const wxBitmap::wxBitmap(const wxBitmap& bmp) { Ref(bmp); - - if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } wxBitmap::wxBitmap(const wxString &filename, wxBitmapType type) { LoadFile(filename, type); - - if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); } wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) @@ -393,13 +380,6 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth) bdc->clearDevice(); bdc->putMonoImage(0, 0, width, (width + 7) / 8, height, (void*)bits); delete bdc; - - if ( wxTheBitmapList ) wxTheBitmapList->AddBitmap(this); -} - -wxBitmap::~wxBitmap() -{ - if ( wxTheBitmapList ) wxTheBitmapList->DeleteObject(this); } wxBitmap& wxBitmap::operator = (const wxBitmap& bmp) diff --git a/src/mgl/brush.cpp b/src/mgl/brush.cpp index 173c3b2b3c..6bddd63b3b 100644 --- a/src/mgl/brush.cpp +++ b/src/mgl/brush.cpp @@ -121,18 +121,11 @@ wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject) -wxBrush::wxBrush() -{ - if (wxTheBrushList) wxTheBrushList->AddBrush(this); -} - wxBrush::wxBrush(const wxColour &colour, int style) { m_refData = new wxBrushRefData(); M_BRUSHDATA->m_style = style; M_BRUSHDATA->m_colour = colour; - - if (wxTheBrushList) wxTheBrushList->AddBrush(this); } wxBrush::wxBrush(const wxBitmap &stippleBitmap) @@ -152,20 +145,11 @@ wxBrush::wxBrush(const wxBitmap &stippleBitmap) M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; else M_BRUSHDATA->m_style = wxSTIPPLE; - - if (wxTheBrushList) wxTheBrushList->AddBrush(this); } wxBrush::wxBrush(const wxBrush &brush) { Ref(brush); - - if (wxTheBrushList) wxTheBrushList->AddBrush(this); -} - -wxBrush::~wxBrush() -{ - if (wxTheBrushList) wxTheBrushList->RemoveBrush(this); } wxBrush& wxBrush::operator = (const wxBrush& brush) diff --git a/src/mgl/font.cpp b/src/mgl/font.cpp index 85e934c02c..cc8dd3fb38 100644 --- a/src/mgl/font.cpp +++ b/src/mgl/font.cpp @@ -150,12 +150,6 @@ wxFontRefData::~wxFontRefData() IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject) -void wxFont::Init() -{ - if (wxTheFontList) - wxTheFontList->Append(this); -} - bool wxFont::Create(const wxNativeFontInfo& info) { return Create(info.pointSize, info.family, info.style, info.weight, @@ -206,12 +200,6 @@ void wxFont::Unshare() } } -wxFont::~wxFont() -{ - if (wxTheFontList) - wxTheFontList->DeleteObject(this); -} - // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- diff --git a/src/mgl/pen.cpp b/src/mgl/pen.cpp index eacb859d6c..18c599c477 100644 --- a/src/mgl/pen.cpp +++ b/src/mgl/pen.cpp @@ -79,21 +79,12 @@ wxPenRefData::wxPenRefData(const wxPenRefData& data) IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) -wxPen::wxPen() -{ - if ( wxThePenList ) - wxThePenList->AddPen(this); -} - wxPen::wxPen(const wxColour &colour, int width, int style) { m_refData = new wxPenRefData(); M_PENDATA->m_width = width; M_PENDATA->m_style = style; M_PENDATA->m_colour = colour; - - if ( wxThePenList ) - wxThePenList->AddPen(this); } wxPen::wxPen(const wxBitmap& stipple, int width) @@ -107,22 +98,11 @@ wxPen::wxPen(const wxBitmap& stipple, int width) M_PENDATA->m_style = wxSTIPPLE; M_PENDATA->m_stipple = stipple; wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); - - if ( wxThePenList ) - wxThePenList->AddPen(this); } wxPen::wxPen(const wxPen& pen) { Ref(pen); - if ( wxThePenList ) - wxThePenList->AddPen(this); -} - -wxPen::~wxPen() -{ - if ( wxThePenList ) - wxThePenList->RemovePen(this); } wxPen& wxPen::operator = (const wxPen& pen) diff --git a/src/mgl/window.cpp b/src/mgl/window.cpp index 830b19167d..346c33f826 100644 --- a/src/mgl/window.cpp +++ b/src/mgl/window.cpp @@ -132,6 +132,7 @@ static void wxWindowPainter(window_t *wnd, MGLDC *dc) static ibool wxWindowMouseHandler(window_t *wnd, event_t *e) { wxWindowMGL *win = (wxWindowMGL*)MGL_wmGetWindowUserData(wnd); + wxPoint orig(win->GetClientAreaOrigin()); wxPoint where; MGL_wmCoordGlobalToLocal(win->GetHandle(), @@ -149,8 +150,8 @@ static ibool wxWindowMouseHandler(window_t *wnd, event_t *e) wxMouseEvent event; event.SetEventObject(win); event.SetTimestamp(e->when); - event.m_x = where.x; - event.m_y = where.y; + event.m_x = where.x - orig.x; + event.m_y = where.y - orig.y; event.m_shiftDown = e->modifiers & EVT_SHIFTKEY; event.m_controlDown = e->modifiers & EVT_CTRLSTATE; event.m_altDown = e->modifiers & EVT_LEFTALT; @@ -194,6 +195,10 @@ static ibool wxWindowMouseHandler(window_t *wnd, event_t *e) e->where_x, e->where_y, &event2.m_x, &event2.m_y); + wxPoint orig(gs_windowUnderMouse->GetClientAreaOrigin()); + event2.m_x -= orig.x; + event2.m_y -= orig.y; + event2.SetEventObject(gs_windowUnderMouse); event2.SetEventType(wxEVT_LEAVE_WINDOW); gs_windowUnderMouse->GetEventHandler()->ProcessEvent(event2); @@ -469,7 +474,7 @@ void wxWindowMGL::Init() // First of all, make sure window manager is up and running. If it is // not the case, initialize it in default display mode if ( !g_winMng ) - wxTheApp->SetDisplayMode(wxDisplayModeInfo(wxSize(640, 480), 16)); + wxTheApp->SetDisplayMode(wxDisplayModeInfo(640, 480, 16)); // generic: InitBase(); -- 2.45.2