Mercurial > dillo_port1.3
annotate test/dw_links2.cc @ 2016:8cf59505bd0a
tests cleanup
author | corvid <corvid@lavabit.com> |
---|---|
date | Sat, 14 May 2011 06:45:42 +0000 |
parents | bfb8bc9ddf62 |
children |
rev | line source |
---|---|
347 | 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 | |
972
d7dbd3dcfa38
Updated the GPL copyright note in the source files
Detlef Riekenberg <wine.dev@web.de>
parents:
677
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
347 | 18 */ |
19 | |
20 | |
21 | |
1832 | 22 #include <FL/Fl.H> |
23 #include <FL/Fl_Window.H> | |
24 #include <FL/Fl_Box.H> | |
347 | 25 |
26 #include "../dw/core.hh" | |
27 #include "../dw/fltkcore.hh" | |
28 #include "../dw/fltkviewport.hh" | |
29 #include "../dw/textblock.hh" | |
30 | |
31 using namespace dw; | |
32 using namespace dw::core; | |
33 using namespace dw::core::style; | |
34 using namespace dw::fltk; | |
35 | |
1375 | 36 class LinkTestReceiver: public Layout::LinkReceiver |
347 | 37 { |
1314 | 38 bool enter (Widget *widget, int link, int img, int x, int y); |
39 bool press (Widget *widget, int link, int img, int x, int y, | |
40 EventButton *event); | |
41 bool release (Widget *widget, int link, int img, int x, int y, | |
42 EventButton *event); | |
43 bool click (Widget *widget, int link, int img, int x, int y, | |
44 EventButton *event); | |
347 | 45 }; |
46 | |
1314 | 47 bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y) |
347 | 48 { |
49 printf ("enter: %d\n", link); | |
50 return true; | |
51 } | |
52 | |
1314 | 53 bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y, |
347 | 54 EventButton *event) |
55 { | |
56 printf ("press: %d\n", link); | |
57 return true; | |
58 } | |
59 | |
1314 | 60 bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y, |
347 | 61 EventButton *event) |
62 { | |
63 printf ("release: %d\n", link); | |
64 return true; | |
65 } | |
66 | |
1314 | 67 bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y, |
347 | 68 EventButton *event) |
69 { | |
70 printf ("click: %d\n", link); | |
71 return true; | |
72 } | |
73 | |
74 int main(int argc, char **argv) | |
75 { | |
76 int MainIdx; | |
77 int ww = 200, wh = 300, lh = 24; | |
78 | |
79 FltkPlatform *platform = new FltkPlatform (); | |
80 Layout *layout = new Layout (platform); | |
81 | |
1832 | 82 Fl_Window *window = new Fl_Window(200, 300, "Dw Links2"); |
2012
bfb8bc9ddf62
Avoid lots of flicker while resizing the window
Jorge Arellano Cid <jcid@dillo.org>
parents:
1832
diff
changeset
|
83 window->box(FL_NO_BOX); |
347 | 84 window->begin(); |
1832 | 85 Fl_Widget *Panel = new Fl_Box(0, 0, ww, lh, "CONTROL PANEL"); |
347 | 86 |
1832 | 87 Panel->color(FL_GRAY_RAMP + 3); |
88 Panel->labelcolor(FL_WHITE); | |
2012
bfb8bc9ddf62
Avoid lots of flicker while resizing the window
Jorge Arellano Cid <jcid@dillo.org>
parents:
1832
diff
changeset
|
89 Panel->box(FL_FLAT_BOX); |
1832 | 90 Fl_Widget *Main = new Fl_Box(0, lh, ww, wh - 2*lh, "MAIN RENDERING AREA"); |
91 Main->color(FL_GRAY_RAMP + 4); | |
92 Main->labelcolor(FL_WHITE); | |
347 | 93 MainIdx = window->find(Main); |
94 /* status bar */ | |
1832 | 95 Fl_Widget *Bar = new Fl_Box(0, wh - lh, 200, lh, "STATUS BAR..."); |
96 Bar->color(FL_GRAY_RAMP + 3); | |
97 Bar->labelcolor(FL_WHITE); | |
2012
bfb8bc9ddf62
Avoid lots of flicker while resizing the window
Jorge Arellano Cid <jcid@dillo.org>
parents:
1832
diff
changeset
|
98 Bar->box(FL_FLAT_BOX); |
347 | 99 |
100 window->resizable(Main); | |
101 window->end(); | |
102 | |
103 // | |
104 // Create the main Dw and add some text there. | |
105 // | |
106 window->remove(MainIdx); | |
107 window->begin(); | |
108 | |
109 FltkViewport *viewport = new FltkViewport (0, lh, ww, wh - 2*lh); | |
110 layout->attachView (viewport); | |
111 | |
112 window->end(); | |
113 | |
114 | |
115 StyleAttrs styleAttrs; | |
116 styleAttrs.initValues (); | |
117 styleAttrs.margin.setVal (5); | |
118 | |
119 FontAttrs fontAttrs; | |
120 fontAttrs.name = "Bitstream Charter"; | |
121 fontAttrs.size = 14; | |
122 fontAttrs.weight = 400; | |
123 fontAttrs.style = FONT_STYLE_NORMAL; | |
1462
8de487d495f7
initialize fontAttrs.letterSpacing in test programs
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1375
diff
changeset
|
124 fontAttrs.letterSpacing = 0; |
2016 | 125 fontAttrs.fontVariant = FONT_VARIANT_NORMAL; |
1832 | 126 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs); |
347 | 127 |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
128 styleAttrs.color = Color::create (layout, 0x000000); |
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
129 styleAttrs.backgroundColor = Color::create (layout, 0xffffff); |
347 | 130 |
131 Style *widgetStyle = Style::create (layout, &styleAttrs); | |
132 | |
133 Textblock *textblock = new Textblock (false); | |
134 textblock->setStyle (widgetStyle); | |
135 layout->setWidget (textblock); | |
136 | |
1375 | 137 layout->connectLink (new LinkTestReceiver ()); |
347 | 138 |
139 widgetStyle->unref(); | |
140 | |
141 styleAttrs.margin.setVal (0); | |
142 styleAttrs.backgroundColor = NULL; | |
143 styleAttrs.cursor = CURSOR_TEXT; | |
144 | |
145 Style *wordStyle = Style::create (layout, &styleAttrs); | |
146 | |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
147 styleAttrs.color = Color::create (layout, 0x0000ff); |
347 | 148 styleAttrs.textDecoration = TEXT_DECORATION_UNDERLINE; |
149 styleAttrs.cursor = CURSOR_POINTER; | |
1326 | 150 |
347 | 151 for(int i = 1; i <= 30; i++) { |
152 char buf[4]; | |
153 sprintf(buf, "%d.", i); | |
154 | |
155 const char *words1[] = { | |
156 "This", "is", "the", buf, "paragraph.", | |
157 "Here", "comes", "some", "more", "text", | |
158 "to", "demonstrate", "word", "wrapping.", | |
159 NULL }; | |
160 const char *words2[] = { | |
161 "Click", "here", "for", "more..", NULL }; | |
162 | |
163 for(int j = 0; words1[j]; j++) { | |
164 textblock->addText (words1[j], wordStyle); | |
165 textblock->addSpace(wordStyle); | |
166 } | |
1326 | 167 |
347 | 168 styleAttrs.x_link = i; |
169 Style *linkStyle = Style::create (layout, &styleAttrs); | |
1326 | 170 |
347 | 171 for(int j = 0; words2[j]; j++) { |
172 textblock->addText (words2[j], linkStyle); | |
173 textblock->addSpace(wordStyle); | |
174 } | |
1326 | 175 |
347 | 176 linkStyle->unref (); |
177 | |
178 textblock->addParbreak(10, wordStyle); | |
179 } | |
180 | |
181 wordStyle->unref(); | |
182 | |
183 textblock->flush (); | |
184 | |
185 window->resizable(viewport); | |
186 window->show(); | |
1832 | 187 int errorCode = Fl::run(); |
347 | 188 |
189 delete layout; | |
190 | |
191 return errorCode; | |
192 } |