Initial nsText* implimentation. This should be about 90% functional.

This commit is contained in:
pavlov%pavlov.net 1998-11-08 04:05:34 +00:00
Родитель 84c38473e3
Коммит 2a87f9c8c0
4 изменённых файлов: 72 добавлений и 59 удалений

Просмотреть файл

@ -59,16 +59,15 @@ NS_METHOD nsTextAreaWidget::Create(nsIWidget *aParent,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
#if 0
aParent->AddChild(this);
Widget parentWidget = nsnull;
GtkWidget *parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
parentWidget = GTK_WIDGET(aParent->GetNativeData(NS_NATIVE_WIDGET));
} else {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
parentWidget = GTK_WIDGET(aAppShell->GetNativeData(NS_NATIVE_SHELL));
}
InitToolkit(aToolkit, aParent);
@ -76,19 +75,27 @@ NS_METHOD nsTextAreaWidget::Create(nsIWidget *aParent,
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
mWidget = gtk_text_new(FALSE, FALSE);
gtk_layout_put(GTK_LAYOUT(parentWidget), mWidget, aRect.x, aRect.y);
gtk_widget_set_usize(mWidget, aRect.width, aRect.height);
gtk_widget_show(mWidget);
/*
mWidget = ::XtVaCreateManagedWidget("button",
xmTextWidgetClass,
parentWidget,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNrecomputeSize, PR_FALSE,
XmNhighlightOnEnter, PR_FALSE,
XmNeditMode, XmMULTI_LINE_EDIT,
XmNeditable, mMakeReadOnly?False:True,
XmNeditable, mMakeReadOnly?PR_FALSE:PR_TRUE,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
*/
// save the event callback function
mEventCallback = aHandleEventFunction;
@ -98,7 +105,6 @@ NS_METHOD nsTextAreaWidget::Create(nsIWidget *aParent,
PRBool oldReadOnly;
SetReadOnly(PR_TRUE, oldReadOnly);
}
#endif
return NS_OK;
}

Просмотреть файл

@ -52,54 +52,69 @@ nsTextHelper::~nsTextHelper()
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars)
{
#if 0
XmTextSetMaxLength(mWidget, (int)aChars);
#endif
// This is a normal entry only thing, not a text box
gtk_entry_set_max_length(GTK_ENTRY(mWidget), (int)aChars);
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize)
{
#if 0
char *str;
if (!mIsPassword) {
char * str = XmTextGetString(mWidget);
if (GTK_IS_ENTRY(mWidget))
{
str = gtk_entry_get_text(GTK_ENTRY(mWidget));
}
else if (GTK_IS_TEXT(mWidget))
{
str = gtk_editable_get_chars (GTK_EDITABLE (mWidget), 0,
gtk_text_get_length (GTK_TEXT (mWidget)));
}
aTextBuffer.SetLength(0);
aTextBuffer.Append(str);
PRUint32 len = (PRUint32)strlen(str);
XtFree(str);
aActualSize = len;
} else {
/*
PasswordData * data;
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
aTextBuffer = data->mPassword;
aActualSize = aTextBuffer.Length();
*/
}
#endif
return(NS_OK);
}
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetText(const nsString& aText, PRUint32& aActualSize)
{
#if 0
if (!mIsPassword) {
NS_ALLOC_STR_BUF(buf, aText, 512);
XmTextSetString(mWidget, buf);
if (GTK_IS_ENTRY(mWidget))
{
gtk_entry_set_text(GTK_ENTRY(mWidget), buf);
}
else if (GTK_IS_TEXT(mWidget))
{
gtk_text_insert(GTK_TEXT(mWidget), NULL, NULL, NULL, buf, aActualSize);
}
NS_FREE_STR_BUF(buf);
} else {
/*
PasswordData * data;
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
data->mPassword = aText;
data->mIgnore = True;
data->mIgnore = PR_TRUE;
char * buf = new char[aText.Length()+1];
memset(buf, '*', aText.Length());
buf[aText.Length()] = 0;
XmTextSetString(mWidget, buf);
data->mIgnore = False;
gtk_entry_set_text(GTK_ENTRY(mWidget), buf);
data->mIgnore = PR_FALSE;
*/
}
aActualSize = aText.Length();
#endif
return NS_OK;
}
@ -114,14 +129,14 @@ NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, P
} else {
PasswordData * data;
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
data->mIgnore = True;
data->mIgnore = PR_TRUE;
nsString newText(aText);
data->mPassword.Insert(newText, aStartPos, aText.Length());
char * buf = new char[data->mPassword.Length()+1];
memset(buf, '*', data->mPassword.Length());
buf[data->mPassword.Length()] = 0;
XmTextInsert(mWidget, aStartPos, buf);
data->mIgnore = False;
data->mIgnore = PR_FALSE;
}
aActualSize = aText.Length();
#endif
@ -131,12 +146,7 @@ NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, P
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::RemoveText()
{
#if 0
char blank[2];
blank[0] = 0;
XmTextSetString(mWidget, blank);
#endif
gtk_entry_set_text(GTK_ENTRY(mWidget), "");
return NS_OK;
}
@ -150,13 +160,11 @@ NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldReadOnlyFlag)
{
#if 0
NS_ASSERTION(nsnull != mWidget,
"SetReadOnly - Widget is NULL, Create may not have been called!");
aOldReadOnlyFlag = mIsReadOnly;
mIsReadOnly = aReadOnlyFlag;
XmTextSetEditable(mWidget, aReadOnlyFlag?False:True);
#endif
gtk_editable_set_editable(GTK_EDITABLE(mWidget), aReadOnlyFlag?PR_FALSE:PR_TRUE);
return NS_OK;
}
@ -164,12 +172,10 @@ NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldReadOnlyF
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SelectAll()
{
#if 0
nsString text;
PRUint32 actualSize = 0;
PRUint32 numChars = GetText(text, 0, actualSize);
SetSelection(0, numChars);
#endif
return NS_OK;
}
@ -177,13 +183,7 @@ NS_METHOD nsTextHelper::SelectAll()
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
{
#if 0
XmTextPosition left = (XmTextPosition)aStartSel;
XmTextPosition right = (XmTextPosition)aEndSel;
Time time;
XmTextSetSelection(mWidget, left, right, 0);
#endif
gtk_editable_select_region(GTK_EDITABLE(mWidget), aStartSel, aEndSel);
return NS_OK;
}
@ -209,17 +209,13 @@ NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition)
{
#if 0
XmTextSetInsertionPosition(mWidget, (XmTextPosition)aPosition);
#endif
gtk_editable_set_position(GTK_EDITABLE(mWidget), aPosition);
return NS_OK;
}
//-------------------------------------------------------------------------
NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPosition)
{
#if 0
aPosition = (PRUint32)XmTextGetInsertionPosition(mWidget);
#endif
aPosition = (PRUint32)GTK_EDITABLE(mWidget)->current_pos;
return NS_OK;
}

Просмотреть файл

@ -62,36 +62,43 @@ NS_METHOD nsTextWidget::Create(nsIWidget *aParent,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
#if 0
aParent->AddChild(this);
Widget parentWidget = nsnull;
GtkWidget *parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
parentWidget = GTK_WIDGET(aParent->GetNativeData(NS_NATIVE_WIDGET));
} else {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
parentWidget = GTK_WIDGET(aAppShell->GetNativeData(NS_NATIVE_SHELL));
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
mWidget = gtk_entry_new();
gtk_entry_set_editable(GTK_ENTRY(mWidget), mMakeReadOnly?PR_FALSE:PR_TRUE);
gtk_layout_put(GTK_LAYOUT(parentWidget), mWidget, aRect.x, aRect.y);
gtk_widget_set_usize(mWidget, aRect.width, aRect.height);
gtk_widget_show(mWidget);
/*
mWidget = ::XtVaCreateManagedWidget("button",
xmTextWidgetClass,
parentWidget,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNeditable, mMakeReadOnly?False:True,
XmNrecomputeSize, PR_FALSE,
XmNhighlightOnEnter, PR_FALSE,
XmNeditable, mMakeReadOnly?PR_FALSE:PR_TRUE,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
*/
// save the event callback function
mEventCallback = aHandleEventFunction;
/*
InitCallbacks("nsTextWidget");
XtAddCallback(mWidget,
@ -103,18 +110,20 @@ NS_METHOD nsTextWidget::Create(nsIWidget *aParent,
XmNlosingFocusCallback,
nsXtWidget_Focus_Callback,
this);
*/
if (mMakeReadOnly) {
PRUint32 oldReadOnly;
SetReadOnly(PR_TRUE, oldReadOnly);
}
if (mMakePassword) {
SetPassword(PR_TRUE);
/*
PasswordData * data = new PasswordData();
data->mPassword = "";
XtVaSetValues(mWidget, XmNuserData, data, NULL);
*/
}
#endif
return NS_OK;
}
@ -175,6 +184,7 @@ NS_METHOD nsTextWidget::SetPassword(PRBool aIsPassword)
mMakePassword = PR_TRUE;
return NS_OK;
}
gtk_entry_set_visibility(GTK_ENTRY(mWidget), aIsPassword);
#if 0
if (aIsPassword) {
if (!mIsPasswordCallBacksInstalled) {

Просмотреть файл

@ -23,6 +23,7 @@
#include "nsToolkit.h"
#include "nsIAppShell.h"
#include <gtk/gtk.h>
#include "gtklayout.h"
/**
* Base of all GTK native widgets.