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
24 * $XConsortium: MarkListView.C /main/8 1996/09/13 20:45:08 cde-hal $
26 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27 * All rights reserved. Unpublished -- rights reserved under
28 * the Copyright Laws of the United States. USE OF A COPYRIGHT
29 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
32 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
34 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
38 * RESTRICTED RIGHTS LEGEND
39 * Use, duplication, or disclosure by the Government is subject
40 * to the restrictions as set forth in subparagraph (c)(l)(ii)
41 * of the Rights in Technical Data and Computer Software clause
42 * at DFARS 252.227-7013.
44 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
53 #define C_MarkListView
57 #define C_WindowSystem
64 #include "Other/XmStringLocalized.hh"
65 #include "Managers/CatMgr.hh"
69 #include "Registration.hh"
71 #include <WWL/WXmForm.h>
72 #include <WWL/WXmSeparator.h>
74 #define CLASS MarkListView
75 #include "create_macros.hh"
77 #include "utility/mmdb_exception.h"
79 // /////////////////////////////////////////////////////////////////
81 // /////////////////////////////////////////////////////////////////
83 MarkListView::MarkListView()
90 // /////////////////////////////////////////////////////////////////
92 // /////////////////////////////////////////////////////////////////
94 MarkListView::~MarkListView()
102 // /////////////////////////////////////////////////////////////////
103 // display - display the dialog and update the mark list
104 // /////////////////////////////////////////////////////////////////
107 MarkListView::display()
123 // /////////////////////////////////////////////////////////////////
125 // /////////////////////////////////////////////////////////////////
128 MarkListView::create_ui()
130 XmStringLocalized mtfstring;
133 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "mark_list");
134 window_system().register_shell(&f_shell);
136 string = CATGETS(Set_MarkList, 1, "Dtinfo: User Marks List");
137 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
139 DECL (WXmForm, form, f_shell, "form");
140 ASSNM (WXmPushButton, f_view, form, "view");
141 ASSNM (WXmPushButton, f_edit, form, "edit");
142 ASSNM (WXmPushButton, f_delete, form, "delete"); // ross bug #14441
143 DECLM (WXmPushButton, close, form, "close");
144 DECLM (WXmPushButton, help, form, "help");
145 DECLM (WXmSeparator, sep, form, "separator");
146 Widget list = XmCreateScrolledList (form, "list", NULL, 0);
147 f_list = WXmList (list);
150 mtfstring = CATGETS(Set_AgentLabel, 165, "Display");
151 XtVaSetValues(f_view, XmNlabelString, (XmString)mtfstring, NULL);
152 mtfstring = CATGETS(Set_AgentLabel, 16, "Edit");
153 XtVaSetValues(f_edit, XmNlabelString, (XmString)mtfstring, NULL);
154 mtfstring = CATGETS(Set_AgentLabel, 183, "Delete");
155 XtVaSetValues(f_delete, XmNlabelString, (XmString)mtfstring, NULL);
156 mtfstring = CATGETS(Set_AgentLabel, 12, "Close");
157 XtVaSetValues(close, XmNlabelString, (XmString)mtfstring, NULL);
158 mtfstring = CATGETS(Set_AgentLabel, 48, "Help");
159 XtVaSetValues(help, XmNlabelString, (XmString)mtfstring, NULL);
161 SET_CALLBACK (f_list,SingleSelection,select);
162 SET_CALLBACK (f_list,BrowseSelection,select);
163 SET_CALLBACK (f_list,DefaultAction,view);
164 ON_ACTIVATE (f_view,view);
165 ON_ACTIVATE (f_edit,edit);
166 ON_ACTIVATE (f_delete,remove);
167 ON_ACTIVATE (close,close);
168 help_agent().add_activate_help (help, "mark_list_help");
170 SET_CALLBACK (f_shell,Popdown,popdown);
172 form.DefaultButton (f_view);
173 form.ShadowThickness (0);
177 f_shell.MinWidth (f_shell.Width());
178 f_shell.MinHeight (f_shell.Height());
180 MarkMgr::request (this);
181 Mark::request ((UAS_Receiver<MarkDeleted> *) this);
182 Mark::request ((UAS_Receiver<MarkChanged> *) this);
186 // /////////////////////////////////////////////////////////////////
187 // get_list - get the list of user marks
188 // /////////////////////////////////////////////////////////////////
191 MarkListView::refresh_mark_list()
193 mark_mgr().get_all_marks (f_mark_list);
195 unsigned int length = f_mark_list.length();
196 // Convert the list to XmString values.
197 XmStringTable table = new XmString[length];
199 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
204 table[i] = XmStringCreateLocalized ((String) m.item()->name());
209 // Update the list to display those items.
210 f_list.Set (WArgList (XmNitemCount, (XtArgVal) length,
214 // Free the strings since the list widget keeps its own copy.
216 XmStringFree (table[--i]);
221 // /////////////////////////////////////////////////////////////////
222 // free_list - release the mark ptrs in the list
223 // /////////////////////////////////////////////////////////////////
226 MarkListView::free_mark_list()
228 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
231 f_mark_list.remove (m);
235 // /////////////////////////////////////////////////////////////////
237 // /////////////////////////////////////////////////////////////////
240 MarkListView::popdown()
243 // Forget about everything while the dialog isn't visible.
245 f_list.DeleteAllItems();
246 // Current we forget about the selected item.
247 // This is fixable by remembering the selected mark pointer.
249 f_view.SetSensitive (False);
250 f_edit.SetSensitive (False);
251 f_delete.SetSensitive (False); // ross for bug #14441
254 // /////////////////////////////////////////////////////////////////
255 // select - handle item selection
256 // /////////////////////////////////////////////////////////////////
259 MarkListView::select (WCallback *wcb)
261 CALL_DATA (XmListCallbackStruct,lcs);
263 f_selected_item = lcs->item_position;
265 ON_DEBUG (printf ("Selected item #%d\n", f_selected_item);)
267 f_view.SetSensitive (True);
268 f_edit.SetSensitive (True);
269 f_delete.SetSensitive (True); // ross for bug #14441
273 // /////////////////////////////////////////////////////////////////
274 // view - view a mark
275 // /////////////////////////////////////////////////////////////////
280 Wait_Cursor bob_dobbs;
285 Xassert (f_selected_item > 0);
286 Xassert (f_selected_item <= f_mark_list.length());
288 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
291 // Skip ahead to the selected item in the list.
292 while (i < f_selected_item)
295 // Now `m' points to the selected Mark.
298 catch(demoException &, demo)
300 message_mgr().demo_failure(demo);
306 // /////////////////////////////////////////////////////////////////
307 // remove - delete a mark
308 // /////////////////////////////////////////////////////////////////
311 MarkListView::remove()
313 Xassert (f_selected_item > 0);
314 Xassert (f_selected_item <= f_mark_list.length());
316 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
319 // Skip ahead to the selected item in the list.
320 while (i < f_selected_item)
323 // Now `m' points to the selected Mark.
324 m.item()->remove(); // ross bug #14441
330 // /////////////////////////////////////////////////////////////////
331 // edit - edit a mark
332 // /////////////////////////////////////////////////////////////////
337 Xassert (f_selected_item > 0);
338 Xassert (f_selected_item <= f_mark_list.length());
340 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
343 // Skip ahead to the selected item in the list.
344 while (i < f_selected_item)
347 // Now `m' points to the selected Mark.
352 // /////////////////////////////////////////////////////////////////
353 // close - popdown the the dialog
354 // /////////////////////////////////////////////////////////////////
357 MarkListView::close()
363 // /////////////////////////////////////////////////////////////////
364 // receive - handle mark creation/deletion
365 // /////////////////////////////////////////////////////////////////
368 MarkListView::receive (MarkCreated &msg, void* /*client_data*/)
373 f_list.AddItemUnselected (msg.f_mark_ptr->name(), 0);
374 f_mark_list.append (msg.f_mark_ptr);
379 MarkListView::receive (MarkDeleted &msg, void* /*client_data*/)
384 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
387 // Skip ahead to the deleted item item in the list.
388 while (m && m.item() != msg.f_mark_ptr)
390 ON_DEBUG (printf ("Checking <%s> against <%s>\n",
391 m.item()->name(), msg.f_mark_ptr->name()));
398 // XXXSWM: Need to check if this is the selected item.
399 // if so, we gotta clear f_selected_item and Desensitize
400 // the display and edit buttons.
402 if (XmListPosSelected (f_list, i)) {
404 f_view.SetSensitive (False);
405 f_edit.SetSensitive (False);
406 f_delete.SetSensitive (False);
409 // Remove it from the list widget and our list.
410 f_list.DeletePos (i);
411 f_mark_list.remove (m);
416 MarkListView::receive (MarkChanged &msg, void* /*client_data*/)
421 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
424 // Skip ahead to the changed item item in the list.
425 while (m && m.item() != msg.f_mark_ptr)
427 ON_DEBUG (printf ("Checking <%s> against <%s>\n",
428 m.item()->name(), msg.f_mark_ptr->name()));
434 // Change the title of the entry, once it is found.
435 WXmString title (msg.f_mark_ptr->name());
439 f_list.ReplaceItemsPosUnselected (table, 1, i);
440 if (f_selected_item == i)
441 f_list.SelectPos (i, False);