Last of the spelling fixed
[oweals/cde.git] / cde / programs / dtstyle / Keyboard.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /************************************<+>*************************************
24  ****************************************************************************
25  **
26  **   File:        Keyboard.c
27  **
28  **   Project:     DT 3.0
29  **
30  **   Description: Controls the DtStyle keyboard dialog
31  **
32  **
33  **  (c) Copyright Hewlett-Packard Company, 1990.  
34  **
35  **
36  **
37  ****************************************************************************
38  ************************************<+>*************************************/
39 /* $XConsortium: Keyboard.c /main/4 1995/10/30 13:10:18 rswiston $ */
40
41 /*+++++++++++++++++++++++++++++++++++++++*/
42 /* include files                         */
43 /*+++++++++++++++++++++++++++++++++++++++*/
44
45 #include <errno.h>
46 #include <X11/Xlib.h>
47 #include <Xm/MwmUtil.h>
48
49 #include <Xm/Xm.h>
50 #include <Xm/XmP.h>
51 #include <Xm/Form.h>
52 #include <Xm/LabelG.h>
53 #include <Xm/PushBG.h>
54 #include <Xm/Scale.h>
55 #include <Xm/ToggleBG.h>
56 #include <Xm/VendorSEP.h>
57
58 #include <Dt/DialogBox.h>
59 #include <Dt/Icon.h>
60
61 #include <Dt/Message.h>
62 #include <Dt/HourGlass.h>
63
64 #include "Help.h"
65 #include "Main.h"
66 #include "SaveRestore.h"
67 #include "Protocol.h"
68
69 /*+++++++++++++++++++++++++++++++++++++++*/
70 /* include extern functions              */
71 /*+++++++++++++++++++++++++++++++++++++++*/
72 #include "Keyboard.h"
73
74 /*+++++++++++++++++++++++++++++++++++++++*/
75 /* Local #defines                        */
76 /*+++++++++++++++++++++++++++++++++++++++*/
77 #define VOLUME_MAX       100
78 #define SCALE_WIDTH      200
79
80 /*+++++++++++++++++++++++++++++++++++++++*/
81 /* Internal Functions                    */
82 /*+++++++++++++++++++++++++++++++++++++++*/
83
84
85 static Widget build_keyboardDlg( Widget shell) ;
86 static void layoutCB( 
87                         Widget w,
88                         XtPointer client_data,
89                         XtPointer call_data) ;
90 static void _DtmapCB_keyboardDlg( 
91                         Widget w,
92                         XtPointer client_data,
93                         XtPointer call_data) ;
94 static int getValue( Widget w) ;
95 static void valueChangedCB( 
96                         Widget w,
97                         XtPointer client_data,
98                         XtPointer call_data) ;
99 static void autoRepeatToggleCB( 
100                         Widget w,
101                         XtPointer client_data,
102                         XtPointer call_data) ;
103 static void systemDefaultCB( 
104                         Widget w,
105                         XtPointer client_data,
106                         XtPointer call_data) ;
107 static void ButtonCB( 
108                         Widget w,
109                         XtPointer client_data,
110                         XtPointer call_data) ;
111
112
113 /*+++++++++++++++++++++++++++++++++++++++*/
114 /* Internal Variables                    */
115 /*+++++++++++++++++++++++++++++++++++++++*/
116
117 typedef struct {
118     Widget          pictLabel;
119     Widget          systemDefault;
120     Widget          volumeLabGad;
121     Widget          volumeScale;
122     Widget          autoRepeatToggle;
123     XKeyboardState  values;
124     int             new_key_click_percent;
125     int             new_autoRepeat;
126     Boolean         systemDefaultFlag;
127 } Kbd, *KdbPtr;
128
129 static Kbd kbd;
130 static saveRestore save = {FALSE, 0, };
131
132 /*+++++++++++++++++++++++++++++++++++++++*/
133 /* popup_kbdDialog                       */
134 /*+++++++++++++++++++++++++++++++++++++++*/
135 void 
136 popup_keyboardBB(
137         Widget shell )
138 {
139     if (style.kbdDialog == NULL) 
140     {
141       _DtTurnOnHourGlass(shell);  
142       build_keyboardDlg(shell);
143       XtManageChild(style.kbdDialog);
144       _DtTurnOffHourGlass(shell);  
145     }
146     else 
147     {
148       XtManageChild(style.kbdDialog);
149       raiseWindow(XtWindow(XtParent(style.kbdDialog)));
150     }
151 }
152
153 /*+++++++++++++++++++++++++++++++++++++++*/
154 /* build__keyboardDlg                    */
155 /*+++++++++++++++++++++++++++++++++++++++*/
156 static Widget 
157 build_keyboardDlg(
158         Widget shell )
159 {
160     register int     i, n;
161     Arg              args[MAX_ARGS];
162     Widget           widget_list[12]; 
163     int              count = 0;
164     Widget           form;
165     Pixel            foreground, background;
166     Boolean          set;
167     XmString         button_string[NUM_LABELS]; 
168     XmString         string;
169
170     /* Set up DialogBoxDialog button labels */
171     button_string[0] = CMPSTR((String) _DtOkString);
172     button_string[1] = CMPSTR((String) _DtCancelString);
173     button_string[2] = CMPSTR((String) _DtHelpString);
174
175     /* Create toplevel DialogBox */
176
177     /* saveRestore
178      * Note that save.poscnt has been initialized elsewhere.  
179      * save.posArgs may contain information from restoreBeep().*/
180
181     XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);  
182     save.poscnt++;
183     XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);  
184     save.poscnt++;
185     XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False); 
186     save.poscnt++;
187     style.kbdDialog = __DtCreateDialogBoxDialog(shell, "KeyboardDialog", save.posArgs, save.poscnt);
188     XtAddCallback(style.kbdDialog, XmNcallback, ButtonCB, NULL);
189     XtAddCallback(style.kbdDialog, XmNhelpCallback,
190             (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_KEYBOARD_DIALOG);
191
192     XmStringFree(button_string[0]);
193     XmStringFree(button_string[1]);
194     XmStringFree(button_string[2]);
195
196     widget_list[0] = _DtDialogBoxGetButton(style.kbdDialog,2);
197     n=0;
198     XtSetArg(args[n], XmNautoUnmanage, False); n++;
199     XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
200     XtSetValues (style.kbdDialog, args, n);
201
202     n=0;
203     XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(13, 6, "Style Manager - Keyboard"))); n++;
204     XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
205     XtSetArg(args[n], XmNmwmFunctions,  DIALOG_MWM_FUNC ); n++;
206     XtSetValues (XtParent(style.kbdDialog), args, n);
207
208     n = 0;
209     XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
210     XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
211     XtSetArg(args[n], XmNallowOverlap, False); n++;
212     XtSetArg(args[n], XmNchildType, XmWORK_AREA);  n++;
213     form = XmCreateForm(style.kbdDialog, "keyboardForm", args, n);
214
215     /* create keyboard pixmap */
216
217     n = 0;
218     XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
219     XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
220     XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
221     XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
222     XtSetArg(args[n], XmNstring, NULL); n++;  
223     XtSetArg(args[n], XmNshadowThickness, 0); n++;  
224     XtSetArg(args[n], XmNimageName, KEYBOARD_ICON); n++;  
225     XtSetArg(args[n], XmNtraversalOn, False); n++;  
226     widget_list[count++] = 
227     kbd.pictLabel= _DtCreateIcon(form, "keyboardpictLabel", args, n);
228
229     n = 0;
230     XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT);  n++;
231     XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH);  n++;
232     string = CMPSTR(((char *)GETMESSAGE(13, 2, "Default")));
233     XtSetArg(args[n], XmNlabelString, string); n++;
234     XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;  
235     widget_list[count++] = 
236     kbd.systemDefault= XmCreatePushButtonGadget(form, "systemDefault", args, n);
237     XmStringFree(string);
238     
239     n = 0;
240     set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
241     XtSetArg(args[n], XmNset, set);  n++;
242     string = CMPSTR(((char *)GETMESSAGE(13, 3, "Auto Repeat")));
243     XtSetArg(args[n], XmNlabelString, string); n++;
244     XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;  
245     widget_list[count++] = 
246     kbd.autoRepeatToggle= XmCreateToggleButtonGadget(form, "autoRepeatToggle", args, n);
247     XmStringFree(string);
248
249     n = 0;
250     XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
251     string = CMPSTR(((char *)GETMESSAGE(13, 4, "Click Volume")));
252     XtSetArg(args[n], XmNmarginHeight, 0); n++;
253     XtSetArg(args[n], XmNlabelString, string); n++;
254     widget_list[count++] = 
255     kbd.volumeLabGad= XmCreateLabelGadget(form,"volumeLabGad", args, n);
256     XmStringFree(string);
257
258     n = 0;
259     XtSetArg(args[n], XmNmaximum, VOLUME_MAX); n++; 
260     XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
261     XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
262     XtSetArg(args[n], XmNshowValue, True); n++;
263     XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++; 
264     XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++; 
265     widget_list[count++] = 
266     kbd.volumeScale= XmCreateScale(form,"volumeScale", args, n);
267
268     XtAddCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
269     XtAddCallback(style.kbdDialog, XmNmapCallback, _DtmapCB_keyboardDlg, shell);
270     XtAddCallback(kbd.systemDefault, XmNactivateCallback, systemDefaultCB, NULL);
271     XtAddCallback(kbd.volumeScale, XmNvalueChangedCallback, valueChangedCB, NULL);
272     XtAddCallback(kbd.autoRepeatToggle, XmNvalueChangedCallback, autoRepeatToggleCB, NULL);
273
274     XtManageChild(form);
275     XtManageChildren(widget_list,count); 
276
277     return(style.kbdDialog);
278 }
279
280 /*+++++++++++++++++++++++++++++++++++++++*/
281 /* layoutCB                              */
282 /*+++++++++++++++++++++++++++++++++++++++*/
283 static void 
284 layoutCB(
285         Widget w,
286         XtPointer client_data,
287         XtPointer call_data )
288 {
289     int              n;
290     Arg              args[MAX_ARGS];
291
292     /* Picture Label */
293     n=0;
294     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);       n++;
295     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
296     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
297     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
298     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
299     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
300     XtSetValues (kbd.pictLabel, args, n);
301
302     /* system Default */
303     n=0;
304     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_FORM);       n++;
305     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);    n++;
306     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
307     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_NONE);       n++;
308     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);       n++;
309     XtSetArg(args[n], XmNrightOffset,        style.horizontalSpacing);  n++;
310     XtSetValues (kbd.systemDefault, args, n);
311
312     /* auto repeat toggle */
313     n=0;
314     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
315     XtSetArg(args[n], XmNtopWidget,          kbd.pictLabel);       n++;
316     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing); n++;
317     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_NONE);       n++;
318     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
319     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
320     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
321     XtSetValues (kbd.autoRepeatToggle, args, n);
322
323     /* Volume Label */
324     n=0;
325
326     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_NONE);     n++;
327     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM);       n++;
328     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);    n++;
329     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_FORM);       n++;
330     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
331     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_NONE);       n++;
332     XtSetValues (kbd.volumeLabGad, args, n);
333
334
335     /* Volume Scale */
336     n=0;
337     XtSetArg(args[n], XmNtopAttachment,      XmATTACH_WIDGET);     n++;
338     XtSetArg(args[n], XmNtopWidget,          kbd.autoRepeatToggle);n++;
339     XtSetArg(args[n], XmNtopOffset,          style.verticalSpacing);n++;
340     XtSetArg(args[n], XmNbottomAttachment,   XmATTACH_FORM); n++;
341     XtSetArg(args[n], XmNbottomOffset,       style.verticalSpacing);  n++;
342     XtSetArg(args[n], XmNleftAttachment,     XmATTACH_WIDGET);     n++;
343     XtSetArg(args[n], XmNleftWidget,         kbd.volumeLabGad);    n++;
344     XtSetArg(args[n], XmNleftOffset,         style.horizontalSpacing);  n++;
345     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);       n++;
346     XtSetValues (kbd.volumeScale, args, n);
347
348     XtRemoveCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
349 }
350
351
352 /*+++++++++++++++++++++++++++++++++++++++*/
353 /* _DtmapCB_keyboardDlg                     */
354 /*+++++++++++++++++++++++++++++++++++++++*/
355 static void 
356 _DtmapCB_keyboardDlg(
357         Widget w,
358         XtPointer client_data,
359         XtPointer call_data )
360 {
361     static int  first_time = 1;
362     int         n;
363     Arg         args[MAX_ARGS];
364     Boolean     set;
365
366     if (first_time)
367     {
368         DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
369
370         if (!save.restoreFlag)
371             putDialog ((Widget)client_data, w);
372
373         first_time = 0;
374     }
375
376     /* get keyboard values for click volume */
377     XGetKeyboardControl(style.display, &kbd.values);
378     kbd.new_key_click_percent = kbd.values.key_click_percent;
379     kbd.new_autoRepeat = kbd.values.global_auto_repeat;
380
381     n=0;
382     XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
383     XtSetValues(kbd.volumeScale, args, n);
384
385     n=0;
386     set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
387     XtSetArg(args[n], XmNset, set);  n++;
388     XtSetValues(kbd.autoRepeatToggle, args, n);
389 }
390
391 static int 
392 getValue(
393         Widget w )
394 {
395     int n, value;
396     Arg args[1];
397
398     n=0;
399     XtSetArg(args[n], XmNvalue, &value); n++;
400     XtGetValues(w, args, n);
401     return(value);
402 }
403
404
405 /*+++++++++++++++++++++++++++++++++++++++*/
406 /* valueChangedCB                        */
407 /*+++++++++++++++++++++++++++++++++++++++*/
408 static void 
409 valueChangedCB(
410         Widget w,
411         XtPointer client_data,
412         XtPointer call_data )
413 {
414
415     XKeyboardControl    kbdControl;
416     int                 kbdControlMask;
417
418     /* set keyboard click volume to scale value */
419
420     kbdControlMask = KBKeyClickPercent;
421     kbdControl.key_click_percent = kbd.new_key_click_percent =
422                   getValue(kbd.volumeScale);
423     XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
424     kbd.systemDefaultFlag = False;
425 }
426
427 /*+++++++++++++++++++++++++++++++++++++++*/
428 /* autoRepeatToggleCB                    */
429 /*+++++++++++++++++++++++++++++++++++++++*/
430 static void 
431 autoRepeatToggleCB(
432         Widget w,
433         XtPointer client_data,
434         XtPointer call_data )
435 {
436
437     /* set auto repeat to new value */
438
439     if (((XmToggleButtonCallbackStruct *)call_data)->set)
440     {
441         XAutoRepeatOn(style.display);
442         kbd.new_autoRepeat = AutoRepeatModeOn;
443     }
444     else
445     {
446         XAutoRepeatOff(style.display);
447         kbd.new_autoRepeat = AutoRepeatModeOff;
448     }
449     kbd.systemDefaultFlag = False;
450 }
451
452 /*+++++++++++++++++++++++++++++++++++++++*/
453 /* systemDefaultCB                       */
454 /*+++++++++++++++++++++++++++++++++++++++*/
455 static void 
456 systemDefaultCB(
457         Widget w,
458         XtPointer client_data,
459         XtPointer call_data )
460 {
461     int                 n;
462     Arg                 args[MAX_ARGS];
463     XKeyboardControl    kbdControl;
464     int                 kbdControlMask;
465     XKeyboardState      kbdState;
466     Boolean             set;
467
468     /* set keyboard click volume to system default value */
469
470     kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
471     kbdControl.key_click_percent = -1;
472     kbdControl.auto_repeat_mode = AutoRepeatModeDefault;
473     XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
474
475     XGetKeyboardControl(style.display, &kbdState);
476
477     n=0;
478     XtSetArg(args[n], XmNvalue, kbdState.key_click_percent); n++;
479     XtSetValues(kbd.volumeScale, args, n);
480
481     n=0;
482     set = (kbdState.global_auto_repeat == AutoRepeatModeOn) ? True : False;
483     XtSetArg(args[n], XmNset, set);  n++;
484     XtSetValues(kbd.autoRepeatToggle, args, n);
485
486     kbd.systemDefaultFlag = True;
487 }
488
489 /*+++++++++++++++++++++++++++++++++++++++*/
490 /* ButtonCB                              */
491 /* callback for PushButtons in DialogBox */
492 /*+++++++++++++++++++++++++++++++++++++++*/
493 static void 
494 ButtonCB(
495         Widget w,
496         XtPointer client_data,
497         XtPointer call_data )
498 {
499     int                 n;
500     Arg                 args[MAX_ARGS];
501     XKeyboardControl    kbdControl;
502     int                 kbdControlMask;
503     DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
504
505
506     switch (cb->button_position)
507     {
508       case OK_BUTTON:
509           XtUnmanageChild (w);
510
511           /* if sendSettings is true send message to Session Manager */
512
513           if(style.smState.smSendSettings)
514           {
515              if(kbd.systemDefaultFlag)
516              {
517                 SmDefaultKeyboardSettings();
518              }
519              else
520              {
521                 SmNewKeyboardSettings( kbd.new_key_click_percent, /* 0-100 */
522                                        kbd.new_autoRepeat);       /* 0,1   */
523              }
524           }
525           break;
526
527       case CANCEL_BUTTON:
528           /* reset to incoming keyboard values */ 
529
530           n=0;
531           XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
532           XtSetValues(kbd.volumeScale, args, n);
533
534           n=0;
535           XtSetArg(args[n], XmNset, kbd.values.global_auto_repeat); n++;
536           XtSetValues(kbd.autoRepeatToggle, args, n);
537
538           kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
539           kbdControl.key_click_percent = kbd.values.key_click_percent;
540           kbdControl.auto_repeat_mode = kbd.values.global_auto_repeat;
541           XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
542
543           XtUnmanageChild(w);
544           break;
545
546       case HELP_BUTTON:
547           XtCallCallbacks(style.kbdDialog, XmNhelpCallback, (XtPointer)NULL);
548           break;
549
550       default:
551           break;
552     }
553 }
554
555
556 /************************************************************************
557  * restoreKeybd()
558  *
559  * restore any state information saved with saveKeybd.
560  * This is called from restoreSession with the application
561  * shell and the special xrm database retrieved for restore.
562  ************************************************************************/
563 void 
564 restoreKeybd(
565         Widget shell,
566         XrmDatabase db )
567 {
568     XrmName xrm_name[5];
569     XrmRepresentation rep_type;
570     XrmValue value;
571
572     xrm_name [0] = XrmStringToQuark ("keyboardDlg");
573     xrm_name [2] = 0;
574
575     /* get x position */
576     xrm_name [1] = XrmStringToQuark ("x");
577     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
578       XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
579       save.restoreFlag = True;
580     }
581
582     /* get y position */
583     xrm_name [1] = XrmStringToQuark ("y");
584     if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
585       XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
586     }
587
588     xrm_name [1] = XrmStringToQuark ("ismapped");
589     XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
590     /* Are we supposed to be mapped? */
591     if (strcmp(value.addr, "True") == 0)
592       popup_keyboardBB(shell);
593 }
594
595 /************************************************************************
596  * saveKeybd()
597  *
598  * This routine will write out to the passed file descriptor any state
599  * information this dialog needs.  It is called from saveSessionCB with the
600  * file already opened.
601  * All information is saved in xrm format.  There is no restriction
602  * on what can be saved.  It doesn't have to be defined or be part of any
603  * widget or Xt definition.  Just name and save it here and recover it in
604  * restoreBackdrop.  The suggested minimum is whether you are mapped, and your
605  * location.
606  ************************************************************************/
607 void 
608 saveKeybd(
609         int fd )
610 {
611     Position x,y;
612     char *bufr = style.tmpBigStr;     /* size=[1024], make bigger if needed */
613     XmVendorShellExtObject  vendorExt;
614     XmWidgetExtData         extData;
615
616     if (style.kbdDialog != NULL) 
617     {
618         if (XtIsManaged(style.kbdDialog))
619             sprintf(bufr, "*keyboardDlg.ismapped: True\n");
620         else
621             sprintf(bufr, "*keyboardDlg.ismapped: False\n");
622
623         /* Get and write out the geometry info for our Window */
624         x = XtX(XtParent(style.kbdDialog));
625         y = XtY(XtParent(style.kbdDialog));
626
627         /* Modify x & y to take into account window mgr frames
628          * This is pretty bogus, but I don't know a better way to do it.
629          */
630         extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
631         vendorExt = (XmVendorShellExtObject)extData->widget;
632         x -= vendorExt->vendor.xOffset;
633         y -= vendorExt->vendor.yOffset;
634
635         sprintf(bufr, "%s*keyboardDlg.x: %d\n", bufr, x);
636         sprintf(bufr, "%s*keyboardDlg.y: %d\n", bufr, y);
637
638         if(-1 == write (fd, bufr, strlen(bufr))) {
639             perror(strerror(errno));
640         }
641     }
642 }
643