/usr/lib/Wt/examples/widgetgallery/EventsDemo.C is in witty-examples 3.1.10-1ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#include "EventsDemo.h"
#include <Wt/WText>
#include <Wt/WBreak>
#include <Wt/WCssDecorationStyle>
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <Wt/WLineEdit>
#include <Wt/WHBoxLayout>
#include "DragExample.h"
using namespace Wt;
EventsDemo::EventsDemo(EventDisplayer *ed)
: ControlsWidget(ed, true),
keyEventRepeatCounter_(0)
{
new WText(tr("events-intro"), this);
}
void EventsDemo::populateSubMenu(WMenu *menu)
{
menu->addItem("WKeyEvent", wKeyEvent());
menu->addItem("WMouseEvent", wMouseEvent());
menu->addItem("WDropEvent", wDropEvent());
}
WWidget *EventsDemo::wKeyEvent()
{
WContainerWidget *result = new WContainerWidget();
topic("WKeyEvent", result);
new WText(tr("events-WKeyEvent-1"), result);
WLineEdit *l = new WLineEdit(result);
l->setTextSize(50);
l->keyWentUp().connect(this, &EventsDemo::showKeyWentUp);
l->keyWentDown().connect(this, &EventsDemo::showKeyWentDown);
new WText(tr("events-WKeyEvent-2"), result);
l = new WLineEdit(result);
l->setTextSize(50);
l->keyPressed().connect(this, &EventsDemo::showKeyPressed);
new WText(tr("events-WKeyEvent-3"), result);
l = new WLineEdit(result);
l->setTextSize(50);
l->enterPressed().connect(this, &EventsDemo::showEnterPressed);
l->escapePressed().connect(this, &EventsDemo::showEscapePressed);
new WBreak(result);
new WText("Last event: ", result);
keyEventType_ = new WText(result);
new WBreak(result);
keyEventDescription_ = new WText(result);
return result;
}
WWidget *EventsDemo::wMouseEvent()
{
WContainerWidget *result = new WContainerWidget();
topic("WMouseEvent", result);
new WText(tr("events-WMouseEvent"), result);
WContainerWidget *c = new WContainerWidget(result);
WHBoxLayout *hlayout = new WHBoxLayout;
c->setLayout(hlayout);
WContainerWidget *l = new WContainerWidget;
WContainerWidget *r = new WContainerWidget;
new WText("clicked<br/>doubleClicked<br/>mouseWentOut<br/>mouseWentOver",
l);
new WText("mouseWentDown<br/>mouseWentUp<br/>mouseMoved<br/>mouseWheel", r);
hlayout->addWidget(l);
hlayout->addWidget(r);
c->resize(600, 300);
l->decorationStyle().setBackgroundColor(Wt::gray);
r->decorationStyle().setBackgroundColor(Wt::gray);
// prevent that firefox interprets drag as drag&drop action
l->setStyleClass("unselectable");
r->setStyleClass("unselectable");
l->clicked().connect(this, &EventsDemo::showClicked);
l->doubleClicked().connect(this, &EventsDemo::showDoubleClicked);
l->mouseWentOut().connect(this, &EventsDemo::showMouseWentOut);
l->mouseWentOver().connect(this, &EventsDemo::showMouseWentOver);
r->mouseMoved().connect(this, &EventsDemo::showMouseMoved);
r->mouseWentUp().connect(this, &EventsDemo::showMouseWentUp);
r->mouseWentDown().connect(this, &EventsDemo::showMouseWentDown);
r->mouseWheel().connect(this, &EventsDemo::showMouseWheel);
r->mouseWheel().preventDefaultAction(true);
new WBreak(result);
new WText("Last event: ", result);
mouseEventType_ = new WText(result);
new WBreak(result);
mouseEventDescription_ = new WText(result);
return result;
}
WWidget *EventsDemo::wDropEvent()
{
WContainerWidget *result = new WContainerWidget();
topic("WDropEvent", result);
new WText(tr("events-WDropEvent"), result);
new DragExample(result);
return result;
}
namespace {
std::ostream &operator<<(std::ostream &o, Wt::WMouseEvent::Button b)
{
switch (b) {
case WMouseEvent::LeftButton:
return o << "LeftButton";
case WMouseEvent::RightButton:
return o << "LeftButton";
case WMouseEvent::MiddleButton:
return o << "LeftButton";
default:
return o << "Unknown Button";
}
}
std::ostream &operator<<(std::ostream &o, Wt::Key k)
{
switch(k) {
default:
case Key_unknown : return o << "Key_unknown";
case Key_Enter : return o << "Key_Enter";
case Key_Tab : return o << "Key_Tab";
case Key_Backspace : return o << "Key_Backspace";
case Key_Shift : return o << "Key_Shift";
case Key_Control : return o << "Key_Control";
case Key_Alt : return o << "Key_Alt";
case Key_PageUp : return o << "Key_PageUp";
case Key_PageDown : return o << "Key_PageDown";
case Key_End : return o << "Key_End";
case Key_Home : return o << "Key_Home";
case Key_Left : return o << "Key_Left";
case Key_Up : return o << "Key_Up";
case Key_Right : return o << "Key_Right";
case Key_Down : return o << "Key_Down";
case Key_Insert : return o << "Key_Insert";
case Key_Delete : return o << "Key_Delete";
case Key_Escape : return o << "Key_Escape";
case Key_F1 : return o << "Key_F1";
case Key_F2 : return o << "Key_F2";
case Key_F3 : return o << "Key_F3";
case Key_F4 : return o << "Key_F4";
case Key_F5 : return o << "Key_F5";
case Key_F6 : return o << "Key_F6";
case Key_F7 : return o << "Key_F7";
case Key_F8 : return o << "Key_F8";
case Key_F9 : return o << "Key_F9";
case Key_F10 : return o << "Key_F10";
case Key_F11 : return o << "Key_F11";
case Key_F12 : return o << "Key_F12";
case Key_Space : return o << "Key_Space";
case Key_A : return o << "Key_A";
case Key_B : return o << "Key_B";
case Key_C : return o << "Key_C";
case Key_D : return o << "Key_D";
case Key_E : return o << "Key_E";
case Key_F : return o << "Key_F";
case Key_G : return o << "Key_G";
case Key_H : return o << "Key_H";
case Key_I : return o << "Key_I";
case Key_J : return o << "Key_J";
case Key_K : return o << "Key_K";
case Key_L : return o << "Key_L";
case Key_M : return o << "Key_M";
case Key_N : return o << "Key_N";
case Key_O : return o << "Key_O";
case Key_P : return o << "Key_P";
case Key_Q : return o << "Key_Q";
case Key_R : return o << "Key_R";
case Key_S : return o << "Key_S";
case Key_T : return o << "Key_T";
case Key_U : return o << "Key_U";
case Key_V : return o << "Key_V";
case Key_W : return o << "Key_W";
case Key_X : return o << "Key_X";
case Key_Y : return o << "Key_Y";
case Key_Z : return o << "Key_Z";
}
}
std::ostream &operator<<(std::ostream &o, Wt::WMouseEvent::Coordinates c)
{
return o << c.x << ", " << c.y;
}
std::string modifiersToString(const WFlags< KeyboardModifier >& modifiers)
{
std::stringstream o;
if (modifiers & ShiftModifier) o << "Shift ";
if (modifiers & ControlModifier) o << "Control ";
if (modifiers & AltModifier) o << "Alt ";
if (modifiers & MetaModifier) o << "Meta ";
if (modifiers == 0) o << "No modifiers";
return o.str();
}
}
void EventsDemo::setKeyType(const std::string &type, const WKeyEvent *e)
{
std::string repeatString = "";
if (lastKeyType_ == type) {
keyEventRepeatCounter_++;
repeatString = " ("
+ boost::lexical_cast<std::string>(keyEventRepeatCounter_) + " times)";
} else {
lastKeyType_ = type;
keyEventRepeatCounter_ = 0;
}
keyEventType_->setText(type + repeatString);
if (e) {
describe(*e);
} else {
keyEventDescription_->setText("");
}
}
void EventsDemo::showKeyWentUp(const WKeyEvent &e)
{
setKeyType("keyWentUp", &e);
}
void EventsDemo::showKeyWentDown(const WKeyEvent &e)
{
setKeyType("keyWentDown", &e);
}
void EventsDemo::showKeyPressed(const WKeyEvent &e)
{
setKeyType("keyPressed", &e);
}
void EventsDemo::showEnterPressed()
{
setKeyType("enterPressed");
}
void EventsDemo::showEscapePressed()
{
setKeyType("escapePressed");
}
void EventsDemo::describe(const Wt::WKeyEvent &e)
{
std::stringstream ss;
ss << "Key: " << e.key() << "<br/>"
<< "Modifiers: " << modifiersToString(e.modifiers()) << "<br/>"
<< "Char code: " << (int)e.charCode() << "<br/>"
<< "text: " << e.text() << "<br/>";
keyEventDescription_->setText(ss.str());
}
void EventsDemo::showClicked(const WMouseEvent &e)
{
mouseEventType_->setText("clicked");
describe(e);
}
void EventsDemo::showDoubleClicked(const WMouseEvent &e)
{
mouseEventType_->setText("doubleClicked");
describe(e);
}
void EventsDemo::showMouseWentOut(const WMouseEvent &e)
{
mouseEventType_->setText("mouseWentOut");
describe(e);
}
void EventsDemo::showMouseWheel(const WMouseEvent &e)
{
mouseEventType_->setText("mouseWheel");
describe(e);
}
void EventsDemo::showMouseWentOver(const WMouseEvent &e)
{
mouseEventType_->setText("mouseWentOver");
describe(e);
}
void EventsDemo::showMouseMoved(const WMouseEvent &e)
{
mouseEventType_->setText("mouseMoved");
describe(e);
}
void EventsDemo::showMouseWentUp(const WMouseEvent &e)
{
mouseEventType_->setText("mouseWentUp");
describe(e);
}
void EventsDemo::showMouseWentDown(const WMouseEvent &e)
{
mouseEventType_->setText("mouseWentDown");
describe(e);
}
void EventsDemo::describe(const Wt::WMouseEvent &e)
{
std::stringstream ss;
ss << "Button: " << e.button() << "<br/>"
<< "Modifiers: " << modifiersToString(e.modifiers()) << "<br/>"
<< "Document coordinates: " << e.document() << "<br/>"
<< "Window coordinates: " << e.window() << "<br/>"
<< "Screen coordinates: " << e.screen() << "<br/>"
<< "Widget coordinates: " << e.widget() << "<br/>"
<< "DragDelta coordinates: " << e.dragDelta() << "<br/>"
<< "Wheel delta: " << e.wheelDelta() << "<br/>";
mouseEventDescription_->setText(ss.str());
}
|