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

FXIconDict.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                         I c o n   D i c t i o n a r y                         *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1998,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: FXIconDict.h,v 1.12 2009/01/06 13:07:25 fox Exp $                        *
00022 ********************************************************************************/
00023 #ifndef FXICONDICT_H
00024 #define FXICONDICT_H
00025 
00026 #ifndef FXDICT_H
00027 #include "FXDict.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 class FXIconSource;
00034 
00035 
00036 /**
00037 * The Icon Dictionary manages a collection of icons.  The icons are referenced
00038 * by their file name.  When first encountering a new file name, the icon is
00039 * located by searching the icon search path for the icon file.  If found, the
00040 * services of the icon source object are used to load the icon from the file.
00041 * A custom icon source may be installed to furnish support for additonal
00042 * image file formats.
00043 * Once the icon is loaded, an association between the icon name and the icon
00044 * is entered into the icon dictionary.  Subsequent searches for an icon with
00045 * this name will be satisfied from the cached value.
00046 * The lifetype of the icons is managed by the icon dictionary, and thus all
00047 * icons will be deleted when the dictionary is deleted.
00048 */
00049 class FXAPI FXIconDict : public FXDict {
00050   FXDECLARE(FXIconDict)
00051 private:
00052   FXIconSource *source; // Icon source
00053   FXString      path;   // Where to search icons
00054 protected:
00055   FXIconDict():source(NULL){}
00056   virtual void *createData(void*);
00057   virtual void deleteData(void*);
00058 private:
00059   FXIconDict(const FXIconDict&);
00060   FXIconDict &operator=(const FXIconDict&);
00061 public:
00062 
00063   /// Default icon search path
00064   static const FXchar defaultIconPath[];
00065 
00066 public:
00067 
00068   /**
00069   * Construct icon dictionary, and set initial search path; also
00070   * creates a default icon source object.
00071   */
00072   FXIconDict(FXApp* app,const FXString& p=defaultIconPath);
00073 
00074   /// Change icon source
00075   void setIconSource(FXIconSource *src){ source=src; }
00076 
00077   /// Return icon source
00078   FXIconSource* getIconSource() const { return source; }
00079 
00080   /// Set icon search path
00081   void setIconPath(const FXString& p){ path=p; }
00082 
00083   /// Return current icon search path
00084   const FXString& getIconPath() const { return path; }
00085 
00086   /// Insert unique icon loaded from filename into dictionary
00087   FXIcon* insert(const FXchar* name){ return (FXIcon*)FXDict::insert(name,(void*)name); }
00088 
00089   /// Replace icon loaded from filename into dictionary
00090   FXIcon* replace(const FXchar* name){ return (FXIcon*)FXDict::replace(name,(void*)name); }
00091 
00092   /// Remove icon from dictionary
00093   FXIcon* remove(const FXchar* name){ return (FXIcon*)FXDict::remove(name); }
00094 
00095   /// Find icon by name
00096   FXIcon* find(const FXchar* name){ return (FXIcon*)FXDict::find(name); }
00097 
00098   /// Return icon at position pos
00099   FXIcon* data(FXint pos) const { return (FXIcon*)FXDict::data(pos); }
00100 
00101   /// Save to stream
00102   virtual void save(FXStream& store) const;
00103 
00104   /// Load from stream
00105   virtual void load(FXStream& store);
00106 
00107   /// Destroy the icon dict as well as the icon source
00108   virtual ~FXIconDict();
00109   };
00110 
00111 
00112 }
00113 
00114 #endif

Copyright © 1997-2009 Jeroen van der Zijp