Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXAccelTable.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * A c c e l e r a t o r T a b l e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1998,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXAccelTable.h,v 1.27 2006/01/22 17:57:58 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXACCELTABLE_H
25 #define FXACCELTABLE_H
26 
27 #ifndef FXOBJECT_H
28 #include "FXObject.h"
29 #endif
30 
31 namespace FX {
32 
33 
34 /**
35 * The accelerator table sends a message to a specific
36 * target object when the indicated key and modifier combination
37 * is pressed.
38 */
39 class FXAPI FXAccelTable : public FXObject {
41 protected:
42  struct FXAccelKey {
43  FXObject *target; // Target object of message
44  FXSelector messagedn; // Message being sent
45  FXSelector messageup; // Message being sent
46  FXHotKey code; // Keysym and modifier mask to match
47  };
48 private:
49  FXAccelKey *key; // Accelerator table
50  FXuint max; // Largest table index
51  FXuint num; // Number of entries
52 private:
53  void resize(FXuint m);
54 private:
55  FXAccelTable(const FXAccelTable&);
56  FXAccelTable &operator=(const FXAccelTable&);
57 public:
58  long onKeyPress(FXObject*,FXSelector,void*);
59  long onKeyRelease(FXObject*,FXSelector,void*);
60 public:
61 
62  /// Construct empty accelerator table
63  FXAccelTable();
64 
65  /// Add an accelerator into the table
66  void addAccel(FXHotKey hotkey,FXObject* target=NULL,FXSelector seldn=0,FXSelector selup=0);
67 
68  /// Remove an accelerator from the table
69  void removeAccel(FXHotKey hotkey);
70 
71  /// Return true if accelerator specified
72  bool hasAccel(FXHotKey hotkey) const;
73 
74  /// Return target object of the given accelerator
75  FXObject* targetOfAccel(FXHotKey hotkey) const;
76 
77  /**
78  * Parse accelerator from string, yielding modifier and
79  * key code. For example, parseAccel("Ctl+Shift+X")
80  * yields MKUINT(KEY_X,CONTROLMASK|SHIFTMASK).
81  */
82  friend FXAPI FXHotKey parseAccel(const FXString& string);
83 
84  /**
85  * Unparse hot key comprising modifier and key code back
86  * into a string suitable for parsing with fxparseHotKey.
87  */
88  friend FXAPI FXString unparseAccel(FXHotKey key);
89 
90  /**
91  * Parse hot key from string, yielding modifier and
92  * key code. For example, parseHotKey(""Salt && &Pepper!"")
93  * yields MKUINT(KEY_p,ALTMASK).
94  */
95  friend FXAPI FXHotKey parseHotKey(const FXString& string);
96 
97  /**
98  * Obtain hot key offset in string, or -1 if not found.
99  * For example, findHotKey("Salt && &Pepper!") yields 7.
100  * Note that this is the byte-offset, not the character
101  * index!
102  */
103  friend FXAPI FXint findHotKey(const FXString& string);
104 
105  /**
106  * Strip hot key combination from the string.
107  * For example, stripHotKey("Salt && &Pepper") should
108  * yield "Salt & Pepper".
109  */
110  friend FXAPI FXString stripHotKey(const FXString& string);
111 
112  /// Save table to a stream
113  virtual void save(FXStream& store) const;
114 
115  /// Load table from a stream
116  virtual void load(FXStream& store);
117 
118  /// Destructor
119  virtual ~FXAccelTable();
120  };
121 
122 
123 extern FXAPI FXHotKey parseAccel(const FXString& string);
124 extern FXAPI FXString unparseAccel(FXHotKey key);
125 extern FXAPI FXHotKey parseHotKey(const FXString& string);
126 extern FXAPI FXint findHotKey(const FXString& string);
127 extern FXAPI FXString stripHotKey(const FXString& string);
128 
129 }
130 
131 #endif
unsigned int FXuint
Definition: fxdefs.h:396
FXuint FXHotKey
Definition: fxdefs.h:457
FXuint FXSelector
Association key.
Definition: FXObject.h:53
The accelerator table sends a message to a specific target object when the indicated key and modifier...
Definition: FXAccelTable.h:39
FXHotKey parseAccel(const FXString &string)
#define FXAPI
Definition: fxdefs.h:122
FXHotKey parseHotKey(const FXString &string)
#define NULL
Definition: fxdefs.h:41
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:397
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
FXString unparseAccel(FXHotKey key)
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33
FXString stripHotKey(const FXString &string)
FXint findHotKey(const FXString &string)

Copyright © 1997-2005 Jeroen van der Zijp