[PATCH] FltkViewport fixes and TextEditor for FltkMultiLineResource
Finally (I hope)! This patch changes FltkMultiLineResource to use the FLTK TextEditor. It includes fixes for the double free problem in FltkMultiLineResource that Johannes found, Johannes' fixes for the Viewport drawing code and the patch for the Viewport scrolling bug (which was previously posted separately so please ignore that post). Regards, Jeremy Henty diff -pru -- dw2-ref/dw/fltkui.cc dw2-cur/dw/fltkui.cc --- dw2-ref/dw/fltkui.cc 2007-12-19 12:26:59.000000000 +0000 +++ dw2-cur/dw/fltkui.cc 2007-12-22 12:48:23.000000000 +0000 @@ -30,7 +30,7 @@ #include <fltk/Group.h> #include <fltk/Input.h> #include <fltk/SecretInput.h> -#include <fltk/MultiLineInput.h> +#include <fltk/TextEditor.h> #include <fltk/RadioButton.h> #include <fltk/CheckButton.h> #include <fltk/Choice.h> @@ -533,7 +533,7 @@ FltkMultiLineTextResource::FltkMultiLine FltkSpecificResource <dw::core::ui::MultiLineTextResource> (platform), numCols(cols), numRows(rows) { - initText = NULL; + buffer = new ::fltk::TextBuffer; editable = false; init (platform); @@ -541,27 +541,23 @@ FltkMultiLineTextResource::FltkMultiLine FltkMultiLineTextResource::~FltkMultiLineTextResource () { - if (initText) - delete initText; + for (Iterator <ViewAndWidget> it = viewsAndWidgets->iterator (); + it.hasNext(); ) { + ViewAndWidget *viewAndWidget = it.getNext (); + ((::fltk::TextEditor *) viewAndWidget->widget)->buffer (0); + } + delete buffer; } ::fltk::Widget *FltkMultiLineTextResource::createNewWidget (core::Allocation *allocation) { - ::fltk::MultiLineInput *input = - new ::fltk::MultiLineInput (allocation->x, allocation->y, - allocation->width, - allocation->ascent + allocation->descent); - - if (viewsAndWidgets->isEmpty ()) { - // First widget created, attach the set text. - if (initText) - input->value (initText); - } else - input->value - (((::fltk::MultiLineInput*)viewsAndWidgets->getFirst()->widget)->value ()); - - return input; + ::fltk::TextEditor *text = + new ::fltk::TextEditor (allocation->x, allocation->y, + allocation->width, + allocation->ascent + allocation->descent); + text->buffer (buffer); + return text; } void FltkMultiLineTextResource::sizeRequest (core::Requisition *requisition) @@ -586,23 +582,12 @@ void FltkMultiLineTextResource::sizeRequ const char *FltkMultiLineTextResource::getText () { - if (viewsAndWidgets->isEmpty ()) - return initText; - else - return ((::fltk::MultiLineInput*)viewsAndWidgets->getFirst()->widget)->value (); + return buffer->text (); } void FltkMultiLineTextResource::setText (const char *text) { - if (initText) - delete initText; - initText = strdup (text); - - for (Iterator <ViewAndWidget> it = viewsAndWidgets->iterator (); - it.hasNext(); ) { - ViewAndWidget *viewAndWidget = it.getNext (); - ((::fltk::MultiLineInput*)viewAndWidget->widget)->value (initText); - } + buffer->text (text); } bool FltkMultiLineTextResource::isEditable () diff -pru -- dw2-ref/dw/fltkui.hh dw2-cur/dw/fltkui.hh --- dw2-ref/dw/fltkui.hh 2007-12-19 12:26:59.000000000 +0000 +++ dw2-cur/dw/fltkui.hh 2007-12-22 12:48:23.000000000 +0000 @@ -7,6 +7,7 @@ #include <fltk/Button.h> #include <fltk/Menu.h> +#include <fltk/TextBuffer.h> namespace dw { namespace fltk { @@ -317,7 +318,7 @@ class FltkMultiLineTextResource: public FltkSpecificResource <dw::core::ui::MultiLineTextResource> { private: - const char *initText; + ::fltk::TextBuffer *buffer; bool editable; int numCols, numRows; diff -pru -- dw2-ref/dw/fltkviewbase.cc dw2-cur/dw/fltkviewbase.cc --- dw2-ref/dw/fltkviewbase.cc 2007-12-06 17:29:59.000000000 +0000 +++ dw2-cur/dw/fltkviewbase.cc 2007-12-22 12:48:23.000000000 +0000 @@ -53,9 +53,7 @@ void FltkViewBase::draw () { int d = damage(); - if (d == DAMAGE_CHILD) { - Group::draw (); - } else if (d == DAMAGE_VALUE) { + if (d == DAMAGE_VALUE) { container::typed::Iterator <core::Rectangle> it; ::fltk::Rectangle view (0, 0, w (), h ()); @@ -76,7 +74,16 @@ void FltkViewBase::draw () pop_clip (); } } - } else { + + d &= ~DAMAGE_VALUE; + } + + if (d & DAMAGE_CHILD) { + Group::draw (); + d &= ~DAMAGE_CHILD; + } + + if (d) { ::fltk::Rectangle rect (x(), y(), w(), h()); /* fltk-clipping does not use widget coordinates */ @@ -98,6 +105,7 @@ void FltkViewBase::draw () drawRegion.clear (); } + core::ButtonState getDwButtonState () { int s1 = event_state (); @@ -113,7 +121,6 @@ core::ButtonState getDwButtonState () return (core::ButtonState)s2; } - int FltkViewBase::handle (int event) { bool processed; @@ -349,6 +356,23 @@ FltkWidgetView::~FltkWidgetView () delete canvasWidgets; } +void FltkWidgetView::layout () { + /** + * pass layout to child widgets. This is needed for complex fltk + * widgets as TextEditor. + * We can't use Group::layout() as that would rearrange the widgets. + */ + for(Iterator <TypedPointer < ::fltk::Widget> > it + = canvasWidgets->iterator (); + it.hasNext (); ) { + ::fltk::Widget *widget = it.getNext()->getTypedValue (); + + if (widget->layout_damage ()) { + widget->layout (); + } + } +} + void FltkWidgetView::drawText (core::style::Font *font, core::style::Color *color, core::style::Color::Shading shading, diff -pru -- dw2-ref/dw/fltkviewbase.hh dw2-cur/dw/fltkviewbase.hh --- dw2-ref/dw/fltkviewbase.hh 2007-12-06 17:29:59.000000000 +0000 +++ dw2-cur/dw/fltkviewbase.hh 2007-12-22 12:48:23.000000000 +0000 @@ -74,6 +74,8 @@ public: FltkWidgetView (int x, int y, int w, int h, const char *label = 0); ~FltkWidgetView (); + void layout(); + void drawText (core::style::Font *font, core::style::Color *color, core::style::Color::Shading shading, diff -pru -- dw2-ref/dw/fltkviewport.cc dw2-cur/dw/fltkviewport.cc --- dw2-ref/dw/fltkviewport.cc 2007-11-18 07:36:53.000000000 +0000 +++ dw2-cur/dw/fltkviewport.cc 2007-12-22 12:48:23.000000000 +0000 @@ -46,7 +46,7 @@ FltkViewport::FltkViewport (int x, int y vscrollbar->set_vertical(); vscrollbar->callback (vscrollbarCallback, this); - scrollX = scrollY = 0; + scrollX = scrollY = scrollDX = scrollDY = 0; dragScrolling = 0; gadgetOrientation[0] = GADGET_HORIZONTAL; @@ -154,6 +154,8 @@ void FltkViewport::layout () { theLayout->viewportSizeChanged (this, w(), h()); adjustScrollbarsAndGadgetsAllocation (); + + FltkWidgetView::layout (); } void FltkViewport::draw_area (void *data, const Rectangle& cr )
On Sat, Dec 22, 2007 at 12:58:52PM +0000, Jeremy Henty wrote:
Finally (I hope)! This patch changes FltkMultiLineResource to use the FLTK TextEditor. It includes fixes for the double free problem in FltkMultiLineResource that Johannes found, Johannes' fixes for the Viewport drawing code and the patch for the Viewport scrolling bug (which was previously posted separately so please ignore that post).
Committed! It is soothing to see dillo2 progressing day by day. Thanks a lot, and keep the patches coming! -- Cheers Jorge.-
participants (2)
-
jcid@dillo.org
-
onepoint@starurchin.org