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 _itemSpacing;
88  int _scrollBarWidth;
89 
90  Common::U32String _filter;
91  bool _quickSelect;
92  bool _dictionarySelect;
93 
94  uint32 _cmd;
95 
96  ThemeEngine::FontColor _editColor;
97 
98  int _lastRead;
99 
100  FilterMatcher _filterMatcher;
101  void *_filterMatcherArg;
102 public:
103  ListWidget(Dialog *boss, const Common::String &name, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
104  ListWidget(Dialog *boss, int x, int y, int w, int h, bool scale, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
105  ListWidget(Dialog *boss, int x, int y, int w, int h, const Common::U32String &tooltip = Common::U32String(), uint32 cmd = 0);
106 
107  bool containsWidget(Widget *) const override;
108  Widget *findWidget(int x, int y) override;
109 
110  void setList(const Common::U32StringArray &list);
111  const Common::U32StringArray &getList() const { return _cleanedList; }
112 
113  void append(const Common::String &s);
114 
115  void setSelected(int item);
116  int getSelected() const { return (_filter.empty() || _selectedItem == -1) ? _selectedItem : _listIndex[_selectedItem]; }
117 
118  const Common::U32String getSelectedString() const { return stripGUIformatting(_list[_selectedItem]); }
119 
120  void setNumberingMode(NumberingMode numberingMode) { _numberingMode = numberingMode; }
121 
122  void scrollTo(int item);
123  void scrollToEnd();
124  int getCurrentScrollPos() const { return _currentPos; }
125  bool isItemVisible(int item) const { return _currentPos <= item && item < _currentPos + _entriesPerPage; }
126 
127  void enableQuickSelect(bool enable) { _quickSelect = enable; }
128  Common::String getQuickSelectString() const { return _quickSelectStr; }
129 
130  void enableDictionarySelect(bool enable) { _dictionarySelect = enable; }
131 
132  bool isEditable() const { return _editable; }
133  void setEditable(bool editable) { _editable = editable; }
134  void setEditColor(ThemeEngine::FontColor color) { _editColor = color; }
135  void setFilterMatcher(FilterMatcher matcher, void *arg) { _filterMatcher = matcher; _filterMatcherArg = arg; }
136 
137  // Made startEditMode/endEditMode for SaveLoadChooser
138  void startEditMode() override;
139  void endEditMode() override;
140 
141  void setFilter(const Common::U32String &filter, bool redraw = true);
142 
143  void handleTickle() override;
144  void handleMouseDown(int x, int y, int button, int clickCount) override;
145  void handleMouseUp(int x, int y, int button, int clickCount) override;
146  void handleMouseWheel(int x, int y, int direction) override;
147  void handleMouseMoved(int x, int y, int button) override;
148  void handleMouseLeft(int button) override;
149  bool handleKeyDown(Common::KeyState state) override;
150  bool handleKeyUp(Common::KeyState state) override;
151  void handleCommand(CommandSender *sender, uint32 cmd, uint32 data) override;
152 
153  void reflowLayout() override;
154 
155  bool wantsFocus() override { return true; }
156 
157  static Common::U32String getThemeColor(byte r, byte g, byte b);
158  static Common::U32String getThemeColor(ThemeEngine::FontColor color);
159  static ThemeEngine::FontColor getThemeColor(const Common::U32String &color);
160  static Common::U32String stripGUIformatting(const Common::U32String &str);
161  static Common::U32String escapeString(const Common::U32String &str);
162 
163 protected:
164  void drawWidget() override;
165 
167  int findItem(int x, int y) const;
168  void scrollBarRecalc();
169 
170  void abortEditMode() override;
171 
172  Common::Rect getEditRect() const override;
173  int getCaretOffset() const override;
174 
175  void copyListData(const Common::U32StringArray &list);
176 
177  void receivedFocusWidget() override;
178  void lostFocusWidget() override;
179  void checkBounds();
180  void scrollToCurrent();
181 
182  virtual ThemeEngine::WidgetStateInfo getItemState(int item) const { return _state; }
183 
184  void drawFormattedText(const Common::Rect &r, const Common::U32String &str, ThemeEngine::WidgetStateInfo state = ThemeEngine::kStateEnabled,
186  ThemeEngine::TextInversionState inverted = ThemeEngine::kTextInversionNone, int deltax = 0, bool useEllipsis = true,
188 };
189 
190 } // End of namespace GUI
191 
192 #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:524
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.