Skip to content

Commit

Permalink
updated with current N++ versions 8.1.4+
Browse files Browse the repository at this point in the history
  • Loading branch information
chcg committed Aug 29, 2021
1 parent b1413fd commit 1d910dd
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 63 deletions.
34 changes: 33 additions & 1 deletion Common/Ccpp/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "Common.h"
#include "Utf8.h"
//#include <Parameters.h> //MODIFIED by HEXEDIT
#include "NppDarkMode.h"
#include "NppDarkMode.h" //MODIFIED by HEXEDIT, added

void printInt(int int2print)
{
Expand Down Expand Up @@ -1301,6 +1301,15 @@ void trim(generic_string& str)
else str.erase(str.begin(), str.end());
}

bool endsWith(const generic_string& s, const generic_string& suffix)
{
#if defined(_MSVC_LANG) && (_MSVC_LANG > 201402L)
#error Replace this function with basic_string::ends_with
#endif
size_t pos = s.find(suffix);
return pos != s.npos && ((s.length() - pos) == suffix.length());
}

int nbDigitsFromNbLines(size_t nbLines)
{
int nbDigits = 0; // minimum number of digit should be 4
Expand All @@ -1323,3 +1332,26 @@ int nbDigitsFromNbLines(size_t nbLines)
}
return nbDigits;
}

generic_string getDateTimeStrFrom(const generic_string& dateTimeFormat, const SYSTEMTIME& st)
{
generic_string dateTimeStr = dateTimeFormat;
dateTimeStr = stringReplace(dateTimeStr, TEXT("Y"), std::to_wstring(st.wYear));
wchar_t buf[3];
_snwprintf(buf, sizeof(buf), TEXT("%02d"), st.wMonth);
dateTimeStr = stringReplace(dateTimeStr, TEXT("M"), buf);

_snwprintf(buf, sizeof(buf), TEXT("%02d"), st.wDay);
dateTimeStr = stringReplace(dateTimeStr, TEXT("D"), buf);

_snwprintf(buf, sizeof(buf), TEXT("%02d"), st.wHour);
dateTimeStr = stringReplace(dateTimeStr, TEXT("h"), buf);

_snwprintf(buf, sizeof(buf), TEXT("%02d"), st.wMinute);
dateTimeStr = stringReplace(dateTimeStr, TEXT("m"), buf);

_snwprintf(buf, sizeof(buf), TEXT("%02d"), st.wSecond);
dateTimeStr = stringReplace(dateTimeStr, TEXT("s"), buf);

return dateTimeStr;
}
3 changes: 3 additions & 0 deletions Common/Ccpp/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,8 @@ template<typename T> size_t vecRemoveDuplicates(std::vector<T>& vec, bool isSort
}

void trim(generic_string& str);
bool endsWith(const generic_string& s, const generic_string& suffix);

int nbDigitsFromNbLines(size_t nbLines);

generic_string getDateTimeStrFrom(const generic_string& dateTimeFormat, const SYSTEMTIME& st);
25 changes: 13 additions & 12 deletions Common/Ccpp/Notepad_plus_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum LangType {L_TEXT, L_PHP , L_C, L_CPP, L_CS, L_OBJC, L_JAVA, L_RC,\
L_ASN1, L_AVS, L_BLITZBASIC, L_PUREBASIC, L_FREEBASIC, \
L_CSOUND, L_ERLANG, L_ESCRIPT, L_FORTH, L_LATEX, \
L_MMIXAL, L_NIM, L_NNCRONTAB, L_OSCRIPT, L_REBOL, \
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG,\
L_REGISTRY, L_RUST, L_SPICE, L_TXT2TAGS, L_VISUALPROLOG, L_TYPESCRIPT,\
// Don't use L_JS, use L_JAVASCRIPT instead
// The end of enumated language type, so it should be always at the end
L_EXTERNAL};
Expand Down Expand Up @@ -346,7 +346,8 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
#define NPPM_ALLOCATEMARKER (NPPMSG + 82)
// BOOL NPPM_ALLOCATEMARKER(int numberRequested, int* startNumber)
// sets startNumber to the initial command ID if successful
// Allocates a marker number to a plugin
// Allocates a marker number to a plugin: if a plugin need to add a marker on Notepad++'s Scintilla marker margin,
// it has to use this message to get marker number, in order to prevent from the conflict with the other plugins.
// Returns: TRUE if successful, FALSE otherwise. startNumber will also be set to 0 if unsuccessful

#define NPPM_GETLANGUAGENAME (NPPMSG + 83)
Expand All @@ -365,14 +366,14 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
// You allocate a buffer of the length of (the number of characters + 1) then call NPPM_GETLANGUAGEDESC function the 2nd time
// by passing allocated buffer as argument langDesc

#define NPPM_SHOWDOCSWITCHER (NPPMSG + 85)
// VOID NPPM_SHOWDOCSWITCHER(0, BOOL toShowOrNot)
// Send this message to show or hide doc switcher.
// if toShowOrNot is TRUE then show doc switcher, otherwise hide it.
#define NPPM_SHOWDOCLIST (NPPMSG + 85)
// VOID NPPM_SHOWDOCLIST(0, BOOL toShowOrNot)
// Send this message to show or hide Document List.
// if toShowOrNot is TRUE then show Document List, otherwise hide it.

#define NPPM_ISDOCSWITCHERSHOWN (NPPMSG + 86)
// BOOL NPPM_ISDOCSWITCHERSHOWN(0, 0)
// Check to see if doc switcher is shown.
#define NPPM_ISDOCLISTSHOWN (NPPMSG + 86)
// BOOL NPPM_ISDOCLISTSHOWN(0, 0)
// Check to see if Document List is shown.

#define NPPM_GETAPPDATAPLUGINSALLOWED (NPPMSG + 87)
// BOOL NPPM_GETAPPDATAPLUGINSALLOWED(0, 0)
Expand All @@ -382,9 +383,9 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64 };
// INT NPPM_GETCURRENTVIEW(0, 0)
// Return: current edit view of Notepad++. Only 2 possible values: 0 = Main, 1 = Secondary

#define NPPM_DOCSWITCHERDISABLECOLUMN (NPPMSG + 89)
// VOID NPPM_DOCSWITCHERDISABLECOLUMN(0, BOOL disableOrNot)
// Disable or enable extension column of doc switcher
#define NPPM_DOCLISTDISABLECOLUMN (NPPMSG + 89)
// VOID NPPM_DOCLISTDISABLECOLUMN(0, BOOL disableOrNot)
// Disable or enable extension column of Document List

#define NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR (NPPMSG + 90)
// INT NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR(0, 0)
Expand Down
96 changes: 88 additions & 8 deletions Common/Ccpp/NppDarkMode.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
// This file is part of Notepad++ project
// Copyright (c) 2021 adzm / Adam D. Walling

// 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/>.

#pragma once

#include <Windows.h>
Expand All @@ -13,14 +29,26 @@ constexpr COLORREF HEXRGB(DWORD rrggbb) {

namespace NppDarkMode
{
struct Colors
{
COLORREF background = 0;
COLORREF softerBackground = 0;
COLORREF hotBackground = 0;
COLORREF pureBackground = 0;
COLORREF errorBackground = 0;
COLORREF text = 0;
COLORREF darkerText = 0;
COLORREF disabledText = 0;
COLORREF linkText = 0;
COLORREF edge = 0;
};

struct Options
{
bool enable = false;
bool enableExperimental = false;
bool enableMenubar = false;
bool enableScrollbarHack = false;
};

enum class ToolTipsType
{
tooltip,
Expand All @@ -30,16 +58,36 @@ namespace NppDarkMode
tabbar
};

enum ColorTone {
blackTone = 0,
redTone = 1,
greenTone = 2,
blueTone = 3,
purpleTone = 4,
cyanTone = 5,
oliveTone = 6,
customizedTone = 32
};

enum class TreeViewStyle
{
classic = 0,
light = 1,
dark = 2
};

void initDarkMode(); // pulls options from NppParameters
void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent

bool isEnabled();
bool isDarkMenuEnabled();
bool isExperimentalEnabled();
bool isScrollbarHackEnabled();
bool isExperimentalSupported();

COLORREF invertLightness(COLORREF c);
COLORREF invertLightnessSofter(COLORREF c);
double calculatePerceivedLighness(COLORREF c);

void setDarkTone(ColorTone colorToneChoice);

COLORREF getBackgroundColor();
COLORREF getSofterBackgroundColor();
Expand All @@ -50,6 +98,8 @@ namespace NppDarkMode
COLORREF getTextColor();
COLORREF getDarkerTextColor();
COLORREF getDisabledTextColor();
COLORREF getLinkTextColor();

COLORREF getEdgeColor();

HBRUSH getBackgroundBrush();
Expand All @@ -58,6 +108,23 @@ namespace NppDarkMode
HBRUSH getHotBackgroundBrush();
HBRUSH getErrorBackgroundBrush();

HPEN getDarkerTextPen();
HPEN getEdgePen();

void setBackgroundColor(COLORREF c);
void setSofterBackgroundColor(COLORREF c);
void setHotBackgroundColor(COLORREF c);
void setDarkerBackgroundColor(COLORREF c);
void setErrorBackgroundColor(COLORREF c);
void setTextColor(COLORREF c);
void setDarkerTextColor(COLORREF c);
void setDisabledTextColor(COLORREF c);
void setLinkTextColor(COLORREF c);
void setEdgeColor(COLORREF c);

Colors getDarkModeDefaultColors();
void changeCustomTheme(const Colors& colors);

// handle events
void handleSettingChange(HWND hwnd, LPARAM lParam);

Expand All @@ -67,10 +134,11 @@ namespace NppDarkMode
void drawUAHMenuNCBottomLine(HWND hWnd);

// from DarkMode.h
void initExperimentalDarkMode(bool fixDarkScrollbar, bool dark);
void initExperimentalDarkMode();
void setDarkMode(bool useDark, bool fixDarkScrollbar);
void allowDarkModeForApp(bool allow);
bool allowDarkModeForWindow(HWND hWnd, bool allow);
void setTitleBarThemeColor(HWND hWnd, bool dark);
void setTitleBarThemeColor(HWND hWnd);

// enhancements to DarkMode.h
void enableDarkScrollBarForWindowAndChildren(HWND hwnd);
Expand All @@ -79,13 +147,25 @@ namespace NppDarkMode
void subclassGroupboxControl(HWND hwnd);
void subclassToolbarControl(HWND hwnd);
void subclassTabControl(HWND hwnd);
void subclassComboBoxControl(HWND hwnd);

void autoSubclassAndThemeChildControls(HWND hwndParent, bool subclass = true, bool theme = true);
void autoThemeChildControls(HWND hwndParent);

void setDarkTitleBar(HWND hwnd);
void setDarkExplorerTheme(HWND hwnd);
void setDarkScrollBar(HWND hwnd);
void setDarkTooltips(HWND hwnd, ToolTipsType type);
void setDarkLineAbovePanelToolbar(HWND hwnd);
void setDarkListView(HWND hwnd);

void disableVisualStyle(HWND hwnd, bool doDisable);
void calculateTreeViewStyle();
void setTreeViewStyle(HWND hwnd);
void setBorder(HWND hwnd, bool border = true);

void setExplorerTheme(HWND hwnd, bool doEnable);
LRESULT onCtlColor(HDC hdc);
LRESULT onCtlColorSofter(HDC hdc);
LRESULT onCtlColorDarker(HDC hdc);
LRESULT onCtlColorError(HDC hdc);
}
38 changes: 0 additions & 38 deletions Common/Ccpp/StaticDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,41 +256,3 @@ INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, L
}
}

void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point)
{
RECT rc, rc2;
::GetWindowRect(handle, &rc);

point.x = rc.left;
point.y = rc.top;

switch (pos)
{
case PosAlign::left:
{
::GetWindowRect(handle2Align, &rc2);
point.x -= rc2.right - rc2.left;
break;
}
case PosAlign::right:
{
::GetWindowRect(handle, &rc2);
point.x += rc2.right - rc2.left;
break;
}
case PosAlign::top:
{
::GetWindowRect(handle2Align, &rc2);
point.y -= rc2.bottom - rc2.top;
break;
}
case PosAlign::bottom:
{
::GetWindowRect(handle, &rc2);
point.y += rc2.bottom - rc2.top;
break;
}
}

::ScreenToClient(_hSelf, &point);
}
1 change: 0 additions & 1 deletion Common/Ccpp/StaticDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,5 @@ public :
static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0;

void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point);
HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate);
};
11 changes: 8 additions & 3 deletions Common/Ccpp/menuCmdID.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
#define IDM_EDIT_SORTLINES_LEXICO_CASE_INSENS_DESCENDING (IDM_EDIT + 81)
#define IDM_EDIT_COPY_LINK (IDM_EDIT + 82)
#define IDM_EDIT_SORTLINES_REVERSE_ORDER (IDM_EDIT + 83)
#define IDM_EDIT_INSERT_DATETIME_SHORT (IDM_EDIT + 84)
#define IDM_EDIT_INSERT_DATETIME_LONG (IDM_EDIT + 85)
#define IDM_EDIT_INSERT_DATETIME_CUSTOMIZED (IDM_EDIT + 86)

#define IDM_EDIT_AUTOCOMPLETE (50000 + 0)
#define IDM_EDIT_AUTOCOMPLETE_CURRENTFILE (50000 + 1)
Expand Down Expand Up @@ -244,8 +247,8 @@
#define IDM_SEARCH_MARKONEEXT5 (IDM_SEARCH + 66)

#define IDM_MISC (IDM + 3500)
#define IDM_FILESWITCHER_FILESCLOSE (IDM_MISC + 1)
#define IDM_FILESWITCHER_FILESCLOSEOTHERS (IDM_MISC + 2)
#define IDM_DOCLIST_FILESCLOSE (IDM_MISC + 1)
#define IDM_DOCLIST_FILESCLOSEOTHERS (IDM_MISC + 2)


#define IDM_VIEW (IDM + 4000)
Expand Down Expand Up @@ -319,7 +322,7 @@
#define IDM_VIEW_UNFOLD_7 (IDM_VIEW_UNFOLD + 7)
#define IDM_VIEW_UNFOLD_8 (IDM_VIEW_UNFOLD + 8)

#define IDM_VIEW_FILESWITCHER_PANEL (IDM_VIEW + 70)
#define IDM_VIEW_DOCLIST (IDM_VIEW + 70)
#define IDM_VIEW_SWITCHTO_OTHER_VIEW (IDM_VIEW + 72)
#define IDM_EXPORT_FUNC_LIST_AND_QUIT (IDM_VIEW + 73)

Expand Down Expand Up @@ -356,6 +359,7 @@
#define IDM_VIEW_SWITCHTO_PROJECT_PANEL_3 (IDM_VIEW + 106)
#define IDM_VIEW_SWITCHTO_FILEBROWSER (IDM_VIEW + 107)
#define IDM_VIEW_SWITCHTO_FUNC_LIST (IDM_VIEW + 108)
#define IDM_VIEW_SWITCHTO_DOCLIST (IDM_VIEW + 109)

#define IDM_VIEW_GOTO_ANOTHER_VIEW 10001
#define IDM_VIEW_CLONE_TO_ANOTHER_VIEW 10002
Expand Down Expand Up @@ -516,6 +520,7 @@
#define IDM_LANG_SPICE (IDM_LANG + 81)
#define IDM_LANG_TXT2TAGS (IDM_LANG + 82)
#define IDM_LANG_VISUALPROLOG (IDM_LANG + 83)
#define IDM_LANG_TYPESCRIPT (IDM_LANG + 84)

#define IDM_LANG_EXTERNAL (IDM_LANG + 165)
#define IDM_LANG_EXTERNAL_LIMIT (IDM_LANG + 179)
Expand Down

0 comments on commit 1d910dd

Please sign in to comment.