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 DATA_GRID_WIDGET_HXX
19#define DATA_GRID_WIDGET_HXX
20
21class DataGridOpsWidget;
22class ScrollBarWidget;
23class CommandSender;
24
25#include "Widget.hxx"
26#include "EditableWidget.hxx"
27#include "Base.hxx"
28#include "Rect.hxx"
29
30/* DataGridWidget */
31class DataGridWidget : public EditableWidget
32{
33 public:
34 // Commands emitted by this commandsender
35 enum {
36 kItemDoubleClickedCmd = 'DGdb',
37 kItemActivatedCmd = 'DGac',
38 kItemDataChangedCmd = 'DGch',
39 kSelectionChangedCmd = 'DGsc'
40 };
41
42 public:
43 DataGridWidget(GuiObject* boss, const GUI::Font& font,
44 int x, int y, int cols, int rows,
45 int colchars, int bits,
46 Common::Base::Format format = Common::Base::F_DEFAULT,
47 bool useScrollbar = false);
48 virtual ~DataGridWidget() = default;
49
50 void setList(const IntArray& alist, const IntArray& vlist,
51 const BoolArray& changed);
52 /** Convenience method for when the datagrid contains only one value */
53 void setList(int a, int v, bool changed);
54 void setList(int a, int v); // automatically calculate if changed
55
56 void setEditable(bool editable, bool hiliteBG = true) override;
57
58 void setHiliteList(const BoolArray& hilitelist);
59 void setNumRows(int rows);
60
61 /** Set value at current selection point */
62 void setSelectedValue(int value);
63 /** Set value at given position */
64 void setValue(int position, int value);
65 /** Set value at given position, do not emit any signals */
66 void setValueInternal(int position, int value, bool changed = true);
67 /** Set value at given position, manually specifying if the value changed */
68 void setValue(int position, int value, bool changed, bool emitSignal = true);
69
70 int getSelectedAddr() const { return _addrList[_selectedItem]; }
71 int getSelectedValue() const { return _valueList[_selectedItem]; }
72
73 void setRange(int lower, int upper);
74
75 bool wantsFocus() const override { return true; }
76
77 // Account for the extra width of embedded scrollbar
78 int getWidth() const override;
79
80 int colWidth() { return _colWidth; }
81
82 void setOpsWidget(DataGridOpsWidget* w) { _opsWidget = w; }
83
84 void setCrossed(bool enable) { _crossGrid = enable; }
85
86 protected:
87 void drawWidget(bool hilite) override;
88
89 int findItem(int x, int y);
90
91 void startEditMode() override;
92 void endEditMode() override;
93 void abortEditMode() override;
94
95 Common::Rect getEditRect() const override;
96
97 void receivedFocusWidget() override;
98 void lostFocusWidget() override;
99
100 void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
101 void handleMouseUp(int x, int y, MouseButton b, int clickCount) override;
102 void handleMouseWheel(int x, int y, int direction) override;
103 void handleMouseEntered() override;
104 void handleMouseLeft() override;
105 bool handleText(char text) override;
106 bool handleKeyDown(StellaKey key, StellaMod mod) override;
107 bool handleKeyUp(StellaKey key, StellaMod mod) override;
108 void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
109
110 protected:
111 int _rows;
112 int _cols;
113 int _currentRow;
114 int _currentCol;
115 int _rowHeight;
116 int _colWidth;
117 int _bits;
118 int _lowerBound;
119 int _upperBound;
120 bool _crossGrid;
121
122 Common::Base::Format _base;
123
124 IntArray _addrList;
125 IntArray _valueList;
126 StringList _valueStringList;
127 BoolArray _changedList;
128 BoolArray _hiliteList;
129
130 bool _editMode;
131 int _selectedItem;
132 StellaKey _currentKeyDown;
133 string _backupString;
134
135 DataGridOpsWidget* _opsWidget;
136 ScrollBarWidget* _scrollBar;
137
138 private:
139 /** Common operations on the currently selected cell */
140 void negateCell();
141 void invertCell();
142 void decrementCell();
143 void incrementCell();
144 void lshiftCell();
145 void rshiftCell();
146 void zeroCell();
147
148 void enableEditMode(bool state) { _editMode = state; }
149
150 private:
151 // Following constructors and assignment operators not supported
152 DataGridWidget() = delete;
153 DataGridWidget(const DataGridWidget&) = delete;
154 DataGridWidget(DataGridWidget&&) = delete;
155 DataGridWidget& operator=(const DataGridWidget&) = delete;
156 DataGridWidget& operator=(DataGridWidget&&) = delete;
157};
158
159#endif
160