From 9e152a55785098472ca1c0df110ad0a1203f710f Mon Sep 17 00:00:00 2001 From: =?utf8?q?W=C5=82odzimierz=20Skiba?= Date: Tue, 15 Jun 2004 15:25:33 +0000 Subject: [PATCH] wxParseWildcard added instead of methods hidden under wxUSE_FILEDLG and wxUSE_DIRDLG. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27811 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 2 ++ docs/latex/wx/function.tex | 13 +++++++++ include/wx/filedlg.h | 2 ++ include/wx/filefn.h | 7 +++++ include/wx/generic/dirctrlg.h | 2 ++ src/common/filefn.cpp | 54 +++++++++++++++++++++++++++++++++++ src/common/fldlgcmn.cpp | 50 +++----------------------------- src/generic/dirctrlg.cpp | 10 +++---- src/generic/filedlgg.cpp | 2 +- 9 files changed, 90 insertions(+), 52 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index b8ffe74ebc..7ef22a1045 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -55,6 +55,8 @@ INCOMPATIBLE CHANGES SINCE 2.4.x simply switch to using const methods. - EVT_XXX macros are now type-safe; code that uses wrong type for event handler's argument will no longer compile. +- Identical functionality of wxFileDialog::ParseWildcard and + wxGenericDirCtrl::ParseFilter is now accessible in ::wxParseWildcard diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex index e13adba784..d7c5913610 100644 --- a/docs/latex/wx/function.tex +++ b/docs/latex/wx/function.tex @@ -181,6 +181,7 @@ the corresponding topic. \helpref{wxNow}{wxnow}\\ \helpref{wxOnAssert}{wxonassert}\\ \helpref{wxOpenClipboard}{wxopenclipboard}\\ +\helpref{wxParseWildcard}{wxparsewildcard}\\ \helpref{wxPathOnly}{wxpathonly}\\ \helpref{wxPostDelete}{wxpostdelete}\\ \helpref{wxPostEvent}{wxpostevent}\\ @@ -1093,6 +1094,18 @@ Makes the directory {\it dir}, returning true if successful. supported (Unix) and doesn't have effect for the other ones. +\membersection{::wxParseWildcard}\label{wxparsewildcard} + +\func{int}{wxParseWildcard}{\param{const wxString\& }{wildCard}, \param{wxArrayString\& }{descriptions}, \param{wxArrayString\& }{filters}} + +Parses the wildCard, returning the number of filters. +Returns 0 if none or if there's a problem, +The arrays will contain an equal number of items found before the error. +{\it wildCard} is in the form: +\begin{verbatim} + "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png" +\end{verbatim} + \membersection{::wxRemoveFile}\label{wxremovefile} \func{bool}{wxRemoveFile}{\param{const wxString\& }{file}} diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index 23eccc3bc7..581aea398b 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -78,6 +78,7 @@ public: // Utility functions +#if WXWIN_COMPATIBILITY_2_4 // Parses the wildCard, returning the number of filters. // Returns 0 if none or if there's a problem, // The arrays will contain an equal number of items found before the error. @@ -86,6 +87,7 @@ public: static int ParseWildcard(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters); +#endif // WXWIN_COMPATIBILITY_2_4 // Append first extension to filePath from a ';' separated extensionList // if filePath = "path/foo.bar" just return it as is diff --git a/include/wx/filefn.h b/include/wx/filefn.h index 65e3396aa0..7c825eda5f 100644 --- a/include/wx/filefn.h +++ b/include/wx/filefn.h @@ -353,6 +353,13 @@ WXDLLIMPEXP_BASE wxString wxGetOSDirectory(); // Get file modification time WXDLLIMPEXP_BASE time_t wxFileModificationTime(const wxString& filename); +// Parses the wildCard, returning the number of filters. +// Returns 0 if none or if there's a problem, +// The arrays will contain an equal number of items found before the error. +// wildCard is in the form: +// "All files (*)|*|Image Files (*.jpeg *.png)|*.jpg;*.png" +WXDLLIMPEXP_BASE int wxParseWildcard(const wxString& wildCard, wxArrayString& descriptions, wxArrayString& filters); + // ---------------------------------------------------------------------------- // classes // ---------------------------------------------------------------------------- diff --git a/include/wx/generic/dirctrlg.h b/include/wx/generic/dirctrlg.h index 43dc914c23..cc6624c6fc 100644 --- a/include/wx/generic/dirctrlg.h +++ b/include/wx/generic/dirctrlg.h @@ -147,8 +147,10 @@ public: // Helper virtual void SetupSections(); +#if WXWIN_COMPATIBILITY_2_4 // Parse the filter into an array of filters and an array of descriptions virtual int ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions); +#endif // WXWIN_COMPATIBILITY_2_4 // Find the child that matches the first part of 'path'. // E.g. if a child path is "/usr" and 'path' is "/usr/include" diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index e227020173..940e50bc18 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -1836,6 +1836,60 @@ time_t WXDLLEXPORT wxFileModificationTime(const wxString& filename) } +// Parses the filterStr, returning the number of filters. +// Returns 0 if none or if there's a problem. +// filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg" + +int WXDLLEXPORT wxParseWildcard(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters) +{ + descriptions.Clear(); + filters.Clear(); + + wxString str(filterStr); + + wxString description, filter; + int pos = 0; + while( pos != wxNOT_FOUND ) + { + pos = str.Find(wxT('|')); + if ( pos == wxNOT_FOUND ) + { + // if there are no '|'s at all in the string just take the entire + // string as filter + if ( filters.IsEmpty() ) + { + descriptions.Add(filterStr); + filters.Add(filterStr); + } + else + { + wxFAIL_MSG( _T("missing '|' in the wildcard string!") ); + } + + break; + } + + description = str.Left(pos); + str = str.Mid(pos + 1); + pos = str.Find(wxT('|')); + if ( pos == wxNOT_FOUND ) + { + filter = str; + } + else + { + filter = str.Left(pos); + str = str.Mid(pos + 1); + } + + descriptions.Add(description); + filters.Add(filter); + } + + return filters.GetCount(); +} + + //------------------------------------------------------------------------ // wild character routines //------------------------------------------------------------------------ diff --git a/src/common/fldlgcmn.cpp b/src/common/fldlgcmn.cpp index c9d8e15494..df96a83102 100644 --- a/src/common/fldlgcmn.cpp +++ b/src/common/fldlgcmn.cpp @@ -80,59 +80,17 @@ wxFileDialogBase::wxFileDialogBase(wxWindow *parent, } } +#if WXWIN_COMPATIBILITY_2_4 // Parses the filterStr, returning the number of filters. // Returns 0 if none or if there's a problem. // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg" - int wxFileDialogBase::ParseWildcard(const wxString& filterStr, wxArrayString& descriptions, wxArrayString& filters) { - descriptions.Clear(); - filters.Clear(); - - wxString str(filterStr); - - wxString description, filter; - for ( int pos = 0; pos != wxNOT_FOUND; ) - { - pos = str.Find(wxT('|')); - if ( pos == wxNOT_FOUND ) - { - // if there are no '|'s at all in the string just take the entire - // string as filter - if ( filters.IsEmpty() ) - { - descriptions.Add(filterStr); - filters.Add(filterStr); - } - else - { - wxFAIL_MSG( _T("missing '|' in the wildcard string!") ); - } - - break; - } - - description = str.Left(pos); - str = str.Mid(pos + 1); - pos = str.Find(wxT('|')); - if ( pos == wxNOT_FOUND ) - { - filter = str; - } - else - { - filter = str.Left(pos); - str = str.Mid(pos + 1); - } - - descriptions.Add(description); - filters.Add(filter); - } - - return filters.GetCount(); + return ::wxParseWildcard(filterStr, descriptions, filters); } +#endif // WXWIN_COMPATIBILITY_2_4 wxString wxFileDialogBase::AppendExtension(const wxString &filePath, const wxString &extensionList) @@ -217,7 +175,7 @@ wxString wxFileSelector(const wxChar *title, wxArrayString descriptions, filters; // don't care about errors, handled already by wxFileDialog - (void)wxFileDialogBase::ParseWildcard(filter2, descriptions, filters); + (void)wxParseWildcard(filter2, descriptions, filters); for (size_t n=0; n 0 && n < count) { filter = filters[n]; @@ -1143,14 +1142,15 @@ bool wxGenericDirCtrl::ExtractWildcard(const wxString& filterStr, int n, wxStrin return FALSE; } +#if WXWIN_COMPATIBILITY_2_4 // Parses the global filter, returning the number of filters. // Returns 0 if none or if there's a problem. // filterStr is in the form: "All files (*.*)|*.*|JPEG Files (*.jpeg)|*.jpg" - int wxGenericDirCtrl::ParseFilter(const wxString& filterStr, wxArrayString& filters, wxArrayString& descriptions) { - return wxFileDialogBase::ParseWildcard(filterStr, descriptions, filters ); + return wxParseWildcard(filterStr, descriptions, filters ); } +#endif // WXWIN_COMPATIBILITY_2_4 void wxGenericDirCtrl::DoResize() { @@ -1252,7 +1252,7 @@ void wxDirFilterListCtrl::FillFilterList(const wxString& filter, int defaultFilt { Clear(); wxArrayString descriptions, filters; - size_t n = (size_t) m_dirCtrl->ParseFilter(filter, filters, descriptions); + size_t n = (size_t) wxParseWildcard(filter, filters, descriptions); if (n > 0 && defaultFilter < (int) n) { diff --git a/src/generic/filedlgg.cpp b/src/generic/filedlgg.cpp index 903c2423cc..6e593b95fb 100644 --- a/src/generic/filedlgg.cpp +++ b/src/generic/filedlgg.cpp @@ -900,7 +900,7 @@ wxGenericFileDialog::wxGenericFileDialog(wxWindow *parent, // interpret wildcards wxArrayString wildDescriptions, wildFilters; - if ( !ParseWildcard(m_wildCard, wildDescriptions, wildFilters) ) + if ( !wxParseWildcard(m_wildCard, wildDescriptions, wildFilters) ) { wxFAIL_MSG( wxT("Wrong file type description") ); } -- 2.45.2