1 //
2 // "$Id$"
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 
19 /* \file
20    Fl_File_Icon widget . */
21 
22 //
23 // Include necessary header files...
24 //
25 
26 #ifndef _Fl_Fl_File_Icon_H_
27 #  define _Fl_Fl_File_Icon_H_
28 
29 #  include "Fl.H"
30 
31 
32 //
33 // Special color value for the icon color.
34 //
35 
36 #  define FL_ICON_COLOR (Fl_Color)0xffffffff	/**< icon color [background?]*/
37 
38 
39 //
40 // Fl_File_Icon class...
41 //
42 
43 /**
44   The Fl_File_Icon class manages icon images that can be used
45   as labels in other widgets and as icons in the FileBrowser widget.
46 */
47 class FL_EXPORT Fl_File_Icon {			//// Icon data
48 
49   static Fl_File_Icon *first_;	// Pointer to first icon/filetype
50   Fl_File_Icon	*next_;		// Pointer to next icon/filetype
51   const char	*pattern_;	// Pattern string
52   int		type_;		// Match only if directory or file?
53   int		num_data_;	// Number of data elements
54   int		alloc_data_;	// Number of allocated elements
55   short		*data_;		// Icon data
56 
57   public:
58 
59   enum				// File types
60   {
61     ANY,			// Any kind of file
62     PLAIN,			// Only plain files
63     FIFO,			// Only named pipes
64     DEVICE,			// Only character and block devices
65     LINK,			// Only symbolic links
66     DIRECTORY			// Only directories
67   };
68 
69   enum				// Data opcodes
70   {
71     END,			// End of primitive/icon
72     COLOR,			// Followed by color value (2 shorts)
73     LINE,			// Start of line
74     CLOSEDLINE,			// Start of closed line
75     POLYGON,			// Start of polygon
76     OUTLINEPOLYGON,		// Followed by outline color (2 shorts)
77     VERTEX			// Followed by scaled X,Y
78   };
79 
80   Fl_File_Icon(const char *p, int t, int nd = 0, short *d = 0);
81   ~Fl_File_Icon();
82 
83   short		*add(short d);
84 
85   /**
86     Adds a color value to the icon array, returning a pointer to it.
87     \param[in] c color value
88   */
add_color(Fl_Color c)89   short		*add_color(Fl_Color c)
90 		{ short *d = add((short)COLOR); add((short)(c >> 16)); add((short)c); return (d); }
91 
92   /**
93     Adds a vertex value to the icon array, returning a pointer to it.
94     The integer version accepts coordinates from 0 to 10000.
95     The origin (0.0) is in the lower-lefthand corner of the icon.
96     \param[in] x, y vertex coordinates
97   */
add_vertex(int x,int y)98   short		*add_vertex(int x, int y)
99 		{ short *d = add((short)VERTEX); add((short)x); add((short)y); return (d); }
100 
101   /**
102     Adds a vertex value to the icon array, returning a pointer to it.
103     The floating point version goes from 0.0 to 1.0.
104     The origin (0.0) is in the lower-lefthand corner of the icon.
105     \param[in] x, y vertex coordinates
106   */
add_vertex(float x,float y)107   short		*add_vertex(float x, float y)
108 		{ short *d = add((short)VERTEX); add((short)(x * 10000.0));
109 		  add((short)(y * 10000.0)); return (d); }
110 
111   /** Clears all icon data from the icon.*/
clear()112   void		clear() { num_data_ = 0; }
113 
114   void		draw(int x, int y, int w, int h, Fl_Color ic, int active = 1);
115 
116   void		label(Fl_Widget *w);
117 
118   static void	labeltype(const Fl_Label *o, int x, int y, int w, int h, Fl_Align a);
119   void		load(const char *f);
120   int		load_fti(const char *fti);
121   int		load_image(const char *i);
122 
123   /** Returns next file icon object. See Fl_File_Icon::first() */
next()124   Fl_File_Icon	*next() { return (next_); }
125 
126   /** Returns the filename matching pattern for the icon.*/
pattern()127   const char	*pattern() { return (pattern_); }
128 
129   /**  Returns the number of words of data used by the icon.*/
size()130   int		size() { return (num_data_); }
131 
132   /**
133     Returns the filetype associated with the icon, which can be one of the
134     following:
135 
136     \li Fl_File_Icon::ANY, any kind of file.
137     \li Fl_File_Icon::PLAIN, plain files.
138     \li Fl_File_Icon::FIFO, named pipes.
139     \li Fl_File_Icon::DEVICE, character and block devices.
140     \li Fl_File_Icon::LINK, symbolic links.
141     \li Fl_File_Icon::DIRECTORY, directories.
142   */
type()143   int		type() { return (type_); }
144 
145   /**  Returns the data array for the icon.*/
value()146   short		*value() { return (data_); }
147 
148   static Fl_File_Icon *find(const char *filename, int filetype = ANY);
149 
150   /** Returns a pointer to the first icon in the list.*/
first()151   static Fl_File_Icon *first() { return (first_); }
152   static void	load_system_icons(void);
153 };
154 
155 #endif // !_Fl_Fl_File_Icon_H_
156 
157 //
158 // End of "$Id$".
159 //
160