/usr/include/Wt/WComboBox is in libwt-dev 3.3.4+dfsg-6ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WCOMBOBOX_H_
#define WCOMBOBOX_H_
#include <Wt/WAbstractItemModel>
#include <Wt/WFormWidget>
#include <string>
namespace Wt {
/*! \class WComboBox Wt/WComboBox Wt/WComboBox
* \brief A widget that provides a drop-down combo-box control.
*
* A combo box provides the user with a set of options, from which one
* option may be selected.
*
* %WComboBox is an MVC view class, using a simple string list model
* by default. The model may be populated using
* addItem(const WString&) or
* insertItem(int, const WString&) and the contents can
* be cleared through clear(). These methods manipulate the underlying
* model().
*
* To use the combo box with a custom model instead of the default
* WStringListModel, use setModel().
*
* To react to selection events, connect to the changed(), activated()
* or sactivated() signals.
*
* At all times, the current selection index is available through
* currentIndex() and the current selection text using currentText().
*
* WComboBox does not have support for auto-completion, this behaviour
* can be found in the WSuggestionPopup.
*
* \if cpp
* Usage example:
* \code
* Wt::WComboBox *combo = new Wt::WComboBox(this);
* combo->addItem("Clint Eastwood");
* combo->addItem("Mick Jagger");
* combo->addItem("Johnny Depp");
* combo->addItem("Kate Winslet");
*
* combo->setCurrentIndex(2); // Johnny Depp
* combo->activated().connect(this, &MyWidget::comboChanged);
* \endcode
* \endif
*
* %WComboBox is an \link WWidget::setInline(bool) inline \endlink widget.
*
* <h3>CSS</h3>
*
* The widget corresponds to the HTML <tt><select></tt> tag and
* does not provide styling. It can be styled using inline or external
* CSS as appropriate.
*
* \ingroup modelview
*/
class WT_API WComboBox : public WFormWidget
{
public:
/*! \brief Creates an empty combo-box with optional <i>parent</i>.
*/
WComboBox(WContainerWidget *parent = 0);
/*! \brief Adds an option item.
*
* Equivalent to
* \link insertItem(int, const WString&) insertItem\endlink (count(),
* \p text).
*/
void addItem(const WString& text);
/*! \brief Returns the number of items
*/
int count() const;
/*! \brief Returns the currently selected item.
*
* If no item is currently selected, the method returns -1.
*
* By default, for a combo box, the first item is selected,
* and thus currentIndex() = 0, while for a selection box no item is
* selected.
*/
int currentIndex() const;
/*! \brief Inserts an item at the specified position.
*
* The item is inserted in the underlying model at position
* \p index. This requires that the model() is editable.
*
* \sa addItem(const WString&), removeItem(int)
*/
void insertItem(int index, const WString& text);
/*! \brief Removes the item at the specified position.
*
* The item is removed from the underlying model. This requires that
* the model() is editable.
*
* \sa insertItem(int index, const WString&), clear()
*/
void removeItem(int index);
/*! \brief Changes the current selection.
*
* Specify a value of -1 for \p index to clear the selection.
*
* \note Setting a value of -1 works only if JavaScript is available.
*/
void setCurrentIndex(int index);
/*! \brief Changes the text for a specified option.
*
* The text for the item at position \p index is changed. This requires
* that the model() is editable.
*/
void setItemText(int index, const WString& text);
/*! \brief Returns the text of the currently selected item.
*
* \sa currentIndex(), itemText(int) const
*/
const WString currentText() const;
/*! \brief Returns the text of a particular item.
*
* \sa setItemText(int, const WString&), currentText()
*/
const WString itemText(int index) const;
/*! \brief Sets the model to be used for the items.
*
* The \p model may not be 0, and ownership of the model is not
* transferred.
*
* The default value is a WStringListModel that is owned by the
* combo box. Items in the model can be grouped by setting the
* \ref LevelRole. The contents is interpreted by \ref Wt::asString, and
* subsequent items of the same group are rendered as children of a HTML
* <tt> <optgroup> </tt>element.
*
* \sa setModelColumn(int)
*/
void setModel(WAbstractItemModel *model);
/*! \brief Sets the column in the model to be used for the items.
*
* The column \p index in the model will be used to retrieve data.
*
* The default value is 0.
*
* \sa setModel()
*/
void setModelColumn(int index);
/*! \brief Returns the data model.
*
* \sa setModel()
*/
WAbstractItemModel *model() const { return model_; }
/*! \brief Returns the index of the first item that matches a text.
*/
int findText(const WString& text,
WFlags<MatchFlag> flags = MatchExactly | MatchCaseSensitive);
/*! \brief Returns the current value.
*
* Returns currentText() converted from a WString to a string.
*/
virtual WT_USTRING valueText() const;
/*! \brief Sets the current value.
*
* Sets the current index to the item corresponding to \p value.
*/
virtual void setValueText(const WT_USTRING& value);
virtual void refresh();
/*! \brief Clears all items.
*
* Removes all items from the underlying model. This requires that the
* model() is editable.
*/
void clear();
/*! \brief %Signal emitted when the selection changed.
*
* The newly selected item is passed as an argument.
*
* \sa sactivated(), currentIndex()
*/
Signal<int>& activated() { return activated_; }
/*! \brief %Signal emitted when the selection changed.
*
* The newly selected text is passed as an argument.
*
* \sa activated(), currentText()
*/
Signal<WString>& sactivated() { return sactivated_; }
private:
WAbstractItemModel *model_;
int modelColumn_;
int currentIndex_;
void *currentIndexRaw_;
bool itemsChanged_;
bool selectionChanged_;
bool currentlyConnected_;
std::vector<Wt::Signals::connection> modelConnections_;
Signal<int> activated_;
Signal<WString> sactivated_;
void layoutChanged();
void itemsChanged();
void propagateChange();
void rowsInserted(const WModelIndex &index, int from, int to);
void rowsRemoved(const WModelIndex &index, int from, int to);
void saveSelection();
void restoreSelection();
virtual bool supportsNoSelection() const;
protected:
virtual void updateDom(DomElement& element, bool all);
virtual DomElementType domElementType() const;
virtual void propagateRenderOk(bool deep);
virtual void setFormData(const FormData& formData);
virtual bool isSelected(int index) const;
friend class WSelectionBox;
};
}
#endif // WCOMBOBOX_H_
|