From 2fa39f82f534b27d3e2f05bb7328d21d8042a3bc Mon Sep 17 00:00:00 2001 From: rods Date: Fri, 5 Jun 1998 21:37:19 +0000 Subject: [PATCH] added nsTextHelper git-svn-id: svn://10.0.0.236/trunk@3379 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/widget/src/motif/Makefile | 2 + mozilla/widget/src/motif/nsTextHelper.cpp | 146 ++++++++++++++++++++++ mozilla/widget/src/motif/nsTextHelper.h | 57 +++++++++ 3 files changed, 205 insertions(+) create mode 100644 mozilla/widget/src/motif/nsTextHelper.cpp create mode 100644 mozilla/widget/src/motif/nsTextHelper.h diff --git a/mozilla/widget/src/motif/Makefile b/mozilla/widget/src/motif/Makefile index 64825ef2285..f549570eb39 100644 --- a/mozilla/widget/src/motif/Makefile +++ b/mozilla/widget/src/motif/Makefile @@ -45,6 +45,7 @@ EXTRA_DSO_LDOPTS+= -lX11 -lm endif CPPSRCS= \ + nsTextHelper.cpp \ nsCheckButton.cpp \ nsScrollbar.cpp \ nsButton.cpp \ @@ -55,6 +56,7 @@ CPPSRCS= \ nsToolkit.cpp CPP_OBJS= \ + ./$(OBJDIR)/nsTextHelper.o \ ./$(OBJDIR)/nsCheckButton.o \ ./$(OBJDIR)/nsButton.o \ ./$(OBJDIR)/nsScrollbar.o \ diff --git a/mozilla/widget/src/motif/nsTextHelper.cpp b/mozilla/widget/src/motif/nsTextHelper.cpp new file mode 100644 index 00000000000..dfe6cd5f6f2 --- /dev/null +++ b/mozilla/widget/src/motif/nsTextHelper.cpp @@ -0,0 +1,146 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsTextHelper.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + + +void nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData) +{ + if (nsnull != aInitData) { + nsTextWidgetInitData* data = (nsTextWidgetInitData *) aInitData; + mIsPassword = data->mIsPassword; + } +} + +void nsTextHelper::SetMaxTextLength(PRUint32 aChars) +{ + //::SendMessage(mWnd, EM_SETLIMITTEXT, (WPARAM) (INT)aChars, 0); +} + +PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) { + + /*int length = GetWindowTextLength(mWnd); + int bufLength = length + 1; + NS_ALLOC_CHAR_BUF(buf, 512, bufLength); + int charsCopied = GetWindowText(mWnd, buf, bufLength); + aTextBuffer.SetLength(0); + aTextBuffer.Append(buf); + NS_FREE_CHAR_BUF(buf); + + return(0); +} + +PRUint32 nsTextHelper::SetText(const nsString &aText) +{ +/* + NS_ALLOC_STR_BUF(buf, aText, 512); + SetWindowText(mWnd, buf); + NS_FREE_STR_BUF(buf); + return(aText.Length()); +*/ +return 0; +} + +PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos) +{ + // NOT IMPLEMENTED + return(0); +} + +void nsTextHelper::RemoveText() +{ + //SetWindowText(mWnd, ""); +} + +void nsTextHelper::SetPassword(PRBool aIsPassword) +{ + mIsPassword = aIsPassword; +} + +PRBool nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag) +{ + PRBool oldSetting = mIsReadOnly; + mIsReadOnly = aReadOnlyFlag; + return(oldSetting); +} + + +void nsTextHelper::SelectAll() +{ + //::SendMessage(mWnd, EM_SETSEL, (WPARAM) 0, (LPARAM)-1); +} + + +void nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel) +{ + //::SendMessage(mWnd, EM_SETSEL, (WPARAM) (INT)aStartSel, (INT) (LPDWORD)aEndSel); +} + + +void nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel) +{ + //::SendMessage(mWnd, EM_GETSEL, (WPARAM) (LPDWORD)aStartSel, (LPARAM) (LPDWORD)aEndSel); +} + +void nsTextHelper::SetCaretPosition(PRUint32 aPosition) +{ +} + +PRUint32 nsTextHelper::GetCaretPosition() +{ + return(0); +} + +//------------------------------------------------------------------------- +// +// nsTextHelper constructor +// +//------------------------------------------------------------------------- + +nsTextHelper::nsTextHelper(nsISupports *aOuter) : nsWindow(aOuter) +{ + mIsReadOnly = PR_FALSE; + mIsPassword = PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// nsTextHelper destructor +// +//------------------------------------------------------------------------- +nsTextHelper::~nsTextHelper() +{ +} + +//------------------------------------------------------------------------- +// +// Clear window before paint +// +//------------------------------------------------------------------------- + +PRBool nsTextHelper::AutoErase() +{ + return(PR_TRUE); +} + + diff --git a/mozilla/widget/src/motif/nsTextHelper.h b/mozilla/widget/src/motif/nsTextHelper.h new file mode 100644 index 00000000000..e9dcf94b8fa --- /dev/null +++ b/mozilla/widget/src/motif/nsTextHelper.h @@ -0,0 +1,57 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsTextHelper_h__ +#define nsTextHelper_h__ + +#include "nsITextWidget.h" +#include "nsWindow.h" + +/** + * Base class for nsTextAreaWidget and nsTextWidget + */ + +class nsTextHelper : public nsWindow, public nsITextWidget +{ + +public: + nsTextHelper(nsISupports *aOuter); + virtual ~nsTextHelper(); + + virtual void SelectAll(); + 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); + virtual void RemoveText(); + virtual void SetPassword(PRBool aIsPassword); + virtual PRBool SetReadOnly(PRBool aReadOnlyFlag); + virtual void SetSelection(PRUint32 aStartSel, PRUint32 aEndSel); + virtual void GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel); + virtual void SetCaretPosition(PRUint32 aPosition); + virtual PRUint32 GetCaretPosition(); + virtual void PreCreateWidget(nsWidgetInitData *aInitData); + virtual PRBool AutoErase(); + +protected: + + PRBool mIsPassword; + PRBool mIsReadOnly; + +}; + +#endif // nsTextHelper_h__