add default value for the encoding parameter of wxMacCFStringHolder() instead of passing wxLocale::GetSystemEncoding() which doesn't work when wxUSE_INTL == 0 to it in many places (replaces 2nd part of patch 1501724)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40283 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-07-24 18:01:39 +00:00
parent b9eb3d9de6
commit a8d69700fc
4 changed files with 57 additions and 57 deletions

View File

@@ -39,19 +39,20 @@ void wxMacWakeUp() ;
class wxMacCFStringHolder class wxMacCFStringHolder
{ {
public: public:
wxMacCFStringHolder() wxMacCFStringHolder()
: m_cfs(NULL) , m_release(false) : m_cfs(NULL) , m_release(false)
{ {
} }
wxMacCFStringHolder(const wxString &str , wxFontEncoding encoding ) wxMacCFStringHolder(const wxString &str,
: m_cfs(NULL) , m_release(false) wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
: m_cfs(NULL) , m_release(false)
{ {
Assign( str , encoding ) ; Assign( str , encoding ) ;
} }
wxMacCFStringHolder(CFStringRef ref , bool release = true ) wxMacCFStringHolder(CFStringRef ref , bool release = true )
: m_cfs(ref) , m_release(release) : m_cfs(ref) , m_release(release)
{ {
} }
@@ -75,7 +76,8 @@ public:
m_cfs = NULL ; m_cfs = NULL ;
} }
void Assign( const wxString &str , wxFontEncoding encoding ) ; void Assign(const wxString &str,
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
operator CFStringRef () const { return m_cfs; } operator CFStringRef () const { return m_cfs; }
wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ; wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
@@ -84,7 +86,7 @@ private:
CFStringRef m_cfs; CFStringRef m_cfs;
bool m_release ; bool m_release ;
DECLARE_NO_COPY_CLASS( wxMacCFStringHolder ) DECLARE_NO_COPY_CLASS( wxMacCFStringHolder )
} ; } ;
@@ -94,13 +96,13 @@ class wxMacUniCharBuffer
{ {
public : public :
wxMacUniCharBuffer( const wxString &str ) ; wxMacUniCharBuffer( const wxString &str ) ;
~wxMacUniCharBuffer() ; ~wxMacUniCharBuffer() ;
UniChar* GetBuffer() ; UniChar* GetBuffer() ;
UniCharCount GetChars() ; UniCharCount GetChars() ;
private : private :
UniChar* m_ubuf ; UniChar* m_ubuf ;
UniCharCount m_chars ; UniCharCount m_chars ;

View File

@@ -883,15 +883,15 @@ wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathCompon
CFRelease( fullURLRef ) ; CFRelease( fullURLRef ) ;
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString); CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfString);
CFRelease( cfString ); CFRelease( cfString );
CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
return wxMacCFStringHolder(cfMutableString).AsString(wxLocale::GetSystemEncoding()); return wxMacCFStringHolder(cfMutableString).AsString();
} }
OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef )
{ {
OSStatus err = noErr ; OSStatus err = noErr ;
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(path ,wxLocale::GetSystemEncoding() ) ) ; CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(path));
CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kDefaultPathStyle, false); CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kDefaultPathStyle, false);
CFRelease( cfMutableString ); CFRelease( cfMutableString );
if ( NULL != url ) if ( NULL != url )
@@ -914,7 +914,7 @@ wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname )
uniname->length ); uniname->length );
CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfname); CFMutableStringRef cfMutableString = CFStringCreateMutableCopy(NULL, 0, cfname);
CFRelease( cfname ); CFRelease( cfname );
CFStringNormalize(cfMutableString,kCFStringNormalizationFormC); CFStringNormalize(cfMutableString,kCFStringNormalizationFormC);
return wxMacCFStringHolder(cfMutableString).AsString() ; return wxMacCFStringHolder(cfMutableString).AsString() ;
} }

View File

@@ -105,9 +105,10 @@ wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
#if wxUSE_GUI #if wxUSE_GUI
encoding = wxFont::GetDefaultEncoding() ; encoding = wxFont::GetDefaultEncoding() ;
#else #else
encoding = wxLocale::GetSystemEncoding() ; encoding = wxFONTENCODING_SYSTEM; // to be set below
#endif #endif
} }
if ( encoding == wxFONTENCODING_SYSTEM ) if ( encoding == wxFONTENCODING_SYSTEM )
{ {
enc = CFStringGetSystemEncoding(); enc = CFStringGetSystemEncoding();

View File

@@ -51,10 +51,10 @@
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// //
// wxMacExecute // wxMacExecute
// //
// argv is the command line split up, with the application path first // argv is the command line split up, with the application path first
// flags are the flags from wxExecute // flags are the flags from wxExecute
// process is the process passed from wxExecute for pipe streams etc. // process is the process passed from wxExecute for pipe streams etc.
// returns -1 on error for wxEXEC_SYNC and 0 on error for wxEXEC_ASYNC // returns -1 on error for wxEXEC_SYNC and 0 on error for wxEXEC_ASYNC
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -63,8 +63,8 @@ long wxMacExecute(wxChar **argv,
wxProcess *process) wxProcess *process)
{ {
// Semi-macros used for return value of wxMacExecute // Semi-macros used for return value of wxMacExecute
const long errorCode = ((flags & wxEXEC_SYNC) ? -1 : 0); const long errorCode = ((flags & wxEXEC_SYNC) ? -1 : 0);
const long successCode = ((flags & wxEXEC_SYNC) ? 0 : -1); // fake PID const long successCode = ((flags & wxEXEC_SYNC) ? 0 : -1); // fake PID
// Obtains the number of arguments for determining the size of // Obtains the number of arguments for determining the size of
// the CFArray used to hold them // the CFArray used to hold them
@@ -81,18 +81,17 @@ long wxMacExecute(wxChar **argv,
wxLogDebug(wxT("wxMacExecute No file to launch!")); wxLogDebug(wxT("wxMacExecute No file to launch!"));
return errorCode ; return errorCode ;
} }
// Path to bundle // Path to bundle
wxString path = *argv++; wxString path = *argv++;
// Create a CFURL for the application path // Create a CFURL for the application path
// Created this way because we are opening a bundle which is a directory // Created this way because we are opening a bundle which is a directory
CFURLRef cfurlApp = CFURLRef cfurlApp =
CFURLCreateWithFileSystemPath( CFURLCreateWithFileSystemPath(
kCFAllocatorDefault, kCFAllocatorDefault,
wxMacCFStringHolder(path, wxMacCFStringHolder(path),
wxLocale::GetSystemEncoding()), kDefaultPathStyle,
kDefaultPathStyle,
true); //false == not a directory true); //false == not a directory
// Check for error from the CFURL // Check for error from the CFURL
@@ -114,7 +113,7 @@ long wxMacExecute(wxChar **argv,
CFRelease(cfurlApp); CFRelease(cfurlApp);
return errorCode ; return errorCode ;
} }
// Get the bundle type and make sure its an 'APPL' bundle // Get the bundle type and make sure its an 'APPL' bundle
// Otherwise we're dealing with something else here... // Otherwise we're dealing with something else here...
UInt32 dwBundleType, dwBundleCreator; UInt32 dwBundleType, dwBundleCreator;
@@ -126,42 +125,41 @@ long wxMacExecute(wxChar **argv,
CFRelease(cfurlApp); CFRelease(cfurlApp);
return errorCode ; return errorCode ;
} }
// Create a CFArray for dealing with the command line // Create a CFArray for dealing with the command line
// arguments to the bundle // arguments to the bundle
CFMutableArrayRef cfaFiles = CFArrayCreateMutable(kCFAllocatorDefault, CFMutableArrayRef cfaFiles = CFArrayCreateMutable(kCFAllocatorDefault,
cfiCount-1, &kCFTypeArrayCallBacks); cfiCount-1, &kCFTypeArrayCallBacks);
if(!cfaFiles) //This should never happen if(!cfaFiles) //This should never happen
{ {
wxLogDebug(wxT("wxMacExecute Could not create CFMutableArray")); wxLogDebug(wxT("wxMacExecute Could not create CFMutableArray"));
CFRelease(cfbApp); CFRelease(cfbApp);
CFRelease(cfurlApp); CFRelease(cfurlApp);
return errorCode ; return errorCode ;
} }
// Loop through command line arguments to the bundle, // Loop through command line arguments to the bundle,
// turn them into CFURLs and then put them in cfaFiles // turn them into CFURLs and then put them in cfaFiles
// For use to launch services call // For use to launch services call
for( ; *argv != NULL ; ++argv) for( ; *argv != NULL ; ++argv)
{ {
// Check for '<' as this will ring true for // Check for '<' as this will ring true for
// CFURLCreateWithString but is generally not considered // CFURLCreateWithString but is generally not considered
// typical on mac but is usually passed here from wxExecute // typical on mac but is usually passed here from wxExecute
if (wxStrcmp(*argv, wxT("<")) == 0) if (wxStrcmp(*argv, wxT("<")) == 0)
continue; continue;
CFURLRef cfurlCurrentFile; // CFURL to hold file path CFURLRef cfurlCurrentFile; // CFURL to hold file path
wxFileName argfn(*argv); // Filename for path wxFileName argfn(*argv); // Filename for path
if(argfn.DirExists()) if(argfn.DirExists())
{ {
// First, try creating as a directory // First, try creating as a directory
cfurlCurrentFile = CFURLCreateWithFileSystemPath( cfurlCurrentFile = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault, kCFAllocatorDefault,
wxMacCFStringHolder(*argv, wxMacCFStringHolder(*argv),
wxLocale::GetSystemEncoding()), kDefaultPathStyle,
kDefaultPathStyle,
true); //true == directory true); //true == directory
} }
else if(argfn.FileExists()) else if(argfn.FileExists())
@@ -170,27 +168,26 @@ long wxMacExecute(wxChar **argv,
// as a regular file // as a regular file
cfurlCurrentFile = CFURLCreateWithFileSystemPath( cfurlCurrentFile = CFURLCreateWithFileSystemPath(
kCFAllocatorDefault, kCFAllocatorDefault,
wxMacCFStringHolder(*argv, wxMacCFStringHolder(*argv),
wxLocale::GetSystemEncoding()), kDefaultPathStyle,
kDefaultPathStyle,
false); //false == regular file false); //false == regular file
} }
else else
{ {
// Argument did not refer to // Argument did not refer to
// an entry in the local filesystem, // an entry in the local filesystem,
// so try creating it through CFURLCreateWithString // so try creating it through CFURLCreateWithString
cfurlCurrentFile = CFURLCreateWithString( cfurlCurrentFile = CFURLCreateWithString(
kCFAllocatorDefault, kCFAllocatorDefault,
wxMacCFStringHolder(*argv, wxLocale::GetSystemEncoding()), wxMacCFStringHolder(*argv),
NULL); NULL);
} }
// Continue in the loop if the CFURL could not be created // Continue in the loop if the CFURL could not be created
if(!cfurlCurrentFile) if(!cfurlCurrentFile)
{ {
wxLogDebug( wxLogDebug(
wxT("wxMacExecute Could not create CFURL for argument:%s"), wxT("wxMacExecute Could not create CFURL for argument:%s"),
*argv); *argv);
continue; continue;
} }
@@ -203,7 +200,7 @@ long wxMacExecute(wxChar **argv,
); );
CFRelease(cfurlCurrentFile); // array has retained it CFRelease(cfurlCurrentFile); // array has retained it
} }
// Create a LSLaunchURLSpec for use with LSOpenFromURLSpec // Create a LSLaunchURLSpec for use with LSOpenFromURLSpec
// Note that there are several flag options (launchFlags) such // Note that there are several flag options (launchFlags) such
// as kLSLaunchDontSwitch etc. and maybe we could be more // as kLSLaunchDontSwitch etc. and maybe we could be more
@@ -211,10 +208,10 @@ long wxMacExecute(wxChar **argv,
LSLaunchURLSpec launchspec; LSLaunchURLSpec launchspec;
launchspec.appURL = cfurlApp; launchspec.appURL = cfurlApp;
launchspec.itemURLs = cfaFiles; launchspec.itemURLs = cfaFiles;
launchspec.passThruParams = NULL; //AEDesc* launchspec.passThruParams = NULL; //AEDesc*
launchspec.launchFlags = kLSLaunchDefaults; launchspec.launchFlags = kLSLaunchDefaults;
launchspec.asyncRefCon = NULL; launchspec.asyncRefCon = NULL;
// Finally, call LSOpenFromURL spec with our arguments // Finally, call LSOpenFromURL spec with our arguments
// 2nd parameter is a pointer to a CFURL that gets // 2nd parameter is a pointer to a CFURL that gets
// the actual path launched by the function // the actual path launched by the function
@@ -224,16 +221,16 @@ long wxMacExecute(wxChar **argv,
CFRelease(cfbApp); CFRelease(cfbApp);
CFRelease(cfurlApp); CFRelease(cfurlApp);
CFRelease(cfaFiles); CFRelease(cfaFiles);
// Check for error from LSOpenFromURLSpec // Check for error from LSOpenFromURLSpec
if(status != noErr) if(status != noErr)
{ {
wxLogDebug(wxT("wxMacExecute LSOpenFromURLSpec Error: %d"), wxLogDebug(wxT("wxMacExecute LSOpenFromURLSpec Error: %d"),
(int)status); (int)status);
return errorCode ; return errorCode ;
} }
// No error from LSOpenFromURLSpec, so app was launched // No error from LSOpenFromURLSpec, so app was launched
return successCode; return successCode;
} }