2
0

ColorEdit.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  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. /* $XConsortium: ColorEdit.c /main/5 1995/10/30 13:08:03 rswiston $ */
  24. /************************************<+>*************************************
  25. ***************************************************************************
  26. **
  27. ** File: ColorEdit.c
  28. **
  29. ** Project: DT 3.0
  30. **
  31. ** Description: Controls the Dtstyle Color Editor dialog
  32. **
  33. **
  34. ** (c) Copyright Hewlett-Packard Company, 1990.
  35. **
  36. **
  37. **
  38. ****************************************************************************
  39. ************************************<+>*************************************/
  40. /* +++++++++++++++++++++++++++++++++++++++*/
  41. /* include files */
  42. /* +++++++++++++++++++++++++++++++++++++++*/
  43. #include <X11/cursorfont.h>
  44. #include <X11/keysym.h>
  45. #include <math.h>
  46. #include <errno.h>
  47. #include <X11/Xlib.h>
  48. #include <Xm/MwmUtil.h>
  49. #include <Xm/XmP.h>
  50. #include <Xm/LabelG.h>
  51. #include <Xm/PushB.h>
  52. #include <Xm/PushBG.h>
  53. #include <Xm/Form.h>
  54. #include <Xm/Scale.h>
  55. #include <Xm/VendorSEP.h>
  56. #include <Dt/DialogBox.h>
  57. #include <Dt/TitleBox.h>
  58. #include <Dt/Wsm.h>
  59. #include <Dt/UserMsg.h>
  60. #include "Help.h"
  61. #include "Main.h"
  62. #include "ColorMain.h"
  63. #include "ColorFile.h"
  64. /*+++++++++++++++++++++++++++++++++++++++*/
  65. /* include extern functions */
  66. /*+++++++++++++++++++++++++++++++++++++++*/
  67. #include "ColorEdit.h"
  68. /*+++++++++++++++++++++++++++++++++++++++*/
  69. /* Local #defines */
  70. /*+++++++++++++++++++++++++++++++++++++++*/
  71. #define NONE 0
  72. #define RED 1
  73. #define GREEN 2
  74. #define BLUE 3
  75. #define HUE 4
  76. #define SATURATION 5
  77. #define VALUE 6
  78. #define MAX_STR_LEN 128
  79. #define SCALE_LEFT_POSITION 10
  80. #define BUTTON_MARGIN 10
  81. #define OLD_BUTTON_LEFT_POSITION 10
  82. #define SCALE_WIDTH 300
  83. #define SATURATION_BITS "Dtsatur"
  84. #define VALUE_BITS "Dtvalue"
  85. /*+++++++++++++++++++++++++++++++++++++++*/
  86. /* Internal Functions */
  87. /*+++++++++++++++++++++++++++++++++++++++*/
  88. static void CreateColorEditor( Widget parent) ;
  89. static void sliderLayoutCB(
  90. Widget w,
  91. XtPointer client_data,
  92. XtPointer call_data) ;
  93. static void InitializeNewButton( void ) ;
  94. static void InitializeOldButton( void ) ;
  95. static void GenerateColors( void ) ;
  96. static Pixel GetPixel( Widget widget,
  97. char *color_string ) ;
  98. static void changRGB_CB(
  99. Widget w,
  100. XtPointer client_data,
  101. XtPointer call_data) ;
  102. static void changHSV_CB(
  103. Widget w,
  104. XtPointer client_data,
  105. XtPointer call_data) ;
  106. static void SetScales( XColor *rgb) ;
  107. static void SetRGBHSVScales(
  108. XColor *rgb,
  109. int h,
  110. int s,
  111. int v) ;
  112. static void CopyPixelSet(
  113. ColorSet *color_set_dest,
  114. ColorSet *color_set_src) ;
  115. static void HSVtoRGB(
  116. int h,
  117. int s,
  118. int v,
  119. unsigned short *r,
  120. unsigned short *g,
  121. unsigned short *b) ;
  122. static double max(
  123. double x,
  124. double y,
  125. double z) ;
  126. static double min(
  127. double x,
  128. double y,
  129. double z) ;
  130. static void grabcolorCB(
  131. Widget w,
  132. XtPointer client_data,
  133. XtPointer call_data) ;
  134. static void dialogBoxCB(
  135. Widget w,
  136. XtPointer client_data,
  137. XtPointer call_data) ;
  138. static void _DtmapCB(
  139. Widget w,
  140. XtPointer client_data,
  141. XtPointer call_data) ;
  142. /*+++++++++++++++++++++++++++++++++++++++*/
  143. /* Global Variables */
  144. /*+++++++++++++++++++++++++++++++++++++++*/
  145. EditData edit;
  146. /*+++++++++++++++++++++++++++++++++++++++*/
  147. /* Internal Variables */
  148. /*+++++++++++++++++++++++++++++++++++++++*/
  149. static saveRestore save = {FALSE, 0, };
  150. static Boolean OldNewSame = False;
  151. /************************************************************************
  152. * ColorEditor() - Create ColorEditor dialog first time up.
  153. * If has already been created, set up oldButton and newButton
  154. * colors, set the scale values for the new color and manage
  155. * the dialog.
  156. ************************************************************************/
  157. void
  158. ColorEditor(
  159. Widget parent,
  160. ColorSet *color_set )
  161. {
  162. if (edit.DialogShell == NULL)
  163. {
  164. _DtTurnOnHourGlass(parent);
  165. edit.color_set = color_set;
  166. CreateColorEditor(parent);
  167. _DtTurnOffHourGlass(parent);
  168. }
  169. else
  170. {
  171. if (!XtIsManaged(edit.DialogShell))
  172. {
  173. edit.color_set = color_set;
  174. CopyPixelSet(&edit.oldButtonColor,edit.color_set);
  175. /* update "old" button if necessary */
  176. if(style.visualClass==TrueColor || style.visualClass==DirectColor){
  177. XtVaSetValues(edit.oldButton,
  178. XmNbackground,edit.color_set->bg.pixel,
  179. XmNarmColor,edit.color_set->bg.pixel,
  180. XmNforeground,edit.color_set->fg.pixel,
  181. XmNtopShadowColor,edit.color_set->ts.pixel,
  182. XmNbottomShadowColor,edit.color_set->bs.pixel,NULL);
  183. }
  184. InitializeNewButton();
  185. SetScales(&edit.color_set->bg);
  186. XtManageChild(edit.DialogShell);
  187. XMapRaised(style.display, XtWindow(edit.DialogShell));
  188. }
  189. }
  190. }
  191. /************************************************************************
  192. * CreateColorEditor()
  193. * Create the Color Editor Dialog
  194. ************************************************************************/
  195. static void
  196. CreateColorEditor(
  197. Widget parent )
  198. {
  199. int n,i;
  200. Arg args[MAX_ARGS];
  201. Widget sampleTB;
  202. Widget sampleForm;
  203. Widget sliderTB;
  204. XmString string; /* temp Xm string */
  205. Widget widgetlist1[10]; /* main_form */
  206. Widget widgetlist2[16]; /* sliderForm */
  207. Widget widgetlist3[10]; /* sampleForm */
  208. int widget_count1 = 0;
  209. int widget_count2 = 0;
  210. int widget_count3 = 0;
  211. XmString button_string[NUM_LABELS];
  212. Pixel foreground, background;
  213. int height;
  214. WidgetList children;
  215. Dimension w, width_old, width_new;
  216. edit.current_scale = NONE;
  217. /* Set up DialogBox button labels. */
  218. button_string[0] = CMPSTR((String) _DtOkString);
  219. button_string[1] = CMPSTR((String) _DtCancelString);
  220. button_string[2] = CMPSTR((String) _DtHelpString);
  221. /* Note that save.poscnt has been initialized elsewhere.
  222. * save.posArgs may contain information from restoreColorEdit(). */
  223. XtSetArg(args[save.poscnt], XmNchildType, XmWORK_AREA); save.poscnt++;
  224. XtSetArg(save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS);
  225. save.poscnt++;
  226. XtSetArg(save.posArgs[save.poscnt], XmNbuttonLabelStrings,
  227. button_string);
  228. save.poscnt++;
  229. XtSetArg(save.posArgs[save.poscnt], XmNdefaultPosition, False);
  230. save.poscnt++;
  231. edit.DialogShell = __DtCreateDialogBoxDialog(parent,"colorEditDlg",
  232. save.posArgs, save.poscnt);
  233. XtAddCallback(edit.DialogShell, XmNmapCallback, sliderLayoutCB, NULL);
  234. XtAddCallback(edit.DialogShell, XmNcallback, dialogBoxCB, NULL);
  235. XtAddCallback(edit.DialogShell, XmNmapCallback, _DtmapCB, parent);
  236. XtAddCallback(edit.DialogShell, XmNhelpCallback,
  237. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_MODIFY_PALETTE_DIALOG);
  238. XmStringFree(button_string[0]);
  239. XmStringFree(button_string[1]);
  240. XmStringFree(button_string[2]);
  241. widgetlist1[0] = _DtDialogBoxGetButton(edit.DialogShell,2);
  242. n=0;
  243. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  244. XtSetArg(args[n], XmNcancelButton, widgetlist1[0]); n++;
  245. XtSetValues (edit.DialogShell, args, n);
  246. n=0;
  247. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(17, 16, "Style Manager - Modify Color"))); n++;
  248. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  249. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  250. XtSetValues (XtParent(edit.DialogShell), args, n);
  251. n=0;
  252. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  253. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  254. edit.main_form = XmCreateForm(edit.DialogShell, "main_form", args, n);
  255. n=0;
  256. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  257. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  258. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  259. XtSetArg (args[n], XmNmarginWidth, 0); n++;
  260. XtSetArg (args[n], XmNmarginHeight, 0); n++;
  261. string = CMPSTR(((char *)GETMESSAGE(17, 4, "Color Sample")));
  262. XtSetArg (args[n], XmNtitleString, string); n++;
  263. sampleTB = _DtCreateTitleBox(edit.main_form, "sampleTB", args, n);
  264. widgetlist1[widget_count1++] = sampleTB;
  265. XmStringFree(string);
  266. n=0;
  267. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  268. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  269. sampleForm = XmCreateForm(sampleTB, "sampleForm", args, n);
  270. /* Create Old and New Buttons */
  271. if(style.visualClass==TrueColor || style.visualClass==DirectColor){
  272. edit.oldButtonColor.bg.pixel = edit.color_set->bg.pixel;
  273. edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
  274. edit.oldButtonColor.sc.pixel = edit.color_set->sc.pixel;
  275. edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
  276. edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
  277. CopyPixelSet(&edit.oldButtonColor,edit.color_set);
  278. }else{
  279. InitializeOldButton();
  280. }
  281. if(!OldNewSame) {
  282. n=0;
  283. string = CMPSTR(((char *)GETMESSAGE(17, 5, "Old")));
  284. XtSetArg(args[n], XmNlabelString, string); n++;
  285. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  286. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  287. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  288. /* Set the old button color to the color of the selected button */
  289. XtSetArg(args[n], XmNforeground, edit.oldButtonColor.fg.pixel); n++;
  290. XtSetArg(args[n], XmNbackground, edit.oldButtonColor.bg.pixel); n++;
  291. XtSetArg(args[n], XmNarmColor, edit.oldButtonColor.sc.pixel); n++;
  292. XtSetArg(args[n], XmNtopShadowColor,
  293. edit.oldButtonColor.ts.pixel); n++;
  294. XtSetArg(args[n], XmNbottomShadowColor,
  295. edit.oldButtonColor.bs.pixel); n++;
  296. edit.oldButton =
  297. XmCreatePushButton(sampleForm, "oldButton", args, n);
  298. widgetlist3[widget_count3++] = edit.oldButton;
  299. XmStringFree(string);
  300. }
  301. string = CMPSTR(((char *)GETMESSAGE(17, 6, "New")));
  302. n=0;
  303. XtSetArg(args[n], XmNlabelString, string); n++;
  304. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  305. if(!OldNewSame) {
  306. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  307. XtSetArg (args[n], XmNleftWidget, edit.oldButton); n++;
  308. }
  309. else {
  310. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  311. }
  312. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  313. edit.newButton = XmCreatePushButton(sampleForm, "newButton", args, n);
  314. widgetlist3[widget_count3++] = edit.newButton;
  315. XmStringFree(string);
  316. if(!OldNewSame) {
  317. /* make old and new button both the size of the larger of the two */
  318. width_old = XtWidth(edit.oldButton);
  319. width_new = XtWidth(edit.newButton);
  320. w = (width_old>width_new) ? width_old : width_new;
  321. n=0;
  322. XtSetArg (args[n], XmNrecomputeSize, False); n++;
  323. XtSetArg (args[n], XmNwidth, w+2*BUTTON_MARGIN); n++;
  324. XtSetArg (args[n], XmNheight, w+2*BUTTON_MARGIN); n++;
  325. XtSetValues(edit.oldButton, args, n);
  326. XtSetValues(edit.newButton, args, n);
  327. }
  328. else
  329. {
  330. w = XtWidth(edit.newButton);
  331. n=0;
  332. XtSetArg (args[n], XmNrecomputeSize, False); n++;
  333. XtSetArg (args[n], XmNwidth, w+2*BUTTON_MARGIN); n++;
  334. XtSetArg (args[n], XmNheight, w+2*BUTTON_MARGIN); n++;
  335. XtSetValues(edit.newButton, args, n);
  336. }
  337. InitializeNewButton();
  338. n=0;
  339. string = CMPSTR(((char *)GETMESSAGE(17, 7, "Grab Color")));
  340. XtSetArg(args[n], XmNlabelString, string); n++;
  341. XtSetArg(args[n], XmNnavigationType, XmTAB_GROUP); n++;
  342. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  343. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  344. XtSetArg(args[n], XmNmarginHeight, LB_MARGIN_HEIGHT); n++;
  345. XtSetArg(args[n], XmNmarginWidth, LB_MARGIN_WIDTH); n++;
  346. edit.grabColor = XmCreatePushButtonGadget(sampleForm, "grabColor", args, n);
  347. widgetlist3[widget_count3++] = edit.grabColor;
  348. XtAddCallback(edit.grabColor, XmNactivateCallback,
  349. grabcolorCB, (XtPointer)NULL);
  350. XmStringFree(string);
  351. /* Create frame for RGB/HSV scales */
  352. n = 0;
  353. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  354. XtSetArg(args[n], XmNtopWidget, sampleTB); n++;
  355. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  356. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  357. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  358. XtSetArg (args[n], XmNmarginWidth, 0); n++;
  359. XtSetArg (args[n], XmNmarginHeight, 0); n++;
  360. string = CMPSTR(((char *)GETMESSAGE(17, 8, "Color Editor")));
  361. XtSetArg (args[n], XmNtitleString, string); n++;
  362. sliderTB = _DtCreateTitleBox(edit.main_form, "sliderTB", args, n);
  363. widgetlist1[widget_count1++] = sliderTB;
  364. XmStringFree(string);
  365. n = 0;
  366. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  367. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  368. edit.sliderForm = XmCreateForm(sliderTB, "sliderForm", args, n);
  369. /*
  370. * Create Hue label and scale
  371. */
  372. n = 0;
  373. string = CMPSTR(((char *)GETMESSAGE(17, 9, "Hue")));
  374. XtSetArg(args[n], XmNlabelString, string); n++;
  375. edit.hueLabel = XmCreateLabelGadget(edit.sliderForm, "hueLabel", args, n);
  376. widgetlist2[widget_count2++] = edit.hueLabel;
  377. XmStringFree(string);
  378. n = 0;
  379. XtSetArg(args[n], XmNshowValue, TRUE); n++;
  380. XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
  381. XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_BOTTOM); n++;
  382. XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
  383. XtSetArg(args[n], XmNmaximum, 359); n++;
  384. XtSetArg(args[n], XmNminimum, 0x0); n++;
  385. XtSetArg(args[n], XmNincrement, 1); n++;
  386. edit.hueScale = XmCreateScale(edit.sliderForm, "hueScale", args, n);
  387. widgetlist2[widget_count2++] = edit.hueScale;
  388. XtAddCallback(edit.hueScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) HUE);
  389. XtAddCallback(edit.hueScale, XmNdragCallback, changHSV_CB, (XtPointer) HUE );
  390. /*
  391. * Create RGB scales
  392. */
  393. string = CMPSTR(((char *)GETMESSAGE(17, 10, "R")));
  394. n = 0;
  395. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  396. XtSetArg(args[n], XmNlabelString, string); n++;
  397. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  398. edit.redLabel = XmCreateLabelGadget(edit.sliderForm, "redLabel", args, n);
  399. widgetlist2[widget_count2++] = edit.redLabel;
  400. XmStringFree(string);
  401. string = CMPSTR(((char *)GETMESSAGE(17, 11, "G")));
  402. n = 0;
  403. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  404. XtSetArg(args[n], XmNlabelString, string); n++;
  405. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  406. edit.greenLabel = XmCreateLabelGadget(edit.sliderForm, "greenLabel", args, n);
  407. widgetlist2[widget_count2++] = edit.greenLabel;
  408. XmStringFree(string);
  409. string = CMPSTR(((char *)GETMESSAGE(17, 12, "B")));
  410. n = 0;
  411. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  412. XtSetArg(args[n], XmNlabelString, string); n++;
  413. XtSetArg(args[n], XmNmarginHeight, 0); n++;
  414. edit.blueLabel = XmCreateLabelGadget(edit.sliderForm, "blueLabel", args, n);
  415. widgetlist2[widget_count2++] = edit.blueLabel;
  416. XmStringFree(string);
  417. n = 0;
  418. XtSetArg(args[n], XmNshowValue, TRUE); n++;
  419. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  420. XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
  421. XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
  422. XtSetArg(args[n], XmNmaximum, 0xff); n++;
  423. XtSetArg(args[n], XmNminimum, 0x0); n++;
  424. XtSetArg(args[n], XmNincrement, 1); n++;
  425. XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
  426. widgetlist2[widget_count2++] = edit.redScale =
  427. XmCreateScale(edit.sliderForm, "redScale", args, n);
  428. XtAddCallback(edit.redScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) RED);
  429. XtAddCallback(edit.redScale, XmNdragCallback, changRGB_CB, (XtPointer) RED );
  430. widgetlist2[widget_count2++] = edit.greenScale =
  431. XmCreateScale(edit.sliderForm, "greenScale", args, n);
  432. XtAddCallback(edit.greenScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) GREEN );
  433. XtAddCallback(edit.greenScale, XmNdragCallback, changRGB_CB, (XtPointer) GREEN );
  434. widgetlist2[widget_count2++] = edit.blueScale =
  435. XmCreateScale(edit.sliderForm, "blueScale", args, n);
  436. XtAddCallback(edit.blueScale, XmNvalueChangedCallback, changRGB_CB, (XtPointer) BLUE );
  437. XtAddCallback(edit.blueScale, XmNdragCallback, changRGB_CB, (XtPointer) BLUE);
  438. /*
  439. * Create SV scales
  440. */
  441. /* create Saturation pixmap */
  442. n=0;
  443. XtSetArg(args[n], XmNforeground, &foreground); n++;
  444. XtSetArg(args[n], XmNbackground, &background); n++;
  445. XtGetValues(edit.sliderForm, args, n);
  446. n = 0;
  447. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  448. XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
  449. XtSetArg(args[n], XmNlabelPixmap, XmGetPixmap(style.screen, SATURATION_BITS,
  450. foreground, background)); n++;
  451. XtSetArg(args[n], XmNmarginHeight, 3); n++;
  452. edit.satLabel = XmCreateLabelGadget(edit.sliderForm, "satLabel", args, n);
  453. widgetlist2[widget_count2++] = edit.satLabel;
  454. /* create Value pixmap */
  455. n = 0;
  456. XtSetArg(args[n], XmNalignment, XmALIGNMENT_END); n++;
  457. XtSetArg(args[n], XmNlabelType, XmPIXMAP); n++;
  458. XtSetArg(args[n], XmNlabelPixmap, XmGetPixmap(style.screen, VALUE_BITS,
  459. foreground, background)); n++;
  460. XtSetArg(args[n], XmNmarginHeight, 3); n++;
  461. edit.valLabel = XmCreateLabelGadget(edit.sliderForm, "valLabel", args, n);
  462. widgetlist2[widget_count2++] = edit.valLabel;
  463. n = 0;
  464. XtSetArg(args[n], XmNshowValue, TRUE); n++;
  465. XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
  466. XtSetArg(args[n], XmNprocessingDirection, XmMAX_ON_RIGHT); n++;
  467. XtSetArg(args[n], XmNhighlightThickness, SCALE_HIGHLIGHT_THICKNESS); n++;
  468. XtSetArg(args[n], XmNmaximum, 0xff); n++;
  469. XtSetArg(args[n], XmNminimum, 0x0); n++;
  470. XtSetArg(args[n], XmNincrement, 1); n++;
  471. XtSetArg(args[n], XmNscaleWidth, SCALE_WIDTH); n++;
  472. widgetlist2[widget_count2++] = edit.satScale =
  473. XmCreateScale(edit.sliderForm, "satScale", args, n);
  474. XtAddCallback(edit.satScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) SATURATION);
  475. XtAddCallback(edit.satScale, XmNdragCallback, changHSV_CB, (XtPointer) SATURATION );
  476. widgetlist2[widget_count2++] = edit.valScale =
  477. XmCreateScale(edit.sliderForm, "valScale", args, n);
  478. XtAddCallback(edit.valScale, XmNvalueChangedCallback, changHSV_CB, (XtPointer) VALUE);
  479. XtAddCallback(edit.valScale, XmNdragCallback, changHSV_CB, (XtPointer) VALUE );
  480. /* Set the scales to the bg component of the selected color */
  481. SetScales(&edit.color_set->bg);
  482. /* Do all the mapping */
  483. XtManageChildren(widgetlist3, widget_count3);
  484. XtManageChild(sampleForm);
  485. XtManageChildren(widgetlist2, widget_count2);
  486. XtManageChild(edit.sliderForm);
  487. XtManageChildren(widgetlist1, widget_count1);
  488. XtManageChild(edit.main_form);
  489. XtManageChild(edit.DialogShell);
  490. if(TypeOfMonitor == XmCO_HIGH_COLOR)
  491. {
  492. /* set the trough colors of the RGB scales -
  493. get the composite children of the scales -
  494. child[1] is the scrollbar */
  495. n=0;
  496. XtSetArg(args[n], XtNchildren, &children); n++;
  497. XtGetValues(edit.redScale, args, n);
  498. n=0;
  499. XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"red")); n++;
  500. XtSetValues (children[1], args, n);
  501. n=0;
  502. XtSetArg(args[n], XtNchildren, &children); n++;
  503. XtGetValues(edit.greenScale, args, n);
  504. n=0;
  505. XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"green")); n++;
  506. XtSetValues (children[1], args, n);
  507. n=0;
  508. XtSetArg(args[n], XtNchildren, &children); n++;
  509. XtGetValues(edit.blueScale, args, n);
  510. n=0;
  511. XtSetArg(args[n], XmNtroughColor, GetPixel(edit.main_form,"blue")); n++;
  512. XtSetValues (children[1], args, n);
  513. }
  514. }
  515. static void
  516. sliderLayoutCB(
  517. Widget w,
  518. XtPointer client_data,
  519. XtPointer call_data )
  520. {
  521. int n;
  522. Arg args[12];
  523. Dimension redLabelWidth;
  524. Dimension greenLabelWidth;
  525. Dimension blueLabelWidth;
  526. Dimension satLabelWidth;
  527. Dimension valLabelWidth;
  528. Dimension MaxLabelWidth;
  529. Dimension redLabelHeight;
  530. Dimension satLabelHeight;
  531. Dimension valLabelHeight;
  532. Dimension redScaleHeight;
  533. Dimension TopOffset;
  534. Dimension scale_width;
  535. Dimension pieces;
  536. /*
  537. * Do the scale and label attachments
  538. */
  539. redLabelHeight = XtHeight(edit.redLabel);
  540. MaxLabelWidth = redLabelWidth = XtWidth(edit.redLabel);
  541. greenLabelWidth = XtWidth(edit.greenLabel);
  542. if (greenLabelWidth > MaxLabelWidth)
  543. {
  544. MaxLabelWidth = greenLabelWidth;
  545. }
  546. blueLabelWidth = XtWidth(edit.blueLabel);
  547. if (blueLabelWidth > MaxLabelWidth)
  548. {
  549. MaxLabelWidth = blueLabelWidth;
  550. }
  551. satLabelHeight = XtHeight(edit.satLabel);
  552. satLabelWidth = XtWidth(edit.satLabel);
  553. if (satLabelWidth > MaxLabelWidth)
  554. {
  555. MaxLabelWidth = satLabelWidth;
  556. }
  557. valLabelHeight = XtHeight(edit.valLabel);
  558. valLabelWidth = XtWidth(edit.valLabel);
  559. if (valLabelWidth > MaxLabelWidth)
  560. {
  561. MaxLabelWidth = valLabelWidth;
  562. }
  563. redScaleHeight = XtHeight(edit.redScale);
  564. /* Attach grab button to New button if they are overlapping */
  565. if(!OldNewSame)
  566. pieces = XtWidth(edit.oldButton) +
  567. XtWidth(edit.newButton) +
  568. XtWidth(edit.grabColor) +
  569. 4*style.horizontalSpacing;
  570. else
  571. pieces = XtWidth(edit.newButton) +
  572. XtWidth(edit.grabColor) +
  573. 3*style.horizontalSpacing;
  574. if (XtWidth(edit.main_form) < pieces)
  575. {
  576. n=0;
  577. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  578. XtSetArg(args[n], XmNleftWidget, edit.newButton); n++;
  579. XtSetValues (edit.grabColor, args, n);
  580. scale_width = XtWidth(edit.main_form) - MaxLabelWidth -
  581. XtWidth(edit.hueScale) - 4*style.horizontalSpacing;
  582. n=0;
  583. XtSetArg(args[n], XmNscaleWidth, scale_width); n++;
  584. XtSetValues (edit.redScale, args, n);
  585. XtSetValues (edit.greenScale, args, n);
  586. XtSetValues (edit.blueScale, args, n);
  587. XtSetValues (edit.satScale, args, n);
  588. XtSetValues (edit.valScale, args, n);
  589. }
  590. /* Hue Label */
  591. n=0;
  592. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  593. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  594. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  595. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  596. XtSetValues (edit.hueLabel, args, n);
  597. /* Hue Scale */
  598. n=0;
  599. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  600. XtSetArg(args[n], XmNtopWidget, edit.hueLabel); n++;
  601. XtSetArg(args[n], XmNtopOffset, style.verticalSpacing); n++;
  602. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  603. XtSetArg(args[n], XmNbottomOffset,
  604. 2*(style.verticalSpacing + redScaleHeight) + 40); n++;
  605. XtSetArg(args[n], XmNleftAttachment, XmATTACH_NONE); n++;
  606. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  607. XtSetValues (edit.hueScale, args, n);
  608. /* Red Label */
  609. n=0;
  610. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  611. XtSetArg(args[n], XmNtopWidget, edit.hueLabel); n++;
  612. TopOffset = style.verticalSpacing + redScaleHeight - redLabelHeight;
  613. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  614. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  615. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  616. XtSetArg(args[n], XmNleftOffset,
  617. style.horizontalSpacing + (MaxLabelWidth - redLabelWidth)); n++;
  618. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  619. XtSetValues (edit.redLabel, args, n);
  620. /* Green Label */
  621. n=0;
  622. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  623. XtSetArg(args[n], XmNtopWidget, edit.redLabel); n++;
  624. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  625. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  626. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  627. XtSetArg(args[n], XmNleftOffset,
  628. style.horizontalSpacing + (MaxLabelWidth - greenLabelWidth)); n++;
  629. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  630. XtSetValues (edit.greenLabel, args, n);
  631. /* Blue Label */
  632. n=0;
  633. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  634. XtSetArg(args[n], XmNtopWidget, edit.greenLabel); n++;
  635. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  636. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  637. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  638. XtSetArg(args[n], XmNleftOffset,
  639. style.horizontalSpacing + (MaxLabelWidth - blueLabelWidth)); n++;
  640. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  641. XtSetValues (edit.blueLabel, args, n);
  642. /* Saturation Label */
  643. n=0;
  644. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  645. XtSetArg(args[n], XmNtopWidget, edit.blueLabel); n++;
  646. TopOffset = style.verticalSpacing + 40 + redScaleHeight - satLabelHeight;
  647. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  648. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  649. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  650. XtSetArg(args[n], XmNleftOffset,
  651. style.horizontalSpacing + (MaxLabelWidth - satLabelWidth)); n++;
  652. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  653. XtSetValues (edit.satLabel, args, n);
  654. /* Value Label */
  655. n=0;
  656. XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  657. XtSetArg(args[n], XmNtopWidget, edit.satLabel); n++;
  658. TopOffset = style.verticalSpacing + redScaleHeight - valLabelHeight;
  659. XtSetArg(args[n], XmNtopOffset, TopOffset); n++;
  660. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  661. XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  662. XtSetArg(args[n], XmNleftOffset,
  663. style.horizontalSpacing + (MaxLabelWidth - valLabelWidth)); n++;
  664. XtSetArg(args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  665. XtSetValues (edit.valLabel, args, n);
  666. /* Red Scale */
  667. n=0;
  668. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  669. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  670. XtSetArg(args[n], XmNbottomWidget, edit.redLabel); n++;
  671. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  672. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  673. XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
  674. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  675. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  676. XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
  677. XtSetValues (edit.redScale, args, n);
  678. /* Green Scale */
  679. n=0;
  680. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  681. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  682. XtSetArg(args[n], XmNbottomWidget, edit.greenLabel); n++;
  683. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  684. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  685. XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
  686. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  687. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  688. XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
  689. XtSetValues (edit.greenScale, args, n);
  690. /* Blue Scale */
  691. n=0;
  692. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  693. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  694. XtSetArg(args[n], XmNbottomWidget, edit.blueLabel); n++;
  695. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  696. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  697. XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
  698. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  699. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  700. XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
  701. XtSetValues (edit.blueScale, args, n);
  702. /* Saturation Scale */
  703. n=0;
  704. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  705. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  706. XtSetArg(args[n], XmNbottomWidget, edit.satLabel); n++;
  707. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  708. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  709. XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
  710. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  711. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  712. XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
  713. XtSetValues (edit.satScale, args, n);
  714. /* Value Scale */
  715. n=0;
  716. XtSetArg(args[n], XmNtopAttachment, XmATTACH_NONE); n++;
  717. XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET); n++;
  718. XtSetArg(args[n], XmNbottomWidget, edit.valLabel); n++;
  719. XtSetArg(args[n], XmNbottomOffset, 0); n++;
  720. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  721. XtSetArg(args[n], XmNleftWidget, edit.redLabel); n++;
  722. XtSetArg(args[n], XmNleftOffset, style.horizontalSpacing); n++;
  723. XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
  724. XtSetArg(args[n], XmNrightWidget, edit.hueScale); n++;
  725. XtSetValues (edit.valScale, args, n);
  726. XtRemoveCallback(edit.DialogShell, XmNmapCallback, sliderLayoutCB, NULL);
  727. }
  728. /************************************************************************
  729. * InitializeNewButton()
  730. * set NewButton colors to point to the PixelSet being
  731. * modified so they both get updated.
  732. ************************************************************************/
  733. static void
  734. InitializeNewButton( void )
  735. {
  736. int n;
  737. Arg args[6];
  738. n=0;
  739. XtSetArg(args[n], XmNforeground, edit.color_set->fg.pixel); n++;
  740. XtSetArg(args[n], XmNbackground, edit.color_set->bg.pixel); n++;
  741. XtSetArg(args[n], XmNarmColor, edit.color_set->sc.pixel); n++;
  742. if(UsePixmaps == FALSE)
  743. {
  744. XtSetArg(args[n], XmNtopShadowColor,
  745. edit.color_set->ts.pixel); n++;
  746. XtSetArg(args[n], XmNbottomShadowColor,
  747. edit.color_set->bs.pixel); n++;
  748. }
  749. XtSetValues(edit.newButton,args,n);
  750. }
  751. /************************************************************************
  752. * InitializeOldButton()
  753. * Called only once from CreateColorEditor. Allocates a
  754. * new PixelSet to hold onto the original ColorSet values
  755. * while the newButton gets updated. Shouldn't be called if
  756. * monitor is B_W.
  757. ************************************************************************/
  758. static void
  759. InitializeOldButton( void )
  760. {
  761. int i,n, numOfPixels;
  762. unsigned long *pixels;
  763. unsigned long plane_mask;
  764. int hue, val, sat, status;
  765. if(UsePixmaps == FALSE)
  766. if(FgColor == DYNAMIC)
  767. numOfPixels = 5;
  768. else /* FgColor == BLACK or WHITE */
  769. numOfPixels = 4;
  770. else /* UsePixmaps == TRUE */
  771. if(FgColor == DYNAMIC)
  772. numOfPixels = 3;
  773. else /* FgColor == BLACK or WHITE */
  774. numOfPixels = 2;
  775. /* Allocate enough space to store numOfPixels. */
  776. pixels = (unsigned long *)XtMalloc (numOfPixels * sizeof (unsigned long));
  777. /* Allocate new color cells for the new button */
  778. status = XAllocColorCells (style.display, style.colormap,
  779. 0, &plane_mask, 0, pixels, numOfPixels);
  780. if(status == FALSE)
  781. {
  782. /* Dialog stating that can't allocate enough pixels to color
  783. the old button. Just don't create old button.*/
  784. edit.oldButtonColor.bg.pixel = edit.color_set->bg.pixel;
  785. edit.oldButtonColor.bg.flags = edit.color_set->bg.flags;
  786. edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
  787. edit.oldButtonColor.fg.flags = edit.color_set->fg.flags;
  788. edit.oldButtonColor.sc.pixel = edit.color_set->sc.pixel;
  789. edit.oldButtonColor.sc.flags = edit.color_set->sc.flags;
  790. edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
  791. edit.oldButtonColor.bs.flags = edit.color_set->bs.flags;
  792. edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
  793. edit.oldButtonColor.ts.flags = edit.color_set->ts.flags;
  794. OldNewSame = True;
  795. }
  796. else
  797. {
  798. /* Assign the pixels */
  799. n=0;
  800. edit.oldButtonColor.bg.pixel = pixels[n++];
  801. edit.oldButtonColor.bg.flags = DoRed | DoGreen | DoBlue;
  802. edit.oldButtonColor.sc.pixel = pixels[n++];
  803. edit.oldButtonColor.sc.flags = DoRed | DoGreen | DoBlue;
  804. if(FgColor == DYNAMIC)
  805. {
  806. edit.oldButtonColor.fg.pixel = pixels[n++];
  807. edit.oldButtonColor.fg.flags = DoRed | DoGreen | DoBlue;
  808. }
  809. else
  810. {
  811. edit.oldButtonColor.fg.pixel = edit.color_set->fg.pixel;
  812. edit.oldButtonColor.fg.flags = edit.color_set->fg.flags;
  813. }
  814. if(UsePixmaps == FALSE)
  815. {
  816. edit.oldButtonColor.bs.pixel = pixels[n++];
  817. edit.oldButtonColor.bs.flags = DoRed | DoGreen | DoBlue;
  818. edit.oldButtonColor.ts.pixel = pixels[n];
  819. edit.oldButtonColor.ts.flags = DoRed | DoGreen | DoBlue;
  820. }
  821. else
  822. {
  823. edit.oldButtonColor.bs.pixel = edit.color_set->bs.pixel;
  824. edit.oldButtonColor.bs.flags = edit.color_set->bs.flags;
  825. edit.oldButtonColor.ts.pixel = edit.color_set->ts.pixel;
  826. edit.oldButtonColor.ts.flags = edit.color_set->ts.flags;
  827. }
  828. }
  829. CopyPixelSet(&edit.oldButtonColor,edit.color_set);
  830. RGBtoHSV(edit.oldButtonColor.bg.red,
  831. edit.oldButtonColor.bg.green,
  832. edit.oldButtonColor.bg.blue,
  833. &hue, &sat, &val);
  834. XtFree((char *)pixels);
  835. }
  836. /************************************************************************
  837. * GenerateColors()
  838. * Generates new RGB values for fg, ts, bs, sc based on bg.
  839. * The Color generation routine will be exported in motif1.1
  840. * The generated colors are then used to update the pixels
  841. * of the ColorSet being edited.
  842. ************************************************************************/
  843. static void
  844. GenerateColors( void )
  845. {
  846. int hue, sat, val;
  847. int j=0;
  848. XColor colors[5];
  849. if (edit.calcRGB == NULL)
  850. edit.calcRGB = XmGetColorCalculation();
  851. (*edit.calcRGB) (&edit.color_set->bg, &edit.color_set->fg,
  852. &edit.color_set->sc, &edit.color_set->ts,
  853. &edit.color_set->bs);
  854. RGBtoHSV(edit.color_set->bg.red, edit.color_set->bg.green,
  855. edit.color_set->bg.blue,
  856. &hue, &sat, &val);
  857. colors[j++] = edit.color_set->bg;
  858. colors[j++] = edit.color_set->sc;
  859. if (FgColor == DYNAMIC)
  860. colors[j++] = edit.color_set->fg;
  861. if(UsePixmaps == FALSE)
  862. {
  863. colors[j++] = edit.color_set->ts;
  864. colors[j++] = edit.color_set->bs;
  865. }
  866. else
  867. {
  868. edit.color_set->ts.red = 65535;
  869. edit.color_set->ts.green = 65535;
  870. edit.color_set->ts.blue = 65535;
  871. edit.color_set->bs.red = 0;
  872. edit.color_set->bs.green = 0;
  873. edit.color_set->bs.blue = 0;
  874. }
  875. if(style.visualClass==PseudoColor || style.visualClass==StaticColor)
  876. {
  877. XStoreColors(style.display, style.colormap, colors, j );
  878. }
  879. else if(style.visualClass==TrueColor || style.visualClass==DirectColor)
  880. {
  881. static unsigned long pixels[4];
  882. static int count=0;
  883. if(count){
  884. XFreeColors(style.display,style.colormap,pixels,count,0);
  885. count=0;
  886. }
  887. if(XAllocColor(style.display,style.colormap,&edit.color_set->fg))
  888. pixels[count++]=edit.color_set->fg.pixel;
  889. if(XAllocColor(style.display,style.colormap,&edit.color_set->bg))
  890. pixels[count++]=edit.color_set->bg.pixel;
  891. if(XAllocColor(style.display,style.colormap,&edit.color_set->ts))
  892. pixels[count++]=edit.color_set->ts.pixel;
  893. if(XAllocColor(style.display,style.colormap,&edit.color_set->bs))
  894. pixels[count++]=edit.color_set->bs.pixel;
  895. XtVaSetValues(edit.newButton,
  896. XmNbackground,edit.color_set->bg.pixel,
  897. XmNarmColor,edit.color_set->bg.pixel,
  898. XmNforeground,edit.color_set->fg.pixel,
  899. XmNtopShadowColor,edit.color_set->ts.pixel,
  900. XmNbottomShadowColor,edit.color_set->bs.pixel,NULL);
  901. }
  902. }
  903. /************************************************************************
  904. * changeRGB_CB()
  905. * Called when one of the RGB scales is moved
  906. ************************************************************************/
  907. static void
  908. changRGB_CB(
  909. Widget w,
  910. XtPointer client_data,
  911. XtPointer call_data )
  912. {
  913. int reason_code;
  914. int value;
  915. int color;
  916. reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
  917. if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
  918. {
  919. color = (int) (intptr_t) client_data;
  920. value = ((XmScaleCallbackStruct *)call_data)->value;
  921. if (edit.current_scale == NONE)
  922. {
  923. edit.current_scale = color;
  924. /*
  925. * Shift value -- to make up for scale max of only 0xff
  926. */
  927. value <<= 8;
  928. switch (color)
  929. {
  930. case RED:
  931. edit.color_set->bg.red = value;
  932. break;
  933. case GREEN:
  934. edit.color_set->bg.green = value;
  935. break;
  936. case BLUE:
  937. edit.color_set->bg.blue = value;
  938. break;
  939. default:
  940. /* this case should never be hit */
  941. return;
  942. }
  943. SetScales(&edit.color_set->bg);
  944. GenerateColors();
  945. edit.current_scale = NONE;
  946. }
  947. }
  948. }
  949. /************************************************************************
  950. * changHSV_CB()
  951. * Called when one of the HSV scales is moved
  952. ************************************************************************/
  953. static void
  954. changHSV_CB(
  955. Widget w,
  956. XtPointer client_data,
  957. XtPointer call_data )
  958. {
  959. int reason_code;
  960. int value;
  961. int scale;
  962. int hue, sat, val;
  963. reason_code = ((XmAnyCallbackStruct *)call_data)->reason;
  964. if ( reason_code == XmCR_VALUE_CHANGED || reason_code == XmCR_DRAG )
  965. {
  966. scale = (int) (intptr_t) client_data;
  967. value = ((XmScaleCallbackStruct *)call_data)->value;
  968. if (edit.current_scale == NONE)
  969. {
  970. edit.current_scale = scale;
  971. switch (scale)
  972. {
  973. case HUE:
  974. hue = value;
  975. XmScaleGetValue(edit.satScale, &sat);
  976. XmScaleGetValue(edit.valScale, &val);
  977. break;
  978. case SATURATION:
  979. XmScaleGetValue(edit.hueScale, &hue);
  980. sat = value;
  981. XmScaleGetValue(edit.valScale, &val);
  982. break;
  983. case VALUE:
  984. XmScaleGetValue(edit.hueScale, &hue);
  985. XmScaleGetValue(edit.satScale, &sat);
  986. val = value;
  987. break;
  988. default:
  989. /* this case should never be hit */
  990. return;
  991. }
  992. HSVtoRGB(hue, sat, val,
  993. &edit.color_set->bg.red,
  994. &edit.color_set->bg.green,
  995. &edit.color_set->bg.blue);
  996. SetRGBHSVScales(&edit.color_set->bg, hue, sat, val);
  997. GenerateColors();
  998. edit.current_scale = NONE;
  999. }
  1000. }
  1001. }
  1002. /************************************************************************
  1003. * SetScales()
  1004. * passed a XColor, generates HSV values and updates all scales.
  1005. ************************************************************************/
  1006. static void
  1007. SetScales(
  1008. XColor *rgb )
  1009. {
  1010. int h, s, v;
  1011. RGBtoHSV(rgb->red, rgb->green, rgb->blue, &h, &s, &v);
  1012. SetRGBHSVScales(rgb, h, s, v);
  1013. }
  1014. /************************************************************************
  1015. * SetRGBHSVScales()
  1016. * updates RGB and HSV scales
  1017. ************************************************************************/
  1018. static void
  1019. SetRGBHSVScales(
  1020. XColor *rgb,
  1021. int h,
  1022. int s,
  1023. int v )
  1024. {
  1025. XmScaleSetValue(edit.redScale,rgb->red >> 8);
  1026. XmScaleSetValue(edit.greenScale,rgb->green >> 8);
  1027. XmScaleSetValue(edit.blueScale,rgb->blue >> 8);
  1028. XmScaleSetValue(edit.hueScale,h);
  1029. XmScaleSetValue(edit.satScale,s);
  1030. XmScaleSetValue(edit.valScale,v);
  1031. }
  1032. /************************************************************************
  1033. * CopyPixelSet()
  1034. *
  1035. ************************************************************************/
  1036. static void
  1037. CopyPixelSet(
  1038. ColorSet *color_set_dest,
  1039. ColorSet *color_set_src )
  1040. {
  1041. Arg args[6];
  1042. int n;
  1043. int j=0;
  1044. XColor colors[5];
  1045. color_set_dest->bg.red = color_set_src->bg.red;
  1046. color_set_dest->bg.blue = color_set_src->bg.blue;
  1047. color_set_dest->bg.green = color_set_src->bg.green;
  1048. if(OldNewSame)
  1049. color_set_dest->bg.pixel = color_set_src->bg.pixel;
  1050. colors[j++] = color_set_dest->bg;
  1051. color_set_dest->sc.red = color_set_src->sc.red;
  1052. color_set_dest->sc.blue = color_set_src->sc.blue;
  1053. color_set_dest->sc.green = color_set_src->sc.green;
  1054. if(OldNewSame)
  1055. color_set_dest->bg.pixel = color_set_src->bg.pixel;
  1056. colors[j++] = color_set_dest->sc;
  1057. color_set_dest->fg.red = color_set_src->fg.red;
  1058. color_set_dest->fg.blue = color_set_src->fg.blue;
  1059. color_set_dest->fg.green = color_set_src->fg.green;
  1060. if(FgColor == DYNAMIC)
  1061. {
  1062. if(OldNewSame)
  1063. color_set_dest->bg.pixel = color_set_src->bg.pixel;
  1064. colors[j++] = color_set_dest->fg;
  1065. }
  1066. color_set_dest->ts.red = color_set_src->ts.red;
  1067. color_set_dest->ts.blue = color_set_src->ts.blue;
  1068. color_set_dest->ts.green = color_set_src->ts.green;
  1069. color_set_dest->bs.red = color_set_src->bs.red;
  1070. color_set_dest->bs.blue = color_set_src->bs.blue;
  1071. color_set_dest->bs.green = color_set_src->bs.green;
  1072. if(UsePixmaps == FALSE)
  1073. {
  1074. if(OldNewSame)
  1075. color_set_dest->bg.pixel = color_set_src->bg.pixel;
  1076. colors[j++] = color_set_dest->ts;
  1077. colors[j++] = color_set_dest->bs;
  1078. }
  1079. if(OldNewSame && edit.oldButton != NULL)
  1080. {
  1081. n=0;
  1082. XtSetArg(args[n], XmNforeground, color_set_dest->fg.pixel); n++;
  1083. XtSetArg(args[n], XmNbackground, color_set_dest->bg.pixel); n++;
  1084. XtSetArg(args[n], XmNarmColor, color_set_dest->sc.pixel); n++;
  1085. XtSetArg(args[n], XmNtopShadowColor,
  1086. color_set_dest->ts.pixel); n++;
  1087. XtSetArg(args[n], XmNbottomShadowColor,
  1088. color_set_dest->bs.pixel); n++;
  1089. XtSetValues(edit.oldButton, args, n);
  1090. }
  1091. if(style.visualClass == PseudoColor || style.visualClass == GrayScale)
  1092. XStoreColors(style.display, style.colormap, colors, j );
  1093. }
  1094. /************************************************************************
  1095. * RGBtoHSV()
  1096. *
  1097. ************************************************************************/
  1098. void
  1099. RGBtoHSV(
  1100. #if NeedWidePrototypes
  1101. unsigned int r ,
  1102. unsigned int g ,
  1103. unsigned int b ,
  1104. #else
  1105. unsigned short r,
  1106. unsigned short g,
  1107. unsigned short b,
  1108. #endif
  1109. int *h,
  1110. int *s,
  1111. int *v )
  1112. {
  1113. double red, green, blue;
  1114. double red1, green1, blue1;
  1115. double hue, saturation, value;
  1116. double base;
  1117. red1 = (double)r / 65280.0;
  1118. green1 = (double)g / 65280.0;
  1119. blue1 = (double)b / 65280.0;
  1120. value = max(red1, green1, blue1);
  1121. base = min(red1, green1, blue1);
  1122. if(value != 0.0)
  1123. saturation = (value - base) / value;
  1124. else
  1125. saturation = 0.0;
  1126. hue = 0.0;
  1127. if( saturation != 0.0 )
  1128. {
  1129. red = (value - red1 ) / (value - base);
  1130. green = (value - green1 ) / (value - base);
  1131. blue = (value - blue1 ) / (value - base);
  1132. if(value == red1)
  1133. {
  1134. if(base == green1)
  1135. hue = 5.0 + blue;
  1136. else
  1137. hue = 1.0 - green;
  1138. }
  1139. else if(value == green1)
  1140. {
  1141. if(base == blue1)
  1142. hue = 1.0 + red;
  1143. else
  1144. hue = 3.0 - blue;
  1145. }
  1146. else
  1147. {
  1148. if(base == red1)
  1149. hue = 3.0 + green;
  1150. else
  1151. hue = 5.0 - red;
  1152. }
  1153. hue *= 60.0;
  1154. if( hue == 360.0)
  1155. hue = 0.0;
  1156. }
  1157. *h = (int)hue;
  1158. *s = ((int)(saturation * 65280.0)) >> 8;
  1159. *v = ((int)(value * 65280.0)) >> 8;
  1160. }
  1161. /************************************************************************
  1162. * HSVtoRGB()
  1163. *
  1164. * Converts hue, saturation, and value to RGB values.
  1165. * Hue is in the range 0 to 360, while saturation and value
  1166. * are in the range 0 to 255
  1167. ************************************************************************/
  1168. static void
  1169. HSVtoRGB(
  1170. int h,
  1171. int s,
  1172. int v,
  1173. unsigned short *r,
  1174. unsigned short *g,
  1175. unsigned short *b )
  1176. {
  1177. double p1, p2, p3;
  1178. double hue, sat, val;
  1179. double red = 0.0, green = 0.0, blue = 0.0;
  1180. double i, f;
  1181. hue = (double)h / 60.0;
  1182. i = floor(hue);
  1183. f = hue - i;
  1184. val = (double)v / 255.0;
  1185. sat = (double)s / 255.0;
  1186. p1 = val * (1.0 - sat);
  1187. p2 = val * (1.0 -(sat * f));
  1188. p3 = val * (1.0 -(sat * (1.0 - f)));
  1189. switch((int)i)
  1190. {
  1191. case 0:
  1192. red = val;
  1193. green = p3;
  1194. blue = p1;
  1195. break;
  1196. case 1:
  1197. red = p2;
  1198. green = val;
  1199. blue = p1;
  1200. break;
  1201. case 2:
  1202. red = p1;
  1203. green = val;
  1204. blue = p3;
  1205. break;
  1206. case 3:
  1207. red = p1;
  1208. green = p2;
  1209. blue = val;
  1210. break;
  1211. case 4:
  1212. red = p3;
  1213. green = p1;
  1214. blue = val;
  1215. break;
  1216. case 5:
  1217. red = val;
  1218. green = p1;
  1219. blue = p2;
  1220. break;
  1221. }
  1222. *r = (int)(red * 65280.0);
  1223. *g = (int)(green * 65280.0);
  1224. *b = (int)(blue * 65280.0);
  1225. }
  1226. /************************************************************************
  1227. * max()
  1228. *
  1229. ************************************************************************/
  1230. static double
  1231. max(
  1232. double x,
  1233. double y,
  1234. double z )
  1235. {
  1236. if(x >= y && x >= z)
  1237. return(x);
  1238. if(y >= z && y >= x)
  1239. return(y);
  1240. if(z >= y && z >= x)
  1241. return(z);
  1242. }
  1243. /************************************************************************
  1244. * min()
  1245. *
  1246. ************************************************************************/
  1247. static double
  1248. min(
  1249. double x,
  1250. double y,
  1251. double z )
  1252. {
  1253. if(x <= y && x <= z)
  1254. return(x);
  1255. if(y <= z && y <= x)
  1256. return(y);
  1257. if(z <= y && z <= x)
  1258. return(z);
  1259. }
  1260. /************************************************************************
  1261. * grabcolorCB()
  1262. * Call back routine for grabbing a color from the screen
  1263. ************************************************************************/
  1264. static void
  1265. grabcolorCB(
  1266. Widget w,
  1267. XtPointer client_data,
  1268. XtPointer call_data )
  1269. {
  1270. Cursor cursor = XCreateFontCursor(style.display, XC_crosshair);
  1271. XImage *image_ptr;
  1272. Position x,y;
  1273. XEvent event;
  1274. Pixel pixel;
  1275. XColor colorStruct;
  1276. char color_string[MAX_STR_LEN];
  1277. int status, offset;
  1278. Boolean notDone=True;
  1279. KeySym keySym;
  1280. /* grab the pointer using target cursor */
  1281. status = XtGrabPointer(style.colorDialog, TRUE,
  1282. ButtonPressMask | ButtonReleaseMask,
  1283. GrabModeAsync, GrabModeAsync, None,
  1284. cursor, CurrentTime);
  1285. if (status != GrabSuccess)
  1286. {
  1287. _DtSimpleError (progName, DtWarning, NULL,
  1288. ((char *)GETMESSAGE(17, 14, "Warning, couldn't grab pointer.\n")), NULL);
  1289. return;
  1290. }
  1291. /* grab the keyboard so we can get the ESC button press */
  1292. status = XtGrabKeyboard(style.colorDialog, False, GrabModeAsync,
  1293. GrabModeAsync, CurrentTime);
  1294. if (status != GrabSuccess)
  1295. {
  1296. XtUngrabPointer (style.colorDialog, CurrentTime);
  1297. _DtSimpleError (progName, DtWarning, NULL,
  1298. ((char *)GETMESSAGE(17, 15, "Warning, couldn't grab Keyboard.\n")), NULL);
  1299. return;
  1300. }
  1301. while(notDone)
  1302. {
  1303. XtNextEvent(&event);
  1304. switch (event.type) {
  1305. case ButtonPress:
  1306. break;
  1307. case ButtonRelease:
  1308. notDone = False;
  1309. break;
  1310. case KeyPress:
  1311. /* look for ESC key press and stop if we get one */
  1312. if( event.xkey.state & ShiftMask)
  1313. offset = 1;
  1314. else
  1315. offset = 0;
  1316. keySym = XLookupKeysym((XKeyEvent *)&event, offset);
  1317. if (keySym == XK_Escape)
  1318. {
  1319. XtUngrabKeyboard (style.colorDialog, CurrentTime);
  1320. XtUngrabPointer (style.colorDialog, CurrentTime);
  1321. return;
  1322. }
  1323. default:
  1324. XtDispatchEvent(&event);
  1325. }
  1326. }
  1327. XtUngrabKeyboard (style.colorDialog, CurrentTime);
  1328. XtUngrabPointer (style.colorDialog, CurrentTime);
  1329. x = (Position)event.xbutton.x_root;
  1330. y = (Position)event.xbutton.y_root;
  1331. image_ptr = XGetImage (style.display, style.root, x, y, 1, 1,
  1332. AllPlanes, ZPixmap);
  1333. pixel = (Pixel) XGetPixel (image_ptr, 0, 0);
  1334. XDestroyImage (image_ptr);
  1335. colorStruct.pixel = pixel;
  1336. XQueryColor (style.display, style.colormap, &colorStruct);
  1337. edit.color_set->bg.red = colorStruct.red;
  1338. edit.color_set->bg.green = colorStruct.green;
  1339. edit.color_set->bg.blue = colorStruct.blue;
  1340. SetScales(&edit.color_set->bg);
  1341. GenerateColors();
  1342. }
  1343. /************************************************************************
  1344. * GetPixel()
  1345. *
  1346. ************************************************************************/
  1347. static Pixel
  1348. GetPixel(
  1349. Widget widget,
  1350. char *color_string )
  1351. {
  1352. XrmValue from, to;
  1353. from.size = strlen(color_string) + 1;
  1354. if (from.size < sizeof(String))
  1355. from.size = sizeof(String);
  1356. from.addr = color_string;
  1357. XtConvert(widget, XmRString, &from, XmRPixel, &to);
  1358. return ((Pixel) *((Pixel *) to.addr));
  1359. }
  1360. /*
  1361. ** dialogBoxCB
  1362. ** Process callback from the Ok, Cancel and Help pushButtons in the
  1363. ** DialogBox.
  1364. */
  1365. static void
  1366. dialogBoxCB(
  1367. Widget w,
  1368. XtPointer client_data,
  1369. XtPointer call_data )
  1370. {
  1371. palette *tmp_palette;
  1372. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  1373. switch (cb->button_position)
  1374. {
  1375. case OK_BUTTON:
  1376. WriteOutPalette( pCurrentPalette->name);
  1377. if(strcmp(pCurrentPalette->name, defaultName) == 0)
  1378. {
  1379. UpdateDefaultPalette();
  1380. SaveOrgPalette();
  1381. }
  1382. XtUnmanageChild(edit.DialogShell);
  1383. break;
  1384. case CANCEL_BUTTON:
  1385. CopyPixelSet(edit.color_set, &edit.oldButtonColor);
  1386. XtUnmanageChild(edit.DialogShell);
  1387. break;
  1388. case HELP_BUTTON:
  1389. XtCallCallbacks(edit.DialogShell, XmNhelpCallback, (XtPointer)NULL);
  1390. break;
  1391. default:
  1392. break;
  1393. }
  1394. }
  1395. /************************************************************************
  1396. * _DtmapCB
  1397. *
  1398. ************************************************************************/
  1399. static void
  1400. _DtmapCB(
  1401. Widget w,
  1402. XtPointer client_data,
  1403. XtPointer call_data )
  1404. {
  1405. Position newX,newY;
  1406. Position x,y;
  1407. Dimension editWidth,editHeight;
  1408. Dimension width,height;
  1409. Arg args[6];
  1410. int n;
  1411. XtWidgetGeometry reply;
  1412. Widget parent = (Widget) client_data;
  1413. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  1414. if (!save.restoreFlag)
  1415. {
  1416. /* get x,y,width,height of parent shell */
  1417. x = XtX(XtParent(parent));
  1418. y = XtY(XtParent(parent));
  1419. height = XtHeight(parent);
  1420. width = XtWidth(parent);
  1421. editHeight = XtHeight(edit.DialogShell);
  1422. editWidth = XtWidth(edit.DialogShell);
  1423. newX = x + width/2 - editWidth/2;
  1424. if (newX < 0)
  1425. newX = 0;
  1426. newY = y + height/2 - editHeight;
  1427. if (newY < 0)
  1428. newY = y + height;
  1429. n = 0;
  1430. XtSetArg(args[n], XmNx, newX); n++;
  1431. XtSetArg(args[n], XmNy, newY); n++;
  1432. XtSetValues(edit.DialogShell,args,n);
  1433. }
  1434. XtRemoveCallback(edit.DialogShell, XmNmapCallback, _DtmapCB, NULL);
  1435. }
  1436. /****************************************************
  1437. * restoreColor(shell, db)
  1438. * restore any state information saved with saveColor.
  1439. * This is called from restoreSession with the application shell
  1440. * and the special xrm database retrieved for restore.
  1441. ****************************************************/
  1442. void
  1443. restoreColorEdit(
  1444. Widget shell,
  1445. XrmDatabase db )
  1446. {
  1447. XrmName xrm_name[5];
  1448. XrmRepresentation rep_type;
  1449. XrmValue value;
  1450. xrm_name [0] = XrmStringToQuark ("colorEditDlg");
  1451. xrm_name [2] = 0;
  1452. /* get x position */
  1453. xrm_name [1] = XrmStringToQuark ("x");
  1454. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  1455. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
  1456. save.restoreFlag = True;
  1457. }
  1458. /* get y position */
  1459. xrm_name [1] = XrmStringToQuark ("y");
  1460. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  1461. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
  1462. }
  1463. /*Collect any other parameters you saved into static variables.*/
  1464. xrm_name [1] = XrmStringToQuark ("ismapped");
  1465. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  1466. /* Are we supposed to be mapped? */
  1467. if (strcmp(value.addr, "True") == 0)
  1468. XtCallCallbacks(modifyColorButton, XmNactivateCallback, NULL);
  1469. }
  1470. /****************************************************
  1471. * saveColorEdit(fd)
  1472. * This routine will write out to the passed file descriptor any state
  1473. * information this dialog needs. It is called from saveSessionCB with
  1474. * the file already opened.
  1475. * All information is saved in xrm format. There is no restriction
  1476. * on what can be saved. It doesn't have to be defined or be part of any
  1477. * widget or Xt definition. Just name and save it here and recover it in
  1478. * restoreColor. The suggested minimum is whether you are mapped, and your
  1479. * location.
  1480. *****************************************************/
  1481. void
  1482. saveColorEdit(
  1483. int fd )
  1484. {
  1485. Position x,y;
  1486. char bufr[1024]; /* size=[1024], make bigger if needed */
  1487. XmVendorShellExtObject vendorExt;
  1488. XmWidgetExtData extData;
  1489. if (edit.DialogShell != NULL)
  1490. {
  1491. if (XtIsManaged(edit.DialogShell))
  1492. sprintf(bufr, "*colorEditDlg.ismapped: True\n");
  1493. else
  1494. sprintf(bufr, "*colorEditDlg.ismapped: False\n");
  1495. WRITE_STR2FD(fd, bufr);
  1496. /* Get and write out the geometry info for our Window */
  1497. x = XtX(XtParent(edit.DialogShell));
  1498. y = XtY(XtParent(edit.DialogShell));
  1499. /* Modify x & y to take into account window mgr frames
  1500. * This is pretty bogus, but I don't know a better way to do it.
  1501. */
  1502. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  1503. vendorExt = (XmVendorShellExtObject)extData->widget;
  1504. x -= vendorExt->vendor.xOffset;
  1505. y -= vendorExt->vendor.yOffset;
  1506. snprintf(bufr, sizeof(bufr), "*colorEditDlg.x: %d\n", x);
  1507. WRITE_STR2FD(fd, bufr);
  1508. snprintf(bufr, sizeof(bufr), "*colorEditDlg.y: %d\n", y);
  1509. WRITE_STR2FD(fd, bufr);
  1510. /*any other parameter you want to save goes here*/
  1511. }
  1512. }