ColorEdit.c 58 KB

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