fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_File_Icon2.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Fl_File_Icon system icon routines.
5 //
6 // KDE icon code donated by Maarten De Boer.
7 //
8 // Copyright 1999-2010 by Michael Sweet.
9 //
10 // This library is free software. Distribution and use rights are outlined in
11 // the file "COPYING" which should have been included with this file. If this
12 // file is missing or damaged, see the license at:
13 //
14 // http://www.fltk.org/COPYING.php
15 //
16 // Please report all bugs and problems on the following page:
17 //
18 // http://www.fltk.org/str.php
19 //
20 // Contents:
21 //
22 // Fl_File_Icon::load() - Load an icon file...
23 // Fl_File_Icon::load_fti() - Load an SGI-format FTI file...
24 // Fl_File_Icon::load_image() - Load an image icon file...
25 // Fl_File_Icon::load_system_icons() - Load the standard system icons/filetypes.
26 // load_kde_icons() - Load KDE icon files.
27 // load_kde_mimelnk() - Load a KDE "mimelnk" file.
28 // kde_to_fltk_pattern() - Convert a KDE pattern to a FLTK pattern.
29 // get_kde_val() - Get a KDE value.
30 //
31 
32 //
33 // Include necessary header files...
34 //
35 
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <FL/fl_utf8.h>
39 #include "flstring.h"
40 #include <ctype.h>
41 #include <errno.h>
42 #include <FL/math.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #if defined(WIN32) && !defined(__CYGWIN__)
46 # include <io.h>
47 # define F_OK 0
48 // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
49 // on Windows, which is supposed to be POSIX compliant...
50 # define access _access
51 #else
52 # include <unistd.h>
53 #endif // WIN32
54 
55 #include <FL/Fl_File_Icon.H>
56 #include <FL/Fl_Shared_Image.H>
57 #include <FL/Fl_Widget.H>
58 #include <FL/fl_draw.H>
59 #include <FL/filename.H>
60 
61 
62 //
63 // Define missing POSIX/XPG4 macros as needed...
64 //
65 
66 #ifndef S_ISDIR
67 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
68 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
69 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
70 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
71 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
72 #endif /* !S_ISDIR */
73 
74 
75 //
76 // Local functions...
77 //
78 
79 static void load_kde_icons(const char *directory, const char *icondir);
80 static void load_kde_mimelnk(const char *filename, const char *icondir);
81 static char *kde_to_fltk_pattern(const char *kdepattern);
82 static char *get_kde_val(char *str, const char *key);
83 
84 
85 //
86 // Local globals...
87 //
88 
89 static const char *kdedir = NULL;
90 
91 
96 void
97 Fl_File_Icon::load(const char *f) // I - File to read from
98 {
99  int i; // Load status...
100  const char *ext; // File extension
101 
102 
103  ext = fl_filename_ext(f);
104 
105  if (ext && strcmp(ext, ".fti") == 0)
106  i = load_fti(f);
107  else
108  i = load_image(f);
109 
110  if (i)
111  {
112  Fl::warning("Fl_File_Icon::load(): Unable to load icon file \"%s\".", f);
113  return;
114  }
115 }
116 
117 
123 int // O - 0 on success, non-zero on error
124 Fl_File_Icon::load_fti(const char *fti) // I - File to read from
125 {
126  FILE *fp; // File pointer
127  int ch; // Current character
128  char command[255], // Command string ("vertex", etc.)
129  params[255], // Parameter string ("10.0,20.0", etc.)
130  *ptr; // Pointer into strings
131  int outline; // Outline polygon
132 
133 
134  // Try to open the file...
135  if ((fp = fl_fopen(fti, "rb")) == NULL)
136  {
137  Fl::error("Fl_File_Icon::load_fti(): Unable to open \"%s\" - %s",
138  fti, strerror(errno));
139  return -1;
140  }
141 
142  // Read the entire file, adding data as needed...
143  outline = 0;
144 
145  while ((ch = getc(fp)) != EOF)
146  {
147  // Skip whitespace
148  if (isspace(ch))
149  continue;
150 
151  // Skip comments starting with "#"...
152  if (ch == '#')
153  {
154  while ((ch = getc(fp)) != EOF)
155  if (ch == '\n')
156  break;
157 
158  if (ch == EOF)
159  break;
160  else
161  continue;
162  }
163 
164  // OK, this character better be a letter...
165  if (!isalpha(ch))
166  {
167  Fl::error("Fl_File_Icon::load_fti(): Expected a letter at file position %ld (saw '%c')",
168  ftell(fp) - 1, ch);
169  break;
170  }
171 
172  // Scan the command name...
173  ptr = command;
174  *ptr++ = ch;
175 
176  while ((ch = getc(fp)) != EOF)
177  {
178  if (ch == '(')
179  break;
180  else if (ptr < (command + sizeof(command) - 1))
181  *ptr++ = ch;
182  }
183 
184  *ptr++ = '\0';
185 
186  // Make sure we stopped on a parenthesis...
187  if (ch != '(')
188  {
189  Fl::error("Fl_File_Icon::load_fti(): Expected a ( at file position %ld (saw '%c')",
190  ftell(fp) - 1, ch);
191  break;
192  }
193 
194  // Scan the parameters...
195  ptr = params;
196 
197  while ((ch = getc(fp)) != EOF)
198  {
199  if (ch == ')')
200  break;
201  else if (ptr < (params + sizeof(params) - 1))
202  *ptr++ = ch;
203  }
204 
205  *ptr++ = '\0';
206 
207  // Make sure we stopped on a parenthesis...
208  if (ch != ')')
209  {
210  Fl::error("Fl_File_Icon::load_fti(): Expected a ) at file position %ld (saw '%c')",
211  ftell(fp) - 1, ch);
212  break;
213  }
214 
215  // Make sure the next character is a semicolon...
216  if ((ch = getc(fp)) != ';')
217  {
218  Fl::error("Fl_File_Icon::load_fti(): Expected a ; at file position %ld (saw '%c')",
219  ftell(fp) - 1, ch);
220  break;
221  }
222 
223  // Now process the command...
224  if (strcmp(command, "color") == 0)
225  {
226  // Set the color; for negative colors blend the two primaries to
227  // produce a composite color. Also, the following symbolic color
228  // names are understood:
229  //
230  // name FLTK color
231  // ------------- ----------
232  // iconcolor FL_ICON_COLOR; mapped to the icon color in
233  // Fl_File_Icon::draw()
234  // shadowcolor FL_DARK3
235  // outlinecolor FL_BLACK
236  if (strcmp(params, "iconcolor") == 0)
238  else if (strcmp(params, "shadowcolor") == 0)
240  else if (strcmp(params, "outlinecolor") == 0)
242  else
243  {
244  int c = atoi(params); // Color value
245 
246 
247  if (c < 0)
248  {
249  // Composite color; compute average...
250  c = -c;
252  (Fl_Color)(c & 15), 0.5f));
253  }
254  else
255  add_color((Fl_Color)c);
256  }
257  }
258  else if (strcmp(command, "bgnline") == 0)
259  add(LINE);
260  else if (strcmp(command, "bgnclosedline") == 0)
261  add(CLOSEDLINE);
262  else if (strcmp(command, "bgnpolygon") == 0)
263  add(POLYGON);
264  else if (strcmp(command, "bgnoutlinepolygon") == 0)
265  {
267  outline = add(0) - data_;
268  add(0);
269  }
270  else if (strcmp(command, "endoutlinepolygon") == 0 && outline)
271  {
272  unsigned cval; // Color value
273 
274  // Set the outline color; see above for valid values...
275  if (strcmp(params, "iconcolor") == 0)
276  cval = FL_ICON_COLOR;
277  else if (strcmp(params, "shadowcolor") == 0)
278  cval = FL_DARK3;
279  else if (strcmp(params, "outlinecolor") == 0)
280  cval = FL_BLACK;
281  else
282  {
283  int c = atoi(params); // Color value
284 
285 
286  if (c < 0)
287  {
288  // Composite color; compute average...
289  c = -c;
290  cval = fl_color_average((Fl_Color)(c >> 4), (Fl_Color)(c & 15), 0.5f);
291  }
292  else
293  cval = c;
294  }
295 
296  // Store outline color...
297  data_[outline] = cval >> 16;
298  data_[outline + 1] = cval;
299 
300  outline = 0;
301  add(END);
302  }
303  else if (strncmp(command, "end", 3) == 0)
304  add(END);
305  else if (strcmp(command, "vertex") == 0)
306  {
307  float x, y; // Coordinates of vertex
308 
309 
310  if (sscanf(params, "%f,%f", &x, &y) != 2)
311  break;
312 
313  add_vertex((short)(int)rint(x * 100.0), (short)(int)rint(y * 100.0));
314  }
315  else
316  {
317  Fl::error("Fl_File_Icon::load_fti(): Unknown command \"%s\" at file position %ld.",
318  command, ftell(fp) - 1);
319  break;
320  }
321  }
322 
323  // Close the file and return...
324  fclose(fp);
325 
326 #ifdef DEBUG
327  printf("Icon File \"%s\":\n", fti);
328  for (int i = 0; i < num_data_; i ++)
329  printf(" %d,\n", data_[i]);
330 #endif /* DEBUG */
331 
332  return 0;
333 }
334 
335 
341 int Fl_File_Icon::load_image(const char *ifile) // I - File to read from
342 {
343  Fl_Shared_Image *img; // Image file
344 
345 
346  img = Fl_Shared_Image::get(ifile);
347  if (!img || !img->count() || !img->w() || !img->h()) return -1;
348 
349  if (img->count() == 1) {
350  int x, y; // X & Y in image
351  int startx; // Starting X coord
352  Fl_Color c, // Current color
353  temp; // Temporary color
354  const uchar *row; // Pointer into image
355 
356  const int extra_data = img->ld() ? (img->ld()-img->w()*img->d()) : 0;
357 
358  // Loop through grayscale or RGB image...
359  for (y = 0, row = (const uchar *)(*(img->data())); y < img->h(); y ++, row += extra_data)
360  {
361  for (x = 0, startx = 0, c = (Fl_Color)-1;
362  x < img->w();
363  x ++, row += img->d())
364  {
365  switch (img->d())
366  {
367  case 1 :
368  temp = fl_rgb_color(row[0], row[0], row[0]);
369  break;
370  case 2 :
371  if (row[1] > 127)
372  temp = fl_rgb_color(row[0], row[0], row[0]);
373  else
374  temp = (Fl_Color)-1;
375  break;
376  case 3 :
377  temp = fl_rgb_color(row[0], row[1], row[2]);
378  break;
379  default :
380  if (row[3] > 127)
381  temp = fl_rgb_color(row[0], row[1], row[2]);
382  else
383  temp = (Fl_Color)-1;
384  break;
385  }
386 
387  if (temp != c)
388  {
389  if (x > startx && c != (Fl_Color)-1)
390  {
391  add_color(c);
392  add(POLYGON);
393  add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
394  add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
395  add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
396  add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
397  add(END);
398  }
399 
400  c = temp;
401  startx = x;
402  }
403  }
404 
405  if (x > startx && c != (Fl_Color)-1)
406  {
407  add_color(c);
408  add(POLYGON);
409  add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
410  add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
411  add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
412  add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
413  add(END);
414  }
415  }
416  } else {
417  int i, j; // Looping vars
418  int ch; // Current character
419  int newch; // New character
420  int bg; // Background color
421  char val[16]; // Color value
422  const char *lineptr, // Pointer into line
423  *const*ptr; // Pointer into data array
424  int ncolors, // Number of colors
425  chars_per_color; // Characters per color
426  Fl_Color *colors; // Colors
427  int red, green, blue; // Red, green, and blue values
428  int x, y; // X & Y in image
429  int startx; // Starting X coord
430 
431  // Get the pixmap data...
432  ptr = img->data();
433  sscanf(*ptr, "%*d%*d%d%d", &ncolors, &chars_per_color);
434 
435  colors = new Fl_Color[1 << (chars_per_color * 8)];
436 
437  // Read the colormap...
438  memset(colors, 0, sizeof(Fl_Color) << (chars_per_color * 8));
439  bg = ' ';
440 
441  ptr ++;
442 
443  if (ncolors < 0) {
444  // Read compressed colormap...
445  const uchar *cmapptr;
446 
447  ncolors = -ncolors;
448 
449  for (i = 0, cmapptr = (const uchar *)*ptr; i < ncolors; i ++, cmapptr += 4)
450  colors[cmapptr[0]] = fl_rgb_color(cmapptr[1], cmapptr[2], cmapptr[3]);
451 
452  ptr ++;
453  } else {
454  for (i = 0; i < ncolors; i ++, ptr ++) {
455  // Get the color's character
456  lineptr = *ptr;
457  ch = *lineptr++;
458 
459  if (chars_per_color > 1) ch = (ch << 8) | *lineptr++;
460 
461  // Get the color value...
462  if ((lineptr = strstr(lineptr, "c ")) == NULL) {
463  // No color; make this black...
464  colors[ch] = FL_BLACK;
465  } else if (lineptr[2] == '#') {
466  // Read the RGB triplet...
467  lineptr += 3;
468  for (j = 0; j < 12; j ++)
469  if (!isxdigit(lineptr[j]))
470  break;
471 
472  switch (j) {
473  case 0 :
474  bg = ch;
475  default :
476  red = green = blue = 0;
477  break;
478 
479  case 3 :
480  val[0] = lineptr[0];
481  val[1] = '\0';
482  red = 255 * strtol(val, NULL, 16) / 15;
483 
484  val[0] = lineptr[1];
485  val[1] = '\0';
486  green = 255 * strtol(val, NULL, 16) / 15;
487 
488  val[0] = lineptr[2];
489  val[1] = '\0';
490  blue = 255 * strtol(val, NULL, 16) / 15;
491  break;
492 
493  case 6 :
494  case 9 :
495  case 12 :
496  j /= 3;
497 
498  val[0] = lineptr[0];
499  val[1] = lineptr[1];
500  val[2] = '\0';
501  red = strtol(val, NULL, 16);
502 
503  val[0] = lineptr[j + 0];
504  val[1] = lineptr[j + 1];
505  val[2] = '\0';
506  green = strtol(val, NULL, 16);
507 
508  val[0] = lineptr[2 * j + 0];
509  val[1] = lineptr[2 * j + 1];
510  val[2] = '\0';
511  blue = strtol(val, NULL, 16);
512  break;
513  }
514 
515  colors[ch] = fl_rgb_color((uchar)red, (uchar)green, (uchar)blue);
516  } else {
517  // Read a color name...
518  if (strncasecmp(lineptr + 2, "white", 5) == 0) colors[ch] = FL_WHITE;
519  else if (strncasecmp(lineptr + 2, "black", 5) == 0) colors[ch] = FL_BLACK;
520  else if (strncasecmp(lineptr + 2, "none", 4) == 0) {
521  colors[ch] = FL_BLACK;
522  bg = ch;
523  } else colors[ch] = FL_GRAY;
524  }
525  }
526  }
527 
528  // Read the image data...
529  for (y = 0; y < img->h(); y ++, ptr ++) {
530  lineptr = *ptr;
531  startx = 0;
532  ch = bg;
533 
534  for (x = 0; x < img->w(); x ++) {
535  newch = *lineptr++;
536 
537  if (chars_per_color > 1) newch = (newch << 8) | *lineptr++;
538 
539  if (newch != ch) {
540  if (ch != bg) {
541  add_color(colors[ch]);
542  add(POLYGON);
543  add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
544  add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
545  add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
546  add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
547  add(END);
548  }
549 
550  ch = newch;
551  startx = x;
552  }
553  }
554 
555  if (ch != bg) {
556  add_color(colors[ch]);
557  add(POLYGON);
558  add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
559  add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
560  add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
561  add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
562  add(END);
563  }
564  }
565 
566  // Free the colormap...
567  delete[] colors;
568  }
569 
570  img->release();
571 
572 #ifdef DEBUG
573 {
574  int i;
575  printf("Icon File \"%s\":\n", ifile);
576  for (i = 0; i < num_data_; i ++)
577  {
578  printf(" %d,\n", data_[i]);
579  }
580 }
581 #endif // DEBUG
582 
583  return 0;
584 }
585 
586 
595 void
597  int i; // Looping var
598  Fl_File_Icon *icon; // New icons
599  char filename[FL_PATH_MAX]; // Filename
600  char icondir[FL_PATH_MAX]; // Icon directory
601  static int init = 0; // Have the icons been initialized?
602  const char * const icondirs[] = {
603  "Bluecurve", // Icon directories to look for, in order
604  "crystalsvg",
605  "default.kde",
606  "hicolor",
607  NULL
608  };
609  static short plain[] = { // Plain file icon
610  COLOR, -1, -1, OUTLINEPOLYGON, 0, FL_GRAY,
611  VERTEX, 2000, 1000, VERTEX, 2000, 9000,
612  VERTEX, 6000, 9000, VERTEX, 8000, 7000,
613  VERTEX, 8000, 1000, END, OUTLINEPOLYGON, 0, FL_GRAY,
614  VERTEX, 6000, 9000, VERTEX, 6000, 7000,
615  VERTEX, 8000, 7000, END,
616  COLOR, 0, FL_BLACK, LINE, VERTEX, 6000, 7000,
617  VERTEX, 8000, 7000, VERTEX, 8000, 1000,
618  VERTEX, 2000, 1000, END, LINE, VERTEX, 3000, 7000,
619  VERTEX, 5000, 7000, END, LINE, VERTEX, 3000, 6000,
620  VERTEX, 5000, 6000, END, LINE, VERTEX, 3000, 5000,
621  VERTEX, 7000, 5000, END, LINE, VERTEX, 3000, 4000,
622  VERTEX, 7000, 4000, END, LINE, VERTEX, 3000, 3000,
623  VERTEX, 7000, 3000, END, LINE, VERTEX, 3000, 2000,
624  VERTEX, 7000, 2000, END,
625  END
626  };
627  static short image[] = { // Image file icon
628  COLOR, -1, -1, OUTLINEPOLYGON, 0, FL_GRAY,
629  VERTEX, 2000, 1000, VERTEX, 2000, 9000,
630  VERTEX, 6000, 9000, VERTEX, 8000, 7000,
631  VERTEX, 8000, 1000, END, OUTLINEPOLYGON, 0, FL_GRAY,
632  VERTEX, 6000, 9000, VERTEX, 6000, 7000,
633  VERTEX, 8000, 7000, END,
634  COLOR, 0, FL_BLACK, LINE, VERTEX, 6000, 7000,
635  VERTEX, 8000, 7000, VERTEX, 8000, 1000,
636  VERTEX, 2000, 1000, END,
637  COLOR, 0, FL_RED, POLYGON, VERTEX, 3500, 2500,
638  VERTEX, 3000, 3000, VERTEX, 3000, 4000,
639  VERTEX, 3500, 4500, VERTEX, 4500, 4500,
640  VERTEX, 5000, 4000, VERTEX, 5000, 3000,
641  VERTEX, 4500, 2500, END,
642  COLOR, 0, FL_GREEN, POLYGON, VERTEX, 5500, 2500,
643  VERTEX, 5000, 3000, VERTEX, 5000, 4000,
644  VERTEX, 5500, 4500, VERTEX, 6500, 4500,
645  VERTEX, 7000, 4000, VERTEX, 7000, 3000,
646  VERTEX, 6500, 2500, END,
647  COLOR, 0, FL_BLUE, POLYGON, VERTEX, 4500, 3500,
648  VERTEX, 4000, 4000, VERTEX, 4000, 5000,
649  VERTEX, 4500, 5500, VERTEX, 5500, 5500,
650  VERTEX, 6000, 5000, VERTEX, 6000, 4000,
651  VERTEX, 5500, 3500, END,
652  END
653  };
654  static short dir[] = { // Directory icon
655  COLOR, -1, -1, POLYGON, VERTEX, 1000, 1000,
656  VERTEX, 1000, 7500, VERTEX, 9000, 7500,
657  VERTEX, 9000, 1000, END,
658  POLYGON, VERTEX, 1000, 7500, VERTEX, 2500, 9000,
659  VERTEX, 5000, 9000, VERTEX, 6500, 7500, END,
660  COLOR, 0, FL_WHITE, LINE, VERTEX, 1500, 1500,
661  VERTEX, 1500, 7000, VERTEX, 9000, 7000, END,
662  COLOR, 0, FL_BLACK, LINE, VERTEX, 9000, 7500,
663  VERTEX, 9000, 1000, VERTEX, 1000, 1000, END,
664  COLOR, 0, FL_GRAY, LINE, VERTEX, 1000, 1000,
665  VERTEX, 1000, 7500, VERTEX, 2500, 9000,
666  VERTEX, 5000, 9000, VERTEX, 6500, 7500,
667  VERTEX, 9000, 7500, END,
668  END
669  };
670 
671 
672  // Add symbols if they haven't been added already...
673  if (!init) {
674  // This method requires the images library...
676 
677  if (!kdedir) {
678  // Figure out where KDE is installed...
679  if ((kdedir = getenv("KDEDIR")) == NULL) {
680  if (!access("/opt/kde", F_OK)) kdedir = "/opt/kde";
681  else if (!access("/usr/local/share/mimelnk", F_OK)) kdedir = "/usr/local";
682  else kdedir = "/usr";
683  }
684  }
685 
686  snprintf(filename, sizeof(filename), "%s/share/mimelnk", kdedir);
687 
688  if (!access(filename, F_OK)) {
689  // Load KDE icons...
691 
692  for (i = 0; icondirs[i]; i ++) {
693  snprintf(icondir, sizeof(icondir), "%s/share/icons/%s", kdedir,
694  icondirs[i]);
695 
696  if (!access(icondir, F_OK)) break;
697  }
698 
699  if (icondirs[i]) {
700  snprintf(filename, sizeof(filename), "%s/16x16/mimetypes/unknown.png",
701  icondir);
702  } else {
703  snprintf(filename, sizeof(filename), "%s/share/icons/unknown.xpm",
704  kdedir);
705  }
706 
707  if (!access(filename, F_OK)) icon->load_image(filename);
708 
710 
711  snprintf(filename, sizeof(filename), "%s/16x16/filesystems/link.png",
712  icondir);
713 
714  if (!access(filename, F_OK)) icon->load_image(filename);
715 
716  snprintf(filename, sizeof(filename), "%s/share/mimelnk", kdedir);
717  load_kde_icons(filename, icondir);
718  } else if (!access("/usr/share/icons/folder.xpm", F_OK)) {
719  // Load GNOME icons...
721  icon->load_image("/usr/share/icons/page.xpm");
722 
724  icon->load_image("/usr/share/icons/folder.xpm");
725  } else if (!access("/usr/dt/appconfig/icons", F_OK)) {
726  // Load CDE icons...
728  icon->load_image("/usr/dt/appconfig/icons/C/Dtdata.m.pm");
729 
731  icon->load_image("/usr/dt/appconfig/icons/C/DtdirB.m.pm");
732 
733  icon = new Fl_File_Icon("core", Fl_File_Icon::PLAIN);
734  icon->load_image("/usr/dt/appconfig/icons/C/Dtcore.m.pm");
735 
736  icon = new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN);
737  icon->load_image("/usr/dt/appconfig/icons/C/Dtimage.m.pm");
738 
739  icon = new Fl_File_Icon("*.{eps|pdf|ps}", Fl_File_Icon::PLAIN);
740  icon->load_image("/usr/dt/appconfig/icons/C/Dtps.m.pm");
741 
742  icon = new Fl_File_Icon("*.ppd", Fl_File_Icon::PLAIN);
743  icon->load_image("/usr/dt/appconfig/icons/C/DtPrtpr.m.pm");
744  } else if (!access("/usr/lib/filetype", F_OK)) {
745  // Load SGI icons...
747  icon->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti");
748 
750  icon->load_fti("/usr/lib/filetype/iconlib/generic.folder.closed.fti");
751 
752  icon = new Fl_File_Icon("core", Fl_File_Icon::PLAIN);
753  icon->load_fti("/usr/lib/filetype/default/iconlib/CoreFile.fti");
754 
755  icon = new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN);
756  icon->load_fti("/usr/lib/filetype/system/iconlib/ImageFile.fti");
757 
758  if (!access("/usr/lib/filetype/install/iconlib/acroread.doc.fti", F_OK)) {
759  icon = new Fl_File_Icon("*.{eps|ps}", Fl_File_Icon::PLAIN);
760  icon->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
761 
762  icon = new Fl_File_Icon("*.pdf", Fl_File_Icon::PLAIN);
763  icon->load_fti("/usr/lib/filetype/install/iconlib/acroread.doc.fti");
764  } else {
765  icon = new Fl_File_Icon("*.{eps|pdf|ps}", Fl_File_Icon::PLAIN);
766  icon->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
767  }
768 
769  if (!access("/usr/lib/filetype/install/iconlib/html.fti", F_OK)) {
770  icon = new Fl_File_Icon("*.{htm|html|shtml}", Fl_File_Icon::PLAIN);
771  icon->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti");
772  icon->load_fti("/usr/lib/filetype/install/iconlib/html.fti");
773  }
774 
775  if (!access("/usr/lib/filetype/install/iconlib/color.ps.idle.fti", F_OK)) {
776  icon = new Fl_File_Icon("*.ppd", Fl_File_Icon::PLAIN);
777  icon->load_fti("/usr/lib/filetype/install/iconlib/color.ps.idle.fti");
778  }
779  } else {
780  // Create the default icons...
781  new Fl_File_Icon("*", Fl_File_Icon::PLAIN, sizeof(plain) / sizeof(plain[0]), plain);
782  new Fl_File_Icon("*.{bm|bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN,
783  sizeof(image) / sizeof(image[0]), image);
784  new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY, sizeof(dir) / sizeof(dir[0]), dir);
785  }
786 
787  // Mark things as initialized...
788  init = 1;
789 
790 #ifdef DEBUG
791  int count;
792  Fl_File_Icon *temp;
793  for (count = 0, temp = first_; temp; temp = temp->next_, count ++);
794  printf("count of Fl_File_Icon's is %d...\n", count);
795 #endif // DEBUG
796  }
797 }
798 
799 
800 //
801 // 'load_kde_icons()' - Load KDE icon files.
802 //
803 
804 static void
805 load_kde_icons(const char *directory, // I - Directory to load
806  const char *icondir) { // I - Location of icons
807  int i; // Looping var
808  int n; // Number of entries in directory
809  dirent **entries; // Entries in directory
810  char full[FL_PATH_MAX]; // Full name of file
811 
812 
813  entries = (dirent **)0;
814  n = fl_filename_list(directory, &entries);
815 
816  for (i = 0; i < n; i ++) {
817  if (entries[i]->d_name[0] != '.') {
818  snprintf(full, sizeof(full), "%s/%s", directory, entries[i]->d_name);
819 
820  if (fl_filename_isdir(full)) load_kde_icons(full, icondir);
821  else load_kde_mimelnk(full, icondir);
822  }
823 
824  free((void *)entries[i]);
825  }
826 
827  free((void*)entries);
828 }
829 
830 
831 //
832 // 'load_kde_mimelnk()' - Load a KDE "mimelnk" file.
833 //
834 
835 static void
836 load_kde_mimelnk(const char *filename, // I - mimelnk filename
837  const char *icondir) { // I - Location of icons
838  FILE *fp;
839  char tmp[1024];
840  char iconfilename[FL_PATH_MAX];
841  char pattern[1024];
842  char mimetype[1024];
843  char *val;
844  char full_iconfilename[FL_PATH_MAX];
846 
847 
848  mimetype[0] = '\0';
849  pattern[0] = '\0';
850  iconfilename[0] = '\0';
851 
852  if ((fp = fl_fopen(filename, "rb")) != NULL) {
853  while (fgets(tmp, sizeof(tmp), fp)) {
854  if ((val = get_kde_val(tmp, "Icon")) != NULL)
855  strlcpy(iconfilename, val, sizeof(iconfilename));
856  else if ((val = get_kde_val(tmp, "MimeType")) != NULL)
857  strlcpy(mimetype, val, sizeof(mimetype));
858  else if ((val = get_kde_val(tmp, "Patterns")) != NULL)
859  strlcpy(pattern, val, sizeof(pattern));
860  }
861 
862  fclose(fp);
863 
864 #ifdef DEBUG
865  printf("%s: Icon=\"%s\", MimeType=\"%s\", Patterns=\"%s\"\n", filename,
866  iconfilename, mimetype, pattern);
867 #endif // DEBUG
868 
869  if (!pattern[0] && strncmp(mimetype, "inode/", 6)) return;
870 
871  if (iconfilename[0]) {
872  if (iconfilename[0] == '/') {
873  strlcpy(full_iconfilename, iconfilename, sizeof(full_iconfilename));
874  } else if (!access(icondir, F_OK)) {
875  // KDE 3.x and 2.x icons
876  int i; // Looping var
877  static const char *paths[] = { // Subdirs to look in...
878  "16x16/actions",
879  "16x16/apps",
880  "16x16/devices",
881  "16x16/filesystems",
882  "16x16/mimetypes",
883 /*
884  "20x20/actions",
885  "20x20/apps",
886  "20x20/devices",
887  "20x20/filesystems",
888  "20x20/mimetypes",
889 
890  "22x22/actions",
891  "22x22/apps",
892  "22x22/devices",
893  "22x22/filesystems",
894  "22x22/mimetypes",
895 
896  "24x24/actions",
897  "24x24/apps",
898  "24x24/devices",
899  "24x24/filesystems",
900  "24x24/mimetypes",
901 */
902  "32x32/actions",
903  "32x32/apps",
904  "32x32/devices",
905  "32x32/filesystems",
906  "32x32/mimetypes",
907 /*
908  "36x36/actions",
909  "36x36/apps",
910  "36x36/devices",
911  "36x36/filesystems",
912  "36x36/mimetypes",
913 
914  "48x48/actions",
915  "48x48/apps",
916  "48x48/devices",
917  "48x48/filesystems",
918  "48x48/mimetypes",
919 
920  "64x64/actions",
921  "64x64/apps",
922  "64x64/devices",
923  "64x64/filesystems",
924  "64x64/mimetypes",
925 
926  "96x96/actions",
927  "96x96/apps",
928  "96x96/devices",
929  "96x96/filesystems",
930  "96x96/mimetypes"
931 */ };
932 
933  for (i = 0; i < (int)(sizeof(paths) / sizeof(paths[0])); i ++) {
934  snprintf(full_iconfilename, sizeof(full_iconfilename),
935  "%s/%s/%s.png", icondir, paths[i], iconfilename);
936 
937  if (!access(full_iconfilename, F_OK)) break;
938  }
939 
940  if (i >= (int)(sizeof(paths) / sizeof(paths[0]))) return;
941  } else {
942  // KDE 1.x icons
943  snprintf(full_iconfilename, sizeof(full_iconfilename),
944  "%s/%s", tmp, iconfilename);
945 
946  if (access(full_iconfilename, F_OK)) return;
947  }
948 
949  if (strncmp(mimetype, "inode/", 6) == 0) {
950  if (!strcmp(mimetype + 6, "directory"))
952  else if (!strcmp(mimetype + 6, "blockdevice"))
954  else if (!strcmp(mimetype + 6, "fifo"))
956  else return;
957  } else {
958  icon = new Fl_File_Icon(kde_to_fltk_pattern(pattern),
960  }
961 
962  icon->load(full_iconfilename);
963  }
964  }
965 }
966 
967 
968 //
969 // 'kde_to_fltk_pattern()' - Convert a KDE pattern to a FLTK pattern.
970 //
971 
972 static char *
973 kde_to_fltk_pattern(const char *kdepattern) {
974  char *pattern,
975  *patptr;
976 
977 
978  pattern = (char *)malloc(strlen(kdepattern) + 3);
979  strcpy(pattern, "{");
980  strcpy(pattern + 1, kdepattern);
981 
982  if (pattern[strlen(pattern) - 1] == ';') pattern[strlen(pattern) - 1] = '\0';
983 
984  strcat(pattern, "}");
985 
986  for (patptr = pattern; *patptr; patptr ++) {
987  if (*patptr == ';') *patptr = '|';
988  }
989 
990  return (pattern);
991 }
992 
993 
994 //
995 // 'get_kde_val()' - Get a KDE value.
996 //
997 
998 static char *
999 get_kde_val(char *str,
1000  const char *key) {
1001  while (*str == *key) {
1002  str ++;
1003  key ++;
1004  }
1005 
1006  if (*key == '\0' && *str == '=') {
1007  if (str[strlen(str) - 1] == '\n') str[strlen(str) - 1] = '\0';
1008 
1009  return (str + 1);
1010  }
1011 
1012  return ((char *)0);
1013 }
1014 
1015 
1016 //
1017 // End of "$Id$".
1018 //
Fl_Widget.H
Fl_Image::d
void d(int D)
Definition: Fl_Image.H:84
Fl_File_Icon
Definition: Fl_File_Icon.H:47
Fl_File_Icon::num_data_
int num_data_
Definition: Fl_File_Icon.H:53
kde_to_fltk_pattern
static char * kde_to_fltk_pattern(const char *kdepattern)
Definition: Fl_File_Icon2.cxx:973
get_kde_val
static char * get_kde_val(char *str, const char *key)
Definition: Fl_File_Icon2.cxx:999
Fl_Color
unsigned int Fl_Color
Definition: Enumerations.H:934
Fl_Image::data
void data(const char *const *p, int c)
Definition: Fl_Image.H:100
Fl_File_Icon::next_
Fl_File_Icon * next_
Definition: Fl_File_Icon.H:50
Fl_Image::h
void h(int H)
Definition: Fl_Image.H:80
ncolors
static int ncolors
Definition: fl_draw_pixmap.cxx:41
fl_rgb_color
Fl_Color fl_rgb_color(uchar r, uchar g, uchar b)
Definition: Enumerations.H:997
FL_WHITE
const Fl_Color FL_WHITE
Definition: Enumerations.H:971
FL_GREEN
const Fl_Color FL_GREEN
Definition: Enumerations.H:958
Fl_Image::count
int count() const
Definition: Fl_Image.H:133
Fl_File_Icon::PLAIN
Definition: Fl_File_Icon.H:62
filename.H
free
void free()
FL_BLUE
const Fl_Color FL_BLUE
Definition: Enumerations.H:960
NULL
#define NULL
Definition: forms.H:34
FL_ICON_COLOR
#define FL_ICON_COLOR
Definition: Fl_File_Icon.H:36
fl_filename_isdir
int fl_filename_isdir(const char *name)
Definition: filename_isdir.cxx:52
Fl_File_Icon::load_system_icons
static void load_system_icons(void)
Definition: Fl_File_Icon2.cxx:596
load_kde_icons
static void load_kde_icons(const char *directory, const char *icondir)
Definition: Fl_File_Icon2.cxx:805
Fl_Image::w
void w(int W)
Definition: Fl_Image.H:76
fl_fopen
FILE * fl_fopen(const char *f, const char *mode)
Definition: fl_utf8.cxx:498
load_kde_mimelnk
static void load_kde_mimelnk(const char *filename, const char *icondir)
Definition: Fl_File_Icon2.cxx:836
Fl_File_Icon::load
void load(const char *f)
Definition: Fl_File_Icon2.cxx:97
key
int key
Definition: Fl_Text_Editor.cxx:91
FL_BLACK
const Fl_Color FL_BLACK
Definition: Enumerations.H:956
snprintf
#define snprintf
Definition: flstring.h:64
icon
static Fl_Box * icon
Definition: fl_ask.cxx:48
Fl_File_Icon::OUTLINEPOLYGON
Definition: Fl_File_Icon.H:76
Fl_File_Icon::VERTEX
Definition: Fl_File_Icon.H:77
Fl_File_Icon::first_
static Fl_File_Icon * first_
Definition: Fl_File_Icon.H:49
fl_register_images
void fl_register_images()
Register the image formats.
Definition: fl_images_core.cxx:54
Fl_File_Icon::add_color
short * add_color(Fl_Color c)
Definition: Fl_File_Icon.H:89
math.h
dir
static int dir
Definition: fl_draw_image.cxx:67
fl_utf8.h
header for Unicode and UTF-8 character handling
command
static unsigned int command(const char *cmd)
Definition: Fl_Help_View.cxx:3018
FL_PATH_MAX
#define FL_PATH_MAX
Definition: filename.H:38
Fl_File_Icon::add
short * add(short d)
Definition: Fl_File_Icon.cxx:145
fl_filename_list
int fl_filename_list(const char *d, dirent ***list, Fl_File_Sort_F *sort)
Definition: filename_list.cxx:75
fl_draw.H
utility header to pull drawing functions together
filename
static const char * filename
Definition: fluid.cxx:119
strlcpy
#define strlcpy
Definition: flstring.h:84
Fl_File_Icon::FIFO
Definition: Fl_File_Icon.H:63
Fl_File_Icon::DIRECTORY
Definition: Fl_File_Icon.H:66
Fl_File_Icon::load_image
int load_image(const char *i)
Definition: Fl_File_Icon2.cxx:341
Fl_File_Icon.H
Fl_File_Icon::add_vertex
short * add_vertex(int x, int y)
Definition: Fl_File_Icon.H:98
Fl_Shared_Image.H
Fl_File_Icon::LINE
Definition: Fl_File_Icon.H:73
FL_RED
const Fl_Color FL_RED
Definition: Enumerations.H:957
Fl_File_Icon::LINK
Definition: Fl_File_Icon.H:65
Fl_File_Icon::POLYGON
Definition: Fl_File_Icon.H:75
x
int x
Definition: test.c:73
Fl_Shared_Image::get
static Fl_Shared_Image * get(const char *name, int W=0, int H=0)
Definition: Fl_Shared_Image.cxx:541
Fl_File_Icon::DEVICE
Definition: Fl_File_Icon.H:64
y
int y
Definition: test.c:74
FL_GRAY
#define FL_GRAY
Definition: Enumerations.H:978
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
malloc
voidp malloc()
Fl::warning
static void(* warning)(const char *,...)
Definition: Fl.H:498
flstring.h
kdedir
static const char * kdedir
Definition: Fl_File_Icon2.cxx:89
Fl_Image::ld
void ld(int LD)
Definition: Fl_Image.H:96
Fl_File_Icon::load_fti
int load_fti(const char *fti)
Definition: Fl_File_Icon2.cxx:124
Fl::error
static void(* error)(const char *,...)
Definition: Fl.H:513
fl_color_average
Fl_Color fl_color_average(Fl_Color c1, Fl_Color c2, float weight)
Definition: fl_color.cxx:402
uchar
unsigned char uchar
Definition: fl_types.h:30
Fl_File_Icon::data_
short * data_
Definition: Fl_File_Icon.H:55
Fl_Shared_Image
Definition: Fl_Shared_Image.H:50
Fl_File_Icon::COLOR
Definition: Fl_File_Icon.H:72
fl_filename_ext
const char * fl_filename_ext(const char *buf)
Definition: filename_ext.cxx:34
dirent
#define dirent
Definition: numericsort.c:31
Fl_File_Icon::END
Definition: Fl_File_Icon.H:71
Fl_Shared_Image::release
void release()
Definition: Fl_Shared_Image.cxx:230
Fl_File_Icon::Fl_File_Icon
Fl_File_Icon(const char *p, int t, int nd=0, short *d=0)
Definition: Fl_File_Icon.cxx:82
Fl_File_Icon::CLOSEDLINE
Definition: Fl_File_Icon.H:74
FL_DARK3
const Fl_Color FL_DARK3
Definition: Enumerations.H:946