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