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,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (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 GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXAccelTable.h,v 1.27 2006/01/22 17:57:58 fox Exp $                      *
00023 ********************************************************************************/
00024 #ifndef FXACCELTABLE_H
00025 #define FXACCELTABLE_H
00026 
00027 #ifndef FXOBJECT_H
00028 #include "FXObject.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 /**
00035 * The accelerator table sends a message to a specific
00036 * target object when the indicated key and modifier combination
00037 * is pressed.
00038 */
00039 class FXAPI FXAccelTable : public FXObject {
00040   FXDECLARE(FXAccelTable)
00041 protected:
00042   struct FXAccelKey {
00043     FXObject    *target;    // Target object of message
00044     FXSelector   messagedn; // Message being sent
00045     FXSelector   messageup; // Message being sent
00046     FXHotKey     code;      // Keysym and modifier mask to match
00047     };
00048 private:
00049   FXAccelKey *key;          // Accelerator table
00050   FXuint      max;          // Largest table index
00051   FXuint      num;          // Number of entries
00052 private:
00053   void resize(FXuint m);
00054 private:
00055   FXAccelTable(const FXAccelTable&);
00056   FXAccelTable &operator=(const FXAccelTable&);
00057 public:
00058   long onKeyPress(FXObject*,FXSelector,void*);
00059   long onKeyRelease(FXObject*,FXSelector,void*);
00060 public:
00061 
00062   /// Construct empty accelerator table
00063   FXAccelTable();
00064 
00065   /// Add an accelerator into the table
00066   void addAccel(FXHotKey hotkey,FXObject* target=NULL,FXSelector seldn=0,FXSelector selup=0);
00067 
00068   /// Remove an accelerator from the table
00069   void removeAccel(FXHotKey hotkey);
00070 
00071   /// Return true if accelerator specified
00072   bool hasAccel(FXHotKey hotkey) const;
00073 
00074   /// Return target object of the given accelerator
00075   FXObject* targetOfAccel(FXHotKey hotkey) const;
00076 
00077   /**
00078   * Parse accelerator from string, yielding modifier and
00079   * key code.  For example, parseAccel("Ctl+Shift+X")
00080   * yields MKUINT(KEY_X,CONTROLMASK|SHIFTMASK).
00081   */
00082   friend FXAPI FXHotKey parseAccel(const FXString& string);
00083 
00084   /**
00085   * Unparse hot key comprising modifier and key code back
00086   * into a string suitable for parsing with fxparseHotKey.
00087   */
00088   friend FXAPI FXString unparseAccel(FXHotKey key);
00089 
00090   /**
00091   * Parse hot key from string, yielding modifier and
00092   * key code.  For example, parseHotKey(""Salt && &Pepper!"")
00093   * yields MKUINT(KEY_p,ALTMASK).
00094   */
00095   friend FXAPI FXHotKey parseHotKey(const FXString& string);
00096 
00097   /**
00098   * Obtain hot key offset in string, or -1 if not found.
00099   * For example, findHotKey("Salt && &Pepper!") yields 7.
00100   * Note that this is the byte-offset, not the character
00101   * index!
00102   */
00103   friend FXAPI FXint findHotKey(const FXString& string);
00104 
00105   /**
00106   * Strip hot key combination from the string.
00107   * For example, stripHotKey("Salt && &Pepper") should
00108   * yield "Salt & Pepper".
00109   */
00110   friend FXAPI FXString stripHotKey(const FXString& string);
00111 
00112   /// Save table to a stream
00113   virtual void save(FXStream& store) const;
00114 
00115   /// Load table from a stream
00116   virtual void load(FXStream& store);
00117 
00118   /// Destructor
00119   virtual ~FXAccelTable();
00120   };
00121 
00122 
00123 extern FXAPI FXHotKey parseAccel(const FXString& string);
00124 extern FXAPI FXString unparseAccel(FXHotKey key);
00125 extern FXAPI FXHotKey parseHotKey(const FXString& string);
00126 extern FXAPI FXint findHotKey(const FXString& string);
00127 extern FXAPI FXString stripHotKey(const FXString& string);
00128 
00129 }
00130 
00131 #endif

Copyright © 1997-2005 Jeroen van der Zijp