Continued to implement the remain methods

This commit is contained in:
rods 1998-07-02 21:18:04 +00:00
parent d138bc14e1
commit 73324e9369
6 changed files with 182 additions and 82 deletions

View File

@ -52,7 +52,7 @@ void nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
str = XmStringCreateLocalized(val);
XmListAddItem(mWidget, str, (int)aPosition);
XmListAddItem(mWidget, str, (int)aPosition+1);
NS_FREE_STR_BUF(val);
}
@ -64,8 +64,15 @@ void nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
{
NS_ALLOC_STR_BUF(val, aItem, 256);
int index = 0;//::SendMessage(mWnd, LB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val);
XmString str = XmStringCreate(val, XmFONTLIST_DEFAULT_TAG);
int index = XmListItemPos(mWidget, str)-1;
if (index < aStartPos) {
index = -1;
}
NS_FREE_STR_BUF(val);
XmStringFree(str);
return index;
}
@ -77,7 +84,10 @@ PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
//-------------------------------------------------------------------------
PRInt32 nsListBox::GetItemCount()
{
return (PRInt32)0;//::SendMessage(mWnd, LB_GETCOUNT, (int)0, (LPARAM)0);
int count = 0;
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
return (PRInt32)count;
}
//-------------------------------------------------------------------------
@ -87,29 +97,38 @@ PRInt32 nsListBox::GetItemCount()
//-------------------------------------------------------------------------
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
{
int status = 0;//::SendMessage(mWnd, LB_DELETESTRING, (int)aPosition, (LPARAM)(LPCTSTR)0);
return 0;//(status != LB_ERR?PR_TRUE:PR_FALSE);
int count = 0;
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
if (aPosition >= 0 && aPosition < count) {
XmListDeletePos(mWidget, aPosition+1);
return PR_TRUE;
}
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//
//-------------------------------------------------------------------------
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
{
PRBool result = PR_FALSE;
/*int len = ::SendMessage(mWnd, LB_GETTEXTLEN, (int)aPosition, (LPARAM)0);
if (len != LB_ERR) {
char * str = new char[len+1];
anItem.SetLength(0);
int status = ::SendMessage(mWnd, LB_GETTEXT, (int)aPosition, (LPARAM)(LPCTSTR)str);
if (status != LB_ERR) {
anItem.Append(str);
XmStringTable list;
int count = 0;
XtVaGetValues(mWidget, XmNitems, &list, XmNitemCount, &count, nsnull);
if (aPosition >= 0 && aPosition < count) {
char * text;
if (XmStringGetLtoR(list[aPosition], XmFONTLIST_DEFAULT_TAG, &text)) {
anItem.SetLength(0);
anItem.Append(text);
XtFree(text);
result = PR_TRUE;
}
delete str;
}*/
}
return result;
}
@ -120,8 +139,13 @@ PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
//-------------------------------------------------------------------------
void nsListBox::GetSelectedItem(nsString& aItem)
{
int index = 0;//::SendMessage(mWnd, LB_GETCURSEL, (int)0, (LPARAM)0);
GetItemAt(aItem, index);
int * list;
int count;
if (XmListGetSelectedPos(mWidget, &list, &count)) {
GetItemAt(aItem, list[0]-1);
XtFree((char *)list);
}
}
//-------------------------------------------------------------------------
@ -132,11 +156,21 @@ void nsListBox::GetSelectedItem(nsString& aItem)
PRInt32 nsListBox::GetSelectedIndex()
{
if (!mMultiSelect) {
return 0;//::SendMessage(mWnd, LB_GETCURSEL, (int)0, (LPARAM)0);
int * list;
int count;
if (XmListGetSelectedPos(mWidget, &list, &count)) {
int index = -1;
if (count > 0) {
index = list[0]-1;
}
XtFree((char *)list);
return index;
}
} else {
NS_ASSERTION(0, "Multi selection list box does not support GetSlectedIndex()");
}
return 0;
return -1;
}
//-------------------------------------------------------------------------
@ -146,10 +180,10 @@ PRInt32 nsListBox::GetSelectedIndex()
//-------------------------------------------------------------------------
void nsListBox::SelectItem(PRInt32 aPosition)
{
if (!mMultiSelect) {
//::SendMessage(mWnd, LB_SETCURSEL, (int)aPosition, (LPARAM)0);
} else {
//::SendMessage(mWnd, LB_SETSEL, (WPARAM) (BOOL)PR_TRUE, (LPARAM)(UINT)aPosition);
int count = 0;
XtVaGetValues(mWidget, XmNitemCount, &count, nsnull);
if (aPosition >= 0 && aPosition < count) {
XmListSelectPos(mWidget, aPosition+1, FALSE);
}
}
@ -160,12 +194,9 @@ void nsListBox::SelectItem(PRInt32 aPosition)
//-------------------------------------------------------------------------
PRInt32 nsListBox::GetSelectedCount()
{
if (!mMultiSelect) {
PRInt32 inx = GetSelectedIndex();
return (inx == -1? 0 : 1);
} else {
return 0;//::SendMessage(mWnd, LB_GETSELCOUNT, (int)0, (LPARAM)0);
}
int count = 0;
XtVaGetValues(mWidget, XmNselectedItemCount, &count, nsnull);
return (PRInt32)count;
}
//-------------------------------------------------------------------------
@ -175,7 +206,17 @@ PRInt32 nsListBox::GetSelectedCount()
//-------------------------------------------------------------------------
void nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
{
//::SendMessage(mWnd, LB_GETSELITEMS, (int)aSize, (LPARAM)aIndices);
int * list;
int count;
if (XmListGetSelectedPos(mWidget, &list, &count)) {
int num = aSize > count?count:aSize;
int i;
for (i=0;i<num;i++) {
aIndices[i] = (PRInt32)list[i]-1;
}
XtFree((char *)list);
}
}
//-------------------------------------------------------------------------
@ -185,12 +226,7 @@ void nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
//-------------------------------------------------------------------------
void nsListBox::Deselect()
{
if (!mMultiSelect) {
//::SendMessage(mWnd, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0);
} else {
//::SendMessage(mWnd, LB_SETSEL, (WPARAM) (BOOL)PR_FALSE, (LPARAM)(UINT)-1);
}
XtVaSetValues(mWidget, XmNselectedItemCount, 0);
}
@ -269,10 +305,11 @@ void nsListBox::Create(nsIWidget *aParent,
xmListWidgetClass,
parentWidget,
XmNitemCount, 0,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNx, aRect.x,
XmNy, aRect.y,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
nsnull);
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);

View File

@ -75,6 +75,7 @@ void nsTextAreaWidget::Create(nsIWidget *aParent,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNeditMode, XmMULTI_LINE_EDIT,
XmNeditable, mMakeReadOnly?False:True,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);

View File

@ -17,6 +17,7 @@
*/
#include "nsTextHelper.h"
#include "nsTextWidget.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
@ -58,36 +59,66 @@ void nsTextHelper::SetMaxTextLength(PRUint32 aChars)
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize)
{
char * str = XmTextGetString(mWidget);
aTextBuffer.SetLength(0);
aTextBuffer.Append(str);
PRUint32 len = (PRUint32)strlen(str);
XtFree(str);
return len;
if (!mIsPassword) {
char * str = XmTextGetString(mWidget);
aTextBuffer.SetLength(0);
aTextBuffer.Append(str);
PRUint32 len = (PRUint32)strlen(str);
XtFree(str);
return len;
} else {
PasswordData * data;
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
aTextBuffer = data->mPassword;
return aTextBuffer.Length();
}
}
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::SetText(const nsString& aText)
{
if (!mIsReadOnly) {
//printf("SetText Password %d\n", mIsPassword);
if (!mIsPassword) {
NS_ALLOC_STR_BUF(buf, aText, 512);
XmTextSetString(mWidget, buf);
NS_FREE_STR_BUF(buf);
return(aText.Length());
} else {
PasswordData * data;
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
data->mPassword = aText;
data->mIgnore = True;
char * buf = new char[aText.Length()+1];
memset(buf, '*', aText.Length());
buf[aText.Length()] = 0;
//printf("SetText [%s] [%s]\n", data->mPassword.ToNewCString(), buf);
XmTextSetString(mWidget, buf);
data->mIgnore = False;
}
return 0;
return(aText.Length());
}
//-------------------------------------------------------------------------
PRUint32 nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos)
{
if (!mIsReadOnly) {
if (!mIsPassword) {
NS_ALLOC_STR_BUF(buf, aText, 512);
XmTextInsert(mWidget, aStartPos, buf);
NS_FREE_STR_BUF(buf);
} else {
PasswordData * data;
XtVaGetValues(mWidget, XmNuserData, &data, NULL);
data->mIgnore = True;
data->mPassword.Insert(aText, aStartPos, aText.Length());
char * buf = new char[data->mPassword.Length()+1];
memset(buf, '*', data->mPassword.Length());
buf[data->mPassword.Length()] = 0;
//printf("SetText [%s] [%s]\n", data->mPassword.ToNewCString(), buf);
XmTextInsert(mWidget, aStartPos, buf);
data->mIgnore = False;
}
return(0);
return(aText.Length());
}
//-------------------------------------------------------------------------
@ -96,9 +127,7 @@ void nsTextHelper::RemoveText()
char blank[2];
blank[0] = 0;
if (!mIsReadOnly) {
XmTextSetString(mWidget, blank);
}
XmTextSetString(mWidget, blank);
}
//-------------------------------------------------------------------------
@ -110,10 +139,12 @@ void nsTextHelper::SetPassword(PRBool aIsPassword)
//-------------------------------------------------------------------------
PRBool nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag)
{
NS_ASSERTION(mWidget != nsnull, "SetReadOnly - Widget is NULL, Create may not have been called!");
NS_ASSERTION(mWidget != nsnull,
"SetReadOnly - Widget is NULL, Create may not have been called!");
PRBool oldSetting = mIsReadOnly;
mIsReadOnly = aReadOnlyFlag;
XmTextSetEditable(mWidget, aReadOnlyFlag);
XmTextSetEditable(mWidget, aReadOnlyFlag?False:True);
return(oldSetting);
}
@ -134,8 +165,8 @@ void nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
XmTextPosition right = (XmTextPosition)aEndSel;
Time time;
XmTextSetSelection(mWidget, left, right, time);
printf("SetSel %d %d\n", left, right);
XmTextSetSelection(mWidget, left, right, 0);
}
@ -145,9 +176,13 @@ void nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
XmTextPosition left;
XmTextPosition right;
XmTextGetSelectionPosition(mWidget, &left, &right);
*aStartSel = left;
*aEndSel = 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");
}
}
//-------------------------------------------------------------------------

View File

@ -78,6 +78,7 @@ void nsTextWidget::Create(nsIWidget *aParent,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNeditable, mMakeReadOnly?False:True,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
@ -94,7 +95,13 @@ void nsTextWidget::Create(nsIWidget *aParent,
}
if (mMakePassword) {
SetPassword(PR_TRUE);
PasswordData * data = new PasswordData();
data->mPassword = "";
XtVaSetValues(mWidget, XmNuserData, data, NULL);
}
}
@ -165,6 +172,7 @@ void nsTextWidget::SetPassword(PRBool aIsPassword)
mIsPasswordCallBacksInstalled = PR_FALSE;
}
}
mHelper->SetPassword(aIsPassword);
}
//--------------------------------------------------------------

View File

@ -24,11 +24,15 @@
#include "nsITextWidget.h"
typedef struct _PasswordData {
nsString mPassword;
Boolean mIgnore;
} PasswordData;
/**
* Native Motif single line edit control wrapper.
*/
//class nsTextWidget : public nsTextHelper
class nsTextWidget : public nsWindow
{

View File

@ -20,6 +20,7 @@
#include "nsXtEventHandler.h"
#include "nsWindow.h"
#include "nsTextWidget.h"
#include "nsCheckButton.h"
#include "nsRadioButton.h"
#include "nsFileWidget.h"
@ -619,40 +620,54 @@ void nsXtWidget_Text_Callback(Widget w, XtPointer p, XtPointer call_data)
{
if (DBG) fprintf(stderr, "In nsXtWidget_Text_Callback\n");
nsWindow * widgetWindow = (nsWindow *) p ;
static char * passwd;
char * newStr;
int len;
XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct *) call_data;
if (cbs->reason == XmCR_ACTIVATE) {
//printf ("Password: %s\n", passwd);
return;
PasswordData * data;
XtVaGetValues(w, XmNuserData, &data, NULL);
if (data == NULL || data->mIgnore) {
return;
}
if (cbs->reason == XmCR_ACTIVATE) {
printf ("Password: %s\n", data->mPassword.ToNewCString());
return;
}
printf("start %d insert %d len %d end %d ptr [%s]\n",
cbs->startPos, cbs->currInsert, cbs->text->length, cbs->endPos, cbs->text->ptr);
if (cbs->startPos < cbs->currInsert) { /* backspace */
cbs->endPos = strlen (passwd); /* delete from here to end */
passwd[cbs->startPos] = 0; /* backspace--terminate */
cbs->endPos = data->mPassword.Length(); /* delete from here to end */
data->mPassword.SetLength(cbs->startPos); /* backspace--terminate */
printf("[%s]\n", data == NULL?"<null>":data->mPassword.ToNewCString());
return;
}
if (cbs->text->length > 1) {
cbs->doit = False; /* don't allow "paste" operations */
return; /* make the user *type* the password! */
//if (cbs->text->length > 1) {
//cbs->doit = False; /* don't allow "paste" operations */
//return; /* make the user *type* the password! */
//}
if (cbs->startPos == cbs->currInsert && cbs->currInsert < data->mPassword.Length()) {
printf("Inserting [%s] at %d\n", cbs->text->ptr, cbs->currInsert);
nsString insStr(cbs->text->ptr);
data->mPassword.Insert(insStr, cbs->currInsert, strlen(cbs->text->ptr));
} else if (cbs->startPos == cbs->currInsert && cbs->endPos != cbs->startPos) {
data->mPassword.SetLength(cbs->startPos);
printf("Setting Length [%s] at %d\n", cbs->text->ptr, cbs->currInsert);
} else if (cbs->startPos == cbs->currInsert) { /* backspace */
data->mPassword.Append(cbs->text->ptr);
printf("Appending [%s] at %d\n", cbs->text->ptr, cbs->currInsert);
} else {
printf("Shouldn't be here!\n");
}
newStr = XtMalloc (cbs->endPos + 2); /* new char + NULL terminator */
if (passwd) {
strcpy (newStr, passwd);
XtFree (passwd);
} else
newStr[0] = 0;
passwd = newStr;
strncat (passwd, cbs->text->ptr, cbs->text->length);
passwd[cbs->endPos + cbs->text->length] = 0;
for (len = 0; len < cbs->text->length; len++)
cbs->text->ptr[len] = '*';
cbs->text->ptr[len] = '*';
if (DBG) fprintf(stderr, "Out nsXtWidget_Text_Callback\n");
}