Mercurial > dillo_port1.3
annotate test/dw_anchors_test.cc @ 2016:8cf59505bd0a
tests cleanup
author | corvid <corvid@lavabit.com> |
---|---|
date | Sat, 14 May 2011 06:45:42 +0000 |
parents | bfb8bc9ddf62 |
children | 16e52ecf20a8 |
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 | |
22 #include <ctype.h> | |
1832 | 23 #include <FL/Fl_Window.H> |
24 #include <FL/Fl.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 lout::container::typed; | |
32 using namespace dw; | |
33 using namespace dw::core; | |
34 using namespace dw::core::style; | |
35 using namespace dw::fltk; | |
36 | |
37 static FltkPlatform *platform; | |
38 static Layout *layout; | |
1832 | 39 static Fl_Window *window; |
347 | 40 static FltkViewport *viewport; |
41 static Style *topWidgetStyle, *widgetStyle, *wordStyle, *headingStyle; | |
42 static Textblock *topTextblock = NULL; | |
43 static int textblockNo = 0; | |
44 | |
45 static const char *numbers[10] = { | |
46 "one", "two", "three", "four", "five", | |
47 "six", "seven", "eight", "nine", "ten" | |
48 }; | |
49 | |
1832 | 50 static void anchorCallback (Fl_Widget *widget, void *data) |
347 | 51 { |
52 layout->setAnchor (numbers[(long)data]); | |
53 } | |
54 | |
55 static void textTimeout (void *data) | |
56 { | |
57 Textblock *oldTop = topTextblock; | |
58 topTextblock = new Textblock (false); | |
1326 | 59 |
347 | 60 if (oldTop) { |
61 oldTop->addLinebreak (wordStyle); | |
62 oldTop->addWidget (topTextblock, widgetStyle); | |
63 } else { | |
64 topTextblock->setStyle (topWidgetStyle); | |
65 layout->setWidget (topTextblock); | |
66 } | |
67 | |
68 topTextblock->addAnchor (numbers[textblockNo], headingStyle); | |
69 | |
70 char buf[16]; | |
71 strcpy (buf, numbers[textblockNo]); | |
72 buf[0] = toupper (buf[0]); | |
73 topTextblock->addText (buf, headingStyle); | |
74 topTextblock->addParbreak (5, headingStyle); | |
1326 | 75 |
347 | 76 for (int i = 0; i < 30; i++) { |
77 strcpy (buf, numbers[textblockNo]); | |
78 if (i == 0) | |
79 buf[0] = toupper (buf[0]); | |
80 strcat (buf, i == 29 ? "." : ","); | |
81 | |
82 topTextblock->addText (buf, wordStyle); | |
83 topTextblock->addSpace (wordStyle); | |
84 } | |
85 | |
86 topTextblock->flush (); | |
1326 | 87 |
347 | 88 textblockNo++; |
89 if (textblockNo < 10) | |
1832 | 90 Fl::repeat_timeout (1, textTimeout, NULL); |
347 | 91 |
92 } | |
93 | |
94 int main(int argc, char **argv) | |
95 { | |
96 char *buttonLabel[10]; | |
97 | |
98 platform = new FltkPlatform (); | |
99 layout = new Layout (platform); | |
100 | |
1832 | 101 window = new Fl_Window(250, 200, "Dw Anchors Test"); |
2012
bfb8bc9ddf62
Avoid lots of flicker while resizing the window
Jorge Arellano Cid <jcid@dillo.org>
parents:
2010
diff
changeset
|
102 window->box(FL_NO_BOX); |
347 | 103 window->begin(); |
104 | |
105 viewport = new FltkViewport (50, 0, 200, 200); | |
2010
c60462acb9cf
Fix for dw_anchors_test.cc and dw_find_test.cc
Jorge Arellano Cid <jcid@dillo.org>
parents:
1832
diff
changeset
|
106 viewport->end(); |
347 | 107 layout->attachView (viewport); |
108 | |
109 for (int i = 0; i < 10; i++) { | |
110 char buf[16]; | |
111 strcpy (buf, numbers[i]); | |
112 buf[0] = toupper (buf[0]); | |
113 buttonLabel[i] = strdup(buf); | |
1832 | 114 Fl_Button *button = new Fl_Button(0, 20 * i, 50, 20, buttonLabel[i]); |
347 | 115 button->callback (anchorCallback, (void*)i); |
1832 | 116 button->when (FL_WHEN_RELEASE); |
347 | 117 } |
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:
1326
diff
changeset
|
124 fontAttrs.letterSpacing = 0; |
2016 | 125 fontAttrs.fontVariant = FONT_VARIANT_NORMAL; |
347 | 126 |
127 StyleAttrs styleAttrs; | |
128 styleAttrs.initValues (); | |
1832 | 129 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs); |
347 | 130 styleAttrs.margin.setVal (5); |
677
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
131 styleAttrs.color = Color::create (layout, 0x000000); |
b6ef23efdac7
always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
347
diff
changeset
|
132 styleAttrs.backgroundColor = Color::create (layout, 0xffffff); |
347 | 133 topWidgetStyle = Style::create (layout, &styleAttrs); |
134 | |
135 styleAttrs.margin.left = 20; | |
136 styleAttrs.margin.right = 0; | |
137 styleAttrs.backgroundColor = NULL; | |
138 widgetStyle = Style::create (layout, &styleAttrs); | |
139 | |
140 styleAttrs.margin.left = 0; | |
141 wordStyle = Style::create (layout, &styleAttrs); | |
142 | |
143 fontAttrs.size = 28; | |
144 fontAttrs.weight = 700; | |
1832 | 145 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs); |
347 | 146 headingStyle = Style::create (layout, &styleAttrs); |
147 | |
1832 | 148 Fl::add_timeout (0, textTimeout, NULL); |
347 | 149 |
150 window->resizable(viewport); | |
151 window->show(); | |
152 | |
1832 | 153 int errorCode = Fl::run(); |
347 | 154 |
155 topWidgetStyle->unref (); | |
156 widgetStyle->unref (); | |
157 wordStyle->unref (); | |
158 headingStyle->unref (); | |
159 for (int i = 0; i < 10; i++) | |
2016 | 160 free(buttonLabel[i]); |
347 | 161 delete layout; |
162 | |
163 return errorCode; | |
164 } |