1
//============================================================================
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
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
13
// See the file "license" for information on usage and redistribution of
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: CheckListWidget.cxx,v 1.10 2006/02/22 17:38:04 stephena Exp $
18
// Based on code from ScummVM - Scumm Interpreter
19
// Copyright (C) 2002-2004 The ScummVM project
20
//============================================================================
22
#include "CheckListWidget.hxx"
25
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26
CheckListWidget::CheckListWidget(GuiObject* boss, const GUI::Font& font,
27
int x, int y, int w, int h)
28
: ListWidget(boss, font, x, y, w, h)
32
// rowheight is determined by largest item on a line,
33
// possibly meaning that number of rows will change
34
_fontHeight = MAX(_fontHeight, CheckboxWidget::boxSize());
35
_rows = h / _fontHeight;
37
// Create a CheckboxWidget for each row in the list
39
for(int i = 0; i < _rows; ++i)
41
t = new CheckboxWidget(boss, font, _x + 2, ypos, "", kCheckActionCmd);
47
_checkList.push_back(t);
51
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52
CheckListWidget::~CheckListWidget()
56
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57
void CheckListWidget::setStyle(CheckStyle style)
59
for(unsigned int i = 0; i < _checkList.size(); ++i)
63
_checkList[i]->drawBox(true);
64
_checkList[i]->setFill(false);
65
_checkList[i]->setColor(kTextColor);
67
else if(style == kSolidFill)
69
_checkList[i]->drawBox(false);
70
_checkList[i]->setFill(true);
71
_checkList[i]->setColor(kTextColorEm);
76
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
77
void CheckListWidget::setList(const StringList& list, const BoolArray& state)
82
assert(_list.size() == _stateList.size());
84
// Enable all checkboxes
85
for(int i = 0; i < _rows; ++i)
86
_checkList[i]->setFlags(WIDGET_ENABLED);
88
// Then turn off any extras
89
if((int)_stateList.size() < _rows)
90
for(int i = _stateList.size(); i < _rows; ++i)
91
_checkList[i]->clearFlags(WIDGET_ENABLED);
96
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97
void CheckListWidget::setLine(int line, const string& str, const bool& state)
99
if(line >= (int)_list.size())
103
_stateList[line] = state;
106
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107
void CheckListWidget::drawWidget(bool hilite)
109
//cerr << "CheckListWidget::drawWidget\n";
110
FrameBuffer& fb = _boss->instance()->frameBuffer();
111
int i, pos, len = _list.size();
115
// Draw a thin frame around the list and to separate columns
116
fb.hLine(_x, _y, _x + _w - 1, kColor);
117
fb.hLine(_x, _y + _h - 1, _x + _w - 1, kShadowColor);
118
fb.vLine(_x, _y, _y + _h - 1, kColor);
120
fb.vLine(_x + CheckboxWidget::boxSize() + 5, _y, _y + _h - 1, kColor);
122
// Draw the list items
123
for (i = 0, pos = _currentPos; i < _rows && pos < len; i++, pos++)
125
// Draw checkboxes for correct lines (takes scrolling into account)
126
_checkList[i]->setState(_stateList[pos]);
127
_checkList[i]->setDirty();
128
_checkList[i]->draw();
130
const int y = _y + 2 + _fontHeight * i + 2;
132
GUI::Rect r(getEditRect());
134
// Draw the selected item inverted, on a highlighted background.
135
if (_selectedItem == pos)
137
if (_hasFocus && !_editMode)
138
fb.fillRect(_x + r.left - 3, _y + 1 + _fontHeight * i,
139
_w - r.left, _fontHeight,
142
fb.frameRect(_x + r.left - 3, _y + 1 + _fontHeight * i,
143
_w - r.left, _fontHeight,
147
if (_selectedItem == pos && _editMode)
149
buffer = _editString;
151
deltax = -_editScrollOffset;
153
fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor,
154
kTextAlignLeft, deltax, false);
160
fb.drawString(_font, buffer, _x + r.left, y, r.width(), kTextColor);
164
// Only draw the caret while editing, and if it's in the current viewport
165
if(_editMode && (_selectedItem >= _scrollBar->_currentPos) &&
166
(_selectedItem < _scrollBar->_currentPos + _rows))
170
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171
GUI::Rect CheckListWidget::getEditRect() const
173
GUI::Rect r(2, 1, _w, _fontHeight);
174
const int yoffset = (_selectedItem - _currentPos) * _fontHeight,
175
xoffset = CheckboxWidget::boxSize() + 10;
179
r.right -= xoffset - 15;
184
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185
bool CheckListWidget::getState(int line)
187
if(line >= 0 && line < (int)_stateList.size())
188
return _stateList[line];
193
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194
void CheckListWidget::handleCommand(CommandSender* sender, int cmd,
199
case kCheckActionCmd:
201
// Figure out which line has been checked
202
int line = _currentPos + id;
203
_stateList[line] = bool(data);
205
// Let the boss know about it
206
sendCommand(kListItemChecked, line, _id);
211
ListWidget::handleCommand(sender, cmd, data, id);