From c8f5903ce5f692a7fbd412ed060623031012293d Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 16 Oct 2010 13:31:33 +0000 Subject: [PATCH] [BUG_FIXED] (Author: Jocelyn Legault) Fix a heap corruption of ColourPicker. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@681 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/MISC/RegExt/regExtDlg.cpp | 4 +- .../src/ScitillaComponent/FindReplaceDlg.cpp | 2 +- .../WinControls/ColourPicker/ColourPicker.cpp | 50 ++++++++++--------- .../WinControls/ColourPicker/ColourPicker.h | 7 +-- .../WinControls/ColourPicker/ColourPopup.cpp | 3 -- 5 files changed, 30 insertions(+), 36 deletions(-) diff --git a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp index f0226648c..f1d4780f5 100644 --- a/PowerEditor/src/MISC/RegExt/regExtDlg.cpp +++ b/PowerEditor/src/MISC/RegExt/regExtDlg.cpp @@ -348,7 +348,7 @@ void RegExtDlg::writeNppPath() TCHAR nppPath[MAX_PATH]; ::GetModuleFileName(_hInst, nppPath, MAX_PATH); - TCHAR nppPathParam[256] = TEXT("\""); + TCHAR nppPathParam[MAX_PATH] = TEXT("\""); lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\" \"%1\"")); ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR)); @@ -377,7 +377,7 @@ void RegExtDlg::writeNppPath() TCHAR nppPath[MAX_PATH]; ::GetModuleFileName(_hInst, nppPath, MAX_PATH); - TCHAR nppPathParam[256] = TEXT("\""); + TCHAR nppPathParam[MAX_PATH] = TEXT("\""); lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0")); ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR)); diff --git a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp index e60339421..f9a44a0bb 100644 --- a/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScitillaComponent/FindReplaceDlg.cpp @@ -1232,7 +1232,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op int flags = Searching::buildSearchFlags(pOptions); (*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); - //::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pText); + int posFind = (*_ppEditView)->searchInTarget(pText, stringSizeFind, startPosition, endPosition); if (posFind == -1) //no match found in target, check if a new target should be used { diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp index 74956200a..8d3aa9813 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.cpp @@ -45,6 +45,16 @@ void ColourPicker::init(HINSTANCE hInst, HWND parent) } +void ColourPicker::destroy() +{ + if (_pColourPopup) + { + delete _pColourPopup; + _pColourPopup = NULL; + } + ::DestroyWindow(_hSelf); +} + void ColourPicker::drawBackground(HDC hDC) { RECT rc; @@ -94,21 +104,25 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) case WM_LBUTTONDBLCLK : case WM_LBUTTONDOWN : { + RECT rc; + POINT p; + Window::getClientRect(rc); + ::InflateRect(&rc, -2, -2); + p.x = rc.left; + p.y = rc.top + rc.bottom; + ::ClientToScreen(_hSelf, &p); + if (!_pColourPopup) { - RECT rc; - POINT p; - - Window::getClientRect(rc); - ::InflateRect(&rc, -2, -2); - p.x = rc.left; - p.y = rc.top + rc.bottom; - - ::ClientToScreen(_hSelf, &p); _pColourPopup = new ColourPopup(_currentColour); _pColourPopup->init(_hInst, _hSelf); _pColourPopup->doDialog(p); } + else + { + _pColourPopup->doDialog(p); + _pColourPopup->display(true); + } return TRUE; } case WM_RBUTTONDOWN: @@ -141,9 +155,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) _currentColour = (COLORREF)wParam; redraw(); - _pColourPopup->destroy(); - delete _pColourPopup; - _pColourPopup = NULL; + _pColourPopup->display(false); ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), (LPARAM)_hSelf); return TRUE; } @@ -159,18 +171,8 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) } case WM_PICKUP_CANCEL : - case WM_DESTROY : - { - if (_pColourPopup) - { - _pColourPopup->destroy(); - delete _pColourPopup; - _pColourPopup = NULL; - - return TRUE; - } - break; - } + _pColourPopup->display(false); + return TRUE; default : return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam); diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h index 5700be76e..0c88b3821 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPicker.h @@ -22,7 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. class ColourPopup; -//#define CP_CLASS_NAME "colourPickerButton" #define CPN_COLOURPICKED (BN_CLICKED) class ColourPicker : public Window @@ -31,16 +30,12 @@ public : ColourPicker() : Window(), _currentColour(RGB(0xFF, 0x00, 0x00)), _pColourPopup(NULL), _isEnabled(true) {}; ~ColourPicker(){}; virtual void init(HINSTANCE hInst, HWND parent); - virtual void destroy() { - DestroyWindow(_hSelf); - }; + virtual void destroy(); void setColour(COLORREF c) { _currentColour = c; - //drawSelf(); }; COLORREF getColour() const {return _currentColour;}; - bool isEnabled() {return _isEnabled;}; void setEnabled(bool enabled) {_isEnabled = enabled;}; diff --git a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp index 30de6f7d6..db9837816 100644 --- a/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp +++ b/PowerEditor/src/WinControls/ColourPicker/ColourPopup.cpp @@ -87,10 +87,7 @@ BOOL CALLBACK ColourPopup::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPara { ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_ADDSTRING, nColor, (LPARAM) ""); ::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETITEMDATA , nColor, (LPARAM) colourItems[nColor]); - //if (g_bgColor == colourItems[nColor]) - //::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETCURSEL, nColor, 0); } - //::SetCapture(_hSelf); return TRUE; }