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 librararies 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: MoveMenuListUiItem.C /main/5 1997/09/03 17:39:09 mgreess $ */
27 * $TOG: MoveMenuListUiItem.C /main/5 1997/09/03 17:39:09 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.
45 #include <DtMail/options_util.h>
46 #include "options_ui.h"
47 #include <DtMail/PropUi.hh>
48 #include <DtMail/ListUiItem.hh>
49 #include <DtMail/MoveMenuListUiItem.hh>
51 extern void handleIgnoreSelection(Widget, XtPointer, XtPointer );
52 extern Boolean props_changed;
54 // MoveMenuListUiItem::MoveMenuListUiItem
55 // MoveMenuListUiItem ctor
56 ////////////////////////////////////////////////////////////////////
58 MoveMenuListUiItem::MoveMenuListUiItem(Widget w,
61 Widget text_entry_widget):ListUiItem(w, source, search_key, NULL)
63 source = source; search_key = search_key;
65 entry_field_widget = text_entry_widget;
72 XmNautomaticSelection, True,
73 XmNselectionPolicy, XmBROWSE_SELECT,
77 XmNbrowseSelectionCallback,
78 (XtCallbackProc)handleMMSelection,
83 //---------------------------------------------------------------
84 void handleMMSelection(Widget w, XtPointer, XtPointer calldata)
86 MoveMenuListUiItem *item;
87 XmListCallbackStruct *list_info = (XmListCallbackStruct *)calldata;
88 char *selection_string = NULL;
89 DtVirtArray<PropStringPair *> *list_items;
95 list_items = item->getItemList();
97 if(list_items != NULL)
99 // motif index is 1 based
100 //virtarry is 0 based
101 PropStringPair *pair = (*list_items)[list_info->item_position - 1];
105 XtVaSetValues(item->getEntryFieldWidget(),
106 XmNvalue,pair->label,
114 // MoveMenuListUiItem::writeFromUiToSource()
115 // Takes values in the UI and puts them into the source DB
116 ///////////////////////////////////////////////////////////////////
117 void MoveMenuListUiItem::writeFromUiToSource()
119 Widget w = this->getWidget();
121 DtMail::Session * d_session = theRoamApp.session()->session();
122 DtMail::MailRc * mail_rc = d_session->mailRc(error);
123 int i, num_items, total_len = 0;
126 if(list_items != NULL)
128 if(list_items->length() > 0)
130 num_items = list_items->length();
132 // calc mailrc strlen...
133 total_len = 1; // add space for the terminator...
134 for(i = 0; i < num_items; i++)
137 total_len = total_len + strlen((*list_items)[i]->label) + 1;
140 mm_str = (char *)malloc(total_len);
143 for(i = 0; i < num_items; i++)
145 strcat(mm_str, (*list_items)[i]->label);
149 mail_rc->setValue(error, "filemenu2", mm_str);
153 mail_rc->removeValue(error, "filemenu2");
158 mail_rc->removeValue(error, "filemenu2");
163 // MoveMenuListUiItem::writeFromSourceToUi()
164 // Takes values in the UI and puts them into the source DB
165 ///////////////////////////////////////////////////////////////////
166 void MoveMenuListUiItem::writeFromSourceToUi()
169 DtMail::Session * d_session = theRoamApp.session()->session();
170 DtMail::MailRc * mail_rc = d_session->mailRc(error);
171 Widget w = this->getWidget();
172 const char *list_str = NULL;
173 char *token, *buf = NULL;
174 PropStringPair *new_pair;
175 DtVirtArray<char *> *char_list = NULL;
177 XmListDeleteAllItems(w);
179 // set up move menu list
180 mail_rc->getValue(error, "filemenu2", &list_str);
182 if (list_str == NULL) {
183 list_str = strdup(" ");
185 // set list_items to NULL, otherwise the cancel and reset will not
186 // work. The list_items will be showed up next time even the cancel
187 // or reset button is pressed
190 if ((buf = (char *) malloc(strlen(list_str) + 1)) == NULL)
192 strcpy(buf, (char *)list_str);
195 char * expanded_str = d_session->expandPath(error, list_str);
196 if ((buf = (char *) malloc(strlen(expanded_str) + 1)) == NULL) {
200 strcpy(buf, expanded_str);
204 if((token = (char *) strtok(buf, " ")))
206 list_items = new DtVirtArray<PropStringPair *>(10);
207 char_list = new DtVirtArray<char *>(10);
209 new_pair = new PropStringPair;
210 new_pair->label = strdup(token);
211 new_pair->value = NULL;
212 list_items->append(new_pair);
214 char_list->append(strdup(token));
216 while(token = (char *)strtok(NULL, " "))
218 new_pair = new PropStringPair;
219 new_pair->label = strdup(token);
220 new_pair->value = NULL;
221 list_items->append(new_pair);
223 char_list->append(strdup(token));
227 options_list_init(w, char_list);
232 free((void*) list_str);
239 ///////////////////////////////////////////////////////////
240 void MoveMenuListUiItem::handleAddButtonPress()
242 Widget entry_field = this->getEntryFieldWidget();
243 char *test_str = NULL;
244 PropStringPair *new_pair = NULL;
246 XtVaGetValues(entry_field,
251 if(strlen(test_str) > 0)
253 new_pair = new PropStringPair;
254 int *pos_list, num_pos;
256 new_pair->label = strdup(test_str);
257 new_pair->value = NULL;
259 if(XmListGetSelectedPos(this->getWidget(),
263 if(list_items == NULL)
264 list_items = new DtVirtArray<PropStringPair *>(10);
266 list_items->insert(new_pair,pos_list[0] - 1);
267 XmListAddItem(this->getWidget(),
268 XmStringCreateLocalized(new_pair->label),
271 XmListSelectPos(this->getWidget(),
275 XmListSetPos(this->getWidget(),
280 if(list_items == NULL)
281 list_items = new DtVirtArray<PropStringPair *>(10);
283 list_items->insert(new_pair,0);
284 XmListAddItem(this->getWidget(),
285 XmStringCreateLocalized(new_pair->label),
287 XmListSelectPos(this->getWidget(),
291 XmListSetPos(this->getWidget(),
294 props_changed = TRUE;
297 ///////////////////////////////////////////////////////////
298 void MoveMenuListUiItem::handleChangeButtonPress()
300 Widget entry_field = this->getEntryFieldWidget();
301 char *test_str = NULL;
302 PropStringPair *new_pair = NULL;
303 XmString replace_string;
304 int *pos_list, num_pos;
306 // if nothing selected nothing to change...
307 if(XmListGetSelectedPos(this->getWidget(),
311 XtVaGetValues(entry_field,
316 if(strlen(test_str) > 0)
319 new_pair = (*list_items)[pos_list[0] - 1];
321 free(new_pair->label);
322 new_pair->label = strdup(test_str);
325 // list_items->insert(new_pair,pos_list[0] - 1);
326 replace_string = XmStringCreateLocalized(new_pair->label);
328 XmListReplaceItemsPos(this->getWidget(),
333 XmListSelectPos(this->getWidget(),
337 props_changed = TRUE;
340 ///////////////////////////////////////////////////////////
341 void MoveMenuListUiItem::handleDeleteButtonPress()
343 Widget list_widget = this->getWidget();
344 int *p_list, p_count;
346 // get the selected position
347 if(XmListGetSelectedPos(list_widget,
352 // delete the item from our list
353 this->list_items->remove(p_list[0] - 1); // remove only first
355 // delete the item from the widget
356 XmListDeletePos(list_widget, p_list[0]);
358 XtVaSetValues(this->getEntryFieldWidget(),
361 XmListSelectPos(list_widget,
364 props_changed = TRUE;