Skip to content

Commit 11485bb

Browse files
author
Koen Deforche
committed
Several updates:
- allow HTML5 history to process state-pop's from a previous session - support XHTML tooltips in item models - memory fixes for WMenuItem. This code crashed on session destruction: - fix drag/drop regression initiated on an inline element
1 parent 2252884 commit 11485bb

File tree

9 files changed

+122
-72
lines changed

9 files changed

+122
-72
lines changed

src/Wt/WItemDelegate.C

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ WWidget *WItemDelegate::update(WWidget *widget, const WModelIndex& index,
140140

141141
WString tooltip = asString(index.data(ToolTipRole));
142142
if (!tooltip.empty() || !isNew)
143-
widgetRef.w->setToolTip(tooltip);
143+
widgetRef.w->setToolTip(tooltip,
144+
(index.flags() & ItemIsXHTMLText) ?
145+
XHTMLText : PlainText);
144146

145147
WT_USTRING sc = asString(index.data(StyleClassRole));
146148

src/Wt/WMenuItem

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ public:
299299
* this item.
300300
*/
301301
WWidget *contents() const;
302+
302303
WWidget *takeContents();
303304

304305
/*! \brief Returns the widget that represents the item (<b>deprecated</b>).
@@ -371,6 +372,7 @@ private:
371372
bool separator_, selectable_, signalsConnected_;
372373

373374
Signal<WMenuItem *> triggered_;
375+
Wt::Signals::connection contentsDestroyedConnection_;
374376

375377
std::string pathComponent_;
376378
bool customPathComponent_, internalPathEnabled_;
@@ -390,6 +392,7 @@ private:
390392
void connectClose();
391393
void connectSignals();
392394
void setItemPadding(bool padding);
395+
void contentsDestroyed();
393396

394397
friend class WMenu;
395398
friend class WPopupMenu;

src/Wt/WMenuItem.C

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ void WMenuItem::create(const std::string& iconPath, const WString& text,
6262
{
6363
contentsContainer_ = 0;
6464
contents_ = contents;
65+
66+
#ifndef WT_CNOR
67+
// contents' ownership will be moved to a containerwidget once
68+
// it is in the widget tree (contentsLoaded). In any case, if
69+
// contents_ is destroyed elsewhere, we want to know about it.
70+
contentsDestroyedConnection_ =
71+
contents_->destroyed().connect(this, &WMenuItem::contentsDestroyed);
72+
#endif // WT_CNOR
73+
6574
menu_ = 0;
6675
customPathComponent_ = false;
6776
internalPathEnabled_ = true;
@@ -378,6 +387,8 @@ bool WMenuItem::contentsLoaded() const
378387

379388
void WMenuItem::loadContents()
380389
{
390+
if (!contents_)
391+
return;
381392
if (!contentsLoaded()) {
382393
contentsContainer_->addWidget(contents_);
383394
signalsConnected_ = false;
@@ -434,20 +445,34 @@ WWidget *WMenuItem::contents() const
434445

435446
WWidget *WMenuItem::takeContents()
436447
{
448+
if (contents_ == 0)
449+
return 0;
450+
437451
WWidget *result = contents_;
438452

439-
if (contentsLoaded())
453+
if (contentsLoaded()) {
440454
if (contentsContainer_)
441455
contentsContainer_->removeWidget(contents_);
456+
} else {
457+
// contents_ is still owned by WMenuItem -> setting ptr to 0 is ok
458+
}
442459

460+
if (contentsDestroyedConnection_.connected())
461+
contentsDestroyedConnection_.disconnect();
443462
contents_ = 0;
444463

445464
return result;
446465
}
447466

448467
void WMenuItem::purgeContents()
449468
{
469+
// this is called to avoid dangling pointers to objects that are deleted
450470
contentsContainer_ = 0;
471+
// two cases are possible for contents: either ownership is with WMenuItem,
472+
// or it was with the destroyed container. In the first case, we have to
473+
// delete, while in the second case, contents_ will already be deleted and
474+
// set to 0 by the contentsDestroyed() slot
475+
delete contents_;
451476
contents_ = 0;
452477
}
453478

@@ -515,4 +540,10 @@ void WMenuItem::setItemPadding(bool padding)
515540
}
516541
}
517542

543+
void WMenuItem::contentsDestroyed()
544+
{
545+
contentsContainer_ = 0;
546+
contents_ = 0;
547+
}
548+
518549
}

src/Wt/WModelIndex

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,19 @@ typedef std::treeset<WModelIndex> WModelIndexSet;
113113
* \ingroup modelview
114114
*/
115115
enum ItemDataRole {
116-
DisplayRole = 0, //!< Role for textual representation
117-
DecorationRole = 1, //!< Role for the url of an icon
118-
EditRole = 2, //!< Role for the edited value
119-
StyleClassRole = 3, //!< Role for the style class
120-
/*! Role that indicates the check state. Data for this role should be
121-
* a <tt>bool</tt>. When the Wt::ItemIsTristate flag is set for the item,
122-
* data for this role should be of type Wt::CheckState.
116+
DisplayRole = 0, //!< Role for textual representation
117+
DecorationRole = 1, //!< Role for the url of an icon
118+
EditRole = 2, //!< Role for the edited value
119+
StyleClassRole = 3, //!< Role for the style class
120+
121+
/*! Role that indicates the check state.
122+
*
123+
* Data for this role should be a <tt>bool</tt>. When the
124+
* Wt::ItemIsTristate flag is set for the item, data for this role
125+
* should be of type Wt::CheckState.
123126
*/
124127
CheckStateRole = 4,
125-
ToolTipRole = 5, //!< Role for a tooltip
128+
ToolTipRole = 5, //!< Role for a (plain) tooltip
126129
LinkRole = 6, //!< Role for a link
127130
MimeTypeRole = 7, //!< Role for mime type information
128131
LevelRole = 8, //!< Level in aggregation, for header data.
@@ -148,11 +151,13 @@ enum ItemFlag {
148151
ItemIsUserCheckable = 0x4, //!< Item can be checked (checkbox is enabled)
149152
ItemIsDragEnabled = 0x8, //!< Item can be dragged
150153
ItemIsDropEnabled = 0x10, //!< Item can be a drop target
151-
/*! Item has tree states. When set, Wt::CheckStateRole data is of type
154+
/*! Item has tree states.
155+
*
156+
* When set, Wt::CheckStateRole data is of type
152157
* Wt::CheckState
153158
*/
154159
ItemIsTristate = 0x20,
155-
ItemIsXHTMLText = 0x40, //!< Item's textual is HTML
160+
ItemIsXHTMLText = 0x40, //!< Item's text (DisplayRole, ToolTipRole) is HTML
156161
ItemIsDirty = 0x80 //!< Item's value has been modified
157162
};
158163

src/Wt/WStandardItem.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void WStandardItem::setEditable(bool editable)
370370
signalModelDataChange();
371371
}
372372
else if (isEditable() && !editable) {
373-
flags_ ^= ItemIsEditable;
373+
flags_.clear(ItemIsEditable);
374374
signalModelDataChange();
375375
}
376376
}

src/Wt/WTableView.C

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,10 @@ WTableView::WTableView(WContainerWidget *parent)
166166
"if (obj) obj.autoJavaScript();}");
167167

168168
connectObjJS(canvas_->mouseWentDown(), "mouseDown");
169-
connectObjJS(contentsContainer_->scrolled(),
170-
"onContentsContainerScroll");
169+
170+
/* Two-lines needed for WT_PORT */
171+
EventSignalBase& ccScrolled = contentsContainer_->scrolled();
172+
connectObjJS(ccScrolled, "onContentsContainerScroll");
171173
} else {
172174
plainTable_ = new WTable();
173175
plainTable_->setStyleClass("Wt-plaintable");

src/js/WTableView.min.js

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/web/skeleton/Wt.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,8 +1620,14 @@ if (html5History) {
16201620
newState = stateMap[w.location.pathname + w.location.search];
16211621

16221622
if (newState == null) {
1623-
saveState(currentState);
1624-
return;
1623+
var endw = w.location.pathname.lastIndexOf(currentState);
1624+
if (endw != -1 &&
1625+
endw == w.location.pathname.length - currentState.length) {
1626+
saveState(currentState);
1627+
return;
1628+
} else {
1629+
newState = w.location.pathname.substr(baseUrl.length);
1630+
}
16251631
}
16261632

16271633
if (newState != currentState) {
@@ -2044,8 +2050,9 @@ function dragStart(obj, e) {
20442050
/*
20452051
* Ignore drags that start on a scrollbar (#1231)
20462052
*/
2047-
if (t.offsetWidth > t.clientWidth
2048-
|| t.offsetHeight > t.clientHeight) {
2053+
if (WT.css(t, 'display') !== 'inline' &&
2054+
(t.offsetWidth > t.clientWidth ||
2055+
t.offsetHeight > t.clientHeight)) {
20492056
var wc = WT.widgetPageCoordinates(t);
20502057
var pc = WT.pageCoordinates(e);
20512058
var x = pc.x - wc.x;

0 commit comments

Comments
 (0)