Add GNU LGPL headers to all .c .C and .h files
[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 extern char *strdup(const char *);
93
94 #ifdef FNS_DEMO
95 /* This stuff is currently broken */
96 Tt_message
97 tempbr_sundex_ttedit_cb(
98         Tt_message      m,
99         void            *c_data,
100         Tttk_op         op, 
101         unsigned char   *contents,
102         int             len,
103         char            *file)
104
105 {
106         char    *user_str = "user:";
107         char    *p;
108
109         Tempbr  *tb = (Tempbr *)c_data;
110         /*
111         cmfns_name_to_namepanel(contents, tb->np);
112         */
113         /* XXX Yech, but hell it is just a demo */
114         if (strncmp(user_str, (char *)contents, strlen(user_str)) == 0) {
115                 p = strchr((char *)contents, ':');
116                 p++;
117         } else {
118                 p = (char *)contents;
119         }
120                 
121         XmTextFieldSetString(tb->name_text, p);
122         return m;
123 }
124
125 static void
126 tempbr_sundex_cb(Widget w, XtPointer data, XtPointer cbs)
127 {
128         Tempbr  *tb = (Tempbr *)data;
129         Tt_message      msg = NULL;
130         Tt_status       status;
131
132         msg = ttmedia_load(0, (Ttmedia_load_msg_cb)tempbr_sundex_ttedit_cb,
133                         tb, TTME_EDIT, "Sun_Info", data, strlen(data) + 1,
134                         NULL, "calendar-address", 0);
135
136         status = tt_ptr_error(msg);
137         if (tt_is_err(status)) {
138                 fprintf(stderr, "dtcm: ttmedia_load: %s\n",
139                         tt_status_message(status));
140                 return;
141         }
142
143         status = tt_message_send(msg);
144         if (tt_is_err(status)) {
145                 fprintf(stderr, "dtcm: tt_message_send: %s\n",
146                         tt_status_message(status));
147         }
148
149         return;
150 }
151 #endif /* FNS_DEMO */
152
153 static void
154 tempbr_show_cb(Widget w, XtPointer data, XtPointer cbs)
155 {
156         Calendar *c = calendar;
157         char *name;
158         Tempbr  *tb = (Tempbr *)data;
159         char msg_buf[256];
160         char buf[256];
161
162         if ((name = XmTextGetString(tb->name_text)) == NULL) {
163                 return;
164         }
165
166         _DtTurnOnHourGlass(tb->frame);
167
168 #ifdef FNS
169         if (cmfns_use_fns((Props *)c->properties)) {
170                 sprintf(msg_buf, catgets(c->DT_catd, 1, 647,
171                         "Looking up %s..."), name);
172                 set_message(tb->show_message, msg_buf);
173                 XmUpdateDisplay(tb->show_message);
174                 XFlush(XtDisplay(w));
175                 /* Translate name to a calendar address */
176                 cmfns_lookup_calendar(name, buf, sizeof(buf));
177                 name = buf;
178         }
179 #endif
180
181         sprintf(msg_buf, catgets(c->DT_catd, 1, 559, "Browsing %s..."),
182                 name);
183         set_message(tb->show_message, msg_buf);
184         XFlush(XtDisplay(w));
185         switch_it(tb->cal, name, tempbrowser);
186         _DtTurnOffHourGlass(tb->frame);
187         return;
188 }
189
190 extern caddr_t
191 make_std_tempbr(Calendar *c)
192 {
193         Tempbr *tb;
194         XmString        label_str;
195         Widget          separator, button_form;
196         char            *title;
197
198         if (c->tempbr == NULL) {
199                 c->tempbr = (caddr_t)ckalloc(sizeof(Tempbr));
200                 tb = (Tempbr*)c->tempbr;
201         }
202         else
203                 tb = (Tempbr*)c->tempbr;
204
205         title = XtNewString(catgets(c->DT_catd, 1, 560, "Calendar : Show Other Calendar"));
206         tb->frame = XtVaCreatePopupShell("frame",
207                 xmDialogShellWidgetClass, c->frame,
208                 XmNtitle,               title,
209                 XmNallowShellResize,    True,
210                 XmNmappedWhenManaged,   False,
211                 NULL);
212         XtFree(title);
213
214         tb->form = XtVaCreateWidget("form",
215                 xmFormWidgetClass,      
216                 tb->frame,
217                 XmNautoUnmanage,        False,
218                 XmNfractionBase,        3,
219                 XmNhorizontalSpacing,   4,
220                 XmNverticalSpacing,     4,
221                 XmNmarginWidth,         0,
222                 XmNmarginHeight,        0,
223                 NULL);
224
225         label_str = XmStringCreateLocalized(
226                                 catgets(c->DT_catd, 1, 410, "User Name:"));
227         tb->name_label = XtVaCreateWidget("name_label", 
228                 xmLabelWidgetClass, 
229                 tb->form,
230                 XmNlabelString,         label_str,
231                 XmNleftAttachment,      XmATTACH_FORM,
232                 XmNleftOffset,          5,
233                 XmNtopAttachment,       XmATTACH_FORM,
234                 XmNtopOffset,           11,
235                 NULL);
236         XmStringFree(label_str);
237
238         tb->name_text = XtVaCreateWidget("show_text",
239                 xmTextWidgetClass, 
240                 tb->form,
241                 XmNbottomAttachment,    XmATTACH_OPPOSITE_WIDGET,
242                 XmNbottomWidget,        tb->name_label,
243                 XmNbottomOffset,        -4,
244                 XmNleftAttachment,      XmATTACH_WIDGET,
245                 XmNleftWidget,          tb->name_label,
246                 XmNrightAttachment,     XmATTACH_POSITION,
247                 XmNrightPosition,       3,
248                 XmNrightOffset,         10,
249                 XmNcolumns,             30,
250                 NULL);
251
252         separator = XtVaCreateWidget("separator",
253                 xmSeparatorGadgetClass,
254                 tb->form,
255                 XmNleftAttachment,      XmATTACH_FORM,
256                 XmNrightAttachment,     XmATTACH_FORM,
257                 XmNtopAttachment,       XmATTACH_WIDGET,
258                 XmNtopWidget,           tb->name_text,
259                 XmNtopOffset,           5,
260                 NULL);
261
262         button_form = XtVaCreateWidget("form",
263                 xmFormWidgetClass,      
264                 tb->form,
265                 XmNautoUnmanage,        False,
266                 XmNleftAttachment,      XmATTACH_FORM,
267                 XmNleftOffset,          5,
268                 XmNrightAttachment,     XmATTACH_FORM,
269                 XmNrightOffset,         5,
270                 XmNtopAttachment,       XmATTACH_WIDGET,
271                 XmNtopWidget,           separator,
272                 XmNhorizontalSpacing,   4,
273                 XmNfractionBase,        3,
274                 NULL);
275  
276         label_str = XmStringCreateLocalized(
277                                 catgets(c->DT_catd, 1, 562, "Show"));
278         tb->show_button = XtVaCreateWidget("show_button",
279                 xmPushButtonWidgetClass, 
280                 button_form,
281                 XmNlabelString, label_str,
282                 XmNtopAttachment, XmATTACH_WIDGET,
283                 XmNtopWidget, separator,
284                 XmNleftAttachment, XmATTACH_POSITION,
285                 XmNleftPosition, 0,
286                 XmNrightAttachment, XmATTACH_POSITION,
287                 XmNrightPosition, 1,
288                 XmNnavigationType, XmTAB_GROUP,
289                 NULL);
290         XmStringFree(label_str);
291
292         label_str = XmStringCreateLocalized(
293                                 catgets(c->DT_catd, 1, 680, "Close"));
294         tb->cancel_button = XtVaCreateWidget("cancelButton",
295                 xmPushButtonWidgetClass, 
296                 button_form,
297                 XmNlabelString, label_str,
298                 XmNtopAttachment, XmATTACH_WIDGET,
299                 XmNtopWidget, separator,
300                 XmNleftAttachment, XmATTACH_POSITION,
301                 XmNleftPosition, 1,
302                 XmNrightAttachment, XmATTACH_POSITION,
303                 XmNrightPosition, 2,
304                 XmNuserData, c,
305                 NULL);
306         XmStringFree(label_str);
307         XtAddCallback(tb->cancel_button, 
308                         XmNactivateCallback, tb_cancel_cb, NULL);
309
310         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 77, "Help"));
311         tb->help_button = XtVaCreateWidget("helpButton",
312                 xmPushButtonWidgetClass, button_form,
313                 XmNlabelString, label_str,
314                 XmNtopAttachment, XmATTACH_WIDGET,
315                 XmNtopWidget, separator,
316                 XmNleftAttachment, XmATTACH_POSITION,
317                 XmNleftPosition, 2,
318                 XmNrightAttachment, XmATTACH_POSITION,
319                 XmNrightPosition, 3,
320                 NULL);
321         XmStringFree(label_str);
322         XtAddCallback(tb->help_button, XmNactivateCallback,
323                 (XtCallbackProc)help_cb, SHOW_OTHER_CAL_HELP_BUTTON);
324         XtAddCallback(tb->form, XmNhelpCallback,
325                 (XtCallbackProc)help_cb, (XtPointer) SHOW_OTHER_CAL_HELP_BUTTON);
326
327 #ifdef FNS_SUNDEX_DEMO
328         label_str = XmStringCreateLocalized(catgets(c->DT_catd, 1, 648,
329                                             "SunDex"));
330         tb->show_button = XtVaCreateWidget("sundex_button",
331                 xmPushButtonWidgetClass, tb->form,
332                 XmNlabelString,         label_str,
333                 XmNtopAttachment, XmATTACH_FORM,
334                 XmNtopOffset, 9,
335                 XmNleftAttachment, XmATTACH_WIDGET,
336                 XmNleftWidget,  tb->name_text,
337                 XmNleftOffset, 5,
338                 NULL);
339         XmStringFree(label_str);
340         XtAddCallback(tb->show_button, XmNactivateCallback,
341                 tempbr_sundex_cb, tb);
342 #endif
343
344         tb->show_message = XtVaCreateWidget("show_message",
345                 xmLabelGadgetClass, tb->form,
346                 XmNalignment, XmALIGNMENT_BEGINNING,
347                 XmNtopAttachment, XmATTACH_WIDGET,
348                 XmNtopWidget, tb->cancel_button,
349                 XmNleftAttachment, XmATTACH_FORM,
350                 XmNrightAttachment, XmATTACH_FORM,
351                 XmNbottomAttachment, XmATTACH_FORM,
352                 NULL);
353
354         set_message(tb->show_message, "");
355
356         XtAddCallback(tb->show_button, XmNactivateCallback,
357                         tempbr_show_cb, tb);
358         ds_position_popup(c->frame, tb->frame, DS_POPUP_LOR);
359
360         /* set default button */
361         XtVaSetValues(button_form, 
362                         XmNdefaultButton,       tb->show_button, 
363                         XmNcancelButton,        tb->show_button, 
364                         NULL);
365         XtVaSetValues(tb->form, 
366                         XmNdefaultButton,       tb->show_button, 
367                         XmNcancelButton,        tb->show_button, 
368                         NULL);
369
370         XmProcessTraversal(tb->name_text, XmTRAVERSE_CURRENT);
371         XtVaSetValues(tb->form, XmNinitialFocus, tb->name_text, NULL);
372
373         ManageChildren(button_form);
374         ManageChildren(tb->form);
375         XtManageChild(tb->form);
376         XtVaSetValues(tb->frame, XmNmappedWhenManaged, True, NULL);
377         XtRealizeWidget(tb->frame);
378
379         XtPopup(tb->frame, XtGrabNone);
380
381         return(caddr_t)tb;
382 }
383
384 caddr_t
385 make_tempbr(Calendar *c)
386 {
387         caddr_t tb;
388
389         tb = make_std_tempbr(c);
390         ((Tempbr *)tb)->cal = c;
391
392         return tb;
393 }
394
395 static void
396 tb_cancel_cb(
397         Widget  widget,
398         XtPointer client_data,
399         XmPushButtonCallbackStruct *cbs)
400 {
401         Calendar *c;
402         Tempbr      *tb;
403
404         XtVaGetValues(widget, XmNuserData, &c, NULL);
405         tb = (Tempbr *)c->tempbr;
406
407         XmTextSetString(tb->name_text, "");
408         XtPopdown(tb->frame);
409
410         return;
411 }
412
413 static void
414 tb_close_cb(Widget w, XtPointer data, XtPointer cbs)
415 {
416         Tempbr  *tb = (Tempbr *)data;
417
418         XtPopdown(tb->frame);
419
420         return;
421 }