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

FXIconSource.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                            I c o n   S o u r c e                              *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2005,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 *********************************************************************************
00021 * $Id: FXIconSource.h,v 1.17 2009/01/06 13:07:25 fox Exp $                      *
00022 ********************************************************************************/
00023 #ifndef FXICONSOURCE_H
00024 #define FXICONSOURCE_H
00025 
00026 #ifndef FXOBJECT_H
00027 #include "FXObject.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 class FXApp;
00033 class FXIcon;
00034 class FXImage;
00035 
00036 /**
00037 * An icon source is a class that loads an icon of any type.
00038 * It exists purely for convenience, to make loading icons
00039 * simpler by concentrating the knowledge of the supported
00040 * icon formats in a single place.
00041 * Needless to say, this class is subclassable, allowing users
00042 * to add additional icon types and make them available to
00043 * all widgets which deal with icons.
00044 * Note, the icons are loaded, but NOT created (realized) yet;
00045 * this allows users to manipulate the pixel data prior to
00046 * realizing the icons.
00047 */
00048 class FXAPI FXIconSource : public FXObject {
00049   FXDECLARE(FXIconSource)
00050 protected:
00051   FXApp *app;
00052 protected:
00053   FXIconSource():app(NULL){}
00054 private:
00055   FXIconSource(const FXIconSource&);
00056   FXIconSource &operator=(const FXIconSource&);
00057   FXImage *scaleToSize(FXImage *image,FXint size,FXint qual) const;
00058 public:
00059 
00060   /// Construct an icon source
00061   FXIconSource(FXApp* a);
00062 
00063   /**
00064   * Load an icon from the file filename. By default, the file extension is
00065   * stripped and used as the icon type; if an explicit icon type is forced,
00066   * then that type is used and the extension is ignored.
00067   * For example, loadIcon("icon","gif") will try to load a CompuServe GIF
00068   * file, since the filename does not give any clue as to the type of the
00069   * icon.
00070   */
00071   virtual FXIcon *loadIconFile(const FXString& filename,const FXString& type=FXString::null) const;
00072 
00073   /**
00074   * Load an icon of a given type (e.g. "gif") from reswrapped data.
00075   * Returns NULL if there's some error loading the icon.  [The optional
00076   * parameter is actually mandatory at the time of this writing; future
00077   * versions will attempt to inspect the first few bytes of the stream
00078   * to divine the icon format if the parameter is omitted].
00079   */
00080   virtual FXIcon *loadIconData(const void *pixels,const FXString& type=FXString::null) const;
00081 
00082   /**
00083   * Load an icon of a given type (e.g. "gif") from an already open stream.
00084   * Returns NULL if there's some error loading the icon.  [The optional
00085   * parameter is actually mandatory at the time of this writing; future
00086   * versions will attempt to inspect the first few bytes of the stream
00087   * to divine the icon format if the parameter is omitted].
00088   */
00089   virtual FXIcon *loadIconStream(FXStream& store,const FXString& type=FXString::null) const;
00090 
00091   /**
00092   * Load an image from the file filename. By default, the file extension is
00093   * stripped and used as the image type; if an explicit image type is forced,
00094   * then that type is used and the extension is ignored.
00095   * For example, loadImage("image","gif") will try to load a CompuServe GIF
00096   * file, since the filename does not give any clue as to the type of the
00097   * image.
00098   */
00099   virtual FXImage *loadImageFile(const FXString& filename,const FXString& type=FXString::null) const;
00100 
00101   /**
00102   * Load an image of a given type (e.g. "gif") from reswrapped data.
00103   * Returns NULL if there's some error loading the icon.  [The optional
00104   * parameter is actually mandatory at the time of this writing; future
00105   * versions will attempt to inspect the first few bytes of the stream
00106   * to divine the icon format if the parameter is omitted].
00107   */
00108   virtual FXImage *loadImageData(const void *pixels,const FXString& type=FXString::null) const;
00109 
00110   /**
00111   * Load an image of a given type (e.g. "gif") from an already open stream.
00112   * Returns NULL if there's some error loading the image.  [The optional
00113   * parameter is actually mandatory at the time of this writing; future
00114   * versions will attempt to inspect the first few bytes of the stream
00115   * to divine the image format if the parameter is omitted].
00116   */
00117   virtual FXImage *loadImageStream(FXStream& store,const FXString& type=FXString::null) const;
00118 
00119 
00120   /// Load icon and scale it such that its dimensions does not exceed given size
00121   virtual FXIcon *loadScaledIconFile(const FXString& filename,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
00122 
00123   /// Load icon and scale it such that its dimensions does not exceed given size
00124   virtual FXIcon *loadScaledIconData(const void *pixels,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
00125 
00126   /// Load icon and scale it such that its dimensions does not exceed given size
00127   virtual FXIcon *loadScaledIconStream(FXStream& store,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
00128 
00129   /// Load image and scale it such that its dimensions does not exceed given size
00130   virtual FXImage *loadScaledImageFile(const FXString& filename,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
00131 
00132   /// Load image and scale it such that its dimensions does not exceed given size
00133   virtual FXImage *loadScaledImageData(const void *pixels,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
00134 
00135   /// Load image and scale it such that its dimensions does not exceed given size
00136   virtual FXImage *loadScaledImageStream(FXStream& store,FXint size=32,FXint qual=0,const FXString& type=FXString::null) const;
00137 
00138 
00139   /// Save to stream
00140   virtual void save(FXStream& store) const;
00141 
00142   /// Load from stream
00143   virtual void load(FXStream& store);
00144 
00145   /// Destroy
00146   virtual ~FXIconSource();
00147   };
00148 
00149 
00150 }
00151 
00152 #endif

Copyright © 1997-2009 Jeroen van der Zijp