Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
    - use WStandardItem::setItemPrototype() to accept numeric data in models (#2717)
    - install DomElement.h and EscapeOStream.h (#2684)
    - use rpath for macsox builds (#2705)
    - implemented WTextEdit::setEnabled() and setReadOnly()
    - Removed obsolete Safari workaround (#2701)
    - Sending mail: report success/failure as return value for send()
    - added WTemplate::renderTemplateText error reporting
    - Fixed bestMatch logic in RequestHandler (#2694)
    - Added automatic redirect following to HTTP client (#2605)
    - Fix Http client: Change empty path into /
    - WDoubleSpinBox: decimalPoint and groupSeparator support (#2363)
  • Loading branch information
Koen Deforche committed Feb 25, 2014
1 parent 88ef994 commit 7b836d9
Show file tree
Hide file tree
Showing 91 changed files with 523 additions and 212 deletions.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,19 @@ IF (DOXYGEN_FOUND)
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/examples
COMMENT "Doxygen for examples ...")
ADD_DEPENDENCIES(doc doxygen-examples)
ENDIF (DOXYGEN_FOUND)
ENDIF (DOXYGEN_FOUND)

# we enable rpath support for APPLE, this probably goes against policy
# linux distributions?
IF(APPLE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_MACOSX_RPATH TRUE)
ENDIF(APPLE)

SUBDIRS(src)

Expand Down
6 changes: 6 additions & 0 deletions WConfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define WT_VERSION (((WT_SERIES & 0xff) << 24) | ((WT_MAJOR & 0xff) << 16) | ((WT_MINOR & 0xff) << 8))
#define WT_VERSION_STR "${VERSION_SERIES}.${VERSION_MAJOR}.${VERSION_MINOR}"
#define WT_CLASS "Wt${VERSION_SERIES}_${VERSION_MAJOR}_${VERSION_MINOR}"
#define WT_INCLUDED_VERSION Wt_${VERSION_SERIES}_${VERSION_MAJOR}_${VERSION_MINOR}

#define RUNDIR "${RUNDIR}"
#define WT_CONFIG_XML "${CONFIGURATION}"
Expand Down Expand Up @@ -43,5 +44,10 @@
#cmakedefine WT_USE_BOOST_SIGNALS
#cmakedefine WT_USE_BOOST_SIGNALS2

// our win32: WIN32 (gcc) or _WIN32 (MSC)
#if defined(WIN32) || defined(_WIN32)
#define WT_WIN32 1
#endif

#endif

6 changes: 3 additions & 3 deletions examples/blog/asciidoc/asciidoc.C
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace {

std::string tempFileName()
{
#ifndef WIN32
#ifndef WT_WIN32
char spool[20];
strcpy(spool, "/tmp/wtXXXXXX");

Expand Down Expand Up @@ -64,7 +64,7 @@ WString asciidoc(const Wt::WString& src)
#endif
std::string command = cmd + " -o " + htmlFileName + " -s " + srcFileName;

#ifndef WIN32
#ifndef WT_WIN32
/*
* So, asciidoc apparently sends a SIGINT which is caught by its parent
* process.. So we have to temporarily ignore it.
Expand All @@ -76,7 +76,7 @@ WString asciidoc(const Wt::WString& src)
sigaction(SIGINT, &newAction, &oldAction);
#endif
bool ok = system(command.c_str()) == 0;
#ifndef WIN32
#ifndef WT_WIN32
sigaction(SIGINT, &oldAction, 0);
#endif

Expand Down
4 changes: 2 additions & 2 deletions examples/blog/model/BlogSession.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

#include <Wt/Dbo/FixedSqlConnectionPool>

#ifndef WIN32
#ifndef WT_WIN32
#include <unistd.h>
#endif

#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(ANDROID)
#if !defined(WT_WIN32) && !defined(__CYGWIN__) && !defined(ANDROID)
#define HAVE_CRYPT
#endif

Expand Down
4 changes: 1 addition & 3 deletions examples/blog/view/EditUsers.C
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ void EditUsers::limitList()
dbo::Transaction t(session_);
UserList users = session_.find<User>().where("name like ?").bind("%"+limitEdit_->text()+"%").orderBy("name");

WSignalMapper<dbo::dbo_traits<User>::IdType >* userLinkMap = new WSignalMapper<dbo::dbo_traits<User>::IdType >(this);
userLinkMap->mapped().connect(this,&EditUsers::onUserClicked);
for (UserList::const_iterator i = users.begin(); i != users.end(); ++i) {
WText* t = new WText((*i)->name, list);
t->setStyleClass("link");
new WBreak(list);
userLinkMap->mapConnect(t->clicked(), (*i).id());
t->clicked().connect(boost::bind(&EditUsers::onUserClicked, this, (*i).id()));
}
if (!users.size())
new WText(tr("no-users-found"),list);
Expand Down
30 changes: 30 additions & 0 deletions examples/charts/ChartsExample.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,43 @@

using namespace Wt;
using namespace Wt::Chart;

namespace {

/*
* A standard item which converts text edits to numbers
*/
class NumericItem : public WStandardItem {
public:
virtual NumericItem *clone() const {
return new NumericItem();
}

virtual void setData(const boost::any &data, int role = UserRole) {
boost::any dt;

if (role == EditRole) {
std::string s = Wt::asString(data).toUTF8();
char *endptr;
double d = strtod(s.c_str(), &endptr);
if (*endptr == 0)
dt = boost::any(d);
else
dt = data;
}

WStandardItem::setData(data, role);
}
};

/*
* Reads a CSV file as an (editable) standard item model.
*/
WAbstractItemModel *readCsvFile(const std::string &fname,
WContainerWidget *parent)
{
WStandardItemModel *model = new WStandardItemModel(0, 0, parent);
model->setItemPrototype(new NumericItem());
std::ifstream f(fname.c_str());

if (f) {
Expand Down Expand Up @@ -255,6 +283,7 @@ ScatterPlotExample::ScatterPlotExample(WContainerWidget *parent):
new WText(WString::tr("scatter plot 2"), this);

WStandardItemModel *model = new WStandardItemModel(40, 2, this);
model->setItemPrototype(new NumericItem());
model->setHeaderData(0, WString("X"));
model->setHeaderData(1, WString("Y = sin(X)"));

Expand Down Expand Up @@ -304,6 +333,7 @@ PieExample::PieExample(WContainerWidget *parent):
new WText(WString::tr("pie chart"), this);

WStandardItemModel *model = new WStandardItemModel(this);
model->setItemPrototype(new NumericItem());

//headers
model->insertColumns(model->columnCount(), 2);
Expand Down
14 changes: 7 additions & 7 deletions examples/feature/socketnotifier/SocketNotifier.C
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <iostream>
#include <boost/thread.hpp>

#if WIN32
#if WT_WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
typedef int socklen_t;
Expand Down Expand Up @@ -120,7 +120,7 @@ private:
writeNotifier_->activated().connect(this, &RssReader::write);

// Set sockets to non-blocking
#ifndef WIN32
#ifndef WT_WIN32
int flags = ::fcntl(socket_, F_GETFL, 0);
flags |= O_NONBLOCK;
::fcntl(socket_, F_SETFL, flags);
Expand All @@ -131,7 +131,7 @@ private:
// Perform a non-blocking connect. POSIX specifies that the socket
// will be marked as ready for write when the connect call completes.
int err = ::connect(socket_, info->ai_addr, info->ai_addrlen);
#ifndef WIN32
#ifndef WT_WIN32
int err2 = errno;
#else
int err2 = GetLastError();
Expand All @@ -146,7 +146,7 @@ private:
state_ = WRITE;
// write() will be invoked automatically by the notifier.
} else if (err == -1) {
#ifndef WIN32
#ifndef WT_WIN32
if (err2 == EINPROGRESS) {
#else
if (err2 == WSAEWOULDBLOCK) {
Expand Down Expand Up @@ -202,7 +202,7 @@ private:
readNotifier_->setEnabled(true);
}
} else {
#ifndef WIN32
#ifndef WT_WIN32
if (errno != EAGAIN) {
#else
if (GetLastError() == WSAEWOULDBLOCK) {
Expand All @@ -228,7 +228,7 @@ private:
addText(" Done! (Remote end closed connection)<br/>");
cleanup();
} else if (retval < 0) {
#ifndef WIN32
#ifndef WT_WIN32
if (errno != EAGAIN) {
#else
if (GetLastError() == WSAEWOULDBLOCK) {
Expand All @@ -252,7 +252,7 @@ private:
delete readNotifier_;
delete writeNotifier_;
readNotifier_ = writeNotifier_ = 0;
#ifdef WIN32
#ifdef WT_WIN32
closesocket(socket_);
#else
close(socket_);
Expand Down
4 changes: 2 additions & 2 deletions examples/hangman/Session.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <Wt/WApplication>
#include <Wt/WLogger>

#ifndef WIN32
#ifndef WT_WIN32
#include <unistd.h>
#endif

#if !defined(WIN32) && !defined(__CYGWIN__) && !defined(ANDROID)
#if !defined(WT_WIN32) && !defined(__CYGWIN__) && !defined(ANDROID)
#define HAVE_CRYPT
#endif

Expand Down
46 changes: 30 additions & 16 deletions examples/treeview-dragdrop/CsvUtil.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,38 @@

#include <Wt/WAbstractItemModel>
#include <Wt/WStandardItemModel>
#include <Wt/WStandardItem>
#include <Wt/WString>

#include "CsvUtil.h"

/*
* A standard item which converts text edits to numbers
*/
class NumericItem : public Wt::WStandardItem {
public:
virtual NumericItem *clone() const {
return new NumericItem();
}

virtual void setData(const boost::any &data, int role = Wt::UserRole) {
boost::any dt;

if (role == Wt::EditRole) {
std::string s = Wt::asString(data).toUTF8();

char *end;
double d = std::strtod(s.c_str(), &end);
if (*end == 0)
dt = boost::any(d);
else
dt = data;
}

Wt::WStandardItem::setData(dt, role);
}
};

Wt::WStandardItemModel *csvToModel(const std::string& csvFile,
Wt::WObject *parent,
bool firstLineIsHeaders)
Expand All @@ -17,6 +45,7 @@ Wt::WStandardItemModel *csvToModel(const std::string& csvFile,

if (f) {
Wt::WStandardItemModel *result = new Wt::WStandardItemModel(0, 0, parent);
result->setItemPrototype(new NumericItem());
readFromCsv(f, result, -1, firstLineIsHeaders);
return result;
} else
Expand Down Expand Up @@ -57,22 +86,7 @@ void readFromCsv(std::istream& f, Wt::WAbstractItemModel *model,
model->insertRows(model->rowCount(),
dataRow + 1 - model->rowCount());

std::string s = *i;

boost::any data;

char *end;
int i = std::strtol(s.c_str(), &end, 10);
if (*end == 0)
data = boost::any(i);
else {
double d = std::strtod(s.c_str(), &end);
if (*end == 0)
data = boost::any(d);
else
data = boost::any(Wt::WString::fromUTF8(s));
}

boost::any data(Wt::WString::fromUTF8(*i));
model->setData(dataRow, col, data);
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/widgetgallery/Services.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#if defined(WT_THREADED) || defined(WT_TARGET_JAVA)
#include <boost/thread.hpp>
#else
#if defined(WIN32)
#if WT_WIN32
#include <windows.h>
#endif
#endif
Expand Down Expand Up @@ -85,7 +85,7 @@ void StyleLayout::load(Wt::WMouseEvent) {
#if defined(WT_THREADED) || defined(WT_TARGET_JAVA)
boost::this_thread::sleep(boost::posix_time::milliseconds(2000));
#else
#ifdef WIN32
#ifdef WT_WIN32
Sleep(2000);
#else
sleep(2);
Expand Down
6 changes: 3 additions & 3 deletions examples/widgetgallery/TreesTables.C
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ Wt::WWidget *TreesTables::tableViews()
#endif
#endif

#ifndef _WIN32
#ifndef WT_WIN32
#include "examples/GitModel.cpp"
#include "examples/TreeView.cpp"
#endif

Wt::WWidget *TreesTables::treeViews()
{
Wt::WTemplate *result = new TopicTemplate("treestables-TreeViews");
#ifndef _WIN32
#ifndef WT_WIN32
result->bindWidget("TreeView", TreeView());
#else
result->bindString("TreeView", "Example not available on windows");
Expand All @@ -121,7 +121,7 @@ Wt::WWidget *TreesTables::itemModels()
Wt::WTemplate *result = new TopicTemplate("treestables-ItemModels");

result->bindWidget("LargeTableView", LargeTableView());
#ifndef _WIN32
#ifndef WT_WIN32
result->bindWidget("TreeView", TreeView());
#else
result->bindString("TreeView", "Example not available on windows");
Expand Down
10 changes: 5 additions & 5 deletions examples/widgetgallery/approot/text.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2992,13 +2992,13 @@
<tt>WMenuItem::setData()</tt>.
</li>
<li>
You can bind a separate method to each item's
<tt>WMenuItem::triggered</tt> signal.
You can use a lambda function to connect to each of the listeners.
In C++, you can use boost::bind() to bind parameters that identify the
selected item.
</li>
<li>
You can use a ${doc-link WSignalMapper} to bind extra data with an
item's <tt>WMenuItem::triggered</tt> signal, and handle them in a
single slot.
You can bind a separate method to each item's
<tt>WMenuItem::triggered</tt> signal.
</li>
</ul>
</p>
Expand Down
1 change: 1 addition & 0 deletions examples/widgetgallery/approot/wt_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<!-- <web-sockets>true</web-sockets> -->
<bootstrap-method>
<for path="*">progressive</for>
<for path="/forms/line_text-editor">default</for>
<for path="/trees-tables/mvc-table-views">default</for>
<for path="/trees-tables/mvc-tree-views">default</for>
<for path="/trees-tables/mvc-item-models">default</for>
Expand Down
Loading

0 comments on commit 7b836d9

Please sign in to comment.