~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/gui/PopUpWidget.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-07-12 23:49:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100712234936-juawrr3etzhr2qpv
Tags: 3.1.2-1
* New maintainer (closes: #532039).
* New upstream version (closes: #461121):
  - includes launcher (closes: #396058).
* Fix the reference to the X Window System in the description (closes:
  #411815).
* Move to main, DFSG-free ROMs are available (see README.Debian).
* Enhance the package description.
* Drop the libslang2-dev dependency (closes: #560274).
* Remove the Encoding entry from stella.desktop.
* Avoid ignoring errors when cleaning.
* Add ${misc:Depends} to the package dependencies.
* Provide a doc-base file to install the documentation using doc-base.
* Switch to debhelper 7 with a simplified rules file.
* Use autotools-dev to provide updated configuration files.
* Update to Standards-Version 3.9.0:
  - Move to menu section Applications/Emulators.
  - Move the homepage declaration.
* Re-write the manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
//  SS  SS   tt   ee      ll   ll  aa  aa
9
9
//   SSSS     ttt  eeeee llll llll  aaaaa
10
10
//
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
12
13
//
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.
15
16
//
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 $
17
18
//
18
19
//   Based on code from ScummVM - Scumm Interpreter
19
20
//   Copyright (C) 2002-2004 The ScummVM project
23
24
#define POPUP_WIDGET_HXX
24
25
 
25
26
class GUIObject;
26
 
class PopUpDialog;
27
27
 
28
28
#include "bspf.hxx"
29
29
 
30
30
#include "Array.hxx"
31
31
#include "Command.hxx"
32
 
#include "Dialog.hxx"
 
32
#include "ContextMenu.hxx"
 
33
#include "StringList.hxx"
33
34
#include "Widget.hxx"
34
35
 
35
36
 
42
43
 */
43
44
class PopUpWidget : public Widget, public CommandSender
44
45
{
45
 
  friend class PopUpDialog;
46
 
 
47
 
  struct Entry {
48
 
    string name;
49
 
    int tag;
50
 
  };
51
 
 
52
 
  typedef Common::Array<Entry> EntryList;
53
 
 
54
 
  protected:
55
 
    EntryList _entries;
56
 
    int       _selectedItem;
57
 
    string    _label;
58
 
    int       _labelWidth;
59
 
 
60
46
  public:
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);
64
50
    ~PopUpWidget();
65
51
 
 
52
    /** Add the given items to the widget. */
 
53
 
 
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();      }
 
62
 
 
63
    int getSelected() const               { return myMenu->getSelected();     }
 
64
    const string& getSelectedName() const { return myMenu->getSelectedName(); }
 
65
    const string& getSelectedTag() const  { return myMenu->getSelectedTag();  }
 
66
 
66
67
    bool wantsFocus()  { return true; }
67
68
 
68
 
    void appendEntry(const string& entry, int tag = (int)-1);
69
 
    void clearEntries();
70
 
 
71
 
    /** Select the entry at the given index. */
72
 
    void setSelected(int item);
73
 
        
74
 
    /** Select the first entry matching the given name. */
75
 
    void setSelectedName(const string& name);
76
 
 
77
 
    /** Select the first entry matching the given tag. */
78
 
    void setSelectedTag(int tag);
79
 
 
80
 
    /** Select the highest/last entry in the internal list. */
81
 
    void setSelectedMax();
82
 
 
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; }
89
 
 
90
69
  protected:
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);
94
74
 
95
 
  protected:
96
 
    int _cmd;
97
 
 
98
75
  private:
99
 
    PopUpDialog* myPopUpDialog;
 
76
    ContextMenu* myMenu;
100
77
    int myArrowsY;
101
78
    int myTextY;
102
 
};
103
 
 
104
 
//
105
 
// PopUpDialog
106
 
//
107
 
class PopUpDialog : public Dialog
108
 
{
109
 
  friend class PopUpWidget;
110
 
 
111
 
  public:
112
 
    PopUpDialog(PopUpWidget* boss, int clickX, int clickY);
113
 
        
114
 
    void drawDialog();
115
 
    void center() { recalc(); }
116
 
 
117
 
  protected:
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);
126
 
 
127
 
    void drawMenuEntry(int entry, bool hilite);
128
 
 
129
 
    void recalc();
130
 
    int findItem(int x, int y) const;
131
 
    void setSelection(int item);
132
 
    bool isMouseDown();
133
 
        
134
 
    void moveUp();
135
 
    void moveDown();
136
 
 
137
 
  private:
138
 
    void sendSelection();
139
 
    void cancelSelection();
140
 
 
141
 
  protected:
142
 
    PopUpWidget* _popUpBoss;
143
 
    int          _clickX, _clickY;
144
 
    uInt8*       _buffer;
145
 
    int          _selection;
146
 
    int          _oldSelection;
147
 
    int          _openTime;
148
 
    bool         _twoColumns;
149
 
    int          _entriesPerColumn;
 
79
 
 
80
    string _label;
 
81
    int    _labelWidth;
150
82
};
151
83
 
152
84
#endif