ColorMain.c 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /************************************<+>*************************************
  24. ****************************************************************************
  25. **
  26. ** File: ColorMain.c
  27. **
  28. ** Project: DT 3.0
  29. **
  30. ** Description: Controls the Dtstyle Color dialog
  31. **
  32. **
  33. ** (c) Copyright Hewlett-Packard Company, 1990.
  34. **
  35. **
  36. **
  37. ****************************************************************************
  38. ************************************<+>*************************************/
  39. /* $TOG: ColorMain.c /main/8 1998/01/12 10:41:53 cshi $ */
  40. /*+++++++++++++++++++++++++++++++++++++++*/
  41. /* include files */
  42. /*+++++++++++++++++++++++++++++++++++++++*/
  43. #include <limits.h>
  44. #include <locale.h>
  45. #include <stdlib.h>
  46. #include <errno.h>
  47. #include <X11/Intrinsic.h>
  48. #include <X11/Xlib.h>
  49. #include <Xm/MwmUtil.h>
  50. #include <Xm/Xm.h>
  51. #include <Xm/XmP.h>
  52. #include <Xm/Form.h>
  53. #include <Xm/Frame.h>
  54. #include <Xm/Label.h>
  55. #include <Xm/List.h>
  56. #include <Xm/MessageB.h>
  57. #include <Xm/Protocols.h>
  58. #include <Xm/PushB.h>
  59. #include <Xm/PushBG.h>
  60. #include <Xm/ToggleBG.h>
  61. #include <Xm/RowColumn.h>
  62. #include <Xm/SelectioB.h>
  63. #include <Xm/TextF.h>
  64. #include <Xm/VendorSEP.h>
  65. #include <Dt/DialogBox.h>
  66. #include <Dt/Icon.h>
  67. #include <Dt/TitleBox.h>
  68. #include <Dt/HourGlass.h>
  69. #include "Help.h"
  70. #include "Main.h"
  71. #include "SaveRestore.h"
  72. #include "ColorMain.h"
  73. #include "ColorFile.h"
  74. #include "ColorEdit.h"
  75. #ifdef sun
  76. #include "OWsync.h"
  77. #endif
  78. /*+++++++++++++++++++++++++++++++++++++++*/
  79. /* include extern functions */
  80. /*+++++++++++++++++++++++++++++++++++++++*/
  81. /*+++++++++++++++++++++++++++++++++++++++*/
  82. /* Local #defines */
  83. /*+++++++++++++++++++++++++++++++++++++++*/
  84. #define DEFAULT_PALETTE "Default"
  85. #define TYPE_OF_MONITOR "Type Of Monitor" /* also in dtsession/SrvPalette.c */
  86. #define BORDER_WIDTH 3
  87. #define COLOR_BUTTON_WIDTH 35
  88. #define COLOR_BUTTON_HEIGHT 35
  89. #define ADD_PALETTE_TOP_OFFSET 20
  90. #define ADD_PALETTE_LEFT_POSITION 65
  91. #define PALETTE_RC_RIGHT_POSITION 60
  92. #define DEFAULT_COLOR (XmCO_HIGH_COLOR + 1)
  93. #define B_W_STR "B_W"
  94. #define LOW_COLOR_STR "LOW_COLOR"
  95. #define MEDIUM_COLOR_STR "MEDIUM_COLOR"
  96. #define HIGH_COLOR_STR "HIGH_COLOR"
  97. #define DEFAULT_COLOR_STR "DEFAULT"
  98. #define STR1 ((char *)GETMESSAGE(14, 29, "A palette named '%s' already exists.\nThis new palette will overwrite the old one.\nIs this what you want to do?"))
  99. #define STR2 ((char *)GETMESSAGE(14, 23, "Delete palette '%s'?\n"))
  100. #define NEXT_SESSION ((char *)GETMESSAGE(14, 28, "The selected palette will take effect\nat your next session."))
  101. #define CANT_DELETE ((char *)GETMESSAGE(14, 18, "Can't delete the last palette.\n"))
  102. #define COLORUSE_WHEN ((char *)GETMESSAGE(14, 27, "The new Color Use value will take effect\nat your next session."))
  103. /*+++++++++++++++++++++++++++++++++++++++*/
  104. /* Local typedefs */
  105. /*+++++++++++++++++++++++++++++++++++++++*/
  106. typedef struct {
  107. Widget colorForm;
  108. Widget paletteTB;
  109. Widget palettesForm;
  110. Widget addPaletteButton;
  111. Widget deletePaletteButton;
  112. Widget buttonsTB;
  113. Widget colorlabel;
  114. Widget highColorTG;
  115. Widget mediumColorTG;
  116. Widget lowColorTG;
  117. Widget blackWhiteTG;
  118. Widget defaultTG;
  119. Widget dlg;
  120. int origColorUse;
  121. char *currentColorUseStr;
  122. int currentColorUse;
  123. } colorWidgets;
  124. /*+++++++++++++++++++++++++++++++++++++++*/
  125. /* Internal Functions */
  126. /*+++++++++++++++++++++++++++++++++++++++*/
  127. static int CreateMainWindow( Widget parent) ;
  128. static void selectPaletteCB(
  129. Widget w,
  130. XtPointer client_data,
  131. XtPointer call_data) ;
  132. static void selectColorCB(
  133. Widget w,
  134. XtPointer client_data,
  135. XtPointer call_data) ;
  136. static void timeoutCB(
  137. XtPointer client_data,
  138. XtIntervalId *id) ;
  139. static void addPaletteCB(
  140. Widget w,
  141. XtPointer client_data,
  142. XtPointer call_data) ;
  143. static void addCancelCB(
  144. Widget w,
  145. XtPointer client_data,
  146. XtPointer call_data) ;
  147. static void addOkCB(
  148. Widget w,
  149. XtPointer client_data,
  150. XtPointer call_data) ;
  151. static void setDlgOkCB(
  152. Widget w,
  153. XtPointer client_data,
  154. XtPointer call_data) ;
  155. static void modifyColorCB(
  156. Widget w,
  157. XtPointer client_data,
  158. XtPointer call_data) ;
  159. static void dialogBoxCB(
  160. Widget w,
  161. XtPointer client_data,
  162. XtPointer call_data) ;
  163. static void AddName(
  164. palette *newPalette) ;
  165. static void deletePaletteCB(
  166. Widget w,
  167. XtPointer client_data,
  168. XtPointer call_data) ;
  169. static void deleteOkCB(
  170. Widget w,
  171. XtPointer client_data,
  172. XtPointer call_data) ;
  173. static void deleteCancelCB(
  174. Widget w,
  175. XtPointer client_data,
  176. XtPointer call_data) ;
  177. static void resourcesCB(
  178. Widget w,
  179. XtPointer client_data,
  180. XtPointer call_data) ;
  181. static void colorUseCB(
  182. Widget w,
  183. XtPointer client_data,
  184. XtPointer call_data) ;
  185. static void colorUseExitCB(
  186. Widget w,
  187. XtPointer client_data,
  188. XtPointer call_data) ;
  189. static void activateCBexitColor(
  190. Widget w,
  191. XtPointer client_data,
  192. XtPointer call_data) ;
  193. static void _DtmapCB(
  194. Widget w,
  195. XtPointer client_data,
  196. XtPointer call_data) ;
  197. static void _DtmapCB_colorUse(
  198. Widget w,
  199. XtPointer client_data,
  200. XtPointer call_data) ;
  201. static void colorEditorCB(
  202. Widget w,
  203. XtPointer client_data,
  204. XtPointer call_data) ;
  205. static void allocNewColors(void);
  206. static Boolean ValidName( char *name) ;
  207. void loadDatabase();
  208. /*+++++++++++++++++++++++++++++++++++++++*/
  209. /* Global Variables */
  210. /*+++++++++++++++++++++++++++++++++++++++*/
  211. Atom XA_CUSTOMIZE;
  212. Atom XA_TYPE_MONITOR;
  213. /* Palettes exist in a linked list. */
  214. palette *pHeadPalette;
  215. palette *pCurrentPalette;
  216. palette *pOldPalette;
  217. Widget modifyColorButton;
  218. int TypeOfMonitor;
  219. Bool UsePixmaps;
  220. int FgColor;
  221. Widget paletteList;
  222. Widget deleteButton;
  223. char *defaultName;
  224. Bool WaitSelection;
  225. int NumOfPalettes;
  226. /*+++++++++++++++++++++++++++++++++++++++*/
  227. /* Internal Variables */
  228. /*+++++++++++++++++++++++++++++++++++++++*/
  229. /* palette names without the .dp */
  230. static char *WHITE_BLACK = "WhiteBlack";
  231. static char *BLACK_WHITE = "BlackWhite";
  232. static char *WHITE_ONLY = "White";
  233. static char *BLACK_ONLY = "Black";
  234. static char *PALETTEDLG = "paletteDlg";
  235. static saveRestore save = {FALSE, 0, };
  236. static Widget colorButton[XmCO_MAX_NUM_COLORS];
  237. static Widget addDialog;
  238. static Widget deleteDialog;
  239. static Widget colorUseDialog;
  240. static palette OrgPalette;
  241. static XtIntervalId timeID;
  242. static int dclick_time;
  243. static int selected_button;
  244. static int selected_position;
  245. static Atom XA_WM_DELETE_WINDOW;
  246. static char defaultName_restore[50];
  247. static palette *loop_palette, *loop_palette2;
  248. static int loopcount = 0;
  249. static colorWidgets colorDialog;
  250. static Widget gParent;
  251. /*
  252. * copy of the system palette description file for the
  253. * current locale in xrm form
  254. */
  255. XrmDatabase sys_pl_DB = NULL;
  256. /*
  257. * copy of the admin palette description file for the
  258. * current locale in xrm form
  259. */
  260. XrmDatabase adm_pl_DB = NULL;
  261. /*
  262. * final combination of the admin & system dta bases
  263. */
  264. XrmDatabase pl_DB = NULL;
  265. /*
  266. * copy of the palette description file from the user's home
  267. * directory. This database is locale independent and will always
  268. * be loaded.
  269. */
  270. XrmDatabase hm_pl_DB = NULL;
  271. void
  272. loadDatabase(void)
  273. {
  274. char *lang;
  275. char *pl_desc;
  276. /* load the palette description data base for the given locale*/
  277. /* from that locale's description file from the system location */
  278. lang = setlocale (LC_CTYPE,NULL);
  279. #ifdef hpux /* hpux-specific parsing of the locale string */
  280. /* The following code is identical to the
  281. ExtractLocaleName function in WmResParse.c
  282. from dtwm
  283. */
  284. #define MAXLOCALE 64 /* buffer size of locale name */
  285. { char *start;
  286. char *end;
  287. int len;
  288. static char buf[MAXLOCALE];
  289. /* If lang has a substring ":<category>;", extract <category>
  290. * from the first such occurrence as the locale name.
  291. */
  292. start = lang;
  293. if (start = strchr (lang, ':')) {
  294. start++;
  295. if (end = strchr (start, ';')) {
  296. len = end - start;
  297. strncpy(buf, start, len);
  298. *(buf + len) = '\0';
  299. lang = buf;
  300. }
  301. }
  302. }
  303. #endif /* hpux */
  304. pl_desc = (char *)XtMalloc(strlen("/usr/dt/palettes/desc.") + strlen(lang) + 1);
  305. strcpy (pl_desc,"/usr/dt/palettes/desc.");
  306. strcat (pl_desc, lang);
  307. if(sys_pl_DB = XrmGetFileDatabase (pl_desc))
  308. XrmMergeDatabases(sys_pl_DB, &pl_DB);
  309. XtFree(pl_desc);
  310. /* load the palette description data base for the given locale*/
  311. /* from that locale's description file from the admin location */
  312. pl_desc = (char *)XtMalloc(strlen("/etc/dt/palettes/desc.") + strlen(lang) + 1);
  313. strcpy (pl_desc,"/etc/dt/palettes/desc.");
  314. strcat (pl_desc, lang);
  315. if (adm_pl_DB = XrmGetFileDatabase (pl_desc))
  316. XrmMergeDatabases(adm_pl_DB, &pl_DB);
  317. XtFree(pl_desc);
  318. /* load the palette description data base regardless of locale*/
  319. pl_desc = (char *) XtMalloc(strlen(style.home) +(strlen("/.dt/palettes/desc.palettes") + 1));
  320. strcpy (pl_desc, style.home);
  321. strcat (pl_desc, "/.dt/palettes/desc.palettes");
  322. if (hm_pl_DB = XrmGetFileDatabase (pl_desc))
  323. XrmMergeDatabases(hm_pl_DB, &pl_DB);
  324. XtFree(pl_desc);
  325. /* load the palette description data base regardless of locale for later use*/
  326. pl_desc = (char *) XtMalloc(strlen(style.home) +(strlen("/.dt/palettes/desc.palettes") + 1));
  327. strcpy (pl_desc, style.home);
  328. strcat (pl_desc, "/.dt/palettes/desc.palettes");
  329. if (XrmCombineFileDatabase (pl_desc, &pl_DB, True))
  330. /* load a separate home data base to be later saved as a file */
  331. /* if any palettes are added */
  332. hm_pl_DB = XrmGetFileDatabase (pl_desc);
  333. XtFree(pl_desc);
  334. }
  335. void
  336. Customize(
  337. Widget shell )
  338. {
  339. int i;
  340. /*
  341. ** Main routine does the following:
  342. ** 1. Creates the color dialog shell
  343. ** 2. Checks which monitor the customizer is running on
  344. ** 3. Initialize color palettes
  345. **
  346. */
  347. /* can the user access the Color portion of Style? */
  348. /* Not if Color Server is not running */
  349. if (style.colorSrv == FALSE)
  350. {
  351. ErrDialog(((char *)GETMESSAGE(14, 25, "The color portion of the Style Manager\nwill not operate because the color server\nis not running. Check $HOME/.dt/errorlog.")), style.shell);
  352. return;
  353. }
  354. /* Not if useColorObj resource is False. XmeUseColorObj will return false
  355. if color server is not running or if the resource UseColorObj is False.
  356. If the color server is not running, that case is caught above so if
  357. we get here, the resource UseColorObj must be False. This is an
  358. undocumented resource. */
  359. if (XmeUseColorObj() == FALSE)
  360. {
  361. ErrDialog(((char *)GETMESSAGE(14, 26, "The color portion of the Style Manager\nwill not operate because the resource\n'useColorObj' is set to False.")), style.shell);
  362. return;
  363. }
  364. if (style.colorDialog == NULL || style.count < 12)
  365. {
  366. _DtTurnOnHourGlass(shell);
  367. /* Create Main Color Dialog */
  368. if(CreateMainWindow(shell) == -1)
  369. {
  370. _DtTurnOffHourGlass(shell);
  371. return;
  372. }
  373. XtManageChild(style.colorDialog);
  374. _DtTurnOffHourGlass(shell);
  375. }
  376. else
  377. {
  378. XtManageChild(style.colorDialog);
  379. raiseWindow(XtWindow(XtParent(style.colorDialog)));
  380. }
  381. /* also determine if system uses long filenames, used by add palette only */
  382. CheckFileType();
  383. SaveOrgPalette();
  384. }
  385. /*
  386. ** This routine creates the Color Customizer Main Window. It is passed
  387. ** the top level shell.
  388. */
  389. static int
  390. CreateMainWindow(
  391. Widget parent )
  392. {
  393. /* Create the DialogBox dialog */
  394. CreateDialogBoxD(parent);
  395. /* add some more to the dialog box */
  396. AddToDialogBox();
  397. /* Create the top part of the color dialog */
  398. CreateTopColor1();
  399. CreateTopColor2();
  400. /* read in palettes */
  401. ReadInPalettes(style.xrdb.paletteDir);
  402. if (NumOfPalettes == 0)
  403. {
  404. /* error dialog - no palettes */
  405. ErrDialog(((char *)GETMESSAGE(14, 38, "The color portion of the Style Manager\n\
  406. will not operate because there are no palette\n\
  407. files available. Check $HOME/.dt/errorlog.")), style.shell);
  408. return(-1);
  409. }
  410. /* go get the list of palettes of the color dialog */
  411. InitializePaletteList(parent,paletteList, False);
  412. /* Allocate the pixels for the Current palette.
  413. * Will get the pixel values from the color server.
  414. */
  415. AllocatePaletteCells(parent);
  416. /* go create the bottom portion of the color dialog */
  417. CreateBottomColor();
  418. /*
  419. ** Create the color buttons. Have to do it after
  420. ** initialize palettes so the correct pixels would be used.
  421. */
  422. CreatePaletteButtons(style.buttonsForm);
  423. return(0);
  424. }
  425. void
  426. CreatePaletteButtons(
  427. Widget parent )
  428. {
  429. int i,n;
  430. Arg args[16];
  431. XmString string;
  432. Pixmap pixmap100;
  433. Widget paletteRc;
  434. if(style.count > 11)
  435. return;
  436. if (TypeOfMonitor == XmCO_BLACK_WHITE) /* create pixmaps for top/bottom shadow */
  437. {
  438. edit.pixmap25 = XmGetPixmap (style.screen, "25_foreground",
  439. BlackPixelOfScreen(style.screen),
  440. WhitePixelOfScreen(style.screen));
  441. edit.pixmap75 = XmGetPixmap (style.screen, "75_foreground",
  442. BlackPixelOfScreen(style.screen),
  443. WhitePixelOfScreen(style.screen));
  444. }
  445. pixmap100 = XmGetPixmap (style.screen, "background",
  446. BlackPixelOfScreen(style.screen),
  447. pCurrentPalette->color[pCurrentPalette->active].bg.pixel);
  448. n = 0;
  449. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  450. XtSetArg (args[n], XmNtopOffset, 0); n++;
  451. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  452. XtSetArg (args[n], XmNleftOffset, 0); n++;
  453. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  454. XtSetArg (args[n], XmNrightPosition, PALETTE_RC_RIGHT_POSITION); n++;
  455. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  456. XtSetArg (args[n], XmNbottomOffset, 0); n++;
  457. XtSetArg (args[n], XmNspacing, 0); n++;
  458. XtSetArg (args[n], XmNmarginWidth, style.horizontalSpacing); n++;
  459. XtSetArg (args[n], XmNmarginHeight, style.verticalSpacing); n++;
  460. XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  461. XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
  462. XtSetArg (args[n], XmNadjustLast, False); n++;
  463. if(TypeOfMonitor == XmCO_HIGH_COLOR)
  464. {
  465. XtSetArg (args[n], XmNnumColumns, 2); n++;
  466. }
  467. else
  468. {
  469. XtSetArg (args[n], XmNnumColumns, 1); n++;
  470. }
  471. paletteRc = XmCreateRowColumn(parent, "paletteRc", args, n);
  472. XtManageChild(paletteRc);
  473. for (i=0; i<XmCO_MAX_NUM_COLORS; i++)
  474. {
  475. n=0;
  476. XtSetArg (args[n], XmNrecomputeSize, False); n++;
  477. XtSetArg (args[n], XmNwidth, COLOR_BUTTON_WIDTH); n++;
  478. XtSetArg (args[n], XmNheight, COLOR_BUTTON_HEIGHT); n++;
  479. /* allow traversal only if editing is possible */
  480. if (style.dynamicColor || style.visualClass==TrueColor
  481. || style.visualClass==DirectColor)
  482. {
  483. XtSetArg (args[n], XmNtraversalOn, False); n++;
  484. }
  485. XtSetArg (args[n], XmNborderWidth, BORDER_WIDTH); n++;
  486. XtSetArg (args[n], XmNborderColor,
  487. pCurrentPalette->color[pCurrentPalette->secondary].bg.pixel); n++;
  488. XtSetArg (args[n], XmNforeground,
  489. pCurrentPalette->color[i].fg.pixel); n++;
  490. XtSetArg (args[n], XmNbackground,
  491. pCurrentPalette->color[i].bg.pixel); n++;
  492. XtSetArg (args[n], XmNarmColor, pCurrentPalette->color[i].sc.pixel); n++;
  493. XtSetArg (args[n], XmNmultiClick, XmMULTICLICK_KEEP); n++;
  494. if (TypeOfMonitor == XmCO_LOW_COLOR)
  495. {
  496. XtSetArg (args[n], XmNhighlightColor,
  497. pCurrentPalette->color[pCurrentPalette->secondary].fg.pixel); n++;
  498. }
  499. else
  500. {
  501. XtSetArg (args[n], XmNhighlightPixmap, pixmap100); n++;
  502. }
  503. if(UsePixmaps == FALSE && TypeOfMonitor != XmCO_BLACK_WHITE)
  504. {
  505. XtSetArg (args[n], XmNtopShadowColor,
  506. pCurrentPalette->color[i].ts.pixel); n++;
  507. XtSetArg (args[n], XmNbottomShadowColor,
  508. pCurrentPalette->color[i].bs.pixel); n++;
  509. }
  510. else if (TypeOfMonitor == XmCO_BLACK_WHITE)
  511. {
  512. XtSetArg (args[n], XmNtopShadowPixmap, edit.pixmap25); n++;
  513. XtSetArg (args[n], XmNbottomShadowPixmap, edit.pixmap75); n++;
  514. }
  515. string = CMPSTR(" ");
  516. XtSetArg (args[n], XmNlabelString, string); n++;
  517. colorButton[i] = XmCreatePushButton(paletteRc, "colorButton", args, n);
  518. /* allow access to modify functionality if available */
  519. if (style.dynamicColor || style.visualClass==TrueColor
  520. || style.visualClass==DirectColor)
  521. XtAddCallback(colorButton[i], XmNactivateCallback, selectColorCB,
  522. (XtPointer) (intptr_t) i);
  523. XmStringFree(string);
  524. }
  525. XtManageChildren(colorButton,pCurrentPalette->num_of_colors);
  526. if(!save.restoreFlag)
  527. selected_button = 0;
  528. /* draw selection border if editing is possible */
  529. if (style.dynamicColor || style.visualClass==TrueColor
  530. || style.visualClass==DirectColor)
  531. {
  532. n=0;
  533. XtSetArg (args[n], XmNborderColor, BlackPixelOfScreen(style.screen)); n++;
  534. XtSetValues(colorButton[selected_button],args,n);
  535. }
  536. if(style.visualClass==TrueColor || style.visualClass==DirectColor)
  537. allocNewColors();
  538. style.count++;
  539. }
  540. Boolean
  541. InitializePaletteList(
  542. Widget shell,
  543. Widget list,
  544. #if NeedWidePrototypes
  545. int startup )
  546. #else
  547. Boolean startup )
  548. #endif
  549. {
  550. int n;
  551. Arg args[4];
  552. XmString string;
  553. XmStringTable string_table;
  554. char *name_str;
  555. char *class_str;
  556. char *str_type_return;
  557. XrmValue value_return;
  558. if(style.count > 8)
  559. return(True);
  560. /*
  561. ** Add the palettes read in from ReadInPalettes
  562. */
  563. if(loopcount == 0) {
  564. if (TypeOfMonitor != XmCO_BLACK_WHITE) {
  565. loop_palette = pHeadPalette;
  566. loop_palette2 = pHeadPalette;
  567. }
  568. else {
  569. loop_palette = pHeadPalette;
  570. loop_palette2 = NULL;
  571. while(loop_palette != NULL)
  572. if(strcmp(loop_palette->name, "Black") == 0) {
  573. loop_palette2 = loop_palette;
  574. loop_palette = NULL;
  575. }
  576. else
  577. loop_palette = loop_palette->next;
  578. loop_palette = pHeadPalette;
  579. if(loop_palette2 == NULL)
  580. loop_palette2 = pHeadPalette;
  581. }
  582. }
  583. while( loop_palette != NULL)
  584. {
  585. if (pl_DB !=NULL)
  586. {
  587. name_str = (char *) XtMalloc(strlen("palettes.") +
  588. strlen(loop_palette->name) +
  589. strlen(".desc") + 1);
  590. class_str = (char *) XtMalloc(strlen("Palettes.") +
  591. strlen(loop_palette->name) +
  592. strlen(".Desc") + 1);
  593. strcpy(name_str, "palettes.");
  594. strcpy(class_str, "Palettes.");
  595. strcat(name_str, loop_palette->name);
  596. strcat(class_str, loop_palette->name);
  597. strcat(name_str, ".desc");
  598. strcat(class_str, ".Desc");
  599. if (XrmGetResource (pl_DB, name_str, class_str, &str_type_return, &value_return))
  600. {
  601. loop_palette->desc = (char *)XtMalloc(strlen (value_return.addr) + 1 );
  602. strcpy(loop_palette->desc, value_return.addr);
  603. }
  604. else
  605. {
  606. loop_palette->desc = (char *)XtMalloc(strlen (loop_palette->name) + 1 );
  607. strcpy(loop_palette->desc, loop_palette->name);
  608. }
  609. XtFree(name_str);
  610. XtFree(class_str);
  611. }
  612. else
  613. {
  614. loop_palette->desc = (char *)XtMalloc(strlen (loop_palette->name) + 1 );
  615. strcpy(loop_palette->desc, loop_palette->name);
  616. }
  617. XmListAddItem(list, CMPSTR(loop_palette->desc), loop_palette->item_position);
  618. /* if the item is the same as the default name provided by the
  619. color Server, save it */
  620. if(!save.restoreFlag || defaultName_restore == NULL) {
  621. if (!(strcmp(loop_palette->name, defaultName)))
  622. loop_palette2 = loop_palette;
  623. }
  624. else {
  625. if (!(strcmp(loop_palette->name, defaultName_restore)))
  626. loop_palette2 = loop_palette;
  627. }
  628. loop_palette = loop_palette->next;
  629. loopcount++;
  630. if((loopcount % 5 == 0) && startup)
  631. {
  632. return(False);}
  633. }
  634. /*
  635. ** Make the palette named by the color Server the selected palette, if the
  636. ** palette returned by the color server doesn't match make it the head
  637. ** palette.
  638. */
  639. pOldPalette = NULL;
  640. /* the default name is the name to be selected */
  641. if (loop_palette2->name == NULL)
  642. string = CMPSTR("");
  643. else
  644. string = CMPSTR(loop_palette2->desc);
  645. string_table = &string;
  646. n=0;
  647. XtSetArg (args[n], XmNselectedItemCount, 1); n++;
  648. XtSetArg (args[n], XmNselectedItems, string_table); n++;
  649. XtSetValues (list, args, n);
  650. XmStringFree(string);
  651. XmListSetPos(list, loop_palette2->item_position);
  652. XtManageChild(list);
  653. pCurrentPalette = loop_palette2;
  654. selected_position = pCurrentPalette->item_position;
  655. style.count++;
  656. return(True);
  657. }
  658. /*
  659. * Allocate new pixel values and update color palette buttons.
  660. * This is needed for screens without dynamicColor.
  661. */
  662. static void allocNewColors(void)
  663. {
  664. int i, n;
  665. Arg args[10];
  666. static unsigned long pixels[XmCO_MAX_NUM_COLORS*5];
  667. static int count = 0;
  668. if(count)
  669. {
  670. /* free the cells from last selection */
  671. XFreeColors(style.display, style.colormap, pixels, count, 0);
  672. count=0;
  673. }
  674. for (i=0; i<pCurrentPalette->num_of_colors; i++)
  675. {
  676. n=0;
  677. if (XAllocColor(style.display, style.colormap,
  678. &(pCurrentPalette->color[i].fg)) == 0) break;
  679. pixels[count++] = pCurrentPalette->color[i].fg.pixel;
  680. if (XAllocColor(style.display, style.colormap,
  681. &(pCurrentPalette->color[i].bg)) == 0) break;
  682. pixels[count++] = pCurrentPalette->color[i].bg.pixel;
  683. XtSetArg (args[n], XmNbackground,
  684. pCurrentPalette->color[i].bg.pixel); n++;
  685. if (XAllocColor(style.display, style.colormap,
  686. &(pCurrentPalette->color[i].sc)) == 0) break;
  687. pixels[count++] = pCurrentPalette->color[i].sc.pixel;
  688. XtSetArg (args[n], XmNarmColor,
  689. pCurrentPalette->color[i].sc.pixel); n++;
  690. if (UsePixmaps == FALSE)
  691. {
  692. if (XAllocColor(style.display, style.colormap,
  693. &(pCurrentPalette->color[i].ts)) == 0) break;
  694. pixels[count++] = pCurrentPalette->color[i].ts.pixel;
  695. XtSetArg (args[n], XmNtopShadowColor,
  696. pCurrentPalette->color[i].ts.pixel); n++;
  697. if (XAllocColor(style.display, style.colormap,
  698. &(pCurrentPalette->color[i].bs)) == 0) break;
  699. pixels[count++] = pCurrentPalette->color[i].bs.pixel;
  700. XtSetArg (args[n], XmNbottomShadowColor,
  701. pCurrentPalette->color[i].bs.pixel); n++;
  702. }
  703. else /* create pixmaps for top/bottom shadow */
  704. {
  705. XmDestroyPixmap(style.screen, edit.pixmap25);
  706. XmDestroyPixmap(style.screen, edit.pixmap75);
  707. edit.pixmap25 = XmGetPixmap (style.screen,
  708. "50_foreground",pCurrentPalette->color[i].bg.pixel,
  709. WhitePixelOfScreen(style.screen));
  710. edit.pixmap75 = XmGetPixmap (style.screen,
  711. "50_foreground",pCurrentPalette->color[i].bg.pixel,
  712. BlackPixelOfScreen(style.screen));
  713. XtSetArg (args[n], XmNtopShadowPixmap, edit.pixmap25); n++;
  714. XtSetArg (args[n], XmNbottomShadowPixmap, edit.pixmap75); n++;
  715. }
  716. XtSetValues(colorButton[i], args, n);
  717. }
  718. }
  719. /*
  720. ** This is the selection callback for the Scrolled list.
  721. ** The routine finds the item the user selected and changes
  722. ** the already allocated pixels to the colors of the selected palette.
  723. */
  724. static void
  725. selectPaletteCB(
  726. Widget w,
  727. XtPointer client_data,
  728. XtPointer call_data )
  729. {
  730. int n;
  731. Arg args[10];
  732. XmListCallbackStruct *cb = (XmListCallbackStruct *)call_data;
  733. palette *tmp_palette;
  734. XmString string;
  735. Pixel white, black;
  736. static Boolean First = True;
  737. white = WhitePixelOfScreen(style.screen);
  738. black = BlackPixelOfScreen(style.screen);
  739. if (((edit.DialogShell == NULL) || (!XtIsManaged(edit.DialogShell))) &&
  740. selected_position != cb->item_position)
  741. {
  742. selected_position = cb->item_position;
  743. tmp_palette = pHeadPalette;
  744. while( tmp_palette != NULL &&
  745. tmp_palette->item_position != selected_position ) {
  746. tmp_palette = tmp_palette->next;
  747. }
  748. if(tmp_palette->item_position == selected_position)
  749. {
  750. pOldPalette = pCurrentPalette;
  751. pCurrentPalette = tmp_palette;
  752. n=0;
  753. string = CMPSTR(pCurrentPalette->desc);
  754. XtSetArg (args[n], XmNtitleString, string); n++;
  755. XtSetValues (colorDialog.buttonsTB, args, n);
  756. XmStringFree(string);
  757. if (style.dynamicColor)
  758. ReColorPalette();
  759. else
  760. {
  761. if (TypeOfMonitor != XmCO_BLACK_WHITE)
  762. {
  763. /* PUT DIALOG saying can't dynamically change */
  764. if(First)
  765. {
  766. InfoDialog(NEXT_SESSION, style.colorDialog, False);
  767. First = False;
  768. }
  769. allocNewColors();
  770. }
  771. else /* XmCO_BLACK_WHITE */
  772. {
  773. /* set color buttons for new palette - read only cells */
  774. /* primary=color[1] secondary=color[0] */
  775. if (strcmp(pCurrentPalette->name, WHITE_BLACK) == 0)
  776. {
  777. n=0; /* secondary color white */
  778. XtSetArg (args[n], XmNforeground, black); n++;
  779. XtSetArg (args[n], XmNbackground, white); n++;
  780. XtSetArg (args[n], XmNarmColor, white); n++;
  781. XtSetValues(colorButton[0], args, n);
  782. pCurrentPalette->color[0].fg.pixel = black;
  783. pCurrentPalette->color[0].bg.pixel = white;
  784. pCurrentPalette->color[0].sc.pixel = white;
  785. pCurrentPalette->color[0].ts.pixel = black;
  786. pCurrentPalette->color[0].bs.pixel = black;
  787. n=0; /* primary color black */
  788. XtSetArg (args[n], XmNforeground, white); n++;
  789. XtSetArg (args[n], XmNbackground, black); n++;
  790. XtSetArg (args[n], XmNarmColor, black); n++;
  791. XtSetValues(colorButton[1], args, n);
  792. pCurrentPalette->color[1].fg.pixel = white;
  793. pCurrentPalette->color[1].bg.pixel = black;
  794. pCurrentPalette->color[1].sc.pixel = black;
  795. pCurrentPalette->color[1].ts.pixel = white;
  796. pCurrentPalette->color[1].bs.pixel = white;
  797. }
  798. else if (strcmp(pCurrentPalette->name, BLACK_WHITE) == 0)
  799. {
  800. n=0; /* secondary color black */
  801. XtSetArg (args[n], XmNforeground, white); n++;
  802. XtSetArg (args[n], XmNbackground, black); n++;
  803. XtSetArg (args[n], XmNarmColor, black); n++;
  804. XtSetValues(colorButton[0], args, n);
  805. pCurrentPalette->color[0].fg.pixel = white;
  806. pCurrentPalette->color[0].bg.pixel = black;
  807. pCurrentPalette->color[0].sc.pixel = black;
  808. pCurrentPalette->color[0].ts.pixel = white;
  809. pCurrentPalette->color[0].bs.pixel = white;
  810. n=0; /* primary color white */
  811. XtSetArg (args[n], XmNforeground, black); n++;
  812. XtSetArg (args[n], XmNbackground, white); n++;
  813. XtSetArg (args[n], XmNarmColor, white); n++;
  814. XtSetValues(colorButton[1], args, n);
  815. pCurrentPalette->color[1].fg.pixel = black;
  816. pCurrentPalette->color[1].bg.pixel = white;
  817. pCurrentPalette->color[1].sc.pixel = white;
  818. pCurrentPalette->color[1].ts.pixel = black;
  819. pCurrentPalette->color[1].bs.pixel = black;
  820. }
  821. else if (strcmp(pCurrentPalette->name, BLACK_ONLY) == 0)
  822. {
  823. n=0; /* primary and secondary color black */
  824. XtSetArg (args[n], XmNforeground, white); n++;
  825. XtSetArg (args[n], XmNbackground, black); n++;
  826. XtSetArg (args[n], XmNarmColor, black); n++;
  827. XtSetValues(colorButton[0], args, n);
  828. pCurrentPalette->color[0].fg.pixel = white;
  829. pCurrentPalette->color[0].bg.pixel = black;
  830. pCurrentPalette->color[0].sc.pixel = black;
  831. pCurrentPalette->color[0].ts.pixel = white;
  832. pCurrentPalette->color[0].bs.pixel = white;
  833. XtSetValues(colorButton[1], args, n);
  834. pCurrentPalette->color[1].fg.pixel = white;
  835. pCurrentPalette->color[1].bg.pixel = black;
  836. pCurrentPalette->color[1].sc.pixel = black;
  837. pCurrentPalette->color[1].ts.pixel = white;
  838. pCurrentPalette->color[1].bs.pixel = white;
  839. }
  840. else /* WHITE_ONLY */
  841. {
  842. n=0; /* primary and secondary color white */
  843. XtSetArg (args[n], XmNforeground, black); n++;
  844. XtSetArg (args[n], XmNbackground, white); n++;
  845. XtSetArg (args[n], XmNarmColor, white); n++;
  846. XtSetValues(colorButton[0], args, n);
  847. pCurrentPalette->color[0].fg.pixel = black;
  848. pCurrentPalette->color[0].bg.pixel = white;
  849. pCurrentPalette->color[0].sc.pixel = white;
  850. pCurrentPalette->color[0].ts.pixel = black;
  851. pCurrentPalette->color[0].bs.pixel = black;
  852. XtSetValues(colorButton[1], args, n);
  853. pCurrentPalette->color[1].fg.pixel = black;
  854. pCurrentPalette->color[1].bg.pixel = white;
  855. pCurrentPalette->color[1].sc.pixel = white;
  856. pCurrentPalette->color[1].ts.pixel = black;
  857. pCurrentPalette->color[1].bs.pixel = black;
  858. }
  859. }
  860. }
  861. }
  862. }
  863. }
  864. static void
  865. selectColorCB(
  866. Widget w,
  867. XtPointer client_data,
  868. XtPointer call_data )
  869. {
  870. intptr_t i;
  871. int n;
  872. Arg args[4];
  873. ColorSet *color_set;
  874. XmPushButtonCallbackStruct *cb = (XmPushButtonCallbackStruct *)call_data;
  875. i = (intptr_t) client_data;
  876. /* if click_count == 1 .. first button press, set time out */
  877. if(cb->click_count == 1)
  878. {
  879. timeID = XtAppAddTimeOut(XtWidgetToApplicationContext(gParent),
  880. (unsigned long) dclick_time, timeoutCB,
  881. (XtPointer) i);
  882. return;
  883. }
  884. /* else .. second button press, remove the time out */
  885. XtRemoveTimeOut(timeID);
  886. if ((edit.DialogShell == NULL) || (!XtIsManaged(edit.DialogShell)))
  887. {
  888. Pixel bg_pixel;
  889. /* make the new selected button have a border color */
  890. n=0;
  891. XtSetArg(args[n],XmNbackground,&bg_pixel); n++;
  892. XtGetValues(colorDialog.colorForm,args,n);
  893. n=0;
  894. XtSetArg (args[n], XmNborderColor,bg_pixel);
  895. n++;
  896. XtSetValues(colorButton[selected_button],args,n);
  897. n=0;
  898. XtSetArg (args[n], XmNborderColor, BlackPixelOfScreen(style.screen));
  899. n++;
  900. XtSetValues(colorButton[i],args,n);
  901. selected_button = i;
  902. color_set = (ColorSet *) &pCurrentPalette->color[selected_button];
  903. ColorEditor(style.colorDialog,color_set);
  904. if(!style.dynamicColor) /* need to update pixels */
  905. XtAddCallback(edit.DialogShell, XmNcallback, colorEditorCB, NULL);
  906. }
  907. }
  908. /*
  909. * Color editor callback for screens without dynamicColor.
  910. */
  911. static void colorEditorCB(Widget w, XtPointer client_data, XtPointer call_data)
  912. {
  913. static Boolean first = True;
  914. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  915. /* show "next session" message if first edit */
  916. if(cb->button_position==OK_BUTTON && first){
  917. InfoDialog(NEXT_SESSION, style.colorDialog, False);
  918. first = False;
  919. }
  920. allocNewColors();
  921. XtRemoveCallback(edit.DialogShell, XmNcallback, colorEditorCB, NULL);
  922. }
  923. /*
  924. ** This is the double click timeout callback. If this routine is called
  925. ** then there was only a single click on a colorbutton
  926. */
  927. static void
  928. timeoutCB(
  929. XtPointer client_data,
  930. XtIntervalId *id )
  931. {
  932. int n;
  933. intptr_t i;
  934. Arg args[2];
  935. Pixel bg_pixel;
  936. if (TypeOfMonitor == XmCO_BLACK_WHITE)
  937. return;
  938. i = (intptr_t) client_data;
  939. if ((edit.DialogShell == NULL) || (!XtIsManaged(edit.DialogShell)))
  940. {
  941. /* make the new selected button have a border color */
  942. n=0;
  943. XtSetArg(args[n],XmNbackground,&bg_pixel); n++;
  944. XtGetValues(colorDialog.colorForm,args,n);
  945. n=0;
  946. XtSetArg (args[n], XmNborderColor,bg_pixel);
  947. n++;
  948. XtSetValues(colorButton[selected_button],args,n);
  949. n=0;
  950. XtSetArg (args[n], XmNborderColor, BlackPixelOfScreen(style.screen));
  951. n++;
  952. XtSetValues(colorButton[i],args,n);
  953. selected_button = i;
  954. }
  955. }
  956. static void
  957. addPaletteCB(
  958. Widget w,
  959. XtPointer client_data,
  960. XtPointer call_data )
  961. {
  962. int n;
  963. Arg args[10];
  964. XmString string;
  965. XmString string1;
  966. if (addDialog == NULL)
  967. {
  968. n = 0;
  969. XtSetArg(args[n], XmNokLabelString, CMPSTR((String) _DtOkString)); n++;
  970. XtSetArg(args[n], XmNcancelLabelString, CMPSTR((String) _DtCancelString)); n++;
  971. XtSetArg(args[n], XmNhelpLabelString, CMPSTR((String) _DtHelpString)); n++;
  972. string = CMPSTR(((char *)GETMESSAGE(14, 10, "New palette name:")));
  973. XtSetArg(args[n], XmNselectionLabelString, string); n++;
  974. string1 = CMPSTR("");
  975. XtSetArg(args[n], XmNtextString, string1); n++;
  976. XtSetArg(args[n], XmNborderWidth, 3); n++;
  977. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  978. addDialog = XmCreatePromptDialog(style.colorDialog,"AddDialog",
  979. args, n);
  980. XmStringFree(string);
  981. XmStringFree(string1);
  982. XtAddCallback(addDialog, XmNokCallback, addOkCB,
  983. (XtPointer) NULL);
  984. XtAddCallback(addDialog, XmNcancelCallback, addCancelCB,
  985. (XtPointer) NULL);
  986. XtAddCallback(addDialog, XmNhelpCallback,
  987. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_ADD_PALETTE_DIALOG);
  988. n = 0;
  989. XtSetArg (args[n], XmNmwmInputMode,
  990. MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
  991. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  992. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(14, 11, "Add Palette"))); n++;
  993. XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  994. XtSetValues (XtParent (addDialog), args, n);
  995. }
  996. n=0;
  997. string = CMPSTR("");
  998. XtSetArg(args[n], XmNtextString, string); n++;
  999. XtSetValues(addDialog, args, n);
  1000. XmStringFree(string);
  1001. XtManageChild(addDialog);
  1002. }
  1003. static void
  1004. addCancelCB(
  1005. Widget w,
  1006. XtPointer client_data,
  1007. XtPointer call_data )
  1008. {
  1009. XtUnmanageChild(addDialog);
  1010. }
  1011. static void
  1012. addOkCB(
  1013. Widget w,
  1014. XtPointer client_data,
  1015. XtPointer call_data )
  1016. {
  1017. int n, i;
  1018. Arg args[6];
  1019. XmString string;
  1020. char *name, *filename, *tmpstr;
  1021. palette *tmpPalette, *newPalette;
  1022. int count;
  1023. int ii, length;
  1024. int len;
  1025. /* Get the text from the promp dialog */
  1026. name = XmTextFieldGetString( XmSelectionBoxGetChild(addDialog, XmDIALOG_TEXT));
  1027. /* see if the user typed in a valid palette name */
  1028. if(!ValidName(name)) {
  1029. ErrDialog(((char *)GETMESSAGE(14, 12, "The palette name cannot contain\nthese characters:\n\n * : ( ) [ ] { } < > ! | \" / \\")),
  1030. style.colorDialog);
  1031. XtFree(name);
  1032. return;
  1033. }
  1034. /* check the number of characters in name in a locale independent way */
  1035. for ( ii = 0, count = 0; name[ii] != '\0'; ii += length ) {
  1036. length = mblen( &(name[ii]), MB_CUR_MAX );
  1037. if ( length <=0 )
  1038. break;
  1039. count++;
  1040. }
  1041. /* make sure the length of name is ok, short file names can only be 11 chars */
  1042. if(count > 10 && !style.longfilename) {
  1043. ErrDialog(((char *)GETMESSAGE(14, 13, "The palette name must be\n10 characters or less.\n")),style.colorDialog);
  1044. XtFree(name);
  1045. return;
  1046. }
  1047. /* Unmanage the promptDialog */
  1048. XtUnmanageChild(addDialog);
  1049. /* first search through palette descriptions and make sure the name to */
  1050. /* add is not already in the list and go to the end of the palette list */
  1051. for(tmpPalette = pHeadPalette; tmpPalette->next != NULL;
  1052. tmpPalette = tmpPalette->next)
  1053. {
  1054. if((strcmp(tmpPalette->desc, name) == 0)) {
  1055. SameName(w, tmpPalette, name);
  1056. XtFree(name);
  1057. return;
  1058. }
  1059. }
  1060. /* Check the last palette */
  1061. if((strcmp(tmpPalette->desc, name) == 0)) {
  1062. SameName(w, tmpPalette, name);
  1063. XtFree(name);
  1064. return;
  1065. }
  1066. /* allocate space for a new palette */
  1067. newPalette = (palette *)XtMalloc(sizeof(palette) + 1 );
  1068. /* set the previous last palatte to this new one, it is now the last one*/
  1069. tmpPalette->next = newPalette;
  1070. newPalette->next = NULL;
  1071. /* malloc space for the new palette desc */
  1072. newPalette->desc = (char *)XtMalloc(strlen(name) + 1);
  1073. for(i = 0; i < strlen(name); i++)
  1074. newPalette->desc[i] = name[i];
  1075. newPalette->desc[i] = '\0';
  1076. /* malloc space for the new palette name directory */
  1077. newPalette->directory = (char *)XtMalloc(strlen(style.home) +
  1078. strlen(DT_PAL_DIR) + 1);
  1079. strcpy(newPalette->directory, style.home);
  1080. strcat(newPalette->directory, DT_PAL_DIR);
  1081. /* makeup a new name for the palette */
  1082. tmpstr = (char *)XtMalloc(strlen(style.home) + strlen(DT_PAL_DIR) +
  1083. strlen("dtXXXXXX") + 1);
  1084. strcpy(tmpstr, newPalette->directory);
  1085. len = strlen(tmpstr);
  1086. strcat(tmpstr, "dtXXXXXX");
  1087. mktemp(tmpstr);
  1088. newPalette->name = (char *) XtMalloc(15 * sizeof(char));
  1089. strcpy(newPalette->name, tmpstr + len);
  1090. XtFree(tmpstr);
  1091. /* the new palette is the next palette .. increase NumOfPalettes by one */
  1092. newPalette->item_position = NumOfPalettes + 1;
  1093. NumOfPalettes++;
  1094. /* set all the new palette's color parameters to the current palette */
  1095. newPalette->num_of_colors = pCurrentPalette->num_of_colors;
  1096. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  1097. {
  1098. newPalette->color[i].fg.pixel = pCurrentPalette->color[i].fg.pixel;
  1099. newPalette->color[i].fg.red = pCurrentPalette->color[i].fg.red;
  1100. newPalette->color[i].fg.green = pCurrentPalette->color[i].fg.green;
  1101. newPalette->color[i].fg.blue = pCurrentPalette->color[i].fg.blue;
  1102. newPalette->color[i].fg.flags = pCurrentPalette->color[i].fg.flags;
  1103. newPalette->color[i].bg.pixel = pCurrentPalette->color[i].bg.pixel;
  1104. newPalette->color[i].bg.red = pCurrentPalette->color[i].bg.red;
  1105. newPalette->color[i].bg.green = pCurrentPalette->color[i].bg.green;
  1106. newPalette->color[i].bg.blue = pCurrentPalette->color[i].bg.blue;
  1107. newPalette->color[i].bg.flags = pCurrentPalette->color[i].bg.flags;
  1108. newPalette->color[i].ts.pixel = pCurrentPalette->color[i].ts.pixel;
  1109. newPalette->color[i].ts.red = pCurrentPalette->color[i].ts.red;
  1110. newPalette->color[i].ts.green = pCurrentPalette->color[i].ts.green;
  1111. newPalette->color[i].ts.blue = pCurrentPalette->color[i].ts.blue;
  1112. newPalette->color[i].ts.flags = pCurrentPalette->color[i].ts.flags;
  1113. newPalette->color[i].bs.pixel = pCurrentPalette->color[i].bs.pixel;
  1114. newPalette->color[i].bs.red = pCurrentPalette->color[i].bs.red;
  1115. newPalette->color[i].bs.green = pCurrentPalette->color[i].bs.green;
  1116. newPalette->color[i].bs.blue = pCurrentPalette->color[i].bs.blue;
  1117. newPalette->color[i].bs.flags = pCurrentPalette->color[i].bs.flags;
  1118. newPalette->color[i].sc.pixel = pCurrentPalette->color[i].sc.pixel;
  1119. newPalette->color[i].sc.red = pCurrentPalette->color[i].sc.red;
  1120. newPalette->color[i].sc.green = pCurrentPalette->color[i].sc.green;
  1121. newPalette->color[i].sc.blue = pCurrentPalette->color[i].sc.blue;
  1122. newPalette->color[i].sc.flags = pCurrentPalette->color[i].sc.flags;
  1123. }
  1124. /* Write out the palette */
  1125. if ((WriteOutPalette(newPalette->name)) == -1)
  1126. {
  1127. XtFree(name);
  1128. /* remove palette from list */
  1129. tmpPalette->next = NULL;
  1130. XtFree ((char *)newPalette);
  1131. return;
  1132. }
  1133. else
  1134. WriteOutDesc(newPalette);
  1135. /* add the name to the scrolled window list and select it */
  1136. AddName(newPalette);
  1137. /* now check to see if there is a ~filename .. if there is delete it */
  1138. /* use the $HOME environment varible then constuct the full file name */
  1139. filename = (char *)XtMalloc(strlen(style.home) + strlen(DT_PAL_DIR) +
  1140. strlen(newPalette->name) + strlen(PALETTE_SUFFIX) + 2);
  1141. /* create the full path name plus file name */
  1142. strcpy(filename, style.home);
  1143. strcat(filename, DT_PAL_DIR);
  1144. strcat(filename, "~");
  1145. strcat(filename, newPalette->name);
  1146. strcat(filename, PALETTE_SUFFIX);
  1147. unlink(filename);
  1148. XtFree(filename);
  1149. XtFree(name);
  1150. /* Go write out the palette */
  1151. pCurrentPalette = newPalette;
  1152. }
  1153. static void
  1154. setDlgOkCB(
  1155. Widget w,
  1156. XtPointer client_data,
  1157. XtPointer call_data )
  1158. {
  1159. palette *tmpPalette = (palette *)client_data;
  1160. int i;
  1161. /* free the directory */
  1162. XtFree(tmpPalette->directory);
  1163. /* put the new (users) directory there */
  1164. tmpPalette->directory = (char *)XtMalloc(strlen(style.home) +
  1165. strlen(DT_PAL_DIR) + 1);
  1166. strcpy(tmpPalette->directory, style.home);
  1167. strcat(tmpPalette->directory, DT_PAL_DIR);
  1168. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  1169. {
  1170. tmpPalette->color[i].fg.pixel = pCurrentPalette->color[i].fg.pixel;
  1171. tmpPalette->color[i].fg.red = pCurrentPalette->color[i].fg.red;
  1172. tmpPalette->color[i].fg.green = pCurrentPalette->color[i].fg.green;
  1173. tmpPalette->color[i].fg.blue = pCurrentPalette->color[i].fg.blue;
  1174. tmpPalette->color[i].fg.flags = pCurrentPalette->color[i].fg.flags;
  1175. tmpPalette->color[i].bg.pixel = pCurrentPalette->color[i].bg.pixel;
  1176. tmpPalette->color[i].bg.red = pCurrentPalette->color[i].bg.red;
  1177. tmpPalette->color[i].bg.green = pCurrentPalette->color[i].bg.green;
  1178. tmpPalette->color[i].bg.blue = pCurrentPalette->color[i].bg.blue;
  1179. tmpPalette->color[i].bg.flags = pCurrentPalette->color[i].bg.flags;
  1180. tmpPalette->color[i].ts.pixel = pCurrentPalette->color[i].ts.pixel;
  1181. tmpPalette->color[i].ts.red = pCurrentPalette->color[i].ts.red;
  1182. tmpPalette->color[i].ts.green = pCurrentPalette->color[i].ts.green;
  1183. tmpPalette->color[i].ts.blue = pCurrentPalette->color[i].ts.blue;
  1184. tmpPalette->color[i].ts.flags = pCurrentPalette->color[i].ts.flags;
  1185. tmpPalette->color[i].bs.pixel = pCurrentPalette->color[i].bs.pixel;
  1186. tmpPalette->color[i].bs.red = pCurrentPalette->color[i].bs.red;
  1187. tmpPalette->color[i].bs.green = pCurrentPalette->color[i].bs.green;
  1188. tmpPalette->color[i].bs.blue = pCurrentPalette->color[i].bs.blue;
  1189. tmpPalette->color[i].bs.flags = pCurrentPalette->color[i].bs.flags;
  1190. tmpPalette->color[i].sc.pixel = pCurrentPalette->color[i].sc.pixel;
  1191. tmpPalette->color[i].sc.red = pCurrentPalette->color[i].sc.red;
  1192. tmpPalette->color[i].sc.green = pCurrentPalette->color[i].sc.green;
  1193. tmpPalette->color[i].sc.blue = pCurrentPalette->color[i].sc.blue;
  1194. tmpPalette->color[i].sc.flags = pCurrentPalette->color[i].sc.flags;
  1195. }
  1196. /* Write out the palette */
  1197. if ((WriteOutPalette(tmpPalette->name)) == -1)
  1198. return;
  1199. else
  1200. WriteOutDesc(tmpPalette);
  1201. pCurrentPalette = tmpPalette;
  1202. /* select item in list as if user had selected it */
  1203. XmListSelectPos (paletteList, tmpPalette->item_position, TRUE);
  1204. XmListSetBottomPos(paletteList, tmpPalette->item_position);
  1205. selected_position = tmpPalette->item_position;
  1206. }
  1207. static void
  1208. modifyColorCB(
  1209. Widget w,
  1210. XtPointer client_data,
  1211. XtPointer call_data )
  1212. {
  1213. ColorSet *color_set;
  1214. if(TypeOfMonitor == XmCO_BLACK_WHITE)
  1215. return;
  1216. color_set = (ColorSet *) &pCurrentPalette->color[selected_button];
  1217. ColorEditor(style.colorDialog,color_set);
  1218. if(!style.dynamicColor) /* need to update pixels */
  1219. XtAddCallback(edit.DialogShell, XmNcallback, colorEditorCB, NULL);
  1220. }
  1221. /*
  1222. ** dialogBoxCB
  1223. ** Process callback from the Ok, Cancel and Help pushButtons in the
  1224. ** DialogBox.
  1225. */
  1226. static void
  1227. dialogBoxCB(
  1228. Widget w,
  1229. XtPointer client_data,
  1230. XtPointer call_data )
  1231. {
  1232. palette *tmp_palette;
  1233. Bool match = FALSE;
  1234. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  1235. switch (cb->button_position)
  1236. {
  1237. case OK_BUTTON:
  1238. if ((edit.DialogShell != NULL) && (XtIsManaged(edit.DialogShell)))
  1239. XtUnmanageChild(edit.DialogShell);
  1240. XtUnmanageChild(style.colorDialog);
  1241. UpdateDefaultPalette();
  1242. break;
  1243. case CANCEL_BUTTON:
  1244. if ((edit.DialogShell != NULL) && (XtIsManaged(edit.DialogShell)))
  1245. XtUnmanageChild(edit.DialogShell);
  1246. if ((addDialog != NULL) && (XtIsManaged(addDialog)))
  1247. XtCallCallbacks(addDialog, XmNcancelCallback, (XtPointer)NULL);
  1248. if ((deleteDialog != NULL) && (XtIsManaged(deleteDialog)))
  1249. XtCallCallbacks(deleteDialog, XmNcancelCallback, (XtPointer)NULL);
  1250. if ((colorUseDialog != NULL) && (XtIsManaged(colorUseDialog)))
  1251. XtCallCallbacks(colorUseDialog, XmNcallback, (XtPointer)NULL);
  1252. XtUnmanageChild(style.colorDialog);
  1253. tmp_palette = pHeadPalette;
  1254. for(tmp_palette = pHeadPalette; tmp_palette != NULL; tmp_palette = tmp_palette->next)
  1255. if(!(strcmp(tmp_palette->name, defaultName)))
  1256. {
  1257. match = TRUE;
  1258. break;
  1259. }
  1260. if(match == FALSE) /* the default palette is no longer valid */
  1261. UpdateDefaultPalette();
  1262. else
  1263. RestoreOrgPalette();
  1264. break;
  1265. case HELP_BUTTON:
  1266. XtCallCallbacks(style.colorDialog, XmNhelpCallback, (XtPointer)NULL);
  1267. break;
  1268. default:
  1269. break;
  1270. }
  1271. }
  1272. static void
  1273. AddName(
  1274. palette *newPalette )
  1275. {
  1276. XmString string;
  1277. /*
  1278. ** Add the palette name to the list
  1279. */
  1280. string = CMPSTR(newPalette->desc);
  1281. XmListAddItem(paletteList, string, newPalette->item_position);
  1282. XmListSelectPos(paletteList, newPalette->item_position, TRUE);
  1283. XmListSetBottomPos(paletteList, newPalette->item_position);
  1284. selected_position = newPalette->item_position;
  1285. XSync(style.display, 0);
  1286. XmStringFree(string);
  1287. }
  1288. static void
  1289. deletePaletteCB(
  1290. Widget w,
  1291. XtPointer client_data,
  1292. XtPointer call_data )
  1293. {
  1294. int n;
  1295. Arg args[10];
  1296. char *tmpStr;
  1297. palette *tmp_palette;
  1298. char *string;
  1299. char *class_str;
  1300. char *str_type_return;
  1301. XrmValue value_return;
  1302. tmp_palette = pHeadPalette;
  1303. while( tmp_palette != NULL
  1304. && tmp_palette->item_position != selected_position ) {
  1305. tmp_palette = tmp_palette->next;
  1306. }
  1307. if (deleteDialog == NULL)
  1308. {
  1309. n=0;
  1310. XtSetArg(args[n], XmNokLabelString, CMPSTR((String) _DtOkString)); n++;
  1311. XtSetArg(args[n], XmNcancelLabelString, CMPSTR((String) _DtCancelString)); n++;
  1312. XtSetArg(args[n], XmNhelpLabelString, CMPSTR((String) _DtHelpString)); n++;
  1313. XtSetArg(args[n], XmNdialogType, XmDIALOG_INFORMATION); n++;
  1314. XtSetArg(args[n], XmNborderWidth, 3); n++;
  1315. XtSetArg(args[n], XmNdefaultPosition, False); n++;
  1316. deleteDialog = XmCreateQuestionDialog(style.colorDialog,
  1317. "deleteDialog", args, n);
  1318. XtAddCallback(deleteDialog, XmNmapCallback, CenterMsgCB,
  1319. style.colorDialog);
  1320. XtAddCallback(deleteDialog, XmNcancelCallback, deleteCancelCB, NULL);
  1321. XtAddCallback(deleteDialog, XmNokCallback, deleteOkCB,
  1322. (XtPointer)(paletteList));
  1323. XtAddCallback(deleteDialog, XmNhelpCallback,
  1324. (XtCallbackProc)HelpRequestCB,
  1325. (XtPointer)HELP_DELETE_PALETTE_WARNING_DIALOG);
  1326. n = 0;
  1327. XtSetArg (args[n], XmNmwmInputMode,
  1328. MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
  1329. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  1330. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(14, 16, "Delete Palette"))); n++;
  1331. XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  1332. XtSetValues (XtParent (deleteDialog), args, n);
  1333. }
  1334. n = 0;
  1335. tmpStr = XtMalloc(strlen(STR2) + strlen(tmp_palette->desc) + 1);
  1336. sprintf(tmpStr, STR2, tmp_palette->desc);
  1337. XtSetArg(args[n], XmNmessageString, CMPSTR(tmpStr)); n++;
  1338. XtSetValues(deleteDialog, args, n);
  1339. XtFree (tmpStr);
  1340. XtManageChild(deleteDialog);
  1341. }
  1342. static void
  1343. deleteOkCB(
  1344. Widget w,
  1345. XtPointer client_data,
  1346. XtPointer call_data )
  1347. {
  1348. XtUnmanageChild(deleteDialog);
  1349. if(NumOfPalettes == 1)
  1350. {
  1351. InfoDialog(CANT_DELETE, style.colorDialog, False);
  1352. }
  1353. else
  1354. {
  1355. if (RemovePalette() == True)
  1356. DeletePaletteFromLinkList((Widget)client_data);
  1357. }
  1358. }
  1359. static void
  1360. deleteCancelCB(
  1361. Widget w,
  1362. XtPointer client_data,
  1363. XtPointer call_data )
  1364. {
  1365. XtUnmanageChild(deleteDialog);
  1366. }
  1367. static void
  1368. resourcesCB(
  1369. Widget w,
  1370. XtPointer client_data,
  1371. XtPointer call_data )
  1372. {
  1373. int n;
  1374. Arg args[12];
  1375. XmString button_string[NUM_LABELS];
  1376. XmString string;
  1377. Widget parent = (Widget) client_data;
  1378. Widget colorUseTB;
  1379. Widget form;
  1380. Widget widget_list[10];
  1381. int count=0;
  1382. Widget pictLabel;
  1383. Widget colorUseRC;
  1384. if (colorUseDialog == NULL)
  1385. {
  1386. n = 0;
  1387. /* Set up DialogBox button labels. */
  1388. button_string[0] = CMPSTR((String) _DtOkString);
  1389. button_string[1] = CMPSTR((String) _DtCancelString);
  1390. button_string[2] = CMPSTR((String) _DtHelpString);
  1391. XtSetArg (args[n], XmNchildType, XmWORK_AREA); n++;
  1392. XtSetArg (args[n], XmNbuttonCount, NUM_LABELS); n++;
  1393. XtSetArg (args[n], XmNbuttonLabelStrings, button_string); n++;
  1394. XtSetArg (args[n], XmNdefaultPosition, False); n++;
  1395. colorUseDialog = __DtCreateDialogBoxDialog(parent, "colorUseDialog",
  1396. args, n);
  1397. XtAddCallback(colorUseDialog, XmNcallback, colorUseExitCB, NULL);
  1398. XtAddCallback(colorUseDialog, XmNmapCallback, _DtmapCB_colorUse, NULL);
  1399. XtAddCallback(colorUseDialog, XmNhelpCallback,
  1400. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_COLOR_USE_DIALOG);
  1401. XmStringFree(button_string[0]);
  1402. XmStringFree(button_string[1]);
  1403. XmStringFree(button_string[2]);
  1404. widget_list[0] = _DtDialogBoxGetButton(colorUseDialog,2);
  1405. n=0;
  1406. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  1407. XtSetArg(args[n], XmNcancelButton, widget_list[0]); n++;
  1408. XtSetValues (colorUseDialog, args, n);
  1409. n = 0;
  1410. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  1411. XtSetArg (args[n], XmNtitle,
  1412. ((char *)GETMESSAGE(14, 39, "Number Of Colors To Use:"))); n++;
  1413. XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  1414. XtSetValues (XtParent(colorUseDialog), args, n);
  1415. n = 0;
  1416. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  1417. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  1418. XtSetArg(args[n], XmNallowOverlap, False); n++;
  1419. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  1420. form = XmCreateForm(colorUseDialog, "colorUseForm", args, n);
  1421. XtManageChild(form);
  1422. n = 0;
  1423. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  1424. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1425. XtSetArg (args[n], XmNrightAttachment, XmATTACH_NONE); n++;
  1426. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  1427. XtSetArg (args[n], XmNbehavior, XmICON_LABEL); n++;
  1428. XtSetArg (args[n], XmNshadowThickness, 0); n++;
  1429. XtSetArg (args[n], XmNstring, NULL); n++;
  1430. XtSetArg (args[n], XmNpixmapForeground, style.primBSCol); n++;
  1431. XtSetArg (args[n], XmNpixmapBackground, style.primTSCol); n++;
  1432. XtSetArg (args[n], XmNimageName, COLOR_ICON); n++;
  1433. XtSetArg (args[n], XmNtraversalOn, False); n++;
  1434. pictLabel = _DtCreateIcon(form, "pictLabel", args, n);
  1435. XtManageChild(pictLabel);
  1436. n = 0;
  1437. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  1438. XtSetArg (args[n], XmNtopWidget, pictLabel); n++;
  1439. XtSetArg (args[n], XmNtopOffset, style.verticalSpacing); n++;
  1440. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  1441. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  1442. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  1443. colorUseTB
  1444. = XmCreateFrame(form, "colorUseTB", args, n);
  1445. XtManageChild(colorUseTB);
  1446. /* create a rowColumn for ColorUse selections */
  1447. n = 0;
  1448. colorUseRC = XmCreateRadioBox(colorUseTB, "colorUseRC", args, n);
  1449. XtManageChild(colorUseRC);
  1450. n = 0;
  1451. string = CMPSTR(((char *)GETMESSAGE(14, 41, "More Colors for Desktop")));
  1452. XtSetArg(args[n], XmNlabelString, string); n++;
  1453. widget_list[count++] = colorDialog.highColorTG
  1454. = XmCreateToggleButtonGadget(colorUseRC,"highColorTG", args, n);
  1455. XtAddCallback(colorDialog.highColorTG, XmNvalueChangedCallback,
  1456. colorUseCB, (XtPointer)XmCO_HIGH_COLOR);
  1457. XmStringFree(string);
  1458. n = 0;
  1459. string = CMPSTR(((char *)GETMESSAGE(14, 42, "More Colors for Applications")));
  1460. XtSetArg(args[n], XmNlabelString, string); n++;
  1461. widget_list[count++] = colorDialog.mediumColorTG
  1462. = XmCreateToggleButtonGadget(colorUseRC,"mediumColorTG", args, n);
  1463. XmStringFree(string);
  1464. XtAddCallback(colorDialog.mediumColorTG, XmNvalueChangedCallback,
  1465. colorUseCB, (XtPointer)XmCO_MEDIUM_COLOR);
  1466. n = 0;
  1467. string = CMPSTR(((char *)GETMESSAGE(14, 43, "Most Colors for Applications")));
  1468. XtSetArg(args[n], XmNlabelString, string); n++;
  1469. widget_list[count++] = colorDialog.lowColorTG
  1470. = XmCreateToggleButtonGadget(colorUseRC,"lowColorTG", args, n);
  1471. XmStringFree(string);
  1472. XtAddCallback(colorDialog.lowColorTG, XmNvalueChangedCallback,
  1473. colorUseCB, (XtPointer)XmCO_LOW_COLOR);
  1474. n = 0;
  1475. string = CMPSTR(((char *)GETMESSAGE(14, 34, "Black and White")));
  1476. XtSetArg(args[n], XmNlabelString, string); n++;
  1477. widget_list[count++] = colorDialog.blackWhiteTG
  1478. = XmCreateToggleButtonGadget(colorUseRC,"blackWhiteTG", args, n);
  1479. XmStringFree(string);
  1480. XtAddCallback(colorDialog.blackWhiteTG, XmNvalueChangedCallback,
  1481. colorUseCB, (XtPointer)XmCO_BLACK_WHITE);
  1482. n = 0;
  1483. string = CMPSTR(((char *)GETMESSAGE(14, 35, "Default")));
  1484. XtSetArg(args[n], XmNlabelString, string); n++;
  1485. widget_list[count++] = colorDialog.defaultTG
  1486. = XmCreateToggleButtonGadget(colorUseRC,"defaultTG", args, n);
  1487. XmStringFree(string);
  1488. XtAddCallback(colorDialog.defaultTG, XmNvalueChangedCallback,
  1489. colorUseCB, (XtPointer)DEFAULT_COLOR);
  1490. XtManageChildren(widget_list,count);
  1491. putDialog (XtParent(style.colorDialog), colorUseDialog);
  1492. }
  1493. XtManageChild(colorUseDialog);
  1494. }
  1495. /*
  1496. ** colorUseCB
  1497. ** Process new ColorUse selection
  1498. */
  1499. static void
  1500. colorUseCB(
  1501. Widget w,
  1502. XtPointer client_data,
  1503. XtPointer call_data )
  1504. {
  1505. Arg args[4];
  1506. XmToggleButtonCallbackStruct *cb =
  1507. (XmToggleButtonCallbackStruct *)call_data;
  1508. colorDialog.currentColorUse = (int) (intptr_t) client_data;
  1509. switch (colorDialog.currentColorUse)
  1510. {
  1511. case XmCO_HIGH_COLOR:
  1512. colorDialog.currentColorUseStr = HIGH_COLOR_STR;
  1513. break;
  1514. case XmCO_MEDIUM_COLOR:
  1515. colorDialog.currentColorUseStr = MEDIUM_COLOR_STR;
  1516. break;
  1517. case XmCO_LOW_COLOR:
  1518. colorDialog.currentColorUseStr = LOW_COLOR_STR;
  1519. break;
  1520. case XmCO_BLACK_WHITE:
  1521. colorDialog.currentColorUseStr = B_W_STR;
  1522. break;
  1523. case DEFAULT_COLOR:
  1524. colorDialog.currentColorUseStr = DEFAULT_COLOR_STR;
  1525. break;
  1526. }
  1527. }
  1528. /*
  1529. ** colorUseExitCB
  1530. ** Process callback from the Ok, Cancel and Help pushButtons in the
  1531. ** Configure DT Colors DialogBox.
  1532. */
  1533. static void
  1534. colorUseExitCB(
  1535. Widget w,
  1536. XtPointer client_data,
  1537. XtPointer call_data )
  1538. {
  1539. char colorUseRes[64];
  1540. DtDialogBoxCallbackStruct *cb = (DtDialogBoxCallbackStruct *) call_data;
  1541. switch (cb->button_position)
  1542. {
  1543. case HELP_BUTTON:
  1544. XtCallCallbacks(colorUseDialog, XmNhelpCallback, (XtPointer)NULL);
  1545. break;
  1546. case OK_BUTTON:
  1547. XtUnmanageChild(colorUseDialog);
  1548. if (colorDialog.origColorUse != colorDialog.currentColorUse)
  1549. {
  1550. InfoDialog(COLORUSE_WHEN, style.colorDialog, False);
  1551. /* create the ColorUse resource spec for xrdb */
  1552. /* remove ColorUse specification from database for DEFAULT_COLOR */
  1553. sprintf(colorUseRes, "*%d*ColorUse: %s\n",
  1554. style.screenNum,colorDialog.currentColorUseStr);
  1555. switch (colorDialog.currentColorUse)
  1556. {
  1557. case XmCO_MEDIUM_COLOR:
  1558. sprintf(colorUseRes+strlen(colorUseRes),
  1559. "*HelpColorUse: GRAY_SCALE\n");
  1560. break;
  1561. case XmCO_LOW_COLOR:
  1562. case XmCO_BLACK_WHITE:
  1563. sprintf(colorUseRes+strlen(colorUseRes),
  1564. "*HelpColorUse: B_W\n");
  1565. break;
  1566. case XmCO_HIGH_COLOR:
  1567. case DEFAULT_COLOR:
  1568. default:
  1569. sprintf(colorUseRes+strlen(colorUseRes),
  1570. "*HelpColorUse: COLOR\n");
  1571. break;
  1572. }
  1573. _DtAddToResource(style.display, colorUseRes);
  1574. colorDialog.origColorUse = colorDialog.currentColorUse;
  1575. }
  1576. break;
  1577. case CANCEL_BUTTON:
  1578. default:
  1579. XtUnmanageChild(colorUseDialog);
  1580. switch (colorDialog.origColorUse)
  1581. {
  1582. case XmCO_HIGH_COLOR:
  1583. XmToggleButtonGadgetSetState(colorDialog.highColorTG, True, True);
  1584. break;
  1585. case XmCO_MEDIUM_COLOR:
  1586. XmToggleButtonGadgetSetState(colorDialog.mediumColorTG, True, True);
  1587. break;
  1588. case XmCO_LOW_COLOR:
  1589. XmToggleButtonGadgetSetState(colorDialog.lowColorTG, True, True);
  1590. break;
  1591. case XmCO_BLACK_WHITE:
  1592. XmToggleButtonGadgetSetState(colorDialog.blackWhiteTG, True, True);
  1593. break;
  1594. case DEFAULT_COLOR:
  1595. XmToggleButtonGadgetSetState(colorDialog.defaultTG, True, True);
  1596. break;
  1597. }
  1598. break;
  1599. }
  1600. }
  1601. static void
  1602. activateCBexitColor(
  1603. Widget w,
  1604. XtPointer client_data,
  1605. XtPointer call_data )
  1606. {
  1607. DtDialogBoxCallbackStruct CancelBut;
  1608. if(style.colorDialog != NULL && XtIsManaged(style.colorDialog)) {
  1609. CancelBut.button_position = CANCEL_BUTTON;
  1610. XtCallCallbacks(style.colorDialog, XmNcallback, &CancelBut);
  1611. }
  1612. }
  1613. static void
  1614. _DtmapCB(
  1615. Widget w,
  1616. XtPointer client_data,
  1617. XtPointer call_data )
  1618. {
  1619. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  1620. if (!save.restoreFlag)
  1621. putDialog ((Widget)client_data, XtParent(w));
  1622. XtRemoveCallback(style.colorDialog, XmNmapCallback, _DtmapCB, NULL);
  1623. }
  1624. static void
  1625. _DtmapCB_colorUse(
  1626. Widget w,
  1627. XtPointer client_data,
  1628. XtPointer call_data )
  1629. {
  1630. char *str_type_return;
  1631. XrmValue value_return;
  1632. XrmValue cvt_value;
  1633. XrmDatabase db;
  1634. Boolean status;
  1635. char *string;
  1636. char instanceString[24], nameString[24];
  1637. DtWsmRemoveWorkspaceFunctions(style.display, XtWindow(XtParent(w)));
  1638. db = XtDatabase(style.display);
  1639. /* Get ColorUse value */
  1640. sprintf (instanceString, "dtsession*%d*colorUse",style.screenNum);
  1641. sprintf (nameString, "Dtsession*%d*ColorUse",style.screenNum);
  1642. if (status = XrmGetResource (db, instanceString,
  1643. nameString,
  1644. &str_type_return, &value_return))
  1645. {
  1646. /* make local copy of string */
  1647. string = (char *) XtMalloc( value_return.size );
  1648. strcpy (string, value_return.addr);
  1649. if (strcmp(string, HIGH_COLOR_STR) == 0)
  1650. {
  1651. XmToggleButtonGadgetSetState (colorDialog.highColorTG, True, True);
  1652. colorDialog.origColorUse = XmCO_HIGH_COLOR;
  1653. }
  1654. else if (strcmp(string, MEDIUM_COLOR_STR) == 0)
  1655. {
  1656. XmToggleButtonGadgetSetState (colorDialog.mediumColorTG, True, True);
  1657. colorDialog.origColorUse = XmCO_MEDIUM_COLOR;
  1658. }
  1659. else if (strcmp(string, LOW_COLOR_STR) == 0)
  1660. {
  1661. XmToggleButtonGadgetSetState (colorDialog.lowColorTG, True, True);
  1662. colorDialog.origColorUse = XmCO_LOW_COLOR;
  1663. }
  1664. else if (strcmp(string, B_W_STR) == 0)
  1665. {
  1666. XmToggleButtonGadgetSetState (colorDialog.blackWhiteTG, True, True);
  1667. colorDialog.origColorUse = XmCO_BLACK_WHITE;
  1668. }
  1669. else
  1670. {
  1671. XmToggleButtonGadgetSetState (colorDialog.defaultTG, True, True);
  1672. colorDialog.origColorUse = DEFAULT_COLOR;
  1673. }
  1674. XtFree (string);
  1675. }
  1676. else /* ColorUse not specified */
  1677. {
  1678. XmToggleButtonGadgetSetState (colorDialog.defaultTG, True, True);
  1679. colorDialog.origColorUse = DEFAULT_COLOR;
  1680. }
  1681. XtRemoveCallback(colorUseDialog, XmNmapCallback, _DtmapCB_colorUse, NULL);
  1682. }
  1683. /************************************************************************
  1684. *
  1685. * DeletePaletteFromLinkList - routine used to delete a palette from
  1686. * the link list of palettes. The palette which is at the current
  1687. * selected_position is the palette that is going to be deleted.
  1688. * Special things have to happen if the selected palette is at the
  1689. * head of the list.
  1690. *
  1691. ************************************************************************/
  1692. void
  1693. DeletePaletteFromLinkList(
  1694. Widget list )
  1695. {
  1696. int n;
  1697. Arg args[2];
  1698. int i;
  1699. XmString string;
  1700. palette *tmp_palette, *tmp2_palette;
  1701. palette *selected_palette;
  1702. selected_palette = pHeadPalette;
  1703. while( selected_palette != NULL
  1704. && selected_palette->item_position != selected_position ) {
  1705. selected_palette = selected_palette->next;
  1706. }
  1707. XmListDeletePos (list, selected_palette->item_position);
  1708. /* delete item from palette list structure */
  1709. /* If the palette is at the head .. remove the head and the next
  1710. palette becomes the new selected palette */
  1711. if (selected_palette->item_position == 1)
  1712. {
  1713. pHeadPalette = selected_palette->next;
  1714. tmp_palette = pHeadPalette;
  1715. tmp_palette->item_position--;
  1716. /* new current palette */
  1717. pCurrentPalette = tmp_palette;
  1718. }
  1719. else /* find the palette just above the palette to be deleted .. it
  1720. will become the new selected palette */
  1721. {
  1722. tmp_palette = pHeadPalette;
  1723. for (i=1; i < selected_palette->item_position-1; i++)
  1724. tmp_palette = tmp_palette->next;
  1725. tmp_palette->next = selected_palette->next;
  1726. /* what is CurrentPalette now? prev or next item?
  1727. special case empty list or NULL entry */
  1728. if (tmp_palette->next != NULL)
  1729. pCurrentPalette = tmp_palette->next;
  1730. else
  1731. pCurrentPalette = tmp_palette;
  1732. }
  1733. /* decrement item_positions values in remaining palette entries */
  1734. tmp2_palette = tmp_palette;
  1735. while ((tmp2_palette = tmp2_palette->next) != NULL)
  1736. {
  1737. tmp2_palette->item_position--;
  1738. }
  1739. /* go copy the pixel numbers to the new palette */
  1740. CopyPixel(selected_palette->color, pCurrentPalette->color,
  1741. selected_palette->num_of_colors);
  1742. /* select item in list as if user had selected it */
  1743. XmListSelectPos (list, tmp_palette->item_position, TRUE);
  1744. /* Need to check to see if the first palette is being deleted if it is
  1745. need to change colors and update title box */
  1746. if(selected_position == tmp_palette->item_position) {
  1747. pOldPalette = selected_palette;
  1748. n=0;
  1749. string = CMPSTR(pCurrentPalette->desc);
  1750. XtSetArg (args[n], XmNtitleString, string); n++;
  1751. XtSetValues (colorDialog.buttonsTB, args, n);
  1752. XmStringFree(string);
  1753. ReColorPalette();
  1754. }
  1755. XmListSetBottomPos(paletteList, tmp_palette->item_position);
  1756. selected_position = tmp_palette->item_position;
  1757. NumOfPalettes--;
  1758. /* deallocate the palette structure */
  1759. XtFree(selected_palette->name);
  1760. XtFree(selected_palette->desc);
  1761. XtFree(selected_palette->directory);
  1762. XtFree((char *)selected_palette);
  1763. }
  1764. void
  1765. CopyPixel(
  1766. ColorSet srcPixels[XmCO_MAX_NUM_COLORS],
  1767. ColorSet dstPixels[XmCO_MAX_NUM_COLORS],
  1768. int numOfColors )
  1769. {
  1770. int i;
  1771. for(i=0; i < numOfColors; i++)
  1772. {
  1773. dstPixels[i].bg.pixel = srcPixels[i].bg.pixel;
  1774. dstPixels[i].fg.pixel = srcPixels[i].fg.pixel;
  1775. dstPixels[i].ts.pixel = srcPixels[i].ts.pixel;
  1776. dstPixels[i].bs.pixel = srcPixels[i].bs.pixel;
  1777. dstPixels[i].sc.pixel = srcPixels[i].sc.pixel;
  1778. }
  1779. }
  1780. void
  1781. SaveOrgPalette( void )
  1782. {
  1783. int i;
  1784. palette *tmp_palette, *tmp2_palette;
  1785. if(save.restoreFlag && defaultName_restore[0] != 0) {
  1786. tmp_palette = pHeadPalette;
  1787. while(tmp_palette->next != NULL )
  1788. if(strcmp(tmp_palette->name, defaultName))
  1789. {
  1790. tmp_palette = tmp_palette->next;
  1791. }
  1792. else
  1793. {
  1794. break;
  1795. }
  1796. if(!strcmp(tmp_palette->name, defaultName)) {
  1797. tmp2_palette = pCurrentPalette;
  1798. pCurrentPalette = tmp_palette;
  1799. }
  1800. else
  1801. tmp_palette = NULL;
  1802. }
  1803. OrgPalette.item_position = pCurrentPalette->item_position;
  1804. OrgPalette.num_of_colors = pCurrentPalette->num_of_colors;
  1805. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  1806. {
  1807. OrgPalette.primary = pCurrentPalette->primary;
  1808. OrgPalette.secondary = pCurrentPalette->secondary;
  1809. OrgPalette.active = pCurrentPalette->active;
  1810. OrgPalette.inactive = pCurrentPalette->inactive;
  1811. if(save.restoreFlag && defaultName_restore[0] != 0)
  1812. OrgPalette.color[i].bg.pixel = tmp2_palette->color[i].bg.pixel;
  1813. else
  1814. OrgPalette.color[i].bg.pixel = pCurrentPalette->color[i].bg.pixel;
  1815. OrgPalette.color[i].bg.red = pCurrentPalette->color[i].bg.red;
  1816. OrgPalette.color[i].bg.green = pCurrentPalette->color[i].bg.green;
  1817. OrgPalette.color[i].bg.blue = pCurrentPalette->color[i].bg.blue;
  1818. if(save.restoreFlag && defaultName_restore[0] != 0)
  1819. OrgPalette.color[i].fg.pixel = tmp2_palette->color[i].fg.pixel;
  1820. else
  1821. OrgPalette.color[i].fg.pixel = pCurrentPalette->color[i].fg.pixel;
  1822. OrgPalette.color[i].fg.red = pCurrentPalette->color[i].fg.red;
  1823. OrgPalette.color[i].fg.green = pCurrentPalette->color[i].fg.green;
  1824. OrgPalette.color[i].fg.blue = pCurrentPalette->color[i].fg.blue;
  1825. if(save.restoreFlag && defaultName_restore[0] != 0)
  1826. OrgPalette.color[i].ts.pixel = tmp2_palette->color[i].ts.pixel;
  1827. else
  1828. OrgPalette.color[i].ts.pixel = pCurrentPalette->color[i].ts.pixel;
  1829. OrgPalette.color[i].ts.red = pCurrentPalette->color[i].ts.red;
  1830. OrgPalette.color[i].ts.green = pCurrentPalette->color[i].ts.green;
  1831. OrgPalette.color[i].ts.blue = pCurrentPalette->color[i].ts.blue;
  1832. if(save.restoreFlag && defaultName_restore[0] != 0)
  1833. OrgPalette.color[i].bs.pixel = tmp2_palette->color[i].bs.pixel;
  1834. else
  1835. OrgPalette.color[i].bs.pixel = pCurrentPalette->color[i].bs.pixel;
  1836. OrgPalette.color[i].bs.red = pCurrentPalette->color[i].bs.red;
  1837. OrgPalette.color[i].bs.green = pCurrentPalette->color[i].bs.green;
  1838. OrgPalette.color[i].bs.blue = pCurrentPalette->color[i].bs.blue;
  1839. if(save.restoreFlag && defaultName_restore[0] != 0)
  1840. OrgPalette.color[i].sc.pixel = tmp2_palette->color[i].sc.pixel;
  1841. else
  1842. OrgPalette.color[i].sc.pixel = pCurrentPalette->color[i].sc.pixel;
  1843. OrgPalette.color[i].sc.red = pCurrentPalette->color[i].sc.red;
  1844. OrgPalette.color[i].sc.green = pCurrentPalette->color[i].sc.green;
  1845. OrgPalette.color[i].sc.blue = pCurrentPalette->color[i].sc.blue;
  1846. }
  1847. if(save.restoreFlag && defaultName_restore[0] != 0)
  1848. if(tmp_palette != NULL)
  1849. pCurrentPalette = tmp2_palette;
  1850. }
  1851. void
  1852. RestoreOrgPalette( void )
  1853. {
  1854. int i;
  1855. palette *tmp_palette;
  1856. int j=0;
  1857. XColor colors[XmCO_MAX_NUM_COLORS * 5];
  1858. tmp_palette = pHeadPalette;
  1859. while ( tmp_palette != NULL &&
  1860. tmp_palette->item_position != OrgPalette.item_position )
  1861. tmp_palette = tmp_palette->next;
  1862. if ( tmp_palette != NULL &&
  1863. tmp_palette->item_position == OrgPalette.item_position)
  1864. {
  1865. pCurrentPalette = tmp_palette;
  1866. OrgPalette.num_of_colors = pCurrentPalette->num_of_colors;
  1867. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  1868. {
  1869. pCurrentPalette->primary = OrgPalette.primary;
  1870. pCurrentPalette->secondary = OrgPalette.secondary;
  1871. pCurrentPalette->inactive = OrgPalette.inactive;
  1872. pCurrentPalette->active = OrgPalette.active;
  1873. pCurrentPalette->color[i].bg.pixel = OrgPalette.color[i].bg.pixel;
  1874. pCurrentPalette->color[i].bg.red = OrgPalette.color[i].bg.red;
  1875. pCurrentPalette->color[i].bg.green = OrgPalette.color[i].bg.green;
  1876. pCurrentPalette->color[i].bg.blue = OrgPalette.color[i].bg.blue;
  1877. if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
  1878. colors[j++] = pCurrentPalette->color[i].bg;
  1879. pCurrentPalette->color[i].sc.pixel = OrgPalette.color[i].sc.pixel;
  1880. pCurrentPalette->color[i].sc.red = OrgPalette.color[i].sc.red;
  1881. pCurrentPalette->color[i].sc.green = OrgPalette.color[i].sc.green;
  1882. pCurrentPalette->color[i].sc.blue = OrgPalette.color[i].sc.blue;
  1883. if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
  1884. colors[j++] = pCurrentPalette->color[i].sc;
  1885. pCurrentPalette->color[i].fg.pixel = OrgPalette.color[i].fg.pixel;
  1886. pCurrentPalette->color[i].fg.red = OrgPalette.color[i].fg.red;
  1887. pCurrentPalette->color[i].fg.green = OrgPalette.color[i].fg.green;
  1888. pCurrentPalette->color[i].fg.blue = OrgPalette.color[i].fg.blue;
  1889. if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
  1890. if(FgColor == DYNAMIC)
  1891. colors[j++] = pCurrentPalette->color[i].fg;
  1892. pCurrentPalette->color[i].ts.pixel = OrgPalette.color[i].ts.pixel;
  1893. pCurrentPalette->color[i].ts.red = OrgPalette.color[i].ts.red;
  1894. pCurrentPalette->color[i].ts.green = OrgPalette.color[i].ts.green;
  1895. pCurrentPalette->color[i].ts.blue = OrgPalette.color[i].ts.blue;
  1896. if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
  1897. if(UsePixmaps == FALSE)
  1898. colors[j++] = pCurrentPalette->color[i].ts;
  1899. pCurrentPalette->color[i].bs.pixel = OrgPalette.color[i].bs.pixel;
  1900. pCurrentPalette->color[i].bs.red = OrgPalette.color[i].bs.red;
  1901. pCurrentPalette->color[i].bs.green = OrgPalette.color[i].bs.green;
  1902. pCurrentPalette->color[i].bs.blue = OrgPalette.color[i].bs.blue;
  1903. if(i < OrgPalette.num_of_colors && TypeOfMonitor != XmCO_BLACK_WHITE)
  1904. if(UsePixmaps == FALSE)
  1905. colors[j++] = pCurrentPalette->color[i].bs;
  1906. }
  1907. if (style.dynamicColor)
  1908. XStoreColors (style.display, style.colormap, colors, j);
  1909. XmListSelectPos (paletteList, OrgPalette.item_position, TRUE);
  1910. XmListSetBottomPos(paletteList, OrgPalette.item_position);
  1911. }
  1912. }
  1913. void
  1914. UpdateDefaultPalette( void )
  1915. {
  1916. int i;
  1917. char temp[XmCO_MAX_NUM_COLORS][60];
  1918. char xrdb_string[100];
  1919. XColor saved_color[2] = { { 0, 0, 0 }, { 0, 0, 0 } };
  1920. for(i = 0; i < XmCO_MAX_NUM_COLORS; i++)
  1921. {
  1922. /* put the colors of the palette in the form #RRRRGGGGBBBB */
  1923. if(TypeOfMonitor == XmCO_LOW_COLOR && (i == 0 || i == 1))
  1924. sprintf(temp[i],"#%04x%04x%04x\n", saved_color[i].red,
  1925. saved_color[i].green,
  1926. saved_color[i].blue);
  1927. else if(TypeOfMonitor == XmCO_LOW_COLOR && i == 2)
  1928. sprintf(temp[i],"#%04x%04x%04x\n",pCurrentPalette->color[1].bg.red,
  1929. pCurrentPalette->color[1].bg.green,
  1930. pCurrentPalette->color[1].bg.blue);
  1931. else if(TypeOfMonitor == XmCO_LOW_COLOR && i == 3)
  1932. sprintf(temp[i],"#%04x%04x%04x\n",pCurrentPalette->color[0].bg.red,
  1933. pCurrentPalette->color[0].bg.green,
  1934. pCurrentPalette->color[0].bg.blue);
  1935. else
  1936. sprintf(temp[i],"#%04x%04x%04x\n",pCurrentPalette->color[i].bg.red,
  1937. pCurrentPalette->color[i].bg.green,
  1938. pCurrentPalette->color[i].bg.blue);
  1939. }
  1940. /* update the resource manager property with the palette resource */
  1941. if (TypeOfMonitor == XmCO_BLACK_WHITE)
  1942. {
  1943. sprintf(xrdb_string, "*%d*MonochromePalette: %s%s\n",
  1944. style.screenNum, pCurrentPalette->name, PALETTE_SUFFIX);
  1945. }
  1946. else
  1947. {
  1948. sprintf(xrdb_string, "*%d*ColorPalette: %s%s\n",
  1949. style.screenNum, pCurrentPalette->name, PALETTE_SUFFIX);
  1950. }
  1951. _DtAddToResource(style.display, xrdb_string);
  1952. /* update the defaultName */
  1953. XtFree(defaultName);
  1954. defaultName = (char *)XtMalloc(strlen(pCurrentPalette->name)+1);
  1955. strcpy(defaultName, pCurrentPalette->name);
  1956. /* update Xrdb for non Motif1.1 clients */
  1957. if (style.xrdb.writeXrdbColors)
  1958. {
  1959. #ifdef sun
  1960. OWsyncColorResources(style.display, TypeOfMonitor,
  1961. pCurrentPalette->color);
  1962. #else
  1963. int chipnum = TypeOfMonitor == XmCO_HIGH_COLOR ? 4 : 1;
  1964. sprintf(xrdb_string,
  1965. "*background: #%04X%04X%04X\n*foreground: #%04X%04X%04X\n",
  1966. pCurrentPalette->color[chipnum].bg.red,
  1967. pCurrentPalette->color[chipnum].bg.green,
  1968. pCurrentPalette->color[chipnum].bg.blue,
  1969. pCurrentPalette->color[chipnum].fg.red,
  1970. pCurrentPalette->color[chipnum].fg.green,
  1971. pCurrentPalette->color[chipnum].fg.blue);
  1972. _DtAddToResource(style.display, xrdb_string);
  1973. #endif
  1974. }
  1975. }
  1976. void
  1977. show_selection(
  1978. Widget w,
  1979. XtPointer client_data,
  1980. Atom *selection,
  1981. Atom *type,
  1982. XtPointer value,
  1983. unsigned long *length,
  1984. int *format )
  1985. {
  1986. int dynamic_color;
  1987. style.colorSrv = True;
  1988. if(value != NULL)
  1989. {
  1990. if((intptr_t) client_data == GET_TYPE_MONITOR)
  1991. {
  1992. sscanf ((char *)value, "%x_%x_%x_%x", (unsigned int *) &(TypeOfMonitor),
  1993. (unsigned int *) &(UsePixmaps), (unsigned int *) &(FgColor), (unsigned int *) &dynamic_color);
  1994. if(dynamic_color == FALSE)
  1995. style.dynamicColor = False;
  1996. else
  1997. style.dynamicColor = True;
  1998. }
  1999. WaitSelection = FALSE;
  2000. free(value);
  2001. }
  2002. else /* no response from Color Server - it must not be there */
  2003. {
  2004. style.colorSrv = False;
  2005. WaitSelection = FALSE;
  2006. }
  2007. }
  2008. /************************************************************************
  2009. * restoreColor()
  2010. *
  2011. * restore any state information saved with saveBackdrop.
  2012. * This is called from restoreSession with the application
  2013. * shell and the special xrm database retrieved for restore.
  2014. ************************************************************************/
  2015. void
  2016. restoreColor(
  2017. Widget shell,
  2018. XrmDatabase db )
  2019. {
  2020. XrmName xrm_name[5];
  2021. XrmRepresentation rep_type;
  2022. XrmValue value;
  2023. palette *tmp_palette;
  2024. /*"paletteDlg" is the resource name of the dialog shell we are saving for.*/
  2025. xrm_name [0] = XrmStringToQuark (PALETTEDLG);
  2026. xrm_name [2] = 0;
  2027. /* get x position */
  2028. xrm_name [1] = XrmStringToQuark ("x");
  2029. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  2030. XtSetArg (save.posArgs[save.poscnt], XmNx, atoi((char *)value.addr)); save.poscnt++;
  2031. }
  2032. /* get y position */
  2033. xrm_name [1] = XrmStringToQuark ("y");
  2034. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  2035. XtSetArg (save.posArgs[save.poscnt], XmNy, atoi((char *)value.addr)); save.poscnt++;
  2036. }
  2037. /* get selected palette */
  2038. xrm_name [1] = XrmStringToQuark ("selected_palette");
  2039. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  2040. strcpy(defaultName_restore, value.addr);
  2041. }
  2042. else
  2043. defaultName_restore[0] = 0;
  2044. /* get selected button */
  2045. xrm_name [1] = XrmStringToQuark ("selected_button");
  2046. if (XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value)){
  2047. selected_button = atoi((char *)value.addr);
  2048. }
  2049. /* need to have some variables initialized before creating the
  2050. Color's dialog ... */
  2051. InitializeAtoms();
  2052. CheckMonitor(shell);
  2053. GetDefaultPal(shell);
  2054. xrm_name [1] = XrmStringToQuark ("ismapped");
  2055. XrmQGetResource (db, xrm_name, xrm_name, &rep_type, &value);
  2056. /* Are we supposed to be mapped? */
  2057. if (strcmp(value.addr, "True") == 0) {
  2058. save.restoreFlag = True;
  2059. Customize(shell);
  2060. }
  2061. }
  2062. /************************************************************************
  2063. * saveColor()
  2064. *
  2065. * This routine will write out to the passed file descriptor any state
  2066. * information this dialog needs. It is called from saveSessionCB with the
  2067. * file already opened.
  2068. * All information is saved in xrm format. There is no restriction
  2069. * on what can be saved. It doesn't have to be defined or be part of any
  2070. * widget or Xt definition. Just name and save it here and recover it in
  2071. * restoreBackdrop. The suggested minimum is whether you are mapped, and your
  2072. * location.
  2073. ************************************************************************/
  2074. void
  2075. saveColor(
  2076. int fd )
  2077. {
  2078. Position x,y;
  2079. char *bufr = style.tmpBigStr; /* size=[1024], make bigger if needed */
  2080. XmVendorShellExtObject vendorExt;
  2081. XmWidgetExtData extData;
  2082. if (style.colorDialog != NULL)
  2083. {
  2084. if (XtIsManaged(style.colorDialog))
  2085. sprintf(bufr, "*paletteDlg.ismapped: True\n");
  2086. else
  2087. sprintf(bufr, "*paletteDlg.ismapped: False\n");
  2088. /* Get and write out the geometry info for our Window */
  2089. x = XtX(XtParent(style.colorDialog));
  2090. y = XtY(XtParent(style.colorDialog));
  2091. /* Modify x & y to take into account window mgr frames
  2092. * This is pretty bogus, but I don't know a better way to do it.
  2093. */
  2094. extData = _XmGetWidgetExtData(style.shell, XmSHELL_EXTENSION);
  2095. vendorExt = (XmVendorShellExtObject)extData->widget;
  2096. x -= vendorExt->vendor.xOffset;
  2097. y -= vendorExt->vendor.yOffset;
  2098. sprintf(bufr, "%s*paletteDlg.x: %d\n", bufr, x);
  2099. sprintf(bufr, "%s*paletteDlg.y: %d\n", bufr, y);
  2100. sprintf(bufr, "%s*paletteDlg.selected_palette: %s\n", bufr,
  2101. pCurrentPalette->name);
  2102. sprintf(bufr, "%s*paletteDlg.selected_button: %d\n", bufr,
  2103. selected_button);
  2104. if(-1 == write (fd, bufr, strlen(bufr))) {
  2105. perror(strerror(errno));
  2106. }
  2107. }
  2108. }
  2109. /**************************************************************************
  2110. *
  2111. * SameName - procedure used by the Add palette .. if the palette desc the
  2112. * user selects is the same name as a palette already in the
  2113. * linked list this procedure gets called. It set up a
  2114. * Warning dialog asking the user if they really want to add
  2115. * a palette with the same name as an existing palette.
  2116. *
  2117. **************************************************************************/
  2118. void
  2119. SameName(
  2120. Widget w,
  2121. palette *tmpPalette,
  2122. char *name )
  2123. {
  2124. char *tmpStr;
  2125. int n=0;
  2126. Arg args[10];
  2127. if (colorDialog.dlg == NULL) {
  2128. tmpStr = (char *)XtMalloc(strlen(STR1) + strlen(name) + 1);
  2129. sprintf(tmpStr, STR1, name);
  2130. XtSetArg(args[n], XmNmessageString, CMPSTR(tmpStr)); n++;
  2131. XtSetArg(args[n], XmNokLabelString, CMPSTR((String) _DtOkString)); n++;
  2132. XtSetArg(args[n], XmNcancelLabelString, CMPSTR((String) _DtCancelString)); n++;
  2133. XtSetArg(args[n], XmNhelpLabelString, CMPSTR((String) _DtHelpString)); n++;
  2134. XtSetArg(args[n], XmNmwmFunctions, DIALOG_MWM_FUNC ); n++;
  2135. XtSetArg(args[n], XmNdialogTitle, CMPSTR(((char *)GETMESSAGE(14, 21, "Warning")))); n++;
  2136. colorDialog.dlg = XmCreateWarningDialog(style.colorDialog, "QNotice", args, n);
  2137. XtAddCallback(colorDialog.dlg, XmNokCallback, setDlgOkCB, (XtPointer)tmpPalette);
  2138. XtAddCallback(colorDialog.dlg, XmNhelpCallback,
  2139. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_ADD_PALETTE_WARNING_DIALOG);
  2140. n=0;
  2141. XtSetArg (args[n], XmNmwmInputMode,
  2142. MWM_INPUT_PRIMARY_APPLICATION_MODAL); n++;
  2143. XtSetValues (XtParent(colorDialog.dlg), args, n);
  2144. XtFree(tmpStr);
  2145. }
  2146. XtManageChild(colorDialog.dlg);
  2147. }
  2148. /****************************************************************************
  2149. *
  2150. * ValidName - procedure which checks to make sure the name being passed
  2151. * in is a valid filename. Weeds out many of the non
  2152. * alphabit characters.
  2153. *
  2154. ***************************************************************************/
  2155. static Boolean
  2156. ValidName(
  2157. char *name )
  2158. {
  2159. int i;
  2160. Boolean valid = True;
  2161. #ifdef NLS16
  2162. int chlen;
  2163. #endif /* NLS16 */
  2164. if (!name || strlen(name) == 0)
  2165. {
  2166. valid = False;
  2167. }
  2168. #ifdef NLS16
  2169. chlen = mblen (&name[0], MB_CUR_MAX);
  2170. for (i = 0; (i < strlen(name)) && chlen && valid; i += chlen)
  2171. {
  2172. chlen = mblen (&name[i], MB_CUR_MAX);
  2173. if ((chlen == 1) &&
  2174. ((name[i] == '*') ||
  2175. (name[i] == '"') ||
  2176. (name[i] == '\\') ||
  2177. (name[i] == '[') ||
  2178. (name[i] == ']') ||
  2179. (name[i] == '{') ||
  2180. (name[i] == '}') ||
  2181. (name[i] == '>') ||
  2182. (name[i] == '<') ||
  2183. (name[i] == '(') ||
  2184. (name[i] == ')') ||
  2185. (name[i] == '!') ||
  2186. (name[i] == '|') ||
  2187. (name[i] == ':') ||
  2188. (name[i] == '/')))
  2189. {
  2190. valid = False;
  2191. }
  2192. }
  2193. #else /* NLS16 */
  2194. for (i = 0; (i < strlen(name)) && valid; i++)
  2195. {
  2196. if (strchr ("|!(){}[]<>*:\"\\", (int) name[i]))
  2197. {
  2198. valid = False;
  2199. }
  2200. }
  2201. #endif /* NLS16 */
  2202. return (valid);
  2203. }
  2204. void
  2205. InitializeAtoms( void )
  2206. {
  2207. char cust_str[24];
  2208. sprintf(cust_str,"%s%d", XmSCUSTOMIZE_DATA, style.screenNum);
  2209. XA_CUSTOMIZE = XInternAtom(style.display, cust_str, FALSE);
  2210. XA_TYPE_MONITOR = XInternAtom(style.display, TYPE_OF_MONITOR, FALSE);
  2211. XA_WM_DELETE_WINDOW = XInternAtom(style.display, "WM_DELETE_WINDOW", False);
  2212. }
  2213. void
  2214. GetDefaultPal(
  2215. Widget shell )
  2216. {
  2217. char *str_type_return;
  2218. XrmValue value_return;
  2219. XrmDatabase db;
  2220. Boolean status;
  2221. char *p;
  2222. char *string;
  2223. char instanceName[30], instanceClass[30];
  2224. /* get the current default palette from the Reource Manager Property */
  2225. db = XtDatabase(style.display);
  2226. if (TypeOfMonitor == XmCO_BLACK_WHITE)
  2227. {
  2228. sprintf(instanceName,"dtsession.%d.monochromePalette", style.screenNum);
  2229. sprintf(instanceClass,"Dtsession.%d.MonochromePalette", style.screenNum);
  2230. }
  2231. else
  2232. {
  2233. sprintf(instanceName,"dtsession.%d.colorPalette", style.screenNum);
  2234. sprintf(instanceClass,"Dtsession.%d.ColorPalette", style.screenNum);
  2235. }
  2236. if (status = XrmGetResource (db, instanceName, instanceClass,
  2237. &str_type_return, &value_return))
  2238. {
  2239. /* copy string to defaultName */
  2240. defaultName = (char *) XtMalloc( value_return.size );
  2241. strcpy (defaultName, value_return.addr);
  2242. p = strstr (defaultName, PALETTE_SUFFIX);
  2243. if (p) *p = '\0';
  2244. }
  2245. else
  2246. {
  2247. /* set defaultName to default palette */
  2248. defaultName = (char *) XtMalloc( strlen(DEFAULT_PALETTE));
  2249. strcpy (defaultName, DEFAULT_PALETTE);
  2250. }
  2251. }
  2252. void
  2253. CreateDialogBoxD(
  2254. Widget parent )
  2255. {
  2256. XmString button_string[NUM_LABELS];
  2257. Arg args[2];
  2258. int n;
  2259. Widget w;
  2260. if(style.count > 0)
  2261. return;
  2262. /* Get the default value of multiclick */
  2263. dclick_time = XtGetMultiClickTime(style.display);
  2264. gParent = parent;
  2265. if(!XtIsRealized(parent))
  2266. XtRealizeWidget(parent);
  2267. /* Set up DialogBox button labels. */
  2268. button_string[0] = CMPSTR((String) _DtOkString);
  2269. button_string[1] = CMPSTR((String) _DtCancelString);
  2270. button_string[2] = CMPSTR((String) _DtHelpString);
  2271. /* saveRestore
  2272. * Note that save.poscnt has been initialized elsewhere.
  2273. * save.posArgs may contain information from restoreColor().*/
  2274. XtSetArg (save.posArgs[save.poscnt], XmNchildType, XmWORK_AREA); save.poscnt++;
  2275. XtSetArg (save.posArgs[save.poscnt], XmNbuttonCount, NUM_LABELS); save.poscnt++;
  2276. XtSetArg (save.posArgs[save.poscnt], XmNbuttonLabelStrings, button_string); save.poscnt++;
  2277. XtSetArg (save.posArgs[save.poscnt], XmNdefaultPosition, False); save.poscnt++;
  2278. style.colorDialog = __DtCreateDialogBoxDialog(parent,PALETTEDLG, save.posArgs, save.poscnt);
  2279. XtAddCallback(style.colorDialog, XmNcallback, dialogBoxCB, NULL);
  2280. XtAddCallback(style.colorDialog, XmNmapCallback, _DtmapCB, parent);
  2281. XtAddCallback(style.colorDialog, XmNhelpCallback,
  2282. (XtCallbackProc)HelpRequestCB, (XtPointer)HELP_COLOR_DIALOG);
  2283. XmStringFree(button_string[0]);
  2284. XmStringFree(button_string[1]);
  2285. XmStringFree(button_string[2]);
  2286. w = _DtDialogBoxGetButton(style.colorDialog,2);
  2287. n=0;
  2288. XtSetArg(args[n], XmNautoUnmanage, False); n++;
  2289. XtSetArg(args[n], XmNcancelButton, w); n++;
  2290. XtSetValues (style.colorDialog, args, n);
  2291. style.count++;
  2292. }
  2293. void
  2294. AddToDialogBox( void )
  2295. {
  2296. int n;
  2297. Arg args[3];
  2298. if(style.count > 1)
  2299. return;
  2300. n = 0;
  2301. XtSetArg (args[n], XmNtitle, ((char *)GETMESSAGE(14, 30, "Style Manager - Color"))); n++;
  2302. XtSetArg (args[n], XmNuseAsyncGeometry, True); n++;
  2303. XtSetArg (args[n], XmNmwmFunctions, DIALOG_MWM_FUNC); n++;
  2304. XtSetValues (XtParent(style.colorDialog), args, n);
  2305. /* Add save session property to the main window */
  2306. XmAddWMProtocolCallback(XtParent(style.colorDialog),
  2307. XA_WM_DELETE_WINDOW, activateCBexitColor, NULL);
  2308. /*
  2309. ** Create a main form for color dialog
  2310. */
  2311. n = 0;
  2312. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  2313. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  2314. colorDialog.colorForm = XmCreateForm(style.colorDialog, "colorForm", args, n);
  2315. XtManageChild(colorDialog.colorForm);
  2316. style.count++;
  2317. }
  2318. void
  2319. CreateTopColor1( void )
  2320. {
  2321. int n;
  2322. Arg args[6];
  2323. XmString string;
  2324. if(style.count > 2)
  2325. return;
  2326. /*
  2327. ** titlebox as child of the main form
  2328. */
  2329. n = 0;
  2330. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  2331. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  2332. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2333. XtSetArg (args[n], XmNmarginWidth, 0); n++;
  2334. XtSetArg (args[n], XmNmarginHeight, 0); n++;
  2335. string = CMPSTR(((char *)GETMESSAGE(14, 5, "Palettes")));
  2336. XtSetArg (args[n], XmNtitleString, string); n++;
  2337. colorDialog.paletteTB = _DtCreateTitleBox(colorDialog.colorForm, "paletteTB", args, n);
  2338. XtManageChild(colorDialog.paletteTB);
  2339. XmStringFree(string);
  2340. /*
  2341. ** Create a form inside palette titlebox
  2342. */
  2343. n = 0;
  2344. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  2345. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  2346. colorDialog.palettesForm = XmCreateForm(colorDialog.paletteTB, "palettesForm", args, n);
  2347. XtManageChild(colorDialog.palettesForm);
  2348. style.count++;
  2349. }
  2350. void
  2351. CreateTopColor2( void )
  2352. {
  2353. int n;
  2354. Arg args[8];
  2355. if(style.count > 3)
  2356. return;
  2357. /*
  2358. ** Create a scrolled list widget. This widget will contain the list of
  2359. ** palettes currently loaded (by ReadPalettes) in the customizer.
  2360. */
  2361. n=0;
  2362. XtSetArg (args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++;
  2363. XtSetArg (args[n], XmNautomaticSelection, True); n++;
  2364. XtSetArg (args[n], XmNvisibleItemCount, 6); n++;
  2365. paletteList = XmCreateScrolledList(colorDialog.palettesForm,"paletteList",args,n);
  2366. XtAddCallback(paletteList, XmNbrowseSelectionCallback,
  2367. selectPaletteCB, NULL);
  2368. n=0;
  2369. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  2370. XtSetArg (args[n], XmNtopOffset, style.horizontalSpacing); n++;
  2371. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  2372. XtSetArg (args[n], XmNleftOffset, style.horizontalSpacing); n++;
  2373. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  2374. XtSetArg (args[n], XmNrightPosition, 60); n++;
  2375. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  2376. XtSetValues (XtParent(paletteList), args, n);
  2377. style.count++;
  2378. }
  2379. void
  2380. CreateBottomColor( void )
  2381. {
  2382. int n;
  2383. Arg args[12];
  2384. XmString string;
  2385. Widget addDeleteForm;
  2386. Widget resourcesPB;
  2387. colorDialog.dlg = NULL;
  2388. if(style.count > 10)
  2389. return;
  2390. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  2391. {
  2392. /* Create form for Add and Delete buttons */
  2393. n = 0;
  2394. XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  2395. XtSetArg(args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  2396. XtSetArg(args[n], XmNleftWidget, paletteList); n++;
  2397. XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2398. XtSetArg(args[n], XmNrightOffset, 0); n++;
  2399. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  2400. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  2401. XtSetArg(args[n], XmNallowOverlap, False); n++;
  2402. XtSetArg(args[n], XmNchildType, XmWORK_AREA); n++;
  2403. addDeleteForm =
  2404. XmCreateForm(colorDialog.palettesForm, "addDeleteForm", args, n);
  2405. XtManageChild(addDeleteForm);
  2406. /* Create Add button */
  2407. n = 0;
  2408. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  2409. XtSetArg (args[n], XmNtopOffset, ADD_PALETTE_TOP_OFFSET); n++;
  2410. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  2411. XtSetArg (args[n], XmNleftOffset, style.horizontalSpacing); n++;
  2412. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2413. string = CMPSTR(((char *)GETMESSAGE(14, 6, "Add...")));
  2414. XtSetArg (args[n], XmNlabelString, string); n++;
  2415. colorDialog.addPaletteButton =
  2416. XmCreatePushButtonGadget(addDeleteForm, "addPalette", args, n);
  2417. XmStringFree(string);
  2418. XtManageChild(colorDialog.addPaletteButton);
  2419. XtAddCallback(colorDialog.addPaletteButton, XmNactivateCallback, addPaletteCB,
  2420. (XtPointer) NULL);
  2421. /* Create Delete button */
  2422. n = 0;
  2423. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  2424. XtSetArg (args[n], XmNtopWidget, colorDialog.addPaletteButton); n++;
  2425. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  2426. XtSetArg (args[n], XmNleftOffset, style.horizontalSpacing); n++;
  2427. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2428. string = CMPSTR(((char *)GETMESSAGE(14, 7, "Delete...")));
  2429. XtSetArg (args[n], XmNlabelString, string); n++;
  2430. colorDialog.deletePaletteButton =
  2431. XmCreatePushButtonGadget(addDeleteForm,"deletePalette",args,n);
  2432. XmStringFree(string);
  2433. XtManageChild(colorDialog.deletePaletteButton);
  2434. XtAddCallback(colorDialog.deletePaletteButton, XmNactivateCallback, deletePaletteCB,
  2435. (XtPointer) NULL);
  2436. }
  2437. /*
  2438. ** Create a title box for palette color buttons
  2439. */
  2440. n=0;
  2441. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  2442. XtSetArg (args[n], XmNtopWidget, colorDialog.paletteTB); n++;
  2443. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  2444. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2445. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_NONE); n++;
  2446. XtSetArg (args[n], XmNmarginWidth, 0); n++;
  2447. XtSetArg (args[n], XmNmarginHeight, 0); n++;
  2448. string = CMPSTR(pCurrentPalette->desc);
  2449. XtSetArg (args[n], XmNtitleString, string); n++;
  2450. colorDialog.buttonsTB = _DtCreateTitleBox(colorDialog.colorForm, "ButtonsTB", args, n);
  2451. XtManageChild(colorDialog.buttonsTB);
  2452. XmStringFree(string);
  2453. /* Create a form inside palette buttons titlebox */
  2454. n = 0;
  2455. XtSetArg(args[n], XmNhorizontalSpacing, style.horizontalSpacing); n++;
  2456. XtSetArg(args[n], XmNverticalSpacing, style.verticalSpacing); n++;
  2457. style.buttonsForm = XmCreateForm(colorDialog.buttonsTB, "buttonsForm", args, n);
  2458. XtManageChild(style.buttonsForm);
  2459. /* Create Modify... button */
  2460. if(TypeOfMonitor != XmCO_BLACK_WHITE)
  2461. {
  2462. n = 0;
  2463. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  2464. XtSetArg (args[n], XmNtopOffset, style.horizontalSpacing+BORDER_WIDTH); n++;
  2465. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  2466. XtSetArg (args[n], XmNleftPosition, ADD_PALETTE_LEFT_POSITION); n++;
  2467. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2468. string = CMPSTR(((char *)GETMESSAGE(14, 8, "Modify...")));
  2469. XtSetArg (args[n], XmNlabelString, string); n++;
  2470. modifyColorButton =
  2471. XmCreatePushButtonGadget(style.buttonsForm, "modifyColorButton", args, n);
  2472. XmStringFree(string);
  2473. XtManageChild(modifyColorButton);
  2474. XtAddCallback(modifyColorButton, XmNactivateCallback, modifyColorCB,
  2475. (XtPointer) NULL);
  2476. }
  2477. /*
  2478. ** Create a pushbutton for configuring DT colors
  2479. */
  2480. n=0;
  2481. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  2482. XtSetArg (args[n], XmNtopWidget, colorDialog.buttonsTB); n++;
  2483. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  2484. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  2485. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  2486. XtSetArg (args[n], XmNnavigationType, XmTAB_GROUP); n++;
  2487. string = CMPSTR(((char *)GETMESSAGE(14, 40, "Number Of Colors...")));
  2488. XtSetArg (args[n], XmNlabelString, string); n++;
  2489. resourcesPB = XmCreatePushButtonGadget(colorDialog.colorForm, "resourcesPB", args, n);
  2490. XtManageChild(resourcesPB);
  2491. XtAddCallback(resourcesPB, XmNactivateCallback, resourcesCB,
  2492. (XtPointer) style.colorDialog);
  2493. XmStringFree(string);
  2494. style.count++;
  2495. }