// 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);
#ifdef __UNIX__
// the temp file should have the same permissions as the original one
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;
}
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"));
}
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;
}
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
}
else // mkstemp() succeeded
{
- path = wxConvFile.cMB2WX(buf);
-
+ path = wxConvFile.cMB2WX( (const char*) buf );
+
// avoid leaking the fd
if ( 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
virtual void OnExit()
{
#if wxUSE_WCHAR_T
- wxConvLocal.Clear();
+ wxConvLocal.Clear();
#endif
}
{
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
{
for (size_t i = 0; i < wxStrlen( psz )+1; i++)
buf[i] = (char) psz[i];
- // printf( "libc %s\n", buf );
return wxStrlen( psz );
}
else
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
cset = NULL;
}
-#if defined(__WIN32__) && !defined(__WXMICROWIN__)
- cset = new CP_CharSet(name);
+#if wxUSE_FONTMAP
+ cset = new EC_CharSet(name);
if ( cset->usable() )
return cset;
delete cset;
cset = NULL;
-#endif // __WIN32__
+#endif // wxUSE_FONTMAP
-#if wxUSE_FONTMAP
- cset = new EC_CharSet(name);
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+ cset = new CP_CharSet(name);
if ( cset->usable() )
return cset;
delete cset;
cset = NULL;
-#endif // wxUSE_FONTMAP
+#endif // __WIN32__
wxLogError(_("Cannot convert from encoding '%s'!"), name);
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 )
{
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;
static void
selection_received( GtkWidget *WXUNUSED(widget),
GtkSelectionData *selection_data,
-#if (GTK_MINOR_VERSION > 0)
guint32 WXUNUSED(time),
-#endif
wxClipboard *clipboard )
{
if (!wxTheClipboard)
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;
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,
/* 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;
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;
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],
void wxDataFormat::SetType( wxDataFormatId type )
{
PrepareFormats();
- m_type = type;
+
+ if (type == wxDF_UNICODETEXT)
+ type = wxDF_TEXT;
+ m_type = type;
+
if (m_type == wxDF_TEXT)
m_format = g_textAtom;
else
// 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
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 )
{
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;
static void
selection_received( GtkWidget *WXUNUSED(widget),
GtkSelectionData *selection_data,
-#if (GTK_MINOR_VERSION > 0)
guint32 WXUNUSED(time),
-#endif
wxClipboard *clipboard )
{
if (!wxTheClipboard)
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;
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,
/* 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;
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;
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],
void wxDataFormat::SetType( wxDataFormatId type )
{
PrepareFormats();
- m_type = type;
+
+ if (type == wxDF_UNICODETEXT)
+ type = wxDF_TEXT;
+ m_type = type;
+
if (m_type == wxDF_TEXT)
m_format = g_textAtom;
else
// 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