mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00:00
Changed TextField and TextArea to use new inteface definition.
This commit is contained in:
parent
1fe79f4f15
commit
dfb853cfb5
@ -47,12 +47,12 @@ CPPSRCS= \
|
||||
nsObject.cpp \
|
||||
nsWindow.cpp \
|
||||
nsComboBox.cpp \
|
||||
nsTextHelper.cpp \
|
||||
nsTextAreaWidget.cpp \
|
||||
nsTextWidget.cpp \
|
||||
nsListBox.cpp \
|
||||
nsRadioButton.cpp \
|
||||
nsFileWidget.cpp \
|
||||
nsTextHelper.cpp \
|
||||
nsTextWidget.cpp \
|
||||
nsCheckButton.cpp \
|
||||
nsScrollbar.cpp \
|
||||
nsButton.cpp \
|
||||
|
@ -32,10 +32,10 @@
|
||||
// nsTextAreaWidget constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextAreaWidget::nsTextAreaWidget(nsISupports *aOuter) : nsWindow(aOuter),
|
||||
mMakeReadOnly(PR_FALSE)
|
||||
nsTextAreaWidget::nsTextAreaWidget()
|
||||
{
|
||||
//mBackground = NS_RGB(124, 124, 124);
|
||||
mMakeReadOnly = PR_FALSE;
|
||||
mBackground = NS_RGB(124, 124, 124);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -84,7 +84,6 @@ void nsTextAreaWidget::Create(nsIWidget *aParent,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
nsnull);
|
||||
mHelper = new nsTextHelper(mWidget);
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
@ -93,7 +92,8 @@ void nsTextAreaWidget::Create(nsIWidget *aParent,
|
||||
InitCallbacks("nsTextAreaWidget");
|
||||
|
||||
if (mMakeReadOnly) {
|
||||
SetReadOnly(PR_TRUE);
|
||||
PRBool oldReadOnly;
|
||||
SetReadOnly(PR_TRUE, oldReadOnly);
|
||||
}
|
||||
|
||||
}
|
||||
@ -110,29 +110,29 @@ void nsTextAreaWidget::Create(nsNativeWidget aParent,
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsTextAreaWidget::QueryObject(REFNSIID aIID, void** aInstancePtr)
|
||||
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||
|
||||
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
|
||||
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
||||
|
||||
|
||||
if (aIID.Equals(kITextWidgetIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITextAreaWidgetIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
nsITextAreaWidget* textArea = this;
|
||||
*aInstancePtr = (void*) (textArea);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
else if (aIID.Equals(kIWidgetIID))
|
||||
{
|
||||
nsIWidget* widget = this;
|
||||
*aInstancePtr = (void*) (widget);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
return nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
@ -150,175 +150,3 @@ PRBool nsTextAreaWidget::OnResize(nsSizeEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
if (mWidget == nsnull && aReadOnlyFlag) {
|
||||
mMakeReadOnly = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return mHelper->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
mHelper->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return mHelper->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return mHelper->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return mHelper->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::RemoveText()
|
||||
{
|
||||
mHelper->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SelectAll()
|
||||
{
|
||||
mHelper->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
mHelper->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
mHelper->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
mHelper->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::GetCaretPosition()
|
||||
{
|
||||
return mHelper->GetCaretPosition();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::AutoErase()
|
||||
{
|
||||
return mHelper->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
#define GET_OUTER() ((nsTextAreaWidget*) ((char*)this - nsTextAreaWidget::GetOuterOffset()))
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
GET_OUTER()->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return GET_OUTER()->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return GET_OUTER()->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return GET_OUTER()->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::RemoveText()
|
||||
{
|
||||
GET_OUTER()->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
GET_OUTER()->SetPassword(aIsPassword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextAreaWidget::AggTextAreaWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
return GET_OUTER()->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SelectAll()
|
||||
{
|
||||
GET_OUTER()->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
GET_OUTER()->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
GET_OUTER()->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextAreaWidget::AggTextAreaWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
GET_OUTER()->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextAreaWidget::AggTextAreaWidget::GetCaretPosition()
|
||||
{
|
||||
return GET_OUTER()->GetCaretPosition();
|
||||
}
|
||||
|
||||
PRBool nsTextAreaWidget::AggTextAreaWidget::AutoErase()
|
||||
{
|
||||
return GET_OUTER()->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsTextAreaWidget, AggTextAreaWidget);
|
||||
|
||||
|
@ -25,17 +25,20 @@
|
||||
#include "nsITextAreaWidget.h"
|
||||
|
||||
/**
|
||||
* Native Motif single line edit control wrapper.
|
||||
* Native Motif multi-line edit control wrapper.
|
||||
*/
|
||||
|
||||
class nsTextAreaWidget : public nsWindow
|
||||
class nsTextAreaWidget : public nsTextHelper
|
||||
{
|
||||
|
||||
public:
|
||||
nsTextAreaWidget(nsISupports *aOuter);
|
||||
nsTextAreaWidget();
|
||||
virtual ~nsTextAreaWidget();
|
||||
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
@ -57,61 +60,9 @@ public:
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
// nsTextHelper Interface
|
||||
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 PRBool AutoErase();
|
||||
|
||||
protected:
|
||||
nsTextHelper *mHelper;
|
||||
|
||||
private:
|
||||
PRBool mMakeReadOnly;
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsTextAreaWidget,mAggWidget);
|
||||
}
|
||||
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIText interface to nsText w/o using multiple
|
||||
// inheritance.
|
||||
class AggTextAreaWidget : public nsITextAreaWidget {
|
||||
public:
|
||||
AggTextAreaWidget();
|
||||
virtual ~AggTextAreaWidget();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
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 PRBool AutoErase();
|
||||
|
||||
};
|
||||
AggTextAreaWidget mAggWidget;
|
||||
friend class AggTextAreaWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsTextAreaWidget_h__
|
||||
|
@ -34,9 +34,8 @@
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
nsTextHelper::nsTextHelper(Widget aWidget)
|
||||
nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget()
|
||||
{
|
||||
mWidget = aWidget;
|
||||
mIsReadOnly = PR_FALSE;
|
||||
mIsPassword = PR_FALSE;
|
||||
}
|
||||
@ -51,13 +50,14 @@ nsTextHelper::~nsTextHelper()
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetMaxTextLength(PRUint32 aChars)
|
||||
NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
XmTextSetMaxLength(mWidget, (int)aChars);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize)
|
||||
NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize)
|
||||
{
|
||||
if (!mIsPassword) {
|
||||
char * str = XmTextGetString(mWidget);
|
||||
@ -65,19 +65,19 @@ PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize)
|
||||
aTextBuffer.Append(str);
|
||||
PRUint32 len = (PRUint32)strlen(str);
|
||||
XtFree(str);
|
||||
return len;
|
||||
aActualSize = len;
|
||||
} else {
|
||||
PasswordData * data;
|
||||
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
|
||||
aTextBuffer = data->mPassword;
|
||||
return aTextBuffer.Length();
|
||||
aActualSize = aTextBuffer.Length();
|
||||
}
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::SetText(const nsString& aText)
|
||||
NS_METHOD nsTextHelper::SetText(const nsString& aText, PRUint32& aActualSize)
|
||||
{
|
||||
//printf("SetText Password %d\n", mIsPassword);
|
||||
if (!mIsPassword) {
|
||||
NS_ALLOC_STR_BUF(buf, aText, 512);
|
||||
XmTextSetString(mWidget, buf);
|
||||
@ -94,11 +94,12 @@ PRUint32 nsTextHelper::SetText(const nsString& aText)
|
||||
XmTextSetString(mWidget, buf);
|
||||
data->mIgnore = False;
|
||||
}
|
||||
return(aText.Length());
|
||||
aActualSize = aText.Length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize)
|
||||
{
|
||||
|
||||
if (!mIsPassword) {
|
||||
@ -118,91 +119,93 @@ PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PR
|
||||
XmTextInsert(mWidget, aStartPos, buf);
|
||||
data->mIgnore = False;
|
||||
}
|
||||
return(aText.Length());
|
||||
|
||||
aActualSize = aText.Length();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::RemoveText()
|
||||
NS_METHOD nsTextHelper::RemoveText()
|
||||
{
|
||||
char blank[2];
|
||||
blank[0] = 0;
|
||||
|
||||
XmTextSetString(mWidget, blank);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetPassword(PRBool aIsPassword)
|
||||
NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
mIsPassword = aIsPassword;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldReadOnlyFlag)
|
||||
{
|
||||
NS_ASSERTION(mWidget != nsnull,
|
||||
"SetReadOnly - Widget is NULL, Create may not have been called!");
|
||||
PRBool oldSetting = mIsReadOnly;
|
||||
aOldReadOnlyFlag = mIsReadOnly;
|
||||
mIsReadOnly = aReadOnlyFlag;
|
||||
XmTextSetEditable(mWidget, aReadOnlyFlag?False:True);
|
||||
|
||||
return(oldSetting);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SelectAll()
|
||||
NS_METHOD nsTextHelper::SelectAll()
|
||||
{
|
||||
nsString text;
|
||||
PRUint32 numChars = GetText(text, 0);
|
||||
PRUint32 actualSize = 0;
|
||||
PRUint32 numChars = GetText(text, 0, actualSize);
|
||||
SetSelection(0, numChars);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
XmTextPosition left = (XmTextPosition)aStartSel;
|
||||
XmTextPosition right = (XmTextPosition)aEndSel;
|
||||
|
||||
Time time;
|
||||
printf("SetSel %d %d\n", left, right);
|
||||
XmTextSetSelection(mWidget, left, right, 0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
XmTextPosition left;
|
||||
XmTextPosition right;
|
||||
|
||||
if (XmTextGetSelectionPosition(mWidget, &left, &right)) {
|
||||
printf("left %d right %d\n", left, right);
|
||||
*aStartSel = (PRUint32)left;
|
||||
*aEndSel = (PRUint32)right;
|
||||
} else {
|
||||
printf("nsTextHelper::GetSelection Error getting positions\n");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
void nsTextHelper::SetCaretPosition(PRUint32 aPosition)
|
||||
NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
XmTextSetInsertionPosition(mWidget, (XmTextPosition)aPosition);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRUint32 nsTextHelper::GetCaretPosition()
|
||||
NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPosition)
|
||||
{
|
||||
return (PRUint32)XmTextGetInsertionPosition(mWidget);
|
||||
aPosition = (PRUint32)XmTextGetInsertionPosition(mWidget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsTextHelper::AutoErase()
|
||||
{
|
||||
return(PR_TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define nsTextHelper_h__
|
||||
|
||||
#include "nsITextWidget.h"
|
||||
#include "nsITextAreaWidget.h"
|
||||
#include "nsWindow.h"
|
||||
#include <Xm/Xm.h>
|
||||
|
||||
@ -26,32 +27,32 @@
|
||||
* Base class for nsTextAreaWidget and nsTextWidget
|
||||
*/
|
||||
|
||||
class nsTextHelper
|
||||
class nsTextHelper : public nsWindow,
|
||||
public nsITextAreaWidget,
|
||||
public nsITextWidget
|
||||
{
|
||||
|
||||
public:
|
||||
nsTextHelper(Widget aWidget);
|
||||
nsTextHelper();
|
||||
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();
|
||||
NS_IMETHOD SelectAll();
|
||||
NS_IMETHOD SetMaxTextLength(PRUint32 aChars);
|
||||
NS_IMETHOD GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize);
|
||||
NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize);
|
||||
NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize);
|
||||
NS_IMETHOD RemoveText();
|
||||
NS_IMETHOD SetPassword(PRBool aIsPassword);
|
||||
NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag);
|
||||
NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||
NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||
NS_IMETHOD SetCaretPosition(PRUint32 aPosition);
|
||||
NS_IMETHOD GetCaretPosition(PRUint32& aPosition);
|
||||
|
||||
protected:
|
||||
Widget mWidget;
|
||||
PRBool mIsPassword;
|
||||
PRBool mIsReadOnly;
|
||||
// Widget mWidget;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -34,12 +34,11 @@ extern int mIsPasswordCallBacksInstalled;
|
||||
// nsTextWidget constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsTextWidget::nsTextWidget(nsISupports *aOuter) : nsWindow(aOuter),
|
||||
nsTextWidget::nsTextWidget() : nsTextHelper(),
|
||||
mIsPasswordCallBacksInstalled(PR_FALSE),
|
||||
mMakeReadOnly(PR_FALSE),
|
||||
mMakePassword(PR_FALSE)
|
||||
{
|
||||
//mBackground = NS_RGB(124, 124, 124);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -88,7 +87,6 @@ void nsTextWidget::Create(nsIWidget *aParent,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
nsnull);
|
||||
mHelper = new nsTextHelper(mWidget);
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
@ -107,7 +105,8 @@ void nsTextWidget::Create(nsIWidget *aParent,
|
||||
this);
|
||||
|
||||
if (mMakeReadOnly) {
|
||||
SetReadOnly(PR_TRUE);
|
||||
PRUint32 oldReadOnly;
|
||||
SetReadOnly(PR_TRUE, oldReadOnly);
|
||||
}
|
||||
if (mMakePassword) {
|
||||
SetPassword(PR_TRUE);
|
||||
@ -133,24 +132,6 @@ void nsTextWidget::Create(nsNativeWidget aParent,
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsTextWidget::QueryObject(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||
|
||||
if (aIID.Equals(kITextWidgetIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryObject(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// paint, resizes message - ignore
|
||||
@ -169,7 +150,7 @@ PRBool nsTextWidget::OnResize(nsSizeEvent &aEvent)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetPassword(PRBool aIsPassword)
|
||||
NS_METHOD nsTextWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
if (mWidget == nsnull && aIsPassword) {
|
||||
mMakePassword = PR_TRUE;
|
||||
@ -189,172 +170,9 @@ void nsTextWidget::SetPassword(PRBool aIsPassword)
|
||||
mIsPasswordCallBacksInstalled = PR_FALSE;
|
||||
}
|
||||
}
|
||||
mHelper->SetPassword(aIsPassword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
if (mWidget == nsnull && aReadOnlyFlag) {
|
||||
mMakeReadOnly = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return mHelper->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
mHelper->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return mHelper->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return mHelper->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return mHelper->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::RemoveText()
|
||||
{
|
||||
mHelper->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SelectAll()
|
||||
{
|
||||
mHelper->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
mHelper->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
mHelper->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
mHelper->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::GetCaretPosition()
|
||||
{
|
||||
return mHelper->GetCaretPosition();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::AutoErase()
|
||||
{
|
||||
return mHelper->AutoErase();
|
||||
nsTextHelper::SetPassword(aIsPassword);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
#define GET_OUTER() ((nsTextWidget*) ((char*)this - nsTextWidget::GetOuterOffset()))
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetMaxTextLength(PRUint32 aChars)
|
||||
{
|
||||
GET_OUTER()->SetMaxTextLength(aChars);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::GetText(nsString& aTextBuffer, PRUint32 aBufferSize) {
|
||||
return GET_OUTER()->GetText(aTextBuffer, aBufferSize);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::SetText(const nsString& aText)
|
||||
{
|
||||
return GET_OUTER()->SetText(aText);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
|
||||
{
|
||||
return GET_OUTER()->InsertText(aText, aStartPos, aEndPos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::RemoveText()
|
||||
{
|
||||
GET_OUTER()->RemoveText();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetPassword(PRBool aIsPassword)
|
||||
{
|
||||
GET_OUTER()->SetPassword(aIsPassword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRBool nsTextWidget::AggTextWidget::SetReadOnly(PRBool aReadOnlyFlag)
|
||||
{
|
||||
return GET_OUTER()->SetReadOnly(aReadOnlyFlag);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SelectAll()
|
||||
{
|
||||
GET_OUTER()->SelectAll();
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||
{
|
||||
GET_OUTER()->SetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||
{
|
||||
GET_OUTER()->GetSelection(aStartSel, aEndSel);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void nsTextWidget::AggTextWidget::SetCaretPosition(PRUint32 aPosition)
|
||||
{
|
||||
GET_OUTER()->SetCaretPosition(aPosition);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
PRUint32 nsTextWidget::AggTextWidget::GetCaretPosition()
|
||||
{
|
||||
return GET_OUTER()->GetCaretPosition();
|
||||
}
|
||||
|
||||
PRBool nsTextWidget::AggTextWidget::AutoErase()
|
||||
{
|
||||
return GET_OUTER()->AutoErase();
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsTextWidget, AggTextWidget);
|
||||
|
||||
|
@ -33,14 +33,16 @@ typedef struct _PasswordData {
|
||||
* Native Motif single line edit control wrapper.
|
||||
*/
|
||||
|
||||
class nsTextWidget : public nsWindow
|
||||
class nsTextWidget : public nsTextHelper
|
||||
{
|
||||
|
||||
public:
|
||||
nsTextWidget(nsISupports *aOuter);
|
||||
nsTextWidget();
|
||||
virtual ~nsTextWidget();
|
||||
|
||||
NS_IMETHOD QueryObject(REFNSIID aIID, void** aInstancePtr);
|
||||
// nsISupports. Forware to the nsObject base class
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
@ -61,64 +63,15 @@ public:
|
||||
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent);
|
||||
virtual PRBool OnResize(nsSizeEvent &aEvent);
|
||||
|
||||
// nsTextHelper Interface
|
||||
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 PRBool AutoErase();
|
||||
NS_IMETHOD SetPassword(PRBool aIsPassword);
|
||||
|
||||
protected:
|
||||
PRBool mIsPasswordCallBacksInstalled;
|
||||
nsTextHelper *mHelper;
|
||||
|
||||
private:
|
||||
PRBool mMakeReadOnly;
|
||||
PRBool mMakePassword;
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsTextWidget,mAggWidget);
|
||||
}
|
||||
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIText interface to nsText w/o using multiple
|
||||
// inheritance.
|
||||
class AggTextWidget : public nsITextWidget {
|
||||
public:
|
||||
AggTextWidget();
|
||||
virtual ~AggTextWidget();
|
||||
|
||||
AGGREGATE_METHOD_DEF
|
||||
|
||||
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 PRBool AutoErase();
|
||||
|
||||
};
|
||||
AggTextWidget mAggWidget;
|
||||
friend class AggTextWidget;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsTextWidget_h__
|
||||
|
@ -182,7 +182,9 @@ protected:
|
||||
virtual void UpdateVisibilityFlag();
|
||||
virtual void UpdateDisplay();
|
||||
|
||||
public:
|
||||
Widget mWidget;
|
||||
protected:
|
||||
EVENT_CALLBACK mEventCallback;
|
||||
nsIDeviceContext *mContext;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
|
Loading…
Reference in New Issue
Block a user