2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-12-12 12:07:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-12-12 12:07:46 +00:00
|
|
|
*
|
2006-02-11 10:08:56 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2002-12-12 12:07:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef POPUPWIDGET_H
|
|
|
|
#define POPUPWIDGET_H
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
#include "gui/widget.h"
|
2002-12-12 12:07:46 +00:00
|
|
|
#include "common/str.h"
|
2004-04-09 15:10:23 +00:00
|
|
|
#include "common/array.h"
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
enum {
|
|
|
|
kPopUpItemSelectedCmd = 'POPs'
|
|
|
|
};
|
|
|
|
|
2003-11-03 01:00:26 +00:00
|
|
|
/**
|
|
|
|
* Popup or dropdown widget which, when clicked, "pop up" a list of items and
|
2002-12-12 12:07:46 +00:00
|
|
|
* lets the user pick on of them.
|
|
|
|
*
|
2005-07-30 21:11:48 +00:00
|
|
|
* Implementation wise, when the user selects an item, then a kPopUpItemSelectedCmd
|
2002-12-12 12:07:46 +00:00
|
|
|
* is broadcast, with data being equal to the tag value of the selected entry.
|
|
|
|
*/
|
|
|
|
class PopUpWidget : public Widget, public CommandSender {
|
|
|
|
friend class PopUpDialog;
|
2003-10-02 17:43:02 +00:00
|
|
|
typedef Common::String String;
|
2003-11-08 23:22:16 +00:00
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
struct Entry {
|
|
|
|
String name;
|
|
|
|
uint32 tag;
|
|
|
|
};
|
2004-04-09 15:10:23 +00:00
|
|
|
typedef Common::Array<Entry> EntryList;
|
2002-12-12 12:07:46 +00:00
|
|
|
protected:
|
|
|
|
EntryList _entries;
|
|
|
|
int _selectedItem;
|
|
|
|
|
2006-04-16 10:23:36 +00:00
|
|
|
int _leftPadding;
|
|
|
|
int _rightPadding;
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
public:
|
2010-06-15 10:52:35 +00:00
|
|
|
PopUpWidget(GuiObject *boss, const String &name, const char *tooltip = 0);
|
2006-04-19 01:05:28 +00:00
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
void handleMouseDown(int x, int y, int button, int clickCount);
|
2008-12-23 23:47:16 +00:00
|
|
|
void handleMouseWheel(int x, int y, int direction);
|
2002-12-12 12:07:46 +00:00
|
|
|
|
|
|
|
void appendEntry(const String &entry, uint32 tag = (uint32)-1);
|
|
|
|
void clearEntries();
|
2010-06-15 10:57:28 +00:00
|
|
|
int numEntries() { return _entries.size(); }
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2004-03-13 12:33:31 +00:00
|
|
|
/** Select the entry at the given index. */
|
2002-12-12 12:07:46 +00:00
|
|
|
void setSelected(int item);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2004-03-13 12:33:31 +00:00
|
|
|
/** Select the first entry matching the given tag. */
|
|
|
|
void setSelectedTag(uint32 tag);
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
int getSelected() const { return _selectedItem; }
|
2003-11-05 00:58:42 +00:00
|
|
|
uint32 getSelectedTag() const { return (_selectedItem >= 0) ? _entries[_selectedItem].tag : (uint32)-1; }
|
2009-12-30 23:01:36 +00:00
|
|
|
// const String& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : String::emptyString; }
|
2002-12-12 12:07:46 +00:00
|
|
|
|
2006-04-18 18:50:07 +00:00
|
|
|
void handleMouseEntered(int button) { setFlags(WIDGET_HILITED); draw(); }
|
|
|
|
void handleMouseLeft(int button) { clearFlags(WIDGET_HILITED); draw(); }
|
2006-04-19 01:05:28 +00:00
|
|
|
|
2006-08-04 13:55:53 +00:00
|
|
|
virtual void reflowLayout();
|
2002-12-12 12:07:46 +00:00
|
|
|
protected:
|
2007-11-04 03:38:30 +00:00
|
|
|
void drawWidget();
|
2002-12-12 12:07:46 +00:00
|
|
|
};
|
|
|
|
|
2003-11-10 23:40:48 +00:00
|
|
|
} // End of namespace GUI
|
|
|
|
|
2002-12-12 12:07:46 +00:00
|
|
|
#endif
|