Lots more Unicode fixes.
wxClipboard fixes for GTK2 and UTF8. wxFileConfig now uses wxConvLocal to convert text and doesn't crash anymore.. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16601 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -99,7 +99,7 @@ public:
|
||||
// returns the number of bytes written
|
||||
size_t Write(const void *pBuf, size_t nCount);
|
||||
// returns true on success
|
||||
bool Write(const wxString& s, wxMBConv& conv = wxConvLibc)
|
||||
bool Write(const wxString& s, wxMBConv& conv = wxConvLocal)
|
||||
{
|
||||
const wxWX2MBbuf buf = s.mb_str(conv);
|
||||
size_t size = strlen(buf);
|
||||
|
@@ -504,7 +504,7 @@ bool wxTempFile::Open(const wxString& strName)
|
||||
mode_t mode;
|
||||
|
||||
wxStructStat st;
|
||||
if ( stat(m_strName.fn_str(), &st) == 0 )
|
||||
if ( stat( (const char*) m_strName.fn_str(), &st) == 0 )
|
||||
{
|
||||
mode = st.st_mode;
|
||||
}
|
||||
@@ -517,7 +517,7 @@ bool wxTempFile::Open(const wxString& strName)
|
||||
umask(mask);
|
||||
}
|
||||
|
||||
if ( chmod(m_strTemp.mb_str(), mode) == -1 )
|
||||
if ( chmod( (const char*) m_strTemp.fn_str(), mode) == -1 )
|
||||
{
|
||||
wxLogSysError(_("Failed to set temporary file permissions"));
|
||||
}
|
||||
|
@@ -901,14 +901,24 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||
|
||||
wxTempFile file(m_strLocalFile);
|
||||
|
||||
if ( !file.IsOpened() ) {
|
||||
if ( !file.IsOpened() )
|
||||
{
|
||||
wxLogError(_("can't open user configuration file."));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// write all strings to file
|
||||
for ( wxFileConfigLineList *p = m_linesHead; p != NULL; p = p->Next() ) {
|
||||
if ( !file.Write(p->Text() + wxTextFile::GetEOL()) ) {
|
||||
for ( wxFileConfigLineList *p = m_linesHead; p != NULL; p = p->Next() )
|
||||
{
|
||||
wxString line = p->Text();
|
||||
line += wxTextFile::GetEOL();
|
||||
#if wxUSE_UNICODE
|
||||
wxCharBuffer buf = wxConvLocal.cWX2MB( line );
|
||||
if ( !file.Write( (const char*)buf, strlen( (const char*) buf ) ) )
|
||||
#else
|
||||
if ( !file.Write( line.c_str(), line.Len() ) )
|
||||
#endif
|
||||
{
|
||||
wxLogError(_("can't write user configuration file."));
|
||||
return FALSE;
|
||||
}
|
||||
|
@@ -639,10 +639,10 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
|
||||
path += _T("XXXXXX");
|
||||
|
||||
// we need to copy the path to the buffer in which mkstemp() can modify it
|
||||
wxCharBuffer buf(path.fn_str());
|
||||
wxCharBuffer buf = wxConvFile.cWX2MB( path );
|
||||
|
||||
// cast is safe because the string length doesn't change
|
||||
int fdTemp = mkstemp( (char *)buf.data() );
|
||||
int fdTemp = mkstemp( (char*)(const char*) buf );
|
||||
if ( fdTemp == -1 )
|
||||
{
|
||||
// this might be not necessary as mkstemp() on most systems should have
|
||||
@@ -651,7 +651,7 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
|
||||
}
|
||||
else // mkstemp() succeeded
|
||||
{
|
||||
path = wxConvFile.cMB2WX(buf);
|
||||
path = wxConvFile.cMB2WX( (const char*) buf );
|
||||
|
||||
// avoid leaking the fd
|
||||
if ( fileTemp )
|
||||
@@ -669,14 +669,14 @@ wxFileName::CreateTempFileName(const wxString& prefix, wxFile *fileTemp)
|
||||
// same as above
|
||||
path += _T("XXXXXX");
|
||||
|
||||
wxCharBuffer buf(path.fn_str());
|
||||
if ( !mktemp( buf ) )
|
||||
wxCharBuffer buf = wxConvFile.cWX2MB( path );
|
||||
if ( !mktemp( (const char*) buf ) )
|
||||
{
|
||||
path.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
path = wxConvFile.cMB2WX(buf);
|
||||
path = wxConvFile.cMB2WX( (const char*) buf );
|
||||
}
|
||||
#else // !HAVE_MKTEMP (includes __DOS__)
|
||||
// generate the unique file name ourselves
|
||||
|
@@ -195,7 +195,6 @@ size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
|
||||
{
|
||||
for (size_t i = 0; i < strlen( psz )+1; i++)
|
||||
buf[i] = (wchar_t) psz[i];
|
||||
// printf( "libc %s\n", buf );
|
||||
return strlen( psz );
|
||||
}
|
||||
else
|
||||
@@ -214,7 +213,6 @@ size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
|
||||
{
|
||||
for (size_t i = 0; i < wxStrlen( psz )+1; i++)
|
||||
buf[i] = (char) psz[i];
|
||||
// printf( "libc %s\n", buf );
|
||||
return wxStrlen( psz );
|
||||
}
|
||||
else
|
||||
@@ -250,7 +248,6 @@ const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
|
||||
return wxCharBuffer((char *) NULL);
|
||||
wxCharBuffer buf(nLen); // this allocates nLen+1
|
||||
WC2MB((char *)(const char *) buf, psz, nLen+1);
|
||||
// printf( "str %s\n", (const char*) buf );
|
||||
return buf;
|
||||
}
|
||||
else
|
||||
@@ -911,15 +908,6 @@ static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
|
||||
cset = NULL;
|
||||
}
|
||||
|
||||
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
|
||||
cset = new CP_CharSet(name);
|
||||
if ( cset->usable() )
|
||||
return cset;
|
||||
|
||||
delete cset;
|
||||
cset = NULL;
|
||||
#endif // __WIN32__
|
||||
|
||||
#if wxUSE_FONTMAP
|
||||
cset = new EC_CharSet(name);
|
||||
if ( cset->usable() )
|
||||
@@ -929,6 +917,15 @@ static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
|
||||
cset = NULL;
|
||||
#endif // wxUSE_FONTMAP
|
||||
|
||||
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
|
||||
cset = new CP_CharSet(name);
|
||||
if ( cset->usable() )
|
||||
return cset;
|
||||
|
||||
delete cset;
|
||||
cset = NULL;
|
||||
#endif // __WIN32__
|
||||
|
||||
wxLogError(_("Cannot convert from encoding '%s'!"), name);
|
||||
|
||||
return NULL;
|
||||
|
@@ -74,14 +74,12 @@ struct _GtkSelectionData
|
||||
static void
|
||||
targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
GtkSelectionData *selection_data,
|
||||
#if (GTK_MINOR_VERSION > 0)
|
||||
guint32 WXUNUSED(time),
|
||||
#endif
|
||||
wxClipboard *clipboard )
|
||||
{
|
||||
if ( wxTheClipboard && selection_data->length > 0 )
|
||||
{
|
||||
/* make sure we got the data in the correct form */
|
||||
// make sure we got the data in the correct form
|
||||
GdkAtom type = selection_data->type;
|
||||
if ( type != GDK_SELECTION_TYPE_ATOM )
|
||||
{
|
||||
@@ -113,6 +111,10 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
wxT("selection received for targets, format %s"),
|
||||
format.GetId().c_str() );
|
||||
|
||||
// printf( "format %s requested %s\n",
|
||||
// gdk_atom_name( atoms[i] ),
|
||||
// gdk_atom_name( clipboard->m_targetRequested ) );
|
||||
|
||||
if (format == clipboard->m_targetRequested)
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
@@ -132,9 +134,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
static void
|
||||
selection_received( GtkWidget *WXUNUSED(widget),
|
||||
GtkSelectionData *selection_data,
|
||||
#if (GTK_MINOR_VERSION > 0)
|
||||
guint32 WXUNUSED(time),
|
||||
#endif
|
||||
wxClipboard *clipboard )
|
||||
{
|
||||
if (!wxTheClipboard)
|
||||
@@ -159,7 +159,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
wxDataFormat format( selection_data->target );
|
||||
|
||||
/* make sure we got the data in the correct format */
|
||||
// make sure we got the data in the correct format
|
||||
if (!data_object->IsSupportedFormat( format ) )
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
@@ -248,23 +248,9 @@ selection_handler( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
void *d = malloc(size);
|
||||
|
||||
// Text data will be in UTF8 in Unicode mode.
|
||||
data->GetDataHere( selection_data->target, d );
|
||||
|
||||
// transform Unicode text into multibyte before putting it on clipboard
|
||||
#if wxUSE_UNICODE
|
||||
if ( format.GetType() == wxDF_TEXT )
|
||||
{
|
||||
const wchar_t *wstr = (const wchar_t *)d;
|
||||
size_t len = wxConvCurrent->WC2MB(NULL, wstr, 0);
|
||||
char *str = (char*) malloc(len + 1);
|
||||
wxConvCurrent->WC2MB(str, wstr, len);
|
||||
str[len] = '\0';
|
||||
|
||||
free(d);
|
||||
d = str;
|
||||
}
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
@@ -341,8 +327,8 @@ void wxClipboard::Clear()
|
||||
/* disable GUI threads */
|
||||
#endif
|
||||
|
||||
/* As we have data we also own the clipboard. Once we no longer own
|
||||
it, clear_selection is called which will set m_data to zero */
|
||||
// As we have data we also own the clipboard. Once we no longer own
|
||||
// it, clear_selection is called which will set m_data to zero
|
||||
if (gdk_selection_owner_get( g_clipboardAtom ) == m_clipboardWidget->window)
|
||||
{
|
||||
m_waiting = TRUE;
|
||||
@@ -404,16 +390,16 @@ bool wxClipboard::AddData( wxDataObject *data )
|
||||
|
||||
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
|
||||
|
||||
/* we can only store one wxDataObject */
|
||||
// we can only store one wxDataObject
|
||||
Clear();
|
||||
|
||||
m_data = data;
|
||||
|
||||
/* get formats from wxDataObjects */
|
||||
// get formats from wxDataObjects
|
||||
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
|
||||
m_data->GetAllFormats( array );
|
||||
|
||||
/* primary selection or clipboard */
|
||||
// primary selection or clipboard
|
||||
GdkAtom clipboard = m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
|
||||
: g_clipboardAtom;
|
||||
|
||||
@@ -424,6 +410,9 @@ bool wxClipboard::AddData( wxDataObject *data )
|
||||
wxT("wxClipboard now supports atom %s"),
|
||||
array[i].GetId().c_str() );
|
||||
|
||||
// printf( "added %s\n",
|
||||
// gdk_atom_name( array[i].GetFormatId() ) );
|
||||
|
||||
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
|
||||
clipboard,
|
||||
array[i],
|
||||
|
@@ -72,6 +72,10 @@ wxDataFormat::wxDataFormat( NativeFormat format )
|
||||
void wxDataFormat::SetType( wxDataFormatId type )
|
||||
{
|
||||
PrepareFormats();
|
||||
|
||||
if (type == wxDF_UNICODETEXT)
|
||||
type = wxDF_TEXT;
|
||||
|
||||
m_type = type;
|
||||
|
||||
if (m_type == wxDF_TEXT)
|
||||
@@ -135,7 +139,7 @@ void wxDataFormat::PrepareFormats()
|
||||
// here (with whom?)
|
||||
if (!g_textAtom)
|
||||
#if wxUSE_UNICODE
|
||||
g_textAtom = gdk_atom_intern( "text/utf8", FALSE );
|
||||
g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE );
|
||||
#else
|
||||
g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
|
||||
#endif
|
||||
|
@@ -74,14 +74,12 @@ struct _GtkSelectionData
|
||||
static void
|
||||
targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
GtkSelectionData *selection_data,
|
||||
#if (GTK_MINOR_VERSION > 0)
|
||||
guint32 WXUNUSED(time),
|
||||
#endif
|
||||
wxClipboard *clipboard )
|
||||
{
|
||||
if ( wxTheClipboard && selection_data->length > 0 )
|
||||
{
|
||||
/* make sure we got the data in the correct form */
|
||||
// make sure we got the data in the correct form
|
||||
GdkAtom type = selection_data->type;
|
||||
if ( type != GDK_SELECTION_TYPE_ATOM )
|
||||
{
|
||||
@@ -113,6 +111,10 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
wxT("selection received for targets, format %s"),
|
||||
format.GetId().c_str() );
|
||||
|
||||
// printf( "format %s requested %s\n",
|
||||
// gdk_atom_name( atoms[i] ),
|
||||
// gdk_atom_name( clipboard->m_targetRequested ) );
|
||||
|
||||
if (format == clipboard->m_targetRequested)
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
@@ -132,9 +134,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
static void
|
||||
selection_received( GtkWidget *WXUNUSED(widget),
|
||||
GtkSelectionData *selection_data,
|
||||
#if (GTK_MINOR_VERSION > 0)
|
||||
guint32 WXUNUSED(time),
|
||||
#endif
|
||||
wxClipboard *clipboard )
|
||||
{
|
||||
if (!wxTheClipboard)
|
||||
@@ -159,7 +159,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
wxDataFormat format( selection_data->target );
|
||||
|
||||
/* make sure we got the data in the correct format */
|
||||
// make sure we got the data in the correct format
|
||||
if (!data_object->IsSupportedFormat( format ) )
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
@@ -248,23 +248,9 @@ selection_handler( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
void *d = malloc(size);
|
||||
|
||||
// Text data will be in UTF8 in Unicode mode.
|
||||
data->GetDataHere( selection_data->target, d );
|
||||
|
||||
// transform Unicode text into multibyte before putting it on clipboard
|
||||
#if wxUSE_UNICODE
|
||||
if ( format.GetType() == wxDF_TEXT )
|
||||
{
|
||||
const wchar_t *wstr = (const wchar_t *)d;
|
||||
size_t len = wxConvCurrent->WC2MB(NULL, wstr, 0);
|
||||
char *str = (char*) malloc(len + 1);
|
||||
wxConvCurrent->WC2MB(str, wstr, len);
|
||||
str[len] = '\0';
|
||||
|
||||
free(d);
|
||||
d = str;
|
||||
}
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
@@ -341,8 +327,8 @@ void wxClipboard::Clear()
|
||||
/* disable GUI threads */
|
||||
#endif
|
||||
|
||||
/* As we have data we also own the clipboard. Once we no longer own
|
||||
it, clear_selection is called which will set m_data to zero */
|
||||
// As we have data we also own the clipboard. Once we no longer own
|
||||
// it, clear_selection is called which will set m_data to zero
|
||||
if (gdk_selection_owner_get( g_clipboardAtom ) == m_clipboardWidget->window)
|
||||
{
|
||||
m_waiting = TRUE;
|
||||
@@ -404,16 +390,16 @@ bool wxClipboard::AddData( wxDataObject *data )
|
||||
|
||||
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
|
||||
|
||||
/* we can only store one wxDataObject */
|
||||
// we can only store one wxDataObject
|
||||
Clear();
|
||||
|
||||
m_data = data;
|
||||
|
||||
/* get formats from wxDataObjects */
|
||||
// get formats from wxDataObjects
|
||||
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
|
||||
m_data->GetAllFormats( array );
|
||||
|
||||
/* primary selection or clipboard */
|
||||
// primary selection or clipboard
|
||||
GdkAtom clipboard = m_usePrimary ? (GdkAtom)GDK_SELECTION_PRIMARY
|
||||
: g_clipboardAtom;
|
||||
|
||||
@@ -424,6 +410,9 @@ bool wxClipboard::AddData( wxDataObject *data )
|
||||
wxT("wxClipboard now supports atom %s"),
|
||||
array[i].GetId().c_str() );
|
||||
|
||||
// printf( "added %s\n",
|
||||
// gdk_atom_name( array[i].GetFormatId() ) );
|
||||
|
||||
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
|
||||
clipboard,
|
||||
array[i],
|
||||
|
@@ -72,6 +72,10 @@ wxDataFormat::wxDataFormat( NativeFormat format )
|
||||
void wxDataFormat::SetType( wxDataFormatId type )
|
||||
{
|
||||
PrepareFormats();
|
||||
|
||||
if (type == wxDF_UNICODETEXT)
|
||||
type = wxDF_TEXT;
|
||||
|
||||
m_type = type;
|
||||
|
||||
if (m_type == wxDF_TEXT)
|
||||
@@ -135,7 +139,7 @@ void wxDataFormat::PrepareFormats()
|
||||
// here (with whom?)
|
||||
if (!g_textAtom)
|
||||
#if wxUSE_UNICODE
|
||||
g_textAtom = gdk_atom_intern( "text/utf8", FALSE );
|
||||
g_textAtom = gdk_atom_intern( "UTF8_STRING", FALSE );
|
||||
#else
|
||||
g_textAtom = gdk_atom_intern( "STRING" /* "text/plain" */, FALSE );
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user