Mercurial > sdl-ios-xcode
comparison EXCLUDE/GLTSF/src/TSF.cpp @ 4740:abf528de6d2e
Added condition check macros to make the code clear and easier to debug.
Updated code to use macros.
author | dewyatt |
---|---|
date | Sun, 27 Jun 2010 22:03:08 -0400 |
parents | f51a9f01b508 |
children |
comparison
equal
deleted
inserted
replaced
4739:f51a9f01b508 | 4740:abf528de6d2e |
---|---|
72 | 72 |
73 delete this; | 73 delete this; |
74 return 0; | 74 return 0; |
75 } | 75 } |
76 | 76 |
77 #define CHECK_CONDITION(condition, retval, function, line) \ | |
78 if (!condition) \ | |
79 { \ | |
80 printf("%s:%d: Condition failure: %s\n", function, line, #condition); \ | |
81 } | |
82 | |
83 #define ENSURE(condition, retval) CHECK_CONDITION(condition, retval, __FUNCTION__, __LINE__) | |
84 | |
77 STDMETHODIMP TSF::TSF_Text_Store::AdviseSink(REFIID riid, IUnknown *punk, DWORD dwMask) | 85 STDMETHODIMP TSF::TSF_Text_Store::AdviseSink(REFIID riid, IUnknown *punk, DWORD dwMask) |
78 { | 86 { |
79 if (!punk || IID_ITextStoreACPSink != riid) | 87 ENSURE(punk && IID_ITextStoreACP == riid, E_INVALIDARG); |
80 return E_INVALIDARG; | |
81 | 88 |
82 if (!my_Sink) | 89 if (!my_Sink) |
83 { | 90 { |
84 punk->QueryInterface(&my_Sink); | 91 HRESULT hr = punk->QueryInterface(&my_Sink); |
85 if (!my_Sink) | 92 ENSURE(SUCCEEDED(hr) && my_Sink, E_UNEXPECTED); |
86 return E_UNEXPECTED; | |
87 } | 93 } |
88 else | 94 else |
89 { | 95 { |
90 CComPtr<IUnknown> Unknown_1, Unknown_2; | 96 CComPtr<IUnknown> Unknown_1, Unknown_2; |
91 punk->QueryInterface(&Unknown_1); | 97 punk->QueryInterface(&Unknown_1); |
97 return S_OK; | 103 return S_OK; |
98 } | 104 } |
99 | 105 |
100 STDMETHODIMP TSF::TSF_Text_Store::UnadviseSink(IUnknown *punk) | 106 STDMETHODIMP TSF::TSF_Text_Store::UnadviseSink(IUnknown *punk) |
101 { | 107 { |
102 if (!punk) | 108 ENSURE(punk, E_INVALIDARG); |
103 return E_INVALIDARG; | 109 ENSURE(my_Sink, CONNECT_E_NOCONNECTION); |
104 | |
105 if (!my_Sink) | |
106 return CONNECT_E_NOCONNECTION; | |
107 | 110 |
108 CComPtr<IUnknown> Unknown_1, Unknown_2; | 111 CComPtr<IUnknown> Unknown_1, Unknown_2; |
109 punk->QueryInterface(&Unknown_1); | 112 punk->QueryInterface(&Unknown_1); |
110 my_Sink->QueryInterface(&Unknown_2); | 113 my_Sink->QueryInterface(&Unknown_2); |
111 | 114 |
117 return S_OK; | 120 return S_OK; |
118 } | 121 } |
119 | 122 |
120 STDMETHODIMP TSF::TSF_Text_Store::RequestLock(DWORD dwLockFlags, HRESULT *phrSession) | 123 STDMETHODIMP TSF::TSF_Text_Store::RequestLock(DWORD dwLockFlags, HRESULT *phrSession) |
121 { | 124 { |
122 if (!my_Sink) | 125 ENSURE(my_Sink, E_FAIL); |
123 return E_FAIL; | 126 ENSURE(phrSession, E_INVALIDARG); |
124 | |
125 if (!phrSession) | |
126 return E_INVALIDARG; | |
127 | |
128 if (my_Lock) | 127 if (my_Lock) |
129 { | 128 { |
130 if (TS_LF_READ == (my_Lock & TS_LF_READWRITE) | 129 if (TS_LF_READ == (my_Lock & TS_LF_READWRITE) |
131 && TS_LF_READWRITE == (dwLockFlags & TS_LF_READWRITE) | 130 && TS_LF_READWRITE == (dwLockFlags & TS_LF_READWRITE) |
132 && !(dwLockFlags & TS_LF_SYNC)) | 131 && !(dwLockFlags & TS_LF_SYNC)) |
155 return S_OK; | 154 return S_OK; |
156 } | 155 } |
157 | 156 |
158 STDMETHODIMP TSF::TSF_Text_Store::GetStatus(TS_STATUS *pdcs) | 157 STDMETHODIMP TSF::TSF_Text_Store::GetStatus(TS_STATUS *pdcs) |
159 { | 158 { |
160 if (!pdcs) | 159 ENSURE(pdcs, E_INVALIDARG); |
161 return E_INVALIDARG; | |
162 | |
163 pdcs->dwDynamicFlags = 0; | 160 pdcs->dwDynamicFlags = 0; |
164 pdcs->dwStaticFlags = TS_SS_NOHIDDENTEXT; | 161 pdcs->dwStaticFlags = TS_SS_NOHIDDENTEXT; |
165 return S_OK; | 162 return S_OK; |
166 } | 163 } |
167 | 164 |
168 STDMETHODIMP TSF::TSF_Text_Store::QueryInsert(LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart, LONG *pacpResultEnd) | 165 STDMETHODIMP TSF::TSF_Text_Store::QueryInsert(LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart, LONG *pacpResultEnd) |
169 { | 166 { |
170 if (acpTestStart < 0 || acpTestStart > acpTestEnd || !pacpResultStart || !pacpResultEnd) | 167 ENSURE(0 <= acpTestStart && acpTestStart <= acpTestEnd && pacpResultStart && pacpResultEnd, E_INVALIDARG); |
171 return E_INVALIDARG; | |
172 | 168 |
173 *pacpResultStart = acpTestStart; | 169 *pacpResultStart = acpTestStart; |
174 *pacpResultEnd = acpTestStart + cch; | 170 *pacpResultEnd = acpTestStart + cch; |
175 return S_OK; | 171 return S_OK; |
176 } | 172 } |
177 | 173 |
178 STDMETHODIMP TSF::TSF_Text_Store::GetSelection(ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched) | 174 STDMETHODIMP TSF::TSF_Text_Store::GetSelection(ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched) |
179 { | 175 { |
180 if (TS_LF_READ != (my_Lock & TS_LF_READ)) | 176 ENSURE(TS_LF_READ == (my_Lock && TS_LF_READ), TS_E_NOLOCK); |
181 return TS_E_NOLOCK; | 177 ENSURE(ulCount && pSelection && pcFetched, E_INVALIDARG); |
182 | 178 |
183 if (!ulCount || !pSelection || !pcFetched) | 179 *pcFetched = 0; |
180 ENSURE(TS_DEFAULT_SELECTION == ulIndex || 0 == ulIndex, TS_E_NOSELECTION); | |
181 if (my_Composition_View) | |
182 { | |
183 *pSelection = my_Composition_Selection; | |
184 } | |
185 else | |
186 { | |
187 //TODO | |
188 } | |
189 *pcFetched = 1; | |
190 return S_OK; | |
191 } | |
192 | |
193 STDMETHODIMP TSF::TSF_Text_Store::SetSelection(ULONG ulCount, const TS_SELECTION_ACP *pSelection) | |
194 { | |
195 return E_NOTIMPL; | |
196 } | |
197 | |
198 STDMETHODIMP TSF::TSF_Text_Store::GetText(LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq, ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq, ULONG *pcRunInfoRet, LONG *pacpNext) | |
199 { | |
200 ENSURE(TS_LF_READ == (my_Lock & TS_LF_READ), TS_E_NOLOCK); | |
201 ENSURE(pcchPlainRet && (pchPlain || prgRunInfo) | |
202 && (!cchPlainReq == !pchPlain) | |
203 && (!cRunInfoReq == !prgRunInfo), E_INVALIDARG); | |
204 ENSURE(0 <= acpStart && -1 <= acpEnd | |
205 && (-1 == acpEnd || acpStart <= acpEnd), TS_E_INVALIDPOS); | |
206 | |
207 *pcchPlainRet = 0; | |
208 if (pchPlain && cchPlainReq) *pchPlain = 0; | |
209 if (pcRunInfoRet) *pcRunInfoRet = 0; | |
210 //TODO | |
211 return S_OK; | |
212 } | |
213 | |
214 STDMETHODIMP TSF::TSF_Text_Store::SetText(DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText, ULONG cch, TS_TEXTCHANGE *pChange) | |
215 { | |
216 return E_NOTIMPL; | |
217 } | |
218 | |
219 STDMETHODIMP TSF::TSF_Text_Store::GetFormattedText(LONG acpStart, LONG acpEnd, IDataObject **ppDataObject) | |
220 { | |
221 //not needed | |
222 return E_NOTIMPL; | |
223 } | |
224 | |
225 STDMETHODIMP TSF::TSF_Text_Store::GetEmbedded(LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk) | |
226 { | |
227 //not needed | |
228 return E_NOTIMPL; | |
229 } | |
230 | |
231 STDMETHODIMP TSF::TSF_Text_Store::QueryInsertEmbedded(const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable) | |
232 { | |
233 if (!pfInsertable) | |
184 return E_INVALIDARG; | 234 return E_INVALIDARG; |
185 | 235 |
186 *pcFetched = 0; | 236 //Not supported |
187 if (TS_DEFAULT_SELECTION != ulIndex && 0 != ulIndex) | 237 *pfInsertable = FALSE; |
188 return TS_E_NOSELECTION; | |
189 | |
190 if (my_Composition_View) | |
191 { | |
192 *pSelection = my_Composition_Selection; | |
193 } | |
194 else | |
195 { | |
196 //TODO | |
197 } | |
198 return S_OK; | |
199 } | |
200 | |
201 STDMETHODIMP TSF::TSF_Text_Store::SetSelection(ULONG ulCount, const TS_SELECTION_ACP *pSelection) | |
202 { | |
203 return E_NOTIMPL; | |
204 } | |
205 | |
206 STDMETHODIMP TSF::TSF_Text_Store::GetText(LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq, ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq, ULONG *pcRunInfoRet, LONG *pacpNext) | |
207 { | |
208 return E_NOTIMPL; | |
209 } | |
210 | |
211 STDMETHODIMP TSF::TSF_Text_Store::SetText(DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText, ULONG cch, TS_TEXTCHANGE *pChange) | |
212 { | |
213 return E_NOTIMPL; | |
214 } | |
215 | |
216 STDMETHODIMP TSF::TSF_Text_Store::GetFormattedText(LONG acpStart, LONG acpEnd, IDataObject **ppDataObject) | |
217 { | |
218 return E_NOTIMPL; | |
219 } | |
220 | |
221 STDMETHODIMP TSF::TSF_Text_Store::GetEmbedded(LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk) | |
222 { | |
223 return E_NOTIMPL; | |
224 } | |
225 | |
226 STDMETHODIMP TSF::TSF_Text_Store::QueryInsertEmbedded(const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable) | |
227 { | |
228 return E_NOTIMPL; | 238 return E_NOTIMPL; |
229 } | 239 } |
230 | 240 |
231 STDMETHODIMP TSF::TSF_Text_Store::InsertEmbedded(DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject, TS_TEXTCHANGE *pChange) | 241 STDMETHODIMP TSF::TSF_Text_Store::InsertEmbedded(DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject, TS_TEXTCHANGE *pChange) |
232 { | 242 { |
238 return E_NOTIMPL; | 248 return E_NOTIMPL; |
239 } | 249 } |
240 | 250 |
241 STDMETHODIMP TSF::TSF_Text_Store::InsertEmbeddedAtSelection(DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd, TS_TEXTCHANGE *pChange) | 251 STDMETHODIMP TSF::TSF_Text_Store::InsertEmbeddedAtSelection(DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd, TS_TEXTCHANGE *pChange) |
242 { | 252 { |
253 //not needed | |
243 return E_NOTIMPL; | 254 return E_NOTIMPL; |
244 } | 255 } |
245 | 256 |
246 STDMETHODIMP TSF::TSF_Text_Store::RequestSupportedAttrs(DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs) | 257 STDMETHODIMP TSF::TSF_Text_Store::RequestSupportedAttrs(DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs) |
247 { | 258 { |
259 //not needed | |
248 return E_NOTIMPL; | 260 return E_NOTIMPL; |
249 } | 261 } |
250 | 262 |
251 STDMETHODIMP TSF::TSF_Text_Store::RequestAttrsAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags) | 263 STDMETHODIMP TSF::TSF_Text_Store::RequestAttrsAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags) |
252 { | 264 { |
265 //not needed | |
253 return E_NOTIMPL; | 266 return E_NOTIMPL; |
254 } | 267 } |
255 | 268 |
256 STDMETHODIMP TSF::TSF_Text_Store::RequestAttrsTransitioningAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags) | 269 STDMETHODIMP TSF::TSF_Text_Store::RequestAttrsTransitioningAtPosition(LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags) |
257 { | 270 { |
271 //not needed | |
258 return E_NOTIMPL; | 272 return E_NOTIMPL; |
259 } | 273 } |
260 | 274 |
261 STDMETHODIMP TSF::TSF_Text_Store::FindNextAttrTransition(LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset) | 275 STDMETHODIMP TSF::TSF_Text_Store::FindNextAttrTransition(LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs, DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset) |
262 { | 276 { |
277 //not needed | |
263 return E_NOTIMPL; | 278 return E_NOTIMPL; |
264 } | 279 } |
265 | 280 |
266 STDMETHODIMP TSF::TSF_Text_Store::RetrieveRequestedAttrs(ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched) | 281 STDMETHODIMP TSF::TSF_Text_Store::RetrieveRequestedAttrs(ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched) |
267 { | 282 { |
283 //not needed | |
268 return E_NOTIMPL; | 284 return E_NOTIMPL; |
269 } | 285 } |
270 | 286 |
271 STDMETHODIMP TSF::TSF_Text_Store::GetEndACP(LONG *pacp) | 287 STDMETHODIMP TSF::TSF_Text_Store::GetEndACP(LONG *pacp) |
272 { | 288 { |
298 return E_NOTIMPL; | 314 return E_NOTIMPL; |
299 } | 315 } |
300 | 316 |
301 STDMETHODIMP TSF::TSF_Text_Store::OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk) | 317 STDMETHODIMP TSF::TSF_Text_Store::OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk) |
302 { | 318 { |
303 *pfOk = FALSE; | 319 return E_NOTIMPL; |
304 return S_OK; | |
305 } | 320 } |
306 | 321 |
307 STDMETHODIMP TSF::TSF_Text_Store::OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew) | 322 STDMETHODIMP TSF::TSF_Text_Store::OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew) |
308 { | 323 { |
309 return E_NOTIMPL; | 324 return E_NOTIMPL; |