dtcm: Resolve CID 87562
[oweals/cde.git] / cde / programs / dtcm / dtcm / tempbr.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 **
25 **  tempbr.c
26 **
27 **  $TOG: tempbr.c /main/5 1999/02/23 09:42:53 mgreess $
28 **
29 **  RESTRICTED CONFIDENTIAL INFORMATION:
30 **
31 **  The information in this document is subject to special
32 **  restrictions in a confidential disclosure agreement between
33 **  HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34 **  document outside HP, IBM, Sun, USL, SCO, or Univel without
35 **  Sun's specific written approval.  This document and all copies
36 **  and derivative works thereof must be returned or destroyed at
37 **  Sun's request.
38 **
39 **  Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40 **
41 *******************************************************************************/
42
43 /*                                                                      *
44  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
45  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
46  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
47  * (c) Copyright 1993, 1994 Novell, Inc.                                *
48  */
49
50 #ifndef lint
51 static  char sccsid[] = "@(#)tempbr.c 1.48 95/03/28 Copyr 1991 Sun Microsystems, Inc.";
52 #endif
53
54 #include <EUSCompat.h>
55 #include <stdio.h>
56 #include <Xm/Xm.h>
57 #include <Xm/Form.h>
58 #include <Xm/Label.h>
59 #include <Xm/LabelG.h>
60 #include <Xm/List.h>
61 #include <Xm/DialogS.h>
62 #include <Xm/PushB.h>
63 #include <Xm/PushBG.h>
64 #include <Xm/RowColumn.h>
65 #include <Xm/Scale.h>
66 #include <Xm/SeparatoG.h>
67 #include <Xm/TextF.h>
68 #include <Xm/Text.h>
69 #include <Xm/ToggleBG.h>
70 #include <Xm/XmStrDefs.h>
71 #include <Xm/MwmUtil.h>
72 #include <Dt/HourGlass.h>
73 #ifdef FNS_DEMO
74 #include <Tt/tt_c.h>
75 #include <Tt/tttk.h>
76 #endif
77 #include "util.h"
78 #include "timeops.h"
79 #include "tempbr.h"
80 #include "datefield.h"
81 #include "props.h"
82 #include "editor.h"
83 #include "deskset.h"
84 #include "help.h"
85 #ifdef FNS
86 #include "cmfns.h"
87 #endif
88
89 static void tb_cancel_cb();
90 static void tb_close_cb();
91 static void tempbr_show_cb(Widget w, XtPointer data, XtPointer cbs);
92 #if defined(linux)
93 #include <string.h>
94 #else
95 extern char *strdup(const char *);
96 #endif
97
98 #ifdef FNS_DEMO
99 /* This stuff is currently broken */
100 Tt_message
101 tempbr_sundex_ttedit_cb(
102         Tt_message      m,
103         void            *c_data,
104         Tttk_op         op, 
105         unsigned char   *contents,
106         int             len,
107         char            *file)
108
109 {
110         char    *user_str = "user:";
111         char    *p;
112
113         Tempbr  *tb = (Tempbr *)c_data;
114         /*
115         cmfns_name_to_namepanel(contents, tb->np);
116         */
117         /* XXX Yech, but hell it is just a demo */
118         if (strncmp(user_str, (char *)contents, strlen(user_str)) == 0) {
119                 p = strchr((char *)contents, ':');
120                 p++;
121         } else {
122                 p = (char *)contents;
123         }
124                 
125         XmTextFieldSetString(tb->name_text, p);
126         return m;
127 }
128
129 static void
130 tempbr_sundex_cb(Widget w, XtPointer data, XtPointer cbs)
131 {
132         Tempbr  *tb = (Tempbr *)data;
133         Tt_message      msg = NULL;
134         Tt_status       status;
135
136         msg = ttmedia_load(0, (Ttmedia_load_msg_cb)tempbr_sundex_ttedit_cb,
137                         tb, TTME_EDIT, "Sun_Info", data, strlen(data) + 1,
138                         NULL, "calendar-address", 0);
139
140         status = tt_ptr_error(msg);
141         if (tt_is_err(status)) {
142                 fprintf(stderr, "dtcm: ttmedia_load: %s\n",
143                         tt_status_message(status));
144                 return;
145         }
146
147         status = tt_message_send(msg);
148         if (tt_is_err(status)) {
149                 fprintf(stderr, "dtcm: tt_message_send: %s\n",
150                         tt_status_message(status));
151         }
152
153         return;
154 }
155 #endif /* FNS_DEMO */
156
157 static void
158 tempbr_show_cb(Widget w, XtPointer data, XtPointer cbs)
159 {
160         Calendar *c = calendar;
161         char *name;
162         Tempbr  *tb = (Tempbr *)data;
163         char msg_buf[256];
164         char buf[256];
165
166         if ((name = XmTextGetString(tb->name_text)) == NULL) {
167                 return;
168         }
169
170         _DtTurnOnHourGlass(tb->frame);
171
172 #ifdef FNS
173         if (cmfns_use_fns((Props *)c->properties)) {
174                 sprintf(msg_buf, catgets(c->DT_catd, 1, 647,
175                         "Looking up %s..."), name);
176                 set_message(tb->show_message, msg_buf);
177                 XmUpdateDisplay(tb->show_message);
178                 XFlush(XtDisplay(w));
179                 /* Translate name to a calendar address */
180                 cmfns_lookup_calendar(name, buf, sizeof(buf));
181                 name = buf;
182         }
183 #endif
184
185         sprintf(msg_buf, catgets(c->DT_catd, 1, 559, "Browsing %s..."),
186                 name);
187         set_message(tb->show_message, msg_buf);
188         XFlush(XtDisplay(w));
189         switch_it(tb->cal, name, tempbrowser);
190         _DtTurnOffHourGlass(tb->frame);
191         return;
192 }
193
194 extern caddr_t
195 make_std_tempbr(Calendar *c)
196 {
197         Tempbr *tb;
198         XmString        label_str;
199         Widget          separator, button_form;
200         char            *title;
201
202         if (c->tempbr == NULL) {
203                 c->tempbr = (caddr_t)ckalloc(sizeof(Tempbr));
204                 tb = (Tempbr*)c->tempbr;
205         }
206         else
207                 tb = (Tempbr*)c->tempbr;
208
209         title = XtNewString(catgets(c->DT_catd, 1, 560, "Calendar : Show Other Calendar"));
210         tb->frame = XtVaCreatePopupShell("frame",
211                 xmDialogShellWidgetClass, c->frame,
212                 XmNtitle,               title,
213                 XmNallowShellResize,    True,
214                 XmNmappedWhenManaged,   False,
215                 NULL);
216         XtFree(title);
217
218         tb->form = XtVaCreateWidget("form",
219                 xmFormWidgetClass,      
220                 tb->frame,
221                 XmNautoUnmanage,        False,
222                 XmNfractionBase,        3,
223                 XmNhorizontalSpacing,   4,
224                 XmNverticalSpacing,     4,
225                 XmNmarginWidth,         0,
226                 XmNmarginHeight,        0,
227                 NULL);
228
229         label_str = XmStringCreateLocalized(
230                                 catgets(c->DT_catd, 1, 410, "User Name:"));
231         tb->name_label = XtVaCreateWidget("name_label", 
232                 xmLabelWidgetClass, 
233                 tb->form,
234                 XmNlabelString,         label_str,
235                 XmNleftAttachment,      XmATTACH_FORM,
236                 XmNleftOffset,          5,
237                 XmNtopAttachment,       XmATTACH_FORM,
238                 XmNtopOffset,           11,
239                 NULL);
240         XmStringFree(label_str);
241
242         tb->name_text = XtVaCreateWidget("show_text",
243                 xmTextWidgetClass, 
244                 tb->form,
245                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
246                 XmNbottomWidget,        tb->name_label,
247                 XmNbottomOffset,        -4,
248                 XmNleftAttachment,      XmATTACH_WIDGET,
249                 XmNleftWidget,          tb->name_label,
250                 XmNrightAttachment,     XmATTACH_POSITION,
251                 XmNrightPosition,       3,
252                 XmNrightOffset,         10,
253                 XmNcolumns,             30,
254                 NULL);
255
256         separator = XtVaCreateWidget("separator",
257                 xmSeparatorGadgetClass,
258                 tb->form,
259                 XmNleftAttachment,      XmATTACH_FORM,
260                 XmNrightAttachment,     XmATTACH_FORM,
261                 XmNtopAttachment,       XmATTACH_WIDGET,
262                 XmNtopWidget,           tb->name_text,
263                 XmNtopOffset,           5,
264                 NULL);
265
266         button_form = XtVaCreateWidget("form",
267                 xmFormWidgetClass,      
268                 tb->form,
269                 XmNautoUnmanage,        False,
270                 XmNleftAttachment,      XmATTACH_FORM,
271                 XmNleftOffset,          5,
272                 XmNrightAttachment,     XmATTACH_FORM,
273                 XmNrightOffset,         5,
274                 XmNtopAttachment,       XmATTACH_WIDGET,
275                 XmNtopWidget,           separator,
276                 XmNhorizontalSpacing,   4,
277                 XmNfractionBase,        3,
278                 NULL);
279  
280         label_str = XmStringCreateLocalized(
281                                 catgets(c->DT_catd, 1, 562, "Show"));
282         tb->show_button = XtVaCreateWidget("show_button",
283                 xmPushButtonWidgetClass, 
284                 button_form,
285                 XmNlabelString, label_str,
286                 XmNtopAttachment, XmATTACH_WIDGET,
287                 XmNtopWidget, separator,
288                 XmNleftAttachment, XmATTACH_POSITION,
289                 XmNleftPosition, 0,
290                 XmNrightAttachment, XmATTACH_POSITION,
291                 XmNrightPosition, 1,
292                 XmNnavigationType, XmTAB_GROUP,
293                 NULL);
294         XmStringFree(label_str);
295
296         label_str = XmStringCreateLocalized(
297                                 catgets(c->DT_catd, 1, 680, "Close"));
298         tb->cancel_button = XtVaCreateWidget("cancelButton",
299                 xmPushButtonWidgetClass, 
300                 button_form,
301                 XmNlabelString, label_str,
302                 XmNtopAttachment, XmATTACH_WIDGET,
303                 XmNtopWidget, separator,
304                 XmNleftAttachment, XmATTACH_POSITION,
305                 XmNleftPosition, 1,
306                 XmNrightAttachment, XmATTACH_POSITION,
307                 XmNrightPosition, 2,
308                 XmNuserData, c,
309                 NULL);
310         XmStringFree(label_str);
311         XtAddCallback(tb->cancel_button, 
312                         XmNactivateCallback, tb_cancel_cb, NULL);
313
314         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
315         tb->help_button = XtVaCreateWidget("helpButton",
316                 xmPushButtonWidgetClass, button_form,
317                 XmNlabelString, label_str,
318                 XmNtopAttachment, XmATTACH_WIDGET,
319                 XmNtopWidget, separator,
320                 XmNleftAttachment, XmATTACH_POSITION,
321                 XmNleftPosition, 2,
322                 XmNrightAttachment, XmATTACH_POSITION,
323                 XmNrightPosition, 3,
324                 NULL);
325         XmStringFree(label_str);
326         XtAddCallback(tb->help_button, XmNactivateCallback,
327                 (XtCallbackProc)help_cb, SHOW_OTHER_CAL_HELP_BUTTON);
328         XtAddCallback(tb->form, XmNhelpCallback,
329                 (XtCallbackProc)help_cb, (XtPointer) SHOW_OTHER_CAL_HELP_BUTTON);
330
331 #ifdef FNS_SUNDEX_DEMO
332         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 648,
333                                             "SunDex"));
334         tb->show_button = XtVaCreateWidget("sundex_button",
335                 xmPushButtonWidgetClass, tb->form,
336                 XmNlabelString,         label_str,
337                 XmNtopAttachment, XmATTACH_FORM,
338                 XmNtopOffset, 9,
339                 XmNleftAttachment, XmATTACH_WIDGET,
340                 XmNleftWidget,  tb->name_text,
341                 XmNleftOffset, 5,
342                 NULL);
343         XmStringFree(label_str);
344         XtAddCallback(tb->show_button, XmNactivateCallback,
345                 tempbr_sundex_cb, tb);
346 #endif
347
348         tb->show_message = XtVaCreateWidget("show_message",
349                 xmLabelGadgetClass, tb->form,
350                 XmNalignment, XmALIGNMENT_BEGINNING,
351                 XmNtopAttachment, XmATTACH_WIDGET,
352                 XmNtopWidget, tb->cancel_button,
353                 XmNleftAttachment, XmATTACH_FORM,
354                 XmNrightAttachment, XmATTACH_FORM,
355                 XmNbottomAttachment, XmATTACH_FORM,
356                 NULL);
357
358         set_message(tb->show_message, "");
359
360         XtAddCallback(tb->show_button, XmNactivateCallback,
361                         tempbr_show_cb, tb);
362         ds_position_popup(c->frame, tb->frame, DS_POPUP_LOR);
363
364         /* set default button */
365         XtVaSetValues(button_form, 
366                         XmNdefaultButton,       tb->show_button, 
367                         XmNcancelButton,        tb->show_button, 
368                         NULL);
369         XtVaSetValues(tb->form, 
370                         XmNdefaultButton,       tb->show_button, 
371                         XmNcancelButton,        tb->show_button, 
372                         NULL);
373
374         XmProcessTraversal(tb->name_text, XmTRAVERSE_CURRENT);
375         XtVaSetValues(tb->form, XmNinitialFocus, tb->name_text, NULL);
376
377         ManageChildren(button_form);
378         ManageChildren(tb->form);
379         XtManageChild(tb->form);
380         XtVaSetValues(tb->frame, XmNmappedWhenManaged, True, NULL);
381         XtRealizeWidget(tb->frame);
382
383         XtPopup(tb->frame, XtGrabNone);
384
385         return(caddr_t)tb;
386 }
387
388 caddr_t
389 make_tempbr(Calendar *c)
390 {
391         caddr_t tb;
392
393         tb = make_std_tempbr(c);
394         ((Tempbr *)tb)->cal = c;
395
396         return tb;
397 }
398
399 static void
400 tb_cancel_cb(
401         Widget  widget,
402         XtPointer client_data,
403         XmPushButtonCallbackStruct *cbs)
404 {
405         Calendar *c;
406         Tempbr      *tb;
407
408         XtVaGetValues(widget, XmNuserData, &c, NULL);
409         tb = (Tempbr *)c->tempbr;
410
411         XmTextSetString(tb->name_text, "");
412         XtPopdown(tb->frame);
413
414         return;
415 }
416
417 static void
418 tb_close_cb(Widget w, XtPointer data, XtPointer cbs)
419 {
420         Tempbr  *tb = (Tempbr *)data;
421
422         XtPopdown(tb->frame);
423
424         return;
425 }