Some code enhancements

This commit is contained in:
Don HO 2016-07-11 01:07:01 +02:00
parent 1e38c628bc
commit 2573f4b492
6 changed files with 16 additions and 40 deletions

View File

@ -2434,10 +2434,9 @@ int Notepad_plus::findMachedBracePos(size_t startPos, size_t endPos, char target
if (startPos == endPos) if (startPos == endPos)
return -1; return -1;
int balance = 0;
if (startPos > endPos) // backward if (startPos > endPos) // backward
{ {
int balance = 0;
for (int i = int(startPos); i >= int(endPos); --i) for (int i = int(startPos); i >= int(endPos); --i)
{ {
char aChar = (char)_pEditView->execute(SCI_GETCHARAT, i); char aChar = (char)_pEditView->execute(SCI_GETCHARAT, i);
@ -4985,7 +4984,6 @@ void Notepad_plus::loadCommandlineParams(const TCHAR * commandLine, CmdLineParam
NppParameters *nppParams = NppParameters::getInstance(); NppParameters *nppParams = NppParameters::getInstance();
FileNameStringSplitter fnss(commandLine); FileNameStringSplitter fnss(commandLine);
const TCHAR *pFn = NULL;
// loading file as session file is allowed only when there is only one file // loading file as session file is allowed only when there is only one file
if (pCmdParams->_isSessionFile && fnss.size() == 1) if (pCmdParams->_isSessionFile && fnss.size() == 1)
@ -5008,7 +5006,7 @@ void Notepad_plus::loadCommandlineParams(const TCHAR * commandLine, CmdLineParam
BufferID lastOpened = BUFFER_INVALID; BufferID lastOpened = BUFFER_INVALID;
for (int i = 0, len = fnss.size(); i < len ; ++i) for (int i = 0, len = fnss.size(); i < len ; ++i)
{ {
pFn = fnss.getFileName(i); const TCHAR *pFn = fnss.getFileName(i);
if (!pFn) return; if (!pFn) return;
BufferID bufID = doOpen(pFn, recursive, readOnly); BufferID bufID = doOpen(pFn, recursive, readOnly);

View File

@ -2874,10 +2874,9 @@ void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMa
size_t size = scintKeyMap.getSize(); size_t size = scintKeyMap.getSize();
if (size > 1) if (size > 1)
{ {
TiXmlNode * keyNext;
for (size_t i = 1; i < size; ++i) for (size_t i = 1; i < size; ++i)
{ {
keyNext = keyRoot->InsertEndChild(TiXmlElement(TEXT("NextKey"))); TiXmlNode *keyNext = keyRoot->InsertEndChild(TiXmlElement(TEXT("NextKey")));
key = scintKeyMap.getKeyComboByIndex(i); key = scintKeyMap.getKeyComboByIndex(i);
keyNext->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no")); keyNext->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?TEXT("yes"):TEXT("no"));
keyNext->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no")); keyNext->ToElement()->SetAttribute(TEXT("Alt"), key._isAlt?TEXT("yes"):TEXT("no"));
@ -3112,11 +3111,10 @@ void NppParameters::feedUserKeywordList(TiXmlNode *node)
childNode = childNode->NextSibling(TEXT("Keywords"))) childNode = childNode->NextSibling(TEXT("Keywords")))
{ {
const TCHAR * keywordsName = (childNode->ToElement())->Attribute(TEXT("name")); const TCHAR * keywordsName = (childNode->ToElement())->Attribute(TEXT("name"));
TCHAR *kwl = nullptr;
TiXmlNode *valueNode = childNode->FirstChild(); TiXmlNode *valueNode = childNode->FirstChild();
if (valueNode) if (valueNode)
{ {
TCHAR *kwl = nullptr;
if (!lstrcmp(udlVersion, TEXT("")) && !lstrcmp(keywordsName, TEXT("Delimiters"))) // support for old style (pre 2.0) if (!lstrcmp(udlVersion, TEXT("")) && !lstrcmp(keywordsName, TEXT("Delimiters"))) // support for old style (pre 2.0)
{ {
basic_string<TCHAR> temp; basic_string<TCHAR> temp;
@ -4235,7 +4233,6 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
int g5 = 0; // up to 48 int g5 = 0; // up to 48
int g6 = 0; // up to 56 int g6 = 0; // up to 56
int g7 = 0; // up to 64 int g7 = 0; // up to 64
const int nbMax = 64;
// TODO some refactoring needed here.... // TODO some refactoring needed here....
{ {
@ -4282,10 +4279,6 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
} }
} }
bool langArray[nbMax];
for (int i = 0 ; i < nbMax ; ++i)
langArray[i] = false;
UCHAR mask = 1; UCHAR mask = 1;
for (int i = 0 ; i < 8 ; ++i) for (int i = 0 ; i < 8 ; ++i)
{ {
@ -4566,7 +4559,6 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
if (n) if (n)
{ {
const TCHAR* val = n->Value(); const TCHAR* val = n->Value();
val = n->Value();
if (val) if (val)
_nppGUI._definedWorkspaceExt = val; _nppGUI._definedWorkspaceExt = val;
} }

View File

@ -71,7 +71,7 @@ INT_PTR CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LP
{ {
ColourPopup *pColourPopup = reinterpret_cast<ColourPopup *>(lParam); ColourPopup *pColourPopup = reinterpret_cast<ColourPopup *>(lParam);
pColourPopup->_hSelf = hwnd; pColourPopup->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam); ::SetWindowLongPtr(hwnd, GWLP_USERDATA, static_cast<LONG_PTR>(lParam));
pColourPopup->run_dlgProc(message, wParam, lParam); pColourPopup->run_dlgProc(message, wParam, lParam);
return TRUE; return TRUE;
} }

View File

@ -29,26 +29,22 @@
#include <windows.h> #include <windows.h>
#include "StaticDialog.h" #include "StaticDialog.h"
StaticDialog::~StaticDialog() StaticDialog::~StaticDialog()
{ {
if (isCreated()) if (isCreated())
{ {
// Prevent run_dlgProc from doing anything, since its virtual // Prevent run_dlgProc from doing anything, since its virtual
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR) NULL); ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, NULL);
destroy(); destroy();
} }
} }
void StaticDialog::destroy() void StaticDialog::destroy()
{ {
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf); ::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, reinterpret_cast<WPARAM>(_hSelf));
::DestroyWindow(_hSelf); ::DestroyWindow(_hSelf);
} }
POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const
{ {
RECT rc; RECT rc;
@ -65,7 +61,6 @@ POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const
return p; return p;
} }
void StaticDialog::goToCenter() void StaticDialog::goToCenter()
{ {
RECT rc; RECT rc;
@ -81,7 +76,6 @@ void StaticDialog::goToCenter()
::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); ::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW);
} }
void StaticDialog::display(bool toShow) const void StaticDialog::display(bool toShow) const
{ {
if (toShow) if (toShow)
@ -113,7 +107,6 @@ void StaticDialog::display(bool toShow) const
Window::display(toShow); Window::display(toShow);
} }
HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate) HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate)
{ {
// Get Dlg Template resource // Get Dlg Template resource
@ -151,11 +144,11 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
{ {
DLGTEMPLATE *pMyDlgTemplate = NULL; DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate); HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate);
_hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, (LPARAM)this); _hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate); ::GlobalFree(hMyDlgTemplate);
} }
else else
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, (LPARAM)this); _hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
if (!_hSelf) if (!_hSelf)
{ {
@ -167,10 +160,9 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
} }
// if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent // if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent
::SendMessage(msgDestParent?_hParent:(::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf); ::SendMessage(msgDestParent ? _hParent : (::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf));
} }
INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)
@ -179,7 +171,7 @@ INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, L
{ {
StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(lParam); StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(lParam);
pStaticDlg->_hSelf = hwnd; pStaticDlg->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam); ::SetWindowLongPtr(hwnd, GWLP_USERDATA, static_cast<LONG_PTR>(lParam));
::GetWindowRect(hwnd, &(pStaticDlg->_rc)); ::GetWindowRect(hwnd, &(pStaticDlg->_rc));
pStaticDlg->run_dlgProc(message, wParam, lParam); pStaticDlg->run_dlgProc(message, wParam, lParam);

View File

@ -28,12 +28,10 @@
#include "Notepad_plus_msgs.h" #include "Notepad_plus_msgs.h"
#include "Window.h" #include "Window.h"
typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD); typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD);
enum class PosAlign { left, right, top, bottom }; enum class PosAlign { left, right, top, bottom };
struct DLGTEMPLATEEX struct DLGTEMPLATEEX
{ {
WORD dlgVer; WORD dlgVer;
@ -49,8 +47,6 @@ struct DLGTEMPLATEEX
// The structure has more fields but are variable length // The structure has more fields but are variable length
}; };
class StaticDialog : public Window class StaticDialog : public Window
{ {
public : public :
@ -58,8 +54,7 @@ public :
virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true); virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true);
virtual bool isCreated() const virtual bool isCreated() const {
{
return (_hSelf != NULL); return (_hSelf != NULL);
} }
@ -76,7 +71,6 @@ public :
virtual void destroy() override; virtual void destroy() override;
protected: protected:
RECT _rc; RECT _rc;
static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);

View File

@ -36,7 +36,7 @@ const int DEFAULT_NB_NUMBER = 2;
class ValueDlg : public StaticDialog class ValueDlg : public StaticDialog
{ {
public : public :
ValueDlg() : StaticDialog(), _nbNumber(DEFAULT_NB_NUMBER) {}; ValueDlg() : StaticDialog() {};
void init(HINSTANCE hInst, HWND parent, int valueToSet, const TCHAR *text); void init(HINSTANCE hInst, HWND parent, int valueToSet, const TCHAR *text);
int doDialog(POINT p, bool isRTL = false); int doDialog(POINT p, bool isRTL = false);
void setNBNumber(int nbNumber) { void setNBNumber(int nbNumber) {
@ -50,8 +50,8 @@ protected :
INT_PTR CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM); INT_PTR CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM);
private : private :
int _nbNumber; int _nbNumber = DEFAULT_NB_NUMBER;
int _defaultValue; int _defaultValue = 0;
generic_string _name; generic_string _name;
POINT _p; POINT _p;
}; };