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
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()
91 // /////////////////////////////////////////////////////////////////
93 // /////////////////////////////////////////////////////////////////
95 MarkListView::~MarkListView()
103 // /////////////////////////////////////////////////////////////////
104 // display - display the dialog and update the mark list
105 // /////////////////////////////////////////////////////////////////
108 MarkListView::display()
124 // /////////////////////////////////////////////////////////////////
126 // /////////////////////////////////////////////////////////////////
129 MarkListView::create_ui()
131 XmStringLocalized mtfstring;
134 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "mark_list");
135 window_system().register_shell(&f_shell);
137 string = CATGETS(Set_MarkList, 1, "Dtinfo: User Marks List");
138 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
140 DECL (WXmForm, form, f_shell, "form");
141 ASSNM (WXmPushButton, f_view, form, "view");
142 ASSNM (WXmPushButton, f_edit, form, "edit");
143 ASSNM (WXmPushButton, f_delete, form, "delete"); // ross bug #14441
144 DECLM (WXmPushButton, close, form, "close");
145 DECLM (WXmPushButton, help, form, "help");
146 DECLM (WXmSeparator, sep, form, "separator");
147 Widget list = XmCreateScrolledList (form, (char*)"list", NULL, 0);
148 f_list = WXmList (list);
151 mtfstring = CATGETS(Set_AgentLabel, 165, "Display");
152 XtVaSetValues(f_view, XmNlabelString, (XmString)mtfstring, NULL);
153 mtfstring = CATGETS(Set_AgentLabel, 16, "Edit");
154 XtVaSetValues(f_edit, XmNlabelString, (XmString)mtfstring, NULL);
155 mtfstring = CATGETS(Set_AgentLabel, 183, "Delete");
156 XtVaSetValues(f_delete, XmNlabelString, (XmString)mtfstring, NULL);
157 mtfstring = CATGETS(Set_AgentLabel, 12, "Close");
158 XtVaSetValues(close, XmNlabelString, (XmString)mtfstring, NULL);
159 mtfstring = CATGETS(Set_AgentLabel, 48, "Help");
160 XtVaSetValues(help, XmNlabelString, (XmString)mtfstring, NULL);
162 SET_CALLBACK (f_list,SingleSelection,select);
163 SET_CALLBACK (f_list,BrowseSelection,select);
164 SET_CALLBACK (f_list,DefaultAction,view);
165 ON_ACTIVATE (f_view,view);
166 ON_ACTIVATE (f_edit,edit);
167 ON_ACTIVATE (f_delete,remove);
168 ON_ACTIVATE (close,close);
169 help_agent().add_activate_help (help, (char*)"mark_list_help");
171 SET_CALLBACK (f_shell,Popdown,popdown);
173 form.DefaultButton (f_view);
174 form.ShadowThickness (0);
178 f_shell.MinWidth (f_shell.Width());
179 f_shell.MinHeight (f_shell.Height());
181 MarkMgr::request (this);
182 Mark::request ((UAS_Receiver<MarkDeleted> *) this);
183 Mark::request ((UAS_Receiver<MarkChanged> *) this);
187 // /////////////////////////////////////////////////////////////////
188 // get_list - get the list of user marks
189 // /////////////////////////////////////////////////////////////////
192 MarkListView::refresh_mark_list()
194 mark_mgr().get_all_marks (f_mark_list);
196 unsigned int length = f_mark_list.length();
197 // Convert the list to XmString values.
198 XmStringTable table = new XmString[length];
200 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
205 table[i] = XmStringCreateLocalized ((String) m.item()->name());
210 // Update the list to display those items.
211 f_list.Set (WArgList (XmNitemCount, (XtArgVal) length,
215 // Free the strings since the list widget keeps its own copy.
217 XmStringFree (table[--i]);
222 // /////////////////////////////////////////////////////////////////
223 // free_list - release the mark ptrs in the list
224 // /////////////////////////////////////////////////////////////////
227 MarkListView::free_mark_list()
229 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
232 f_mark_list.remove (m);
236 // /////////////////////////////////////////////////////////////////
238 // /////////////////////////////////////////////////////////////////
241 MarkListView::popdown()
244 // Forget about everything while the dialog isn't visible.
246 f_list.DeleteAllItems();
247 // Current we forget about the selected item.
248 // This is fixable by remembering the selected mark pointer.
250 f_view.SetSensitive (False);
251 f_edit.SetSensitive (False);
252 f_delete.SetSensitive (False); // ross for bug #14441
255 // /////////////////////////////////////////////////////////////////
256 // select - handle item selection
257 // /////////////////////////////////////////////////////////////////
260 MarkListView::select (WCallback *wcb)
262 CALL_DATA (XmListCallbackStruct,lcs);
264 f_selected_item = lcs->item_position;
266 ON_DEBUG (printf ("Selected item #%d\n", f_selected_item);)
268 f_view.SetSensitive (True);
269 f_edit.SetSensitive (True);
270 f_delete.SetSensitive (True); // ross for bug #14441
274 // /////////////////////////////////////////////////////////////////
275 // view - view a mark
276 // /////////////////////////////////////////////////////////////////
281 Wait_Cursor bob_dobbs;
286 Xassert (f_selected_item > 0);
287 Xassert (f_selected_item <= (int) f_mark_list.length());
289 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
292 // Skip ahead to the selected item in the list.
293 while (i < f_selected_item)
296 // Now `m' points to the selected Mark.
299 mcatch(demoException &, demo)
301 message_mgr().demo_failure(demo);
307 // /////////////////////////////////////////////////////////////////
308 // remove - delete a mark
309 // /////////////////////////////////////////////////////////////////
312 MarkListView::remove()
314 Xassert (f_selected_item > 0);
315 Xassert (f_selected_item <= (int) f_mark_list.length());
317 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
320 // Skip ahead to the selected item in the list.
321 while (i < f_selected_item)
324 // Now `m' points to the selected Mark.
325 m.item()->remove(); // ross bug #14441
331 // /////////////////////////////////////////////////////////////////
332 // edit - edit a mark
333 // /////////////////////////////////////////////////////////////////
338 Xassert (f_selected_item > 0);
339 Xassert (f_selected_item <= (int) f_mark_list.length());
341 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
344 // Skip ahead to the selected item in the list.
345 while (i < f_selected_item)
348 // Now `m' points to the selected Mark.
353 // /////////////////////////////////////////////////////////////////
354 // close - popdown the the dialog
355 // /////////////////////////////////////////////////////////////////
358 MarkListView::close()
364 // /////////////////////////////////////////////////////////////////
365 // receive - handle mark creation/deletion
366 // /////////////////////////////////////////////////////////////////
369 MarkListView::receive (MarkCreated &msg, void* /*client_data*/)
374 f_list.AddItemUnselected (msg.f_mark_ptr->name(), 0);
375 f_mark_list.append (msg.f_mark_ptr);
380 MarkListView::receive (MarkDeleted &msg, void* /*client_data*/)
385 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
388 // Skip ahead to the deleted item item in the list.
389 while (m && m.item() != msg.f_mark_ptr)
391 ON_DEBUG (printf ("Checking <%s> against <%s>\n",
392 m.item()->name(), msg.f_mark_ptr->name()));
399 // XXXSWM: Need to check if this is the selected item.
400 // if so, we gotta clear f_selected_item and Desensitize
401 // the display and edit buttons.
403 if (XmListPosSelected (f_list, i)) {
405 f_view.SetSensitive (False);
406 f_edit.SetSensitive (False);
407 f_delete.SetSensitive (False);
410 // Remove it from the list widget and our list.
411 f_list.DeletePos (i);
412 f_mark_list.remove (m);
417 MarkListView::receive (MarkChanged &msg, void* /*client_data*/)
422 List_Iterator<UAS_Pointer<Mark> > m (f_mark_list);
425 // Skip ahead to the changed item item in the list.
426 while (m && m.item() != msg.f_mark_ptr)
428 ON_DEBUG (printf ("Checking <%s> against <%s>\n",
429 m.item()->name(), msg.f_mark_ptr->name()));
435 // Change the title of the entry, once it is found.
436 WXmString title (msg.f_mark_ptr->name());
440 f_list.ReplaceItemsPosUnselected (table, 1, i);
441 if (f_selected_item == i)
442 f_list.SelectPos (i, False);