cea3c9f6bad831eb24543c55fc1bb448c024e719
[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 n,i;
829     Widget *im_tog = NULL;
830     int ret = NoError;
831
832     /* Clean first the existing list */
833     
834     /* destroy toggle in radio box is any */
835     XtVaGetValues(i18n.inputMethodRC, XmNchildren, &im_tog,
836                   XmNnumChildren, &n, NULL);
837     if (n) {
838         XtUnmanageChildren(im_tog, n);
839         for (i=0; i<n; i++) XtDestroyWidget(im_tog[i]);
840         im_tog = NULL;
841     }    
842
843     /* Empty what we used to have here */
844     if (env->ims_sel->ims_list_size) {
845         XtFree((char *) env->ims_sel->ims_list);
846         env->ims_sel->ims_list = NULL;
847         env->ims_sel->ims_list_size = 0 ;
848     }
849
850     /* then update the env struct with new ims name and status */
851     ret = _DtI18nGetImList(env, hostname);
852     if (ret != NoError) {
853         _DtTurnOffHourGlass(i18n.inputMethodTB);
854         _DtI18nErrorDialog(ret);
855     }
856 }
857
858
859 /*+++++++++++++++++++++++++++++++++++++++*/
860 /* SystemDefaultCB                       */
861 /*+++++++++++++++++++++++++++++++++++++++*/
862 static void 
863 SystemDefaultCB(
864         Widget w,
865         XtPointer client_data,
866         XtPointer call_data )
867 {
868     static XmStringTable preeditTable = NULL ;
869     Cardinal i;
870     I18nEnv *env;
871
872     env = &i18n_env;
873
874     /* Set the Server Host to local, that is use the NULL string */
875     XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"), 
876                   XmNvalue, "local", NULL);  
877
878     UpdateImList(env, "local");
879
880     /* Set the Input Method Start Mode to Ask at login */
881     XmToggleButtonGadgetSetState(i18n.askAtLoginTG, True, True);
882
883     if (!preeditTable) {
884         /* Set the preeditType list to the default in Motif */
885         preeditTable = (XmStringTable) XtMalloc(NUM_PREEDIT * 
886                                                 sizeof( XmString ));
887         for ( i = 0; i < NUM_PREEDIT; i ++ )
888             preeditTable[i] = XmStringCreate(defaultPreedit[i],
889                                              "ISO8859-1");
890     }
891     
892     SetPreeditType(env, preeditTable, NUM_PREEDIT);
893
894     /* Mark that the preeditType list has changed. */
895     i18n.preeditHasChanged = True;
896
897     return;
898
899 }
900
901 /*+++++++++++++++++++++++++++++++++++++++*/
902 /* TextFocusCB - disable the default     */
903 /* button in the dialog, so that return  */
904 /* in the TextField doesn't activate it. */
905 /*+++++++++++++++++++++++++++++++++++++++*/
906 static void 
907 TextFocusCB(
908         Widget w,
909         XtPointer client_data,
910         XtPointer call_data )
911 {
912     XtVaGetValues(style.i18nDialog, XmNdefaultButton, &i18n.defaultButton,
913                   NULL);
914     XtVaSetValues(style.i18nDialog, XmNdefaultButton, NULL, NULL);
915
916     return;
917
918 }
919
920 /*+++++++++++++++++++++++++++++++++++++++*/
921 /* TextLosingFocusCB - enable the        */
922 /* default button, so that return key in */
923 /* the dialog activate it.               */
924 /*+++++++++++++++++++++++++++++++++++++++*/
925 static void 
926 TextLosingFocusCB(
927         Widget w,
928         XtPointer client_data,
929         XtPointer call_data )
930 {
931     XtVaSetValues(style.i18nDialog, XmNdefaultButton, i18n.defaultButton,
932                   NULL);
933     
934     return;
935
936 }
937
938 /*+++++++++++++++++++++++++++++++++++++++*/
939 /* ButtonCB                              */
940 /* callback for PushButtons in DialogBox */
941 /*+++++++++++++++++++++++++++++++++++++++*/
942 static void 
943 ButtonCB(
944         Widget w,
945         XtPointer client_data,
946         XtPointer call_data )
947 {
948   int         n;
949   int         ret = NoError;
950   I18nEnv     *env;
951   DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
952
953   env = &i18n_env;
954
955   switch (cb->button_position)
956     {
957     case OK_BUTTON:
958
959       ret = SaveSelectedValues(env);
960       XtUnmanageChild (w);
961
962       break;
963       
964       
965     case CANCEL_BUTTON:
966     
967       XtUnmanageChild(w);
968
969       /* reset the i18n values from last saved values */
970       ResetLastSavedValues(env);
971
972       if (i18n.preeditHasChanged) {
973           /* Reset the preeditType value from the saved one. */
974           SetPreeditType(env, i18n.preeditSavedVal, i18n.preeditSavedNum);
975
976           i18n.preeditHasChanged = False;
977       }
978       break;
979     
980   case HELP_BUTTON:
981     XtCallCallbacks(style.i18nDialog, XmNhelpCallback, (XtPointer)NULL);
982     break;
983     
984   default:
985     break;
986   }
987 }
988
989 static int
990 SaveSelectedValues(
991       I18nEnv *env)
992 {
993     int ret = NoError;
994     char *preeditStr = NULL, *tmpStr;
995     int i, num_preedit = 0;
996     XmStringTable list_preedit;
997     static char preeditTypeRes[1024];
998
999     /* Get the values from the UI and update the FileSel structure */
1000     SetFileSelValues(env);
1001
1002     /* Write these values in the IMS Selection File */
1003     ret = _DtI18nWriteImSelectionFile(env);
1004
1005     /* Save the preeditType resource value if needed */
1006     if (i18n.preeditHasChanged) {
1007
1008         if (style.xrdb.writeXrdbImmediate)
1009             InfoDialog(MSG_IMMEDIATE, style.shell, False);
1010         else
1011             InfoDialog(MSG_LATER, style.shell, False);
1012
1013         /* generate a string from the list to set the resource */
1014         XtVaGetValues(i18n.preeditTypeList,
1015                       XmNitemCount, &num_preedit,
1016                       XmNitems, &list_preedit, NULL);
1017
1018         /* Save this value in case of a Cancel */
1019         if (i18n.preeditSavedVal) {
1020             FreeST(i18n.preeditSavedVal, i18n.preeditSavedNum);
1021         }
1022
1023         i18n.preeditSavedVal = CopyST(list_preedit, num_preedit);
1024         i18n.preeditSavedNum = num_preedit;
1025
1026         for (i = 0; i < num_preedit; i++) {
1027             /* get the text of the XmString */
1028             tmpStr = XmStringUnparse(list_preedit[i], NULL, XmCHARSET_TEXT, 
1029                                      XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
1030             /* realloc mallocs the first time */
1031             preeditStr = XtRealloc(preeditStr, 
1032                                    strlen(preeditStr) + strlen(tmpStr) + 2);
1033
1034             /* insert the comma before the second, third. etc */
1035             if (i != 0) {
1036                 strcat(preeditStr, ",");
1037                 strcat(preeditStr, tmpStr);
1038             }
1039             else
1040                 strcpy(preeditStr, tmpStr);
1041
1042             XtFree(tmpStr);
1043         }
1044
1045         /* if writeXrdbImmediate true write to Xrdb else send to 
1046            session mgr */
1047
1048         sprintf(preeditTypeRes, "*preeditType: %s\n", preeditStr);
1049
1050         XtFree(preeditStr);
1051
1052         if(style.xrdb.writeXrdbImmediate)
1053             _DtAddToResource(style.display, preeditTypeRes);
1054
1055         SmNewPreeditSettings(preeditTypeRes);
1056
1057         /* Reset the state of the list. */
1058         i18n.preeditHasChanged = False;
1059     }
1060
1061     return (ret);
1062
1063 }
1064
1065 static void 
1066 SetFileSelValues(
1067      I18nEnv *env
1068 )
1069 {
1070     char *hostname;
1071     Cardinal n,i;
1072     Widget *im_tog;
1073
1074     /* The hostname value is stored in the ImsSel structure. */
1075     env->file_sel->hostname = XtNewString(env->ims_sel->host_name);
1076
1077     /* Get the selected IM from the selected Toggle button */
1078     XtVaGetValues(i18n.inputMethodRC, XmNchildren, &im_tog,
1079                   XmNnumChildren, &n, NULL);
1080     if (n) {
1081         for (i=0; i<n; i++) {
1082             if (XmToggleButtonGadgetGetState(im_tog[i]) == TRUE) {
1083                 XtVaGetValues(im_tog[i], XmNuserData, 
1084                               &(env->file_sel->im_name),
1085                               NULL);
1086                 break;
1087             }
1088         }
1089     }
1090     else
1091         env->file_sel->im_name = NULL;
1092
1093     /* Get the start mode from the askAtLoginTG state */
1094     if (XmToggleButtonGadgetGetState(i18n.askAtLoginTG) == TRUE)
1095         env->file_sel->start_mode = 0;
1096     else
1097         env->file_sel->start_mode = 1;
1098 }
1099
1100 static void
1101 ResetLastSavedValues(
1102      I18nEnv *env
1103 )
1104 {
1105     if (env->file_sel->start_mode == -1) return;
1106
1107     /* Reset the TextField of the ComboBox to the last saved hostname. */
1108     XtVaSetValues(XtNameToWidget(i18n.serverHostCB,"Text"), 
1109                   XmNvalue, env->file_sel->hostname, NULL);  
1110
1111     UpdateImList(env, env->file_sel->hostname);
1112
1113     /* Reset the saved start mode */
1114     SetImsMode(env);
1115
1116 }
1117
1118 /************************************************************************
1119  * restoreI18n()
1120  * restore any state information saved with savei18n.
1121  * This is called from restoreSession with the application
1122  * shell and the special xrm database retrieved for restore.
1123  ************************************************************************/
1124 void 
1125 restoreI18n(
1126         Widget shell,
1127         XrmDatabase db )
1128 {
1129     XrmName xrm_name[5];
1130     XrmRepresentation rep_type;
1131     XrmValue value;
1132
1133     xrm_name [0] = XrmStringToQuark ("i18nDlg");
1134     xrm_name [2] = 0;
1135
1136     /* get x position */
1137     xrm_name [1] = XrmStringToQuark ("x");
1138     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1139       XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); 
1140       save.poscnt++;
1141       save.restoreFlag = True;
1142     }
1143
1144     /* get y position */
1145     xrm_name [1] = XrmStringToQuark ("y");
1146     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
1147       XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
1148     }
1149
1150     xrm_name [1] = XrmStringToQuark ("ismapped");
1151     XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
1152     /* Are we supposed to be mapped? */
1153     if (strcmp(value.addr, "True") == 0) 
1154       popup_i18nBB(shell);
1155 }
1156
1157 /************************************************************************
1158  * saveI18n()
1159  *
1160  * This routine will write out to the passed file descriptor any state
1161  * information this dialog needs.  It is called from saveSessionCB with the
1162  * file already opened.
1163  * All information is saved in xrm format.  There is no restriction
1164  * on what can be saved.  It doesn't have to be defined or be part of any
1165  * widget or Xt definition.  Just name and save it here and recover it in
1166  * restoreBackdrop.  The suggested minimum is whether you are mapped, and your
1167  * location.
1168  ************************************************************************/
1169 void 
1170 saveI18n(
1171         int fd )
1172 {
1173     Position x,y;
1174     Dimension width, height;
1175     char *bufr = style.tmpBigStr;     /* size=[1024], make bigger if needed */
1176     XmVendorShellExtObject  vendorExt;
1177     XmWidgetExtData         extData;
1178
1179     if (style.i18nDialog != NULL) 
1180     {
1181         if (XtIsManaged(style.i18nDialog))
1182             sprintf(bufr, "*i18nDlg.ismapped: True\n");
1183         else
1184             sprintf(bufr, "*i18nDlg.ismapped: False\n");
1185
1186         /* Get and write out the geometry info for our Window */
1187         x = XtX(XtParent(style.i18nDialog));
1188         y = XtY(XtParent(style.i18nDialog));
1189
1190         /* Modify x & y to take into account window mgr frames
1191          * This is pretty bogus, but I don't know a better way to do it.
1192          */
1193         extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
1194         vendorExt = (XmVendorShellExtObject)extData->widget;
1195         x -= vendorExt->vendor.xOffset;
1196         y -= vendorExt->vendor.yOffset;
1197
1198         width = XtWidth(style.i18nDialog);
1199         height = XtHeight(style.i18nDialog);
1200
1201         sprintf(bufr, "%s*i18nDlg.x: %d\n", bufr, x);
1202         sprintf(bufr, "%s*i18nDlg.y: %d\n", bufr, y);
1203         sprintf(bufr, "%s*i18nDlg.width: %d\n", bufr, width);
1204         sprintf(bufr, "%s*i18nDlg.height: %d\n", bufr, height);
1205         write (fd, bufr, strlen(bufr));
1206     }
1207 }
1208
1209
1210 /*+++++++++++++++++++++++++++++++++++++++*/
1211 /* cancelWarnCB - callback for the       */
1212 /* cancel button of the warnDialog       */
1213 /*+++++++++++++++++++++++++++++++++++++++*/
1214
1215 static void 
1216 CancelWarnCB(
1217         Widget w,
1218         XtPointer client_data,
1219         XtPointer call_data )
1220 {
1221     return;
1222 }
1223
1224
1225
1226
1227 /*+++++++++++++++++++++++++++++++++++++++*/
1228 /* okWarnCB - callback for the           */
1229 /* OK button of the warnDialog           */
1230 /*+++++++++++++++++++++++++++++++++++++++*/
1231
1232 static void 
1233 OkWarnCB(
1234         Widget w,
1235         XtPointer client_data,
1236         XtPointer call_data )
1237 {
1238     return;
1239 }
1240
1241
1242 /*+++++++++++++++++++++++++++++++++++++++*/
1243 /* _DtI18nSetSensitiveImTB - set the     */
1244 /* sensitivity of the TitleBox. This is  */
1245 /* used when changing host, while getting*/
1246 /* information.                          */
1247 /* Also recreate the toggle list.        */
1248 /*+++++++++++++++++++++++++++++++++++++++*/
1249
1250 void 
1251 _DtI18nSetSensitiveImTB(
1252                         I18nEnv * env,
1253                         Boolean sensitivity )
1254 {
1255     static Boolean first_time = True;
1256
1257     XtSetSensitive(i18n.inputMethodRC, sensitivity);
1258
1259     if (sensitivity) {
1260         SetImsToggleList(env);
1261         /* Save the initial values in case of a Cancel */
1262         if (first_time) {
1263             SetFileSelValues(env);
1264             first_time = False;
1265         }
1266     }
1267
1268 }
1269
1270
1271 void
1272 _DtI18nErrorDialog(
1273     int err
1274 )
1275 {
1276     char *err_str;
1277
1278     switch(err) {
1279
1280     case ErrNoHome: 
1281         err_str = GETMESSAGE(19, 30, 
1282                              "The environment variable HOME is not defined.");
1283         break;
1284     case ErrNoLocale:
1285         err_str = GETMESSAGE(19, 31, 
1286                              "The environment variable LANG is not defined.");
1287         break;
1288     case ErrNoCDELocale:
1289         err_str = GETMESSAGE(19, 32, 
1290                              "This locale is not supported by the desktop.");
1291         break;
1292
1293         /* File I/O */
1294     case ErrFileCreate: 
1295         err_str = GETMESSAGE(19, 33, 
1296                        "Cannot create the user Input Method Selection file");
1297         break;
1298
1299         /* Selection */
1300     case ErrNoSelectionFile:
1301         err_str = GETMESSAGE(19, 34, 
1302                              "Cannot find the user Input Method Selection file.");
1303         break;
1304     case ErrSaveSelection:      
1305         err_str = GETMESSAGE(19, 35, 
1306                              "Cannot save the user Input Method Selection file.");
1307         break;
1308
1309         /* Remote */
1310     case ErrUnknownHost:        
1311         err_str = GETMESSAGE(19, 36, "Unknown host");
1312         break;
1313     case ErrNoDtimsstart:
1314         err_str = GETMESSAGE(19, 37, 
1315                              "dtimsstart was not found.\nPerhaps the desktop environment\nis not properly installed.");
1316         break;
1317     case ErrRemoteFailed:
1318         err_str = GETMESSAGE(19, 38, "Remote execution failed on\n the selected host.");
1319
1320         /* Pipe */
1321     case ErrNoPopen:
1322         err_str = GETMESSAGE(19, 39, "Cannot initialize remote execution");
1323         break;
1324     case ErrTimeOut:
1325         err_str = GETMESSAGE(19, 40, "Getting the Input Method on the \nselected host is taking too long");
1326         break;
1327
1328     default:
1329         err_str = GETMESSAGE(19, 41, "Unknown error");
1330         break;
1331     }
1332
1333     ErrDialog(err_str, style.i18nDialog);
1334 }
1335
1336 /*+++++++++++++++++++++++++++++++++++++++*/
1337 /* ListItemSelectCB - callback for the   */
1338 /* selection on an item in the preedit   */
1339 /* Type List.                            */
1340 /*+++++++++++++++++++++++++++++++++++++++*/
1341
1342 static void 
1343 ListItemSelectCB(
1344         Widget w,
1345         XtPointer client_data,
1346         XtPointer call_data )
1347 {
1348     XmListCallbackStruct *listCBS = (XmListCallbackStruct *) call_data;
1349
1350     /* Set the sensitivity of the MoveUp and MoveDown buttons depending 
1351        on the selected item position. MoveUp is insensitive is the first
1352        item in the list is selected; MoveDown is insensitive if the last 
1353        item in the list is selected */
1354
1355     if (listCBS->item_position == 1)
1356         XtSetSensitive(i18n.buttonMoveUp, False);
1357     else
1358         XtSetSensitive(i18n.buttonMoveUp, True);
1359
1360     if (listCBS->item_position == i18n.preeditTypeListLastPos)
1361         XtSetSensitive(i18n.buttonMoveDown, False);
1362     else
1363         XtSetSensitive(i18n.buttonMoveDown, True);
1364
1365     return;
1366 }
1367
1368 /*+++++++++++++++++++++++++++++++++++++++*/
1369 /* MoveUpCB - callback for the           */
1370 /* MoveUp button                         */
1371 /*+++++++++++++++++++++++++++++++++++++++*/
1372
1373 static void 
1374 MoveUpCB(
1375         Widget w,
1376         XtPointer client_data,
1377         XtPointer call_data )
1378 {
1379     int *position_list;
1380     int position_count;
1381
1382     if (XmListGetSelectedPos(i18n.preeditTypeList, &position_list, 
1383                              &position_count)) {
1384
1385         /* there should be only one selected per our selection
1386            policy set on the list, but consider the first selected one 
1387            in any case */
1388
1389         /* this should always be the case as the MoveUp button should be
1390            insensitive when the first item is selected, but check anyway */
1391
1392         if (position_list[0] > 1) {
1393             XmStringTable list_items;
1394             XmString items[2];
1395             int sel_pos = position_list[0];
1396             int sel_index = sel_pos - 1;
1397
1398             XtVaGetValues(i18n.preeditTypeList, XmNitems, &list_items, NULL);
1399
1400             /* makes an array of two XmStrings by reversing the selected
1401                one and the item preceeding it */
1402             items[0] = list_items[sel_index];
1403             items[1] = list_items[sel_index - 1];
1404
1405             /* this call preserves selected state */
1406             XmListReplaceItemsPos(i18n.preeditTypeList,
1407                                   items, 2,
1408                                   sel_pos - 1);
1409
1410             if (sel_pos == 2) {
1411                 /* it's now 1, so set the MoveUp button insensitive */
1412                 XtSetSensitive(i18n.buttonMoveUp, False);
1413             }
1414
1415             if (sel_pos == i18n.preeditTypeListLastPos) {
1416                 /* it's not anymore the last one, so set the MoveDown 
1417                    button sensitive */
1418                 XtSetSensitive(i18n.buttonMoveDown, True);
1419             }
1420
1421             /* preeditType has changed */
1422             i18n.preeditHasChanged = True;
1423         }
1424     }
1425 }
1426
1427 /*+++++++++++++++++++++++++++++++++++++++*/
1428 /* MoveDownCB - callback for the         */
1429 /* MoveDown button                       */
1430 /*+++++++++++++++++++++++++++++++++++++++*/
1431
1432 static void 
1433 MoveDownCB(
1434         Widget w,
1435         XtPointer client_data,
1436         XtPointer call_data )
1437 {
1438     int *position_list;
1439     int position_count;
1440
1441     if (XmListGetSelectedPos(i18n.preeditTypeList, &position_list, 
1442                              &position_count)) {
1443
1444         /* there should be only one selected per our selection
1445            policy set on the list, but consider the first selected one 
1446            in any case */
1447
1448         /* this should always be the case as the Move Down button should be
1449            insensitive when the first item is selected, but check anyway */
1450
1451         if (position_list[0] != i18n.preeditTypeListLastPos) {
1452             XmStringTable list_items;
1453             XmString items[2];
1454             int sel_pos = position_list[0];
1455             int sel_index = sel_pos - 1;
1456
1457             XtVaGetValues(i18n.preeditTypeList, XmNitems, &list_items, NULL);
1458
1459             /* makes an array of two XmStrings by reversing the selected
1460                one and the item succeeding it */
1461             items[0] = list_items[sel_index + 1];
1462             items[1] = list_items[sel_index];
1463
1464             /* this call preserves selected state */
1465             XmListReplaceItemsPos(i18n.preeditTypeList,
1466                                   items, 2,
1467                                   sel_pos);
1468
1469             if (sel_pos == (i18n.preeditTypeListLastPos - 1)) {
1470                 /* it's now the last one, so set the MoveDown button 
1471                    insensitive */
1472                 XtSetSensitive(i18n.buttonMoveDown, False);
1473             }
1474
1475             if (sel_pos == 1) {
1476                 /* it's not anymore the first one, so set the MoveUp 
1477                    button sensitive */
1478                 XtSetSensitive(i18n.buttonMoveUp, True);
1479             }
1480
1481             /* preeditType has changed */
1482             i18n.preeditHasChanged = True;
1483         }
1484     }
1485
1486 }
1487
1488
1489 static XmStringTable
1490 CopyST (XmStringTable st, int nst)
1491 {
1492     XmStringTable lst = (XmStringTable) XtMalloc(sizeof(XmString) * nst);
1493     int i ;
1494
1495     for (i=0; i < nst ; i++) {
1496         lst[i] = XmStringCopy(st[i]);
1497     }
1498
1499     return lst ;
1500 }
1501
1502
1503 static void
1504 FreeST (XmStringTable st, int nst)
1505 {
1506     int i;
1507
1508     for (i=0; i < nst ; i++) {
1509        XmStringFree(st[i]);
1510     }
1511
1512     XtFree((char*)st);
1513 }
1514