Audio.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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: Audio.c
  27. **
  28. ** Project: DT 3.0
  29. **
  30. ** Description: Controls the Dtstyle Audio dialog
  31. **
  32. **
  33. ** (c) Copyright Hewlett-Packard Company, 1990.
  34. **
  35. **
  36. **
  37. ****************************************************************************
  38. ************************************<+>*************************************/
  39. /* $XConsortium: Audio.c /main/4 1995/10/30 13:07:24 rswiston $ */
  40. /*+++++++++++++++++++++++++++++++++++++++*/
  41. /* include files */
  42. /*+++++++++++++++++++++++++++++++++++++++*/
  43. #include <X11/Xlib.h>
  44. #include <errno.h>
  45. #include <Xm/MwmUtil.h>
  46. #include <Xm/XmP.h>
  47. #include <Xm/Xm.h>
  48. #include <Xm/Form.h>
  49. #include <Xm/PushBG.h>
  50. #include <Xm/Scale.h>
  51. #include <Xm/VendorSEP.h>
  52. #include <Xm/LabelG.h>
  53. #include <Dt/DialogBox.h>
  54. #include <Dt/Icon.h>
  55. #include <Dt/Message.h>
  56. #include <Dt/HourGlass.h>
  57. #include "Help.h"
  58. #include "Main.h"
  59. #include "SaveRestore.h"
  60. #include "Protocol.h"
  61. /*+++++++++++++++++++++++++++++++++++++++*/
  62. /* include extern functions */
  63. /*+++++++++++++++++++++++++++++++++++++++*/
  64. #include "Audio.h"
  65. /*+++++++++++++++++++++++++++++++++++++++*/
  66. /* Local #defines */
  67. /*+++++++++++++++++++++++++++++++++++++++*/
  68. #define VOLUME_MAX 100
  69. #define SCALE_WIDTH 200
  70. /*+++++++++++++++++++++++++++++++++++++++*/
  71. /* Internal Functions */
  72. /*+++++++++++++++++++++++++++++++++++++++*/
  73. static Widget build_audioDlg( Widget shell) ;
  74. static void formLayoutCB ( Widget, XtPointer, XtPointer ) ;
  75. static void _DtmapCB_audioDlg ( Widget, XtPointer, XtPointer ) ;
  76. static int getValue ( Widget w) ;
  77. static void valueChangedCB ( Widget, XtPointer, XtPointer ) ;
  78. static void systemDefaultCB ( Widget, XtPointer, XtPointer ) ;
  79. static void ButtonCB ( Widget, XtPointer, XtPointer ) ;
  80. /*+++++++++++++++++++++++++++++++++++++++*/
  81. /* Internal Variables */
  82. /*+++++++++++++++++++++++++++++++++++++++*/
  83. typedef struct {
  84. Widget pictLabel;
  85. Widget systemDefault;
  86. Widget volLabGad;
  87. Widget toneLabGad;
  88. Widget durLabGad;
  89. Widget volScale;
  90. Widget toneScale;
  91. Widget durScale;
  92. Boolean systemDefaultFlag;
  93. XKeyboardState values;
  94. } Audio, *AudioPtr;
  95. static Audio audio;
  96. static saveRestore save = {FALSE, 0, };
  97. /*+++++++++++++++++++++++++++++++++++++++*/
  98. /* popup_audioBB */
  99. /*+++++++++++++++++++++++++++++++++++++++*/
  100. void
  101. popup_audioBB(
  102. Widget shell )
  103. {
  104. if (style.audioDialog == NULL) {
  105. _DtTurnOnHourGlass(shell);
  106. build_audioDlg(shell);
  107. XtManageChild(style.audioDialog);
  108. _DtTurnOffHourGlass(shell);
  109. }
  110. else
  111. {
  112. XtManageChild(style.audioDialog);
  113. raiseWindow(XtWindow(XtParent(style.audioDialog)));
  114. }
  115. audio.systemDefaultFlag = False;
  116. }
  117. /*+++++++++++++++++++++++++++++++++++++++*/
  118. /* build__audioDlg */
  119. /*+++++++++++++++++++++++++++++++++++++++*/
  120. static Widget
  121. build_audioDlg(
  122. Widget shell )
  123. {
  124. int i, n;
  125. Arg args[MAX_ARGS];
  126. XmString button_string[NUM_LABELS];
  127. XmString string;
  128. Widget form;
  129. Pixmap audioPixmap;
  130. int count = 0;
  131. Widget widget_list[12];
  132. /*get audio values for sliders*/
  133. XGetKeyboardControl(style.display, &audio.values);
  134. if(audio.values.bell_duration == 0)
  135. audio.values.bell_duration = 1;
  136. /* Set up DialogBoxDialog button labels */
  137. button_string[0] = CMPSTR((String) _DtOkString);
  138. button_string[1] = CMPSTR((String) _DtCancelString);
  139. button_string[2] = CMPSTR((String) _DtHelpString);
  140. /* Create toplevel DialogBox */
  141. /* saveRestore
  142. * Note that save.poscnt has been initialized elsewhere.
  143. * save.posArgs may contain information from restoreBeep().*/
  144. XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS); save.poscnt++;
  145. XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string); save.poscnt++;
  146. XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False);
  147. save.poscnt++;
  148. style.audioDialog =
  149. __DtCreateDialogBoxDialog(shell, "AudioDialog", save.posArgs, save.poscnt);
  150. XtAddCallback(style.audioDialog, XmNmapCallback, formLayoutCB, NULL);
  151. XtAddCallback(style.audioDialog, XmNmapCallback, _DtmapCB_audioDlg, shell);
  152. XtAddCallback(style.audioDialog, XmNcallback, ButtonCB, NULL);
  153. XtAddCallback(style.audioDialog, XmNhelpCallback,
  154. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_AUDIO_DIALOG);
  155. XmStringFree(button_string[0]);
  156. XmStringFree(button_string[1]);
  157. XmStringFree(button_string[2]);
  158. widget_list[0] = _DtDialogBoxGetButton(style.audioDialog,2);
  159. n=0;
  160. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  161. XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
  162. XtSetValues (style.audioDialog, args, n);
  163. n=0;
  164. XtSetArg(args[n], XmNtitle, ((char *)GETMESSAGE(6, 7, "Style Manager - Beep"))); n++;
  165. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  166. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  167. XtSetValues (XtParent(style.audioDialog), args, n);
  168. n = 0;
  169. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  170. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  171. XtSetArg(args[n], XmNallowOverlap, False); n++;
  172. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  173. form = XmCreateForm(style.audioDialog, "audioForm", args, n);
  174. n = 0;
  175. XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
  176. XtSetArg(args[n], XmNbehavior, XmICON_LABEL); n++;
  177. XtSetArg(args[n], XmNpixmapForeground, style.secBSCol); n++;
  178. XtSetArg(args[n], XmNpixmapBackground, style.secTSCol); n++;
  179. XtSetArg(args[n], XmNstring, NULL); n++;
  180. XtSetArg(args[n], XmNshadowThickness, 0); n++;
  181. XtSetArg(args[n], XmNimageName, BEEP_ICON); n++;
  182. XtSetArg(args[n], XmNtraversalOn, False); n++;
  183. widget_list[count++] =
  184. audio.pictLabel = _DtCreateIcon(form, "audiopictLabel", args, n);
  185. n = 0;
  186. XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
  187. XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
  188. string = CMPSTR(((char *)GETMESSAGE(6, 2, "Default")));
  189. XtSetArg(args[n], XmNlabelString, string); n++;
  190. widget_list[count++] =
  191. audio.systemDefault = XmCreatePushButtonGadget(form, "systemDefault", args, n);
  192. XmStringFree(string);
  193. n = 0;
  194. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  195. string = CMPSTR(((char *)GETMESSAGE(6, 3, "Volume")));
  196. XtSetArg(args[n], XmNlabelString, string); n++;
  197. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  198. widget_list[count++] =
  199. audio.volLabGad= XmCreateLabelGadget(form,"volLabGad", args, n);
  200. XmStringFree(string);
  201. n = 0;
  202. XtSetArg(args[n], XmNmaximum, VOLUME_MAX); n++;
  203. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  204. XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
  205. XtSetArg(args[n], XmNshowValue, True); n++;
  206. XtSetArg(args[n], XmNvalue,audio.values.bell_percent); n++;
  207. XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
  208. XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
  209. widget_list[count++] =
  210. audio.volScale= XmCreateScale(form,"volScale", args, n);
  211. n = 0;
  212. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  213. string = CMPSTR(((char *)GETMESSAGE(6, 4, "Tone")));
  214. XtSetArg(args[n], XmNlabelString, string); n++;
  215. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  216. widget_list[count++] =
  217. audio.toneLabGad= XmCreateLabelGadget(form,"toneLabGad", args, n);
  218. XmStringFree(string);
  219. n = 0;
  220. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  221. XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
  222. XtSetArg(args[n], XmNshowValue, True); n++;
  223. XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
  224. XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
  225. XtSetArg(args[n], XmNvalue,audio.values.bell_pitch); n++;
  226. widget_list[count++] =
  227. audio.toneScale= XmCreateScale(form,"toneScale", args, n);
  228. n = 0;
  229. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  230. string = CMPSTR(((char *)GETMESSAGE(6, 5, "Duration")));
  231. XtSetArg(args[n], XmNlabelString, string); n++;
  232. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  233. widget_list[count++] =
  234. audio.durLabGad= XmCreateLabelGadget(form,"durLabGad", args, n);
  235. XmStringFree(string);
  236. n = 0;
  237. XtSetArg(args[n], XmNdecimalPoints, (short)1); n++;
  238. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  239. XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
  240. XtSetArg(args[n], XmNshowValue, True); n++;
  241. XtSetArg(args[n], XmNminimum, 1); n++;
  242. XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
  243. XtSetArg(args[n], XmNvalue,(int)audio.values.bell_duration/100); n++;
  244. XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
  245. widget_list[count++] =
  246. audio.durScale= XmCreateScale(form,"durationScale", args, n);
  247. XtAddCallback(audio.systemDefault, XmNactivateCallback, systemDefaultCB, NULL);
  248. XtAddCallback(audio.volScale, XmNvalueChangedCallback, valueChangedCB, NULL);
  249. XtAddCallback(audio.toneScale, XmNvalueChangedCallback, valueChangedCB, NULL);
  250. XtAddCallback(audio.durScale, XmNvalueChangedCallback, valueChangedCB, NULL);
  251. XtManageChild(form);
  252. XtManageChildren(widget_list,count);
  253. return(style.audioDialog);
  254. }
  255. /*+++++++++++++++++++++++++++++++++++++++*/
  256. /* formLayoutCB */
  257. /*+++++++++++++++++++++++++++++++++++++++*/
  258. static void
  259. formLayoutCB(
  260. Widget w,
  261. XtPointer client_data,
  262. XtPointer call_data )
  263. {
  264. int n;
  265. Arg args[MAX_ARGS];
  266. Dimension ScaleHeight;
  267. Dimension LabelHeight;
  268. Dimension volLabelWidth;
  269. Dimension toneLabelWidth;
  270. Dimension durLabelWidth;
  271. Dimension MaxLabelWidth;
  272. Dimension TopOffset;
  273. Dimension LeftOffset;
  274. /* get component sizes */
  275. ScaleHeight = XtHeight(audio.volScale);
  276. LabelHeight = XtHeight(audio.volLabGad);
  277. MaxLabelWidth = volLabelWidth = XtWidth(audio.volLabGad);
  278. toneLabelWidth = XtWidth(audio.toneLabGad);
  279. if (toneLabelWidth > MaxLabelWidth)
  280. {
  281. MaxLabelWidth = toneLabelWidth;
  282. }
  283. durLabelWidth = XtWidth(audio.durLabGad);
  284. if (durLabelWidth > MaxLabelWidth)
  285. {
  286. MaxLabelWidth = durLabelWidth;
  287. }
  288. TopOffset = style.verticalSpacing + ScaleHeight - LabelHeight;
  289. /* do form attachments */
  290. /* Picture Label */
  291. n=0;
  292. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  293. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  294. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  295. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  296. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  297. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  298. XtSetValues (audio.pictLabel, args, n);
  299. /* system Default */
  300. n=0;
  301. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  302. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  303. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  304. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  305. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  306. XtSetArg(args[n], XmNrightOffset, style.horizontalSpacing); n++;
  307. XtSetValues (audio.systemDefault, args, n);
  308. /* Volume Label */
  309. n=0;
  310. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  311. XtSetArg(args[n], XmNtopWidget, audio.pictLabel); n++;
  312. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  313. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  314. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  315. LeftOffset = style.horizontalSpacing + (MaxLabelWidth - volLabelWidth);
  316. XtSetArg(args[n], XmNleftOffset, LeftOffset); n++;
  317. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  318. XtSetValues (audio.volLabGad, args, n);
  319. /* Volume Scale */
  320. n=0;
  321. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  322. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  323. XtSetArg(args[n], XmNbottomWidget, audio.volLabGad); n++;
  324. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  325. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  326. XtSetArg(args[n], XmNleftWidget, audio.volLabGad); n++;
  327. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  328. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  329. XtSetValues (audio.volScale, args, n);
  330. /* Tone Label */
  331. n=0;
  332. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  333. XtSetArg(args[n], XmNtopWidget, audio.volScale); n++;
  334. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  335. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  336. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  337. LeftOffset = style.horizontalSpacing + (MaxLabelWidth - toneLabelWidth);
  338. XtSetArg(args[n], XmNleftOffset, LeftOffset); n++;
  339. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  340. XtSetValues (audio.toneLabGad, args, n);
  341. /* Tone Scale */
  342. n=0;
  343. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  344. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  345. XtSetArg(args[n], XmNbottomWidget, audio.toneLabGad); n++;
  346. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  347. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  348. XtSetArg(args[n], XmNleftWidget, audio.toneLabGad); n++;
  349. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  350. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  351. XtSetValues (audio.toneScale, args, n);
  352. /* Duration Label */
  353. n=0;
  354. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  355. XtSetArg(args[n], XmNtopWidget, audio.toneScale); n++;
  356. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  357. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  358. XtSetArg(args[n], XmNbottomOffset, style.verticalSpacing); n++;
  359. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  360. LeftOffset = style.horizontalSpacing + (MaxLabelWidth - durLabelWidth);
  361. XtSetArg(args[n], XmNleftOffset, LeftOffset); n++;
  362. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  363. XtSetValues (audio.durLabGad, args, n);
  364. /* Duration Scale */
  365. n=0;
  366. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  367. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  368. XtSetArg(args[n], XmNbottomWidget, audio.durLabGad); n++;
  369. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  370. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  371. XtSetArg(args[n], XmNleftWidget, audio.durLabGad); n++;
  372. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  373. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  374. XtSetValues (audio.durScale, args, n);
  375. XtRemoveCallback(style.audioDialog, XmNmapCallback, formLayoutCB, NULL);
  376. }
  377. /*+++++++++++++++++++++++++++++++++++++++*/
  378. /* _DtmapCB_audioDlg */
  379. /*+++++++++++++++++++++++++++++++++++++++*/
  380. static void
  381. _DtmapCB_audioDlg(
  382. Widget w,
  383. XtPointer client_data,
  384. XtPointer call_data )
  385. {
  386. static int first_time = 1;
  387. int n;
  388. Arg args[MAX_ARGS];
  389. if (first_time)
  390. {
  391. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  392. if (!save.restoreFlag)
  393. putDialog ((Widget)client_data, w);
  394. first_time = 0;
  395. }
  396. else
  397. {
  398. /*get audio values for sliders*/
  399. XGetKeyboardControl(style.display, &audio.values);
  400. if(audio.values.bell_duration == 0)
  401. audio.values.bell_duration = 1;
  402. n=0;
  403. XtSetArg(args[n], XmNvalue,audio.values.bell_percent); n++;
  404. XtSetValues(audio.volScale, args, n);
  405. n=0;
  406. XtSetArg(args[n], XmNvalue,audio.values.bell_pitch); n++;
  407. XtSetValues(audio.toneScale, args, n);
  408. n=0;
  409. XtSetArg(args[n], XmNvalue,(int)audio.values.bell_duration/100); n++;
  410. XtSetValues(audio.durScale, args, n);
  411. }
  412. }
  413. static int
  414. getValue(
  415. Widget w )
  416. {
  417. int n, value;
  418. Arg args[1];
  419. n=0;
  420. XtSetArg(args[n], XmNvalue, &value); n++;
  421. XtGetValues(w, args, n);
  422. return(value);
  423. }
  424. /*+++++++++++++++++++++++++++++++++++++++*/
  425. /* valueChangedCB */
  426. /*+++++++++++++++++++++++++++++++++++++++*/
  427. static void
  428. valueChangedCB(
  429. Widget w,
  430. XtPointer client_data,
  431. XtPointer call_data )
  432. {
  433. int n, value;
  434. Arg args[1];
  435. XKeyboardControl kbdControl;
  436. int kbdControlMask;
  437. /*set audio parameters to val returned and ring audio*/
  438. kbdControlMask = KBBellPercent | KBBellPitch | KBBellDuration;
  439. kbdControl.bell_percent = getValue(audio.volScale);
  440. kbdControl.bell_pitch = getValue(audio.toneScale);
  441. kbdControl.bell_duration = getValue(audio.durScale)*100;
  442. XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
  443. XBell(style.display,0);
  444. audio.systemDefaultFlag = False;
  445. }
  446. /*+++++++++++++++++++++++++++++++++++++++*/
  447. /* systemDefaultCB */
  448. /*+++++++++++++++++++++++++++++++++++++++*/
  449. static void
  450. systemDefaultCB(
  451. Widget w,
  452. XtPointer client_data,
  453. XtPointer call_data )
  454. {
  455. int n, value;
  456. Arg args[1];
  457. XKeyboardControl kbdControl;
  458. int kbdControlMask;
  459. XKeyboardState kbdState;
  460. /*set audio parameters to val returned and ring bell*/
  461. kbdControlMask = KBBellPercent | KBBellPitch | KBBellDuration;
  462. kbdControl.bell_percent = -1;
  463. kbdControl.bell_pitch = -1;
  464. kbdControl.bell_duration = -1;
  465. XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
  466. /*get audio values for sliders*/
  467. XGetKeyboardControl(style.display, &kbdState);
  468. n=0;
  469. XtSetArg(args[n], XmNvalue,kbdState.bell_percent); n++;
  470. XtSetValues(audio.volScale, args, n);
  471. n=0;
  472. XtSetArg(args[n], XmNvalue,kbdState.bell_pitch); n++;
  473. XtSetValues(audio.toneScale, args, n);
  474. n=0;
  475. XtSetArg(args[n], XmNvalue,(int)kbdState.bell_duration/100); n++;
  476. XtSetValues(audio.durScale, args, n);
  477. XBell(style.display,0);
  478. audio.systemDefaultFlag = True;
  479. }
  480. /*+++++++++++++++++++++++++++++++++++++++*/
  481. /* ButtonCB */
  482. /* callback for PushButtons in DialogBox */
  483. /*+++++++++++++++++++++++++++++++++++++++*/
  484. static void
  485. ButtonCB(
  486. Widget w,
  487. XtPointer client_data,
  488. XtPointer call_data )
  489. {
  490. int n;
  491. Arg args[MAX_ARGS];
  492. XKeyboardControl kbdControl;
  493. int kbdControlMask;
  494. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  495. switch (cb->button_position)
  496. {
  497. case OK_BUTTON:
  498. XtUnmanageChild (w);
  499. /* if sendSetting is True send message to Session manager */
  500. if(style.smState.smSendSettings)
  501. {
  502. if(audio.systemDefaultFlag)
  503. {
  504. SmDefaultAudioSettings();
  505. }
  506. else
  507. {
  508. SmNewAudioSettings(getValue(audio.volScale),
  509. getValue(audio.toneScale),
  510. getValue(audio.durScale) * 100);
  511. }
  512. }
  513. break;
  514. case CANCEL_BUTTON:
  515. /* reset to incoming audio values */
  516. XtUnmanageChild(w);
  517. n=0;
  518. XtSetArg(args[n], XmNvalue,audio.values.bell_percent);
  519. XtSetValues(audio.volScale, args, n);
  520. n=0;
  521. XtSetArg(args[n], XmNvalue,audio.values.bell_pitch);
  522. XtSetValues(audio.toneScale, args, n);
  523. n=0;
  524. XtSetArg(args[n], XmNvalue,(int)audio.values.bell_duration/100);
  525. XtSetValues(audio.durScale, args, n);
  526. kbdControlMask = KBBellPercent | KBBellPitch | KBBellDuration;
  527. kbdControl.bell_percent = audio.values.bell_percent;
  528. kbdControl.bell_pitch = audio.values.bell_pitch;
  529. kbdControl.bell_duration = audio.values.bell_duration;
  530. XChangeKeyboardControl(style.display, kbdControlMask, &kbdControl);
  531. XBell(style.display,0);
  532. break;
  533. case HELP_BUTTON:
  534. XtCallCallbacks(style.audioDialog, XmNhelpCallback, (XtPointer)NULL);
  535. break;
  536. default:
  537. break;
  538. }
  539. }
  540. /************************************************************************
  541. * restoreAudio()
  542. *
  543. * restore any state information saved with saveAudio.
  544. * This is called from restoreSession with the application
  545. * shell and the special xrm database retrieved for restore.
  546. ************************************************************************/
  547. void
  548. restoreAudio(
  549. Widget shell,
  550. XrmDatabase db )
  551. {
  552. XrmName xrm_name[5];
  553. XrmRepresentation rep_type;
  554. XrmValue value;
  555. xrm_name [0] = XrmStringToQuark ("audioDlg");
  556. xrm_name [2] = 0;
  557. /* get x position */
  558. xrm_name [1] = XrmStringToQuark ("x");
  559. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  560. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
  561. save.restoreFlag = True;
  562. }
  563. /* get y position */
  564. xrm_name [1] = XrmStringToQuark ("y");
  565. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  566. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
  567. }
  568. xrm_name [1] = XrmStringToQuark ("ismapped");
  569. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  570. /* Are we supposed to be mapped? */
  571. if (strcmp(value.addr, "True") == 0)
  572. popup_audioBB(shell);
  573. }
  574. /************************************************************************
  575. * saveAudio()
  576. *
  577. * This routine will write out to the passed file descriptor any state
  578. * information this dialog needs. It is called from saveSessionCB with the
  579. * file already opened.
  580. * All information is saved in xrm format. There is no restriction
  581. * on what can be saved. It doesn't have to be defined or be part of any
  582. * widget or Xt definition. Just name and save it here and recover it in
  583. * restoreBackdrop. The suggested minimum is whether you are mapped, and your
  584. * location.
  585. ************************************************************************/
  586. void
  587. saveAudio(
  588. int fd )
  589. {
  590. Position x,y;
  591. char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
  592. XmVendorShellExtObject vendorExt;
  593. XmWidgetExtData extData;
  594. if (style.audioDialog != NULL)
  595. {
  596. if (XtIsManaged(style.audioDialog))
  597. sprintf(bufr, "*audioDlg.ismapped: True\n");
  598. else
  599. sprintf(bufr, "*audioDlg.ismapped: False\n");
  600. /* Get and write out the geometry info for our Window */
  601. x = XtX(XtParent(style.audioDialog));
  602. y = XtY(XtParent(style.audioDialog));
  603. /* Modify x & y to take into account window mgr frames
  604. * This is pretty bogus, but I don't know a better way to do it.
  605. */
  606. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  607. vendorExt = (XmVendorShellExtObject)extData->widget;
  608. x -= vendorExt->vendor.xOffset;
  609. y -= vendorExt->vendor.yOffset;
  610. sprintf(bufr, "%s*audioDlg.x: %d\n", bufr, x);
  611. sprintf(bufr, "%s*audioDlg.y: %d\n", bufr, y);
  612. if(-1 == write (fd, bufr, strlen(bufr))) {
  613. perror(strerror(errno));
  614. }
  615. }
  616. }