<html> <head> <link rel="stylesheet" href="page.css" type="text/css"> <title>fox-toolkit.org - Documentation</title> </head> <body bgcolor=#ffffff link=#990033 vlink=#990033 alink=#990033 text=#000000> <font face='verdana,sans-serif' size=2 > <!---- TOPIC TITLE WITH LOGO---> <table border=0 cellpadding= cellspacing=2 width=100% ><tr><td><a href='http://www.fox-toolkit.org/doc.html'><img src='../art/foxlogo_small.jpg' border=0></a></td><td width=100% valign=bottom><font face='verdana,sans-serif' size=2 ><b> <a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <br><img src='../art/line.gif' width=100% height=1></b></font></td></tr></table> <p> <!--- TOPIC TITLE WITH LOGO ---> <!-- Generated by Doxygen 1.3.3 --> <h1>FXFileDict.h</h1><div class="fragment"><pre>00001 <span class="comment">/********************************************************************************</span> 00002 <span class="comment">* *</span> 00003 <span class="comment">* F i l e - A s s o c i a t i o n T a b l e *</span> 00004 <span class="comment">* *</span> 00005 <span class="comment">*********************************************************************************</span> 00006 <span class="comment">* Copyright (C) 1998,2004 by Jeroen van der Zijp. All Rights Reserved. *</span> 00007 <span class="comment">*********************************************************************************</span> 00008 <span class="comment">* This library is free software; you can redistribute it and/or *</span> 00009 <span class="comment">* modify it under the terms of the GNU Lesser General Public *</span> 00010 <span class="comment">* License as published by the Free Software Foundation; either *</span> 00011 <span class="comment">* version 2.1 of the License, or (at your option) any later version. *</span> 00012 <span class="comment">* *</span> 00013 <span class="comment">* This library is distributed in the hope that it will be useful, *</span> 00014 <span class="comment">* but WITHOUT ANY WARRANTY; without even the implied warranty of *</span> 00015 <span class="comment">* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *</span> 00016 <span class="comment">* Lesser General Public License for more details. *</span> 00017 <span class="comment">* *</span> 00018 <span class="comment">* You should have received a copy of the GNU Lesser General Public *</span> 00019 <span class="comment">* License along with this library; if not, write to the Free Software *</span> 00020 <span class="comment">* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *</span> 00021 <span class="comment">*********************************************************************************</span> 00022 <span class="comment">* $Id: FXFileDict.h,v 1.21 2004/02/08 17:17:33 fox Exp $ *</span> 00023 <span class="comment">********************************************************************************/</span> 00024 <span class="preprocessor">#ifndef FXFILEDICT_H</span> 00025 <span class="preprocessor"></span><span class="preprocessor">#define FXFILEDICT_H</span> 00026 <span class="preprocessor"></span> 00027 <span class="preprocessor">#ifndef FXDICT_H</span> 00028 <span class="preprocessor"></span><span class="preprocessor">#include "FXDict.h"</span> 00029 <span class="preprocessor">#endif</span> 00030 <span class="preprocessor"></span> 00031 <span class="keyword">namespace </span>FX { 00032 00033 <span class="comment"></span> 00034 <span class="comment">/// Registers stuff to know about the extension</span> <a name="l00035"></a><a class="code" href="structFX_1_1FXFileAssoc.html">00035</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="structFX_1_1FXFileAssoc.html">FXFileAssoc</a> { 00036 <a class="code" href="classFX_1_1FXString.html">FXString</a> command; <span class="comment">/// Command to execute</span> <a name="l00037"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o1">00037</a> <span class="comment"></span> <a class="code" href="classFX_1_1FXString.html">FXString</a> <a class="code" href="structFX_1_1FXFileAssoc.html#o1">extension</a>; <span class="comment">/// Full extension name</span> <a name="l00038"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o2">00038</a> <span class="comment"></span> <a class="code" href="classFX_1_1FXString.html">FXString</a> <a class="code" href="structFX_1_1FXFileAssoc.html#o2">mimetype</a>; <span class="comment">/// Mime type name</span> <a name="l00039"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o3">00039</a> <span class="comment"></span> <a class="code" href="classFX_1_1FXIcon.html">FXIcon</a> *<a class="code" href="structFX_1_1FXFileAssoc.html#o3">bigicon</a>; <span class="comment">/// Big normal icon</span> <a name="l00040"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o4">00040</a> <span class="comment"></span> <a class="code" href="classFX_1_1FXIcon.html">FXIcon</a> *<a class="code" href="structFX_1_1FXFileAssoc.html#o4">bigiconopen</a>; <span class="comment">/// Big open icon</span> <a name="l00041"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o5">00041</a> <span class="comment"></span> <a class="code" href="classFX_1_1FXIcon.html">FXIcon</a> *<a class="code" href="structFX_1_1FXFileAssoc.html#o5">miniicon</a>; <span class="comment">/// Mini normal icon</span> <a name="l00042"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o6">00042</a> <span class="comment"></span> <a class="code" href="classFX_1_1FXIcon.html">FXIcon</a> *<a class="code" href="structFX_1_1FXFileAssoc.html#o6">miniiconopen</a>; <span class="comment">/// Mini open icon</span> <a name="l00043"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o7">00043</a> <span class="comment"></span> FXDragType <a class="code" href="structFX_1_1FXFileAssoc.html#o7">dragtype</a>; <span class="comment">/// Registered drag type</span> <a name="l00044"></a><a class="code" href="structFX_1_1FXFileAssoc.html#o8">00044</a> <span class="comment"></span> FXuint <a class="code" href="structFX_1_1FXFileAssoc.html#o8">flags</a>; <span class="comment">/// Flags</span> 00045 <span class="comment"></span> }; 00046 00047 <span class="comment"></span> 00048 <span class="comment">/// Icon dictionary</span> <a name="l00049"></a><a class="code" href="classFX_1_1FXIconDict.html">00049</a> <span class="comment"></span><span class="keyword">class </span>FXAPI FXIconDict : <span class="keyword">public</span> <a class="code" href="classFX_1_1FXDict.html">FXDict</a> { 00050 FXDECLARE(FXIconDict) 00051 <span class="keyword">private</span>: 00052 <a class="code" href="classFX_1_1FXApp.html">FXApp</a> *app; <span class="comment">// Application object</span> 00053 <a class="code" href="classFX_1_1FXString.html">FXString</a> path; <span class="comment">// Where to search icons</span> <a name="l00054"></a><a class="code" href="classFX_1_1FXIconDict.html#s0">00054</a> <span class="keyword">protected</span>: 00055 FXIconDict(){} 00056 <span class="keyword">virtual</span> <span class="keywordtype">void</span> *createData(<span class="keyword">const</span> <span class="keywordtype">void</span>*); 00057 <span class="keyword">virtual</span> <span class="keywordtype">void</span> deleteData(<span class="keywordtype">void</span>*); 00058 <span class="keyword">private</span>: 00059 FXIconDict(<span class="keyword">const</span> FXIconDict&); 00060 FXIconDict &operator=(<span class="keyword">const</span> FXIconDict&); 00061 <span class="keyword">public</span>: <a name="l00062"></a><a class="code" href="classFX_1_1FXIconDict.html#a1">00062</a> <span class="comment"></span> 00063 <span class="comment"> /// Default icon search path</span> 00064 <span class="comment"></span> <span class="keyword">static</span> <span class="keyword">const</span> FXchar defaultIconPath[]; <a name="l00065"></a><a class="code" href="classFX_1_1FXIconDict.html#a2">00065</a> 00066 <span class="keyword">public</span>: 00067 <span class="comment"></span> <a name="l00068"></a><a class="code" href="classFX_1_1FXIconDict.html#a3">00068</a> <span class="comment"> /// Construct an icon dictionary, with given path</span> 00069 <span class="comment"></span> FXIconDict(<a class="code" href="classFX_1_1FXApp.html">FXApp</a>* a,<span class="keyword">const</span> <a class="code" href="classFX_1_1FXString.html">FXString</a>& p=defaultIconPath); 00070 <span class="comment"></span> <a name="l00071"></a><a class="code" href="classFX_1_1FXIconDict.html#a4">00071</a> <span class="comment"> /// Get application</span> 00072 <span class="comment"></span> <a class="code" href="classFX_1_1FXApp.html">FXApp</a>* getApp()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> app; } 00073 <span class="comment"></span> <a name="l00074"></a><a class="code" href="classFX_1_1FXIconDict.html#a5">00074</a> <span class="comment"> /// Set icon search path</span> 00075 <span class="comment"></span> <span class="keywordtype">void</span> setIconPath(<span class="keyword">const</span> <a class="code" href="classFX_1_1FXString.html">FXString</a>& p){ path=p; } 00076 <span class="comment"></span> <a name="l00077"></a><a class="code" href="classFX_1_1FXIconDict.html#a6">00077</a> <span class="comment"> /// Return current icon search path</span> 00078 <span class="comment"></span> <a class="code" href="classFX_1_1FXString.html">FXString</a> getIconPath()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> path; } 00079 <span class="comment"></span> 00080 <span class="comment"> /// Insert unique icon loaded from filename into dictionary</span> 00081 <span class="comment"></span> FXIcon* insert(<span class="keyword">const</span> FXchar* name){ <span class="keywordflow">return</span> (FXIcon*)FXDict::insert(name,name); } 00082 <span class="comment"></span> 00083 <span class="comment"> /// Remove icon from dictionary</span> 00084 <span class="comment"></span> FXIcon* remove(<span class="keyword">const</span> FXchar* name){ <span class="keywordflow">return</span> (FXIcon*)FXDict::remove(name); } 00085 <span class="comment"></span> 00086 <span class="comment"> /// Find icon by name</span> 00087 <span class="comment"></span> FXIcon* find(<span class="keyword">const</span> FXchar* name){ <span class="keywordflow">return</span> (FXIcon*)FXDict::find(name); } 00088 <span class="comment"></span> 00089 <span class="comment"> /// Save to stream</span> 00090 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> save(FXStream& store) <span class="keyword">const</span>; 00091 <span class="comment"></span> 00092 <span class="comment"> /// Load from stream</span> 00093 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> load(FXStream& store); 00094 <span class="comment"></span> 00095 <span class="comment"> /// Destructor</span> 00096 <span class="comment"></span> <span class="keyword">virtual</span> ~FXIconDict(); <a name="l00097"></a><a class="code" href="classFX_1_1FXFileDict.html">00097</a> }; 00098 00099 <span class="comment"></span> 00100 <span class="comment">/**</span> 00101 <span class="comment">* The File Association dictionary associates a file extension</span> <a name="l00102"></a><a class="code" href="classFX_1_1FXFileDict.html#s0">00102</a> <span class="comment">* with a FXFileAssoc record which contains command name, mime type,</span> 00103 <span class="comment">* icons, and other information about the file type.</span> 00104 <span class="comment">* The Registry is used as source of the file bindings; an alternative</span> <a name="l00105"></a><a class="code" href="classFX_1_1FXFileDict.html#s1">00105</a> <span class="comment">* Settings database may be specified however.</span> 00106 <span class="comment">*/</span> 00107 <span class="keyword">class </span>FXAPI FXFileDict : <span class="keyword">public</span> <a class="code" href="classFX_1_1FXDict.html">FXDict</a> { <a name="l00108"></a><a class="code" href="classFX_1_1FXFileDict.html#s2">00108</a> FXDECLARE(FXFileDict) 00109 <span class="keyword">private</span>: 00110 <a class="code" href="classFX_1_1FXApp.html">FXApp</a> *app; <span class="comment">// Application object</span> 00111 <a class="code" href="classFX_1_1FXSettings.html">FXSettings</a> *settings; <span class="comment">// Settings database where to get bindings</span> 00112 FXIconDict *icons; <span class="comment">// Icon table</span> 00113 <span class="keyword">protected</span>: 00114 FXFileDict(){} 00115 <span class="keyword">virtual</span> <span class="keywordtype">void</span> *createData(<span class="keyword">const</span> <span class="keywordtype">void</span>*); 00116 <span class="keyword">virtual</span> <span class="keywordtype">void</span> deleteData(<span class="keywordtype">void</span>*); 00117 <span class="keyword">private</span>: 00118 FXFileDict(<span class="keyword">const</span> FXFileDict&); 00119 FXFileDict &operator=(<span class="keyword">const</span> FXFileDict&); 00120 <span class="keyword">public</span>: 00121 <span class="comment"></span> 00122 <span class="comment"> /// Registry key used to find fallback executable icons</span> 00123 <span class="comment"></span> <span class="keyword">static</span> <span class="keyword">const</span> FXchar defaultExecBinding[]; <a name="l00124"></a><a class="code" href="classFX_1_1FXFileDict.html#a2">00124</a> <span class="comment"></span> 00125 <span class="comment"> /// Registry key used to find fallback directory icons</span> 00126 <span class="comment"></span> <span class="keyword">static</span> <span class="keyword">const</span> FXchar defaultDirBinding[]; 00127 <span class="comment"></span> 00128 <span class="comment"> /// Registry key used to find fallback document icons</span> 00129 <span class="comment"></span> <span class="keyword">static</span> <span class="keyword">const</span> FXchar defaultFileBinding[]; 00130 <span class="keyword">public</span>: 00131 <span class="comment"></span> 00132 <span class="comment"> /**</span> 00133 <span class="comment"> * Construct a dictionary mapping file-extension to file associations,</span> 00134 <span class="comment"> * using the application registry settings as a source for the bindings.</span> 00135 <span class="comment"> */</span> 00136 FXFileDict(<a class="code" href="classFX_1_1FXApp.html">FXApp</a>* a); 00137 <span class="comment"></span> 00138 <span class="comment"> /**</span> 00139 <span class="comment"> * Construct a dictionary mapping file-extension to file associations,</span> 00140 <span class="comment"> * using the specified settings database as a source for the bindings.</span> 00141 <span class="comment"> */</span> 00142 FXFileDict(<a class="code" href="classFX_1_1FXApp.html">FXApp</a>* a,<a class="code" href="classFX_1_1FXSettings.html">FXSettings</a>* db); 00143 <span class="comment"></span> 00144 <span class="comment"> /// Get application</span> 00145 <span class="comment"></span> <a class="code" href="classFX_1_1FXApp.html">FXApp</a>* getApp()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> app; } 00146 <span class="comment"></span> 00147 <span class="comment"> /// Set icon search path</span> 00148 <span class="comment"></span> <span class="keywordtype">void</span> setIconPath(<span class="keyword">const</span> FXString& path); 00149 <span class="comment"></span> 00150 <span class="comment"> /// Return current icon search path</span> 00151 <span class="comment"></span> FXString getIconPath() <span class="keyword">const</span>; 00152 <span class="comment"></span> 00153 <span class="comment"> /**</span> 00154 <span class="comment"> * Replace file association.</span> 00155 <span class="comment"> * The new association is written into the settings database under the</span> 00156 <span class="comment"> * FILETYPES section; the format of the association is as follows:</span> 00157 <span class="comment"> *</span> <a name="l00158"></a><a class="code" href="classFX_1_1FXFileDict.html#a7">00158</a> <span class="comment"> * <extension> = "<command> ; <type> ; <bigicon> [ : <bigopenicon> ] ; <smallicon> [ : <smalliconopen> ] ; <mimetype>"</span> 00159 <span class="comment"> *</span> 00160 <span class="comment"> * Where <command> is the command used to launch the application (e.g. "xv %s &"),</span> 00161 <span class="comment"> * and <type> is the file type string (e.g. "GIF Image"),</span> 00162 <span class="comment"> * <bigicon> and <bigiconopen> are the large icons shown in "Icons" mode,</span> 00163 <span class="comment"> * <smallicon> and <smalliconopen> are the small icons shown in "Details" mode,</span> 00164 <span class="comment"> * and <mimetype> is the RFC2045 mime type of the file.</span> 00165 <span class="comment"> *</span> 00166 <span class="comment"> * For example:</span> 00167 <span class="comment"> *</span> 00168 <span class="comment"> * [FILETYPES]</span> 00169 <span class="comment"> * gif="xv %s &;GIF Image;big.xpm:bigopen.xpm;mini.xpm:miniopen.xpm;image/gif"</span> 00170 <span class="comment"> * /home/jeroen=";Home;home.xpm;minihome.xpm;application/x-folder"</span> 00171 <span class="comment"> *</span> 00172 <span class="comment"> */</span> 00173 <a class="code" href="structFX_1_1FXFileAssoc.html">FXFileAssoc</a>* replace(<span class="keyword">const</span> FXchar* ext,<span class="keyword">const</span> FXchar* str); 00174 <span class="comment"></span> 00175 <span class="comment"> /// Remove file association</span> 00176 <span class="comment"></span> <a class="code" href="structFX_1_1FXFileAssoc.html">FXFileAssoc</a>* remove(<span class="keyword">const</span> FXchar* ext); 00177 <span class="comment"></span> 00178 <span class="comment"> /// Find file association already in dictionary</span> 00179 <span class="comment"></span> <a class="code" href="structFX_1_1FXFileAssoc.html">FXFileAssoc</a>* find(<span class="keyword">const</span> FXchar* ext){ <span class="keywordflow">return</span> (<a class="code" href="structFX_1_1FXFileAssoc.html">FXFileAssoc</a>*)FXDict::find(ext); } 00180 <span class="comment"></span> 00181 <span class="comment"> /// Find file association from registry</span> 00182 <span class="comment"></span> FXFileAssoc* associate(<span class="keyword">const</span> FXchar* key); 00183 <span class="comment"></span> 00184 <span class="comment"> /**</span> 00185 <span class="comment"> * Determine binding for the given file.</span> 00186 <span class="comment"> * The default implementation tries the whole filename first,</span> 00187 <span class="comment"> * then tries the extensions.</span> 00188 <span class="comment"> * For example, for a file "source.tar.gz":</span> 00189 <span class="comment"> *</span> 00190 <span class="comment"> * "source.tar.gz",</span> 00191 <span class="comment"> * "tar.gz",</span> 00192 <span class="comment"> * "gz"</span> 00193 <span class="comment"> *</span> 00194 <span class="comment"> * are tried in succession. If no association is found the</span> 00195 <span class="comment"> * key "defaultfilebinding" is tried as a fallback association.</span> 00196 <span class="comment"> * A NULL is returned if no association of any kind is found.</span> 00197 <span class="comment"> */</span> 00198 <span class="keyword">virtual</span> FXFileAssoc* findFileBinding(<span class="keyword">const</span> FXchar* pathname); 00199 <span class="comment"></span> 00200 <span class="comment"> /**</span> 00201 <span class="comment"> * Find directory binding from registry.</span> 00202 <span class="comment"> * The default implementation tries the whole pathname first,</span> 00203 <span class="comment"> * then tries successively smaller parts of the path.</span> 00204 <span class="comment"> * For example, a pathname "/usr/people/jeroen":</span> 00205 <span class="comment"> *</span> 00206 <span class="comment"> * "/usr/people/jeroen"</span> 00207 <span class="comment"> * "/people/jeroen"</span> 00208 <span class="comment"> * "/jeroen"</span> 00209 <span class="comment"> *</span> 00210 <span class="comment"> * are tried in succession. If no bindings are found, the</span> 00211 <span class="comment"> * key "defaultdirbinding" is tried as a fallback association.</span> 00212 <span class="comment"> * A NULL is returned if no association of any kind is found.</span> 00213 <span class="comment"> */</span> 00214 <span class="keyword">virtual</span> FXFileAssoc* findDirBinding(<span class="keyword">const</span> FXchar* pathname); 00215 <span class="comment"></span> 00216 <span class="comment"> /**</span> 00217 <span class="comment"> * Determine binding for the given executable.</span> 00218 <span class="comment"> * The default implementation returns the fallback binding associated with</span> 00219 <span class="comment"> * the key "defaultexecbinding".</span> 00220 <span class="comment"> * A NULL is returned if no association of any kind is found.</span> 00221 <span class="comment"> */</span> 00222 <span class="keyword">virtual</span> FXFileAssoc* findExecBinding(<span class="keyword">const</span> FXchar* pathname); 00223 <span class="comment"></span> 00224 <span class="comment"> /// Save to stream</span> 00225 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> save(FXStream& store) <span class="keyword">const</span>; 00226 <span class="comment"></span> 00227 <span class="comment"> /// Load from stream</span> 00228 <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> load(FXStream& store); 00229 <span class="comment"></span> 00230 <span class="comment"> /// Destructor</span> 00231 <span class="comment"></span> <span class="keyword">virtual</span> ~FXFileDict(); 00232 }; 00233 00234 } 00235 00236 <span class="preprocessor">#endif</span> </pre></div></font> <!--- COPYRIGHT --> <p> <table width=100% cellpadding=0 cellspacing=0><tr><td width=100% valign=top id=HEADLINE align=right> <img src='../art/line.gif' width=100% height=1><font size=-1> Copyright © 1997-2004 Jeroen van der Zijp</font> </td></tr></table> </p> <!--- COPYRIGHT --> </body> </html>