Audio.c 25 KB

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