-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathActiveLanguageProfileNotifySink.cpp
118 lines (96 loc) · 3.19 KB
/
ActiveLanguageProfileNotifySink.cpp
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
// 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) Microsoft Corporation. All rights reserved
#include "Private.h"
#include "Globals.h"
#include "SampleIME.h"
#include "CompositionProcessorEngine.h"
BOOL CSampleIME::VerifySampleIMECLSID(_In_ REFCLSID clsid)
{
if (IsEqualCLSID(clsid, Global::SampleIMECLSID))
{
return TRUE;
}
return FALSE;
}
//+---------------------------------------------------------------------------
//
// ITfActiveLanguageProfileNotifySink::OnActivated
//
// Sink called by the framework when changes activate language profile.
//----------------------------------------------------------------------------
STDAPI CSampleIME::OnActivated(_In_ REFCLSID clsid, _In_ REFGUID guidProfile, _In_ BOOL isActivated)
{
guidProfile;
if (FALSE == VerifySampleIMECLSID(clsid))
{
return S_OK;
}
if (isActivated)
{
_AddTextProcessorEngine();
}
if (nullptr == _pCompositionProcessorEngine)
{
return S_OK;
}
if (isActivated)
{
_pCompositionProcessorEngine->ShowAllLanguageBarIcons();
_pCompositionProcessorEngine->ConversionModeCompartmentUpdated(_pThreadMgr);
}
else
{
_DeleteCandidateList(FALSE, nullptr);
_pCompositionProcessorEngine->HideAllLanguageBarIcons();
}
return S_OK;
}
//+---------------------------------------------------------------------------
//
// _InitActiveLanguageProfileNotifySink
//
// Advise a active language profile notify sink.
//----------------------------------------------------------------------------
BOOL CSampleIME::_InitActiveLanguageProfileNotifySink()
{
ITfSource *pSource = nullptr;
BOOL ret = FALSE;
if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK)
{
return ret;
}
if (pSource->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, (ITfActiveLanguageProfileNotifySink *)this,
&_activeLanguageProfileNotifySinkCookie) != S_OK)
{
_activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE;
goto Exit;
}
ret = TRUE;
Exit:
pSource->Release();
return ret;
}
//+---------------------------------------------------------------------------
//
// _UninitActiveLanguageProfileNotifySink
//
// Unadvise a active language profile notify sink. Assumes we have advised one already.
//----------------------------------------------------------------------------
void CSampleIME::_UninitActiveLanguageProfileNotifySink()
{
ITfSource *pSource = nullptr;
if (_activeLanguageProfileNotifySinkCookie == TF_INVALID_COOKIE)
{
return; // never Advised
}
if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK)
{
pSource->UnadviseSink(_activeLanguageProfileNotifySinkCookie);
pSource->Release();
}
_activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE;
}