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: NodeHistoryAgentMotif.C /main/13 1998/04/17 11:34:27 mgreess $
24 /* Copyright (c) 1994,1995,1996 FUJITSU LIMITED */
25 /* All Rights Reserved */
28 * Copyright (c) 1993 HAL Computer Systems International, Ltd.
29 * All rights reserved. Unpublished -- rights reserved under
30 * the Copyright Laws of the United States. USE OF A COPYRIGHT
31 * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
34 * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
35 * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD. USE,
36 * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
37 * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
40 * RESTRICTED RIGHTS LEGEND
41 * Use, duplication, or disclosure by the Government is subject
42 * to the restrictions as set forth in subparagraph (c)(l)(ii)
43 * of the Rights in Technical Data and Computer Software clause
44 * at DFARS 252.227-7013.
46 * HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
62 #define C_GlobalHistoryMgr
68 #define C_NodeHistoryAgent
71 #define C_WindowSystem
74 #include "Other/XmStringLocalized.hh"
75 #include "Managers/CatMgr.hh"
76 #include "Managers/WString.hh"
80 #include "Registration.hh"
82 #include <WWL/WXmForm.h>
83 #include <WWL/WXmSeparator.h>
84 #include <WWL/WXmLabel.h>
86 #define CLASS NodeHistoryAgent
87 #include "create_macros.hh"
90 NodeHistoryAgent::~NodeHistoryAgent()
97 // /////////////////////////////////////////////////////////////////
99 // /////////////////////////////////////////////////////////////////
102 NodeHistoryAgent::display()
108 ON_DEBUG (puts ("Popping up the node hist list"));
115 // /////////////////////////////////////////////////////////////////
117 // /////////////////////////////////////////////////////////////////
119 #define SECTION_OFFSET 150
122 NodeHistoryAgent::create_ui()
124 XmStringLocalized mtfstring;
127 f_shell = WTopLevelShell (window_system().toplevel(), WPopup, "node_hist");
128 window_system().register_shell (&f_shell);
130 string = CATGETS(Set_NodeHistoryAgent, 1, "Dtinfo: Section History");
131 XtVaSetValues((Widget)f_shell, XmNtitle, string, NULL);
133 DECL (WXmForm, form, f_shell, "form");
134 ASSNM (WXmPushButton, f_display, form, "display");
135 DECLM (WXmPushButton, close, form, "close");
136 DECLM (WXmPushButton, help, form, "help");
137 DECLM (WXmSeparator, sep, form, "separator");
139 mtfstring = CATGETS(Set_AgentLabel, 165, "Display");
140 XtVaSetValues(f_display, XmNlabelString, (XmString)mtfstring, NULL);
141 mtfstring = CATGETS(Set_AgentLabel, 12, "Close");
142 XtVaSetValues(close, XmNlabelString, (XmString)mtfstring, NULL);
143 mtfstring = CATGETS(Set_AgentLabel, 48, "Help");
144 XtVaSetValues(help, XmNlabelString, (XmString)mtfstring, NULL);
146 // set up column labels (Book, Section)
147 WXmLabel booklabel (form, "book", WAutoManage);
148 WXmLabel sectionlabel (form, "section", WAutoManage);
150 mtfstring = CATGETS(Set_AgentLabel, 184, "Book");
151 XtVaSetValues(booklabel, XmNlabelString, (XmString)mtfstring, NULL);
152 mtfstring = CATGETS(Set_AgentLabel, 185, "Section");
153 XtVaSetValues(sectionlabel, XmNlabelString, (XmString)mtfstring, NULL);
155 Widget scrolled_list = XmCreateScrolledList (form, "list", NULL, 0);
156 f_list = WXmList (scrolled_list);
159 XmFontList defaultList;
162 XtVaGetValues(scrolled_list, XmNfontList, &font, NULL);
163 defaultList = XmFontListCopy(font);
166 if (window_system().dtinfo_space_font())
167 defaultList = XmFontListAppendEntry(defaultList,
168 window_system().dtinfo_space_font());
169 XtVaSetValues(scrolled_list, XmNfontList, defaultList, NULL);
171 SET_CALLBACK (f_shell,Popdown,popdown);
172 SET_CALLBACK (f_list,SingleSelection,select);
173 SET_CALLBACK (f_list,BrowseSelection,select);
174 SET_CALLBACK (f_list,DefaultAction,view);
175 ON_ACTIVATE (f_display,view);
176 ON_ACTIVATE (close,close);
177 help_agent().add_activate_help (help, "node_hist_help");
179 global_history_mgr().UAS_Sender<HistoryAdd>::request (this);
180 global_history_mgr().UAS_Sender<HistoryDelete>::request (this);
182 form.DefaultButton (f_display);
183 form.ShadowThickness(0);
186 // Set the min size based on the current size.
188 f_shell.MinWidth (f_shell.Width());
189 f_shell.MinHeight (f_shell.Height());
191 // account for list offset in its frame
192 #define MARGIN_FACTOR 3
194 booklabel.LeftOffset(MARGIN_FACTOR + offset);
196 sectionlabel.LeftPosition(0);
197 sectionlabel.LeftAttachment(XmATTACH_POSITION);
198 sectionlabel.LeftOffset(SECTION_OFFSET + MARGIN_FACTOR + offset);
201 WXmPrimitive prim(XtParent(f_list));
202 prim.TopWidget(booklabel);
203 prim.TopAttachment(XmATTACH_WIDGET);
207 // /////////////////////////////////////////////////////////////////
208 // refresh_list - get all history list items and display them
209 // /////////////////////////////////////////////////////////////////
212 NodeHistoryAgent::refresh_list()
214 Xassert (f_list != NULL);
216 xList<UAS_Pointer<UAS_Common> > &hist_list = global_history_mgr().history_list();
217 XmStringTable table = new XmString [hist_list.length()];
218 List_Iterator<UAS_Pointer<UAS_Common> > hl (hist_list);
220 // Create the XmString values for the list.
221 // Stick the items in the list in reverse order.
222 int i = hist_list.length() - 1;
225 UAS_String bn = hl.item()->book_name(UAS_SHORT_TITLE);
226 UAS_String tt = hl.item()->title();
228 table[i--] = compose_entry(bn, tt);
232 // Set the items in the list.
233 f_list.DeselectAllItems();
234 f_display.SetSensitive (False);
235 f_list.Set (WArgList (XmNitems, (XtArgVal) table,
236 XmNitemCount, hist_list.length(),
239 // Free up memory used to make the list.
240 for (i = hist_list.length() - 1; i >= 0; i--)
241 XmStringFree (table[i]);
246 // /////////////////////////////////////////////////////////////////
247 // select - handle item selection
248 // /////////////////////////////////////////////////////////////////
251 NodeHistoryAgent::select (WCallback *wcb)
253 CALL_DATA (XmListCallbackStruct,lcs);
255 f_selected_item = lcs->item_position;
257 ON_DEBUG (printf ("Selected item #%d\n", f_selected_item);)
259 f_display.SetSensitive (True);
263 // /////////////////////////////////////////////////////////////////
265 // /////////////////////////////////////////////////////////////////
268 NodeHistoryAgent::view()
270 Xassert (f_list.SelectedItemCount() == 1);
271 Xassert (f_selected_item != 0);
273 xList<UAS_Pointer<UAS_Common> > &hist_list = global_history_mgr().history_list();
274 List_Iterator<UAS_Pointer<UAS_Common> > n (hist_list);
275 int i = hist_list.length();
277 // Skip ahead to the selected item in the list.
278 while (i > f_selected_item)
281 // Now `n' points to the selected Node.
282 n.item()->retrieve();
285 // /////////////////////////////////////////////////////////////////
287 // /////////////////////////////////////////////////////////////////
290 NodeHistoryAgent::close()
297 NodeHistoryAgent::popdown()
300 f_list.DeleteAllItems();
302 f_display.SetSensitive (False);
306 // /////////////////////////////////////////////////////////////////
308 // /////////////////////////////////////////////////////////////////
311 NodeHistoryAgent::receive (HistoryAdd &message, void* /*client_data*/)
315 // Add new item to the beginning (index 1) of the list.
316 UAS_String bn = message.f_new_entry->book_name(UAS_SHORT_TITLE);
317 UAS_String tt = message.f_new_entry->title();
319 f_list.AddItemUnselected (compose_entry(bn, tt), 1);
321 if (message.f_moving)
322 f_list.SelectPos (1, True);
326 NodeHistoryAgent::compose_entry(UAS_String book, UAS_String section)
328 WXmString bookString((char*)book);
329 WXmString sectString((char*)section);
331 if (bookString.Width(f_list.FontList()) >= SECTION_OFFSET)
335 char* ungenerated = (char*)(bookString + WXmString(dots));
337 WString anonym_wstring = ungenerated;
338 wchar_t* buf = (wchar_t*)anonym_wstring;
339 wchar_t* ptr = buf + wcslen(buf) - (strlen(dots)+1);
350 memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));
352 stake = str = WString(buf).get_mbstr();
354 allowance = SECTION_OFFSET - stake.Width(f_list.FontList());
358 while (allowance <= 0 && ptr >= buf);
360 while (*ptr <= (wchar_t)' ' && ptr >= buf)
363 memcpy(ptr--, (wchar_t*)wdots, (strlen(dots)+1) * sizeof(wchar_t));
365 stake = str = WString(buf).get_mbstr();
366 allowance = SECTION_OFFSET - stake.Width(f_list.FontList());
374 WXmString space(window_system().
375 make_space(SECTION_OFFSET -
376 bookString.Width(f_list.FontList()), f_list),
379 WXmString entry = bookString + space + sectString;
381 return entry.disown();
385 NodeHistoryAgent::receive (HistoryDelete &message, void* /*client_data*/)
389 // Remove old items from the list.
390 int length = f_list.ItemCount();
391 ON_DEBUG (printf ("----- history list delete: count %d, index %d, len %d\n",
393 length - message.f_index - message.f_count + 1, length));
394 // The list is stored in inverted form, ie: new items on top.
395 int item = length - message.f_index - message.f_count + 1;
396 if (f_selected_item == item && message.f_moving == TRUE)
397 f_display.SetSensitive (False);
398 f_list.DeleteItemsPos (message.f_count, item);