2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /************************************<+>*************************************
24 ****************************************************************************
30 ** Description: Controls the DtStyle keyboard dialog
33 ** (c) Copyright Hewlett-Packard Company, 1990.
37 ****************************************************************************
38 ************************************<+>*************************************/
39 /* $XConsortium: Keyboard.c /main/4 1995/10/30 13:10:18 rswiston $ */
41 /*+++++++++++++++++++++++++++++++++++++++*/
43 /*+++++++++++++++++++++++++++++++++++++++*/
46 #include <Xm/MwmUtil.h>
51 #include <Xm/LabelG.h>
52 #include <Xm/PushBG.h>
54 #include <Xm/ToggleBG.h>
55 #include <Xm/VendorSEP.h>
57 #include <Dt/DialogBox.h>
60 #include <Dt/Message.h>
61 #include <Dt/HourGlass.h>
65 #include "SaveRestore.h"
68 /*+++++++++++++++++++++++++++++++++++++++*/
69 /* include extern functions */
70 /*+++++++++++++++++++++++++++++++++++++++*/
73 /*+++++++++++++++++++++++++++++++++++++++*/
75 /*+++++++++++++++++++++++++++++++++++++++*/
76 #define VOLUME_MAX 100
77 #define SCALE_WIDTH 200
79 /*+++++++++++++++++++++++++++++++++++++++*/
80 /* Internal Functions */
81 /*+++++++++++++++++++++++++++++++++++++++*/
84 static Widget build_keyboardDlg( Widget shell) ;
87 XtPointer client_data,
88 XtPointer call_data) ;
89 static void _DtmapCB_keyboardDlg(
91 XtPointer client_data,
92 XtPointer call_data) ;
93 static int getValue( Widget w) ;
94 static void valueChangedCB(
96 XtPointer client_data,
97 XtPointer call_data) ;
98 static void autoRepeatToggleCB(
100 XtPointer client_data,
101 XtPointer call_data) ;
102 static void systemDefaultCB(
104 XtPointer client_data,
105 XtPointer call_data) ;
106 static void ButtonCB(
108 XtPointer client_data,
109 XtPointer call_data) ;
112 /*+++++++++++++++++++++++++++++++++++++++*/
113 /* Internal Variables */
114 /*+++++++++++++++++++++++++++++++++++++++*/
118 Widget systemDefault;
121 Widget autoRepeatToggle;
122 XKeyboardState values;
123 int new_key_click_percent;
125 Boolean systemDefaultFlag;
129 static saveRestore save = {FALSE, 0, };
131 /*+++++++++++++++++++++++++++++++++++++++*/
132 /* popup_kbdDialog */
133 /*+++++++++++++++++++++++++++++++++++++++*/
138 if (style.kbdDialog == NULL)
140 _DtTurnOnHourGlass(shell);
141 build_keyboardDlg(shell);
142 XtManageChild(style.kbdDialog);
143 _DtTurnOffHourGlass(shell);
147 XtManageChild(style.kbdDialog);
148 raiseWindow(XtWindow(XtParent(style.kbdDialog)));
152 /*+++++++++++++++++++++++++++++++++++++++*/
153 /* build__keyboardDlg */
154 /*+++++++++++++++++++++++++++++++++++++++*/
161 Widget widget_list[12];
164 Pixel foreground, background;
166 XmString button_string[NUM_LABELS];
169 /* Set up DialogBoxDialog button labels */
170 button_string[0] = CMPSTR(_DtOkString);
171 button_string[1] = CMPSTR(_DtCancelString);
172 button_string[2] = CMPSTR(_DtHelpString);
174 /* Create toplevel DialogBox */
177 * Note that save.poscnt has been initialized elsewhere.
178 * save.posArgs may contain information from restoreBeep().*/
180 XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
182 XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
184 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
186 style.kbdDialog = __DtCreateDialogBoxDialog(shell, "KeyboardDialog", save.posArgs, save.poscnt);
187 XtAddCallback(style.kbdDialog, XmNcallback, ButtonCB, NULL);
188 XtAddCallback(style.kbdDialog, XmNhelpCallback,
189 (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_KEYBOARD_DIALOG);
191 XmStringFree(button_string[0]);
192 XmStringFree(button_string[1]);
193 XmStringFree(button_string[2]);
195 widget_list[0] = _DtDialogBoxGetButton(style.kbdDialog,2);
197 XtSetArg(args[n], XmNautoUnmanage, False); n++;
198 XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
199 XtSetValues (style.kbdDialog, args, n);
202 XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(13, 6, "Style Manager - Keyboard"))); n++;
203 XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
204 XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
205 XtSetValues (XtParent(style.kbdDialog), args, n);
208 XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
209 XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
210 XtSetArg(args[n], XmNallowOverlap, False); n++;
211 XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
212 form = XmCreateForm(style.kbdDialog, "keyboardForm", args, n);
214 /* create keyboard pixmap */
217 XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
218 XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
219 XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
220 XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
221 XtSetArg(args[n], XmNstring, NULL); n++;
222 XtSetArg(args[n], XmNshadowThickness, 0); n++;
223 XtSetArg(args[n], XmNimageName, KEYBOARD_ICON); n++;
224 XtSetArg(args[n], XmNtraversalOn, False); n++;
225 widget_list[count++] =
226 kbd.pictLabel= _DtCreateIcon(form, "keyboardpictLabel", args, n);
229 XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
230 XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
231 string = CMPSTR(((char *)GETMESSAGE(13, 2, "Default")));
232 XtSetArg(args[n], XmNlabelString, string); n++;
233 XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
234 widget_list[count++] =
235 kbd.systemDefault= XmCreatePushButtonGadget(form, "systemDefault", args, n);
236 XmStringFree(string);
239 set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
240 XtSetArg(args[n], XmNset, set); n++;
241 string = CMPSTR(((char *)GETMESSAGE(13, 3, "Auto Repeat")));
242 XtSetArg(args[n], XmNlabelString, string); n++;
243 XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
244 widget_list[count++] =
245 kbd.autoRepeatToggle= XmCreateToggleButtonGadget(form, "autoRepeatToggle", args, n);
246 XmStringFree(string);
249 XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
250 string = CMPSTR(((char *)GETMESSAGE(13, 4, "Click Volume")));
251 XtSetArg(args[n], XmNmarginHeight, 0); n++;
252 XtSetArg(args[n], XmNlabelString, string); n++;
253 widget_list[count++] =
254 kbd.volumeLabGad= XmCreateLabelGadget(form,"volumeLabGad", args, n);
255 XmStringFree(string);
258 XtSetArg(args[n], XmNmaximum, VOLUME_MAX); n++;
259 XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
260 XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
261 XtSetArg(args[n], XmNshowValue, True); n++;
262 XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
263 XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
264 widget_list[count++] =
265 kbd.volumeScale= XmCreateScale(form,"volumeScale", args, n);
267 XtAddCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
268 XtAddCallback(style.kbdDialog, XmNmapCallback, _DtmapCB_keyboardDlg, shell);
269 XtAddCallback(kbd.systemDefault, XmNactivateCallback, systemDefaultCB, NULL);
270 XtAddCallback(kbd.volumeScale, XmNvalueChangedCallback, valueChangedCB, NULL);
271 XtAddCallback(kbd.autoRepeatToggle, XmNvalueChangedCallback, autoRepeatToggleCB, NULL);
274 XtManageChildren(widget_list,count);
276 return(style.kbdDialog);
279 /*+++++++++++++++++++++++++++++++++++++++*/
281 /*+++++++++++++++++++++++++++++++++++++++*/
285 XtPointer client_data,
286 XtPointer call_data )
293 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
294 XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
295 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
296 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
297 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
298 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
299 XtSetValues (kbd.pictLabel, args, n);
303 XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
304 XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
305 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
306 XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
307 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
308 XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
309 XtSetValues (kbd.systemDefault, args, n);
311 /* auto repeat toggle */
313 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
314 XtSetArg(args[n], XmNtopWidget, kbd.pictLabel); n++;
315 XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
316 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
317 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
318 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
319 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
320 XtSetValues (kbd.autoRepeatToggle, args, n);
325 XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
326 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
327 XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
328 XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
329 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
330 XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
331 XtSetValues (kbd.volumeLabGad, args, n);
336 XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
337 XtSetArg(args[n], XmNtopWidget, kbd.autoRepeatToggle);n++;
338 XtSetArg(args[n], XmNtopOffset, style.verticalSpacing);n++;
339 XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
340 XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
341 XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
342 XtSetArg(args[n], XmNleftWidget, kbd.volumeLabGad); n++;
343 XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
344 XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
345 XtSetValues (kbd.volumeScale, args, n);
347 XtRemoveCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
351 /*+++++++++++++++++++++++++++++++++++++++*/
352 /* _DtmapCB_keyboardDlg */
353 /*+++++++++++++++++++++++++++++++++++++++*/
355 _DtmapCB_keyboardDlg(
357 XtPointer client_data,
358 XtPointer call_data )
360 static int first_time = 1;
367 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
369 if (!save.restoreFlag)
370 putDialog ((Widget)client_data, w);
375 /* get keyboard values for click volume */
376 XGetKeyboardControl(style.display, &kbd.values);
377 kbd.new_key_click_percent = kbd.values.key_click_percent;
378 kbd.new_autoRepeat = kbd.values.global_auto_repeat;
381 XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
382 XtSetValues(kbd.volumeScale, args, n);
385 set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
386 XtSetArg(args[n], XmNset, set); n++;
387 XtSetValues(kbd.autoRepeatToggle, args, n);
398 XtSetArg(args[n], XmNvalue, &value); n++;
399 XtGetValues(w, args, n);
404 /*+++++++++++++++++++++++++++++++++++++++*/
406 /*+++++++++++++++++++++++++++++++++++++++*/
410 XtPointer client_data,
411 XtPointer call_data )
414 XKeyboardControl kbdControl;
417 /* set keyboard click volume to scale value */
419 kbdControlMask = KBKeyClickPercent;
420 kbdControl.key_click_percent = kbd.new_key_click_percent =
421 getValue(kbd.volumeScale);
422 XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
423 kbd.systemDefaultFlag = False;
426 /*+++++++++++++++++++++++++++++++++++++++*/
427 /* autoRepeatToggleCB */
428 /*+++++++++++++++++++++++++++++++++++++++*/
432 XtPointer client_data,
433 XtPointer call_data )
436 /* set auto repeat to new value */
438 if (((XmToggleButtonCallbackStruct *)call_data)->set)
440 XAutoRepeatOn(style.display);
441 kbd.new_autoRepeat = AutoRepeatModeOn;
445 XAutoRepeatOff(style.display);
446 kbd.new_autoRepeat = AutoRepeatModeOff;
448 kbd.systemDefaultFlag = False;
451 /*+++++++++++++++++++++++++++++++++++++++*/
452 /* systemDefaultCB */
453 /*+++++++++++++++++++++++++++++++++++++++*/
457 XtPointer client_data,
458 XtPointer call_data )
462 XKeyboardControl kbdControl;
464 XKeyboardState kbdState;
467 /* set keyboard click volume to system default value */
469 kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
470 kbdControl.key_click_percent = -1;
471 kbdControl.auto_repeat_mode = AutoRepeatModeDefault;
472 XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
474 XGetKeyboardControl(style.display, &kbdState);
477 XtSetArg(args[n], XmNvalue, kbdState.key_click_percent); n++;
478 XtSetValues(kbd.volumeScale, args, n);
481 set = (kbdState.global_auto_repeat == AutoRepeatModeOn) ? True : False;
482 XtSetArg(args[n], XmNset, set); n++;
483 XtSetValues(kbd.autoRepeatToggle, args, n);
485 kbd.systemDefaultFlag = True;
488 /*+++++++++++++++++++++++++++++++++++++++*/
490 /* callback for PushButtons in DialogBox */
491 /*+++++++++++++++++++++++++++++++++++++++*/
495 XtPointer client_data,
496 XtPointer call_data )
500 XKeyboardControl kbdControl;
502 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
505 switch (cb->button_position)
510 /* if sendSettings is true send message to Session Manager */
512 if(style.smState.smSendSettings)
514 if(kbd.systemDefaultFlag)
516 SmDefaultKeyboardSettings();
520 SmNewKeyboardSettings( kbd.new_key_click_percent, /* 0-100 */
521 kbd.new_autoRepeat); /* 0,1 */
527 /* reset to incoming keyboard values */
530 XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
531 XtSetValues(kbd.volumeScale, args, n);
534 XtSetArg(args[n], XmNset, kbd.values.global_auto_repeat); n++;
535 XtSetValues(kbd.autoRepeatToggle, args, n);
537 kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
538 kbdControl.key_click_percent = kbd.values.key_click_percent;
539 kbdControl.auto_repeat_mode = kbd.values.global_auto_repeat;
540 XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
546 XtCallCallbacks(style.kbdDialog, XmNhelpCallback, (XtPointer)NULL);
555 /************************************************************************
558 * restore any state information saved with saveKeybd.
559 * This is called from restoreSession with the application
560 * shell and the special xrm database retrieved for restore.
561 ************************************************************************/
568 XrmRepresentation rep_type;
571 xrm_name [0] = XrmStringToQuark ("keyboardDlg");
575 xrm_name [1] = XrmStringToQuark ("x");
576 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
577 XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
578 save.restoreFlag = True;
582 xrm_name [1] = XrmStringToQuark ("y");
583 if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
584 XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
587 xrm_name [1] = XrmStringToQuark ("ismapped");
588 XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
589 /* Are we supposed to be mapped? */
590 if (strcmp(value.addr, "True") == 0)
591 popup_keyboardBB(shell);
594 /************************************************************************
597 * This routine will write out to the passed file descriptor any state
598 * information this dialog needs. It is called from saveSessionCB with the
599 * file already opened.
600 * All information is saved in xrm format. There is no restriction
601 * on what can be saved. It doesn't have to be defined or be part of any
602 * widget or Xt definition. Just name and save it here and recover it in
603 * restoreBackdrop. The suggested minimum is whether you are mapped, and your
605 ************************************************************************/
611 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
612 XmVendorShellExtObject vendorExt;
613 XmWidgetExtData extData;
615 if (style.kbdDialog != NULL)
617 if (XtIsManaged(style.kbdDialog))
618 sprintf(bufr, "*keyboardDlg.ismapped: True\n");
620 sprintf(bufr, "*keyboardDlg.ismapped: False\n");
622 /* Get and write out the geometry info for our Window */
623 x = XtX(XtParent(style.kbdDialog));
624 y = XtY(XtParent(style.kbdDialog));
626 /* Modify x & y to take into account window mgr frames
627 * This is pretty bogus, but I don't know a better way to do it.
629 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
630 vendorExt = (XmVendorShellExtObject)extData->widget;
631 x -= vendorExt->vendor.xOffset;
632 y -= vendorExt->vendor.yOffset;
634 sprintf(bufr, "%s*keyboardDlg.x: %d\n", bufr, x);
635 sprintf(bufr, "%s*keyboardDlg.y: %d\n", bufr, y);
637 write (fd, bufr, strlen(bufr));