From: <arn...@us...> - 2008-03-30 08:14:24
|
Revision: 1086 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=1086&view=rev Author: arnetheduck Date: 2008-03-30 01:14:18 -0700 (Sun, 30 Mar 2008) Log Message: ----------- Update load/save dialogs Modified Paths: -------------- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h dcplusplus/trunk/smartwin/include/smartwin/widgets/LoadDialog.h dcplusplus/trunk/smartwin/include/smartwin/widgets/SaveDialog.h Property Changed: ---------------- dcplusplus/trunk/ Property changes on: dcplusplus/trunk ___________________________________________________________________ Name: bzr:revision-info - timestamp: 2008-03-29 07:15:58.839999914 +0100 committer: Jacek Sieka <arn...@gm...> properties: branch-nick: dcplusplus + timestamp: 2008-03-29 09:12:53.312000036 +0100 committer: Jacek Sieka <arn...@gm...> properties: branch-nick: dcplusplus Name: bzr:revision-id:v3-trunk1 - 1027 arn...@gm...-20080323183926-schknwnkgeo7ivdn 1028 zouzou123gen-20080323220411-r8usuc3qxwuh7zsn 1029 zouzou123gen-20080323221249-0su72zaj13e706mk 1030 arn...@gm...-20080324140623-muba1dl46m000o8c 1031 zouzou123gen-20080324141933-qbgr93ugpe0297m6 1032 arn...@gm...-20080324153706-siidja05n84i00b1 1033 arn...@gm...-20080324153823-lhn3awurnu77riln 1034 arn...@gm...-20080324165650-zapppziji67yf5a2 1035 zouzou123gen-20080324175936-4mqc2kh0lo5wtdu2 1036 zouzou123gen-20080325004602-6wdsoym95mjuhwd3 1037 arn...@gm...-20080325100659-8fqy6q65itmghlep 1038 zouzou123gen-20080325175216-s297sdiucukfvijh 1039 arn...@gm...-20080325210137-3dfqyoi8ykosy087 1040 arn...@gm...-20080325211747-nwwy1eb33r071sca 1041 arn...@gm...-20080326084110-qbselrjckku275xi 1042 zouzou123gen-20080326123631-35642mgbk2i4ty32 1043 zouzou123gen-20080326124345-f4xwn2d3ty8ubd6r 1044 arn...@gm...-20080326162031-il0nyms30w0mky43 1045 arn...@gm...-20080326164801-8dru8mjc06xgzjpv 1046 arn...@gm...-20080326170438-uzl2rx8fqnohak7g 1047 zouzou123gen-20080326172821-d6uqcbmfb0c6rwlv 1048 arn...@gm...-20080326213257-qlgdh7m2712p2l0q 1049 arn...@gm...-20080326214313-ktnoekgk3s0wmatz 1050 arn...@gm...-20080326215256-0j1iqrf286b9g7zf 1051 arn...@gm...-20080327082121-hoi22wh1gwjdfbyd 1052 arn...@gm...-20080327120639-um3tukdt374rwvgm 1053 zouzou123gen-20080327130703-6vtek6uxy3vua543 1054 arn...@gm...-20080327215831-dmg5mkufskabwkro 1055 arn...@gm...-20080327231459-cdztcv25alsuyqmf 1056 arn...@gm...-20080328085925-gceybsr53oml1p24 1057 arn...@gm...-20080328200512-1sjuu6bcnl2dyd2a 1058 arn...@gm...-20080328210347-bussqjrm5mfswh7o 1059 arn...@gm...-20080329055630-braiir1dskv7a4qm 1060 arn...@gm...-20080329061558-rck8dz60wpj3c5ja + 1027 arn...@gm...-20080323183926-schknwnkgeo7ivdn 1028 zouzou123gen-20080323220411-r8usuc3qxwuh7zsn 1029 zouzou123gen-20080323221249-0su72zaj13e706mk 1030 arn...@gm...-20080324140623-muba1dl46m000o8c 1031 zouzou123gen-20080324141933-qbgr93ugpe0297m6 1032 arn...@gm...-20080324153706-siidja05n84i00b1 1033 arn...@gm...-20080324153823-lhn3awurnu77riln 1034 arn...@gm...-20080324165650-zapppziji67yf5a2 1035 zouzou123gen-20080324175936-4mqc2kh0lo5wtdu2 1036 zouzou123gen-20080325004602-6wdsoym95mjuhwd3 1037 arn...@gm...-20080325100659-8fqy6q65itmghlep 1038 zouzou123gen-20080325175216-s297sdiucukfvijh 1039 arn...@gm...-20080325210137-3dfqyoi8ykosy087 1040 arn...@gm...-20080325211747-nwwy1eb33r071sca 1041 arn...@gm...-20080326084110-qbselrjckku275xi 1042 zouzou123gen-20080326123631-35642mgbk2i4ty32 1043 zouzou123gen-20080326124345-f4xwn2d3ty8ubd6r 1044 arn...@gm...-20080326162031-il0nyms30w0mky43 1045 arn...@gm...-20080326164801-8dru8mjc06xgzjpv 1046 arn...@gm...-20080326170438-uzl2rx8fqnohak7g 1047 zouzou123gen-20080326172821-d6uqcbmfb0c6rwlv 1048 arn...@gm...-20080326213257-qlgdh7m2712p2l0q 1049 arn...@gm...-20080326214313-ktnoekgk3s0wmatz 1050 arn...@gm...-20080326215256-0j1iqrf286b9g7zf 1051 arn...@gm...-20080327082121-hoi22wh1gwjdfbyd 1052 arn...@gm...-20080327120639-um3tukdt374rwvgm 1053 zouzou123gen-20080327130703-6vtek6uxy3vua543 1054 arn...@gm...-20080327215831-dmg5mkufskabwkro 1055 arn...@gm...-20080327231459-cdztcv25alsuyqmf 1056 arn...@gm...-20080328085925-gceybsr53oml1p24 1057 arn...@gm...-20080328200512-1sjuu6bcnl2dyd2a 1058 arn...@gm...-20080328210347-bussqjrm5mfswh7o 1059 arn...@gm...-20080329055630-braiir1dskv7a4qm 1060 arn...@gm...-20080329061558-rck8dz60wpj3c5ja 1061 arn...@gm...-20080329081253-if6o5jn329mbzfpl Modified: dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h 2008-03-29 08:10:38 UTC (rev 1085) +++ dcplusplus/trunk/smartwin/include/smartwin/aspects/AspectFileFilter.h 2008-03-30 08:14:18 UTC (rev 1086) @@ -29,8 +29,7 @@ #define AspectFileFilter_h #include "../WindowsHeaders.h" -#include <vector> -#include "SmartUtil.h" +#include "../../SmartUtil.h" #include "../xCeption.h" namespace SmartWin @@ -44,6 +43,7 @@ * Help the LoadDialog and the SaveDialog to add up filters on which file * types to look for! */ +template<typename WidgetType> class AspectFileFilter { public: @@ -52,12 +52,13 @@ * "HTML Files" etc. filter is the actual filter to filter in files to show * normally this would be e.g. "*.html". */ - void addFilter( const SmartUtil::tstring & filterName, const SmartUtil::tstring & filter ) + WidgetType& addFilter( const SmartUtil::tstring & filterName, const SmartUtil::tstring & filter ) { itsFilter.insert( itsFilter.end(), filterName.begin(), filterName.end() ); itsFilter.push_back( '\0' ); itsFilter.insert( itsFilter.end(), filter.begin(), filter.end() ); itsFilter.push_back( '\0' ); + return *static_cast<WidgetType*>(this); } /// Sets the active filter to the specified index @@ -65,21 +66,24 @@ * filter you added will be the active filter. Active filter means the default * filter used when first showing the dialog. */ - void activeFilter( unsigned filterNo ) - { + WidgetType& setActiveFilter( unsigned filterNo ) { if ( filterNo >= itsFilter.size() ) { xCeption x( _T( "Tried to set active filter to more than number of filters in filter..." ) ); throw x; } itsActiveFilter = filterNo; + return *static_cast<WidgetType*>(this); } + + WidgetType& setDefaultExtension(const SmartUtil::tstring& defExt) { + itsDefExt = defExt; + } /// Returns the active filter of the object /** The active filter is the "currently selected" filter of the filter class */ - unsigned getActiveFilter() const - { + unsigned getActiveFilter() const { // Filter index is NOT a zero indexed array... return itsActiveFilter + 1; } @@ -88,73 +92,47 @@ /** If given your dialog will try to start in the given directory, otherwise it * will use the working directory of the process. */ - void setStartDirectory( SmartUtil::tstring startDir ) - { - itsStartDir = startDir; + WidgetType& setInitialDirectory( const SmartUtil::tstring& initialDir ) { + itsInitialDir = initialDir; + return *static_cast<WidgetType*>(this); } - /// Ensure filename meets OS expectations for path separators. - /** We want SaveDialog and LoadDialog to always return a pathname that - * meets the OS expectations. <br> - * Windows wants: C:\dir\dir\file.ext <br> - * and UnixLinux: /dir/dir/file.ext <br> - * - * Wine produces z:\dir\dir\file.exe from GetLoadFileName(&ofn) )and - * GetSaveFileName(&ofn). <br> - * - * So if we are building for wine, we need to convert from the wine output to - * the Linux format. <br> - * IE: convert z:\home\awebb\file.txt to /home/awebb/file.txt <br> - * - * The assumption is that the C++ standard library is Linux native, and thus - * needs / pathnames. - */ - //TODO: use boost filenames - void backslashToForwardSlashForUnix( SmartUtil::tstring & filename ) - { - // wineg++ defines __WINE__ Note we can't use WIN32 because that is also true for wine builds. -#ifdef __WINE__ - if ( 0 != filename.find( "z:" ) ) return; // Not a WINE produced path ?, nothing to do. - filename.erase( 0, 2 ); // Remove "z:" prefix. +protected: + Widget* itsParent; - // Unix file system do not use "\", so convert to "/" - size_t pos_n; - while ( std::string::npos != ( pos_n = filename.find( '\\' ) ) ) - { - filename.replace( pos_n, 1, "/" ); - } -#endif - } + static const int PATH_BUFFER_SIZE = 32768; - -protected: - Widget * itsParent; + TCHAR szFile[PATH_BUFFER_SIZE]; + HWND getParentHandle() { return itsParent ? itsParent->handle() : NULL; } AspectFileFilter(Widget* parent) : itsParent(parent), itsActiveFilter( 0 ) {} - static const int PATH_BUFFER_SIZE = 32768; //really arbitrary, but 32K sounds reasonable. size in number of TCHARS! - // Fills out the common members of the OPENFILENAME struct. // This is called for both LoadDialog and for SaveDialog Widgets - void fillOFN( OPENFILENAME & ofn, HWND parent, int flags ) - { - ofn.hwndOwner = parent; + void fillOFN( OPENFILENAME & ofn, int flags ) { + ofn.hwndOwner = getParentHandle(); ofn.nMaxFile = PATH_BUFFER_SIZE; - ofn.lpstrFilter = itsFilter.c_str(); + ofn.lpstrFile = szFile; + ofn.lpstrDefExt = ifNotEmpty(itsDefExt); + ofn.lpstrInitialDir = ifNotEmpty(itsInitialDir); + ofn.lpstrFilter = ifNotEmpty(itsFilter); ofn.nFilterIndex = this->getActiveFilter(); - ofn.lpstrInitialDir = itsStartDir.c_str(); ofn.Flags = flags; } - private: unsigned int itsActiveFilter; - SmartUtil::tstring itsStartDir; + SmartUtil::tstring itsInitialDir; SmartUtil::tstring itsFilter; + SmartUtil::tstring itsDefExt; + + static const TCHAR* ifNotEmpty(const SmartUtil::tstring& str) { + return str.empty() ? NULL : str.c_str(); + } }; // end namespace SmartWin Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/LoadDialog.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/LoadDialog.h 2008-03-29 08:10:38 UTC (rev 1085) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/LoadDialog.h 2008-03-30 08:14:18 UTC (rev 1086) @@ -45,7 +45,7 @@ * \sa AspectFileFilter */ class LoadDialog - : public AspectFileFilter + : public AspectFileFilter<LoadDialog> { public: /// Class type @@ -64,7 +64,7 @@ * before calling this function, if you wish the dialog to show only certain * types of files. */ - SmartUtil::tstring showDialog(); + bool open(SmartUtil::tstring& file); /// Shows the dialog /** Returns an empty vector if user press cancel. <br> @@ -74,7 +74,7 @@ * before calling this function, if you wish the dialog to show only certain * types of files. */ - std::vector<SmartUtil::tstring> showDialogMultiSelect(); + bool open(std::vector<SmartUtil::tstring>& files); // Constructor Taking pointer to parent explicit LoadDialog( Widget * parent = 0 ); @@ -86,66 +86,9 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Implementation of class /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -inline SmartUtil::tstring LoadDialog::showDialog() -{ - TCHAR szFile[PATH_BUFFER_SIZE]; // buffer for file name - szFile[0] = '\0'; - OPENFILENAME ofn = { sizeof(OPENFILENAME) }; // common dialog box structure - fillOFN( ofn, getParentHandle(), OFN_FILEMUSTEXIST ); - ofn.lpstrFile = szFile; - ofn.Flags |= OFN_FILEMUSTEXIST; - - SmartUtil::tstring retVal; - if ( ::GetOpenFileName( & ofn ) ) - { - retVal = ofn.lpstrFile; - backslashToForwardSlashForUnix( retVal ); - } - return retVal; -} - -inline std::vector<SmartUtil::tstring> LoadDialog::showDialogMultiSelect() -{ - TCHAR szFile[PATH_BUFFER_SIZE]; // buffer for file name - szFile[0] = '\0'; - - OPENFILENAME ofn = { sizeof(OPENFILENAME) }; // common dialog box structure - fillOFN( ofn, getParentHandle(), OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER ); - ofn.lpstrFile = szFile; - std::vector<SmartUtil::tstring> retVal; - if( ::GetOpenFileName(&ofn) ) - { - // If a single file is selected, the lpstrFile string is just the path terminated by TWO null bytes - // If multiple files are selected, the format of the string returned is: - // DIRECTORY_PATH + '\0' + FILE_NAME_1 + '\0' + FILE_NAME_2 + '\0' + ... + FILE_NAME_N + '\0' + '\0' - // (Note the last file name is terminated by two null bytes) - - SmartUtil::tstring fileName; - SmartUtil::tstring filePath; - SmartUtil::tstring directory; - directory = ofn.lpstrFile; // tstring ends at first null - TCHAR *array_p = ofn.lpstrFile + directory.length() + 1; // set pointer to one position past null - fileName = array_p; // fileName is substring from array_p to next null - if (fileName.length() == 0) // only one file was selected - retVal.push_back(directory); // string 'directory' contains full path - else - { - while (fileName.length() > 0) - { - filePath = directory + _T("\\") + fileName; - backslashToForwardSlashForUnix(filePath); - retVal.push_back(filePath); - array_p = array_p + fileName.length() + 1; // set pointer one position past null - fileName = array_p; // fileName is substring from array_p to next null - } - } - } - return retVal; -} - inline LoadDialog::LoadDialog( Widget * parent ) - : AspectFileFilter( parent ) + : AspectFileFilter<LoadDialog>( parent ) {} // end namespace SmartWin Modified: dcplusplus/trunk/smartwin/include/smartwin/widgets/SaveDialog.h =================================================================== --- dcplusplus/trunk/smartwin/include/smartwin/widgets/SaveDialog.h 2008-03-29 08:10:38 UTC (rev 1085) +++ dcplusplus/trunk/smartwin/include/smartwin/widgets/SaveDialog.h 2008-03-30 08:14:18 UTC (rev 1086) @@ -44,7 +44,7 @@ * \sa AspectFileFilter */ class SaveDialog - : public AspectFileFilter + : public AspectFileFilter<SaveDialog> { public: /// Class type @@ -73,26 +73,9 @@ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Implementation of class /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -inline bool SaveDialog::open(SmartUtil::tstring& target) -{ - TCHAR szFile[PATH_BUFFER_SIZE + 1]; // buffer for file name - szFile[0] = '\0'; - OPENFILENAME ofn = { sizeof(OPENFILENAME) }; // common dialog box structure - fillOFN( ofn, getParentHandle(), 0 ); - ofn.lpstrFile = szFile; - - if ( ::GetSaveFileName( & ofn ) ) - { - target = ofn.lpstrFile; - backslashToForwardSlashForUnix( target ); - return true; - } - return false; -} - inline SaveDialog::SaveDialog( Widget * parent ) - : AspectFileFilter( parent ) + : AspectFileFilter<SaveDialog>( parent ) { } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |