Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_links2.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#include <FL/Fl_Box.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 dw;
33using namespace dw::core;
34using namespace dw::core::style;
35using namespace dw::fltk;
36
37class LinkTestReceiver: public Layout::LinkReceiver
38{
39 bool enter (Widget *widget, int link, int img, int x, int y);
40 bool press (Widget *widget, int link, int img, int x, int y,
41 EventButton *event);
42 bool release (Widget *widget, int link, int img, int x, int y,
43 EventButton *event);
44 bool click (Widget *widget, int link, int img, int x, int y,
45 EventButton *event);
46};
47
48bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y)
49{
50 printf ("enter: %d\n", link);
51 return true;
52}
53
54bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y,
55 EventButton *event)
56{
57 printf ("press: %d\n", link);
58 return true;
59}
60
61bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y,
62 EventButton *event)
63{
64 printf ("release: %d\n", link);
65 return true;
66}
67
68bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y,
69 EventButton *event)
70{
71 printf ("click: %d\n", link);
72 return true;
73}
74
75int main(int argc, char **argv)
76{
77 int MainIdx;
78 int ww = 200, wh = 300, lh = 24;
79
82
83 Fl_Window *window = new Fl_Window(200, 300, "Dw Links2");
84 window->box(FL_NO_BOX);
85 window->begin();
86 Fl_Widget *Panel = new Fl_Box(0, 0, ww, lh, "CONTROL PANEL");
87
88 Panel->color(FL_GRAY_RAMP + 3);
89 Panel->labelcolor(FL_WHITE);
90 Panel->box(FL_FLAT_BOX);
91 Fl_Widget *Main = new Fl_Box(0, lh, ww, wh - 2*lh, "MAIN RENDERING AREA");
92 Main->color(FL_GRAY_RAMP + 4);
93 Main->labelcolor(FL_WHITE);
94 MainIdx = window->find(Main);
95 /* status bar */
96 Fl_Widget *Bar = new Fl_Box(0, wh - lh, 200, lh, "STATUS BAR...");
97 Bar->color(FL_GRAY_RAMP + 3);
98 Bar->labelcolor(FL_WHITE);
99 Bar->box(FL_FLAT_BOX);
100
101 window->resizable(Main);
102 window->end();
103
104 //
105 // Create the main Dw and add some text there.
106 //
107 window->remove(MainIdx);
108 window->begin();
109
110 FltkViewport *viewport = new FltkViewport (0, lh, ww, wh - 2*lh);
112
113 window->end();
114
115
116 StyleAttrs styleAttrs;
117 styleAttrs.initValues ();
118 styleAttrs.margin.setVal (5);
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 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
128
129 styleAttrs.color = Color::create (layout, 0x000000);
130 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
131
132 Style *widgetStyle = Style::create (&styleAttrs);
133
134 Textblock *textblock = new Textblock (false);
135 textblock->setStyle (widgetStyle);
136 layout->setWidget (textblock);
137
138 layout->connectLink (new LinkTestReceiver ());
139
141
142 styleAttrs.margin.setVal (0);
143 styleAttrs.backgroundColor = NULL;
144 styleAttrs.cursor = CURSOR_TEXT;
145
146 Style *wordStyle = Style::create (&styleAttrs);
147
148 styleAttrs.color = Color::create (layout, 0x0000ff);
150 styleAttrs.cursor = CURSOR_POINTER;
151
152 for(int i = 1; i <= 30; i++) {
153 char buf[4];
154 sprintf(buf, "%d.", i);
155
156 const char *words1[] = {
157 "This", "is", "the", buf, "paragraph.",
158 "Here", "comes", "some", "more", "text",
159 "to", "demonstrate", "word", "wrapping.",
160 NULL };
161 const char *words2[] = {
162 "Click", "here", "for", "more..", NULL };
163
164 for(int j = 0; words1[j]; j++) {
165 textblock->addText (words1[j], wordStyle);
166 textblock->addSpace(wordStyle);
167 }
168
169 styleAttrs.x_link = i;
170 Style *linkStyle = Style::create (&styleAttrs);
171
172 for(int j = 0; words2[j]; j++) {
173 textblock->addText (words2[j], linkStyle);
174 textblock->addSpace(wordStyle);
175 }
176
177 linkStyle->unref ();
178
179 textblock->addParbreak(10, wordStyle);
180 }
181
182 wordStyle->unref();
183
184 textblock->flush ();
185
186 window->resizable(viewport);
187 window->show();
188 int errorCode = Fl::run();
189
190 delete layout;
191
192 return errorCode;
193}
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:459
void setWidget(Widget *widget)
Definition layout.cc:433
void connectLink(LinkReceiver *receiver)
Definition layout.hh:259
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:1316
void setVal(int val)
Definition style.hh:510
static Color * create(Layout *layout, int color)
Definition style.cc:529
FontVariant fontVariant
Definition style.hh:688
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:444
static Style * create(StyleAttrs *attrs)
Definition style.hh:629
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:353
@ FONT_VARIANT_NORMAL
Definition style.hh:333
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.