Added a function to return path name in unicode, contributed by m_kato@ga2.so-net.ne.jp, edited by nhotta, bug 22863, r=ftang.
git-svn-id: svn://10.0.0.236/trunk@60365 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
bcd82a3e6a
commit
d93c3cf8c0
@ -258,10 +258,9 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
if (result) {
|
||||
nsFileSpec fileSpec;
|
||||
fileWidget->GetFile(fileSpec);
|
||||
const char * pathName = fileSpec.GetNativePathCString();
|
||||
if (pathName) {
|
||||
mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName);
|
||||
}
|
||||
nsAutoString pathName;
|
||||
fileSpec.GetNativePathString(pathName);
|
||||
mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName);
|
||||
}
|
||||
NS_RELEASE(fileWidget);
|
||||
}
|
||||
|
||||
@ -258,10 +258,9 @@ nsFileControlFrame::MouseClick(nsIDOMEvent* aMouseEvent)
|
||||
if (result) {
|
||||
nsFileSpec fileSpec;
|
||||
fileWidget->GetFile(fileSpec);
|
||||
const char * pathName = fileSpec.GetNativePathCString();
|
||||
if (pathName) {
|
||||
mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName);
|
||||
}
|
||||
nsAutoString pathName;
|
||||
fileSpec.GetNativePathString(pathName);
|
||||
mTextFrame->SetProperty(mPresContext, nsHTMLAtoms::value, pathName);
|
||||
}
|
||||
NS_RELEASE(fileWidget);
|
||||
}
|
||||
|
||||
@ -31,6 +31,13 @@
|
||||
#include "plbase64.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsIPlatformCharset.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIUnicodeDecoder.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@ -795,6 +802,8 @@ nsFilePath nsFilePath::operator +(const char* inRelativeUnixPath) const
|
||||
// nsFileSpec implementation
|
||||
//========================================================================================
|
||||
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
|
||||
#ifndef XP_MAC
|
||||
//----------------------------------------------------------------------------------------
|
||||
nsFileSpec::nsFileSpec()
|
||||
@ -1102,6 +1111,91 @@ PRBool nsFileSpec::IsChildOf(nsFileSpec &possibleParent)
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsFileSpec::GetFileSystemCharset(nsString & fileSystemCharset)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// From mozilla/widget/src/windows/nsFileWidget.cpp
|
||||
|
||||
static nsAutoString aCharset;
|
||||
nsresult rv;
|
||||
|
||||
if (aCharset.Length() < 1) {
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset;
|
||||
rv = nsComponentManager::CreateInstance(NS_PLATFORMCHARSET_PROGID, nsnull,
|
||||
NS_GET_IID(nsIPlatformCharset), getter_AddRefs(platformCharset));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, aCharset);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error getting platform charset");
|
||||
if (NS_FAILED(rv))
|
||||
aCharset.SetString("ISO-8859-1");
|
||||
}
|
||||
fileSystemCharset = aCharset;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
PRUnichar * nsFileSpec::ConvertFromFileSystemCharset(const char *inString)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
// From mozilla/widget/src/windows/nsFileWidget.cpp
|
||||
|
||||
nsIUnicodeDecoder *aUnicodeDecoder = nsnull;
|
||||
PRUnichar *outString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// get file system charset and create a unicode encoder
|
||||
nsAutoString fileSystemCharset;
|
||||
GetFileSystemCharset(fileSystemCharset);
|
||||
|
||||
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ccm->GetUnicodeDecoder(&fileSystemCharset, &aUnicodeDecoder);
|
||||
}
|
||||
|
||||
// converts from the file system charset to unicode
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRInt32 inLength = nsCRT::strlen(inString);
|
||||
PRInt32 outLength;
|
||||
rv = aUnicodeDecoder->GetMaxLength(inString, inLength, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString = new PRUnichar[outLength+1];
|
||||
if (nsnull == outString) {
|
||||
return nsnull;
|
||||
}
|
||||
rv = aUnicodeDecoder->Convert(inString, &inLength, outString, &outLength);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
outString[outLength] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(aUnicodeDecoder);
|
||||
|
||||
return NS_SUCCEEDED(rv) ? outString : nsnull;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
void nsFileSpec::GetNativePathString(nsString &nativePathString)
|
||||
//----------------------------------------------------------------------------------------
|
||||
{
|
||||
const char *path = GetCString();
|
||||
if (nsnull == path) {
|
||||
nativePathString.SetString("");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
PRUnichar *converted = ConvertFromFileSystemCharset(path);
|
||||
if (nsnull != converted) {
|
||||
nativePathString.SetString(converted);
|
||||
delete [] converted;
|
||||
}
|
||||
else
|
||||
nativePathString.SetString(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#pragma mark -
|
||||
#endif
|
||||
|
||||
@ -182,6 +182,9 @@ class nsOutputConsoleStream;
|
||||
|
||||
class nsString;
|
||||
|
||||
class nsIUnicodeEncoder;
|
||||
class nsIUnicodeDecoder;
|
||||
|
||||
//========================================================================================
|
||||
// Conversion of native file errors to nsresult values. These are really only for use
|
||||
// in the file module, clients of this interface shouldn't really need them.
|
||||
@ -351,6 +354,9 @@ class NS_COM nsFileSpec
|
||||
// Do not try to free this!
|
||||
const char* GetNativePathCString() const { return GetCString(); }
|
||||
|
||||
// Returns a path in unicode
|
||||
// converted from a file system charset.
|
||||
void GetNativePathString(nsString &nativePathString);
|
||||
|
||||
PRBool IsChildOf(nsFileSpec &possibleParent);
|
||||
|
||||
@ -524,6 +530,16 @@ class NS_COM nsFileSpec
|
||||
return Execute(argsString);
|
||||
}
|
||||
|
||||
// Internal routine
|
||||
//--------------------------------------------------
|
||||
|
||||
// Convert's routine from Native charset to Unicode.
|
||||
protected:
|
||||
|
||||
// use delete [] to free the returned buffer
|
||||
PRUnichar* ConvertFromFileSystemCharset(const char *inString);
|
||||
static void GetFileSystemCharset(nsString & fileSystemCharset);
|
||||
|
||||
//--------------------------------------------------
|
||||
// Data
|
||||
//--------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user