Skip to content

Commit

Permalink
Several changes:
Browse files Browse the repository at this point in the history
    - WApplication::singlePixelGifUrl(): make sure resource isn't GC'ed (in Java), and use data URL when possible
    - WCartesianChart: Support for descending X axis values for followCurve
    - CMakeLists.txt: so version bump
    - WMenu: do not allow hidden menu items to be selected (by internal path changes)
    - WMenu: make sure a disabled menu item isn't being selected by internal paths
    - Added Auth::AuthModel::setRememberMeCookie() and ability to specify cookie domain
    - WCartesianChart: Only use JavaScript bound WTransforms when interactive
  • Loading branch information
Koen Deforche committed Sep 29, 2015
1 parent 4e0ac55 commit 3fb7e72
Show file tree
Hide file tree
Showing 23 changed files with 242 additions and 124 deletions.
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ SET(VERSION_SERIES 3)
SET(VERSION_MAJOR 3)
SET(VERSION_MINOR 5)

SET(WT_SOVERSION 38)
SET(WTEXT_SOVERSION 38)
SET(WTHTTP_SOVERSION 38)
SET(WTFCGI_SOVERSION 38)
SET(WTISAPI_SOVERSION 14)
SET(WTDBO_SOVERSION 38)
SET(WTDBOSQLITE3_SOVERSION 38)
SET(WTDBOPOSTGRES_SOVERSION 38)
SET(WTDBOFIREBIRD_SOVERSION 38)
SET(WTDBOMYSQL_SOVERSION 38)
SET(WTTEST_SOVERSION 8)
SET(WT_SOVERSION 39)
SET(WTEXT_SOVERSION 39)
SET(WTHTTP_SOVERSION 39)
SET(WTFCGI_SOVERSION 39)
SET(WTISAPI_SOVERSION 15)
SET(WTDBO_SOVERSION 39)
SET(WTDBOSQLITE3_SOVERSION 39)
SET(WTDBOPOSTGRES_SOVERSION 39)
SET(WTDBOFIREBIRD_SOVERSION 39)
SET(WTDBOMYSQL_SOVERSION 39)
SET(WTTEST_SOVERSION 9)

IF(NOT SHARED_LIBS)
IF(WIN32)
Expand Down
3 changes: 2 additions & 1 deletion examples/treeview-dragdrop/CsvUtil.C
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public:
dt = boost::any(d);
else
dt = data;
}
} else
dt = data;

Wt::WStandardItem::setData(dt, role);
}
Expand Down
6 changes: 6 additions & 0 deletions src/Wt/Auth/AuthModel
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public:
*/
virtual EmailTokenResult processEmailToken(const std::string& token);

/*! \brief Creates a token and stores it in a cookie.
*
* This enables automatic authentication in a next session.
*/
virtual void setRememberMeCookie(const User& user);

/*! \brief Detects and processes an authentication token.
*
* This returns a user that was identified with an authentication token
Expand Down
20 changes: 13 additions & 7 deletions src/Wt/Auth/AuthModel.C
Original file line number Diff line number Diff line change
Expand Up @@ -167,22 +167,28 @@ bool AuthModel::validate()
return result;
}

void AuthModel::setRememberMeCookie(const User& user)
{
WApplication *app = WApplication::instance();
const AuthService *s = baseAuth();

app->setCookie(s->authTokenCookieName(),
s->createAuthToken(user),
s->authTokenValidity() * 60,
s->authTokenCookieDomain());
}

bool AuthModel::login(Login& login)
{
if (valid()) {
User user = users().findWithIdentity(Identity::LoginName,
valueText(LoginNameField));
boost::any v = value(RememberMeField);
const AuthService *s = baseAuth();
if (loginUser(login, user)) {
reset();

if (!v.empty() && boost::any_cast<bool>(v) == true) {
WApplication *app = WApplication::instance();
app->setCookie(s->authTokenCookieName(),
s->createAuthToken(user),
s->authTokenValidity() * 60);
}
if (!v.empty() && boost::any_cast<bool>(v) == true)
setRememberMeCookie(user);

return true;
} else
Expand Down
16 changes: 15 additions & 1 deletion src/Wt/Auth/AuthService
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ public:
* \sa setTokenHashFunction(), setAuthTokenValidity()
*/
void setAuthTokensEnabled(bool enabled,
const std::string& cookieName = "wtauth");
const std::string& cookieName = "wtauth",
const std::string& cookieDomain = std::string());

/*! \brief Returns whether authentication tokens are enabled.
*
Expand All @@ -333,6 +334,18 @@ public:
*/
std::string authTokenCookieName() const { return authTokenCookieName_; }

/*! \brief Returns the authentication token cookie domain.
*
* This is the domain used for the authentication cookie. By default this
* is empty, which means that a cookie will be set for this application.
*
* You may want to set a more general domain if you are sharing the authentication
* with multiple applications.
*
* \sa setAuthTokensEnabled()
*/
std::string authTokenCookieDomain() const { return authTokenCookieDomain_; }

/*! \brief Sets the token hash function.
*
* Sets the hash function used to safely store authentication tokens
Expand Down Expand Up @@ -568,6 +581,7 @@ private:
bool authTokens_;
int authTokenValidity_; // minutes
std::string authTokenCookieName_;
std::string authTokenCookieDomain_;
};

}
Expand Down
4 changes: 3 additions & 1 deletion src/Wt/Auth/AuthService.C
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ void AuthService::setIdentityPolicy(IdentityPolicy identityPolicy)
identityPolicy_ = identityPolicy;
}

void AuthService::setAuthTokensEnabled(bool enabled, const std::string& cookieName)
void AuthService::setAuthTokensEnabled(bool enabled, const std::string& cookieName,
const std::string& cookieDomain)
{
authTokens_ = enabled;
authTokenCookieName_ = cookieName;
authTokenCookieDomain_ = cookieDomain;
}

User AuthService::identifyUser(const Identity& identity,
Expand Down
2 changes: 1 addition & 1 deletion src/Wt/Chart/WAxisSliderWidget.C
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void WAxisSliderWidget::paintEvent(WPaintDevice *paintDevice)

double maxW = w - left - right;
WRectF drawArea(left, 0, maxW, h);
std::vector<WAxis::Segment> segmentsBak = chart_->axis(XAxis).segments_;
std::vector<WAxis::Segment> segmentsBak = std::vector<WAxis::Segment>(chart_->axis(XAxis).segments_);
double renderIntervalBak = chart_->axis(XAxis).renderInterval_;
chart_->axis(XAxis).prepareRender(horizontal ? Horizontal : Vertical, drawArea.width());

Expand Down
23 changes: 13 additions & 10 deletions src/Wt/Chart/WCartesianChart
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ public:
void setLegendColumns(int columns, const WLength& width);

virtual void paint(WPainter& painter, const WRectF& rectangle = WRectF())
const;
const WT_CXX11ONLY(override);

/*! \brief Draws the marker for a given data series.
*
Expand Down Expand Up @@ -786,6 +786,9 @@ public:
* follow curve functionality has priority over the crosshair functionality.
*
* Use column index -1 or disableFollowCurve() to disable the follow curve feature.
*
* \note The follow curve functionality requires that the X axis values of the data series
* are strictly increasing or strictly decreasing.
*/
void setFollowCurve(int modelColumn);

Expand Down Expand Up @@ -891,20 +894,20 @@ private:

protected:
virtual void modelColumnsInserted(const WModelIndex& parent,
int start, int end);
int start, int end) WT_CXX11ONLY(override);
virtual void modelColumnsRemoved(const WModelIndex& parent,
int start, int end);
int start, int end) WT_CXX11ONLY(override);
virtual void modelRowsInserted(const WModelIndex& parent,
int start, int end);
int start, int end) WT_CXX11ONLY(override);
virtual void modelRowsRemoved(const WModelIndex& parent,
int start, int end);
int start, int end) WT_CXX11ONLY(override);
virtual void modelDataChanged(const WModelIndex& topLeft,
const WModelIndex& bottomRight);
const WModelIndex& bottomRight) WT_CXX11ONLY(override);
virtual void modelHeaderDataChanged(Orientation orientation,
int start, int end);
int start, int end) WT_CXX11ONLY(override);

virtual void modelChanged();
virtual void modelReset();
virtual void modelChanged() WT_CXX11ONLY(override);
virtual void modelReset() WT_CXX11ONLY(override);

/** @name Rendering logic
*/
Expand All @@ -913,7 +916,7 @@ protected:
*
* This calls render() to paint on the paint device.
*/
void paintEvent(WPaintDevice *paintDevice);
virtual void paintEvent(WPaintDevice *paintDevice) WT_CXX11ONLY(override);

/*! \brief Renders the chart.
*
Expand Down
28 changes: 21 additions & 7 deletions src/Wt/Chart/WCartesianChart.C
Original file line number Diff line number Diff line change
Expand Up @@ -854,8 +854,8 @@ void WCartesianChart::init()

xTransformHandle_ = createJSTransform();
yTransformHandle_ = createJSTransform();
xTransform_ = xTransformHandle_.value();
yTransform_ = yTransformHandle_.value();
xTransform_ = WTransform();
yTransform_ = WTransform();

if (WApplication::instance() != 0) {
mouseWentDown().connect("function(o, e){var o=" + this->cObjJsRef() + ";if(o){o.mouseDown(o, e);}}");
Expand Down Expand Up @@ -1776,6 +1776,11 @@ void WCartesianChart::render(WPainter& painter, const WRectF& rectangle) const
painter.save();
painter.translate(rectangle.topLeft());

if (isInteractive()) {
xTransform_ = xTransformHandle_.value();
yTransform_ = yTransformHandle_.value();
}

if (initLayout(rectangle, painter.device())) {
renderBackground(painter);
renderGrid(painter, axis(XAxis));
Expand All @@ -1787,6 +1792,11 @@ void WCartesianChart::render(WPainter& painter, const WRectF& rectangle) const
renderBorder(painter);
renderLegend(painter);
}

if (isInteractive()) {
xTransform_ = WTransform();
yTransform_ = WTransform();
}

painter.restore();
}
Expand Down Expand Up @@ -1828,8 +1838,10 @@ bool WCartesianChart::initLayout(const WRectF& rectangle, WPaintDevice *device)
yTransform_ = WTransform();

if (chartArea_.width() <= 5 || chartArea_.height() <= 5 || !prepareAxes()) {
xTransform_ = xTransformHandle_.value();
yTransform_ = yTransformHandle_.value();
if (isInteractive()) {
xTransform_ = xTransformHandle_.value();
yTransform_ = yTransformHandle_.value();
}
return false;
}

Expand Down Expand Up @@ -1867,8 +1879,10 @@ bool WCartesianChart::initLayout(const WRectF& rectangle, WPaintDevice *device)

bool result = chartArea_.width() > 5 && chartArea_.height() > 5 && prepareAxes();

xTransform_ = xTransformHandle_.value();
yTransform_ = yTransformHandle_.value();
if (isInteractive()) {
xTransform_ = xTransformHandle_.value();
yTransform_ = yTransformHandle_.value();
}

return result;
}
Expand Down Expand Up @@ -2828,7 +2842,7 @@ void WCartesianChart::renderLegend(WPainter& painter) const
+ (w - plotAreaPadding(Left) - plotAreaPadding(Right)) / 2 ;
painter.save();
painter.setFont(titleFont());
int titleHeight = titleFont().sizeLength().toPixels();
double titleHeight = titleFont().sizeLength().toPixels();
const int TITLE_PADDING = 10;
painter.drawText(x - 500,
plotAreaPadding(Top) - titleHeight - TITLE_PADDING,
Expand Down
2 changes: 1 addition & 1 deletion src/Wt/Json/Value.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LOGGER("Json.Value");

TypeException::TypeException(const std::string& name,
Type actualType, Type expectedType)
: WException("Type error: " + name_ + " is " + typeNames[actualType]
: WException("Type error: " + name + " is " + typeNames[actualType]
+ ", expected " + typeNames[expectedType]),
name_(name),
actualType_(actualType),
Expand Down
2 changes: 1 addition & 1 deletion src/Wt/WApplication
Original file line number Diff line number Diff line change
Expand Up @@ -2225,7 +2225,7 @@ private:
AjaxMethod ajaxMethod_;
bool quitted_;
WString quittedMessage_;
std::string onePixelGifUrl_;
WResource *onePixelGifR_;
bool internalPathsEnabled_;
WWidget *exposedOnly_;
WLoadingIndicator *loadingIndicator_;
Expand Down
33 changes: 19 additions & 14 deletions src/Wt/WApplication.C
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ WApplication::WApplication(const WEnvironment& env
#endif // WT_CNOR
javaScriptClass_("Wt"),
quitted_(false),
onePixelGifR_(0),
internalPathsEnabled_(false),
exposedOnly_(0),
loadingIndicator_(0),
Expand Down Expand Up @@ -353,21 +354,25 @@ WMessageResourceBundle& WApplication::messageResourceBundle()

std::string WApplication::onePixelGifUrl()
{
if (onePixelGifUrl_.empty()) {
WMemoryResource *w = new WMemoryResource("image/gif", this);

static const unsigned char gifData[]
= { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
0x80, 0x00, 0x00, 0xdb, 0xdf, 0xef, 0x00, 0x00, 0x00, 0x21,
0xf9, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
0x01, 0x00, 0x3b };

w->setData(gifData, 43);
onePixelGifUrl_ = w->url();
}
if (environment().agentIsIElt(7)) {
if (!onePixelGifR_) {
WMemoryResource *w = new WMemoryResource("image/gif", this);

static const unsigned char gifData[]
= { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x01, 0x00, 0x01, 0x00,
0x80, 0x00, 0x00, 0xdb, 0xdf, 0xef, 0x00, 0x00, 0x00, 0x21,
0xf9, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00,
0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44,
0x01, 0x00, 0x3b };

w->setData(gifData, 43);
onePixelGifR_ = w;
}

return onePixelGifUrl_;
return onePixelGifR_->url();
} else
return "data:image/gif;base64,"
"R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
}

WApplication::~WApplication()
Expand Down
2 changes: 0 additions & 2 deletions src/Wt/WCanvasPaintDevice.C
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ void WCanvasPaintDevice::render(const std::string& canvasId,

tmp << "}";

text->callJavaScript(tmp.str());

for (unsigned i = 0; i < textElements_.size(); ++i)
text->addChild(textElements_[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Wt/WCircleArea
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private:
double x_, y_, r_;

protected:
virtual bool updateDom(DomElement& element, bool all);
virtual bool updateDom(DomElement& element, bool all) WT_CXX11ONLY(override);
virtual std::string updateAreaCoordsJS() WT_CXX11ONLY(override);
};

Expand Down
7 changes: 5 additions & 2 deletions src/Wt/WMenu.C
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ int WMenu::nextAfterHide(int index)
if (current_ == index) {
// Try to find visible item to the right of the current.
for (int i = current_ + 1; i < count(); ++i)
if (!isItemHidden(i))
if (!isItemHidden(i) && itemAt(i)->isEnabled())
return i;

// Try to find visible item to the left of the current.
for (int i = current_ - 1; i >= 0; --i)
if (!isItemHidden(i))
if (!isItemHidden(i) && itemAt(i)->isEnabled())
return i;
}

Expand Down Expand Up @@ -477,6 +477,9 @@ void WMenu::internalPathChanged(const std::string& path)
int bestI = -1, bestMatchLength = -1;

for (int i = 0; i < count(); ++i) {
if (!itemAt(i)->isEnabled() || itemAt(i)->isHidden())
continue;

int matchLength = match(subPath, itemAt(i)->pathComponent());

if (matchLength > bestMatchLength) {
Expand Down
4 changes: 4 additions & 0 deletions src/Wt/WMenuItem
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ public:

virtual void enableAjax();

virtual void setHidden(bool hidden,
const WAnimation& animation = WAnimation());
virtual void setDisabled(bool disabled);

protected:
virtual void render(WFlags<RenderFlag> flags);

Expand Down
Loading

0 comments on commit 3fb7e72

Please sign in to comment.