[MODIF] Code clean up: make code adapt the coding convention.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@1348 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2015-02-24 18:27:55 +00:00
parent aa7461f062
commit 8d3583ccfd
3 changed files with 97 additions and 100 deletions

View File

@ -1449,7 +1449,7 @@ bool Notepad_plus::replaceInFiles()
getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir);
CProgress progress; Progress progress(_pPublicInterface->getHinst());
size_t filesCount = fileNames.size(); size_t filesCount = fileNames.size();
size_t filesPerPercent = 1; size_t filesPerPercent = 1;
@ -1457,12 +1457,12 @@ bool Notepad_plus::replaceInFiles()
{ {
if (filesCount >= 200) if (filesCount >= 200)
filesPerPercent = filesCount / 100; filesPerPercent = filesCount / 100;
progress.Open(NULL, TEXT("Replace In Files progress...")); progress.open(NULL, TEXT("Replace In Files progress..."));
} }
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i) for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
{ {
if (progress.IsCancelled()) break; if (progress.isCancelled()) break;
bool closeBuf = false; bool closeBuf = false;
@ -1494,15 +1494,15 @@ bool Notepad_plus::replaceInFiles()
if (i == updateOnCount) if (i == updateOnCount)
{ {
updateOnCount += filesPerPercent; updateOnCount += filesPerPercent;
progress.SetPercent((i * 100) / filesCount, fileNames.at(i).c_str()); progress.setPercent((i * 100) / filesCount, fileNames.at(i).c_str());
} }
else else
{ {
progress.SetInfo(fileNames.at(i).c_str()); progress.setInfo(fileNames.at(i).c_str());
} }
} }
progress.Close(); progress.close();
_invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc); _invisibleEditView.execute(SCI_SETDOCPOINTER, 0, oldDoc);
_invisibleEditView.setCurrentBuffer(oldBuf); _invisibleEditView.setCurrentBuffer(oldBuf);
@ -1543,7 +1543,8 @@ bool Notepad_plus::findInFiles()
_findReplaceDlg.beginNewFilesSearch(); _findReplaceDlg.beginNewFilesSearch();
CProgress progress; Progress progress(_pPublicInterface->getHinst());
size_t filesCount = fileNames.size(); size_t filesCount = fileNames.size();
size_t filesPerPercent = 1; size_t filesPerPercent = 1;
@ -1551,12 +1552,12 @@ bool Notepad_plus::findInFiles()
{ {
if (filesCount >= 200) if (filesCount >= 200)
filesPerPercent = filesCount / 100; filesPerPercent = filesCount / 100;
progress.Open(NULL, TEXT("Find In Files progress...")); progress.open(NULL, TEXT("Find In Files progress..."));
} }
for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i) for (size_t i = 0, updateOnCount = filesPerPercent; i < filesCount; ++i)
{ {
if (progress.IsCancelled()) break; if (progress.isCancelled()) break;
bool closeBuf = false; bool closeBuf = false;
BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str());
@ -1580,15 +1581,15 @@ bool Notepad_plus::findInFiles()
if (i == updateOnCount) if (i == updateOnCount)
{ {
updateOnCount += filesPerPercent; updateOnCount += filesPerPercent;
progress.SetPercent((i * 100) / filesCount, fileNames.at(i).c_str()); progress.setPercent((i * 100) / filesCount, fileNames.at(i).c_str());
} }
else else
{ {
progress.SetInfo(fileNames.at(i).c_str()); progress.setInfo(fileNames.at(i).c_str());
} }
} }
progress.Close(); progress.close();
_findReplaceDlg.finishFilesSearch(nbTotal); _findReplaceDlg.finishFilesSearch(nbTotal);

View File

@ -2903,34 +2903,30 @@ void FindIncrementDlg::addToRebar(ReBar * rebar)
_pRebar->setGrayBackground(_rbBand.wID); _pRebar->setGrayBackground(_rbBand.wID);
} }
const TCHAR CProgress::cClassName[] = TEXT("NppProgressClass"); const TCHAR Progress::cClassName[] = TEXT("NppProgressClass");
const TCHAR CProgress::cDefaultHeader[] = TEXT("Operation progress..."); const TCHAR Progress::cDefaultHeader[] = TEXT("Operation progress...");
const int CProgress::cBackgroundColor = COLOR_3DFACE; const int Progress::cBackgroundColor = COLOR_3DFACE;
const int CProgress::cPBwidth = 600; const int Progress::cPBwidth = 600;
const int CProgress::cPBheight = 10; const int Progress::cPBheight = 10;
const int CProgress::cBTNwidth = 80; const int Progress::cBTNwidth = 80;
const int CProgress::cBTNheight = 25; const int Progress::cBTNheight = 25;
volatile LONG CProgress::RefCount = 0; volatile LONG Progress::refCount = 0;
HINSTANCE CProgress::HInst = NULL;
CProgress::CProgress() : _hwnd(NULL) Progress::Progress(HINSTANCE hInst) : _hwnd(NULL)
{ {
if (::InterlockedIncrement(&RefCount) == 1) if (::InterlockedIncrement(&refCount) == 1)
{ {
::GetModuleHandleEx( _hInst = hInst;
GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
GET_MODULE_HANDLE_EX_FLAG_PIN, cClassName, &HInst);
WNDCLASSEX wcex; WNDCLASSEX wcex;
::SecureZeroMemory(&wcex, sizeof(wcex)); ::SecureZeroMemory(&wcex, sizeof(wcex));
wcex.cbSize = sizeof(wcex); wcex.cbSize = sizeof(wcex);
wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = wndProc; wcex.lpfnWndProc = wndProc;
wcex.hInstance = HInst; wcex.hInstance = _hInst;
wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW); wcex.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = ::GetSysColorBrush(cBackgroundColor); wcex.hbrBackground = ::GetSysColorBrush(cBackgroundColor);
wcex.lpszClassName = cClassName; wcex.lpszClassName = cClassName;
@ -2948,16 +2944,16 @@ CProgress::CProgress() : _hwnd(NULL)
} }
CProgress::~CProgress() Progress::~Progress()
{ {
Close(); close();
if (::InterlockedDecrement(&RefCount) == 0) if (::InterlockedDecrement(&refCount) == 0)
::UnregisterClass(cClassName, HInst); ::UnregisterClass(cClassName, _hInst);
} }
HWND CProgress::Open(HWND hOwner, const TCHAR* header) HWND Progress::open(HWND hOwner, const TCHAR* header)
{ {
if (_hwnd) if (_hwnd)
return _hwnd; return _hwnd;
@ -2997,7 +2993,7 @@ HWND CProgress::Open(HWND hOwner, const TCHAR* header)
} }
bool CProgress::IsCancelled() const bool Progress::isCancelled() const
{ {
if (_hwnd) if (_hwnd)
return (::WaitForSingleObject(_hActiveState, 0) != WAIT_OBJECT_0); return (::WaitForSingleObject(_hActiveState, 0) != WAIT_OBJECT_0);
@ -3005,7 +3001,7 @@ bool CProgress::IsCancelled() const
} }
void CProgress::SetPercent(unsigned percent, const TCHAR *fileName) const void Progress::setPercent(unsigned percent, const TCHAR *fileName) const
{ {
if (_hwnd) if (_hwnd)
{ {
@ -3015,7 +3011,7 @@ void CProgress::SetPercent(unsigned percent, const TCHAR *fileName) const
} }
void CProgress::Close() void Progress::close()
{ {
if (_hwnd) if (_hwnd)
{ {
@ -3028,14 +3024,14 @@ void CProgress::Close()
} }
DWORD CProgress::threadFunc(LPVOID data) DWORD Progress::threadFunc(LPVOID data)
{ {
CProgress* pw = static_cast<CProgress*>(data); Progress* pw = static_cast<Progress*>(data);
return (DWORD)pw->thread(); return (DWORD)pw->thread();
} }
int CProgress::thread() int Progress::thread()
{ {
BOOL r = createProgressWindow(); BOOL r = createProgressWindow();
::SetEvent(_hActiveState); ::SetEvent(_hActiveState);
@ -3054,7 +3050,7 @@ int CProgress::thread()
} }
int CProgress::createProgressWindow() int Progress::createProgressWindow()
{ {
DWORD styleEx = WS_EX_OVERLAPPEDWINDOW; DWORD styleEx = WS_EX_OVERLAPPEDWINDOW;
if (_hOwner) if (_hOwner)
@ -3063,7 +3059,7 @@ int CProgress::createProgressWindow()
_hwnd = ::CreateWindowEx(styleEx, _hwnd = ::CreateWindowEx(styleEx,
cClassName, _header, WS_POPUP | WS_CAPTION, cClassName, _header, WS_POPUP | WS_CAPTION,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
_hOwner, NULL, HInst, (LPVOID)this); _hOwner, NULL, _hInst, (LPVOID)this);
if (!_hwnd) if (!_hwnd)
return -1; return -1;
@ -3080,7 +3076,7 @@ int CProgress::createProgressWindow()
_hPText = ::CreateWindowEx(0, TEXT("STATIC"), TEXT(""), _hPText = ::CreateWindowEx(0, TEXT("STATIC"), TEXT(""),
WS_CHILD | WS_VISIBLE | BS_TEXT, WS_CHILD | WS_VISIBLE | BS_TEXT,
5, 5, 5, 5,
width - 10, 20, _hwnd, NULL, HInst, NULL); width - 10, 20, _hwnd, NULL, _hInst, NULL);
HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
if (hf) if (hf)
::SendMessage(_hPText, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); ::SendMessage(_hPText, WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0));
@ -3088,13 +3084,13 @@ int CProgress::createProgressWindow()
_hPBar = ::CreateWindowEx(0, PROGRESS_CLASS, TEXT("Progress Bar"), _hPBar = ::CreateWindowEx(0, PROGRESS_CLASS, TEXT("Progress Bar"),
WS_CHILD | WS_VISIBLE | PBS_SMOOTH, WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
5, 25, width - 10, cPBheight, 5, 25, width - 10, cPBheight,
_hwnd, NULL, HInst, NULL); _hwnd, NULL, _hInst, NULL);
SendMessage(_hPBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100)); SendMessage(_hPBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
_hBtn = ::CreateWindowEx(0, TEXT("BUTTON"), TEXT("Cancel"), _hBtn = ::CreateWindowEx(0, TEXT("BUTTON"), TEXT("Cancel"),
WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_TEXT, WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON | BS_TEXT,
(width - cBTNwidth) / 2, height - cBTNheight - 5, (width - cBTNwidth) / 2, height - cBTNheight - 5,
cBTNwidth, cBTNheight, _hwnd, NULL, HInst, NULL); cBTNwidth, cBTNheight, _hwnd, NULL, _hInst, NULL);
if (hf) if (hf)
@ -3107,7 +3103,7 @@ int CProgress::createProgressWindow()
} }
RECT CProgress::adjustSizeAndPos(int width, int height) RECT Progress::adjustSizeAndPos(int width, int height)
{ {
RECT win, maxWin; RECT win, maxWin;
@ -3148,20 +3144,20 @@ RECT CProgress::adjustSizeAndPos(int width, int height)
} }
LRESULT APIENTRY CProgress::wndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam) LRESULT APIENTRY Progress::wndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam)
{ {
switch (umsg) switch (umsg)
{ {
case WM_CREATE: case WM_CREATE:
{ {
CProgress* pw =(CProgress*)((LPCREATESTRUCT)lparam)->lpCreateParams; Progress* pw =(Progress*)((LPCREATESTRUCT)lparam)->lpCreateParams;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, PtrToUlong(pw)); ::SetWindowLongPtr(hwnd, GWLP_USERDATA, PtrToUlong(pw));
return 0; return 0;
} }
case WM_SETFOCUS: case WM_SETFOCUS:
{ {
CProgress* pw = reinterpret_cast<CProgress*>(static_cast<LONG_PTR> Progress* pw = reinterpret_cast<Progress*>(static_cast<LONG_PTR>
(::GetWindowLongPtr(hwnd, GWLP_USERDATA))); (::GetWindowLongPtr(hwnd, GWLP_USERDATA)));
::SetFocus(pw->_hBtn); ::SetFocus(pw->_hBtn);
return 0; return 0;
@ -3170,8 +3166,8 @@ LRESULT APIENTRY CProgress::wndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM
case WM_COMMAND: case WM_COMMAND:
if (HIWORD(wparam) == BN_CLICKED) if (HIWORD(wparam) == BN_CLICKED)
{ {
CProgress* pw = Progress* pw =
reinterpret_cast<CProgress*>(static_cast<LONG_PTR> reinterpret_cast<Progress*>(static_cast<LONG_PTR>
(::GetWindowLongPtr(hwnd, GWLP_USERDATA))); (::GetWindowLongPtr(hwnd, GWLP_USERDATA)));
::ResetEvent(pw->_hActiveState); ::ResetEvent(pw->_hActiveState);
::EnableWindow(pw->_hBtn, FALSE); ::EnableWindow(pw->_hBtn, FALSE);

View File

@ -404,21 +404,21 @@ private :
}; };
class CProgress class Progress
{ {
public: public:
CProgress(); Progress(HINSTANCE hInst);
~CProgress(); ~Progress();
HWND Open(HWND hOwner = NULL, const TCHAR* header = NULL); HWND open(HWND hOwner = NULL, const TCHAR* header = NULL);
bool IsCancelled() const; bool isCancelled() const;
void SetPercent(unsigned percent, const TCHAR *fileName) const; void setPercent(unsigned percent, const TCHAR *fileName) const;
void SetInfo(const TCHAR *info) const { void setInfo(const TCHAR *info) const {
if (_hwnd) if (_hwnd)
::SendMessage(_hPText, WM_SETTEXT, 0, (LPARAM)info); ::SendMessage(_hPText, WM_SETTEXT, 0, (LPARAM)info);
}; };
void Close(); void close();
private: private:
static const TCHAR cClassName[]; static const TCHAR cClassName[];
@ -429,20 +429,20 @@ private:
static const int cBTNwidth; static const int cBTNwidth;
static const int cBTNheight; static const int cBTNheight;
static volatile LONG RefCount; static volatile LONG refCount;
static HINSTANCE HInst;
static DWORD threadFunc(LPVOID data); static DWORD threadFunc(LPVOID data);
static LRESULT APIENTRY wndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam); static LRESULT APIENTRY wndProc(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
// Disable copy construction and operator= // Disable copy construction and operator=
CProgress(const CProgress&); Progress(const Progress&);
const CProgress& operator=(const CProgress&); const Progress& operator=(const Progress&);
int thread(); int thread();
int createProgressWindow(); int createProgressWindow();
RECT adjustSizeAndPos(int width, int height); RECT adjustSizeAndPos(int width, int height);
HINSTANCE _hInst;
volatile HWND _hwnd; volatile HWND _hwnd;
HWND _hOwner; HWND _hOwner;
TCHAR _header[128]; TCHAR _header[128];