Keyboard.c 21 KB

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