[PATCH] implements dw::fltk::ui::FltkMultiLineTextResource
I promised you all something more substantial than whitespace and comment fixes next, didn't I? This patch implements the dw::fltk::ui::FltkMultiLineTextResource class, using ::fltk:LMultiLineInput to create the widget. It also adds a FltkMultiLineTextResource to the dw-ui-test example. This isn't complete yet; the number of rows and columns are hardwired. Comments are welcome. Regards, Jeremy Henty diff -pru -- dw2-ref/dw/fltkplatform.cc dw2-cur/dw/fltkplatform.cc --- dw2-ref/dw/fltkplatform.cc 2007-12-06 17:29:59.000000000 +0000 +++ dw2-cur/dw/fltkplatform.cc 2007-12-15 01:41:02.000000000 +0000 @@ -144,8 +144,7 @@ FltkPlatform::FltkResourceFactory::creat core::ui::MultiLineTextResource * FltkPlatform::FltkResourceFactory::createMultiLineTextResource () { - /** \bug Not implemented. */ - return NULL; + return new ui::FltkMultiLineTextResource (platform); } core::ui::CheckButtonResource * diff -pru -- dw2-ref/dw/fltkui.cc dw2-cur/dw/fltkui.cc --- dw2-ref/dw/fltkui.cc 2007-12-06 17:29:59.000000000 +0000 +++ dw2-cur/dw/fltkui.cc 2007-12-15 02:34:13.000000000 +0000 @@ -30,6 +30,7 @@ #include <fltk/Group.h> #include <fltk/Input.h> #include <fltk/SecretInput.h> +#include <fltk/MultiLineInput.h> #include <fltk/RadioButton.h> #include <fltk/CheckButton.h> #include <fltk/Choice.h> @@ -527,6 +528,107 @@ void FltkEntryResource::setEditable (boo // ---------------------------------------------------------------------- +FltkMultiLineTextResource::FltkMultiLineTextResource (FltkPlatform *platform): + FltkSpecificResource <dw::core::ui::MultiLineTextResource> (platform) +{ + initText = NULL; + editable = false; + + init (platform); +} + +FltkMultiLineTextResource::~FltkMultiLineTextResource () +{ + if (initText) + delete initText; +} + +::fltk::Widget *FltkMultiLineTextResource::createNewWidget (core::Allocation + *allocation) +{ + ::fltk::MultiLineInput *input = + new ::fltk::MultiLineInput (allocation->x, allocation->y, + allocation->width, + allocation->ascent + allocation->descent); + input->callback (widgetCallback, this); + input->when (::fltk::WHEN_ENTER_KEY_ALWAYS); + + 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; +} + +void FltkMultiLineTextResource::sizeRequest (core::Requisition *requisition) +{ + if (style) { + FltkFont *font = (FltkFont*)style->font; + requisition->width = + (int)::fltk::getwidth ("M", 1) * 20 + + 2 * RELIEF_X_THICKNESS; + requisition->ascent = RELIEF_Y_THICKNESS; + requisition->descent = + (font->ascent + font->descent) * 10 + RELIEF_Y_THICKNESS; + } else { + requisition->width = 1; + requisition->ascent = 1; + requisition->descent = 0; + } +} + +void FltkMultiLineTextResource::widgetCallback (::fltk::Widget *widget, + void *data) +{ + /* The (::fltk::event_key() == ::fltk::ReturnKey) test + * is necessary because WHEN_ENTER_KEY also includes + * other events we're not interested in. For instance pressing + * The Back or Forward, buttons, or the first click on a rendered + * page. BUG: this must be investigated and reported to FLTK2 team + */ + printf ("when = %d\n", widget->when ()); + if ((widget->when () & ::fltk::WHEN_ENTER_KEY_ALWAYS) && + (::fltk::event_key() == ::fltk::ReturnKey)) + ((FltkMultiLineTextResource*)data)->emitActivate (); +} + +const char *FltkMultiLineTextResource::getText () +{ + if (viewsAndWidgets->isEmpty ()) + return initText; + else + return ((::fltk::MultiLineInput*)viewsAndWidgets->getFirst()->widget)->value (); +} + +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); + } +} + +bool FltkMultiLineTextResource::isEditable () +{ + return editable; +} + +void FltkMultiLineTextResource::setEditable (bool editable) +{ + this->editable = editable; +} + +// ---------------------------------------------------------------------- + template <class I> FltkToggleButtonResource<I>::FltkToggleButtonResource (FltkPlatform *platform, bool activated): diff -pru -- dw2-ref/dw/fltkui.hh dw2-cur/dw/fltkui.hh --- dw2-ref/dw/fltkui.hh 2007-10-06 23:03:01.000000000 +0100 +++ dw2-cur/dw/fltkui.hh 2007-12-15 01:28:53.000000000 +0000 @@ -313,6 +313,31 @@ public: }; +class FltkMultiLineTextResource: + public FltkSpecificResource <dw::core::ui::MultiLineTextResource> +{ +private: + const char *initText; + bool editable; + + static void widgetCallback (::fltk::Widget *widget, void *data); + +protected: + ::fltk::Widget *createNewWidget (core::Allocation *allocation); + +public: + FltkMultiLineTextResource (FltkPlatform *platform); + ~FltkMultiLineTextResource (); + + void sizeRequest (core::Requisition *requisition); + + const char *getText (); + void setText (const char *text); + bool isEditable (); + void setEditable (bool editable); +}; + + template <class I> class FltkToggleButtonResource: public FltkSpecificResource <I> { diff -pru -- dw2-ref/test/dw_ui_test.cc dw2-cur/test/dw_ui_test.cc --- dw2-ref/test/dw_ui_test.cc 2007-10-06 23:03:01.000000000 +0100 +++ dw2-cur/test/dw_ui_test.cc 2007-12-15 02:35:22.000000000 +0000 @@ -44,10 +44,10 @@ int main(int argc, char **argv) FltkPlatform *platform = new FltkPlatform (); Layout *layout = new Layout (platform); - ::fltk::Window *window = new ::fltk::Window(300, 300, "Dw UI Test"); + ::fltk::Window *window = new ::fltk::Window(400, 400, "Dw UI Test"); window->begin(); - FltkViewport *viewport = new FltkViewport (0, 0, 300, 300); + FltkViewport *viewport = new FltkViewport (0, 0, 400, 400); layout->attachView (viewport); StyleAttrs styleAttrs; @@ -83,6 +83,8 @@ int main(int argc, char **argv) entryres1->setText ("Hi!"); EntryResource *entryres2 = layout->getResourceFactory()->createEntryResource (10, true); + MultiLineTextResource *textres = + layout->getResourceFactory()->createMultiLineTextResource (); RadioButtonResource *radiores1 = layout->getResourceFactory()->createRadioButtonResource (NULL, false); RadioButtonResource *radiores2 = @@ -115,6 +117,7 @@ int main(int argc, char **argv) form::Form *form = new form::Form(); form->addTextResource ("val1", entryres1); form->addTextResource ("val2", entryres2); + form->addTextResource ("text", textres); const char *radiovalues[] = { "radio1", "radio2", NULL }; form->addRadioButtonResource ("val3", radiores1, radiovalues); form->addCheckButtonResource ("check", checkres); @@ -151,6 +154,19 @@ int main(int argc, char **argv) table->addCell (input2, 1, 1); table->addRow (cellStyle); + + Textblock *label = new Textblock(false); + label->setStyle (cellStyle); + table->addCell (label, 1, 1); + label->addText (strdup ("text = "), cellStyle); + label->flush (); + + Embed *text = new Embed (textres); + text->setStyle (cellStyle); + table->addCell (text, 1, 1); + + table->addRow (cellStyle); + Textblock *radiolabel1 = new Textblock(false); radiolabel1->setStyle (cellStyle); table->addCell (radiolabel1, 2, 1);
Hi Jeremy, On Sat, Dec 15, 2007 at 03:53:51AM +0000, Jeremy Henty wrote:
I promised you all something more substantial than whitespace and comment fixes next, didn't I? This patch implements the dw::fltk::ui::FltkMultiLineTextResource class, using ::fltk:LMultiLineInput to create the widget. It also adds a FltkMultiLineTextResource to the dw-ui-test example.
This isn't complete yet; the number of rows and columns are hardwired. Comments are welcome.
It looks good so far! BTW, I decided to bind it to the html parser and to commit. The next time you visit a form with a TEXTAREA, it will show! :-) Please test and polish to full functionality. -- Cheers Jorge.-
On Sun, Dec 16, 2007 at 09:53:06AM -0300, Jorge Arellano Cid wrote:
BTW, I decided to bind it to the html parser ...
Hey, *I* wanted to do that! Why are you spoiling my fun? :-) Guess I'll have to look at selections instead.
The next time you visit a form with a TEXTAREA, it will show! :-)
Which means I can use Dillo to post flamebait to blogs. Clearly a great milestone has been passed! :-)
Please test and polish to full functionality.
OK, I'm looking at adding the rows and columns parameters. It should be easy, except that I'm not sure which class to add the extra members to. Options are: 1) dw::core::ui::MultiLineTextResource 2) dw::fltk::ui::FltkMultiLineTextResource I'm inclined to say 2), since I don't like the idea of hardwiring this API into the base class. Do you agree? Regards, Jeremy Henty
On Sun, Dec 16, 2007 at 04:58:38PM +0000, Jeremy Henty (ie. *me*) wrote:
OK, I'm looking at adding the rows and columns parameters. It should be easy, except that I'm not sure which class to add the extra members to. Options are:
1) dw::core::ui::MultiLineTextResource 2) dw::fltk::ui::FltkMultiLineTextResource
I'm inclined to say 2), since I don't like the idea of hardwiring this API into the base class. Do you agree?
On second thoughts, if I add members to 2) I still have to add an abstract version of the API to 1) so that the HTML parser can set the parameters in a platform-independent way. It still looks like the right way to go, though. Regards, Jeremy Henty
Hi Jeremy, On Sun, Dec 16, 2007 at 05:20:42PM +0000, Jeremy Henty wrote:
On Sun, Dec 16, 2007 at 04:58:38PM +0000, Jeremy Henty (ie. *me*) wrote:
OK, I'm looking at adding the rows and columns parameters. It should be easy, except that I'm not sure which class to add the extra members to. Options are:
1) dw::core::ui::MultiLineTextResource 2) dw::fltk::ui::FltkMultiLineTextResource
I'm inclined to say 2), since I don't like the idea of hardwiring this API into the base class. Do you agree?
On second thoughts, if I add members to 2) I still have to add an abstract version of the API to 1) so that the HTML parser can set the parameters in a platform-independent way. It still looks like the right way to go, though.
I would do it as it is done for the maxLength and password members of FltkEntryResource: Add parameters to createMultiLineTextResource() and store the values in private members of FltkMultiLineTextResource. Cheers, Johannes
On Sun, Dec 16, 2007 at 08:19:57PM +0100, Johannes Hofmann wrote:
I would do it as it is done for the maxLength and password members of FltkEntryResource: Add parameters to createMultiLineTextResource() and store the values in private members of FltkMultiLineTextResource.
OK, here's the patch to dw2. I'll follow up with the (extremely short) patch to dillo2. How should extra stuff like word-wrap be supported? More arguments to the constructor or some other API? Regards, Jeremy Henty diff -pru -- dw2-ref/dw/fltkplatform.cc dw2-cur/dw/fltkplatform.cc --- dw2-ref/dw/fltkplatform.cc 2007-12-16 16:02:02.000000000 +0000 +++ dw2-cur/dw/fltkplatform.cc 2007-12-16 22:23:40.000000000 +0000 @@ -142,9 +142,10 @@ FltkPlatform::FltkResourceFactory::creat } core::ui::MultiLineTextResource * -FltkPlatform::FltkResourceFactory::createMultiLineTextResource () +FltkPlatform::FltkResourceFactory::createMultiLineTextResource (int cols, + int rows) { - return new ui::FltkMultiLineTextResource (platform); + return new ui::FltkMultiLineTextResource (platform, cols, rows); } core::ui::CheckButtonResource * diff -pru -- dw2-ref/dw/fltkplatform.hh dw2-cur/dw/fltkplatform.hh --- dw2-ref/dw/fltkplatform.hh 2007-12-06 17:29:59.000000000 +0000 +++ dw2-cur/dw/fltkplatform.hh 2007-12-16 22:22:55.000000000 +0000 @@ -70,7 +70,8 @@ private: core::ui::OptionMenuResource *createOptionMenuResource (); core::ui::EntryResource *createEntryResource (int maxLength, bool password); - core::ui::MultiLineTextResource *createMultiLineTextResource (); + core::ui::MultiLineTextResource *createMultiLineTextResource (int cols, + int rows); core::ui::CheckButtonResource *createCheckButtonResource (bool activated); core::ui::RadioButtonResource * diff -pru -- dw2-ref/dw/fltkui.cc dw2-cur/dw/fltkui.cc --- dw2-ref/dw/fltkui.cc 2007-12-16 16:02:02.000000000 +0000 +++ dw2-cur/dw/fltkui.cc 2007-12-16 22:32:49.000000000 +0000 @@ -528,8 +528,10 @@ void FltkEntryResource::setEditable (boo // ---------------------------------------------------------------------- -FltkMultiLineTextResource::FltkMultiLineTextResource (FltkPlatform *platform): - FltkSpecificResource <dw::core::ui::MultiLineTextResource> (platform) +FltkMultiLineTextResource::FltkMultiLineTextResource (FltkPlatform *platform, + int cols, int rows): + FltkSpecificResource <dw::core::ui::MultiLineTextResource> (platform), + numCols(cols), numRows(rows) { initText = NULL; editable = false; @@ -569,11 +571,11 @@ void FltkMultiLineTextResource::sizeRequ if (style) { FltkFont *font = (FltkFont*)style->font; requisition->width = - (int)::fltk::getwidth ("M", 1) * 20 + (int)::fltk::getwidth ("M", 1) * numCols + 2 * RELIEF_X_THICKNESS; requisition->ascent = RELIEF_Y_THICKNESS; requisition->descent = - (font->ascent + font->descent) * 10 + RELIEF_Y_THICKNESS; + (font->ascent + font->descent) * numRows + RELIEF_Y_THICKNESS; } else { requisition->width = 1; requisition->ascent = 1; diff -pru -- dw2-ref/dw/fltkui.hh dw2-cur/dw/fltkui.hh --- dw2-ref/dw/fltkui.hh 2007-12-16 16:02:02.000000000 +0000 +++ dw2-cur/dw/fltkui.hh 2007-12-16 22:20:40.000000000 +0000 @@ -319,6 +319,7 @@ class FltkMultiLineTextResource: private: const char *initText; bool editable; + int numCols, numRows; static void widgetCallback (::fltk::Widget *widget, void *data); @@ -326,7 +327,7 @@ protected: ::fltk::Widget *createNewWidget (core::Allocation *allocation); public: - FltkMultiLineTextResource (FltkPlatform *platform); + FltkMultiLineTextResource (FltkPlatform *platform, int cols, int rows); ~FltkMultiLineTextResource (); void sizeRequest (core::Requisition *requisition); diff -pru -- dw2-ref/dw/ui.hh dw2-cur/dw/ui.hh --- dw2-ref/dw/ui.hh 2007-10-06 23:03:01.000000000 +0100 +++ dw2-cur/dw/ui.hh 2007-12-16 22:19:32.000000000 +0000 @@ -537,7 +537,8 @@ public: virtual OptionMenuResource *createOptionMenuResource () = 0; virtual EntryResource *createEntryResource (int maxLength, bool password) = 0; - virtual MultiLineTextResource *createMultiLineTextResource () = 0; + virtual MultiLineTextResource *createMultiLineTextResource (int cols, + int rows) = 0; virtual CheckButtonResource *createCheckButtonResource (bool activated) = 0; virtual RadioButtonResource *createRadioButtonResource (RadioButtonResource *groupedWith, diff -pru -- dw2-ref/test/dw_ui_test.cc dw2-cur/test/dw_ui_test.cc --- dw2-ref/test/dw_ui_test.cc 2007-12-16 16:02:03.000000000 +0000 +++ dw2-cur/test/dw_ui_test.cc 2007-12-16 22:24:19.000000000 +0000 @@ -84,7 +84,7 @@ int main(int argc, char **argv) EntryResource *entryres2 = layout->getResourceFactory()->createEntryResource (10, true); MultiLineTextResource *textres = - layout->getResourceFactory()->createMultiLineTextResource (); + layout->getResourceFactory()->createMultiLineTextResource (15,3); RadioButtonResource *radiores1 = layout->getResourceFactory()->createRadioButtonResource (NULL, false); RadioButtonResource *radiores2 =
On Sun, Dec 16, 2007 at 10:56:28PM +0000, Jeremy Henty (ie. *me*) wrote:
OK, here's the patch to dw2. I'll follow up with the (extremely short) patch to dillo2.
Following up as promised... Jeremy Henty diff -pru -- dillo2-ref/src/html.cc dillo2-cur/src/html.cc --- dillo2-ref/src/html.cc 2007-12-16 22:15:06.000000000 +0000 +++ dillo2-cur/src/html.cc 2007-12-16 22:25:40.000000000 +0000 @@ -4287,7 +4287,8 @@ static void Html_tag_open_textarea(Dillo name = dStrdup(attrbuf); MultiLineTextResource *textres = - HT2LT(html)->getResourceFactory()->createMultiLineTextResource (); + HT2LT(html)->getResourceFactory()->createMultiLineTextResource (cols, + rows); Widget *widget; Embed *embed;
On Sun, Dec 16, 2007 at 11:08:06PM +0000, Jeremy Henty wrote:
On Sun, Dec 16, 2007 at 10:56:28PM +0000, Jeremy Henty (ie. *me*) wrote:
OK, here's the patch to dw2. I'll follow up with the (extremely short) patch to dillo2.
Following up as promised...
Committed. Please note that the multiline widget should be embedded inside a scroller. Something like what firefox does with the attached page. Disclaimer: I haven't checked whether this is easy or not! :-) -- Cheers Jorge.-
On Sun, Dec 16, 2007 at 10:56:28PM +0000, Jeremy Henty wrote:
On Sun, Dec 16, 2007 at 08:19:57PM +0100, Johannes Hofmann wrote:
I would do it as it is done for the maxLength and password members of FltkEntryResource: Add parameters to createMultiLineTextResource() and store the values in private members of FltkMultiLineTextResource.
OK, here's the patch to dw2. I'll follow up with the (extremely short) patch to dillo2.
Committed.
How should extra stuff like word-wrap be supported? More arguments to the constructor or some other API?
I think something akin to setText, getText is enough. -- Cheers Jorge.-
On Sun, Dec 16, 2007 at 04:58:38PM +0000, Jeremy Henty wrote:
On Sun, Dec 16, 2007 at 09:53:06AM -0300, Jorge Arellano Cid wrote:
BTW, I decided to bind it to the html parser ...
Hey, *I* wanted to do that! Why are you spoiling my fun? :-) Guess I'll have to look at selections instead.
There was a small chance of you still hesitant to dig in the parser... I'll happily expect the full patch for the SELECT element! :-)
The next time you visit a form with a TEXTAREA, it will show! :-)
Which means I can use Dillo to post flamebait to blogs. Clearly a great milestone has been passed! :-)
I'm afraid that's not yet the case.
Please test and polish to full functionality.
Text is not yet submitted, the enter key doesn't work as enter key when the textarea is selected, no word wrapping, rows&columns...
OK, I'm looking at adding the rows and columns parameters. It should be easy, except that I'm not sure which class to add the extra members to. Options are:
1) dw::core::ui::MultiLineTextResource 2) dw::fltk::ui::FltkMultiLineTextResource
I'm inclined to say 2), since I don't like the idea of hardwiring this API into the base class. Do you agree?
From a distance, to me, it looks like the idea is to have MultiLineTextResource as an abstraction that can have different potential implementations (as FLTK2, GTK2, etc). If this is correct, FltkMultiLineTextResource is the implementation of that API in FLTK2. Now, I see no problem in implementing it in FltkMultiLineTextResource to test and then to decide what general API should go (or not) in the base class. -- Cheers Jorge.-
participants (3)
-
jcid@dillo.org
-
Johannes.Hofmann@gmx.de
-
onepoint@starurchin.org