Dillo v3.1.1-11-g8f0909b7
Loading...
Searching...
No Matches
dw_anchors_test.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2023 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22
23#include <ctype.h>
24#include <FL/Fl_Window.H>
25#include <FL/Fl.H>
26
27#include "dw/core.hh"
28#include "dw/fltkcore.hh"
29#include "dw/fltkviewport.hh"
30#include "dw/textblock.hh"
31
32using namespace lout::container::typed;
33using namespace dw;
34using namespace dw::core;
35using namespace dw::core::style;
36using namespace dw::fltk;
37
39static Layout *layout;
40static Fl_Window *window;
43static Textblock *topTextblock = NULL;
44static int textblockNo = 0;
45
46static const char *numbers[10] = {
47 "one", "two", "three", "four", "five",
48 "six", "seven", "eight", "nine", "ten"
49};
50
51static void anchorCallback (Fl_Widget *widget, void *data)
52{
53 layout->setAnchor (numbers[(long)data]);
54}
55
56static void textTimeout (void *data)
57{
58 Textblock *oldTop = topTextblock;
59 topTextblock = new Textblock (false);
60
61 if (oldTop) {
62 oldTop->addLinebreak (wordStyle);
64 } else {
67 }
68
70
71 char buf[16];
72 strcpy (buf, numbers[textblockNo]);
73 buf[0] = lout::misc::AsciiToupper (buf[0]);
76
77 for (int i = 0; i < 30; i++) {
78 strcpy (buf, numbers[textblockNo]);
79 if (i == 0)
80 buf[0] = lout::misc::AsciiToupper (buf[0]);
81 strcat (buf, i == 29 ? "." : ",");
82
85 }
86
88
90 if (textblockNo < 10)
91 Fl::repeat_timeout (1, textTimeout, NULL);
92
93}
94
95int main(int argc, char **argv)
96{
97 char *buttonLabel[10];
98
99 platform = new FltkPlatform ();
100 layout = new Layout (platform);
101
102 window = new Fl_Window(250, 200, "Dw Anchors Test");
103 window->box(FL_NO_BOX);
104 window->begin();
105
106 viewport = new FltkViewport (50, 0, 200, 200);
107 viewport->end();
109
110 for (int i = 0; i < 10; i++) {
111 char buf[16];
112 strcpy (buf, numbers[i]);
113 buf[0] = lout::misc::AsciiToupper (buf[0]);
114 buttonLabel[i] = strdup(buf);
115 Fl_Button *button = new Fl_Button(0, 20 * i, 50, 20, buttonLabel[i]);
116 button->callback (anchorCallback, (void*)(long)i);
117 button->when (FL_WHEN_RELEASE);
118 }
119
120 FontAttrs fontAttrs;
121 fontAttrs.name = "Bitstream Charter";
122 fontAttrs.size = 14;
123 fontAttrs.weight = 400;
124 fontAttrs.style = FONT_STYLE_NORMAL;
125 fontAttrs.letterSpacing = 0;
127
128 StyleAttrs styleAttrs;
129 styleAttrs.initValues ();
130 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
131 styleAttrs.margin.setVal (5);
132 styleAttrs.color = Color::create (layout, 0x000000);
133 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
134 topWidgetStyle = Style::create (&styleAttrs);
135
136 styleAttrs.margin.left = 20;
137 styleAttrs.margin.right = 0;
138 styleAttrs.backgroundColor = NULL;
139 widgetStyle = Style::create (&styleAttrs);
140
141 styleAttrs.margin.left = 0;
142 wordStyle = Style::create (&styleAttrs);
143
144 fontAttrs.size = 28;
145 fontAttrs.weight = 700;
146 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
147 headingStyle = Style::create (&styleAttrs);
148
149 Fl::add_timeout (0, textTimeout, NULL);
150
151 window->resizable(viewport);
152 window->show();
153
154 int errorCode = Fl::run();
155
157 widgetStyle->unref ();
158 wordStyle->unref ();
160 for (int i = 0; i < 10; i++)
161 free(buttonLabel[i]);
162 delete layout;
163
164 return errorCode;
165}
int main(void)
Definition bookmarks.c:1613
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addWidget(core::Widget *widget, core::style::Style *style)
Add a widget (word type) to the page.
void addSpace(core::style::Style *style)
?
bool addAnchor(const char *name, core::style::Style *style)
Add an anchor to the page.
void addText(const char *text, size_t len, core::style::Style *style)
Add a word to the page structure.
void addParbreak(int space, core::style::Style *style)
Cause a paragraph break.
void addLinebreak(core::style::Style *style)
The central class for managing and drawing a widget tree.
Definition layout.hh:17
void attachView(View *view)
Attach a view to the layout.
Definition layout.cc:453
void setWidget(Widget *widget)
Definition layout.cc:431
void setAnchor(const char *anchor)
Sets the anchor to scroll to.
Definition layout.cc:730
virtual void setStyle(style::Style *style)
Change the style of a widget.
Definition widget.cc:1233
void setVal(int val)
Definition style.hh:509
static Color * create(Layout *layout, int color)
Definition style.cc:528
FontVariant fontVariant
Definition style.hh:687
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:443
static Style * create(StyleAttrs *attrs)
Definition style.hh:628
static Style * wordStyle
static Style * widgetStyle
static Fl_Window * window
static const char * numbers[10]
static void textTimeout(void *data)
static Style * topWidgetStyle
static Layout * layout
static Textblock * topTextblock
static int textblockNo
static FltkPlatform * platform
static void anchorCallback(Fl_Widget *widget, void *data)
static Style * headingStyle
static FltkViewport * viewport
Anything related to Dillo Widget styles is defined here.
Definition style.cc:33
@ FONT_VARIANT_NORMAL
Definition style.hh:332
The core of Dw is defined in this namespace.
Definition core.hh:23
This namespace contains FLTK implementations of Dw interfaces.
Dw is in this namespace, or sub namespaces of this one.
This namespace provides thin wrappers, implemented as C++ templates, to gain type-safety.
Definition container.hh:387
int AsciiToupper(char c)
Definition misc.hh:71