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: CustomListUiItem.C /main/6 1997/09/03 17:34:40 mgreess $ */
27 * $TOG: CustomListUiItem.C /main/6 1997/09/03 17:34:40 mgreess $
29 * RESTRICTED CONFIDENTIAL INFORMATION:
31 * The information in this document is subject to special
32 * restrictions in a confidential disclosure agreement bertween
33 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
34 * document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
35 * Sun's specific written approval. This documment and all copies
36 * and derivative works thereof must be returned or destroyed at
39 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
46 #include <DtMail/options_util.h>
47 #include "options_ui.h"
48 #include <DtMail/PropUi.hh>
49 #include <DtMail/ListUiItem.hh>
50 #include <DtMail/CustomListUiItem.hh>
52 extern void handleCustSelection(Widget, XtPointer, XtPointer );
53 extern Boolean props_changed;
55 // CustomListUiItem::CustomListUiItem
56 // CustomListUiItem ctor
57 ////////////////////////////////////////////////////////////////////
59 CustomListUiItem::CustomListUiItem(Widget w,
62 Widget key_entry_widget,
63 Widget value_entry_widget):ListUiItem(w, source, search_key, NULL)
65 source = source; search_key = search_key;
67 key_widget = key_entry_widget;
68 value_widget = value_entry_widget;
75 XmNautomaticSelection, True,
76 XmNselectionPolicy, XmBROWSE_SELECT,
80 XmNbrowseSelectionCallback,
81 (XtCallbackProc)handleCustSelection,
89 //-----------------======================-----------------
90 void handleDoubleSelection(Widget w, XtPointer clientdata, XtPointer calldata)
92 CustomListUiItem *item;
93 XmListCallbackStruct *list_info = (XmListCallbackStruct *)calldata;
94 char *selection_string = NULL;
95 DtVirtArray<PropStringPair *> *list_items;
102 list_items = item->getItemList();
104 if(list_items != NULL)
105 { // motif index is 1 based
106 //virtarry is 0 based
107 PropStringPair *pair = (*list_items)[list_info->item_position - 1];
111 XtVaSetValues(item->getKeyWidget(),
112 XmNvalue,pair->label,
115 XtVaSetValues(item->getValueWidget(),
116 XmNvalue,pair->value,
121 #endif /* DEAD_WOOD */
123 //-----------------======================-----------------
124 void handleCustSelection(Widget w, XtPointer, XtPointer calldata)
126 CustomListUiItem *item;
127 XmListCallbackStruct *list_info = (XmListCallbackStruct *)calldata;
128 char *selection_string = NULL;
129 DtVirtArray<PropStringPair *> *list_items;
136 list_items = item->getItemList();
138 if(list_items != NULL)
139 { // motif index is 1 based
140 //virtarry is 0 based
141 PropStringPair *pair = (*list_items)[list_info->item_position - 1];
145 XtVaSetValues(item->getKeyWidget(),
146 XmNvalue,pair->label,
149 XtVaSetValues(item->getValueWidget(),
150 XmNvalue,pair->value,
155 // CustomListUiItem::writeFromUiToSource()
156 // Takes values in the UI and puts them into the source DB
157 ///////////////////////////////////////////////////////////////////
158 void CustomListUiItem::writeFromUiToSource()
160 Widget w = this->getWidget();
162 DtMail::Session * d_session = theRoamApp.session()->session();
163 DtMail::MailRc * mail_rc = d_session->mailRc(error);
167 if(list_items != NULL) {
168 if(list_items->length() > 0)
170 num_items = list_items->length();
171 // calc mailrc strlen...
172 int total_len = 1; // add space for the terminator...
173 for(i = 0; i < num_items; i++) {
175 for (char *ptr = (*list_items)[i]->value;
177 if (*ptr == ' ') num_blanks++;
178 // strlen(label) strlen(value) + space + colon +
179 // potential \'s that precede the blank character
180 if((*list_items)[i]->label != NULL)
181 total_len = total_len + strlen(":") +
182 (strlen("\\") * num_blanks) +
183 strlen((*list_items)[i]->label) + 2;
185 if((*list_items)[i]->value != NULL)
186 total_len = total_len + strlen((*list_items)[i]->value);
188 cf_str = (char *)malloc(total_len);
191 for(i = 0; i < num_items; i++) {
192 if((*list_items)[i]->label != NULL)
193 strcat(cf_str, (*list_items)[i]->label);
195 if((*list_items)[i]->value != NULL) {
196 if (strchr((char*)(*list_items)[i]->value, ' ')) {
197 char *token, *tmpbuf;
198 tmpbuf = strdup((*list_items)[i]->value);
199 if (token = (char *)strtok(tmpbuf, " ")) {
200 strcat(cf_str, token);
201 while(token = (char *)strtok(NULL, " ")) {
202 strcat(cf_str, "\\ ");
203 strcat(cf_str, token);
209 strcat(cf_str, (*list_items)[i]->value);
213 mail_rc->setValue(error, "additionalfields", cf_str);
216 mail_rc->removeValue(error, "additionalfields");
219 mail_rc->removeValue(error, "additionalfields");
223 // CustomListUiItem::writeFromSourceToUi()
224 // Takes values in the UI and puts them into the source DB
225 ///////////////////////////////////////////////////////////////////
226 void CustomListUiItem::writeFromSourceToUi()
229 DtMail::Session * d_session = theRoamApp.session()->session();
230 DtMail::MailRc * mail_rc = d_session->mailRc(error);
231 Widget w = this->getWidget();
232 const char *list_str = NULL;
233 DtVirtArray<char *> list_str_list(10);
236 const char *value = NULL;
238 XmListDeleteAllItems(w);
240 mail_rc->getValue(error, "additionalfields", &value);
242 if(list_items != NULL)
245 list_items = new DtVirtArray<PropStringPair *>(10);
247 parsePropString(value, *list_items);
249 list_len = list_items->length();
250 for(i = 0; i < list_len; i++)
251 list_str_list.append(formatPropPair((*list_items)[i]->label,
252 (*list_items)[i]->value));
254 options_list_init(w, &list_str_list);
260 ///////////////////////////////////////////////////////////
261 void CustomListUiItem::handleAddButtonPress()
263 char *key_str = NULL;
264 char *value_str = NULL;
265 PropStringPair *new_pair = NULL;
267 XtVaGetValues(key_widget,
271 XtVaGetValues(value_widget,
272 XmNvalue, &value_str,
276 if(strlen(key_str) > 0)
278 new_pair = new PropStringPair;
279 int *pos_list, num_pos;
281 new_pair->label = strdup(key_str);
283 if(value_str != NULL)
284 new_pair->value = strdup(value_str);
286 new_pair->value = NULL;
288 if(XmListGetSelectedPos(this->getWidget(),
292 if(list_items == NULL)
293 list_items = new DtVirtArray<PropStringPair *>(10);
295 list_items->insert(new_pair,pos_list[0] - 1);
297 XmListAddItem(this->getWidget(),
298 XmStringCreateLocalized(
304 XmListSelectPos(this->getWidget(),
308 XmListSetPos(this->getWidget(),
313 if(list_items == NULL)
314 list_items = new DtVirtArray<PropStringPair *>(10);
316 list_items->insert(new_pair,0);
317 XmListAddItem(this->getWidget(),
318 XmStringCreateLocalized(
323 XmListSelectPos(this->getWidget(),
327 XmListSetPos(this->getWidget(),
330 props_changed = TRUE;
333 ///////////////////////////////////////////////////////////
334 void CustomListUiItem::handleChangeButtonPress()
336 char *key_str = NULL;
337 char *value_str = NULL;
338 PropStringPair *new_pair = NULL;
339 XmString replace_string;
340 int *pos_list, num_pos;
342 // if nothing selected nothing to change...
343 if(XmListGetSelectedPos(this->getWidget(),
347 XtVaGetValues(key_widget,
351 XtVaGetValues(value_widget,
352 XmNvalue, &value_str,
356 if(strlen(key_str) > 0)
359 new_pair = (*list_items)[pos_list[0] - 1];
361 free(new_pair->label);
362 new_pair->label = strdup(key_str);
364 if(new_pair->value != NULL)
366 free(new_pair->value);
367 if(value_str != NULL)
368 new_pair->value = strdup(value_str);
370 new_pair->value = NULL;
373 replace_string = XmStringCreateLocalized(
374 formatPropPair(new_pair->label,
377 XmListReplaceItemsPos(this->getWidget(),
382 XmListSelectPos(this->getWidget(),
386 props_changed = TRUE;
389 ///////////////////////////////////////////////////////////
390 void CustomListUiItem::handleDeleteButtonPress()
392 Widget list_widget = this->getWidget();
393 int *p_list, p_count;
395 // get the selected position
396 if(XmListGetSelectedPos(list_widget,
401 // delete the item from our list
402 this->list_items->remove(p_list[0] - 1); // remove only first
404 // delete the item from the widget
405 XmListDeletePos(list_widget, p_list[0]);
407 XtVaSetValues(this->getKeyWidget(),
411 XtVaSetValues(this->getValueWidget(),
415 XmListSelectPos(list_widget,
419 props_changed = TRUE;