annotate test/dw_anchors_test.cc @ 2104:3e7e5395f0bc

non-ASCII keybindings Alexander Voigt has kindly done some testing, and it seems that this makes bindings to most keys on a German keyboard possible -- except those that need AltGr don't work yet.
author corvid <corvid@lavabit.com>
date Thu, 23 Jun 2011 19:24:11 +0000
parents 16e52ecf20a8
children
rev   line source
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
1 /*
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
2 * Dillo Widget
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
3 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
5 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
9 * (at your option) any later version.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
10 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
14 * GNU General Public License for more details.
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
15 *
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
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
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
18 */
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
19
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
20
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
21
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
22 #include <ctype.h>
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
23 #include <FL/Fl_Window.H>
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
24 #include <FL/Fl.H>
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
25
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
26 #include "../dw/core.hh"
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
27 #include "../dw/fltkcore.hh"
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
28 #include "../dw/fltkviewport.hh"
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
29 #include "../dw/textblock.hh"
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
30
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
31 using namespace lout::container::typed;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
32 using namespace dw;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
33 using namespace dw::core;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
34 using namespace dw::core::style;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
35 using namespace dw::fltk;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
36
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
37 static FltkPlatform *platform;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
38 static Layout *layout;
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
39 static Fl_Window *window;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
40 static FltkViewport *viewport;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
41 static Style *topWidgetStyle, *widgetStyle, *wordStyle, *headingStyle;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
42 static Textblock *topTextblock = NULL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
43 static int textblockNo = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
44
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
45 static const char *numbers[10] = {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
46 "one", "two", "three", "four", "five",
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
47 "six", "seven", "eight", "nine", "ten"
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
48 };
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
49
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
50 static void anchorCallback (Fl_Widget *widget, void *data)
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
51 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
52 layout->setAnchor (numbers[(long)data]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
53 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
54
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
55 static void textTimeout (void *data)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
56 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
57 Textblock *oldTop = topTextblock;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
58 topTextblock = new Textblock (false);
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1314
diff changeset
59
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
60 if (oldTop) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
61 oldTop->addLinebreak (wordStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
62 oldTop->addWidget (topTextblock, widgetStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
63 } else {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
64 topTextblock->setStyle (topWidgetStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
65 layout->setWidget (topTextblock);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
66 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
67
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
68 topTextblock->addAnchor (numbers[textblockNo], headingStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
69
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
70 char buf[16];
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
71 strcpy (buf, numbers[textblockNo]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
72 buf[0] = toupper (buf[0]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
73 topTextblock->addText (buf, headingStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
74 topTextblock->addParbreak (5, headingStyle);
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1314
diff changeset
75
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
76 for (int i = 0; i < 30; i++) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
77 strcpy (buf, numbers[textblockNo]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
78 if (i == 0)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
79 buf[0] = toupper (buf[0]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
80 strcat (buf, i == 29 ? "." : ",");
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
81
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
82 topTextblock->addText (buf, wordStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
83 topTextblock->addSpace (wordStyle);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
84 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
85
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
86 topTextblock->flush ();
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1314
diff changeset
87
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
88 textblockNo++;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
89 if (textblockNo < 10)
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
90 Fl::repeat_timeout (1, textTimeout, NULL);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
91
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
92 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
93
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
94 int main(int argc, char **argv)
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
95 {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
96 char *buttonLabel[10];
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
97
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
98 platform = new FltkPlatform ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
99 layout = new Layout (platform);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
100
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
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
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
103 window->begin();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
104
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
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
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
107 layout->attachView (viewport);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
108
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
109 for (int i = 0; i < 10; i++) {
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
110 char buf[16];
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
111 strcpy (buf, numbers[i]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
112 buf[0] = toupper (buf[0]);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
113 buttonLabel[i] = strdup(buf);
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
114 Fl_Button *button = new Fl_Button(0, 20 * i, 50, 20, buttonLabel[i]);
2103
16e52ecf20a8 Eliminated a pack of 22 compiler warnings (gcc-4.6.1 amd64)
Jorge Arellano Cid <jcid@dillo.org>
parents: 2016
diff changeset
115 button->callback (anchorCallback, (void*)(long)i);
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
116 button->when (FL_WHEN_RELEASE);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
117 }
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
118
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
119 FontAttrs fontAttrs;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
120 fontAttrs.name = "Bitstream Charter";
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
121 fontAttrs.size = 14;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
122 fontAttrs.weight = 400;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
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
8cf59505bd0a tests cleanup
corvid <corvid@lavabit.com>
parents: 2012
diff changeset
125 fontAttrs.fontVariant = FONT_VARIANT_NORMAL;
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
126
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
127 StyleAttrs styleAttrs;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
128 styleAttrs.initValues ();
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
129 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
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
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
133 topWidgetStyle = Style::create (layout, &styleAttrs);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
134
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
135 styleAttrs.margin.left = 20;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
136 styleAttrs.margin.right = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
137 styleAttrs.backgroundColor = NULL;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
138 widgetStyle = Style::create (layout, &styleAttrs);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
139
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
140 styleAttrs.margin.left = 0;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
141 wordStyle = Style::create (layout, &styleAttrs);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
142
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
143 fontAttrs.size = 28;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
144 fontAttrs.weight = 700;
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
145 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
146 headingStyle = Style::create (layout, &styleAttrs);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
147
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
148 Fl::add_timeout (0, textTimeout, NULL);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
149
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
150 window->resizable(viewport);
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
151 window->show();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
152
1832
corvid <corvid@lavabit.com>
parents: 1462
diff changeset
153 int errorCode = Fl::run();
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
154
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
155 topWidgetStyle->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
156 widgetStyle->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
157 wordStyle->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
158 headingStyle->unref ();
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
159 for (int i = 0; i < 10; i++)
2016
8cf59505bd0a tests cleanup
corvid <corvid@lavabit.com>
parents: 2012
diff changeset
160 free(buttonLabel[i]);
347
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
161 delete layout;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
162
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
163 return errorCode;
e5955ab8dafb - Moved the dw2 tree into dillo2's tree.
jcid
parents:
diff changeset
164 }