Skip to content

Commit

Permalink
Add ability to pre-populate the predefined color sets to the custom tone
Browse files Browse the repository at this point in the history
Allow to reset custom tone colors with other predefined color sets.

Fix notepad-plus-plus#15055, close notepad-plus-plus#15387
  • Loading branch information
ozone10 authored and donho committed Jul 2, 2024
1 parent c2da907 commit 5501485
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 43 deletions.
51 changes: 38 additions & 13 deletions PowerEditor/src/NppDarkMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,15 +503,15 @@ namespace NppDarkMode
g_advOptions._enableWindowsMode = enable;
}

void setThemeName(const generic_string& newThemeName)
void setThemeName(const std::wstring& newThemeName)
{
if (NppDarkMode::isEnabled())
g_advOptions._darkDefaults._xmlFileName = newThemeName;
else
g_advOptions._lightDefaults._xmlFileName = newThemeName;
}

generic_string getThemeName()
std::wstring getThemeName()
{
auto& theme = NppDarkMode::isEnabled() ? g_advOptions._darkDefaults._xmlFileName : g_advOptions._lightDefaults._xmlFileName;
return (lstrcmp(theme.c_str(), L"stylers.xml") == 0) ? L"" : theme;
Expand Down Expand Up @@ -728,11 +728,36 @@ namespace NppDarkMode
getTheme().change(clrs);
}

Colors getDarkModeDefaultColors()
Colors getDarkModeDefaultColors(ColorTone colorTone)
{
return darkColors;
switch (colorTone)
{
case NppDarkMode::ColorTone::redTone:
return darkRedColors;

case NppDarkMode::ColorTone::greenTone:
return darkGreenColors;

case NppDarkMode::ColorTone::blueTone:
return darkBlueColors;

case NppDarkMode::ColorTone::purpleTone:
return darkPurpleColors;

case NppDarkMode::ColorTone::cyanTone:
return darkCyanColors;

case NppDarkMode::ColorTone::oliveTone:
return darkOliveColors;

case NppDarkMode::ColorTone::customizedTone:
case NppDarkMode::ColorTone::blackTone:
default:
return darkColors;
}
}


void changeCustomTheme(const Colors& colors)
{
tCustom.change(colors);
Expand Down Expand Up @@ -1612,7 +1637,7 @@ namespace NppDarkMode

SetBkMode(hdc, TRANSPARENT);

TCHAR label[MAX_PATH]{};
wchar_t label[MAX_PATH]{};
TCITEM tci{};
tci.mask = TCIF_TEXT;
tci.pszText = label;
Expand Down Expand Up @@ -1971,7 +1996,7 @@ namespace NppDarkMode
::SetTextColor(hdc, isWindowEnabled ? NppDarkMode::getTextColor() : NppDarkMode::getDisabledTextColor());
::SetBkColor(hdc, NppDarkMode::getBackgroundColor());
auto bufferLen = static_cast<size_t>(::SendMessage(hWnd, CB_GETLBTEXTLEN, index, 0));
TCHAR* buffer = new TCHAR[(bufferLen + 1)];
wchar_t* buffer = new wchar_t[(bufferLen + 1)];
::SendMessage(hWnd, CB_GETLBTEXT, index, reinterpret_cast<LPARAM>(buffer));

RECT rcText = rcTextBg;
Expand Down Expand Up @@ -2002,7 +2027,7 @@ namespace NppDarkMode
::SetTextColor(hdc, isWindowEnabled ? colorEnabledText : NppDarkMode::getDisabledTextColor());
::SetBkColor(hdc, isHot ? NppDarkMode::getHotBackgroundColor() : NppDarkMode::getBackgroundColor());
::FillRect(hdc, &rcArrow, isHot ? NppDarkMode::getHotBackgroundBrush() : NppDarkMode::getBackgroundBrush());
TCHAR arrow[] = L"˅";
wchar_t arrow[] = L"˅";
::DrawText(hdc, arrow, -1, &rcArrow, DT_NOPREFIX | DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOCLIP);
::SetBkColor(hdc, NppDarkMode::getBackgroundColor());

Expand Down Expand Up @@ -2275,7 +2300,7 @@ namespace NppDarkMode
bool subclassTabUpDownControl(HWND hwnd)
{
constexpr size_t classNameLen = 16;
TCHAR className[classNameLen]{};
wchar_t className[classNameLen]{};
GetClassName(hwnd, className, classNameLen);
if (wcscmp(className, UPDOWN_CLASS) == 0)
{
Expand All @@ -2301,7 +2326,7 @@ namespace NppDarkMode
EnumChildWindows(hwndParent, [](HWND hwnd, LPARAM lParam) WINAPI_LAMBDA {
auto& p = *reinterpret_cast<NppDarkModeParams*>(lParam);
constexpr size_t classNameLen = 32;
TCHAR className[classNameLen]{};
wchar_t className[classNameLen]{};
GetClassName(hwnd, className, classNameLen);

if (wcscmp(className, WC_BUTTON) == 0)
Expand Down Expand Up @@ -2881,7 +2906,7 @@ namespace NppDarkMode
if (NppDarkMode::isEnabled())
{
constexpr size_t classNameLen = 16;
TCHAR className[classNameLen]{};
wchar_t className[classNameLen]{};
auto hwndEdit = reinterpret_cast<HWND>(lParam);
GetClassName(hwndEdit, className, classNameLen);
if (wcscmp(className, WC_EDIT) == 0)
Expand Down Expand Up @@ -2910,7 +2935,7 @@ namespace NppDarkMode
case NM_CUSTOMDRAW:
{
constexpr size_t classNameLen = 16;
TCHAR className[classNameLen]{};
wchar_t className[classNameLen]{};
GetClassName(nmhdr->hwndFrom, className, classNameLen);

if (wcscmp(className, TOOLBARCLASSNAME) == 0)
Expand Down Expand Up @@ -3059,7 +3084,7 @@ namespace NppDarkMode
auto nmhdr = reinterpret_cast<LPNMHDR>(lParam);

constexpr size_t classNameLen = 16;
TCHAR className[classNameLen]{};
wchar_t className[classNameLen]{};
GetClassName(nmhdr->hwndFrom, className, classNameLen);

switch (nmhdr->code)
Expand Down Expand Up @@ -3305,7 +3330,7 @@ namespace NppDarkMode
static BOOL CALLBACK enumAutocompleteProc(HWND hwnd, LPARAM /*lParam*/)
{
constexpr size_t classNameLen = 16;
TCHAR className[classNameLen]{};
wchar_t className[classNameLen]{};
GetClassName(hwnd, className, classNameLen);
if ((wcscmp(className, L"ListBoxX") == 0))
{
Expand Down
10 changes: 5 additions & 5 deletions PowerEditor/src/NppDarkMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#pragma once

#include <string>
#include <windows.h>

#include "Common.h" // for generic_string

namespace NppDarkMode
{
Expand Down Expand Up @@ -81,7 +81,7 @@ namespace NppDarkMode

struct AdvOptDefaults
{
generic_string _xmlFileName;
std::wstring _xmlFileName;
int _toolBarIconSet = -1;
int _tabIconSet = -1;
bool _tabUseTheme = false;
Expand Down Expand Up @@ -110,8 +110,8 @@ namespace NppDarkMode

bool isWindowsModeEnabled();
void setWindowsMode(bool enable);
generic_string getThemeName();
void setThemeName(const generic_string& newThemeName);
std::wstring getThemeName();
void setThemeName(const std::wstring& newThemeName);
int getToolBarIconSet(bool useDark);
void setToolBarIconSet(int state2Set, bool useDark);
int getTabIconSet(bool useDark);
Expand Down Expand Up @@ -173,7 +173,7 @@ namespace NppDarkMode
void setHotEdgeColor(COLORREF c);
void setDisabledEdgeColor(COLORREF c);

Colors getDarkModeDefaultColors();
Colors getDarkModeDefaultColors(ColorTone colorTone = ColorTone::blackTone);
void changeCustomTheme(const Colors& colors);

// handle events
Expand Down
51 changes: 34 additions & 17 deletions PowerEditor/src/WinControls/ContextMenu/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "Parameters.h"
#include "localization.h"

MenuItemUnit::MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName) : _cmdID(cmdID)
MenuItemUnit::MenuItemUnit(unsigned long cmdID, const wchar_t* itemName, const wchar_t* parentFolderName) : _cmdID(cmdID)
{
if (!itemName)
_itemName.clear();
Expand All @@ -33,27 +33,15 @@ MenuItemUnit::MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCH
_parentFolderName = parentFolderName;
}


ContextMenu::~ContextMenu()
{
if (isCreated())
{
for (size_t i = 0, len = _subMenus.size(); i < len; ++i)
::DestroyMenu(_subMenus[i]);
::DestroyMenu(_hMenu);
}
}


void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle, bool copyLink)
{
_hParent = hParent;
_hMenu = ::CreatePopupMenu();
bool lastIsSep = false;
HMENU hParentFolder = NULL;
generic_string currentParentFolderStr;
std::wstring currentParentFolderStr;
int j = 0;
MENUITEMINFO mii;
MENUITEMINFO mii{};

for (size_t i = 0, len = menuItemArray.size(); i < len; ++i)
{
Expand Down Expand Up @@ -127,17 +115,46 @@ void ContextMenu::create(HWND hParent, const std::vector<MenuItemUnit> & menuIte
if (copyLink && (item._cmdID == IDM_EDIT_COPY))
{
NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
generic_string localized = nativeLangSpeaker->getNativeLangMenuString(IDM_EDIT_COPY_LINK);
std::wstring localized = nativeLangSpeaker->getNativeLangMenuString(IDM_EDIT_COPY_LINK);
if (localized.length() == 0)
localized = L"Copy link";
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_ID | MIIM_STRING | MIIM_STATE;
mii.wID = IDM_EDIT_COPY_LINK;
mii.dwTypeData = (TCHAR*) localized.c_str();
mii.dwTypeData = (wchar_t*) localized.c_str();
mii.fState = MFS_ENABLED;
int c = GetMenuItemCount(_hMenu);
SetMenuItemInfo(_hMenu, c - 1, TRUE, & mii);
}
}
}

void ContextMenu::display(HWND hwnd) const
{
RECT rcItem{};
::GetClientRect(hwnd, &rcItem);
::MapWindowPoints(hwnd, HWND_DESKTOP, reinterpret_cast<LPPOINT>(&rcItem), 2);

TPMPARAMS tpm{};
tpm.cbSize = sizeof(TPMPARAMS);
tpm.rcExclude = rcItem;

const NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
const UINT flags = nativeLangSpeaker->isRTL() ? (TPM_RIGHTALIGN | TPM_RIGHTBUTTON | TPM_LAYOUTRTL) : (TPM_LEFTALIGN | TPM_LEFTBUTTON);
::TrackPopupMenuEx(_hMenu, flags | TPM_VERTICAL, rcItem.left, rcItem.bottom, _hParent, &tpm);
}

void ContextMenu::destroy()
{
if (isCreated())
{
for (size_t i = 0, len = _subMenus.size(); i < len; ++i)
{
::DestroyMenu(_subMenus[i]);
_subMenus[i] = nullptr;
}
::DestroyMenu(_hMenu);
_hMenu = nullptr;
}
}
17 changes: 11 additions & 6 deletions PowerEditor/src/WinControls/ContextMenu/ContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@
struct MenuItemUnit final
{
unsigned long _cmdID = 0;
generic_string _itemName;
generic_string _parentFolderName;
std::wstring _itemName;
std::wstring _parentFolderName;

MenuItemUnit() = default;
MenuItemUnit(unsigned long cmdID, const generic_string& itemName, const generic_string& parentFolderName = generic_string())
MenuItemUnit(unsigned long cmdID, const std::wstring& itemName, const std::wstring& parentFolderName = std::wstring())
: _cmdID(cmdID), _itemName(itemName), _parentFolderName(parentFolderName){};
MenuItemUnit(unsigned long cmdID, const TCHAR *itemName, const TCHAR *parentFolderName = nullptr);
MenuItemUnit(unsigned long cmdID, const wchar_t* itemName, const wchar_t* parentFolderName = nullptr);
};


class ContextMenu final
{
public:
~ContextMenu();
~ContextMenu() {
destroy();
}

void create(HWND hParent, const std::vector<MenuItemUnit> & menuItemArray, const HMENU mainMenuHandle = NULL, bool copyLink = false);
bool isCreated() const {return _hMenu != NULL;}
Expand All @@ -43,6 +45,8 @@ class ContextMenu final
::TrackPopupMenu(_hMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hParent, NULL);
}

void display(HWND hwnd) const;

void enableItem(int cmdID, bool doEnable) const
{
int flag = doEnable ? (MF_ENABLED | MF_BYCOMMAND) : (MF_DISABLED | MF_GRAYED | MF_BYCOMMAND);
Expand All @@ -59,9 +63,10 @@ class ContextMenu final
return _hMenu;
}

void destroy();

private:
HWND _hParent = NULL;
HMENU _hMenu = NULL;
std::vector<HMENU> _subMenus;

};
2 changes: 1 addition & 1 deletion PowerEditor/src/WinControls/Preference/preference.rc
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ BEGIN
LTEXT "Edge",IDD_CUSTOMIZED_COLOR9_STATIC,342,80,94,8
LTEXT "Edge highlight",IDD_CUSTOMIZED_COLOR11_STATIC,342,100,94,8
LTEXT "Edge disabled",IDD_CUSTOMIZED_COLOR12_STATIC,342,120,94,8
PUSHBUTTON "Reset",IDD_CUSTOMIZED_RESET_BUTTON,340,158,45,14
CONTROL "Reset",IDD_CUSTOMIZED_RESET_BUTTON,"Button",BS_SPLITBUTTON | WS_TABSTOP,330,158,65,14
END


Expand Down
Loading

0 comments on commit 5501485

Please sign in to comment.