Browse Source

Some code enhancements

pull/2074/head
Don HO 8 years ago
parent
commit
2573f4b492
  1. 6
      PowerEditor/src/Notepad_plus.cpp
  2. 12
      PowerEditor/src/Parameters.cpp
  3. 2
      PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp
  4. 20
      PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp
  5. 10
      PowerEditor/src/WinControls/StaticDialog/StaticDialog.h
  6. 6
      PowerEditor/src/lesDlgs.h

6
PowerEditor/src/Notepad_plus.cpp

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

12
PowerEditor/src/Parameters.cpp

@ -2874,10 +2874,9 @@ void NppParameters::insertScintKey(TiXmlNode *scintKeyRoot, const ScintillaKeyMa
size_t size = scintKeyMap.getSize();
if (size > 1)
{
TiXmlNode * keyNext;
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);
keyNext->ToElement()->SetAttribute(TEXT("Ctrl"), key._isCtrl?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")))
{
const TCHAR * keywordsName = (childNode->ToElement())->Attribute(TEXT("name"));
TCHAR *kwl = nullptr;
TiXmlNode *valueNode = childNode->FirstChild();
if (valueNode)
{
TCHAR *kwl = nullptr;
if (!lstrcmp(udlVersion, TEXT("")) && !lstrcmp(keywordsName, TEXT("Delimiters"))) // support for old style (pre 2.0)
{
basic_string<TCHAR> temp;
@ -4235,7 +4233,6 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
int g5 = 0; // up to 48
int g6 = 0; // up to 56
int g7 = 0; // up to 64
const int nbMax = 64;
// 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;
for (int i = 0 ; i < 8 ; ++i)
{
@ -4566,7 +4559,6 @@ void NppParameters::feedGUIParameters(TiXmlNode *node)
if (n)
{
const TCHAR* val = n->Value();
val = n->Value();
if (val)
_nppGUI._definedWorkspaceExt = val;
}

2
PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp

@ -71,7 +71,7 @@ INT_PTR CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LP
{
ColourPopup *pColourPopup = reinterpret_cast<ColourPopup *>(lParam);
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);
return TRUE;
}

20
PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp

@ -29,26 +29,22 @@
#include <windows.h>
#include "StaticDialog.h"
StaticDialog::~StaticDialog()
{
if (isCreated())
{
// Prevent run_dlgProc from doing anything, since its virtual
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR) NULL);
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, NULL);
destroy();
}
}
void StaticDialog::destroy()
{
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf);
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, reinterpret_cast<WPARAM>(_hSelf));
::DestroyWindow(_hSelf);
}
POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const
{
RECT rc;
@ -65,7 +61,6 @@ POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const
return p;
}
void StaticDialog::goToCenter()
{
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);
}
void StaticDialog::display(bool toShow) const
{
if (toShow)
@ -113,7 +107,6 @@ void StaticDialog::display(bool toShow) const
Window::display(toShow);
}
HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate)
{
// Get Dlg Template resource
@ -151,11 +144,11 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
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);
}
else
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, (LPARAM)this);
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
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
::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)
{
switch (message)
@ -179,7 +171,7 @@ INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, L
{
StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(lParam);
pStaticDlg->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)lParam);
::SetWindowLongPtr(hwnd, GWLP_USERDATA, static_cast<LONG_PTR>(lParam));
::GetWindowRect(hwnd, &(pStaticDlg->_rc));
pStaticDlg->run_dlgProc(message, wParam, lParam);

10
PowerEditor/src/WinControls/StaticDialog/StaticDialog.h

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

6
PowerEditor/src/lesDlgs.h

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

Loading…
Cancel
Save