From 2d1e95d36ba054bb851eb26a28f47109657cf6be21180946a36ccc171cc952d5 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Thu, 21 Aug 2025 17:52:30 -0400 Subject: [PATCH] Requested anchor RAIIed. --- dw/layout.cc | 20 +++++++------------- dw/layout.hh | 4 ++-- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/dw/layout.cc b/dw/layout.cc index bd4cee2..69f3a7d 100644 --- a/dw/layout.cc +++ b/dw/layout.cc @@ -281,7 +281,6 @@ Layout::Layout (std::unique_ptr< Platform > platform, bool limit) DBG_OBJ_SET_NUM ("hScrollbarThickness", hScrollbarThickness); DBG_OBJ_SET_NUM ("vScrollbarThickness", vScrollbarThickness); - requestedAnchor = NULL; scrollIdleId = -1; scrollIdleNotInterrupted = false; @@ -332,9 +331,6 @@ Layout::~Layout () delete view; delete textZone; - if (requestedAnchor) - free (requestedAnchor); - DBG_OBJ_DELETE (); } @@ -410,7 +406,7 @@ void Layout::removeWidget () view->setViewportSize (viewportWidth, viewportHeight, 0, 0); view->queueDrawTotal (); - setAnchor (NULL); + setAnchor (std::nullopt); updateAnchor (); emitter.emitCanvasSizeChanged (canvasWidth, canvasAscent, canvasDescent); @@ -724,13 +720,11 @@ int Layout::currVScrollbarThickness() /** * Sets the anchor to scroll to. */ -void Layout::setAnchor (const char *anchor) +void Layout::setAnchor (const std::optional< std::string_view > anchor) { - _MSG("setAnchor (%s)\n", anchor); + _MSG("setAnchor (%s)\n", anchor.value_or("").string().c_str()); - if (requestedAnchor) - free (requestedAnchor); - requestedAnchor = anchor ? dStrdup (anchor) : NULL; + requestedAnchor = anchor; updateAnchor (); } @@ -776,9 +770,9 @@ void Layout::removeAnchor (Widget *widget, char* name) void Layout::updateAnchor () { Anchor *anchor= nullptr; - if (requestedAnchor and anchorsTable.contains( requestedAnchor ) ) + if (requestedAnchor and anchorsTable.contains( requestedAnchor.value() ) ) { - anchor= anchorsTable[ requestedAnchor ].get(); + anchor= anchorsTable[ requestedAnchor.value() ].get(); } if (anchor == NULL) { @@ -1292,7 +1286,7 @@ void Layout::scrollPosChanged (View *view, int x, int y) scrollX = x; scrollY = y; - setAnchor (NULL); + setAnchor( std::nullopt ); updateAnchor (); } } diff --git a/dw/layout.hh b/dw/layout.hh index 04d169b..2c33f5b 100644 --- a/dw/layout.hh +++ b/dw/layout.hh @@ -182,7 +182,7 @@ private: VPosition scrollTargetVpos; int scrollTargetX, scrollTargetY, scrollTargetWidth, scrollTargetHeight; - char *requestedAnchor; + std::optional< std::string > requestedAnchor; int scrollIdleId, resizeIdleId; bool scrollIdleNotInterrupted; @@ -300,7 +300,7 @@ public: void scrollTo (HPosition hpos, VPosition vpos, int x, int y, int width, int height); void scroll (ScrollCommand); - void setAnchor (const char *anchor); + void setAnchor (std::optional< std::string_view > anchor); /* View */