FileDlg.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003-2008 T. Zachary Laine
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public License
00007    as published by the Free Software Foundation; either version 2.1
00008    of the License, or (at your option) any later version.
00009    
00010    This library 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 GNU
00013    Lesser General Public License for more details.
00014     
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA
00019 
00020    If you do not wish to comply with the terms of the LGPL please
00021    contact the author as other terms are available for a fee.
00022     
00023    Zach Laine
00024    whatwasthataddress@gmail.com */
00025 
00028 #ifndef _GG_FileDlg_h_
00029 #define _GG_FileDlg_h_
00030 
00031 #include <GG/DropDownList.h>
00032 
00033 #include <boost/filesystem/path.hpp>
00034 
00035 
00036 namespace GG {
00037 
00038 class TextControl;
00039 class Edit;
00040 class Button;
00041 class Font;
00042 
00055 class GG_API FileDlg : public Wnd
00056 {
00057 public: 
00059 
00069     FileDlg(const std::string& directory, const std::string& filename, bool save, bool multi, const boost::shared_ptr<Font>& font,
00070             Clr color, Clr border_color, Clr text_color = CLR_BLACK);
00072  
00074     std::set<std::string> Result() const; 
00075 
00077     bool SelectDirectories() const;
00078 
00085     bool AppendMissingSaveExtension() const;
00086 
00087     const std::string& FilesString() const;                
00088     const std::string& FileTypesString() const;            
00089     const std::string& SaveString() const;                 
00090     const std::string& OpenString() const;                 
00091     const std::string& CancelString() const;               
00092 
00093     const std::string& MalformedFilenameString() const;    
00094     const std::string& OverwritePromptString() const;      
00095     const std::string& InvalidFilenameString() const;      
00096     const std::string& FilenameIsADirectoryString() const; 
00097     const std::string& FileDoesNotExistString() const;     
00098     const std::string& DeviceIsNotReadyString() const;     
00099     const std::string& ThreeButtonDlgOKString() const;     
00100     const std::string& ThreeButtonDlgCancelString() const; 
00101 
00102  
00104     virtual void Render();
00105     virtual void KeyPress(Key key, boost::uint32_t key_code_point, Flags<ModKey> mod_keys);
00106 
00109     void SelectDirectories(bool directories);
00110 
00117     void AppendMissingSaveExtension(bool append);
00118 
00130     void SetFileFilters(const std::vector<std::pair<std::string, std::string> >& filters);
00131 
00132     void SetFilesString(const std::string& str);                
00133     void SetFileTypesString(const std::string& str);            
00134     void SetSaveString(const std::string& str);                 
00135     void SetOpenString(const std::string& str);                 
00136     void SetCancelString(const std::string& str);               
00137 
00138     void SetMalformedFilenameString(const std::string& str);    
00139     void SetOverwritePromptString(const std::string& str);      
00140     void SetInvalidFilenameString(const std::string& str);      
00141     void SetFilenameIsADirectoryString(const std::string& str); 
00142     void SetFileDoesNotExistString(const std::string& str);     
00143     void SetDeviceIsNotReadyString(const std::string& str);     
00144     void SetThreeButtonDlgOKString(const std::string& str);     
00145     void SetThreeButtonDlgCancelString(const std::string& str); 
00146 
00147 
00150     static const boost::filesystem::path& WorkingDirectory();
00151  
00153 
00154     GG_ABSTRACT_EXCEPTION(Exception);
00155 
00157     GG_CONCRETE_EXCEPTION(BadInitialDirectory, GG::FileDlg, Exception);
00159 
00160 protected:
00161     static const X DEFAULT_WIDTH;  
00162     static const Y DEFAULT_HEIGHT; 
00163  
00165     FileDlg(); 
00166 
00167 
00168 private:
00169     void CreateChildren(const std::string& filename, bool multi);
00170     void PlaceLabelsAndEdits(X button_width, Y button_height);
00171     void AttachSignalChildren();
00172     void DetachSignalChildren();
00173     void Init(const std::string& directory);
00174     void ConnectSignals();
00175     void OkClicked();
00176     void OkHandler(bool double_click);
00177     void CancelClicked();
00178     void FileSetChanged(const ListBox::SelectionSet& files);
00179     void FileDoubleClicked(DropDownList::iterator it);
00180     void FilesEditChanged(const std::string& str);
00181     void FilterChanged(DropDownList::iterator it);
00182     void SetWorkingDirectory(const boost::filesystem::path& p);
00183     void PopulateFilters();
00184     void UpdateList();
00185     void UpdateDirectoryText();
00186     void OpenDirectory();
00187 
00188     Clr              m_color;
00189     Clr              m_border_color;
00190     Clr              m_text_color;
00191     boost::shared_ptr<Font>
00192                      m_font;
00193 
00194     bool             m_save;
00195     std::vector<std::pair<std::string, std::string> > 
00196                      m_file_filters;
00197     std::set<std::string>
00198                      m_result;
00199     bool             m_select_directories;
00200     bool             m_append_missing_save_extension;
00201     bool             m_in_win32_drive_selection;
00202 
00203     std::string      m_save_str;
00204     std::string      m_open_str;
00205     std::string      m_cancel_str;
00206 
00207     std::string      m_malformed_filename_str;
00208     std::string      m_overwrite_prompt_str;
00209     std::string      m_invalid_filename_str;
00210     std::string      m_filename_is_a_directory_str;
00211     std::string      m_file_does_not_exist_str;
00212     std::string      m_device_is_not_ready_str;
00213     std::string      m_three_button_dlg_ok_str;
00214     std::string      m_three_button_dlg_cancel_str;
00215 
00216     TextControl*     m_curr_dir_text;
00217     ListBox*         m_files_list;
00218     Edit*            m_files_edit;
00219     DropDownList*    m_filter_list;
00220     Button*          m_ok_button;
00221     Button*          m_cancel_button;
00222     TextControl*     m_files_label;
00223     TextControl*     m_file_types_label;
00224 
00225     static boost::filesystem::path s_working_dir; 
00226 
00227     friend class boost::serialization::access;
00228     template <class Archive>
00229     void serialize(Archive& ar, const unsigned int version);
00230 };
00231 
00232 } // namespace GG
00233 
00234 
00235 // template implementations
00236 template <class Archive>
00237 void GG::FileDlg::serialize(Archive& ar, const unsigned int version)
00238 {
00239     ar  & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Wnd)
00240         & BOOST_SERIALIZATION_NVP(m_color)
00241         & BOOST_SERIALIZATION_NVP(m_border_color)
00242         & BOOST_SERIALIZATION_NVP(m_text_color)
00243         & BOOST_SERIALIZATION_NVP(m_font)
00244         & BOOST_SERIALIZATION_NVP(m_save)
00245         & BOOST_SERIALIZATION_NVP(m_file_filters)
00246         & BOOST_SERIALIZATION_NVP(m_result)
00247         & BOOST_SERIALIZATION_NVP(m_save_str)
00248         & BOOST_SERIALIZATION_NVP(m_open_str)
00249         & BOOST_SERIALIZATION_NVP(m_cancel_str)
00250         & BOOST_SERIALIZATION_NVP(m_malformed_filename_str)
00251         & BOOST_SERIALIZATION_NVP(m_overwrite_prompt_str)
00252         & BOOST_SERIALIZATION_NVP(m_invalid_filename_str)
00253         & BOOST_SERIALIZATION_NVP(m_filename_is_a_directory_str)
00254         & BOOST_SERIALIZATION_NVP(m_file_does_not_exist_str)
00255         & BOOST_SERIALIZATION_NVP(m_device_is_not_ready_str)
00256         & BOOST_SERIALIZATION_NVP(m_three_button_dlg_ok_str)
00257         & BOOST_SERIALIZATION_NVP(m_three_button_dlg_cancel_str)
00258         & BOOST_SERIALIZATION_NVP(m_curr_dir_text)
00259         & BOOST_SERIALIZATION_NVP(m_files_list)
00260         & BOOST_SERIALIZATION_NVP(m_files_edit)
00261         & BOOST_SERIALIZATION_NVP(m_filter_list)
00262         & BOOST_SERIALIZATION_NVP(m_ok_button)
00263         & BOOST_SERIALIZATION_NVP(m_cancel_button)
00264         & BOOST_SERIALIZATION_NVP(m_files_label)
00265         & BOOST_SERIALIZATION_NVP(m_file_types_label)
00266         & BOOST_SERIALIZATION_NVP(m_select_directories)
00267         & BOOST_SERIALIZATION_NVP(m_append_missing_save_extension);
00268 
00269     if (Archive::is_loading::value)
00270         ConnectSignals();
00271 }
00272 
00273 #endif // _GG_FileDlg_h_

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9