Dillo v3.1.1-98-g318d1f14
Loading...
Searching...
No Matches
dw_lists.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#include "dw/listitem.hh"
31
32using namespace dw;
33using namespace dw::core;
34using namespace dw::core::style;
35using namespace dw::fltk;
36
37int main(int argc, char **argv)
38{
41
42 Fl_Window *window = new Fl_Window(200, 300, "Dw Lists");
43 window->box(FL_NO_BOX);
44 window->begin();
45
46 FltkViewport *viewport = new FltkViewport (0, 0, 200, 300);
48
49 StyleAttrs styleAttrs;
50 styleAttrs.initValues ();
51 styleAttrs.margin.setVal (5);
52
53 FontAttrs fontAttrs;
54 fontAttrs.name = "Bitstream Charter";
55 fontAttrs.size = 14;
56 fontAttrs.weight = 400;
57 fontAttrs.style = FONT_STYLE_NORMAL;
58 fontAttrs.letterSpacing = 0;
60 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
61
62 styleAttrs.color = Color::create (layout, 0x000000);
63 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
64
65 Style *widgetStyle = Style::create (&styleAttrs);
66
67 Textblock *textblock = new Textblock (false);
68 textblock->setStyle (widgetStyle);
69 layout->setWidget (textblock);
70
72
73 styleAttrs.margin.setVal (0);
74 styleAttrs.backgroundColor = NULL;
75 styleAttrs.cursor = CURSOR_TEXT;
76
77 Style *wordStyle = Style::create (&styleAttrs);
78
79 styleAttrs.margin.setVal (5);
80 styleAttrs.padding.setVal (5);
81 styleAttrs.backgroundColor = Color::create (layout, 0xffff40);
82 styleAttrs.setBorderColor (Color::create (layout, 0x000000));
83 styleAttrs.setBorderStyle (BORDER_SOLID);
84 styleAttrs.borderWidth.setVal (1);
85
86 Style *itemStyle = Style::create (&styleAttrs);
87
88 const char *wordsPar[] = {
89 "This", "is", "a", "normal", "paragraph.", "And",
90 "some", "list", "items", "follow:", NULL };
91 const char *wordsItem[] = {
92 "This", "is", "a", "list", "item.", "Here",
93 "comes", "some", "more", "text", "to",
94 "demonstrate", "word", "wrapping.", NULL };
95
96
97 for(int i = 0; wordsPar[i]; i++) {
98 if(i != 0)
99 textblock->addSpace (wordStyle);
100 textblock->addText (wordsPar[i], wordStyle);
101 }
102 textblock->addParbreak (5, wordStyle);
103
104 ListItem *refItem = NULL;
105
106 for(int i = 1; i <= 100; i++) {
107 ListItem *listItem = new ListItem (refItem, false);
108 refItem = listItem;
109
110 textblock->addWidget (listItem, itemStyle);
111 textblock->addParbreak (2, wordStyle);
112
113 char buf[16];
114 sprintf (buf, "%d.", i);
115 listItem->initWithText (buf, wordStyle);
116
117 for(int j = 0; wordsItem[j]; j++) {
118 if(j != 0)
119 listItem->addSpace (wordStyle);
120 listItem->addText (wordsItem[j], wordStyle);
121 }
122
123 listItem->flush ();
124 }
125
126 wordStyle->unref();
127
128 textblock->flush ();
129
130 window->resizable(viewport);
131 window->show();
132 int errorCode = Fl::run();
133
134 delete layout;
135
136 return errorCode;
137}
int main(void)
Definition bookmarks.c:1613
void initWithText(const char *text, core::style::Style *style)
Definition listitem.cc:58
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)
?
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.
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
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
void setBorderStyle(BorderStyle val)
Definition style.hh:588
void setBorderColor(Color *val)
Definition style.hh:585
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
@ 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.