[CODE_ENHANCEMENT] Code enhancement.

pull/131/head^2
Don Ho 10 years ago
parent 7f6dd17f03
commit 9d50da76b1

@ -956,12 +956,12 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const
if (posFound != -1 && posFound != -2)
{
const char *encodingBlockRegExpr = "encoding[ \\t]*=[ \\t]*\"[^\".]+\"";
posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingBlockRegExpr), (LPARAM)encodingBlockRegExpr);
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingBlockRegExpr), (LPARAM)encodingBlockRegExpr);
const char *encodingRegExpr = "\".+\"";
posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingRegExpr), (LPARAM)encodingRegExpr);
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingRegExpr), (LPARAM)encodingRegExpr);
posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingAliasRegExpr), (LPARAM)encodingAliasRegExpr);
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingAliasRegExpr), (LPARAM)encodingAliasRegExpr);
startPos = int(_invisibleEditView.execute(SCI_GETTARGETSTART));
endPos = int(_invisibleEditView.execute(SCI_GETTARGETEND));
@ -998,9 +998,9 @@ int Notepad_plus::getHtmlXmlEncoding(const TCHAR *fileName) const
if (posFound == -1 || posFound == -2)
return -1;
}
posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(charsetBlock), (LPARAM)charsetBlock);
posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(intermediaire), (LPARAM)intermediaire);
posFound = _invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingStrRE), (LPARAM)encodingStrRE);
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(charsetBlock), (LPARAM)charsetBlock);
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(intermediaire), (LPARAM)intermediaire);
_invisibleEditView.execute(SCI_SEARCHINTARGET, strlen(encodingStrRE), (LPARAM)encodingStrRE);
startPos = int(_invisibleEditView.execute(SCI_GETTARGETSTART));
endPos = int(_invisibleEditView.execute(SCI_GETTARGETEND));
@ -6074,7 +6074,8 @@ void Notepad_plus::showQuote(const char *quote, const char *quoter, bool doTroll
void Notepad_plus::launchDocumentBackupTask()
{
HANDLE hThread = ::CreateThread(NULL, 0, backupDocument, NULL, 0, NULL);
::CloseHandle(hThread);
if (hThread)
::CloseHandle(hThread);
}
DWORD WINAPI Notepad_plus::backupDocument(void * /*param*/)
@ -6150,7 +6151,6 @@ bool Notepad_plus::undoStreamComment()
generic_string white_space(TEXT(" "));
int start_comment_length = start_comment.length();
int end_comment_length = end_comment.length();
int startCommentLength, endCommentLength;
do { // do as long as stream-comments are within selection
@ -6166,7 +6166,7 @@ bool Notepad_plus::undoStreamComment()
//-- First, search all start_comment and end_comment before and after the selectionStart and selectionEnd position.
const int iSelStart=0, iSelEnd=1;
#define N_CMNT 2
const size_t N_CMNT = 2
int posStartCommentBefore[N_CMNT], posEndCommentBefore[N_CMNT], posStartCommentAfter[N_CMNT], posEndCommentAfter[N_CMNT];
bool blnStartCommentBefore[N_CMNT], blnEndCommentBefore[N_CMNT], blnStartCommentAfter[N_CMNT], blnEndCommentAfter[N_CMNT];
int posStartComment, posEndComment;
@ -6238,8 +6238,8 @@ bool Notepad_plus::undoStreamComment()
//-- Ok, there are valid start-comment and valid end-comment around the caret-position.
// Now, un-comment stream-comment:
retVal = true;
startCommentLength = start_comment_length;
endCommentLength = end_comment_length;
int startCommentLength = start_comment_length;
int endCommentLength = end_comment_length;
//-- First delete end-comment, so that posStartCommentBefore does not change!
//-- Get character before end-comment to decide, if there is a white character before the end-comment, which will be removed too!
_pEditView->getGenericText(charbuf, charbufLen, posEndComment-1, posEndComment);

@ -47,7 +47,7 @@ class Printer
public :
Printer(){};
void init(HINSTANCE hInst, HWND hwnd, ScintillaEditView *pSEView, bool showDialog, int startPos, int endPos);
size_t Printer::doPrint() {
size_t doPrint() {
if (!::PrintDlg(&_pdlg))
return 0;

@ -72,7 +72,7 @@ public:
};
protected:
virtual BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
ScintillaEditView **_ppEditView;

@ -99,7 +99,7 @@ public:
void drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
protected:
virtual BOOL CALLBACK ClipboardHistoryPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
ScintillaEditView **_ppEditView;

@ -678,10 +678,9 @@ void DockingManager::setActiveTab(int iCont, int iItem)
void DockingManager::showDockableDlg(HWND hDlg, BOOL view)
{
tTbData *pTbData = NULL;
for (size_t i = 0, len = _vContainer.size(); i < len; ++i)
{
pTbData = _vContainer[i]->findToolbarByWnd(hDlg);
tTbData *pTbData = _vContainer[i]->findToolbarByWnd(hDlg);
if (pTbData != NULL)
{
_vContainer[i]->showToolbar(pTbData, view);

@ -457,7 +457,7 @@ void Gripper::doTabReordering(POINT pt)
_iItem = iItem;
}
else if ((hTab != _hTab) || (_iItem == -1))
else if (_hTab && ((hTab != _hTab) || (_iItem == -1)))
{
/* test if cusor points after last tab */
int iLastItem = ::SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0) - 1;
@ -501,7 +501,7 @@ void Gripper::doTabReordering(POINT pt)
}
/* insert new entry when mouse doesn't point to current hovered tab */
if ((_hTab != hTabOld) || (_iItem != iItemOld))
if (_hTab && ((_hTab != hTabOld) || (_iItem != iItemOld)))
{
_tcItem.mask = TCIF_PARAM | (_hTab == _hTabSource ? TCIF_TEXT : 0);
::SendMessage(_hTab, TCM_INSERTITEM, _iItem, (LPARAM)&_tcItem);

@ -37,7 +37,7 @@ struct foundInfo {
generic_string _data2;
int _pos;
int _pos2;
//foundInfo(): /*_data(TEXT("")), _data2(TEXT("")), _pos(-1) _pos2(-1) */{};
foundInfo(): _data(TEXT("")), _data2(TEXT("")), _pos(-1), _pos2(-1) {};
};
class FunctionParser {

@ -257,7 +257,7 @@ bool PreferenceDlg::renameDialogTitle(const TCHAR *internalName, const TCHAR *ne
return false;
const size_t lenMax = 256;
TCHAR oldName[lenMax];
TCHAR oldName[lenMax] = {0};
size_t txtLen = ::SendDlgItemMessage(_hSelf, IDC_LIST_DLGTITLE, LB_GETTEXTLEN, i, 0);
if (txtLen >= lenMax)
return false;

@ -134,7 +134,7 @@ protected:
void setWorkSpaceDirty(bool isDirty);
void popupMenuCmd(int cmdID);
POINT getMenuDisplyPoint(int iButton);
virtual BOOL CALLBACK ProjectPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
bool buildTreeFrom(TiXmlNode *projectRoot, HTREEITEM hParentItem);
void notified(LPNMHDR notification);
void showContextMenu(int x, int y);

@ -49,7 +49,8 @@ void StaticDialog::display(bool toShow) const
if (toShow) {
// If the user has switched from a dual monitor to a single monitor since we last
// displayed the dialog, then ensure that it's still visible on the single monitor.
RECT workAreaRect, rc;
RECT workAreaRect = {0};
RECT rc = {0};
::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0);
::GetWindowRect(_hSelf, &rc);
int newLeft = rc.left;
@ -77,9 +78,17 @@ HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplat
{
// Get Dlg Template resource
HRSRC hDialogRC = ::FindResource(_hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG);
if (!hDialogRC)
return NULL;
HGLOBAL hDlgTemplate = ::LoadResource(_hInst, hDialogRC);
if (!hDlgTemplate)
return NULL;
DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE *)::LockResource(hDlgTemplate);
if (!pDlgTemplate)
return NULL;
// Duplicate Dlg Template resource
unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC);
HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg);

@ -53,7 +53,7 @@ public :
_isVertical = isVertical;
TabBar::init(hInst, hwnd, false, isTraditional, isMultiLine);
};
void ControlsTab::createTabs(WindowVector & winVector);
void createTabs(WindowVector & winVector);
void destroy() {
TabBar::destroy();

@ -104,7 +104,7 @@ public:
};
protected:
virtual BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
private:
VerticalFileSwitcherListView _fileListView;

@ -546,7 +546,7 @@ void Accelerator::updateShortcuts()
tmpAccelArray[i] = IFAcc[i];
}
_hIncFindAccTab = ::CreateAcceleratorTable(tmpAccelArray, nb);
delete tmpAccelArray;
delete [] tmpAccelArray;
return;
}

@ -215,7 +215,7 @@ public:
};
KeyCombo getKeyComboByIndex(int index) const;
void ScintillaKeyMap::setKeyComboByIndex(int index, KeyCombo combo);
void setKeyComboByIndex(int index, KeyCombo combo);
void removeKeyComboByIndex(int index);
void clearDups() {
if (size > 1)

@ -495,7 +495,7 @@ DEVOMER*/
} catch (const Win32Exception & ex) {
TCHAR message[1024]; //TODO: sane number
wsprintf(message, TEXT("An exception occured. Notepad++ cannot recover and must be shut down.\r\nThe exception details are as follows:\r\n")
TEXT("Code:\t0x%08X\r\nType:\t%S\r\nException address: 0x%08X"), ex.code(), ex.what(), ex.where());
TEXT("Code:\t0x%08X\r\nType:\t%S\r\nException address: 0x%08X"), ex.code(), ex.what(), (long)ex.where());
::MessageBox(Notepad_plus_Window::gNppHWND, message, TEXT("Win32Exception"), MB_OK | MB_ICONERROR);
mdump.writeDump(ex.info());
doException(notepad_plus_plus);

Loading…
Cancel
Save