icon_selection_dialog.c 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: icon_selection_dialog.c /main/10 1996/10/15 13:39:13 rswiston $ */
  24. /*******************************************************************************
  25. icon_selection_dialog.c
  26. Associated Header file: icon_selection_dialog.h
  27. *******************************************************************************/
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <sys/stat.h>
  32. #include <Xm/Xm.h>
  33. #include <Xm/MwmUtil.h>
  34. #include <Xm/DialogS.h>
  35. #include <Xm/MenuShell.h>
  36. #include <Xm/List.h>
  37. #include <Xm/ScrolledW.h>
  38. #include <Xm/Label.h>
  39. #include <Xm/Text.h>
  40. #include <Xm/TextF.h>
  41. #include <Xm/SeparatoG.h>
  42. #include <Xm/PushB.h>
  43. #include <Xm/Form.h>
  44. #include <Xm/RowColumn.h>
  45. #include <Xm/MessageB.h>
  46. #include <Xm/XmPrivate.h> /* XmeFlushIconFileCache */
  47. #include <X11/cursorfont.h>
  48. #include <Dt/Icon.h>
  49. #include "dtcreate.h"
  50. #include "UxXt.h"
  51. #include "cmncbs.h"
  52. #include "cmnrtns.h"
  53. #include "cmnutils.h"
  54. #include "fileio.h"
  55. #include "ErrorDialog.h"
  56. /*******************************************************************************
  57. Includes, Defines, and Global variables from the Declarations Editor:
  58. *******************************************************************************/
  59. #include <sys/types.h> /* for directory routines */
  60. #ifdef _KERNEL
  61. #undef _KERNEL
  62. #endif
  63. #include <dirent.h> /* includes sys/dir.h */
  64. #include <Xm/ScrolledW.h>
  65. #include <Dt/Icon.h>
  66. /*#include "Container.h"*/
  67. static char *selected_icon_name = (char *)NULL;
  68. static Widget selected_icon = (Widget)NULL;
  69. static int icon_count = 0;
  70. char *main_filter;
  71. char *file_filter_global;
  72. DtIconGadget **icons_in_container = NULL;
  73. int myscandir(char *, struct dirent ***, int (), int ());
  74. int get_top_b1_position (int buttoncount);
  75. int get_top_b2_position (int buttoncount);
  76. void load_directories_list (char **dirlist);
  77. char *get_initial_filter (void);
  78. void load_filter_text_field (char *filter);
  79. char *update_filter (char *filter);
  80. void apply_filter (char *filter);
  81. char *initialize_filter (char *filter_end);
  82. struct dirent **build_dirent_list (char *filter, int *filecount);
  83. void update_container_contents (char *filter);
  84. void free_container_contents (void);
  85. int new_name_select(struct dirent *, char *);
  86. /*int name_select(struct dirent *);*/
  87. static void selectionCB_icon_scrolled_container ( Widget UxWidget,
  88. XtPointer UxClientData,
  89. XtPointer UxCallbackArg);
  90. static void calc_bottom_attachment( Widget UxWidget,
  91. XtPointer UxClientData,
  92. XtPointer UxCallbackArg);
  93. /*******************************************************************************
  94. The following header file defines the context structure.
  95. *******************************************************************************/
  96. #define CONTEXT_MACRO_ACCESS 1
  97. #include "icon_selection_dialog.h"
  98. #undef CONTEXT_MACRO_ACCESS
  99. /*******************************************************************************
  100. Auxiliary code from the Declarations Editor:
  101. *******************************************************************************/
  102. /*********************************************************************/
  103. /* auxfuncs - icon selection dialog auxiliary functions */
  104. /*********************************************************************/
  105. /***************************************************************************/
  106. /* */
  107. /* myscandir */
  108. /* */
  109. /***************************************************************************/
  110. int myscandir(char *pszDirName, struct dirent ***NameList, int Select(), int Compare())
  111. {
  112. DIR *dirptr;
  113. struct dirent *dp;
  114. struct dirent *dptmp;
  115. int count = 0;
  116. /* int size = 0; */
  117. struct dirent **adirent;
  118. #define AINCREMENT ((int)512)
  119. int sizeArray = AINCREMENT;
  120. char *msgPtr, *fmtPtr, *errPtr;
  121. if (!(dirptr = opendir(pszDirName))) {
  122. /* INTERNATIONALIZE */
  123. msgPtr = "Could not open the following directory:";
  124. fmtPtr = "%s\n %s";
  125. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  126. strlen(pszDirName) + 1) * sizeof(char));
  127. sprintf(errPtr, fmtPtr, msgPtr, pszDirName);
  128. display_error_message(CreateActionAppShell, errPtr);
  129. XtFree(errPtr);
  130. return(0);
  131. }
  132. #if 0
  133. size = sizeof(void *) * 1024;
  134. *NameList = (struct dirent **)malloc(sizeof(void *) * 1024);
  135. #endif
  136. adirent = (struct dirent **)malloc(sizeof(void *) * sizeArray);
  137. for (dp = readdir(dirptr); dp != NULL; dp = readdir(dirptr)) {
  138. #if 0
  139. if ((*Select)(dp, pszDirName)) {
  140. (*NameList)[count] = dp;
  141. if ((*Select)(dp)) {
  142. #endif
  143. if ((*Select)(dp, pszDirName)) {
  144. dptmp = (struct dirent *)malloc(sizeof(struct dirent) + strlen(dp->d_name) + 1);
  145. memcpy(dptmp, dp, sizeof(struct dirent));
  146. strcpy(dptmp->d_name, dp->d_name);
  147. adirent[count] = dptmp;
  148. count++;
  149. if (count == (sizeArray - 1)) {
  150. adirent = (struct dirent **)realloc(adirent, (sizeof(void *) * (sizeArray + AINCREMENT)));
  151. if (adirent) {
  152. sizeArray += AINCREMENT;
  153. }
  154. }
  155. }
  156. }
  157. *NameList = adirent;
  158. closedir(dirptr);
  159. return(count);
  160. }
  161. /***************************************************************************/
  162. /* */
  163. /* build_dirent_list - builds a list of icon files to be displayed */
  164. /* in a container */
  165. /* Input: char *filter - directory in which to search for files */
  166. /* Output: struct dirent **namelist - list of files */
  167. /* */
  168. /***************************************************************************/
  169. struct dirent **build_dirent_list (char *filter, int *filecount)
  170. {
  171. char *dirname, *dirname_end;
  172. DIR *dirptr;
  173. struct dirent **namelist;
  174. char *msgPtr, *fmtPtr, *errPtr;
  175. /********************************************************************/
  176. /* initialize filecount and namelist */
  177. /********************************************************************/
  178. *filecount = 0;
  179. namelist = NULL;
  180. /********************************************************************/
  181. /* get length of file filter and create a copy */
  182. /********************************************************************/
  183. dirname = (char *)calloc (strlen(filter)+1, sizeof(char));
  184. #ifdef DEBUG
  185. if (!dirname) {
  186. printf("error callocing memory for dirname\n");
  187. printf("dirname of size: %i\n", strlen(dirname));
  188. }
  189. #endif
  190. dirname = strcpy (dirname, filter);
  191. /********************************************************************/
  192. /* strip wildcard from end of directory name */
  193. /********************************************************************/
  194. dirname_end = strrchr (dirname, '/');
  195. dirname_end[1] = '\0';
  196. /********************************************************************/
  197. /* build list of file name that match the wildcard string */
  198. /********************************************************************/
  199. dirptr = (DIR *)opendir (dirname);
  200. if (dirptr) {
  201. *filecount = myscandir (dirname, &namelist, new_name_select, NULL);
  202. #ifdef DEBUG
  203. printf("# of icons = %d\n", *filecount);
  204. #endif
  205. closedir (dirptr);
  206. } else {
  207. /* INTERNATIONALIZE */
  208. msgPtr = "Could not open the following directory:";
  209. fmtPtr = "%s\n %s";
  210. errPtr = XtMalloc((strlen(msgPtr) + strlen(fmtPtr) +
  211. strlen(dirname) + 1) * sizeof(char));
  212. sprintf(errPtr, fmtPtr, msgPtr, dirname);
  213. display_error_message(CreateActionAppShell, errPtr);
  214. XtFree(errPtr);
  215. namelist = NULL;
  216. }
  217. #ifdef DEBUG
  218. printf ("Freeing dirname, sizeof: %ld\n", (long)sizeof(dirname));
  219. #endif
  220. free (dirname);
  221. return (namelist);
  222. }
  223. /***************************************************************************/
  224. /* */
  225. /* new_name_select - determines if file is included in list of icon */
  226. /* files to be displayed in a container */
  227. /* Input: struct dirent *dir_entry - directory entry structure */
  228. /* Output: (int)found - >0 if file name accepted, 0 otherwise */
  229. /* */
  230. /***************************************************************************/
  231. int new_name_select (struct dirent *dir_entry, char *pszdir_name)
  232. {
  233. struct stat stat_buffer;
  234. char filename[256];
  235. /***********************************************************************/
  236. /* This will only filter the icons of the filter size which by default */
  237. /* is medium icons. */
  238. /***********************************************************************/
  239. if (strstr(dir_entry->d_name, file_filter_global)) {
  240. sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
  241. if (!stat(filename, &stat_buffer)) {
  242. if ( (S_ISREG(stat_buffer.st_mode)) ||
  243. (S_ISLNK(stat_buffer.st_mode)) ) {
  244. return(1);
  245. }
  246. }
  247. }
  248. return(0);
  249. #if 0
  250. /***********************************************************************/
  251. /* This is the new filter to get all three sizes of icons. */
  252. /***********************************************************************/
  253. if (bShowPixmaps) {
  254. if ( (strstr(dir_entry->d_name, ".l.pm")) ||
  255. (strstr(dir_entry->d_name, ".m.pm")) ||
  256. (strstr(dir_entry->d_name, ".t.pm")) ) {
  257. sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
  258. if (!stat(filename, &stat_buffer)) {
  259. if ( (S_ISREG(stat_buffer.st_mode)) ||
  260. (S_ISLNK(stat_buffer.st_mode)) ) {
  261. return(1);
  262. }
  263. }
  264. }
  265. } else {
  266. if ( (strstr(dir_entry->d_name, ".l.bm")) ||
  267. (strstr(dir_entry->d_name, ".m.bm")) ||
  268. (strstr(dir_entry->d_name, ".t.bm")) ) {
  269. sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
  270. if (!stat(filename, &stat_buffer)) {
  271. if ( (S_ISREG(stat_buffer.st_mode)) ||
  272. (S_ISLNK(stat_buffer.st_mode)) ) {
  273. return(1);
  274. }
  275. }
  276. }
  277. }
  278. return(0);
  279. #endif
  280. }
  281. #if 0
  282. /***************************************************************************/
  283. /* */
  284. /* new_name_select - determines if file is included in list of icon */
  285. /* files to be displayed in a container */
  286. /* Input: struct dirent *dir_entry - directory entry structure */
  287. /* Output: (int)found - >0 if file name accepted, 0 otherwise */
  288. /* */
  289. /***************************************************************************/
  290. int new_name_select (struct dirent *dir_entry, char *pszdir_name)
  291. {
  292. struct stat stat_buffer;
  293. char filename[256];
  294. if (strstr(dir_entry->d_name, file_filter_global)) {
  295. sprintf(filename, "%s%s", pszdir_name, dir_entry->d_name);
  296. if (!stat(filename, &stat_buffer)) {
  297. if ( (S_ISREG(stat_buffer.st_mode)) ||
  298. (S_ISLNK(stat_buffer.st_mode)) ) {
  299. return(1);
  300. }
  301. }
  302. }
  303. return(0);
  304. }
  305. #endif
  306. /***************************************************************************/
  307. /* */
  308. /* int get_top_b1_position - determine position of button */
  309. /* INPUT: int buttoncount - number of buttons in row */
  310. /* OUTPUT: int position - position of left edge of button */
  311. /* */
  312. /***************************************************************************/
  313. int get_top_b1_position (int buttoncount)
  314. {
  315. int position;
  316. switch (buttoncount) {
  317. case 1: position = 38; break;
  318. case 2: position = 14; break;
  319. case 3: position = 8; break;
  320. default : position = 0;
  321. };
  322. return (position);
  323. }
  324. /***************************************************************************/
  325. /* */
  326. /* int get_top_b2_position - determine position of button */
  327. /* INPUT: int buttoncount - number of buttons in row */
  328. /* OUTPUT: int position - position of left edge of button */
  329. /* */
  330. /***************************************************************************/
  331. int get_top_b2_position (int buttoncount)
  332. {
  333. int position;
  334. switch (buttoncount) {
  335. case 2: position = 60; break;
  336. case 3: position = 40; break;
  337. default : position = 0;
  338. };
  339. return (position);
  340. }
  341. /***************************************************************************/
  342. /* */
  343. /* void load_directories_list - load scrolled list with directory */
  344. /* names */
  345. /* Input: char **dirlist - list of text strings */
  346. /* Output: none */
  347. /* */
  348. /***************************************************************************/
  349. void load_directories_list (char **dirlist)
  350. {
  351. XmStringTable xmstringlist;
  352. int stringcount = 0;
  353. int i;
  354. /******************************************************************/
  355. /* get number of directories in list */
  356. /******************************************************************/
  357. stringcount = countItems (dirlist);
  358. /******************************************************************/
  359. /* convert strings to xmstrings */
  360. /******************************************************************/
  361. xmstringlist = (XmStringTable) TextStringsToXmStrings (dirlist);
  362. /******************************************************************/
  363. /* put xmstrings in list */
  364. /******************************************************************/
  365. XtVaSetValues (dir_scrolled_list, XmNitems, xmstringlist,
  366. XmNitemCount, stringcount, NULL);
  367. XmListSelectPos(dir_scrolled_list, 1, False);
  368. /******************************************************************/
  369. /* free xmstrings array */
  370. /******************************************************************/
  371. for (i=0; i < stringcount; i++) {
  372. XmStringFree(xmstringlist[i]);
  373. }
  374. free(xmstringlist);
  375. return;
  376. }
  377. /***************************************************************************/
  378. /* */
  379. /* void initialize_filter - build path/wildcard filter */
  380. /* Input: none */
  381. /* Output: char *initial_filter */
  382. /* */
  383. /***************************************************************************/
  384. char *initialize_filter (char *filter_end)
  385. {
  386. char *filter, *initial_filter;
  387. int filter_length, filter_end_length;
  388. int add_slash = 0;
  389. /******************************************************************/
  390. /* initial filter string is first directory in list */
  391. /******************************************************************/
  392. filter = get_initial_filter ();
  393. /******************************************************************/
  394. /* determine space needed */
  395. /******************************************************************/
  396. filter_length = strlen(filter);
  397. if ((filter[filter_length-1] == '/') && (filter_end[0] == '/')) {
  398. filter_end++;
  399. } else {
  400. if (!(filter[filter_length-1] == '/') && !(filter_end[0] == '/')) {
  401. add_slash = 1;
  402. filter_length++;
  403. }
  404. }
  405. filter_end_length = strlen(filter_end);
  406. /******************************************************************/
  407. /* allocate space and put string in initial filter */
  408. /******************************************************************/
  409. initial_filter = (char *)calloc (filter_length + filter_end_length + 1,
  410. sizeof(char));
  411. #ifdef DEBUG
  412. if (!initial_filter) printf("Error callocing memory in initialize_filter.\n");
  413. #endif
  414. initial_filter = strcpy (initial_filter, filter);
  415. if (add_slash) initial_filter[filter_length-1] = '/';
  416. initial_filter = strcat (initial_filter, filter_end);
  417. return(initial_filter);
  418. }
  419. /***************************************************************************/
  420. /* */
  421. /* char *get_initial_filter - get value of first file filter */
  422. /* Input: none */
  423. /* Output: char *new_filter - string containing filter */
  424. /* */
  425. /***************************************************************************/
  426. char *get_initial_filter (void)
  427. {
  428. char *new_filter;
  429. /******************************************************************/
  430. /* initial filter is first one in directory list */
  431. /******************************************************************/
  432. new_filter = (char *)directories_list[0];
  433. return (new_filter);
  434. }
  435. /***************************************************************************/
  436. /* */
  437. /* char *update_filter - put main filter end on new main filter */
  438. /* Input: char *filter - new filter from which gets main filter end */
  439. /* Output: char *new_filter - new main filter */
  440. /* */
  441. /***************************************************************************/
  442. char *update_filter (char *filter)
  443. {
  444. char *filter_end, *new_filter, *main_end;
  445. char *fe_ptr, *ffg_ptr;
  446. /******************************************************************/
  447. /* get new end */
  448. /******************************************************************/
  449. main_end = strrchr (main_filter, '/');
  450. filter_end = (char *)calloc(strlen(main_end)+1, sizeof(char));
  451. #ifdef DEBUG
  452. if (!filter_end)
  453. printf("Error callocing memory for filter_end in update_filter.\n");
  454. #endif
  455. filter_end = strcpy (filter_end, main_end);
  456. /******************************************************************/
  457. /* determine what filter should be depending on icon type (pm/bm) */
  458. /******************************************************************/
  459. if (fe_ptr = strrchr(filter_end, EXT_DELIMITER)) {
  460. ffg_ptr = strrchr(file_filter_global, EXT_DELIMITER);
  461. if (bShowPixmaps) {
  462. if ((int)strlen(fe_ptr) >= (int)strlen(PIXMAP_EXT)) {
  463. strcpy(fe_ptr, PIXMAP_EXT);
  464. }
  465. if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(PIXMAP_EXT)) ) {
  466. strcpy(ffg_ptr, PIXMAP_EXT);
  467. }
  468. } else {
  469. if ((int)strlen(fe_ptr) >= (int)strlen(BITMAP_EXT)) {
  470. strcpy(fe_ptr, BITMAP_EXT);
  471. }
  472. if ( (ffg_ptr) && ((int)strlen(ffg_ptr) >= (int)strlen(BITMAP_EXT)) ) {
  473. strcpy(ffg_ptr, BITMAP_EXT);
  474. }
  475. }
  476. }
  477. /******************************************************************/
  478. /* find old end on main filter and delete it */
  479. /******************************************************************/
  480. main_end = memset (main_end, '\0', strlen(main_end));
  481. /******************************************************************/
  482. /* allocate space for new filter */
  483. /******************************************************************/
  484. new_filter = (char *)calloc (strlen(filter) +
  485. strlen(filter_end) + 1, sizeof(char));
  486. #ifdef DEBUG
  487. if (!new_filter)
  488. printf("Error callocing memory for new_filter in update_filter.\n");
  489. #endif
  490. new_filter = strcpy (new_filter, filter);
  491. /******************************************************************/
  492. /* put new end on filter */
  493. /******************************************************************/
  494. new_filter = strcat (new_filter, filter_end);
  495. /******************************************************************/
  496. /* display new file filter in text field */
  497. /******************************************************************/
  498. load_filter_text_field (new_filter);
  499. /******************************************************************/
  500. /* free resources */
  501. /******************************************************************/
  502. free(filter_end);
  503. return (new_filter);
  504. }
  505. /***************************************************************************/
  506. /* */
  507. /* void apply_filter - apply filter to create a list of files and */
  508. /* display files in scrolled list */
  509. /* Input: char *filter - file filter to use */
  510. /* Output: none */
  511. /* */
  512. /***************************************************************************/
  513. void apply_filter (char *filter)
  514. {
  515. char *old_main;
  516. /******************************************************************/
  517. /* Get length of main file filter and create a copy */
  518. /******************************************************************/
  519. old_main = (char *)calloc (strlen(main_filter)+1, sizeof(char));
  520. #ifdef DEBUG
  521. if (!old_main) printf("Calloc error for old_main, in apply filter.\n");
  522. #endif
  523. old_main = strcpy (old_main, main_filter);
  524. /******************************************************************/
  525. /* Update main filter to reflect changes made by user */
  526. /******************************************************************/
  527. main_filter = update_filter (filter);
  528. /******************************************************************/
  529. /* if the filter has changed, update container with new icons */
  530. /******************************************************************/
  531. if (strcmp (old_main, main_filter)) {
  532. /******************************************************************/
  533. /* Turn on the hour glass */
  534. /******************************************************************/
  535. TurnOnHourGlassAllWindows();
  536. /******************************************************************/
  537. /* Since we are changing to a new directory, clear out the */
  538. /* globals and clear the selected icon text string. */
  539. /******************************************************************/
  540. if (selected_icon) {
  541. _DtIconSetState(selected_icon, FALSE, FALSE);
  542. selected_icon = (Widget)NULL;
  543. }
  544. if (selected_icon_name) {
  545. XtFree(selected_icon_name);
  546. selected_icon_name = (char *)NULL;
  547. }
  548. XmTextFieldSetString (icon_name_text_field, "");
  549. /******************************************************************/
  550. /* Update the container icon gadgets */
  551. /******************************************************************/
  552. update_container_contents (main_filter);
  553. /******************************************************************/
  554. /* Turn off the hour glass */
  555. /******************************************************************/
  556. TurnOffHourGlassAllWindows();
  557. }
  558. #ifdef DEBUG
  559. printf ("Freeing old_main, sizeof: %ld\n", (long)sizeof(old_main));
  560. #endif
  561. free (old_main);
  562. return;
  563. }
  564. /***************************************************************************/
  565. /* */
  566. /* void load_filter_text_field - display file filter text */
  567. /* Input: char *filter - file filter text string */
  568. /* Output: none */
  569. /* */
  570. /***************************************************************************/
  571. void load_filter_text_field (char *filter)
  572. {
  573. if (use_filter_field) {
  574. /* display file filter in text field */
  575. XmTextFieldSetString (filter_text_field, filter);
  576. /* set cursor to end of string */
  577. XmTextSetInsertionPosition (filter_text_field, strlen(filter));
  578. }
  579. return;
  580. }
  581. /***************************************************************************/
  582. /* */
  583. /* void update_container_contents - create new icon gadgets which */
  584. /* correspont to the new filter */
  585. /* Input: char *filter - file filter text string */
  586. /* Output: none */
  587. /* */
  588. /***************************************************************************/
  589. void update_container_contents (char *filter)
  590. {
  591. char *path, *pathend;
  592. char iconfile[MAXFILENAME];
  593. int namecount, lcv;
  594. struct dirent **filelist;
  595. int count, old_count;
  596. int n;
  597. Arg args[10];
  598. XmString xmstring;
  599. char *ptr;
  600. XtUnmanageChild (icon_scrolled_container);
  601. /* free_container_contents (); */
  602. path = (char *)calloc (strlen(filter)+1, sizeof(char));
  603. #ifdef DEBUG
  604. if (!path) printf("Calloc error for path, in update_container_contents.\n");
  605. #endif
  606. path = strcpy (path, filter);
  607. pathend = strrchr (path, '/');
  608. pathend[1] = '\0';
  609. /******************************************************************/
  610. /* Get number of icon files and list of file names */
  611. /******************************************************************/
  612. filelist = build_dirent_list (filter, &namecount);
  613. /******************************************************************/
  614. /* Set up argument list */
  615. /******************************************************************/
  616. n = 0;
  617. /*
  618. XtSetArg(args[n], XmNimageName, "/usr/dt/appconfig/icons/C/Dtactn.m.pm"); n++;
  619. */
  620. XtSetArg(args[n], XmNimageName, NULL); n++;
  621. XtSetArg(args[n], XmNfillMode, XmFILL_SELF); n++;
  622. XtSetArg(args[n], XmNbehavior, XmICON_TOGGLE); n++;
  623. XtSetArg(args[n], XmNrecomputeSize, TRUE); n++;
  624. XtSetArg(args[n], XmNfillOnArm, TRUE); n++;
  625. XtSetArg(args[n], XmNtraversalOn, TRUE); n++;
  626. /******************************************************************/
  627. /* Need at least one icon for the empty directory icon. */
  628. /******************************************************************/
  629. if (namecount) {
  630. count = namecount;
  631. } else {
  632. count = 1;
  633. }
  634. /******************************************************************/
  635. /* create any additional icon gadgets */
  636. /******************************************************************/
  637. if (count > icon_count) {
  638. old_count = icon_count;
  639. icon_count = count;
  640. icons_in_container = (DtIconGadget **)realloc
  641. (icons_in_container,
  642. (icon_count+1) * sizeof(DtIconGadget *));
  643. /*memset(&(icons_in_container[icon_count]), 0, sizeof(DtIconGadget *));*/
  644. for (lcv = old_count; lcv < icon_count; lcv++) {
  645. icons_in_container[lcv] =
  646. /*(DtIconGadget *)XtCreateManagedWidget (filelist[lcv]->d_name,*/
  647. (DtIconGadget *)XtCreateManagedWidget ("IconGadget",
  648. dtIconGadgetClass, (Widget)icon_scrolled_container,
  649. args, n);
  650. XtAddCallback((Widget) icons_in_container[lcv], XmNcallback,
  651. (XtCallbackProc) selectionCB_icon_scrolled_container,
  652. (XtPointer) NULL);
  653. #ifdef DEBUG
  654. if (!icons_in_container[lcv])
  655. printf("Error creating icon gadget, in update_container_contents\n");
  656. #endif
  657. #if 0
  658. if (!icons_in_container[lcv]) {
  659. printf ("Could not allocate memory to create new icon\n", lcv);
  660. }
  661. #endif
  662. #ifdef DEBUG
  663. } else {
  664. printf ("Created icon #%i\n", lcv);
  665. }
  666. #endif
  667. } /* end for */
  668. } /* end if (count > icon_count) */
  669. /******************************************************************/
  670. /* load icon gadgets with information */
  671. /******************************************************************/
  672. if (namecount) {
  673. /****************************************************************/
  674. /* The following flush call is a work-around for a known motif */
  675. /* bug. This is here in the application because motif will not */
  676. /* correct this bug because doing so would impair performance. */
  677. /* Therefore, I am forced to add this call to the code. */
  678. /* The problem this fixes is that when new icons are added to */
  679. /* the filesystem after the application is already up and */
  680. /* running, the icon gadgets to not see them. */
  681. /****************************************************************/
  682. XmeFlushIconFileCache(NULL);
  683. for (lcv = 0; lcv < count; lcv++) {
  684. snprintf(iconfile, sizeof(iconfile), "%s%s", path, filelist[lcv]->d_name);
  685. ptr = strstr(filelist[lcv]->d_name, ".m.");
  686. if (ptr) {
  687. *ptr = '\0';
  688. }
  689. xmstring = XmStringCreateLocalized(filelist[lcv]->d_name);
  690. XtVaSetValues ((Widget) icons_in_container[lcv],
  691. XmNstring, xmstring,
  692. XmNimageName, iconfile,
  693. NULL);
  694. XtManageChild((Widget) icons_in_container [lcv]);
  695. XmStringFree(xmstring);
  696. #ifdef DEBUG
  697. printf ("Loading icon gadget #%i\n", lcv);
  698. #endif
  699. } /* end for */
  700. /******************************************************************/
  701. /* This is the empty directory case */
  702. /******************************************************************/
  703. } else {
  704. snprintf(iconfile, sizeof(iconfile), "%s", GETMESSAGE(11, 60, "[Empty]"));
  705. xmstring = XmStringCreateLocalized(iconfile);
  706. XtVaSetValues ((Widget) icons_in_container[0],
  707. XmNstring, xmstring,
  708. XmNimageName, (char *)NULL,
  709. NULL);
  710. XtManageChild((Widget) icons_in_container[0]);
  711. XmStringFree(xmstring);
  712. }
  713. /******************************************************************/
  714. /* unmanage any spare icon gadgets */
  715. /******************************************************************/
  716. for (lcv = count; lcv < icon_count; lcv++) {
  717. XtUnmanageChild ((Widget) icons_in_container[lcv]);
  718. }
  719. /******************************************************************/
  720. /* free dirent list */
  721. /******************************************************************/
  722. for (lcv = 0; lcv < namecount; lcv++) {
  723. free (filelist[lcv]);
  724. }
  725. if (namecount) {
  726. free (filelist);
  727. }
  728. XtManageChild (icon_scrolled_container);
  729. free(path);
  730. return;
  731. }
  732. #ifdef _ICONSELECTOR_DESTROY_ENABLED
  733. /***************************************************************************/
  734. /* */
  735. /* void free_container_contents - free icon gadgets in container */
  736. /* Input: none */
  737. /* Output: none */
  738. /* */
  739. /***************************************************************************/
  740. void free_container_contents (void)
  741. {
  742. int lcv = 0;
  743. char *filename;
  744. Pixmap icon_pixmap;
  745. Screen *screen_id;
  746. if (icons_in_container) {
  747. screen_id = XtScreen (icons_in_container[0]);
  748. lcv = 0;
  749. while (icons_in_container[lcv]) {
  750. #if 0
  751. XtVaGetValues (icons_in_container[lcv], XmNimageName, &filename,
  752. XmNpixmap, &icon_pixmap, NULL);
  753. XmDestroyPixmap (screen_id, icon_pixmap);
  754. XtVaSetValues (icons_in_container[lcv], XmNpixmap, NULL, NULL);
  755. #endif
  756. XtDestroyWidget (icons_in_container[lcv]);
  757. /*
  758. icons_in_container[lcv]=NULL;
  759. */
  760. lcv++;
  761. } /* end while icons_in_container */
  762. free (icons_in_container);
  763. icons_in_container = NULL;
  764. }
  765. #ifdef DEBUG
  766. printf ("In free_container_contents...\n");
  767. printf ("Just destroyed all %i icons.\n", lcv);
  768. #endif
  769. icon_count = 0;
  770. return;
  771. }
  772. #endif
  773. #if 0
  774. /***************************************************************************/
  775. /* */
  776. /* void load_new_filter - displays selected directory string as */
  777. /* new filter base */
  778. /* Input: char *new_filter - new directory string to use as filter */
  779. /* Output: none */
  780. /* */
  781. /***************************************************************************/
  782. void load_new_filter (char *new_filter)
  783. {
  784. /* no longer need old filter */
  785. free (main_filter);
  786. /* create space for new filter */
  787. main_filter = (char *)calloc (strlen(new_filter)+3, sizeof (char));
  788. #ifdef DEBUG
  789. if (!main_filter) printf("Calloc error for main_filter, in load_new_filter.\n");
  790. #endif
  791. /* copy new filter and add filter end */
  792. main_filter = strcpy (main_filter, new_filter);
  793. main_filter = strcat (main_filter, "/*");
  794. /* display new filter */
  795. load_filter_text_field (main_filter);
  796. return;
  797. }
  798. #endif
  799. /*****************************************************************************/
  800. /* The following are callback functions. */
  801. /*****************************************************************************/
  802. /***************************************************************************/
  803. /* */
  804. /* calc_bottom_attachment */
  805. /* */
  806. /* */
  807. /***************************************************************************/
  808. static void calc_bottom_attachment( Widget UxWidget,
  809. XtPointer UxClientData,
  810. XtPointer UxCallbackArg )
  811. {
  812. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  813. UxSaveCtx = UxIcon_selection_dialogContext;
  814. UxIcon_selection_dialogContext = UxContext =
  815. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  816. {
  817. if (numberOfTopButtons > 0) {
  818. XtVaSetValues (UxWidget, XmNbottomWidget, top_button_form, NULL);
  819. } else if (use_icon_name_field) {
  820. XtVaSetValues (UxWidget, XmNbottomWidget, icon_name_textfield_label, NULL);
  821. } else XtVaSetValues (UxWidget, XmNbottomWidget, separatorGadget1, NULL);
  822. }
  823. return;
  824. }
  825. /***************************************************************************/
  826. /* */
  827. /* activateCB_bottom_button */
  828. /* */
  829. /* */
  830. /***************************************************************************/
  831. /* default cb for bottom buttons */
  832. static void activateCB_bottom_button( Widget UxWidget,
  833. XtPointer UxClientData,
  834. XtPointer UxCallbackArg )
  835. {
  836. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  837. UxSaveCtx = UxIcon_selection_dialogContext;
  838. UxIcon_selection_dialogContext = UxContext =
  839. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  840. {
  841. }
  842. return;
  843. }
  844. /******************************************************************************/
  845. /* activateCB_NoFindIconDialog_ChangeNameButton */
  846. /******************************************************************************/
  847. void activateCB_NoFindIconDialog_ChangeNameButton( Widget UxWidget,
  848. XtPointer UxClientData,
  849. XtPointer UxCallbackArg)
  850. {
  851. XtDestroyWidget(UxWidget);
  852. }
  853. /******************************************************************************/
  854. /* activateCB_NoFindIconDialog_NameOKButton */
  855. /******************************************************************************/
  856. void activateCB_NoFindIconDialog_NameOKButton( Widget UxWidget,
  857. XtPointer UxClientData,
  858. XtPointer UxCallbackArg)
  859. {
  860. char *basename = (char *)NULL;
  861. TurnOnHourGlassAllWindows();
  862. if (bottom_button_one_cb) {
  863. GetWidgetTextString(icon_name_text_field, &basename);
  864. bottom_button_one_cb(UxWidget,
  865. (XtPointer)basename, UxCallbackArg);
  866. if (basename) XtFree(basename);
  867. }
  868. TurnOffHourGlassAllWindows();
  869. UxPopdownInterface (IconSelector);
  870. XtDestroyWidget(UxWidget);
  871. }
  872. /******************************************************************************/
  873. /* display_nofindicon_message - display cant find icons error dialog */
  874. /* INPUT: Widget parent - parent to position error dialog new */
  875. /* OUTPIT: none */
  876. /******************************************************************************/
  877. void display_nofindicon_message (Widget parent)
  878. {
  879. Widget dialog;
  880. Widget widChild;
  881. char buffer[512];
  882. dialog = XmCreateErrorDialog(parent, "nofindiconDialog", NULL, 0);
  883. widChild = XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON);
  884. XtVaSetValues(widChild,
  885. RES_CONVERT( XmNlabelString, "Change Name"),
  886. NULL);
  887. widChild = XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON);
  888. XtVaSetValues(widChild,
  889. RES_CONVERT( XmNlabelString, "Name OK"),
  890. NULL);
  891. XtUnmanageChild (XmMessageBoxGetChild (dialog, XmDIALOG_HELP_BUTTON));
  892. XtAddCallback( dialog, XmNokCallback,
  893. (XtCallbackProc) activateCB_NoFindIconDialog_ChangeNameButton,
  894. (XtPointer) NULL );
  895. XtAddCallback( dialog, XmNcancelCallback,
  896. (XtCallbackProc) activateCB_NoFindIconDialog_NameOKButton,
  897. (XtPointer) NULL );
  898. /********* WARNING - this needs to be translated !!! ***********/
  899. strcpy(buffer, "There is no set of icons with that filename in the icon folders.\n");
  900. strcat(buffer, "Move the icons into one of the icon folders, then select \"Name OK\".\n");
  901. strcat(buffer, "Or, to select a different set of icons, select \"Change Name\".\n");
  902. strcat(buffer, "\nIf you are a software developer creating a registration package,\n");
  903. strcat(buffer, "ignore this message and select \"Name OK\".");
  904. XtVaSetValues (dialog,
  905. RES_CONVERT(XmNdialogTitle, GETMESSAGE(6, 31, "Create Action - Error")),
  906. RES_CONVERT(XmNmessageString, buffer),
  907. NULL);
  908. XtManageChild (dialog);
  909. return;
  910. }
  911. /***************************************************************************/
  912. /* */
  913. /* activateCB_bottom_button1 */
  914. /* */
  915. /* */
  916. /***************************************************************************/
  917. /* cb for bottom button 1 = OK */
  918. static void activateCB_bottom_button1( Widget UxWidget,
  919. XtPointer UxClientData,
  920. XtPointer UxCallbackArg )
  921. {
  922. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  923. UxSaveCtx = UxIcon_selection_dialogContext;
  924. UxIcon_selection_dialogContext = UxContext =
  925. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  926. {
  927. char *basename = (char *)NULL;
  928. char *fullname = (char *)NULL;
  929. char *msgPtr, *errPtr;
  930. GetWidgetTextString(icon_name_text_field, &basename);
  931. if (basename) {
  932. if (strchr(basename, '/')) {
  933. /**** WARNING - this needs to be in a message catalog in the future ****/
  934. /* INTERNATIONALIZE */
  935. msgPtr = "Invalid Icon filename.\n\
  936. Pathnames are not valid in the \"Enter Icon Filename\" field.\n\
  937. Enter only the name of the icon without the path or extensions.";
  938. errPtr = XtNewString(msgPtr);
  939. display_error_message(IconSelector, errPtr);
  940. XtFree(errPtr);
  941. } else {
  942. FIND_ICONGADGET_ICON(basename, fullname, DtMEDIUM);
  943. if ( (fullname) && (check_file_exists(fullname)) ) {
  944. TurnOnHourGlassAllWindows();
  945. if (bottom_button_one_cb) {
  946. bottom_button_one_cb(UxWidget,
  947. (XtPointer)fullname, UxCallbackArg);
  948. }
  949. TurnOffHourGlassAllWindows();
  950. UxPopdownInterface (IconSelector);
  951. if (basename) XtFree(basename);
  952. } else {
  953. display_nofindicon_message(IconSelector);
  954. }
  955. }
  956. } else {
  957. msgPtr = GETMESSAGE(11, 50, "The Icon Filename is invalid.\n\
  958. Please enter a valid icon file name in the\n'Enter Icon Filename' field.");
  959. errPtr = XtNewString(msgPtr);
  960. display_error_message(IconSelector, errPtr);
  961. XtFree(errPtr);
  962. }
  963. }
  964. return;
  965. #if 0 /************* old code *********************/
  966. char *pszIconFileName = (char *)NULL;
  967. char buffer[MAXBUFSIZE];
  968. GetWidgetTextString(icon_name_text_field, &pszIconFileName);
  969. if ( (pszIconFileName) && (check_file_exists(pszIconFileName)) ) {
  970. TurnOnHourGlassAllWindows();
  971. if (bottom_button_one_cb) {
  972. bottom_button_one_cb(UxWidget,
  973. (XtPointer)pszIconFileName, UxCallbackArg);
  974. }
  975. #ifdef _ICONSELECTOR_DESTROY_ENABLED
  976. free_container_contents ();
  977. if (selected_icon_name) {
  978. XtFree(selected_icon_name);
  979. }
  980. selected_icon_name = (char *)NULL;
  981. XtDestroyWidget (XtParent(icon_selection_dialog));
  982. IconSelector = (Widget)NULL;
  983. TurnOffHourGlassAllWindows();
  984. #else
  985. TurnOffHourGlassAllWindows();
  986. UxPopdownInterface (IconSelector);
  987. #endif /* _ICONSELECTOR_DESTROY_ENABLED */
  988. XtFree(pszIconFileName);
  989. } else {
  990. strcpy(buffer, GETMESSAGE(11, 50, "The Icon Filename is invalid.\nPlease enter a valid icon file name in the\n'Enter Icon Filename' field."));
  991. display_error_message(IconSelector, buffer);
  992. }
  993. }
  994. #if 0
  995. if (selected_icon_name) {
  996. TurnOnHourGlassAllWindows();
  997. if (bottom_button_one_cb) {
  998. bottom_button_one_cb(UxWidget,
  999. (XtPointer)selected_icon_name, UxCallbackArg);
  1000. }
  1001. #ifdef _ICONSELECTOR_DESTROY_ENABLED
  1002. free_container_contents ();
  1003. XtFree(selected_icon_name);
  1004. selected_icon_name = (char *)NULL;
  1005. XtDestroyWidget (XtParent(icon_selection_dialog));
  1006. IconSelector = (Widget)NULL;
  1007. TurnOffHourGlassAllWindows();
  1008. #else
  1009. TurnOffHourGlassAllWindows();
  1010. UxPopdownInterface (IconSelector);
  1011. #endif /* _ICONSELECTOR_DESTROY_ENABLED */
  1012. }
  1013. }
  1014. #endif
  1015. return;
  1016. #endif /************* old code *********************/
  1017. }
  1018. /***************************************************************************/
  1019. /* */
  1020. /* activateCB_bottom_button2 */
  1021. /* */
  1022. /* */
  1023. /***************************************************************************/
  1024. /* cb for bottom button 2 = CANCEL */
  1025. static void activateCB_bottom_button2( Widget UxWidget,
  1026. XtPointer UxClientData,
  1027. XtPointer UxCallbackArg )
  1028. {
  1029. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  1030. UxSaveCtx = UxIcon_selection_dialogContext;
  1031. UxIcon_selection_dialogContext = UxContext =
  1032. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  1033. {
  1034. #ifdef _ICONSELECTOR_DESTROY_ENABLED
  1035. free_container_contents ();
  1036. XtDestroyWidget (XtParent(icon_selection_dialog));
  1037. IconSelector = (Widget)NULL;
  1038. #else
  1039. UxPopdownInterface (IconSelector);
  1040. #endif /* _ICONSELECTOR_DESTROY_ENABLED */
  1041. }
  1042. return;
  1043. }
  1044. /***************************************************************************/
  1045. /* */
  1046. /* activateCB_bottom_button3 */
  1047. /* */
  1048. /* */
  1049. /***************************************************************************/
  1050. /* default cb for bottom button3 = HELP */
  1051. static void activateCB_bottom_button3( Widget UxWidget,
  1052. XtPointer UxClientData,
  1053. XtPointer UxCallbackArg )
  1054. {
  1055. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  1056. UxSaveCtx = UxIcon_selection_dialogContext;
  1057. UxIcon_selection_dialogContext = UxContext =
  1058. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  1059. {
  1060. DisplayHelpDialog(UxWidget, (XtPointer)HELP_ICONSELECTOR, UxCallbackArg);
  1061. }
  1062. return;
  1063. }
  1064. /***************************************************************************/
  1065. /* */
  1066. /* activateCB_filter_text_field */
  1067. /* */
  1068. /* */
  1069. /***************************************************************************/
  1070. static void activateCB_filter_text_field( Widget UxWidget,
  1071. XtPointer UxClientData,
  1072. XtPointer UxCallbackArg )
  1073. {
  1074. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  1075. UxSaveCtx = UxIcon_selection_dialogContext;
  1076. UxIcon_selection_dialogContext = UxContext =
  1077. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  1078. {
  1079. char *filter;
  1080. filter = XmTextFieldGetString (UxWidget);
  1081. apply_filter (filter);
  1082. }
  1083. UxIcon_selection_dialogContext = UxSaveCtx;
  1084. }
  1085. /***************************************************************************/
  1086. /* */
  1087. /* defaultActionCB_dir_scrolled_list */
  1088. /* */
  1089. /* */
  1090. /***************************************************************************/
  1091. static void defaultActionCB_dir_scrolled_list( Widget UxWidget,
  1092. XtPointer UxClientData,
  1093. XtPointer UxCallbackArg )
  1094. {
  1095. _UxCicon_selection_dialog *UxSaveCtx, *UxContext;
  1096. UxSaveCtx = UxIcon_selection_dialogContext;
  1097. UxIcon_selection_dialogContext = UxContext =
  1098. (_UxCicon_selection_dialog *) UxGetContext( UxWidget );
  1099. {
  1100. XmListCallbackStruct *listcb;
  1101. char *filter;
  1102. listcb = (XmListCallbackStruct *) UxCallbackArg;
  1103. filter = (char *)XmStringToText (listcb->item);
  1104. apply_filter (filter);
  1105. /* XtManageChild (icon_scrolled_win); */
  1106. free(filter);
  1107. }
  1108. UxIcon_selection_dialogContext = UxSaveCtx;
  1109. }
  1110. /***************************************************************************/
  1111. /* */
  1112. /* selectionCB_icon_scrolled_container */
  1113. /* */
  1114. /***************************************************************************/
  1115. static void selectionCB_icon_scrolled_container ( Widget UxWidget,
  1116. XtPointer UxClientData,
  1117. XtPointer UxCallbackArg )
  1118. {
  1119. char *filename;
  1120. XmString xmbasename;
  1121. char *basename;
  1122. XtVaGetValues (UxWidget, XmNimageName, &filename, NULL);
  1123. #ifdef DEBUG
  1124. printf("In icon callback for '%s'\n", filename);
  1125. #endif
  1126. if (use_icon_name_field) {
  1127. XtVaGetValues (UxWidget, XmNstring, &xmbasename, NULL);
  1128. basename = XmStringToText(xmbasename);
  1129. XmTextFieldSetString (icon_name_text_field, basename);
  1130. if (basename) free(basename);
  1131. }
  1132. if (selected_icon_name) {
  1133. if (selected_icon != UxWidget) {
  1134. _DtIconSetState(selected_icon, FALSE, FALSE);
  1135. }
  1136. XtFree(selected_icon_name);
  1137. selected_icon_name = (char *)NULL;
  1138. }
  1139. if (filename) {
  1140. selected_icon_name = XtMalloc(strlen(filename) + 1);
  1141. selected_icon_name = strcpy(selected_icon_name, filename);
  1142. } else {
  1143. selected_icon_name = (char *)NULL;
  1144. }
  1145. selected_icon = UxWidget;
  1146. return;
  1147. }
  1148. /***************************************************************************/
  1149. /* */
  1150. /* resizeCB_clipWindow */
  1151. /* */
  1152. /***************************************************************************/
  1153. void resizeCB_clipWindow( Widget UxWidget,
  1154. XtPointer UxClientData,
  1155. XtPointer UxCallbackArg )
  1156. {
  1157. Widget widvScrollbar;
  1158. Widget widRowColumn;
  1159. int increment;
  1160. XtArgVal /* Dimension */ height;
  1161. XtVaGetValues(XtParent(UxWidget), XmNverticalScrollBar, &widvScrollbar, NULL);
  1162. widRowColumn = (Widget)UxClientData;
  1163. XtVaGetValues(widRowColumn, XmNheight, &height, NULL);
  1164. #ifdef DEBUG
  1165. printf("height = %d\n", height);
  1166. printf("icon_count = %d\n", icon_count);
  1167. #endif
  1168. increment = (int)height / icon_count;
  1169. XtVaSetValues(widvScrollbar, XmNincrement, increment, NULL);
  1170. return;
  1171. }
  1172. /***************************************************************************/
  1173. /* */
  1174. /* _Uxbuild_icon_selection_dialog */
  1175. /* */
  1176. /* */
  1177. /***************************************************************************/
  1178. static Widget _Uxbuild_icon_selection_dialog(void)
  1179. {
  1180. Widget _UxParent;
  1181. char *UxTmp0;
  1182. int nbutton = 0;
  1183. int ntotalbuttons = numberOfBottomButtons;
  1184. #define TIGHTNESS 20
  1185. Arg args[20];
  1186. int i=0;
  1187. Widget widclipWindow;
  1188. /* Creation of icon_selection_dialog */
  1189. _UxParent = UxParent;
  1190. if ( _UxParent == NULL )
  1191. {
  1192. _UxParent = UxTopLevel;
  1193. }
  1194. _UxParent = XtVaCreatePopupShell( "icon_selection_dialog_shell",
  1195. xmDialogShellWidgetClass, _UxParent,
  1196. XmNx, 18,
  1197. XmNy, 116,
  1198. XmNwidth, 610,
  1199. XmNheight, 534,
  1200. XmNshellUnitType, XmPIXELS,
  1201. XmNkeyboardFocusPolicy, XmEXPLICIT,
  1202. XmNtitle, "icon_selection_dialog",
  1203. NULL );
  1204. UxTmp0 = dialog_title ? (char *)dialog_title : "Icon Selection Window";
  1205. icon_selection_dialog = XtVaCreateWidget( "icon_selection_dialog",
  1206. xmFormWidgetClass,
  1207. _UxParent,
  1208. XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL,
  1209. XmNwidth, 550,
  1210. XmNheight, 534,
  1211. XmNunitType, XmPIXELS,
  1212. RES_CONVERT( XmNdialogTitle, UxTmp0 ),
  1213. XmNautoUnmanage, FALSE,
  1214. XmNdefaultPosition, FALSE,
  1215. NULL );
  1216. UxPutContext( icon_selection_dialog, (char *) UxIcon_selection_dialogContext );
  1217. /*******************************************************************/
  1218. /* Set up help callback */
  1219. /*******************************************************************/
  1220. XtAddCallback( icon_selection_dialog, XmNhelpCallback,
  1221. (XtCallbackProc) helpCB_general,
  1222. (XtPointer) HELP_ICONSELECTOR );
  1223. /* Creation of bottom_button_form */
  1224. bottom_button_form = XtVaCreateManagedWidget( "bottom_button_form",
  1225. xmFormWidgetClass,
  1226. icon_selection_dialog,
  1227. XmNskipAdjust, TRUE,
  1228. XmNfractionBase, ((TIGHTNESS * ntotalbuttons) - 1),
  1229. XmNleftOffset, 10,
  1230. XmNleftAttachment, XmATTACH_FORM,
  1231. XmNrightOffset, 10,
  1232. XmNrightAttachment, XmATTACH_FORM,
  1233. XmNbottomOffset, 20,
  1234. XmNbottomAttachment, XmATTACH_FORM,
  1235. NULL );
  1236. UxPutContext( bottom_button_form, (char *) UxIcon_selection_dialogContext );
  1237. UxTmp0 = bottom_button_one_label ? (char *)bottom_button_one_label : GETMESSAGE(6, 10, "OK");
  1238. /* Creation of bottom_button1 = OK */
  1239. bottom_button1 = XtVaCreateManagedWidget( "bottom_button1",
  1240. xmPushButtonWidgetClass,
  1241. bottom_button_form,
  1242. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1243. XmNleftAttachment, nbutton ?
  1244. XmATTACH_POSITION : XmATTACH_FORM,
  1245. XmNleftPosition, TIGHTNESS * nbutton,
  1246. XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
  1247. XmATTACH_POSITION : XmATTACH_FORM,
  1248. XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
  1249. NULL );
  1250. nbutton++;
  1251. XtAddCallback( bottom_button1, XmNactivateCallback,
  1252. (XtCallbackProc) activateCB_bottom_button1,
  1253. (XtPointer) NULL );
  1254. UxPutContext( bottom_button1, (char *) UxIcon_selection_dialogContext );
  1255. UxTmp0 = bottom_button_two_label ? (char *)bottom_button_two_label : GETMESSAGE(6, 12, "Cancel");
  1256. /* Creation of bottom_button2 = CANCEL */
  1257. bottom_button2 = XtVaCreateManagedWidget( "bottom_button2",
  1258. xmPushButtonWidgetClass,
  1259. bottom_button_form,
  1260. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1261. XmNleftAttachment, nbutton ?
  1262. XmATTACH_POSITION : XmATTACH_FORM,
  1263. XmNleftPosition, TIGHTNESS * nbutton,
  1264. XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
  1265. XmATTACH_POSITION : XmATTACH_FORM,
  1266. XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
  1267. NULL );
  1268. nbutton++;
  1269. XtAddCallback( bottom_button2, XmNactivateCallback,
  1270. (XtCallbackProc) bottom_button_two_cb ?
  1271. bottom_button_two_cb : activateCB_bottom_button2,
  1272. (XtPointer) UxIcon_selection_dialogContext );
  1273. UxPutContext( bottom_button2, (char *) UxIcon_selection_dialogContext );
  1274. UxTmp0 = bottom_button_three_label ? (char *)bottom_button_three_label : GETMESSAGE(6, 13, "Help");
  1275. /* Creation of bottom_button3 = HELP */
  1276. bottom_button3 = XtVaCreateManagedWidget( "bottom_button3",
  1277. xmPushButtonWidgetClass,
  1278. bottom_button_form,
  1279. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1280. XmNuserData, icon_selection_dialog,
  1281. XmNleftAttachment, nbutton ?
  1282. XmATTACH_POSITION : XmATTACH_FORM,
  1283. XmNleftPosition, TIGHTNESS * nbutton,
  1284. XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
  1285. XmATTACH_POSITION : XmATTACH_FORM,
  1286. XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
  1287. NULL );
  1288. nbutton++;
  1289. XtAddCallback( bottom_button3, XmNactivateCallback,
  1290. (XtCallbackProc) bottom_button_three_cb ?
  1291. bottom_button_three_cb : activateCB_bottom_button3,
  1292. (XtPointer) UxIcon_selection_dialogContext );
  1293. UxPutContext( bottom_button3, (char *) UxIcon_selection_dialogContext );
  1294. UxTmp0 = bottom_button_four_label ? (char *)bottom_button_four_label : GETMESSAGE(12, 10, "Filter");
  1295. /* Creation of bottom_button4 */
  1296. bottom_button4 = XtVaCreateManagedWidget( "bottom_button4",
  1297. xmPushButtonWidgetClass,
  1298. bottom_button_form,
  1299. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1300. XmNleftAttachment, nbutton ?
  1301. XmATTACH_POSITION : XmATTACH_FORM,
  1302. XmNleftPosition, TIGHTNESS * nbutton,
  1303. XmNrightAttachment, nbutton != (ntotalbuttons - 1) ?
  1304. XmATTACH_POSITION : XmATTACH_FORM,
  1305. XmNrightPosition, (TIGHTNESS * nbutton)+(TIGHTNESS - 1),
  1306. NULL );
  1307. nbutton++;
  1308. XtAddCallback( bottom_button4, XmNactivateCallback,
  1309. (XtCallbackProc) bottom_button_four_cb ?
  1310. bottom_button_four_cb : activateCB_bottom_button,
  1311. (XtPointer) UxIcon_selection_dialogContext );
  1312. UxPutContext( bottom_button4, (char *) UxIcon_selection_dialogContext );
  1313. /* Creation of separatorGadget1 */
  1314. separatorGadget1 = XtVaCreateManagedWidget( "separatorGadget1",
  1315. xmSeparatorGadgetClass,
  1316. icon_selection_dialog,
  1317. XmNx, 0,
  1318. XmNy, 490,
  1319. XmNrightOffset, 1,
  1320. XmNrightAttachment, XmATTACH_FORM,
  1321. XmNleftOffset, 1,
  1322. XmNleftAttachment, XmATTACH_FORM,
  1323. XmNbottomOffset, 10,
  1324. XmNbottomWidget, bottom_button_form,
  1325. XmNbottomAttachment, XmATTACH_WIDGET,
  1326. NULL );
  1327. UxPutContext( separatorGadget1, (char *) UxIcon_selection_dialogContext );
  1328. /* Creation of icon_name_text_field */
  1329. icon_name_text_field = XtVaCreateManagedWidget( "icon_name_text_field",
  1330. xmTextFieldWidgetClass,
  1331. icon_selection_dialog,
  1332. XmNx, 9,
  1333. XmNy, 440,
  1334. XmNbottomOffset, 10,
  1335. XmNbottomWidget, separatorGadget1,
  1336. XmNbottomAttachment, XmATTACH_WIDGET,
  1337. XmNrightOffset, 10,
  1338. XmNrightAttachment, XmATTACH_FORM,
  1339. XmNleftOffset, 10,
  1340. XmNleftAttachment, XmATTACH_FORM,
  1341. NULL );
  1342. UxPutContext( icon_name_text_field, (char *) UxIcon_selection_dialogContext );
  1343. ISD_SelectedIconTextField = icon_name_text_field;
  1344. UxTmp0 = name_field_title ? (char *)name_field_title : GETMESSAGE(11, 12, "Enter Icon Filename");
  1345. /* Creation of icon_name_textfield_label */
  1346. icon_name_textfield_label = XtVaCreateManagedWidget( "icon_name_textfield_label",
  1347. xmLabelWidgetClass,
  1348. icon_selection_dialog,
  1349. XmNx, 9,
  1350. XmNy, 410,
  1351. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1352. XmNbottomOffset, 0,
  1353. XmNbottomWidget, icon_name_text_field,
  1354. XmNbottomAttachment, XmATTACH_WIDGET,
  1355. XmNleftOffset, 0,
  1356. XmNleftWidget, icon_name_text_field,
  1357. XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
  1358. XmNalignment, XmALIGNMENT_BEGINNING,
  1359. NULL );
  1360. UxPutContext( icon_name_textfield_label, (char *) UxIcon_selection_dialogContext );
  1361. UxTmp0 = filter_field_title ? (char *)filter_field_title : GETMESSAGE(12, 10, "Filter");
  1362. /* Creation of filter_textfield_label */
  1363. filter_textfield_label = XtVaCreateManagedWidget( "filter_textfield_label",
  1364. xmLabelWidgetClass,
  1365. icon_selection_dialog,
  1366. XmNx, 10,
  1367. XmNy, 10,
  1368. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1369. XmNalignment, XmALIGNMENT_BEGINNING,
  1370. XmNtopOffset, 10,
  1371. XmNtopAttachment, XmATTACH_FORM,
  1372. XmNleftOffset, 10,
  1373. XmNleftAttachment, XmATTACH_FORM,
  1374. NULL );
  1375. UxPutContext( filter_textfield_label, (char *) UxIcon_selection_dialogContext );
  1376. /* Creation of filter_text_field */
  1377. filter_text_field = XtVaCreateManagedWidget( "filter_text_field",
  1378. xmTextFieldWidgetClass,
  1379. icon_selection_dialog,
  1380. XmNx, 10,
  1381. XmNy, 40,
  1382. XmNtopOffset, 0,
  1383. XmNtopWidget, filter_textfield_label,
  1384. XmNtopAttachment, XmATTACH_WIDGET,
  1385. XmNrightOffset, 10,
  1386. XmNrightAttachment, XmATTACH_FORM,
  1387. XmNleftOffset, 10,
  1388. XmNleftAttachment, XmATTACH_FORM,
  1389. NULL );
  1390. XtAddCallback( filter_text_field, XmNactivateCallback,
  1391. (XtCallbackProc) activateCB_filter_text_field,
  1392. (XtPointer) UxIcon_selection_dialogContext );
  1393. UxPutContext( filter_text_field, (char *) UxIcon_selection_dialogContext );
  1394. UxTmp0 = directory_title ? (char *)directory_title : GETMESSAGE(11, 30, "Icon Folders");
  1395. /* Creation of directory_list_label */
  1396. directory_list_label = XtVaCreateManagedWidget( "directory_list_label",
  1397. xmLabelWidgetClass,
  1398. icon_selection_dialog,
  1399. XmNx, 0,
  1400. XmNy, 90,
  1401. XmNlabelType, XmSTRING,
  1402. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1403. XmNalignment, XmALIGNMENT_BEGINNING,
  1404. XmNtopOffset, 10,
  1405. XmNtopWidget, filter_text_field,
  1406. XmNtopAttachment, use_filter_field ? XmATTACH_WIDGET : XmATTACH_FORM,
  1407. XmNleftOffset, 10,
  1408. XmNleftAttachment, XmATTACH_FORM,
  1409. NULL );
  1410. UxPutContext( directory_list_label, (char *) UxIcon_selection_dialogContext );
  1411. UxTmp0 = container_title ? (char *)container_title : GETMESSAGE(11, 11, "Icon Files");
  1412. /* Creation of icon_container_label */
  1413. icon_container_label = XtVaCreateManagedWidget( "icon_container_label",
  1414. xmLabelWidgetClass,
  1415. icon_selection_dialog,
  1416. XmNx, 281,
  1417. XmNy, 90,
  1418. XmNlabelType, XmSTRING,
  1419. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1420. XmNalignment, XmALIGNMENT_BEGINNING,
  1421. XmNtopOffset, 10,
  1422. XmNtopWidget, filter_text_field,
  1423. XmNtopAttachment, XmATTACH_WIDGET,
  1424. XmNleftAttachment, XmATTACH_POSITION,
  1425. XmNleftPosition, 55,
  1426. NULL );
  1427. UxPutContext( icon_container_label, (char *) UxIcon_selection_dialogContext );
  1428. /* Creation of top_button_form */
  1429. top_button_form = XtVaCreateManagedWidget( "top_button_form",
  1430. xmFormWidgetClass,
  1431. icon_selection_dialog,
  1432. XmNresizePolicy, XmRESIZE_NONE,
  1433. XmNx, 10,
  1434. XmNy, 290,
  1435. XmNbottomOffset, 10,
  1436. XmNbottomWidget, use_icon_name_field ? icon_name_textfield_label : separatorGadget1,
  1437. XmNbottomAttachment, XmATTACH_WIDGET,
  1438. XmNrightOffset, 1,
  1439. XmNrightAttachment, XmATTACH_FORM,
  1440. XmNleftOffset, 1,
  1441. XmNleftAttachment, XmATTACH_FORM,
  1442. NULL );
  1443. UxPutContext( top_button_form, (char *) UxIcon_selection_dialogContext );
  1444. UxTmp0 = top_button_one_label ? (char *)top_button_one_label : "No_Label";
  1445. /* Creation of top_button1 */
  1446. top_button1 = XtVaCreateManagedWidget( "top_button1",
  1447. xmPushButtonWidgetClass,
  1448. top_button_form,
  1449. XmNx, 40,
  1450. XmNy, 0,
  1451. XmNleftOffset, 0,
  1452. XmNbottomAttachment, XmATTACH_FORM,
  1453. XmNleftAttachment, XmATTACH_POSITION,
  1454. XmNtopOffset, 0,
  1455. XmNleftPosition, get_top_b1_position (numberOfTopButtons),
  1456. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1457. NULL );
  1458. XtAddCallback( top_button1, XmNactivateCallback,
  1459. (XtCallbackProc) top_button_one_cb,
  1460. (XtPointer) UxIcon_selection_dialogContext );
  1461. UxPutContext( top_button1, (char *) UxIcon_selection_dialogContext );
  1462. UxTmp0 = top_button_two_label ? (char *)top_button_two_label : "No_Label";
  1463. /* Creation of top_button2 */
  1464. top_button2 = XtVaCreateManagedWidget( "top_button2",
  1465. xmPushButtonWidgetClass,
  1466. top_button_form,
  1467. XmNx, 220,
  1468. XmNy, 0,
  1469. XmNleftOffset, 0,
  1470. XmNtopOffset, 0,
  1471. XmNleftPosition, get_top_b2_position (numberOfTopButtons),
  1472. XmNbottomAttachment, XmATTACH_FORM,
  1473. XmNleftAttachment, XmATTACH_POSITION,
  1474. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1475. NULL );
  1476. XtAddCallback( top_button2, XmNactivateCallback,
  1477. (XtCallbackProc) top_button_two_cb,
  1478. (XtPointer) UxIcon_selection_dialogContext );
  1479. UxPutContext( top_button2, (char *) UxIcon_selection_dialogContext );
  1480. UxTmp0 = top_button_three_label ? (char *)top_button_three_label : "No_Label";
  1481. /* Creation of top_button3 */
  1482. top_button3 = XtVaCreateManagedWidget( "top_button3",
  1483. xmPushButtonWidgetClass,
  1484. top_button_form,
  1485. XmNx, 310,
  1486. XmNy, 0,
  1487. RES_CONVERT( XmNlabelString, UxTmp0 ),
  1488. XmNleftPosition, 72,
  1489. XmNleftOffset, 1,
  1490. XmNleftAttachment, XmATTACH_POSITION,
  1491. XmNbottomOffset, 0,
  1492. XmNbottomAttachment, XmATTACH_FORM,
  1493. NULL );
  1494. XtAddCallback( top_button3, XmNactivateCallback,
  1495. (XtCallbackProc) top_button_three_cb,
  1496. (XtPointer) UxIcon_selection_dialogContext );
  1497. UxPutContext( top_button3, (char *) UxIcon_selection_dialogContext );
  1498. UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
  1499. /* Creation of dir_scrolled_list */
  1500. XtSetArg(args[i], XmNshadowThickness, 2); i++;
  1501. XtSetArg(args[i], XmNlistSizePolicy, XmCONSTANT); i++;
  1502. XtSetArg(args[i], XmNleftOffset, 10); i++;
  1503. XtSetArg(args[i], XmNleftAttachment, XmATTACH_FORM); i++;
  1504. XtSetArg(args[i], XmNtopOffset, 0); i++;
  1505. XtSetArg(args[i], XmNtopWidget, directory_list_label); i++;
  1506. XtSetArg(args[i], XmNtopAttachment, XmATTACH_WIDGET); i++;
  1507. XtSetArg(args[i], XmNrightOffset, 20); i++;
  1508. XtSetArg(args[i], XmNrightWidget, icon_container_label); i++;
  1509. XtSetArg(args[i], XmNrightAttachment, XmATTACH_WIDGET); i++;
  1510. XtSetArg(args[i], XmNbottomOffset, 10); i++;
  1511. if (numberOfTopButtons > 0) {
  1512. XtSetArg(args[i], XmNbottomWidget, top_button_form); i++;
  1513. } else if (use_icon_name_field) {
  1514. XtSetArg(args[i], XmNbottomWidget, icon_name_textfield_label); i++;
  1515. } else {
  1516. XtSetArg(args[i], XmNbottomWidget, separatorGadget1); i++;
  1517. }
  1518. XtSetArg(args[i], XmNbottomAttachment, XmATTACH_WIDGET); i++;
  1519. dir_scrolled_list = XmCreateScrolledList(icon_selection_dialog,
  1520. "dir_scrolled_list",
  1521. args,
  1522. i);
  1523. XtVaSetValues(dir_scrolled_list,
  1524. XmNselectionPolicy, XmBROWSE_SELECT,
  1525. XmNvisibleItemCount, 15,
  1526. NULL );
  1527. XtManageChild(dir_scrolled_list);
  1528. UxPutContext( dir_scrolled_list, (char *) UxIcon_selection_dialogContext );
  1529. calc_bottom_attachment (dir_scrolled_list,
  1530. (XtPointer) UxIcon_selection_dialogContext,
  1531. (XtPointer) NULL);
  1532. XtAddCallback( dir_scrolled_list, XmNdefaultActionCallback,
  1533. (XtCallbackProc) defaultActionCB_dir_scrolled_list,
  1534. (XtPointer) UxIcon_selection_dialogContext );
  1535. UxTmp0 = (char *)((numberOfTopButtons > 0) ? top_button_form : icon_name_textfield_label);
  1536. /* Creation of icon_scrolled_win */
  1537. icon_scrolled_win = XtVaCreateManagedWidget( "icon_scrolled_win",
  1538. xmScrolledWindowWidgetClass,
  1539. icon_selection_dialog,
  1540. XmNscrollingPolicy, XmAUTOMATIC,
  1541. /* XmNnavigationType, XmTAB_GROUP, */
  1542. XmNx, 282,
  1543. XmNy, 84,
  1544. XmNscrollBarDisplayPolicy, XmAS_NEEDED,
  1545. XmNrightOffset, 10,
  1546. XmNrightAttachment, XmATTACH_FORM,
  1547. XmNtopOffset, 0,
  1548. XmNtopWidget, icon_container_label,
  1549. XmNtopAttachment, XmATTACH_WIDGET,
  1550. XmNleftOffset, 0,
  1551. XmNleftWidget, icon_container_label,
  1552. XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
  1553. XmNbottomOffset, 10,
  1554. XmNbottomWidget, None,
  1555. XmNbottomAttachment, XmATTACH_WIDGET,
  1556. NULL );
  1557. UxPutContext( icon_scrolled_win, (char *) UxIcon_selection_dialogContext );
  1558. calc_bottom_attachment (icon_scrolled_win,
  1559. (XtPointer) UxIcon_selection_dialogContext,
  1560. (XtPointer) NULL);
  1561. /* Creation of icon_scrolled_container */
  1562. icon_scrolled_container = XtVaCreateManagedWidget( "icon_scrolled_container",
  1563. xmRowColumnWidgetClass,
  1564. icon_scrolled_win,
  1565. XmNnavigationType, XmTAB_GROUP,
  1566. /*XmNborderWidth, 1,*/
  1567. /*XmNnumColumns, 2,*/
  1568. XmNnumColumns, 1,
  1569. XmNorientation, XmVERTICAL,
  1570. XmNpacking, XmPACK_COLUMN,
  1571. XmNshadowThickness, 1,
  1572. NULL );
  1573. XtVaSetValues(icon_selection_dialog,
  1574. XmNcancelButton, bottom_button2,
  1575. NULL );
  1576. XtAddCallback( icon_selection_dialog, XmNdestroyCallback,
  1577. (XtCallbackProc) UxDestroyContextCB,
  1578. (XtPointer) UxIcon_selection_dialogContext);
  1579. XtVaGetValues (icon_scrolled_win, XmNclipWindow, &widclipWindow, NULL);
  1580. XtAddCallback( widclipWindow, XmNresizeCallback,
  1581. (XtCallbackProc) resizeCB_clipWindow,
  1582. (XtPointer) icon_scrolled_container );
  1583. return ( icon_selection_dialog );
  1584. }
  1585. /*******************************************************************************
  1586. The following is the 'Interface function' which is the
  1587. external entry point for creating this interface.
  1588. This function should be called from your application or from
  1589. a callback function.
  1590. *******************************************************************************/
  1591. Widget create_icon_selection_dialog(swidget _UxUxParent,
  1592. unsigned char *_Uxdialog_title,
  1593. unsigned char *_Uxfilter_field_title,
  1594. int _Uxuse_filter_field,
  1595. unsigned char *_Uxfile_filter,
  1596. unsigned char *_Uxdirectory_title,
  1597. unsigned char **_Uxdirectories_list,
  1598. unsigned char *_Uxcontainer_title,
  1599. int _UxnumberOfTopButtons,
  1600. unsigned char *_Uxtop_button_one_label,
  1601. void (*_Uxtop_button_one_cb)(),
  1602. unsigned char *_Uxtop_button_two_label,
  1603. void (*_Uxtop_button_two_cb)(),
  1604. unsigned char *_Uxtop_button_three_label,
  1605. void (*_Uxtop_button_three_cb)(),
  1606. int _Uxuse_icon_name_field,
  1607. unsigned char *_Uxname_field_title,
  1608. int _UxnumberOfBottomButtons,
  1609. unsigned char *_Uxbottom_button_one_label,
  1610. void (*_Uxbottom_button_one_cb)(),
  1611. unsigned char *_Uxbottom_button_two_label,
  1612. void (*_Uxbottom_button_two_cb)(),
  1613. unsigned char *_Uxbottom_button_three_label,
  1614. void (*_Uxbottom_button_three_cb)(),
  1615. unsigned char *_Uxbottom_button_four_label,
  1616. void (*_Uxbottom_button_four_cb)() )
  1617. {
  1618. char *initial_filter;
  1619. char *icon_file_name;
  1620. Widget rtrn;
  1621. int lcv;
  1622. _UxCicon_selection_dialog *UxContext;
  1623. UxIcon_selection_dialogContext = UxContext =
  1624. (_UxCicon_selection_dialog *) UxNewContext( sizeof(_UxCicon_selection_dialog), False );
  1625. UxParent = _UxUxParent;
  1626. dialog_title = _Uxdialog_title;
  1627. filter_field_title = _Uxfilter_field_title;
  1628. use_filter_field = _Uxuse_filter_field;
  1629. file_filter = _Uxfile_filter;
  1630. directory_title = _Uxdirectory_title;
  1631. directories_list = _Uxdirectories_list;
  1632. container_title = _Uxcontainer_title;
  1633. numberOfTopButtons = _UxnumberOfTopButtons;
  1634. top_button_one_label = _Uxtop_button_one_label;
  1635. top_button_one_cb = _Uxtop_button_one_cb;
  1636. top_button_two_label = _Uxtop_button_two_label;
  1637. top_button_two_cb = _Uxtop_button_two_cb;
  1638. top_button_three_label = _Uxtop_button_three_label;
  1639. top_button_three_cb = _Uxtop_button_three_cb;
  1640. use_icon_name_field = _Uxuse_icon_name_field;
  1641. name_field_title = _Uxname_field_title;
  1642. numberOfBottomButtons = _UxnumberOfBottomButtons;
  1643. bottom_button_one_label = _Uxbottom_button_one_label;
  1644. bottom_button_one_cb = _Uxbottom_button_one_cb;
  1645. bottom_button_two_label = _Uxbottom_button_two_label;
  1646. bottom_button_two_cb = _Uxbottom_button_two_cb;
  1647. bottom_button_three_label = _Uxbottom_button_three_label;
  1648. bottom_button_three_cb = _Uxbottom_button_three_cb;
  1649. bottom_button_four_label = _Uxbottom_button_four_label;
  1650. bottom_button_four_cb = _Uxbottom_button_four_cb;
  1651. rtrn = _Uxbuild_icon_selection_dialog();
  1652. switch (numberOfTopButtons){
  1653. case 0 : XtUnmanageChild (top_button_form); break;
  1654. case 1 : XtUnmanageChild (top_button2);
  1655. case 2 : XtUnmanageChild (top_button3);
  1656. };
  1657. if (numberOfBottomButtons == 3)
  1658. XtUnmanageChild (bottom_button4);
  1659. if (!use_filter_field) {
  1660. XtUnmanageChild (filter_textfield_label);
  1661. XtUnmanageChild (filter_text_field);
  1662. }
  1663. if (!use_icon_name_field) {
  1664. XtUnmanageChild (icon_name_textfield_label);
  1665. XtUnmanageChild (icon_name_text_field);
  1666. }
  1667. TurnOnHourGlassAllWindows();
  1668. /******************************************************************/
  1669. /* save file_filter */
  1670. /******************************************************************/
  1671. file_filter_global = (char *)calloc(strlen((char *)file_filter)+1, sizeof(char));
  1672. #ifdef DEBUG
  1673. if (!file_filter_global) printf("Calloc error for file_filter_global, in create_icon_selection_dialog.\n");
  1674. #endif
  1675. if (file_filter[0] == '*')
  1676. file_filter_global = strcpy(file_filter_global, (char *)&file_filter[1]);
  1677. else
  1678. file_filter_global = strcpy(file_filter_global, (char *)file_filter);
  1679. load_directories_list ((char **)directories_list);
  1680. initial_filter = initialize_filter ((char *)file_filter);
  1681. /******************************************************************/
  1682. /* save main_filter */
  1683. /******************************************************************/
  1684. main_filter = (char *)calloc(strlen(initial_filter)+1, sizeof(char));
  1685. #ifdef DEBUG
  1686. if (!main_filter) printf("Calloc error for main_filter, in create_icon_selection_dialog.\n");
  1687. #endif
  1688. main_filter = strcpy(main_filter, initial_filter);;
  1689. icons_in_container = NULL;
  1690. icon_count = 0;
  1691. update_container_contents (initial_filter);
  1692. /******************************************************************/
  1693. /* set selected_icon_name to first name in list */
  1694. /******************************************************************/
  1695. #if 0
  1696. if (icons_in_container) {
  1697. XtVaGetValues (icons_in_container[0], XmNimageName, &icon_file_name, NULL);
  1698. XmTextFieldSetString (icon_name_text_field, icon_file_name);
  1699. selected_icon_name = XtMalloc(strlen(icon_file_name) + 1);
  1700. if (selected_icon_name)
  1701. selected_icon_name = strcpy(selected_icon_name, icon_file_name);
  1702. }
  1703. #endif
  1704. load_filter_text_field (initial_filter);
  1705. TurnOffHourGlassAllWindows();
  1706. return(rtrn);
  1707. }