ScummVM API documentation
list.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef GUI_WIDGETS_LIST_H
23 #define GUI_WIDGETS_LIST_H
24 
25 #include "gui/widgets/editable.h"
26 #include "common/str.h"
27 
28 #include "gui/ThemeEngine.h"
29 
30 namespace GUI {
31 
32 class ScrollBarWidget;
33 
34 enum NumberingMode {
35  kListNumberingOff = -1,
36  kListNumberingZero = 0,
37  kListNumberingOne = 1
38 };
39 
41 enum {
42  kListItemSingleClickedCmd = 'LIsc',
43  kListItemDoubleClickedCmd = 'LIdc',
44  kListItemActivatedCmd = 'LIac',
45  kListItemRemovalRequestCmd = 'LIrm',
46  kListItemEditModeStartedCmd = 'LIes',
47  kListSelectionChangedCmd = 'Lsch'
48 };
49 
50 /* ListWidget */
51 class ListWidget : public EditableWidget {
52 public:
53  typedef bool (*FilterMatcher)(void *arg, int idx, const Common::U32String &item, const Common::U32String &token);
54 
55  struct ListData {
56  Common::U32String orig;
57  Common::U32String clean;
58 
59  ListData(const Common::U32String &o, const Common::U32String &c) { orig = o; clean = c; }
60  };
61 
63 
64 protected:
66  Common::U32StringArray _cleanedList;
67  ListDataArray _dataList;
68  Common::Array<int> _listIndex;
69  bool _editable;
70  bool _editMode;
71  NumberingMode _numberingMode;
72  int _currentPos;
73  int _entriesPerPage;
74  int _selectedItem;
75  ScrollBarWidget *_scrollBar;
76  int _currentKeyDown;
77 
78  Common::String _quickSelectStr;
79  uint32 _quickSelectTime;
80 
81  int _hlLeftPadding;
82  int _hlRightPadding;
83  int _leftPadding;
84  int _rightPadding;
85  int _topPadding;
86  int _bottomPadding;
87  int _scrollBarWidth;
88 
89  Common::U32String _filter;
90  bool _quickSelect;
91  bool _dictionarySelect;
92 
93  uint32 _cmd;
94 
95  ThemeEngine::FontColor _editColor;
96 
97  int _lastRead;
98 
99  FilterMatcher _filterMatcher;
100  void *_filterMatcherArg;
101 public:
102  ListWidget(Dialog *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
103  ListWidget(Dialog *boss, int x, int y, int w, int h, bool scale, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
104  ListWidget(Dialog *boss, int x, int y, int w, int h, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
105 
106  bool containsWidget(Widget *) const override;
107  Widget *findWidget(int x, int y) override;
108 
109  void setList(const Common::U32StringArray &list);
110  const Common::U32StringArray &getList() const { return _cleanedList; }
111 
112  void append(const Common::String &s);
113 
114  void setSelected(int item);
115  int getSelected() const { return (_filter.empty() || _selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
116 
117  const Common::U32String getSelectedString() const { return stripGUIformatting(_list[_selectedItem]); }
118 
119  void setNumberingMode(NumberingMode numberingMode) { _numberingMode = numberingMode; }
120 
121  void scrollTo(int item);
122  void scrollToEnd();
123  int getCurrentScrollPos() const { return _currentPos; }
124 
125  void enableQuickSelect(bool enable) { _quickSelect = enable; }
126  Common::String getQuickSelectString() const { return _quickSelectStr; }
127 
128  void enableDictionarySelect(bool enable) { _dictionarySelect = enable; }
129 
130  bool isEditable() const { return _editable; }
131  void setEditable(bool editable) { _editable = editable; }
132  void setEditColor(ThemeEngine::FontColor color) { _editColor = color; }
133  void setFilterMatcher(FilterMatcher matcher, void *arg) { _filterMatcher = matcher; _filterMatcherArg = arg; }
134 
135  // Made startEditMode/endEditMode for SaveLoadChooser
136  void startEditMode() override;
137  void endEditMode() override;
138 
139  void setFilter(const Common::U32String &filter, bool redraw = true);
140 
141  void handleTickle() override;
142  void handleMouseDown(int x, int y, int button, int clickCount) override;
143  void handleMouseUp(int x, int y, int button, int clickCount) override;
144  void handleMouseWheel(int x, int y, int direction) override;
145  void handleMouseMoved(int x, int y, int button) override;
146  void handleMouseLeft(int button) override;
147  bool handleKeyDown(Common::KeyState state) override;
148  bool handleKeyUp(Common::KeyState state) override;
149  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
150 
151  void reflowLayout() override;
152 
153  bool wantsFocus() override { return true; }
154 
155  static Common::U32String getThemeColor(byte r, byte g, byte b);
156  static Common::U32String getThemeColor(ThemeEngine::FontColor color);
157  static ThemeEngine::FontColor getThemeColor(const Common::U32String &color);
158  static Common::U32String stripGUIformatting(const Common::U32String &str);
159  static Common::U32String escapeString(const Common::U32String &str);
160 
161 protected:
162  void drawWidget() override;
163 
165  int findItem(int x, int y) const;
166  void scrollBarRecalc();
167 
168  void abortEditMode() override;
169 
170  Common::Rect getEditRect() const override;
171  int getCaretOffset() const override;
172 
173  void copyListData(const Common::U32StringArray &list);
174 
175  void receivedFocusWidget() override;
176  void lostFocusWidget() override;
177  void checkBounds();
178  void scrollToCurrent();
179 
180  virtual ThemeEngine::WidgetStateInfo getItemState(int item) const { return _state; }
181 
182  void drawFormattedText(const Common::Rect &r, const Common::U32String &str, ThemeEngine::WidgetStateInfo state = ThemeEngine::kStateEnabled,
184  ThemeEngine::TextInversionState inverted = ThemeEngine::kTextInversionNone, int deltax = 0, bool useEllipsis = true,
186 };
187 
188 } // End of namespace GUI
189 
190 #endif
Center the text.
Definition: font.h:52
Definition: str.h:59
Indicates that the text should not be drawn inverted.
Definition: ThemeEngine.h:260
FontColor
Font color selector.
Definition: ThemeEngine.h:288
TextAlign
Definition: font.h:48
Common::Rect getEditRect() const override
Use color from formatting.
Definition: ThemeEngine.h:289
Definition: list.h:55
Definition: rect.h:144
Definition: scrollbar.h:34
Definition: system.h:46
TextInversionState
Text inversion state of the text to be draw.
Definition: ThemeEngine.h:259
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
Definition: ustr.h:57
Indicates that the widget is enabled.
Definition: ThemeEngine.h:251
Definition: list.h:51
Definition: dialog.h:49
Definition: editable.h:41
State
State of the widget to be drawn.
Definition: ThemeEngine.h:249
Definition: widget.h:101
Definition: keyboard.h:294
Definition: object.h:40
int findItem(int x, int y) const
Finds the item at position (x,y). Returns -1 if there is no item there.