-
Notifications
You must be signed in to change notification settings - Fork 4
/
SettingsDlg.cpp
219 lines (192 loc) · 5.29 KB
/
SettingsDlg.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
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
// SettingsDlg.cpp : Implementation of CSettingsDlg
#include "stdafx.h"
#include "Settings.h"
#include "SettingsDlg.h"
#include "SettingsOtherDlg.h"
#include "SettingsHotkeysDlg.h"
#include "SettingsWordsDlg.h"
#include "res1.h"
extern CSettings _Settings;
// CSettingsDlg
CSettingsDlg::CSettingsDlg()
{
}
CSettingsDlg::~CSettingsDlg()
{
}
typedef BOOL (__stdcall *PFNISTHEMEACTIVE)();
typedef HRESULT (__stdcall *PFNENABLETHEMEDIALOGTEXTURE)(HWND hwnd, DWORD dwFlags);
LRESULT CSettingsDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CAxDialogImpl<CSettingsDlg>::OnInitDialog(uMsg, wParam, lParam, bHandled);
m_tab_ctrl = this->GetDlgItem(IDC_TAB_CTRL);
TC_ITEM TabItem;
TabItem.mask = TCIF_TEXT;
wchar_t buf[MAX_LOAD_STRING + 1];
if(::LoadString(_Module.GetResourceInstance(), IDS_SETTINGS_VIEW_CAPTION, buf, MAX_LOAD_STRING))
TabItem.pszText = buf;
m_tab_ctrl.InsertItem(0, &TabItem);
if(::LoadString(_Module.GetResourceInstance(), IDS_SETTINGS_OTHER_CAPTION, buf, MAX_LOAD_STRING))
TabItem.pszText = buf;
m_tab_ctrl.InsertItem(1, &TabItem);
if(::LoadString(_Module.GetResourceInstance(), IDS_SETTINGS_HOTKEYS_CAPTION, buf, MAX_LOAD_STRING))
TabItem.pszText = buf;
m_tab_ctrl.InsertItem(2, &TabItem);
if(::LoadString(_Module.GetResourceInstance(), IDS_SETTINGS_WORDS_CAPTION, buf, MAX_LOAD_STRING))
TabItem.pszText = buf;
m_tab_ctrl.InsertItem(3, &TabItem);
CRect rect;
m_tab_ctrl.GetWindowRect(rect);
m_tab_ctrl.ScreenToClient(rect);
m_tab_ctrl.AdjustRect(FALSE, rect);
COptDlg* pPage1;
pPage1 = new COptDlg;
pPage1->ShowDialog(m_tab_ctrl);
this->AddTabPage(0, pPage1, rect);
CSettingsOtherDlg* pPage2 = new CSettingsOtherDlg;
pPage2->Create(m_tab_ctrl);
this->AddTabPage(1, pPage2, rect);
CSettingsHotkeysDlg* pPage3 = new CSettingsHotkeysDlg;
pPage3->Create(m_tab_ctrl);
this->AddTabPage(2, pPage3, rect);
CSettingsWordsDlg* pPage4 = new CSettingsWordsDlg;
pPage4->Create(m_tab_ctrl);
this->AddTabPage(3, pPage4, rect);
HMODULE hThemeDll = LoadLibrary(_T("UxTheme.dll"));
if (hThemeDll != NULL)
{
PFNENABLETHEMEDIALOGTEXTURE pEnableThemeDialogTexture = (PFNENABLETHEMEDIALOGTEXTURE)GetProcAddress(hThemeDll, "EnableThemeDialogTexture");
if(pEnableThemeDialogTexture)
{
pEnableThemeDialogTexture(*pPage1, ETDT_USETABTEXTURE);
pEnableThemeDialogTexture(*pPage2, ETDT_USETABTEXTURE);
}
FreeLibrary(hThemeDll);
}
return 1;
}
LRESULT CSettingsDlg::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
if(GetFocus() == GetDlgItem(IDOK))
{
CWindow* pWnd;
TC_ITEM tci;
tci.mask = TCIF_PARAM;
int cnt = m_tab_ctrl.GetItemCount();
for (int i = cnt - 1; i >= 0; i--)
{
m_tab_ctrl.GetItem(i, &tci);
pWnd = (CWindow*)tci.lParam;
if(pWnd)
{
pWnd->SendMessage(WM_COMMAND, MAKELONG(IDOK, 0), 0);
}
}
EndDialog(wID);
}
else
{
int nTab = m_tab_ctrl.GetCurSel();
TC_ITEM tci;
tci.mask = TCIF_PARAM;
m_tab_ctrl.GetItem(nTab, &tci);
CWindow* pWnd = (CWindow*)tci.lParam;
if(pWnd)
{
pWnd->SendMessage(WM_COMMAND, MAKELONG(IDOK, 0), 0);
pWnd->ShowWindow(SW_SHOW);
}
}
return 0;
}
LRESULT CSettingsDlg::OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
int nTab = m_tab_ctrl.GetCurSel();
int lres = 1;
if(nTab != 3)
{
if(_Settings.m_initial_scripts_folder != _Settings.GetScriptsFolder())
{
_Settings.SetScriptsFolder(_Settings.m_initial_scripts_folder, true);
}
CWindow* pWnd;
TC_ITEM tci;
tci.mask = TCIF_PARAM;
int cnt = m_tab_ctrl.GetItemCount();
for (int i = cnt - 1; i >= 0; i--)
{
m_tab_ctrl.GetItem(i, &tci);
pWnd = (CWindow*)tci.lParam;
if(pWnd)
{
pWnd->SendMessage(WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
}
}
}
else
{
TC_ITEM tci;
tci.mask = TCIF_PARAM;
m_tab_ctrl.GetItem(nTab, &tci);
CWindow* pWnd = (CWindow*)tci.lParam;
if(pWnd)
{
lres = pWnd->SendMessage(WM_COMMAND, MAKELONG(IDCANCEL, 0), 0);
}
}
if(lres)
EndDialog(wID);
return 0;
}
LRESULT CSettingsDlg::OnSelchangeTab(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
int nTab = m_tab_ctrl.GetCurSel();
TC_ITEM tci;
tci.mask = TCIF_PARAM;
m_tab_ctrl.GetItem(nTab, &tci);
CWindow* pWnd = (CWindow*)tci.lParam;
if(pWnd)
pWnd->ShowWindow(SW_SHOW);
bHandled = false;
return 0;
}
LRESULT CSettingsDlg::OnSelchangingTab(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
int nTab = m_tab_ctrl.GetCurSel();
TC_ITEM tci;
tci.mask = TCIF_PARAM;
m_tab_ctrl.GetItem(nTab, &tci);
tci.lParam;
CWindow* pWnd = (CWindow*)tci.lParam;
int res = 0;
if(pWnd)
res = pWnd->ShowWindow(SW_HIDE);
bHandled = false;
return 0;
}
LRESULT CSettingsDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CWindow* pWnd;
TC_ITEM tci;
tci.mask = TCIF_PARAM;
int cnt = m_tab_ctrl.GetItemCount();
for (int i = cnt - 1; i>=0; i--)
{
m_tab_ctrl.GetItem(i, &tci);
pWnd = (CWindow*)tci.lParam;
if(pWnd)
{
pWnd->DestroyWindow();
delete (CModelessDialogImpl<CWindow>*)pWnd;
}
}
return 0;
}
void CSettingsDlg::AddTabPage(const int index, CWindow* pDialog, const CRect& rect)
{
TC_ITEM TabItem;
TabItem.mask = TCIF_PARAM;
TabItem.lParam = (LPARAM)(CWindow*)pDialog;
m_tab_ctrl.SetItem(index, &TabItem);
pDialog->MoveWindow(rect.left, rect.top, rect.Width(), rect.Height(), SWP_NOSIZE | SWP_NOZORDER);
}