You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.9KB

  1. //
  2. // "$Id: Fl_File_Icon.H 8306 2011-01-24 17:04:22Z 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. static Fl_File_Icon *first_; // Pointer to first icon/filetype
  48. Fl_File_Icon *next_; // Pointer to next icon/filetype
  49. const char *pattern_; // Pattern string
  50. int type_; // Match only if directory or file?
  51. int num_data_; // Number of data elements
  52. int alloc_data_; // Number of allocated elements
  53. short *data_; // Icon data
  54. public:
  55. enum // File types
  56. {
  57. ANY, // Any kind of file
  58. PLAIN, // Only plain files
  59. FIFO, // Only named pipes
  60. DEVICE, // Only character and block devices
  61. LINK, // Only symbolic links
  62. DIRECTORY // Only directories
  63. };
  64. enum // Data opcodes
  65. {
  66. END, // End of primitive/icon
  67. COLOR, // Followed by color value (2 shorts)
  68. LINE, // Start of line
  69. CLOSEDLINE, // Start of closed line
  70. POLYGON, // Start of polygon
  71. OUTLINEPOLYGON, // Followed by outline color (2 shorts)
  72. VERTEX // Followed by scaled X,Y
  73. };
  74. Fl_File_Icon(const char *p, int t, int nd = 0, short *d = 0);
  75. ~Fl_File_Icon();
  76. short *add(short d);
  77. /**
  78. Adds a color value to the icon array, returning a pointer to it.
  79. \param[in] c color value
  80. */
  81. short *add_color(Fl_Color c)
  82. { short *d = add((short)COLOR); add((short)(c >> 16)); add((short)c); return (d); }
  83. /**
  84. Adds a vertex value to the icon array, returning a pointer to it.
  85. The integer version accepts coordinates from 0 to 10000.
  86. The origin (0.0) is in the lower-lefthand corner of the icon.
  87. \param[in] x, y vertex coordinates
  88. */
  89. short *add_vertex(int x, int y)
  90. { short *d = add((short)VERTEX); add((short)x); add((short)y); return (d); }
  91. /**
  92. Adds a vertex value to the icon array, returning a pointer to it.
  93. The floating point version goes from 0.0 to 1.0.
  94. The origin (0.0) is in the lower-lefthand corner of the icon.
  95. \param[in] x, y vertex coordinates
  96. */
  97. short *add_vertex(float x, float y)
  98. { short *d = add((short)VERTEX); add((short)(x * 10000.0));
  99. add((short)(y * 10000.0)); return (d); }
  100. /** Clears all icon data from the icon.*/
  101. void clear() { num_data_ = 0; }
  102. void draw(int x, int y, int w, int h, Fl_Color ic, int active = 1);
  103. void label(Fl_Widget *w);
  104. static void labeltype(const Fl_Label *o, int x, int y, int w, int h, Fl_Align a);
  105. void load(const char *f);
  106. int load_fti(const char *fti);
  107. int load_image(const char *i);
  108. /** Returns next file icon object. See Fl_File_Icon::first() */
  109. Fl_File_Icon *next() { return (next_); }
  110. /** Returns the filename matching pattern for the icon.*/
  111. const char *pattern() { return (pattern_); }
  112. /** Returns the number of words of data used by the icon.*/
  113. int size() { return (num_data_); }
  114. /**
  115. Returns the filetype associated with the icon, which can be one of the
  116. following:
  117. \li Fl_File_Icon::ANY, any kind of file.
  118. \li Fl_File_Icon::PLAIN, plain files.
  119. \li Fl_File_Icon::FIFO, named pipes.
  120. \li Fl_File_Icon::DEVICE, character and block devices.
  121. \li Fl_File_Icon::LINK, symbolic links.
  122. \li Fl_File_Icon::DIRECTORY, directories.
  123. */
  124. int type() { return (type_); }
  125. /** Returns the data array for the icon.*/
  126. short *value() { return (data_); }
  127. static Fl_File_Icon *find(const char *filename, int filetype = ANY);
  128. /** Returns a pointer to the first icon in the list.*/
  129. static Fl_File_Icon *first() { return (first_); }
  130. static void load_system_icons(void);
  131. };
  132. #endif // !_Fl_Fl_File_Icon_H_
  133. //
  134. // End of "$Id: Fl_File_Icon.H 8306 2011-01-24 17:04:22Z matt $".
  135. //