Dillo v3.1.1-46-g8a360e32
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 "dlib/dlib.h"
28#include "dw/core.hh"
29#include "dw/fltkcore.hh"
30#include "dw/fltkviewport.hh"
31#include "dw/textblock.hh"
32
33using namespace lout::container::typed;
34using namespace dw;
35using namespace dw::core;
36using namespace dw::core::style;
37using namespace dw::fltk;
38
40static Layout *layout;
41static Fl_Window *window;
44static Textblock *topTextblock = NULL;
45static int textblockNo = 0;
46
47static const char *numbers[10] = {
48 "one", "two", "three", "four", "five",
49 "six", "seven", "eight", "nine", "ten"
50};
51
52static void anchorCallback (Fl_Widget *widget, void *data)
53{
54 layout->setAnchor (numbers[(long)data]);
55}
56
57static void textTimeout (void *data)
58{
59 Textblock *oldTop = topTextblock;
60 topTextblock = new Textblock (false);
61
62 if (oldTop) {
63 oldTop->addLinebreak (wordStyle);
65 } else {
68 }
69
71
72 char buf[16];
73 strcpy (buf, numbers[textblockNo]);
74 buf[0] = lout::misc::AsciiToupper (buf[0]);
77
78 for (int i = 0; i < 30; i++) {
79 strcpy (buf, numbers[textblockNo]);
80 if (i == 0)
81 buf[0] = lout::misc::AsciiToupper (buf[0]);
82 strcat (buf, i == 29 ? "." : ",");
83
86 }
87
89
91 if (textblockNo < 10)
92 Fl::repeat_timeout (1, textTimeout, NULL);
93
94}
95
96int main(int argc, char **argv)
97{
98 char *buttonLabel[10];
99
100 platform = new FltkPlatform ();
101 layout = new Layout (platform);
102
103 window = new Fl_Window(250, 200, "Dw Anchors Test");
104 window->box(FL_NO_BOX);
105 window->begin();
106
107 viewport = new FltkViewport (50, 0, 200, 200);
108 viewport->end();
110
111 for (int i = 0; i < 10; i++) {
112 char buf[16];
113 strcpy (buf, numbers[i]);
114 buf[0] = lout::misc::AsciiToupper (buf[0]);
115 buttonLabel[i] = dStrdup(buf);
116 Fl_Button *button = new Fl_Button(0, 20 * i, 50, 20, buttonLabel[i]);
117 button->callback (anchorCallback, (void*)(long)i);
118 button->when (FL_WHEN_RELEASE);
119 }
120
121 FontAttrs fontAttrs;
122 fontAttrs.name = "Bitstream Charter";
123 fontAttrs.size = 14;
124 fontAttrs.weight = 400;
125 fontAttrs.style = FONT_STYLE_NORMAL;
126 fontAttrs.letterSpacing = 0;
128
129 StyleAttrs styleAttrs;
130 styleAttrs.initValues ();
131 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
132 styleAttrs.margin.setVal (5);
133 styleAttrs.color = Color::create (layout, 0x000000);
134 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
135 topWidgetStyle = Style::create (&styleAttrs);
136
137 styleAttrs.margin.left = 20;
138 styleAttrs.margin.right = 0;
139 styleAttrs.backgroundColor = NULL;
140 widgetStyle = Style::create (&styleAttrs);
141
142 styleAttrs.margin.left = 0;
143 wordStyle = Style::create (&styleAttrs);
144
145 fontAttrs.size = 28;
146 fontAttrs.weight = 700;
147 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
148 headingStyle = Style::create (&styleAttrs);
149
150 Fl::add_timeout (0, textTimeout, NULL);
151
152 window->resizable(viewport);
153 window->show();
154
155 int errorCode = Fl::run();
156
158 widgetStyle->unref ();
159 wordStyle->unref ();
161 for (int i = 0; i < 10; i++)
162 free(buttonLabel[i]);
163 delete layout;
164
165 return errorCode;
166}
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:458
void setWidget(Widget *widget)
Definition layout.cc:432
void setAnchor(const char *anchor)
Sets the anchor to scroll to.
Definition layout.cc:737
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:529
FontVariant fontVariant
Definition style.hh:687
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:444
static Style * create(StyleAttrs *attrs)
Definition style.hh:628
char * dStrdup(const char *s)
Definition dlib.c:77
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:34
@ 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:72