xref: /reactos/dll/ime/msctfime/ui.h (revision 980ebf06)
1 /*
2  * PROJECT:     ReactOS msctfime.ime
3  * LICENSE:     LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4  * PURPOSE:     User Interface of msctfime.ime
5  * COPYRIGHT:   Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6  */
7 
8 #pragma once
9 
10 class CUIFGripper;
11     class CDefCompFrameGripper;
12 class CUIFToolbarButton;
13     class CCompFinalizeButton;
14 class CUIFWindow;
15     class CCompFrameWindow;
16         class CCompButtonFrameWindow;
17         class CDefCompFrameWindow;
18 
19 /***********************************************************************/
20 
21 extern UINT WM_MSIME_SERVICE;
22 extern UINT WM_MSIME_UIREADY;
23 extern UINT WM_MSIME_RECONVERTREQUEST;
24 extern UINT WM_MSIME_RECONVERT;
25 extern UINT WM_MSIME_DOCUMENTFEED;
26 extern UINT WM_MSIME_QUERYPOSITION;
27 extern UINT WM_MSIME_MODEBIAS;
28 extern UINT WM_MSIME_SHOWIMEPAD;
29 extern UINT WM_MSIME_MOUSE;
30 extern UINT WM_MSIME_KEYMAP;
31 
32 BOOL IsMsImeMessage(_In_ UINT uMsg);
33 BOOL RegisterMSIMEMessage(VOID);
34 
35 /***********************************************************************/
36 
37 class CDefCompFrameGripper : public CUIFGripper
38 {
39 public:
40     CDefCompFrameWindow *m_pDefCompFrameWindow;
41 
42     CDefCompFrameGripper(CDefCompFrameWindow *pDefCompFrameWindow, LPCRECT prc, DWORD style);
43 };
44 
45 /***********************************************************************/
46 
47 class CCompFinalizeButton : public CUIFToolbarButton
48 {
49 public:
50     CCompFrameWindow *m_pCompFrameWindow;
51 
52     CCompFinalizeButton(
53         CCompFrameWindow *pParent,
54         DWORD nObjectID,
55         LPCRECT prc,
56         DWORD style,
57         DWORD dwButtonFlags,
58         LPCWSTR pszText);
59     ~CCompFinalizeButton() override;
60 
61     STDMETHOD_(void, OnLeftClick)() override;
62 };
63 
64 /***********************************************************************/
65 
66 class CCompFrameWindow : public CUIFWindow
67 {
68 public:
69     HIMC m_hIMC;
70 
71     CCompFrameWindow(HIMC hIMC, DWORD style);
72 };
73 
74 /***********************************************************************/
75 
76 class CCompButtonFrameWindow : public CCompFrameWindow
77 {
78 public:
79     MARGINS m_Margins;
80     CCompFinalizeButton *m_pFinalizeButton;
81 
82     CCompButtonFrameWindow(HIMC hIMC, DWORD style);
83 
84     void Init();
85     void MoveShow(LONG x, LONG y, BOOL bShow);
86 
87     STDMETHOD_(void, OnCreate)(HWND hWnd) override;
88 };
89 
90 /***********************************************************************/
91 
92 class CDefCompFrameWindow : public CCompFrameWindow
93 {
94 public:
95     HWND m_hwndCompStr;
96     CDefCompFrameGripper *m_pGripper;
97     CCompFinalizeButton *m_pFinalizeButton;
98     MARGINS m_Margins;
99 
100 public:
101     CDefCompFrameWindow(HIMC hIMC, DWORD style);
102     ~CDefCompFrameWindow() override;
103 
104     void Init();
105     INT GetGripperWidth();
106     void MyScreenToClient(LPPOINT ppt, LPRECT prc);
107     void SetCompStrRect(INT nWidth, INT nHeight, BOOL bShow);
108 
109     void LoadPosition();
110     void SavePosition();
111 
112     STDMETHOD_(void, OnCreate)(HWND hWnd) override;
113     STDMETHOD_(BOOL, OnSetCursor)(UINT uMsg, LONG x, LONG y) override;
114     STDMETHOD_(LRESULT, OnWindowPosChanged)(HWND hWnd, UINT uMsg, WPARAM wParam,
115                                             LPARAM lParam) override;
116     STDMETHOD_(void, HandleMouseMsg)(UINT uMsg, LONG x, LONG y) override;
117 };
118 
119 /***********************************************************************/
120 
121 struct CPolyText
122 {
123     CicArray<POLYTEXTW> m_PolyTextArray;
124     CicArray<DWORD> m_ValueArray;
125 
126     HRESULT ShiftPolyText(INT xDelta, INT yDelta);
127     POLYTEXTW *GetPolyAt(INT iItem);
128     HRESULT RemoveLastLine(BOOL bHorizontal);
129     void RemoveAll();
130 };
131 
132 /***********************************************************************/
133 
134 struct COMPWND
135 {
136     HWND m_hWnd;
137     CPolyText m_PolyText;
138     CicCaret m_Caret;
139     DWORD m_dwUnknown57[3];
140 
141     void _ClientToScreen(LPRECT prc);
142 };
143 
144 /***********************************************************************/
145 
146 class UIComposition
147 {
148 public:
149     HWND m_hwndParent;
150     BOOL m_bHasCompWnd;
151     COMPWND m_CompStrs[4];
152     HFONT m_hFont1;
153     DWORD m_dwUnknown54;
154     HFONT m_hFont2;
155     DWORD m_dwUnknown55;
156     SIZE m_CaretSize;
157     DWORD m_dwUnknown56[2];
158     LPWSTR m_strCompStr;
159     INT m_cchCompStr;
160     BOOL m_bInComposition;
161     BOOL m_bHasCompStr;
162     CDefCompFrameWindow *m_pDefCompFrameWindow;
163     CCompButtonFrameWindow *m_pCompButtonFrameWindow;
164 
165 public:
166     UIComposition(HWND hwndParent);
167     virtual ~UIComposition();
168 
169     HRESULT CreateDefFrameWnd(HWND hwndParent, HIMC hIMC);
170     HRESULT CreateCompButtonWnd(HWND hwndParent, HIMC hIMC);
171     HRESULT CreateCompositionWindow(CicIMCLock& imcLock, HWND hwndParent);
172     HRESULT DestroyCompositionWindow();
173 
174     HRESULT UpdateShowCompWndFlag(CicIMCLock& imcLock, DWORD *pdwCompStrLen);
175     HRESULT UpdateFont(CicIMCLock& imcLock);
176     HRESULT UpdateCompositionRect(CicIMCLock& imcLock);
177     LPWSTR GetCompStrBuffer(INT cchStr);
178     INT GetLevelFromIMC(CicIMCLock& imcLock);
179 
180     void OnImeStartComposition(CicIMCLock& imcLock, HWND hUIWnd);
181     HRESULT OnImeCompositionUpdate(CicIMCLock& imcLock);
182     HRESULT OnImeEndComposition();
183     HRESULT OnImeNotifySetCompositionWindow(CicIMCLock& imcLock);
184     HRESULT OnImeSetContextAfter(CicIMCLock& imcLock);
185     void OnImeSetContext(CicIMCLock& imcLock, HWND hUIWnd, WPARAM wParam, LPARAM lParam);
186     void OnPaintTheme(WPARAM wParam);
187     void OnTimer(HWND hWnd);
188     HRESULT OnDestroy();
189 
190     static BOOL SendMessageToUI(CicIMCLock& imcLock, WPARAM wParam, LPARAM lParam);
191     static BOOL InquireImeUIWndState(CicIMCLock& imcLock);
192     static BOOL GetImeUIWndTextExtent(CicIMCLock& imcLock, LPARAM lParam);
193 
194     static LRESULT CALLBACK CompWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
195 };
196 
197 /***********************************************************************/
198 
199 struct UI
200 {
201     HWND m_hWnd;
202     UIComposition *m_pComp;
203 
204     UI(HWND hWnd);
205     virtual ~UI();
206 
207     HRESULT _Create();
208     void _Destroy();
209 
210     static void OnCreate(HWND hWnd);
211     static void OnDestroy(HWND hWnd);
212 
213     void OnImeSetContext(CicIMCLock& imcLock, WPARAM wParam, LPARAM lParam);
214 };
215 
216 /***********************************************************************/
217 
218 EXTERN_C LRESULT CALLBACK
219 UIWndProc(
220     _In_ HWND hWnd,
221     _In_ UINT uMsg,
222     _In_ WPARAM wParam,
223     _In_ LPARAM lParam);
224 
225 BOOL RegisterImeClass(VOID);
226 VOID UnregisterImeClass(VOID);
227