433b5fd03459136b84d34d7c564a0ec08eba84e8
[oweals/cde.git] / cde / programs / dtstyle / I18nMain.c
1 /* $TOG: I18nMain.c /main/4 1997/08/11 12:31:36 samborn $ */
2 /*
3  * (c) Copyright 1996 Digital Equipment Corporation.
4  * (c) Copyright 1996 Hewlett-Packard Company.
5  * (c) Copyright 1996 International Business Machines Corp.
6  * (c) Copyright 1996 Sun Microsystems, Inc.
7  * (c) Copyright 1996 Novell, Inc. 
8  * (c) Copyright 1996 FUJITSU LIMITED.
9  * (c) Copyright 1996 Hitachi.
10  */
11 /************************************<+>*************************************
12  ****************************************************************************
13  **
14  **   File:        I18nMain.c
15  **
16  **   Description: Controls the Dtstyle I18N customization dialog
17  **
18  **
19  ****************************************************************************
20  ************************************<+>*************************************/
21
22 /*+++++++++++++++++++++++++++++++++++++++*/
23 /* include files                         */
24 /*+++++++++++++++++++++++++++++++++++++++*/
25
26 #include <X11/Xlib.h>
27 #include <Xm/MwmUtil.h>
28
29 #include <Xm/XmP.h>
30 #include <Xm/Xm.h>
31 #include <Xm/Form.h>
32 #include <Xm/LabelG.h>
33 #include <Xm/PushBG.h>
34 #include <Xm/RowColumn.h>
35 #include <Xm/ToggleBG.h>
36 #include <Xm/SeparatoG.h>
37 #include <Xm/VendorSEP.h>
38 #include <Xm/MessageB.h>
39
40 #include <Dt/DialogBox.h>
41 #include <Dt/Icon.h>
42 #include <Dt/TitleBox.h>
43 #include <Dt/UserMsg.h>
44 #include <Dt/Message.h>
45 #include <Dt/HourGlass.h>
46 #include <Dt/Wsm.h>
47
48 #include "Help.h"
49 #include "Main.h"
50 #include "SaveRestore.h"
51 #include "Protocol.h"
52
53 #include <ctype.h>
54
55 /*+++++++++++++++++++++++++++++++++++++++*/
56 /* include extern functions              */
57 /*+++++++++++++++++++++++++++++++++++++++*/
58 #include "I18nMain.h"
59 #include "I18nEnv.h"
60
61 /*+++++++++++++++++++++++++++++++++++++++*/
62 /* Local #defines                        */
63 /*+++++++++++++++++++++++++++++++++++++++*/
64
65 #define MSG_IMMEDIATE  ((char *)GETMESSAGE(19, 20, "The new XmNpreeditType value will take effect\nas applications are restarted."))
66 #define MSG_LATER      ((char *)GETMESSAGE(19, 21, "Your selection will take effect\n at your next session."))
67
68 /*+++++++++++++++++++++++++++++++++++++++*/
69 /* Internal Functions                    */
70 /*+++++++++++++++++++++++++++++++++++++++*/
71
72 static int  InitI18nValues(Widget shell);
73 static void SetImServerHosts(I18nEnv *env);
74 static void SetImsToggleList(I18nEnv *env);
75 static void SetImsMode(I18nEnv *env);
76 static void SetPreeditType(I18nEnv *env, XmStringTable preeditTable,
77                            int preeditTableNum);
78
79 static Widget BuildI18nDlg(Widget shell);
80 static void FormLayoutCB(Widget w, XtPointer client_data, XtPointer call_data);
81 static void MapCB(Widget w, XtPointer client_data, XtPointer call_data);
82 static void SystemDefaultCB(Widget w, XtPointer client_data, 
83                             XtPointer call_data);
84 static void ServerHostCB(Widget w, XtPointer client_data, XtPointer call_data);
85 static void UpdateImList(I18nEnv *env, char *hostname);
86 static void TextFocusCB(Widget w, XtPointer client_data, XtPointer call_data);
87 static void TextLosingFocusCB(Widget w, XtPointer client_data, 
88                               XtPointer call_data);
89 static void ButtonCB(Widget w, XtPointer client_data, XtPointer call_data);
90 static int  SaveSelectedValues(I18nEnv *env);
91 static void SetFileSelValues(I18nEnv *env);
92 static void ResetLastSavedValues(I18nEnv *env);
93
94 static void OkWarnCB(Widget w, XtPointer client_data, XtPointer call_data);
95 static void CancelWarnCB(Widget w, XtPointer client_data, XtPointer call_data);
96
97 static void ListItemSelectCB(Widget w, XtPointer client_data, 
98                              XtPointer call_data);
99 static void MoveUpCB(Widget w, XtPointer client_data, XtPointer call_data);
100 static void MoveDownCB(Widget w, XtPointer client_data, XtPointer call_data);
101
102 static XmStringTable CopyST (XmStringTable st, int nst);
103 static void FreeST (XmStringTable st, int nst);
104
105 /*+++++++++++++++++++++++++++++++++++++++*/
106 /* Internal Variables                    */
107 /*+++++++++++++++++++++++++++++++++++++++*/
108
109 typedef struct {
110     Widget      pictLabel;
111     Widget      systemDefault;
112     Widget      inputMethodTB;
113     Widget      serverHostLabel;
114     Widget      serverHostCB;
115     Widget      inputMethodLabel;
116     Widget      inputMethodRC;
117     Widget      imStartModeTB;
118     Widget      imStartModeRC;
119     Widget      askAtLoginTG;
120     Widget      resumeCurrentImTG;
121     Widget      preeditTypeTB;
122     Widget      preeditTypeList;
123     int         preeditTypeListLastPos;
124     Boolean     preeditHasChanged;
125     XmStringTable preeditSavedVal;
126     int         preeditSavedNum;
127     Widget      buttonMoveUp;
128     Widget      buttonMoveDown;
129     Widget      warnDialog;
130     Widget      defaultButton;
131 } I18n, *I18nPtr;
132
133 static I18n i18n;
134
135 static saveRestore save = {FALSE, 0, };
136
137 static char i18nRes[150]="";
138
139 static char *defaultPreedit[] = 
140 { "OnTheSpot",
141   "OverTheSpot",
142   "OffTheSpot",
143   "Root" 
144 };
145 #define NUM_PREEDIT 4
146
147 /*+++++++++++++++++++++++++++++++++++++++*/
148 /* popup_i18nBB                          */
149 /*+++++++++++++++++++++++++++++++++++++++*/
150
151 void 
152 popup_i18nBB(
153         Widget shell )
154 {
155     int ret = NoError;
156
157     if (style.i18nDialog == NULL) {
158       _DtTurnOnHourGlass(shell);  
159       BuildI18nDlg(shell);
160       ret = InitI18nValues(shell);
161       XtManageChild(style.i18nDialog);
162       if (ret != NoError)
163           _DtI18nErrorDialog(ret) ;
164       _DtTurnOffHourGlass(shell);  
165     }
166     else 
167     {
168         XtManageChild(style.i18nDialog);
169         raiseWindow(XtWindow(XtParent(style.i18nDialog)));
170     }
171 }
172
173 /*+++++++++++++++++++++++++++++++++++++++*/
174 /* InitI18nValues                         */
175 /*+++++++++++++++++++++++++++++++++++++++*/
176
177 static int 
178 InitI18nValues(Widget shell)
179 {
180     I18nEnv *env;
181     int ret = NoError;
182     int num_preedit = 0;
183     XmString *str = style.xrdb.preeditType;
184
185     /* Initialize */
186     env = &i18n_env;
187     env->shell = shell;
188
189     /* Get all the needed values from the environment. */
190     if ((ret = _DtI18nGetEnvValues(env)) == NoError) {
191         /* Update the display with the values */
192         SetImServerHosts(env);
193         SetImsMode(env);
194     }
195
196     /* Get the preeditType resource value */
197     while (str[num_preedit]) num_preedit++;
198     
199     SetPreeditType(env, style.xrdb.preeditType, num_preedit);
200
201     i18n.preeditHasChanged = False;
202
203     /* Save the initial value in case of a reset. */
204     i18n.preeditSavedVal = style.xrdb.preeditType;
205     i18n.preeditSavedNum = num_preedit;
206
207     return ret ;
208 }
209
210
211 static void
212 SetImServerHosts(I18nEnv *env)
213 {
214     Cardinal num_hosts = 0 ;
215
216     /* Set the TextField of the ComboBox with the value found in 
217        the IMS selection file */
218     XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"), 
219                   XmNvalue, env->file_sel->hostname, NULL);
220     
221     /* update ComboBox with list of server hostnames found in
222        "imServerHosts" resource */
223
224     if (style.xrdb.imServerHosts)
225         while (style.xrdb.imServerHosts[num_hosts]) num_hosts ++ ;
226
227     /* TBD: need to add file_sel->hostname if not null
228        or localhost, if not already present */
229
230     XtVaSetValues(i18n.serverHostCB,
231                   XmNitemCount, num_hosts,
232                   XmNitems, style.xrdb.imServerHosts, NULL);
233 }
234
235 static void 
236 SetImsToggleList(I18nEnv *env)
237 {
238     Cardinal n,i;
239     XmString string;
240     Widget *im_tog = NULL;
241     Arg args[5];
242     Boolean found = FALSE;
243     Cardinal default_index = 0;
244
245     /* create new toggles */
246
247     if (env->ims_sel->ims_list_size > 0)
248         im_tog = (Widget*)XtMalloc(sizeof(Widget) 
249                                    * env->ims_sel->ims_list_size);
250
251
252     for (i=0; i< env->ims_sel->ims_list_size; i++) {
253         string = XmStringCreateLocalized(env->ims_sel->ims_list[i].im_label);
254         n = 0;
255         XtSetArg(args[n], XmNlabelString, string); n++;
256         XtSetArg(args[n], XmNsensitive, 
257                  !(env->ims_sel->ims_list[i].inactive)); n++;
258         XtSetArg(args[n], XmNuserData, 
259                  env->ims_sel->ims_list[i].im_name); n++;
260
261         /* Need to default to the file_sel->im_name, if in the list */
262         if (strcmp(env->file_sel->im_name, 
263                    env->ims_sel->ims_list[i].im_name) == 0) {
264             found = TRUE;
265             XtSetArg(args[n], XmNset, True); n++;
266         }
267
268         if (env->ims_sel->ims_list[i].im_default) {
269             default_index = i;
270         }
271
272         im_tog[i] = XmCreateToggleButtonGadget(i18n.inputMethodRC, 
273                                                "IM", args, n);
274         XmStringFree(string);
275     }
276
277     if (env->ims_sel->ims_list_size > 0)
278         XtManageChildren(im_tog, env->ims_sel->ims_list_size);
279
280     /* If we provided toggle buttons, but the file_sel->im_name was not 
281        found, default it to the default from the locale file. */
282
283     if (im_tog && !found) {
284         n = 0;
285         XtSetArg(args[n], XmNset, True); n++;
286         XtSetValues(im_tog[default_index], args, n);
287     }
288
289     if (im_tog)
290         XtFree((char *) im_tog);
291
292     _DtTurnOffHourGlass(i18n.inputMethodTB);
293 }
294
295 static void
296 SetImsMode(I18nEnv *env)
297 {
298
299     /* only called once at startup, or when resetting the saved values */
300     if (env->file_sel->start_mode == 0)
301         XmToggleButtonGadgetSetState(i18n.askAtLoginTG, True, True); 
302     else
303         XmToggleButtonGadgetSetState(i18n.resumeCurrentImTG, True, True); 
304 }
305
306 static void 
307 SetPreeditType(
308     I18nEnv *env, 
309     XmStringTable preeditTable, 
310     int preeditTableNum)
311 {
312     XmStringTable loc_preeditTable ;
313
314     loc_preeditTable = CopyST(preeditTable, preeditTableNum); 
315     
316     /* initialize List with preeditType values */
317     XtVaSetValues(i18n.preeditTypeList,
318                   XmNvisibleItemCount, preeditTableNum,
319                   XmNitemCount, preeditTableNum,
320                   XmNitems, loc_preeditTable,
321                   XmNselectedItemCount, 1,
322                   XmNselectedItems, loc_preeditTable, NULL);
323
324     /* set the last item position - This is the number of items in the list. */
325     i18n.preeditTypeListLastPos = preeditTableNum;
326
327     /* If more than one item in the list, set the Button MoveDown sentivity to 
328        True. */
329     if (preeditTableNum > 1)
330         XtVaSetValues(i18n.buttonMoveDown, XmNsensitive, True, NULL);
331
332     XtVaSetValues(i18n.buttonMoveUp, XmNsensitive, False, NULL);
333 }
334
335
336 /*+++++++++++++++++++++++++++++++++++++++*/
337 /* build__i18nDlg                        */
338 /*+++++++++++++++++++++++++++++++++++++++*/
339 static Widget 
340 BuildI18nDlg(
341       Widget shell )
342 {
343     register int     i, n;
344     Arg              args[MAX_ARGS];
345     XmString         button_string[NUM_LABELS]; 
346     XmString         string; 
347     Widget           form;
348     Widget           inputMethodForm;
349     Widget           imStartModeForm;
350     Widget           preeditTypeForm;
351     int              count = 0;
352     Widget           widgetList1[6];
353
354     /* get i18n resource values  */
355
356     /* Set up DialogBoxDialog button labels */
357     button_string[0] = CMPSTR(_DtOkString);
358     button_string[1] = CMPSTR(_DtCancelString);
359     button_string[2] = CMPSTR(_DtHelpString);
360
361     /* Create toplevel DialogBox */
362
363     /* Initialize the i18n structure */
364     i18n.pictLabel = NULL;
365     i18n.systemDefault = NULL;
366     i18n.inputMethodTB = NULL;
367     i18n.serverHostLabel = NULL;
368     i18n.serverHostCB = NULL;
369     i18n.inputMethodLabel = NULL;
370     i18n.inputMethodRC = NULL;
371     i18n.imStartModeTB = NULL;
372     i18n.imStartModeRC = NULL;
373     i18n.askAtLoginTG = NULL;
374     i18n.resumeCurrentImTG = NULL;
375     i18n.preeditTypeTB = NULL;
376     i18n.preeditTypeList = NULL;
377     i18n.buttonMoveUp = NULL;
378     i18n.buttonMoveDown = NULL;
379     i18n.warnDialog = NULL;
380
381     /* saveRestore
382      * Note that save.poscnt has been initialized elsewhere.  
383      * save.posArgs may contain information from restoreBeep().*/
384
385     XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);  
386     save.poscnt++;
387     XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
388     save.poscnt++;
389     XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
390     save.poscnt++;
391     style.i18nDialog = 
392         __DtCreateDialogBoxDialog(shell, "i18nDialog", save.posArgs, 
393                                   save.poscnt);
394     XtAddCallback(style.i18nDialog, XmNhelpCallback,
395             (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_I18N_DIALOG);
396
397     XmStringFree(button_string[0]);
398     XmStringFree(button_string[1]);
399     XmStringFree(button_string[2]);
400
401     widgetList1[0] = _DtDialogBoxGetButton(style.i18nDialog,2);
402     n=0;
403     XtSetArg(args[n], XmNautoUnmanage, False); n++;
404     XtSetArg(args[n], XmNcancelButton, widgetList1[0]); n++;
405     XtSetValues (style.i18nDialog, args, n);
406
407     n=0;
408     XtSetArg(args[n], XmNtitle, 
409          ((char *)GETMESSAGE(19, 1, "Style Manager - Internationalization")));
410     n++;
411     XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
412     XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
413     XtSetValues (XtParent(style.i18nDialog), args, n);
414
415     n = 0;
416     XtSetArg(args[n], XmNallowOverlap, False); n++;
417     XtSetArg(args[n], XmNchildType, XmWORK_AREA);  n++;
418     form = XmCreateForm(style.i18nDialog, "i18nForm", args, n);
419
420     n = 0;
421     XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
422     XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
423     XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
424     XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
425     XtSetArg(args[n], XmNstring, NULL); n++;  
426     XtSetArg(args[n], XmNshadowThickness, 0); n++;  
427     XtSetArg(args[n], XmNimageName, I18N_ICON); n++;  
428     XtSetArg(args[n], XmNtraversalOn, False); n++;  
429     widgetList1[count++] = i18n.pictLabel =
430         _DtCreateIcon(form, "i18npictLabel", args, n);
431
432     n = 0;
433     XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT);  n++;
434     XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH);  n++;
435     string = CMPSTR(((char *)GETMESSAGE(19, 2, "Default")));
436     XtSetArg(args[n], XmNlabelString, string); n++;
437     widgetList1[count++] = i18n.systemDefault = 
438         XmCreatePushButtonGadget(form, "systemDefault", args, n);
439     XmStringFree(string);
440
441     n = 0;
442     string = CMPSTR((char *)GETMESSAGE(19, 3, "Input Method"));
443     XtSetArg(args[n], XmNtitleString, string);  n++;
444     widgetList1[count++] = i18n.inputMethodTB =
445         _DtCreateTitleBox(form, "inputMethodTB", args, n);
446     XmStringFree(string);
447     
448     n = 0;
449     XtSetArg(args[n], XmNallowOverlap, False); n++;
450     XtSetArg(args[n], XmNchildType, XmWORK_AREA);  n++;
451     inputMethodForm = 
452         XmCreateForm(i18n.inputMethodTB, "inputMethodForm", args, n);
453
454     n = 0;
455     string = CMPSTR((char *)GETMESSAGE(19, 4, "Input Method Start Mode"));
456     XtSetArg(args[n], XmNtitleString, string);  n++;
457     widgetList1[count++] = i18n.imStartModeTB =
458         _DtCreateTitleBox(form, "imStartModeTB", args, n);
459     XmStringFree(string);
460
461     n = 0;
462     XtSetArg(args[n], XmNallowOverlap, False); n++;
463     XtSetArg(args[n], XmNchildType, XmWORK_AREA);  n++;
464     imStartModeForm = 
465         XmCreateForm(i18n.imStartModeTB, "imStartModeForm", args, n);
466
467     n = 0;
468     string = CMPSTR((char *)GETMESSAGE(19, 5, "Preedit Type"));
469     XtSetArg(args[n], XmNtitleString, string);  n++;
470     widgetList1[count++] = i18n.preeditTypeTB =
471         _DtCreateTitleBox(form, "preeditTypeTB", args, n);
472     XmStringFree(string);
473
474     n = 0;
475     XtSetArg(args[n], XmNallowOverlap, False); n++;
476     XtSetArg(args[n], XmNchildType, XmWORK_AREA);  n++;
477     preeditTypeForm = 
478         XmCreateForm(i18n.preeditTypeTB, "preeditTypeForm", args, n);
479
480     /* Create widgets inside the inputMethodForm */
481     n = 0;
482     string = CMPSTR((char *)GETMESSAGE(19, 6, "Server Host :"));
483     XtSetArg(args[n], XmNlabelString, string); n++;
484     i18n.serverHostLabel = 
485         XmCreateLabelGadget(inputMethodForm, "serverHostLabel", args, n);
486
487     n = 0;
488     XtSetArg(args[n], XmNcomboBoxType, XmDROP_DOWN_COMBO_BOX); n++;
489     i18n.serverHostCB =
490         (Widget) XmCreateComboBox(inputMethodForm, "serverHostCB", args, n);
491
492     XtAddCallback(XtNameToWidget(i18n.serverHostCB, "Text"),
493                   XmNactivateCallback, ServerHostCB, NULL);
494     XtAddCallback(XtNameToWidget(i18n.serverHostCB, "Text"),
495                   XmNfocusCallback, TextFocusCB, NULL);
496     XtAddCallback(XtNameToWidget(i18n.serverHostCB, "Text"),
497                   XmNlosingFocusCallback, TextLosingFocusCB, NULL);
498     
499
500     n = 0;
501     string = CMPSTR((char *)GETMESSAGE(19, 7, "Input Method"));
502     XtSetArg(args[n], XmNlabelString, string); n++;
503     i18n.inputMethodLabel = 
504         XmCreateLabelGadget(inputMethodForm, "inputMethodLabel", args, n);
505
506     n = 0;
507     XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
508     XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
509     i18n.inputMethodRC = 
510         XmCreateRadioBox(inputMethodForm, "inputMethodRC", args, n);
511
512
513     /* Create widgets inside the imStartModeForm */
514     n = 0;
515     XtSetArg(args[n], XmNmarginWidth, 0); n++;
516     XtSetArg(args[n], XmNmarginHeight, 0); n++;
517     i18n.imStartModeRC = 
518         XmCreateRadioBox(imStartModeForm, "imStartModeRC", args, n);
519
520     n = 0;
521     string = CMPSTR((char *)GETMESSAGE(19, 8, "Ask at login"));
522     XtSetArg(args[n], XmNlabelString, string); n++;
523     i18n.askAtLoginTG = 
524         XmCreateToggleButtonGadget(i18n.imStartModeRC, "askAtLoginTG", 
525                                    args, n);
526     XmStringFree(string);
527
528     n = 0;
529     string = CMPSTR((char *)GETMESSAGE(19, 9, "Resume Current Input Method"));
530     XtSetArg(args[n], XmNlabelString, string); n++;
531     i18n.resumeCurrentImTG = 
532         XmCreateToggleButtonGadget(i18n.imStartModeRC, "resumeCurrentImTG", 
533                                    args, n);
534     XmStringFree(string);
535
536     /* Create widgets inside the preeditTypeForm */
537
538     n = 0;
539     XtSetArg(args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
540     i18n.preeditTypeList =
541         (Widget) XmCreateList(preeditTypeForm, "preeditTypeList", args, n);
542
543     n = 0;
544     string = CMPSTR((char *)GETMESSAGE(19, 10, "Move Up"));
545     XtSetArg(args[n], XmNlabelString, string); n++;
546     XtSetArg(args[n], XmNsensitive, False); n++;
547     i18n.buttonMoveUp =
548         XmCreatePushButtonGadget(preeditTypeForm, "buttonMoveUp", args, n);
549     XmStringFree(string);
550
551     n = 0;
552     string = CMPSTR((char *)GETMESSAGE(19, 11, "Move Down"));
553     XtSetArg(args[n], XmNlabelString, string); n++;
554     XtSetArg(args[n], XmNsensitive, False); n++;
555     i18n.buttonMoveDown =
556         XmCreatePushButtonGadget(preeditTypeForm, "buttonMoveDown", args, n);
557     XmStringFree(string);
558
559     XtAddCallback(style.i18nDialog, XmNmapCallback, FormLayoutCB, NULL);
560     XtAddCallback(style.i18nDialog, XmNmapCallback, MapCB, shell);
561     XtAddCallback(style.i18nDialog, XmNcallback, ButtonCB, NULL);
562     XtAddCallback(i18n.systemDefault, XmNactivateCallback, 
563                   SystemDefaultCB, NULL);
564     XtAddCallback(i18n.preeditTypeList, XmNbrowseSelectionCallback, 
565                   ListItemSelectCB, NULL);
566     XtAddCallback(i18n.buttonMoveUp, XmNactivateCallback, 
567                   MoveUpCB, NULL);
568     XtAddCallback(i18n.buttonMoveDown, XmNactivateCallback, 
569                   MoveDownCB, NULL);
570
571     XtManageChild(form);
572     XtManageChildren(widgetList1,count); 
573
574     XtManageChild(inputMethodForm);
575     XtManageChild(imStartModeForm);
576     XtManageChild(preeditTypeForm);
577
578     XtManageChild(i18n.serverHostLabel);
579     XtManageChild(i18n.serverHostCB);
580     XtManageChild(i18n.inputMethodLabel);
581     XtManageChild(i18n.inputMethodRC);
582
583     XtManageChild(i18n.imStartModeRC);
584     XtManageChild(i18n.askAtLoginTG);
585     XtManageChild(i18n.resumeCurrentImTG);
586
587     XtManageChild(i18n.preeditTypeList);
588     XtManageChild(i18n.buttonMoveUp);
589     XtManageChild(i18n.buttonMoveDown);
590
591     return(style.i18nDialog);
592 }
593
594
595 /*+++++++++++++++++++++++++++++++++++++++*/
596 /* FormLayoutCB                          */
597 /*+++++++++++++++++++++++++++++++++++++++*/
598 static void 
599 FormLayoutCB(
600         Widget w,
601         XtPointer client_data,
602         XtPointer call_data )
603 {
604     int              n;
605     Arg              args[MAX_ARGS];
606
607     /* Picture Label */
608     n=0;
609     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);       n++;
610     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
611     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
612     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
613     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
614     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
615     XtSetValues (i18n.pictLabel, args, n);
616
617     /* system Default */
618     n=0;
619     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);       n++;
620     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
621     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
622     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_NONE);       n++;
623     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);       n++;
624     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing);  n++;
625     XtSetValues (i18n.systemDefault, args, n);
626
627     /* Input Method TitleBox */
628     n=0;
629     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
630     XtSetArg(args[n], XmNtopWidget,          i18n.pictLabel);     n++;
631     XtSetArg(args[n], XmNtopOffset,          style.horizontalSpacing);  n++;
632     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
633     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
634     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
635     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM); n++;
636     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing);  n++;
637     XtSetValues (i18n.inputMethodTB, args, n);
638
639     /* Input Method widgets */
640
641     n = 0;
642     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);         n++;
643     XtSetArg(args[n], XmNtopOffset,          2*style.verticalSpacing); n++;
644     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);         n++;
645     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);         n++;
646     XtSetArg(args[n], XmNleftOffset,         0);                     n++;
647     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);         n++;
648     XtSetValues (i18n.serverHostLabel, args, n);
649
650     n = 0;
651     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);         n++;
652     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
653     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);         n++;
654     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_WIDGET);       n++;
655     XtSetArg(args[n], XmNleftWidget,         i18n.serverHostLabel);  n++;
656     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);         n++;
657     XtSetValues (i18n.serverHostCB, args, n);
658
659     n = 0;
660     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);       n++;
661     XtSetArg(args[n], XmNtopWidget,          i18n.serverHostCB);     n++;
662     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
663     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);         n++;
664     XtSetArg(args[n], XmNleftOffset,         0);                     n++;
665     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);         n++;
666     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);         n++;
667     XtSetValues (i18n.inputMethodLabel, args, n);
668
669     n = 0;
670     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);       n++;
671     XtSetArg(args[n], XmNtopWidget,          i18n.inputMethodLabel); n++;
672     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
673     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);         n++;
674     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing); n++;
675     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);         n++;
676     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing); n++;
677     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);         n++;
678     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing); n++;
679     XtSetValues (i18n.inputMethodRC, args, n);
680     
681     /* Input Method Start Mode TitleBox */
682     n=0;
683     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);       n++;
684     XtSetArg(args[n], XmNtopWidget,          i18n.inputMethodTB);    n++;
685     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
686     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);         n++;
687     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);         n++;
688     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing); n++;
689     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);         n++;
690     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing); n++;
691     XtSetValues (i18n.imStartModeTB, args, n);
692
693     /* IM Start Mode RC */
694     n=0;
695     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);          n++;
696     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);  n++;
697     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);          n++;
698     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);          n++;
699     XtSetArg(args[n], XmNleftOffset,         0);                      n++;
700     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);          n++;
701     XtSetArg(args[n], XmNrightOffset,        0);                      n++;
702     XtSetValues (i18n.imStartModeRC, args, n);
703
704     /* Preedit Type TitleBox */
705     n=0;
706     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
707     XtSetArg(args[n], XmNtopWidget,          i18n.imStartModeTB); n++;
708     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
709     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);       n++;
710     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);    n++;
711     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
712     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
713     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM); n++;
714     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing);  n++;
715     XtSetValues (i18n.preeditTypeTB, args, n);
716
717     /* Preedit Type widgets */
718     n = 0;
719     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);     n++;
720     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
721     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);       n++;
722     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);    n++;
723     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
724     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
725     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE); n++;
726     XtSetValues (i18n.preeditTypeList, args, n);
727
728     n = 0;
729     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);     n++;
730     XtSetArg(args[n], XmNtopOffset,          2*style.verticalSpacing); n++;
731     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
732     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_WIDGET);       n++;
733     XtSetArg(args[n], XmNleftWidget,         i18n.preeditTypeList); n++;
734     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
735     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM); n++;
736     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
737     XtSetValues (i18n.buttonMoveUp, args, n);
738
739     n = 0;
740     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
741     XtSetArg(args[n], XmNtopWidget,          i18n.buttonMoveUp); n++;
742     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
743     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
744     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_WIDGET);       n++;
745     XtSetArg(args[n], XmNleftWidget,         i18n.preeditTypeList); n++;
746     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
747     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM); n++;
748     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
749     XtSetValues (i18n.buttonMoveDown, args, n);
750
751     XtRemoveCallback(style.i18nDialog, XmNmapCallback, FormLayoutCB, NULL);
752 }
753
754 /*+++++++++++++++++++++++++++++++++++++++*/
755 /* MapCB                                 */
756 /*+++++++++++++++++++++++++++++++++++++++*/
757 static void 
758 MapCB(
759         Widget w,
760         XtPointer client_data,
761         XtPointer call_data )
762 {
763
764     static int  first_time = 1;
765     int         n;
766     Arg         args[MAX_ARGS];
767
768
769     DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
770
771     if (!save.restoreFlag)
772         putDialog ((Widget)client_data, w);
773    
774     XtRemoveCallback(style.i18nDialog, XmNmapCallback, MapCB, NULL);
775   
776 }
777
778 /*+++++++++++++++++++++++++++++++++++++++*/
779 /* ServerHostCB - get the new hostname,  */
780 /* query its list of im and update the   */
781 /* radio box.                            */
782 /*+++++++++++++++++++++++++++++++++++++++*/
783 static void 
784 ServerHostCB(
785         Widget w,
786         XtPointer client_data,
787         XtPointer call_data )
788 {
789     char *hostname;
790
791      _DtTurnOnHourGlass(i18n.inputMethodTB);
792     /* Get the current hostname in the TextField of the ComboBox, 
793        as string */
794     XtVaGetValues(XtNameToWidget(i18n.serverHostCB,"Text"), 
795                   XmNvalue, &hostname, NULL);
796
797     /* Update the display and query for new IM on this host. */
798     UpdateImList(&i18n_env, hostname);
799 }
800
801 static void 
802 UpdateImList(
803     I18nEnv *env,
804     char *hostname)
805 {
806     Cardinal n,i;
807     Widget *im_tog = NULL;
808     int ret = NoError;
809
810     /* Clean first the existing list */
811     
812     /* destroy toggle in radio box is any */
813     XtVaGetValues(i18n.inputMethodRC, XmNchildren, &im_tog,
814                   XmNnumChildren, &n, NULL);
815     if (n) {
816         XtUnmanageChildren(im_tog, n);
817         for (i=0; i<n; i++) XtDestroyWidget(im_tog[i]);
818         im_tog = NULL;
819     }    
820
821     /* Empty what we used to have here */
822     if (env->ims_sel->ims_list_size) {
823         XtFree((char *) env->ims_sel->ims_list);
824         env->ims_sel->ims_list = NULL;
825         env->ims_sel->ims_list_size = 0 ;
826     }
827
828     /* then update the env struct with new ims name and status */
829     ret = _DtI18nGetImList(env, hostname);
830     if (ret != NoError) {
831         _DtTurnOffHourGlass(i18n.inputMethodTB);
832         _DtI18nErrorDialog(ret);
833     }
834 }
835
836
837 /*+++++++++++++++++++++++++++++++++++++++*/
838 /* SystemDefaultCB                       */
839 /*+++++++++++++++++++++++++++++++++++++++*/
840 static void 
841 SystemDefaultCB(
842         Widget w,
843         XtPointer client_data,
844         XtPointer call_data )
845 {
846     static XmStringTable preeditTable = NULL ;
847     Cardinal i;
848     I18nEnv *env;
849
850     env = &i18n_env;
851
852     /* Set the Server Host to local, that is use the NULL string */
853     XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"), 
854                   XmNvalue, "local", NULL);  
855
856     UpdateImList(env, "local");
857
858     /* Set the Input Method Start Mode to Ask at login */
859     XmToggleButtonGadgetSetState(i18n.askAtLoginTG, True, True);
860
861     if (!preeditTable) {
862         /* Set the preeditType list to the default in Motif */
863         preeditTable = (XmStringTable) XtMalloc(NUM_PREEDIT * 
864                                                 sizeof( XmString ));
865         for ( i = 0; i < NUM_PREEDIT; i ++ )
866             preeditTable[i] = XmStringCreate(defaultPreedit[i],
867                                              "ISO8859-1");
868     }
869     
870     SetPreeditType(env, preeditTable, NUM_PREEDIT);
871
872     /* Mark that the preeditType list has changed. */
873     i18n.preeditHasChanged = True;
874
875     return;
876
877 }
878
879 /*+++++++++++++++++++++++++++++++++++++++*/
880 /* TextFocusCB - disable the default     */
881 /* button in the dialog, so that return  */
882 /* in the TextField doesn't activate it. */
883 /*+++++++++++++++++++++++++++++++++++++++*/
884 static void 
885 TextFocusCB(
886         Widget w,
887         XtPointer client_data,
888         XtPointer call_data )
889 {
890     XtVaGetValues(style.i18nDialog, XmNdefaultButton, &i18n.defaultButton,
891                   NULL);
892     XtVaSetValues(style.i18nDialog, XmNdefaultButton, NULL, NULL);
893
894     return;
895
896 }
897
898 /*+++++++++++++++++++++++++++++++++++++++*/
899 /* TextLosingFocusCB - enable the        */
900 /* default button, so that return key in */
901 /* the dialog activate it.               */
902 /*+++++++++++++++++++++++++++++++++++++++*/
903 static void 
904 TextLosingFocusCB(
905         Widget w,
906         XtPointer client_data,
907         XtPointer call_data )
908 {
909     XtVaSetValues(style.i18nDialog, XmNdefaultButton, i18n.defaultButton,
910                   NULL);
911     
912     return;
913
914 }
915
916 /*+++++++++++++++++++++++++++++++++++++++*/
917 /* ButtonCB                              */
918 /* callback for PushButtons in DialogBox */
919 /*+++++++++++++++++++++++++++++++++++++++*/
920 static void 
921 ButtonCB(
922         Widget w,
923         XtPointer client_data,
924         XtPointer call_data )
925 {
926   int         n;
927   int         ret = NoError;
928   I18nEnv     *env;
929   DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
930
931   env = &i18n_env;
932
933   switch (cb->button_position)
934     {
935     case OK_BUTTON:
936
937       ret = SaveSelectedValues(env);
938       XtUnmanageChild (w);
939
940       break;
941       
942       
943     case CANCEL_BUTTON:
944     
945       XtUnmanageChild(w);
946
947       /* reset the i18n values from last saved values */
948       ResetLastSavedValues(env);
949
950       if (i18n.preeditHasChanged) {
951           /* Reset the preeditType value from the saved one. */
952           SetPreeditType(env, i18n.preeditSavedVal, i18n.preeditSavedNum);
953
954           i18n.preeditHasChanged = False;
955       }
956       break;
957     
958   case HELP_BUTTON:
959     XtCallCallbacks(style.i18nDialog, XmNhelpCallback, (XtPointer)NULL);
960     break;
961     
962   default:
963     break;
964   }
965 }
966
967 static int
968 SaveSelectedValues(
969       I18nEnv *env)
970 {
971     int ret = NoError;
972     char *preeditStr = NULL, *tmpStr;
973     int i, num_preedit = 0;
974     XmStringTable list_preedit;
975     static char preeditTypeRes[1024];
976
977     /* Get the values from the UI and update the FileSel structure */
978     SetFileSelValues(env);
979
980     /* Write these values in the IMS Selection File */
981     ret = _DtI18nWriteImSelectionFile(env);
982
983     /* Save the preeditType resource value if needed */
984     if (i18n.preeditHasChanged) {
985
986         if (style.xrdb.writeXrdbImmediate)
987             InfoDialog(MSG_IMMEDIATE, style.shell, False);
988         else
989             InfoDialog(MSG_LATER, style.shell, False);
990
991         /* generate a string from the list to set the resource */
992         XtVaGetValues(i18n.preeditTypeList,
993                       XmNitemCount, &num_preedit,
994                       XmNitems, &list_preedit, NULL);
995
996         /* Save this value in case of a Cancel */
997         if (i18n.preeditSavedVal) {
998             FreeST(i18n.preeditSavedVal, i18n.preeditSavedNum);
999         }
1000
1001         i18n.preeditSavedVal = CopyST(list_preedit, num_preedit);
1002         i18n.preeditSavedNum = num_preedit;
1003
1004         for (i = 0; i < num_preedit; i++) {
1005             /* get the text of the XmString */
1006             tmpStr = XmStringUnparse(list_preedit[i], NULL, XmCHARSET_TEXT, 
1007                                      XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
1008             /* realloc mallocs the first time */
1009             preeditStr = XtRealloc(preeditStr, 
1010                                    strlen(preeditStr) + strlen(tmpStr) + 2);
1011
1012             /* insert the comma before the second, third. etc */
1013             if (i != 0) {
1014                 strcat(preeditStr, ",");
1015                 strcat(preeditStr, tmpStr);
1016             }
1017             else
1018                 strcpy(preeditStr, tmpStr);
1019
1020             XtFree(tmpStr);
1021         }
1022
1023         /* if writeXrdbImmediate true write to Xrdb else send to 
1024            session mgr */
1025
1026         sprintf(preeditTypeRes, "*preeditType: %s\n", preeditStr);
1027
1028         XtFree(preeditStr);
1029
1030         if(style.xrdb.writeXrdbImmediate)
1031             _DtAddToResource(style.display, preeditTypeRes);
1032
1033         SmNewPreeditSettings(preeditTypeRes);
1034
1035         /* Reset the state of the list. */
1036         i18n.preeditHasChanged = False;
1037     }
1038
1039     return (ret);
1040
1041 }
1042
1043 static void 
1044 SetFileSelValues(
1045      I18nEnv *env
1046 )
1047 {
1048     char *hostname;
1049     Cardinal n,i;
1050     Widget *im_tog;
1051
1052     /* The hostname value is stored in the ImsSel structure. */
1053     env->file_sel->hostname = XtNewString(env->ims_sel->host_name);
1054
1055     /* Get the selected IM from the selected Toggle button */
1056     XtVaGetValues(i18n.inputMethodRC, XmNchildren, &im_tog,
1057                   XmNnumChildren, &n, NULL);
1058     if (n) {
1059         for (i=0; i<n; i++) {
1060             if (XmToggleButtonGadgetGetState(im_tog[i]) == TRUE) {
1061                 XtVaGetValues(im_tog[i], XmNuserData, 
1062                               &(env->file_sel->im_name),
1063                               NULL);
1064                 break;
1065             }
1066         }
1067     }
1068     else
1069         env->file_sel->im_name = NULL;
1070
1071     /* Get the start mode from the askAtLoginTG state */
1072     if (XmToggleButtonGadgetGetState(i18n.askAtLoginTG) == TRUE)
1073         env->file_sel->start_mode = 0;
1074     else
1075         env->file_sel->start_mode = 1;
1076 }
1077
1078 static void
1079 ResetLastSavedValues(
1080      I18nEnv *env
1081 )
1082 {
1083     if (env->file_sel->start_mode == -1) return;
1084
1085     /* Reset the TextField of the ComboBox to the last saved hostname. */
1086     XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"), 
1087                   XmNvalue, env->file_sel->hostname, NULL);  
1088
1089     UpdateImList(env, env->file_sel->hostname);
1090
1091     /* Reset the saved start mode */
1092     SetImsMode(env);
1093
1094 }
1095
1096 /************************************************************************
1097  * restoreI18n()
1098  * restore any state information saved with savei18n.
1099  * This is called from restoreSession with the application
1100  * shell and the special xrm database retrieved for restore.
1101  ************************************************************************/
1102 void 
1103 restoreI18n(
1104         Widget shell,
1105         XrmDatabase db )
1106 {
1107     XrmName xrm_name[5];
1108     XrmRepresentation rep_type;
1109     XrmValue value;
1110
1111     xrm_name [0] = XrmStringToQuark ("i18nDlg");
1112     xrm_name [2] = NULL;
1113
1114     /* get x position */
1115     xrm_name [1] = XrmStringToQuark ("x");
1116     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1117       XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); 
1118       save.poscnt++;
1119       save.restoreFlag = True;
1120     }
1121
1122     /* get y position */
1123     xrm_name [1] = XrmStringToQuark ("y");
1124     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1125       XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
1126     }
1127
1128     xrm_name [1] = XrmStringToQuark ("ismapped");
1129     XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1130     /* Are we supposed to be mapped? */
1131     if (strcmp(value.addr, "True") == 0) 
1132       popup_i18nBB(shell);
1133 }
1134
1135 /************************************************************************
1136  * saveI18n()
1137  *
1138  * This routine will write out to the passed file descriptor any state
1139  * information this dialog needs.  It is called from saveSessionCB with the
1140  * file already opened.
1141  * All information is saved in xrm format.  There is no restriction
1142  * on what can be saved.  It doesn't have to be defined or be part of any
1143  * widget or Xt definition.  Just name and save it here and recover it in
1144  * restoreBackdrop.  The suggested minimum is whether you are mapped, and your
1145  * location.
1146  ************************************************************************/
1147 void 
1148 saveI18n(
1149         int fd )
1150 {
1151     Position x,y;
1152     Dimension width, height;
1153     char *bufr = style.tmpBigStr;     /* size=[1024], make bigger if needed */
1154     XmVendorShellExtObject  vendorExt;
1155     XmWidgetExtData         extData;
1156
1157     if (style.i18nDialog != NULL) 
1158     {
1159         if (XtIsManaged(style.i18nDialog))
1160             sprintf(bufr, "*i18nDlg.ismapped: True\n");
1161         else
1162             sprintf(bufr, "*i18nDlg.ismapped: False\n");
1163
1164         /* Get and write out the geometry info for our Window */
1165         x = XtX(XtParent(style.i18nDialog));
1166         y = XtY(XtParent(style.i18nDialog));
1167
1168         /* Modify x & y to take into account window mgr frames
1169          * This is pretty bogus, but I don't know a better way to do it.
1170          */
1171         extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1172         vendorExt = (XmVendorShellExtObject)extData->widget;
1173         x -= vendorExt->vendor.xOffset;
1174         y -= vendorExt->vendor.yOffset;
1175
1176         width = XtWidth(style.i18nDialog);
1177         height = XtHeight(style.i18nDialog);
1178
1179         sprintf(bufr, "%s*i18nDlg.x: %d\n", bufr, x);
1180         sprintf(bufr, "%s*i18nDlg.y: %d\n", bufr, y);
1181         sprintf(bufr, "%s*i18nDlg.width: %d\n", bufr, width);
1182         sprintf(bufr, "%s*i18nDlg.height: %d\n", bufr, height);
1183         write (fd, bufr, strlen(bufr));
1184     }
1185 }
1186
1187
1188 /*+++++++++++++++++++++++++++++++++++++++*/
1189 /* cancelWarnCB - callback for the       */
1190 /* cancel button of the warnDialog       */
1191 /*+++++++++++++++++++++++++++++++++++++++*/
1192
1193 static void 
1194 CancelWarnCB(
1195         Widget w,
1196         XtPointer client_data,
1197         XtPointer call_data )
1198 {
1199     return;
1200 }
1201
1202
1203
1204
1205 /*+++++++++++++++++++++++++++++++++++++++*/
1206 /* okWarnCB - callback for the           */
1207 /* OK button of the warnDialog           */
1208 /*+++++++++++++++++++++++++++++++++++++++*/
1209
1210 static void 
1211 OkWarnCB(
1212         Widget w,
1213         XtPointer client_data,
1214         XtPointer call_data )
1215 {
1216     return;
1217 }
1218
1219
1220 /*+++++++++++++++++++++++++++++++++++++++*/
1221 /* _DtI18nSetSensitiveImTB - set the     */
1222 /* sensitivity of the TitleBox. This is  */
1223 /* used when changing host, while getting*/
1224 /* information.                          */
1225 /* Also recreate the toggle list.        */
1226 /*+++++++++++++++++++++++++++++++++++++++*/
1227
1228 void 
1229 _DtI18nSetSensitiveImTB(
1230                         I18nEnv * env,
1231                         Boolean sensitivity )
1232 {
1233     static Boolean first_time = True;
1234
1235     XtSetSensitive(i18n.inputMethodRC, sensitivity);
1236
1237     if (sensitivity) {
1238         SetImsToggleList(env);
1239         /* Save the initial values in case of a Cancel */
1240         if (first_time) {
1241             SetFileSelValues(env);
1242             first_time = False;
1243         }
1244     }
1245
1246 }
1247
1248
1249 void
1250 _DtI18nErrorDialog(
1251     int err
1252 )
1253 {
1254     char *err_str;
1255
1256     switch(err) {
1257
1258     case ErrNoHome: 
1259         err_str = GETMESSAGE(19, 30, 
1260                              "The environment variable HOME is not defined.");
1261         break;
1262     case ErrNoLocale:
1263         err_str = GETMESSAGE(19, 31, 
1264                              "The environment variable LANG is not defined.");
1265         break;
1266     case ErrNoCDELocale:
1267         err_str = GETMESSAGE(19, 32, 
1268                              "This locale is not supported by the desktop.");
1269         break;
1270
1271         /* File I/O */
1272     case ErrFileCreate: 
1273         err_str = GETMESSAGE(19, 33, 
1274                        "Cannot create the user Input Method Selection file");
1275         break;
1276
1277         /* Selection */
1278     case ErrNoSelectionFile:
1279         err_str = GETMESSAGE(19, 34, 
1280                              "Cannot find the user Input Method Selection file.");
1281         break;
1282     case ErrSaveSelection:      
1283         err_str = GETMESSAGE(19, 35, 
1284                              "Cannot save the user Input Method Selection file.");
1285         break;
1286
1287         /* Remote */
1288     case ErrUnknownHost:        
1289         err_str = GETMESSAGE(19, 36, "Unknown host");
1290         break;
1291     case ErrNoDtimsstart:
1292         err_str = GETMESSAGE(19, 37, 
1293                              "dtimsstart was not found.\nPerhaps the desktop environment\nis not properly installed.");
1294         break;
1295     case ErrRemoteFailed:
1296         err_str = GETMESSAGE(19, 38, "Remote execution failed on\n the selected host.");
1297
1298         /* Pipe */
1299     case ErrNoPopen:
1300         err_str = GETMESSAGE(19, 39, "Cannot initialize remote execution");
1301         break;
1302     case ErrTimeOut:
1303         err_str = GETMESSAGE(19, 40, "Getting the Input Method on the \nselected host is taking too long");
1304         break;
1305
1306     default:
1307         err_str = GETMESSAGE(19, 41, "Unknown error");
1308         break;
1309     }
1310
1311     ErrDialog(err_str, style.i18nDialog);
1312 }
1313
1314 /*+++++++++++++++++++++++++++++++++++++++*/
1315 /* ListItemSelectCB - callback for the   */
1316 /* selection on an item in the preedit   */
1317 /* Type List.                            */
1318 /*+++++++++++++++++++++++++++++++++++++++*/
1319
1320 static void 
1321 ListItemSelectCB(
1322         Widget w,
1323         XtPointer client_data,
1324         XtPointer call_data )
1325 {
1326     XmListCallbackStruct *listCBS = (XmListCallbackStruct *) call_data;
1327
1328     /* Set the sensitivity of the MoveUp and MoveDown buttons depending 
1329        on the selected item position. MoveUp is insensitive is the first
1330        item in the list is selected; MoveDown is insensitive if the last 
1331        item in the list is selected */
1332
1333     if (listCBS->item_position == 1)
1334         XtSetSensitive(i18n.buttonMoveUp, False);
1335     else
1336         XtSetSensitive(i18n.buttonMoveUp, True);
1337
1338     if (listCBS->item_position == i18n.preeditTypeListLastPos)
1339         XtSetSensitive(i18n.buttonMoveDown, False);
1340     else
1341         XtSetSensitive(i18n.buttonMoveDown, True);
1342
1343     return;
1344 }
1345
1346 /*+++++++++++++++++++++++++++++++++++++++*/
1347 /* MoveUpCB - callback for the           */
1348 /* MoveUp button                         */
1349 /*+++++++++++++++++++++++++++++++++++++++*/
1350
1351 static void 
1352 MoveUpCB(
1353         Widget w,
1354         XtPointer client_data,
1355         XtPointer call_data )
1356 {
1357     int *position_list;
1358     int position_count;
1359
1360     if (XmListGetSelectedPos(i18n.preeditTypeList, &position_list, 
1361                              &position_count)) {
1362
1363         /* there should be only one selected per our selection
1364            policy set on the list, but consider the first selected one 
1365            in any case */
1366
1367         /* this should always be the case as the MoveUp button should be
1368            insensitive when the first item is selected, but check anyway */
1369
1370         if (position_list[0] > 1) {
1371             XmStringTable list_items;
1372             XmString items[2];
1373             int sel_pos = position_list[0];
1374             int sel_index = sel_pos - 1;
1375
1376             XtVaGetValues(i18n.preeditTypeList, XmNitems, &list_items, NULL);
1377
1378             /* makes an array of two XmStrings by reversing the selected
1379                one and the item preceeding it */
1380             items[0] = list_items[sel_index];
1381             items[1] = list_items[sel_index - 1];
1382
1383             /* this call preserves selected state */
1384             XmListReplaceItemsPos(i18n.preeditTypeList,
1385                                   items, 2,
1386                                   sel_pos - 1);
1387
1388             if (sel_pos == 2) {
1389                 /* it's now 1, so set the MoveUp button insensitive */
1390                 XtSetSensitive(i18n.buttonMoveUp, False);
1391             }
1392
1393             if (sel_pos == i18n.preeditTypeListLastPos) {
1394                 /* it's not anymore the last one, so set the MoveDown 
1395                    button sensitive */
1396                 XtSetSensitive(i18n.buttonMoveDown, True);
1397             }
1398
1399             /* preeditType has changed */
1400             i18n.preeditHasChanged = True;
1401         }
1402     }
1403 }
1404
1405 /*+++++++++++++++++++++++++++++++++++++++*/
1406 /* MoveDownCB - callback for the         */
1407 /* MoveDown button                       */
1408 /*+++++++++++++++++++++++++++++++++++++++*/
1409
1410 static void 
1411 MoveDownCB(
1412         Widget w,
1413         XtPointer client_data,
1414         XtPointer call_data )
1415 {
1416     int *position_list;
1417     int position_count;
1418
1419     if (XmListGetSelectedPos(i18n.preeditTypeList, &position_list, 
1420                              &position_count)) {
1421
1422         /* there should be only one selected per our selection
1423            policy set on the list, but consider the first selected one 
1424            in any case */
1425
1426         /* this should always be the case as the Move Down button should be
1427            insensitive when the first item is selected, but check anyway */
1428
1429         if (position_list[0] != i18n.preeditTypeListLastPos) {
1430             XmStringTable list_items;
1431             XmString items[2];
1432             int sel_pos = position_list[0];
1433             int sel_index = sel_pos - 1;
1434
1435             XtVaGetValues(i18n.preeditTypeList, XmNitems, &list_items, NULL);
1436
1437             /* makes an array of two XmStrings by reversing the selected
1438                one and the item succeeding it */
1439             items[0] = list_items[sel_index + 1];
1440             items[1] = list_items[sel_index];
1441
1442             /* this call preserves selected state */
1443             XmListReplaceItemsPos(i18n.preeditTypeList,
1444                                   items, 2,
1445                                   sel_pos);
1446
1447             if (sel_pos == (i18n.preeditTypeListLastPos - 1)) {
1448                 /* it's now the last one, so set the MoveDown button 
1449                    insensitive */
1450                 XtSetSensitive(i18n.buttonMoveDown, False);
1451             }
1452
1453             if (sel_pos == 1) {
1454                 /* it's not anymore the first one, so set the MoveUp 
1455                    button sensitive */
1456                 XtSetSensitive(i18n.buttonMoveUp, True);
1457             }
1458
1459             /* preeditType has changed */
1460             i18n.preeditHasChanged = True;
1461         }
1462     }
1463
1464 }
1465
1466
1467 static XmStringTable
1468 CopyST (XmStringTable st, int nst)
1469 {
1470     XmStringTable lst = (XmStringTable) XtMalloc(sizeof(XmString) * nst);
1471     int i ;
1472
1473     for (i=0; i < nst ; i++) {
1474         lst[i] = XmStringCopy(st[i]);
1475     }
1476
1477     return lst ;
1478 }
1479
1480
1481 static void
1482 FreeST (XmStringTable st, int nst)
1483 {
1484     int i;
1485
1486     for (i=0; i < nst ; i++) {
1487        XmStringFree(st[i]);
1488     }
1489
1490     XtFree((char*)st);
1491 }
1492