Skip to content

Commit

Permalink
Remove legacy feature: external hot and disabled toolbar images.
Browse files Browse the repository at this point in the history
  • Loading branch information
zufuliu committed Oct 22, 2024
1 parent beffa94 commit 7752980
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 152 deletions.
5 changes: 1 addition & 4 deletions doc/Notepad4.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@
;WikiSearchUrl=https://en.wikipedia.org/wiki/Special:Search?search=%s
;CustomAction1=
;CustomAction2=
;ToolbarImage=Toolbar.bmp
[Recent Files]
[Recent Find]
[Recent Replace]
[Toolbar Images]
;BitmapDefault=Toolbar.bmp
;BitmapHot=ToolbarHot.bmp
;BitmapDisabled=ToolbarDisabled.bmp
[Custom Colors]
[Styles]
FavoriteSchemes=1 3 27 2 4 54 29 32 33 28 26 25
Expand Down
5 changes: 1 addition & 4 deletions matepath/doc/matepath.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@
;AutoRefreshRate=3000
;NoFadeHidden=0
;OpacityLevel=75
;ToolbarImage=Toolbar.bmp
[Window]
[Filters]
&All Files=*.*
&Windows Text Files=*.txt;*.asc;*.bat;*.vbs;*.ini;*.inf;*.reg
&HTML Related Files=*.htm;*.html;*.shtml;*.xml;*.php;*.css;*.js;*.vbs;*.gif;*.png;*.jpg;*.jpeg
&C/C++ Files=*.c;*.cpp;*.cxx;*.h;*.hpp;*.rc;*.ico;*.cur;*.bmp;*.txt
&No Binary Files=-*.exe;*.dll;*.cpl;*.ocx
[Toolbar Images]
;BitmapDefault=Toolbar.bmp
;BitmapHot=ToolbarHot.bmp
;BitmapDisabled=ToolbarDisabled.bmp
[Target Application]
UseTargetApplication=
TargetApplicationPath=
Expand Down
82 changes: 12 additions & 70 deletions matepath/src/matepath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ WCHAR tchFavoritesDir[MAX_PATH];
WCHAR tchOpenWithDir[MAX_PATH];
static WCHAR tchToolbarButtons[MAX_TOOLBAR_BUTTON_CONFIG_BUFFER_SIZE];
static LPWSTR tchToolbarBitmap = nullptr;
static LPWSTR tchToolbarBitmapHot = nullptr;
static LPWSTR tchToolbarBitmapDisabled = nullptr;
bool bClearReadOnly;
bool bRenameOnCollision;
bool bSingleClick;
Expand Down Expand Up @@ -235,12 +233,6 @@ static void CleanUpResources(bool initialized) noexcept {
if (tchToolbarBitmap != nullptr) {
LocalFree(tchToolbarBitmap);
}
if (tchToolbarBitmapHot != nullptr) {
LocalFree(tchToolbarBitmapHot);
}
if (tchToolbarBitmapDisabled != nullptr) {
LocalFree(tchToolbarBitmapDisabled);
}
if (hTrayIcon) {
DestroyIcon(hTrayIcon);
}
Expand Down Expand Up @@ -895,17 +887,14 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) noexcept {

SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);

bool internalBitmap = false;
// Add normal Toolbar Bitmap
HBITMAP hbmp = nullptr;
HBITMAP hbmpCopy = nullptr;
bool bExternalBitmap = false;

if (tchToolbarBitmap != nullptr) {
hbmp = LoadBitmapFile(tchToolbarBitmap);
}
if (hbmp != nullptr) {
bExternalBitmap = true;
} else {
if (hbmp == nullptr) {
internalBitmap = true;
const int resource = GetBitmapResourceIdForCurrentDPI(IDB_TOOLBAR16);
hbmp = static_cast<HBITMAP>(LoadImage(g_exeInstance, MAKEINTRESOURCE(resource), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));
}
Expand All @@ -915,54 +904,21 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) noexcept {

BITMAP bmp;
GetObject(hbmp, sizeof(BITMAP), &bmp);

HIMAGELIST himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, AsInteger<LPARAM>(himl));

// Optionally add hot Toolbar Bitmap
if (tchToolbarBitmapHot != nullptr) {
hbmp = LoadBitmapFile(tchToolbarBitmapHot);
if (hbmp != nullptr) {
if (bAutoScaleToolbar) {
hbmp = ResizeImageForCurrentDPI(hbmp);
}
GetObject(hbmp, sizeof(BITMAP), &bmp);
himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETHOTIMAGELIST, 0, AsInteger<LPARAM>(himl));
}
}

// Optionally add disabled Toolbar Bitmap
if (tchToolbarBitmapDisabled != nullptr) {
hbmp = LoadBitmapFile(tchToolbarBitmapDisabled);
if (hbmp != nullptr) {
if (bAutoScaleToolbar) {
hbmp = ResizeImageForCurrentDPI(hbmp);
}
GetObject(hbmp, sizeof(BITMAP), &bmp);
himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETDISABLEDIMAGELIST, 0, AsInteger<LPARAM>(himl));
bExternalBitmap = true;
}
}

if (!bExternalBitmap) {
if (internalBitmap) {
HBITMAP hbmpCopy = static_cast<HBITMAP>(CopyImage(hbmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));
const bool fProcessed = BitmapAlphaBlend(hbmpCopy, GetSysColor(COLOR_3DFACE), 0x60);
if (fProcessed) {
himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmpCopy, CLR_DEFAULT);
SendMessage(hwndToolbar, TB_SETDISABLEDIMAGELIST, 0, AsInteger<LPARAM>(himl));
}
}
if (hbmpCopy) {
DeleteObject(hbmpCopy);
}
DeleteObject(hbmp);

#if NP2_ENABLE_CUSTOMIZE_TOOLBAR_LABELS
// Load toolbar labels
Expand Down Expand Up @@ -2624,25 +2580,6 @@ void LoadSettings() noexcept {
bShowStatusbar = section.GetBool(L"ShowStatusbar", true);
bShowDriveBox = section.GetBool(L"ShowDriveBox", true);

// toolbar image
{
LoadIniSection(INI_SECTION_NAME_TOOLBAR_IMAGES, pIniSectionBuf, cchIniSection);
section.Parse(pIniSectionBuf);

strValue = section.GetValue(L"BitmapDefault");
if (StrNotEmpty(strValue)) {
tchToolbarBitmap = StrDup(strValue);
}
strValue = section.GetValue(L"BitmapHot");
if (StrNotEmpty(strValue)) {
tchToolbarBitmapHot = StrDup(strValue);
}
strValue = section.GetValue(L"BitmapDisabled");
if (StrNotEmpty(strValue)) {
tchToolbarBitmapDisabled = StrDup(strValue);
}
}

// window position section
{
WCHAR sectionName[96];
Expand Down Expand Up @@ -3070,8 +3007,13 @@ void LoadFlags() noexcept {
const int iValue = section.GetInt(L"OpacityLevel", 75);
iOpacityLevel = validate(iValue, 0, 100, 75);

LPCWSTR strValue = section.GetValue(L"ToolbarImage");
if (StrNotEmpty(strValue)) {
tchToolbarBitmap = StrDup(strValue);
}

if (StrIsEmpty(g_wchAppUserModelID)) {
LPCWSTR strValue = section.GetValue(L"ShellAppUserModelID");
strValue = section.GetValue(L"ShellAppUserModelID");
if (StrNotEmpty(strValue)) {
lstrcpyn(g_wchAppUserModelID, strValue, COUNTOF(g_wchAppUserModelID));
} else {
Expand Down
1 change: 0 additions & 1 deletion matepath/src/matepath.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ enum TargetApplicationMode {
#define INI_SECTION_NAME_FLAGS L"Settings2"
#define INI_SECTION_NAME_WINDOW_POSITION L"Window Position"
#define INI_SECTION_NAME_TOOLBAR_LABELS L"Toolbar Labels"
#define INI_SECTION_NAME_TOOLBAR_IMAGES L"Toolbar Images"
#define INI_SECTION_NAME_FILTERS L"Filters"
#define INI_SECTION_NAME_TARGET_APPLICATION L"Target Application"

Expand Down
85 changes: 13 additions & 72 deletions src/Notepad4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ WCHAR tchFavoritesDir[MAX_PATH];
static WCHAR tchDefaultDir[MAX_PATH];
static WCHAR tchToolbarButtons[MAX_TOOLBAR_BUTTON_CONFIG_BUFFER_SIZE];
static LPWSTR tchToolbarBitmap = nullptr;
static LPWSTR tchToolbarBitmapHot = nullptr;
static LPWSTR tchToolbarBitmapDisabled = nullptr;
static TitlePathNameFormat iPathNameFormat;
bool fWordWrapG;
int iWordWrapMode;
Expand Down Expand Up @@ -453,12 +451,6 @@ static void CleanUpResources(bool initialized) noexcept {
if (tchToolbarBitmap != nullptr) {
LocalFree(tchToolbarBitmap);
}
if (tchToolbarBitmapHot != nullptr) {
LocalFree(tchToolbarBitmapHot);
}
if (tchToolbarBitmapDisabled != nullptr) {
LocalFree(tchToolbarBitmapDisabled);
}
if (lpSchemeArg) {
LocalFree(lpSchemeArg);
}
Expand Down Expand Up @@ -1904,75 +1896,38 @@ void CreateBars(HWND hwnd, HINSTANCE hInstance) noexcept {

SendMessage(hwndToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);

bool bExternalBitmap = false;
bool internalBitmap = false;
// Add normal Toolbar Bitmap
HBITMAP hbmp = nullptr;
if (tchToolbarBitmap != nullptr) {
hbmp = LoadBitmapFile(tchToolbarBitmap);
}
if (hbmp != nullptr) {
bExternalBitmap = true;
} else {
if (hbmp == nullptr) {
internalBitmap = true;
const int resource = GetBitmapResourceIdForCurrentDPI(IDB_TOOLBAR16);
hbmp = static_cast<HBITMAP>(LoadImage(g_exeInstance, MAKEINTRESOURCE(resource), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));
}
if (bAutoScaleToolbar) {
hbmp = ResizeImageForCurrentDPI(hbmp);
}
HBITMAP hbmpCopy = nullptr;
if (!bExternalBitmap) {
hbmpCopy = static_cast<HBITMAP>(CopyImage(hbmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));
}

BITMAP bmp;
GetObject(hbmp, sizeof(BITMAP), &bmp);

HIMAGELIST himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETIMAGELIST, 0, AsInteger<LPARAM>(himl));

// Optionally add hot Toolbar Bitmap
if (tchToolbarBitmapHot != nullptr) {
hbmp = LoadBitmapFile(tchToolbarBitmapHot);
if (hbmp != nullptr) {
if (bAutoScaleToolbar) {
hbmp = ResizeImageForCurrentDPI(hbmp);
}
GetObject(hbmp, sizeof(BITMAP), &bmp);
himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETHOTIMAGELIST, 0, AsInteger<LPARAM>(himl));
}
}

// Optionally add disabled Toolbar Bitmap
if (tchToolbarBitmapDisabled != nullptr) {
hbmp = LoadBitmapFile(tchToolbarBitmapDisabled);
if (hbmp != nullptr) {
if (bAutoScaleToolbar) {
hbmp = ResizeImageForCurrentDPI(hbmp);
}
GetObject(hbmp, sizeof(BITMAP), &bmp);
himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmp, CLR_DEFAULT);
DeleteObject(hbmp);
SendMessage(hwndToolbar, TB_SETDISABLEDIMAGELIST, 0, AsInteger<LPARAM>(himl));
bExternalBitmap = true;
}
}

if (!bExternalBitmap) {
if (internalBitmap) {
HBITMAP hbmpCopy = static_cast<HBITMAP>(CopyImage(hbmp, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION));
const bool fProcessed = BitmapAlphaBlend(hbmpCopy, GetSysColor(COLOR_3DFACE), 0x60);
if (fProcessed) {
himl = ImageList_Create(bmp.bmHeight, bmp.bmHeight, ILC_COLOR32 | ILC_MASK, 0, 0);
ImageList_AddMasked(himl, hbmpCopy, CLR_DEFAULT);
SendMessage(hwndToolbar, TB_SETDISABLEDIMAGELIST, 0, AsInteger<LPARAM>(himl));
}
}
if (hbmpCopy) {
DeleteObject(hbmpCopy);
}
DeleteObject(hbmp);

#if NP2_ENABLE_CUSTOMIZE_TOOLBAR_LABELS
// Load toolbar labels
Expand Down Expand Up @@ -5423,25 +5378,6 @@ void LoadSettings() noexcept {
iFullScreenMode = iValue;
bInFullScreenMode = iValue & FullScreenMode_OnStartup;

// toolbar image section
{
LoadIniSection(INI_SECTION_NAME_TOOLBAR_IMAGES, pIniSectionBuf, cchIniSection);
section.Parse(pIniSectionBuf);

strValue = section.GetValue(L"BitmapDefault");
if (StrNotEmpty(strValue)) {
tchToolbarBitmap = StrDup(strValue);
}
strValue = section.GetValue(L"BitmapHot");
if (StrNotEmpty(strValue)) {
tchToolbarBitmapHot = StrDup(strValue);
}
strValue = section.GetValue(L"BitmapDisabled");
if (StrNotEmpty(strValue)) {
tchToolbarBitmapDisabled = StrDup(strValue);
}
}

// window position section
{
WCHAR sectionName[96];
Expand Down Expand Up @@ -6483,8 +6419,13 @@ void LoadFlags() noexcept {
fNoAutoDetection = section.GetBool(L"NoAutoDetection", false);
fNoFileVariables = section.GetBool(L"NoFileVariables", false);

LPCWSTR strValue = section.GetValue(L"ToolbarImage");
if (StrNotEmpty(strValue)) {
tchToolbarBitmap = StrDup(strValue);
}

if (StrIsEmpty(g_wchAppUserModelID)) {
LPCWSTR strValue = section.GetValue(L"ShellAppUserModelID");
strValue = section.GetValue(L"ShellAppUserModelID");
if (StrNotEmpty(strValue)) {
lstrcpyn(g_wchAppUserModelID, strValue, COUNTOF(g_wchAppUserModelID));
} else {
Expand Down
1 change: 0 additions & 1 deletion src/Notepad4.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ enum PrintFooterOption {
#define INI_SECTION_NAME_FLAGS L"Settings2"
#define INI_SECTION_NAME_WINDOW_POSITION L"Window Position"
#define INI_SECTION_NAME_TOOLBAR_LABELS L"Toolbar Labels"
#define INI_SECTION_NAME_TOOLBAR_IMAGES L"Toolbar Images"
#define INI_SECTION_NAME_SUPPRESSED_MESSAGES L"Suppressed Messages"

#define MRU_KEY_RECENT_FILES L"Recent Files"
Expand Down

0 comments on commit 7752980

Please sign in to comment.