Click here to Skip to main content
15,888,579 members
Articles / Web Development / HTML

Mouse Gestures for Internet Explorer

Rate me:
Please Sign up or sign in to vote.
4.84/5 (99 votes)
21 Sep 200514 min read 1.3M   13.4K   235  
Adding mouse gesture recognition to Internet Explorer.
///////////////////////////////////////////////////////////////
//
// GestureTracker.h
//
// Created: 13/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 __GESTURETRACKER_H_4635CA4B_77B4_400C_A34B_22BEF5262818_
#define __GESTURETRACKER_H_4635CA4B_77B4_400C_A34B_22BEF5262818_

#include "MouseTracker.h"
#include "Gesture.h"
#include "GestureManager.h"

/**
 * @brief The GestureTracker class tracks mouse movements and
 * informs the observer of any gestures that occured.
 *
 * The Gesture tracker class subclasses a window (via a MouseTracker object),
 * and recognises gestures performed while the left and/or right mouse buttons
 * are held down (using a Gesture object).
 **/
class GestureTracker : public MouseTracker::Watcher
{
public:
    struct Observer
    {
    /**
     * @param hWnd handle to the window where the gesture occured
     * @param pattern the mouse gesture pattern performed
     * @param path the points that make up the mouse gesture
     * @return return true if the mouse gesture has been handled
     *         return false if the mouse gesture has not been handled
     *         if the mouse gesture hasn't been handled then the GestureTracker
     *         will synthesise the button click that caused the gesture
     **/
        virtual bool OnGesture( 
                            HWND hWnd, 
                            GestureManager::Pattern pattern,
                            const Path &path
                            ) = 0;
    };

public:
    GestureTracker( bool trackLeft = false, bool trackRight = true );

    HRESULT Advise( HWND hWnd, Observer *pObserver );
    HRESULT Unadvise();

// MouseTracker::Watcher
private:
    bool OnLeftButtonDown( HWND hWnd, const POINT &pt, DWORD flags );
    bool OnRightButtonDown( HWND hWnd, const POINT &pt, DWORD flags );
    bool OnLeftButtonUp( HWND, const POINT &, DWORD );
    bool OnRightButtonUp( HWND, const POINT &, DWORD );
    bool OnMouseWheel( HWND hWnd, WORD flags, WORD delta, const POINT &pt );

    void OnLeftButtonUp( HWND hWnd, const Path &path );
    void OnRightButtonUp( HWND hWnd, const Path &path );

private:
    void SynthesiseLeftClick( const Path &path );
    void SynthesiseRightClick( const Path &path );

private:
    MouseTracker    m_mouseTracker;
    Gesture         m_gesture;
    Observer        *m_pObserver;
    bool            m_trackLeft;
    bool            m_trackRight;
};

#endif // __GESTURETRACKER_H_4635CA4B_77B4_400C_A34B_22BEF5262818_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions