1 /*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21
22 #include <FL/Fl.H>
23 #include <FL/Fl_Window.H>
24 #include <FL/Fl_Box.H>
25 #include "../dw/core.hh"
26 #include "../dw/fltkcore.hh"
27 #include "../dw/fltkviewport.hh"
28 #include "../dw/textblock.hh"
29
30 using namespace lout::container::typed;
31 using namespace dw;
32 using namespace dw::core;
33 using namespace dw::core::style;
34 using namespace dw::fltk;
35
36 static FltkPlatform *platform;
37 static Layout *layout;
38 static Fl_Window *window;
39 static FltkViewport *viewport;
40 static Fl_Button *findButton, *resetButton;
41 static Fl_Widget *resultLabel;
42
findCallback(Fl_Widget * widget,void * data)43 static void findCallback (Fl_Widget *widget, void *data)
44 {
45 //switch(layout->search ("worm", true)) {
46 switch(layout->search ("WORM", false, false)) {
47 case FindtextState::SUCCESS:
48 resultLabel->label("SUCCESS");
49 break;
50
51 case FindtextState::RESTART:
52 resultLabel->label("RESTART");
53 break;
54
55 case FindtextState::NOT_FOUND:
56 resultLabel->label("NOT_FOUND");
57 break;
58 }
59
60 resultLabel->redraw ();
61 }
62
resetCallback(Fl_Widget * widget,void * data)63 static void resetCallback (Fl_Widget *widget, void *data)
64 {
65 layout->resetSearch ();
66 resultLabel->label("---");
67 resultLabel->redraw ();
68 }
69
main(int argc,char ** argv)70 int main(int argc, char **argv)
71 {
72 platform = new FltkPlatform ();
73 layout = new Layout (platform);
74
75 window = new Fl_Window(200, 300, "Dw Find Test");
76 window->box(FL_NO_BOX);
77 window->begin();
78
79 viewport = new FltkViewport (0, 0, 200, 280);
80 viewport->end();
81 layout->attachView (viewport);
82
83 findButton = new Fl_Button(0, 280, 50, 20, "Find");
84 findButton->callback (findCallback, NULL);
85 findButton->when (FL_WHEN_RELEASE);
86 findButton->clear_visible_focus ();
87
88 resetButton = new Fl_Button(50, 280, 50, 20, "Reset");
89 resetButton->callback (resetCallback, NULL);
90 resetButton->when (FL_WHEN_RELEASE);
91 resetButton->clear_visible_focus ();
92
93 resultLabel = new Fl_Box(100, 280, 100, 20, "---");
94 resultLabel->box(FL_FLAT_BOX);
95
96 FontAttrs fontAttrs;
97 fontAttrs.name = "Bitstream Charter";
98 fontAttrs.size = 14;
99 fontAttrs.weight = 400;
100 fontAttrs.style = FONT_STYLE_NORMAL;
101 fontAttrs.letterSpacing = 0;
102 fontAttrs.fontVariant = FONT_VARIANT_NORMAL;
103
104 StyleAttrs styleAttrs;
105 styleAttrs.initValues ();
106 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
107 styleAttrs.margin.setVal (10);
108 styleAttrs.color = Color::create (layout, 0x000000);
109 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
110 Style *topWidgetStyle = Style::create (&styleAttrs);
111
112 styleAttrs.margin.setVal (0);
113 styleAttrs.margin.left = 30;
114 styleAttrs.backgroundColor = NULL;
115 Style *widgetStyle = Style::create (&styleAttrs);
116
117 styleAttrs.margin.left = 0;
118 Style *wordStyle = Style::create (&styleAttrs);
119
120 Textblock *textblock = new Textblock (false);
121 textblock->setStyle (topWidgetStyle);
122 layout->setWidget (textblock);
123
124 Stack <Textblock> *stack = new Stack <Textblock> (false);
125 stack->push (textblock);
126
127 for(int i = 0; i < 10; i++)
128 for(int j = 0; j < 10; j++) {
129 Textblock *current;
130 if(j < 5) {
131 current = new Textblock (false);
132 stack->getTop()->addWidget (current, widgetStyle);
133 stack->push (current);
134 } else {
135 stack->getTop()->flush ();
136 stack->pop ();
137 current = stack->getTop ();
138 }
139
140 current->addText ((i == j ? "worm" : "apple"), wordStyle);
141 current->addLinebreak (wordStyle);
142 }
143
144 stack->getTop()->flush ();
145
146 topWidgetStyle->unref ();
147 widgetStyle->unref ();
148 wordStyle->unref ();
149
150 window->resizable(viewport);
151 window->show();
152 int errorCode = Fl::run();
153
154 delete layout;
155
156 return errorCode;
157 }
158