home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kkeynative.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.1 KB  |  259 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2002 Ellis Whitehead <ellis@kde.org>
  3.  
  4.     Win32 port:
  5.     Copyright (C) 2004 Jaroslaw Staniek <js@iidea.pl>
  6.  
  7.     This library is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU Library General Public
  9.     License as published by the Free Software Foundation; either
  10.     version 2 of the License, or (at your option) any later version.
  11.  
  12.     This library is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     Library General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU Library General Public License
  18.     along with this library; see the file COPYING.LIB.  If not, write to
  19.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20.     Boston, MA 02110-1301, USA.
  21. */
  22.  
  23. #ifndef __KKEYNATIVE_H
  24. #define __KKEYNATIVE_H
  25.  
  26. #include <kshortcut.h>
  27.  
  28. #ifdef Q_WS_X11
  29. typedef union _XEvent XEvent;
  30. #endif
  31.  
  32. class KKeyNativePrivate;
  33. /**
  34.  * Representation of a key in the format native of the windowing system (eg. X11).
  35.  * @see KKey
  36.  */
  37. class KDECORE_EXPORT KKeyNative
  38. {
  39.  public:
  40.     /**
  41.      * Creates a new null KKey.
  42.      * @see clear()
  43.      * @see isNull()
  44.      * @see null()
  45.      */
  46.     KKeyNative();
  47.  
  48. #ifdef Q_WS_X11
  49.     /**
  50.      * Extracts a new native key from the given xevent.
  51.      * @param xevent the XEvent that contains the key
  52.      */
  53.     KKeyNative( const XEvent* xevent );
  54. #endif
  55.  
  56.     /**
  57.      * Creates a new native key for the given KKey code.
  58.      * @param key the KKey that contains the generic key
  59.      */
  60.     KKeyNative( const KKey& key );
  61.  
  62.     /**
  63.      * Copy constructor.
  64.      */
  65.     KKeyNative( const KKeyNative& );
  66.  
  67.     /**
  68.      * @internal
  69.      */
  70.     KKeyNative( uint code, uint mod, uint sym );
  71.     ~KKeyNative();
  72.  
  73.     /**
  74.      * Clears the key. The key is null after calling this function.
  75.      * @see isNull()
  76.      */
  77.     void clear();
  78.  
  79. #ifdef Q_WS_X11
  80.     /**
  81.      * Initializes the native key by extracting the information
  82.      * from the given xevent.
  83.      * @param xevent the XEvent that contains the key
  84.      * @return true if successful, false otherwise
  85.      */
  86.     bool init( const XEvent* xevent );
  87. #endif
  88.  
  89.     /**
  90.      * Creates a new native key for the given KKey code.
  91.      * @param key the KKey that contains the generic key
  92.      * @return true if successful, false otherwise
  93.      */
  94.     bool init( const KKey& key );
  95.  
  96.     /**
  97.      * Copies the given key into this key.
  98.      * @param key the key to copy
  99.      * @return true if successful, false otherwise
  100.      */
  101.     bool init( const KKeyNative& key );
  102.  
  103.     /**
  104.      * Copies the given key into this key.
  105.      * @param key the key to copy
  106.      * @return this key
  107.      */
  108.     KKeyNative& operator =( const KKeyNative& key )
  109.         { init( key ); return *this; }
  110.  
  111.     /**
  112.      * Returns the qt key code.
  113.      * @return the qt key code or 0 if there is no key set.
  114.      * @see Qt::Key
  115.      */
  116.  
  117.     int keyCodeQt() const;
  118.  
  119.     /**
  120.      * Returns the KKey representation of this key.
  121.      * @return the KKey representation
  122.      */
  123.     KKey key() const;
  124.  
  125.     /**
  126.      * Converts this key to its KKey representation.
  127.      * @return the KKey representation
  128.      * @see key()
  129.      */
  130.     operator KKey() const     { return key(); }
  131.  
  132.     /**
  133.      * The native keycode of the key.
  134.      * @return the native keycode
  135.      */
  136.     uint code() const;
  137.  
  138.     /**
  139.      * The native modifier flags of the key.
  140.      * @return the native modifier flags
  141.      */
  142.     uint mod() const;
  143.  
  144.     /**
  145.      * The native symbol (KeySym) of the key.
  146.      * @return the native symbol (KeySym)
  147.      */
  148.     uint sym() const;
  149.  
  150.     /**
  151.      * Returns true if the key is null (after clear() or empty
  152.      * constructor).
  153.      * @return true if the key is null
  154.      * @see clear()
  155.      * @see null()
  156.      */
  157.     bool isNull() const;
  158.  
  159.     /**
  160.      * Compares this key with the given KKeyNative object. Returns a
  161.      * negative number if the given KKeyNative is larger, 0 if they
  162.      * are equal and a positive number this KKeyNative is larger. The
  163.      * returned value is the difference between the symbol, modifier
  164.      * or code, whatever is non-zero first.
  165.      *
  166.      * @param key the key to compare with this key
  167.      * @return a negative number if the given KKeyNative is larger, 0 if
  168.      * they are equal and a positive number this KKeyNative is larger
  169.      */
  170.     int compare( const KKeyNative& key ) const;
  171.  
  172.     /**
  173.      * Compares the symbol, modifiers and code of both keys.
  174.      * @see compare()
  175.      */
  176.     bool operator == ( const KKeyNative& key ) const
  177.         { return compare( key ) == 0; }
  178.  
  179.     /**
  180.      * Compares the symbol, modifiers and code of both keys.
  181.      * @see compare()
  182.      */
  183.     bool operator != ( const KKeyNative& key ) const
  184.         { return compare( key ) != 0; }
  185.  
  186.     /**
  187.      * Compares the symbol, modifiers and code of both keys.
  188.      * @see compare()
  189.      */
  190.     bool operator < ( const KKeyNative& key ) const
  191.         { return compare( key ) < 0; }
  192.  
  193.     /**
  194.      * Returns a null key.
  195.      * @return the null key
  196.      * @see isNull()
  197.      * @see clear()
  198.      */
  199.     static KKeyNative& null();
  200.  
  201.     // General query functions. //
  202.     /**
  203.      * Checks whether the keyboard has a Win key.
  204.      * @return true if the keyboard has a Win key
  205.      */
  206.     static bool keyboardHasWinKey();
  207.  
  208. #ifdef Q_WS_X11
  209.     /**
  210.      * Returns the equivalent X modifier mask of the given modifier flag.
  211.      * @param modFlag the mod flags to test
  212.      * @return the equivalent native flags of the window system
  213.      */
  214.     static uint modX( KKey::ModFlag modFlag );
  215.  
  216.     /**
  217.      * Returns bitwise OR'ed mask containing Shift, Ctrl, Alt, and
  218.      * Win (if available).
  219.      * @return the mask of Shift, Ctrl, Alt and Win.
  220.      */
  221.     static uint accelModMaskX();
  222.  
  223.     /**
  224.      * Returns the X11 NumLock modifier mask/flag.
  225.      * @return the X11 NumLock modifier mask/flag.
  226.      * @see accelModMaskX()
  227.      */
  228.     static uint modXNumLock();
  229.  
  230.     /**
  231.      * Returns the X11 Lock modifier mask/flag.
  232.      * @return the X11 Lock modifier mask/flag.
  233.      * @see accelModMaskX()
  234.      */
  235.     static uint modXLock();
  236.  
  237.     /**
  238.      * Returns the X11 ScrollLock modifier mask/flag.
  239.      * @return the X11 ScrollLock modifier mask/flag.
  240.      * @see accelModMaskX()
  241.      */
  242.     static uint modXScrollLock();
  243.  
  244.     /** 
  245.      * Returns the X11 Mode_switch modifier mask/flag. 
  246.      * @return the X11 Mode_switch modifier mask/flag. 
  247.      * @see accelModMaskX() 
  248.      * @since 3.5
  249.      */ 
  250.     static uint modXModeSwitch(); 
  251. #endif
  252.  
  253.  private:
  254.     uint m_code, m_mod, m_sym;
  255.     KKeyNativePrivate* d;
  256. };
  257.  
  258. #endif // !__KKEYNATIVE_H
  259.