xref: /reactos/dll/ime/msctfime/sinks.h (revision b2ec7867)
1 /*
2  * PROJECT:     ReactOS msctfime.ime
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     The sinks of msctfime.ime
5  * COPYRIGHT:   Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #pragma once
9 
10 /***********************************************************************/
11 
12 typedef struct CESMAP
13 {
14     ITfCompartment *m_pComp;
15     DWORD m_dwCookie;
16 } CESMAP, *PCESMAP;
17 
18 typedef INT (CALLBACK *FN_EVENTSINK)(LPVOID, REFGUID);
19 
20 class CCompartmentEventSink : public ITfCompartmentEventSink
21 {
22     CicArray<CESMAP> m_array;
23     LONG m_cRefs;
24     FN_EVENTSINK m_fnEventSink;
25     LPVOID m_pUserData;
26 
27 public:
28     CCompartmentEventSink(FN_EVENTSINK fnEventSink, LPVOID pUserData);
29     virtual ~CCompartmentEventSink();
30 
31     HRESULT _Advise(IUnknown *pUnknown, REFGUID rguid, BOOL bThread);
32     HRESULT _Unadvise();
33 
34     // IUnknown interface
35     STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppvObj) override;
36     STDMETHODIMP_(ULONG) AddRef() override;
37     STDMETHODIMP_(ULONG) Release() override;
38 
39     // ITfCompartmentEventSink interface
40     STDMETHODIMP OnChange(REFGUID rguid) override;
41 };
42 
43 /***********************************************************************/
44 
45 typedef INT (CALLBACK *FN_ENDEDIT)(INT, LPVOID, LPVOID);
46 typedef INT (CALLBACK *FN_LAYOUTCHANGE)(UINT nType, FN_ENDEDIT fnEndEdit, ITfContextView *pView);
47 
48 class CTextEventSink : public ITfTextEditSink, ITfTextLayoutSink
49 {
50 protected:
51     LONG m_cRefs;
52     IUnknown *m_pUnknown;
53     DWORD m_dwEditSinkCookie;
54     DWORD m_dwLayoutSinkCookie;
55     union
56     {
57         UINT m_uFlags;
58         FN_LAYOUTCHANGE m_fnLayoutChange;
59     };
60     FN_ENDEDIT m_fnEndEdit;
61     LPVOID m_pCallbackPV;
62 
63 public:
64     CTextEventSink(FN_ENDEDIT fnEndEdit, LPVOID pCallbackPV);
65     virtual ~CTextEventSink();
66 
67     HRESULT _Advise(IUnknown *pUnknown, UINT uFlags);
68     HRESULT _Unadvise();
69 
70     // IUnknown interface
71     STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppvObj) override;
72     STDMETHODIMP_(ULONG) AddRef() override;
73     STDMETHODIMP_(ULONG) Release() override;
74 
75     // ITfTextEditSink interface
76     STDMETHODIMP OnEndEdit(
77         ITfContext *pic,
78         TfEditCookie ecReadOnly,
79         ITfEditRecord *pEditRecord) override;
80 
81     // ITfTextLayoutSink interface
82     STDMETHODIMP
83     OnLayoutChange(
84         ITfContext *pContext,
85         TfLayoutCode lcode,
86         ITfContextView *pContextView) override;
87 };
88 
89 /***********************************************************************/
90 
91 typedef INT (CALLBACK *FN_INITDOCMGR)(UINT, ITfDocumentMgr *, ITfDocumentMgr *, LPVOID);
92 typedef INT (CALLBACK *FN_PUSHPOP)(UINT, ITfContext *, LPVOID);
93 
94 class CThreadMgrEventSink : public ITfThreadMgrEventSink
95 {
96 protected:
97     ITfThreadMgr *m_pThreadMgr;
98     DWORD m_dwCookie;
99     FN_INITDOCMGR m_fnInit;
100     FN_PUSHPOP m_fnPushPop;
101     DWORD m_dw;
102     LPVOID m_pCallbackPV;
103     LONG m_cRefs;
104 
105 public:
106     CThreadMgrEventSink(
107         _In_ FN_INITDOCMGR fnInit,
108         _In_ FN_PUSHPOP fnPushPop = NULL,
109         _Inout_ LPVOID pvCallbackPV = NULL);
~CThreadMgrEventSink()110     virtual ~CThreadMgrEventSink() { }
111 
112     void SetCallbackPV(_Inout_ LPVOID pv);
113     HRESULT _Advise(ITfThreadMgr *pThreadMgr);
114     HRESULT _Unadvise();
115 
116     // IUnknown interface
117     STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppvObj) override;
118     STDMETHODIMP_(ULONG) AddRef() override;
119     STDMETHODIMP_(ULONG) Release() override;
120 
121     // ITfThreadMgrEventSink interface
122     STDMETHODIMP OnInitDocumentMgr(ITfDocumentMgr *pdim) override;
123     STDMETHODIMP OnUninitDocumentMgr(ITfDocumentMgr *pdim) override;
124     STDMETHODIMP OnSetFocus(ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus) override;
125     STDMETHODIMP OnPushContext(ITfContext *pic) override;
126     STDMETHODIMP OnPopContext(ITfContext *pic) override;
127 
128     static INT CALLBACK DIMCallback(
129         UINT nCode,
130         ITfDocumentMgr *pDocMgr1,
131         ITfDocumentMgr *pDocMgr2,
132         LPVOID pUserData);
133 };
134 
135 /***********************************************************************/
136 
137 class CActiveLanguageProfileNotifySink : public ITfActiveLanguageProfileNotifySink
138 {
139 protected:
140     typedef INT (CALLBACK *FN_COMPARE)(REFGUID rguid1, REFGUID rguid2, BOOL fActivated,
141                                        LPVOID pUserData);
142     LONG m_cRefs;
143     ITfThreadMgr *m_pThreadMgr;
144     DWORD m_dwConnection;
145     FN_COMPARE m_fnCompare;
146     LPVOID m_pUserData;
147 
148 public:
149     CActiveLanguageProfileNotifySink(_In_ FN_COMPARE fnCompare, _Inout_opt_ void *pUserData);
150     virtual ~CActiveLanguageProfileNotifySink();
151 
152     HRESULT _Advise(ITfThreadMgr *pThreadMgr);
153     HRESULT _Unadvise();
154 
155     // IUnknown interface
156     STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppvObj) override;
157     STDMETHODIMP_(ULONG) AddRef() override;
158     STDMETHODIMP_(ULONG) Release() override;
159 
160     // ITfActiveLanguageProfileNotifySink interface
161     STDMETHODIMP
162     OnActivated(
163         REFCLSID clsid,
164         REFGUID guidProfile,
165         BOOL fActivated) override;
166 };
167