f3501f607cf5fc877efbf6acdf74ba1f08a35eeb
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Agents / ListViewMotif.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
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)
10  * any later version.
11  *
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
16  * details.
17  *
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
22  */
23 /*      Copyright (c) 1995,1996 FUJITSU LIMITED         */
24 /*      All Rights Reserved                             */
25
26 /*
27  * $XConsortium: ListViewMotif.C /main/9 1996/10/15 17:35:55 cde-hal $
28  *
29  * Copyright (c) 1992 HaL Computer Systems, Inc.  All rights reserved.
30  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
31  * States.  Use of a copyright notice is precautionary only and does not
32  * imply publication or disclosure.
33  * 
34  * This software contains confidential information and trade secrets of HaL
35  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
36  * without the prior express written permission of HaL Computer Systems, Inc.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject to
40  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
41  * Technical Data and Computer Software clause at DFARS 252.227-7013.
42  *                        HaL Computer Systems, Inc.
43  *                  1315 Dell Avenue, Campbell, CA  95008
44  * 
45  */
46
47 #include <WWL/WTopLevelShell.h>
48 #include <WWL/WXmPushButton.h>
49 #include <WWL/WXmList.h>
50 #include <WWL/WXmForm.h>
51 #include <WWL/WXmLabelGadget.h>
52 #include <WWL/WXmSeparator.h>
53
54 #include <stdio.h>
55
56 #define C_WindowSystem
57 #define L_Other
58
59
60 #define C_TOC_Element
61 #define C_List
62 #define L_Basic
63
64 #define C_HelpAgent
65 #define C_ListView
66 #define L_Agents
67
68 #include "Prelude.h"
69
70 #include "Other/XmStringLocalized.hh"
71 #include "Managers/CatMgr.hh"
72
73 #include "Registration.hh"
74
75 // /////////////////////////////////////////////////////////////////
76 // class destructor
77 // /////////////////////////////////////////////////////////////////
78
79 ListView::~ListView()
80 {
81   if (f_shell != NULL)
82     {
83       f_shell->Destroy();
84       delete f_shell;
85       delete f_list;
86       delete f_wm_delete_callback;
87     }
88 }
89
90
91 // /////////////////////////////////////////////////////////////////
92 // list - set/get the list
93 // /////////////////////////////////////////////////////////////////
94
95 void
96 ListView::list (List *list)
97 {
98   if (f_the_list != NULL)
99     f_the_list->
100       RemoveDependent ((notify_handler_t) &ListView::list_changed,
101                         List::APPENDED);
102   f_the_list = list;
103   f_the_list->AddDependent ((notify_handler_t) &ListView::list_changed,
104                              List::APPENDED);
105   display_list();
106 }
107
108 const List *
109 ListView::list()
110 {
111   return (f_the_list);
112 }
113
114 // /////////////////////////////////////////////////////////////////
115 // display - display it on the screen
116 // /////////////////////////////////////////////////////////////////
117
118 void
119 ListView::display()
120 {
121   if (f_shell == NULL)
122     {
123       create_ui_objects();
124       display_list();
125     }
126
127   f_shell->Popup();
128   f_shell->DeIconify();
129 }
130
131
132 // /////////////////////////////////////////////////////////////////
133 // create_ui_objects
134 // /////////////////////////////////////////////////////////////////
135
136 void
137 ListView::create_ui_objects()
138 {
139   /* -------- Create ui components. -------- */
140   f_shell = new WTopLevelShell (toplevel(), WPopup, f_name);
141   window_system().register_shell (f_shell);
142   WXmForm form (*f_shell, "form");
143
144   /* -------- allow child to be creative -------- */
145   child_create_ui_pre(form);
146
147
148   WXmPushButton close (form, "close", WAutoManage);
149   WXmPushButton help (form, "help", WAutoManage);
150
151   XtVaSetValues(close, XmNlabelString,
152         (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 12, "Close")), NULL);
153   XtVaSetValues(help, XmNlabelString,
154         (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 48, "Help")), NULL);
155
156   // 7/30/93 rtp - bear with this hack, it's a little bogus
157   char *help_name = new char[strlen(f_name) + strlen("_help") + 1];
158   sprintf(help_name, "%s%s", f_name, "_help");
159   // What i've done is appended '_help' to the widget name and added
160   // a help callback to the help button that will reference this name
161   help_agent().add_activate_help (help, help_name);
162
163   f_activate = WXmPushButton (form, "activate", WAutoManage);
164   XtVaSetValues(f_activate, XmNlabelString,
165         (XmString)XmStringLocalized(CATGETS(Set_AgentLabel, 165, "Display")), NULL);
166   //  WXmLabelGadget label (form, "label", WAutoManage);
167   WXmSeparator separator (form, "separator", WAutoManage);
168   // NOTE: Fix WWL to have a scrolled list object!
169   Widget scrolled_list = XmCreateScrolledList (form, "list", NULL, 0);
170   f_list = new WXmList (scrolled_list);
171   f_list->Manage();
172
173   XmFontList defaultList;
174   {
175     XmFontList font;
176     XtVaGetValues(scrolled_list, XmNfontList, &font, NULL);
177     defaultList = XmFontListCopy(font);
178   }
179   if (window_system().dtinfo_space_font())
180     defaultList = XmFontListAppendEntry(defaultList,
181                                         window_system().dtinfo_space_font());
182   XtVaSetValues(scrolled_list, XmNfontList, defaultList, NULL);
183
184   /* -------- let child add anything else -------- */
185   child_create_ui_post(form);
186
187   /* -------- Callbacks -------- */
188   f_wm_delete_callback =
189     new WCallback (*f_shell, window_system().WM_DELETE_WINDOW(),
190                    this, (WWL_FUN) &ListView::close_window);
191   close.SetActivateCallback (this, (WWL_FUN) &ListView::close_window);
192   f_list->SetSingleSelectionCallback (this, (WWL_FUN) &ListView::select);
193   f_list->SetBrowseSelectionCallback (this, (WWL_FUN) &ListView::select);
194   f_list->SetDefaultActionCallback (this, (WWL_FUN) &ListView::activate);
195   f_activate.SetActivateCallback (this, (WWL_FUN) &ListView::activate);
196
197   /* -------- Finalize -------- */
198   form.DefaultButton (f_activate);
199   form.ShadowThickness (0);  // get rid of border turds (motif bug)
200   form.Manage();
201 }
202   
203
204 // /////////////////////////////////////////////////////////////////
205 // display_list - put the list in the Motif list widget
206 // /////////////////////////////////////////////////////////////////
207
208 void
209 ListView::display_list()
210 {
211   // NOTE: What does it mean to display a NULL list? 6/22/92 djb 
212   if (f_shell == NULL || f_the_list == NULL)
213     return;
214
215   int i;
216
217   // NOTE: There should be a wwl object for string tables!! 6/19/92 djb
218   XmStringTable st = (XmStringTable)
219     malloc (sizeof (XmStringTable) * f_the_list->length());
220
221   for (i = 0; i < f_the_list->length(); i++)
222     st[i] = display_value((*f_the_list)[i]);
223
224   // Basically bogus, but best fix for now.  18:32 10-May-94 DJB
225   f_list->DeselectAllItems();
226   WArgList args;
227   f_list->Items (st, args);
228   f_list->ItemCount (f_the_list->length(), args);
229   f_list->Set (args);
230
231   for (i = 0; i < f_the_list->length(); i++)
232     XmStringFree(st[i]);
233
234   free ((char *) st);
235 }
236
237
238 // /////////////////////////////////////////////////////////////////
239 // select
240 // /////////////////////////////////////////////////////////////////
241
242 void
243 ListView::select (WCallback *wcb)
244 {
245   XmListCallbackStruct *lcs = (XmListCallbackStruct *) wcb->CallData();
246
247   f_activate.SetSensitive (True);
248   f_selected_item = lcs->item_position - 1;
249 }
250
251
252 // /////////////////////////////////////////////////////////////////
253 // activate
254 // /////////////////////////////////////////////////////////////////
255
256 void
257 ListView::activate (WCallback *)
258 {
259   notify (ENTRY_ACTIVATE, (void *) f_selected_item);
260 }
261   
262
263 // /////////////////////////////////////////////////////////////////
264 // close_window
265 // /////////////////////////////////////////////////////////////////
266
267 void
268 ListView::close_window (WCallback *)
269 {
270   f_shell->Popdown();
271 }
272
273
274 // /////////////////////////////////////////////////////////////////
275 // list_changed - the list was altered somehow
276 // /////////////////////////////////////////////////////////////////
277
278 void
279 ListView::list_changed (FolioObject *, u_int, void *, void *)
280 {
281   // NOTE: simplistic for now 6/23/92 djb
282   display_list();
283 }
284
285 XmString
286 ListView::display_value(FolioObject *object)
287 {
288   return XmStringCreateLocalized((char*)object->display_as());
289 }
290
291 void
292 ListView::child_create_ui_pre(WXmForm &)
293 {
294   /* -------- empty -------- */
295 }
296
297 void
298 ListView::child_create_ui_post(WXmForm &)
299 {
300   /* -------- empty -------- */
301 }