• Main Page
  • Classes
  • Files
  • File List

CInputFilter.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2005 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #ifndef CINPUTFILTER_H
00020 #define CINPUTFILTER_H
00021 
00022 #include "KeyTypes.h"
00023 #include "MouseTypes.h"
00024 #include "ProtocolTypes.h"
00025 #include "IPlatformScreen.h"
00026 #include "CString.h"
00027 #include "stdmap.h"
00028 #include "stdset.h"
00029 
00030 class CPrimaryClient;
00031 class CEvent;
00032 
00033 class CInputFilter {
00034 public:
00035     // -------------------------------------------------------------------------
00036     // Input Filter Condition Classes
00037     // -------------------------------------------------------------------------
00038     enum EFilterStatus {
00039         kNoMatch,
00040         kActivate,
00041         kDeactivate
00042     };
00043 
00044     class CCondition {
00045     public:
00046         CCondition();
00047         virtual ~CCondition();
00048 
00049         virtual CCondition*     clone() const = 0;
00050         virtual CString         format() const = 0;
00051 
00052         virtual EFilterStatus   match(const CEvent&) = 0;
00053 
00054         virtual void            enablePrimary(CPrimaryClient*);
00055         virtual void            disablePrimary(CPrimaryClient*);
00056     };
00057     
00058     // CKeystrokeCondition
00059     class CKeystrokeCondition : public CCondition {
00060     public:
00061         CKeystrokeCondition(IPlatformScreen::CKeyInfo*);
00062         CKeystrokeCondition(KeyID key, KeyModifierMask mask);
00063         virtual ~CKeystrokeCondition();
00064 
00065         KeyID                   getKey() const;
00066         KeyModifierMask         getMask() const;
00067 
00068         // CCondition overrides
00069         virtual CCondition*     clone() const;
00070         virtual CString         format() const;
00071         virtual EFilterStatus   match(const CEvent&);
00072         virtual void            enablePrimary(CPrimaryClient*);
00073         virtual void            disablePrimary(CPrimaryClient*);
00074 
00075     private:
00076         UInt32                  m_id;
00077         KeyID                   m_key;
00078         KeyModifierMask         m_mask;
00079     };
00080 
00081     // CMouseButtonCondition
00082     class CMouseButtonCondition : public CCondition {
00083     public:
00084         CMouseButtonCondition(IPlatformScreen::CButtonInfo*);
00085         CMouseButtonCondition(ButtonID, KeyModifierMask mask);
00086         virtual ~CMouseButtonCondition();
00087 
00088         ButtonID                getButton() const;
00089         KeyModifierMask         getMask() const;
00090 
00091         // CCondition overrides
00092         virtual CCondition*     clone() const;
00093         virtual CString         format() const;
00094         virtual EFilterStatus   match(const CEvent&);
00095 
00096     private:
00097         ButtonID                m_button;
00098         KeyModifierMask         m_mask;
00099     };
00100 
00101     // CScreenConnectedCondition
00102     class CScreenConnectedCondition : public CCondition {
00103     public:
00104         CScreenConnectedCondition(const CString& screen);
00105         virtual ~CScreenConnectedCondition();
00106 
00107         // CCondition overrides
00108         virtual CCondition*     clone() const;
00109         virtual CString         format() const;
00110         virtual EFilterStatus   match(const CEvent&);
00111 
00112     private:
00113         CString                 m_screen;
00114     };
00115 
00116     // -------------------------------------------------------------------------
00117     // Input Filter Action Classes
00118     // -------------------------------------------------------------------------
00119     
00120     class CAction {
00121     public:
00122         CAction();
00123         virtual ~CAction();
00124 
00125         virtual CAction*        clone() const = 0;
00126         virtual CString         format() const = 0;
00127 
00128         virtual void            perform(const CEvent&) = 0;
00129     };
00130     
00131     // CLockCursorToScreenAction
00132     class CLockCursorToScreenAction : public CAction {
00133     public:
00134         enum Mode { kOff, kOn, kToggle };
00135 
00136         CLockCursorToScreenAction(Mode = kToggle);
00137 
00138         Mode                    getMode() const;
00139 
00140         // CAction overrides
00141         virtual CAction*        clone() const;
00142         virtual CString         format() const;
00143         virtual void            perform(const CEvent&);
00144 
00145     private:
00146         Mode                    m_mode;
00147     };
00148     
00149     // CSwitchToScreenAction
00150     class CSwitchToScreenAction : public CAction {
00151     public:
00152         CSwitchToScreenAction(const CString& screen);
00153 
00154         CString                 getScreen() const;
00155 
00156         // CAction overrides
00157         virtual CAction*        clone() const;
00158         virtual CString         format() const;
00159         virtual void            perform(const CEvent&);
00160 
00161     private:
00162         CString                 m_screen;
00163     };
00164     
00165     // CSwitchInDirectionAction
00166     class CSwitchInDirectionAction : public CAction {
00167     public:
00168         CSwitchInDirectionAction(EDirection);
00169 
00170         EDirection              getDirection() const;
00171 
00172         // CAction overrides
00173         virtual CAction*        clone() const;
00174         virtual CString         format() const;
00175         virtual void            perform(const CEvent&);
00176 
00177     private:
00178         EDirection              m_direction;
00179     };
00180     
00181     // CKeyboardBroadcastAction
00182     class CKeyboardBroadcastAction : public CAction {
00183     public:
00184         enum Mode { kOff, kOn, kToggle };
00185 
00186         CKeyboardBroadcastAction(Mode = kToggle);
00187         CKeyboardBroadcastAction(Mode, const std::set<CString>& screens);
00188 
00189         Mode                    getMode() const;
00190         std::set<CString>       getScreens() const;
00191 
00192         // CAction overrides
00193         virtual CAction*        clone() const;
00194         virtual CString         format() const;
00195         virtual void            perform(const CEvent&);
00196 
00197     private:
00198         Mode                    m_mode;
00199         CString                 m_screens;
00200     };
00201 
00202     // CKeystrokeAction
00203     class CKeystrokeAction : public CAction {
00204     public:
00205         CKeystrokeAction(IPlatformScreen::CKeyInfo* adoptedInfo, bool press);
00206         ~CKeystrokeAction();
00207 
00208         void                    adoptInfo(IPlatformScreen::CKeyInfo*);
00209         const IPlatformScreen::CKeyInfo*
00210                                 getInfo() const;
00211         bool                    isOnPress() const;
00212 
00213         // CAction overrides
00214         virtual CAction*        clone() const;
00215         virtual CString         format() const;
00216         virtual void            perform(const CEvent&);
00217 
00218     protected:
00219         virtual const char*     formatName() const;
00220 
00221     private:
00222         IPlatformScreen::CKeyInfo*  m_keyInfo;
00223         bool                        m_press;
00224     };
00225 
00226     // CMouseButtonAction -- modifier combinations not implemented yet
00227     class CMouseButtonAction : public CAction {
00228     public:
00229         CMouseButtonAction(IPlatformScreen::CButtonInfo* adoptedInfo,
00230                                     bool press);
00231         ~CMouseButtonAction();
00232 
00233         const IPlatformScreen::CButtonInfo*
00234                                 getInfo() const;
00235         bool                    isOnPress() const;
00236 
00237         // CAction overrides
00238         virtual CAction*        clone() const;
00239         virtual CString         format() const;
00240         virtual void            perform(const CEvent&);
00241 
00242     protected:
00243         virtual const char*     formatName() const;
00244 
00245     private:
00246         IPlatformScreen::CButtonInfo*   m_buttonInfo;
00247         bool                            m_press;
00248     };
00249 
00250     class CRule {
00251     public:
00252         CRule();
00253         CRule(CCondition* adopted);
00254         CRule(const CRule&);
00255         ~CRule();
00256 
00257         CRule& operator=(const CRule&);
00258 
00259         // replace the condition
00260         void            setCondition(CCondition* adopted);
00261 
00262         // add an action to the rule
00263         void            adoptAction(CAction*, bool onActivation);
00264 
00265         // remove an action from the rule
00266         void            removeAction(bool onActivation, UInt32 index);
00267 
00268         // replace an action in the rule
00269         void            replaceAction(CAction* adopted,
00270                             bool onActivation, UInt32 index);
00271 
00272         // enable/disable
00273         void            enable(CPrimaryClient*);
00274         void            disable(CPrimaryClient*);
00275 
00276         // event handling
00277         bool            handleEvent(const CEvent&);
00278 
00279         // convert rule to a string
00280         CString         format() const;
00281 
00282         // get the rule's condition
00283         const CCondition*
00284                         getCondition() const;
00285 
00286         // get number of actions
00287         UInt32          getNumActions(bool onActivation) const;
00288 
00289         // get action by index
00290         const CAction&  getAction(bool onActivation, UInt32 index) const;
00291 
00292     private:
00293         void            clear();
00294         void            copy(const CRule&);
00295 
00296     private:
00297         typedef std::vector<CAction*> CActionList;
00298 
00299         CCondition*     m_condition;
00300         CActionList     m_activateActions;
00301         CActionList     m_deactivateActions;
00302     };
00303 
00304     // -------------------------------------------------------------------------
00305     // Input Filter Class
00306     // -------------------------------------------------------------------------
00307     typedef std::vector<CRule> CRuleList;
00308 
00309     CInputFilter();
00310     CInputFilter(const CInputFilter&);
00311     virtual ~CInputFilter();
00312 
00313     CInputFilter&       operator=(const CInputFilter&);
00314 
00315     // add rule, adopting the condition and the actions
00316     void                addFilterRule(const CRule& rule);
00317 
00318     // remove a rule
00319     void                removeFilterRule(UInt32 index);
00320 
00321     // get rule by index
00322     CRule&              getRule(UInt32 index);
00323 
00324     // enable event filtering using the given primary client.  disable
00325     // if client is NULL.
00326     void                setPrimaryClient(CPrimaryClient* client);
00327 
00328     // convert rules to a string
00329     CString             format(const CString& linePrefix) const;
00330 
00331     // get number of rules
00332     UInt32              getNumRules() const;
00333 
00335     bool                operator==(const CInputFilter&) const;
00337     bool                operator!=(const CInputFilter&) const;
00338 
00339 private:
00340     // event handling
00341     void                handleEvent(const CEvent&, void*);
00342 
00343 private:
00344     CRuleList           m_ruleList;
00345     CPrimaryClient*     m_primaryClient;
00346 };
00347 
00348 #endif

Generated on Fri May 24 2013 00:00:03 for Synergy by  doxygen 1.7.1