Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXIconSource.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * I c o n S o u r c e *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2005,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 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 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser 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 USA. *
21 *********************************************************************************
22 * $Id: FXIconSource.h,v 1.13 2006/02/03 00:44:32 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXICONSOURCE_H
25 #define FXICONSOURCE_H
26 
27 #ifndef FXOBJECT_H
28 #include "FXObject.h"
29 #endif
30 
31 namespace FX {
32 
33 class FXApp;
34 class FXIcon;
35 class FXImage;
36 
37 /**
38 * An icon source is a class that loads an icon of any type.
39 * It exists purely for convenience, to make loading icons
40 * simpler by concentrating the knowledge of the supported
41 * icon formats in a single place.
42 * Needless to say, this class is subclassable, allowing users
43 * to add additional icon types and make them available to
44 * all widgets which deal with icons.
45 * Note, the icons are loaded, but NOT created (realized) yet;
46 * this allows users to manipulate the pixel data prior to
47 * realizing the icons.
48 */
49 class FXAPI FXIconSource : public FXObject {
51 protected:
52  FXApp *app;
53 protected:
54  FXIconSource():app(NULL){}
55 private:
56  FXIconSource(const FXIconSource&);
57  FXIconSource &operator=(const FXIconSource&);
58  FXImage *scaleToSize(FXImage *image,FXint size,FXint qual) const;
59 public:
60 
61  /// Construct an icon source
62  FXIconSource(FXApp* a);
63 
64  /**
65  * Load an icon from the file filename. By default, the file extension is
66  * stripped and used as the icon type; if an explicit icon type is forced,
67  * then that type is used and the extension is ignored.
68  * For example, loadIcon("icon","gif") will try to load a CompuServe GIF
69  * file, since the filename does not give any clue as to the type of the
70  * icon.
71  */
72  virtual FXIcon *loadIconFile(const FXString& filename,const FXString& type=FXString::null) const;
73 
74  /**
75  * Load an icon of a given type (e.g. "gif") from reswrapped data.
76  * Returns NULL if there's some error loading the icon. [The optional
77  * parameter is actually mandatory at the time of this writing; future
78  * versions will attempt to inspect the first few bytes of the stream
79  * to divine the icon format if the parameter is omitted].
80  */
81  virtual FXIcon *loadIconData(const void *pixels,const FXString& type=FXString::null) const;
82 
83  /**
84  * Load an icon of a given type (e.g. "gif") from an already open stream.
85  * Returns NULL if there's some error loading the icon. [The optional
86  * parameter is actually mandatory at the time of this writing; future
87  * versions will attempt to inspect the first few bytes of the stream
88  * to divine the icon format if the parameter is omitted].
89  */
90  virtual FXIcon *loadIconStream(FXStream& store,const FXString& type=FXString::null) const;
91 
92  /**
93  * Load an image from the file filename. By default, the file extension is
94  * stripped and used as the image type; if an explicit image type is forced,
95  * then that type is used and the extension is ignored.
96  * For example, loadImage("image","gif") will try to load a CompuServe GIF
97  * file, since the filename does not give any clue as to the type of the
98  * image.
99  */
100  virtual FXImage *loadImageFile(const FXString& filename,const FXString& type=FXString::null) const;
101 
102  /**
103  * Load an image of a given type (e.g. "gif") from reswrapped data.
104  * Returns NULL if there's some error loading the icon. [The optional
105  * parameter is actually mandatory at the time of this writing; future
106  * versions will attempt to inspect the first few bytes of the stream
107  * to divine the icon format if the parameter is omitted].
108  */
109  virtual FXImage *loadImageData(const void *pixels,const FXString& type=FXString::null) const;
110 
111  /**
112  * Load an image of a given type (e.g. "gif") from an already open stream.
113  * Returns NULL if there's some error loading the image. [The optional
114  * parameter is actually mandatory at the time of this writing; future
115  * versions will attempt to inspect the first few bytes of the stream
116  * to divine the image format if the parameter is omitted].
117  */
118  virtual FXImage *loadImageStream(FXStream& store,const FXString& type=FXString::null) const;
119 
120 
121  /// Load icon and scale it such that its dimensions does not exceed given size
122  virtual FXIcon *loadScaledIconFile(const FXString& filename,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
123 
124  /// Load icon and scale it such that its dimensions does not exceed given size
125  virtual FXIcon *loadScaledIconData(const void *pixels,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
126 
127  /// Load icon and scale it such that its dimensions does not exceed given size
128  virtual FXIcon *loadScaledIconStream(FXStream& store,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
129 
130  /// Load image and scale it such that its dimensions does not exceed given size
131  virtual FXImage *loadScaledImageFile(const FXString& filename,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
132 
133  /// Load image and scale it such that its dimensions does not exceed given size
134  virtual FXImage *loadScaledImageData(const void *pixels,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
135 
136  /// Load image and scale it such that its dimensions does not exceed given size
137  virtual FXImage *loadScaledImageStream(FXStream& store,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
138 
139 
140  /// Save to stream
141  virtual void save(FXStream& store) const;
142 
143  /// Load from stream
144  virtual void load(FXStream& store);
145 
146  /// Destroy
147  virtual ~FXIconSource();
148  };
149 
150 
151 }
152 
153 #endif
An icon source is a class that loads an icon of any type.
Definition: FXIconSource.h:49
#define FXAPI
Definition: fxdefs.h:122
Application Object.
Definition: FXApp.h:158
#define NULL
Definition: fxdefs.h:41
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
int FXint
Definition: fxdefs.h:397
An Icon is an image with two additional server-side resources: a shape bitmap, which is used to mask ...
Definition: FXIcon.h:45
Object is the base class for all objects in FOX; in order to receive messages from the user interface...
Definition: FXObject.h:166
An Image is a rectangular array of pixels.
Definition: FXImage.h:67
static const FXchar null[]
Definition: FXString.h:35
#define FXDECLARE(classname)
Macro to set up class declaration.
Definition: FXObject.h:92
FXString provides essential string manipulation capabilities.
Definition: FXString.h:33

Copyright © 1997-2005 Jeroen van der Zijp