Use wxOverlay::IsNative() rather than wxHAS_NATIVE_OVERLAY

This commit is contained in:
Paul Cornett 2022-02-08 09:56:36 -08:00
parent 38a7861391
commit b401dfbdac
4 changed files with 56 additions and 77 deletions

View File

@ -15,10 +15,6 @@
#include "wx/dc.h" #include "wx/dc.h"
#include "wx/overlay.h" #include "wx/overlay.h"
#ifdef wxHAS_NATIVE_OVERLAY
#define wxHAS_CARET_USING_OVERLAYS
#endif
class WXDLLIMPEXP_FWD_CORE wxCaret; class WXDLLIMPEXP_FWD_CORE wxCaret;
class WXDLLIMPEXP_CORE wxCaretTimer : public wxTimer class WXDLLIMPEXP_CORE wxCaretTimer : public wxTimer
@ -75,17 +71,13 @@ private:
// GTK specific initialization // GTK specific initialization
void InitGeneric(); void InitGeneric();
#ifdef wxHAS_CARET_USING_OVERLAYS
// the overlay for displaying the caret // the overlay for displaying the caret
wxOverlay m_overlay; wxOverlay m_overlay;
#else
// the bitmap holding the part of window hidden by the caret when it was // the bitmap holding the part of window hidden by the caret when it was
// at (m_xOld, m_yOld) // at (m_xOld, m_yOld)
wxBitmap m_bmpUnderCaret; wxBitmap m_bmpUnderCaret;
int m_xOld, int m_xOld,
m_yOld; m_yOld;
#endif
wxCaretTimer m_timer; wxCaretTimer m_timer;
bool m_blinkedOut, // true => caret hidden right now bool m_blinkedOut, // true => caret hidden right now
m_hasFocus; // true => our window has focus m_hasFocus; // true => our window has focus

View File

@ -144,14 +144,9 @@ public:
// Attributes // Attributes
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
#ifdef wxHAS_NATIVE_OVERLAY
// backing store is not used when native overlays are
void SetBackingBitmap(wxBitmap* WXUNUSED(bitmap)) { }
#else
// For efficiency, tell wxGenericDragImage to use a bitmap that's already // For efficiency, tell wxGenericDragImage to use a bitmap that's already
// created (e.g. from last drag) // created (e.g. from last drag)
void SetBackingBitmap(wxBitmap* bitmap) { m_pBackingBitmap = bitmap; } void SetBackingBitmap(wxBitmap* bitmap) { m_pBackingBitmap = bitmap; }
#endif // wxHAS_NATIVE_OVERLAY/!wxHAS_NATIVE_OVERLAY
// Operations // Operations
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
@ -234,19 +229,13 @@ protected:
bool m_isShown; bool m_isShown;
wxWindow* m_window; wxWindow* m_window;
wxDC* m_windowDC; wxDC* m_windowDC;
#ifdef wxHAS_NATIVE_OVERLAY
wxOverlay m_overlay; wxOverlay m_overlay;
wxDCOverlay* m_dcOverlay;
#else
// Stores the window contents while we're dragging the image around // Stores the window contents while we're dragging the image around
wxBitmap m_backingBitmap; wxBitmap m_backingBitmap;
wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap wxBitmap* m_pBackingBitmap; // Pointer to existing backing bitmap
// (pass to wxGenericDragImage as an efficiency measure) // (pass to wxGenericDragImage as an efficiency measure)
// A temporary bitmap for repairing/redrawing // A temporary bitmap for repairing/redrawing
wxBitmap m_repairBitmap; wxBitmap m_repairBitmap;
#endif // !wxHAS_NATIVE_OVERLAY
wxRect m_boundingRect; wxRect m_boundingRect;
bool m_fullScreen; bool m_fullScreen;

View File

@ -97,12 +97,10 @@ void wxCaret::InitGeneric()
{ {
m_hasFocus = true; m_hasFocus = true;
m_blinkedOut = true; m_blinkedOut = true;
#ifndef wxHAS_CARET_USING_OVERLAYS
m_xOld = m_xOld =
m_yOld = -1; m_yOld = -1;
if (m_width && m_height) if (!m_overlay.IsNative() && m_width && m_height)
m_bmpUnderCaret.Create(m_width, m_height); m_bmpUnderCaret.Create(m_width, m_height);
#endif
} }
wxCaret::~wxCaret() wxCaret::~wxCaret()
@ -141,9 +139,12 @@ void wxCaret::DoHide()
void wxCaret::DoMove() void wxCaret::DoMove()
{ {
#ifdef wxHAS_CARET_USING_OVERLAYS if (m_overlay.IsNative())
m_overlay.Reset(); {
#endif m_overlay.Reset();
return;
}
if ( IsVisible() ) if ( IsVisible() )
{ {
if ( !m_blinkedOut ) if ( !m_blinkedOut )
@ -168,15 +169,17 @@ void wxCaret::DoSize()
m_countVisible = 0; m_countVisible = 0;
DoHide(); DoHide();
} }
#ifdef wxHAS_CARET_USING_OVERLAYS
m_overlay.Reset(); if (m_overlay.IsNative())
#else m_overlay.Reset();
// Change bitmap size
if (m_width && m_height)
m_bmpUnderCaret = wxBitmap(m_width, m_height);
else else
m_bmpUnderCaret = wxBitmap(); {
#endif // Change bitmap size
m_bmpUnderCaret.UnRef();
if (m_width && m_height)
m_bmpUnderCaret.Create(m_width, m_height);
}
if (countVisible > 0) if (countVisible > 0)
{ {
m_countVisible = countVisible; m_countVisible = countVisible;
@ -229,18 +232,17 @@ void wxCaret::Blink()
void wxCaret::Refresh() void wxCaret::Refresh()
{ {
wxClientDC dcWin(GetWindow()); wxClientDC dcWin(GetWindow());
// this is the new code, switch to 0 if this gives problems if (m_overlay.IsNative())
#ifdef wxHAS_CARET_USING_OVERLAYS
wxDCOverlay dcOverlay( m_overlay, &dcWin, m_x, m_y, m_width , m_height );
if ( m_blinkedOut )
{ {
dcOverlay.Clear(); wxDCOverlay dcOverlay(m_overlay, &dcWin, m_x, m_y, m_width, m_height);
if (m_blinkedOut)
dcOverlay.Clear();
else
DoDraw(&dcWin, GetWindow());
return;
} }
else
{
DoDraw( &dcWin, GetWindow() );
}
#else
wxMemoryDC dcMem; wxMemoryDC dcMem;
dcMem.SelectObject(m_bmpUnderCaret); dcMem.SelectObject(m_bmpUnderCaret);
if ( m_blinkedOut ) if ( m_blinkedOut )
@ -268,7 +270,6 @@ void wxCaret::Refresh()
// and draw the caret there // and draw the caret there
DoDraw(&dcWin, GetWindow()); DoDraw(&dcWin, GetWindow());
} }
#endif
} }
void wxCaret::DoDraw(wxDC *dc, wxWindow* win) void wxCaret::DoDraw(wxDC *dc, wxWindow* win)

View File

@ -65,11 +65,7 @@ void wxGenericDragImage::Init()
m_windowDC = NULL; m_windowDC = NULL;
m_window = NULL; m_window = NULL;
m_fullScreen = false; m_fullScreen = false;
#ifdef wxHAS_NATIVE_OVERLAY
m_dcOverlay = NULL;
#else
m_pBackingBitmap = NULL; m_pBackingBitmap = NULL;
#endif
} }
// Attributes // Attributes
@ -227,12 +223,13 @@ bool wxGenericDragImage::BeginDrag(const wxPoint& hotspot,
} }
} }
#ifndef wxHAS_NATIVE_OVERLAY if (!m_overlay.IsNative())
wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap); {
wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap);
if (!backing->IsOk() || (backing->GetWidth() < clientSize.x || backing->GetHeight() < clientSize.y)) if (!backing->IsOk() || (backing->GetWidth() < clientSize.x || backing->GetHeight() < clientSize.y))
(*backing) = wxBitmap(clientSize.x, clientSize.y); (*backing) = wxBitmap(clientSize.x, clientSize.y);
#endif // !wxHAS_NATIVE_OVERLAY }
if (!m_fullScreen) if (!m_fullScreen)
{ {
@ -295,17 +292,15 @@ bool wxGenericDragImage::EndDrag()
if (m_windowDC) if (m_windowDC)
{ {
#ifdef wxHAS_NATIVE_OVERLAY if (m_overlay.IsNative())
m_overlay.Reset(); m_overlay.Reset();
#else else
m_windowDC->DestroyClippingRegion(); m_windowDC->DestroyClippingRegion();
#endif
wxDELETE(m_windowDC); wxDELETE(m_windowDC);
} }
#ifndef wxHAS_NATIVE_OVERLAY
m_repairBitmap = wxNullBitmap; m_repairBitmap = wxNullBitmap;
#endif
return true; return true;
} }
@ -347,16 +342,17 @@ bool wxGenericDragImage::Show()
// This is where we restore the backing bitmap, in case // This is where we restore the backing bitmap, in case
// something has changed on the window. // something has changed on the window.
#ifndef wxHAS_NATIVE_OVERLAY if (!m_overlay.IsNative())
wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap); {
wxMemoryDC memDC; wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap);
memDC.SelectObject(* backing); wxMemoryDC memDC;
memDC.SelectObject(* backing);
UpdateBackingFromWindow(* m_windowDC, memDC, m_boundingRect, wxRect(0, 0, m_boundingRect.width, m_boundingRect.height)); UpdateBackingFromWindow(* m_windowDC, memDC, m_boundingRect, wxRect(0, 0, m_boundingRect.width, m_boundingRect.height));
//memDC.Blit(0, 0, m_boundingRect.width, m_boundingRect.height, m_windowDC, m_boundingRect.x, m_boundingRect.y); //memDC.Blit(0, 0, m_boundingRect.width, m_boundingRect.height, m_windowDC, m_boundingRect.x, m_boundingRect.y);
memDC.SelectObject(wxNullBitmap); memDC.SelectObject(wxNullBitmap);
#endif // !wxHAS_NATIVE_OVERLAY }
RedrawImage(m_position - m_offset, m_position - m_offset, false, true); RedrawImage(m_position - m_offset, m_position - m_offset, false, true);
} }
@ -399,15 +395,17 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos,
if (!m_windowDC) if (!m_windowDC)
return false; return false;
#ifdef wxHAS_NATIVE_OVERLAY if (m_overlay.IsNative())
wxUnusedVar(oldPos); {
wxDCOverlay dcoverlay( m_overlay, (wxWindowDC*) m_windowDC ) ;
if ( eraseOld )
dcoverlay.Clear() ;
if (drawNew)
DoDrawImage(*m_windowDC, newPos);
return true;
}
wxDCOverlay dcoverlay( m_overlay, (wxWindowDC*) m_windowDC ) ;
if ( eraseOld )
dcoverlay.Clear() ;
if (drawNew)
DoDrawImage(*m_windowDC, newPos);
#else // !wxHAS_NATIVE_OVERLAY
wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap); wxBitmap* backing = (m_pBackingBitmap ? m_pBackingBitmap : (wxBitmap*) & m_backingBitmap);
if (!backing->IsOk()) if (!backing->IsOk())
return false; return false;
@ -473,7 +471,6 @@ bool wxGenericDragImage::RedrawImage(const wxPoint& oldPos,
memDCTemp.SelectObject(wxNullBitmap); memDCTemp.SelectObject(wxNullBitmap);
memDC.SelectObject(wxNullBitmap); memDC.SelectObject(wxNullBitmap);
#endif // wxHAS_NATIVE_OVERLAY/!wxHAS_NATIVE_OVERLAY
return true; return true;
} }