Skip to content

Commit db9efff

Browse files
committed
update to current N++ version notepad-plus-plus/notepad-plus-plus@a4a8f72
1 parent 882a21f commit db9efff

24 files changed

+1040
-259
lines changed

NppPlugin/include/Common.h

Lines changed: 78 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,43 +14,27 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616

17+
1718
#pragma once
18-
#include <vector>
19-
#include <string>
20-
#include <sstream>
19+
2120
#include <windows.h>
21+
2222
#include <commctrl.h>
23-
#include <iso646.h>
24-
#include <cstdint>
25-
#include <unordered_set>
26-
#include <algorithm>
2723
#include <tchar.h>
2824

25+
#include <algorithm>
26+
#include <locale>
27+
#include <sstream>
28+
#include <string>
29+
#include <unordered_set>
30+
#include <vector>
31+
32+
#if defined(_MSC_VER)
2933
#pragma deprecated(PathFileExists) // Use doesFileExist, doesDirectoryExist or doesPathExist (for file or directory) instead.
3034
#pragma deprecated(PathIsDirectory) // Use doesDirectoryExist instead.
31-
32-
33-
const bool dirUp = true;
34-
const bool dirDown = false;
35-
36-
#define NPP_CP_WIN_1252 1252
37-
#define NPP_CP_DOS_437 437
38-
#define NPP_CP_BIG5 950
39-
40-
#define LINKTRIGGERED WM_USER+555
41-
42-
#define BCKGRD_COLOR (RGB(255,102,102))
43-
#define TXT_COLOR (RGB(255,255,255))
44-
45-
#ifndef __MINGW32__
46-
#define WCSTOK wcstok
47-
#else
48-
#define WCSTOK wcstok_s
4935
#endif
5036

5137

52-
#define NPP_INTERNAL_FUNCTION_STR L"Notepad++::InternalFunction"
53-
5438

5539
std::wstring folderBrowser(HWND parent, const std::wstring & title = L"", int outputCtrlID = 0, const wchar_t *defaultStr = NULL);
5640
std::wstring getFolderName(HWND parent, const wchar_t *defaultDir = NULL);
@@ -68,12 +52,12 @@ std::vector<std::wstring> tokenizeString(const std::wstring & tokenString, const
6852
void ClientRectToScreenRect(HWND hWnd, RECT* rect);
6953
void ScreenRectToClientRect(HWND hWnd, RECT* rect);
7054

71-
std::wstring string2wstring(const std::string & rString, UINT codepage);
72-
std::string wstring2string(const std::wstring & rwString, UINT codepage);
73-
bool isInList(const wchar_t *token, const wchar_t *list);
55+
std::wstring string2wstring(const std::string& rString, UINT codepage = CP_UTF8);
56+
std::string wstring2string(const std::wstring& rwString, UINT codepage = CP_UTF8);
57+
bool isInList(const wchar_t* token, const wchar_t* list);
7458
std::wstring BuildMenuFileName(int filenameLen, unsigned int pos, const std::wstring &filename, bool ordinalNumber = true);
7559

76-
std::string getFileContent(const wchar_t *file2read);
60+
std::string getFileContent(const wchar_t* file2read, bool* pbFailed = nullptr);
7761
std::wstring relativeFilePathToFullFilePath(const wchar_t *relativeFilePath);
7862
void writeFileContent(const wchar_t *file2write, const char *content2write);
7963
bool matchInList(const wchar_t *fileName, const std::vector<std::wstring> & patterns);
@@ -88,12 +72,12 @@ class WcharMbcsConvertor final
8872
return instance;
8973
}
9074

91-
const wchar_t* char2wchar(const char* mbStr, size_t codepage, int lenMbcs = -1, int* pLenOut = NULL, int* pBytesNotProcessed = NULL);
92-
const wchar_t* char2wchar(const char* mbcs2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend, int len = 0);
93-
size_t getSizeW() { return _wideCharStr.size(); };
94-
const char* wchar2char(const wchar_t* wcStr, size_t codepage, int lenIn = -1, int* pLenOut = NULL);
95-
const char* wchar2char(const wchar_t* wcStr, size_t codepage, intptr_t* mstart, intptr_t* mend, int lenIn = 0, int* lenOut = nullptr);
96-
size_t getSizeA() { return _multiByteStr.size(); };
75+
const wchar_t* char2wchar(const char* mbcs2Convert, size_t codepage, int lenMbcs = -1, int* pLenWc = nullptr, int* pBytesNotProcessed = NULL);
76+
const wchar_t* char2wchar(const char* mbcs2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend, int mbcsLen = 0);
77+
size_t getSizeW() const { return _wideCharStr.size(); }
78+
const char* wchar2char(const wchar_t* wcharStr2Convert, size_t codepage, int lenWc = -1, int* pLenMbcs = nullptr);
79+
const char* wchar2char(const wchar_t* wcharStr2Convert, size_t codepage, intptr_t* mstart, intptr_t* mend, int wcharLenIn = 0, int* lenOut = nullptr);
80+
size_t getSizeA() const { return _multiByteStr.size(); }
9781

9882
const char* encode(UINT fromCodepage, UINT toCodepage, const char* txt2Encode, int lenIn = -1, int* pLenOut = NULL, int* pBytesNotProcessed = NULL) {
9983
int lenWc = 0;
@@ -144,7 +128,7 @@ class WcharMbcsConvertor final
144128
operator const T* () const { return _str; }
145129

146130
protected:
147-
static const int initSize = 1024;
131+
static constexpr int initSize = 1024;
148132
size_t _allocLen = 0;
149133
size_t _dataLen = 0;
150134
T* _str = nullptr;
@@ -154,8 +138,6 @@ class WcharMbcsConvertor final
154138
StringBuffer<wchar_t> _wideCharStr;
155139
};
156140

157-
#define REBARBAND_SIZE sizeof(REBARBANDINFO)
158-
159141
std::wstring pathRemoveFileSpec(std::wstring & path);
160142
std::wstring pathAppend(std::wstring &strDest, const std::wstring & str2append);
161143
COLORREF getCtrlBgColor(HWND hWnd);
@@ -168,6 +150,8 @@ void stringJoin(const std::vector<std::wstring>& strings, const std::wstring& se
168150
std::wstring stringTakeWhileAdmissable(const std::wstring& input, const std::wstring& admissable);
169151
double stodLocale(const std::wstring& str, _locale_t loc, size_t* idx = NULL);
170152

153+
const std::locale& getSysLocale();
154+
171155
bool str2Clipboard(const std::wstring &str2cpy, HWND hwnd);
172156
std::wstring strFromClipboard();
173157
class Buffer;
@@ -178,11 +162,11 @@ std::wstring GetLastErrorAsString(DWORD errorCode = 0);
178162
std::wstring intToString(int val);
179163
std::wstring uintToString(unsigned int val);
180164

181-
HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PTSTR pszText, bool isRTL);
182-
HWND CreateToolTipRect(int toolID, HWND hWnd, HINSTANCE hInst, const PTSTR pszText, const RECT rc);
165+
HWND CreateToolTip(int toolID, HWND hDlg, HINSTANCE hInst, const PWSTR pszText, bool isRTL);
166+
HWND CreateToolTipRect(int toolID, HWND hWnd, HINSTANCE hInst, const PWSTR pszText, const RECT rc);
183167

184168
bool isCertificateValidated(const std::wstring & fullFilePath, const std::wstring & subjectName2check);
185-
bool isAssoCommandExisting(LPCTSTR FullPathName);
169+
bool isAssoCommandExisting(LPCWSTR FullPathName);
186170

187171
bool deleteFileOrFolder(const std::wstring& f2delete);
188172

@@ -233,42 +217,43 @@ class Version final
233217
{
234218
public:
235219
Version() = default;
236-
Version(const std::wstring& versionStr);
220+
explicit Version(const std::wstring& versionStr);
237221

238222
void setVersionFrom(const std::wstring& filePath);
239-
std::wstring toString();
240-
bool isNumber(const std::wstring& s) const {
223+
std::wstring toString() const;
224+
static bool isNumber(const std::wstring& s) {
225+
static const auto& loc = std::locale::classic();
241226
return !s.empty() &&
242-
find_if(s.begin(), s.end(), [](wchar_t c) { return !_istdigit(c); }) == s.end();
243-
};
227+
find_if(s.begin(), s.end(), [](auto c) { return !std::isdigit(c, loc); }) == s.end();
228+
}
244229

245230
int compareTo(const Version& v2c) const;
246231

247232
bool operator < (const Version& v2c) const {
248233
return compareTo(v2c) == -1;
249-
};
234+
}
250235

251236
bool operator <= (const Version& v2c) const {
252237
int r = compareTo(v2c);
253238
return r == -1 || r == 0;
254-
};
239+
}
255240

256241
bool operator > (const Version& v2c) const {
257242
return compareTo(v2c) == 1;
258-
};
243+
}
259244

260245
bool operator >= (const Version& v2c) const {
261246
int r = compareTo(v2c);
262247
return r == 1 || r == 0;
263-
};
248+
}
264249

265250
bool operator == (const Version& v2c) const {
266251
return compareTo(v2c) == 0;
267-
};
252+
}
268253

269254
bool operator != (const Version& v2c) const {
270255
return compareTo(v2c) != 0;
271-
};
256+
}
272257

273258
bool empty() const {
274259
return _major == 0 && _minor == 0 && _patch == 0 && _build == 0;
@@ -300,26 +285,25 @@ bool isWindowVisibleOnAnyMonitor(const RECT& rectWndIn);
300285
bool isCoreWindows();
301286

302287

303-
#define IDT_HIDE_TOOLTIP 1001
304-
305288
class ControlInfoTip final
306289
{
307290
public:
308-
ControlInfoTip() {};
291+
ControlInfoTip() = default;
309292
~ControlInfoTip() {
310293
if (_hWndInfoTip) {
311294
hide();
312295
}
313-
};
296+
}
297+
314298
bool init(HINSTANCE hInst, HWND ctrl2attached, HWND ctrl2attachedParent, const std::wstring& tipStr, bool isRTL, unsigned int remainTimeMillisecond = 0, int maxWidth = 200); // remainTimeMillisecond = 0: no timeout
315299

316300
bool isValid() const {
317301
return _hWndInfoTip != nullptr;
318-
};
302+
}
319303

320304
HWND getTipHandle() const {
321305
return _hWndInfoTip;
322-
};
306+
}
323307

324308
enum showPosition {beginning, middle, end};
325309
void show(showPosition pos = middle) const;
@@ -334,9 +318,38 @@ class ControlInfoTip final
334318
ControlInfoTip& operator=(const ControlInfoTip&) = delete;
335319
};
336320

321+
DWORD invokeNppUacOp(const std::wstring& strCmdLineParams);
322+
bool fileTimeToYMD(const FILETIME& ft, int& yyyymmdd);
323+
void expandEnv(std::wstring& path2Expand);
337324

338-
#define NPP_UAC_SAVE_SIGN L"#UAC-SAVE#"
339-
#define NPP_UAC_SETFILEATTRIBUTES_SIGN L"#UAC-SETFILEATTRIBUTES#"
340-
#define NPP_UAC_MOVEFILE_SIGN L"#UAC-MOVEFILE#"
341-
#define NPP_UAC_CREATEEMPTYFILE_SIGN L"#UAC-CREATEEMPTYFILE#"
342-
DWORD invokeNppUacOp(std::wstring& strCmdLineParams);
325+
class ScopedCOMInit final // never use this in DllMain
326+
{
327+
public:
328+
ScopedCOMInit() {
329+
HRESULT hr = ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); // attempt STA init 1st (older CoInitialize(NULL))
330+
if (hr == RPC_E_CHANGED_MODE) {
331+
hr = ::CoInitializeEx(nullptr, COINIT_MULTITHREADED); // STA init failed, switch to MTA
332+
}
333+
if (SUCCEEDED(hr)) {
334+
// S_OK or S_FALSE, both needs subsequent CoUninitialize()
335+
_bInitialized = true;
336+
}
337+
}
338+
339+
~ScopedCOMInit() {
340+
if (_bInitialized) {
341+
_bInitialized = false;
342+
::CoUninitialize();
343+
}
344+
}
345+
346+
bool isInitialized() const {
347+
return _bInitialized;
348+
}
349+
350+
private:
351+
bool _bInitialized = false;
352+
353+
ScopedCOMInit(const ScopedCOMInit&) = delete;
354+
ScopedCOMInit& operator=(const ScopedCOMInit&) = delete;
355+
};

NppPlugin/include/DockingDlgInterface.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@
1717

1818
#pragma once
1919

20-
#include "dockingResource.h"
21-
#include "Docking.h"
20+
#include <windows.h>
2221

23-
#include <array>
24-
#include <assert.h>
2522
#include <shlwapi.h>
26-
#include "Common.h"
27-
#include "StaticDialog.h"
28-
#include "NppDarkMode.h"
2923

24+
#include <array>
25+
#include <cassert>
26+
#include <string>
3027

28+
#include "Docking.h"
29+
#include "Notepad_plus_msgs.h"
30+
#include "NppDarkMode.h"
31+
#include "StaticDialog.h"
32+
#include "dockingResource.h"
3133

3234
class DockingDlgInterface : public StaticDialog
3335
{
@@ -101,6 +103,8 @@ protected :
101103
bool _isFloating = true;
102104
bool _isClosed = false;
103105

106+
using StaticDialog::create;
107+
104108
intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override {
105109
switch (message)
106110
{
@@ -149,5 +153,5 @@ protected :
149153
break;
150154
}
151155
return FALSE;
152-
};
156+
}
153157
};

NppPlugin/include/Notepad_plus_msgs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
917917

918918
// Standard flags for main parent usually used in NPPN_DARKMODECHANGED.
919919
constexpr ULONG dmfHandleChange = 0x0000000CUL;
920-
};
920+
}
921921

922922
// ULONG NPPM_DARKMODESUBCLASSANDTHEME(ULONG dmFlags, HWND hwnd)
923923
// Add support for generic dark mode to plugin dialog. Subclassing is applied automatically unless DWS_USEOWNDARKMODE flag is used.

NppPlugin/include/NppDarkMode.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ namespace NppDarkMode
4444
struct Options
4545
{
4646
bool enable = false;
47-
bool enableMenubar = false;
4847
bool enablePlugin = false;
4948
};
5049

@@ -90,7 +89,6 @@ namespace NppDarkMode
9089
void initAdvancedOptions();
9190

9291
bool isEnabled();
93-
bool isDarkMenuEnabled();
9492
bool isEnabledForPlugins();
9593
bool isExperimentalActive();
9694
bool isExperimentalSupported();
@@ -176,11 +174,6 @@ namespace NppDarkMode
176174
void handleSettingChange(HWND hwnd, LPARAM lParam, bool isFromBtn = false);
177175
bool isDarkModeReg();
178176

179-
// processes messages related to UAH / custom menubar drawing.
180-
// return true if handled, false to continue with normal processing in your wndproc
181-
bool runUAHWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT* lr);
182-
void drawUAHMenuNCBottomLine(HWND hWnd);
183-
184177
// from DarkMode.h
185178
void initExperimentalDarkMode();
186179
void setDarkMode(bool useDark, bool fixDarkScrollbar);
@@ -216,6 +209,7 @@ namespace NppDarkMode
216209
ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags);
217210
void autoSubclassCtlColor(HWND hWnd);
218211
void autoSubclassAndThemeWindowNotify(HWND hwnd);
212+
void autoSubclassWindowMenuBar(HWND hWnd);
219213

220214
void setDarkTitleBar(HWND hwnd);
221215
void setDarkExplorerTheme(HWND hwnd);

0 commit comments

Comments
 (0)