From 1c46487c8b0844459d45487fda8edb28815dec2a Mon Sep 17 00:00:00 2001 From: kmcclusk Date: Thu, 23 Apr 1998 20:21:24 +0000 Subject: [PATCH] Added SetMaxTextLength method to text widget and textarea widget. git-svn-id: svn://10.0.0.236/trunk@559 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/public/nsITextWidget.h | 9 +++++++++ mozilla/widget/public/nsIWidget.h | 2 +- mozilla/widget/src/windows/nsTextAreaWidget.cpp | 4 ++++ mozilla/widget/src/windows/nsTextAreaWidget.h | 1 + mozilla/widget/src/windows/nsTextHelper.cpp | 6 ++++++ mozilla/widget/src/windows/nsTextHelper.h | 5 +++-- mozilla/widget/tests/windows/winmain.cpp | 1 + 7 files changed, 25 insertions(+), 3 deletions(-) diff --git a/mozilla/widget/public/nsITextWidget.h b/mozilla/widget/public/nsITextWidget.h index edf5a56b523..e6946e8effb 100644 --- a/mozilla/widget/public/nsITextWidget.h +++ b/mozilla/widget/public/nsITextWidget.h @@ -86,6 +86,15 @@ class nsITextWidget : public nsIWidget virtual void SetPassword(PRBool aIsPassword) = 0; + /** + * Sets the maximum number of characters the widget can hold + * + * @param aChars maximum number of characters for this widget. if 0 then there isn't any limit + */ + + virtual void SetMaxTextLength(PRUint32 aChars) = 0; + + /** * Set the text widget to be read-only * diff --git a/mozilla/widget/public/nsIWidget.h b/mozilla/widget/public/nsIWidget.h index 2a0f5eb62cb..a6007e49ec8 100644 --- a/mozilla/widget/public/nsIWidget.h +++ b/mozilla/widget/public/nsIWidget.h @@ -72,7 +72,7 @@ typedef void* nsNativeWindow; */ enum nsBorderStyle { - ///window border with title area + ///no border eBorderStyle_none, ///dialog box border + title area eBorderStyle_dialog, diff --git a/mozilla/widget/src/windows/nsTextAreaWidget.cpp b/mozilla/widget/src/windows/nsTextAreaWidget.cpp index e4265e439f2..61f8fbdf40d 100644 --- a/mozilla/widget/src/windows/nsTextAreaWidget.cpp +++ b/mozilla/widget/src/windows/nsTextAreaWidget.cpp @@ -22,6 +22,10 @@ #include "nsString.h" #include +void nsTextAreaWidget::SetMaxTextLength(PRUint32 aChars) { + nsTextHelper::SetMaxTextLength(aChars); +} + PRUint32 nsTextAreaWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) { return(nsTextHelper::GetText(aTextBuffer, aBufferSize)); } diff --git a/mozilla/widget/src/windows/nsTextAreaWidget.h b/mozilla/widget/src/windows/nsTextAreaWidget.h index f6131543215..6ff657810e8 100644 --- a/mozilla/widget/src/windows/nsTextAreaWidget.h +++ b/mozilla/widget/src/windows/nsTextAreaWidget.h @@ -49,6 +49,7 @@ public: BASE_IWIDGET_IMPL // nsITextWidget part + virtual void SetMaxTextLength(PRUint32 aChars); virtual PRUint32 SetText(const nsString &aText); virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize); virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos); diff --git a/mozilla/widget/src/windows/nsTextHelper.cpp b/mozilla/widget/src/windows/nsTextHelper.cpp index 6b08f610029..9866595fe16 100644 --- a/mozilla/widget/src/windows/nsTextHelper.cpp +++ b/mozilla/widget/src/windows/nsTextHelper.cpp @@ -25,6 +25,12 @@ #include +void nsTextHelper::SetMaxTextLength(PRUint32 aChars) +{ + ::SendMessage(mWnd, EM_SETLIMITTEXT, (WPARAM) (INT)aChars, 0); +} + + PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) { int length = GetWindowTextLength(mWnd); diff --git a/mozilla/widget/src/windows/nsTextHelper.h b/mozilla/widget/src/windows/nsTextHelper.h index 164fe17abae..99d968e5aaa 100644 --- a/mozilla/widget/src/windows/nsTextHelper.h +++ b/mozilla/widget/src/windows/nsTextHelper.h @@ -32,7 +32,8 @@ class nsTextHelper : public nsWindow, public nsITextWidget public: nsTextHelper(nsISupports *aOuter); virtual ~nsTextHelper(); - + + virtual void SetMaxTextLength(PRUint32 aChars); virtual PRUint32 GetText(nsString& aTextBuffer, PRUint32 aBufferSize); virtual PRUint32 SetText(const nsString &aText); virtual PRUint32 InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos); @@ -50,7 +51,7 @@ protected: PRBool mIsPassword; PRBool mIsReadOnly; - + virtual DWORD WindowExStyle(); }; diff --git a/mozilla/widget/tests/windows/winmain.cpp b/mozilla/widget/tests/windows/winmain.cpp index fdfe3a802bd..b565e71d552 100644 --- a/mozilla/widget/tests/windows/winmain.cpp +++ b/mozilla/widget/tests/windows/winmain.cpp @@ -994,6 +994,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd textWidget->SetFont(font); nsString initialText("0123456789"); textWidget->SetText(initialText); + textWidget->SetMaxTextLength(12); NS_RELEASE(textWidget); y += rect.height + 5;