Project

General

Profile

Bug #7669 » 0002-Fix-WPopupWidget-use-in-autocomplete-example.patch

Bruce Toll, 07/28/2020 10:29 PM

View differences:

examples/widgetgallery/examples/AutoComplete.cpp
contactOptions.appendReplacedText = ", ";
Wt::WSuggestionPopup *sp =
container->addNew<Wt::WSuggestionPopup>(
container->addChildNew<Wt::WSuggestionPopup>(
Wt::WSuggestionPopup::generateMatcherJS(contactOptions),
Wt::WSuggestionPopup::generateReplacerJS(contactOptions));
src/Wt/WContainerWidget.h
template <typename Widget, typename ...Args>
Widget *addNew( Args&& ...args )
{
static_assert(!std::is_convertible<Widget*, WPopupWidget*>::value,
"Cannot use addNew() for types derived from WPopupWidget. "
"Did you mean to use addChildNew()?");
std::unique_ptr<Widget> w{new Widget(std::forward<Args>(args)...)};
Widget *result = w.get();
addWidget(std::unique_ptr<WWidget>{std::move(w)});
src/Wt/WObject.h
return result;
}
/*! \brief Create a child WObject and add it, returning a raw pointer.
*
* This is implemented as:
*
* \code
* std::unique_ptr<Child> child{new Child(std::forward<Args>(args)...)};
* Child *result = child.get();
* addChild(std::unique_ptr<WObject>(std::move(child)));
* return result;
* \endcode
*
* This is a useful shorthand for adding a new child object, and
* getting a reference to it, e.g.:
*
* \code
* Wt::WMessageBox *mb = addChildNew<Wt::WMessageBox>("Status", "All is well...", Wt::Icon::Information, Wt::StandardButton::Ok);
* \endcode
*/
template <typename Child, typename ...Args>
Child *addChildNew( Args&& ...args )
{
std::unique_ptr<Child> child{new Child(std::forward<Args>(args)...)};
Child *result = child.get();
addChild(std::unique_ptr<WObject>(std::move(child)));
return result;
}
/*! \brief Remove a child WObject, so its lifetime is no longer determined by this WObject
*/
std::unique_ptr<WObject> removeChild(WObject *child);
(2-2/3)