1 /* $TOG: EncryptedTextFieldUiItem.C /main/2 1997/11/13 13:25:10 mgreess $ */
5 * RESTRICTED CONFIDENTIAL INFORMATION:
7 * The information in this document is subject to special
8 * restrictions in a confidential disclosure agreement bertween
9 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
10 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
11 * Sun's specific written approval. This documment and all copies
12 * and derivative works thereof must be returned or destroyed at
15 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
20 #include <sys/param.h>
23 #include <DtMail/options_util.h>
24 #include <DtMail/EncryptedTextFieldUiItem.hh>
25 #include <DtMail/PropUi.hh>
26 #include <DtMail/DtMailServer.hh>
27 #include <DtMail/DtMailTypes.h>
29 ////////////////////////////////////////////////////////////////////
30 EncryptedTextFieldUiItem::EncryptedTextFieldUiItem(
34 PropUiCallback validator,
36 : PropUiItem(w, source, search_key, validator, validator_data)
40 _text = (char*) malloc(_maxtextlen);
42 _writeAllowed = DTM_FALSE;
51 XmNmodifyVerifyCallback, EncryptedTextFieldUiItem::verifyCB,
54 options_field_init(w, &(this->dirty_bit));
57 ///////////////////////////////////////////////////////////////////
58 void EncryptedTextFieldUiItem::writeAllowed(DtMailBoolean allowed)
60 Widget w = getWidget();
62 if (_writeAllowed == allowed) return;
64 _writeAllowed = allowed;
65 if (DTM_TRUE == _writeAllowed)
68 char *value = strdup(_text);
70 for (s=value; *s; s++) *s = '*';
73 XtVaSetValues(w, XmNeditable, True, XmNsensitive, True, NULL);
74 options_field_set_value(w, value, this->dirty_bit);
82 XtVaSetValues(w, XmNeditable, False, XmNsensitive, False, NULL);
83 options_field_set_value(w, "", this->dirty_bit);
90 // Takes values in the UI and puts them into the source DB
91 ///////////////////////////////////////////////////////////////////
92 void EncryptedTextFieldUiItem::writeFromUiToSource()
94 if (DTM_TRUE == _writeAllowed)
95 prop_source->setValue(_text, DTM_TRUE);
97 prop_source->setValue(DTMAS_PROPDFLT_PASSWORD, DTM_TRUE);
100 // Takes values in the UI and puts them into the source DB
101 ///////////////////////////////////////////////////////////////////
102 void EncryptedTextFieldUiItem::writeFromSourceToUi()
106 Widget w = this->getWidget();
108 value = (char *)prop_source->getValue(DTM_TRUE);
109 if (! strcmp(value, PropSourceDEFAULTVALUE)) return;
111 validateLength(strlen(value));
112 strcpy(_text, value);
114 for (i=0, s=value; i<strlen(value); i++, s++)
118 options_field_set_value(w, value, this->dirty_bit);
119 if (NULL != value) free((void*) value);
120 _loading = DTM_FALSE;
123 // Verifies that the _text array is sufficiently long for a string
124 // of the specified size.
125 ///////////////////////////////////////////////////////////////////
126 void EncryptedTextFieldUiItem::validateLength(int length)
128 length++; // Account for the '\0'
129 if (length >= _maxtextlen)
132 _text = (char*) realloc((void*) _text, (size_t) _maxtextlen);
137 ///////////////////////////////////////////////////////////////////
138 void EncryptedTextFieldUiItem::verify(XmTextVerifyPtr cbs)
141 static char buffer[MAXPATHLEN];
142 register char *s, *t;
144 #if defined(ENCRYPTED_TEXTFIELD_DEBUG)
146 "currInsert=%d newInsert=%d startPos=%d endPos=%d\n",
147 cbs->currInsert,cbs->newInsert,cbs->startPos, cbs->endPos);
148 if (cbs->text->ptr) printf("text->ptr=%s\n", cbs->text->ptr);
149 printf("_text->ptr=%s\n", _text);
152 for (i=0, s=buffer, t=_text; (*t && i<cbs->startPos); i++, s++, t++)
157 strcpy(s, cbs->text->ptr);
158 s += cbs->text->length;
163 if (strlen(_text) >= cbs->endPos)
165 t = _text+cbs->endPos;
170 validateLength(strlen(buffer));
171 strcpy(_text, buffer);
174 for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
177 #if defined(ENCRYPTED_TEXTFIELD_DEBUG)
178 printf("text=%s\n", _text);
182 // ValueChangedCallback for the text field. Saves the user input
184 ///////////////////////////////////////////////////////////////////
185 void EncryptedTextFieldUiItem::verifyCB(
187 XtPointer client_data,
190 EncryptedTextFieldUiItem *etf = (EncryptedTextFieldUiItem*) client_data;
191 XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct*) call_data;
193 if (DTM_FALSE == etf->_loading) etf->verify(cbs);