Skip to content

Commit 1168db6

Browse files
committed
further merge
1 parent 0b90f2b commit 1168db6

89 files changed

Lines changed: 4453 additions & 3386 deletions

File tree

Some content is hidden

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

NppPlugin/include/Common.h

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,14 @@ const bool dirDown = false;
3737
#define BCKGRD_COLOR (RGB(255,102,102))
3838
#define TXT_COLOR (RGB(255,255,255))
3939

40-
#define generic_strtol wcstol
41-
#define generic_strncpy wcsncpy
42-
#define generic_stricmp wcsicmp
43-
#define generic_strncmp wcsncmp
44-
#define generic_strnicmp wcsnicmp
45-
#define generic_strncat wcsncat
46-
#define generic_strchr wcschr
47-
#define generic_atoi _wtoi
48-
#define generic_itoa _itow
49-
#define generic_atof _wtof
50-
#define generic_strtok wcstok
51-
#define generic_strftime wcsftime
52-
#define generic_fprintf fwprintf
53-
#define generic_sprintf swprintf
54-
#define generic_sscanf swscanf
55-
#define generic_fopen _wfopen
56-
#define generic_fgets fgetws
57-
#define COPYDATA_FILENAMES COPYDATA_FILENAMESW
58-
#define NPP_INTERNAL_FUCTION_STR TEXT("Notepad++::InternalFunction")
40+
#ifndef __MINGW32__
41+
#define WCSTOK wcstok
42+
#else
43+
#define WCSTOK wcstok_s
44+
#endif
45+
46+
47+
#define NPP_INTERNAL_FUCTION_STR L"Notepad++::InternalFunction"
5948

6049
typedef std::basic_string<TCHAR> generic_string;
6150
typedef std::basic_stringstream<TCHAR> generic_stringstream;
@@ -132,7 +121,7 @@ class WcharMbcsConvertor final
132121
{
133122
if (_allocLen)
134123
delete[] _str;
135-
_allocLen = max(size, initSize);
124+
_allocLen = std::max<size_t>(size, initSize);
136125
_str = new T[_allocLen];
137126
}
138127
}
@@ -168,9 +157,9 @@ COLORREF getCtrlBgColor(HWND hWnd);
168157
generic_string stringToUpper(generic_string strToConvert);
169158
generic_string stringToLower(generic_string strToConvert);
170159
generic_string stringReplace(generic_string subject, const generic_string& search, const generic_string& replace);
171-
std::vector<generic_string> stringSplit(const generic_string& input, const generic_string& delimiter);
160+
void stringSplit(const generic_string& input, const generic_string& delimiter, std::vector<generic_string>& output);
172161
bool str2numberVector(generic_string str2convert, std::vector<size_t>& numVect);
173-
generic_string stringJoin(const std::vector<generic_string>& strings, const generic_string& separator);
162+
void stringJoin(const std::vector<generic_string>& strings, const generic_string& separator, generic_string& joinedString);
174163
generic_string stringTakeWhileAdmissable(const generic_string& input, const generic_string& admissable);
175164
double stodLocale(const generic_string& str, _locale_t loc, size_t* idx = NULL);
176165

@@ -224,14 +213,19 @@ template<typename T> size_t vecRemoveDuplicates(std::vector<T>& vec, bool isSort
224213
return vec.size();
225214
}
226215

227-
void trim(generic_string& str);
228-
bool endsWith(const generic_string& s, const generic_string& suffix);
216+
void trim(std::wstring& str);
229217

230218
int nbDigitsFromNbLines(size_t nbLines);
231219

232220
generic_string getDateTimeStrFrom(const generic_string& dateTimeFormat, const SYSTEMTIME& st);
233221

234222
HFONT createFont(const TCHAR* fontName, int fontSize, bool isBold, HWND hDestParent);
223+
bool removeReadOnlyFlagFromFileAttributes(const wchar_t* fileFullPath);
224+
225+
bool isWin32NamespacePrefixedFileName(const generic_string& fileName);
226+
bool isWin32NamespacePrefixedFileName(const TCHAR* szFileName);
227+
bool isUnsupportedFileName(const generic_string& fileName);
228+
bool isUnsupportedFileName(const TCHAR* szFileName);
235229

236230
class Version final
237231
{

NppPlugin/include/DockingDlgInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class DockingDlgInterface : public StaticDialog
3737
virtual void init(HINSTANCE hInst, HWND parent) {
3838
StaticDialog::init(hInst, parent);
3939
TCHAR temp[MAX_PATH];
40-
::GetModuleFileName(reinterpret_cast<HMODULE>(hInst), temp, MAX_PATH);
40+
::GetModuleFileName(hInst, temp, MAX_PATH);
4141
_moduleName = ::PathFindFileName(temp);
4242
}
4343

NppPlugin/include/Notepad_plus_msgs.h

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\
3232
L_ASN1, L_AVS, L_BLITZBASIC, L_PUREBASIC, L_FREEBASIC, \
3333
L_CSOUND, L_ERLANG, L_ESCRIPT, L_FORTH, L_LATEX, \
3434
L_MMIXAL, L_NIM, L_NNCRONTAB, L_OSCRIPT, L_REBOL, \
35-
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG, L_TYPESCRIPT,\
35+
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG,\
36+
L_TYPESCRIPT, L_JSON5, L_MSSQL, L_GDSCRIPT, L_HOLLYWOOD,\
3637
// Don't use L_JS, use L_JAVASCRIPT instead
3738
// The end of enumated language type, so it should be always at the end
3839
L_EXTERNAL};
3940
enum class ExternalLexerAutoIndentMode { Standard, C_Like, Custom };
4041
enum class MacroStatus { Idle, RecordInProgress, RecordingStopped, PlayingBack };
4142

42-
enum winVer { WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81, WV_WIN10 };
43+
enum winVer { WV_UNKNOWN, WV_WIN32S, WV_95, WV_98, WV_ME, WV_NT, WV_W2K, WV_XP, WV_S2003, WV_XPX64, WV_VISTA, WV_WIN7, WV_WIN8, WV_WIN81, WV_WIN10, WV_WIN11 };
4344
enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
4445

4546

@@ -167,8 +168,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
167168
#define NPPM_MAKECURRENTBUFFERDIRTY (NPPMSG + 44)
168169
//BOOL NPPM_MAKECURRENTBUFFERDIRTY(0, 0)
169170

170-
#define NPPM_GETENABLETHEMETEXTUREFUNC (NPPMSG + 45)
171-
//BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0)
171+
#define NPPM_GETENABLETHEMETEXTUREFUNC_DEPRECATED (NPPMSG + 45)
172+
//BOOL NPPM_GETENABLETHEMETEXTUREFUNC(0, 0) -- DEPRECATED : use EnableThemeDialogTexture from uxtheme.h instead
172173

173174
#define NPPM_GETPLUGINSCONFIGDIR (NPPMSG + 46)
174175
//INT NPPM_GETPLUGINSCONFIGDIR(int strLen, TCHAR *str)
@@ -367,7 +368,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
367368

368369
#define NPPM_ALLOCATEMARKER (NPPMSG + 82)
369370
// BOOL NPPM_ALLOCATEMARKER(int numberRequested, int* startNumber)
370-
// sets startNumber to the initial command ID if successful
371+
// sets startNumber to the initial marker ID if successful
371372
// Allocates a marker number to a plugin: if a plugin need to add a marker on Notepad++'s Scintilla marker margin,
372373
// it has to use this message to get marker number, in order to prevent from the conflict with the other plugins.
373374
// Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful
@@ -541,24 +542,79 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
541542
// allocate commandLineStr buffer with the return value + 1, then call it again to get the current command line string.
542543

543544
#define NPPM_CREATELEXER (NPPMSG + 110)
544-
// void* NPPN_CREATELEXER(0, const TCHAR *lexer_name)
545+
// void* NPPM_CREATELEXER(0, const TCHAR *lexer_name)
545546
// Returns the ILexer pointer created by Lexilla
546547

547-
#define VAR_NOT_RECOGNIZED 0
548-
#define FULL_CURRENT_PATH 1
549-
#define CURRENT_DIRECTORY 2
550-
#define FILE_NAME 3
551-
#define NAME_PART 4
552-
#define EXT_PART 5
553-
#define CURRENT_WORD 6
554-
#define NPP_DIRECTORY 7
555-
#define CURRENT_LINE 8
556-
#define CURRENT_COLUMN 9
557-
#define NPP_FULL_FILE_PATH 10
558-
#define GETFILENAMEATCURSOR 11
559-
#define CURRENT_LINESTR 12
560-
561-
#define RUNCOMMAND_USER (WM_USER + 3000)
548+
#define NPPM_GETBOOKMARKID (NPPMSG + 111)
549+
// void* NPPM_GETBOOKMARKID(0, 0)
550+
// Returns the bookmark ID
551+
552+
#define NPPM_DARKMODESUBCLASSANDTHEME (NPPMSG + 112)
553+
// ULONG NPPM_DARKMODESUBCLASSANDTHEME(ULONG dmFlags, HWND hwnd)
554+
// Add support for generic dark mode.
555+
//
556+
// Docking panels don't need to call NPPM_DARKMODESUBCLASSANDTHEME for main hwnd.
557+
// Subclassing is applied automatically unless DWS_USEOWNDARKMODE flag is used.
558+
//
559+
// Might not work properly in C# plugins.
560+
//
561+
// Returns succesful combinations of flags.
562+
//
563+
564+
namespace NppDarkMode
565+
{
566+
// Standard flags for main parent after its children are initialized.
567+
constexpr ULONG dmfInit = 0x0000000BUL;
568+
569+
// Standard flags for main parent usually used in NPPN_DARKMODECHANGED.
570+
constexpr ULONG dmfHandleChange = 0x0000000CUL;
571+
};
572+
573+
// Examples:
574+
//
575+
// - after controls initializations in WM_INITDIALOG, in WM_CREATE or after CreateWindow:
576+
//
577+
//auto success = static_cast<ULONG>(::SendMessage(nppData._nppHandle, NPPM_DARKMODESUBCLASSANDTHEME, static_cast<WPARAM>(NppDarkMode::dmfInit), reinterpret_cast<LPARAM>(mainHwnd)));
578+
//
579+
// - handling dark mode change:
580+
//
581+
//extern "C" __declspec(dllexport) void beNotified(SCNotification * notifyCode)
582+
//{
583+
// switch (notifyCode->nmhdr.code)
584+
// {
585+
// case NPPN_DARKMODECHANGED:
586+
// {
587+
// ::SendMessage(nppData._nppHandle, NPPM_DARKMODESUBCLASSANDTHEME, static_cast<WPARAM>(dmfHandleChange), reinterpret_cast<LPARAM>(mainHwnd));
588+
// ::SetWindowPos(mainHwnd, nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); // to redraw titlebar and window
589+
// break;
590+
// }
591+
// }
592+
//}
593+
594+
#define NPPM_ALLOCATEINDICATOR (NPPMSG + 113)
595+
// BOOL NPPM_ALLOCATEINDICATOR(int numberRequested, int* startNumber)
596+
// sets startNumber to the initial indicator ID if successful
597+
// Allocates an indicator number to a plugin: if a plugin needs to add an indicator,
598+
// it has to use this message to get the indicator number, in order to prevent a conflict with the other plugins.
599+
// Returns: TRUE if successful, FALSE otherwise.
600+
601+
// For RUNCOMMAND_USER
602+
#define VAR_NOT_RECOGNIZED 0
603+
#define FULL_CURRENT_PATH 1
604+
#define CURRENT_DIRECTORY 2
605+
#define FILE_NAME 3
606+
#define NAME_PART 4
607+
#define EXT_PART 5
608+
#define CURRENT_WORD 6
609+
#define NPP_DIRECTORY 7
610+
#define CURRENT_LINE 8
611+
#define CURRENT_COLUMN 9
612+
#define NPP_FULL_FILE_PATH 10
613+
#define GETFILENAMEATCURSOR 11
614+
#define CURRENT_LINESTR 12
615+
616+
#define RUNCOMMAND_USER (WM_USER + 3000)
617+
562618
#define NPPM_GETFULLCURRENTPATH (RUNCOMMAND_USER + FULL_CURRENT_PATH)
563619
#define NPPM_GETCURRENTDIRECTORY (RUNCOMMAND_USER + CURRENT_DIRECTORY)
564620
#define NPPM_GETFILENAME (RUNCOMMAND_USER + FILE_NAME)
@@ -737,3 +793,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 };
737793
//scnNotification->nmhdr.code = NPPN_CMDLINEPLUGINMSG;
738794
//scnNotification->nmhdr.hwndFrom = hwndNpp;
739795
//scnNotification->nmhdr.idFrom = pluginMessage; //where pluginMessage is pointer of type wchar_t
796+
797+
#define NPPN_EXTERNALLEXERBUFFER (NPPN_FIRST + 29) // To notify lexer plugins that the buffer (in idFrom) is just applied to a external lexer
798+
//scnNotification->nmhdr.code = NPPN_EXTERNALLEXERBUFFER;
799+
//scnNotification->nmhdr.hwndFrom = hwndNpp;
800+
//scnNotification->nmhdr.idFrom = BufferID; //where pluginMessage is pointer of type wchar_t

NppPlugin/include/NppDarkMode.h

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@
1616

1717
#pragma once
1818

19-
#include <Windows.h>
20-
21-
constexpr COLORREF HEXRGB(DWORD rrggbb) {
22-
// from 0xRRGGBB like natural #RRGGBB
23-
// to the little-endian 0xBBGGRR
24-
return
25-
((rrggbb & 0xFF0000) >> 16) |
26-
((rrggbb & 0x00FF00) ) |
27-
((rrggbb & 0x0000FF) << 16);
28-
}
19+
#include <windows.h>
20+
21+
#include "Common.h" // for generic_string
2922

3023
namespace NppDarkMode
3124
{
@@ -86,16 +79,47 @@ namespace NppDarkMode
8679
dark = 2
8780
};
8881

82+
struct AdvOptDefaults
83+
{
84+
generic_string _xmlFileName;
85+
int _toolBarIconSet = -1;
86+
int _tabIconSet = -1;
87+
bool _tabUseTheme = false;
88+
};
89+
90+
struct AdvancedOptions
91+
{
92+
bool _enableWindowsMode = false;
93+
94+
NppDarkMode::AdvOptDefaults _darkDefaults{ L"DarkModeDefault.xml", 0, 2, false };
95+
NppDarkMode::AdvOptDefaults _lightDefaults{ L"", 4, 0, true };
96+
};
97+
8998
void initDarkMode(); // pulls options from NppParameters
9099
void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent
91100

101+
void initAdvancedOptions();
102+
92103
bool isEnabled();
93104
bool isDarkMenuEnabled();
94105
bool isEnabledForPlugins();
106+
bool isExperimentalActive();
95107
bool isExperimentalSupported();
96108

109+
bool isWindowsModeEnabled();
110+
void setWindowsMode(bool enable);
111+
generic_string getThemeName();
112+
void setThemeName(const generic_string& newThemeName);
113+
int getToolBarIconSet(bool useDark);
114+
void setToolBarIconSet(int state2Set, bool useDark);
115+
int getTabIconSet(bool useDark);
116+
void setTabIconSet(bool useAltIcons, bool useDark);
117+
bool useTabTheme();
118+
void setAdvancedOptions();
119+
97120
bool isWindows10();
98121
bool isWindows11();
122+
DWORD getWindowsBuildNumber();
99123

100124
COLORREF invertLightness(COLORREF c);
101125
COLORREF invertLightnessSofter(COLORREF c);
@@ -133,6 +157,8 @@ namespace NppDarkMode
133157
HPEN getHotEdgePen();
134158
HPEN getDisabledEdgePen();
135159

160+
COLORREF getIndividualTabColour(int colourIndex, bool themeDependant, bool saturated);
161+
136162
void setBackgroundColor(COLORREF c);
137163
void setSofterBackgroundColor(COLORREF c);
138164
void setHotBackgroundColor(COLORREF c);
@@ -150,7 +176,8 @@ namespace NppDarkMode
150176
void changeCustomTheme(const Colors& colors);
151177

152178
// handle events
153-
void handleSettingChange(HWND hwnd, LPARAM lParam);
179+
void handleSettingChange(HWND hwnd, LPARAM lParam, bool isFromBtn = false);
180+
bool isDarkModeReg();
154181

155182
// processes messages related to UAH / custom menubar drawing.
156183
// return true if handled, false to continue with normal processing in your wndproc
@@ -174,6 +201,8 @@ namespace NppDarkMode
174201
void subclassTabControl(HWND hwnd);
175202
void subclassComboBoxControl(HWND hwnd);
176203

204+
bool subclassTabUpDownControl(HWND hwnd);
205+
177206
void subclassAndThemeButton(HWND hwnd, NppDarkModeParams p);
178207
void subclassAndThemeComboBox(HWND hwnd, NppDarkModeParams p);
179208
void subclassAndThemeListBoxOrEditControl(HWND hwnd, NppDarkModeParams p, bool isListBox);
@@ -190,10 +219,9 @@ namespace NppDarkMode
190219
LRESULT darkTreeViewNotifyCustomDraw(LPARAM lParam);
191220

192221
void autoSubclassAndThemePluginDockWindow(HWND hwnd);
222+
ULONG autoSubclassAndThemePlugin(HWND hwnd, ULONG dmFlags);
193223
void autoSubclassAndThemeWindowNotify(HWND hwnd);
194224

195-
bool subclassTabUpDownControl(HWND hwnd);
196-
197225
void setDarkTitleBar(HWND hwnd);
198226
void setDarkExplorerTheme(HWND hwnd);
199227
void setDarkScrollBar(HWND hwnd);
@@ -204,6 +232,7 @@ namespace NppDarkMode
204232
void disableVisualStyle(HWND hwnd, bool doDisable);
205233
void calculateTreeViewStyle();
206234
void setTreeViewStyle(HWND hwnd);
235+
bool isThemeDark();
207236
void setBorder(HWND hwnd, bool border = true);
208237

209238
BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM lParam);

0 commit comments

Comments
 (0)