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 POPUP_WIDGET_HXX
19#define POPUP_WIDGET_HXX
20
21class GUIObject;
22class ContextMenu;
23
24#include "bspf.hxx"
25#include "Variant.hxx"
26#include "Command.hxx"
27#include "Widget.hxx"
28
29/**
30 * Popup or dropdown widget which, when clicked, "pop up" a list of items and
31 * lets the user pick on of them.
32 *
33 * Implementation wise, when the user selects an item, then a kPopUpItemSelectedCmd
34 * is broadcast, with data being equal to the tag value of the selected entry.
35 */
36class PopUpWidget : public Widget, public CommandSender
37{
38 public:
39 PopUpWidget(GuiObject* boss, const GUI::Font& font,
40 int x, int y, int w, int h, const VariantList& items,
41 const string& label, int labelWidth = 0, int cmd = 0);
42 virtual ~PopUpWidget() = default;
43
44 int getTop() const override { return _y + 1; }
45 int getBottom() const override { return _y + 1 + getHeight(); }
46
47 /** Add the given items to the widget. */
48 void addItems(const VariantList& items);
49
50 /** Various selection methods passed directly to the underlying menu
51 See ContextMenu.hxx for more information. */
52 void setSelected(const Variant& tag,
53 const Variant& def = EmptyVariant);
54 void setSelectedIndex(int idx, bool changed = false);
55 void setSelectedMax(bool changed = false);
56 void clearSelection();
57
58 int getSelected() const;
59 const string& getSelectedName() const;
60 const Variant& getSelectedTag() const;
61
62 bool wantsFocus() const override { return true; }
63
64 protected:
65 void handleMouseDown(int x, int y, MouseButton b, int clickCount) override;
66 void handleMouseWheel(int x, int y, int direction) override;
67 void handleMouseEntered() override;
68 void handleMouseLeft() override;
69 bool handleEvent(Event::Type e) override;
70 void handleCommand(CommandSender* sender, int cmd, int data, int id) override;
71 void drawWidget(bool hilite) override;
72
73 private:
74 unique_ptr<ContextMenu> myMenu;
75 int myArrowsY;
76 int myTextY;
77
78 string _label;
79 int _labelWidth;
80 bool _changed;
81
82 private:
83 // Following constructors and assignment operators not supported
84 PopUpWidget() = delete;
85 PopUpWidget(const PopUpWidget&) = delete;
86 PopUpWidget(PopUpWidget&&) = delete;
87 PopUpWidget& operator=(const PopUpWidget&) = delete;
88 PopUpWidget& operator=(PopUpWidget&&) = delete;
89};
90
91#endif
92