1 // InkCollectorEvents.cpp
3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2005 David Ward
7 /////////////////////////////////////////////////////////////////////////////
9 #include "..\Common\WinCommon.h"
10 #include "InkCollectorEvents.h"
12 /////////////////////////////////////////////////////////////////////////////
16 HRESULT __stdcall
CInkCollectorEvents::QueryInterface(REFIID riid
, void **ppvObject
)
20 if (NULL
== ppvObject
)
25 // This object only supports IDispatch/_IInkCollectorEvents
26 if ((riid
== IID_IUnknown
)
27 || (riid
== IID_IDispatch
)
28 || (riid
== DIID__IInkCollectorEvents
))
30 *ppvObject
= (IDispatch
*) this;
32 // Note: we do not AddRef here because the lifetime
33 // of this object does not depend on reference counting
34 // but on the duration of the connection set up by
35 // the user of this class.
39 else if (riid
== IID_IMarshal
)
41 // Assert that the free threaded marshaller has been
42 // initialized. It is necessary to call Init() before
43 // invoking this method.
44 assert(NULL
!= m_punkFTM
);
46 // Use free threaded marshalling.
47 return m_punkFTM
->QueryInterface(riid
, ppvObject
);
53 /////////////////////////////////////////////////////////////////////////////
55 ULONG STDMETHODCALLTYPE
CInkCollectorEvents::AddRef()
57 // Note: we do not AddRef here because the lifetime
58 // of this object depends on the duration of the connection
59 // set up by the derived class.
63 /////////////////////////////////////////////////////////////////////////////
65 ULONG STDMETHODCALLTYPE
CInkCollectorEvents::Release()
70 /////////////////////////////////////////////////////////////////////////////
72 // IDispatch Interface
74 HRESULT
CInkCollectorEvents::GetTypeInfoCount(UINT
* pctinfo
)
76 // Not needs for processing events.
80 /////////////////////////////////////////////////////////////////////////////
82 HRESULT
CInkCollectorEvents::GetTypeInfo( UINT itinfo
, LCID lcid
, ITypeInfo
** pptinfo
)
84 // Not needs for processing events.
88 /////////////////////////////////////////////////////////////////////////////
90 HRESULT
CInkCollectorEvents::GetIDsOfNames( REFIID riid
, LPOLESTR
* rgszNames
, UINT cNames
,
91 LCID lcid
, DISPID
* rgdispid
)
93 // Not needs for processing events.
97 /////////////////////////////////////////////////////////////////////////////
99 // Translates from IDispatch to the virtual functions
101 HRESULT
CInkCollectorEvents::Invoke( DISPID dispidMember
, REFIID riid
, LCID lcid
,
102 WORD
/*wFlags*/, DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
,
103 EXCEPINFO
* /*pexcepinfo*/, UINT
* /*puArgErr*/)
107 case DISPID_ICEStroke
:
109 (IInkCursor
*) pdispparams
->rgvarg
[2].pdispVal
,
110 (IInkStrokeDisp
*) pdispparams
->rgvarg
[1].pdispVal
,
111 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
114 case DISPID_ICECursorDown
:
116 (IInkCursor
*) pdispparams
->rgvarg
[1].pdispVal
,
117 (IInkStrokeDisp
*) pdispparams
->rgvarg
[0].pdispVal
);
120 case DISPID_ICENewPackets
:
122 (IInkCursor
*) pdispparams
->rgvarg
[3].pdispVal
,
123 (IInkStrokeDisp
*) pdispparams
->rgvarg
[2].pdispVal
,
124 pdispparams
->rgvarg
[1].lVal
,
125 pdispparams
->rgvarg
[0].pvarVal
);
128 case DISPID_IPEDblClick
:
130 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
133 case DISPID_IPEMouseMove
:
135 (InkMouseButton
) pdispparams
->rgvarg
[4].lVal
,
136 (InkShiftKeyModifierFlags
) pdispparams
->rgvarg
[3].lVal
,
137 pdispparams
->rgvarg
[2].lVal
,
138 pdispparams
->rgvarg
[1].lVal
,
139 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
142 case DISPID_IPEMouseDown
:
144 (InkMouseButton
) pdispparams
->rgvarg
[4].lVal
,
145 (InkShiftKeyModifierFlags
) pdispparams
->rgvarg
[3].lVal
,
146 pdispparams
->rgvarg
[2].lVal
,
147 pdispparams
->rgvarg
[1].lVal
,
148 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
151 case DISPID_IPEMouseUp
:
153 (InkMouseButton
) pdispparams
->rgvarg
[4].lVal
,
154 (InkShiftKeyModifierFlags
) pdispparams
->rgvarg
[3].lVal
,
155 pdispparams
->rgvarg
[2].lVal
,
156 pdispparams
->rgvarg
[1].lVal
,
157 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
160 case DISPID_IPEMouseWheel
:
162 (InkMouseButton
) pdispparams
->rgvarg
[5].lVal
,
163 (InkShiftKeyModifierFlags
) pdispparams
->rgvarg
[4].lVal
,
164 pdispparams
->rgvarg
[3].lVal
,
165 pdispparams
->rgvarg
[2].lVal
,
166 pdispparams
->rgvarg
[1].lVal
,
167 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
170 case DISPID_ICENewInAirPackets
:
172 (IInkCursor
*) pdispparams
->rgvarg
[2].pdispVal
,
173 pdispparams
->rgvarg
[1].lVal
,
174 pdispparams
->rgvarg
[0].pvarVal
);
177 case DISPID_ICECursorButtonDown
:
179 (IInkCursor
*) pdispparams
->rgvarg
[1].pdispVal
,
180 (IInkCursorButton
*) pdispparams
->rgvarg
[0].pdispVal
);
183 case DISPID_ICECursorButtonUp
:
185 (IInkCursor
*) pdispparams
->rgvarg
[1].pdispVal
,
186 (IInkCursorButton
*) pdispparams
->rgvarg
[0].pdispVal
);
189 case DISPID_ICECursorInRange
:
191 (IInkCursor
*) pdispparams
->rgvarg
[2].pdispVal
,
192 (VARIANT_BOOL
) pdispparams
->rgvarg
[1].iVal
,
193 pdispparams
->rgvarg
[0]);
196 case DISPID_ICECursorOutOfRange
:
198 (IInkCursor
*) pdispparams
->rgvarg
[0].pdispVal
);
201 case DISPID_ICESystemGesture
:
203 (IInkCursor
*) pdispparams
->rgvarg
[6].pdispVal
,
204 (InkSystemGesture
) pdispparams
->rgvarg
[5].lVal
,
205 pdispparams
->rgvarg
[4].lVal
,
206 pdispparams
->rgvarg
[3].lVal
,
207 pdispparams
->rgvarg
[2].lVal
,
208 pdispparams
->rgvarg
[1].bstrVal
,
209 pdispparams
->rgvarg
[0].lVal
);
212 case DISPID_ICEGesture
:
214 (IInkCursor
*) pdispparams
->rgvarg
[3].pdispVal
,
215 (IInkStrokes
*) pdispparams
->rgvarg
[2].pdispVal
,
216 pdispparams
->rgvarg
[1],
217 (VARIANT_BOOL
*)pdispparams
->rgvarg
[0].pboolVal
);
220 case DISPID_ICETabletAdded
:
222 (IInkTablet
*) pdispparams
->rgvarg
[0].pdispVal
);
225 case DISPID_ICETabletRemoved
:
227 pdispparams
->rgvarg
[0].lVal
);
237 /////////////////////////////////////////////////////////////////////////////
239 CInkCollectorEvents::CInkCollectorEvents() : m_pIConnectionPoint(NULL
),
244 /////////////////////////////////////////////////////////////////////////////
246 CInkCollectorEvents::~CInkCollectorEvents()
248 UnadviseInkCollector();
250 if (m_punkFTM
!= NULL
)
251 m_punkFTM
->Release();
254 /////////////////////////////////////////////////////////////////////////////
256 // Set up free threaded marshaller.
258 HRESULT
CInkCollectorEvents::Init()
260 return CoCreateFreeThreadedMarshaler(this, &m_punkFTM
);
263 /////////////////////////////////////////////////////////////////////////////
265 // Set up connection between sink and Ink Collector
266 HRESULT
CInkCollectorEvents::AdviseInkCollector( IInkCollector
*pIInkCollector
)
270 // Check to ensure that the sink is not currently connected
271 // with another Ink Collector...
272 if (NULL
== m_pIConnectionPoint
)
274 // Get the connection point container
275 IConnectionPointContainer
*pIConnectionPointContainer
;
276 hr
= pIInkCollector
->QueryInterface(
277 IID_IConnectionPointContainer
,
278 (void **) &pIConnectionPointContainer
);
285 // Find the connection point for Ink Collector events
286 hr
= pIConnectionPointContainer
->FindConnectionPoint(
287 __uuidof(_IInkCollectorEvents
), &m_pIConnectionPoint
);
291 // Hook up sink to connection point
292 hr
= m_pIConnectionPoint
->Advise(this, &m_dwCookie
);
297 // Clean up after an error.
298 if (m_pIConnectionPoint
)
300 m_pIConnectionPoint
->Release();
301 m_pIConnectionPoint
= NULL
;
305 // We don't need the connection point container any more.
306 pIConnectionPointContainer
->Release();
308 // If the sink is already connected to an Ink Collector, return a
309 // failure; only one Ink Collector can be attached at any given time.
319 /////////////////////////////////////////////////////////////////////////////
321 // Remove the connection of the event sink to the Ink Collector
323 HRESULT
CInkCollectorEvents::UnadviseInkCollector()
327 // Unadvise if connected
328 if (m_pIConnectionPoint
!= NULL
)
330 hr
= m_pIConnectionPoint
->Unadvise(m_dwCookie
);
331 m_pIConnectionPoint
->Release();
332 m_pIConnectionPoint
= NULL
;
338 /////////////////////////////////////////////////////////////////////////////