Dillo v3.1.1-99-gf3103cc4
Loading...
Searching...
No Matches
dw_table.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/table.hh"
30
31using namespace dw;
32using namespace dw::core;
33using namespace dw::core::style;
34using namespace dw::fltk;
35
36int main(int argc, char **argv)
37{
40
41 Fl_Window *window = new Fl_Window(300, 300, "Dw Table");
42 window->box(FL_NO_BOX);
43 window->begin();
44
45 FltkViewport *viewport = new FltkViewport (0, 0, 300, 300);
47
48 StyleAttrs styleAttrs;
49 styleAttrs.initValues ();
50 styleAttrs.margin.setVal (5);
51 styleAttrs.padding.setVal (0);
52 styleAttrs.borderWidth.setVal (1);
53 styleAttrs.setBorderStyle (BORDER_OUTSET);
54 styleAttrs.setBorderColor (Color::create (layout, 0xffffff));
55 styleAttrs.color = Color::create (layout, 0x000000);
56 styleAttrs.backgroundColor = Color::create (layout, 0xffffff);
57 styleAttrs.hBorderSpacing = 5;
58 styleAttrs.vBorderSpacing = 5;
59
60 FontAttrs fontAttrs;
61 fontAttrs.name = "Bitstream Charter";
62 fontAttrs.size = 14;
63 fontAttrs.weight = 400;
64 fontAttrs.style = FONT_STYLE_NORMAL;
65 fontAttrs.letterSpacing = 0;
67 styleAttrs.font = dw::core::style::Font::create (layout, &fontAttrs);
68
69 Style *tableStyle = Style::create (&styleAttrs);
70
71 Table *table = new Table (false);
72 table->setStyle (tableStyle);
73 layout->setWidget (table);
74
75 tableStyle->unref();
76
77 styleAttrs.setBorderStyle (BORDER_INSET);
78 styleAttrs.backgroundColor = NULL;
79 styleAttrs.margin.setVal (0);
80 styleAttrs.padding.setVal (5);
81
82 Style *cellStyle = Style::create (&styleAttrs);
83
84 styleAttrs.borderWidth.setVal (0);
85 styleAttrs.margin.setVal (0);
86 styleAttrs.cursor = CURSOR_TEXT;
87 styleAttrs.textAlignChar = '.';
88
89 Style *wordStyle = Style::create (&styleAttrs);
90
91 for (int i = 0; i < 4; i++) {
92 table->addRow (wordStyle);
93
94 for (int j = 0; j < 4; j++) {
95 Textblock *cell = new Textblock (false);
96 cell->setStyle (cellStyle);
97 table->addCell (cell, 1, 1);
98
99 char buf[10];
100 sprintf (buf, "cell %c", 'A' + 4 * i + j);
101
102 cell->addText (buf, wordStyle);
103 cell->flush ();
104 }
105 }
106
107 wordStyle->unref();
108 cellStyle->unref();
109
110 window->resizable(viewport);
111 window->show();
112 int errorCode = Fl::run();
113
114 delete layout;
115
116 return errorCode;
117}
int main(void)
Definition bookmarks.c:1613
A Widget for rendering tables.
Definition table.hh:326
void addCell(Widget *widget, int colspan, int rowspan)
Definition table.cc:468
void addRow(core::style::Style *style)
Definition table.cc:584
A Widget for rendering text blocks, i.e.
Definition textblock.hh:206
void addText(const char *text, size_t len, core::style::Style *style)
Add a word to the page structure.
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 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.