tagging release
[dasher.git] / trunk / Src / Win32 / TabletPC / InkCollectorEvents.cpp
blobc18b3474034d409194fe17037f97bc44bdec688c
1 // InkCollectorEvents.cpp
2 //
3 /////////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (c) 2005 David Ward
6 //
7 /////////////////////////////////////////////////////////////////////////////
9 #include "..\Common\WinCommon.h"
10 #include "InkCollectorEvents.h"
12 /////////////////////////////////////////////////////////////////////////////
14 // IUnknown Interface
16 HRESULT __stdcall CInkCollectorEvents::QueryInterface(REFIID riid, void **ppvObject)
19 // Validate the input
20 if (NULL == ppvObject)
22 return E_POINTER;
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.
37 return S_OK;
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);
50 return E_NOINTERFACE;
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.
60 return 1;
63 /////////////////////////////////////////////////////////////////////////////
65 ULONG STDMETHODCALLTYPE CInkCollectorEvents::Release()
67 return 1;
70 /////////////////////////////////////////////////////////////////////////////
72 // IDispatch Interface
74 HRESULT CInkCollectorEvents::GetTypeInfoCount(UINT* pctinfo)
76 // Not needs for processing events.
77 return E_NOTIMPL;
80 /////////////////////////////////////////////////////////////////////////////
82 HRESULT CInkCollectorEvents::GetTypeInfo( UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
84 // Not needs for processing events.
85 return E_NOTIMPL;
88 /////////////////////////////////////////////////////////////////////////////
90 HRESULT CInkCollectorEvents::GetIDsOfNames( REFIID riid, LPOLESTR* rgszNames, UINT cNames,
91 LCID lcid, DISPID* rgdispid)
93 // Not needs for processing events.
94 return E_NOTIMPL;
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*/)
105 switch(dispidMember)
107 case DISPID_ICEStroke:
108 Stroke(
109 (IInkCursor*) pdispparams->rgvarg[2].pdispVal,
110 (IInkStrokeDisp*) pdispparams->rgvarg[1].pdispVal,
111 (VARIANT_BOOL *)pdispparams->rgvarg[0].pboolVal);
112 break;
114 case DISPID_ICECursorDown:
115 CursorDown(
116 (IInkCursor*) pdispparams->rgvarg[1].pdispVal,
117 (IInkStrokeDisp*) pdispparams->rgvarg[0].pdispVal);
118 break;
120 case DISPID_ICENewPackets:
121 NewPackets(
122 (IInkCursor*) pdispparams->rgvarg[3].pdispVal,
123 (IInkStrokeDisp*) pdispparams->rgvarg[2].pdispVal,
124 pdispparams->rgvarg[1].lVal,
125 pdispparams->rgvarg[0].pvarVal);
126 break;
128 case DISPID_IPEDblClick:
129 DblClick(
130 (VARIANT_BOOL *)pdispparams->rgvarg[0].pboolVal);
131 break;
133 case DISPID_IPEMouseMove:
134 MouseMove(
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);
140 break;
142 case DISPID_IPEMouseDown:
143 MouseDown(
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);
149 break;
151 case DISPID_IPEMouseUp:
152 MouseUp(
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);
158 break;
160 case DISPID_IPEMouseWheel:
161 MouseWheel(
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);
168 break;
170 case DISPID_ICENewInAirPackets:
171 NewInAirPackets(
172 (IInkCursor*) pdispparams->rgvarg[2].pdispVal,
173 pdispparams->rgvarg[1].lVal,
174 pdispparams->rgvarg[0].pvarVal);
175 break;
177 case DISPID_ICECursorButtonDown:
178 CursorButtonDown(
179 (IInkCursor*) pdispparams->rgvarg[1].pdispVal,
180 (IInkCursorButton*) pdispparams->rgvarg[0].pdispVal);
181 break;
183 case DISPID_ICECursorButtonUp:
184 CursorButtonUp(
185 (IInkCursor*) pdispparams->rgvarg[1].pdispVal,
186 (IInkCursorButton*) pdispparams->rgvarg[0].pdispVal);
187 break;
189 case DISPID_ICECursorInRange:
190 CursorInRange(
191 (IInkCursor*) pdispparams->rgvarg[2].pdispVal,
192 (VARIANT_BOOL) pdispparams->rgvarg[1].iVal,
193 pdispparams->rgvarg[0]);
194 break;
196 case DISPID_ICECursorOutOfRange:
197 CursorOutOfRange(
198 (IInkCursor*) pdispparams->rgvarg[0].pdispVal);
199 break;
201 case DISPID_ICESystemGesture:
202 SystemGesture(
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);
210 break;
212 case DISPID_ICEGesture:
213 Gesture(
214 (IInkCursor*) pdispparams->rgvarg[3].pdispVal,
215 (IInkStrokes*) pdispparams->rgvarg[2].pdispVal,
216 pdispparams->rgvarg[1],
217 (VARIANT_BOOL *)pdispparams->rgvarg[0].pboolVal);
218 break;
220 case DISPID_ICETabletAdded:
221 TabletAdded(
222 (IInkTablet*) pdispparams->rgvarg[0].pdispVal);
223 break;
225 case DISPID_ICETabletRemoved:
226 TabletRemoved(
227 pdispparams->rgvarg[0].lVal);
228 break;
230 default:
231 break;
234 return S_OK;
237 /////////////////////////////////////////////////////////////////////////////
239 CInkCollectorEvents::CInkCollectorEvents() : m_pIConnectionPoint(NULL),
240 m_punkFTM(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)
268 HRESULT hr = S_OK;
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);
280 if (FAILED(hr))
282 return hr;
285 // Find the connection point for Ink Collector events
286 hr = pIConnectionPointContainer->FindConnectionPoint(
287 __uuidof(_IInkCollectorEvents), &m_pIConnectionPoint);
289 if (SUCCEEDED(hr))
291 // Hook up sink to connection point
292 hr = m_pIConnectionPoint->Advise(this, &m_dwCookie);
295 if (FAILED(hr))
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.
310 else
312 hr = E_FAIL;
315 return hr;
319 /////////////////////////////////////////////////////////////////////////////
321 // Remove the connection of the event sink to the Ink Collector
323 HRESULT CInkCollectorEvents::UnadviseInkCollector()
325 HRESULT hr = S_OK;
327 // Unadvise if connected
328 if (m_pIConnectionPoint != NULL)
330 hr = m_pIConnectionPoint->Unadvise(m_dwCookie);
331 m_pIConnectionPoint->Release();
332 m_pIConnectionPoint = NULL;
335 return hr;
338 /////////////////////////////////////////////////////////////////////////////