[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
This commit is contained in:
Don Ho 2010-10-16 13:31:33 +00:00
parent 7107532531
commit c8f5903ce5
5 changed files with 30 additions and 36 deletions

View File

@ -348,7 +348,7 @@ void RegExtDlg::writeNppPath()
TCHAR nppPath[MAX_PATH]; TCHAR nppPath[MAX_PATH];
::GetModuleFileName(_hInst, nppPath, MAX_PATH); ::GetModuleFileName(_hInst, nppPath, MAX_PATH);
TCHAR nppPathParam[256] = TEXT("\""); TCHAR nppPathParam[MAX_PATH] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\" \"%1\"")); lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\" \"%1\""));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR)); ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));
@ -377,7 +377,7 @@ void RegExtDlg::writeNppPath()
TCHAR nppPath[MAX_PATH]; TCHAR nppPath[MAX_PATH];
::GetModuleFileName(_hInst, nppPath, MAX_PATH); ::GetModuleFileName(_hInst, nppPath, MAX_PATH);
TCHAR nppPathParam[256] = TEXT("\""); TCHAR nppPathParam[MAX_PATH] = TEXT("\"");
lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0")); lstrcat(lstrcat(nppPathParam, nppPath), TEXT("\",0"));
::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR)); ::RegSetValueEx(hKey, NULL, 0, REG_SZ, (LPBYTE)nppPathParam, (lstrlen(nppPathParam)+1)*sizeof(TCHAR));

View File

@ -1232,7 +1232,7 @@ bool FindReplaceDlg::processFindNext(const TCHAR *txt2find, const FindOption *op
int flags = Searching::buildSearchFlags(pOptions); int flags = Searching::buildSearchFlags(pOptions);
(*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags); (*_ppEditView)->execute(SCI_SETSEARCHFLAGS, flags);
//::SendMessageA(_hParent, WM_SETTEXT, 0, (LPARAM)pText);
int posFind = (*_ppEditView)->searchInTarget(pText, stringSizeFind, startPosition, endPosition); int posFind = (*_ppEditView)->searchInTarget(pText, stringSizeFind, startPosition, endPosition);
if (posFind == -1) //no match found in target, check if a new target should be used if (posFind == -1) //no match found in target, check if a new target should be used
{ {

View File

@ -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) void ColourPicker::drawBackground(HDC hDC)
{ {
RECT rc; RECT rc;
@ -93,22 +103,26 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
{ {
case WM_LBUTTONDBLCLK : case WM_LBUTTONDBLCLK :
case WM_LBUTTONDOWN : case WM_LBUTTONDOWN :
{
if (!_pColourPopup)
{ {
RECT rc; RECT rc;
POINT p; POINT p;
Window::getClientRect(rc); Window::getClientRect(rc);
::InflateRect(&rc, -2, -2); ::InflateRect(&rc, -2, -2);
p.x = rc.left; p.x = rc.left;
p.y = rc.top + rc.bottom; p.y = rc.top + rc.bottom;
::ClientToScreen(_hSelf, &p); ::ClientToScreen(_hSelf, &p);
if (!_pColourPopup)
{
_pColourPopup = new ColourPopup(_currentColour); _pColourPopup = new ColourPopup(_currentColour);
_pColourPopup->init(_hInst, _hSelf); _pColourPopup->init(_hInst, _hSelf);
_pColourPopup->doDialog(p); _pColourPopup->doDialog(p);
} }
else
{
_pColourPopup->doDialog(p);
_pColourPopup->display(true);
}
return TRUE; return TRUE;
} }
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
@ -141,9 +155,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
_currentColour = (COLORREF)wParam; _currentColour = (COLORREF)wParam;
redraw(); redraw();
_pColourPopup->destroy(); _pColourPopup->display(false);
delete _pColourPopup;
_pColourPopup = NULL;
::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), (LPARAM)_hSelf); ::SendMessage(_hParent, WM_COMMAND, MAKELONG(0, CPN_COLOURPICKED), (LPARAM)_hSelf);
return TRUE; return TRUE;
} }
@ -159,18 +171,8 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
} }
case WM_PICKUP_CANCEL : case WM_PICKUP_CANCEL :
case WM_DESTROY : _pColourPopup->display(false);
{
if (_pColourPopup)
{
_pColourPopup->destroy();
delete _pColourPopup;
_pColourPopup = NULL;
return TRUE; return TRUE;
}
break;
}
default : default :
return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam); return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam);

View File

@ -22,7 +22,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
class ColourPopup; class ColourPopup;
//#define CP_CLASS_NAME "colourPickerButton"
#define CPN_COLOURPICKED (BN_CLICKED) #define CPN_COLOURPICKED (BN_CLICKED)
class ColourPicker : public Window class ColourPicker : public Window
@ -31,16 +30,12 @@ public :
ColourPicker() : Window(), _currentColour(RGB(0xFF, 0x00, 0x00)), _pColourPopup(NULL), _isEnabled(true) {}; ColourPicker() : Window(), _currentColour(RGB(0xFF, 0x00, 0x00)), _pColourPopup(NULL), _isEnabled(true) {};
~ColourPicker(){}; ~ColourPicker(){};
virtual void init(HINSTANCE hInst, HWND parent); virtual void init(HINSTANCE hInst, HWND parent);
virtual void destroy() { virtual void destroy();
DestroyWindow(_hSelf);
};
void setColour(COLORREF c) { void setColour(COLORREF c) {
_currentColour = c; _currentColour = c;
//drawSelf();
}; };
COLORREF getColour() const {return _currentColour;}; COLORREF getColour() const {return _currentColour;};
bool isEnabled() {return _isEnabled;}; bool isEnabled() {return _isEnabled;};
void setEnabled(bool enabled) {_isEnabled = enabled;}; void setEnabled(bool enabled) {_isEnabled = enabled;};

View File

@ -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_ADDSTRING, nColor, (LPARAM) "");
::SendDlgItemMessage(_hSelf, IDC_COLOUR_LIST, LB_SETITEMDATA , nColor, (LPARAM) colourItems[nColor]); ::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; return TRUE;
} }