![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * F i l e - A s s o c i a t i o n T a b l e * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 1998,2002 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: FXFileDict.h,v 1.17 2002/01/23 18:53:57 jeroen Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXFILEDICT_H 00025 #define FXFILEDICT_H 00026 00027 #ifndef FXDICT_H 00028 #include "FXDict.h" 00029 #endif 00030 00031 00032 00033 /// Registers stuff to know about the extension 00034 struct FXFileAssoc { 00035 FXString command; /// Command to execute 00036 FXString extension; /// Full extension name 00037 FXString mimetype; /// Mime type name 00038 FXIcon *bigicon; /// Big normal icon 00039 FXIcon *bigiconopen; /// Big open icon 00040 FXIcon *miniicon; /// Mini normal icon 00041 FXIcon *miniiconopen; /// Mini open icon 00042 FXDragType dragtype; /// Registered drag type 00043 FXuint flags; /// Flags 00044 }; 00045 00046 00047 /// Icon dictionary 00048 class FXAPI FXIconDict : public FXDict { 00049 FXDECLARE(FXIconDict) 00050 private: 00051 FXApp *app; // Application object 00052 FXString path; // Where to search icons 00053 protected: 00054 FXIconDict(){} 00055 virtual void *createData(const void*); 00056 virtual void deleteData(void*); 00057 private: 00058 FXIconDict(const FXIconDict&); 00059 FXIconDict &operator=(const FXIconDict&); 00060 public: 00061 00062 /// Default icon search path 00063 static const FXchar defaultIconPath[]; 00064 00065 public: 00066 00067 /// Construct an icon dictionary, with given path 00068 FXIconDict(FXApp* a,const FXString& p=defaultIconPath); 00069 00070 /// Get application 00071 FXApp* getApp() const { return app; } 00072 00073 /// Set icon search path 00074 void setIconPath(const FXString& p){ path=p; } 00075 00076 /// Return current icon search path 00077 FXString getIconPath() const { return path; } 00078 00079 /// Insert unique icon loaded from filename into dictionary 00080 FXIcon* insert(const FXchar* name){ return (FXIcon*)FXDict::insert(name,name); } 00081 00082 /// Remove icon from dictionary 00083 FXIcon* remove(const FXchar* name){ return (FXIcon*)FXDict::remove(name); } 00084 00085 /// Find icon by name 00086 FXIcon* find(const FXchar* name){ return (FXIcon*)FXDict::find(name); } 00087 00088 /// Save to stream 00089 virtual void save(FXStream& store) const; 00090 00091 /// Load from stream 00092 virtual void load(FXStream& store); 00093 00094 /// Destructor 00095 virtual ~FXIconDict(); 00096 }; 00097 00098 00099 /** 00100 * The File Association dictionary associates a file extension 00101 * with a FXFileAssoc record which contains command name, mime type, 00102 * icons, and other information about the file type. 00103 * The Registry is used as source of the file bindings; an alternative 00104 * Settings database may be specified however. 00105 */ 00106 class FXAPI FXFileDict : public FXDict { 00107 FXDECLARE(FXFileDict) 00108 private: 00109 FXApp *app; // Application object 00110 FXSettings *settings; // Settings database where to get bindings 00111 FXIconDict *icons; // Icon table 00112 protected: 00113 FXFileDict(){} 00114 virtual void *createData(const void*); 00115 virtual void deleteData(void*); 00116 private: 00117 FXFileDict(const FXFileDict&); 00118 FXFileDict &operator=(const FXFileDict&); 00119 public: 00120 00121 /// Registry key used to find fallback executable icons 00122 static const FXchar defaultExecBinding[]; 00123 00124 /// Registry key used to find fallback directory icons 00125 static const FXchar defaultDirBinding[]; 00126 00127 /// Registry key used to find fallback document icons 00128 static const FXchar defaultFileBinding[]; 00129 public: 00130 00131 /** 00132 * Construct a dictionary mapping file-extension to file associations, 00133 * using the application registry settings as a source for the bindings. 00134 */ 00135 FXFileDict(FXApp* a); 00136 00137 /** 00138 * Construct a dictionary mapping file-extension to file associations, 00139 * using the specified settings database as a source for the bindings. 00140 */ 00141 FXFileDict(FXApp* a,FXSettings* db); 00142 00143 /// Get application 00144 FXApp* getApp() const { return app; } 00145 00146 /// Set icon search path 00147 void setIconPath(const FXString& path); 00148 00149 /// Return current icon search path 00150 FXString getIconPath() const; 00151 00152 /** 00153 * Replace file association. 00154 * The new association is written into the settings database under the 00155 * FILETYPES section; the format of the association is as follows: 00156 * 00157 * <extension> = "<command> ; <type> ; <bigicon> [ : <bigopenicon> ] ; <smallicon> [ : <smalliconopen> ] ; <mimetype>" 00158 * 00159 * Where <command> is the command used to launch the application (e.g. "xv %s &"), 00160 * and <type> is the file type string (e.g. "GIF Image"), 00161 * <bigicon> and <bigiconopen> are the large icons shown in "Icons" mode, 00162 * <smallicon> and <smalliconopen> are the small icons shown in "Details" mode, 00163 * and <mimetype> is the RFC2045 mime type of the file. 00164 * 00165 * For example: 00166 * 00167 * [FILETYPES] 00168 * gif="xv %s &;GIF Image;big.xpm:bigopen.xpm;mini.xpm:miniopen.xpm;image/gif" 00169 * /home/jeroen=";Home;home.xpm;minihome.xpm;application/x-folder" 00170 * 00171 */ 00172 FXFileAssoc* replace(const FXchar* ext,const FXchar* str); 00173 00174 /// Remove file association 00175 FXFileAssoc* remove(const FXchar* ext); 00176 00177 /// Find file association already in dictionary 00178 FXFileAssoc* find(const FXchar* ext){ return (FXFileAssoc*)FXDict::find(ext); } 00179 00180 /// Find file association from registry 00181 FXFileAssoc* associate(const FXchar* key); 00182 00183 /** 00184 * Determine binding for the given file. 00185 * The default implementation tries the whole filename first, 00186 * then tries the extensions. 00187 * For example, for a file "source.tar.gz": 00188 * 00189 * "source.tar.gz", 00190 * "tar.gz", 00191 * "gz" 00192 * 00193 * are tried in succession. If no association is found the 00194 * key "defaultfilebinding" is tried as a fallback association. 00195 * A NULL is returned if no association of any kind is found. 00196 */ 00197 virtual FXFileAssoc* findFileBinding(const FXchar* pathname); 00198 00199 /** 00200 * Find directory binding from registry. 00201 * The default implementation tries the whole pathname first, 00202 * then tries successively smaller parts of the path. 00203 * For example, a pathname "/usr/people/jeroen": 00204 * 00205 * "/usr/people/jeroen" 00206 * "/people/jeroen" 00207 * "/jeroen" 00208 * 00209 * are tried in succession. If no bindings are found, the 00210 * key "defaultdirbinding" is tried as a fallback association. 00211 * A NULL is returned if no association of any kind is found. 00212 */ 00213 virtual FXFileAssoc* findDirBinding(const FXchar* pathname); 00214 00215 /** 00216 * Determine binding for the given executable. 00217 * The default implementation returns the fallback binding associated with 00218 * the key "defaultexecbinding". 00219 * A NULL is returned if no association of any kind is found. 00220 */ 00221 virtual FXFileAssoc* findExecBinding(const FXchar* pathname); 00222 00223 /// Save to stream 00224 virtual void save(FXStream& store) const; 00225 00226 /// Load from stream 00227 virtual void load(FXStream& store); 00228 00229 /// Destructor 00230 virtual ~FXFileDict(); 00231 }; 00232 00233 00234 #endif