-
Notifications
You must be signed in to change notification settings - Fork 388
Expand file tree
/
Copy pathWAbstractArea.C
More file actions
328 lines (255 loc) · 6.23 KB
/
WAbstractArea.C
File metadata and controls
328 lines (255 loc) · 6.23 KB
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
* Copyright (C) 2008 Emweb bv, Herent, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include "Wt/WAbstractArea.h"
#include "Wt/WApplication.h"
#include "Wt/WResource.h"
#include "Wt/WEnvironment.h"
#include "Wt/WException.h"
#include "Wt/WImage.h"
#include "Wt/Utils.h"
#include "DomElement.h"
#include "WebUtils.h"
#include "boost/algorithm/string.hpp"
namespace Wt {
namespace Impl {
class AreaWidget : public WInteractWidget
{
public:
AreaWidget(WAbstractArea *facade)
: facade_(facade)
{ }
~AreaWidget()
{ }
WAbstractArea *facade() const { return facade_; }
private:
WAbstractArea *facade_;
protected:
virtual void updateDom(DomElement& element, bool all) override
{
bool needsUrlResolution = facade_->updateDom(element, all);
WInteractWidget::updateDom(element, all);
if (element.getAttribute("href").empty()) {
if (!wApp->environment().agentIsGecko()) {
element.setAttribute("href", "#");
}
element.addPropertyWord(Property::Class, WInteractWidget::noDefault);
// Add back all of the style classes to avoid removing them.
auto styleClassesVector = Utils::getWidgetStyleClasses(this);
for (const auto& className : styleClassesVector) {
element.addPropertyWord(Property::Class, className);
}
}
if (needsUrlResolution)
WAnchor::renderUrlResolution(this, element, all);
}
virtual DomElementType domElementType() const override
{
return DomElementType::AREA;
}
friend class Wt::WAbstractArea;
};
}
WAbstractArea::WAbstractArea()
: uWidget_(new Impl::AreaWidget(this)),
widget_(uWidget_.get()),
hole_(false),
transformable_(true)
{ }
WAbstractArea::~WAbstractArea()
{ }
EventSignal<WKeyEvent>& WAbstractArea::keyWentDown()
{
return widget_->keyWentDown();
}
EventSignal<WKeyEvent>& WAbstractArea::keyPressed()
{
return widget_->keyPressed();
}
EventSignal<WKeyEvent>& WAbstractArea::keyWentUp()
{
return widget_->keyWentUp();
}
EventSignal<>& WAbstractArea::enterPressed()
{
return widget_->enterPressed();
}
EventSignal<>& WAbstractArea::escapePressed()
{
return widget_->escapePressed();
}
EventSignal<WMouseEvent>& WAbstractArea::clicked()
{
return widget_->clicked();
}
EventSignal<WMouseEvent>& WAbstractArea::doubleClicked()
{
return widget_->doubleClicked();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseWentDown()
{
return widget_->mouseWentDown();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseWentUp()
{
return widget_->mouseWentUp();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseWentOut()
{
return widget_->mouseWentOut();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseWentOver()
{
return widget_->mouseWentOver();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseMoved()
{
return widget_->mouseMoved();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseDragged()
{
return widget_->mouseDragged();
}
EventSignal<WMouseEvent>& WAbstractArea::mouseWheel()
{
return widget_->mouseWheel();
}
void WAbstractArea::setObjectName(const std::string& name)
{
widget_->setObjectName(name);
WObject::setObjectName(name);
}
void WAbstractArea::setImage(WImage *image)
{
image_ = image;
}
WImage *WAbstractArea::image() const
{
return image_.get();
}
void WAbstractArea::setHole(bool hole)
{
hole_ = hole;
repaint();
}
void WAbstractArea::setTransformable(bool transformable)
{
transformable_ = transformable;
repaint();
}
void WAbstractArea::setLink(const WLink& link)
{
createAnchorImpl();
anchor_->linkState.link = link;
if (anchor_->linkState.link.type() == LinkType::Resource)
anchor_->linkState.link.resource()->dataChanged().connect
(this, &WAbstractArea::resourceChanged);
repaint();
}
WLink WAbstractArea::link() const
{
if (!anchor_)
return WLink();
else
return anchor_->linkState.link;
}
void WAbstractArea::setAlternateText(const WString& text)
{
createAnchorImpl();
anchor_->altText = text;
repaint();
}
const WString WAbstractArea::alternateText() const
{
if (anchor_)
return anchor_->altText;
else
return WString();
}
void WAbstractArea::setToolTip(const WString& text)
{
widget_->setToolTip(text);
}
WString WAbstractArea::toolTip() const
{
return widget_->toolTip();
}
void WAbstractArea::setStyleClass(const WT_USTRING& styleClass)
{
widget_->setStyleClass(styleClass);
}
void WAbstractArea::setStyleClass(const char *styleClass)
{
widget_->setStyleClass(styleClass);
}
WT_USTRING WAbstractArea::styleClass() const
{
return widget_->styleClass();
}
void WAbstractArea::addStyleClass(const WT_USTRING& styleClass, bool force)
{
widget_->addStyleClass(styleClass, force);
}
void WAbstractArea::removeStyleClass(const WT_USTRING& styleClass, bool force)
{
widget_->removeStyleClass(styleClass, force);
}
void WAbstractArea::setCursor(Cursor cursor)
{
widget_->decorationStyle().setCursor(cursor);
}
void WAbstractArea::setCursor(std::string cursorImage, Cursor fallback)
{
widget_->decorationStyle().setCursor(cursorImage, fallback);
}
Cursor WAbstractArea::cursor() const
{
return widget_->decorationStyle().cursor();
}
void WAbstractArea::createAnchorImpl()
{
if (!anchor_)
anchor_.reset(new AnchorImpl());
}
void WAbstractArea::resourceChanged()
{
repaint();
}
void WAbstractArea::repaint()
{
widget_->repaint();
}
bool WAbstractArea::updateDom(DomElement& element, bool all)
{
bool needsUrlResolution = false;
if (!hole_ && anchor_) {
needsUrlResolution
= WAnchor::renderHRef(widget_, anchor_->linkState, element);
WAnchor::renderHTarget(anchor_->linkState, element, all);
element.setAttribute("alt", anchor_->altText.toUTF8());
} else {
element.setAttribute("alt", "");
if (hole_)
element.setAttribute("nohref", "nohref");
}
return needsUrlResolution;
}
WInteractWidget *WAbstractArea::widget()
{
return widget_;
}
std::unique_ptr<WWidget> WAbstractArea::takeWidget()
{
return std::move(uWidget_);
}
void WAbstractArea::returnWidget(std::unique_ptr<WWidget> w)
{
uWidget_ = Utils::dynamic_unique_ptr_cast<Impl::AreaWidget>(std::move(w));
}
std::string WAbstractArea::jsRef() const
{
return widget_->jsRef();
}
}