From 9c446a13cd25a6f9e2e20345e99ee31ec64ea649 Mon Sep 17 00:00:00 2001 From: Dmitry Timoshkov Date: Mon, 22 Jan 2001 19:28:27 +0000 Subject: [PATCH] Protect read-only edit control from modification. --- controls/edit.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/controls/edit.c b/controls/edit.c index 57ed054ed4c..d6ccdce6a22 100644 --- a/controls/edit.c +++ b/controls/edit.c @@ -308,6 +308,10 @@ static inline void EDIT_WM_Clear(WND *wnd, EDITSTATE *es) { static const WCHAR empty_stringW[] = {0}; + /* Protect read-only edit control from modification */ + if(es->style & ES_READONLY) + return; + EDIT_EM_ReplaceSel(wnd, es, TRUE, empty_stringW, TRUE); if (es->flags & EF_UPDATE) { @@ -3400,8 +3404,15 @@ static void EDIT_EM_SetWordBreakProc16(WND *wnd, EDITSTATE *es, EDITWORDBREAKPRO */ static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es) { - INT ulength = strlenW(es->undo_text); - LPWSTR utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR)); + INT ulength; + LPWSTR utext; + + /* Protect read-only edit control from modification */ + if(es->style & ES_READONLY) + return FALSE; + + ulength = strlenW(es->undo_text); + utext = HeapAlloc(GetProcessHeap(), 0, (ulength + 1) * sizeof(WCHAR)); strcpyW(utext, es->undo_text); @@ -3434,7 +3445,14 @@ static BOOL EDIT_EM_Undo(WND *wnd, EDITSTATE *es) */ static void EDIT_WM_Char(WND *wnd, EDITSTATE *es, WCHAR c) { - BOOL control = GetKeyState(VK_CONTROL) & 0x8000; + BOOL control; + + /* Protect read-only edit control from modification */ + if(es->style & ES_READONLY) + return; + + control = GetKeyState(VK_CONTROL) & 0x8000; + switch (c) { case '\r': /* If the edit doesn't want the return and it's not a multiline edit, do nothing */ @@ -3567,15 +3585,15 @@ static void EDIT_WM_ContextMenu(WND *wnd, EDITSTATE *es, INT x, INT y) ORDER_UINT(start, end); /* undo */ - EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(popup, 0, MF_BYPOSITION | (EDIT_EM_CanUndo(es) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); /* cut */ - EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(popup, 2, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); /* copy */ EnableMenuItem(popup, 3, MF_BYPOSITION | ((end - start) && !(es->style & ES_PASSWORD) ? MF_ENABLED : MF_GRAYED)); /* paste */ - EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(popup, 4, MF_BYPOSITION | (IsClipboardFormatAvailable(CF_UNICODETEXT) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); /* delete */ - EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) ? MF_ENABLED : MF_GRAYED)); + EnableMenuItem(popup, 5, MF_BYPOSITION | ((end - start) && !(es->style & ES_READONLY) ? MF_ENABLED : MF_GRAYED)); /* select all */ EnableMenuItem(popup, 7, MF_BYPOSITION | (start || (end != strlenW(es->text)) ? MF_ENABLED : MF_GRAYED)); @@ -4349,6 +4367,10 @@ static void EDIT_WM_Paste(WND *wnd, EDITSTATE *es) HGLOBAL hsrc; LPWSTR src; + /* Protect read-only edit control from modification */ + if(es->style & ES_READONLY) + return; + OpenClipboard(wnd->hwndSelf); if ((hsrc = GetClipboardData(CF_UNICODETEXT))) { src = (LPWSTR)GlobalLock(hsrc);