-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayAttribute.cpp
More file actions
116 lines (93 loc) · 3.75 KB
/
DisplayAttribute.cpp
File metadata and controls
116 lines (93 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//////////////////////////////////////////////////////////////////////
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (C) 2003 Microsoft Corporation. All rights reserved.
//
// DisplayAttribure.cpp
//
// apply the display attribute to the composition range.
//
//////////////////////////////////////////////////////////////////////
#include "globals.h"
#include "TextService.h"
//+---------------------------------------------------------------------------
//
// _ClearCompositionDisplayAttributes
//
//----------------------------------------------------------------------------
void CTextService::_ClearCompositionDisplayAttributes(TfEditCookie ec, ITfContext *pContext)
{
ITfRange *pRangeComposition;
ITfProperty *pDisplayAttributeProperty;
// get the compositon range.
if (_pComposition->GetRange(&pRangeComposition) != S_OK)
return;
// get our the display attribute property
if (pContext->GetProperty(GUID_PROP_ATTRIBUTE, &pDisplayAttributeProperty) == S_OK)
{
// clear the value over the range
pDisplayAttributeProperty->Clear(ec, pRangeComposition);
pDisplayAttributeProperty->Release();
}
pRangeComposition->Release();
}
//+---------------------------------------------------------------------------
//
// _SetCompositionDisplayAttributes
//
//----------------------------------------------------------------------------
BOOL CTextService::_SetCompositionDisplayAttributes(TfEditCookie ec, ITfContext *pContext, TfGuidAtom gaDisplayAttribute)
{
ITfRange *pRangeComposition;
ITfProperty *pDisplayAttributeProperty;
HRESULT hr;
// we need a range and the context it lives in
if (_pComposition->GetRange(&pRangeComposition) != S_OK)
return FALSE;
hr = E_FAIL;
// get our the display attribute property
if (pContext->GetProperty(GUID_PROP_ATTRIBUTE, &pDisplayAttributeProperty) == S_OK)
{
VARIANT var;
// set the value over the range
// the application will use this guid atom to lookup the acutal rendering information
var.vt = VT_I4; // we're going to set a TfGuidAtom
var.lVal = gaDisplayAttribute;
hr = pDisplayAttributeProperty->SetValue(ec, pRangeComposition, &var);
pDisplayAttributeProperty->Release();
}
pRangeComposition->Release();
return (hr == S_OK);
}
//+---------------------------------------------------------------------------
//
// _InitDisplayAttributeGuidAtom
//
// Because it's expensive to map our display attribute GUID to a TSF
// TfGuidAtom, we do it once when Activate is called.
//----------------------------------------------------------------------------
BOOL CTextService::_InitDisplayAttributeGuidAtom()
{
ITfCategoryMgr *pCategoryMgr;
HRESULT hr;
if (CoCreateInstance(CLSID_TF_CategoryMgr,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITfCategoryMgr,
(void**)&pCategoryMgr) != S_OK)
{
return FALSE;
}
// register the display attribute for input text.
hr = pCategoryMgr->RegisterGUID(c_guidDisplayAttributeInput, &_gaDisplayAttributeInput);
// register the display attribute for the converted text.
hr = pCategoryMgr->RegisterGUID(c_guidDisplayAttributeConverted, &_gaDisplayAttributeConverted);
// register the display attribute for the focused converted text.
hr = pCategoryMgr->RegisterGUID(c_guidDisplayAttributeFocusedConverted, &_gaDisplayAttributeFocusedConverted);
pCategoryMgr->Release();
return (hr == S_OK);
}