Fl_File_Icon.H 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // "$Id: Fl_File_Icon.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. // Fl_File_Icon definitions.
  5. //
  6. // Copyright 1999-2010 by Michael Sweet.
  7. //
  8. // This library is free software. Distribution and use rights are outlined in
  9. // the file "COPYING" which should have been included with this file. If this
  10. // file is missing or damaged, see the license at:
  11. //
  12. // http://www.fltk.org/COPYING.php
  13. //
  14. // Please report all bugs and problems on the following page:
  15. //
  16. // http://www.fltk.org/str.php
  17. //
  18. /* \file
  19. Fl_File_Icon widget . */
  20. //
  21. // Include necessary header files...
  22. //
  23. #ifndef _Fl_Fl_File_Icon_H_
  24. # define _Fl_Fl_File_Icon_H_
  25. # include "Fl.H"
  26. //
  27. // Special color value for the icon color.
  28. //
  29. # define FL_ICON_COLOR (Fl_Color)0xffffffff /**< icon color [background?]*/
  30. //
  31. // Fl_File_Icon class...
  32. //
  33. /**
  34. The Fl_File_Icon class manages icon images that can be used
  35. as labels in other widgets and as icons in the FileBrowser widget.
  36. */
  37. class FL_EXPORT Fl_File_Icon { //// Icon data
  38. static Fl_File_Icon *first_; // Pointer to first icon/filetype
  39. Fl_File_Icon *next_; // Pointer to next icon/filetype
  40. const char *pattern_; // Pattern string
  41. int type_; // Match only if directory or file?
  42. int num_data_; // Number of data elements
  43. int alloc_data_; // Number of allocated elements
  44. short *data_; // Icon data
  45. public:
  46. enum // File types
  47. {
  48. ANY, // Any kind of file
  49. PLAIN, // Only plain files
  50. FIFO, // Only named pipes
  51. DEVICE, // Only character and block devices
  52. LINK, // Only symbolic links
  53. DIRECTORY // Only directories
  54. };
  55. enum // Data opcodes
  56. {
  57. END, // End of primitive/icon
  58. COLOR, // Followed by color value (2 shorts)
  59. LINE, // Start of line
  60. CLOSEDLINE, // Start of closed line
  61. POLYGON, // Start of polygon
  62. OUTLINEPOLYGON, // Followed by outline color (2 shorts)
  63. VERTEX // Followed by scaled X,Y
  64. };
  65. Fl_File_Icon(const char *p, int t, int nd = 0, short *d = 0);
  66. ~Fl_File_Icon();
  67. short *add(short d);
  68. /**
  69. Adds a color value to the icon array, returning a pointer to it.
  70. \param[in] c color value
  71. */
  72. short *add_color(Fl_Color c)
  73. { short *d = add((short)COLOR); add((short)(c >> 16)); add((short)c); return (d); }
  74. /**
  75. Adds a vertex value to the icon array, returning a pointer to it.
  76. The integer version accepts coordinates from 0 to 10000.
  77. The origin (0.0) is in the lower-lefthand corner of the icon.
  78. \param[in] x, y vertex coordinates
  79. */
  80. short *add_vertex(int x, int y)
  81. { short *d = add((short)VERTEX); add((short)x); add((short)y); return (d); }
  82. /**
  83. Adds a vertex value to the icon array, returning a pointer to it.
  84. The floating point version goes from 0.0 to 1.0.
  85. The origin (0.0) is in the lower-lefthand corner of the icon.
  86. \param[in] x, y vertex coordinates
  87. */
  88. short *add_vertex(float x, float y)
  89. { short *d = add((short)VERTEX); add((short)(x * 10000.0));
  90. add((short)(y * 10000.0)); return (d); }
  91. /** Clears all icon data from the icon.*/
  92. void clear() { num_data_ = 0; }
  93. void draw(int x, int y, int w, int h, Fl_Color ic, int active = 1);
  94. void label(Fl_Widget *w);
  95. static void labeltype(const Fl_Label *o, int x, int y, int w, int h, Fl_Align a);
  96. void load(const char *f);
  97. int load_fti(const char *fti);
  98. int load_image(const char *i);
  99. /** Returns next file icon object. See Fl_File_Icon::first() */
  100. Fl_File_Icon *next() { return (next_); }
  101. /** Returns the filename matching pattern for the icon.*/
  102. const char *pattern() { return (pattern_); }
  103. /** Returns the number of words of data used by the icon.*/
  104. int size() { return (num_data_); }
  105. /**
  106. Returns the filetype associated with the icon, which can be one of the
  107. following:
  108. \li Fl_File_Icon::ANY, any kind of file.
  109. \li Fl_File_Icon::PLAIN, plain files.
  110. \li Fl_File_Icon::FIFO, named pipes.
  111. \li Fl_File_Icon::DEVICE, character and block devices.
  112. \li Fl_File_Icon::LINK, symbolic links.
  113. \li Fl_File_Icon::DIRECTORY, directories.
  114. */
  115. int type() { return (type_); }
  116. /** Returns the data array for the icon.*/
  117. short *value() { return (data_); }
  118. static Fl_File_Icon *find(const char *filename, int filetype = ANY);
  119. /** Returns a pointer to the first icon in the list.*/
  120. static Fl_File_Icon *first() { return (first_); }
  121. static void load_system_icons(void);
  122. };
  123. #endif // !_Fl_Fl_File_Icon_H_
  124. //
  125. // End of "$Id: Fl_File_Icon.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
  126. //