8
8
// SS SS tt ee ll ll aa aa
9
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
11
// Copyright (c) 1995-2010 by Bradford W. Mott, Stephen Anthony
12
// and the Stella Team
13
// See the file "license" for information on usage and redistribution of
14
// See the file "License.txt" for information on usage and redistribution of
14
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: PopUpWidget.hxx,v 1.20 2008/02/06 13:45:24 stephena Exp $
17
// $Id: PopUpWidget.hxx 2001 2010-04-10 21:37:23Z stephena $
18
19
// Based on code from ScummVM - Scumm Interpreter
19
20
// Copyright (C) 2002-2004 The ScummVM project
43
44
class PopUpWidget : public Widget, public CommandSender
45
friend class PopUpDialog;
52
typedef Common::Array<Entry> EntryList;
61
47
PopUpWidget(GuiObject* boss, const GUI::Font& font,
62
int x, int y, int w, int h,
48
int x, int y, int w, int h, const StringMap& items,
63
49
const string& label, int labelWidth = 0, int cmd = 0);
52
/** Add the given items to the widget. */
54
/** Various selection methods passed directly to the underlying menu
55
See ContextMenu.hxx for more information. */
56
void addItems(const StringMap& items) { myMenu->addItems(items); }
57
void setSelected(int item) { myMenu->setSelected(item); }
58
void setSelected(const string& tag,
59
const string& def) { myMenu->setSelected(tag, def); }
60
void setSelectedMax() { myMenu->setSelectedMax(); }
61
void clearSelection() { myMenu->clearSelection(); }
63
int getSelected() const { return myMenu->getSelected(); }
64
const string& getSelectedName() const { return myMenu->getSelectedName(); }
65
const string& getSelectedTag() const { return myMenu->getSelectedTag(); }
66
67
bool wantsFocus() { return true; }
68
void appendEntry(const string& entry, int tag = (int)-1);
71
/** Select the entry at the given index. */
72
void setSelected(int item);
74
/** Select the first entry matching the given name. */
75
void setSelectedName(const string& name);
77
/** Select the first entry matching the given tag. */
78
void setSelectedTag(int tag);
80
/** Select the highest/last entry in the internal list. */
81
void setSelectedMax();
83
int getSelected() const
84
{ return _selectedItem; }
85
int getSelectedTag() const
86
{ return (_selectedItem >= 0) ? _entries[_selectedItem].tag : (int)-1; }
87
const string& getSelectedString() const
88
{ return (_selectedItem >= 0) ? _entries[_selectedItem].name : EmptyString; }
91
70
void handleMouseDown(int x, int y, int button, int clickCount);
92
71
bool handleEvent(Event::Type e);
72
void handleCommand(CommandSender* sender, int cmd, int data, int id);
93
73
void drawWidget(bool hilite);
99
PopUpDialog* myPopUpDialog;
107
class PopUpDialog : public Dialog
109
friend class PopUpWidget;
112
PopUpDialog(PopUpWidget* boss, int clickX, int clickY);
115
void center() { recalc(); }
118
void handleMouseDown(int x, int y, int button, int clickCount);
119
void handleMouseWheel(int x, int y, int direction);
120
void handleMouseMoved(int x, int y, int button);
121
void handleKeyDown(int ascii, int keycode, int modifiers); // Scroll through entries with arrow keys etc
122
void handleJoyDown(int stick, int button);
123
void handleJoyAxis(int stick, int axis, int value);
124
bool handleJoyHat(int stick, int hat, int value);
125
void handleEvent(Event::Type e);
127
void drawMenuEntry(int entry, bool hilite);
130
int findItem(int x, int y) const;
131
void setSelection(int item);
138
void sendSelection();
139
void cancelSelection();
142
PopUpWidget* _popUpBoss;
143
int _clickX, _clickY;
149
int _entriesPerColumn;