removal of pc-mac charset conversion for wxMac

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23579 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2003-09-14 18:40:43 +00:00
parent a2b436fb40
commit 939fba6c17
26 changed files with 131 additions and 572 deletions

View File

@ -291,12 +291,6 @@ public:
int argc;
wxChar **argv;
#ifdef __WXMAC__
// This is needed in the wxAppConsole class because it is refereced from
// the wxBase library
static bool s_macDefaultEncodingIsPC ;
#endif
protected:
// the function which creates the traits object when GetTraits() needs it
// for the first time

View File

@ -157,18 +157,11 @@ enum wxSeekMode
WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
#else
#if defined(__WXMAC__) && !defined(__DARWIN__) && !wxUSE_UNICODE
#include <sys/stat.h>
WXDLLIMPEXP_BASE int wxStat( const wxChar *file_name, wxStructStat *buf );
WXDLLIMPEXP_BASE int wxAccess( const wxChar *pathname, int mode );
WXDLLIMPEXP_BASE int wxOpen( const wxChar *pathname, int flags, mode_t mode );
#else
#define wxOpen open
#define wxStat stat
#define wxAccess access
#endif
#endif
#endif // VC++

View File

@ -161,11 +161,6 @@ void wxMacCleanupConverters() ;
void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
wxCharBuffer wxMacStringToCString( const wxString &from ) ;
wxWCharBuffer wxMacStringToWString( const wxString &from ) ;
wxString wxMacMakeStringFromCString( const char * from , int len ) ;
wxString wxMacMakeStringFromCString( const char * from ) ;
#if TARGET_CARBON
class wxMacCFStringHolder
@ -227,81 +222,7 @@ private:
bool m_release ;
} ;
// CFStringRef wxMacStringToCFString( const wxString &str ) ;
// wxString wxMacMakeStringFromCFString( CFStringRef cf ) ;
#endif
#if 0
void wxMacConvertToPC( const char *from , char *to , int len ) ;
void wxMacConvertFromPC( const char *from , char *to , int len ) ;
void wxMacConvertToPC( const char *from , char *to , int len ) ;
wxString wxMacMakeMacStringFromPC( const wxChar * p ) ;
wxString wxMacMakePCStringFromMac( const wxChar * p ) ;
// converts this c string into a wxString with optional mac 2 pc encoding
wxString wxMacMakeStringFromMacString( const wxChar* from , bool mac2pcEncoding ) ;
// converts this c string into a wxString with pc 2 mac encoding if s_macDefaultEncodingIsPC
inline wxString wxMacMakeStringFromMacString( const wxChar* from )
{ return wxMacMakeStringFromMacString( from , wxApp::s_macDefaultEncodingIsPC ) ; }
#if wxUSE_UNICODE
wxString wxMacMakeMacStringFromPC( const char * p ) ;
wxString wxMacMakePCStringFromMac( const char * p ) ;
// converts this c string into a wxString with optional mac 2 pc encoding
wxString wxMacMakeStringFromMacString( const char* from , bool mac2pcEncoding ) ;
// converts this c string into a wxString with pc 2 mac encoding if s_macDefaultEncodingIsPC
inline wxString wxMacMakeStringFromMacString( const char* from )
{ return wxMacMakeStringFromMacString( from , wxApp::s_macDefaultEncodingIsPC ) ; }
#endif
// converts this c string into a wxString with pc 2 mac encoding if s_macDefaultEncodingIsPC
inline wxString wxMacMakeStringFromMacString( const wxString& from )
{ return wxApp::s_macDefaultEncodingIsPC ?
wxMacMakeStringFromMacString( from.c_str() , true ) : from ; }
//
// Pascal Strings
//
// converts this string into a pascal with optional pc 2 mac encoding
void wxMacStringToPascal( const wxChar * from , StringPtr to , bool pc2macEncoding ) ;
// converts this string into a pascal with pc 2 mac encoding if s_macDefaultEncodingIsPC
inline void wxMacStringToPascal( const wxChar * from , StringPtr to )
{ wxMacStringToPascal( from , to , wxApp::s_macDefaultEncodingIsPC ) ; }
// converts this string into a pascal with optional mac 2 pc encoding
wxString wxMacMakeStringFromPascal( ConstStringPtr from , bool mac2pcEncoding ) ;
// converts this pascal string into a wxString with pc 2 mac encoding if s_macDefaultEncodingIsPC
inline wxString wxMacMakeStringFromPascal( ConstStringPtr from )
{ return wxMacMakeStringFromPascal( from , wxApp::s_macDefaultEncodingIsPC ) ; }
//
// CFStringRefs (Carbon only)
//
#if TARGET_CARBON
// converts this string into a carbon foundation string with optional pc 2 mac encoding
CFStringRef wxMacStringToCFString( const wxString &str , bool pc2macEncoding ) ;
// converts this string into a carbon foundation string with optional pc 2 mac encoding
inline CFStringRef wxMacStringToCFString( const wxString &str )
{ return wxMacStringToCFString( str , wxApp::s_macDefaultEncodingIsPC ) ; }
#endif //TARGET_CARBON
#endif // 0
#endif
// _WX_PRIVATE_H_

View File

@ -580,18 +580,11 @@
#define wxStrxfrm strxfrm
// stdio.h functions
#if defined(__WXMAC__) && !defined(__DARWIN__) && !wxUSE_UNICODE
#include <stdio.h>
WXDLLIMPEXP_BASE FILE * wxFopen(const wxChar *path, const wxChar *mode);
WXDLLIMPEXP_BASE FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream);
WXDLLIMPEXP_BASE int wxRemove(const wxChar *path);
WXDLLIMPEXP_BASE int wxRename(const wxChar *oldpath, const wxChar *newpath);
#else
#define wxFopen fopen
#define wxFreopen freopen
#define wxRemove remove
#define wxRename rename
#endif
#define wxPerror perror
#define wxTmpnam tmpnam

View File

@ -93,10 +93,6 @@ wxAppConsole *wxAppConsole::ms_appInstance = NULL;
wxAppInitializerFunction wxAppConsole::ms_appInitFn = NULL;
#ifdef __WXMAC__
bool wxAppConsole::s_macDefaultEncodingIsPC = true ;
#endif
// ============================================================================
// wxAppConsole implementation
// ============================================================================

View File

@ -196,25 +196,6 @@ const off_t wxInvalidOffset = (off_t)-1;
// implementation
// ============================================================================
#if defined(__WXMAC__) && !defined(__DARWIN__) && !wxUSE_UNICODE
WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf )
{
return stat( wxMacStringToCString( file_name ), buf );
}
WXDLLEXPORT int wxAccess( const wxChar *pathname, int mode )
{
return access( wxMacStringToCString( pathname ), mode );
}
WXDLLEXPORT int wxOpen( const wxChar *pathname, int flags, mode_t mode )
{
return open( wxMacStringToCString( pathname ), flags, mode );
}
#endif
#ifdef wxNEED_WX_UNISTD_H
WXDLLEXPORT int wxStat( const wxChar *file_name, wxStructStat *buf )
@ -991,7 +972,7 @@ wxString wxMacFSSpec2MacFilename( const FSSpec *spec )
(*myPath)[length-1] = 0 ;
// create path string for return value
wxString result = wxMacMakeStringFromCString( *myPath ) ;
wxString result( *myPath , wxConvLocal) ;
// free allocated handle
::HUnlock( myPath ) ;
@ -1037,7 +1018,7 @@ void wxMacFilename2FSSpec( const char *path , FSSpec *spec )
#if wxUSE_UNICODE
WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec )
{
return wxMacFilename2FSSpec( wxMacStringToCString( wxString( path ) ) , spec ) ;
return wxMacFilename2FSSpec( wxConvFile.cWC2MB(path) , spec ) ;
}
#endif

View File

@ -1205,28 +1205,6 @@ WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base)
}
#endif // wxNEED_WX_STRING_H
#if defined(__WXMAC__) && !defined(__DARWIN__) && !wxUSE_UNICODE
WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode)
{
return fopen( wxMacStringToCString(path), mode );
}
WXDLLEXPORT FILE * wxFreopen(const wxChar *path, const wxChar *mode, FILE *stream)
{
return freopen( wxMacStringToCString(path), mode, stream );
}
WXDLLEXPORT int wxRemove(const wxChar *path)
{
return remove( wxMacStringToCString(path) );
}
WXDLLEXPORT int wxRename(const wxChar *oldpath, const wxChar *newpath)
{
return rename( wxMacStringToCString(oldpath), wxMacStringToCString(newpath) );
}
#endif
#ifdef wxNEED_WX_STDIO_H
WXDLLEXPORT FILE * wxFopen(const wxChar *path, const wxChar *mode)
{

View File

@ -1171,14 +1171,7 @@ void wxLogTextCtrl::DoLogString(const wxChar *szString, time_t WXUNUSED(t))
wxString msg;
TimeStamp(&msg);
#if defined(__WXMAC__)
// VZ: this is a bug in wxMac, it *must* accept '\n' as new line, the
// translation must be done in wxTextCtrl, not here! (FIXME)
msg << szString << wxT('\r');
#else
msg << szString << wxT('\n');
#endif
m_pTextCtrl->AppendText(msg);
}

View File

@ -600,7 +600,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
#endif
#endif
wxMacSetupConverters() ;
s_macCursorRgn = ::NewRgn() ;
@ -702,7 +701,6 @@ void wxApp::CleanUp()
// __wxterminate in Mach-O shared libraries
wxStAppResource::CloseSharedLibraryResource();
#endif
wxMacCleanupConverters() ;
UMACleanupToolbox() ;
if (s_macCursorRgn) {

View File

@ -600,7 +600,6 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
#endif
#endif
wxMacSetupConverters() ;
s_macCursorRgn = ::NewRgn() ;
@ -702,7 +701,6 @@ void wxApp::CleanUp()
// __wxterminate in Mach-O shared libraries
wxStAppResource::CloseSharedLibraryResource();
#endif
wxMacCleanupConverters() ;
UMACleanupToolbox() ;
if (s_macCursorRgn) {

View File

@ -272,8 +272,7 @@ wxSize wxChoice::DoGetBestSize() const
&baseline );
wLine = bounds.h ;
#else
wxCharBuffer text = wxMacStringToCString( str ) ;
wLine = ::TextWidth( text , 0 , strlen(text) ) ;
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
#endif
lbWidth = wxMax(lbWidth, wLine);
}

View File

@ -136,18 +136,14 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
return NULL ;
}
if ( dataFormat.GetType() == wxDF_TEXT && wxApp::s_macDefaultEncodingIsPC )
if ( dataFormat.GetType() == wxDF_TEXT )
{
wxString st = wxMacMakeStringFromCString( (char*) data ) ;
#if wxUSE_UNICODE
wxCharBuffer buf = st.ToAscii() ;
#else
const char* buf = st ;
#endif
char* newdata = new char[strlen(buf)+1] ;
memcpy( newdata , buf , strlen(buf)+1 ) ;
delete[] ((char*) data ) ;
data = newdata ;
char * buf = (char*) data ;
while( (buf=strchr(buf,0x0a)) != NULL )
{
*buf = 13 ;
buf++ ;
}
}
return data;
@ -252,8 +248,7 @@ bool wxClipboard::AddData( wxDataObject *data )
case wxDF_OEMTEXT:
{
wxTextDataObject* textDataObject = (wxTextDataObject*) data;
wxString str(textDataObject->GetText());
wxCharBuffer buf = wxMacStringToCString( str ) ;
wxCharBuffer buf = textDataObject->GetText().mb_str() ;
err = UMAPutScrap( strlen(buf) , kScrapFlavorTypeText , (void*) buf.data() ) ;
}
break ;

View File

@ -55,6 +55,8 @@ const double RAD2DEG = 180.0 / M_PI;
const short kEmulatedMode = -1 ;
const short kUnsupportedMode = -2 ;
extern TECObjectRef s_TECNativeCToUnicode ;
// set to 0 if problems arise
#define wxMAC_EXPERIMENTAL_DC 1
@ -1353,24 +1355,9 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 ,
&chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
#else
TECObjectRef ec;
status = TECCreateConverter(&ec,
wxApp::s_macDefaultEncodingIsPC
? (int)kTextEncodingWindowsLatin1
: (int)kTextEncodingMacRoman,
kTextEncodingUnicodeDefault);
wxASSERT_MSG( status == noErr , wxT("couldn't start converter") ) ;
ByteCount byteOutLen ;
ByteCount byteInLen = str.Length() ;
ByteCount byteBufferLen = byteInLen *2 ;
char* buf = new char[byteBufferLen] ;
status = TECConvertText(ec, (ConstTextPtr)str.c_str() , byteInLen, &byteInLen,
(TextPtr)buf, byteBufferLen, &byteOutLen);
wxASSERT_MSG( status == noErr , wxT("couldn't convert text") ) ;
status = TECDisposeConverter(ec);
wxASSERT_MSG( status == noErr , wxT("couldn't dispose converter") ) ;
status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 ,
wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
int wlen = wxWcslen( wchar.data() ) ;
status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) wchar.data() , 0 , wlen , wlen , 1 ,
&chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
#endif
wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
@ -1418,10 +1405,6 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
::ATSUDisposeTextLayout(atsuLayout);
#if wxUSE_UNICODE
#else
delete[] buf ;
#endif
}
void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
@ -1501,7 +1484,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
::DrawText( text , 0 , strlen(text) ) ;
line++ ;
::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
@ -1543,7 +1526,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
::DrawText( text , 0 , strlen(text) ) ;
}
}
@ -1583,21 +1566,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h
if ( externalLeading )
*externalLeading = YDEV2LOGREL( fi.leading ) ;
int length = strtext.Length() ;
/*
const char *text = NULL ;
wxString macText ;
if ( wxApp::s_macDefaultEncodingIsPC )
{
macText = wxMacMakeMacStringFromPC( string ) ;
text = macText ;
length = macText.Length() ;
}
else
{
text = string ;
length = string.Length() ;
}
*/
int laststop = 0 ;
int i = 0 ;
int curwidth = 0 ;
@ -1628,7 +1597,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )
@ -1656,7 +1625,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )

View File

@ -206,7 +206,7 @@ bool wxDropTarget::GetData()
if( theType == 'TEXT' )
{
theData[dataSize]=0 ;
wxString convert = wxMacMakeStringFromCString( theData ) ;
wxString convert( theData , wxConvLocal ) ;
m_dataObject->SetData( format, convert.Length() * sizeof(wxChar), (const wxChar*) convert );
}
else if ( theType == kDragFlavorTypeHFS )
@ -302,7 +302,7 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
dataSize-- ;
dataPtr[ dataSize ] = 0 ;
wxString st( (wxChar*) dataPtr ) ;
wxCharBuffer buf = wxMacStringToCString( st ) ;
wxCharBuffer buf = st.mb_str( wxConvLocal) ;
AddDragItemFlavor(theDrag, theItem, type , buf.data(), strlen(buf), 0);
}
else if (type == kDragFlavorTypeHFS )

View File

@ -137,7 +137,7 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
}
#else
{
wxCharBuffer text = wxMacStringToCString( linetext ) ;
wxCharBuffer text = linetext.mb_str( wxConvLocal) ;
MoveTo(drawRect->left + 4 , drawRect->top + 10 );
DrawText(text, 0 , strlen(text) );
}
@ -633,8 +633,7 @@ wxSize wxListBox::DoGetBestSize() const
&baseline );
wLine = bounds.h ;
#else
wxCharBuffer text = wxMacStringToCString( str ) ;
wLine = ::TextWidth( text , 0 , strlen(text) ) ;
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
#endif
lbWidth = wxMax(lbWidth, wLine);
}

View File

@ -687,7 +687,7 @@ const short kVerticalMargin = 2 ;
const short kHorizontalMargin = 2 ;
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
const wxString& st,
const wxString& str,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
@ -747,6 +747,8 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
m_editable = FALSE ;
}
wxString st = str ;
st.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
@ -771,7 +773,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
if ( !m_macUsesTXN )
{
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ;
}
else
@ -785,7 +787,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
TXNSetData( ((TXNObject) m_macTXN) , kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2,
kTXNStartOffset, kTXNEndOffset);
#else
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TXNSetData( ((TXNObject) m_macTXN) , kTXNTextData, (void*)text.data(), strlen( text ) ,
kTXNStartOffset, kTXNEndOffset);
#endif
@ -817,7 +819,7 @@ wxString wxTextCtrl::GetValue() const
::GetControlData( (ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag,
actualSize , buf.data() , &actualSize ) ;
result = wxMacMakeStringFromCString( buf ) ;
result = wxString( buf , wxConvLocal) ;
}
}
else
@ -856,14 +858,14 @@ wxString wxTextCtrl::GetValue() const
if ( actualSize > 0 )
{
HLock( theText ) ;
result = wxMacMakeStringFromCString( *theText , actualSize ) ;
result = wxString( *theText , wxConvLocal , actualSize ) ;
HUnlock( theText ) ;
}
DisposeHandle( theText ) ;
}
#endif
}
result.Replace(wxT("\r"),wxT("\n")) ;
return result ;
}
@ -880,11 +882,13 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
}
}
void wxTextCtrl::SetValue(const wxString& st)
void wxTextCtrl::SetValue(const wxString& str)
{
wxString st = str ;
st.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ;
}
else
@ -896,7 +900,7 @@ void wxTextCtrl::SetValue(const wxString& st)
TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 ,
kTXNStartOffset, kTXNEndOffset);
#else
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) ,
kTXNStartOffset, kTXNEndOffset);
#endif
@ -1167,8 +1171,10 @@ long wxTextCtrl::GetLastPosition() const
}
}
void wxTextCtrl::Replace(long from, long to, const wxString& value)
void wxTextCtrl::Replace(long from, long to, const wxString& str)
{
wxString value = str ;
value.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
ControlEditTextSelectionRec selection ;
@ -1270,11 +1276,13 @@ bool wxTextCtrl::LoadFile(const wxString& file)
return FALSE;
}
void wxTextCtrl::WriteText(const wxString& st)
void wxTextCtrl::WriteText(const wxString& str)
{
wxString st = str ;
st.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TEInsert( text , strlen(text) , ((TEHandle) m_macTE) ) ;
}
else
@ -1288,7 +1296,7 @@ void wxTextCtrl::WriteText(const wxString& st)
TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 ,
kTXNUseCurrentSelection, kTXNUseCurrentSelection);
#else
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) ,
kTXNUseCurrentSelection, kTXNUseCurrentSelection);
#endif
@ -1477,12 +1485,12 @@ int wxTextCtrl::GetLineLength(long lineNo) const
for (size_t j = i; j < content.Length(); j++)
{
count++;
if (content[j] == '\r') return count;
if (content[j] == '\n') return count;
}
return count;
}
if (content[i] == '\r') count++;
if (content[i] == '\n') count++;
}
return 0;
}
@ -1503,7 +1511,7 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
for (size_t j = i; j < content.Length(); j++)
{
if (content[j] == '\r')
if (content[j] == '\n')
return tmp;
tmp += content[j];
@ -1511,7 +1519,7 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
return tmp;
}
if (content[i] == '\r') count++;
if (content[i] == '\n') count++;
}
return wxEmptyString ;
}

View File

@ -262,7 +262,7 @@ void wxMacToolTip::Draw()
int width = 0 ;
int thiswidth = 0 ;
int laststop = 0 ;
wxCharBuffer text = wxMacStringToCString( m_label ) ;
wxCharBuffer text = m_label.mb_str( wxConvLocal) ;
while( i < length )
{

View File

@ -546,6 +546,8 @@ bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
// wxMac Specific utility functions
//---------------------------------------------------------------------------
#if 0
char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
@ -632,17 +634,17 @@ void wxMacConvertToPC( const char *from , char *to , int len )
TECObjectRef s_TECNativeCToUnicode = NULL ;
TECObjectRef s_TECUnicodeToNativeC = NULL ;
TECObjectRef s_TECPlatformToNativeC = NULL ;
TECObjectRef s_TECNativeCToPlatform = NULL ;
void wxMacSetupConverters()
{
// if we assume errors are happening here we need low level debugging
// since the high level assert will use the encoders that are not yet
// setup...
const int kEncoding = wxApp::s_macDefaultEncodingIsPC
? (int)kTextEncodingWindowsLatin1
: (int)kTextEncodingMacRoman;
#if TARGET_CARBON
const TextEncodingBase kEncoding = CFStringGetSystemEncoding();
#else
const TextEncodingBase kEncoding = kTextEncodingMacRoman;
#endif
OSStatus status = noErr ;
status = TECCreateConverter(&s_TECNativeCToUnicode,
kEncoding,
@ -652,18 +654,6 @@ void wxMacSetupConverters()
status = TECCreateConverter(&s_TECUnicodeToNativeC,
kTextEncodingUnicodeDefault,
kEncoding);
if ( wxApp::s_macDefaultEncodingIsPC )
{
status = TECCreateConverter(&s_TECPlatformToNativeC,
kTextEncodingMacRoman,
kTextEncodingWindowsLatin1);
status = TECCreateConverter(&s_TECNativeCToPlatform,
kTextEncodingWindowsLatin1,
kTextEncodingMacRoman);
}
}
void wxMacCleanupConverters()
@ -672,10 +662,6 @@ void wxMacCleanupConverters()
status = TECDisposeConverter(s_TECNativeCToUnicode);
status = TECDisposeConverter(s_TECUnicodeToNativeC);
status = TECDisposeConverter(s_TECPlatformToNativeC);
status = TECDisposeConverter(s_TECNativeCToPlatform);
}
wxWCharBuffer wxMacStringToWString( const wxString &from )
@ -709,17 +695,7 @@ wxString wxMacMakeStringFromCString( const char * from , int len )
status = TECConvertText(s_TECNativeCToUnicode, (ConstTextPtr)from , byteInLen, &byteInLen,
(TextPtr)buf, byteBufferLen, &byteOutLen);
#else
if ( !wxApp::s_macDefaultEncodingIsPC )
memcpy( buf , from , len ) ;
else
{
ByteCount byteOutLen ;
ByteCount byteInLen = len ;
ByteCount byteBufferLen = byteInLen ;
status = TECConvertText(s_TECPlatformToNativeC, (ConstTextPtr)from , byteInLen, &byteInLen,
(TextPtr)buf, byteBufferLen, &byteOutLen);
}
memcpy( buf , from , len ) ;
#endif
buf[len] = 0 ;
result.UngetWriteBuf() ;
@ -743,26 +719,14 @@ wxCharBuffer wxMacStringToCString( const wxString &from )
(TextPtr)result.data(), byteBufferLen, &byteOutLen);
return result ;
#else
if ( !wxApp::s_macDefaultEncodingIsPC )
return wxCharBuffer( from.c_str() ) ;
else
{
wxCharBuffer result( from.Length() ) ;
OSStatus status = noErr ;
ByteCount byteOutLen ;
ByteCount byteInLen = from.Length() ;
ByteCount byteBufferLen = byteInLen ;
status = TECConvertText(s_TECNativeCToPlatform, (ConstTextPtr)from.c_str() , byteInLen, &byteInLen,
(TextPtr)result.data(), byteBufferLen, &byteOutLen);
return result ;
}
return wxCharBuffer( from.c_str() ) ;
#endif
}
#endif
void wxMacStringToPascal( const wxString&from , StringPtr to )
{
wxCharBuffer buf = wxMacStringToCString( from ) ;
wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
int len = strlen(buf) ;
if ( len > 255 )
@ -773,7 +737,7 @@ void wxMacStringToPascal( const wxString&from , StringPtr to )
wxString wxMacMakeStringFromPascal( ConstStringPtr from )
{
return wxMacMakeStringFromCString( (char*) &from[1] , from[0] ) ;
return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
}
#endif // wxUSE_BASE
@ -794,8 +758,7 @@ void wxMacCFStringHolder::Assign( const wxString &str )
(const unsigned short*)str.wc_str(), str.Len() );
#else
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
wxApp::s_macDefaultEncodingIsPC ?
kCFStringEncodingWindowsLatin1 : CFStringGetSystemEncoding() ) ;
CFStringGetSystemEncoding() ) ;
#endif
m_release = true ;
}
@ -808,89 +771,13 @@ wxString wxMacCFStringHolder::AsString()
#if wxUSE_UNICODE
CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) buf ) ;
#else
CFStringGetCString( m_cfs , buf , len+1 , wxApp::s_macDefaultEncodingIsPC ?
kCFStringEncodingWindowsLatin1 : CFStringGetSystemEncoding() ) ;
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
#endif
buf[len] = 0 ;
result.UngetWriteBuf() ;
return result ;
}
#if 0
wxString wxMacMakeMacStringFromPC( const wxChar * p )
{
wxString result ;
int len = wxStrlen ( p ) ;
if ( len > 0 )
{
wxChar* ptr = result.GetWriteBuf(len) ;
wxMacConvertFromPC( p , ptr , len ) ;
ptr[len] = 0 ;
result.UngetWriteBuf( len ) ;
}
return result ;
}
wxString wxMacMakePCStringFromMac( const wxChar * p )
{
wxString result ;
int len = wxStrlen ( p ) ;
if ( len > 0 )
{
wxChar* ptr = result.GetWriteBuf(len) ;
wxMacConvertToPC( p , ptr , len ) ;
ptr[len] = 0 ;
result.UngetWriteBuf( len ) ;
}
return result ;
}
wxString wxMacMakeStringFromMacString( const wxChar* from , bool mac2pcEncoding )
{
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( from ) ;
}
else
{
return wxString( from ) ;
}
}
//
// Pascal Strings
//
wxString wxMacMakeStringFromPascal( ConstStringPtr from , bool mac2pcEncoding )
{
// this is safe since a pascal string can never be larger than 256 bytes
char s[256] ;
CopyPascalStringToC( from , s ) ;
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( s ) ;
}
else
{
return wxString( s ) ;
}
}
void wxMacStringToPascal( const wxChar * from , StringPtr to , bool pc2macEncoding )
{
if (pc2macEncoding)
{
CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ;
}
else
{
CopyCStringToPascal( from , to ) ;
}
}
#endif
#endif //TARGET_CARBON
// ----------------------------------------------------------------------------

View File

@ -272,8 +272,7 @@ wxSize wxChoice::DoGetBestSize() const
&baseline );
wLine = bounds.h ;
#else
wxCharBuffer text = wxMacStringToCString( str ) ;
wLine = ::TextWidth( text , 0 , strlen(text) ) ;
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
#endif
lbWidth = wxMax(lbWidth, wLine);
}

View File

@ -136,18 +136,14 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
return NULL ;
}
if ( dataFormat.GetType() == wxDF_TEXT && wxApp::s_macDefaultEncodingIsPC )
if ( dataFormat.GetType() == wxDF_TEXT )
{
wxString st = wxMacMakeStringFromCString( (char*) data ) ;
#if wxUSE_UNICODE
wxCharBuffer buf = st.ToAscii() ;
#else
const char* buf = st ;
#endif
char* newdata = new char[strlen(buf)+1] ;
memcpy( newdata , buf , strlen(buf)+1 ) ;
delete[] ((char*) data ) ;
data = newdata ;
char * buf = (char*) data ;
while( (buf=strchr(buf,0x0a)) != NULL )
{
*buf = 13 ;
buf++ ;
}
}
return data;
@ -252,8 +248,7 @@ bool wxClipboard::AddData( wxDataObject *data )
case wxDF_OEMTEXT:
{
wxTextDataObject* textDataObject = (wxTextDataObject*) data;
wxString str(textDataObject->GetText());
wxCharBuffer buf = wxMacStringToCString( str ) ;
wxCharBuffer buf = textDataObject->GetText().mb_str() ;
err = UMAPutScrap( strlen(buf) , kScrapFlavorTypeText , (void*) buf.data() ) ;
}
break ;

View File

@ -55,6 +55,8 @@ const double RAD2DEG = 180.0 / M_PI;
const short kEmulatedMode = -1 ;
const short kUnsupportedMode = -2 ;
extern TECObjectRef s_TECNativeCToUnicode ;
// set to 0 if problems arise
#define wxMAC_EXPERIMENTAL_DC 1
@ -1353,24 +1355,9 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) (const wxChar*) str , 0 , str.Length() , str.Length() , 1 ,
&chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
#else
TECObjectRef ec;
status = TECCreateConverter(&ec,
wxApp::s_macDefaultEncodingIsPC
? (int)kTextEncodingWindowsLatin1
: (int)kTextEncodingMacRoman,
kTextEncodingUnicodeDefault);
wxASSERT_MSG( status == noErr , wxT("couldn't start converter") ) ;
ByteCount byteOutLen ;
ByteCount byteInLen = str.Length() ;
ByteCount byteBufferLen = byteInLen *2 ;
char* buf = new char[byteBufferLen] ;
status = TECConvertText(ec, (ConstTextPtr)str.c_str() , byteInLen, &byteInLen,
(TextPtr)buf, byteBufferLen, &byteOutLen);
wxASSERT_MSG( status == noErr , wxT("couldn't convert text") ) ;
status = TECDisposeConverter(ec);
wxASSERT_MSG( status == noErr , wxT("couldn't dispose converter") ) ;
status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) buf , 0 , byteOutLen / 2 , byteOutLen / 2 , 1 ,
wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
int wlen = wxWcslen( wchar.data() ) ;
status = ::ATSUCreateTextLayoutWithTextPtr( (UniCharArrayPtr) wchar.data() , 0 , wlen , wlen , 1 ,
&chars , (ATSUStyle*) &m_macATSUIStyle , &atsuLayout ) ;
#endif
wxASSERT_MSG( status == noErr , wxT("couldn't create the layout of the rotated text") );
@ -1418,10 +1405,6 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y,
CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) );
CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) );
::ATSUDisposeTextLayout(atsuLayout);
#if wxUSE_UNICODE
#else
delete[] buf ;
#endif
}
void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
@ -1501,7 +1484,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
::DrawText( text , 0 , strlen(text) ) ;
line++ ;
::MoveTo( xx , yy + line*(fi.descent + fi.ascent + fi.leading) );
@ -1543,7 +1526,7 @@ void wxDC::DoDrawText(const wxString& strtext, wxCoord x, wxCoord y)
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
::DrawText( text , 0 , strlen(text) ) ;
}
}
@ -1583,21 +1566,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h
if ( externalLeading )
*externalLeading = YDEV2LOGREL( fi.leading ) ;
int length = strtext.Length() ;
/*
const char *text = NULL ;
wxString macText ;
if ( wxApp::s_macDefaultEncodingIsPC )
{
macText = wxMacMakeMacStringFromPC( string ) ;
text = macText ;
length = macText.Length() ;
}
else
{
text = string ;
length = string.Length() ;
}
*/
int laststop = 0 ;
int i = 0 ;
int curwidth = 0 ;
@ -1628,7 +1597,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )
@ -1656,7 +1625,7 @@ void wxDC::DoGetTextExtent( const wxString &strtext, wxCoord *width, wxCoord *h
else
#endif
{
wxCharBuffer text = wxMacStringToCString(linetext) ;
wxCharBuffer text = linetext.mb_str(wxConvLocal) ;
curwidth = ::TextWidth( text , 0 , strlen(text) ) ;
}
if ( curwidth > *width )

View File

@ -206,7 +206,7 @@ bool wxDropTarget::GetData()
if( theType == 'TEXT' )
{
theData[dataSize]=0 ;
wxString convert = wxMacMakeStringFromCString( theData ) ;
wxString convert( theData , wxConvLocal ) ;
m_dataObject->SetData( format, convert.Length() * sizeof(wxChar), (const wxChar*) convert );
}
else if ( theType == kDragFlavorTypeHFS )
@ -302,7 +302,7 @@ wxDragResult wxDropSource::DoDragDrop(int WXUNUSED(flags))
dataSize-- ;
dataPtr[ dataSize ] = 0 ;
wxString st( (wxChar*) dataPtr ) ;
wxCharBuffer buf = wxMacStringToCString( st ) ;
wxCharBuffer buf = st.mb_str( wxConvLocal) ;
AddDragItemFlavor(theDrag, theItem, type , buf.data(), strlen(buf), 0);
}
else if (type == kDragFlavorTypeHFS )

View File

@ -137,7 +137,7 @@ static pascal void wxMacListDefinition( short message, Boolean isSelected, Rect
}
#else
{
wxCharBuffer text = wxMacStringToCString( linetext ) ;
wxCharBuffer text = linetext.mb_str( wxConvLocal) ;
MoveTo(drawRect->left + 4 , drawRect->top + 10 );
DrawText(text, 0 , strlen(text) );
}
@ -633,8 +633,7 @@ wxSize wxListBox::DoGetBestSize() const
&baseline );
wLine = bounds.h ;
#else
wxCharBuffer text = wxMacStringToCString( str ) ;
wLine = ::TextWidth( text , 0 , strlen(text) ) ;
wLine = ::TextWidth( str.c_str() , 0 , str.Length() ) ;
#endif
lbWidth = wxMax(lbWidth, wLine);
}

View File

@ -687,7 +687,7 @@ const short kVerticalMargin = 2 ;
const short kHorizontalMargin = 2 ;
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
const wxString& st,
const wxString& str,
const wxPoint& pos,
const wxSize& size, long style,
const wxValidator& validator,
@ -747,6 +747,8 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
m_editable = FALSE ;
}
wxString st = str ;
st.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
@ -771,7 +773,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
if ( !m_macUsesTXN )
{
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ;
}
else
@ -785,7 +787,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
TXNSetData( ((TXNObject) m_macTXN) , kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2,
kTXNStartOffset, kTXNEndOffset);
#else
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TXNSetData( ((TXNObject) m_macTXN) , kTXNTextData, (void*)text.data(), strlen( text ) ,
kTXNStartOffset, kTXNEndOffset);
#endif
@ -817,7 +819,7 @@ wxString wxTextCtrl::GetValue() const
::GetControlData( (ControlHandle) m_macControl, 0,
( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag,
actualSize , buf.data() , &actualSize ) ;
result = wxMacMakeStringFromCString( buf ) ;
result = wxString( buf , wxConvLocal) ;
}
}
else
@ -856,14 +858,14 @@ wxString wxTextCtrl::GetValue() const
if ( actualSize > 0 )
{
HLock( theText ) ;
result = wxMacMakeStringFromCString( *theText , actualSize ) ;
result = wxString( *theText , wxConvLocal , actualSize ) ;
HUnlock( theText ) ;
}
DisposeHandle( theText ) ;
}
#endif
}
result.Replace(wxT("\r"),wxT("\n")) ;
return result ;
}
@ -880,11 +882,13 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
}
}
void wxTextCtrl::SetValue(const wxString& st)
void wxTextCtrl::SetValue(const wxString& str)
{
wxString st = str ;
st.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
::SetControlData( (ControlHandle) m_macControl, 0, ( m_windowStyle & wxTE_PASSWORD ) ? kControlEditTextPasswordTag : kControlEditTextTextTag , strlen(text) , text ) ;
}
else
@ -896,7 +900,7 @@ void wxTextCtrl::SetValue(const wxString& st)
TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 ,
kTXNStartOffset, kTXNEndOffset);
#else
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) ,
kTXNStartOffset, kTXNEndOffset);
#endif
@ -1167,8 +1171,10 @@ long wxTextCtrl::GetLastPosition() const
}
}
void wxTextCtrl::Replace(long from, long to, const wxString& value)
void wxTextCtrl::Replace(long from, long to, const wxString& str)
{
wxString value = str ;
value.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
ControlEditTextSelectionRec selection ;
@ -1270,11 +1276,13 @@ bool wxTextCtrl::LoadFile(const wxString& file)
return FALSE;
}
void wxTextCtrl::WriteText(const wxString& st)
void wxTextCtrl::WriteText(const wxString& str)
{
wxString st = str ;
st.Replace(wxT("\n"), wxT("\r"));
if ( !m_macUsesTXN )
{
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TEInsert( text , strlen(text) , ((TEHandle) m_macTE) ) ;
}
else
@ -1288,7 +1296,7 @@ void wxTextCtrl::WriteText(const wxString& st)
TXNSetData( ((TXNObject) m_macTXN), kTXNUnicodeTextData, (void*)st.wc_str(), st.Length() * 2 ,
kTXNUseCurrentSelection, kTXNUseCurrentSelection);
#else
wxCharBuffer text = wxMacStringToCString( st ) ;
wxCharBuffer text = st.mb_str(wxConvLocal) ;
TXNSetData( ((TXNObject) m_macTXN), kTXNTextData, (void*)text.data(), strlen( text ) ,
kTXNUseCurrentSelection, kTXNUseCurrentSelection);
#endif
@ -1477,12 +1485,12 @@ int wxTextCtrl::GetLineLength(long lineNo) const
for (size_t j = i; j < content.Length(); j++)
{
count++;
if (content[j] == '\r') return count;
if (content[j] == '\n') return count;
}
return count;
}
if (content[i] == '\r') count++;
if (content[i] == '\n') count++;
}
return 0;
}
@ -1503,7 +1511,7 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
for (size_t j = i; j < content.Length(); j++)
{
if (content[j] == '\r')
if (content[j] == '\n')
return tmp;
tmp += content[j];
@ -1511,7 +1519,7 @@ wxString wxTextCtrl::GetLineText(long lineNo) const
return tmp;
}
if (content[i] == '\r') count++;
if (content[i] == '\n') count++;
}
return wxEmptyString ;
}

View File

@ -262,7 +262,7 @@ void wxMacToolTip::Draw()
int width = 0 ;
int thiswidth = 0 ;
int laststop = 0 ;
wxCharBuffer text = wxMacStringToCString( m_label ) ;
wxCharBuffer text = m_label.mb_str( wxConvLocal) ;
while( i < length )
{

View File

@ -546,6 +546,8 @@ bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
// wxMac Specific utility functions
//---------------------------------------------------------------------------
#if 0
char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
"\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
"\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
@ -632,17 +634,17 @@ void wxMacConvertToPC( const char *from , char *to , int len )
TECObjectRef s_TECNativeCToUnicode = NULL ;
TECObjectRef s_TECUnicodeToNativeC = NULL ;
TECObjectRef s_TECPlatformToNativeC = NULL ;
TECObjectRef s_TECNativeCToPlatform = NULL ;
void wxMacSetupConverters()
{
// if we assume errors are happening here we need low level debugging
// since the high level assert will use the encoders that are not yet
// setup...
const int kEncoding = wxApp::s_macDefaultEncodingIsPC
? (int)kTextEncodingWindowsLatin1
: (int)kTextEncodingMacRoman;
#if TARGET_CARBON
const TextEncodingBase kEncoding = CFStringGetSystemEncoding();
#else
const TextEncodingBase kEncoding = kTextEncodingMacRoman;
#endif
OSStatus status = noErr ;
status = TECCreateConverter(&s_TECNativeCToUnicode,
kEncoding,
@ -652,18 +654,6 @@ void wxMacSetupConverters()
status = TECCreateConverter(&s_TECUnicodeToNativeC,
kTextEncodingUnicodeDefault,
kEncoding);
if ( wxApp::s_macDefaultEncodingIsPC )
{
status = TECCreateConverter(&s_TECPlatformToNativeC,
kTextEncodingMacRoman,
kTextEncodingWindowsLatin1);
status = TECCreateConverter(&s_TECNativeCToPlatform,
kTextEncodingWindowsLatin1,
kTextEncodingMacRoman);
}
}
void wxMacCleanupConverters()
@ -672,10 +662,6 @@ void wxMacCleanupConverters()
status = TECDisposeConverter(s_TECNativeCToUnicode);
status = TECDisposeConverter(s_TECUnicodeToNativeC);
status = TECDisposeConverter(s_TECPlatformToNativeC);
status = TECDisposeConverter(s_TECNativeCToPlatform);
}
wxWCharBuffer wxMacStringToWString( const wxString &from )
@ -709,17 +695,7 @@ wxString wxMacMakeStringFromCString( const char * from , int len )
status = TECConvertText(s_TECNativeCToUnicode, (ConstTextPtr)from , byteInLen, &byteInLen,
(TextPtr)buf, byteBufferLen, &byteOutLen);
#else
if ( !wxApp::s_macDefaultEncodingIsPC )
memcpy( buf , from , len ) ;
else
{
ByteCount byteOutLen ;
ByteCount byteInLen = len ;
ByteCount byteBufferLen = byteInLen ;
status = TECConvertText(s_TECPlatformToNativeC, (ConstTextPtr)from , byteInLen, &byteInLen,
(TextPtr)buf, byteBufferLen, &byteOutLen);
}
memcpy( buf , from , len ) ;
#endif
buf[len] = 0 ;
result.UngetWriteBuf() ;
@ -743,26 +719,14 @@ wxCharBuffer wxMacStringToCString( const wxString &from )
(TextPtr)result.data(), byteBufferLen, &byteOutLen);
return result ;
#else
if ( !wxApp::s_macDefaultEncodingIsPC )
return wxCharBuffer( from.c_str() ) ;
else
{
wxCharBuffer result( from.Length() ) ;
OSStatus status = noErr ;
ByteCount byteOutLen ;
ByteCount byteInLen = from.Length() ;
ByteCount byteBufferLen = byteInLen ;
status = TECConvertText(s_TECNativeCToPlatform, (ConstTextPtr)from.c_str() , byteInLen, &byteInLen,
(TextPtr)result.data(), byteBufferLen, &byteOutLen);
return result ;
}
return wxCharBuffer( from.c_str() ) ;
#endif
}
#endif
void wxMacStringToPascal( const wxString&from , StringPtr to )
{
wxCharBuffer buf = wxMacStringToCString( from ) ;
wxCharBuffer buf = from.mb_str( wxConvLocal ) ;
int len = strlen(buf) ;
if ( len > 255 )
@ -773,7 +737,7 @@ void wxMacStringToPascal( const wxString&from , StringPtr to )
wxString wxMacMakeStringFromPascal( ConstStringPtr from )
{
return wxMacMakeStringFromCString( (char*) &from[1] , from[0] ) ;
return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ;
}
#endif // wxUSE_BASE
@ -794,8 +758,7 @@ void wxMacCFStringHolder::Assign( const wxString &str )
(const unsigned short*)str.wc_str(), str.Len() );
#else
m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
wxApp::s_macDefaultEncodingIsPC ?
kCFStringEncodingWindowsLatin1 : CFStringGetSystemEncoding() ) ;
CFStringGetSystemEncoding() ) ;
#endif
m_release = true ;
}
@ -808,89 +771,13 @@ wxString wxMacCFStringHolder::AsString()
#if wxUSE_UNICODE
CFStringGetCharacters( m_cfs , CFRangeMake( 0 , len ) , (UniChar*) buf ) ;
#else
CFStringGetCString( m_cfs , buf , len+1 , wxApp::s_macDefaultEncodingIsPC ?
kCFStringEncodingWindowsLatin1 : CFStringGetSystemEncoding() ) ;
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
#endif
buf[len] = 0 ;
result.UngetWriteBuf() ;
return result ;
}
#if 0
wxString wxMacMakeMacStringFromPC( const wxChar * p )
{
wxString result ;
int len = wxStrlen ( p ) ;
if ( len > 0 )
{
wxChar* ptr = result.GetWriteBuf(len) ;
wxMacConvertFromPC( p , ptr , len ) ;
ptr[len] = 0 ;
result.UngetWriteBuf( len ) ;
}
return result ;
}
wxString wxMacMakePCStringFromMac( const wxChar * p )
{
wxString result ;
int len = wxStrlen ( p ) ;
if ( len > 0 )
{
wxChar* ptr = result.GetWriteBuf(len) ;
wxMacConvertToPC( p , ptr , len ) ;
ptr[len] = 0 ;
result.UngetWriteBuf( len ) ;
}
return result ;
}
wxString wxMacMakeStringFromMacString( const wxChar* from , bool mac2pcEncoding )
{
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( from ) ;
}
else
{
return wxString( from ) ;
}
}
//
// Pascal Strings
//
wxString wxMacMakeStringFromPascal( ConstStringPtr from , bool mac2pcEncoding )
{
// this is safe since a pascal string can never be larger than 256 bytes
char s[256] ;
CopyPascalStringToC( from , s ) ;
if (mac2pcEncoding)
{
return wxMacMakePCStringFromMac( s ) ;
}
else
{
return wxString( s ) ;
}
}
void wxMacStringToPascal( const wxChar * from , StringPtr to , bool pc2macEncoding )
{
if (pc2macEncoding)
{
CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ;
}
else
{
CopyCStringToPascal( from , to ) ;
}
}
#endif
#endif //TARGET_CARBON
// ----------------------------------------------------------------------------