34#ifndef RENDERCONTEXT_H
35#define RENDERCONTEXT_H
38#include <wx/dcclient.h>
64 : m_recalcDC(o.m_recalcDC),
65 m_canvasSize(o.m_canvasSize),
66 m_updateRegion(o.m_updateRegion),
67 m_visibleRegion(o.m_visibleRegion),
68 m_worksheetPosition(o.m_worksheetPosition),
69 m_backgroundBrush(o.m_backgroundBrush),
70 m_clipToDrawRegion(o.m_clipToDrawRegion),
71 m_printing(o.m_printing)
88 m_worksheetDC = std::make_unique<wxClientDC>(worksheet);
89 m_recalcDC = m_worksheetDC.get();
94 if (m_recalcDC == m_worksheetDC.get())
96 m_worksheetDC.reset();
133 if (!m_cellRedrawTrace)
134 m_cellRedrawTrace = std::make_unique<std::vector<const Cell *>>();
136 m_cellRedrawTrace->clear();
143 if (m_cellRedrawTrace && cell)
144 m_cellRedrawTrace->push_back(cell);
154 if (!m_cellRedrawTrace)
156 std::sort(m_cellRedrawTrace->begin(), m_cellRedrawTrace->end());
158 const Cell *prev =
nullptr;
159 for (
const Cell *cell : *m_cellRedrawTrace) {
162 report(counter, prev);
169 report(counter, prev);
176 { m_clipToDrawRegion = clipToDrawRegion; }
182 { m_worksheetPosition = worksheetPosition; }
192 m_layoutDeadline = std::chrono::steady_clock::now() +
193 std::chrono::seconds(seconds);
194 m_layoutCancelled.store(
false, std::memory_order_relaxed);
195 m_layoutDeadlineActive =
true;
200 m_layoutDeadlineActive =
false;
201 m_layoutCancelled.store(
false, std::memory_order_relaxed);
206 if (m_layoutCancelled.load(std::memory_order_relaxed))
208 if (m_layoutDeadlineActive &&
209 std::chrono::steady_clock::now() >= m_layoutDeadline) {
210 m_layoutCancelled.store(
true, std::memory_order_relaxed);
218 wxDC *m_recalcDC =
nullptr;
220 std::unique_ptr<wxClientDC> m_worksheetDC;
224 wxRect m_updateRegion;
226 wxRect m_visibleRegion;
228 wxPoint m_worksheetPosition;
230 wxBrush m_backgroundBrush;
232 bool m_clipToDrawRegion =
true;
234 bool m_printing =
false;
236 wxRect m_printedPage;
243 std::unique_ptr<std::vector<const Cell *>> m_cellRedrawTrace;
245 std::chrono::steady_clock::time_point m_layoutDeadline;
247 bool m_layoutDeadlineActive =
false;
249 mutable std::atomic<bool> m_layoutCancelled{
false};
The base class all cell types the worksheet can consist of are derived from.
Definition: Cell.h:148
The state of the current worksheet render pass.
Definition: RenderContext.h:60
void SetRecalcDC(wxDC *dc)
Tells us which dc to measure text sizes on.
Definition: RenderContext.h:79
void SetWorksheetPosition(wxPoint worksheetPosition)
Sets where the worksheet is to be drawn.
Definition: RenderContext.h:181
void NotifyOfCellRedraw(const Cell *cell)
Records that this cell has been drawn, if tracing is enabled.
Definition: RenderContext.h:139
void DetachWorksheetDC()
Drops the worksheet client DC created by AttachWorksheetDC() again.
Definition: RenderContext.h:92
void ClearLayoutCancelled()
Stops the layout deadline and clears the cancelled flag.
Definition: RenderContext.h:198
wxRect GetPrintedPage() const
The part of the worksheet the page being printed shows, if any.
Definition: RenderContext.h:126
wxRect GetUpdateRegion() const
The rectangle of the worksheet that is currently being redrawn.
Definition: RenderContext.h:105
void SetVisibleRegion(wxRect visibleRegion)
Sets the rectangle of the worksheet that is currently visible.
Definition: RenderContext.h:112
void ReportMultipleRedraws(Report report)
Calls report(count, cell) for each cell that was drawn more than once.
Definition: RenderContext.h:152
void SetPrinting(bool printing)
Sets whether we are currently rendering for the printer.
Definition: RenderContext.h:117
bool ClipToDrawRegion() const
Do we want to omit drawing outside the current update region?
Definition: RenderContext.h:173
void ClearAndEnableRedrawTracing()
Starts (or restarts) recording which cells this render pass has drawn.
Definition: RenderContext.h:131
bool Printing() const
Are we currently rendering for the printer rather than the screen?
Definition: RenderContext.h:115
void AttachWorksheetDC(wxWindow *worksheet)
Creates a client DC for the given window and measures text on it.
Definition: RenderContext.h:86
void SetLayoutDeadline(int seconds)
Starts a layout deadline this many seconds in the future.
Definition: RenderContext.h:190
wxBrush GetBackgroundBrush() const
The brush the worksheet's background is painted with.
Definition: RenderContext.h:185
void SetPrintedPage(wxRect page)
Sets the part of the worksheet the page being printed shows.
Definition: RenderContext.h:128
void SetCanvasSize(wxSize siz)
Sets the size of the worksheet's visible window.
Definition: RenderContext.h:102
void ClipToDrawRegion(bool clipToDrawRegion)
Whether to omit drawing outside the current update region.
Definition: RenderContext.h:175
bool IsLayoutCancelled() const
Has the current layout pass exceeded its deadline?
Definition: RenderContext.h:204
wxDC * GetRecalcDC() const
The dc "recalculate" (measuring text) currently draws to.
Definition: RenderContext.h:77
wxPoint GetWorksheetPosition() const
Where is the worksheet to be drawn?
Definition: RenderContext.h:179
wxSize GetCanvasSize() const
The size of the worksheet's visible window.
Definition: RenderContext.h:100
void SetBackgroundBrush(const wxBrush &brush)
Sets the brush the worksheet's background is painted with.
Definition: RenderContext.h:187
wxRect GetVisibleRegion() const
The rectangle of the worksheet that is currently visible.
Definition: RenderContext.h:110
void SetUpdateRegion(wxRect rect)
Sets the rectangle of the worksheet that is currently being redrawn.
Definition: RenderContext.h:107