Fixes for OpenBSD
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Agents / MarkChooser.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 libraries 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) 1994,1995,1996 FUJITSU LIMITED    */
24 /*      All Rights Reserved                             */
25
26 /*
27  * $XConsortium: MarkChooser.cc /main/8 1996/06/14 14:10:02 cde-hal $
28  *
29  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
30  * All rights reserved.  Unpublished -- rights reserved under
31  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
32  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
33  * OR DISCLOSURE.
34  * 
35  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
36  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
37  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
38  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
39  * INTERNATIONAL, LTD.
40  * 
41  *                         RESTRICTED RIGHTS LEGEND
42  * Use, duplication, or disclosure by the Government is subject
43  * to the restrictions as set forth in subparagraph (c)(l)(ii)
44  * of the Rights in Technical Data and Computer Software clause
45  * at DFARS 252.227-7013.
46  *
47  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
48  *                  1315 Dell Avenue
49  *                  Campbell, CA  95008
50  * 
51  */
52
53 #define C_TOC_Element
54 #define L_Basic
55
56 #define C_WindowSystem
57 #define L_Other
58
59 #define C_MarkChooser
60 #define C_MarkCanvas
61 #define C_HelpAgent
62 #define L_Agents
63
64 #define C_MessageMgr
65 #define L_Managers
66
67 #include <Prelude.h>
68
69 #include "Managers/CatMgr.hh"
70 #include "Other/XmStringLocalized.hh"
71
72 #include "Registration.hh"
73
74 #define CLASS MarkChooser
75 #include "create_macros.hh"
76
77 #include <WWL/WXmDialogShell.h>
78 #include <WWL/WXmSeparator.h>
79
80 // /////////////////////////////////////////////////////////////////
81 // class constructor
82 // /////////////////////////////////////////////////////////////////
83
84 MarkChooser::MarkChooser (Widget parent, xList<MarkCanvas *> &marks,
85                           const char *title_key, const char *ok_key)
86 : f_selected_item (-1),
87   f_mark_list (&marks),
88   f_done(FALSE)
89 {
90     create_ui (parent, title_key, ok_key);
91     update_list();
92 }
93
94
95 MarkChooser::~MarkChooser()
96 {
97   f_form.Unmanage();
98   /*
99      have to remove the callbacks first, otherwise the
100      XtDestroyWidget() call will remove the callbacks from
101      the widgets, then our destructor will have memory violations
102      trying to remove them again - brad
103      */
104   removeCallbacks();            
105   XtDestroyWidget (XtParent (f_form));
106 }
107
108
109 // /////////////////////////////////////////////////////////////////
110 // create_ui - create the user interface
111 // /////////////////////////////////////////////////////////////////
112
113 void
114 MarkChooser::create_ui (Widget parent,
115                         const char *title_key, const char *ok_key)
116 {
117   XmStringLocalized mtfstring;
118
119   WXmDialogShell shell (parent, True, "mark_chooser");
120   window_system().register_full_modal_shell (&shell);
121
122   ASSN  (WXmForm,         f_form,   shell,     "form");
123   ASSNM (WXmPushButton,   f_ok,     f_form,    "ok");
124   DECLM (WXmPushButton,   cancel,   f_form,    "cancel");
125 #if 0
126   // do not provide help on full-modal window - 10/27/94 kamiya
127   DECLM (WXmPushButton,   help,     f_form,    "help");
128 #endif
129   DECLM (WXmSeparator,    sep,      f_form,    "separator");
130
131   Widget list = XmCreateScrolledList (f_form, (char*)"list", NULL, 0);
132   f_list = WXmList (list);
133   f_list.Manage();
134
135   XtVaSetValues(f_form, XmNdialogTitle, (XmString)XmStringLocalized((char*)title_key), NULL);
136   XtVaSetValues(f_ok, XmNlabelString, (XmString)XmStringLocalized((char*)ok_key), NULL);
137
138   mtfstring = CATGETS(Set_AgentLabel, 162, "Cancel");
139   XtVaSetValues(cancel, XmNlabelString, (XmString)mtfstring, NULL);
140
141   SET_CALLBACK (f_list,SingleSelection,select);
142   SET_CALLBACK (f_list,BrowseSelection,select);
143   SET_CALLBACK (f_list,DefaultAction,ok);
144   ON_ACTIVATE (f_ok,ok);
145   ON_ACTIVATE (cancel,cancel);
146 #if 0
147   // do not provide help on full-modal window - 10/27/94 kamiya
148   help_agent().add_activate_help (help, "mark_chooser");
149 #endif
150
151   f_form.DefaultButton (f_ok);
152   f_form.ShadowThickness (0);
153   f_form.Manage();
154
155   // Set the min size based on the current size.
156   shell.Realize();
157   shell.MinWidth (shell.Width());
158   shell.MinHeight (shell.Height());
159 }
160
161
162 // /////////////////////////////////////////////////////////////////
163 // update_list - fill in the list with mark items
164 // /////////////////////////////////////////////////////////////////
165
166 void
167 MarkChooser::update_list()
168 {
169   int length = f_mark_list->length();
170   ON_DEBUG (printf ("Chooser list length = %d\n", length));
171   XmStringTable table = new XmString [length];
172
173   List_Iterator<MarkCanvas *> m (f_mark_list);
174
175   int i = 0;
176   while (m)
177     {
178       Xassert (i < length);
179       table[i] = XmStringCreateLocalized((String)m.item()->mark_ptr()->name());
180       m++; i++;
181     }
182   Xassert (i == length);
183
184   f_list.Set (WArgList (XmNitemCount, (XtArgVal) i,
185                         XmNitems, table,
186                         NULL));
187
188   for (i = 0; i < length; i++)
189     XmStringFree (table[i]);
190   delete [] table;
191 }
192
193
194 // /////////////////////////////////////////////////////////////////
195 // get_choice - return the user's choice from the list
196 // /////////////////////////////////////////////////////////////////
197
198 extern int g_blew_away_marks_too_bad_you_lose_dts_14590;
199
200 MarkCanvas *
201 MarkChooser::get_choice()
202 {
203   g_blew_away_marks_too_bad_you_lose_dts_14590 = 0 ;
204
205   f_form.Manage();
206
207   f_done = FALSE;
208   XtAppContext app_context = window_system().app_context();
209   XEvent event;
210
211   while (!f_done)
212     {
213       XtAppNextEvent (app_context, &event);
214       XtDispatchEvent (&event);
215     }
216
217   if (g_blew_away_marks_too_bad_you_lose_dts_14590)
218     {
219       ON_DEBUG(cerr << "blew away marks" << endl);
220       return NULL ;
221     }
222
223   if (f_selected_item > 0)
224     {
225       List_Iterator<MarkCanvas *> m (f_mark_list);
226       int i = 1;
227       while (i < f_selected_item)
228         i++, m++;
229       return (m.item());
230     }
231   else
232     {
233       return (NULL);
234     }
235 }
236
237 // /////////////////////////////////////////////////////////////////
238 // select - process a list item selection
239 // /////////////////////////////////////////////////////////////////
240
241 void
242 MarkChooser::select (WCallback *wcb)
243 {
244   CALL_DATA (XmListCallbackStruct, lcs);
245
246   f_ok.SetSensitive (True);
247   f_selected_item = lcs->item_position;
248 }
249
250
251 // /////////////////////////////////////////////////////////////////
252 // ok, cancel, help - other callbacks
253 // /////////////////////////////////////////////////////////////////
254
255
256 void
257 MarkChooser::ok()
258 {
259   f_done = TRUE;
260 }
261
262 void
263 MarkChooser::cancel()
264 {
265   f_selected_item = -1;
266   f_done = TRUE;
267 }