diff --git a/xvaga/xvaga.cpp b/xvaga/xvaga.cpp index e4a05c66a..f70688f5e 100755 --- a/xvaga/xvaga.cpp +++ b/xvaga/xvaga.cpp @@ -31,8 +31,8 @@ extern "C" { #define CAST_WIN(win,w) XVT_ASSERT(win != NULL_WIN); wxWindow& w = *(wxWindow*)win #define CAST_TWIN(win,w) XVT_ASSERT(win != NULL_WIN); TwxWindow& w = *(TwxWindow*)win; XVT_ASSERT(_task_win != &w); -#define CAST_TDC(win,dc) XVT_ASSERT(win != NULL_WIN); TDC& dc = _dc_map.GetTDC((TwxWindow*)win); -#define CAST_DC(win,dc) XVT_ASSERT(win != NULL_WIN); wxDC& dc = _dc_map.GetDC((TwxWindow*)win); +#define CAST_TDC(win,dc) XVT_ASSERT(win != NULL_WIN); TDC& dc = GetTDCMapper().GetTDC(win); +#define CAST_DC(win,dc) XVT_ASSERT(win != NULL_WIN); wxDC& dc = GetTDCMapper().GetDC(win); // Funzione interna di utilita' MENU_ITEM* xvt_menu_duplicate_tree(const MENU_ITEM* m); @@ -490,24 +490,33 @@ bool TDC::GetClippingBox(RCT* pRct) const return _clip.right > _clip.left; } -WX_DECLARE_HASH_MAP(wxWindow*, TDC*, wxPointerHash, wxPointerEqual, wxTDCHashMap); +WX_DECLARE_HASH_MAP(WINDOW, TDC*, wxIntegerHash, wxIntegerEqual, wxTDCHashMap); class TDCMapper : public wxTDCHashMap { - wxWindow* _pLastOwner; + WINDOW _pLastOwner; TDC* _pLastTDC; public: - TDC& GetTDC(wxWindow* owner); - wxDC& GetDC(wxWindow* owner, bool bPaint = false) { return GetTDC(owner).GetDC(bPaint); } - void DestroyDC(wxWindow* owner); - void DestroyTDC(wxWindow* owner); + TDC& GetTDC(WINDOW owner); + wxDC& GetDC(WINDOW owner, bool bPaint = false) { return GetTDC(owner).GetDC(bPaint); } + void DestroyDC(WINDOW owner); + void DestroyTDC(WINDOW owner); bool HasValidDC(WINDOW owner) const; - TDCMapper() : _pLastOwner(NULL), _pLastTDC(NULL) { } -} _dc_map; + TDCMapper() : _pLastOwner(NULL_WIN), _pLastTDC(NULL) { } + virtual ~TDCMapper() { DestroyTDC(NULL_WIN); } +}; -void TDCMapper::DestroyDC(wxWindow* owner) +TDCMapper& GetTDCMapper() +{ + static TDCMapper* _dc_map = NULL; + if (_dc_map == NULL) + _dc_map = new TDCMapper; + return *_dc_map; +} + +void TDCMapper::DestroyDC(WINDOW owner) { if (owner) { @@ -516,21 +525,29 @@ void TDCMapper::DestroyDC(wxWindow* owner) pTDC->KillDC(); } else - clear(); + { + TDCMapper::iterator it; + for (it = begin(); it != end(); ++it) + { + TDC* pTDC = it->second; + if (pTDC) + pTDC->KillDC(); + } + } } -void TDCMapper::DestroyTDC(wxWindow* owner) +void TDCMapper::DestroyTDC(WINDOW owner) { - if (owner) + if (owner != NULL_WIN) { TDC* pTDC = (*this)[owner]; if (pTDC) delete pTDC; + erase(owner); } else { TDCMapper::iterator it; - for (it = begin(); it != end(); ++it) { TDC* pTDC = it->second; @@ -539,10 +556,10 @@ void TDCMapper::DestroyTDC(wxWindow* owner) } clear(); } - _pLastOwner = NULL; + _pLastOwner = NULL_WIN; } -TDC& TDCMapper::GetTDC(wxWindow* owner) +TDC& TDCMapper::GetTDC(WINDOW owner) { if (owner == _pLastOwner) return *_pLastTDC; @@ -550,10 +567,10 @@ TDC& TDCMapper::GetTDC(wxWindow* owner) TDC* pTDC = (*this)[owner]; if (pTDC == NULL) { - if (owner == (wxWindow*)_print_win) - pTDC = new TPrintDC(owner); + if (owner == _print_win) + pTDC = new TPrintDC((wxWindow*)owner); else - pTDC = new TDC(owner); + pTDC = new TDC((wxWindow*)owner); (*this)[owner] = pTDC; } _pLastOwner = owner; @@ -569,8 +586,7 @@ bool TDCMapper::HasValidDC(WINDOW owner) const if (owner == (WINDOW)_pLastOwner) return true; - CAST_WIN(owner, w); - TDC* pTDC = (*((TDCMapper *) this))[&w]; + TDC* pTDC = (*((TDCMapper *) this))[owner]; return pTDC != NULL; } @@ -900,11 +916,11 @@ void TwxWindow::OnPaint(wxPaintEvent& event) rct.right = rctDamaged.GetRight()+1; rct.bottom = rctDamaged.GetBottom()+1; - TDC& tdc = _dc_map.GetTDC(this); + TDC& tdc = GetTDCMapper().GetTDC((WINDOW)this); tdc.GetDC(true); // Forza la creazione di un wxPaintDC DoXvtEvent(e); tdc.KillDC(); // Distrugge il wxPaintDC - _dc_map.DestroyDC(NULL); // Distrugge davvero tutti i wxClientDC residui (risolve molte "porcate" del video) + GetTDCMapper().DestroyDC(NULL_WIN); // Distrugge davvero tutti i wxClientDC residui (risolve molte "porcate" del video) } static SCROLL_CONTROL ConvertScrollToXVT(wxEventType et) @@ -1073,7 +1089,7 @@ void TTaskWin::OnPaint() rct.right = rctDamaged.GetRight()+1; rct.bottom = rctDamaged.GetBottom()+1; - TDC& dc = _dc_map.GetTDC(this); + TDC& dc = GetTDCMapper().GetTDC((WINDOW)this); dc.GetDC(true); // Forza la creazione di un wxPaintDC _task_win_handler((WINDOW)this, &e); dc.KillDC(); @@ -2180,21 +2196,6 @@ void xvt_dwin_draw_text(WINDOW win, int x, int y, const char *s, int len) { if (s && *s && len != 0) { -/* - CAST_DC(win, dc); - wxRect rct; dc.GetClippingBox(rct); - const int maxx = rct.GetRight(); - if (maxx <= 0 || x < maxx) - { - wxString str(s); - if (len >= 0) - str.Truncate(len); - int height, desc, lead; - dc.GetTextExtent(str, NULL, &height, &desc, &lead); - y -= height-desc; // Triste necessita'! - dc.DrawText(str, x, y); - } -*/ CAST_TDC(win, tdc); RCT rct; const bool noclip = !tdc.GetClippingBox(&rct); @@ -4128,7 +4129,7 @@ void xvt_vobj_destroy(WINDOW win) if (_nice_windows.Get(win) != NULL) { CAST_TWIN(win, w); - _dc_map.DestroyTDC(&w); + GetTDCMapper().DestroyTDC(win); w.Close(true); } #ifdef DBG