From a5aaa1a9ccf3ec6698bc473c9801bbaf26f767b6 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Tue, 22 Apr 2014 17:00:57 +0400 Subject: [PATCH] editors refactoring --- src/dlangui/widgets/editors.d | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index f71437b9..295df498 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -435,7 +435,20 @@ class EditWidgetBase : WidgetGroup, EditableContentListener { ]); } - abstract override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter); + protected void updateMaxLineWidth() { + } + + override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter) { + updateMaxLineWidth(); + measureVisibleText(); + _caretPos = rangeAfter.end; + _selectionRange.start = _caretPos; + _selectionRange.end = _caretPos; + ensureCaretVisible(); + invalidate(); + return true; + } + /// get widget text override @property dstring text() { return _content.text; } @@ -621,13 +634,6 @@ class EditLine : EditWidgetBase { text = initialContent; } - override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter) { - measureVisibleText(); - _caretPos = rangeAfter.end; - invalidate(); - return true; - } - protected dstring _measuredText; protected int[] _measuredTextWidths; protected Point _measuredTextSize; @@ -834,7 +840,7 @@ class EditBox : EditWidgetBase, OnScrollHandler { protected int[][] _visibleLinesMeasurement; // char positions for visible lines protected int[] _visibleLinesWidths; // width (in pixels) of visible lines - protected void updateMaxLineWidth() { + override protected void updateMaxLineWidth() { // find max line width. TODO: optimize!!! int maxw; int[] buf; @@ -937,17 +943,6 @@ class EditBox : EditWidgetBase, OnScrollHandler { updateScrollbars(); } - override bool onContentChange(EditableContent content, EditOperation operation, ref TextRange rangeBefore, ref TextRange rangeAfter) { - updateMaxLineWidth(); - measureVisibleText(); - _caretPos = rangeAfter.end; - _selectionRange.start = _caretPos; - _selectionRange.end = _caretPos; - ensureCaretVisible(); - invalidate(); - return true; - } - override protected Rect textPosToClient(TextPosition p) { Rect res; int lineIndex = p.line - _firstVisibleLine;