newlines conversions streamlined
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24147 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -138,12 +138,7 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
|
|||||||
|
|
||||||
if ( dataFormat.GetType() == wxDF_TEXT )
|
if ( dataFormat.GetType() == wxDF_TEXT )
|
||||||
{
|
{
|
||||||
char * buf = (char*) data ;
|
wxMacConvertNewlines10To13( (char*) data ) ;
|
||||||
while( (buf=strchr(buf,0x0a)) != NULL )
|
|
||||||
{
|
|
||||||
*buf = 13 ;
|
|
||||||
buf++ ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
@@ -22,36 +22,6 @@
|
|||||||
IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
|
IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
short language = 0 ;
|
|
||||||
|
|
||||||
void wxMacConvertNewlines( const char *source , char * destination ) ;
|
|
||||||
void wxMacConvertNewlines( const char *source , char * destination )
|
|
||||||
{
|
|
||||||
const char *s = source ;
|
|
||||||
char *d = destination ;
|
|
||||||
|
|
||||||
while( *s )
|
|
||||||
{
|
|
||||||
switch( *s )
|
|
||||||
{
|
|
||||||
case 0x0a :
|
|
||||||
*d++ = 0x0d ;
|
|
||||||
++s ;
|
|
||||||
break ;
|
|
||||||
case 0x0d :
|
|
||||||
*d++ = 0x0d ;
|
|
||||||
++s ;
|
|
||||||
if ( *s == 0x0a )
|
|
||||||
++s ;
|
|
||||||
break ;
|
|
||||||
default :
|
|
||||||
*d++ = *s++ ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*d = 0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
|
wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
|
||||||
long style, const wxPoint& pos)
|
long style, const wxPoint& pos)
|
||||||
{
|
{
|
||||||
|
@@ -748,7 +748,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxString st = str ;
|
wxString st = str ;
|
||||||
st.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
|
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
|
||||||
@@ -865,7 +865,7 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
result.Replace(wxT("\r"),wxT("\n")) ;
|
wxMacConvertNewlines10To13( &result ) ;
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,7 +885,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
|
|||||||
void wxTextCtrl::SetValue(const wxString& str)
|
void wxTextCtrl::SetValue(const wxString& str)
|
||||||
{
|
{
|
||||||
wxString st = str ;
|
wxString st = str ;
|
||||||
st.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
||||||
@@ -1174,7 +1174,7 @@ long wxTextCtrl::GetLastPosition() const
|
|||||||
void wxTextCtrl::Replace(long from, long to, const wxString& str)
|
void wxTextCtrl::Replace(long from, long to, const wxString& str)
|
||||||
{
|
{
|
||||||
wxString value = str ;
|
wxString value = str ;
|
||||||
value.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
ControlEditTextSelectionRec selection ;
|
ControlEditTextSelectionRec selection ;
|
||||||
@@ -1279,7 +1279,7 @@ bool wxTextCtrl::LoadFile(const wxString& file)
|
|||||||
void wxTextCtrl::WriteText(const wxString& str)
|
void wxTextCtrl::WriteText(const wxString& str)
|
||||||
{
|
{
|
||||||
wxString st = str ;
|
wxString st = str ;
|
||||||
st.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
||||||
|
@@ -46,9 +46,7 @@
|
|||||||
#include "TextCommon.h"
|
#include "TextCommon.h"
|
||||||
#include "TextEncodingConverter.h"
|
#include "TextEncodingConverter.h"
|
||||||
|
|
||||||
#if defined(__WXMAC__)
|
#include "wx/mac/private.h" // includes mac headers
|
||||||
#include "wx/mac/private.h" // includes mac headers
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__MWERKS__) && wxUSE_UNICODE
|
#if defined(__MWERKS__) && wxUSE_UNICODE
|
||||||
#include <wtime.h>
|
#include <wtime.h>
|
||||||
@@ -751,8 +749,10 @@ wxString wxMacMakeStringFromPascal( ConstStringPtr from )
|
|||||||
|
|
||||||
#if TARGET_CARBON
|
#if TARGET_CARBON
|
||||||
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
||||||
void wxMacCFStringHolder::Assign( const wxString &str )
|
void wxMacCFStringHolder::Assign( const wxString &st )
|
||||||
{
|
{
|
||||||
|
wxString str = st ;
|
||||||
|
wxMacConvertNewlines13To10( &str ) ;
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
||||||
(const unsigned short*)str.wc_str(), str.Len() );
|
(const unsigned short*)str.wc_str(), str.Len() );
|
||||||
@@ -774,12 +774,73 @@ wxString wxMacCFStringHolder::AsString()
|
|||||||
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
|
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
|
||||||
#endif
|
#endif
|
||||||
buf[len] = 0 ;
|
buf[len] = 0 ;
|
||||||
|
wxMacConvertNewlines10To13( buf ) ;
|
||||||
result.UngetWriteBuf() ;
|
result.UngetWriteBuf() ;
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //TARGET_CARBON
|
#endif //TARGET_CARBON
|
||||||
|
|
||||||
|
void wxMacConvertNewlines13To10( char * data )
|
||||||
|
{
|
||||||
|
char * buf = data ;
|
||||||
|
while( (buf=strchr(buf,0x0d)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0a ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines10To13( char * data )
|
||||||
|
{
|
||||||
|
char * buf = data ;
|
||||||
|
while( (buf=strchr(buf,0x0a)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0d ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines13To10( wxString * data )
|
||||||
|
{
|
||||||
|
if ( data->Length() == 0 )
|
||||||
|
return ;
|
||||||
|
|
||||||
|
wxMacConvertNewlines13To10( data->GetWriteBuf( data->Length() ) ) ;
|
||||||
|
data->UngetWriteBuf() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines10To13( wxString * data )
|
||||||
|
{
|
||||||
|
if ( data->Length() == 0 )
|
||||||
|
return ;
|
||||||
|
wxMacConvertNewlines10To13( data->GetWriteBuf( data->Length() ) ) ;
|
||||||
|
data->UngetWriteBuf() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
void wxMacConvertNewlines13To10( wxChar * data )
|
||||||
|
{
|
||||||
|
wxChar * buf = data ;
|
||||||
|
while( (buf=wxStrchr(buf,0x0d)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0a ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines10To13( wxChar * data )
|
||||||
|
{
|
||||||
|
wxChar * buf = data ;
|
||||||
|
while( (buf=wxStrchr(buf,0x0a)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0d ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// debugging support
|
// debugging support
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -138,12 +138,7 @@ void *wxGetClipboardData(wxDataFormat dataFormat, long *len)
|
|||||||
|
|
||||||
if ( dataFormat.GetType() == wxDF_TEXT )
|
if ( dataFormat.GetType() == wxDF_TEXT )
|
||||||
{
|
{
|
||||||
char * buf = (char*) data ;
|
wxMacConvertNewlines10To13( (char*) data ) ;
|
||||||
while( (buf=strchr(buf,0x0a)) != NULL )
|
|
||||||
{
|
|
||||||
*buf = 13 ;
|
|
||||||
buf++ ;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
@@ -22,36 +22,6 @@
|
|||||||
IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
|
IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
short language = 0 ;
|
|
||||||
|
|
||||||
void wxMacConvertNewlines( const char *source , char * destination ) ;
|
|
||||||
void wxMacConvertNewlines( const char *source , char * destination )
|
|
||||||
{
|
|
||||||
const char *s = source ;
|
|
||||||
char *d = destination ;
|
|
||||||
|
|
||||||
while( *s )
|
|
||||||
{
|
|
||||||
switch( *s )
|
|
||||||
{
|
|
||||||
case 0x0a :
|
|
||||||
*d++ = 0x0d ;
|
|
||||||
++s ;
|
|
||||||
break ;
|
|
||||||
case 0x0d :
|
|
||||||
*d++ = 0x0d ;
|
|
||||||
++s ;
|
|
||||||
if ( *s == 0x0a )
|
|
||||||
++s ;
|
|
||||||
break ;
|
|
||||||
default :
|
|
||||||
*d++ = *s++ ;
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*d = 0 ;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
|
wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
|
||||||
long style, const wxPoint& pos)
|
long style, const wxPoint& pos)
|
||||||
{
|
{
|
||||||
|
@@ -748,7 +748,7 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxString st = str ;
|
wxString st = str ;
|
||||||
st.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
|
m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , "\p" , false , 0 , 0 , 1,
|
||||||
@@ -865,7 +865,7 @@ wxString wxTextCtrl::GetValue() const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
result.Replace(wxT("\r"),wxT("\n")) ;
|
wxMacConvertNewlines10To13( &result ) ;
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -885,7 +885,7 @@ void wxTextCtrl::GetSelection(long* from, long* to) const
|
|||||||
void wxTextCtrl::SetValue(const wxString& str)
|
void wxTextCtrl::SetValue(const wxString& str)
|
||||||
{
|
{
|
||||||
wxString st = str ;
|
wxString st = str ;
|
||||||
st.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
||||||
@@ -1174,7 +1174,7 @@ long wxTextCtrl::GetLastPosition() const
|
|||||||
void wxTextCtrl::Replace(long from, long to, const wxString& str)
|
void wxTextCtrl::Replace(long from, long to, const wxString& str)
|
||||||
{
|
{
|
||||||
wxString value = str ;
|
wxString value = str ;
|
||||||
value.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
ControlEditTextSelectionRec selection ;
|
ControlEditTextSelectionRec selection ;
|
||||||
@@ -1279,7 +1279,7 @@ bool wxTextCtrl::LoadFile(const wxString& file)
|
|||||||
void wxTextCtrl::WriteText(const wxString& str)
|
void wxTextCtrl::WriteText(const wxString& str)
|
||||||
{
|
{
|
||||||
wxString st = str ;
|
wxString st = str ;
|
||||||
st.Replace(wxT("\n"), wxT("\r"));
|
wxMacConvertNewlines13To10( &st ) ;
|
||||||
if ( !m_macUsesTXN )
|
if ( !m_macUsesTXN )
|
||||||
{
|
{
|
||||||
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
wxCharBuffer text = st.mb_str(wxConvLocal) ;
|
||||||
|
@@ -46,9 +46,7 @@
|
|||||||
#include "TextCommon.h"
|
#include "TextCommon.h"
|
||||||
#include "TextEncodingConverter.h"
|
#include "TextEncodingConverter.h"
|
||||||
|
|
||||||
#if defined(__WXMAC__)
|
#include "wx/mac/private.h" // includes mac headers
|
||||||
#include "wx/mac/private.h" // includes mac headers
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__MWERKS__) && wxUSE_UNICODE
|
#if defined(__MWERKS__) && wxUSE_UNICODE
|
||||||
#include <wtime.h>
|
#include <wtime.h>
|
||||||
@@ -751,8 +749,10 @@ wxString wxMacMakeStringFromPascal( ConstStringPtr from )
|
|||||||
|
|
||||||
#if TARGET_CARBON
|
#if TARGET_CARBON
|
||||||
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
// converts this string into a carbon foundation string with optional pc 2 mac encoding
|
||||||
void wxMacCFStringHolder::Assign( const wxString &str )
|
void wxMacCFStringHolder::Assign( const wxString &st )
|
||||||
{
|
{
|
||||||
|
wxString str = st ;
|
||||||
|
wxMacConvertNewlines13To10( &str ) ;
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
|
||||||
(const unsigned short*)str.wc_str(), str.Len() );
|
(const unsigned short*)str.wc_str(), str.Len() );
|
||||||
@@ -774,12 +774,73 @@ wxString wxMacCFStringHolder::AsString()
|
|||||||
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
|
CFStringGetCString( m_cfs , buf , len+1 , CFStringGetSystemEncoding() ) ;
|
||||||
#endif
|
#endif
|
||||||
buf[len] = 0 ;
|
buf[len] = 0 ;
|
||||||
|
wxMacConvertNewlines10To13( buf ) ;
|
||||||
result.UngetWriteBuf() ;
|
result.UngetWriteBuf() ;
|
||||||
return result ;
|
return result ;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //TARGET_CARBON
|
#endif //TARGET_CARBON
|
||||||
|
|
||||||
|
void wxMacConvertNewlines13To10( char * data )
|
||||||
|
{
|
||||||
|
char * buf = data ;
|
||||||
|
while( (buf=strchr(buf,0x0d)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0a ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines10To13( char * data )
|
||||||
|
{
|
||||||
|
char * buf = data ;
|
||||||
|
while( (buf=strchr(buf,0x0a)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0d ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines13To10( wxString * data )
|
||||||
|
{
|
||||||
|
if ( data->Length() == 0 )
|
||||||
|
return ;
|
||||||
|
|
||||||
|
wxMacConvertNewlines13To10( data->GetWriteBuf( data->Length() ) ) ;
|
||||||
|
data->UngetWriteBuf() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines10To13( wxString * data )
|
||||||
|
{
|
||||||
|
if ( data->Length() == 0 )
|
||||||
|
return ;
|
||||||
|
wxMacConvertNewlines10To13( data->GetWriteBuf( data->Length() ) ) ;
|
||||||
|
data->UngetWriteBuf() ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
void wxMacConvertNewlines13To10( wxChar * data )
|
||||||
|
{
|
||||||
|
wxChar * buf = data ;
|
||||||
|
while( (buf=wxStrchr(buf,0x0d)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0a ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxMacConvertNewlines10To13( wxChar * data )
|
||||||
|
{
|
||||||
|
wxChar * buf = data ;
|
||||||
|
while( (buf=wxStrchr(buf,0x0a)) != NULL )
|
||||||
|
{
|
||||||
|
*buf = 0x0d ;
|
||||||
|
buf++ ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// debugging support
|
// debugging support
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user