~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/gui/ContextMenu.hxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2013-06-28 09:53:13 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20130628095313-j8jkkgxpvx1t18ym
Tags: 3.9-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
// See the file "License.txt" for information on usage and redistribution of
15
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
16
//
17
 
// $Id: ContextMenu.hxx 2579 2013-01-04 19:49:01Z stephena $
 
17
// $Id: ContextMenu.hxx 2732 2013-05-09 14:22:34Z stephena $
18
18
//
19
19
//   Based on code from ScummVM - Scumm Interpreter
20
20
//   Copyright (C) 2002-2004 The ScummVM project
26
26
#include "bspf.hxx"
27
27
#include "Command.hxx"
28
28
#include "Dialog.hxx"
29
 
 
30
 
enum {
31
 
  kCMenuItemSelectedCmd = 'CMsl'
32
 
};
 
29
#include "Variant.hxx"
33
30
 
34
31
/**
35
32
 * Popup context menu which, when clicked, "pop up" a list of items and
37
34
 *
38
35
 * Implementation wise, when the user selects an item, then the given 'cmd'
39
36
 * is broadcast, with data being equal to the tag value of the selected entry.
 
37
 *
 
38
 * There are also several utility methods (named as sendSelectionXXX) that
 
39
 * allow to cycle through the current items without actually opening the dialog.
40
40
 */
41
41
class ContextMenu : public Dialog, public CommandSender
42
42
{
43
43
  public:
 
44
    enum {
 
45
      kItemSelectedCmd = 'CMsl'
 
46
    };
 
47
 
 
48
  public:
44
49
    ContextMenu(GuiObject* boss, const GUI::Font& font,
45
 
                const StringMap& items, int cmd = 0);
 
50
                const VariantList& items, int cmd = 0);
46
51
    virtual ~ContextMenu();
47
52
 
48
53
    /** Add the given items to the widget. */
49
 
    void addItems(const StringMap& items);
 
54
    void addItems(const VariantList& items);
50
55
 
51
56
    /** Show context menu onscreen at the specified coordinates */
52
57
    void show(uInt32 x, uInt32 y, int item = -1);
55
60
    void setSelected(int item);
56
61
        
57
62
    /** Select the first entry matching the given tag. */
58
 
    void setSelected(const string& tag, const string& defaultTag);
 
63
    void setSelected(const Variant& tag, const Variant& defaultTag);
59
64
 
60
65
    /** Select the highest/last entry in the internal list. */
61
66
    void setSelectedMax();
66
71
    /** Accessor methods for the currently selected item. */
67
72
    int getSelected() const;
68
73
    const string& getSelectedName() const;
69
 
    const string& getSelectedTag() const;
 
74
    const Variant& getSelectedTag() const;
70
75
 
71
76
    /** This dialog uses its own positioning, so we override Dialog::center() */
72
77
    void center();
73
78
 
 
79
    /** The following methods are used when we want to select *and*
 
80
        send a command for the new selection.  They are only to be used
 
81
        when the dialog *isn't* open, and are basically a shortcut so
 
82
        that a PopUpWidget has some basic functionality without forcing
 
83
        to open its associated ContextMenu. */
 
84
    bool sendSelectionUp();
 
85
    bool sendSelectionDown();
 
86
    bool sendSelectionFirst();
 
87
    bool sendSelectionLast();
 
88
 
74
89
  protected:
75
90
    void handleMouseDown(int x, int y, int button, int clickCount);
76
91
    void handleMouseMoved(int x, int y, int button);
92
107
        
93
108
    void moveUp();
94
109
    void moveDown();
 
110
    void movePgUp();
 
111
    void movePgDown();
 
112
    void moveToFirst();
 
113
    void moveToLast();
 
114
    void moveToSelected();
95
115
    void scrollUp(int distance = 1);
96
116
    void scrollDown(int distance = 1);
97
117
    void sendSelection();
98
118
 
99
119
  private:
100
 
    StringMap _entries;
 
120
    VariantList _entries;
101
121
 
102
122
    int _rowHeight;
103
123
    int _firstEntry, _numEntries;