Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
dw_links.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 <FL/Fl.H>
24#include <FL/Fl_Window.H>
25
26#include "dw/core.hh"
27#include "dw/fltkcore.hh"
28#include "dw/fltkviewport.hh"
29#include "dw/textblock.hh"
30
31using namespace dw;
32using namespace dw::core;
33using namespace dw::core::style;
34using namespace dw::fltk;
35
36class LinkTestReceiver: public Layout::LinkReceiver
37{
38 bool enter (Widget *widget, int link, int img, int x, int y);
39 bool press (Widget *widget, int link, int img, int x, int y,
40 EventButton *event);
41 bool release (Widget *widget, int link, int img, int x, int y,
42 EventButton *event);
43 bool click (Widget *widget, int link, int img,
44 int x, int y, EventButton *event);
45};
46
47bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y)
48{
49 printf ("enter: %d\n", link);
50 return true;
51}
52
53bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y,
54 EventButton *event)
55{
56 printf ("press: %d\n", link);
57 return true;
58}
59
60bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y,
61 EventButton *event)
62{
63 printf ("release: %d\n", link);
64 return true;
65}
66
67bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y,
68 EventButton *event)
69{
70 printf ("click: %d\n", link);
71 return true;
72}
73
74int main(int argc, char **argv)
75{
76 LinkTestReceiver linkTestReceiver;
79
80 Fl_Window *window = new Fl_Window(200, 300, "Dw Links");
81 window->box(FL_NO_BOX);
82 window->begin();
83
84 FltkViewport *viewport = new FltkViewport (0, 0, 200, 300);
86
87 StyleAttrs styleAttrs;
88 styleAttrs.initValues ();
89 styleAttrs.margin.setVal (5);
90
91 FontAttrs fontAttrs;
92 fontAttrs.name = "Bitstream Charter";
93 fontAttrs.size = 14;
94 fontAttrs.weight = 400;
95 fontAttrs.style = FONT_STYLE_NORMAL;
96 fontAttrs.letterSpacing = 0;
98 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
99
100 styleAttrs.color = Color::create (layout, 0x000000);
101 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
102
103 Style *widgetStyle = Style::create (&styleAttrs);
104
105 Textblock *textblock = new Textblock (false);
106 textblock->setStyle (widgetStyle);
107 layout->setWidget (textblock);
108
109 layout->connectLink (&linkTestReceiver);
110
112
113 styleAttrs.margin.setVal (0);
114 styleAttrs.backgroundColor = NULL;
115 styleAttrs.cursor = CURSOR_TEXT;
116
117 Style *wordStyle = Style::create (&styleAttrs);
118
119 styleAttrs.color = Color::create (layout, 0x0000ff);
121 styleAttrs.cursor = CURSOR_POINTER;
122
123 for(int i = 1; i <= 10; i++) {
124 char buf[4];
125 sprintf(buf, "%d.", i);
126
127 const char *words1[] = {
128 "This", "is", "the", buf, "paragraph.",
129 "Here", "comes", "some", "more", "text",
130 "to", "demonstrate", "word", "wrapping.",
131 NULL };
132 const char *words2[] = {
133 "Click", "here", "for", "more..", NULL };
134
135 for(int j = 0; words1[j]; j++) {
136 textblock->addText(words1[j], wordStyle);
137 textblock->addSpace(wordStyle);
138 }
139
140 styleAttrs.x_link = i;
141 Style *linkStyle = Style::create (&styleAttrs);
142
143 for(int j = 0; words2[j]; j++) {
144 textblock->addText(words2[j], linkStyle);
145 textblock->addSpace(wordStyle);
146 }
147
148 linkStyle->unref ();
149
150 textblock->addParbreak(10, wordStyle);
151 }
152
153 wordStyle->unref();
154
155 textblock->flush ();
156
157 window->resizable(viewport);
158 window->show();
159 int errorCode = Fl::run();
160
161 delete layout;
162
163 return errorCode;
164}
int main(void)
Definition bookmarks.c:1613
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addSpace(core::style::Style *style)
?
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.
Represents a button press or release event.
Definition events.hh:58
virtual bool click(Widget *widget, int link, int img, int x, int y, EventButton *event)
Called, when the user has clicked on a link.
Definition layout.cc:165
virtual bool press(Widget *widget, int link, int img, int x, int y, EventButton *event)
Called, when the user has pressed the mouse button on a link (but not yet released).
Definition layout.cc:153
virtual bool release(Widget *widget, int link, int img, int x, int y, EventButton *event)
Called, when the user has released the mouse button on a link.
Definition layout.cc:159
virtual bool enter(Widget *widget, int link, int img, int x, int y)
Called, when a link is entered, left, or the position has changed.
Definition layout.cc:147
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 connectLink(LinkReceiver *receiver)
Definition layout.hh:258
The base class of all dillo widgets.
Definition widget.hh:44
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
static Style * wordStyle
static Style * widgetStyle
static Fl_Window * window
static Layout * layout
static FltkPlatform * platform
static FltkViewport * viewport
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
@ TEXT_DECORATION_UNDERLINE
Definition style.hh:352
@ 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.