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 librararies 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: win.c /main/9 1997/06/18 17:33:01 samborn $ */
27 #include <X11/Xatom.h>
28 #include <X11/Intrinsic.h>
29 #include <X11/cursorfont.h>
31 #include <Xm/Protocols.h>
32 #include <Xm/MwmUtil.h>
35 #include <Xm/RowColumn.h>
36 #include <Xm/LabelG.h>
37 #include <Xm/SeparatoG.h>
38 #include <Xm/DialogS.h>
39 #include <Xm/MessageB.h>
47 Display *Dpy = (Display *) 0;
48 Widget TopW = (Widget) 0;
49 XtAppContext appC = (XtAppContext) 0;
51 static Widget SelW = (Widget) 0;
52 static Widget ModeW = (Widget) 0;
53 static Widget MsgW = (Widget) 0;
54 static Widget HelpW = (Widget) 0;
55 static Widget HostW = (Widget) 0;
56 static Widget HostText = (Widget) 0;
58 static Widget SelRC = (Widget) 0;
59 static Widget HostRC = (Widget) 0;
61 static Widget FocusW = (Widget) 0;
63 static int (*defaultErrorHandler)() = 0;
66 /* application resource */
68 String selectionHelpMsg;
70 String windowLocation;
71 } AppResRec, *AppResP;
73 static AppResRec appres;
75 static XtResource app_resources[] = {
76 { "selectionHelpMsg", "SelectionHelpMsg", XtRString, sizeof(String),
77 XtOffset(AppResP, selectionHelpMsg), XtRString, (XtPointer)NULL },
78 { "modeHelpMsg", "ModeHelpMsg", XtRString, sizeof(String),
79 XtOffset(AppResP, modeHelpMsg), XtRString, (XtPointer)NULL },
80 { "windowLocation", "WindowLocation", XtRString, sizeof(String),
81 XtOffset(AppResP, windowLocation), XtRString, (XtPointer)NULL },
84 static XrmOptionDescRec options[] = {
85 { "-geometry", "*XmDialogShell.geometry", XrmoptionSepArg, (XPointer) NULL },
86 { "-fn", "*fontList", XrmoptionSepArg, (XPointer) NULL },
87 { "-font", "*fontList", XrmoptionSepArg, (XPointer) NULL },
91 static char *fallbacks[] = {
103 #define WIN_FUNC (MWM_FUNC_RESIZE | MWM_FUNC_MOVE)
104 #define WIN_DECR (MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_RESIZEH)
106 #define WIN_FUNC (MWM_FUNC_MOVE)
107 #define WIN_DECR (MWM_DECOR_BORDER)
110 #define MSGWIN_FUNC 0
111 #define MSGWIN_DECR (MWM_DECOR_BORDER)
112 /* #define DIALOG_STYLE XmDIALOG_MODELESS */
113 #define DIALOG_STYLE XmDIALOG_PRIMARY_APPLICATION_MODAL
115 #define MAX_HOSTNAME_LEN 63 /* limitation of ARPA host name */
116 #define TEXT_COLUMNS (MAX_HOSTNAME_LEN / 4)
120 #define Beep() XBell(Dpy, 0); DPR(("Beep!\n"))
122 #define Beep() XBell(Dpy, 0)
126 /* local functions */
128 static int ignoreBadWindow(/* dpy, error */);
129 static void finish_window(/* w, end_window */);
130 static int own_main_atom(/* win */);
131 static int disown_main_atom(/* win */);
132 /* selection window */
133 static void free_ims_list(/* list */);
134 static void clear_selection_var(/* */);
135 static void finish_selection_window(/* end_window */);
136 static void done_cb(/* w, client_data, call_data */);
137 static void select_cb(/* w, client_data, call_data */);
138 static void host_btn_cb(/* w, client_data, call_data */);
139 static void help_cb(/* w, client_data, call_data */);
140 static int create_selection_window(/* */);
141 static int change_host(/* new_host, host_type */);
142 static void add_btn_trans(/* btn */);
143 static void change_ims_list(/* last_ims_name, init_idx */);
144 static void set_host_label(/* host_type, hostname */);
145 static void add_cmd_btn(/* parent_rc, cb_ok, cb_clear, cb_cancel, cb_host, cb_help */);
147 static void start_host_window(/* cur_host */);
148 static void finish_host_window(/* */);
149 static void host_done_cb(/* w, client_data, call_data */);
150 static void host_clear_cb(/* w, client_data, call_data */);
151 static void host_done_action(/* w, ev, args, num_args */);
152 static void create_host_window(/* cur_host */);
154 static void finish_mode_window(/* end_window */);
155 static void mode_done_cb(/* w, client_data, call_data */);
156 static void mode_cb(/* w, client_data, call_data */);
157 static void mode_help_cb(/* w, client_data, call_data */);
158 static int create_mode_window(/* cur_mode */);
160 static void help_ok(/* w, client_data, call_data */);
161 static void create_help(/* */);
163 static void dialog_resp_cb(/* w, client_data, call_data */);
164 static int wait_confirmation(/* w */);
166 static int window_location(/* loc_str */);
167 static void locate_window(/* w */);
169 static void set_cursor(/* w, is_wait */);
171 static void xt_timer_cb(/* client_data, timer_id */);
174 /* ******** window env ******** */
178 if (Dpy) return NoError; /* already done */
180 Dpy = XOpenDisplay(Opt.DisplayName);
182 DPR(("%s: cannot open display \"%s\"\n",
183 ProgramName, XDisplayName(Opt.DisplayName)));
191 if (TopW) return; /* Xt not finished */
202 return winEnv.status != WIN_ST_NONE ? True : False;
205 int init_window_env()
207 enum { XA_DTIMS_ATOM_MAIN, XA_DTIMS_ATOM_STATUS, XA_DTIMS_ATOM_DATA,
209 static char *atom_names[] = {
210 DTIMS_ATOM_MAIN, DTIMS_ATOM_STATUS, DTIMS_ATOM_DATA };
212 Display *dpy = (Display *) 0;
213 Widget topW = (Widget) 0;
214 XtAppContext app = (XtAppContext) 0;
216 Atom atoms[XtNumber(atom_names)];
218 if (winEnv.status != WIN_ST_NONE) return NoError;
220 /* disable XIM on my own XmText* */
221 putenv("XMODIFIERS=@im=_XIMP_None"); /* putenv("XMODIFIERS=@im=none"); */
222 XtSetLanguageProc(NULL, NULL, NULL);
225 ret = open_display();
230 if (!(OpFlag & FLAG_NORESOURCE) && isXsession()) {
231 if (open_display() == NoError) { /* set RESOURCE_MANAGER */
235 if (Dpy) close_display();
237 topW = XtAppInitialize(&app, DTIMS_CLASS,
238 options, XtNumber(options),
239 &Wargc, Wargv, fallbacks, (ArgList) NULL, (Cardinal) 0);
241 dpy = XtDisplay(topW);
242 XtSetMappedWhenManaged(topW, False);
243 XtRealizeWidget(topW);
245 /* set my error handler */
246 defaultErrorHandler = XSetErrorHandler(ignoreBadWindow);
248 XtGetApplicationResources(topW, &appres,
249 app_resources, XtNumber(app_resources),
253 /* handle system Menu's "close" */
254 XmAddWMProtocolCallback(topW,
255 XmInternAtom(dpy, "WM_DELETE_WINDOW", True),
256 (XtCallbackProc)end_window_env, (XtPointer)0);
259 Dpy = dpy; TopW = topW; appC = app; /* @@@ */
261 XInternAtoms(dpy, atom_names, XtNumber(atom_names), False, atoms);
266 winEnv.atom_main = atoms[XA_DTIMS_ATOM_MAIN];
267 winEnv.atom_status = atoms[XA_DTIMS_ATOM_STATUS];
268 winEnv.atom_data = atoms[XA_DTIMS_ATOM_DATA];
269 winEnv.atom_owner = XGetSelectionOwner(dpy, winEnv.atom_main);
270 winEnv.status = WIN_ST_INIT;
272 clear_cmd_property(XtWindow(topW));
274 if (winEnv.atom_main == None)
277 if ((OpMode == MODE_START || OpMode == MODE_LISTNAME)
278 && !(OpFlag & FLAG_REMOTERUN)) {
279 if (own_main_atom(XtWindow(TopW)) != True) {
280 DPR(("another program is running on the display '%s'\n",
281 XDisplayString(Dpy)));
282 return ErrAnotherProg;
289 void end_window_env()
292 disown_main_atom(XtWindow(TopW));
293 XSetErrorHandler(defaultErrorHandler);
295 /* XtUnmapWidget(TopW); */
296 XtDestroyWidget(TopW);
297 XtDestroyApplicationContext(appC);
302 appC = (XtAppContext) 0;
311 int clear_cmd_property(win) /* clear WM_COMMAND property */
315 int clear_ok = False;
318 /* if (!Dpy || !win) return False; */
320 ret = XGetCommand(Dpy, win, &av, &ac);
323 XSetCommand(Dpy, win, 0, NULL);
326 DPR2(("\tWM_COMMAND cleared on %#x\n", win));
332 static int ignoreBadWindow(dpy, error)
336 if (error->error_code == BadWindow || error->error_code == BadDrawable) {
338 } else { /* invoke default error handler */
339 return (*defaultErrorHandler)(dpy, error);
344 static void finish_window(w, end_window)
362 static int own_main_atom(win) /* own DTIMS_ATOM_MAIN */
367 if (winEnv.atom_main == None) return False;
368 /* if (winEnv.atom_owner != None) return False; */
370 owner = XGetSelectionOwner(winEnv.Dpy, winEnv.atom_main);
371 if (owner != None && owner != win) {
372 winEnv.atom_owner = owner;
376 XSetSelectionOwner(winEnv.Dpy, winEnv.atom_main, win, CurrentTime);
377 DPR2(("own_main_atom(%#x): atom=%s[%d]\n",
378 win, DTIMS_ATOM_MAIN, winEnv.atom_main));
379 winEnv.atom_owner = XGetSelectionOwner(winEnv.Dpy, winEnv.atom_main);
381 return winEnv.atom_owner == win ? True : False;
384 static int disown_main_atom(win) /* disown DTIMS_ATOM_MAIN */
387 if (winEnv.atom_main == None) return False;
388 /* if (winEnv.atom_owner == None) return False; */
390 /* give up ownership of DTIMS_ATOM_MAIN */
391 if (XGetSelectionOwner(winEnv.Dpy, winEnv.atom_main) == winEnv.atom_owner)
392 XSetSelectionOwner(winEnv.Dpy, winEnv.atom_main, None, CurrentTime);
393 winEnv.atom_owner = XGetSelectionOwner(winEnv.Dpy, winEnv.atom_main);
399 /* ******** resource_manager ******** */
401 static char *saved_xdefs = NULL; /* should not be freed */
405 if (!Dpy) return False;
406 saved_xdefs = XResourceManagerString(Dpy);
407 return saved_xdefs ? True : False;
410 int merge_RM(res1, res2)
413 char cmdbuf[BUFSIZ*2];
416 if (!Dpy) return False;
420 char *dtres_cmd = DTSESSION_RES_PATH;
421 if (is_executable(dtres_cmd)) {
422 sprintf(cmdbuf, "%s -merge -system -xdefaults ", dtres_cmd);
423 if (res1) { strcat(cmdbuf, " -file "); strcat(cmdbuf, res1); }
424 if (res2) { strcat(cmdbuf, " -file "); strcat(cmdbuf, res2); }
425 strcat(cmdbuf, " >/dev/null 2>&1");
429 sprintf(cmdbuf, "%s %s %s 2>/dev/null | %s -merge -quiet - 2>/dev/null",
430 CAT_PATH, res1, res2, XRDB_PATH);
433 ret = system(cmdbuf);
435 DPR2(("merge_RM(): '%s' & '%s' merged to RESOURCE_MANAGER\n", res1, res2));
436 return ret == 0 ? True : False;
441 int len = saved_xdefs ? strlen(saved_xdefs) : 0;
442 int max = (XMaxRequestSize(Dpy) << 2) - 28;
443 int mode = PropModeReplace;
444 unsigned char *bp = (unsigned char *) saved_xdefs;
445 Window root = RootWindow(Dpy, 0);
447 if (!Dpy /* || len < 0 */) return False;
449 DPR2(("restore_RM(): saved RESOURCE_MANAGER = %d (bytes)\n", len));
451 if (saved_xdefs == NULL) { /* len == 0 */
452 XDeleteProperty(Dpy, root, XA_RESOURCE_MANAGER);
456 sprintf(buf, "%s -quiet -remove 2>/dev/null", XRDB_PATH);
457 DPR(("restore_RM(): '%s'\n", buf));
467 XChangeProperty(Dpy, root,
468 XA_RESOURCE_MANAGER, XA_STRING, 8, mode, bp, len);
469 bp += max; len -= max;
470 mode = PropModeAppend;
473 XChangeProperty(Dpy, root,
474 XA_RESOURCE_MANAGER, XA_STRING, 8, mode, bp, len);
475 if (mode != PropModeReplace)
482 /* ******** selection window ******** */
484 static int CurIdx = -1;
485 static char *CurHost = NULL;
486 static int CurHostType = HOST_UNKNOWN;
487 static ImsList *curList = 0;
488 static bool selection_changed = False;
491 static void free_ims_list(list)
494 /* DPR(("free_ims_list(list=%p)\n", list)); */
495 if (list && list != localList && list != userSel.list) {
501 static void clear_selection_var()
503 free_ims_list(curList);
504 curList = (ImsList *) 0;
506 if (CurHost) FREE(CurHost);
508 CurHostType = HOST_UNKNOWN;
510 selection_changed = False;
513 int start_selection_window()
517 if ((ret = init_window_env()) != NoError)
520 clear_selection_var();
521 curList = userSel.list;
522 /* curHost = NEWSTR(userSel.hostname); */
524 if ((ret = create_selection_window()) != NoError)
527 /* handle system Menu's "close" */
528 XmAddWMProtocolCallback(XtParent(SelW),
529 XmInternAtom(Dpy, "WM_DELETE_WINDOW", True),
530 (XtCallbackProc)done_cb, (XtPointer)CANCEL_BTN);
533 clear_cmd_property(XtWindow(TopW));
538 XtPopup(XtParent(SelW), XtGrabNone);
541 XmProcessTraversal(FocusW, XmTRAVERSE_CURRENT);
543 XtRealizeWidget(TopW);
548 static void finish_selection_window(end_window)
551 DPR(("finish_selection_window(end=%s)\n", end_window ? "True" : "False"));
553 clear_selection_var();
560 disown_main_atom(XtWindow(TopW));
563 XtUnmanageChild(SelW);
564 XtPopdown(XtParent(SelW));
565 XtDestroyWidget(XtParent(SelW));
569 XtUnmanageChild(HostW);
570 XtPopdown(XtParent(HostW));
571 XtDestroyWidget(XtParent(HostW));
582 static void done_cb(w, client_data, call_data)
584 XtPointer client_data, call_data;
586 int canceled = (int)client_data == CANCEL_BTN;
588 UserSelection *sel = &userSel;
590 if (!canceled) { /* update userSel */
592 DPR2(("done_cb(): selected IMS: [%d]%s\n",
593 idx, curList->elist[idx]->name));
595 if (curList->elist[idx]->status != NoError) {
600 if ((CurHost != sel->hostname)
601 || (CurHost && sel->hostname && strcmp(sel->hostname, CurHost))
602 || sel->list != curList || sel->ims_idx != idx)
603 selection_changed = True;
605 if (selection_changed == True) {
606 update_user_selection(sel, curList, idx, CurHost, CurHostType);
607 curList = (ImsList *) 0;
611 finish_selection_window(False);
614 OpState = canceled ? State_Select_Canceled : State_Select_Done;
618 static void select_cb(w, client_data, call_data)
620 XtPointer client_data, call_data;
622 int new_idx = (int) client_data;
624 if (new_idx < 0 || new_idx >= curList->num_ent) {
625 DPR(("select_cb():\tinvalid index (%d)\n", new_idx));
629 DPR3(("select_cb(): '%s' selected (%d <- %d)\n",
630 curList->elist[new_idx]->name, new_idx, CurIdx));
635 static void host_btn_cb(w, client_data, call_data)
637 XtPointer client_data, call_data;
639 start_host_window(CurHost);
642 static void help_cb(w, client_data, call_data)
644 XtPointer client_data, call_data;
646 ximsHelp(HELP_SELECTION);
650 static int create_selection_window()
652 Widget form, sel_rc, host_rc, cmd_rc, lb, sep;
657 bool use_local = False;
659 /* selection top window */
662 XtSetArg(args[i], XmNmwmFunctions, WIN_FUNC); i++;
663 XtSetArg(args[i], XmNmwmDecorations, WIN_DECR); i++;
664 XtSetArg(args[i], XmNdefaultPosition, False); i++;
665 XtSetArg(args[i], XmNnoResize, True); i++;
666 XtSetArg(args[i], XmNallowShellResize, True); i++;
667 /* XtSetArg(args[i], XmNresizable, True); i++; */
668 XtSetArg(args[i], XmNmappedWhenManaged, False); i++;
670 form = XmCreateFormDialog(TopW, "Selection", args, i);
672 /* for child of form */
674 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
675 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
676 XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
679 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
680 w_tbl[n] = lb = XmCreateLabelGadget(form, "title", args, i + 1);
683 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
685 XtSetArg(args[j], XmNorientation, XmHORIZONTAL); j++;
686 XtSetArg(args[j], XmNpacking, XmPACK_TIGHT); j++;
687 XtSetArg(args[j], XmNisAligned, TRUE); j++;
688 XtSetArg(args[j], XmNentryAlignment, XmALIGNMENT_BEGINNING); j++;
689 XtSetArg(args[j], XmNentryBorder, 0); j++;
690 XtSetArg(args[j], XmNmarginHeight, 1); j++;
691 XtSetArg(args[j], XmNmarginWidth, 20); j++;
693 w_tbl[++n] = host_rc = XmCreateRowColumn(form, "host_rc", args, j);
696 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
698 XtSetArg(args[j], XmNorientation, XmHORIZONTAL); j++;
699 XtSetArg(args[j], XmNpacking, XmPACK_COLUMN); j++;
700 XtSetArg(args[j], XmNnumColumns, curList->num_ent); j++;
701 XtSetArg(args[j], XmNisAligned, TRUE); j++;
702 XtSetArg(args[j], XmNentryAlignment, XmALIGNMENT_BEGINNING); j++;
703 XtSetArg(args[j], XmNentryBorder, 0); j++;
704 XtSetArg(args[j], XmNmarginHeight, 10); j++;
705 /* XtSetArg(args[j], XmNmarginWidth, 40); j++; */
707 w_tbl[++n] = sel_rc = XmCreateRadioBox(form, "select_rc", args, j);
709 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
710 w_tbl[++n] = sep = XmCreateSeparatorGadget(form, "sep", args, i + 1);
712 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
713 XtSetArg(args[i+1], XmNbottomAttachment, XmATTACH_FORM);
714 w_tbl[++n] = cmd_rc = XmCreateRowColumn(form,"cmd_rc", args, i + 2);
718 switch (userSel.host_type) {
720 put_xims_errmsg(ErrUnknownHost, userSel.hostname, 0, 0);
721 ret = change_host(NULL, HOST_LOCAL);
724 ret = change_host(userSel.hostname, userSel.host_type);
725 if (ret == NoError) {
726 change_ims_list(userSel.name, -1);
729 if (ret != ErrRemoteAction) {
730 put_xims_errmsg(ret, 0 /* userSel.hostname */, 0, 0);
736 change_ims_list(NULL, userSel.ims_idx);
738 add_cmd_btn(cmd_rc, done_cb, 0, done_cb,
739 RemoteOn() ? host_btn_cb : 0, help_cb);
741 XtManageChildren(w_tbl, ++n);
743 XtManageChild(SelW); locate_window(SelW); XtUnmanageChild(SelW);
744 XtVaSetValues(SelW, XmNmappedWhenManaged, True, NULL);
745 XtVaSetValues(XtParent(SelW), XmNmappedWhenManaged, True, NULL);
746 set_cursor(SelW, False);
752 static int change_host(new_host, host_type)
757 ImsList *new_list = (ImsList *) 0;
759 if (new_host && host_type == HOST_REMOTE) {
760 set_cursor(HostW, True);
761 ret = get_remote_conf(&new_list, new_host, NULL, NULL);
762 set_cursor(HostW, False);
765 ret = get_ims_list(&localList, NULL, True);
767 new_list = localList;
770 if (ret == NoError) {
771 if (CurHost) FREE(CurHost);
772 CurHost = new_host ? NEWSTR(new_host) : NULL;
773 CurHostType = host_type;
775 DPR(("change_host(%s): curList=(%p) <- (%p)\n",
776 new_host, new_list, curList));
777 free_ims_list(curList);
779 } else if (new_list) {
780 free_ims_list(new_list);
786 # define SelectByReturn 1
788 #ifdef SelectByReturn
789 #include <Xm/ToggleB.h>
790 #include <Xm/PushB.h>
791 #define createPB XmCreatePushButton
792 #define createTB XmCreateToggleButton
794 static void add_btn_trans(btn)
797 char btn_trans_str[] = "<Key>Return: ArmAndActivate()";
798 static XtTranslations btn_trans = 0;
801 btn_trans = XtParseTranslationTable(btn_trans_str);
802 XtOverrideTranslations(btn, btn_trans);
806 #include <Xm/ToggleBG.h>
807 #include <Xm/PushBG.h>
808 #define createPB XmCreatePushButtonGadget
809 #define createTB XmCreateToggleButtonGadget
810 #define add_btn_trans(btn)
811 # endif /* SelectByReturn */
814 static void change_ims_list(last_ims_name, init_idx)
822 static int num_chld = 0;
823 static Widget tb[MAXIMSENT];
825 #define IMS_OK(i) (curList->elist[i]->status == NoError)
827 /* deternime initial selection */
830 i = get_ims_idx(curList, last_ims_name);
831 if (i >= 0 && IMS_OK(i))
835 if (init_idx >= 0 && init_idx < curList->num_ent && IMS_OK(init_idx)) {
838 idx = curList->default_idx;
839 if (!(idx >= 0 && idx < curList->num_ent && IMS_OK(idx))) {
840 for (idx = 0; idx < curList->num_ent; idx++)
841 if (IMS_OK(idx)) break;
842 if (idx >= curList->num_ent)
848 for (j = 0; j < curList->num_ent; j++) {
849 str = XmStringCreateLocalized(curList->elist[j]->label);
851 XtSetArg(args[i], XmNset, j == idx ? True : False); i++;
852 XtSetArg(args[i], XmNsensitive, IMS_OK(j)); i++;
853 XtSetArg(args[i], XmNlabelString, str); i++;
854 XtSetArg(args[i], XmNspacing, 10); i++;
856 XtSetValues(tb[j], args, i);
858 tb[j] = createTB(SelRC, "ims", args, i);
859 XtAddCallback(tb[j], XmNvalueChangedCallback, select_cb, (XtPointer)j);
860 add_btn_trans(tb[j]);
866 else if (j < num_chld)
867 XtUnmanageChildren(tb + j, num_chld - j);
868 XtManageChildren(tb, j);
872 if (CurHostType == HOST_UNKNOWN)
873 CurHostType = check_hostname(CurHost);
874 set_host_label(CurHostType, CurHost);
880 static void set_host_label(host_type, hostname)
884 static Widget lb_host = 0;
886 /* if (!HostRC) return; */
888 if (host_type == HOST_REMOTE) { /* change HostLabel & manage HostRC */
896 XtSetArg(args[n], XmNmarginLeft, 100); n++;
897 lb = XmCreateLabelGadget(HostRC, "host_label", args, n);
898 lb_host = XmCreateLabelGadget(HostRC, "hostname", NULL, 0);
900 XtManageChild(lb_host);
902 str = XmStringCreateLocalized(hostname);
903 XtVaSetValues(lb_host, XmNlabelString, str, NULL);
906 XtManageChild(HostRC);
908 /* unmanage HostRC */
909 XtUnmanageChild(HostRC);
914 static void add_cmd_btn(parent_rc, cb_ok, cb_clear, cb_cancel, cb_host, cb_help)
916 void (*cb_ok)(), (*cb_cancel)(), (*cb_clear)(),
917 (*cb_host)(), (*cb_help)();
925 if (cb_clear) nbtn++;
926 if (cb_cancel) nbtn++;
929 if (nbtn == 0) return;
931 /* command buttons on "cmd_rc" */
934 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
935 XtSetArg(args[n], XmNpacking, XmPACK_TIGHT); n++;
937 XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
938 XtSetArg(args[n], XmNpacking, XmPACK_COLUMN); n++;
940 XtSetArg(args[n], XmNnumColumns, nbtn); n++;
941 XtSetArg(args[n], XmNisAligned, TRUE); n++;
942 XtSetArg(args[n], XmNentryAlignment, XmALIGNMENT_CENTER); n++;
943 XtSetArg(args[n], XmNentryBorder, 0); n++;
944 XtSetArg(args[n], XmNmarginHeight, 1); n++;
945 XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
946 /* XtSetArg(args[n], XmNmarginWidth, 20); n++; */
947 /* XtSetArg(args[n], XmNspacing, 20); n++; */
948 XtSetValues(parent_rc, args, n);
950 /* for child of parent_rc */
955 pb[nbtn] = createPB(parent_rc, "OK", args, n);
956 XtAddCallback(pb[nbtn], XmNactivateCallback,
957 cb_ok, (XtPointer)OK_BTN);
959 /* XtVaSetValues(parent_rc, XmNinitialFocus, pb, NULL); */
963 pb[nbtn] = createPB(parent_rc, "Clear", args, n);
964 XtAddCallback(pb[nbtn], XmNactivateCallback,
965 cb_clear, (XtPointer)CLEAR_BTN);
969 pb[nbtn] = createPB(parent_rc, "Cancel", args, n);
970 XtAddCallback(pb[nbtn], XmNactivateCallback,
971 cb_cancel, (XtPointer)CANCEL_BTN);
975 pb[nbtn] = createPB(parent_rc, "ChangeHost", args, n);
976 XtAddCallback(pb[nbtn], XmNactivateCallback,
977 cb_host, (XtPointer)HOST_BTN);
981 pb[nbtn] = createPB(parent_rc, "Help", args, n);
982 XtAddCallback(pb[nbtn], XmNactivateCallback,
983 cb_help, (XtPointer)HELP_BTN);
986 #ifdef SelectByReturn
987 for (n = 0; n < nbtn; n++)
988 add_btn_trans(pb[n]);
989 #endif /* SelectByReturn */
991 XtManageChildren(pb, nbtn);
994 /* ***** host window ***** */
996 static void start_host_window(cur_host)
1002 create_host_window(cur_host);
1004 /* handle system Menu's "close" */
1005 XmAddWMProtocolCallback(XtParent(HostW),
1006 XmInternAtom(Dpy, "WM_DELETE_WINDOW", True),
1007 (XtCallbackProc)host_done_cb, (XtPointer)CANCEL_BTN);
1010 XtVaSetValues(HostText, XmNvalue, CurHost, NULL);
1013 XmProcessTraversal(HostText, XmTRAVERSE_CURRENT);
1015 locate_window(HostW);
1016 XtManageChild(HostW);
1017 XtPopup(XtParent(HostW), XtGrabNone);
1020 pr_brk("start_host_window");
1026 static void finish_host_window()
1028 DPR(("finish_host_window()\n"));
1031 XtUnmanageChild(HostW);
1032 XtPopdown(XtParent(HostW));
1037 static void host_done_cb(w, client_data, call_data)
1039 XtPointer client_data, call_data;
1041 int cancel = (int)client_data == CANCEL_BTN;
1043 char *new_host, *txt, *p;
1044 bool host_changed = False;
1048 finish_host_window();
1052 /* if (!HostText) return; */
1054 txt = XmTextFieldGetString(HostText);
1057 new_host = (*p) ? p : NULL;
1060 if (!(CurHost) || strcmp(CurHost, new_host)) {
1061 host_type = check_hostname(new_host);
1063 switch (host_type) {
1067 host_changed = True;
1070 host_changed = True;
1073 host_changed = False;
1074 put_xims_errmsg(ErrUnknownHost, new_host, 0, 0);
1076 /* don't finish window */
1081 } else if (CurHost) { /* 'new_host == NULL' ==> local host */
1082 host_type = HOST_LOCAL;
1083 host_changed = True;
1086 DPR(("host_cb(): hostname %s changed '%s' (<- %s)\n",
1087 host_changed ? NULL : "NOT", new_host, CurHost));
1090 char *last_ims = NULL;
1092 /* save the name of selected ims */
1093 if (CurIdx >= 0 && CurIdx < curList->num_ent)
1094 last_ims = NEWSTR(curList->elist[CurIdx]->name);
1096 ret = change_host(new_host, host_type);
1097 if (ret == NoError) {
1098 finish_host_window();
1099 change_ims_list(last_ims, -1);
1100 selection_changed = True;
1102 if (ret != ErrRemoteAction) {
1103 put_xims_errmsg(ret, new_host, 0, 0);
1105 /* don't finish window */
1110 finish_host_window();
1116 pr_brk("host_done_window");
1120 static void host_clear_cb(w, client_data, call_data)
1122 XtPointer client_data, call_data;
1124 /* if (!HostText) return; */
1125 XtVaSetValues(HostText, XmNvalue, "", NULL);
1128 static void host_done_action(w, ev, args, num_args)
1134 host_done_cb(w, (XtPointer) OK_BTN, 0);
1137 static void create_host_window(cur_host)
1140 Widget form, cmd_rc, lb1, sep, w_tbl[5];
1141 Widget host_desc, host_rc, host_lb, host_txt;
1142 Arg args[16], hargs[8];
1146 XtTranslations trans;
1147 static char host_trans[] = "<Key>Return: host-done()";
1148 static XtActionsRec host_actions[] = {
1149 { "host-done", (XtActionProc) host_done_action }
1153 XtSetArg(args[i], XmNmwmFunctions, WIN_FUNC); i++;
1154 XtSetArg(args[i], XmNmwmDecorations, WIN_DECR); i++;
1155 XtSetArg(args[i], XmNdefaultPosition, False); i++;
1156 XtSetArg(args[i], XmNnoResize, True); i++;
1157 XtSetArg(args[i], XmNallowShellResize, True); i++;
1158 XtSetArg(args[i], XmNmappedWhenManaged, False); i++;
1159 XtSetArg(args[i], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL); i++;
1161 form = XmCreateFormDialog(TopW, "Host", args, i);
1163 /* for child of form */
1165 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1166 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1167 XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
1170 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1171 w_tbl[n] = lb1 = XmCreateLabelGadget(form, "title", args, i + 1);
1173 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1175 XtSetArg(args[j], XmNmarginHeight, 8); j++;
1176 XtSetArg(args[j], XmNmarginWidth, 8); j++;
1177 w_tbl[++n] = host_desc = XmCreateLabelGadget(form, "host_desc", args, j);
1179 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1181 XtSetArg(args[j], XmNorientation, XmHORIZONTAL); j++;
1182 XtSetArg(args[j], XmNpacking, XmPACK_TIGHT); j++;
1183 XtSetArg(args[j], XmNisAligned, TRUE); j++;
1184 XtSetArg(args[j], XmNentryAlignment, XmALIGNMENT_BEGINNING); j++;
1185 XtSetArg(args[j], XmNentryBorder, 0); j++;
1186 XtSetArg(args[j], XmNmarginHeight, 1); j++;
1187 /* XtSetArg(args[j], XmNmarginWidth, 20); j++; */
1188 w_tbl[++n] = host_rc = XmCreateRowColumn(form, "host_rc", args, j);
1192 XtSetArg(hargs[j], XmNalignment, XmALIGNMENT_BEGINNING); j++;
1193 hw[nhw++] = host_lb = XmCreateLabelGadget(host_rc, "host_label", hargs, j);
1195 /* XtSetArg(hargs[j], XmNcolumns, TEXT_COLUMNS); j++; */
1196 /* XtSetArg(hargs[j], XmNmaxLength, MAX_HOSTNAME_LEN); j++; */
1197 XtSetArg(hargs[j], XmNeditable, True); j++;
1198 XtSetArg(hargs[j], XmNvalue, cur_host); j++;
1199 XtSetArg(hargs[j], XmNmarginHeight, 1); j++;
1200 XtSetArg(hargs[j], XmNmarginWidth, 1); j++;
1202 hw[nhw++] = host_txt = XmCreateTextField(host_rc, "host_text", hargs, j);
1203 XtManageChildren(hw, nhw);
1205 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1206 w_tbl[++n] = sep = XmCreateSeparatorGadget(form, "sep", args, i + 1);
1207 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1208 XtSetArg(args[i+1], XmNbottomAttachment, XmATTACH_FORM);
1209 w_tbl[++n] = cmd_rc = XmCreateRowColumn(form, "cmd_rc", args, i + 2);
1210 XtManageChildren(w_tbl, ++n);
1212 add_cmd_btn(cmd_rc, host_done_cb, host_clear_cb, host_done_cb, 0, 0);
1214 /* set 'host-done' action for 'Return' key */
1215 XtAppAddActions(appC, host_actions, XtNumber(host_actions));
1216 trans = XtParseTranslationTable(host_trans);
1217 XtOverrideTranslations(HostText, trans);
1219 XtManageChild(HostW); locate_window(HostW); XtUnmanageChild(HostW);
1220 XtVaSetValues(XtParent(HostW), XmNmappedWhenManaged, True, NULL);
1221 XtVaSetValues(HostW, XmNmappedWhenManaged, True, NULL);
1222 set_cursor(HostW, False);
1228 /* ******** mode window ******** */
1230 static int OrgMode = SEL_MODE_NONE;
1231 static int CurMode = SEL_MODE_NONE;
1233 int start_mode_window(cur_mode)
1238 OrgMode = CurMode = cur_mode;
1240 if ((ret = init_window_env()) != NoError)
1243 if ((ret = create_mode_window(cur_mode)) != NoError)
1246 /* handle system Menu's "close" */
1247 XmAddWMProtocolCallback(XtParent(ModeW),
1248 XmInternAtom(Dpy, "WM_DELETE_WINDOW", True),
1249 (XtCallbackProc)mode_done_cb, (XtPointer)CANCEL_BTN);
1251 locate_window(ModeW);
1252 XtManageChild(ModeW);
1253 XtPopup(XtParent(ModeW), XtGrabNone);
1256 XmProcessTraversal(FocusW, XmTRAVERSE_CURRENT);
1258 XtAppMainLoop(appC);
1262 static void finish_mode_window(end_window)
1266 XtUnmanageChild(ModeW);
1267 XtPopdown(XtParent(ModeW));
1268 XtDestroyWidget(XtParent(ModeW));
1279 static void mode_done_cb(w, client_data, call_data)
1281 XtPointer client_data, call_data;
1284 int canceled = (int)client_data == CANCEL_BTN;
1286 DPR(("mode_done(%s):\torg=%d cur=%d\n",
1287 canceled ? "Cancel" : "OK", OrgMode, CurMode));
1289 OpErrCode = NoError;
1290 OpState = State_Mode_Canceled;
1292 ret = set_select_mode(OrgMode, CurMode);
1295 OpState = State_Mode_Done;
1297 if (OpErrCode != NoError) {
1298 finish_mode_window(False);
1299 LastErrMsg = OpErrCode;
1300 put_xims_errmsg(OpErrCode, 0, 0, 0);
1301 if (WaitingDialogReply) {
1302 DPR(("mode_done_cb(): enter xevent_loop()\n"));
1303 xevent_loop(); /* never returns */
1307 finish_mode_window(True);
1311 static void mode_cb(w, client_data, call_data)
1313 XtPointer client_data, call_data;
1315 int is_set = (int)((XmToggleButtonCallbackStruct *)call_data)->set;
1316 int is_auto = (int)client_data;
1318 CurMode = (is_auto && is_set) ? SEL_MODE_AUTO : SEL_MODE_NOAUTO;
1321 static void mode_help_cb(w, client_data, call_data)
1323 XtPointer client_data, call_data;
1325 ximsHelp(HELP_MODE);
1328 static int create_mode_window(cur_mode)
1331 Widget form, mode_rc, cmd_rc, lb1, sep, w_tbl[8];
1336 XtSetArg(args[i], XmNmwmFunctions, WIN_FUNC); i++;
1337 XtSetArg(args[i], XmNmwmDecorations, WIN_DECR); i++;
1338 XtSetArg(args[i], XmNdefaultPosition, False); i++;
1339 XtSetArg(args[i], XmNnoResize, True); i++;
1340 XtSetArg(args[i], XmNallowShellResize, True); i++;
1341 XtSetArg(args[i], XmNmappedWhenManaged, False); i++;
1343 form = XmCreateFormDialog(TopW, "Mode", args, i);
1345 /* for child of form */
1347 XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
1348 XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
1349 XtSetArg(args[i], XmNrightAttachment, XmATTACH_FORM); i++;
1352 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1353 w_tbl[n] = lb1 = XmCreateLabelGadget(form, "title", args, i + 1);
1355 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1357 XtSetArg(args[j], XmNisAligned, TRUE); j++;
1358 XtSetArg(args[j], XmNentryAlignment, XmALIGNMENT_BEGINNING); j++;
1359 XtSetArg(args[j], XmNentryBorder, 0); j++;
1360 XtSetArg(args[j], XmNmarginHeight, 10); j++;
1361 XtSetArg(args[j], XmNmarginWidth, 30); j++;
1363 #ifdef SelectByReturn
1365 XtSetArg(args[j], XmNorientation, XmHORIZONTAL); j++;
1366 XtSetArg(args[j], XmNpacking, XmPACK_COLUMN); j++;
1367 XtSetArg(args[j], XmNnumColumns, NUM_SEL_MODE); j++;
1368 w_tbl[++n] = mode_rc = XmCreateRadioBox(form, "mode_rc", args, j);
1371 Widget tb[NUM_SEL_MODE];
1373 int set_idx = cur_mode == SEL_MODE_AUTO ? 1 : 0;
1376 XtSetArg(bargs[k], XmNspacing, 10); k++;
1377 tb[0] = createTB(mode_rc, "button_0", bargs, k);
1378 tb[1] = createTB(mode_rc, "button_1", bargs, k);
1379 for (k = 0; k < NUM_SEL_MODE; k++) {
1380 XtVaSetValues(tb[k], XmNset, k == set_idx ? True : False, NULL);
1381 XtAddCallback(tb[k], XmNvalueChangedCallback, mode_cb, (XtPointer)k);
1382 add_btn_trans(tb[k]);
1384 XtManageChildren(tb, NUM_SEL_MODE);
1388 XtSetArg(args[j], XmNbuttonCount, NUM_SEL_MODE); j++;
1389 XtSetArg(args[j], XmNbuttonSet, cur_mode == SEL_MODE_AUTO ? 1 : 0); j++;
1390 XtSetArg(args[j], XmNsimpleCallback, mode_cb); j++;
1391 w_tbl[++n] = mode_rc = XmCreateSimpleRadioBox(form, "mode_rc", args, j);
1392 #endif /* SelectByReturn */
1394 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1395 w_tbl[++n] = sep = XmCreateSeparatorGadget(form, "sep", args, i + 1);
1396 XtSetArg(args[i], XmNtopWidget, w_tbl[n]);
1397 XtSetArg(args[i+1], XmNbottomAttachment, XmATTACH_FORM);
1398 w_tbl[++n] = cmd_rc = XmCreateRowColumn(form, "cmd_rc", args, i + 2);
1399 XtManageChildren(w_tbl, ++n);
1401 add_cmd_btn(cmd_rc, mode_done_cb, 0, mode_done_cb, 0, mode_help_cb);
1403 XtManageChild(ModeW); locate_window(ModeW); XtUnmanageChild(ModeW);
1404 XtVaSetValues(XtParent(ModeW), XmNmappedWhenManaged, True, NULL);
1405 XtVaSetValues(ModeW, XmNmappedWhenManaged, True, NULL);
1406 set_cursor(ModeW, False);
1412 /* ******** ximsHelp ******** */
1414 static void help_ok(w, client_data, call_data)
1416 XtPointer client_data, call_data;
1424 XtUnmanageChild(HelpW);
1425 XtPopdown(XtParent(HelpW));
1429 static void create_help()
1435 XtSetArg(args[i], XmNmwmFunctions, WIN_FUNC); i++;
1436 XtSetArg(args[i], XmNmwmDecorations, WIN_DECR); i++;
1437 XtSetArg(args[i], XmNautoUnmanage, True); i++;
1438 XtSetArg(args[i], XmNdefaultPosition, False); i++;
1439 XtSetArg(args[i], XmNnoResize, True); i++;
1440 XtSetArg(args[i], XmNallowShellResize, True); i++;
1441 XtSetArg(args[i], XmNmappedWhenManaged, False); i++;
1442 HelpW = XmCreateInformationDialog(TopW, "Help", args, i);
1444 XtUnmanageChild(XmMessageBoxGetChild(HelpW, XmDIALOG_CANCEL_BUTTON));
1445 XtUnmanageChild(XmMessageBoxGetChild(HelpW, XmDIALOG_HELP_BUTTON));
1446 XtAddCallback(HelpW, XmNokCallback, help_ok, (XtPointer)0);
1448 /* help_dialog is not located correctly unless once managed */
1449 /* XtSetMappedWhenManaged(XtParent(HelpW), False); */
1450 XtManageChild(HelpW);
1451 XtUnmanageChild(HelpW);
1452 XtSetMappedWhenManaged(XtParent(HelpW), True);
1453 XtSetMappedWhenManaged(HelpW, True);
1454 set_cursor(HelpW, False);
1459 void ximsHelp(help_type)
1464 static int last_help_type = -1;
1469 if (help_type != last_help_type) {
1471 switch (help_type) {
1472 case HELP_MODE: msg = appres.modeHelpMsg; break;
1474 case HELP_SELECTION: msg = appres.selectionHelpMsg; break;
1477 if (!msg || !*msg) {
1481 msg = "help message not defined in resource file\n";
1487 if (XtIsManaged(HelpW))
1488 XtUnmanageChild(HelpW);
1490 str = XmStringCreateLocalized(msg);
1491 XtVaSetValues(HelpW, XmNmessageString, str, NULL);
1494 last_help_type = help_type;
1497 locate_window(HelpW);
1498 XtManageChild(HelpW);
1499 XtPopup(XtParent(HelpW), XtGrabNone);
1503 /* ******** message dialog ******** */
1505 static int dialog_resp = XmCR_NONE;
1506 static bool in_confirmation = False;
1508 static void dialog_resp_cb(w, client_data, call_data)
1510 XtPointer client_data, call_data;
1512 Widget msg_box = (Widget) client_data;
1513 XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *) call_data;
1515 dialog_resp = cbs->reason;
1516 XtUnmanageChild(msg_box);
1518 if (!in_confirmation) {
1519 WaitingDialogReply = False;
1520 DPR3(("dialog_resp_cb(): WaitingDialogReply ==> False\n"));
1522 if (InWaitingState())
1528 static int wait_confirmation(w)
1531 XtAppContext context;
1533 dialog_resp = XmCR_NONE;
1535 /* XtManageChild(w); */
1536 /* context = XtWidgetToApplicationContext(w); */
1538 in_confirmation = True;
1539 while (dialog_resp == XmCR_NONE || XtAppPending(context)) {
1540 XtAppProcessEvent(context, XtIMAll);
1543 in_confirmation = False;
1549 int put_msg_win(type, msg)
1555 int wait_resp = FALSE;
1559 DPR3(("put_msg_win(type=%d):\tmsg=%s", type, msg));
1561 if (!msg || !*msg) {
1562 DPR(("put_msg_win(): msg is empty\n"));
1564 } else if (msg[strlen(msg) - 1] != '\n') {
1565 DPR(("put_msg_win(): msg isn't terminated by '\\n'\n"));
1570 case MSGTYP_FATAL: type = XmDIALOG_ERROR; break;
1571 case MSGTYP_WARN: type = XmDIALOG_WARNING; break;
1572 case MSGTYP_CONFIRM: type = XmDIALOG_QUESTION;
1573 wait_resp = TRUE; break;
1575 case MSGTYP_INFO: type = XmDIALOG_INFORMATION; break;
1578 if ((ret = init_window_env()) != NoError)
1581 if (!MsgW) { /* create message dialog */
1585 XtSetArg(args[i], XmNautoUnmanage, True); i++;
1586 XtSetArg(args[i], XmNmwmFunctions, WIN_FUNC); i++;
1587 XtSetArg(args[i], XmNmwmDecorations, WIN_DECR); i++;
1588 XtSetArg(args[i], XmNdefaultButtonType, XmDIALOG_OK_BUTTON); i++;
1589 XtSetArg(args[i], XmNdefaultPosition, False); i++;
1590 XtSetArg(args[i], XmNnoResize, True); i++;
1591 XtSetArg(args[i], XmNallowShellResize, True); i++;
1592 XtSetArg(args[i], XmNmappedWhenManaged, False); i++;
1593 MsgW = XmCreateMessageDialog(TopW, "Message", args, i);
1594 XtUnmanageChild(XmMessageBoxGetChild(MsgW, XmDIALOG_HELP_BUTTON));
1595 XtAddCallback(MsgW, XmNokCallback, dialog_resp_cb, (XtPointer)MsgW);
1596 XtAddCallback(MsgW, XmNcancelCallback, dialog_resp_cb, (XtPointer)MsgW);
1598 /* dialog is not located correctly unless once managed */
1599 XtManageChild(MsgW); XtUnmanageChild(MsgW);
1600 XtSetMappedWhenManaged(XtParent(MsgW), True);
1601 XtSetMappedWhenManaged(MsgW, True);
1602 set_cursor(MsgW, False);
1604 btn = XmMessageBoxGetChild(MsgW, XmDIALOG_CANCEL_BUTTON);
1606 if (wait_resp) XtManageChild(btn);
1607 else XtUnmanageChild(btn);
1609 str = XmStringCreateLocalized(msg);
1610 XtVaSetValues(MsgW, XmNdialogType, type,
1611 XmNmessageString, str,
1612 XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
1614 XmNdialogStyle, wait_resp ? XmDIALOG_FULL_APPLICATION_MODAL
1615 : XmDIALOG_MODELESS,
1620 locate_window(MsgW);
1621 XtManageChild(MsgW);
1622 if (type == MSGTYP_FATAL || type == MSGTYP_WARN) {
1629 DPR3(("wait_dialog_resp(START): WaitingDialogReply ==> True\n"));
1630 WaitingDialogReply = True;
1632 reply = wait_confirmation(MsgW);
1634 WaitingDialogReply = False;
1635 DPR3(("wait_dialog_resp(DONE): WaitingDialogReply ==> False\n"));
1638 DPR3(("put_msg_win(): WaitingDialogReply ==> True\n"));
1639 WaitingDialogReply = True;
1642 return reply == XmCR_OK ? True : False;
1646 /* ******** locate_window ******** */
1649 #define LOC_CENTER 0
1650 #define LOC_TOP (1<<0)
1651 #define LOC_BOTTOM (1<<1)
1652 #define LOC_LEFT (1<<2)
1653 #define LOC_RIGHT (1<<3)
1654 #define LOC_MARGIN 5
1656 static int window_location(loc_str)
1659 int locate_type = LOC_CENTER;
1660 char *lower_str, *p;
1662 lower_str = NEWSTR(loc_str);
1663 if (p = lower_str) {
1665 if (strstr(lower_str, "center")) locate_type |= LOC_CENTER;
1666 if (strstr(lower_str, "top")) locate_type |= LOC_TOP;
1667 if (strstr(lower_str, "bottom")) locate_type |= LOC_BOTTOM;
1668 if (strstr(lower_str, "left")) locate_type |= LOC_LEFT;
1669 if (strstr(lower_str, "right")) locate_type |= LOC_RIGHT;
1675 static void locate_window(w)
1681 Dimension width, height;
1682 static int locate_type = LOC_NONE;
1684 /* if (!isXsession()) return; */
1686 if (locate_type == LOC_NONE) {
1687 locate_type = window_location(appres.windowLocation);
1688 DPR3(("locate_window(): locate_type=%d (%s)\n",
1689 locate_type, appres.windowLocation));
1692 width = height = (Dimension) 0;
1693 scr = XDefaultScreen(Dpy);
1694 dpy_w = DisplayWidth(Dpy, scr);
1695 dpy_h = DisplayHeight(Dpy, scr);
1697 XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, NULL);
1701 if (locate_type & LOC_TOP) y = LOC_MARGIN;
1702 if (locate_type & LOC_BOTTOM) y = dpy_h - height - LOC_MARGIN * 2;
1703 if (locate_type & LOC_LEFT) x = LOC_MARGIN;
1704 if (locate_type & LOC_RIGHT) x = dpy_w - width - LOC_MARGIN * 2;
1706 if (!x) x = (int) (dpy_w - width - LOC_MARGIN * 2) / 2;
1707 if (!y) y = (int) (dpy_h - height - LOC_MARGIN * 2) / 2;
1709 DPR3(("locate_window(): w=%d h=%d ==> x=%d y=%d\n", width, height, x, y));
1711 XtVaSetValues(w, XmNx, x, XmNy, y, NULL);
1715 /* ******** cursor (normal / wait) ******** */
1717 static void set_cursor(w, is_wait)
1721 static Cursor cursors[2] = { None, None };
1724 idx = is_wait ? 1 : 0;
1726 /* if (!Dpy || !TopW || !w) return; */
1727 if (cursors[idx] == None) {
1728 cursors[idx] = XCreateFontCursor(Dpy, idx ? XC_watch : XC_left_ptr);
1731 XDefineCursor(Dpy, XtWindow(w), cursors[idx]);
1736 /* ***** waiting functions ***** */
1740 XtAppMainLoop(appC);
1743 static time_t xt_start_tm = 0L; /* in sec */
1744 static XtIntervalId xt_last_timer = (XtIntervalId)0;
1745 static bool xt_waiting = False;
1747 void xt_start_waiting()
1751 xt_start_tm = time((time_t) 0);
1752 xt_last_timer = XtAppAddTimeOut(appC, (unsigned long) Opt.Interval,
1753 xt_timer_cb, (XtPointer)0);
1754 /* if (!xt_last_timer) return; */
1756 DPR(("xt_start_waiting(): EventLoop (interval=%d)\n", Opt.Interval));
1759 XtAppMainLoop(appC);
1762 void xt_stop_waiting()
1764 if (xt_last_timer) {
1765 XtRemoveTimeOut(xt_last_timer);
1766 xt_last_timer = (XtIntervalId) 0;
1773 static void xt_timer_cb(client_data, timer_id)
1774 XtPointer client_data;
1775 XtIntervalId *timer_id;
1779 /* DPR3(("xt_timer_cb(timer_id=%d): last_timer=%d\n",
1780 *timer_id, xt_last_timer)); */
1782 if (*timer_id != xt_last_timer) return;
1783 xt_last_timer = (XtIntervalId) 0;
1784 lapse = (int) time((time_t) 0) - xt_start_tm;
1787 if (DebugLvl >= 1) putc('.', LogFp), fflush(LogFp);
1790 if (im_mod_available((RunEnv *) 0) != 0 || lapse >= Opt.Timeout) {
1791 DPR(("xt_timer_cb(tmout=%d): wait done (%d sec.)\n",
1792 Opt.Timeout, lapse));
1793 xt_stop_waiting(); /* never returns */
1796 xt_last_timer = XtAppAddTimeOut(appC, (unsigned long) Opt.Interval,
1797 xt_timer_cb, (XtPointer)0);