Skip to content

Commit e4b9960

Browse files
committed
backport changes from master for support of n++ 8.3
expected to fix: - editor.getTextRange crash notepad++ #224 - findText do not find text #223 - Notepad++ 8.3 builds change Sci_position leading to crash #218
1 parent ae36545 commit e4b9960

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2460
-1766
lines changed

NppPlugin/include/Common.h

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
// This file is part of Notepad++ project
2-
// Copyright (C)2003 Don HO <[email protected]>
3-
//
4-
// This program is free software; you can redistribute it and/or
5-
// modify it under the terms of the GNU General Public License
6-
// as published by the Free Software Foundation; either
7-
// version 2 of the License, or (at your option) any later version.
8-
//
9-
// Note that the GPL places important restrictions on "derived works", yet
10-
// it does not provide a detailed definition of that term. To avoid
11-
// misunderstandings, we consider an application to constitute a
12-
// "derivative work" for the purpose of this license if it does any of the
13-
// following:
14-
// 1. Integrates source code from Notepad++.
15-
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
16-
// installer, such as those produced by InstallShield.
17-
// 3. Links to a library or executes a program that does any of the above.
2+
// Copyright (C)2021 Don HO <[email protected]>
3+
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// at your option any later version.
188
//
199
// This program is distributed in the hope that it will be useful,
2010
// but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2212
// GNU General Public License for more details.
2313
//
2414
// You should have received a copy of the GNU General Public License
25-
// along with this program; if not, write to the Free Software
26-
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2716
#pragma once
2817
#include <vector>
2918
#include <string>
3019
#include <sstream>
3120
#include <windows.h>
3221
#include <iso646.h>
3322
#include <cstdint>
23+
#include <unordered_set>
24+
#include <algorithm>
3425

3526

3627
const bool dirUp = true;
@@ -92,35 +83,41 @@ std::string getFileContent(const TCHAR *file2read);
9283
generic_string relativeFilePathToFullFilePath(const TCHAR *relativeFilePath);
9384
void writeFileContent(const TCHAR *file2write, const char *content2write);
9485
bool matchInList(const TCHAR *fileName, const std::vector<generic_string> & patterns);
86+
bool matchInExcludeDirList(const TCHAR* dirName, const std::vector<generic_string>& patterns, size_t level);
87+
bool allPatternsAreExclusion(const std::vector<generic_string> patterns);
9588

9689
class WcharMbcsConvertor final
9790
{
9891
public:
99-
static WcharMbcsConvertor * getInstance() {return _pSelf;}
100-
static void destroyInstance() {delete _pSelf;}
92+
static WcharMbcsConvertor& getInstance() {
93+
static WcharMbcsConvertor instance;
94+
return instance;
95+
}
10196

102-
const wchar_t * char2wchar(const char *mbStr, UINT codepage, int lenIn=-1, int *pLenOut=NULL, int *pBytesNotProcessed=NULL);
103-
const wchar_t * char2wchar(const char *mbcs2Convert, UINT codepage, int *mstart, int *mend);
104-
const char * wchar2char(const wchar_t *wcStr, UINT codepage, int lenIn = -1, int *pLenOut = NULL);
105-
const char * wchar2char(const wchar_t *wcStr, UINT codepage, long *mstart, long *mend);
97+
const wchar_t * char2wchar(const char *mbStr, size_t codepage, int lenMbcs =-1, int* pLenOut=NULL, int* pBytesNotProcessed=NULL);
98+
const wchar_t * char2wchar(const char *mbcs2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend);
99+
const char * wchar2char(const wchar_t *wcStr, size_t codepage, int lenIn = -1, int* pLenOut = NULL);
100+
const char * wchar2char(const wchar_t *wcStr, size_t codepage, intptr_t* mstart, intptr_t* mend);
106101

107-
const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn=-1, int *pLenOut=NULL, int *pBytesNotProcessed=NULL)
102+
const char * encode(UINT fromCodepage, UINT toCodepage, const char *txt2Encode, int lenIn = -1, int* pLenOut=NULL, int* pBytesNotProcessed=NULL)
108103
{
109104
int lenWc = 0;
110105
const wchar_t * strW = char2wchar(txt2Encode, fromCodepage, lenIn, &lenWc, pBytesNotProcessed);
111106
return wchar2char(strW, toCodepage, lenWc, pLenOut);
112107
}
113108

114109
protected:
115-
WcharMbcsConvertor() {}
116-
~WcharMbcsConvertor() {}
110+
WcharMbcsConvertor() = default;
111+
~WcharMbcsConvertor() = default;
117112

118113
// Since there's no public ctor, we need to void the default assignment operator and copy ctor.
119114
// Since these are marked as deleted does not matter under which access specifier are kept
120115
WcharMbcsConvertor(const WcharMbcsConvertor&) = delete;
121116
WcharMbcsConvertor& operator= (const WcharMbcsConvertor&) = delete;
122117

123-
static WcharMbcsConvertor* _pSelf;
118+
// No move ctor and assignment
119+
WcharMbcsConvertor(WcharMbcsConvertor&&) = delete;
120+
WcharMbcsConvertor& operator= (WcharMbcsConvertor&&) = delete;
124121

125122
template <class T>
126123
class StringBuffer final
@@ -169,26 +166,30 @@ class WcharMbcsConvertor final
169166
#define REBARBAND_SIZE sizeof(REBARBANDINFO)
170167

171168
generic_string PathRemoveFileSpec(generic_string & path);
172-
generic_string PathAppend(generic_string &strDest, const generic_string & str2append);
169+
generic_string pathAppend(generic_string &strDest, const generic_string & str2append);
173170
COLORREF getCtrlBgColor(HWND hWnd);
174171
generic_string stringToUpper(generic_string strToConvert);
175172
generic_string stringToLower(generic_string strToConvert);
176173
generic_string stringReplace(generic_string subject, const generic_string& search, const generic_string& replace);
177174
std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter);
175+
bool str2numberVector(generic_string str2convert, std::vector<size_t>& numVect);
178176
generic_string stringJoin(const std::vector<generic_string>& strings, const generic_string& separator);
179177
generic_string stringTakeWhileAdmissable(const generic_string& input, const generic_string& admissable);
180178
double stodLocale(const generic_string& str, _locale_t loc, size_t* idx = NULL);
181179

182180
int OrdinalIgnoreCaseCompareStrings(LPCTSTR sz1, LPCTSTR sz2);
183181

184182
bool str2Clipboard(const generic_string &str2cpy, HWND hwnd);
183+
class Buffer;
184+
bool buf2Clipborad(const std::vector<Buffer*>& buffers, bool isFullPath, HWND hwnd);
185185

186186
generic_string GetLastErrorAsString(DWORD errorCode = 0);
187187

188188
generic_string intToString(int val);
189189
generic_string uintToString(unsigned int val);
190190

191-
HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText);
191+
HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText, bool isRTL);
192+
HWND CreateToolTipRect(int toolID, HWND hWnd, HINSTANCE hInst, const PTSTR pszText, const RECT rc);
192193

193194
bool isCertificateValidated(const generic_string & fullFilePath, const generic_string & subjectName2check);
194195
bool isAssoCommandExisting(LPCTSTR FullPathName);
@@ -199,3 +200,38 @@ std::string ws2s(const std::wstring& wstr);
199200
bool deleteFileOrFolder(const generic_string& f2delete);
200201

201202
void getFilesInFolder(std::vector<generic_string>& files, const generic_string& extTypeFilter, const generic_string& inFolder);
203+
204+
template<typename T> size_t vecRemoveDuplicates(std::vector<T>& vec, bool isSorted = false, bool canSort = false)
205+
{
206+
if (!isSorted && canSort)
207+
{
208+
std::sort(vec.begin(), vec.end());
209+
isSorted = true;
210+
}
211+
212+
if (isSorted)
213+
{
214+
typename std::vector<T>::iterator it;
215+
it = std::unique(vec.begin(), vec.end());
216+
vec.resize(distance(vec.begin(), it)); // unique() does not shrink the vector
217+
}
218+
else
219+
{
220+
std::unordered_set<T> seen;
221+
auto newEnd = std::remove_if(vec.begin(), vec.end(), [&seen](const T& value)
222+
{
223+
return !seen.insert(value).second;
224+
});
225+
vec.erase(newEnd, vec.end());
226+
}
227+
return vec.size();
228+
}
229+
230+
void trim(generic_string& str);
231+
bool endsWith(const generic_string& s, const generic_string& suffix);
232+
233+
int nbDigitsFromNbLines(size_t nbLines);
234+
235+
generic_string getDateTimeStrFrom(const generic_string& dateTimeFormat, const SYSTEMTIME& st);
236+
237+
HFONT createFont(const TCHAR* fontName, int fontSize, bool isBold, HWND hDestParent);

NppPlugin/include/Docking.h

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,18 @@
1-
// this file is part of Notepad++
2-
// Copyright (C)2005 Jens Lorenz <[email protected]>
3-
//
4-
// This program is free software; you can redistribute it and/or
5-
// modify it under the terms of the GNU General Public License
6-
// as published by the Free Software Foundation; either
7-
// version 2 of the License, or (at your option) any later version.
8-
//
9-
// // Note that the GPL places important restrictions on "derived works", yet
10-
// it does not provide a detailed definition of that term. To avoid
11-
// misunderstandings, we consider an application to constitute a
12-
// "derivative work" for the purpose of this license if it does any of the
13-
// following:
14-
// 1. Integrates source code from Notepad++.
15-
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
16-
// installer, such as those produced by InstallShield.
17-
// 3. Links to a library or executes a program that does any of the above.
18-
//
1+
// This file is part of Notepad++ project
2+
// Copyright (C)2021 Don HO <[email protected]>
3+
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// at your option any later version.
8+
//
199
// This program is distributed in the hope that it will be useful,
2010
// but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2212
// GNU General Public License for more details.
23-
//
13+
//
2414
// You should have received a copy of the GNU General Public License
25-
// along with this program; if not, write to the Free Software
26-
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2716

2817

2918
#pragma once
@@ -57,27 +46,27 @@
5746
#define DWS_DF_FLOATING 0x80000000 // default state is floating
5847

5948

60-
typedef struct {
61-
HWND hClient; // client Window Handle
62-
const TCHAR *pszName; // name of plugin (shown in window)
63-
int dlgID; // a funcItem provides the function pointer to start a dialog. Please parse here these ID
49+
struct tTbData {
50+
HWND hClient = nullptr; // client Window Handle
51+
const TCHAR* pszName = nullptr; // name of plugin (shown in window)
52+
int dlgID = 0; // a funcItem provides the function pointer to start a dialog. Please parse here these ID
6453

6554
// user modifications
66-
UINT uMask; // mask params: look to above defines
67-
HICON hIconTab; // icon for tabs
68-
const TCHAR *pszAddInfo; // for plugin to display additional informations
55+
UINT uMask = 0; // mask params: look to above defines
56+
HICON hIconTab = nullptr; // icon for tabs
57+
const TCHAR* pszAddInfo = nullptr; // for plugin to display additional informations
6958

7059
// internal data, do not use !!!
71-
RECT rcFloat; // floating position
72-
int iPrevCont; // stores the privious container (toggling between float and dock)
73-
const TCHAR* pszModuleName; // it's the plugin file name. It's used to identify the plugin
74-
} tTbData;
60+
RECT rcFloat = {0}; // floating position
61+
int iPrevCont = 0; // stores the privious container (toggling between float and dock)
62+
const TCHAR* pszModuleName = nullptr; // it's the plugin file name. It's used to identify the plugin
63+
};
7564

7665

77-
typedef struct {
78-
HWND hWnd; // the docking manager wnd
79-
RECT rcRegion[DOCKCONT_MAX]; // position of docked dialogs
80-
} tDockMgr;
66+
struct tDockMgr {
67+
HWND hWnd = nullptr; // the docking manager wnd
68+
RECT rcRegion[DOCKCONT_MAX] = {{0}}; // position of docked dialogs
69+
};
8170

8271

8372
#define HIT_TEST_THICKNESS 20

NppPlugin/include/DockingDlgInterface.h

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
// this file is part of Function List Plugin for Notepad++
2-
// Copyright (C)2005 Jens Lorenz <[email protected]>
3-
//
4-
// This program is free software; you can redistribute it and/or
5-
// modify it under the terms of the GNU General Public License
6-
// as published by the Free Software Foundation; either
7-
// version 2 of the License, or (at your option) any later version.
8-
//
9-
// Note that the GPL places important restrictions on "derived works", yet
10-
// it does not provide a detailed definition of that term. To avoid
11-
// misunderstandings, we consider an application to constitute a
12-
// "derivative work" for the purpose of this license if it does any of the
13-
// following:
14-
// 1. Integrates source code from Notepad++.
15-
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
16-
// installer, such as those produced by InstallShield.
17-
// 3. Links to a library or executes a program that does any of the above.
1+
// This file is part of Notepad++ project
2+
// Copyright (C)2006 Jens Lorenz <[email protected]>
3+
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// at your option any later version.
188
//
199
// This program is distributed in the hope that it will be useful,
2010
// but WITHOUT ANY WARRANTY; without even the implied warranty of
21-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2212
// GNU General Public License for more details.
23-
//
13+
//
2414
// You should have received a copy of the GNU General Public License
25-
// along with this program; if not, write to the Free Software
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2616

2717

2818
#pragma once
@@ -34,6 +24,7 @@
3424
#include <shlwapi.h>
3525
#include "Common.h"
3626
#include "StaticDialog.h"
27+
#include "NppDarkMode.h"
3728

3829

3930

@@ -43,39 +34,38 @@ class DockingDlgInterface : public StaticDialog
4334
DockingDlgInterface() = default;
4435
explicit DockingDlgInterface(int dlgID): _dlgID(dlgID) {}
4536

46-
virtual void init(HINSTANCE hInst, HWND parent)
47-
{
37+
virtual void init(HINSTANCE hInst, HWND parent) {
4838
StaticDialog::init(hInst, parent);
4939
TCHAR temp[MAX_PATH];
5040
::GetModuleFileName(reinterpret_cast<HMODULE>(hInst), temp, MAX_PATH);
5141
_moduleName = ::PathFindFileName(temp);
5242
}
5343

54-
void create(tTbData * data, bool isRTL = false)
55-
{
44+
void create(tTbData* data, bool isRTL = false) {
5645
assert(data != nullptr);
5746
StaticDialog::create(_dlgID, isRTL);
5847
TCHAR temp[MAX_PATH];
5948
::GetWindowText(_hSelf, temp, MAX_PATH);
6049
_pluginName = temp;
6150

6251
// user information
63-
data->hClient = _hSelf;
64-
data->pszName = _pluginName.c_str();
52+
data->hClient = _hSelf;
53+
data->pszName = _pluginName.c_str();
6554

6655
// supported features by plugin
67-
data->uMask = 0;
56+
data->uMask = 0;
6857

6958
// additional info
70-
data->pszAddInfo = NULL;
59+
data->pszAddInfo = NULL;
7160
}
7261

73-
virtual void updateDockingDlg()
74-
{
62+
virtual void updateDockingDlg() {
7563
::SendMessage(_hParent, NPPM_DMMUPDATEDISPINFO, 0, reinterpret_cast<LPARAM>(_hSelf));
7664
}
7765

78-
virtual void destroy() {}
66+
virtual void destroy() {
67+
StaticDialog::destroy();
68+
}
7969

8070
virtual void setBackgroundColor(COLORREF) {}
8171
virtual void setForegroundColor(COLORREF) {}
@@ -97,11 +87,28 @@ class DockingDlgInterface : public StaticDialog
9787
}
9888

9989
protected :
100-
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM, LPARAM lParam)
101-
{
102-
switch (message)
90+
int _dlgID = -1;
91+
bool _isFloating = true;
92+
int _iDockedPos = 0;
93+
generic_string _moduleName;
94+
generic_string _pluginName;
95+
bool _isClosed = false;
96+
97+
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) {
98+
switch (message)
10399
{
100+
case WM_ERASEBKGND:
101+
{
102+
if (!NppDarkMode::isEnabled())
103+
{
104+
break;
105+
}
104106

107+
RECT rc = { 0 };
108+
getClientRect(rc);
109+
::FillRect(reinterpret_cast<HDC>(wParam), &rc, NppDarkMode::getDarkerBackgroundBrush());
110+
return TRUE;
111+
}
105112
case WM_NOTIFY:
106113
{
107114
LPNMHDR pnmh = reinterpret_cast<LPNMHDR>(lParam);
@@ -136,13 +143,4 @@ protected :
136143
}
137144
return FALSE;
138145
};
139-
140-
// Handles
141-
HWND _HSource = NULL;
142-
int _dlgID = -1;
143-
bool _isFloating = true;
144-
int _iDockedPos = 0;
145-
generic_string _moduleName;
146-
generic_string _pluginName;
147-
bool _isClosed = false;
148146
};

0 commit comments

Comments
 (0)