Dillo v3.1.1-99-gf3103cc4
Loading...
Searching...
No Matches
dw_ui_test.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22
23#include <FL/Fl.H>
24#include <FL/Fl_Window.H>
25
26#include "dw/core.hh"
27#include "dw/fltkcore.hh"
28#include "dw/fltkviewport.hh"
29#include "dw/table.hh"
30#include "dw/textblock.hh"
31#include "dw/ui.hh"
32#include "form.hh"
33
34using namespace lout::object;
35using namespace lout::container::typed;
36using namespace dw;
37using namespace dw::core;
38using namespace dw::core::style;
39using namespace dw::core::ui;
40using namespace dw::fltk;
41
42int main(int argc, char **argv)
43{
46
47 Fl_Window *window = new Fl_Window(400, 400, "Dw UI Test");
48 window->box(FL_NO_BOX);
49 window->begin();
50
51 FltkViewport *viewport = new FltkViewport (0, 0, 400, 400);
53
54 StyleAttrs styleAttrs;
55 styleAttrs.initValues ();
56 styleAttrs.margin.setVal (5);
57 styleAttrs.color = Color::create (layout, 0x000000);
58 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
59
60 FontAttrs fontAttrs;
61 fontAttrs.name = "Helvetica";
62 fontAttrs.size = 14;
63 fontAttrs.weight = 400;
64 fontAttrs.style = FONT_STYLE_NORMAL;
65 fontAttrs.letterSpacing = 0;
67 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
68
69 Style *tableStyle = Style::create (&styleAttrs);
70
71 Table *table = new Table (false);
72 table->setStyle (tableStyle);
73 layout->setWidget (table);
74
75 tableStyle->unref();
76
77 styleAttrs.backgroundColor = NULL;
78 styleAttrs.margin.setVal (0);
79
80 Style *cellStyle = Style::create (&styleAttrs);
81
82 // First of all, the resources. Later, they are embedded into the
83 // widget tree.
84 EntryResource *entryres1 =
85 layout->getResourceFactory()->createEntryResource (10, false, NULL,NULL);
86 entryres1->setText ("Hi!");
87 EntryResource *entryres2 =
89 "password field!");
90 MultiLineTextResource *textres =
92 "textarea placeholder!");
93 RadioButtonResource *radiores1 =
95 RadioButtonResource *radiores2 =
97 false);
98 CheckButtonResource *checkres =
100 SelectionResource *selres[2];
104 LabelButtonResource *buttonres =
106
107 // Note on complex buttons: before any operations on the widget, which
108 // need a layout, the complex button resource should be created, since
109 // then, a layout and a platform are instantiated.
110 Textblock *cbuttontext = new Textblock(false);
111 ComplexButtonResource *cbuttonres =
113 true);
114 cbuttontext->setStyle (cellStyle);
115 cbuttontext->addText ("Run (complex)!", cellStyle);
116 cbuttontext->flush ();
117
118 // The entry resources are put into a special handler, which is
119 // also a receiver for the button resources.
120 form::Form *form = new form::Form();
121 form->addTextResource ("val1", entryres1);
122 form->addTextResource ("val2", entryres2);
123 form->addTextResource ("text", textres);
124 const char *radiovalues[] = { "radio1", "radio2", NULL };
125 form->addRadioButtonResource ("val3", radiores1, radiovalues);
126 form->addCheckButtonResource ("check", checkres);
127 const char *selvalues[] = { "i1", "g1", "i11", "i12", "i13", "(pop)", "i2",
128 "g2", "i21", "i22", "i23", "(pop)", "i3", NULL};
129 form->addSelectionResource ("val4", selres[0], selvalues);
130 form->addSelectionResource ("val5", selres[1], selvalues);
131 form->addButtonResource ("button", buttonres, "Run!");
132 form->addButtonResource ("cbutton", cbuttonres, "cbuttonval");
133
134 // Create the widgets.
135 table->addRow (cellStyle);
136
137 Textblock *label1 = new Textblock(false);
138 label1->setStyle (cellStyle);
139 table->addCell (label1, 1, 1);
140 label1->addText ("val1 = ", cellStyle);
141 label1->flush ();
142
143 Embed *input1 = new Embed (entryres1);
144 input1->setStyle (cellStyle);
145 table->addCell (input1, 1, 1);
146
147 table->addRow (cellStyle);
148
149 Textblock *label2 = new Textblock(false);
150 label2->setStyle (cellStyle);
151 table->addCell (label2, 1, 1);
152 label2->addText ("val2 = ", cellStyle);
153 label2->flush ();
154
155 Embed *input2 = new Embed (entryres2);
156 input2->setStyle (cellStyle);
157 table->addCell (input2, 1, 1);
158
159 table->addRow (cellStyle);
160
161 Textblock *label = new Textblock(false);
162 label->setStyle (cellStyle);
163 table->addCell (label, 1, 1);
164 label->addText ("text = ", cellStyle);
165 label->flush ();
166
167 Embed *text = new Embed (textres);
168 textres->setText("Hi textarea");
169 text->setStyle (cellStyle);
170 table->addCell (text, 1, 1);
171
172 table->addRow (cellStyle);
173
174 Textblock *radiolabel1 = new Textblock(false);
175 radiolabel1->setStyle (cellStyle);
176 table->addCell (radiolabel1, 2, 1);
177 Embed *radio1 = new Embed (radiores1);
178 radiolabel1->addWidget (radio1, cellStyle);
179 radiolabel1->addText (" radio1", cellStyle);
180 radiolabel1->flush ();
181
182 table->addRow (cellStyle);
183 Textblock *radiolabel2 = new Textblock(false);
184 radiolabel2->setStyle (cellStyle);
185 table->addCell (radiolabel2, 2, 1);
186 Embed *radio2 = new Embed (radiores2);
187 radiolabel2->addWidget (radio2, cellStyle);
188 radiolabel2->addText (" radio2", cellStyle);
189 radiolabel2->flush ();
190
191 table->addRow (cellStyle);
192 Textblock *checklabel = new Textblock(false);
193 checklabel->setStyle (cellStyle);
194 table->addCell (checklabel, 2, 1);
195 Embed *check = new Embed (checkres);
196 checklabel->addWidget (check, cellStyle);
197 checklabel->addText (" check", cellStyle);
198 checklabel->flush ();
199
200 for(int i = 0; i < 2; i++) {
201 table->addRow (cellStyle);
202
203 Embed *sel = new Embed (selres[i]);
204 sel->setStyle (cellStyle);
205 table->addCell (sel, 2, 1);
206
207 selres[i]->addItem("item 1", true, false);
208
209 selres[i]->pushGroup("group 1", true);
210 selres[i]->addItem("item 1/1", true, false);
211 selres[i]->addItem("item 1/2", true, true);
212 selres[i]->addItem("item 1/3", false, false);
213 selres[i]->popGroup();
214
215 selres[i]->addItem("item 2", false, i == 1);
216
217 selres[i]->pushGroup("group 2", true);
218 selres[i]->addItem("item 2/1", true, false);
219 selres[i]->addItem("item 2/2", true, false);
220 selres[i]->addItem("item 2/3", false, false);
221 selres[i]->popGroup();
222
223 selres[i]->addItem("item 3", false, false);
224 }
225
226 table->addRow (cellStyle);
227 Embed *button = new Embed (buttonres);
228 button->setStyle (cellStyle);
229 table->addCell (button, 2, 1);
230
231 table->addRow (cellStyle);
232 Embed *cbutton = new Embed (cbuttonres);
233 cbutton->setStyle (cellStyle);
234 table->addCell (cbutton, 2, 1);
235
236 cellStyle->unref();
237
238 window->resizable(viewport);
239 window->show();
240 int errorCode = Fl::run();
241
242 delete form;
243 delete layout;
244
245 return errorCode;
246}
int main(void)
Definition bookmarks.c:1613
A Widget for rendering tables.
Definition table.hh:326
void addCell(Widget *widget, int colspan, int rowspan)
Definition table.cc:468
void addRow(core::style::Style *style)
Definition table.cc:584
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addWidget(core::Widget *widget, core::style::Style *style)
Add a widget (word type) to the page.
void addText(const char *text, size_t len, core::style::Style *style)
Add a word to the page structure.
The central class for managing and drawing a widget tree.
Definition layout.hh:17
void attachView(View *view)
Attach a view to the layout.
Definition layout.cc:459
void setWidget(Widget *widget)
Definition layout.cc:433
ui::ResourceFactory * getResourceFactory()
Definition layout.hh:421
virtual void setStyle(style::Style *style)
Change the style of a widget.
Definition widget.cc:1316
void setVal(int val)
Definition style.hh:510
static Color * create(Layout *layout, int color)
Definition style.cc:529
FontVariant fontVariant
Definition style.hh:688
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:444
static Style * create(StyleAttrs *attrs)
Definition style.hh:629
A widget for embedding UI widgets.
Definition ui.hh:224
void setStyle(style::Style *style)
Change the style of a widget.
Definition ui.cc:152
Interface for labelled buttons resources.
Definition ui.hh:400
@ SELECTION_AT_MOST_ONE
At most one item is selected.
Definition ui.hh:503
virtual OptionMenuResource * createOptionMenuResource()=0
virtual EntryResource * createEntryResource(int size, bool password, const char *label, const char *placeholder)=0
virtual MultiLineTextResource * createMultiLineTextResource(int cols, int rows, const char *placeholder)=0
virtual RadioButtonResource * createRadioButtonResource(RadioButtonResource *groupedWith, bool activated)=0
virtual CheckButtonResource * createCheckButtonResource(bool activated)=0
virtual ListResource * createListResource(ListResource::SelectionMode selectionMode, int rows)=0
virtual ComplexButtonResource * createComplexButtonResource(Widget *widget, bool relief)=0
virtual LabelButtonResource * createLabelButtonResource(const char *label)=0
Base interface for dw::core::ui::ListResource and dw::core::ui::OptionMenuResource.
Definition ui.hh:467
virtual void pushGroup(const char *name, bool enabled)=0
virtual void addItem(const char *str, bool enabled, bool selected)=0
virtual void setText(const char *text)=0
Handles HTML form data.
Definition form.hh:19
static Fl_Window * window
static Layout * layout
static FltkPlatform * platform
static FltkViewport * viewport
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
@ FONT_VARIANT_NORMAL
Definition style.hh:333
Anything related to embedded UI widgets is defined here.
Definition core.hh:36
The core of Dw is defined in this namespace.
Definition core.hh:23
This namespace contains FLTK implementations of Dw interfaces.
Dw is in this namespace, or sub namespaces of this one.
Definition form.cc:25
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.
Definition container.hh:387
Here, some common classes (or interfaces) are defined, to standardize the access to other classes.
Definition object.cc:30