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

Copyright © 1997-2005 Jeroen van der Zijp