Mercurial > dillo_port1.3
comparison test/dw_lists.cc @ 347:e5955ab8dafb
- Moved the dw2 tree into dillo2's tree.
author | jcid |
---|---|
date | Wed, 24 Sep 2008 18:44:40 +0200 |
parents | |
children | b6ef23efdac7 |
comparison
equal
deleted
inserted
replaced
346:05228bc9f399 | 347:e5955ab8dafb |
---|---|
1 /* | |
2 * Dillo Widget | |
3 * | |
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org> | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 3 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
19 */ | |
20 | |
21 | |
22 | |
23 #include <fltk/Window.h> | |
24 #include <fltk/run.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 | |
32 using namespace dw; | |
33 using namespace dw::core; | |
34 using namespace dw::core::style; | |
35 using namespace dw::fltk; | |
36 | |
37 int main(int argc, char **argv) | |
38 { | |
39 FltkPlatform *platform = new FltkPlatform (); | |
40 Layout *layout = new Layout (platform); | |
41 | |
42 ::fltk::Window *window = new ::fltk::Window(200, 300, "Dw Lists"); | |
43 window->begin(); | |
44 | |
45 FltkViewport *viewport = new FltkViewport (0, 0, 200, 300); | |
46 layout->attachView (viewport); | |
47 | |
48 StyleAttrs styleAttrs; | |
49 styleAttrs.initValues (); | |
50 styleAttrs.margin.setVal (5); | |
51 | |
52 FontAttrs fontAttrs; | |
53 fontAttrs.name = "Bitstream Charter"; | |
54 fontAttrs.size = 14; | |
55 fontAttrs.weight = 400; | |
56 fontAttrs.style = FONT_STYLE_NORMAL; | |
57 styleAttrs.font = Font::create (layout, &fontAttrs); | |
58 | |
59 styleAttrs.color = Color::createSimple (layout, 0x000000); | |
60 styleAttrs.backgroundColor = Color::createSimple (layout, 0xffffff); | |
61 | |
62 Style *widgetStyle = Style::create (layout, &styleAttrs); | |
63 | |
64 Textblock *textblock = new Textblock (false); | |
65 textblock->setStyle (widgetStyle); | |
66 layout->setWidget (textblock); | |
67 | |
68 widgetStyle->unref(); | |
69 | |
70 styleAttrs.margin.setVal (0); | |
71 styleAttrs.backgroundColor = NULL; | |
72 styleAttrs.cursor = CURSOR_TEXT; | |
73 | |
74 Style *wordStyle = Style::create (layout, &styleAttrs); | |
75 | |
76 styleAttrs.margin.setVal (5); | |
77 styleAttrs.padding.setVal (5); | |
78 styleAttrs.backgroundColor = Color::createSimple (layout, 0xffff40); | |
79 styleAttrs.setBorderColor (Color::createSimple (layout, 0x000000)); | |
80 styleAttrs.setBorderStyle (BORDER_SOLID); | |
81 styleAttrs.borderWidth.setVal (1); | |
82 | |
83 Style *itemStyle = Style::create (layout, &styleAttrs); | |
84 | |
85 const char *wordsPar[] = { | |
86 "This", "is", "a", "normal", "paragraph.", "And", | |
87 "some", "list", "items", "follow:", NULL }; | |
88 const char *wordsItem[] = { | |
89 "This", "is", "a", "list", "item.", "Here", | |
90 "comes", "some", "more", "text", "to", | |
91 "demonstrate", "word", "wrapping.", NULL }; | |
92 | |
93 | |
94 for(int i = 0; wordsPar[i]; i++) { | |
95 if(i != 0) | |
96 textblock->addSpace (wordStyle); | |
97 textblock->addText (wordsPar[i], wordStyle); | |
98 } | |
99 textblock->addParbreak (5, wordStyle); | |
100 | |
101 ListItem *refItem = NULL; | |
102 | |
103 for(int i = 1; i <= 100; i++) { | |
104 ListItem *listItem = new ListItem (refItem, false); | |
105 refItem = listItem; | |
106 | |
107 textblock->addWidget (listItem, itemStyle); | |
108 textblock->addParbreak (2, wordStyle); | |
109 | |
110 char buf[16]; | |
111 sprintf (buf, "%d.", i); | |
112 listItem->initWithText (strdup (buf), wordStyle); | |
113 | |
114 for(int j = 0; wordsItem[j]; j++) { | |
115 if(j != 0) | |
116 listItem->addSpace (wordStyle); | |
117 listItem->addText (wordsItem[j], wordStyle); | |
118 } | |
119 | |
120 listItem->flush (); | |
121 } | |
122 | |
123 wordStyle->unref(); | |
124 | |
125 textblock->flush (); | |
126 | |
127 window->resizable(viewport); | |
128 window->show(); | |
129 int errorCode = ::fltk::run(); | |
130 | |
131 delete layout; | |
132 | |
133 return errorCode; | |
134 } |