FilterP.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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: FilterP.c /main/4 1995/11/02 14:39:12 rswiston $ */
  24. /************************************<+>*************************************
  25. ****************************************************************************
  26. *
  27. * FILE: FilterP.c
  28. *
  29. * COMPONENT_NAME: Desktop File Manager (dtfile)
  30. *
  31. * Description: Processing functions for the file filter dialog
  32. *
  33. * FUNCTIONS: FilterChange
  34. * FilterClose
  35. * NewFileTypeSelected
  36. * SelectAllFileTypes
  37. * ShowFilterDialog
  38. * UnselectAllFileTypes
  39. *
  40. * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
  41. * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
  42. * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
  43. * (c) Copyright 1993, 1994, 1995 Novell, Inc.
  44. *
  45. ****************************************************************************
  46. ************************************<+>*************************************/
  47. #include <Xm/XmP.h>
  48. #include <Xm/Xm.h>
  49. #include <Xm/RowColumn.h>
  50. #include <Dt/Icon.h>
  51. #include <Dt/HourGlass.h>
  52. #include <Dt/FileM.h>
  53. #include "Encaps.h"
  54. #include "SharedProcs.h"
  55. #include "FileMgr.h"
  56. #include "Desktop.h"
  57. #include "Main.h"
  58. #include "Common.h"
  59. #include "Filter.h"
  60. /******** Static Function Declarations ********/
  61. static void FilterChange(
  62. XtPointer client_data,
  63. DialogData *old_dialog_data,
  64. DialogData *new_dialog_data,
  65. XtPointer call_data) ;
  66. static void FilterClose(
  67. XtPointer client_data,
  68. DialogData *old_dialog_data,
  69. DialogData *new_dialog_data) ;
  70. /******** End Static Function Declarations ********/
  71. /************************************************************************
  72. *
  73. * ShowFilterDialog
  74. * Callback functions invoked from the File Filter ... menu
  75. * item. This function displays the file filter dialog.
  76. *
  77. ************************************************************************/
  78. void
  79. ShowFilterDialog(
  80. Widget w,
  81. XtPointer client_data,
  82. XtPointer callback )
  83. {
  84. FileMgrRec * file_mgr_rec;
  85. DialogData * dialog_data;
  86. FileMgrData * file_mgr_data;
  87. FilterRec * filter_rec;
  88. Arg args[1];
  89. Widget mbar;
  90. char *tmpStr, *tempStr;
  91. /* Set the menu item to insensitive to prevent multiple */
  92. /* dialogs from being posted and get the area under the */
  93. /* menu pane redrawn. */
  94. if (w)
  95. {
  96. mbar = XmGetPostedFromWidget(XtParent(w));
  97. XmUpdateDisplay (w);
  98. XtSetArg(args[0], XmNuserData, &file_mgr_rec);
  99. XtGetValues(mbar, args, 1);
  100. /* Ignore accelerators when we're insensitive */
  101. if ((file_mgr_rec->menuStates & FILTER) == 0)
  102. {
  103. XSetInputFocus(XtDisplay(w),
  104. XtWindow(file_mgr_rec->filterBtn_child),
  105. RevertToParent, CurrentTime);
  106. return;
  107. }
  108. }
  109. else
  110. {
  111. /* Done only during a restore session */
  112. file_mgr_rec = (FileMgrRec *)client_data;
  113. }
  114. /* Ignore accelerators received after we're unposted */
  115. if ((dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec)) == NULL)
  116. return;
  117. file_mgr_data = (FileMgrData *) dialog_data->data;
  118. file_mgr_rec->menuStates &= ~FILTER;
  119. _DtTurnOnHourGlass (file_mgr_rec->shell);
  120. _DtShowDialog (file_mgr_rec->shell, NULL, (XtPointer)file_mgr_rec,
  121. file_mgr_data->filter_edit, FilterChange,
  122. (XtPointer)file_mgr_rec, FilterClose, (XtPointer)file_mgr_rec,
  123. NULL, False, False, NULL, NULL);
  124. filter_rec = (FilterRec *)_DtGetDialogInstance(file_mgr_data->filter_edit);
  125. if(file_mgr_data->title != NULL &&
  126. strcmp(file_mgr_data->helpVol, DTFILE_HELP_NAME) != 0)
  127. {
  128. tmpStr = (GETMESSAGE(13,19, "Set Filter Options"));
  129. tempStr = (char *)XtMalloc(strlen(tmpStr) +
  130. strlen(file_mgr_data->title) + 5);
  131. sprintf(tempStr, "%s - %s", file_mgr_data->title, tmpStr);
  132. }
  133. else
  134. {
  135. tmpStr = (GETMESSAGE(13,24, "File Manager - Set Filter Options"));
  136. tempStr = XtNewString(tmpStr);
  137. }
  138. XtSetArg (args[0], XmNtitle, tempStr);
  139. XtSetValues (filter_rec->shell, args, 1);
  140. XtFree(tempStr);
  141. file_mgr_rec->filterBtn_child=filter_rec->shell;
  142. _DtTurnOffHourGlass (file_mgr_rec->shell);
  143. {
  144. Widget hb = NULL;
  145. if( XtIsRealized( filter_rec->shell ) )
  146. {
  147. /* In order for the set increment to work,
  148. the top level shell has to be realized.
  149. This seemed to be a good place for it.
  150. */
  151. XtSetArg( args[0], XmNhorizontalScrollBar, &hb );
  152. XtGetValues( filter_rec->scrolled_window, args, 1 );
  153. if( hb )
  154. {
  155. XtSetArg( args[0], XmNincrement, 40 );
  156. XtSetValues( hb, args, 1 );
  157. }
  158. }
  159. }
  160. }
  161. /************************************************************************
  162. *
  163. * FilterChange
  164. * Callback functions invoked from the file filter dialog's
  165. * apply button being pressed. This function updates and redisplays
  166. * the current set of objects being viewed.
  167. *
  168. ************************************************************************/
  169. static void
  170. FilterChange(
  171. XtPointer client_data,
  172. DialogData *old_dialog_data,
  173. DialogData *new_dialog_data,
  174. XtPointer call_data )
  175. {
  176. FileMgrRec * file_mgr_rec = (FileMgrRec *) client_data;
  177. DialogData * dialog_data;
  178. FileMgrData * file_mgr_data;
  179. FilterData * filter_data;
  180. XtPointer save_data;
  181. dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
  182. file_mgr_data = (FileMgrData *) dialog_data->data;
  183. /*
  184. * Replace the active values with those just applied in the dialog,
  185. * and then free up the old active values.
  186. */
  187. save_data = file_mgr_data->filter_active->data;
  188. file_mgr_data->filter_active->data = new_dialog_data->data;
  189. new_dialog_data->data = save_data;
  190. _DtFreeDialogData (new_dialog_data);
  191. filter_data = (FilterData *) file_mgr_data->filter_active->data;
  192. filter_data->displayed = False;
  193. /* Refilter the contents of the current directory */
  194. FileMgrRedisplayFiles (file_mgr_rec, file_mgr_data, False);
  195. }
  196. /************************************************************************
  197. *
  198. * FilterClose
  199. * Callback function invoked from the file filter dialog's close
  200. * button. This function resensitizes the menu item, and saves the
  201. * interim dialog values.
  202. *
  203. ************************************************************************/
  204. static void
  205. FilterClose(
  206. XtPointer client_data,
  207. DialogData *old_dialog_data,
  208. DialogData *new_dialog_data )
  209. {
  210. FileMgrRec * file_mgr_rec = (FileMgrRec *) client_data;
  211. XtPointer save_data;
  212. /* Free up the old interim values, and save the new ones */
  213. save_data = old_dialog_data->data;
  214. old_dialog_data->data = new_dialog_data->data;
  215. new_dialog_data->data = save_data;
  216. _DtFreeDialogData (new_dialog_data);
  217. /* Resensitize the associated menubutton */
  218. file_mgr_rec->menuStates |= FILTER;
  219. }
  220. void
  221. NewFileTypeSelected (
  222. Widget w,
  223. XtPointer client_data,
  224. XtPointer callback)
  225. {
  226. XmAnyCallbackStruct * callback_data = (XmAnyCallbackStruct *) callback;
  227. Arg args[10];
  228. Pixel background_color;
  229. Pixel foreground_color;
  230. Pixel pixmap_background;
  231. FilterRec *filter_rec;
  232. XmManagerWidget mgr;
  233. FTData * user_data;
  234. filter_rec = (FilterRec *)client_data;
  235. mgr = (XmManagerWidget)filter_rec->file_window;
  236. if (callback_data->reason == XmCR_ACTIVATE)
  237. {
  238. XtSetArg (args[0], XmNbackground, &background_color);
  239. XtSetArg (args[1], XmNforeground, &foreground_color);
  240. XtSetArg (args[2], XmNtopShadowColor, &pixmap_background);
  241. XtGetValues ((Widget)mgr, args, 3);
  242. XtSetArg(args[0], XmNuserData, &user_data);
  243. XtGetValues(w, args, 1);
  244. if(user_data->selected)
  245. {
  246. /* Draw the old selected icon in normal state */
  247. XtSetArg (args[0], XmNpixmapForeground, black_pixel);
  248. XtSetArg (args[1], XmNforeground, foreground_color);
  249. XtSetArg (args[2], XmNarmColor, white_pixel);
  250. if (background_color == white_pixel)
  251. {
  252. XtSetArg (args[3], XmNbackground, white_pixel);
  253. XtSetArg (args[4], XmNpixmapBackground, white_pixel);
  254. }
  255. else if (background_color == black_pixel)
  256. {
  257. XtSetArg (args[3], XmNbackground, black_pixel);
  258. XtSetArg (args[4], XmNpixmapBackground, white_pixel);
  259. }
  260. else
  261. {
  262. XtSetArg (args[3], XmNbackground, background_color);
  263. XtSetArg (args[4], XmNpixmapBackground, pixmap_background);
  264. }
  265. XtSetValues(w, args, 5);
  266. user_data->selected = False;
  267. }
  268. else
  269. {
  270. /* Draw the selected icon as selected */
  271. if (background_color == white_pixel)
  272. {
  273. XtSetArg(args[0], XmNbackground, black_pixel);
  274. XtSetArg(args[1], XmNforeground, white_pixel);
  275. }
  276. else if (background_color == black_pixel)
  277. {
  278. XtSetArg(args[0], XmNbackground, white_pixel);
  279. XtSetArg(args[1], XmNforeground, black_pixel);
  280. }
  281. else
  282. {
  283. XtSetArg(args[0], XmNbackground, white_pixel);
  284. XtSetArg(args[1], XmNforeground, black_pixel);
  285. }
  286. XtSetArg(args[2], XmNpixmapBackground, white_pixel);
  287. XtSetArg(args[3], XmNpixmapForeground, black_pixel);
  288. XtSetArg(args[4], XmNarmColor, white_pixel);
  289. XtSetValues(w, args, 5);
  290. user_data->selected = True;
  291. }
  292. }
  293. else if (callback_data->reason == XmCR_HIGHLIGHT)
  294. DrawHighlight(w, NULL, NULL, NOT_DESKTOP);
  295. else if (callback_data->reason == XmCR_UNHIGHLIGHT)
  296. DrawUnhighlight(w, NOT_DESKTOP);
  297. else if (callback_data->reason == XmCR_SHADOW)
  298. DrawShadowTh(w, NULL, NOT_DESKTOP);
  299. }
  300. void
  301. SelectAllFileTypes (
  302. Widget w,
  303. XtPointer client_data,
  304. XtPointer callback)
  305. {
  306. Arg args[6];
  307. FilterRec *filter_rec;
  308. Pixel background_color;
  309. XmManagerWidget mgr;
  310. FTData * user_data;
  311. int num_of_filetypes, i;
  312. filter_rec = (FilterRec *)client_data;
  313. mgr = (XmManagerWidget)filter_rec->file_window;
  314. num_of_filetypes = mgr->composite.num_children;
  315. XtSetArg (args[0], XmNbackground, &background_color);
  316. XtGetValues ((Widget)mgr, args, 1);
  317. for(i = 0; i < num_of_filetypes; i++)
  318. {
  319. XtSetArg(args[0], XmNuserData, &user_data);
  320. XtGetValues(mgr->composite.children[i], args, 1);
  321. if(!user_data->selected)
  322. {
  323. /* Draw the selected icon as selected */
  324. if (background_color == white_pixel)
  325. {
  326. XtSetArg(args[0], XmNbackground, black_pixel);
  327. XtSetArg(args[1], XmNforeground, white_pixel);
  328. }
  329. else if (background_color == black_pixel)
  330. {
  331. XtSetArg(args[0], XmNbackground, white_pixel);
  332. XtSetArg(args[1], XmNforeground, black_pixel);
  333. }
  334. else
  335. {
  336. XtSetArg(args[0], XmNbackground, white_pixel);
  337. XtSetArg(args[1], XmNforeground, black_pixel);
  338. }
  339. XtSetArg(args[2], XmNpixmapBackground, white_pixel);
  340. XtSetArg(args[3], XmNpixmapForeground, black_pixel);
  341. XtSetArg(args[4], XmNarmColor, white_pixel);
  342. XtSetValues(mgr->composite.children[i], args, 5);
  343. user_data->selected = True;
  344. }
  345. }
  346. }
  347. void
  348. UnselectAllFileTypes (
  349. Widget w,
  350. XtPointer client_data,
  351. XtPointer callback)
  352. {
  353. Arg args[6];
  354. FilterRec *filter_rec;
  355. Pixel background_color;
  356. Pixel foreground_color;
  357. Pixel pixmap_background;
  358. XmManagerWidget mgr;
  359. FTData * user_data;
  360. int num_of_filetypes, i;
  361. filter_rec = (FilterRec *)client_data;
  362. mgr = (XmManagerWidget)filter_rec->file_window;
  363. num_of_filetypes = mgr->composite.num_children;
  364. XtSetArg (args[0], XmNbackground, &background_color);
  365. XtSetArg (args[1], XmNforeground, &foreground_color);
  366. XtSetArg (args[2], XmNtopShadowColor, &pixmap_background);
  367. XtGetValues ((Widget)mgr, args, 3);
  368. for(i = 0; i < num_of_filetypes; i++)
  369. {
  370. XtSetArg(args[0], XmNuserData, &user_data);
  371. XtGetValues(mgr->composite.children[i], args, 1);
  372. if(user_data->selected)
  373. {
  374. /* Draw the old selected icon in normal state */
  375. XtSetArg (args[0], XmNpixmapForeground, black_pixel);
  376. XtSetArg (args[1], XmNforeground, foreground_color);
  377. XtSetArg (args[2], XmNarmColor, white_pixel);
  378. if (background_color == white_pixel)
  379. {
  380. XtSetArg (args[3], XmNbackground, white_pixel);
  381. XtSetArg (args[4], XmNpixmapBackground, white_pixel);
  382. }
  383. else if (background_color == black_pixel)
  384. {
  385. XtSetArg (args[3], XmNbackground, black_pixel);
  386. XtSetArg (args[4], XmNpixmapBackground, white_pixel);
  387. }
  388. else
  389. {
  390. XtSetArg (args[3], XmNbackground, background_color);
  391. XtSetArg (args[4], XmNpixmapBackground, pixmap_background);
  392. }
  393. XtSetValues(mgr->composite.children[i], args, 5);
  394. user_data->selected = False;
  395. }
  396. }
  397. }