summaryrefslogtreecommitdiff
path: root/test/dw_links.cc
blob: c2384d1e96e963e419ff9f7c7016be6901dfc763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Dillo Widget
 *
 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */



#include <fltk/Window.h>
#include <fltk/run.h>

#include "../dw/core.hh"
#include "../dw/fltkcore.hh"
#include "../dw/fltkviewport.hh"
#include "../dw/textblock.hh"

using namespace dw;
using namespace dw::core;
using namespace dw::core::style;
using namespace dw::fltk;

class LinkTestReceiver: public Widget::LinkReceiver
{
   bool enter (Widget *widget, int link, int img, int x, int y);
   bool press (Widget *widget, int link, int img, int x, int y,
               EventButton *event);
   bool release (Widget *widget, int link, int img, int x, int y,
                 EventButton *event);
   bool click (Widget *widget, int link, int img,
               int x, int y, EventButton *event);
};

bool LinkTestReceiver::enter (Widget *widget, int link, int img, int x, int y)
{
   printf ("enter: %d\n", link);
   return true;
}

bool LinkTestReceiver::press (Widget *widget, int link, int img, int x, int y,
                              EventButton *event)
{
   printf ("press: %d\n", link);
   return true;
}

bool LinkTestReceiver::release (Widget *widget, int link, int img, int x,int y,
                                EventButton *event)
{
   printf ("release: %d\n", link);
   return true;
}

bool LinkTestReceiver::click (Widget *widget, int link, int img, int x, int y,
                              EventButton *event)
{
   printf ("click: %d\n", link);
   return true;
}

int main(int argc, char **argv)
{
   LinkTestReceiver linkTestReceiver;
   FltkPlatform *platform = new FltkPlatform ();
   Layout *layout = new Layout (platform);

   ::fltk::Window *window = new ::fltk::Window(200, 300, "Dw Links");
   window->begin();

   FltkViewport *viewport = new FltkViewport (0, 0, 200, 300);
   layout->attachView (viewport);

   StyleAttrs styleAttrs;
   styleAttrs.initValues ();
   styleAttrs.margin.setVal (5);

   FontAttrs fontAttrs;
   fontAttrs.name = "Bitstream Charter";
   fontAttrs.size = 14;
   fontAttrs.weight = 400;
   fontAttrs.style = FONT_STYLE_NORMAL;
   styleAttrs.font = Font::create (layout, &fontAttrs);

   styleAttrs.color = Color::create (layout, 0x000000);
   styleAttrs.backgroundColor = Color::create (layout, 0xffffff);

   Style *widgetStyle = Style::create (layout, &styleAttrs);

   Textblock *textblock = new Textblock (false);
   textblock->setStyle (widgetStyle);
   layout->setWidget (textblock);

   textblock->connectLink (&linkTestReceiver);

   widgetStyle->unref();

   styleAttrs.margin.setVal (0);
   styleAttrs.backgroundColor = NULL;
   styleAttrs.cursor = CURSOR_TEXT;

   Style *wordStyle = Style::create (layout, &styleAttrs);

   styleAttrs.color = Color::create (layout, 0x0000ff);
   styleAttrs.textDecoration = TEXT_DECORATION_UNDERLINE;
   styleAttrs.cursor = CURSOR_POINTER;
   
   for(int i = 1; i <= 10; i++) {
      char buf[4];
      sprintf(buf, "%d.", i);

      const char *words1[] = {
         "This", "is", "the", buf, "paragraph.",
         "Here", "comes", "some", "more", "text",
         "to", "demonstrate", "word", "wrapping.",
         NULL };
      const char *words2[] = {
         "Click", "here", "for", "more..", NULL };

      for(int j = 0; words1[j]; j++) {
         textblock->addText(words1[j], wordStyle);
         textblock->addSpace(wordStyle);
      }
      
      styleAttrs.x_link = i;
      Style *linkStyle = Style::create (layout, &styleAttrs);
      
      for(int j = 0; words2[j]; j++) {
         textblock->addText(words2[j], linkStyle);
         textblock->addSpace(wordStyle);
      }
      
      linkStyle->unref ();

      textblock->addParbreak(10, wordStyle);
   }

   wordStyle->unref();

   textblock->flush ();

   window->resizable(viewport);
   window->show();
   int errorCode = ::fltk::run();

   delete layout;

   return errorCode;
}