Filter.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  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: Filter.c /main/8 1996/10/30 11:10:48 drk $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: Filter.c
  28. *
  29. * COMPONENT_NAME: Desktop File Manager (dtfile)
  30. *
  31. * Description: Source file for the file filter dialog.
  32. *
  33. * FUNCTIONS: ApplyCallback
  34. * Create
  35. * DefaultCallback
  36. * DeselectAllFilter
  37. * Destroy
  38. * FileTypeAscending
  39. * FreeValues
  40. * GetDefaultValues
  41. * GetFilterValues
  42. * GetResourceValues
  43. * GetValues
  44. * InstallChange
  45. * InstallClose
  46. * OkCallback
  47. * ReadInFiletypes
  48. * SelectAllFilter
  49. * SetValues
  50. * ShowHiddenFiles
  51. * UpdateFilterAfterDBReread
  52. * WriteResourceValues
  53. * filterTypeChanged
  54. *
  55. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  56. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  57. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  58. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  59. *
  60. ****************************************************************************
  61. ************************************<+>*************************************/
  62. #include <stdio.h>
  63. #include <time.h>
  64. #include <stdlib.h>
  65. #include <Xm/XmP.h>
  66. #include <Xm/Xm.h>
  67. #include <Xm/DialogS.h>
  68. #include <Xm/DrawingA.h>
  69. #include <Xm/Form.h>
  70. #include <Xm/LabelG.h>
  71. #include <Xm/List.h>
  72. #include <Xm/MessageB.h>
  73. #include <Xm/PushBG.h>
  74. #include <Xm/RowColumn.h>
  75. #include <Xm/TextF.h>
  76. #include <Xm/ToggleBG.h>
  77. #include <Xm/ScrollBar.h>
  78. #include <Xm/ScrolledW.h>
  79. #include <Xm/SeparatoG.h>
  80. #include <Xm/VendorSEP.h>
  81. #include <Xm/MwmUtil.h>
  82. #include <Xm/Protocols.h>
  83. #include <Dt/TitleBox.h>
  84. #include <Dt/Icon.h>
  85. #include <Dt/IconP.h>
  86. #include <Dt/IconFile.h>
  87. #include <X11/ShellP.h>
  88. #include <X11/Shell.h>
  89. #include <X11/Xatom.h>
  90. #include <Dt/DtP.h>
  91. #include <Dt/DtNlUtils.h>
  92. #include <Dt/Dts.h>
  93. #include <Dt/SharedProcs.h>
  94. #include "Encaps.h"
  95. #include "SharedProcs.h"
  96. #include "FileMgr.h"
  97. #include "Desktop.h"
  98. #include "Main.h"
  99. #include "Common.h"
  100. #include "Filter.h"
  101. #include "Help.h"
  102. char **DtDtsDataTypeNames(void);
  103. static char * FILE_FILTER = "FileFilter";
  104. static DialogResource resources[] =
  105. {
  106. { "matchFilter", XmRBoolean, sizeof(Boolean),
  107. XtOffset(FilterDataPtr, match_flag),
  108. (XtPointer) True, _DtBooleanToString },
  109. { "name", XmRString, sizeof(String),
  110. XtOffset(FilterDataPtr, filter),
  111. (XtPointer) "", _DtStringToString },
  112. { "showHidden", XmRBoolean, sizeof(Boolean),
  113. XtOffset(FilterDataPtr, show_hidden),
  114. (XtPointer) False, _DtBooleanToString },
  115. { "filetypesFilteredCount", XmRInt, sizeof(int),
  116. XtOffset(FilterDataPtr, filetypesFilteredCount),
  117. (XtPointer) 3, _DtIntToString },
  118. { "filetypesFiltered", XmRString, sizeof(String),
  119. XtOffset(FilterDataPtr, filetypesFiltered),
  120. (XtPointer) DEFAULT_FILTER, _DtStringToString },
  121. };
  122. #define FM_TYPE_LABEL "TYPE_LABEL"
  123. /******** Forward Function Declaration ********/
  124. int ReadInFiletypes(FilterData *filter_data);
  125. /******** Static Function Declarations ********/
  126. static void Create(
  127. Display *display,
  128. Widget parent,
  129. Widget *return_widget,
  130. XtPointer *dialog) ;
  131. static void InstallChange(
  132. FilterRec *filter_rec,
  133. XtCallbackProc callback,
  134. XtPointer client_data) ;
  135. static void InstallClose(
  136. FilterRec *filter_rec,
  137. XtCallbackProc callback,
  138. XtPointer client_data) ;
  139. static void Destroy(
  140. FilterRec *filter_rec) ;
  141. static XtPointer GetValues(
  142. FilterRec *filter_rec) ;
  143. static XtPointer GetDefaultValues( void ) ;
  144. static XtPointer GetResourceValues(
  145. XrmDatabase data_base,
  146. char **name_list) ;
  147. static void SetValues(
  148. FilterRec *filter_rec,
  149. FilterData *filter_data) ;
  150. static void WriteResourceValues(
  151. DialogData *values,
  152. int fd,
  153. char **name_list) ;
  154. static void FreeValues(
  155. FilterData *filter_data) ;
  156. static void DefaultCallback(
  157. Widget w,
  158. XtPointer client_data,
  159. XtPointer call_data) ;
  160. static void CancelCallback(
  161. Widget w,
  162. XtPointer client_data,
  163. XtPointer call_data) ;
  164. static void OkCallback(
  165. Widget w,
  166. XtPointer client_data,
  167. XtPointer call_data) ;
  168. static void ApplyCallback(
  169. Widget w,
  170. XtPointer client_data,
  171. XtPointer call_data) ;
  172. static Boolean GetFilterValues(
  173. FilterRec *filter_rec,
  174. FilterData *filter_data) ;
  175. static void filterTypeChanged(
  176. Widget w,
  177. XtPointer client_data,
  178. XtPointer call_data ) ;
  179. static int FileTypeAscending(
  180. FTData **t1,
  181. FTData **t2 );
  182. static void SelectAllFilter(
  183. Widget w,
  184. XEvent *event,
  185. String *params,
  186. Cardinal *num_params );
  187. static void DeselectAllFilter(
  188. Widget w,
  189. XEvent *event,
  190. String *params,
  191. Cardinal *num_params );
  192. /******** End Static Function Declarations ********/
  193. static DialogClass filterClassRec =
  194. {
  195. resources,
  196. XtNumber(resources),
  197. Create,
  198. (DialogInstallChangeProc) InstallChange,
  199. (DialogInstallCloseProc) InstallClose,
  200. (DialogDestroyProc) Destroy,
  201. (DialogGetValuesProc) GetValues,
  202. GetDefaultValues,
  203. GetResourceValues,
  204. (DialogSetValuesProc) SetValues,
  205. WriteResourceValues,
  206. (DialogFreeValuesProc) FreeValues,
  207. (DialogMapWindowProc) _DtGenericMapWindow,
  208. NULL,
  209. };
  210. DialogClass * filterClass = (DialogClass *) &filterClassRec;
  211. static XtActionsRec FilterAction[] = {
  212. { "SelectAllFilter", SelectAllFilter },
  213. { "DeselectAllFilter", DeselectAllFilter }
  214. };
  215. static char FilterTranslationString[] = "\
  216. Ctrl<Key>slash:SelectAllFilter(@)\n\
  217. Ctrl<Key>backslash:DeselectAllFilter(@)";
  218. /************************************************************************
  219. *
  220. * Create
  221. *
  222. ************************************************************************/
  223. static void
  224. Create(
  225. Display *display,
  226. Widget parent,
  227. Widget *return_widget,
  228. XtPointer *dialog )
  229. {
  230. FilterRec * filter_rec;
  231. Widget shell, form, fileNameFilter;
  232. Widget tog_frame, tog_form, fileTypeScrollWin, file_window;
  233. Widget labelPt2, hidden, separator, sel_form;
  234. Widget ok, apply, reset, close, help;
  235. Widget selectAll, unselectAll;
  236. Widget hiddenPulldown;
  237. XmString label_string;
  238. XtTranslations filterTranslationTable;
  239. int flag=FLAG_RESET;
  240. Arg args[20];
  241. int n;
  242. char * tmpStr, * resolvedFilterTranslationString;
  243. /* Allocate the file filter dialog instance record. */
  244. filter_rec = (FilterRec *) XtMalloc (sizeof (FilterRec));
  245. /* Create the shell and form used for the dialog. */
  246. n = 0;
  247. XtSetArg (args[n], XmNmwmFunctions, MWM_FUNC_MOVE |
  248. MWM_FUNC_CLOSE); ++n;
  249. XtSetArg (args[n], XmNmwmDecorations, MWM_DECOR_BORDER |
  250. MWM_DECOR_TITLE); ++n;
  251. XtSetArg (args[n], XmNallowShellResize, True); ++n;
  252. shell = XmCreateDialogShell (parent, "filter_files", args, n);
  253. /* Set the useAsyncGeo on the shell */
  254. XtSetArg (args[0], XmNuseAsyncGeometry, True);
  255. XtSetValues (XtParent(shell), args, 1);
  256. n = 0;
  257. XtSetArg (args[n], XmNmarginWidth, 1); n++;
  258. XtSetArg (args[n], XmNmarginHeight, 1); n++;
  259. XtSetArg (args[n], XmNshadowThickness, 1); n++;
  260. XtSetArg (args[n], XmNshadowType, XmSHADOW_OUT); n++;
  261. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  262. form = XmCreateForm (shell, "form", args, n);
  263. XtAddCallback(form, XmNhelpCallback, HelpRequestCB,
  264. HELP_FILTER_DIALOG_STR);
  265. XtAppAddActions( XtWidgetToApplicationContext(form),
  266. FilterAction,
  267. XtNumber(FilterAction));
  268. resolvedFilterTranslationString = ResolveTranslationString(
  269. FilterTranslationString,
  270. (char *)filter_rec );
  271. filterTranslationTable = XtParseTranslationTable(
  272. resolvedFilterTranslationString );
  273. XtFree( resolvedFilterTranslationString );
  274. resolvedFilterTranslationString = NULL;
  275. XtOverrideTranslations(form, filterTranslationTable);
  276. hiddenPulldown = XmCreatePulldownMenu(form, "hiddenPD", args, 0);
  277. label_string = XmStringCreateLocalized ((GETMESSAGE(13,27, "Shown")));
  278. XtSetArg(args[0], XmNmarginHeight, 1);
  279. XtSetArg(args[1], XmNmarginWidth, 1);
  280. XtSetArg(args[2], XmNlabelString, label_string);
  281. XtSetArg(args[3], XmNuserData, SHOWN);
  282. filter_rec->hidArray[SHOWN] =
  283. XmCreatePushButtonGadget(hiddenPulldown, "shown", args, 4);
  284. XmStringFree(label_string);
  285. XtAddCallback(filter_rec->hidArray[SHOWN], XmNactivateCallback,
  286. filterTypeChanged, (XtPointer) filter_rec);
  287. label_string = XmStringCreateLocalized ((GETMESSAGE(13,28, "Hidden")));
  288. XtSetArg(args[2], XmNlabelString, label_string);
  289. XtSetArg(args[3], XmNuserData, HIDDEN);
  290. filter_rec->hidArray[HIDDEN] =
  291. XmCreatePushButtonGadget(hiddenPulldown, "hidden", args, 4);
  292. XmStringFree(label_string);
  293. XtAddCallback(filter_rec->hidArray[HIDDEN], XmNactivateCallback,
  294. filterTypeChanged, (XtPointer) filter_rec);
  295. XtManageChildren(filter_rec->hidArray, 2);
  296. /* create the Option Menu and attach it to the Pulldown MenuPane */
  297. label_string = XmStringCreateLocalized ((GETMESSAGE(13,31,
  298. "Select Datatypes to be:")));
  299. n = 0;
  300. XtSetArg (args[n], XmNlabelString, label_string); n++;
  301. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  302. XtSetArg (args[n], XmNleftOffset, 5); n++;
  303. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  304. XtSetArg (args[n], XmNtopOffset, 10); n++;
  305. XtSetArg (args[n], XmNsubMenuId, hiddenPulldown); n++;
  306. XtSetArg (args[n], XmNmenuHistory, filter_rec->hidArray[HIDDEN]); n++;
  307. hidden = XmCreateOptionMenu(form, "file_name_label", args, n);
  308. XtManageChild (hidden);
  309. XmStringFree (label_string);
  310. XtAddCallback(hidden, XmNhelpCallback, HelpRequestCB,
  311. HELP_FILTER_DIALOG_STR);
  312. /* Create the Scrolled Window For the filetype display area */
  313. /* and set the scrollbars colors correctly */
  314. n = 0;
  315. XtSetArg (args[n], XmNspacing, 2); n++;
  316. XtSetArg (args[n], XmNscrollingPolicy, XmAUTOMATIC); n++;
  317. XtSetArg (args[n], XmNscrollBarDisplayPolicy, XmAS_NEEDED); n++;
  318. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  319. XtSetArg (args[n], XmNleftOffset, 10); n++;
  320. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  321. XtSetArg (args[n], XmNrightOffset, 10); n++;
  322. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  323. XtSetArg (args[n], XmNtopWidget, hidden); n++;
  324. XtSetArg (args[n], XmNtopOffset, 5); n++;
  325. fileTypeScrollWin = XmCreateScrolledWindow(form, "filetypeSWin", args, n);
  326. XtManageChild (fileTypeScrollWin);
  327. XtAddCallback(fileTypeScrollWin, XmNhelpCallback, HelpRequestCB,
  328. HELP_FILTER_DIALOG_STR);
  329. /* Create a drawing area as a child of the scrolled window */
  330. n = 0;
  331. XtSetArg (args[n], XmNmarginWidth, 4); n++;
  332. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  333. XtSetArg (args[n], XmNresizePolicy, XmRESIZE_ANY); n++;
  334. file_window = XmCreateDrawingArea (fileTypeScrollWin, "file_window",
  335. args, n);
  336. XtManageChild (file_window);
  337. n = 0;
  338. XtSetArg (args[n], XmNmarginWidth, 1); n++;
  339. XtSetArg (args[n], XmNmarginHeight, 1); n++;
  340. XtSetArg (args[n], XmNshadowThickness, 0); n++;
  341. XtSetArg (args[n], XmNautoUnmanage, False); n++;
  342. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  343. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  344. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  345. XtSetArg (args[n], XmNtopWidget, fileTypeScrollWin); n++;
  346. XtSetArg (args[n], XmNtopOffset, 10); n++;
  347. sel_form = XmCreateForm (form, "sel_form", args, n);
  348. XtManageChild(sel_form);
  349. label_string = XmStringCreateLocalized ((GETMESSAGE(13,21, "Select All")));
  350. n = 0;
  351. XtSetArg (args[n], XmNlabelString, label_string); n++;
  352. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  353. XtSetArg (args[n], XmNleftPosition, 15); n++;
  354. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  355. XtSetArg (args[n], XmNtopOffset, 5); n++;
  356. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  357. XtSetArg (args[n], XmNmarginWidth, 10); n++;
  358. selectAll = XmCreatePushButtonGadget (sel_form, "selectAll", args, n);
  359. XtManageChild (selectAll);
  360. XtAddCallback (selectAll, XmNactivateCallback, SelectAllFileTypes,
  361. (XtPointer) filter_rec);
  362. XtAddCallback(selectAll, XmNhelpCallback, HelpRequestCB,
  363. HELP_FILTER_DIALOG_STR);
  364. XmStringFree (label_string);
  365. XtSetArg (args[0], XmNdefaultButton, selectAll);
  366. XtSetValues (sel_form, args, 1);
  367. label_string = XmStringCreateLocalized ((GETMESSAGE(13,22, "Deselect All")));
  368. n = 0;
  369. XtSetArg (args[n], XmNlabelString, label_string); n++;
  370. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  371. XtSetArg (args[n], XmNleftPosition, 55); n++;
  372. XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  373. XtSetArg (args[n], XmNtopOffset, 5); n++;
  374. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  375. XtSetArg (args[n], XmNmarginWidth, 10); n++;
  376. unselectAll = XmCreatePushButtonGadget (sel_form, "deselectAll", args, n);
  377. XtManageChild (unselectAll);
  378. XtAddCallback (unselectAll, XmNactivateCallback, UnselectAllFileTypes,
  379. (XtPointer) filter_rec);
  380. XtAddCallback(unselectAll, XmNhelpCallback, HelpRequestCB,
  381. HELP_FILTER_DIALOG_STR);
  382. XmStringFree (label_string);
  383. /* Create the file name filter label and text fields. */
  384. label_string = XmStringCreateLocalized (((char *)GETMESSAGE(13,26,
  385. "Also hide (Optional): ")));
  386. n = 0;
  387. XtSetArg (args[n], XmNlabelString, label_string); n++;
  388. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  389. XtSetArg (args[n], XmNleftOffset, 5); n++;
  390. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  391. XtSetArg (args[n], XmNtopWidget, sel_form); n++;
  392. XtSetArg (args[n], XmNtopOffset, 18); n++;
  393. XtSetArg (args[n], XmNtraversalOn, False); n++;
  394. labelPt2 = XmCreateLabelGadget (form, "file_name_label", args, n);
  395. XtManageChild (labelPt2);
  396. XmStringFree (label_string);
  397. XtAddCallback(labelPt2, XmNhelpCallback, HelpRequestCB,
  398. HELP_FILTER_DIALOG_STR);
  399. n = 0;
  400. XtSetArg (args[n], XmNleftAttachment, XmATTACH_WIDGET); n++;
  401. XtSetArg (args[n], XmNleftWidget, labelPt2); n++;
  402. XtSetArg (args[n], XmNleftOffset, 0); n++;
  403. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  404. XtSetArg (args[n], XmNtopWidget, sel_form); n++;
  405. XtSetArg (args[n], XmNtopOffset, 10); n++;
  406. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  407. XtSetArg (args[n], XmNrightOffset, 10); n++;
  408. fileNameFilter = XmCreateTextField (form, "file_name_text", args, n);
  409. XtManageChild (fileNameFilter);
  410. XtAddCallback(fileNameFilter, XmNhelpCallback, HelpRequestCB,
  411. HELP_FILTER_DIALOG_STR);
  412. /* Create a separator between the buttons */
  413. n = 0;
  414. XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  415. XtSetArg (args[n], XmNrightAttachment, XmATTACH_FORM); n++;
  416. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  417. XtSetArg (args[n], XmNtopWidget, fileNameFilter); n++;
  418. XtSetArg (args[n], XmNtopOffset, 10); n++;
  419. separator = XmCreateSeparatorGadget (form, "separator", args, n);
  420. XtManageChild (separator);
  421. /* Create the ok, apply, reset, cancel and help buttons */
  422. n = 0;
  423. XtSetArg (args[n], XmNlabelString, okXmString); n++;
  424. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  425. XtSetArg (args[n], XmNleftPosition, 1); n++;
  426. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  427. XtSetArg (args[n], XmNrightPosition, 19); n++;
  428. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  429. XtSetArg (args[n], XmNtopWidget, separator); n++;
  430. XtSetArg (args[n], XmNtopOffset, 5); n++;
  431. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  432. XtSetArg (args[n], XmNbottomOffset, 5); n++;
  433. XtSetArg (args[n], XmNmarginWidth, 4); n++;
  434. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  435. XtSetArg (args[n], XmNmultiClick, XmMULTICLICK_DISCARD); n++;
  436. XtSetArg (args[n], XmNuserData, flag); n++;
  437. ok = XmCreatePushButtonGadget (form, "ok", args, n);
  438. XtManageChild (ok);
  439. XtAddCallback(ok, XmNhelpCallback, HelpRequestCB,
  440. HELP_FILTER_DIALOG_STR);
  441. n = 0;
  442. XtSetArg (args[n], XmNlabelString, applyXmString); n++;
  443. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  444. XtSetArg (args[n], XmNleftPosition, 21); n++;
  445. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  446. XtSetArg (args[n], XmNrightPosition, 39); n++;
  447. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  448. XtSetArg (args[n], XmNtopWidget, separator); n++;
  449. XtSetArg (args[n], XmNtopOffset, 5); n++;
  450. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  451. XtSetArg (args[n], XmNbottomOffset, 5); n++;
  452. XtSetArg (args[n], XmNmarginWidth, 4); n++;
  453. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  454. apply = XmCreatePushButtonGadget (form, "apply", args, n);
  455. XtManageChild (apply);
  456. XtAddCallback(apply, XmNhelpCallback, HelpRequestCB,
  457. HELP_FILTER_DIALOG_STR);
  458. XtSetArg (args[0], XmNdefaultButton, apply);
  459. XtSetValues (form, args, 1);
  460. label_string = XmStringCreateLocalized (((char *)GETMESSAGE(13, 11, "Defaults")));
  461. n = 0;
  462. XtSetArg (args[n], XmNlabelString, label_string); n++;
  463. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  464. XtSetArg (args[n], XmNleftPosition, 41); n++;
  465. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  466. XtSetArg (args[n], XmNrightPosition, 59); n++;
  467. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  468. XtSetArg (args[n], XmNtopWidget, separator); n++;
  469. XtSetArg (args[n], XmNtopOffset, 5); n++;
  470. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  471. XtSetArg (args[n], XmNbottomOffset, 5); n++;
  472. XtSetArg (args[n], XmNmarginWidth, 4); n++;
  473. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  474. reset = XmCreatePushButtonGadget (form, "reset", args, n);
  475. XtManageChild (reset);
  476. XtAddCallback (reset, XmNactivateCallback, DefaultCallback, (XtPointer) filter_rec);
  477. XtAddCallback(reset, XmNhelpCallback, HelpRequestCB,
  478. HELP_FILTER_DIALOG_STR);
  479. XmStringFree (label_string);
  480. n = 0;
  481. XtSetArg (args[n], XmNlabelString, cancelXmString); n++;
  482. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  483. XtSetArg (args[n], XmNleftPosition, 61); n++;
  484. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  485. XtSetArg (args[n], XmNrightPosition, 79); n++;
  486. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  487. XtSetArg (args[n], XmNtopWidget, separator); n++;
  488. XtSetArg (args[n], XmNtopOffset, 5); n++;
  489. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  490. XtSetArg (args[n], XmNbottomOffset, 5); n++;
  491. XtSetArg (args[n], XmNmarginWidth, 4); n++;
  492. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  493. XtSetArg (args[n], XmNmultiClick, XmMULTICLICK_DISCARD); n++;
  494. XtSetArg (args[n], XmNuserData, flag ); n++;
  495. close = XmCreatePushButtonGadget (form, "close", args, n);
  496. XtAddCallback (close, XmNactivateCallback, CancelCallback, (XtPointer) filter_rec);
  497. XtManageChild (close);
  498. XtAddCallback(close, XmNhelpCallback, HelpRequestCB,
  499. HELP_FILTER_DIALOG_STR);
  500. n = 0;
  501. XtSetArg (args[n], XmNlabelString, helpXmString); n++;
  502. XtSetArg (args[n], XmNleftAttachment, XmATTACH_POSITION); n++;
  503. XtSetArg (args[n], XmNleftPosition, 81); n++;
  504. XtSetArg (args[n], XmNrightAttachment, XmATTACH_POSITION); n++;
  505. XtSetArg (args[n], XmNrightPosition, 99); n++;
  506. XtSetArg (args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;
  507. XtSetArg (args[n], XmNtopWidget, separator); n++;
  508. XtSetArg (args[n], XmNtopOffset, 5); n++;
  509. XtSetArg (args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
  510. XtSetArg (args[n], XmNbottomOffset, 5); n++;
  511. XtSetArg (args[n], XmNmarginWidth, 4); n++;
  512. XtSetArg (args[n], XmNmarginHeight, 4); n++;
  513. help = XmCreatePushButtonGadget (form, "help", args, n);
  514. XtManageChild (help);
  515. XtAddCallback(help, XmNactivateCallback, HelpRequestCB,
  516. HELP_FILTER_DIALOG_STR);
  517. XtAddCallback(help, XmNhelpCallback, HelpRequestCB,
  518. HELP_FILTER_DIALOG_STR);
  519. XtSetArg (args[0], XmNcancelButton, close);
  520. XtSetValues (form, args, 1);
  521. /* Fill in our instance structure */
  522. filter_rec->shell = shell;
  523. filter_rec->form = form;
  524. filter_rec->fileNameFilter = fileNameFilter;
  525. filter_rec->hidden = hidden;
  526. filter_rec->scrolled_window = fileTypeScrollWin;
  527. filter_rec->file_window = file_window;
  528. filter_rec->select_all = selectAll;
  529. filter_rec->unselect_all = unselectAll;
  530. filter_rec->label = labelPt2;
  531. filter_rec->cancel = 0x0;
  532. filter_rec->previous_filter_data = NULL;
  533. filter_rec->ok = ok;
  534. filter_rec->apply = apply;
  535. filter_rec->reset = reset;
  536. filter_rec->close = close;
  537. filter_rec->help = help;
  538. /* Set the return values for the dialog widget and dialog instance. */
  539. *return_widget = form;
  540. *dialog = (XtPointer) filter_rec;
  541. }
  542. /************************************************************************
  543. *
  544. * InstallChange
  545. *
  546. ************************************************************************/
  547. static void
  548. InstallChange(
  549. FilterRec *filter_rec,
  550. XtCallbackProc callback,
  551. XtPointer client_data )
  552. {
  553. FilterApply * apply_data;
  554. /* Setup the callback data to be sent to the Ok callback. */
  555. /* This contains the encapsulation callback to invoke upon */
  556. /* the data within the dialog being changed. */
  557. apply_data = (FilterApply *) XtMalloc (sizeof (FilterApply));
  558. apply_data->callback = callback;
  559. apply_data->client_data = client_data;
  560. apply_data->filter_rec = (XtPointer) filter_rec;
  561. filter_rec->apply_data = apply_data;
  562. XtAddCallback (filter_rec->apply, XmNactivateCallback,
  563. ApplyCallback, (XtPointer) apply_data);
  564. XtAddCallback (filter_rec->ok, XmNactivateCallback,
  565. OkCallback, (XtPointer) apply_data);
  566. }
  567. /************************************************************************
  568. *
  569. * InstallClose
  570. *
  571. ************************************************************************/
  572. static void
  573. InstallClose(
  574. FilterRec *filter_rec,
  575. XtCallbackProc callback,
  576. XtPointer client_data )
  577. {
  578. Atom delete_window_atom;
  579. XtAddCallback(filter_rec->close, XmNactivateCallback, callback, client_data);
  580. delete_window_atom = XmInternAtom (XtDisplay(filter_rec->shell), "WM_DELETE_WINDOW", True);
  581. XmRemoveWMProtocols( filter_rec->shell, &delete_window_atom, 1 );
  582. XmAddWMProtocolCallback( filter_rec->shell, delete_window_atom, callback,
  583. (XtPointer) client_data );
  584. }
  585. /************************************************************************
  586. *
  587. * Destroy
  588. *
  589. ************************************************************************/
  590. static void
  591. Destroy(
  592. FilterRec *filter_rec )
  593. {
  594. XtDestroyWidget (filter_rec->shell);
  595. XtFree ((char *) filter_rec->apply_data);
  596. XtFree ((char *) filter_rec);
  597. }
  598. /************************************************************************
  599. *
  600. * GetValues
  601. *
  602. ************************************************************************/
  603. static XtPointer
  604. GetValues(
  605. FilterRec *filter_rec )
  606. {
  607. FilterData * filter_data;
  608. if( filter_rec->cancel
  609. && filter_rec->previous_filter_data )
  610. {
  611. filter_data = filter_rec->previous_filter_data;
  612. filter_rec->previous_filter_data = NULL;
  613. }
  614. else
  615. {
  616. Arg args[4];
  617. /* Allocate and initialize the file filter dialog data. */
  618. filter_data = (FilterData *) XtMalloc (sizeof (FilterData));
  619. filter_data->displayed = True;
  620. XtSetArg (args[0], XmNx, &filter_data->x);
  621. XtSetArg (args[1], XmNy, &filter_data->y);
  622. XtSetArg (args[2], XmNwidth, &filter_data->width);
  623. XtSetArg (args[3], XmNheight, &filter_data->height);
  624. XtGetValues (filter_rec->shell, args, 4);
  625. (void) GetFilterValues (filter_rec, filter_data);
  626. }
  627. filter_rec->cancel = 0x0;
  628. return ((XtPointer) filter_data);
  629. }
  630. /************************************************************************
  631. *
  632. * GetDefaultValues
  633. *
  634. ************************************************************************/
  635. static XtPointer
  636. GetDefaultValues( void )
  637. {
  638. FilterData * filter_data;
  639. /* Allocate and initialize the default file filter dialog data. */
  640. filter_data = (FilterData *) XtMalloc (sizeof (FilterData));
  641. filter_data->displayed = False;
  642. filter_data->x = 0;
  643. filter_data->y = 0;
  644. filter_data->height = 0;
  645. filter_data->width = 0;
  646. filter_data->match_flag = True;
  647. filter_data->filter = XtNewString(".*");
  648. filter_data->show_hidden = False;
  649. filter_data->filetypesFilteredCount = 3;
  650. filter_data->filetypesFiltered = XtNewString(DEFAULT_FILTER);
  651. filter_data->user_data = NULL;
  652. filter_data->count = ReadInFiletypes(filter_data);
  653. return ((XtPointer) filter_data);
  654. }
  655. /************************************************************************
  656. *
  657. * GetResourceValues
  658. *
  659. ************************************************************************/
  660. static XtPointer
  661. GetResourceValues(
  662. XrmDatabase data_base,
  663. char **name_list )
  664. {
  665. FilterData * filter_data;
  666. static Boolean convertersAdded = False;
  667. /* Allocate and get the resources for file filter dialog data. */
  668. filter_data = (FilterData *) XtMalloc (sizeof (FilterData));
  669. filter_data->user_data = NULL;
  670. _DtDialogGetResources (data_base, name_list, FILE_FILTER, (char *)filter_data,
  671. resources, filterClass->resource_count);
  672. /* Create new strings for any string value we read in from our
  673. * resourceDB.
  674. */
  675. filter_data->filter = XtNewString(filter_data->filter);
  676. filter_data->filetypesFiltered = XtNewString(filter_data->filetypesFiltered);
  677. filter_data->count = ReadInFiletypes(filter_data);
  678. return ((XtPointer) filter_data);
  679. }
  680. static FilterData *
  681. CopyFilterData(
  682. FilterData *filter_data )
  683. {
  684. FilterData * CopiedFilterData;
  685. int i;
  686. CopiedFilterData = (FilterData *) XtMalloc (sizeof (FilterData));
  687. CopiedFilterData->displayed = filter_data->displayed;
  688. CopiedFilterData->show_hidden = filter_data->show_hidden;
  689. CopiedFilterData->match_flag = filter_data->match_flag;
  690. CopiedFilterData->filter = XtNewString( filter_data->filter );
  691. CopiedFilterData->filetypesFilteredCount = filter_data->filetypesFilteredCount;
  692. CopiedFilterData->filetypesFiltered = XtNewString( filter_data->filetypesFiltered );
  693. CopiedFilterData->count = filter_data->count;
  694. CopiedFilterData->user_data = (FTData **) XtMalloc(sizeof(FTData *) *
  695. filter_data->count);
  696. for( i = 0; i < filter_data->count; ++i )
  697. {
  698. CopiedFilterData->user_data[i] = (FTData *)XtMalloc(sizeof(FTData));
  699. CopiedFilterData->user_data[i]->filetype =
  700. XtNewString( filter_data->user_data[i]->filetype );
  701. CopiedFilterData->user_data[i]->index =
  702. filter_data->user_data[i]->index;
  703. CopiedFilterData->user_data[i]->selected =
  704. filter_data->user_data[i]->selected;
  705. }
  706. return CopiedFilterData;
  707. }
  708. /************************************************************************
  709. *
  710. * SetValues
  711. *
  712. ************************************************************************/
  713. static void
  714. SetValues(
  715. FilterRec *filter_rec,
  716. FilterData *filter_data )
  717. {
  718. Arg args[20];
  719. int n, i, count;
  720. XmManagerWidget mgr = (XmManagerWidget)filter_rec->file_window;
  721. int num_children = mgr->composite.num_children;
  722. Pixel background_color;
  723. Pixel foreground_color;
  724. Pixel pixmap_background;
  725. Pixel pixmap_foreground;
  726. XmString icon_label;
  727. Widget icon_widget;
  728. Position x;
  729. Dimension max = 0;
  730. XtWidgetGeometry desired, preferred;
  731. FTData *user_data;
  732. PixmapData *pixmapData;
  733. filter_rec->cancel = 0x0;
  734. if( filter_rec->previous_filter_data )
  735. FreeValues( filter_rec->previous_filter_data );
  736. filter_rec->previous_filter_data = CopyFilterData( filter_data );
  737. XmTextFieldSetString (filter_rec->fileNameFilter, filter_data->filter);
  738. if(XmToggleButtonGadgetGetState (*showHiddenMenu))
  739. filter_data->show_hidden = True;
  740. else
  741. filter_data->show_hidden = False;
  742. if(filter_data->match_flag)
  743. XtSetArg (args[0], XmNmenuHistory, filter_rec->hidArray[HIDDEN]);
  744. else
  745. XtSetArg (args[0], XmNmenuHistory, filter_rec->hidArray[SHOWN]);
  746. XtSetValues(filter_rec->hidden, args, 1);
  747. XtSetArg (args[0], XmNbackground, &background_color);
  748. XtSetArg (args[1], XmNforeground, &foreground_color);
  749. XtSetArg (args[2], XmNtopShadowColor, &pixmap_background);
  750. XtSetArg (args[3], XmNbottomShadowColor, &pixmap_foreground);
  751. XtGetValues((Widget)mgr, args, 4);
  752. for (i = 0, x = 5, count = 0; i < filter_data->count; i++)
  753. {
  754. char *ptr;
  755. user_data = filter_data->user_data[i];
  756. if (ptr = (char *)DtDtsDataTypeToAttributeValue(user_data->filetype,
  757. FM_TYPE_LABEL,
  758. NULL))
  759. {
  760. icon_label = XmStringCreateLocalized(ptr);
  761. DtDtsFreeAttributeValue(ptr);
  762. }
  763. else
  764. {
  765. icon_label = XmStringCreateLocalized(user_data->filetype);
  766. }
  767. pixmapData = _DtRetrievePixmapData(user_data->filetype,
  768. NULL,
  769. NULL,
  770. filter_rec->file_window,
  771. LARGE);
  772. n = 0;
  773. XtSetArg (args[n], XmNstring, icon_label); n++;
  774. if (pixmapData)
  775. XtSetArg (args[n], XmNimageName, pixmapData->iconFileName);
  776. else
  777. XtSetArg (args[n], XmNimageName, NULL); n++;
  778. XtSetArg (args[n], XmNunderline, False); n++;
  779. XtSetArg (args[n], XmNpixmapPosition, XmPIXMAP_TOP); n++;
  780. XtSetArg (args[n], XmNbehavior, XmICON_BUTTON); n++;
  781. XtSetArg (args[n], XmNfillMode, XmFILL_PARENT); n++;
  782. XtSetArg (args[n], XmNforeground, foreground_color); n++;
  783. XtSetArg (args[n], XmNarmColor, white_pixel); n++;
  784. if (background_color == white_pixel)
  785. {
  786. XtSetArg (args[n], XmNbackground, white_pixel); n++;
  787. XtSetArg (args[n], XmNpixmapBackground, white_pixel); n++;
  788. XtSetArg (args[n], XmNpixmapForeground, black_pixel); n++;
  789. }
  790. else if (background_color == black_pixel)
  791. {
  792. XtSetArg (args[n], XmNbackground, black_pixel); n++;
  793. XtSetArg (args[n], XmNpixmapBackground, white_pixel); n++;
  794. XtSetArg (args[n], XmNpixmapForeground, black_pixel); n++;
  795. }
  796. else
  797. {
  798. XtSetArg (args[n], XmNbackground, background_color); n++;
  799. XtSetArg (args[n], XmNpixmapBackground, pixmap_background); n++;
  800. XtSetArg (args[n], XmNpixmapForeground, pixmap_foreground); n++;
  801. }
  802. if (i - count < num_children)
  803. {
  804. icon_widget = mgr->composite.children[i - count];
  805. XtSetArg (args[n], XmNx, x); n++;
  806. XtSetArg (args[n], XmNy, 5); n++;
  807. XtSetArg (args[n], XmNuserData, user_data); n++;
  808. XtSetValues(icon_widget, args, n);
  809. XtRemoveAllCallbacks (icon_widget, XmNcallback);
  810. }
  811. else
  812. {
  813. XtSetArg (args[n], XmNx, x); n++;
  814. XtSetArg (args[n], XmNy, 5); n++;
  815. XtSetArg (args[n], XmNshadowThickness, 2); n++;
  816. XtSetArg (args[n], XmNfontList, user_font); n++;
  817. if(keybdFocusPolicy == XmEXPLICIT)
  818. {
  819. XtSetArg (args[n], XmNtraversalOn, True); n++;
  820. }
  821. else
  822. {
  823. XtSetArg (args[n], XmNtraversalOn, False); n++;
  824. XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  825. }
  826. XtSetArg (args[n], XmNborderType, DtNON_RECTANGLE); n++;
  827. if (mgr->composite.num_children == 0)
  828. {
  829. XtSetArg (args[n], XmNuserData, user_data); n++;
  830. icon_widget= _DtCreateIcon ((Widget)mgr, "icon", args, n);
  831. }
  832. else
  833. {
  834. icon_widget = _DtDuplicateIcon((Widget)mgr,
  835. mgr->composite.children[0],
  836. (XmString)args[0].value, (String)args[1].value,
  837. (XtPointer)user_data, (Boolean)args[2].value);
  838. n = 0;
  839. XtSetArg (args[n], XmNx, x); n++;
  840. XtSetArg (args[n], XmNy, 5); n++;
  841. XtSetValues(icon_widget, args, n);
  842. }
  843. XtAddCallback(icon_widget, XmNhelpCallback,
  844. (XtCallbackProc)HelpRequestCB, NULL);
  845. }
  846. XtAddCallback (icon_widget, XmNcallback, NewFileTypeSelected,
  847. (XtPointer)filter_rec);
  848. _DtCheckAndFreePixmapData(user_data->filetype,
  849. filter_rec->file_window,
  850. (DtIconGadget) icon_widget,
  851. pixmapData);
  852. XtManageChild(icon_widget);
  853. x += 5 + icon_widget->core.width;
  854. if (icon_widget->core.height > max)
  855. max = icon_widget->core.height;
  856. XmStringFree(icon_label);
  857. }
  858. for (i = 0, count = 0; i < filter_data->count; i++)
  859. {
  860. user_data = filter_data->user_data[i];
  861. icon_widget = mgr->composite.children[i - count];
  862. if(filter_data->user_data[i]->selected == True)
  863. {
  864. n = 0;
  865. /* Draw the selected icon as selected */
  866. if (background_color == white_pixel)
  867. {
  868. XtSetArg (args[n], XmNbackground, black_pixel); n++;
  869. XtSetArg (args[n], XmNforeground, white_pixel); n++;
  870. }
  871. else
  872. {
  873. XtSetArg (args[n], XmNbackground, white_pixel); n++;
  874. XtSetArg (args[n], XmNforeground, black_pixel); n++;
  875. }
  876. XtSetArg (args[n], XmNpixmapBackground, white_pixel); n++;
  877. XtSetArg (args[n], XmNpixmapForeground, black_pixel); n++;
  878. XtSetArg (args[n], XmNarmColor, white_pixel); n++;
  879. XtSetValues(icon_widget, args, n);
  880. }
  881. }
  882. i -= count;
  883. /* Unmanage any icons left over */
  884. while (i < num_children)
  885. {
  886. XtUnmanageChild(mgr->composite.children[i]);
  887. i++;
  888. }
  889. /* Line up the titles in all of the icons */
  890. num_children = mgr->composite.num_children;
  891. for (i = 0; i < num_children; i++)
  892. {
  893. if (XtIsManaged(mgr->composite.children[i]))
  894. {
  895. if (mgr->composite.children[i]->core.height != max)
  896. {
  897. n = 0;
  898. XtSetArg(args[n], XmNy,
  899. 5 + (max - mgr->composite.children[i]->core.height)); n++;
  900. XtSetValues(mgr->composite.children[i], args, n);
  901. }
  902. }
  903. }
  904. /* Set the height of the scrolled window */
  905. desired.x = filter_rec->scrolled_window->core.x;
  906. desired.y = filter_rec->scrolled_window->core.y;
  907. desired.width = filter_rec->scrolled_window->core.width;
  908. desired.request_mode = (CWWidth);
  909. XtQueryGeometry(filter_rec->scrolled_window, &desired, &preferred);
  910. n = 0;
  911. if (preferred.request_mode & CWWidth)
  912. {
  913. XtSetArg(args[n], XmNwidth, (XtArgVal) preferred.width);
  914. n++;
  915. }
  916. if (preferred.request_mode & CWHeight)
  917. {
  918. XtSetArg(args[n], XmNheight, (XtArgVal) preferred.height);
  919. n++;
  920. }
  921. XtSetValues(filter_rec->scrolled_window, args, n);
  922. }
  923. /************************************************************************
  924. *
  925. * WriteResourceValues
  926. *
  927. ************************************************************************/
  928. static void
  929. WriteResourceValues(
  930. DialogData *values,
  931. int fd,
  932. char **name_list )
  933. {
  934. FilterData * filter_data = (FilterData *) values->data;
  935. FilterRec * filter_rec;
  936. Arg args[2];
  937. /* If the dialog is currently displayed, update the geometry */
  938. /* fields to their current values. */
  939. if (filter_data->displayed == True)
  940. {
  941. _DtGenericUpdateWindowPosition(values);
  942. filter_rec = (FilterRec *) _DtGetDialogInstance (values);
  943. }
  944. _DtDialogPutResources (fd, name_list, FILE_FILTER, values->data,
  945. resources, filterClass->resource_count);
  946. }
  947. /************************************************************************
  948. *
  949. * FreeValues
  950. *
  951. ************************************************************************/
  952. static void
  953. FreeValues(
  954. FilterData *filter_data )
  955. {
  956. int i;
  957. for( i = 0; i < filter_data->count; i++)
  958. {
  959. if(filter_data->user_data[i]->filetype)
  960. XtFree ((char *)filter_data->user_data[i]->filetype);
  961. XtFree ((char *)filter_data->user_data[i]);
  962. }
  963. XtFree ((char *)filter_data->user_data);
  964. XtFree ((char *) filter_data->filter);
  965. XtFree ((char *) filter_data->filetypesFiltered);
  966. XtFree ((char *) filter_data);
  967. }
  968. /************************************************************************
  969. *
  970. * DefaultCallback
  971. *
  972. ************************************************************************/
  973. static void
  974. DefaultCallback(
  975. Widget w,
  976. XtPointer client_data,
  977. XtPointer call_data )
  978. {
  979. FilterRec * filter_rec = (FilterRec *) client_data;
  980. DialogData * dialog_data;
  981. FilterData * filter_data;
  982. int i;
  983. Arg args[1];
  984. /* Get the instance and data for the dialog */
  985. dialog_data = _DtGetInstanceData ((XtPointer)filter_rec);
  986. filter_data = (FilterData *) dialog_data->data;
  987. filter_data->show_hidden = False;
  988. XtSetArg (args[0], XmNmenuHistory, filter_rec->hidArray[HIDDEN]);
  989. XtSetValues(filter_rec->hidden, args, 1);
  990. filter_data->match_flag = True;
  991. XmToggleButtonGadgetSetState(*showHiddenMenu, False, False);
  992. XtFree( filter_data->filter );
  993. filter_data->filter = XtNewString(".*");
  994. filter_data->filetypesFilteredCount = 3;
  995. XtFree( filter_data->filetypesFiltered );
  996. filter_data->filetypesFiltered = XtNewString( DEFAULT_FILTER );
  997. filter_data->count = ReadInFiletypes(filter_data);
  998. /* Display the new type */
  999. SetValues (filter_rec, filter_data);
  1000. }
  1001. /************************************************************************
  1002. *
  1003. * CancelCallback
  1004. *
  1005. ************************************************************************/
  1006. static void
  1007. CancelCallback(
  1008. Widget w,
  1009. XtPointer client_data,
  1010. XtPointer call_data )
  1011. {
  1012. FilterRec * filter_rec = (FilterRec *) client_data;
  1013. filter_rec->cancel = 0x1;
  1014. }
  1015. /************************************************************************
  1016. *
  1017. * OkCallback
  1018. * This is a callback function called when the (Ok) button
  1019. * is pressed. It saves the new file filter data internally and
  1020. * then calls the encapsulations callback function. It then closes
  1021. * the dialog.
  1022. *
  1023. ************************************************************************/
  1024. static void
  1025. OkCallback(
  1026. Widget w,
  1027. XtPointer client_data,
  1028. XtPointer call_data )
  1029. {
  1030. FilterRec * filter_rec = (FilterRec *) ((FilterApply *)client_data)->filter_rec;
  1031. DialogData * dialog_data;
  1032. Widget close = filter_rec->close;
  1033. if(RecheckFlag(NULL,w))
  1034. return;
  1035. else if(RecheckFlag(NULL,close))
  1036. return;
  1037. ApplyCallback(w, client_data, call_data);
  1038. dialog_data = _DtGetInstanceData ((XtPointer)filter_rec);
  1039. ResetFlag(NULL,close);
  1040. XtCallCallbacks(filter_rec->close, XmNactivateCallback,
  1041. (XtPointer)dialog_data);
  1042. }
  1043. /************************************************************************
  1044. *
  1045. * ApplyCallback
  1046. * This is a callback function called when the (Apply) button
  1047. * is pressed. It saves the new file filter data internally and
  1048. * then calls the encapsulations callback function.
  1049. *
  1050. ************************************************************************/
  1051. static void
  1052. ApplyCallback(
  1053. Widget w,
  1054. XtPointer client_data,
  1055. XtPointer call_data )
  1056. {
  1057. FilterRec * filter_rec;
  1058. DialogData * dialog_data;
  1059. FilterData * filter_data;
  1060. FilterData * new_filter_data;
  1061. XmManagerWidget mgr;
  1062. int num_children;
  1063. int i, count;
  1064. Arg args[2];
  1065. filter_rec = (FilterRec *) ((FilterApply *) client_data)->filter_rec;
  1066. dialog_data = _DtGetInstanceData ((XtPointer)filter_rec);
  1067. filter_data = (FilterData *) dialog_data->data;
  1068. new_filter_data = (FilterData *) XtMalloc (sizeof (FilterData));
  1069. mgr = (XmManagerWidget)filter_rec->file_window;
  1070. num_children = mgr->composite.num_children;
  1071. GetFilterValues (filter_rec, new_filter_data);
  1072. FreeValues (filter_data);
  1073. dialog_data->data = (XtPointer) new_filter_data;
  1074. if( filter_rec->previous_filter_data )
  1075. FreeValues( filter_rec->previous_filter_data );
  1076. filter_rec->previous_filter_data = CopyFilterData( new_filter_data );
  1077. /* Need to update 'userData' for each of the icons */
  1078. for (i = 0, count = 0; i < num_children &&
  1079. i + count < new_filter_data->count; i++)
  1080. {
  1081. XtSetArg (args[0], XmNuserData, new_filter_data->user_data[i + count]);
  1082. XtSetValues(mgr->composite.children[i], args, 1);
  1083. }
  1084. (*(((FilterApply *)client_data)->callback)) (w, ((FilterApply *)client_data)->client_data, NULL);
  1085. }
  1086. /************************************************************************
  1087. *
  1088. * GetFilterValues
  1089. * Update the current file filter values within the data structure
  1090. * from the current toggle button values.
  1091. *
  1092. ************************************************************************/
  1093. static Boolean
  1094. GetFilterValues(
  1095. FilterRec *filter_rec,
  1096. FilterData *filter_data )
  1097. {
  1098. int i;
  1099. Widget menuHistory;
  1100. Arg args[2];
  1101. DialogData * dialog_data;
  1102. FilterData * old_filter_data;
  1103. filter_data->displayed = True;
  1104. filter_data->filter = XmTextFieldGetString (filter_rec->fileNameFilter);
  1105. XmToggleButtonGadgetSetState(*showHiddenMenu, False, False);
  1106. filter_data->show_hidden = False;
  1107. XtSetArg (args[0], XmNmenuHistory, &menuHistory);
  1108. XtGetValues (filter_rec->hidden, args, 1);
  1109. if(menuHistory == filter_rec->hidArray[HIDDEN])
  1110. filter_data->match_flag = True;
  1111. else
  1112. filter_data->match_flag = False;
  1113. filter_data->filetypesFiltered = NULL;
  1114. filter_data->filetypesFilteredCount = 0;
  1115. dialog_data = _DtGetInstanceData ((XtPointer)filter_rec);
  1116. if(dialog_data != NULL)
  1117. {
  1118. old_filter_data = (FilterData *) dialog_data->data;
  1119. filter_data->count = old_filter_data->count;
  1120. filter_data->user_data = (FTData **) XtMalloc(sizeof(FTData *) *
  1121. filter_data->count);
  1122. for( i = 0; i < filter_data->count; i++)
  1123. {
  1124. /* Copy current value from the old dialog values */
  1125. filter_data->user_data[i] = (FTData *)XtMalloc(sizeof(FTData));
  1126. filter_data->user_data[i]->filetype =
  1127. XtNewString(old_filter_data->user_data[i]->filetype);
  1128. filter_data->user_data[i]->index =
  1129. old_filter_data->user_data[i]->index;
  1130. filter_data->user_data[i]->selected =
  1131. old_filter_data->user_data[i]->selected;
  1132. if((filter_data->user_data[i]->selected == True &&
  1133. filter_data->match_flag) ||
  1134. (filter_data->user_data[i]->selected == False &&
  1135. !filter_data->match_flag))
  1136. {
  1137. if(filter_data->filetypesFiltered == NULL)
  1138. {
  1139. filter_data->filetypesFiltered =
  1140. XtNewString(filter_data->user_data[i]->filetype);
  1141. }
  1142. else
  1143. {
  1144. filter_data->filetypesFiltered = (char *)XtRealloc(
  1145. (char *)filter_data->filetypesFiltered,
  1146. strlen(filter_data->filetypesFiltered) +
  1147. strlen(filter_data->user_data[i]->filetype) + 2);
  1148. strcat(filter_data->filetypesFiltered, ",");
  1149. strcat(filter_data->filetypesFiltered,
  1150. filter_data->user_data[i]->filetype);
  1151. }
  1152. filter_data->filetypesFilteredCount++;
  1153. }
  1154. }
  1155. return (True);
  1156. }
  1157. return(False);
  1158. }
  1159. void
  1160. ShowHiddenFiles (
  1161. Widget w,
  1162. XtPointer client_data,
  1163. XtPointer callback)
  1164. {
  1165. FilterData *filter_data;
  1166. FileMgrData *file_mgr_data;
  1167. FileMgrRec *file_mgr_rec;
  1168. FilterRec *filter_rec;
  1169. DialogData *dialog_data;
  1170. Widget mbar;
  1171. Arg args[1];
  1172. if ((XtArgVal)client_data == FM_POPUP)
  1173. mbar = XtParent(w);
  1174. else
  1175. mbar = (Widget)XmGetPostedFromWidget(XtParent(w));
  1176. XmUpdateDisplay (w);
  1177. XtSetArg(args[0], XmNuserData, &file_mgr_rec);
  1178. XtGetValues(mbar, args, 1);
  1179. dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
  1180. file_mgr_data = (FileMgrData *) dialog_data->data;
  1181. filter_data = (FilterData *)(file_mgr_data->filter_active->data);
  1182. if (file_mgr_data->show_hid_enabled)
  1183. {
  1184. filter_data->show_hidden = False;
  1185. file_mgr_data->show_hid_enabled = False;
  1186. }
  1187. else
  1188. {
  1189. filter_data->show_hidden = True;
  1190. file_mgr_data->show_hid_enabled = True;
  1191. }
  1192. filter_rec = (FilterRec *)_DtGetDialogInstance( file_mgr_data->filter_edit );
  1193. /* Refilter the contents of the current directory */
  1194. FileMgrRedisplayFiles (file_mgr_rec, file_mgr_data, False);
  1195. }
  1196. int
  1197. ReadInFiletypes(
  1198. FilterData *filter_data)
  1199. {
  1200. char **file_types;
  1201. int i;
  1202. int count = 0;
  1203. int count_size = 0;
  1204. FTData *user_data;
  1205. char *filtered_types, *file_type;
  1206. int j;
  1207. if (filter_data->user_data)
  1208. {
  1209. for(i=0; i<filter_data->count; i++)
  1210. {
  1211. XtFree(filter_data->user_data[i]->filetype);
  1212. XtFree((char *)filter_data->user_data[i]);
  1213. }
  1214. XtFree((char *)filter_data->user_data);
  1215. filter_data->user_data = NULL;
  1216. filter_data->count = 0;
  1217. }
  1218. file_types = (char **) DtDtsDataTypeNames();
  1219. i = 0;
  1220. while(file_types[i])
  1221. {
  1222. /* filter out invisible types and actions */
  1223. if((_DtCheckForDataTypeProperty(file_types[i], "invisible")) ||
  1224. (DtDtsDataTypeIsAction(file_types[i])))
  1225. {
  1226. i++;
  1227. continue;
  1228. }
  1229. if (count == count_size)
  1230. {
  1231. count_size += 10;
  1232. filter_data->user_data =
  1233. (FTData **) XtRealloc ((char *)filter_data->user_data,
  1234. sizeof (FTData *) * count_size);
  1235. }
  1236. user_data = (FTData *)XtMalloc(sizeof(FTData));
  1237. user_data->index = count;
  1238. user_data->selected = False;
  1239. user_data->filetype = XtNewString(file_types[i]);
  1240. filter_data->user_data[count] = user_data;
  1241. count++;
  1242. i++;
  1243. }
  1244. DtDtsFreeDataTypeNames(file_types);
  1245. qsort( filter_data->user_data, count, sizeof( FTData *), (int (*)())FileTypeAscending );
  1246. filtered_types = filter_data->filetypesFiltered;
  1247. for(i = 0; i < filter_data->filetypesFilteredCount; i++)
  1248. {
  1249. file_type = filtered_types;
  1250. filtered_types = DtStrchr(filtered_types, ',');
  1251. if(filter_data->filetypesFilteredCount - 1 != i)
  1252. *filtered_types = '\0';
  1253. for(j = 0; j < count; j++)
  1254. {
  1255. if(strcmp(file_type, filter_data->user_data[j]->filetype) == 0)
  1256. {
  1257. filter_data->user_data[j]->selected = True;
  1258. break;
  1259. }
  1260. }
  1261. if(filter_data->filetypesFilteredCount - 1 != i)
  1262. {
  1263. *filtered_types = ',';
  1264. filtered_types++;
  1265. }
  1266. }
  1267. if(!filter_data->match_flag)
  1268. {
  1269. for(j = 0; j < count; j++)
  1270. {
  1271. if(filter_data->user_data[j]->selected == True)
  1272. filter_data->user_data[j]->selected = False;
  1273. else
  1274. filter_data->user_data[j]->selected = True;
  1275. }
  1276. }
  1277. return(count);
  1278. }
  1279. /*
  1280. * Whenever the database files are reread, we must update the filter
  1281. * values, since the indices of the filetypes may have changed.
  1282. */
  1283. void
  1284. UpdateFilterAfterDBReread (
  1285. DialogData * dialog_data )
  1286. {
  1287. int i, count;
  1288. int num_children;
  1289. XmManagerWidget mgr;
  1290. Arg args[2];
  1291. FilterData * new_filter_data;
  1292. FilterData * filter_data;
  1293. FilterRec * filter_rec;
  1294. Boolean result;
  1295. filter_data = (FilterData *) dialog_data->data;
  1296. new_filter_data = (FilterData *) XtMalloc (sizeof (FilterData));
  1297. if (filter_rec = (FilterRec *) _DtGetDialogInstance(dialog_data))
  1298. {
  1299. /* Dialog is posted */
  1300. result = GetFilterValues (filter_rec, new_filter_data);
  1301. if( result )
  1302. {
  1303. XtFree(new_filter_data->filetypesFiltered);
  1304. new_filter_data->filetypesFiltered =
  1305. XtNewString(filter_data->filetypesFiltered);
  1306. new_filter_data->filetypesFilteredCount =
  1307. filter_data->filetypesFilteredCount;
  1308. FreeValues (filter_data);
  1309. dialog_data->data = (XtPointer) new_filter_data;
  1310. filter_data = new_filter_data;
  1311. }
  1312. }
  1313. /* Reload the filetype information */
  1314. filter_data->count = ReadInFiletypes(filter_data);
  1315. if (filter_rec && result)
  1316. {
  1317. /* Need to update 'userData' for each of the icons */
  1318. mgr = (XmManagerWidget)filter_rec->file_window;
  1319. num_children = mgr->composite.num_children;
  1320. for (i = 0, count = 0; i < num_children &&
  1321. i + count < filter_data->count; i++)
  1322. {
  1323. XtSetArg (args[0], XmNuserData, new_filter_data->user_data[i]);
  1324. XtSetValues(mgr->composite.children[i], args, 1);
  1325. }
  1326. /* Display the new type */
  1327. SetValues (filter_rec, filter_data);
  1328. }
  1329. }
  1330. static void
  1331. filterTypeChanged(
  1332. Widget w,
  1333. XtPointer client_data,
  1334. XtPointer call_data )
  1335. {
  1336. Widget menuHistory;
  1337. FilterRec * filter_rec = (FilterRec *) client_data;
  1338. DialogData * dialog_data;
  1339. FilterData * filter_data;
  1340. Arg args[2];
  1341. XmString label_string;
  1342. /* Get the instance and data for the dialog */
  1343. dialog_data = _DtGetInstanceData ((XtPointer)filter_rec);
  1344. filter_data = (FilterData *) dialog_data->data;
  1345. XtSetArg (args[0], XmNmenuHistory, &menuHistory);
  1346. XtGetValues (filter_rec->hidden, args, 1);
  1347. if(menuHistory == filter_rec->hidArray[HIDDEN])
  1348. {
  1349. filter_data->match_flag = True;
  1350. label_string = XmStringCreateLocalized (((char *)GETMESSAGE(13,26,
  1351. "Also hide (Optional): ")));
  1352. }
  1353. else
  1354. {
  1355. filter_data->match_flag = False;
  1356. label_string = XmStringCreateLocalized (((char *)GETMESSAGE(13,29,
  1357. "Also show (Optional): ")));
  1358. }
  1359. XtSetArg (args[0], XmNlabelString, label_string);
  1360. XtSetValues( filter_rec->label, args, 1 );
  1361. XmStringFree( label_string );
  1362. XmUpdateDisplay( filter_rec->label );
  1363. }
  1364. static int
  1365. FileTypeAscending(
  1366. FTData **t1,
  1367. FTData **t2 )
  1368. {
  1369. return strcmp( (*t1)->filetype, (*t2)->filetype );
  1370. }
  1371. static void
  1372. SelectAllFilter(
  1373. Widget w,
  1374. XEvent *event,
  1375. String *params,
  1376. Cardinal *num_params )
  1377. {
  1378. FilterRec * filterRec;
  1379. sscanf( params[0], "%p", (void **) &filterRec );
  1380. SelectAllFileTypes( w, (XtPointer)filterRec, NULL );
  1381. return ;
  1382. }
  1383. static void
  1384. DeselectAllFilter(
  1385. Widget w,
  1386. XEvent *event,
  1387. String *params,
  1388. Cardinal *num_params )
  1389. {
  1390. FilterRec * filterRec;
  1391. sscanf( params[0], "%p", (void **) &filterRec );
  1392. UnselectAllFileTypes( w, (XtPointer)filterRec, NULL );
  1393. return ;
  1394. }