Libmacro  0.2
Libmacro is an extensible macro and hotkey library.
key_dispatcher.h
Go to the documentation of this file.
1 /* Libmacro - A multi-platform, extendable macro and hotkey C library
2  Copyright (C) 2013 Jonathan Pelletier, New Paradigm Software
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
22 #ifndef __cplusplus
23  #pragma message "C++ support is required for extras module"
24  #include "mcr/err.h"
25 #endif
26 
27 #ifndef MCR_EXTRAS_KEY_DISPATCHER_H_
28 #define MCR_EXTRAS_KEY_DISPATCHER_H_
29 
31 
32 namespace mcr
33 {
35 class KeyDispatcherPrivate;
38 struct MCR_API KeyDispatcher
39 {
40  friend class KeyDispatcherPrivate;
41  const int ANY = MCR_KEY_ANY;
42 
44 
45  KeyDispatcher(Libmacro *context = nullptr);
46  KeyDispatcher(const KeyDispatcher &copytron);
47  virtual ~KeyDispatcher();
48  KeyDispatcher &operator =(const KeyDispatcher &);
49 
50  inline mcr_AbsKeyDispatcher &operator *()
51  {
52  return self;
53  }
54  inline const mcr_AbsKeyDispatcher &operator *() const
55  {
56  return self;
57  }
58  static inline KeyDispatcher *offset(mcr_IDispatcher *originPt)
59  {
60  return mcr::offset<KeyDispatcher>(originPt);
61  }
62  static inline const KeyDispatcher *offset(const mcr_IDispatcher *originPt)
63  {
64  return mcr::offset<KeyDispatcher>(originPt);
65  }
66 
67  virtual void add(struct mcr_Signal *sigPt, void *receiver, mcr_dispatch_receive_fnc receiverFnc);
68  virtual void clear();
69  // dispatch = mcr_AbsKeyDispatcher_dispatch
70  // modifier = mcr_AbsKeyDispatcher_modifier
71  virtual void remove(void *remReceiver);
72  virtual void trim();
73 
74  virtual unsigned int modifiers(int key) const;
75  virtual int key(unsigned int modifiers) const;
76  // map key <=> modifier
77  virtual void setModifiers(int key, unsigned int modifiers, bool updateFlag = true);
78  // map modifier to key
79  virtual void addModifiers(int key, unsigned int modifiers, bool updateFlag = true);
80  virtual void clearModifiers();
81 
82 private:
83  Libmacro *_context;
84  /* non-export */
85  KeyDispatcherPrivate *_private;
86 
87  void ctor();
88  void update();
89 
90  static void deinit(struct mcr_IDispatcher *idispPt)
91  {
92  mcr_throwif(!idispPt, EFAULT);
93  offset(idispPt)->clear();
94  }
95  static int add(struct mcr_IDispatcher *idispPt, struct mcr_Signal *sigPt, void *receiver, mcr_dispatch_receive_fnc receiverFnc);
96  static void clear(struct mcr_IDispatcher *idispPt);
97  // dispatch = mcr_AbsKeyDispatcher_dispatch
98  // modifier = mcr_AbsKeyDispatcher_modifier
99  static void remove(struct mcr_IDispatcher *idispPt, void *remReceiver);
100  static void trim(struct mcr_IDispatcher *idispPt);
101 };
102 }
103 
104 #endif
#define mcr_throwif(condition, errorNumber)
Definition: defines.h:415
bool(* mcr_dispatch_receive_fnc)(struct mcr_DispatchReceiver *dispatchReceiver, struct mcr_Signal *dispatchSignal, unsigned int mods)
Definition: types.h:50
#define ctor
Definition: defines.h:85
#define MCR_KEY_ANY
Definition: defines.h:406
Raise a compiler error. Usage: #include "mcr/err.h"
Libmacro, by Jonathan Pelletier, New Paradigm Software. Alpha version.
Definition: classes.h:31
void(* trim)(struct mcr_IDispatcher *)
Definition: idispatcher.h:108
rT * offset(vT *valuePt)
Definition: functions.h:44