aboutsummaryrefslogtreecommitdiff
path: root/test/dw_ui_test.cc
diff options
context:
space:
mode:
authorjcid <devnull@localhost>2008-09-24 18:44:40 +0200
committerjcid <devnull@localhost>2008-09-24 18:44:40 +0200
commitc377e06400f138325a9a9d43d91a9272691867a1 (patch)
tree49f3ca1c46af11a058a68714899d4137ec717618 /test/dw_ui_test.cc
parent642f9b3e747859a7256ea12fab9f9ed50aa9253a (diff)
- Moved the dw2 tree into dillo2's tree.
Diffstat (limited to 'test/dw_ui_test.cc')
-rw-r--r--test/dw_ui_test.cc241
1 files changed, 241 insertions, 0 deletions
diff --git a/test/dw_ui_test.cc b/test/dw_ui_test.cc
new file mode 100644
index 00000000..5ce949ef
--- /dev/null
+++ b/test/dw_ui_test.cc
@@ -0,0 +1,241 @@
+/*
+ * Dillo Widget
+ *
+ * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+
+#include <fltk/Window.h>
+#include <fltk/run.h>
+
+#include "../dw/core.hh"
+#include "../dw/fltkcore.hh"
+#include "../dw/fltkviewport.hh"
+#include "../dw/table.hh"
+#include "../dw/textblock.hh"
+#include "../dw/ui.hh"
+#include "form.hh"
+
+using namespace lout::object;
+using namespace lout::container::typed;
+using namespace dw;
+using namespace dw::core;
+using namespace dw::core::style;
+using namespace dw::core::ui;
+using namespace dw::fltk;
+
+int main(int argc, char **argv)
+{
+ FltkPlatform *platform = new FltkPlatform ();
+ Layout *layout = new Layout (platform);
+
+ ::fltk::Window *window = new ::fltk::Window(400, 400, "Dw UI Test");
+ window->begin();
+
+ FltkViewport *viewport = new FltkViewport (0, 0, 400, 400);
+ layout->attachView (viewport);
+
+ StyleAttrs styleAttrs;
+ styleAttrs.initValues ();
+ styleAttrs.margin.setVal (5);
+ styleAttrs.color = Color::createSimple (layout, 0x000000);
+ styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff);
+
+ FontAttrs fontAttrs;
+ fontAttrs.name = "Helvetica";
+ fontAttrs.size = 14;
+ fontAttrs.weight = 400;
+ fontAttrs.style = FONT_STYLE_NORMAL;
+ styleAttrs.font = Font::create (layout, &fontAttrs);
+
+ Style *tableStyle = Style::create (layout, &styleAttrs);
+
+ Table *table = new Table (false);
+ table->setStyle (tableStyle);
+ layout->setWidget (table);
+
+ tableStyle->unref();
+
+ styleAttrs.backgroundColor = NULL;
+ styleAttrs.margin.setVal (0);
+
+ Style *cellStyle = Style::create (layout, &styleAttrs);
+
+ // First of all, the resources. Later, they are embedded into the
+ // widget tree.
+ EntryResource *entryres1 =
+ layout->getResourceFactory()->createEntryResource (10, false);
+ entryres1->setText ("Hi!");
+ EntryResource *entryres2 =
+ layout->getResourceFactory()->createEntryResource (10, true);
+ MultiLineTextResource *textres =
+ layout->getResourceFactory()->createMultiLineTextResource (15,3);
+ RadioButtonResource *radiores1 =
+ layout->getResourceFactory()->createRadioButtonResource (NULL, false);
+ RadioButtonResource *radiores2 =
+ layout->getResourceFactory()->createRadioButtonResource (radiores1,
+ false);
+ CheckButtonResource *checkres =
+ layout->getResourceFactory()->createCheckButtonResource (true);
+ SelectionResource *selres[2];
+ selres[0] = layout->getResourceFactory()->createOptionMenuResource ();
+ selres[1] = layout->getResourceFactory()->createListResource
+ (ListResource::SELECTION_AT_MOST_ONE);
+ LabelButtonResource *buttonres =
+ layout->getResourceFactory()->createLabelButtonResource ("Run!");
+
+ // Note on complex buttons: before any operations on the widget, which
+ // need a layout, the complex button resource should be created, since
+ // then, a layout and a platform are instanciated.
+ Textblock *cbuttontext = new Textblock(false);
+ ComplexButtonResource *cbuttonres =
+ layout->getResourceFactory()->createComplexButtonResource (cbuttontext,
+ true);
+ cbuttontext->setStyle (cellStyle);
+ cbuttontext->addText ("Run (complex)!", cellStyle);
+ cbuttontext->flush ();
+
+ // The entry resources are put into a special handler, which is
+ // also a receiver for the button resources.
+ 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);
+ const char *selvalues[] = { "i1", "i11", "i12", "i13", "i2",
+ "i21", "i22", "i23", "i3", NULL };
+ form->addSelectionResource ("val4", selres[0], selvalues);
+ form->addSelectionResource ("val5", selres[1], selvalues);
+ form->addButtonResource ("button", buttonres, "Run!");
+ form->addButtonResource ("cbutton", cbuttonres, "cbuttonval");
+
+ // Create the widgets.
+ table->addRow (cellStyle);
+
+ Textblock *label1 = new Textblock(false);
+ label1->setStyle (cellStyle);
+ table->addCell (label1, 1, 1);
+ label1->addText ("val1 = ", cellStyle);
+ label1->flush ();
+
+ Embed *input1 = new Embed (entryres1);
+ input1->setStyle (cellStyle);
+ table->addCell (input1, 1, 1);
+
+ table->addRow (cellStyle);
+
+ Textblock *label2 = new Textblock(false);
+ label2->setStyle (cellStyle);
+ table->addCell (label2, 1, 1);
+ label2->addText ("val2 = ", cellStyle);
+ label2->flush ();
+
+ Embed *input2 = new Embed (entryres2);
+ input2->setStyle (cellStyle);
+ table->addCell (input2, 1, 1);
+
+ table->addRow (cellStyle);
+
+ Textblock *label = new Textblock(false);
+ label->setStyle (cellStyle);
+ table->addCell (label, 1, 1);
+ label->addText ("text = ", cellStyle);
+ label->flush ();
+
+ Embed *text = new Embed (textres);
+ textres->setText("Hi textarea");
+ text->setStyle (cellStyle);
+ table->addCell (text, 1, 1);
+
+ table->addRow (cellStyle);
+
+ Textblock *radiolabel1 = new Textblock(false);
+ radiolabel1->setStyle (cellStyle);
+ table->addCell (radiolabel1, 2, 1);
+ Embed *radio1 = new Embed (radiores1);
+ radiolabel1->addWidget (radio1, cellStyle);
+ radiolabel1->addText (" radio1", cellStyle);
+ radiolabel1->flush ();
+
+ table->addRow (cellStyle);
+ Textblock *radiolabel2 = new Textblock(false);
+ radiolabel2->setStyle (cellStyle);
+ table->addCell (radiolabel2, 2, 1);
+ Embed *radio2 = new Embed (radiores2);
+ radiolabel2->addWidget (radio2, cellStyle);
+ radiolabel2->addText (" radio2", cellStyle);
+ radiolabel2->flush ();
+
+ table->addRow (cellStyle);
+ Textblock *checklabel = new Textblock(false);
+ checklabel->setStyle (cellStyle);
+ table->addCell (checklabel, 2, 1);
+ Embed *check = new Embed (checkres);
+ checklabel->addWidget (check, cellStyle);
+ checklabel->addText (" check", cellStyle);
+ checklabel->flush ();
+
+ for(int i = 0; i < 2; i++) {
+ table->addRow (cellStyle);
+
+ Embed *sel = new Embed (selres[i]);
+ sel->setStyle (cellStyle);
+ table->addCell (sel, 2, 1);
+
+ selres[i]->addItem("item 1", true, false);
+
+ selres[i]->pushGroup("group 1", true);
+ selres[i]->addItem("item 1/1", true, false);
+ selres[i]->addItem("item 1/2", true, true);
+ selres[i]->addItem("item 1/3", false, false);
+ selres[i]->popGroup();
+
+ selres[i]->addItem("item 2", true, i == 1);
+
+ selres[i]->pushGroup("group 2", false);
+ selres[i]->addItem("item 2/1", true, false);
+ selres[i]->addItem("item 2/2", true, false);
+ selres[i]->addItem("item 2/3", false, false);
+ selres[i]->popGroup();
+
+ selres[i]->addItem("item 3", false, false);
+ }
+
+ table->addRow (cellStyle);
+ Embed *button = new Embed (buttonres);
+ button->setStyle (cellStyle);
+ table->addCell (button, 2, 1);
+
+ table->addRow (cellStyle);
+ Embed *cbutton = new Embed (cbuttonres);
+ cbutton->setStyle (cellStyle);
+ table->addCell (cbutton, 2, 1);
+
+ cellStyle->unref();
+
+ window->resizable(viewport);
+ window->show();
+ int errorCode = ::fltk::run();
+
+ delete form;
+ delete layout;
+
+ return errorCode;
+}