Code improvement, remove unnecessary part

Fix some conversion-null, unused-* warnings, add initializer.

Fix #12151, close #12152
This commit is contained in:
ozone10 2022-09-11 21:53:09 +02:00 committed by Don Ho
parent 84b8c64944
commit 43c8d8115f
14 changed files with 36 additions and 163 deletions

View File

@ -3793,8 +3793,8 @@ void Notepad_plus::command(int id)
}
else
{
_mainEditView.execute(SCI_RESETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, NULL);
_subEditView.execute(SCI_RESETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, NULL);
_mainEditView.execute(SCI_RESETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, 0);
_subEditView.execute(SCI_RESETELEMENTCOLOUR, SC_ELEMENT_CARET_LINE_BACK, 0);
}
_mainEditView.execute(SCI_SETCARETLINEFRAME, frameWidth);

View File

@ -49,11 +49,9 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (!notifyView)
return FALSE;
static bool prevWasEdit = false;
if (notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT))
{
_pEditView->updateBeginEndSelectPosition(notification->modificationType & SC_MOD_INSERTTEXT, notification->position, notification->length);
prevWasEdit = true;
_linkTriggered = true;
::InvalidateRect(notifyView->getHSelf(), NULL, TRUE);
}
@ -64,11 +62,6 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_pEditView->getCurrentBuffer()->setModifiedStatus(true);
}
if ((notification->modificationType & SC_MOD_CHANGEFOLD) || !(notification->modificationType & (SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT)))
{
prevWasEdit = false;
}
if (notification->modificationType & SC_MOD_CHANGEINDICATOR)
{
::InvalidateRect(notifyView->getHSelf(), NULL, FALSE);
@ -161,9 +154,9 @@ BOOL Notepad_plus::notify(SCNotification *notification)
Buffer *currentBufMain = _mainEditView.getCurrentBuffer();
Buffer *currentBufSub = _subEditView.getCurrentBuffer();
RECT rect;
RECT rect{};
TabCtrl_GetItemRect(pTabDocView->getHSelf(), tbHdr->_tabOrigin, &rect);
POINT p;
POINT p{};
p.x = rect.left;
p.y = rect.bottom;
::ClientToScreen(pTabDocView->getHSelf(), &p);
@ -262,7 +255,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
}
else
{
RECT nppZone;
RECT nppZone{};
::GetWindowRect(_pPublicInterface->getHSelf(), &nppZone);
bool isInNppZone = (((p.x >= nppZone.left) && (p.x <= nppZone.right)) && (p.y >= nppZone.top) && (p.y <= nppZone.bottom));
if (isInNppZone)
@ -273,7 +266,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
generic_string quotFileName = TEXT("\"");
quotFileName += _pEditView->getCurrentBuffer()->getFullPathName();
quotFileName += TEXT("\"");
COPYDATASTRUCT fileNamesData;
COPYDATASTRUCT fileNamesData{};
fileNamesData.dwData = COPYDATA_FILENAMES;
fileNamesData.lpData = (void *)quotFileName.c_str();
fileNamesData.cbData = long(quotFileName.length() + 1)*(sizeof(TCHAR));
@ -1126,7 +1119,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
//If N++ ID, use proper object
if (lpnm->wID == REBAR_BAR_TOOLBAR)
{
POINT pt;
POINT pt{};
pt.x = lpnm->rc.left;
pt.y = lpnm->rc.bottom;
ClientToScreen(notifRebar->getHSelf(), &pt);

View File

@ -601,91 +601,6 @@ int getKwClassFromName(const TCHAR *str)
return -1;
}
size_t getAsciiLenFromBase64Len(size_t base64StrLen)
{
return (base64StrLen % 4) ? 0 : (base64StrLen - base64StrLen / 4);
}
int base64ToAscii(char *dest, const char *base64Str)
{
static const int base64IndexArray[123] =
{
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, 62, -1, -1, -1, 63,
52, 53, 54, 55 ,56, 57, 58, 59,
60, 61, -1, -1, -1, -1, -1, -1,
-1, 0, 1, 2, 3, 4, 5, 6,
7, 8, 9, 10, 11, 12, 13, 14,
15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, -1, -1, -1, -1 ,-1,
-1, 26, 27, 28, 29, 30, 31, 32,
33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48,
49, 50, 51
};
size_t b64StrLen = strlen(base64Str);
size_t nbLoop = b64StrLen / 4;
size_t i = 0;
int k = 0;
enum {b64_just, b64_1padded, b64_2padded} padd = b64_just;
for ( ; i < nbLoop ; i++)
{
size_t j = i * 4;
UCHAR uc0, uc1, uc2, uc3, p0, p1;
uc0 = (UCHAR)base64IndexArray[base64Str[j]];
uc1 = (UCHAR)base64IndexArray[base64Str[j+1]];
uc2 = (UCHAR)base64IndexArray[base64Str[j+2]];
uc3 = (UCHAR)base64IndexArray[base64Str[j+3]];
if ((static_cast<char>(uc0) == -1) || (static_cast<char>(uc1) == -1) || (static_cast<char>(uc2) == -1) || (static_cast<char>(uc3) == -1))
return -1;
if (base64Str[j+2] == '=') // && (uc3 == '=')
{
uc2 = uc3 = 0;
padd = b64_2padded;
}
else if (base64Str[j+3] == '=')
{
uc3 = 0;
padd = b64_1padded;
}
p0 = uc0 << 2;
p1 = uc1 << 2;
p1 >>= 6;
dest[k++] = p0 | p1;
p0 = uc1 << 4;
p1 = uc2 << 2;
p1 >>= 4;
dest[k++] = p0 | p1;
p0 = uc2 << 6;
p1 = uc3;
dest[k++] = p0 | p1;
}
//dest[k] = '\0';
if (padd == b64_1padded)
// dest[k-1] = '\0';
return k-1;
else if (padd == b64_2padded)
// dest[k-2] = '\0';
return k-2;
return k;
}
} // anonymous namespace

View File

@ -1686,13 +1686,13 @@ LRESULT StringDlg::customEditProc(HWND hEdit, UINT msg, WPARAM wParam, LPARAM lP
bool StringDlg::isAllowed(const generic_string & txt)
{
#ifndef __MINGW32__
for (auto ch : txt)
{
#ifndef __MINGW32__
if (std::find(_restrictedChars.cbegin(), _restrictedChars.cend(), ch) != _restrictedChars.cend())
return false;
#endif
}
#endif
return true;
}

View File

@ -978,10 +978,6 @@ const char* TiXmlAttributeA::Parse( const char* p, TiXmlParsingDataA* data )
p = SkipWhiteSpace( p );
if ( !p || !*p ) return 0;
int tabsize = 4;
if ( document )
tabsize = document->TabSize();
// TiXmlParsingDataA data( p, prevData );
if ( data )
{

View File

@ -960,10 +960,6 @@ const TCHAR* TiXmlAttribute::Parse( const TCHAR* p, TiXmlParsingData* data )
p = SkipWhiteSpace( p );
if ( !p || !*p ) return 0;
int tabsize = 4;
if ( document )
tabsize = document->TabSize();
// TiXmlParsingData data( p, prevData );
if ( data )
{

View File

@ -700,15 +700,14 @@ BrowserNodeType FileBrowser::getNodeType(HTREEITEM hItem)
void FileBrowser::showContextMenu(int x, int y)
{
TVHITTESTINFO tvHitInfo;
HTREEITEM hTreeItem;
TVHITTESTINFO tvHitInfo{};
// Detect if the given position is on the element TVITEM
tvHitInfo.pt.x = x;
tvHitInfo.pt.y = y;
tvHitInfo.flags = 0;
ScreenToClient(_treeView.getHSelf(), &(tvHitInfo.pt));
hTreeItem = TreeView_HitTest(_treeView.getHSelf(), &tvHitInfo);
TreeView_HitTest(_treeView.getHSelf(), &tvHitInfo);
if (tvHitInfo.hItem == nullptr)
{

View File

@ -946,7 +946,6 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
{
const int row = _babygrid.getSelectedRow();
size_t shortcutIndex = _shortcutIndex[row-1];
DWORD cmdID = 0;
// Menu data
int32_t posBase = 0;
@ -966,7 +965,6 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
{
vector<MacroShortcut> & theMacros = nppParam.getMacroList();
vector<MacroShortcut>::iterator it = theMacros.begin();
cmdID = theMacros[shortcutIndex].getID();
theMacros.erase(it + shortcutIndex);
//save the current view
@ -1001,7 +999,6 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
{
vector<UserCommand> & theUserCmds = nppParam.getUserCommandList();
vector<UserCommand>::iterator it = theUserCmds.begin();
cmdID = theUserCmds[shortcutIndex].getID();
theUserCmds.erase(it + shortcutIndex);
//save the current view

View File

@ -757,7 +757,7 @@ void ProjectPanel::setWorkSpaceDirty(bool isDirty)
NodeType ProjectPanel::getNodeType(HTREEITEM hItem)
{
TVITEM tvItem;
TVITEM tvItem{};
tvItem.hItem = hItem;
tvItem.mask = TVIF_IMAGE | TVIF_PARAM;
SendMessage(_treeView.getHSelf(), TVM_GETITEM, 0, reinterpret_cast<LPARAM>(&tvItem));
@ -786,15 +786,14 @@ NodeType ProjectPanel::getNodeType(HTREEITEM hItem)
void ProjectPanel::showContextMenu(int x, int y)
{
TVHITTESTINFO tvHitInfo;
HTREEITEM hTreeItem;
TVHITTESTINFO tvHitInfo{};
// Detect if the given position is on the element TVITEM
tvHitInfo.pt.x = x;
tvHitInfo.pt.y = y;
tvHitInfo.flags = 0;
ScreenToClient(_treeView.getHSelf(), &(tvHitInfo.pt));
hTreeItem = TreeView_HitTest(_treeView.getHSelf(), &tvHitInfo);
TreeView_HitTest(_treeView.getHSelf(), &tvHitInfo);
if (tvHitInfo.hItem != NULL)
{
@ -809,7 +808,7 @@ void ProjectPanel::showContextMenu(int x, int y)
void ProjectPanel::showContextMenuFromMenuKey(HTREEITEM selectedItem, int x, int y)
{
POINT p;
POINT p{};
p.x = x;
p.y = y;
@ -844,8 +843,8 @@ HMENU ProjectPanel::getMenuHandler(HTREEITEM selectedItem)
POINT ProjectPanel::getMenuDisplayPoint(int iButton)
{
POINT p;
RECT btnRect;
POINT p{};
RECT btnRect{};
SendMessage(_hToolbarMenu, TB_GETITEMRECT, iButton, reinterpret_cast<LPARAM>(&btnRect));
p.x = btnRect.left;
@ -1154,8 +1153,8 @@ void ProjectPanel::popupMenuCmd(int cmdID)
FileRelocalizerDlg fileRelocalizerDlg;
fileRelocalizerDlg.init(_hInst, _hParent);
TCHAR textBuffer[MAX_PATH];
TVITEM tvItem;
TCHAR textBuffer[MAX_PATH] = { '\0' };
TVITEM tvItem{};
tvItem.hItem = hTreeItem;
tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
tvItem.pszText = textBuffer;

View File

@ -49,7 +49,7 @@ void TabBar::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMultiLin
_isVertical = isVertical;
_isMultiLine = isMultiLine;
INITCOMMONCONTROLSEX icce;
INITCOMMONCONTROLSEX icce{};
icce.dwSize = sizeof(icce);
icce.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icce);
@ -97,7 +97,7 @@ void TabBar::destroy()
int TabBar::insertAtEnd(const TCHAR *subTabName)
{
TCITEM tie;
TCITEM tie{};
tie.mask = TCIF_TEXT | TCIF_IMAGE;
int index = -1;
@ -111,7 +111,7 @@ int TabBar::insertAtEnd(const TCHAR *subTabName)
void TabBar::getCurrentTitle(TCHAR *title, int titleLen)
{
TCITEM tci;
TCITEM tci{};
tci.mask = TCIF_TEXT;
tci.pszText = title;
tci.cchTextMax = titleLen-1;
@ -149,12 +149,6 @@ void TabBar::activateAt(int index) const
::SendMessage(_hSelf, TCM_SETCURSEL, index, 0);
}
TBHDR nmhdr;
nmhdr._hdr.hwndFrom = _hSelf;
nmhdr._hdr.code = TCN_SELCHANGE;
nmhdr._hdr.idFrom = reinterpret_cast<UINT_PTR>(this);
nmhdr._tabOrigin = index;
}
@ -166,7 +160,7 @@ void TabBar::deletItemAt(size_t index)
//Therefore, scroll one tab to the left if only one tab visible
if (_nbItem > 1)
{
RECT itemRect;
RECT itemRect{};
::SendMessage(_hSelf, TCM_GETITEMRECT, index, reinterpret_cast<LPARAM>(&itemRect));
if (itemRect.left < 5) //if last visible tab, scroll left once (no more than 5px away should be safe, usually 2px depending on the drawing)
{
@ -196,8 +190,8 @@ void TabBar::setImageList(HIMAGELIST himl)
void TabBar::reSizeTo(RECT & rc2Ajust)
{
RECT rowRect;
int rowCount, tabsHight;
RECT rowRect{};
int rowCount = 0, tabsHight = 0;
// Important to do that!
// Otherwise, the window(s) it contains will take all the resouce of CPU
@ -259,7 +253,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
_isVertical = isVertical;
_isMultiLine = isMultiLine;
INITCOMMONCONTROLSEX icce;
INITCOMMONCONTROLSEX icce{};
icce.dwSize = sizeof(icce);
icce.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&icce);
@ -331,7 +325,7 @@ void TabBarPlus::init(HINSTANCE hInst, HWND parent, bool isVertical, bool isMult
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(this));
_tabBarDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(TabBarPlus_Proc)));
LOGFONT LogFont;
LOGFONT LogFont{};
_hFont = (HFONT)::SendMessage(_hSelf, WM_GETFONT, 0, 0);
@ -424,7 +418,7 @@ void TabBarPlus::doMultiLine()
void TabBarPlus::notify(int notifyCode, int tabIndex)
{
TBHDR nmhdr;
TBHDR nmhdr{};
nmhdr._hdr.hwndFrom = _hSelf;
nmhdr._hdr.code = notifyCode;
nmhdr._hdr.idFrom = reinterpret_cast<UINT_PTR>(this);

View File

@ -22,7 +22,11 @@
int TaskListDlg::_instanceCount = 0;
LRESULT CALLBACK hookProc(int nCode, WPARAM wParam, LPARAM lParam)
static HWND hWndServer = nullptr;
static HHOOK hook = nullptr;
static winVer windowsVersion = WV_UNKNOWN;
static LRESULT CALLBACK hookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if ((nCode >= 0) && (wParam == WM_RBUTTONUP))
{

View File

@ -42,12 +42,6 @@ struct TaskListInfo {
int _currentIndex = -1;
};
static HWND hWndServer = NULL;
static HHOOK hook = NULL;
static winVer windowsVersion = WV_UNKNOWN;
static LRESULT CALLBACK hookProc(int nCode, WPARAM wParam, LPARAM lParam);
class TaskListDlg : public StaticDialog
{
public :

View File

@ -1145,13 +1145,13 @@ void WindowsMenu::initPopupMenu(HMENU hMenu, DocTabView* pTab)
if (firstId > 0 && limitId > 0 && menuPosId > 0)
{
auto curDoc = pTab->getCurrentTabIndex();
size_t nMaxDoc = limitId - firstId + 1;
size_t nMaxDoc = static_cast<size_t>(limitId) - firstId + 1;
size_t nDoc = pTab->nbItem();
nDoc = min(nDoc, nMaxDoc);
UINT id = firstId;
UINT guard = firstId + static_cast<int32_t>(nDoc);
size_t pos = 0;
for (id, pos; id < guard; ++id, ++pos)
for (; id < guard; ++id, ++pos)
{
BufferID bufID = pTab->getBufferByIndex(pos);
Buffer* buf = MainFileManager.getBufferByID(bufID);

View File

@ -669,11 +669,6 @@ void NativeLangSpeaker::changeUserDefineLang(UserDefineDialog *userDefineDlg)
const wchar_t *nameW = wmc.char2wchar(titre, _nativeLangEncoding);
::SetWindowText(hDlg, nameW);
}
// for each control
const int nbControl = 9;
const char *translatedText[nbControl];
for (int i = 0 ; i < nbControl ; ++i)
translatedText[i] = NULL;
for (TiXmlNodeA *childNode = userDefineDlgNode->FirstChildElement("Item");
childNode ;
@ -695,19 +690,10 @@ void NativeLangSpeaker::changeUserDefineLang(UserDefineDialog *userDefineDlg)
::SetWindowText(hItem, nameW);
}
}
else
{
switch(id)
{
case 0: case 1: case 2: case 3: case 4:
case 5: case 6: case 7: case 8:
translatedText[id] = name; break;
}
}
}
}
const int nbDlg = 4;
HWND hDlgArrary[nbDlg];
HWND hDlgArrary[nbDlg]{};
hDlgArrary[0] = userDefineDlg->getFolderHandle();
hDlgArrary[1] = userDefineDlg->getKeywordsHandle();
hDlgArrary[2] = userDefineDlg->getCommentHandle();