e039ac4e1689d330718af07f769e6bd6c28d1ee6
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Agents / NodeListAgentMotif.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 /*
24  * $XConsortium: NodeListAgentMotif.C /main/8 1996/10/15 17:37:13 cde-hal $
25  *
26  * Copyright (c) 1991 HaL Computer Systems, Inc.  All rights reserved.
27  * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
28  * States.  Use of a copyright notice is precautionary only and does not
29  * imply publication or disclosure.
30  * 
31  * This software contains confidential information and trade secrets of HaL
32  * Computer Systems, Inc.  Use, disclosure, or reproduction is prohibited
33  * without the prior express written permission of HaL Computer Systems, Inc.
34  * 
35  *                         RESTRICTED RIGHTS LEGEND
36  * Use, duplication, or disclosure by the Government is subject to
37  * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
38  * Technical Data and Computer Software clause at DFARS 252.227-7013.
39  *                        HaL Computer Systems, Inc.
40  *                  1315 Dell Avenue, Campbell, CA  95008
41  *
42  */
43
44 #define C_TOC_Element
45 #define L_Basic
46
47 #define C_NodeListAgent
48 #define L_Agents
49
50 #define C_MessageMgr
51 #define L_Managers
52
53 #include "Other/XmStringLocalized.hh"
54 #include "Managers/CatMgr.hh"
55
56 #include "Prelude.h"
57
58 #include "Registration.hh"
59
60 #include <WWL/WTopLevelShell.h>
61 #include <WWL/WXmMenu.h>
62 #include <WWL/WXmFrame.h>
63 #include <WWL/WXmTextField.h>
64 #include <WWL/WXmForm.h>
65 #include <WWL/WXmPushButton.h>
66 #include <WWL/WXmSeparator.h>
67 #include <WWL/WXmLabel.h>
68 #include <WWL/WXmList.h>
69 #include <WWL/WXmPanedWindow.h>
70
71 Cardinal NodeListAgent::f_pane_insert_position = 0;
72
73 // /////////////////////////////////////////////////////////////////
74 // class destructor
75 // /////////////////////////////////////////////////////////////////
76
77 NodeListAgent::~NodeListAgent()
78 {
79   // NOTE: Maybe this variable should be in the agent! 
80   delete f_wm_delete_callback;
81   // NOTE: How about deleting the widget hierarchy!! djb 
82 }
83
84
85 // /////////////////////////////////////////////////////////////////
86 // init - let's get started
87 // /////////////////////////////////////////////////////////////////
88
89 void
90 NodeListAgent::init()
91 {
92   f_shell = NULL;
93   f_list = NULL;
94   setInitialized();
95   setStatus (eSuccess);
96 }
97
98 // /////////////////////////////////////////////////////////////////
99 // display
100 // /////////////////////////////////////////////////////////////////
101
102 void
103 NodeListAgent::display()
104 {
105   if (!initialized())
106     {
107       // Error
108       return;
109     }
110
111   /* -------- Create Motif ui if necessary. -------- */
112   Xassert (f_shell != NULL);
113   // Call to create_window should be in subclass
114
115   f_shell->Popup();
116   f_shell->DeIconify();
117   setStatus (eSuccess);
118 }
119
120 // /////////////////////////////////////////////////////////////////
121 // create_base_window
122 // /////////////////////////////////////////////////////////////////
123
124 /* This should be called from subclasses create_window method. */
125
126 void
127 NodeListAgent::create_base_window (char *name)
128 {
129   f_shell = new WTopLevelShell (toplevel(), WPopup, name);
130   window_system().register_shell (f_shell);
131 #define AM WAutoManage
132 //Widget Class       Var Name        Parent           Widget Name
133 //------------------ --------------- ---------------- ----------------
134   f_form     = new WXmForm    (*f_shell, "form");
135   f_menu_bar = new WXmMenuBar (*f_form, (char*)"menu_bar" /* , WAutoManage */);
136
137   WXmCascadeButton   file_cascade    (*f_menu_bar,    "file",           AM);
138   WXmPulldownMenu    file_menu       (*f_menu_bar,    (char*)"file_menu"  );
139   WXmPushButton      close           (file_menu,      "close",          AM);
140   WXmCascadeButton   edit_cascade    (*f_menu_bar,    "edit",           AM);
141   WXmPulldownMenu    edit_menu       (*f_menu_bar,    (char*)"edit_menu"  );
142   WXmPushButton      undo            (edit_menu,      "undo",           AM);
143   /*
144   WXmCascadeButton   view_cascade    (*f_menu_bar,    "view",           AM);
145   WXmPulldownMenu    view_menu       (*f_menu_bar,    (char*)"view_menu"  );
146   WXmCascadeButton   sort_cascade    (view_menu,      "sort",           AM);
147   WXmPulldownMenu    sort_menu       (*f_menu_bar,    (char*)"sort_menu"  );
148   WXmPushButton      ooo             (sort_menu,      "ooo",            AM);
149   */
150
151   WXmCascadeButton   help_cascade    (*f_menu_bar,    "help",           AM);
152   WXmPulldownMenu    help_menu       (*f_menu_bar,    (char*)"help_menu"  );
153   WXmPushButton      context         (help_menu,      "context",        AM);
154   WXmPushButton      window          (help_menu,      "window",         AM);
155
156   XmStringLocalized mtfstring;
157
158   f_display = WXmPushButton (*f_form,       "display",        AM);
159   f_help    = WXmPushButton (*f_form,       "help",        AM);
160   WXmPushButton      closeb          (*f_form,       "close",          AM);
161
162   mtfstring = CATGETS(Set_AgentLabel, 165, "Display");
163   XtVaSetValues((Widget)f_display, XmNlabelString, (XmString)mtfstring, NULL);
164   mtfstring = CATGETS(Set_AgentLabel, 12, "Close");
165   XtVaSetValues((Widget)closeb, XmNlabelString, (XmString)mtfstring, NULL);
166   mtfstring = CATGETS(Set_AgentLabel, 48, "Help");
167   XtVaSetValues((Widget)f_help, XmNlabelString, (XmString)mtfstring, NULL);
168
169   WXmSeparator       separator       (*f_form,        "separator",      AM);
170
171   f_pane = (WXmPanedWindow*)(Widget)WXmPanedWindow (*f_form, "pane");
172   f_pane->InsertPosition (&NodeListAgent::pane_insert_position);
173   
174   f_list_form  = (WXmForm*)(Widget)WXmForm(*f_pane, "listform", AM);
175
176   Widget scrolled_list =  XmCreateScrolledList (*f_list_form, (char*)"list", NULL, 0);
177
178   f_list = (WXmList*)scrolled_list ;
179   f_list->Manage();
180
181   XmFontList defaultList;
182   {
183     XmFontList font;
184     XtVaGetValues(scrolled_list, XmNfontList, &font, NULL);
185     defaultList = XmFontListCopy(font);
186   }
187
188   if (window_system().dtinfo_font())
189     defaultList = XmFontListAppendEntry(defaultList,
190                                         window_system().dtinfo_font());
191   if (window_system().dtinfo_space_font())
192     defaultList = XmFontListAppendEntry(defaultList,
193                                         window_system().dtinfo_space_font());
194   XtVaSetValues(scrolled_list, XmNfontList, defaultList, NULL);
195   
196 #undef AM
197
198   // NOTE: error checking
199
200   /* -------- attach menus -------- */
201   file_cascade.SubMenuId (file_menu);
202   edit_cascade.SubMenuId (edit_menu);
203   help_cascade.SubMenuId (help_menu);
204   f_menu_bar->MenuHelpWidget (help_cascade);
205
206   close.SetActivateCallback (this, (WWL_FUN)&NodeListAgent::close_window);
207   closeb.SetActivateCallback (this, (WWL_FUN)&NodeListAgent::close_window);
208   f_wm_delete_callback =
209     new WCallback (*f_shell, window_system().WM_DELETE_WINDOW(),
210                    this, (WWL_FUN) &NodeListAgent::close_window);
211
212   f_form->ShadowThickness (0);   // gets rid of border turds
213   f_form->DefaultButton (f_display);
214 }
215
216 // /////////////////////////////////////////////////////////////////
217 // insert_position
218 // /////////////////////////////////////////////////////////////////
219
220 Cardinal
221 NodeListAgent::pane_insert_position (Widget w)
222 {
223   extern WidgetClass xmSashWidgetClass, xmSeparatorGadgetClass;
224   Cardinal position;
225   if (XtIsSubclass (w, xmSashWidgetClass) ||
226       XtIsSubclass (w, xmSeparatorGadgetClass))
227     {
228       WComposite cw (XtParent(w));
229       position = cw.NumChildren();
230     }
231   else
232     position = NodeListAgent::f_pane_insert_position;
233
234   /* Code can set this var to determine the insert position of widgets. */
235   return (position);
236   // NodeListAgent::f_pane_insert_position = 0;
237 }
238
239
240 // /////////////////////////////////////////////////////////////////
241 // close_window
242 // /////////////////////////////////////////////////////////////////
243
244 void
245 NodeListAgent::close_window (WCallback *)
246 {
247   f_shell->Popdown();
248 }