simplifying native string handling, see #11061

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Stefan Csomor 2009-08-18 15:30:24 +00:00
parent eceb28f912
commit f66ecdc4fb
7 changed files with 32 additions and 23 deletions

View File

@ -68,7 +68,12 @@ public:
{
}
wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) const;
static wxString AsString( CFStringRef ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
#if wxOSX_USE_COCOA_OR_IPHONE
static wxString AsString( NSString* ref, wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
#endif
#if wxOSX_USE_COCOA_OR_IPHONE
NSString* AsNSString() const { return (NSString*)(CFStringRef) *this; }

View File

@ -99,9 +99,7 @@ int wxDirDialog::ShowModal()
}
if (returnCode == NSOKButton )
{
wxCFStringRef resultpath( [[[oPanel filenames] objectAtIndex:0] retain] );
SetPath( resultpath.AsString() );
SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
result = wxID_OK;
}
return result;

View File

@ -201,9 +201,7 @@ int wxFileDialog::ShowModal()
panel = sPanel;
result = wxID_OK;
wxCFStringRef filename( [[sPanel filename] retain] );
m_path = filename.AsString();
m_path = wxCFStringRef::AsString([sPanel filename]);
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly( m_path );
}
@ -245,8 +243,7 @@ int wxFileDialog::ShowModal()
NSArray* filenames = [oPanel filenames];
for ( size_t i = 0 ; i < [filenames count] ; ++ i )
{
wxCFStringRef filename( [(NSString*) [filenames objectAtIndex:i] retain] );
wxString fnstr = filename.AsString();
wxString fnstr = wxCFStringRef::AsString([filenames objectAtIndex:i]);
m_paths.Add( fnstr );
m_fileNames.Add( wxFileNameFromPath(fnstr) );
if ( i == 0 )

View File

@ -209,7 +209,7 @@ public :
virtual wxString GetStringValue() const
{
if ( [value isKindOfClass:[NSString class]] )
return wxCFStringRef( (CFStringRef) [value retain] ).AsString();
return wxCFStringRef::AsString( (NSString*) value );
return wxEmptyString;
}

View File

@ -333,8 +333,7 @@ wxString wxNSTextViewControl::GetStringValue() const
{
if (m_textView)
{
wxCFStringRef cf( (CFStringRef) [[m_textView string] retain] );
wxString result = cf.AsString(m_wxPeer->GetFont().GetEncoding());
wxString result = wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding());
wxMacConvertNewlines13To10( &result ) ;
return result;
}
@ -446,8 +445,7 @@ wxNSTextFieldControl::~wxNSTextFieldControl()
wxString wxNSTextFieldControl::GetStringValue() const
{
wxCFStringRef cf( (CFStringRef) [[m_textField stringValue] retain] );
return cf.AsString(m_wxPeer->GetFont().GetEncoding());
return wxCFStringRef::AsString([m_textField stringValue], m_wxPeer->GetFont().GetEncoding());
}
void wxNSTextFieldControl::SetStringValue( const wxString &str)

View File

@ -294,13 +294,11 @@ void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charStrin
{
// if charString is set, it did not come from key up / key down
wxevent.SetEventType( wxEVT_CHAR );
wxCFStringRef cfchars((CFStringRef)[charString retain]);
chars = cfchars.AsString();
chars = wxCFStringRef::AsString(charString);
}
else if ( nschars )
{
wxCFStringRef cfchars((CFStringRef)[nschars retain]);
chars = cfchars.AsString();
chars = wxCFStringRef::AsString(nschars);
}
}

View File

@ -632,12 +632,12 @@ wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UN
}
}
wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding))
wxString wxCFStringRef::AsString( CFStringRef ref, wxFontEncoding WXUNUSED_IN_UNICODE(encoding) )
{
if ( !get() )
if ( !ref )
return wxEmptyString ;
Size cflen = CFStringGetLength( get() ) ;
Size cflen = CFStringGetLength( ref ) ;
char* buf = NULL ;
CFStringEncoding cfencoding = 0;
@ -655,10 +655,10 @@ wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding))
#endif
CFIndex cStrLen ;
CFStringGetBytes( get() , CFRangeMake(0, cflen) , cfencoding ,
CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding ,
'?' , false , NULL , 0 , &cStrLen ) ;
buf = new char[ cStrLen ] ;
CFStringGetBytes( get() , CFRangeMake(0, cflen) , cfencoding,
CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding,
'?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
#if wxUSE_UNICODE
@ -678,6 +678,19 @@ wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding))
return result ;
}
wxString wxCFStringRef::AsString(wxFontEncoding encoding) const
{
return AsString( get(), encoding );
}
#if wxOSX_USE_COCOA_OR_IPHONE
wxString wxCFStringRef::AsString( NSString* ref, wxFontEncoding encoding )
{
return AsString( (CFStringRef) ref, encoding );
}
#endif
//
// wxMacUniCharBuffer
//