-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompartment.cpp
More file actions
163 lines (141 loc) · 4.6 KB
/
Compartment.cpp
File metadata and controls
163 lines (141 loc) · 4.6 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//////////////////////////////////////////////////////////////////////
//
// 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.
//
// Compartment.cpp
//
// The status of GUID_COMPARTMENT_KEYBOARD_OPENCLOSE and
// GUID_COMPARTMENT_KEYBOARD_DISABLED.
//
//////////////////////////////////////////////////////////////////////
#include "Globals.h"
#include "TextService.h"
//+---------------------------------------------------------------------------
//
// _IsKeyboardDisabled
//
// GUID_COMPARTMENT_KEYBOARD_DISABLED is the compartment in the context
// object.
//
//----------------------------------------------------------------------------
BOOL CTextService::_IsKeyboardDisabled()
{
ITfCompartmentMgr *pCompMgr = NULL;
ITfDocumentMgr *pDocMgrFocus = NULL;
ITfContext *pContext = NULL;
BOOL fDisabled = FALSE;
if ((_pThreadMgr->GetFocus(&pDocMgrFocus) != S_OK) ||
(pDocMgrFocus == NULL))
{
// if there is no focus document manager object, the keyboard
// is disabled.
fDisabled = TRUE;
goto Exit;
}
if ((pDocMgrFocus->GetTop(&pContext) != S_OK) ||
(pContext == NULL))
{
// if there is no context object, the keyboard is disabled.
fDisabled = TRUE;
goto Exit;
}
if (pContext->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr) == S_OK)
{
ITfCompartment *pCompartmentDisabled;
ITfCompartment *pCompartmentEmptyContext;
// Check GUID_COMPARTMENT_KEYBOARD_DISABLED.
if (pCompMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_DISABLED, &pCompartmentDisabled) == S_OK)
{
VARIANT var;
if (S_OK == pCompartmentDisabled->GetValue(&var))
{
if (var.vt == VT_I4) // Even VT_EMPTY, GetValue() can succeed
{
fDisabled = (BOOL)var.lVal;
}
}
pCompartmentDisabled->Release();
}
// Check GUID_COMPARTMENT_EMPTYCONTEXT.
if (pCompMgr->GetCompartment(GUID_COMPARTMENT_EMPTYCONTEXT, &pCompartmentEmptyContext) == S_OK)
{
VARIANT var;
if (S_OK == pCompartmentEmptyContext->GetValue(&var))
{
if (var.vt == VT_I4) // Even VT_EMPTY, GetValue() can succeed
{
fDisabled = (BOOL)var.lVal;
}
}
pCompartmentEmptyContext->Release();
}
pCompMgr->Release();
}
Exit:
if (pContext)
pContext->Release();
if (pDocMgrFocus)
pDocMgrFocus->Release();
return fDisabled;
}
//+---------------------------------------------------------------------------
//
// _IsKeyboardOpen
//
// GUID_COMPARTMENT_KEYBOARD_OPENCLOSE is the compartment in the thread manager
// object.
//
//----------------------------------------------------------------------------
BOOL CTextService::_IsKeyboardOpen()
{
ITfCompartmentMgr *pCompMgr = NULL;
BOOL fOpen = FALSE;
if (_pThreadMgr->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr) == S_OK)
{
ITfCompartment *pCompartment;
if (pCompMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, &pCompartment) == S_OK)
{
VARIANT var;
if (S_OK == pCompartment->GetValue(&var))
{
if (var.vt == VT_I4) // Even VT_EMPTY, GetValue() can succeed
{
fOpen = (BOOL)var.lVal;
}
}
}
pCompMgr->Release();
}
return fOpen;
}
//+---------------------------------------------------------------------------
//
// _SetKeyboardOpen
//
// GUID_COMPARTMENT_KEYBOARD_OPENCLOSE is the compartment in the thread manager
// object.
//
//----------------------------------------------------------------------------
HRESULT CTextService::_SetKeyboardOpen(BOOL fOpen)
{
HRESULT hr = E_FAIL;
ITfCompartmentMgr *pCompMgr = NULL;
if (_pThreadMgr->QueryInterface(IID_ITfCompartmentMgr, (void **)&pCompMgr) == S_OK)
{
ITfCompartment *pCompartment;
if (pCompMgr->GetCompartment(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, &pCompartment) == S_OK)
{
VARIANT var;
var.vt = VT_I4;
var.lVal = fOpen;
hr = pCompartment->SetValue(_tfClientId, &var);
}
pCompMgr->Release();
}
return hr;
}