bluetoothengine/bthid/manager/inc/modifier.h
changeset 0 f63038272f30
equal deleted inserted replaced
-1:000000000000 0:f63038272f30
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Declares main application class.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __MODIFIER_H
       
    20 #define __MODIFIER_H
       
    21 
       
    22 #include <e32std.h>
       
    23 
       
    24 // ----------------------------------------------------------------------
       
    25 
       
    26 /*!
       
    27  Convenience functions for working with HID (boot protocol style)
       
    28  keyboard modifier flags.  These are stored as an eight bit vector as
       
    29  follows:
       
    30  
       
    31  <pre>
       
    32  +-------------------------------------------------------+
       
    33  |           Right           |           Left            |
       
    34  +-------------------------------------------------------+
       
    35  | Func |  Alt | Shft | Ctrl | Func |  Alt | Shft | Ctrl |
       
    36  +-------------------------------------------------------+
       
    37  bit:  7      6      5      4      3      2      1      0
       
    38  </pre>
       
    39  
       
    40  We also make use of a "folded" representation, where there
       
    41  is no distinction between the left and right versions of
       
    42  the modifier keys:
       
    43  
       
    44  <pre>
       
    45  +---------------------------+---------------------------+
       
    46  |   0  |   0  |   0  |   0  | Func |  Alt | Shft | Ctrl |
       
    47  +---------------------------+---------------------------+
       
    48  bit:  7      6      5      4      3      2      1      0
       
    49  </pre>
       
    50  
       
    51  i.e. folded = left OR right.
       
    52  */
       
    53 class THidModifier
       
    54     {
       
    55 public:
       
    56     THidModifier(TUint8 aFlags);
       
    57 
       
    58     inline void Set(TUint8 aValue);
       
    59     inline void Merge(TUint8 aValue);
       
    60     inline void Clear(TUint8 aValue);
       
    61 
       
    62     inline TUint8 Value() const;
       
    63 
       
    64     inline TBool None() const;
       
    65     inline TBool Shift() const;
       
    66     inline TBool Control() const;
       
    67     inline TBool Alt() const;
       
    68     inline TBool Func() const;
       
    69 
       
    70     inline TBool LeftControl() const;
       
    71     inline TBool LeftShift() const;
       
    72     inline TBool LeftAlt() const;
       
    73     inline TBool LeftFunc() const;
       
    74 
       
    75     inline TBool RightControl() const;
       
    76     inline TBool RightShift() const;
       
    77     inline TBool RightAlt() const;
       
    78     inline TBool RightFunc() const;
       
    79 
       
    80     inline TBool ControlAlt() const;
       
    81 
       
    82     inline TBool ShiftOnly() const;
       
    83     inline TBool ControlOnly() const;
       
    84     inline TBool AltOnly() const;
       
    85     inline TBool FuncOnly() const;
       
    86 
       
    87     inline TUint8 Fold() const;
       
    88 
       
    89     inline void InvertShift();
       
    90 
       
    91 public:
       
    92     enum TModifiers
       
    93         {
       
    94         ELeftControl = (1 << 0),
       
    95         ELeftShift = (1 << 1),
       
    96         ELeftAlt = (1 << 2),
       
    97         ELeftFunc = (1 << 3),
       
    98         ERightControl = (1 << 4),
       
    99         ERightShift = (1 << 5),
       
   100         ERightAlt = (1 << 6),
       
   101         ERightFunc = (1 << 7)
       
   102         };
       
   103 
       
   104     enum TFoldedModifiers
       
   105         {
       
   106         EUnmodified = 0, // ----
       
   107         ECtrl = 1, // ---C
       
   108         EShift = 2, // --S-
       
   109         ECtrlShift = 3, // --SC
       
   110         EAlt = 4, // -A--
       
   111         EAltCtrl = 5, // -A-C
       
   112         EAltShift = 6, // -AS-
       
   113         EAltCtrlShift = 7, // -ASC
       
   114         EFunc = 8, // F---
       
   115         EFuncCtrl = 9, // F--C
       
   116         EFuncShift = 10, // F-S-
       
   117         EFuncCtrlShift = 11, // F-SC
       
   118         EFuncAlt = 12, // FA--
       
   119         EFuncAltCtrl = 13, // FA-C
       
   120         EFuncAltShift = 14, // FAS-
       
   121         EFuncAltCtrlShift = 15
       
   122         // FASC
       
   123         };
       
   124 
       
   125 private:
       
   126     TUint8 iFlags;
       
   127     };
       
   128 
       
   129 // ----------------------------------------------------------------------
       
   130 
       
   131 inline THidModifier::THidModifier(TUint8 aFlags) :
       
   132     iFlags(aFlags)
       
   133     {
       
   134     // nothing else to do
       
   135     }
       
   136 
       
   137 inline TUint8 THidModifier::Value() const
       
   138     {
       
   139     return iFlags;
       
   140     }
       
   141 
       
   142 inline void THidModifier::Set(TUint8 aValue)
       
   143     {
       
   144     iFlags = aValue;
       
   145     }
       
   146 
       
   147 inline void THidModifier::Merge(TUint8 aValue)
       
   148     {
       
   149     iFlags |= aValue;
       
   150     }
       
   151 
       
   152 inline void THidModifier::Clear(TUint8 aValue)
       
   153     {
       
   154     iFlags &= ~aValue;
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------
       
   158 // Individual keys:
       
   159 
       
   160 inline TBool THidModifier::LeftControl() const
       
   161     {
       
   162     return iFlags & ELeftControl;
       
   163     }
       
   164 
       
   165 inline TBool THidModifier::LeftShift() const
       
   166     {
       
   167     return iFlags & ELeftShift;
       
   168     }
       
   169 
       
   170 inline TBool THidModifier::LeftAlt() const
       
   171     {
       
   172     return iFlags & ELeftAlt;
       
   173     }
       
   174 
       
   175 inline TBool THidModifier::LeftFunc() const
       
   176     {
       
   177     return iFlags & ELeftFunc;
       
   178     }
       
   179 
       
   180 inline TBool THidModifier::RightControl() const
       
   181     {
       
   182     return iFlags & ERightControl;
       
   183     }
       
   184 
       
   185 inline TBool THidModifier::RightShift() const
       
   186     {
       
   187     return iFlags & ERightShift;
       
   188     }
       
   189 
       
   190 inline TBool THidModifier::RightAlt() const
       
   191     {
       
   192     return iFlags & ERightAlt;
       
   193     }
       
   194 
       
   195 inline TBool THidModifier::RightFunc() const
       
   196     {
       
   197     return iFlags & ERightFunc;
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------
       
   201 // Modifier states:
       
   202 
       
   203 inline TBool THidModifier::None() const
       
   204     {
       
   205     return iFlags == 0;
       
   206     }
       
   207 
       
   208 inline TBool THidModifier::Shift() const
       
   209     {
       
   210     return LeftShift() || RightShift();
       
   211     }
       
   212 
       
   213 inline TBool THidModifier::Control() const
       
   214     {
       
   215     return LeftControl() || RightControl();
       
   216     }
       
   217 
       
   218 inline TBool THidModifier::Alt() const
       
   219     {
       
   220     return LeftAlt() || RightAlt();
       
   221     }
       
   222 
       
   223 inline TBool THidModifier::Func() const
       
   224     {
       
   225     return LeftFunc() || RightFunc();
       
   226     }
       
   227 
       
   228 inline TBool THidModifier::ControlAlt() const
       
   229     {
       
   230     return Alt() && Control();
       
   231     }
       
   232 
       
   233 // ----------------------------------------------------------------------
       
   234 
       
   235 inline TUint8 THidModifier::Fold() const
       
   236     {
       
   237     TUint left = iFlags & 0x0f;
       
   238     TUint right = (iFlags & 0xf0) >> 4;
       
   239     return static_cast<TUint8> (left | right);
       
   240     }
       
   241 
       
   242 // ----------------------------------------------------------------------
       
   243 
       
   244 inline TBool THidModifier::ShiftOnly() const
       
   245     {
       
   246     return Fold() == EShift;
       
   247     }
       
   248 
       
   249 inline TBool THidModifier::ControlOnly() const
       
   250     {
       
   251     return Fold() == ECtrl;
       
   252     }
       
   253 
       
   254 inline TBool THidModifier::AltOnly() const
       
   255     {
       
   256     return Fold() == EAlt;
       
   257     }
       
   258 
       
   259 inline TBool THidModifier::FuncOnly() const
       
   260     {
       
   261     return Fold() == EFunc;
       
   262     }
       
   263 
       
   264 // ----------------------------------------------------------------------
       
   265 
       
   266 inline void THidModifier::InvertShift()
       
   267     {
       
   268     if (iFlags & (ELeftShift | ERightShift))
       
   269         {
       
   270         iFlags &= ~(ELeftShift | ERightShift);
       
   271         }
       
   272     else
       
   273         {
       
   274         iFlags |= ELeftShift;
       
   275         }
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------------------------
       
   279 
       
   280 #endif