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