2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: EncryptedTextFieldUiItem.C /main/2 1997/11/13 13:25:10 mgreess $ */
27 * RESTRICTED CONFIDENTIAL INFORMATION:
29 * The information in this document is subject to special
30 * restrictions in a confidential disclosure agreement bertween
31 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
32 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33 * Sun's specific written approval. This documment and all copies
34 * and derivative works thereof must be returned or destroyed at
37 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
42 #include <sys/param.h>
45 #include <DtMail/options_util.h>
46 #include <DtMail/EncryptedTextFieldUiItem.hh>
47 #include <DtMail/PropUi.hh>
48 #include <DtMail/DtMailServer.hh>
49 #include <DtMail/DtMailTypes.h>
51 ////////////////////////////////////////////////////////////////////
52 EncryptedTextFieldUiItem::EncryptedTextFieldUiItem(
56 PropUiCallback validator,
58 : PropUiItem(w, source, search_key, validator, validator_data)
62 _text = (char*) malloc(_maxtextlen);
64 _writeAllowed = DTM_FALSE;
73 XmNmodifyVerifyCallback, EncryptedTextFieldUiItem::verifyCB,
76 options_field_init(w, &(this->dirty_bit));
79 ///////////////////////////////////////////////////////////////////
80 void EncryptedTextFieldUiItem::writeAllowed(DtMailBoolean allowed)
82 Widget w = getWidget();
84 if (_writeAllowed == allowed) return;
86 _writeAllowed = allowed;
87 if (DTM_TRUE == _writeAllowed)
90 char *value = strdup(_text);
92 for (s=value; *s; s++) *s = '*';
95 XtVaSetValues(w, XmNeditable, True, XmNsensitive, True, NULL);
96 options_field_set_value(w, value, this->dirty_bit);
104 XtVaSetValues(w, XmNeditable, False, XmNsensitive, False, NULL);
105 options_field_set_value(w, "", this->dirty_bit);
106 _loading = DTM_FALSE;
112 // Takes values in the UI and puts them into the source DB
113 ///////////////////////////////////////////////////////////////////
114 void EncryptedTextFieldUiItem::writeFromUiToSource()
116 if (DTM_TRUE == _writeAllowed)
117 prop_source->setValue(_text, DTM_TRUE);
119 prop_source->setValue(DTMAS_PROPDFLT_PASSWORD, DTM_TRUE);
122 // Takes values in the UI and puts them into the source DB
123 ///////////////////////////////////////////////////////////////////
124 void EncryptedTextFieldUiItem::writeFromSourceToUi()
128 Widget w = this->getWidget();
130 value = (char *)prop_source->getValue(DTM_TRUE);
131 if (! strcmp(value, PropSourceDEFAULTVALUE)) return;
133 validateLength(strlen(value));
134 strcpy(_text, value);
136 for (i=0, s=value; i<strlen(value); i++, s++)
140 options_field_set_value(w, value, this->dirty_bit);
142 _loading = DTM_FALSE;
145 // Verifies that the _text array is sufficiently long for a string
146 // of the specified size.
147 ///////////////////////////////////////////////////////////////////
148 void EncryptedTextFieldUiItem::validateLength(int length)
150 length++; // Account for the '\0'
151 if (length >= _maxtextlen)
154 _text = (char*) realloc((void*) _text, (size_t) _maxtextlen);
159 ///////////////////////////////////////////////////////////////////
160 void EncryptedTextFieldUiItem::verify(XmTextVerifyPtr cbs)
163 static char buffer[MAXPATHLEN];
166 #if defined(ENCRYPTED_TEXTFIELD_DEBUG)
168 "currInsert=%d newInsert=%d startPos=%d endPos=%d\n",
169 cbs->currInsert,cbs->newInsert,cbs->startPos, cbs->endPos);
170 if (cbs->text->ptr) printf("text->ptr=%s\n", cbs->text->ptr);
171 printf("_text->ptr=%s\n", _text);
174 for (i=0, s=buffer, t=_text; (*t && i<cbs->startPos); i++, s++, t++)
179 strcpy(s, cbs->text->ptr);
180 s += cbs->text->length;
185 if (strlen(_text) >= cbs->endPos)
187 t = _text+cbs->endPos;
192 validateLength(strlen(buffer));
193 strcpy(_text, buffer);
196 for (i=0, s=cbs->text->ptr; i<cbs->text->length; i++, s++)
199 #if defined(ENCRYPTED_TEXTFIELD_DEBUG)
200 printf("text=%s\n", _text);
204 // ValueChangedCallback for the text field. Saves the user input
206 ///////////////////////////////////////////////////////////////////
207 void EncryptedTextFieldUiItem::verifyCB(
209 XtPointer client_data,
212 EncryptedTextFieldUiItem *etf = (EncryptedTextFieldUiItem*) client_data;
213 XmTextVerifyCallbackStruct *cbs = (XmTextVerifyCallbackStruct*) call_data;
215 if (DTM_FALSE == etf->_loading) etf->verify(cbs);