Fix wrong plugin toolbar icon display if the ICO format is absent

An empty icon will be displayed after this fix.
This commit is contained in:
Don HO 2021-05-29 16:56:02 +02:00
parent f7a04caca7
commit 46b3e3c7b2
7 changed files with 50 additions and 62 deletions

View File

@ -90,6 +90,8 @@ void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLin
nppGUI._isCmdlineNosessionActivated = cmdLineParams->_isNoSession;
_hIconAbsent = ::LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICONABSENT));
_hSelf = ::CreateWindowEx(
WS_EX_ACCEPTFILES | (_notepad_plus_plus_core._nativeLangSpeaker.isRTL()?WS_EX_LAYOUTRTL:0),
_className,

View File

@ -16,8 +16,6 @@
#pragma once
#include "Notepad_plus.h"
const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\
\r\
notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-pPosition] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qn=\"Easter egg name\" | -qt=\"a text to display.\" | -qf=\"D:\\my quote.txt\"] [-qSpeed1|2|3] [-quickPrint] [-settingsDir=\"d:\\your settings dir\\\"] [-openFoldersAsWorkspace] [-titleAdd=\"additional title bar text\"][filePath]\r\
@ -53,9 +51,6 @@ filePath : file or folder name to open (absolute or relative path name)\r\
");
class Notepad_plus_Window : public Window
{
public:
@ -63,40 +58,39 @@ public:
bool isDlgsMsg(MSG *msg) const;
HACCEL getAccTable() const
{
HACCEL getAccTable() const {
return _notepad_plus_plus_core.getAccTable();
}
};
bool emergency(const generic_string& emergencySavedDir)
{
bool emergency(const generic_string& emergencySavedDir) {
return _notepad_plus_plus_core.emergency(emergencySavedDir);
}
};
bool isPrelaunch() const
{
bool isPrelaunch() const {
return _isPrelaunch;
}
};
void setIsPrelaunch(bool val)
{
void setIsPrelaunch(bool val) {
_isPrelaunch = val;
}
};
generic_string getPluginListVerStr() const
{
generic_string getPluginListVerStr() const {
return _notepad_plus_plus_core.getPluginListVerStr();
}
};
virtual void destroy()
{
virtual void destroy() {
if (_hIconAbsent)
::DestroyIcon(_hIconAbsent);
::DestroyWindow(_hSelf);
}
};
static const TCHAR * getClassName()
{
static const TCHAR * getClassName() {
return _className;
}
};
HICON getAbsentIcoHandle() {
return _hIconAbsent;
};
static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant
@ -112,4 +106,6 @@ private:
QuoteParams _quoteParams; // keep the availability of quote parameters for thread using
std::wstring _userQuote; // keep the availability of this string for thread using
HICON _hIconAbsent = nullptr;
};

View File

@ -2157,7 +2157,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_ADDTOOLBARICON:
{
_toolBar.registerDynBtn(static_cast<UINT>(wParam), reinterpret_cast<toolbarIcons*>(lParam));
_toolBar.registerDynBtn(static_cast<UINT>(wParam), reinterpret_cast<toolbarIcons*>(lParam), _pPublicInterface->getAbsentIcoHandle());
return TRUE;
}

View File

@ -551,11 +551,11 @@ void Gripper::drawRectangle(const POINT* pPt)
// finally ::LockWindowUpdate(NULL) will be called, to enable drawing for others again.
if (!_hdc)
{
HWND hWnd= ::GetDesktopWindow();
HWND hWnd = ::GetDesktopWindow();
#if defined (USE_LOCKWINDOWUPDATE)
_hdc= ::GetDCEx(hWnd, NULL, ::LockWindowUpdate(hWnd) ? DCX_WINDOW|DCX_CACHE|DCX_LOCKWINDOWUPDATE : DCX_WINDOW|DCX_CACHE);
_hdc = ::GetDCEx(hWnd, NULL, ::LockWindowUpdate(hWnd) ? DCX_WINDOW|DCX_CACHE|DCX_LOCKWINDOWUPDATE : DCX_WINDOW|DCX_CACHE);
#else
_hdc= ::GetDCEx(hWnd, NULL, DCX_WINDOW|DCX_CACHE);
_hdc = ::GetDCEx(hWnd, NULL, DCX_WINDOW|DCX_CACHE);
#endif
}
@ -598,25 +598,25 @@ void Gripper::drawRectangle(const POINT* pPt)
rc.right -= rc.left;
rc.bottom-= rc.top;
}
else rc= rcNew; // only new rect will be drawn
else rc = rcNew; // only new rect will be drawn
}
else rc= rcOld; // only old rect will be drawn - to erase it
else rc = rcOld; // only old rect will be drawn - to erase it
// now rc contains the rectangle wich encloses all needed, new and/or previous rectangle
// because in the following we drive within a memory device context wich is limited to rc,
// we have to localize rcNew and rcOld within rc...
//
rcOld.left= rcOld.left - rc.left;
rcOld.left = rcOld.left - rc.left;
rcOld.top = rcOld.top - rc.top;
rcNew.left= rcNew.left - rc.left;
rcNew.left = rcNew.left - rc.left;
rcNew.top = rcNew.top - rc.top;
HDC hdcMem= ::CreateCompatibleDC(_hdc);
HBITMAP hBm= ::CreateCompatibleBitmap(_hdc, rc.right, rc.bottom);
hbrushOrig= (HBRUSH)::SelectObject(hdcMem, hBm);
HDC hdcMem = ::CreateCompatibleDC(_hdc);
HBITMAP hBm = ::CreateCompatibleBitmap(_hdc, rc.right, rc.bottom);
hbrushOrig = (HBRUSH)::SelectObject(hdcMem, hBm);
::SetBrushOrgEx(hdcMem, rc.left%8, rc.top%8, 0);
hbmOrig= (HBITMAP)::SelectObject(hdcMem, _hbrush);
hbmOrig = (HBITMAP)::SelectObject(hdcMem, _hbrush);
::BitBlt(hdcMem, 0, 0, rc.right, rc.bottom, _hdc, rc.left, rc.top, SRCCOPY);
if (_bPtOldValid)
@ -641,14 +641,15 @@ void Gripper::drawRectangle(const POINT* pPt)
#if defined(USE_LOCKWINDOWUPDATE)
::LockWindowUpdate(NULL);
#endif
_bPtOldValid= FALSE;
_bPtOldValid = FALSE;
if (_hdc)
{
::ReleaseDC(0, _hdc);
_hdc= NULL;
_hdc = NULL;
}
}
else _bPtOldValid= TRUE;
else
_bPtOldValid = TRUE;
}

View File

@ -25,16 +25,6 @@
const int WS_TOOLBARSTYLE = WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS |TBSTYLE_FLAT | CCS_TOP | BTNS_AUTOSIZE | CCS_NOPARENTALIGN | CCS_NORESIZE | CCS_NODIVIDER;
ToolBar::ToolBar()
{
_hIconAbsent = (HICON)::LoadImage(_hInst, MAKEINTRESOURCE(IDI_ICONABSENT), IMAGE_ICON, 16, 16, 0);
}
ToolBar::~ToolBar()
{
::DestroyIcon(_hIconAbsent);
}
void ToolBar::initTheme(TiXmlDocument *toolIconsDocRoot)
{
_toolIcons = toolIconsDocRoot->FirstChild(TEXT("NotepadPlus"));
@ -382,7 +372,7 @@ void ToolBar::reset(bool create)
}
}
void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* tIcon)
void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* tIcon, HICON absentIco)
{
// Note: Register of buttons only possible before init!
if ((_hSelf == NULL) && (messageID != 0) && (tIcon->hToolbarBmp != NULL))
@ -390,7 +380,7 @@ void ToolBar::registerDynBtn(UINT messageID, toolbarIcons* tIcon)
DynamicCmdIcoBmp dynList;
dynList._message = messageID;
dynList._hBmp = tIcon->hToolbarBmp;
dynList._hIcon = tIcon->hToolbarIcon ? tIcon->hToolbarIcon : _hIconAbsent;
dynList._hIcon = tIcon->hToolbarIcon ? tIcon->hToolbarIcon : absentIco;
_vDynBtnReg.push_back(dynList);
}
}

View File

@ -49,8 +49,8 @@ class TiXmlNode;
class ToolBar : public Window
{
public :
ToolBar();
~ToolBar();
ToolBar() = default;
~ToolBar() = default;
void initTheme(TiXmlDocument *toolIconsDocRoot);
virtual bool init(HINSTANCE hInst, HWND hPere, toolBarStatusType type,
@ -94,7 +94,7 @@ public :
return _toolBarIcons.replaceIcon(whichLst, iconIndex, iconLocation);
};
void registerDynBtn(UINT message, toolbarIcons* hBmp);
void registerDynBtn(UINT message, toolbarIcons* hBmp, HICON absentIco);
void doPopop(POINT chevPoint); //show the popup if buttons are hidden
@ -113,7 +113,6 @@ private :
REBARBANDINFO _rbBand;
std::vector<iconLocator> _customIconVect;
TiXmlNode *_toolIcons = nullptr;
HICON _hIconAbsent = nullptr;
void setDefaultImageList() {
::SendMessage(_hSelf, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(_toolBarIcons.getDefaultLst()));

View File

@ -33,13 +33,13 @@
#define IDC_STATIC -1
#endif
#define IDI_M30ICON 100
#define IDI_CHAMELEON 101
//#define IDI_JESUISCHARLIE 102
#define IDI_M30ICON 100
#define IDI_CHAMELEON 101
//#define IDI_JESUISCHARLIE 102
//#define IDI_GILETJAUNE 102
//#define IDI_SAMESEXMARRIAGE 102
//#define IDI_SAMESEXMARRIAGE 102
#define IDR_RT_MANIFEST 103
#define IDI_ICONABSENT 104
#define IDI_ICONABSENT 104
//
// TOOLBAR ICO - set 1