]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/mimetype.cpp
Instead of m_menuBar use GetMenuBar() which will be modified (with next patch)
[wxWidgets.git] / src / msw / mimetype.cpp
index 01e59683164c88c8052c7d7a4ceced98bacb26d6..bd6edf88f5f84fd5eac096a9ac904a91a19ada81 100644 (file)
@@ -22,9 +22,6 @@
 
 #if wxUSE_MIMETYPE
 
-// Doesn't compile in WIN16 mode
-#ifndef __WIN16__
-
 #ifndef WX_PRECOMP
     #include "wx/string.h"
     #if wxUSE_GUI
@@ -77,6 +74,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 +226,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 +256,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)
@@ -505,7 +511,7 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
     wxCHECK_MSG( !ftInfo.GetExtensions().IsEmpty(), NULL,
                  _T("Associate() needs extension") );
 
-    bool ok = FALSE ;
+    bool ok;
     int iExtCount = 0 ;
     wxString filetype;
     wxString extWithDot;
@@ -542,7 +548,7 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
                 filetype = filetypeOrig;
             }
 
-            ok = key.SetValue(wxEmptyString, filetype);
+            key.SetValue(wxEmptyString, filetype);
         }
         }
         else
@@ -551,11 +557,11 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
             if (!filetypeOrig.empty())
                 {
                     filetype = filetypeOrig;
-                    ok = key.SetValue(wxEmptyString, filetype);
+                    key.SetValue(wxEmptyString, filetype);
                 }
             else
                 {
-                    ok = key.QueryValue(wxEmptyString, filetype);
+                    key.QueryValue(wxEmptyString, filetype);
                 }
         }
         // now set a mimetypeif we have it, but ignore it if none
@@ -576,7 +582,7 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
                 if ( ok )
                 {
                     // and provide a back link to the extension
-                    ok = keyMIME.SetValue(_T("Extension"), extWithDot);
+                    keyMIME.SetValue(_T("Extension"), extWithDot);
                 }
             }
         }
@@ -592,8 +598,8 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
             extWithDot += ext;
 
             wxRegKey key(wxRegKey::HKCR, extWithDot);
-            if ( !key.Exists() ) ok = key.Create();
-            ok = key.SetValue(wxEmptyString, filetype);
+            if ( !key.Exists() ) key.Create();
+            key.SetValue(wxEmptyString, filetype);
 
         // now set any mimetypes we may have, but ignore it if none
         const wxString& mimetype = ftInfo.GetMimeType();
@@ -613,7 +619,7 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
         if ( ok )
         {
                     // and provide a back link to the extension
-                    ok = keyMIME.SetValue(_T("Extension"), extWithDot);
+                    keyMIME.SetValue(_T("Extension"), extWithDot);
         }
         }
     }
@@ -624,10 +630,9 @@ wxFileType *wxMimeTypesManagerImpl::Associate(const wxFileTypeInfo& ftInfo)
     // create the filetype key itself (it will be empty for now, but
     // SetCommand(), SetDefaultIcon() &c will use it later)
     wxRegKey keyFT(wxRegKey::HKCR, filetype);
-    ok = keyFT.Create();
+    keyFT.Create();
 
-    wxFileType *ft = NULL;
-    ft = CreateFileType(filetype, extWithDot);
+    wxFileType *ft = CreateFileType(filetype, extWithDot);
 
     if (ft)
     {
@@ -814,7 +819,4 @@ bool wxFileTypeImpl::RemoveDescription()
     return !rkey.Exists() || rkey.DeleteSelf();
 }
 
-#endif
-  // __WIN16__
-
 #endif // wxUSE_MIMETYPE