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:
@@ -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
|
#if wxOSX_USE_COCOA_OR_IPHONE
|
||||||
NSString* AsNSString() const { return (NSString*)(CFStringRef) *this; }
|
NSString* AsNSString() const { return (NSString*)(CFStringRef) *this; }
|
||||||
|
@@ -99,9 +99,7 @@ int wxDirDialog::ShowModal()
|
|||||||
}
|
}
|
||||||
if (returnCode == NSOKButton )
|
if (returnCode == NSOKButton )
|
||||||
{
|
{
|
||||||
wxCFStringRef resultpath( [[[oPanel filenames] objectAtIndex:0] retain] );
|
SetPath( wxCFStringRef::AsString([[oPanel filenames] objectAtIndex:0]));
|
||||||
|
|
||||||
SetPath( resultpath.AsString() );
|
|
||||||
result = wxID_OK;
|
result = wxID_OK;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@@ -201,9 +201,7 @@ int wxFileDialog::ShowModal()
|
|||||||
panel = sPanel;
|
panel = sPanel;
|
||||||
result = wxID_OK;
|
result = wxID_OK;
|
||||||
|
|
||||||
wxCFStringRef filename( [[sPanel filename] retain] );
|
m_path = wxCFStringRef::AsString([sPanel filename]);
|
||||||
|
|
||||||
m_path = filename.AsString();
|
|
||||||
m_fileName = wxFileNameFromPath(m_path);
|
m_fileName = wxFileNameFromPath(m_path);
|
||||||
m_dir = wxPathOnly( m_path );
|
m_dir = wxPathOnly( m_path );
|
||||||
}
|
}
|
||||||
@@ -245,8 +243,7 @@ int wxFileDialog::ShowModal()
|
|||||||
NSArray* filenames = [oPanel filenames];
|
NSArray* filenames = [oPanel filenames];
|
||||||
for ( size_t i = 0 ; i < [filenames count] ; ++ i )
|
for ( size_t i = 0 ; i < [filenames count] ; ++ i )
|
||||||
{
|
{
|
||||||
wxCFStringRef filename( [(NSString*) [filenames objectAtIndex:i] retain] );
|
wxString fnstr = wxCFStringRef::AsString([filenames objectAtIndex:i]);
|
||||||
wxString fnstr = filename.AsString();
|
|
||||||
m_paths.Add( fnstr );
|
m_paths.Add( fnstr );
|
||||||
m_fileNames.Add( wxFileNameFromPath(fnstr) );
|
m_fileNames.Add( wxFileNameFromPath(fnstr) );
|
||||||
if ( i == 0 )
|
if ( i == 0 )
|
||||||
|
@@ -209,7 +209,7 @@ public :
|
|||||||
virtual wxString GetStringValue() const
|
virtual wxString GetStringValue() const
|
||||||
{
|
{
|
||||||
if ( [value isKindOfClass:[NSString class]] )
|
if ( [value isKindOfClass:[NSString class]] )
|
||||||
return wxCFStringRef( (CFStringRef) [value retain] ).AsString();
|
return wxCFStringRef::AsString( (NSString*) value );
|
||||||
|
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
}
|
}
|
||||||
|
@@ -333,8 +333,7 @@ wxString wxNSTextViewControl::GetStringValue() const
|
|||||||
{
|
{
|
||||||
if (m_textView)
|
if (m_textView)
|
||||||
{
|
{
|
||||||
wxCFStringRef cf( (CFStringRef) [[m_textView string] retain] );
|
wxString result = wxCFStringRef::AsString([m_textView string], m_wxPeer->GetFont().GetEncoding());
|
||||||
wxString result = cf.AsString(m_wxPeer->GetFont().GetEncoding());
|
|
||||||
wxMacConvertNewlines13To10( &result ) ;
|
wxMacConvertNewlines13To10( &result ) ;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -446,8 +445,7 @@ wxNSTextFieldControl::~wxNSTextFieldControl()
|
|||||||
|
|
||||||
wxString wxNSTextFieldControl::GetStringValue() const
|
wxString wxNSTextFieldControl::GetStringValue() const
|
||||||
{
|
{
|
||||||
wxCFStringRef cf( (CFStringRef) [[m_textField stringValue] retain] );
|
return wxCFStringRef::AsString([m_textField stringValue], m_wxPeer->GetFont().GetEncoding());
|
||||||
return cf.AsString(m_wxPeer->GetFont().GetEncoding());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNSTextFieldControl::SetStringValue( const wxString &str)
|
void wxNSTextFieldControl::SetStringValue( const wxString &str)
|
||||||
|
@@ -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
|
// if charString is set, it did not come from key up / key down
|
||||||
wxevent.SetEventType( wxEVT_CHAR );
|
wxevent.SetEventType( wxEVT_CHAR );
|
||||||
wxCFStringRef cfchars((CFStringRef)[charString retain]);
|
chars = wxCFStringRef::AsString(charString);
|
||||||
chars = cfchars.AsString();
|
|
||||||
}
|
}
|
||||||
else if ( nschars )
|
else if ( nschars )
|
||||||
{
|
{
|
||||||
wxCFStringRef cfchars((CFStringRef)[nschars retain]);
|
chars = wxCFStringRef::AsString(nschars);
|
||||||
chars = cfchars.AsString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -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 ;
|
return wxEmptyString ;
|
||||||
|
|
||||||
Size cflen = CFStringGetLength( get() ) ;
|
Size cflen = CFStringGetLength( ref ) ;
|
||||||
char* buf = NULL ;
|
char* buf = NULL ;
|
||||||
|
|
||||||
CFStringEncoding cfencoding = 0;
|
CFStringEncoding cfencoding = 0;
|
||||||
@@ -655,10 +655,10 @@ wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding))
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
CFIndex cStrLen ;
|
CFIndex cStrLen ;
|
||||||
CFStringGetBytes( get() , CFRangeMake(0, cflen) , cfencoding ,
|
CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding ,
|
||||||
'?' , false , NULL , 0 , &cStrLen ) ;
|
'?' , false , NULL , 0 , &cStrLen ) ;
|
||||||
buf = new char[ cStrLen ] ;
|
buf = new char[ cStrLen ] ;
|
||||||
CFStringGetBytes( get() , CFRangeMake(0, cflen) , cfencoding,
|
CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding,
|
||||||
'?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
|
'?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
@@ -678,6 +678,19 @@ wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding))
|
|||||||
return result ;
|
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
|
// wxMacUniCharBuffer
|
||||||
//
|
//
|
||||||
|
Reference in New Issue
Block a user