mirror of
https://github.com/wxWidgets/wxWidgets.git
synced 2026-09-28 15:50:17 +08:00
Use SelectionShape instead of PolyPolygon to refer to the selection shape
Since selection shape is not clearly expressed using PolyPolygon, SelectionShape is now used instead to denote class/function/variable entities: - PolyPolygon to SelectionShape (class) - GetPolyPolygon() to GetSelectionShape() - ComputePolyPolygon() to ComputeSelectionShape() - InvalidatePolyPolygon() to InvalidateSelectionShape() - m_polyPolygon to m_selectionShape
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
#include <memory>
|
||||
|
||||
// Forward declaration
|
||||
namespace wxGridPrivate { class PolyPolygon; }
|
||||
namespace wxGridPrivate { class SelectionShape; }
|
||||
|
||||
using wxSelectionShape = wxGridPrivate::SelectionShape;
|
||||
|
||||
wxDEPRECATED_MSG("use wxGridBlockCoordsVector instead")
|
||||
typedef wxVector<wxGridBlockCoords> wxVectorGridBlockCoords;
|
||||
@@ -119,10 +121,10 @@ public:
|
||||
void EndSelecting();
|
||||
void CancelSelecting();
|
||||
|
||||
// Return the PolyPolygon object. Call ComputePolyPolygon() if necessary.
|
||||
const wxGridPrivate::PolyPolygon& GetPolyPolygon(const wxRect& renderExtent);
|
||||
// Return the SelectionShape object. Call ComputeSelectionShape() if necessary.
|
||||
const wxSelectionShape& GetSelectionShape(const wxRect& renderExtent);
|
||||
|
||||
void InvalidatePolyPolygon();
|
||||
void InvalidateSelectionShape();
|
||||
|
||||
private:
|
||||
void SelectBlockNoEvent(const wxGridBlockCoords& block)
|
||||
@@ -149,8 +151,8 @@ private:
|
||||
void MergeOrAddBlock(wxGridBlockCoordsVector& blocks,
|
||||
const wxGridBlockCoords& block);
|
||||
|
||||
// Called each time the selection changed or scrolled to recompute m_polyPolygon.
|
||||
void ComputePolyPolygon(const wxRect& renderExtent = {});
|
||||
// Called each time the selection changed or scrolled to recompute m_selectionShape.
|
||||
void ComputeSelectionShape(const wxRect& renderExtent = {});
|
||||
|
||||
// All currently selected blocks. We expect there to be a relatively small
|
||||
// amount of them, even for very large grids, as each block must be
|
||||
@@ -170,9 +172,9 @@ private:
|
||||
// - Simple polygon (using wxDC::DrawPolygon()) if it represents a simple polygon.
|
||||
// - Poly-polygon (using wxDC::DrawPolyPolygon()) if it consists of multiple polygons.
|
||||
//
|
||||
std::unique_ptr<wxGridPrivate::PolyPolygon> m_polyPolygon;
|
||||
std::unique_ptr<wxSelectionShape> m_selectionShape;
|
||||
|
||||
// See ComputePolyPolygon() definition for explanation.
|
||||
// See ComputeSelectionShape() definition for explanation.
|
||||
bool m_updateHighlightedLabels = false;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxGridSelection);
|
||||
|
||||
@@ -1295,16 +1295,16 @@ TryGetValueAsDate(wxDateTime& result,
|
||||
#endif // wxUSE_DATETIME
|
||||
|
||||
//=============================================================================
|
||||
// PolyPolygon & PolyPolygonHelper classes
|
||||
// SelectionShape & PolyPolygonHelper classes
|
||||
//=============================================================================
|
||||
|
||||
// A simple interface used by wxGrid::DrawOverlaySelection() as a helper to draw
|
||||
// the grid selection overlay.
|
||||
class PolyPolygon
|
||||
class SelectionShape
|
||||
{
|
||||
public:
|
||||
PolyPolygon() = default;
|
||||
~PolyPolygon() = default;
|
||||
SelectionShape() = default;
|
||||
~SelectionShape() = default;
|
||||
|
||||
// Return the number of polygons to draw.
|
||||
size_t GetSize() const { return m_counts.size(); }
|
||||
@@ -1335,7 +1335,7 @@ private:
|
||||
|
||||
// This class is just a helper that simply converts (using the sweep line algorithm)
|
||||
// the selected rectangles (retrieved by wxGrid::GetSelectedRectangles()) to
|
||||
// wxGridSelection::PolyPolygon which can then be used in wxGrid::DrawOverlaySelection()
|
||||
// wxGridSelection::SelectionShape which can then be used in wxGrid::DrawOverlaySelection()
|
||||
// to draw the selection overlay.
|
||||
//
|
||||
// The implementation is literally the translation of the Python code found here:
|
||||
@@ -1344,9 +1344,9 @@ private:
|
||||
class PolyPolygonHelper
|
||||
{
|
||||
public:
|
||||
PolyPolygonHelper(PolyPolygon* polyPolygon,
|
||||
PolyPolygonHelper(SelectionShape* selectionShape,
|
||||
const std::vector<wxRect>& rectangles)
|
||||
: m_polyPolygon(polyPolygon)
|
||||
: m_selectionShape(selectionShape)
|
||||
{
|
||||
std::vector<wxPoint> points = GetVertices(rectangles);
|
||||
|
||||
@@ -1425,7 +1425,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
m_polyPolygon->Append(poly);
|
||||
m_selectionShape->Append(poly);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1505,7 +1505,7 @@ private:
|
||||
}
|
||||
|
||||
private:
|
||||
PolyPolygon* const m_polyPolygon;
|
||||
SelectionShape* const m_selectionShape;
|
||||
|
||||
using EdgeType = std::map<wxPoint, wxPoint>;
|
||||
EdgeType m_horzEdges;
|
||||
@@ -1519,7 +1519,7 @@ private:
|
||||
void MergeAdjacentBlocks(wxGridBlockCoordsVector& selection);
|
||||
|
||||
// This function attempts to reduce the number of rectangles returned from
|
||||
// wxGrid::GetSelectedRectangles() before trying to convert them to PolyPolygon.
|
||||
// wxGrid::GetSelectedRectangles() before trying to convert them to SelectionShape.
|
||||
// Most of the time this will result in just one rectangle.
|
||||
void MergeAdjacentRects(std::vector<wxRect>& rectangles);
|
||||
|
||||
|
||||
@@ -7162,9 +7162,9 @@ void wxGrid::DrawOverlaySelection(wxDC& paintDC, wxGridWindow *gridWindow, const
|
||||
if ( !UsesOverlaySelection() || !IsSelection() )
|
||||
return;
|
||||
|
||||
const auto& polygons = m_selection->GetPolyPolygon(renderExtent);
|
||||
const auto& selectionShape = m_selection->GetSelectionShape(renderExtent);
|
||||
|
||||
wxRect updateRect = polygons.GetBoundingBox();
|
||||
wxRect updateRect = selectionShape.GetBoundingBox();
|
||||
|
||||
if ( updateRect.IsEmpty() )
|
||||
{
|
||||
@@ -7217,7 +7217,7 @@ void wxGrid::DrawOverlaySelection(wxDC& paintDC, wxGridWindow *gridWindow, const
|
||||
dc.SetPen(wxPen(colBg));
|
||||
dc.SetBrush(wxColour(colBg.Red(), colBg.Green(), colBg.Blue(), 64));
|
||||
|
||||
const int n = polygons.GetSize();
|
||||
const int n = selectionShape.GetSize();
|
||||
|
||||
if ( n == 0 )
|
||||
{
|
||||
@@ -7227,8 +7227,8 @@ void wxGrid::DrawOverlaySelection(wxDC& paintDC, wxGridWindow *gridWindow, const
|
||||
}
|
||||
else
|
||||
{
|
||||
const int* counts = polygons.GetCounts();
|
||||
const wxPoint* points = polygons.GetPoints();
|
||||
const int* counts = selectionShape.GetCounts();
|
||||
const wxPoint* points = selectionShape.GetPoints();
|
||||
|
||||
if ( n == 1 )
|
||||
{
|
||||
@@ -7249,7 +7249,7 @@ void wxGrid::InvalidateOverlaySelection()
|
||||
{
|
||||
if ( UsesOverlaySelection() && IsSelection() )
|
||||
{
|
||||
m_selection->InvalidatePolyPolygon();
|
||||
m_selection->InvalidateSelectionShape();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-23
@@ -172,7 +172,7 @@ void wxGridSelection::SetSelectionMode( wxGrid::wxGridSelectionModes selmode )
|
||||
|
||||
if ( m_grid->UsesOverlaySelection() )
|
||||
{
|
||||
ComputePolyPolygon();
|
||||
ComputeSelectionShape();
|
||||
}
|
||||
else if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
@@ -393,7 +393,7 @@ wxGridSelection::DeselectBlock(const wxGridBlockCoords& block,
|
||||
|
||||
if ( m_grid->UsesOverlaySelection() )
|
||||
{
|
||||
ComputePolyPolygon();
|
||||
ComputeSelectionShape();
|
||||
}
|
||||
|
||||
count = refreshBlocks.size();
|
||||
@@ -430,7 +430,7 @@ void wxGridSelection::ClearSelection()
|
||||
{
|
||||
m_selection.clear();
|
||||
|
||||
ComputePolyPolygon();
|
||||
ComputeSelectionShape();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -724,7 +724,7 @@ bool wxGridSelection::ExtendCurrentBlock(const wxGridCellCoords& blockStart,
|
||||
|
||||
if ( m_grid->UsesOverlaySelection() )
|
||||
{
|
||||
ComputePolyPolygon();
|
||||
ComputeSelectionShape();
|
||||
}
|
||||
|
||||
// Send Event.
|
||||
@@ -893,7 +893,7 @@ wxGridSelection::Select(const wxGridBlockCoords& block,
|
||||
// Update View:
|
||||
if ( m_grid->UsesOverlaySelection() )
|
||||
{
|
||||
ComputePolyPolygon();
|
||||
ComputeSelectionShape();
|
||||
}
|
||||
else if ( !m_grid->GetBatchCount() )
|
||||
{
|
||||
@@ -1044,20 +1044,20 @@ void wxGridPrivate::MergeAdjacentRects(std::vector<wxRect>& rectangles)
|
||||
}
|
||||
}
|
||||
|
||||
void wxGridSelection::ComputePolyPolygon(const wxRect& renderExtent)
|
||||
void wxGridSelection::ComputeSelectionShape(const wxRect& renderExtent)
|
||||
{
|
||||
if ( m_grid->GetBatchCount() )
|
||||
return;
|
||||
|
||||
wxRect updateRect;
|
||||
|
||||
if ( m_polyPolygon )
|
||||
if ( m_selectionShape )
|
||||
{
|
||||
// the old rect will be refreshed too.
|
||||
updateRect = m_polyPolygon->GetBoundingBox();
|
||||
updateRect = m_selectionShape->GetBoundingBox();
|
||||
}
|
||||
|
||||
m_polyPolygon.reset(new wxGridPrivate::PolyPolygon);
|
||||
m_selectionShape.reset(new wxSelectionShape);
|
||||
|
||||
std::vector<wxRect> rectangles;
|
||||
m_grid->GetSelectedRectangles(rectangles, renderExtent);
|
||||
@@ -1070,15 +1070,15 @@ void wxGridSelection::ComputePolyPolygon(const wxRect& renderExtent)
|
||||
}
|
||||
else if ( rectangles.size() == 1 )
|
||||
{
|
||||
m_polyPolygon->SetBoundingBox(rectangles[0]);
|
||||
m_selectionShape->SetBoundingBox(rectangles[0]);
|
||||
|
||||
updateRect.Union(rectangles[0]);
|
||||
}
|
||||
else if ( rectangles.size() > 1 )
|
||||
{
|
||||
wxGridPrivate::PolyPolygonHelper helper(m_polyPolygon.get(), rectangles);
|
||||
wxGridPrivate::PolyPolygonHelper helper(m_selectionShape.get(), rectangles);
|
||||
|
||||
updateRect.Union(m_polyPolygon->GetBoundingBox());
|
||||
updateRect.Union(m_selectionShape->GetBoundingBox());
|
||||
}
|
||||
else // out-of-view selection
|
||||
{
|
||||
@@ -1123,23 +1123,23 @@ void wxGridSelection::ComputePolyPolygon(const wxRect& renderExtent)
|
||||
m_grid->RefreshRect(!updateRect.IsEmpty() ? &updateRect : nullptr);
|
||||
}
|
||||
|
||||
const wxGridPrivate::PolyPolygon&
|
||||
wxGridSelection::GetPolyPolygon(const wxRect& renderExtent)
|
||||
const wxSelectionShape&
|
||||
wxGridSelection::GetSelectionShape(const wxRect& renderExtent)
|
||||
{
|
||||
if ( !m_polyPolygon )
|
||||
if ( !m_selectionShape )
|
||||
{
|
||||
ComputePolyPolygon(renderExtent);
|
||||
ComputeSelectionShape(renderExtent);
|
||||
}
|
||||
|
||||
return *m_polyPolygon.get();
|
||||
return *m_selectionShape.get();
|
||||
}
|
||||
|
||||
void wxGridSelection::InvalidatePolyPolygon()
|
||||
void wxGridSelection::InvalidateSelectionShape()
|
||||
{
|
||||
m_polyPolygon.reset();
|
||||
m_selectionShape.reset();
|
||||
}
|
||||
|
||||
void wxGridPrivate::PolyPolygon::Append(const std::vector<wxPoint>& points)
|
||||
void wxGridPrivate::SelectionShape::Append(const std::vector<wxPoint>& points)
|
||||
{
|
||||
CalcBoundingBox(points);
|
||||
|
||||
@@ -1148,7 +1148,7 @@ void wxGridPrivate::PolyPolygon::Append(const std::vector<wxPoint>& points)
|
||||
std::back_inserter(m_points));
|
||||
}
|
||||
|
||||
void wxGridPrivate::PolyPolygon::CalcBoundingBox(const std::vector<wxPoint>& points)
|
||||
void wxGridPrivate::SelectionShape::CalcBoundingBox(const std::vector<wxPoint>& points)
|
||||
{
|
||||
for ( const auto& point : points )
|
||||
{
|
||||
@@ -1164,14 +1164,14 @@ void wxGridPrivate::PolyPolygon::CalcBoundingBox(const std::vector<wxPoint>& poi
|
||||
}
|
||||
}
|
||||
|
||||
wxRect wxGridPrivate::PolyPolygon::GetBoundingBox() const
|
||||
wxRect wxGridPrivate::SelectionShape::GetBoundingBox() const
|
||||
{
|
||||
return wxRect(m_minX, m_minY,
|
||||
m_maxX - m_minX,
|
||||
m_maxY - m_minY);
|
||||
}
|
||||
|
||||
void wxGridPrivate::PolyPolygon::SetBoundingBox(const wxRect& rect)
|
||||
void wxGridPrivate::SelectionShape::SetBoundingBox(const wxRect& rect)
|
||||
{
|
||||
m_minX = rect.x;
|
||||
m_minY = rect.y;
|
||||
|
||||
Reference in New Issue
Block a user