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 libraries 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 /*+++++++++++++++++++++++++++++++++++++++*/
47 #include <Xm/MwmUtil.h>
52 #include <Xm/LabelG.h>
53 #include <Xm/PushBG.h>
55 #include <Xm/ToggleBG.h>
56 #include <Xm/VendorSEP.h>
58 #include <Dt/DialogBox.h>
61 #include <Dt/Message.h>
62 #include <Dt/HourGlass.h>
66 #include "SaveRestore.h"
69 /*+++++++++++++++++++++++++++++++++++++++*/
70 /* include extern functions */
71 /*+++++++++++++++++++++++++++++++++++++++*/
74 /*+++++++++++++++++++++++++++++++++++++++*/
76 /*+++++++++++++++++++++++++++++++++++++++*/
77 #define VOLUME_MAX 100
78 #define SCALE_WIDTH 200
80 /*+++++++++++++++++++++++++++++++++++++++*/
81 /* Internal Functions */
82 /*+++++++++++++++++++++++++++++++++++++++*/
85 static Widget build_keyboardDlg( Widget shell) ;
88 XtPointer client_data,
89 XtPointer call_data) ;
90 static void _DtmapCB_keyboardDlg(
92 XtPointer client_data,
93 XtPointer call_data) ;
94 static int getValue( Widget w) ;
95 static void valueChangedCB(
97 XtPointer client_data,
98 XtPointer call_data) ;
99 static void autoRepeatToggleCB(
101 XtPointer client_data,
102 XtPointer call_data) ;
103 static void systemDefaultCB(
105 XtPointer client_data,
106 XtPointer call_data) ;
107 static void ButtonCB(
109 XtPointer client_data,
110 XtPointer call_data) ;
113 /*+++++++++++++++++++++++++++++++++++++++*/
114 /* Internal Variables */
115 /*+++++++++++++++++++++++++++++++++++++++*/
119 Widget systemDefault;
122 Widget autoRepeatToggle;
123 XKeyboardState values;
124 int new_key_click_percent;
126 Boolean systemDefaultFlag;
130 static saveRestore save = {FALSE, 0, };
132 /*+++++++++++++++++++++++++++++++++++++++*/
133 /* popup_kbdDialog */
134 /*+++++++++++++++++++++++++++++++++++++++*/
139 if (style.kbdDialog == NULL)
141 _DtTurnOnHourGlass(shell);
142 build_keyboardDlg(shell);
143 XtManageChild(style.kbdDialog);
144 _DtTurnOffHourGlass(shell);
148 XtManageChild(style.kbdDialog);
149 raiseWindow(XtWindow(XtParent(style.kbdDialog)));
153 /*+++++++++++++++++++++++++++++++++++++++*/
154 /* build__keyboardDlg */
155 /*+++++++++++++++++++++++++++++++++++++++*/
162 Widget widget_list[12];
165 Pixel foreground, background;
167 XmString button_string[NUM_LABELS];
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);
175 /* Create toplevel DialogBox */
178 * Note that save.poscnt has been initialized elsewhere.
179 * save.posArgs may contain information from restoreBeep().*/
181 XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
183 XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string);
185 XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
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);
192 XmStringFree(button_string[0]);
193 XmStringFree(button_string[1]);
194 XmStringFree(button_string[2]);
196 widget_list[0] = _DtDialogBoxGetButton(style.kbdDialog,2);
198 XtSetArg(args[n], XmNautoUnmanage, False); n++;
199 XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
200 XtSetValues (style.kbdDialog, args, n);
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);
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);
215 /* create keyboard pixmap */
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);
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);
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);
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);
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);
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);
275 XtManageChildren(widget_list,count);
277 return(style.kbdDialog);
280 /*+++++++++++++++++++++++++++++++++++++++*/
282 /*+++++++++++++++++++++++++++++++++++++++*/
286 XtPointer client_data,
287 XtPointer call_data )
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);
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);
312 /* auto repeat toggle */
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);
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);
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);
348 XtRemoveCallback(style.kbdDialog, XmNmapCallback, layoutCB, NULL);
352 /*+++++++++++++++++++++++++++++++++++++++*/
353 /* _DtmapCB_keyboardDlg */
354 /*+++++++++++++++++++++++++++++++++++++++*/
356 _DtmapCB_keyboardDlg(
358 XtPointer client_data,
359 XtPointer call_data )
361 static int first_time = 1;
368 DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
370 if (!save.restoreFlag)
371 putDialog ((Widget)client_data, w);
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;
382 XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
383 XtSetValues(kbd.volumeScale, args, n);
386 set = (kbd.values.global_auto_repeat == AutoRepeatModeOn) ? True : False;
387 XtSetArg(args[n], XmNset, set); n++;
388 XtSetValues(kbd.autoRepeatToggle, args, n);
399 XtSetArg(args[n], XmNvalue, &value); n++;
400 XtGetValues(w, args, n);
405 /*+++++++++++++++++++++++++++++++++++++++*/
407 /*+++++++++++++++++++++++++++++++++++++++*/
411 XtPointer client_data,
412 XtPointer call_data )
415 XKeyboardControl kbdControl;
418 /* set keyboard click volume to scale value */
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;
427 /*+++++++++++++++++++++++++++++++++++++++*/
428 /* autoRepeatToggleCB */
429 /*+++++++++++++++++++++++++++++++++++++++*/
433 XtPointer client_data,
434 XtPointer call_data )
437 /* set auto repeat to new value */
439 if (((XmToggleButtonCallbackStruct *)call_data)->set)
441 XAutoRepeatOn(style.display);
442 kbd.new_autoRepeat = AutoRepeatModeOn;
446 XAutoRepeatOff(style.display);
447 kbd.new_autoRepeat = AutoRepeatModeOff;
449 kbd.systemDefaultFlag = False;
452 /*+++++++++++++++++++++++++++++++++++++++*/
453 /* systemDefaultCB */
454 /*+++++++++++++++++++++++++++++++++++++++*/
458 XtPointer client_data,
459 XtPointer call_data )
463 XKeyboardControl kbdControl;
465 XKeyboardState kbdState;
468 /* set keyboard click volume to system default value */
470 kbdControlMask = KBKeyClickPercent | KBAutoRepeatMode;
471 kbdControl.key_click_percent = -1;
472 kbdControl.auto_repeat_mode = AutoRepeatModeDefault;
473 XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
475 XGetKeyboardControl(style.display, &kbdState);
478 XtSetArg(args[n], XmNvalue, kbdState.key_click_percent); n++;
479 XtSetValues(kbd.volumeScale, args, n);
482 set = (kbdState.global_auto_repeat == AutoRepeatModeOn) ? True : False;
483 XtSetArg(args[n], XmNset, set); n++;
484 XtSetValues(kbd.autoRepeatToggle, args, n);
486 kbd.systemDefaultFlag = True;
489 /*+++++++++++++++++++++++++++++++++++++++*/
491 /* callback for PushButtons in DialogBox */
492 /*+++++++++++++++++++++++++++++++++++++++*/
496 XtPointer client_data,
497 XtPointer call_data )
501 XKeyboardControl kbdControl;
503 DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
506 switch (cb->button_position)
511 /* if sendSettings is true send message to Session Manager */
513 if(style.smState.smSendSettings)
515 if(kbd.systemDefaultFlag)
517 SmDefaultKeyboardSettings();
521 SmNewKeyboardSettings( kbd.new_key_click_percent, /* 0-100 */
522 kbd.new_autoRepeat); /* 0,1 */
528 /* reset to incoming keyboard values */
531 XtSetArg(args[n], XmNvalue, kbd.values.key_click_percent); n++;
532 XtSetValues(kbd.volumeScale, args, n);
535 XtSetArg(args[n], XmNset, kbd.values.global_auto_repeat); n++;
536 XtSetValues(kbd.autoRepeatToggle, args, n);
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);
547 XtCallCallbacks(style.kbdDialog, XmNhelpCallback, (XtPointer)NULL);
556 /************************************************************************
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 ************************************************************************/
569 XrmRepresentation rep_type;
572 xrm_name [0] = XrmStringToQuark ("keyboardDlg");
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;
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++;
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);
595 /************************************************************************
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
606 ************************************************************************/
612 char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
613 XmVendorShellExtObject vendorExt;
614 XmWidgetExtData extData;
616 if (style.kbdDialog != NULL)
618 if (XtIsManaged(style.kbdDialog))
619 sprintf(bufr, "*keyboardDlg.ismapped: True\n");
621 sprintf(bufr, "*keyboardDlg.ismapped: False\n");
623 /* Get and write out the geometry info for our Window */
624 x = XtX(XtParent(style.kbdDialog));
625 y = XtY(XtParent(style.kbdDialog));
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.
630 extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
631 vendorExt = (XmVendorShellExtObject)extData->widget;
632 x -= vendorExt->vendor.xOffset;
633 y -= vendorExt->vendor.yOffset;
635 sprintf(bufr, "%s*keyboardDlg.x: %d\n", bufr, x);
636 sprintf(bufr, "%s*keyboardDlg.y: %d\n", bufr, y);
638 if(-1 == write (fd, bufr, strlen(bufr))) {
639 perror(strerror(errno));