-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathConfigDialog.cpp
More file actions
368 lines (324 loc) · 14.8 KB
/
Copy pathConfigDialog.cpp
File metadata and controls
368 lines (324 loc) · 14.8 KB
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
/* -------------------------------------
This file is part of AnalysePlugin for NotePad++
Copyright (c) 2022 Matthias H. mattesh(at)gmx.net
partly copied from the NotePad++ project from
Don HO don.h(at)free.fr
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------- */
//#include "stdafx.h"
#include "menuCmdID.h"
#include "ConfigDialog.h"
#include "PluginInterface.h"
#include "resource.h"
#include <windows.h>
#include "tclPattern.h"
#define MDBG_COMP "CfgDlg:"
#include "myDebug.h"
#define FONTSIZELIST_COUNT 11
const TCHAR * FONTSIZELIST[] = { TEXT("6"), TEXT("7"), TEXT("8"), TEXT("9"), TEXT("10"), TEXT("11"), TEXT("12"), TEXT("14"), TEXT("16"), TEXT("18"), TEXT("20") };
#define LISTLENGTHVALS_COUNT 2
const TCHAR * LISTLENGTHVALS[] = {TEXT("4"), TEXT("10")};
using namespace std;
void ConfigDialog::init(HINSTANCE hInst, NppData nppData)
{
_nppData = nppData;
Window::init(hInst, nppData._nppHandle);
_addCtxDlg.init(hInst, nppData);
setFontList(nppData._nppHandle);
}
void ConfigDialog::setFontList(HWND hWnd)
{
//---------------//
// Sys font list //
//---------------//
LOGFONT lf;
mlsFontList.clear();
lf.lfCharSet = DEFAULT_CHARSET;
lf.lfFaceName[0]='\0';
lf.lfPitchAndFamily = 0;
HDC hDC = ::GetDC(hWnd);
::EnumFontFamiliesEx(hDC,
&lf,
(FONTENUMPROC) EnumFontFamExProc,
(LPARAM) &mlsFontList, 0);
}
int ConfigDialog::EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, NEWTEXTMETRICEX *, int, LPARAM lParam) {
tlsString* pStringSet = reinterpret_cast<tlsString*>(lParam);
//We can add the font
//Add the face name and not the full name, we do not care about any styles
TCHAR* pName = (TCHAR*)lpelfe->elfLogFont.lfFaceName;
generic_string str(pName);
pStringSet->insert(str);
return 1; // I want to get all fonts
};
void ConfigDialog::doDialog(int FuncCmdId)
{
if (!isCreated()) {
create(IDD_ANALYSE_CONF_DLG);
mCmbOnEnterAction.init(::GetDlgItem(_hSelf, IDC_CMB_ONENTERACT));
mCmbSearchType.init(::GetDlgItem(_hSelf, IDC_CMB_SEARCH_TYPE));
// mCmbSearchText.init(::GetDlgItem(_hSelf, IDC_CMB_SEARCH_TEXT));
mCmbSelType.init(::GetDlgItem(_hSelf, IDC_CMB_SELECTION));
#ifdef RESULT_COLORING
//mCmbColor.init(::GetDlgItem(_hSelf, IDC_CMB_COLOR));
#endif
mCmbFontName.init(::GetDlgItem(_hSelf, IDC_CMB_FONTNAME));
mCmbFontSize.init(::GetDlgItem(_hSelf, IDC_CMB_FONTSIZE));
mCmbNumOfCfgFiles.init(::GetDlgItem(_hSelf, IDC_CMB_NUMOFCFGFILES));
// now set defaults
mCmbOnEnterAction.addInitialText2Combo(max_onEnterAction, transOnEnterAction, false);
mCmbSearchType.addInitialText2Combo(mDefPat.getDefSearchTypeListSize(), mDefPat.getDefSearchTypeList(), false);
mCmbSelType.addInitialText2Combo(mDefPat.getDefSelTypeListSize(), mDefPat.getDefSelTypeList(), false);
mCmbFontName.addInitialText2Combo(mlsFontList, false);
mCmbFontSize.addInitialText2Combo(FONTSIZELIST_COUNT, FONTSIZELIST, false);
mCmbNumOfCfgFiles.addInitialText2Combo(LISTLENGTHVALS_COUNT, LISTLENGTHVALS, false);
::SendDlgItemMessage(_hSelf, IDC_CHK_USEBOOKMARK, BM_SETCHECK, getUseBookmark()?BST_CHECKED:BST_UNCHECKED, 0);
// now get the stuff from configuration in the dialog
::SendDlgItemMessage(_hSelf, IDC_CHK_AUTOUPDT, BM_SETCHECK, getOnAutoUpdate()?BST_CHECKED:BST_UNCHECKED, 0);
mCmbOnEnterAction.addText2Combo(getOnEnterActionStr().c_str(), false, false, false);
mCmbSearchType.addText2Combo(mDefPat.getSearchTypeStr().c_str(), false, false, false);
mCmbSelType.addText2Combo(mDefPat.getSelectionTypeStr().c_str(), false, false, false);
// mCmbSearchText.addText2Combo(mDefPat.getSearchText().c_str(), false, false, false);
::SendDlgItemMessage(_hSelf, IDC_CHK_DO_SEARCH, BM_SETCHECK, mDefPat.getDoSearch()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_HIDE, BM_SETCHECK, mDefPat.getIsHideText()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_WHOLE_WORD, BM_SETCHECK, mDefPat.getIsWholeWord()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_MATCH_CASE, BM_SETCHECK, mDefPat.getIsMatchCase()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_DISPLINENO, BM_SETCHECK, getDisplayLineNo()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_SYNCSCROLL, BM_SETCHECK, getIsSyncScroll() ? BST_CHECKED : BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_JUMP2EDIT, BM_SETCHECK, getDblClickJumps2EditView() ? BST_CHECKED : BST_UNCHECKED, 0);
#ifdef RESULT_COLORING
// mCmbColor.addText2Combo(mDefPat.getColorStr().c_str(), false, false, false);
_pFgColour = new ColourPicker2;
_pBgColour = new ColourPicker2;
_pFgColour->init(_hInst, _hSelf);
_pBgColour->init(_hInst, _hSelf);
_pFgColour->setColour(mDefPat.getColorNum());
_pBgColour->setColour(mDefPat.getBgColorNum());
_pFgColour->setCustomColors(_pParent->refCustomColors());
_pBgColour->setCustomColors(_pParent->refCustomColors());
POINT p1, p2;
alignWith(::GetDlgItem(_hSelf, IDC_STATIC_COL_FG2), _pFgColour->getHSelf(), PosAlign::right, p1);
alignWith(::GetDlgItem(_hSelf, IDC_STATIC_COL_BG2), _pBgColour->getHSelf(), PosAlign::right, p2);
p1.y += 1;
p2.y += 1;
::MoveWindow((HWND)_pFgColour->getHSelf(), p1.x, p1.y, 12, 12, TRUE);
::MoveWindow((HWND)_pBgColour->getHSelf(), p2.x, p2.y, 12, 12, TRUE);
_pFgColour->display();
_pBgColour->display();
#endif
const generic_string& s = _pParent->getResultFontName();
if (!s.empty()) {
mCmbFontName.addText2Combo(s.c_str(), false, false, false);
}
TCHAR tmp[10];
generic_itoa(_pParent->getResultFontSize(),tmp, 10);
mCmbFontSize.addText2Combo(tmp, false, false, false);
generic_itoa(mNumOfCfgFiles,tmp, 10);
mCmbNumOfCfgFiles.addText2Combo(tmp, false, false, false);
DBG1("ConfigDialog::dDialog() %s ", mCmbNumOfCfgFiles.getComboTextList(false).c_str());
} // isCreated()
::SendDlgItemMessage(_hSelf, IDC_CHK_RESWORDWRAP, BM_SETCHECK, _pParent->getResultWrapMode() ? BST_CHECKED : BST_UNCHECKED, 0);
::EnableWindow(_pFgColour->getHSelf(), true);
::EnableWindow(_pBgColour->getHSelf(), true);
mbOkPressed = false;
_cmdId = FuncCmdId;
// position dialog to the center of the screen
goToCenter();
}
const TCHAR* ConfigDialog::transOnEnterAction[max_onEnterAction] = {
TEXT("just search"),
TEXT("update line"),
TEXT("add line")
};
generic_string ConfigDialog::getOnEnterActionStr() const {
return generic_string(transOnEnterAction[mOnEnterAction]);
}
void ConfigDialog::setOnEnterActionStr(const generic_string& action) {
for(int i=0; i<max_onEnterAction;i++) {
if(action == transOnEnterAction[i]) {
mOnEnterAction =(teOnEnterAction)i;
break;
}
}
}
bool ConfigDialog::getDialogData(tclPattern& p) const{
if (mbOkPressed) {
p = mDefPat;
return true;
}else{
return false;
}
}
void ConfigDialog::setFontText(const generic_string& str) {
mResultFontName = str;
}
const generic_string& ConfigDialog::getFontText() const {
return mResultFontName;
}
void ConfigDialog::setFontSize(unsigned s) {
if(s) {
mResultFontSize = s;
} else {
DBG0("setFontSize() called with size 0 set it to 8");
mResultFontSize = 8;
}
}
void ConfigDialog::setFontSizeStr(const generic_string& s) {
setFontSize(generic_atoi(s.c_str()));
}
unsigned ConfigDialog::getFontSize() const {
return mResultFontSize;
}
generic_string ConfigDialog::getFontSizeStr() const {
TCHAR cp[10];
generic_itoa(mResultFontSize, cp, 10);
return generic_string(cp);
}
const generic_string ConfigDialog::getNumOfCfgFilesStr() const {
TCHAR cp[10];
generic_itoa(mNumOfCfgFiles, cp, 10);
return generic_string(cp);
}
void ConfigDialog::setNumOfCfgFilesStr(const generic_string& str) {
mNumOfCfgFiles = generic_atoi(str.c_str());
}
void ConfigDialog::setDefaultPattern(const tclPattern& p) {
mDefPat = p;
mIsConfigured = true;
}
void ConfigDialog::setDialogData(const tclPattern& p) {
// store for returning
mDefPat = p;
// set to default values
mCmbSearchType.addText2Combo(p.getSearchTypeStr().c_str(), false, false, false);
mCmbSelType.addText2Combo(p.getSelectionTypeStr().c_str(), false, false, false);
::SendDlgItemMessage(_hSelf, IDC_CHK_DO_SEARCH, BM_SETCHECK, p.getDoSearch()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_HIDE, BM_SETCHECK, p.getIsHideText()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_WHOLE_WORD, BM_SETCHECK, p.getIsWholeWord()?BST_CHECKED:BST_UNCHECKED, 0);
::SendDlgItemMessage(_hSelf, IDC_CHK_MATCH_CASE, BM_SETCHECK, p.getIsMatchCase()?BST_CHECKED:BST_UNCHECKED, 0);
#ifdef RESULT_COLORING
//mCmbColor.addText2Combo(p.getColorStr().c_str(), false, false, false);
_pFgColour->setColour(p.getColorNum());
_pBgColour->setColour(p.getBgColorNum());
#endif
}
INT_PTR CALLBACK ConfigDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM /*lParam*/)
{
switch (Message)
{
case WM_INITDIALOG :
{
// ::SendDlgItemMessage(_hSelf, IDC_EMAIL_LINK, WM_SETTEXT, 0, (LPARAM)EMAIL_LINK);
return TRUE;
}
case WM_CLOSE :
{
::SendMessage(_hParent, NPPM_SETMENUITEMCHECK, (WPARAM)_cmdId, (LPARAM)false);
break;
}
case WM_COMMAND :
{
switch (wParam)
{
case IDOK :
{
::SendMessage(_hParent, NPPM_SETMENUITEMCHECK, (WPARAM)_cmdId, (LPARAM)false);
display(FALSE);
setOnAutoUpdate((BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_AUTOUPDT, BM_GETCHECK, 0, 0))?1:0);
setUseBookmark((BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_USEBOOKMARK, BM_GETCHECK, 0, 0))?1:0);
setDisplayLineNo((BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_DISPLINENO, BM_GETCHECK, 0, 0)));
setOnEnterActionStr(mCmbOnEnterAction.getTextFromCombo(false));
setFontText(mCmbFontName.getTextFromCombo(false));
setFontSizeStr(mCmbFontSize.getTextFromCombo(false));
setNumOfCfgFilesStr(mCmbNumOfCfgFiles.getTextFromCombo(false));
mDefPat.setSearchTypeStr(mCmbSearchType.getTextFromCombo(false));
mDefPat.setSelectionTypeStr(mCmbSelType.getTextFromCombo(false));
mDefPat.setDoSearch(BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_DO_SEARCH, BM_GETCHECK, 0, 0));
mDefPat.setWholeWord(BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_WHOLE_WORD, BM_GETCHECK, 0, 0));
mDefPat.setMatchCase(BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_MATCH_CASE, BM_GETCHECK, 0, 0));
mDefPat.setHideText(BST_CHECKED==::SendDlgItemMessage(_hSelf, IDC_CHK_HIDE, BM_GETCHECK, 0, 0));
#ifdef RESULT_COLORING
// mDefPat.setColorStr(mCmbColor.getTextFromCombo(false));
mDefPat.setColor(mDefPat.convColorNum2Enum(_pFgColour->getColour()));
mDefPat.setBgColor(mDefPat.convColorNum2Enum(_pBgColour->getColour()));
#endif
setIsSyncScroll(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHK_SYNCSCROLL, BM_GETCHECK, 0, 0));
setDblClickJumps2EditView(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHK_JUMP2EDIT, BM_GETCHECK, 0, 0));
mbOkPressed = true;
// inform find dialog that user has pressed ok; findDilog then descides if
// new default data needs to be copied into the find dialog
if(_pFindDlg) {
WPARAM uNumOfCfgFiles = generic_atoi(getNumOfCfgFilesStr().c_str());
::SendMessage(_pFindDlg->getHSelf(), IDC_DO_CHECK_CONF, (WPARAM)uNumOfCfgFiles, (LPARAM)&mDefPat);
}
if(_pResultDlg) {
::SendMessage(_pResultDlg->getHSelf(), IDC_DO_CHECK_CONF, (WPARAM)0, (LPARAM)&mDefPat);
}
_pParent->setResultWrapMode(BST_CHECKED == ::SendDlgItemMessage(_hSelf, IDC_CHK_RESWORDWRAP, BM_GETCHECK, 0, 0));
return TRUE;
}
case IDCANCEL :
{
::SendMessage(_hParent, NPPM_SETMENUITEMCHECK, (WPARAM)_cmdId, (LPARAM)false);
display(FALSE);
mbOkPressed = false;
return TRUE;
}
case IDC_BTN_ADDCONTEXT:
{
::PostMessage(getHSelf(), WM_CLOSE, 0, (LPARAM)0);
::SendMessage(_hParent, NPPM_MENUCOMMAND, 0, IDM_SETTING_EDITCONTEXTMENU);
_addCtxDlg.doDialog();
return TRUE;
}
default :
break;
}
break;
}
case WM_SIZE :
{
// RECT rcDlg, rcText, rcOk;
// getClientRect(rcDlg);
// HWND hOk = ::GetDlgItem(_hSelf, IDOK);
// HWND hText = ::GetDlgItem(_hSelf,IDC_DIALOG_DESCRIPTION);
// ::GetClientRect(hText, &rcText);
// ::GetClientRect(hOk, &rcOk);
// POINT pOk = getLeftTopPoint(hOk);
// POINT pText = getLeftTopPoint(hText);
// int dWidth = rcDlg.right-rcDlg.left-20; // for border
// int dTextHeight = rcDlg.bottom-rcDlg.top-pText.y-10; // for border
// if(dWidth>=0) {
// if(dTextHeight>=0){
// ::MoveWindow(hText, pText.x, pText.y, dWidth, dTextHeight, TRUE);
// }
// ::MoveWindow(hOk, pOk.x, pOk.y, dWidth, rcOk.bottom, TRUE);
//redraw();
// }
break;
}
case WM_DESTROY:
{
_pFgColour->destroy();
_pBgColour->destroy();
delete _pFgColour;
delete _pBgColour;
break;
}
default:;
} // switch
return FALSE;
}
INT_PTR CALLBACK ConfigDialog::run_dlgProc(HWND /*hwnd*/, UINT Message, WPARAM wParam, LPARAM lParam)
{
return run_dlgProc(Message, wParam, lParam);
}