1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#ifndef LIST_WIDGET_HXX
19#define LIST_WIDGET_HXX
20
21class GuiObject;
22class ScrollBarWidget;
23
24#include "Rect.hxx"
25#include "Command.hxx"
26#include "EditableWidget.hxx"
27
28/** ListWidget */
29class ListWidget : public EditableWidget
30{
31 public:
32 enum {
33 kDoubleClickedCmd = 'LIdb', // double click on item - 'data' will be item index
34 kLongButtonPressCmd = 'LIlb', // long button press
35 kActivatedCmd = 'LIac', // item activated by return/enter - 'data' will be item index
36 kDataChangedCmd = 'LIch', // item data changed - 'data' will be item index
37 kRClickedCmd = 'LIrc', // right click on item - 'data' will be item index
38 kSelectionChangedCmd = 'Lsch', // selection changed - 'data' will be item index
39 kScrolledCmd = 'Lscl', // list scrolled - 'data' will be current position
40 kPrevDirCmd = 'Lpdr' // request to go to parent list, if applicable
41 };
42
43 public:
44 ListWidget(GuiObject* boss, const GUI::Font& font,
45 int x, int y, int w, int h);
46 virtual ~ListWidget() = default;
47
48 int rows() const { return _rows; }
49 int currentPos() const { return _currentPos; }
50
51 int getSelected() const { return _selectedItem; }
52 void setSelected(int item);
53 void setSelected(const string& item);
54
55 int getHighlighted() const { return _highlightedItem; }
56 void setHighlighted(int item);
57
58 const StringList& getList() const { return _list; }
59 const string& getSelectedString() const;
60
61 void scrollTo(int item);
62 void scrollToEnd() { scrollToCurrent(int(_list.size())); }
63
64 // Account for the extra width of embedded scrollbar
65 int getWidth() const override;
66
67 protected:
68 void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
69 void handleMouseUp(int x, int y, MouseButton b, int clickCount) override;
70 void handleMouseWheel(int x, int y, int direction) override;
71 bool handleText(char text) override;
72 bool handleKeyDown(StellaKey key, StellaMod mod) override;
73 void handleJoyDown(int stick, int button, bool longPress) override;
74 void handleJoyUp(int stick, int button) override;
75 bool handleEvent(Event::Type e) override;
76 void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
77
78 virtual void drawWidget(bool hilite) override = 0;
79 virtual Common::Rect getEditRect() const override = 0;
80
81 int findItem(int x, int y) const;
82 void recalc();
83 void scrollBarRecalc();
84
85 void startEditMode() override;
86 void endEditMode() override;
87 void abortEditMode() override;
88
89 void lostFocusWidget() override;
90 void scrollToSelected() { scrollToCurrent(_selectedItem); }
91 void scrollToHighlighted() { scrollToCurrent(_highlightedItem); }
92
93 private:
94 void scrollToCurrent(int item);
95
96 protected:
97 int _rows;
98 int _cols;
99 int _currentPos;
100 int _selectedItem;
101 int _highlightedItem;
102 bool _editMode;
103
104 ScrollBarWidget* _scrollBar;
105
106 StringList _list;
107
108 private:
109 // Following constructors and assignment operators not supported
110 ListWidget() = delete;
111 ListWidget(const ListWidget&) = delete;
112 ListWidget(ListWidget&&) = delete;
113 ListWidget& operator=(const ListWidget&) = delete;
114 ListWidget& operator=(ListWidget&&) = delete;
115};
116
117#endif
118