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

FXAccelTable.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                   A c c e l e r a t o r   T a b l e   C l a s s               *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXAccelTable.h,v 1.32 2009/01/06 13:07:21 fox Exp $                      *
00022 ********************************************************************************/
00023 #ifndef FXACCELTABLE_H
00024 #define FXACCELTABLE_H
00025 
00026 #ifndef FXOBJECT_H
00027 #include "FXObject.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 /**
00034 * The accelerator table sends a message to a specific
00035 * target object when the indicated key and modifier combination
00036 * is pressed.
00037 */
00038 class FXAPI FXAccelTable : public FXObject {
00039   FXDECLARE(FXAccelTable)
00040 protected:
00041   struct FXAccelKey {
00042     FXObject    *target;    // Target object of message
00043     FXSelector   messagedn; // Message being sent
00044     FXSelector   messageup; // Message being sent
00045     FXHotKey     code;      // Keysym and modifier mask to match
00046     };
00047 private:
00048   FXAccelKey *key;          // Accelerator table
00049   FXuint      max;          // Largest table index
00050   FXuint      num;          // Number of entries
00051 private:
00052   void resize(FXuint m);
00053 private:
00054   FXAccelTable(const FXAccelTable&);
00055   FXAccelTable &operator=(const FXAccelTable&);
00056 public:
00057   long onKeyPress(FXObject*,FXSelector,void*);
00058   long onKeyRelease(FXObject*,FXSelector,void*);
00059 public:
00060 
00061   /// Construct empty accelerator table
00062   FXAccelTable();
00063 
00064   /// Add an accelerator into the table
00065   void addAccel(FXHotKey hotkey,FXObject* target=NULL,FXSelector seldn=0,FXSelector selup=0);
00066 
00067   /// Remove an accelerator from the table
00068   void removeAccel(FXHotKey hotkey);
00069 
00070   /// Return true if accelerator specified
00071   FXbool hasAccel(FXHotKey hotkey) const;
00072 
00073   /// Return target object of the given accelerator
00074   FXObject* targetOfAccel(FXHotKey hotkey) const;
00075 
00076   /**
00077   * Parse accelerator from string, yielding modifier and
00078   * key code.  For example, parseAccel("Ctl+Shift+X")
00079   * yields MKUINT(KEY_X,CONTROLMASK|SHIFTMASK).
00080   */
00081   friend FXAPI FXHotKey parseAccel(const FXString& string);
00082 
00083   /**
00084   * Unparse hot key comprising modifier and key code back
00085   * into a string suitable for parsing with fxparseHotKey.
00086   */
00087   friend FXAPI FXString unparseAccel(FXHotKey key);
00088 
00089   /**
00090   * Parse hot key from string, yielding modifier and
00091   * key code.  For example, parseHotKey(""Salt && &Pepper!"")
00092   * yields MKUINT(KEY_p,ALTMASK).
00093   */
00094   friend FXAPI FXHotKey parseHotKey(const FXString& string);
00095 
00096   /**
00097   * Obtain hot key offset in string, or -1 if not found.
00098   * For example, findHotKey("Salt && &Pepper!") yields 7.
00099   * Note that this is the byte-offset, not the character
00100   * index!
00101   */
00102   friend FXAPI FXint findHotKey(const FXString& string);
00103 
00104   /**
00105   * Strip hot key combination from the string.
00106   * For example, stripHotKey("Salt && &Pepper") should
00107   * yield "Salt & Pepper".
00108   */
00109   friend FXAPI FXString stripHotKey(const FXString& string);
00110 
00111   /// Save table to a stream
00112   virtual void save(FXStream& store) const;
00113 
00114   /// Load table from a stream
00115   virtual void load(FXStream& store);
00116 
00117   /// Destructor
00118   virtual ~FXAccelTable();
00119   };
00120 
00121 
00122 extern FXAPI FXHotKey parseAccel(const FXString& string);
00123 extern FXAPI FXString unparseAccel(FXHotKey key);
00124 extern FXAPI FXHotKey parseHotKey(const FXString& string);
00125 extern FXAPI FXint findHotKey(const FXString& string);
00126 extern FXAPI FXString stripHotKey(const FXString& string);
00127 
00128 }
00129 
00130 #endif

Copyright © 1997-2009 Jeroen van der Zijp