-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
XG_TextBoxDialog.hpp
263 lines (236 loc) · 7.27 KB
/
XG_TextBoxDialog.hpp
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#pragma once
#include "XG_Window.hpp"
#include "XG_ColorBox.hpp"
#include "XG_Settings.hpp"
#define XG_DEF_TEXTBOX_POINTSIZE 10
class XG_TextBoxDialog : public XG_Dialog
{
public:
XGStringW m_strText;
XG_ColorBox m_hwndTextColor;
XG_ColorBox m_hwndBgColor;
BOOL m_bTextColor = FALSE;
BOOL m_bBgColor = FALSE;
XGStringW m_strFontName;
int m_nFontSizeInPoints = 0;
BOOL GetTextColor() noexcept
{
if (m_bTextColor)
return m_hwndTextColor.GetColor();
else
return CLR_INVALID;
}
void SetTextColor(COLORREF rgbText, BOOL bEnable) noexcept
{
m_hwndTextColor.SetColor(rgbText);
m_bTextColor = bEnable;
}
BOOL GetBgColor() noexcept
{
if (m_bBgColor)
return m_hwndBgColor.GetColor();
else
return CLR_INVALID;
}
void SetBgColor(COLORREF rgbBg, BOOL bEnable) noexcept
{
m_hwndBgColor.SetColor(rgbBg);
m_bBgColor = bEnable;
}
XG_TextBoxDialog() noexcept
{
m_hwndTextColor.SetColor(CLR_INVALID);
m_hwndBgColor.SetColor(CLR_INVALID);
}
static int CALLBACK EnumFontsProc(
const LOGFONTW *lplf,
const TEXTMETRICW *lptm,
DWORD dwType,
LPARAM lParam) noexcept
{
if (dwType != TRUETYPE_FONTTYPE)
return TRUE;
if (lplf->lfFaceName[0] == L'@')
return TRUE;
HWND hCmb1 = reinterpret_cast<HWND>(lParam);
ComboBox_AddString(hCmb1, lplf->lfFaceName);
return TRUE;
}
BOOL OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) noexcept
{
UNREFERENCED_PARAMETER(hwndFocus);
UNREFERENCED_PARAMETER(lParam);
XgCenterDialog(hwnd);
SetDlgItemTextW(hwnd, edt1, m_strText.c_str());
m_hwndTextColor.m_hWnd = GetDlgItem(hwnd, psh1);
m_hwndBgColor.m_hWnd = GetDlgItem(hwnd, psh2);
if (m_bTextColor)
CheckDlgButton(hwnd, chx1, BST_CHECKED);
if (m_bBgColor)
CheckDlgButton(hwnd, chx2, BST_CHECKED);
HDC hDC = CreateCompatibleDC(nullptr);
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
EnumFontsW(hDC, nullptr, EnumFontsProc, reinterpret_cast<LPARAM>(hCmb1));
DeleteDC(hDC);
if (m_strFontName.size())
{
CheckDlgButton(hwnd, chx3, BST_CHECKED);
ComboBox_RealSetText(GetDlgItem(hwnd, cmb1), m_strFontName.c_str());
}
else
{
if (xg_szCellFont[0])
SetDlgItemTextW(hwnd, cmb1, xg_szCellFont);
else
SetDlgItemTextW(hwnd, cmb1, XgLoadStringDx1(IDS_MONOFONT));
EnableWindow(GetDlgItem(hwnd, cmb1), FALSE);
}
if (m_nFontSizeInPoints)
{
CheckDlgButton(hwnd, chx4, BST_CHECKED);
SetDlgItemInt(hwnd, edt2, m_nFontSizeInPoints, FALSE);
}
else
{
SetDlgItemInt(hwnd, edt2, XG_DEF_TEXTBOX_POINTSIZE, FALSE);
EnableWindow(GetDlgItem(hwnd, edt2), FALSE);
}
SendDlgItemMessageW(hwnd, scr1, UDM_SETRANGE, 0, MAKELPARAM(64, 8));
return TRUE;
}
BOOL OnOK(HWND hwnd)
{
HWND hEdt1 = GetDlgItem(hwnd, edt1);
WCHAR szText[MAX_PATH] = L"";
GetWindowText(hEdt1, szText, _countof(szText));
m_strText = szText;
xg_str_trim_right(m_strText);
m_bTextColor = (IsDlgButtonChecked(hwnd, chx1) == BST_CHECKED);
m_bBgColor = (IsDlgButtonChecked(hwnd, chx2) == BST_CHECKED);
if (IsDlgButtonChecked(hwnd, chx3) == BST_CHECKED)
{
HWND hCmb1 = GetDlgItem(hwnd, cmb1);
ComboBox_RealGetText(hCmb1, szText, _countof(szText));
m_strFontName = szText;
xg_str_trim(m_strFontName);
}
else
{
m_strFontName.clear();
}
if (IsDlgButtonChecked(hwnd, chx4) == BST_CHECKED)
{
m_nFontSizeInPoints = GetDlgItemInt(hwnd, edt2, nullptr, FALSE);
}
else
{
m_nFontSizeInPoints = 0;
}
return TRUE;
}
void OnSetFont(HWND hwnd)
{
LOGFONTW lf;
ZeroMemory(&lf, sizeof(lf));
lf.lfHeight = 12;
StringCchCopyW(lf.lfFaceName, _countof(lf.lfFaceName), m_strFontName.c_str());
CHOOSEFONTW cf = { sizeof(cf), hwnd };
cf.lpLogFont = &lf;
cf.Flags = CF_TTONLY | CF_INITTOLOGFONTSTRUCT | CF_NOSIZESEL | CF_NOSTYLESEL |
CF_NOSCRIPTSEL | CF_SCALABLEONLY | CF_NOVERTFONTS;
if (ChooseFontW(&cf)) {
CheckDlgButton(hwnd, chx3, BST_CHECKED);
EnableWindow(GetDlgItem(hwnd, cmb1), TRUE);
ComboBox_RealSetText(GetDlgItem(hwnd, cmb1), lf.lfFaceName);
}
}
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case IDOK:
if (OnOK(hwnd)) {
// ダイアログを終了。
::EndDialog(hwnd, id);
}
break;
case IDCANCEL:
// ダイアログを終了。
::EndDialog(hwnd, id);
break;
case psh1:
m_hwndTextColor.DoChooseColor();
CheckDlgButton(hwnd, chx1, BST_CHECKED);
break;
case psh2:
m_hwndBgColor.DoChooseColor();
CheckDlgButton(hwnd, chx2, BST_CHECKED);
break;
case psh3:
OnSetFont(hwnd);
break;
case chx1:
if (IsDlgButtonChecked(hwnd, chx1) != BST_CHECKED)
{
m_hwndTextColor.SetColor(xg_rgbBlackCellColor);
}
break;
case chx2:
if (IsDlgButtonChecked(hwnd, chx2) != BST_CHECKED)
{
m_hwndBgColor.SetColor(xg_rgbWhiteCellColor);
}
break;
case chx3:
if (IsDlgButtonChecked(hwnd, chx3) == BST_CHECKED)
{
EnableWindow(GetDlgItem(hwnd, cmb1), TRUE);
}
else
{
EnableWindow(GetDlgItem(hwnd, cmb1), FALSE);
}
break;
case chx4:
if (IsDlgButtonChecked(hwnd, chx4) == BST_CHECKED)
{
EnableWindow(GetDlgItem(hwnd, edt2), TRUE);
}
else
{
EnableWindow(GetDlgItem(hwnd, edt2), FALSE);
}
break;
default:
break;
}
}
void OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem) noexcept
{
if (lpDrawItem->hwndItem == m_hwndTextColor) {
m_hwndTextColor.OnOwnerDrawItem(lpDrawItem);
return;
}
if (lpDrawItem->hwndItem == m_hwndBgColor) {
m_hwndBgColor.OnOwnerDrawItem(lpDrawItem);
return;
}
}
INT_PTR CALLBACK
DialogProcDx(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override
{
switch (uMsg)
{
HANDLE_MSG(hwnd, WM_INITDIALOG, OnInitDialog);
HANDLE_MSG(hwnd, WM_COMMAND, OnCommand);
HANDLE_MSG(hwnd, WM_DRAWITEM, OnDrawItem);
default:
break;
}
return 0;
}
INT_PTR DoModal(HWND hwnd)
{
return DialogBoxDx(hwnd, IDD_TEXTBOX);
}
};