File: ControlsWidget.C

package info (click to toggle)
witty 3.2.1-2%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 70,436 kB
  • sloc: cpp: 117,095; ansic: 77,999; xml: 7,564; sh: 1,037; perl: 208; makefile: 144; java: 86; sql: 14
file content (118 lines) | stat: -rw-r--r-- 2,895 bytes parent folder | download
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
/*
 * Copyright (C) 2008 Emweb bvba
 *
 * See the LICENSE file for terms of use.
 */

#include "ControlsWidget.h"
#include <Wt/WText>
#include <sstream>

#include <boost/algorithm/string.hpp>

using namespace Wt;

ControlsWidget::ControlsWidget(EventDisplayer *ed, bool hasSubMenu)
  : WContainerWidget(),
    ed_(ed),
    hasSubMenu_(hasSubMenu)
{ }

void ControlsWidget::populateSubMenu(Wt::WMenu *menu)
{
  
}

std::string ControlsWidget::escape(const std::string &name) const
{
  std::stringstream ss;
  for(unsigned int i = 0; i < name.size(); ++i) {
    if (name[i] != ':') {
      ss << name[i];
    } else {
      ss << "_1";
    }
  }
  return ss.str();
}

std::string ControlsWidget::docAnchor(const std::string &classname) const
{
  std::stringstream ss;

#if !defined(WT_TARGET_JAVA)
  ss << "<a href=\"http://www.webtoolkit.eu/wt/doc/reference/html/class"
     << escape("Wt::" + classname)
     << ".html\" target=\"_blank\">doc</a>";
#else
  std::string cn = boost::replace_all(classname, "Chart::","chart/");
  ss << "<a href=\"http://www.webtoolkit.eu/"
     << "jwt/latest/doc/javadoc/eu/webtoolkit/jwt/"
     << classname
    << ".html\" target=\"_blank\">doc</a>";
#endif

  return ss.str();
}

std::string ControlsWidget::title(const std::string& classname) const
{
  std::string cn;
#if defined(WT_TARGET_JAVA)
    cn = boost::replace_all(classname, "Chart::","");
#else
    cn = classname;
#endif

    return std::string("<span class=\"title\">") + cn + "</span> "
      + "<span class=\"doc\">["
      + docAnchor(classname) + "]</span>";
}

void ControlsWidget::topic(const std::string &classname,
			   WContainerWidget *parent) const
{
  new WText(title(classname) + "<br/>", parent);
}

void ControlsWidget::topic(const std::string &classname1,
			   const std::string &classname2,
			   WContainerWidget *parent) const
{
  new WText(title(classname1) + " and " + title(classname2) + "<br/>",
            parent);
}

void ControlsWidget::topic(const std::string &classname1,
			   const std::string &classname2,
			   const std::string &classname3,
			   WContainerWidget *parent) const
{
  new WText(title(classname1) + ", " + title(classname2) + " and "
	    + title(classname3) + "<br/>", parent);
}

void ControlsWidget::topic(const std::string &classname1,
			   const std::string &classname2,
			   const std::string &classname3,
			   const std::string &classname4,
			   WContainerWidget *parent) const
{
  new WText(title(classname1) + ", " + title(classname2) + ", "
	    + title(classname3) + " and " + title(classname4) + "<br/>",
            parent);
}

WText *ControlsWidget::addText(const WString& s, WContainerWidget *parent)
{
  WText *text = new WText(s, parent);
  bool literal;
#ifndef WT_TARGET_JAVA
  literal = s.literal();
#else
  literal = WString(s).literal();
#endif
  if (!literal)
    text->setInternalPathEncoding(true);
  return text;
}