From aa18e5b5ba3536427a6707b0b906abf53d2a3263 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Mon, 19 Feb 2018 23:02:19 +0100 Subject: [PATCH] Refactoring FScrollView::init --- include/final/fscrollview.h | 1 + src/fscrollview.cpp | 64 ++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/include/final/fscrollview.h b/include/final/fscrollview.h index fee84ba0..f57d1593 100644 --- a/include/final/fscrollview.h +++ b/include/final/fscrollview.h @@ -157,6 +157,7 @@ class FScrollView : public FWidget // Methods void init (FWidget*); + void init_scrollbar(); void calculateScrollbarPos(); void setHorizontalScrollBarVisibility(); void setVerticalScrollBarVisibility(); diff --git a/src/fscrollview.cpp b/src/fscrollview.cpp index cbb2da42..9a56628e 100644 --- a/src/fscrollview.cpp +++ b/src/fscrollview.cpp @@ -727,15 +727,47 @@ inline FPoint FScrollView::getViewportCursorPos() //---------------------------------------------------------------------- void FScrollView::init (FWidget* parent) { - int xoffset_end - , yoffset_end; + int xoffset_end; + int yoffset_end; assert ( parent != 0 ); assert ( ! parent->isInstanceOf("FScrollView") ); setForegroundColor (wc.dialog_fg); setBackgroundColor (wc.dialog_bg); + init_scrollbar(); + xoffset_end = getScrollWidth() - getViewportWidth(); + yoffset_end = getScrollHeight() - getViewportHeight(); + nf_offset = isNewFont() ? 1 : 0; + setTopPadding (1 - getScrollY()); + setLeftPadding (1 - getScrollX()); + setBottomPadding (1 - (yoffset_end - getScrollY())); + setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset); + FPoint no_shadow(0,0); + int w = getViewportWidth(); + int h = getViewportHeight(); + + if ( w < 1 ) + w = 1; + + if ( h < 1 ) + h = 1; + + scroll_geometry.setRect (0, 0, w, h); + createArea (scroll_geometry, no_shadow, viewport); + addPreprocessingHandler + ( + F_PREPROC_HANDLER (this, &FScrollView::copy2area) + ); + + if ( viewport ) + child_print_area = viewport; +} + +//---------------------------------------------------------------------- +void FScrollView::init_scrollbar() +{ try { vbar = new FScrollbar(fc::vertical, this); @@ -765,34 +797,6 @@ void FScrollView::init (FWidget* parent) "change-value", F_METHOD_CALLBACK (this, &FScrollView::cb_HBarChange) ); - - xoffset_end = getScrollWidth() - getViewportWidth(); - yoffset_end = getScrollHeight() - getViewportHeight(); - nf_offset = isNewFont() ? 1 : 0; - setTopPadding (1 - getScrollY()); - setLeftPadding (1 - getScrollX()); - setBottomPadding (1 - (yoffset_end - getScrollY())); - setRightPadding (1 - (xoffset_end - getScrollX()) + nf_offset); - - FPoint no_shadow(0,0); - int w = getViewportWidth(); - int h = getViewportHeight(); - - if ( w < 1 ) - w = 1; - - if ( h < 1 ) - h = 1; - - scroll_geometry.setRect (0, 0, w, h); - createArea (scroll_geometry, no_shadow, viewport); - addPreprocessingHandler - ( - F_PREPROC_HANDLER (this, &FScrollView::copy2area) - ); - - if ( viewport ) - child_print_area = viewport; } //----------------------------------------------------------------------