~ubuntu-branches/debian/wheezy/spice/wheezy

« back to all changes in this revision

Viewing changes to client/menu.h

  • Committer: Package Import Robot
  • Author(s): Liang Guo
  • Date: 2011-07-23 12:21:04 UTC
  • Revision ID: package-import@ubuntu.com-20110723122104-gvv70gd6ui6213qd
Tags: upstream-0.8.2
ImportĀ upstreamĀ versionĀ 0.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2009 Red Hat, Inc.
 
3
 
 
4
   This library is free software; you can redistribute it and/or
 
5
   modify it under the terms of the GNU Lesser General Public
 
6
   License as published by the Free Software Foundation; either
 
7
   version 2.1 of the License, or (at your option) any later version.
 
8
 
 
9
   This library is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
   Lesser General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU Lesser General Public
 
15
   License along with this library; if not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef _H_MENU
 
19
#define _H_MENU
 
20
 
 
21
class CommandTarget {
 
22
public:
 
23
    virtual void do_command(int command) = 0;
 
24
    virtual ~CommandTarget() {}
 
25
};
 
26
 
 
27
class Menu {
 
28
public:
 
29
    Menu(CommandTarget& target, const std::string& name, int id = 0);
 
30
 
 
31
    enum ItemType {
 
32
        MENU_ITEM_TYPE_INVALID,
 
33
        MENU_ITEM_TYPE_COMMAND,
 
34
        MENU_ITEM_TYPE_MENU,
 
35
        MENU_ITEM_TYPE_SEPARATOR,
 
36
    };
 
37
 
 
38
    enum ItemState {
 
39
        MENU_ITEM_STATE_CHECKED = 1 << 0,
 
40
        MENU_ITEM_STATE_DIM     = 1 << 1,
 
41
    };
 
42
 
 
43
    Menu* ref() { _refs++; return this;}
 
44
    void unref() { if (!--_refs) delete this;}
 
45
 
 
46
    void set_name(const std::string& name) { _name = name;}
 
47
    const std::string& get_name() { return _name;}
 
48
    CommandTarget& get_target() { return _target;}
 
49
    int get_id() { return _id;}
 
50
 
 
51
    void add_command(const std::string& name, int cmd_id, int state = 0);
 
52
    void add_separator();
 
53
    void add_sub(Menu* sub);
 
54
 
 
55
    void remove_command(int cmd_id);
 
56
    void remove_sub(Menu* menu);
 
57
 
 
58
    ItemType item_type_at(int pos);
 
59
    void command_at(int pos, std::string& name, int& cmd_id, int& state);
 
60
    Menu* sub_at(int pos);
 
61
    Menu* find_sub(int id);
 
62
 
 
63
    void clear();
 
64
 
 
65
private:
 
66
    virtual ~Menu();
 
67
 
 
68
    class MenuCommand {
 
69
    public:
 
70
        MenuCommand(const std::string& name, int cmd_id, int state)
 
71
            : _name (name)
 
72
            , _cmd_id (cmd_id)
 
73
            , _state (state)
 
74
        {
 
75
        }
 
76
 
 
77
        const std::string& get_name() { return _name;}
 
78
        int get_cmd_id() { return _cmd_id;}
 
79
        int get_state() { return _state;}
 
80
 
 
81
    private:
 
82
        std::string _name;
 
83
        int _cmd_id;
 
84
        int _state;
 
85
    };
 
86
 
 
87
    struct MenuItem {
 
88
        ItemType type;
 
89
        void *obj;
 
90
    };
 
91
 
 
92
    void add_item(MenuItem& item);
 
93
 
 
94
private:
 
95
    int _refs;
 
96
    CommandTarget& _target;
 
97
    std::string _name;
 
98
    std::vector<MenuItem> _items;
 
99
    int _id;
 
100
};
 
101
 
 
102
#endif
 
103