Skip to content

Commit b3a1dd7

Browse files
committed
Several changes:
- Fixed bug in WWebWidget: lower addedChildren_ count if an added widget is removed - More paranoid request handling (to catch rare ackId error that may be caused by a browser's strange behaviour) - Fixed conflicting definition of Dbo4Fixture (issue #5482) - WDialog: fixed escape event not properly processed on unfocused modal dialogs - WFileDropWidget: Added missing WT_API - Issue #5436: pass WServer config arguments to subprocess on Windows. Patch adapted from one provided by Trigve Siver. - Made it possible to configure appRoot() and docRoot() in WTestEnvironment - Fix issue #5479: - Need to set font description to preferred font before pango_itemize - WPdfImage: Fix font size change not being executed - enableAjax: rerender WTableView as Ajax-enabled WTableView (issue #5470) - fix WCalendar of WDateEdit getting partially hidden in WTableView - JSON serializer should serialize NaN and infinity to null - Use app.name for a WApplication's JSignals, prevents WApplication::setObjectName() from causing not exposed Wt-unload problems - Fix sorted map of indexes being inconsisten during removal
1 parent f9f40b5 commit b3a1dd7

29 files changed

+468
-243
lines changed

examples/widgetgallery/examples/FileDrop.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,38 @@ dropWidget->drop().connect(std::bind([=] (const std::vector<Wt::WFileDropWidget:
2626

2727
dropWidget->uploaded().connect(std::bind([=] (Wt::WFileDropWidget::File* file) {
2828
std::vector<Wt::WFileDropWidget::File*> uploads = dropWidget->uploads();
29-
std::vector<Wt::WFileDropWidget::File*>::iterator it =
30-
std::find(uploads.begin(), uploads.end(), file);
31-
std::size_t idx = it - uploads.begin();
29+
std::size_t idx = 0;
30+
for (; idx != uploads.size(); ++idx)
31+
if (uploads[idx] == file)
32+
break;
3233
dropWidget->widget(idx)->removeStyleClass("spinner");
3334
dropWidget->widget(idx)->addStyleClass("ready");
3435
}, std::placeholders::_1));
3536

37+
#ifndef WT_TARGET_JAVA
3638
dropWidget->tooLarge().connect(std::bind([=] (Wt::WFileDropWidget::File *file) {
39+
#else
40+
dropWidget->tooLarge().connect(std::bind([=] (Wt::WFileDropWidget::File *file, uint64_t size) {
41+
#endif
3742
std::vector<Wt::WFileDropWidget::File*> uploads = dropWidget->uploads();
38-
std::vector<Wt::WFileDropWidget::File*>::iterator it =
39-
std::find(uploads.begin(), uploads.end(), file);
40-
std::size_t idx = it - uploads.begin();
43+
std::size_t idx = 0;
44+
for (; idx != uploads.size(); ++idx)
45+
if (uploads[idx] == file)
46+
break;
4147
dropWidget->widget(idx)->removeStyleClass("spinner");
4248
dropWidget->widget(idx)->addStyleClass("failed");
49+
#ifndef WT_TARGET_JAVA
4350
}, std::placeholders::_1));
51+
#else
52+
}, std::placeholders::_1, std::placeholders::_2));
53+
#endif
4454

4555
dropWidget->uploadFailed().connect(std::bind([=] (Wt::WFileDropWidget::File *file) {
4656
std::vector<Wt::WFileDropWidget::File*> uploads = dropWidget->uploads();
47-
std::vector<Wt::WFileDropWidget::File*>::iterator it =
48-
std::find(uploads.begin(), uploads.end(), file);
49-
std::size_t idx = it - uploads.begin();
57+
std::size_t idx = 0;
58+
for (; idx != uploads.size(); ++idx)
59+
if (uploads[idx] == file)
60+
break;
5061
dropWidget->widget(idx)->removeStyleClass("spinner");
5162
dropWidget->widget(idx)->addStyleClass("failed");
5263
}, std::placeholders::_1));

src/Wt/FontSupport.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ class FontSupport
6060
public:
6161
#ifdef HAVE_PANGO
6262

63-
FontMatch(PangoFont *font);
63+
FontMatch(PangoFont *font, PangoFontDescription *desc);
6464

6565
bool matched() const { return true; }
6666
std::string fileName() const;
6767
PangoFont *pangoFont() const { return font_; }
68+
PangoFontDescription *pangoFontDescription() const { return desc_; }
6869

6970
#else
7071

@@ -84,6 +85,7 @@ class FontSupport
8485

8586
#ifdef HAVE_PANGO
8687
mutable PangoFont *font_;
88+
PangoFontDescription *desc_;
8789
#else
8890
std::string file_;
8991
double quality_;
@@ -170,9 +172,10 @@ class FontSupport
170172
struct Matched {
171173
WFont font;
172174
PangoFont *match;
175+
PangoFontDescription *desc;
173176

174-
Matched() : font(), match(nullptr) { }
175-
Matched(const WFont& f, PangoFont *m) : font(f), match(m) { }
177+
Matched() : font(), match(nullptr), desc(nullptr) { }
178+
Matched(const WFont& f, PangoFont *m, PangoFontDescription *d) : font(f), match(m), desc(d) { }
176179
};
177180

178181
typedef std::list<Matched> MatchCache;

src/Wt/FontSupportPango.C

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ FontSupport::Bitmap::~Bitmap()
8787
delete[] buffer_;
8888
}
8989

90-
FontSupport::FontMatch::FontMatch(PangoFont *font)
91-
: font_(font)
90+
FontSupport::FontMatch::FontMatch(PangoFont *font, PangoFontDescription *desc)
91+
: font_(font), desc_(desc)
9292
{ }
9393

9494
std::string FontSupport::FontMatch::fileName() const
@@ -196,7 +196,7 @@ FontSupport::FontMatch FontSupport::matchFont(const WFont& f) const
196196
for (MatchCache::iterator i = cache_.begin(); i != cache_.end(); ++i) {
197197
if (i->font == f) {
198198
cache_.splice(cache_.begin(), cache_, i); // implement LRU
199-
return FontMatch(i->match);
199+
return FontMatch(i->match, i->desc);
200200
}
201201
}
202202

@@ -208,15 +208,16 @@ FontSupport::FontMatch FontSupport::matchFont(const WFont& f) const
208208

209209
PangoFont *match = pango_font_map_load_font(pangoFontMap, context_, desc);
210210
pango_context_set_font_description(context_, desc); // for layoutText()
211-
pango_font_description_free(desc);
212211

213-
if (cache_.back().match)
212+
if (cache_.back().match) {
214213
g_object_unref(cache_.back().match);
214+
pango_font_description_free(cache_.back().desc);
215+
}
215216

216217
cache_.pop_back();
217-
cache_.push_front(Matched(f, match));
218+
cache_.push_front(Matched(f, match, desc));
218219

219-
return FontMatch(match);
220+
return FontMatch(match, desc);
220221
}
221222

222223
void FontSupport::addFontCollection(const std::string& directory,
@@ -259,9 +260,10 @@ GList *FontSupport::layoutText(const WFont& font,
259260

260261
enabledFontFormats = enabledFontFormats_;
261262

262-
matchFont(font);
263+
FontMatch match = matchFont(font);
263264
PangoAttrList *attrs = pango_attr_list_new();
264265

266+
pango_context_set_font_description(context_, match.pangoFontDescription());
265267
GList *items
266268
= pango_itemize(context_, utf8.c_str(), 0, utf8.length(), attrs, nullptr);
267269

@@ -345,7 +347,8 @@ void FontSupport::drawText(const WFont& font, const WRectF& rect,
345347
* is a pitty and possibly wrong if the device does not make the
346348
* same selection !
347349
*/
348-
WString s = WString::fromUTF8(utf8.substr(item->offset, item->length));
350+
WString s = WString::fromUTF8(utf8.substr(item->offset,
351+
item->length));
349352

350353
device_->drawText(WRectF(x, rect.y(),
351354
1000, rect.height()),

src/Wt/Json/Serializer.C

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "EscapeOStream.h"
88
#include "WebUtils.h"
99

10+
#include <limits>
1011
#include <set>
1112
#include "boost/lexical_cast.hpp"
1213
#include "boost/algorithm/string/replace.hpp"
@@ -46,8 +47,13 @@ void serialize(const Value& val, int indentation, EscapeOStream &result)
4647
double intpart;
4748
if (fabs(std::modf(val, &intpart)) == 0.0 && fabs(intpart) < 9.22E18)
4849
result << (long long)intpart;
49-
else
50-
result << Utils::round_js_str(static_cast<double>(val), 16, buf);
50+
else {
51+
double d = val;
52+
if (Utils::isNaN(d) || fabs(d) == std::numeric_limits<double>::infinity())
53+
result << ("null");
54+
else
55+
result << Utils::round_js_str(d, 16, buf);
56+
}
5157
return;
5258
}
5359
break;

src/Wt/Test/WTestEnvironment

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,20 @@ public:
250250
*/
251251
void setInternalPath(const std::string& internalPath);
252252

253+
#ifndef WT_TARGET_JAVA
254+
/*! \brief Sets the server's appRoot
255+
*
256+
* \sa WServer::appRoot()
257+
*/
258+
void setAppRoot(const std::string& appRoot);
259+
260+
/*! \brief Sets the docRoot
261+
*
262+
* \sa WApplication::docRoot()
263+
*/
264+
void setDocRoot(const std::string& docRoot);
265+
#endif // WT_TARGET_JAVA
266+
253267
/*! \brief %Signal used to test a dialog/messagebox reentrant event
254268
* loop.
255269
*

src/Wt/Test/WTestEnvironment.C

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,18 @@ void WTestEnvironment::setInternalPath(const std::string& internalPath)
226226
WEnvironment::setInternalPath(internalPath);
227227
}
228228

229+
#ifndef WT_TARGET_JAVA
230+
void WTestEnvironment::setAppRoot(const std::string &appRoot)
231+
{
232+
server_->setAppRoot(appRoot);
233+
}
234+
235+
void WTestEnvironment::setDocRoot(const std::string &docRoot)
236+
{
237+
session_->setDocRoot(docRoot);
238+
}
239+
#endif // WT_TARGET_JAVA
240+
229241
void WTestEnvironment::setUserAgent(const std::string& userAgent)
230242
{
231243
WEnvironment::setUserAgent(userAgent);

src/Wt/WAbstractProxyModel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,13 @@ protected:
250250
* model has inserted or removed rows. When removing rows (count < 0),
251251
* items may possibly be removed and deleted.
252252
*/
253-
void shiftModelIndexes(const WModelIndex& sourceParent, int start, int count,
254-
ItemMap& items);
253+
void startShiftModelIndexes(const WModelIndex& sourceParent, int start, int count,
254+
ItemMap& items);
255+
void endShiftModelIndexes(const WModelIndex& sourceParent, int start, int count,
256+
ItemMap& items);
255257

256258
private:
259+
std::vector<BaseItem *> itemsToShift_;
257260
std::shared_ptr<WAbstractItemModel> sourceModel_;
258261
};
259262

src/Wt/WAbstractProxyModel.C

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ WModelIndex WAbstractProxyModel::fromRawIndex(void *rawIndex) const
9292
return mapFromSource(sourceModel_->fromRawIndex(rawIndex));
9393
}
9494

95-
WFlags<HeaderFlag> WAbstractProxyModel::headerFlags(int section,
96-
Orientation orientation)
97-
const
95+
WFlags<HeaderFlag> WAbstractProxyModel::headerFlags(int section,
96+
Orientation orientation) const
9897
{
9998
if (orientation == Wt::Orientation::Horizontal) {
10099
section = mapToSource(index(0, section, Wt::WModelIndex())).column();
@@ -121,26 +120,21 @@ WModelIndex WAbstractProxyModel::createSourceIndex(int row, int column,
121120
return sourceModel_->createIndex(row, column, ptr);
122121
}
123122

124-
void WAbstractProxyModel::shiftModelIndexes(const WModelIndex& sourceParent,
125-
int start, int count,
126-
ItemMap& items)
123+
void WAbstractProxyModel::startShiftModelIndexes(const WModelIndex& sourceParent,
124+
int start, int count,
125+
ItemMap& items)
127126
{
128127
/*
129128
* We must shift all indexes within sourceParent >= start with count
130129
* and delete items when count < 0.
131-
*
132-
* If count > 0 : rows inserted, after insertion
133-
* If count < 0 : rows to be removed, before removal
134130
*/
135-
std::vector<BaseItem *> shifted;
136131
std::vector<BaseItem *> erased;
137132

138133
WModelIndex startIndex;
139134
if (sourceModel()->rowCount(sourceParent) == 0)
140135
startIndex = sourceParent;
141136
else if (start >= sourceModel()->rowCount(sourceParent))
142-
startIndex = sourceModel()->index(sourceModel()->rowCount(sourceParent)-1,0,
143-
sourceParent);
137+
return;
144138
else
145139
startIndex = sourceModel()->index(start, 0, sourceParent);
146140

@@ -156,22 +150,27 @@ void WAbstractProxyModel::shiftModelIndexes(const WModelIndex& sourceParent,
156150
++n;
157151
#endif
158152
WModelIndex i = it->first;
159-
if (i == sourceParent)
153+
if (i == sourceParent) {
154+
#ifndef WT_TARGET_JAVA
155+
it = n;
156+
#endif
160157
continue;
158+
}
161159

162160
if (i.isValid()) {
163161
WModelIndex p = i.parent();
164162
if (p != sourceParent && !WModelIndex::isAncestor(p, sourceParent))
165163
break;
166164

167-
if (p == sourceParent) {
165+
if (p == sourceParent) { /* Child of source parent: shift or remove */
168166
if (count < 0 &&
169167
i.row() >= start &&
170168
i.row() < start + (-count))
171169
erased.push_back(it->second);
172-
else
173-
shifted.push_back(it->second);
174-
} else if (count < 0) {
170+
else {
171+
itemsToShift_.push_back(it->second);
172+
}
173+
} else if (count < 0) { /* Other descendent: remove if necessary */
175174
// delete indexes that are about to be deleted, if they are within
176175
// the range of deleted indexes
177176
do {
@@ -191,32 +190,35 @@ void WAbstractProxyModel::shiftModelIndexes(const WModelIndex& sourceParent,
191190
#endif
192191
}
193192

193+
for (unsigned i = 0; i < itemsToShift_.size(); ++i) {
194+
BaseItem *item = itemsToShift_[i];
195+
items.erase(item->sourceIndex_);
196+
item->sourceIndex_ = sourceModel()->index
197+
(item->sourceIndex_.row() + count,
198+
item->sourceIndex_.column(),
199+
sourceParent);
200+
}
201+
194202
for (unsigned i = 0; i < erased.size(); ++i) {
195203
items.erase(erased[i]->sourceIndex_);
196204
delete erased[i];
197205
}
198206

199-
for (unsigned i = 0; i < shifted.size(); ++i) {
200-
BaseItem *item = shifted[i];
201-
items.erase(item->sourceIndex_);
202-
203-
if (item->sourceIndex_.row() + count >= start) {
204-
item->sourceIndex_ = sourceModel()->index
205-
(item->sourceIndex_.row() + count,
206-
item->sourceIndex_.column(),
207-
sourceParent);
208-
} else {
209-
delete item;
210-
shifted[i] = nullptr;
211-
}
212-
}
207+
if (count > 0)
208+
endShiftModelIndexes(sourceParent, start, count, items);
209+
}
210+
211+
void WAbstractProxyModel::endShiftModelIndexes(const WModelIndex& sourceParent,
212+
int start, int count,
213+
ItemMap& items)
214+
{
215+
for (unsigned i = 0; i < itemsToShift_.size(); ++i)
216+
items[itemsToShift_[i]->sourceIndex_] = itemsToShift_[i];
213217

214-
for (unsigned i = 0; i < shifted.size(); ++i) {
215-
if (shifted[i])
216-
items[shifted[i]->sourceIndex_] = shifted[i];
217-
}
218+
itemsToShift_.clear();
218219
}
219220

221+
220222
#endif // DOXYGEN_ONLY
221223

222224
}

src/Wt/WApplication.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ WApplication::decodeExposedSignal(const std::string& signalName) const
773773
std::string WApplication::encodeSignal(const std::string& objectId,
774774
const std::string& name) const
775775
{
776-
return (objectId == "app" ? id() : objectId) + '.' + name;
776+
return objectId + '.' + name;
777777
}
778778

779779
std::string WApplication::resourceMapKey(WResource *resource)

0 commit comments

Comments
 (0)