ColorMain.c 96 KB

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