xref: /reactos/dll/ime/msctfime/inputcontext.h (revision efa86fff)
1 /*
2  * PROJECT:     ReactOS msctfime.ime
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     Input Context of msctfime.ime
5  * COPYRIGHT:   Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #pragma once
9 
10 #include "sinks.h"
11 #include "misc.h"
12 
13 class CInputContextOwnerCallBack;
14 class CInputContextOwner;
15 class CicInputContext;
16 
17 
18 typedef HRESULT (CALLBACK *FN_IC_OWNER_CALLBACK)(UINT uType, LPVOID args, LPVOID param);
19 
20 /***********************************************************************
21  *      CInputContextOwner
22  */
23 class CInputContextOwner
24     : public ITfContextOwner
25     , public ITfMouseTrackerACP
26 {
27 protected:
28     LONG m_cRefs;
29     IUnknown *m_pContext;
30     DWORD m_dwCookie;
31     FN_IC_OWNER_CALLBACK m_fnCallback;
32     LPVOID m_pCallbackPV;
33 
34 public:
35     CInputContextOwner(FN_IC_OWNER_CALLBACK fnCallback, LPVOID pCallbackPV);
36     virtual ~CInputContextOwner();
37 
38     HRESULT _Advise(IUnknown *pContext);
39     HRESULT _Unadvise();
40 
41     // IUnknown methods
42     STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppvObj) override;
43     STDMETHODIMP_(ULONG) AddRef() override;
44     STDMETHODIMP_(ULONG) Release() override;
45 
46     // ITfContextOwner methods
47     STDMETHODIMP GetACPFromPoint(
48         const POINT *ptScreen,
49         DWORD       dwFlags,
50         LONG        *pacp) override;
51     STDMETHODIMP GetTextExt(
52         LONG acpStart,
53         LONG acpEnd,
54         RECT *prc,
55         BOOL *pfClipped) override;
56     STDMETHODIMP GetScreenExt(RECT *prc) override;
57     STDMETHODIMP GetStatus(TF_STATUS *pdcs) override;
58     STDMETHODIMP GetWnd(HWND *phwnd) override;
59     STDMETHODIMP GetAttribute(REFGUID rguidAttribute, VARIANT *pvarValue) override;
60 
61     // ITfMouseTrackerACP methods
62     STDMETHODIMP AdviseMouseSink(
63         ITfRangeACP *range,
64         ITfMouseSink *pSink,
65         DWORD *pdwCookie) override;
66     STDMETHODIMP UnadviseMouseSink(DWORD dwCookie) override;
67 };
68 
69 /***********************************************************************
70  *      CicInputContext
71  *
72  * The msctfime.ime's input context.
73  */
74 class CicInputContext
75     : public ITfCleanupContextSink
76     , public ITfContextOwnerCompositionSink
77     , public ITfCompositionSink
78 {
79 public:
80     LONG m_cRefs;
81     HIMC m_hIMC;
82     ITfDocumentMgr *m_pDocumentMgr;
83     ITfContext *m_pContext;
84     ITfContextOwnerServices *m_pContextOwnerServices;
85     CInputContextOwnerCallBack *m_pICOwnerCallback;
86     CTextEventSink *m_pTextEventSink;
87     CCompartmentEventSink *m_pCompEventSink1;
88     CCompartmentEventSink *m_pCompEventSink2;
89     CInputContextOwner *m_pInputContextOwner;
90     DWORD m_dwUnknown3[3];
91     DWORD m_dwUnknown4[2];
92     DWORD m_dwQueryPos;
93     DWORD m_dwUnknown5;
94     CModeBias m_ModeBias;
95     DWORD m_dwUnknown6;
96     BOOL m_bCandidateOpen;
97     DWORD m_dwUnknown6_5[9];
98     BOOL m_bSelecting;
99     BOOL m_bReconverting;
100     LONG m_cCompLocks;
101     DWORD m_dwUnknown7[5];
102     WORD m_cGuidAtoms;
103     WORD m_padding;
104     DWORD m_adwGuidAtoms[256];
105     DWORD m_dwUnknown8;
106     RECT m_rcCandidate1;
107     CANDIDATEFORM m_CandForm;
108     RECT m_rcCandidate2;
109     TfClientId m_clientId;
110     DWORD m_dwUnknown9;
111 
112 public:
113     CicInputContext(
114         _In_ TfClientId cliendId,
115         _Inout_ PCIC_LIBTHREAD pLibThread,
116         _In_ HIMC hIMC);
~CicInputContext()117     virtual ~CicInputContext() { }
118 
119     // IUnknown interface
120     STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppvObj) override;
121     STDMETHODIMP_(ULONG) AddRef() override;
122     STDMETHODIMP_(ULONG) Release() override;
123 
124     // ITfCleanupContextSink interface
125     STDMETHODIMP OnCleanupContext(_In_ TfEditCookie ecWrite, _Inout_ ITfContext *pic) override;
126 
127     // ITfContextOwnerCompositionSink interface
128     STDMETHODIMP OnStartComposition(ITfCompositionView *pComposition, BOOL *pfOk) override;
129     STDMETHODIMP OnUpdateComposition(ITfCompositionView *pComposition, ITfRange *pRangeNew) override;
130     STDMETHODIMP OnEndComposition(ITfCompositionView *pComposition) override;
131 
132     // ITfCompositionSink interface
133     STDMETHODIMP OnCompositionTerminated(TfEditCookie ecWrite, ITfComposition *pComposition) override;
134 
135     HRESULT
136     GetGuidAtom(
137         _Inout_ CicIMCLock& imcLock,
138         _In_ BYTE iAtom,
139         _Out_opt_ LPDWORD pdwGuidAtom);
140 
141     HRESULT CreateInputContext(_Inout_ ITfThreadMgr *pThreadMgr, _Inout_ CicIMCLock& imcLock);
142     HRESULT DestroyInputContext();
143 
144     BOOL SetCompositionString(CicIMCLock& imcLock, ITfThreadMgr_P *pThreadMgr, DWORD dwIndex,
145                               LPCVOID lpComp, DWORD dwCompLen, LPCVOID lpRead, DWORD dwReadLen,
146                               UINT uCodePage);
147 
148     HRESULT SetupDocFeedString(CicIMCLock& imcLock, UINT uCodePage);
149     HRESULT EscbClearDocFeedBuffer(CicIMCLock& imcLock, BOOL bFlag);
150     HRESULT EscbCompComplete(CicIMCLock& imcLock);
151     HRESULT EscbCompCancel(CicIMCLock& imcLock);
152     HRESULT SetupReconvertString(
153         CicIMCLock& imcLock,
154         ITfThreadMgr_P *pThreadMgr,
155         UINT uCodePage,
156         UINT uMsg,
157         BOOL bUndo);
158     HRESULT MsImeMouseHandler(
159         DWORD dwUnknown58,
160         DWORD dwUnknown59,
161         UINT keys,
162         CicIMCLock& imcLock);
163 
164     HRESULT EndReconvertString(CicIMCLock& imcLock);
165     HRESULT DelayedReconvertFuncCall(CicIMCLock& imcLock);
166     void ClearPrevCandidatePos();
167 
168     HRESULT OnSetCandidatePos(TLS *pTLS, CicIMCLock& imcLock);
169 };
170