Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_find_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#include <FL/Fl_Box.H>
26#include "dw/core.hh"
27#include "dw/fltkcore.hh"
28#include "dw/fltkviewport.hh"
29#include "dw/textblock.hh"
30
31using namespace lout::container::typed;
32using namespace dw;
33using namespace dw::core;
34using namespace dw::core::style;
35using namespace dw::fltk;
36
38static Layout *layout;
39static Fl_Window *window;
41static Fl_Button *findButton, *resetButton;
42static Fl_Widget *resultLabel;
43
44static void findCallback (Fl_Widget *widget, void *data)
45{
46 //switch(layout->search ("worm", true)) {
47 switch(layout->search ("WORM", false, false)) {
49 resultLabel->label("SUCCESS");
50 break;
51
53 resultLabel->label("RESTART");
54 break;
55
57 resultLabel->label("NOT_FOUND");
58 break;
59 }
60
61 resultLabel->redraw ();
62}
63
64static void resetCallback (Fl_Widget *widget, void *data)
65{
67 resultLabel->label("---");
68 resultLabel->redraw ();
69}
70
71int main(int argc, char **argv)
72{
73 platform = new FltkPlatform ();
74 layout = new Layout (platform);
75
76 window = new Fl_Window(200, 300, "Dw Find Test");
77 window->box(FL_NO_BOX);
78 window->begin();
79
80 viewport = new FltkViewport (0, 0, 200, 280);
81 viewport->end();
83
84 findButton = new Fl_Button(0, 280, 50, 20, "Find");
85 findButton->callback (findCallback, NULL);
86 findButton->when (FL_WHEN_RELEASE);
87 findButton->clear_visible_focus ();
88
89 resetButton = new Fl_Button(50, 280, 50, 20, "Reset");
90 resetButton->callback (resetCallback, NULL);
91 resetButton->when (FL_WHEN_RELEASE);
92 resetButton->clear_visible_focus ();
93
94 resultLabel = new Fl_Box(100, 280, 100, 20, "---");
95 resultLabel->box(FL_FLAT_BOX);
96
97 FontAttrs fontAttrs;
98 fontAttrs.name = "Bitstream Charter";
99 fontAttrs.size = 14;
100 fontAttrs.weight = 400;
101 fontAttrs.style = FONT_STYLE_NORMAL;
102 fontAttrs.letterSpacing = 0;
104
105 StyleAttrs styleAttrs;
106 styleAttrs.initValues ();
107 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
108 styleAttrs.margin.setVal (10);
109 styleAttrs.color = Color::create (layout, 0x000000);
110 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
111 Style *topWidgetStyle = Style::create (&styleAttrs);
112
113 styleAttrs.margin.setVal (0);
114 styleAttrs.margin.left = 30;
115 styleAttrs.backgroundColor = NULL;
116 Style *widgetStyle = Style::create (&styleAttrs);
117
118 styleAttrs.margin.left = 0;
119 Style *wordStyle = Style::create (&styleAttrs);
120
121 Textblock *textblock = new Textblock (false);
122 textblock->setStyle (topWidgetStyle);
123 layout->setWidget (textblock);
124
125 Stack <Textblock> *stack = new Stack <Textblock> (false);
126 stack->push (textblock);
127
128 for(int i = 0; i < 10; i++)
129 for(int j = 0; j < 10; j++) {
130 Textblock *current;
131 if(j < 5) {
132 current = new Textblock (false);
133 stack->getTop()->addWidget (current, widgetStyle);
134 stack->push (current);
135 } else {
136 stack->getTop()->flush ();
137 stack->pop ();
138 current = stack->getTop ();
139 }
140
141 current->addText ((i == j ? "worm" : "apple"), wordStyle);
142 current->addLinebreak (wordStyle);
143 }
144
145 stack->getTop()->flush ();
146
148 widgetStyle->unref ();
149 wordStyle->unref ();
150
151 window->resizable(viewport);
152 window->show();
153 int errorCode = Fl::run();
154
155 delete layout;
156
157 return errorCode;
158}
int main(void)
Definition bookmarks.c:1613
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addText(const char *text, size_t len, core::style::Style *style)
Add a word to the page structure.
void addLinebreak(core::style::Style *style)
@ SUCCESS
The next occurrence of the pattern has been found.
Definition findtext.hh:18
@ NOT_FOUND
The patten does not at all occur in the text.
Definition findtext.hh:27
@ RESTART
There is no further occurrence of the pattern, instead, the first occurrence has been selected.
Definition findtext.hh:24
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
FindtextState::Result search(const char *str, bool caseSens, int backwards)
See dw::core::FindtextState::search.
Definition layout.hh:430
void resetSearch()
See dw::core::FindtextState::resetSearch.
Definition layout.hh:435
void setWidget(Widget *widget)
Definition layout.cc:433
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
static Style * wordStyle
static Style * widgetStyle
static Style * topWidgetStyle
static Fl_Button * resetButton
static Fl_Widget * resultLabel
static void findCallback(Fl_Widget *widget, void *data)
static Fl_Window * window
static Layout * layout
static FltkPlatform * platform
static Fl_Button * findButton
static FltkViewport * viewport
static void resetCallback(Fl_Widget *widget, void *data)
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
@ FONT_VARIANT_NORMAL
Definition style.hh:333
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.
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.
Definition container.hh:387