Click here to Skip to main content
15,896,111 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.
///////////////////////////////////////////////////////////////
//
// BrowserHelperObject.h
//
// Created: 07/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 __BROWSERHELPEROBJECT_H_853C1B80_13F9_4D62_8A56_E800344DE4ED_
#define __BROWSERHELPEROBJECT_H_853C1B80_13F9_4D62_8A56_E800344DE4ED_

#include "resource.h"       // main symbols
#include "GestureTracker.h"
#include "Action.h"
#include "BrowserWatcher.h"
#include <memory>

class ATL_NO_VTABLE BrowserHelperObject : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<BrowserHelperObject, &CLSID_BrowserHelperObject>,
	public IDispatchImpl<IBrowserHelperObject, &IID_IBrowserHelperObject, &LIBID_MOUSEGESTURESLib>,
    public IObjectWithSiteImpl< BrowserHelperObject >,
    public GestureTracker::Observer,
    public ActionBase
{
public:
	BrowserHelperObject();
    void FinalRelease();

DECLARE_REGISTRY_RESOURCEID(IDR_BROWSERHELPEROBJECT)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(BrowserHelperObject)
	COM_INTERFACE_ENTRY(IBrowserHelperObject)
	COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IObjectWithSite)
END_COM_MAP()

// IObjectWithSite
private:
    STDMETHOD( SetSite )( IUnknown *pUnkSite );

// ActionBase
private:
    void GotoPrevious( const ActionPacket &ap );
    void GotoNext( const ActionPacket &ap );
    void GotoTop( const ActionPacket &ap );
    void GotoBottom( const ActionPacket &ap );
    void GoHome( const ActionPacket &ap );
    void Close( const ActionPacket &ap );
    void OpenNewForeWindow( const ActionPacket &ap );
    void OpenNewBackWindow( const ActionPacket &ap );
    void Refresh( const ActionPacket &ap );
    void Reload( const ActionPacket &ap );
    void Minimise( const ActionPacket &ap );
    void Restore( const ActionPacket &ap );
    void Duplicate( const ActionPacket &ap );
    void ScrollWindows( const ActionPacket &ap );

// GestureTracker::Observer
private:
    virtual bool OnGesture( 
                        HWND hWnd, 
                        GestureManager::Pattern pattern,
                        const Path &path
                        );

// Implementation
private:
/**
 * Execute the action associated with a gesture
 * @param hWnd handle to the window in which the gesture was performed
 * @param pattern the gesture pattern performed
 * @param path a std::vector of POINT's describing the path of the gesture
 **/
    bool    Execute( HWND hWnd, int pattern, const Path &path );

/**
 * Open a new browser window. If the mouse gesture started on an anchor
 * element (a hyperlink) then the browser will start at the page
 * referenced by the anchor. Otherwise the browser will start at the
 * default home page.
 * @param hWnd handle to the window in which the gesture was performed
 * @param pt the POINT where the user started the mouse gesture (i.e. where
 *           WM_MOUSEDOWN message was received)
 * @param isForeground should the window be opened in the foreground or not
 **/
    void    OpenNewWindow( HWND hWnd, const POINT &pt, bool isForeground );

private:
    typedef std::auto_ptr< BrowserWatcher >     AutoBrowserWatcher;

private:
    CComQIPtr< IWebBrowser2 >   m_pWebBrowser;
    AutoBrowserWatcher          m_pBrowserWatcher;
};

#endif // __BROWSERHELPEROBJECT_H_853C1B80_13F9_4D62_8A56_E800344DE4ED_

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