blob: d0245ee92ac479d20e375fdbfa88d29b6c4ae23c [file] [log] [blame]
Constantin Kaplinskyb30ae7f2006-05-25 05:04:46 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18//
19// TXMenu.h
20//
21// A TXMenu consists of multiple entries which can be added one at a time.
22// Each entry consists of some text, and has an associated integer identifier.
23// A callback is made when a menu entry is selected.
24//
25
26#ifndef __TXMENU_H__
27#define __TXMENU_H__
28
29#include "TXWindow.h"
30
31// TXMenuCallback's menuSelect() method is called when a particular menu entry
32// is selected. The id argument identifies the menu entry.
33class TXMenu;
34class TXMenuCallback {
35public:
36 virtual void menuSelect(long id, TXMenu* menu)=0;
37};
38
39class TXMenu : public TXWindow, public TXEventHandler {
40public:
41 TXMenu(Display* dpy_, TXMenuCallback* cb=0, int width=1, int height=1,
42 TXWindow* parent_=0);
43 virtual ~TXMenu();
44
45 // addEntry() adds an entry to the end of the menu with the given text and
46 // identifier.
47 void addEntry(const char* text, long id);
48
49 // check() sets whether the given menu entry should have a tick next to it.
50 void check(long id, bool checked);
51
52private:
53 int entryHeight(int i);
54 virtual void handleEvent(TXWindow* w, XEvent* ev);
55 void paint();
56
57 GC gc;
58 TXMenuCallback* cb;
59 enum { maxEntries = 64 };
60 char* text[maxEntries];
61 long id[maxEntries];
62 bool checked[maxEntries];
63 int nEntries;
64 int highlight;
65};
66
67#endif