Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

fdftlmk.cpp

Go to the documentation of this file.
00001 /* 00002 * wxChecksums 00003 * Copyright (C) 2003-2004 Julien Couot 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 /** 00021 * \file fdftlmk.cpp 00022 * Files dialog filter maker class. 00023 */ 00024 00025 00026 //--------------------------------------------------------------------------- 00027 // For compilers that support precompilation, includes "wx.h". 00028 #include <wx/wxprec.h> 00029 00030 #ifdef __BORLANDC__ 00031 #pragma hdrstop 00032 #endif 00033 00034 #ifndef WX_PRECOMP 00035 // Include your minimal set of headers here, or wx.h 00036 #include <wx/wx.h> 00037 #endif 00038 00039 #include <wx/filename.h> 00040 #include <wx/tokenzr.h> 00041 00042 #include "fdftlmk.hpp" 00043 #include "utils.hpp" 00044 00045 #include "compat.hpp" 00046 //--------------------------------------------------------------------------- 00047 00048 00049 /// The C++ standard namespace. 00050 using namespace std; 00051 00052 00053 /** 00054 * Default constructor. 00055 */ 00056 wxFileDialogFilterMaker::wxFileDialogFilterMaker() 00057 { 00058 } 00059 //--------------------------------------------------------------------------- 00060 00061 00062 /** 00063 * Clones the source instance in this instance. 00064 * 00065 * @param source Source instance. 00066 */ 00067 void wxFileDialogFilterMaker::clone(const wxFileDialogFilterMaker& source) 00068 { 00069 if (this != &source) 00070 { 00071 this->descrs = source.descrs; 00072 this->filters = source.filters; 00073 } 00074 } 00075 //--------------------------------------------------------------------------- 00076 00077 00078 /** 00079 * Copy constructor. 00080 * 00081 * @param source Source instance. 00082 */ 00083 wxFileDialogFilterMaker::wxFileDialogFilterMaker(const wxFileDialogFilterMaker& source) 00084 { 00085 clone(source); 00086 } 00087 //--------------------------------------------------------------------------- 00088 00089 00090 /** 00091 * Assignment operator. 00092 * 00093 * @param source Source instance. 00094 * @return A reference on the instance. 00095 */ 00096 wxFileDialogFilterMaker& wxFileDialogFilterMaker::operator=(const wxFileDialogFilterMaker& source) 00097 { 00098 clone(source); 00099 return *this; 00100 } 00101 //--------------------------------------------------------------------------- 00102 00103 00104 /** 00105 * Adds a filter. 00106 * 00107 * @param descr Description of the filter (ex: "All files"). 00108 * @param filter List of extensions without dot, separed with '|'. 00109 */ 00110 void wxFileDialogFilterMaker::AddFilter(const wxString& descr, const wxString& filter) 00111 { 00112 descrs.Add(descr); 00113 filters.Add(filter); 00114 } 00115 //--------------------------------------------------------------------------- 00116 00117 00118 /** 00119 * Gets a string that contains the filters for a <CODE>wxFileDialog</CODE> 00120 * instance. 00121 * 00122 * @param format Creates filters for this path format. If the file names of 00123 * this type are case-sensitive, as much as combinaisons with 00124 * lower and upper cases for the filter name will created 00125 * (ex: under Unix 'cp' filter will be expanded to: 'cp', 'Cp', 00126 * 'cP', 'CP'). 00127 * @param addFiltersInDescriptions Adds the filters at the end of the 00128 * description if <CODE>true</CODE> (ex: 00129 * description = 'All the files', 00130 * filter = 'c|cpp', 00131 * result = 'All the files (*.c;*.cpp)'). 00132 * @return A string that contains the filters for a <CODE>wxFileDialog</CODE> 00133 * instance. 00134 */ 00135 wxString wxFileDialogFilterMaker::GetFilters(const wxPathFormat format, 00136 const bool addFiltersInDescriptions) const 00137 { 00138 wxString s; 00139 00140 for (size_t i = 0; i < descrs.GetCount(); i++) 00141 { 00142 // Adds the description 00143 if (!s.empty()) 00144 s += wxT('|'); 00145 s += descrs[i]; 00146 00147 // Adds the filters in the description 00148 if (addFiltersInDescriptions) 00149 { 00150 s += wxT(" ("); 00151 bool firstToken = true; // no ';' before the first filter 00152 wxStringTokenizer tkz(filters[i], wxT("|")); 00153 while (tkz.HasMoreTokens()) 00154 { 00155 wxString token = tkz.GetNextToken(); 00156 if (firstToken) 00157 firstToken = false; 00158 else 00159 s += wxT(';'); 00160 00161 s += wxT("*.") + token; 00162 } 00163 s += wxT(')'); 00164 } 00165 s += wxT('|'); 00166 00167 // Creates the filters if files on the current OS are case sensitive 00168 wxArrayString tk; // tokens to add 00169 wxStringTokenizer tkz(filters[i], wxT("|")); 00170 while (tkz.HasMoreTokens()) 00171 { 00172 wxString token = tkz.GetNextToken(); 00173 if (wxFileName::IsCaseSensitive(format)) 00174 GetAllTokenCases(token, tk); 00175 else 00176 tk.Add(token); 00177 } 00178 00179 // Adds the filters 00180 bool firstToken = true; // no ';' before the first filter 00181 for (size_t j = 0; j < tk.GetCount(); j++) 00182 { 00183 if (firstToken) 00184 firstToken = false; 00185 else 00186 s += wxT(';'); 00187 #if defined(__UNIX__) 00188 if (tk[j] != wxT("*")) 00189 #endif // defined(__UNIX__) 00190 s += wxT("*."); 00191 s += tk[j]; 00192 } 00193 } 00194 00195 return s; 00196 } 00197 //---------------------------------------------------------------------------

Generated on Sun May 30 13:37:44 2004 for wxChecksums by doxygen 1.3.7