Remove unneeded subclass

Fix #12086, close #12087
This commit is contained in:
ozone10 2022-09-02 15:24:21 +02:00 committed by Don Ho
parent 95cb564c27
commit 4ddd2d4a46
8 changed files with 24 additions and 86 deletions

View File

@ -26,7 +26,7 @@ using namespace std;
void ListView::init(HINSTANCE hInst, HWND parent)
{
Window::init(hInst, parent);
INITCOMMONCONTROLSEX icex;
INITCOMMONCONTROLSEX icex{};
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
@ -54,16 +54,13 @@ void ListView::init(HINSTANCE hInst, HWND parent)
throw std::runtime_error("ListView::init : CreateWindowEx() function return null");
}
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(staticProc)));
DWORD exStyle = ListView_GetExtendedListViewStyle(_hSelf);
exStyle |= LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT | LVS_EX_DOUBLEBUFFER | _extraStyle;
ListView_SetExtendedListViewStyle(_hSelf, exStyle);
if (_columnInfos.size())
{
LVCOLUMN lvColumn;
LVCOLUMN lvColumn{};
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH;
short i = 0;
@ -92,7 +89,7 @@ void ListView::addLine(const vector<generic_string> & values2Add, LPARAM lParam,
auto it = values2Add.begin();
LVITEM item;
LVITEM item{};
item.mask = LVIF_TEXT | LVIF_PARAM;
item.pszText = const_cast<TCHAR *>(it->c_str());
@ -143,7 +140,7 @@ size_t ListView::findAlphabeticalOrderPos(const generic_string& string2Cmp, Sort
LPARAM ListView::getLParamFromIndex(int itemIndex) const
{
LVITEM item;
LVITEM item{};
item.mask = LVIF_PARAM;
item.iItem = itemIndex;
ListView_GetItem(_hSelf, &item);
@ -163,9 +160,3 @@ std::vector<size_t> ListView::getCheckedIndexes() const
}
return checkedIndexes;
}
LRESULT ListView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}

View File

@ -45,7 +45,7 @@ public:
};
void setColumnText(size_t i, generic_string txt2Set) {
LVCOLUMN lvColumn;
LVCOLUMN lvColumn{};
lvColumn.mask = LVCF_TEXT;
lvColumn.pszText = const_cast<TCHAR *>(txt2Set.c_str());
ListView_SetColumn(_hSelf, i, &lvColumn);
@ -90,14 +90,6 @@ public:
protected:
WNDPROC _defaultProc = nullptr;
int32_t _extraStyle = 0;
std::vector<columnInfo> _columnInfos;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((ListView *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
};
};

View File

@ -34,9 +34,6 @@ void ToolTip::init(HINSTANCE hInst, HWND hParent)
}
NppDarkMode::setDarkTooltips(_hSelf, NppDarkMode::ToolTipsType::tooltip);
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(staticWinProc)));
}
}
@ -70,10 +67,3 @@ void ToolTip::Show(RECT rectTitle, const TCHAR * pszTitle, int iXOff, int iWidth
::SendMessage(_hSelf, TTM_TRACKPOSITION, 0, MAKELONG(_ti.rect.left + iXOff, _ti.rect.top + iWidthOff));
::SendMessage(_hSelf, TTM_TRACKACTIVATE, true, reinterpret_cast<LPARAM>(&_ti));
}
LRESULT ToolTip::runProc(UINT message, WPARAM wParam, LPARAM lParam)
{
return ::CallWindowProc(_defaultProc, _hSelf, message, wParam, lParam);
}

View File

@ -35,13 +35,6 @@ public:
void Show(RECT rectTitle, const TCHAR* pszTitleText, int iXOff = 0, int iWidthOff = 0);
protected:
WNDPROC _defaultProc = nullptr;
BOOL _bTrackMouse = FALSE;
TOOLINFO _ti = {};
static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((ToolTip *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(Message, wParam, lParam));
};
LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam);
};

View File

@ -24,7 +24,7 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST
{
Window::init(hInst, parent);
_hImaLst = hImaLst;
INITCOMMONCONTROLSEX icex;
INITCOMMONCONTROLSEX icex{};
// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
@ -51,9 +51,6 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST
throw std::runtime_error("VerticalFileSwitcherListView::init : CreateWindowEx() function return null");
}
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(staticProc)));
ListView_SetExtendedListViewStyle(_hSelf, LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT | LVS_EX_INFOTIP | LVS_EX_DOUBLEBUFFER);
ListView_SetItemCountEx(_hSelf, 50, LVSICF_NOSCROLL);
ListView_SetImageList(_hSelf, _hImaLst, LVSIL_SMALL);
@ -61,7 +58,7 @@ void VerticalFileSwitcherListView::init(HINSTANCE hInst, HWND parent, HIMAGELIST
void VerticalFileSwitcherListView::destroy()
{
LVITEM item;
LVITEM item{};
item.mask = LVIF_PARAM;
int nbItem = ListView_GetItemCount(_hSelf);
for (int i = 0 ; i < nbItem ; ++i)
@ -75,11 +72,6 @@ void VerticalFileSwitcherListView::destroy()
_hSelf = NULL;
}
LRESULT VerticalFileSwitcherListView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}
void VerticalFileSwitcherListView::initList()
{
NppParameters& nppParams = NppParameters::getInstance();
@ -88,7 +80,7 @@ void VerticalFileSwitcherListView::initList()
bool isExtColumn = !nppParams.getNppGUI()._fileSwitcherWithoutExtColumn;
bool isPathColumn = !nppParams.getNppGUI()._fileSwitcherWithoutPathColumn;
RECT rc;
RECT rc{};
::GetClientRect(_hParent, &rc);
int nameWidth = rc.right - rc.left;
int colIndex = 0;
@ -121,14 +113,14 @@ void VerticalFileSwitcherListView::initList()
TaskLstFnStatus *tl = new TaskLstFnStatus(fileNameStatus._iView, fileNameStatus._docIndex, fileNameStatus._fn, fileNameStatus._status, (void *)fileNameStatus._bufID);
TCHAR fn[MAX_PATH];
TCHAR fn[MAX_PATH] = { '\0' };
wcscpy_s(fn, ::PathFindFileName(fileNameStatus._fn.c_str()));
if (isExtColumn)
{
::PathRemoveExtension(fn);
}
LVITEM item;
LVITEM item{};
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
item.pszText = fn;
@ -144,7 +136,7 @@ void VerticalFileSwitcherListView::initList()
}
if (isPathColumn)
{
TCHAR dir[MAX_PATH], drive[MAX_PATH];
TCHAR dir[MAX_PATH] = { '\0' }, drive[MAX_PATH] = { '\0' };
_wsplitpath_s(fileNameStatus._fn.c_str(), drive, MAX_PATH, dir, MAX_PATH, NULL, 0, NULL, 0);
wcscat_s(drive, dir);
ListView_SetItemText(_hSelf, i, ++colIndex, drive);
@ -160,7 +152,7 @@ void VerticalFileSwitcherListView::reload()
removeAll();
initList();
RECT rc;
RECT rc{};
::GetClientRect(_hParent, &rc);
resizeColumns(rc.right - rc.left);
}
@ -171,7 +163,7 @@ BufferID VerticalFileSwitcherListView::getBufferInfoFromIndex(int index, int & v
if (index < 0 || index >= nbItem)
return BUFFER_INVALID;
LVITEM item;
LVITEM item{};
item.mask = LVIF_PARAM;
item.iItem = index;
ListView_GetItem(_hSelf, &item);
@ -195,7 +187,7 @@ void VerticalFileSwitcherListView::setItemIconStatus(BufferID bufferID)
{
Buffer *buf = static_cast<Buffer *>(bufferID);
TCHAR fn[MAX_PATH];
TCHAR fn[MAX_PATH] = { '\0' };
wcscpy_s(fn, ::PathFindFileName(buf->getFileName()));
bool isExtColumn = !(NppParameters::getInstance()).getNppGUI()._fileSwitcherWithoutExtColumn;
bool isPathColumn = !(NppParameters::getInstance()).getNppGUI()._fileSwitcherWithoutPathColumn;
@ -203,7 +195,7 @@ void VerticalFileSwitcherListView::setItemIconStatus(BufferID bufferID)
{
::PathRemoveExtension(fn);
}
LVITEM item;
LVITEM item{};
item.pszText = fn;
item.iSubItem = 0;
item.iImage = buf->isMonitoringOn()?3:(buf->isReadOnly()?2:(buf->isDirty()?1:0));
@ -228,7 +220,7 @@ void VerticalFileSwitcherListView::setItemIconStatus(BufferID bufferID)
}
if (isPathColumn)
{
TCHAR dir[MAX_PATH], drive[MAX_PATH];
TCHAR dir[MAX_PATH] = { '\0' }, drive[MAX_PATH] = { '\0' };
_wsplitpath_s(buf->getFullPathName(), drive, MAX_PATH, dir, MAX_PATH, NULL, 0, NULL, 0);
wcscat_s(drive, dir);
ListView_SetItemText(_hSelf, i, ++colIndex, drive);
@ -243,7 +235,7 @@ generic_string VerticalFileSwitcherListView::getFullFilePath(size_t i) const
if (i > nbItem)
return TEXT("");
LVITEM item;
LVITEM item{};
item.mask = LVIF_PARAM;
item.iItem = static_cast<int32_t>(i);
ListView_GetItem(_hSelf, &item);
@ -280,7 +272,7 @@ int VerticalFileSwitcherListView::add(BufferID bufferID, int iView)
NppGUI& nppGUI = NppParameters::getInstance().getNppGUI();
TaskLstFnStatus *tl = new TaskLstFnStatus(iView, 0, buf->getFullPathName(), 0, (void *)bufferID);
TCHAR fn[MAX_PATH];
TCHAR fn[MAX_PATH] = { '\0' };
wcscpy_s(fn, ::PathFindFileName(fileName));
bool isExtColumn = !nppGUI._fileSwitcherWithoutExtColumn;
bool isPathColumn = !nppGUI._fileSwitcherWithoutPathColumn;
@ -288,7 +280,7 @@ int VerticalFileSwitcherListView::add(BufferID bufferID, int iView)
{
::PathRemoveExtension(fn);
}
LVITEM item;
LVITEM item{};
item.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;
item.pszText = fn;
@ -304,7 +296,7 @@ int VerticalFileSwitcherListView::add(BufferID bufferID, int iView)
}
if (isPathColumn)
{
TCHAR dir[MAX_PATH], drive[MAX_PATH];
TCHAR dir[MAX_PATH] = { '\0' }, drive[MAX_PATH] = { '\0' };
_wsplitpath_s(buf->getFullPathName(), drive, MAX_PATH, dir, MAX_PATH, NULL, 0, NULL, 0);
wcscat_s(drive, dir);
ListView_SetItemText(_hSelf, _currentIndex, ++colIndex, drive);
@ -317,7 +309,7 @@ int VerticalFileSwitcherListView::add(BufferID bufferID, int iView)
void VerticalFileSwitcherListView::remove(int index)
{
LVITEM item;
LVITEM item{};
item.mask = LVIF_PARAM;
item.iItem = index;
ListView_GetItem(_hSelf, &item);
@ -346,7 +338,7 @@ void VerticalFileSwitcherListView::removeAll()
int VerticalFileSwitcherListView::find(BufferID bufferID, int iView) const
{
LVITEM item;
LVITEM item{};
bool found = false;
int nbItem = ListView_GetItemCount(_hSelf);
int i = 0;
@ -367,7 +359,7 @@ int VerticalFileSwitcherListView::find(BufferID bufferID, int iView) const
void VerticalFileSwitcherListView::insertColumn(const TCHAR *name, int width, int index)
{
LVCOLUMN lvColumn;
LVCOLUMN lvColumn{};
lvColumn.mask = LVCF_TEXT | LVCF_WIDTH;
lvColumn.cx = width;
@ -403,7 +395,7 @@ void VerticalFileSwitcherListView::resizeColumns(int totalWidth)
std::vector<SwitcherFileInfo> VerticalFileSwitcherListView::getSelectedFiles(bool reverse) const
{
std::vector<SwitcherFileInfo> files;
LVITEM item;
LVITEM item{};
int nbItem = ListView_GetItemCount(_hSelf);
int i = 0;
for (; i < nbItem ; ++i)

View File

@ -87,16 +87,9 @@ public:
protected:
HIMAGELIST _hImaLst = nullptr;
WNDPROC _defaultProc = nullptr;
int _currentIndex = 0;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((VerticalFileSwitcherListView *)(::GetWindowLongPtr(hwnd, GWLP_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
};
int find(BufferID bufferID, int iView) const;
int add(BufferID bufferID, int iView);
void remove(int index);

View File

@ -239,8 +239,6 @@ BEGIN_WINDOW_MAP(WindowsDlgMap)
ENDGROUP()
END_WINDOW_MAP()
LONG_PTR WindowsDlg::originalListViewProc = NULL;
RECT WindowsDlg::_lastKnownLocation;
WindowsDlg::WindowsDlg() : MyBaseClass(WindowsDlgMap)
@ -591,8 +589,6 @@ BOOL WindowsDlg::onInitDialog()
ListView_SetTextBkColor(_hList, bgColor);
ListView_SetTextColor(_hList, fgColor);
originalListViewProc = ::SetWindowLongPtr(_hList, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(listViewProc));
RECT rc;
GetClientRect(_hList, &rc);
LONG width = rc.right - rc.left;
@ -1112,12 +1108,6 @@ Buffer* WindowsDlg::getBuffer(int index) const
return MainFileManager.getBufferByID(bufID);
}
LRESULT CALLBACK WindowsDlg::listViewProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
return CallWindowProc(reinterpret_cast<WNDPROC>(originalListViewProc), hwnd, Message, wParam, lParam);
}
void WindowsMenu::init(HMENU hMainMenu)
{
_hMenu = ::GetSubMenu(hMainMenu, MENUINDEX_WINDOW);

View File

@ -88,9 +88,6 @@ protected :
void putItemsToClipboard(bool isFullPath);
Buffer* getBuffer(int index) const;
static LONG_PTR originalListViewProc;
static LRESULT CALLBACK listViewProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
HWND _hList = nullptr;
static RECT _lastKnownLocation;
SIZE _szMinButton = {};