From 11d395f9d74b35a0bcaf222de1d8f093b9dba2c4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Jul 2003 01:13:18 +0000 Subject: [PATCH] icon location may contain , so added GetIcon() overload taking MessageParameters git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22190 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mimetype.h | 2 ++ src/common/mimecmn.cpp | 19 ++++++++++++++++ src/msw/mimetype.cpp | 51 +++++++++++++++++++++++++----------------- 3 files changed, 51 insertions(+), 21 deletions(-) diff --git a/include/wx/mimetype.h b/include/wx/mimetype.h index 59071d6d30..e2eec1777e 100644 --- a/include/wx/mimetype.h +++ b/include/wx/mimetype.h @@ -212,6 +212,8 @@ public: bool GetExtensions(wxArrayString& extensions); // get the icon corresponding to this file type and of the given size bool GetIcon(wxIconLocation *iconloc) const; + bool GetIcon(wxIconLocation *iconloc, + const MessageParameters& params) const; // get a brief file type description ("*.txt" => "text document") bool GetDescription(wxString *desc) const; diff --git a/src/common/mimecmn.cpp b/src/common/mimecmn.cpp index bd85dc0a58..943645f89d 100644 --- a/src/common/mimecmn.cpp +++ b/src/common/mimecmn.cpp @@ -285,6 +285,25 @@ bool wxFileType::GetIcon(wxIconLocation *iconLoc) const return m_impl->GetIcon(iconLoc); } +bool +wxFileType::GetIcon(wxIconLocation *iconloc, + const MessageParameters& params) const +{ + if ( !GetIcon(iconloc) ) + { + return false; + } + + // we may have "%s" in the icon location string, at least under Windows, so + // expand this + if ( iconloc ) + { + iconloc->SetFileName(ExpandCommand(iconloc->GetFileName(), params)); + } + + return true; +} + bool wxFileType::GetDescription(wxString *desc) const { wxCHECK_MSG( desc, FALSE, _T("invalid parameter in GetDescription") ); diff --git a/src/msw/mimetype.cpp b/src/msw/mimetype.cpp index 01e5968316..a7242a7de4 100644 --- a/src/msw/mimetype.cpp +++ b/src/msw/mimetype.cpp @@ -77,6 +77,33 @@ class WXDLLEXPORT wxIcon; // location, uses it, so it isn't likely to change static const wxChar *MIME_DATABASE_KEY = wxT("MIME\\Database\\Content Type\\"); +// this function replaces Microsoft %1 with Unix-like %s +static bool CanonicalizeParams(wxString& command) +{ + // transform it from '%1' to '%s' style format string (now also test for %L + // as apparently MS started using it as well for the same purpose) + + // NB: we don't make any attempt to verify that the string is valid, i.e. + // doesn't contain %2, or second %1 or .... But we do make sure that we + // return a string with _exactly_ one '%s'! + bool foundFilename = false; + size_t len = command.length(); + for ( size_t n = 0; (n < len) && !foundFilename; n++ ) + { + if ( command[n] == wxT('%') && + (n + 1 < len) && + (command[n + 1] == wxT('1') || command[n + 1] == wxT('L')) ) + { + // replace it with '%s' + command[n + 1] = wxT('s'); + + foundFilename = true; + } + } + + return foundFilename; +} + void wxFileTypeImpl::Init(const wxString& strFileType, const wxString& ext) { // VZ: does it? (FIXME) @@ -202,26 +229,7 @@ wxString wxFileTypeImpl::GetCommand(const wxChar *verb) const if ( key.Open() ) { // it's the default value of the key if ( key.QueryValue(wxEmptyString, command) ) { - // transform it from '%1' to '%s' style format string (now also - // test for %L - apparently MS started using it as well for the - // same purpose) - - // NB: we don't make any attempt to verify that the string is valid, - // i.e. doesn't contain %2, or second %1 or .... But we do make - // sure that we return a string with _exactly_ one '%s'! - bool foundFilename = FALSE; - size_t len = command.Len(); - for ( size_t n = 0; (n < len) && !foundFilename; n++ ) { - if ( command[n] == wxT('%') && - (n + 1 < len) && - (command[n + 1] == wxT('1') || - command[n + 1] == wxT('L')) ) { - // replace it with '%s' - command[n + 1] = wxT('s'); - - foundFilename = TRUE; - } - } + bool foundFilename = CanonicalizeParams(command); #if wxUSE_IPC // look whether we must issue some DDE requests to the application @@ -251,7 +259,8 @@ wxString wxFileTypeImpl::GetCommand(const wxChar *verb) const } else #endif // wxUSE_IPC - if ( !foundFilename ) { + if ( !foundFilename ) + { // we didn't find any '%1' - the application doesn't know which // file to open (note that we only do it if there is no DDEExec // subkey) -- 2.45.2