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