///////////////////////////////////////////////////////////////
//
// GestureManager.h
//
// Created: 12/07/2003
// Copyright (c) 2003 Ralph Hare (ralph.hare@ysgyfarnog.co.uk)
// All rights reserved.
//
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
//
///////////////////////////////////////////////////////////////
#ifndef __GESTUREMANAGER_H_1838234F_5FE5_47C8_83CB_E19662B9E87A_
#define __GESTUREMANAGER_H_1838234F_5FE5_47C8_83CB_E19662B9E87A_
#include <map>
#include "GestureData.h"
#include "Action.h"
/**
* Structure to record info about a mouse gesture. Note the absence of
* a copy constructor and destructor. A bitwise copy is Ok when
* a GestureRec is inserted into a container. Similarly, as we're using
* a bitwise copy, we don't want our resources to be freed when they're
* inserted into the container. Therefore, resources must be freed manually when
* GestureRec's are removed from a container.
**/
struct GestureRec
{
HBITMAP bitmap;
LPCTSTR description;
int action;
GestureRec( UINT id, LPCTSTR description_, int action_ );
};
/**
* Singleton manager object to manage gestures. This manager is designed
* to allow the user to customise the action associated with a particular
* mouse gesture. This is enabled by the GestureManager maintaining a map
* of gestures and their associated action (@see ACTION). ACTION is a typedef
* for member function pointer of the ActionBase class. Implementors of the
* ActionBase base class should invoke this member function along the following
* lines:
*
* <code>
* class GestureImpl : public ActionBase
* {
* void Test( int pattern, const ActionPacket &packet )
* {
* ACTION action = GestureManager::GetAction( pattern );
* if( action )
* {
* ( this->*action )( packet );
* }
* }
*
* // ActionBase
* private:
* void OnGotoNext( const ActionPacket & );
* // etc.
* };
*
* </code>
**/
class GestureManager : public std::map< int, GestureRec >
{
public:
enum Pattern
{
Unknown = -1,
Up = 0,
Down = 1,
UpDown = 2,
DownUp = 3,
Right = 4,
Left = 5,
RightLeft = 6,
LeftRight = 7,
DownRight = 8,
UpLeft = 9,
DownLeft = 11,
UpRight = 12,
LeftArrow = 13,
RightArrow = 14,
ZigZag = 15,
DownArrow = 16,
UpArrow = 17,
ClickLeftRight = 0xF000,
ClickRightLeft,
MouseWheel
};
enum Button
{
LeftButton = 0,
RightButton,
MiddleButton
};
private:
GestureManager();
public:
~GestureManager();
public:
static GestureManager & GetInstance();
static HBITMAP GetBitmap( int pattern );
static ACTION GetAction( int pattern );
static int GetActionIndex( int pattern );
static void SetActionIndex( int pattern, int actionIndex );
static bool IsEnabled();
static void SetEnabled( bool isEnabled );
static bool LoadInExplorer();
static void SetLoadInExplorer( bool loadInExplorer );
static Action::ActionIndex GetDefaultAction( int pattern );
public:
typedef std::map< int, GestureRec >::iterator iterator;
typedef std::map< int, GestureRec >::const_iterator const_iterator;
typedef std::pair< int, GestureRec > pair;
private:
void LoadAction( iterator &it ) const;
void SaveAction( const_iterator &it ) const;
private:
bool m_isEnabled;
CRegKey m_regKey;
private:
mutable CRegKey m_actionKey;
};
#endif // __GESTUREMANAGER_H_1838234F_5FE5_47C8_83CB_E19662B9E87A_