Fl_File_Icon.H 4.9 KB

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