2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $TOG: misc.c /main/14 1999/07/01 09:51:24 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company
26 * (c) Copyright 1993, 1994 International Business Machines Corp.
27 * (c) Copyright 1993, 1994 Novell, Inc.
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
31 #include <EUSCompat.h>
42 #include <sys/param.h>
43 #include <Xm/PushBG.h>
44 #include <Xm/DialogS.h>
46 #include <Xm/LabelG.h>
47 #include <Xm/SeparatoG.h>
48 #include <Xm/Protocols.h>
49 #include <Xm/AtomMgr.h>
50 #include <Xm/RowColumn.h>
52 #include <Xm/MwmUtil.h>
53 #include <Xm/ComboBox.h>
57 #include "datefield.h"
62 #include "contract_xbm"
65 #include <X11/bitmaps/xm_error>
66 #include <X11/bitmaps/xm_information>
67 #include <X11/bitmaps/xm_question>
68 #include <X11/bitmaps/xm_warning>
70 /*******************************************************************************
74 *******************************************************************************/
76 ** Widget building functions
79 create_repeat_menu(Widget parent, XtCallbackProc cb_func, XtPointer data) {
85 extern Calendar *calendar;
88 XtSetArg(args[ac], XmNcomboBoxType, XmDROP_DOWN_LIST); ++ac;
89 XtSetArg(args[ac], XmNpositionMode, XmONE_BASED); ++ac;
90 cb = XmCreateComboBox(parent, "repeat_cb", args, ac);
92 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 200, "One Time"));
93 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
96 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 853, "Daily"));
97 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
100 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 854, "Weekly"));
101 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
104 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 855, "Every Two Weeks"));
105 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
108 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 856, "Monthly By Date"));
109 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
112 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 857, "Monthly By Weekday"));
113 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
116 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 858, "Yearly"));
117 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
120 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 859, "Monday Thru Friday"));
121 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
124 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 860, "Mon, Wed, Fri"));
125 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
128 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 861, "Tuesday, Thursday"));
129 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
132 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 862, "Repeat Every..."));
133 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
137 XtAddCallback(cb, XmNselectionCallback, cb_func, data);
143 create_for_menu(Widget parent) {
146 Widget cb, list, text;
149 extern Calendar *calendar;
152 XtSetArg(args[ac], XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX); ++ac;
153 XtSetArg(args[ac], XmNpositionMode, XmONE_BASED); ++ac;
154 cb = XmCreateComboBox(parent, "for_cb", args, ac);
157 * This is a hack until the sizing bug in the combo box is fixed.
158 * To get it to size correctly, you must managed it and then reset
161 XtVaSetValues(cb, XmNwidth, 80, NULL);
163 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 863, "2"));
164 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
167 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 864, "3"));
168 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
171 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 865, "4"));
172 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
175 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 866, "5"));
176 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
179 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 867, "6"));
180 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
183 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 868, "7"));
184 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
187 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 869, "8"));
188 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
191 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 870, "9"));
192 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
195 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 871, "10"));
196 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
199 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 872, "11"));
200 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
203 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 873, "12"));
204 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
207 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 874, "13"));
208 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
211 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 875, "14"));
212 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
215 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 876, "forever"));
216 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
219 XtVaGetValues(cb, XmNlist, &list, XmNtextField, &text, NULL);
220 XtVaSetValues(list, XmNsensitive, False, NULL);
221 XtVaSetValues(text, XmNsensitive, False, NULL);
227 create_privacy_menu(Widget parent) {
232 extern Calendar *calendar;
235 XtSetArg(args[ac], XmNcomboBoxType, XmDROP_DOWN_LIST); ++ac;
236 XtSetArg(args[ac], XmNvisibleItemCount, 3); ++ac;
237 XtSetArg(args[ac], XmNpositionMode, XmONE_BASED); ++ac;
238 cb = XmCreateComboBox(parent, "privacy_cb", args, ac);
240 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 721, "Others See Time And Text"));
241 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
244 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 722, "Others See Time Only"));
245 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
248 xmstr = XmStringCreateLocalized(catgets(calendar->DT_catd, 1, 723, "Others See Nothing"));
249 XmComboBoxAddItem((Widget)cb, xmstr, 0, False);
257 set_time_submenu(Widget parent,
260 XtCallbackProc callback,
261 XtPointer client_data,
264 Widget **widget_list,
268 int i, j, allocation_counter = 0;
269 char buf[4], buf2[10];
270 Widget menu, menuitem;
271 DisplayType dt = get_int_prop(p, CP_DEFAULTDISP);
272 int beg = get_int_prop(p, CP_DAYBEGIN);
273 int end = get_int_prop(p, CP_DAYEND);
274 Calendar *c = calendar;
276 XtVaGetValues(option_menu, XmNsubMenuId, &menu, NULL);
278 for (i = 0; i < *widget_count; i++)
279 XtDestroyWidget((*widget_list)[i]);
285 *widget_count = ((end - beg) * 4);
293 *widget_list = calloc(sizeof(Widget), *widget_count);
296 ** Loop through and create the time menu using the starting and
297 ** ending times from the properties.
299 for (i = beg; i < end; i++) {
302 sprintf(buf, "%2d:", i-12);
305 cm_strcpy(buf, "12:");
307 sprintf(buf, "%2d:", i);
310 sprintf(buf, "%02d", i);
312 for (j = 0; j <= 45; j += 15) {
313 sprintf(buf2, "%s%02d", buf, j);
314 (*widget_list)[allocation_counter++] =
315 menuitem = XtVaCreateWidget(buf2,
316 xmPushButtonGadgetClass, menu,
317 XmNuserData, (i * hrsec) + (j * minsec),
320 XtAddCallback(menuitem, XmNactivateCallback,
321 callback, client_data);
326 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 353,
328 (*widget_list)[allocation_counter++] =
329 menuitem = XtVaCreateWidget("noTime",
330 xmPushButtonGadgetClass, menu,
331 XmNlabelString, xmstr,
332 XmNuserData, NO_TIME,
336 XtAddCallback(menuitem, XmNactivateCallback,
337 callback, client_data);
341 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 354,
343 (*widget_list)[allocation_counter++] =
344 menuitem = XtVaCreateWidget("allDay",
345 xmPushButtonGadgetClass, menu,
346 XmNlabelString, xmstr,
347 XmNuserData, ALL_DAY,
351 XtAddCallback(menuitem, XmNactivateCallback,
352 callback, client_data);
355 XtManageChildren(*widget_list, allocation_counter);
359 create_start_stop_time_menu(Widget parent,
361 XtCallbackProc callback,
362 XtPointer client_data,
366 Widget **widget_list,
371 Widget menu, option_m;
372 int beg = get_int_prop(p, CP_DAYBEGIN);
373 int end = get_int_prop(p, CP_DAYEND);
375 menu = XmCreatePulldownMenu(parent, "pulldown", NULL, 0);
377 XmNpacking, XmPACK_COLUMN,
378 XmNorientation, XmHORIZONTAL,
379 XmNnumColumns, (end - beg) + 1,
382 XtSetArg(args[ac], XmNsubMenuId, menu); ++ac;
383 XtSetArg(args[ac], XmNlabelString, label); ++ac;
384 option_m = XmCreateOptionMenu(parent, "option_m", args, ac);
386 set_time_submenu(parent, option_m, p, callback,
387 client_data, nt, ad, widget_list, widget_count);
393 create_time_scope_menu(Widget parent,
395 XtCallbackProc callback,
396 XtPointer client_data) {
399 Widget menu, option_m, menuitems[3];
401 Calendar *c = calendar;
403 menu = XmCreatePulldownMenu(parent, "pulldown", NULL, 0);
405 XmNpacking, XmPACK_COLUMN,
406 XmNorientation, XmHORIZONTAL,
407 XmNnumColumns, TIME_DAYS + 1,
411 XtSetArg(args[ac], XmNsubMenuId, menu); ++ac;
412 XtSetArg(args[ac], XmNlabelString, label); ++ac;
413 option_m = XmCreateOptionMenu(parent, "option_m", args, ac);
416 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 877, "Mins"));
417 menuitems[0] = XtVaCreateWidget("timescope0",
418 xmPushButtonGadgetClass, menu,
419 XmNlabelString, xmstr,
423 XtAddCallback(menuitems[0], XmNactivateCallback,
424 callback, client_data);
427 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 878, "Hrs"));
428 menuitems[1] = XtVaCreateWidget("timescope1",
429 xmPushButtonGadgetClass, menu,
430 XmNlabelString, xmstr,
434 XtAddCallback(menuitems[1], XmNactivateCallback,
435 callback, client_data);
438 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 879, "Days"));
439 menuitems[2] = XtVaCreateWidget("timescope2",
440 xmPushButtonGadgetClass, menu,
441 XmNlabelString, xmstr,
445 XtAddCallback(menuitems[2], XmNactivateCallback,
446 callback, client_data);
449 XtVaSetValues(XmOptionButtonGadget(option_m), XmNsensitive, False,
452 XtManageChildren((WidgetList)menuitems, 3);
458 create_repeat_scope_menu(Widget parent, XmString label,
459 XtCallbackProc callback, XtPointer client_data) {
462 char buf[MAXNAMELEN];
463 Widget menu, option_m, menuitems[3];
465 Repeat_scope_menu_op i;
466 Calendar *c = calendar;
468 menu = XmCreatePulldownMenu(parent, "pulldown", NULL, 0);
470 XmNpacking, XmPACK_COLUMN,
471 XmNorientation, XmHORIZONTAL,
472 XmNnumColumns, REPEAT_MONTHS + 1,
476 XtSetArg(args[ac], XmNsubMenuId, menu); ++ac;
477 XtSetArg(args[ac], XmNlabelString, label); ++ac;
478 option_m = XmCreateOptionMenu(parent, "option_m", args, ac);
481 sprintf(buf, "repeatscope%d", REPEAT_DAYS);
482 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 816, "Days"));;
483 menuitems[0] = XtVaCreateWidget(buf,
484 xmPushButtonGadgetClass, menu,
485 XmNlabelString, xmstr,
486 XmNuserData, REPEAT_DAYS,
489 XtAddCallback(menuitems[0], XmNactivateCallback,
490 callback, client_data);
493 sprintf(buf, "repeatscope%d", REPEAT_WEEKS);
494 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 817, "Weeks"));;
495 menuitems[1] = XtVaCreateWidget(buf,
496 xmPushButtonGadgetClass, menu,
497 XmNlabelString, xmstr,
498 XmNuserData, REPEAT_WEEKS,
501 XtAddCallback(menuitems[1], XmNactivateCallback,
502 callback, client_data);
505 sprintf(buf, "repeatscope%d", REPEAT_MONTHS);
506 xmstr = XmStringCreateLocalized(catgets(c->DT_catd, 1, 818, "Months"));;
507 menuitems[2] = XtVaCreateWidget(buf,
508 xmPushButtonGadgetClass, menu,
509 XmNlabelString, xmstr,
510 XmNuserData, REPEAT_MONTHS,
513 XtAddCallback(menuitems[2], XmNactivateCallback,
514 callback, client_data);
517 XtManageChildren((WidgetList)menuitems, 3);
523 fill_pixmap(XImage *xi, int w, int h, unsigned char *data)
527 xi->data = (char *) data;
529 xi->format = XYBitmap;
530 xi->byte_order = MSBFirst;
532 xi->bitmap_bit_order = LSBFirst;
535 xi->bytes_per_line = (int)((w - 1) / 8) + 1;
540 create_all_pixmaps(Props_pu *p, Widget w)
544 static XImage ic, ei, ci, li, ri, eri, ii, pui, qi, wi;
547 XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg,
551 expand_xbm_width, expand_xbm_height, expand_xbm_bits);
552 if (XmInstallImage(&ei, "x_pixmap"))
553 p->expand_pixmap = XmGetPixmap(s, "x_pixmap", fg, bg);
555 fill_pixmap(&ci, contract_xbm_width, contract_xbm_height,
557 if (XmInstallImage(&ci, "c_pixmap"))
558 p->contract_pixmap = XmGetPixmap(s, "c_pixmap", fg, bg);
561 postup_xbm_width, postup_xbm_height, postup_xbm_bits);
562 if (XmInstallImage(&pui, "postup_pixmap"))
563 p->postup_pixmap = XmGetPixmap(s, "postup_pixmap", fg, bg);
565 fill_pixmap(&eri, xm_error_width, xm_error_height,
567 if (XmInstallImage(&eri, "err_pixmap"))
568 p->xm_error_pixmap = XmGetPixmap(s, "err_pixmap", fg, bg);
570 fill_pixmap(&ii, xm_information_width, xm_information_height,
571 xm_information_bits);
572 if (XmInstallImage(&ii, "info_pixmap"))
573 p->xm_info_pixmap = XmGetPixmap(s, "info_pixmap", fg, bg);
575 fill_pixmap(&qi, xm_question_width, xm_question_height,
577 if (XmInstallImage(&qi, "q_pixmap"))
578 p->xm_question_pixmap = XmGetPixmap(s, "q_pixmap", fg, bg);
580 fill_pixmap(&wi, xm_warning_width, xm_warning_height,
582 if (XmInstallImage(&wi, "w_pixmap"))
583 p->xm_warning_pixmap = XmGetPixmap(s, "w_pixmap", fg, bg);
585 if ((p->drag_icon_xbm = XmGetPixmap(s, "DtCMdnd.m.pm", fg, bg)) ==
586 XmUNSPECIFIED_PIXMAP) {
587 p->drag_icon_xbm = 0;
593 ** I18N related routine
594 ** Parameter: A pointer to a multibyte string.
595 ** Return Value: The number of characters in the multibyte string.
598 cm_mbstrlen(char *s) {
599 int num_byte = 0, num_char = 0;
602 if ( (num_byte = mblen(s, MB_LEN_MAX)) <= 0 )
611 ** I18N related routine
612 ** Parameter: A pointer to a multibyte string or a pointer to NULL.
613 ** Return Value: Returns a pointer to the next multibyte character.
614 ** Usage: If the actual argument is non NULL then a pointer to the first
615 ** multibyte character is returned. If the actual argument is NULL
616 ** then a pointer to the next multibyte character is returned. The
617 ** parameter scheme is very much like strtok();
618 ** CAUTION: If the calling function uses the return value then it should
619 ** make a copy. The return value is a static buffer that may
620 ** be overwritten or freed on subsequent calls to this routine.
623 cm_mbchar(char *str) {
625 static char *string_head;
630 if ( string != NULL ) {
635 string = (char *)cm_strdup(str);
636 string_head = string;
642 if ( string == '\0' ) {
646 num_byte = mblen(string, MB_LEN_MAX);
647 buf = (char *)malloc(num_byte+1);
648 strncpy(buf, string, num_byte);
649 buf[num_byte] = '\0';
657 ** Callback for generic dialogs to set the answer so the program can continue
658 ** in a normal flow ...
660 ** This is really frickin brain dead.
662 ** Client data will be set to the button id stored as user data in the widget.
665 response(Widget w, XtPointer client_data, XtPointer cbs) {
666 XtPointer userData = (XtPointer)0;
667 int *answerP = (int *) (intptr_t)client_data;
669 XtVaGetValues(w, XmNuserData, &userData, NULL);
670 *answerP = (intptr_t)userData;
674 ** Generic dialog box creator
677 dialog_popup(Widget parent, ...) {
678 int button_id, t_cnt = 0, b_cnt = 0;
679 char *text_str = NULL, *ptr, buf[MAXNAMELEN], *help_str;
682 Widget frame, form, image, sep, text, last_text, button;
683 Display *dpy = XtDisplayOfObject(parent);
686 extern XtAppContext app;
687 Calendar *c = calendar;
691 frame = XtVaCreatePopupShell("generic_dialog",
692 xmDialogShellWidgetClass, parent,
693 XmNallowShellResize, True,
694 XmNmwmFunctions, MWM_FUNC_MOVE | MWM_FUNC_CLOSE,
697 form = XtVaCreateWidget("form",
698 xmFormWidgetClass, frame,
699 XmNhorizontalSpacing, 5,
700 XmNverticalSpacing, 5,
702 XmNfractionBase, 100,
703 XmNautoUnmanage, False,
704 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
707 image = XtVaCreateWidget("image",
708 xmLabelGadgetClass, form,
709 XmNlabelType, XmPIXMAP,
710 XmNtopAttachment, XmATTACH_FORM,
711 XmNleftAttachment, XmATTACH_FORM,
714 sep = XtVaCreateWidget("sep",
715 xmSeparatorGadgetClass, form,
716 XmNtopAttachment, XmATTACH_WIDGET,
717 XmNleftAttachment, XmATTACH_FORM,
718 XmNrightAttachment, XmATTACH_FORM,
721 va_start(pvar, parent);
722 op = va_arg(pvar, Dialog_create_op);
726 ptr = va_arg(pvar, char *);
727 XtVaSetValues(frame, XtNtitle, ptr,
731 ptr = va_arg(pvar, char *);
734 text_str = cm_strdup(ptr);
737 case BUTTON_INSENSITIVE:
738 button_id = va_arg(pvar, int);
739 ptr = va_arg(pvar, char *);
740 xmstr = XmStringCreateLocalized(ptr);
741 sprintf(buf, "button%d", b_cnt);
742 button = XtVaCreateWidget(buf,
743 xmPushButtonGadgetClass, form,
744 XmNlabelString, xmstr,
745 XmNleftAttachment, XmATTACH_POSITION,
746 XmNleftPosition, b_cnt * 2,
748 XmNrightAttachment, XmATTACH_POSITION,
749 XmNrightPosition, (b_cnt+1) * 2,
751 XmNuserData, button_id,
752 XmNtopAttachment, XmATTACH_WIDGET,
755 XmNbottomAttachment, XmATTACH_FORM,
759 if (op == BUTTON_INSENSITIVE)
760 XtSetSensitive(button, False);
761 XtAddCallback(button, XmNactivateCallback,
762 response, (XtPointer)&answer);
766 help_str = cm_strdup(va_arg(pvar, char *));
767 xmstr = XmStringCreateLocalized(
768 catgets(c->DT_catd, 1, 77, "Help"));
769 button = XtVaCreateWidget("help_button",
770 xmPushButtonGadgetClass, form,
771 XmNlabelString, xmstr,
772 XmNleftAttachment, XmATTACH_POSITION,
773 XmNleftPosition, b_cnt * 2,
774 XmNrightAttachment, XmATTACH_POSITION,
775 XmNrightPosition, (b_cnt+1) * 2,
777 XmNtopAttachment, XmATTACH_WIDGET,
780 XmNbottomAttachment, XmATTACH_FORM,
784 XtAddCallback(button, XmNactivateCallback,
789 px = va_arg(pvar, Pixmap);
790 XtVaSetValues(image, XmNlabelPixmap, px,
796 op = va_arg(pvar, Dialog_create_op);
799 XtVaSetValues(form, XmNfractionBase, b_cnt * 2,
802 ptr = strtok(text_str, "\n");
805 sprintf(buf, "text_label%d", t_cnt);
806 xmstr = XmStringCreateLocalized(ptr);
807 text = XtVaCreateWidget(buf,
808 xmLabelGadgetClass, form,
809 XmNalignment, XmALIGNMENT_BEGINNING,
810 XmNlabelString, xmstr,
811 XmNleftAttachment, XmATTACH_WIDGET,
812 XmNleftWidget, image,
813 XmNrightAttachment, XmATTACH_FORM,
818 XtVaSetValues(text, XmNtopAttachment, XmATTACH_FORM,
821 XtVaSetValues(text, XmNtopAttachment, XmATTACH_WIDGET,
822 XmNtopWidget, last_text,
826 ptr = strtok(NULL, "\n");
831 XmNtopWidget, last_text,
834 ManageChildren(form);
840 XtAppProcessEvent(app, XtIMXEvent | XtIMAll);
841 XtUnmanageChild(form);
842 XtDestroyWidget(frame);
848 ** This routine returns the true boundaries of a particular view, i.e,
849 ** 12 midnight - 11:59:59 pm. It does not return the boundaries for doing
850 ** lookups, i.e., 11:59:59 pm - 12 pm (lookup ranges must encompass true range)
853 get_range(Glance glance, time_t date, time_t *start, time_t *stop) {
858 *start = first_dom(date);
859 *stop = last_dom(date);
862 *start = first_dow(date);
863 *stop = last_dow(date);
866 *start = lowerbound(date);
867 *stop = upperbound(date);
871 *start = lowerbound(jan1(date));
872 *stop = lowerbound(nextjan1(date));
878 ** Standard set of error messages for the editors (errors from data entry
879 ** validation and from the backend).
882 editor_err_msg(Widget frame, char *name, Validate_op op, Pixmap p) {
883 Calendar *c = calendar;
884 char buf[MAXNAMELEN],
885 buf2[MAXNAMELEN * 2],
887 int help_button = True;
890 case COULD_NOT_OPEN_FILE:
891 sprintf(buf, "%s", catgets(c->DT_catd, 1, 355, "Unable to open callog file.\nOperation was cancelled. Calendar"));
892 sprintf(error_buf, CMSD_ERROR_HELP);
895 sprintf(buf, "%s", catgets(c->DT_catd, 1, 356, "Per user request, Operation was cancelled.\nCalendar"));
899 sprintf(buf, "%s", catgets(c->DT_catd, 1, 357, "Invalid value in DATE field.\nOperation was cancelled. Calendar"));
900 sprintf(error_buf, DATE_ERROR_HELP);
903 sprintf(buf, "%s", catgets(c->DT_catd, 1, 358, "Invalid value in START field.\nOperation was cancelled. Calendar"));
904 sprintf(error_buf, START_ERROR_HELP);
906 case INVALID_TIME_DUE:
907 sprintf(buf, "%s", catgets(c->DT_catd, 1, 1011, "Invalid value in the \"Time Due\" field.\nOperation was cancelled. Calendar"));
908 sprintf(error_buf, START_ERROR_HELP);
911 sprintf(buf, "%s", catgets(c->DT_catd, 1, 359, "Invalid value in END field.\nOperation was cancelled. Calendar"));
912 sprintf(error_buf, STOP_ERROR_HELP);
915 sprintf(buf, "%s", catgets(c->DT_catd, 1, 360, "You must provide a DATE value.\nOperation was cancelled. Calendar"));
916 sprintf(error_buf, MISSING_FIELD_ERROR_HELP);
919 sprintf(buf, "%s", catgets(c->DT_catd, 1, 361, "You must provide a START value.\nOperation was cancelled. Calendar"));
920 sprintf(error_buf, MISSING_FIELD_ERROR_HELP);
923 sprintf(buf, "%s", catgets(c->DT_catd, 1, 362, "You must provide a WHAT value.\nOperation was cancelled. Calendar"));
924 sprintf(error_buf, MISSING_FIELD_ERROR_HELP);
926 case REPEAT_FOR_MISMATCH:
927 sprintf(buf, "%s", catgets(c->DT_catd, 1, 363, "Invalid or mismatched REPEAT and FOR values.\nOperation was cancelled. Calendar"));
928 sprintf(error_buf, REPEAT_FOR_ERROR_HELP);
930 case INVALID_NOTIME_APPT:
931 sprintf(buf, "%s", catgets(c->DT_catd, 1, 724, "No Time appointments must have a WHAT value specified.\nOperation was cancelled. Calendar"));
932 sprintf(error_buf, NO_TIME_ERROR_HELP);
935 sprintf(buf, "%s", catgets(c->DT_catd, 1, 1104, "Invalid value in TIME DUE field.\nOperation was cancelled. Calendar"));
936 sprintf(error_buf, START_ERROR_HELP);
939 sprintf(buf, "%s", catgets(c->DT_catd, 1, 1105, "You must provide a TIME DUE value.\nOperation was cancelled. Calendar"));
940 sprintf(error_buf, MISSING_FIELD_ERROR_HELP);
947 sprintf(buf2, "%s %s", buf, name);
949 char *title = XtNewString(catgets(c->DT_catd, 1, 914,
950 "Calendar : Error - Editor"));
951 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95,
953 dialog_popup(frame, DIALOG_TITLE, title,
955 BUTTON_IDENT, 1, ident1,
956 BUTTON_HELP, error_buf,
963 char *title = XtNewString(catgets(c->DT_catd, 1, 914,
964 "Calendar : Error - Editor"));
965 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95,
967 dialog_popup(frame, DIALOG_TITLE, title,
969 BUTTON_IDENT, 1, ident1,
981 CSA_return_code stat,
984 char buf[MAXNAMELEN],
985 buf2[MAXNAMELEN * 2],
987 Calendar *c = calendar;
988 int help_button = True;
990 sprintf(error_buf, BACK_END_ERROR_HELP);
993 case CSA_E_CALENDAR_EXISTS:
994 sprintf(buf, "%s", catgets(c->DT_catd, 1, 367, "Calendar already exists.\nOperation was cancelled. Calendar"));
997 case CSA_E_CALENDAR_NOT_EXIST:
998 sprintf(buf, "%s", catgets(c->DT_catd, 1, 368, "Calendar does not exist.\nOperation was cancelled. Calendar"));
1001 case CSA_X_DT_E_ENTRY_NOT_FOUND:
1002 sprintf(buf, "%s", catgets(c->DT_catd, 1, 725, "Calendar Entry does not exist.\nOperation was cancelled. Calendar"));
1004 case CSA_E_INVALID_ENTRY_HANDLE:
1005 sprintf(buf, "%s", catgets(c->DT_catd, 1, 881, "Internal Error #1: Invalid calendar/entry handle.\nOperation was cancelled. Calendar"));
1007 case CSA_E_INVALID_SESSION_HANDLE:
1008 sprintf(buf, "%s", catgets(c->DT_catd, 1, 882, "Internal Error #2: Invalid session handle.\nOperation was cancelled. Calendar"));
1010 case CSA_E_NO_AUTHORITY:
1011 sprintf(buf, "%s", catgets(c->DT_catd, 1, 370, "Authorization error. Permission denied.\nOperation was cancelled. Calendar"));
1012 help_button = False;
1014 case CSA_E_INVALID_PARAMETER:
1015 sprintf(buf, "%s", catgets(c->DT_catd, 1, 883, "Internal Error #3: Invalid data value.\nOperation was cancelled. Calendar"));
1017 case CSA_E_READONLY:
1018 sprintf(buf, "%s", catgets(c->DT_catd, 1, 884, "Internal Error #4: Value specified for a read-only attribute.\nOperation was cancelled. Calendar"));
1020 case CSA_E_INVALID_ATTRIBUTE_VALUE:
1021 sprintf(buf, "%s", catgets(c->DT_catd, 1, 885, "Internal Error #5: Incorrect data type specified for an attribute value.\nOperation was cancelled. Calendar"));
1023 case CSA_E_UNSUPPORTED_ATTRIBUTE:
1024 sprintf(buf, "%s", catgets(c->DT_catd, 1, 886, "Internal Error #6: Specified attribute is not supported on this calendar version.\nOperation was cancelled. Calendar"));
1026 case CSA_E_NOT_SUPPORTED:
1027 sprintf(buf, "%s", catgets(c->DT_catd, 1, 887, "Internal Error #7: Specified function is not supported on this calendar version.\nOperation was cancelled. Calendar"));
1029 case CSA_E_INVALID_ENUM:
1030 sprintf(buf, "%s", catgets(c->DT_catd, 1, 888, "Internal Error #8: Invalid operator specified.\nOperation was cancelled. Calendar"));
1032 case CSA_E_INSUFFICIENT_MEMORY:
1033 sprintf(buf, "%s", catgets(c->DT_catd, 1, 378, "Memory allocation error - not enough memory.\nOperation was cancelled. Calendar"));
1034 sprintf(error_buf, MEMORY_ALLOC_ERROR_HELP);
1036 case CSA_E_DISK_FULL:
1037 sprintf(buf, "%s", catgets(c->DT_catd, 1, 907, "No space left for calendar file.\nOperation was cancelled. Calendar"));
1039 case CSA_E_SERVICE_UNAVAILABLE:
1040 sprintf(buf, "%s", catgets(c->DT_catd, 1, 921, "Couldn't access calendar: "));
1042 case CSA_X_DT_E_INVALID_SERVER_LOCATION:
1043 sprintf(buf, "%s", catgets(c->DT_catd, 1, 641, "Server failed to get network address\nfor the specified location: invalid hostname."));
1045 case CSA_X_DT_E_SERVICE_NOT_REGISTERED:
1046 sprintf(buf, "%s", catgets(c->DT_catd, 1, 642, "rpc.cmsd daemon is not registered.\nPlease verify rpc.cmsd is installed correctly on your system."));
1047 sprintf(error_buf, CMSD_ERROR_HELP);
1049 case CSA_X_DT_E_SERVER_TIMEOUT:
1050 sprintf(buf, "%s", catgets(c->DT_catd, 1, 727, "Your request timed out\nPlease verify rpc.cmsd is installed correctly on your system."));
1051 sprintf(error_buf, CMSD_ERROR_HELP);
1054 sprintf(buf, "%s", catgets(c->DT_catd, 1, 643, "Couldn't access calendar. Calendar"));
1056 case CSA_E_INVALID_RULE:
1057 sprintf(buf, "%s", catgets(c->DT_catd, 1, 1120, "The event cannot be scheduled in the given time frame.\nThe operation was cancelled."));
1062 sprintf(buf, "%s", catgets(c->DT_catd, 1, 383, "Unknown error.\nOperation was cancelled. Calendar"));
1066 sprintf(buf2, "%s %s", buf, name);
1068 char *title = XtNewString(catgets(c->DT_catd, 1, 890,
1069 "Calendar : Error - Services"));
1070 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95,
1072 dialog_popup(frame, DIALOG_TITLE, title,
1074 BUTTON_IDENT, 1, ident1,
1075 BUTTON_HELP, error_buf,
1082 char *title = XtNewString(catgets(c->DT_catd, 1, 890,
1083 "Calendar : Error - Services"));
1084 char *ident1 = XtNewString(catgets(c->DT_catd, 1, 95,
1086 dialog_popup(frame, DIALOG_TITLE, title,
1088 BUTTON_IDENT, 1, ident1,
1097 * This function is called by the parse_appt_from_file routine if the end_date
1098 * was before the start date for the appointment - this queries the user as to
1102 query_user(void *user_data) {
1103 char buf[MAXNAMELEN];
1104 Calendar *c = (Calendar *)user_data;
1105 Props_pu *p = (Props_pu *)c->properties_pu;
1106 boolean_t ret = B_FALSE;
1112 sprintf(buf, "%s", catgets(c->DT_catd, 1, 386,
1113 "That appointment has an end time earlier than its begin time.\nDo you want to schedule it into the next day?"));
1114 title = XtNewString(catgets(c->DT_catd, 1, 248, "Calendar : Schedule Appointment"));
1115 ident1 = XtNewString(catgets(c->DT_catd, 1, 923, "Cancel"));
1116 ident2 = XtNewString(catgets(c->DT_catd, 1, 389, "Next Day"));
1117 answer = dialog_popup(c->frame,
1118 DIALOG_TITLE, title,
1120 BUTTON_IDENT, 1, ident1,
1121 BUTTON_IDENT, 2, ident2,
1122 DIALOG_IMAGE, p->xm_question_pixmap,
1134 set_message(Widget w, char *msg) {
1138 * If msg is NULL or a null string set it to be a space. This
1139 * prevents label widgets from shrinking (which they do when they
1142 if (msg == NULL || *msg == '\0') {
1147 xmstr = XmStringCreateLocalized(msg);
1148 XtVaSetValues(w, XmNlabelString, xmstr, NULL);
1149 XmStringFree(xmstr);
1156 setup_quit_handler(Widget w, XtCallbackProc cb, caddr_t user_data) {
1159 delete_window = XmInternAtom(XtDisplay(w), "WM_DELETE_WINDOW", False);
1160 XmAddWMProtocolCallback(w, delete_window, cb, user_data);
1164 ds_is_double_click(XEvent *last_event, XEvent *event)
1166 static int time_threshold;
1167 static int dist_threshold;
1168 static short first_time = TRUE;
1169 short ret_value = FALSE;
1171 int delta_x, delta_y;
1173 if (last_event == NULL || event == NULL)
1176 /* first time this is called init the thresholds */
1178 /* Get time threshold in miliseconds */
1179 time_threshold = 800;
1183 /* only deal with the down events */
1184 if (event->type == ButtonRelease)
1187 if ((event->xbutton.type == ButtonPress) &&
1188 (last_event->xbutton.type == ButtonPress)) {
1190 delta_time = event->xbutton.time - last_event->xbutton.time;
1191 delta_time += event->xbutton.time;
1192 delta_time -= last_event->xbutton.time;
1194 /* is the time within bounds? */
1195 if( delta_time <= time_threshold ) {
1197 /* check to see if the distance is ok */
1198 delta_x = (last_event->xbutton.x > event->xbutton.x ?
1199 last_event->xbutton.x - event->xbutton.x :
1200 event->xbutton.x - last_event->xbutton.x);
1202 delta_y = (last_event->xbutton.y > event->xbutton.y ?
1203 last_event->xbutton.y - event->xbutton.y :
1204 event->xbutton.y - last_event->xbutton.y);
1205 if( delta_x <= dist_threshold &&
1206 delta_y <= dist_threshold )
1215 * Select the contents of a text item.
1219 cm_select_text(Widget field, Time time) {
1220 XmTextPosition last;
1222 last = XmTextFieldGetLastPosition(field);
1225 XmTextFieldSetSelection(field, 0, last, time);
1249 w[4] = (Widget) NULL;
1255 for (i = 1; w[i]; i++) {
1261 if ((int)width2 > (int)width1) width1 = width2;
1271 WidgetList children;
1275 XmNchildren, &children,
1278 XtManageChildren(children, n);
1283 * Look for the highest/widest Widget
1286 #include <X11/IntrinsicP.h>
1287 #include <X11/CoreP.h>
1288 #include <Xm/Scale.h>
1289 static Widget _widget[MAX_NUM];
1290 static Dimension _height[MAX_NUM];
1291 static Dimension _width[MAX_NUM];
1294 _i18n_HighestWidget(
1303 Widget _targetW, _highestW;
1305 XtWidgetGeometry geo;
1308 *ret = (Widget)NULL;
1309 *dim = (Dimension)0;
1310 if ( num > MAX_NUM )
1311 return; /* Do nothing */
1313 va_start( ap, dim );
1315 for ( i = 0, _max = (Dimension)0; i < num; i++ ) {
1316 _widget[i] = (Widget)va_arg( ap, Widget );
1318 * Ugly check. XmScale's XmNheight is determined after being mapped.
1319 * So if WidgeClass == xmScaleWidgetClass, use XtQueryGeometry() !!
1320 * ( It's dangerous ! )
1321 * See p_create_display_pane()'s comment :)
1323 * Same for xmRowColumnWidgetClass
1326 if (XmIsManager (_widget[i])) {
1327 _targetW = _widget[i];
1328 XtQueryGeometry( _targetW, NULL, &geo );
1329 _height[i] = geo.height;
1331 _targetW = _widget[i];
1332 XtVaGetValues( _targetW, XmNheight, &(_height[i]), NULL );
1334 if ( _height[i] >= _max ) {
1337 _highestW = _targetW;
1341 *ret = _widget[_high];
1356 Widget _targetW, _widestW;
1358 XtWidgetGeometry geo;
1361 *ret = (Widget)NULL;
1362 *dim = (Dimension)0;
1363 if ( num > MAX_NUM )
1364 return; /* Do nothing */
1366 va_start( ap, dim );
1368 for ( i = 0, _max = (Dimension)0; i < num; i++ ) {
1369 _widget[i] = (Widget)va_arg( ap, Widget );
1371 * Ugly check. XmScale's XmNheight is determined after being mapped.
1372 * So if WidgeClass == xmScaleWidgetClass, use XtQueryGeometry() !!
1373 * ( It's dangerous ! )
1374 * See p_create_display_pane()'s comment :)
1376 * Same for xmRowColumnWidgetClass
1379 if (XmIsManager (_widget[i])) {
1380 _targetW = _widget[i];
1381 XtQueryGeometry( _targetW, NULL, &geo );
1382 _width[i] = geo.width;
1384 _targetW = _widget[i];
1385 XtVaGetValues( _targetW, XmNwidth, &(_width[i]), NULL );
1386 } if ( _width[i] >= _max ) {
1389 _widestW = _targetW;
1393 *ret = _widget[_wide];
1400 * Look for the highest Widget plus, do layout as,
1402 * +-------------------+
1404 * | | +----------------+
1405 * | | +------------+ | |
1406 * | Most Highest | | | | | <--- Center !
1407 * | | +------------+ | |
1408 * | | ^ +----------------+
1410 * +-------------------+ ......|.................|........
1412 * Note : If you are using this function, as for Left/Right Attachment,
1413 * don't use these Widget as XmATTACHMENT_WIDGET's XmNwidget !
1418 _i18n_HighestWidgetAdjust(
1427 Widget _targetW, _highestW;
1429 XtWidgetGeometry geo;
1432 *ret = (Widget)NULL;
1433 *dim = (Dimension)0;
1434 if ( num > MAX_NUM )
1435 return; /* Do nothing */
1437 va_start( ap, dim );
1439 for ( i = 0, _max = (Dimension)0; i < num; i++ ) {
1440 _widget[i] = (Widget)va_arg( ap, Widget );
1442 * Ugly check. XmScale's XmNheight is determined after being mapped.
1443 * So if WidgeClass == xmScaleWidgetClass, use XtQueryGeometry() !!
1444 * ( It's dangerous ! )
1445 * See p_create_display_pane()'s comment :)
1447 * Same for xmRowColumnWidgetClass
1450 if (XmIsManager (_widget[i])) {
1451 _targetW = _widget[i];
1452 XtQueryGeometry( _targetW, NULL, &geo );
1453 _height[i] = geo.height;
1455 _targetW = _widget[i];
1456 XtVaGetValues( _targetW, XmNheight, &(_height[i]), NULL );
1458 if ( _height[i] >= _max ) {
1461 _highestW = _targetW;
1466 * Do layout by XmNbottomAttachment/XmATTACH_OPPTOSITE_WIDGET
1468 for ( i = 0; i < num; i++ ) {
1470 XtSetArg(_args[0], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET );
1471 XtSetArg(_args[1], XmNbottomWidget, _highestW );
1472 XtSetArg(_args[2], XmNbottomOffset, (_max - _height[i]) >> 1 );
1473 XtSetValues( _widget[i], _args, 3 );
1477 *ret = _widget[_high];