forked from sensboston/fictionbookeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptDlg.cpp
237 lines (198 loc) · 6.52 KB
/
OptDlg.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "stdafx.h"
#include "resource.h"
#include "res1.h"
#include "utils.h"
#include "apputils.h"
//#include <atlgdix.h>
#if _WIN32_WINNT>=0x0501
#include <atltheme.h>
#endif
#include "OptDlg.h"
#include "Settings.h"
extern CSettings _Settings;
static int __stdcall EnumFontProc(const ENUMLOGFONTEX *lfe,
const NEWTEXTMETRICEX *ntm,
DWORD type,
LPARAM data)
{
CSimpleArray<CString> *stringList=(CSimpleArray<CString>*)data;
stringList->Add(lfe->elfLogFont.lfFaceName);
return TRUE;
}
static int font_sizes[]={8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,36,48,72};
LRESULT COptDlg::OnInitDialog(UINT, WPARAM, LPARAM, BOOL&)
{
m_fg.SubclassWindow(GetDlgItem(IDC_FG));
m_bg.SubclassWindow(GetDlgItem(IDC_BG));
m_fonts=GetDlgItem(IDC_FONT);
m_srcfonts=GetDlgItem(IDC_SRCFONT);
m_fontsize=GetDlgItem(IDC_FONT_SIZE);
m_fast_mode = GetDlgItem(IDC_FAST_MODE);
m_lang = GetDlgItem(IDC_LANG);
// SeNS
m_usespell_check = GetDlgItem(IDC_USESPELLCHECKER);
m_highlight_check = GetDlgItem(IDC_BACKGROUNDSPELLCHECK);
m_custom_dict = GetDlgItem(IDC_CUSTOM_DICT);
// init color controls
m_bg.SetDefaultColor(::GetSysColor(COLOR_WINDOW));
m_fg.SetDefaultColor(::GetSysColor(COLOR_WINDOWTEXT));
m_bg.SetColor(_Settings.GetColorBG());
m_fg.SetColor(_Settings.GetColorFG());
wchar_t buf[MAX_LOAD_STRING + 1];
if(::LoadString(_Module.GetResourceInstance(), IDS_LANG_ENGLISH, buf, MAX_LOAD_STRING))
m_lang.AddString(buf);
if(::LoadString(_Module.GetResourceInstance(), IDS_LANG_RUSSIAN, buf, MAX_LOAD_STRING))
m_lang.AddString(buf);
if(::LoadString(_Module.GetResourceInstance(), IDS_LANG_UKRAINIAN, buf, MAX_LOAD_STRING))
m_lang.AddString(buf);
if(LANG_RUSSIAN == _Settings.GetInterfaceLanguageID())
m_lang.SetCurSel(1);
else if(LANG_UKRAINIAN == _Settings.GetInterfaceLanguageID())
m_lang.SetCurSel(2);
else
m_lang.SetCurSel(0);
// get font list
CSimpleArray<CString> installedFonts;
HDC hDC=::CreateDC(_T("DISPLAY"),NULL,NULL,NULL);
LOGFONT lf;
memset(&lf,0,sizeof(lf));
lf.lfCharSet=ANSI_CHARSET;
::EnumFontFamiliesEx(hDC,&lf,(FONTENUMPROC)&EnumFontProc,(LPARAM)&installedFonts,0);
::DeleteDC(hDC);
for (int i=0; i<installedFonts.GetSize(); i++)
{
m_fonts.AddString(installedFonts[i]);
m_srcfonts.AddString(installedFonts[i]);
}
// get body font name
CString fnt(_Settings.GetFont());
int idx=m_fonts.FindStringExact(0,fnt);
if (idx<0) idx=0;
m_fonts.SetCurSel(idx);
// get source font name
fnt.SetString(_Settings.GetSrcFont());
idx=m_srcfonts.FindStringExact(0,fnt);
if (idx<0) idx=0;
m_srcfonts.SetCurSel(idx);
// init zoom
int m_fsz_val = _Settings.GetFontSize();
CString szstr;
szstr.Format(_T("%d"),m_fsz_val);
m_fontsize.SetWindowText(szstr);
for (int i=0;i<sizeof(font_sizes)/sizeof(font_sizes[0]);++i) {
szstr.Format(_T("%d"),font_sizes[i]);
m_fontsize.AddString(szstr);
}
m_src_wrap=GetDlgItem(IDC_WRAP);
m_src_hl=GetDlgItem(IDC_SYNTAXHL);
m_src_taghl=GetDlgItem(IDC_TAGHL);
m_src_eol=GetDlgItem(IDC_SHOWEOL);
m_src_whitespace=GetDlgItem(IDC_SHOWWHITESPACE);
m_src_line_numbers=GetDlgItem(IDC_SHOWLINENUMBERS);
// init controls
m_src_wrap.SetCheck(_Settings.XmlSrcWrap());
m_src_hl.SetCheck(_Settings.XmlSrcSyntaxHL());
m_src_taghl.SetCheck(_Settings.XmlSrcTagHL());
m_src_eol.SetCheck(_Settings.XmlSrcShowEOL());
m_src_whitespace.SetCheck(_Settings.XmlSrcShowSpace());
m_src_line_numbers.SetCheck(_Settings.XMLSrcShowLineNumbers());
if(_Settings.FastMode())
m_fast_mode.SetCheck(BST_CHECKED);
else
m_fast_mode.SetCheck(BST_UNCHECKED);
// SeNS
if (_Settings.GetUseSpellChecker())
{
m_usespell_check.SetCheck(BST_CHECKED);
m_highlight_check.EnableWindow(TRUE);
}
else
{
m_usespell_check.SetCheck(BST_UNCHECKED);
m_highlight_check.EnableWindow(FALSE);
}
if(_Settings.GetHighlightMisspells())
m_highlight_check.SetCheck(BST_CHECKED);
else
m_highlight_check.SetCheck(BST_UNCHECKED);
m_custom_dict.SetWindowText (_Settings.GetCustomDict());
return 0;
}
LRESULT COptDlg::OnOK(WORD, WORD wID, HWND, BOOL&)
{
// fetch zoom
CString szstr(U::GetWindowText(m_fontsize));
if (_stscanf(szstr,_T("%d"),&m_fsz_val)!=1 ||
m_fsz_val<6 || m_fsz_val>72)
{
MessageBeep(MB_ICONERROR);
m_fontsize.SetFocus();
return 0;
}
// save colors to registry
_Settings.SetColorBG(m_bg.GetColor());
_Settings.SetColorFG(m_fg.GetColor());
// save source font face
m_face=U::GetWindowText(m_srcfonts);
_Settings.SetSrcFont(m_face);
// save body font face
m_face=U::GetWindowText(m_fonts);
_Settings.SetFont(m_face);
// save zoom
_Settings.SetFontSize(m_fsz_val);
_Settings.SetXmlSrcWrap(m_src_wrap.GetCheck() != 0);
_Settings.SetXmlSrcSyntaxHL(m_src_hl.GetCheck() != 0);
_Settings.SetXmlSrcTagHL(m_src_taghl.GetCheck() != 0);
_Settings.SetXmlSrcShowEOL(m_src_eol.GetCheck() != 0);
_Settings.SetXmlSrcShowSpace(m_src_whitespace.GetCheck() != 0);
_Settings.SetXMLSrcShowLineNumbers(m_src_line_numbers.GetCheck() != 0);
_Settings.SetFastMode(m_fast_mode.GetCheck() != 0);
_Settings.SetUseSpellChecker(m_usespell_check.GetCheck() != 0); // SeNS
_Settings.SetHighlightMisspells(m_highlight_check.GetCheck() != 0); // SeNS
CString s;
m_custom_dict.GetWindowText(s);
_Settings.SetCustomDict(s);
DWORD new_lang;
switch (m_lang.GetCurSel())
{
case 0: new_lang = LANG_ENGLISH; break;
case 1: new_lang = LANG_RUSSIAN; break;
case 2: new_lang = LANG_UKRAINIAN; break;
}
// åñëè ïîëüçîâàòåëü ñìåíèë ÿçûê èíòåðôåéñà....
if(new_lang != _Settings.GetInterfaceLanguageID())
{
// âûäàåì ïðåäóïðåæäåíèå, î òîì, ÷òî íàäî ïåðåçàïóñòèòü ïðîãðàììó.
//...
// âûñòàâëÿåì ôëàã ïåðåçàãðóçêè ïðîãðàììû.
_Settings.SetNeedRestart();
_Settings.SetInterfaceLanguage(new_lang);
}
return 0;
}
LRESULT COptDlg::OnCancel(WORD, WORD wID, HWND, BOOL&)
{
return 0;
}
TCHAR FileNameBuffer[_MAX_PATH];
LRESULT COptDlg::OnShowFileDialog(WORD, WORD, HWND, BOOL&)
{
OPENFILENAME ofn;
memset (&ofn, 0, sizeof (OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hInstance = _Module.m_hInst;
ofn.hwndOwner = m_hWnd;
ofn.lpstrDefExt = L"dic";
ofn.lpstrFilter = L"Dictionaries (*.dic)\0*.dic\0All files (*.*)\0*.*\0\0";
m_custom_dict.GetWindowText(FileNameBuffer, _MAX_PATH);
ofn.lpstrFile = FileNameBuffer;
ofn.nFilterIndex = 0;
ofn.nMaxFile = _MAX_PATH;
ofn.nMaxFileTitle = _MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY;
if (GetOpenFileName(&ofn))
{
m_custom_dict.SetWindowText(ofn.lpstrFile);
}
return 0;
}