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