New wxDataObject etc. Almost works.
A few more compatibility funcs for (long*) vs (int*). Makefile.in regenerated from filelist... git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4058 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -100,7 +100,8 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
|
||||
{
|
||||
/* char *name = gdk_atom_name (atoms[i]);
|
||||
/*
|
||||
char *name = gdk_atom_name (atoms[i]);
|
||||
if (name) printf( "Format available: %s.\n", name ); */
|
||||
|
||||
if (atoms[i] == clipboard->m_targetRequested)
|
||||
@@ -134,7 +135,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
}
|
||||
|
||||
wxDataObject *data_object = clipboard->m_receivedData;
|
||||
|
||||
|
||||
if (!data_object)
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
@@ -148,7 +149,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
}
|
||||
|
||||
/* make sure we got the data in the correct format */
|
||||
if (data_object->GetFormat().GetAtom() != selection_data->target)
|
||||
if (data_object->GetFormat() != selection_data->target)
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
return;
|
||||
@@ -186,7 +187,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
|
||||
|
||||
bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length );
|
||||
bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length );
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -245,10 +246,10 @@ selection_clear_clip( GtkWidget *WXUNUSED(widget), GdkEventSelection *event )
|
||||
(!wxTheClipboard->m_ownsClipboard))
|
||||
{
|
||||
/* the clipboard is no longer in our hands. we can the delete clipboard data. */
|
||||
if (wxTheClipboard->m_dataBroker)
|
||||
if (wxTheClipboard->m_data)
|
||||
{
|
||||
delete wxTheClipboard->m_dataBroker;
|
||||
wxTheClipboard->m_dataBroker = (wxDataBroker*) NULL;
|
||||
delete wxTheClipboard->m_data;
|
||||
wxTheClipboard->m_data = (wxDataObject*) NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,82 +266,64 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
||||
{
|
||||
if (!wxTheClipboard) return;
|
||||
|
||||
if (!wxTheClipboard->m_dataBroker) return;
|
||||
if (!wxTheClipboard->m_data) return;
|
||||
|
||||
wxNode *node = wxTheClipboard->m_dataBroker->m_dataObjects.First();
|
||||
wxDataObject *data = wxTheClipboard->m_data;
|
||||
|
||||
while (node)
|
||||
if (!data->IsSupportedFormat( selection_data->target )) return;
|
||||
|
||||
if (data->GetFormat().GetType() == wxDF_TEXT)
|
||||
{
|
||||
wxDataObject *data_object = (wxDataObject *)node->Data();
|
||||
|
||||
if (data_object->GetFormat().GetAtom() != selection_data->target)
|
||||
{
|
||||
node = node->Next();
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (data_object->GetFormat().GetType())
|
||||
{
|
||||
case wxDF_TEXT:
|
||||
{
|
||||
wxTextDataObject *text_object = (wxTextDataObject*) data_object;
|
||||
|
||||
wxString text = text_object->GetText();
|
||||
|
||||
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
||||
wxString text( text_object->GetText() );
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
const wxWX2MBbuf s = text.mbc_str();
|
||||
int len = strlen(s);
|
||||
const wxWX2MBbuf s = text.mbc_str();
|
||||
int len = strlen(s);
|
||||
#else // more efficient in non-Unicode
|
||||
const char *s = text.c_str();
|
||||
int len = (int) text.Length();
|
||||
const char *s = text.c_str();
|
||||
int len = (int) text.Length();
|
||||
#endif
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
8*sizeof(gchar),
|
||||
(unsigned char*) (const char*) s,
|
||||
len );
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
8*sizeof(gchar),
|
||||
(unsigned char*) (const char*) s,
|
||||
len );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case wxDF_BITMAP:
|
||||
{
|
||||
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object;
|
||||
|
||||
if (bitmap_object->GetSize() == 0) return;
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
8*sizeof(gchar),
|
||||
(unsigned char*) bitmap_object->GetData(),
|
||||
(int) bitmap_object->GetSize() );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case wxDF_PRIVATE:
|
||||
{
|
||||
wxPrivateDataObject *private_object = (wxPrivateDataObject*) data_object;
|
||||
|
||||
if (private_object->GetSize() == 0) return;
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
8*sizeof(gchar),
|
||||
(unsigned char*) private_object->GetData(),
|
||||
(int) private_object->GetSize() );
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
return;
|
||||
}
|
||||
|
||||
if (data->GetFormat().GetType() == wxDF_BITMAP)
|
||||
{
|
||||
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
|
||||
|
||||
if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return;
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
8*sizeof(gchar),
|
||||
(unsigned char*) bitmap_object->GetData(),
|
||||
(int) bitmap_object->GetDataSize(wxDF_BITMAP) );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int size = data->GetDataSize( selection_data->target );
|
||||
|
||||
if (size == 0) return;
|
||||
|
||||
char *d = new char[size];
|
||||
|
||||
data->GetDataHere( selection_data->target, (void*) d );
|
||||
|
||||
gtk_selection_data_set(
|
||||
selection_data,
|
||||
GDK_SELECTION_TYPE_STRING,
|
||||
8*sizeof(gchar),
|
||||
(unsigned char*) d,
|
||||
size );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -356,8 +339,7 @@ wxClipboard::wxClipboard()
|
||||
m_ownsClipboard = FALSE;
|
||||
m_ownsPrimarySelection = FALSE;
|
||||
|
||||
m_dataBroker = (wxDataBroker*) NULL;
|
||||
|
||||
m_data = (wxDataObject*) NULL;
|
||||
m_receivedData = (wxDataObject*) NULL;
|
||||
|
||||
/* we use m_targetsWidget to query what formats are available */
|
||||
@@ -404,8 +386,8 @@ wxClipboard::~wxClipboard()
|
||||
|
||||
void wxClipboard::Clear()
|
||||
{
|
||||
if (m_dataBroker)
|
||||
{
|
||||
if (m_data)
|
||||
{
|
||||
#if wxUSE_THREADS
|
||||
/* disable GUI threads */
|
||||
wxapp_uninstall_thread_wakeup();
|
||||
@@ -431,10 +413,10 @@ void wxClipboard::Clear()
|
||||
while (m_waiting) gtk_main_iteration();
|
||||
}
|
||||
|
||||
if (m_dataBroker)
|
||||
{
|
||||
delete m_dataBroker;
|
||||
m_dataBroker = (wxDataBroker*) NULL;
|
||||
if (m_data)
|
||||
{
|
||||
delete m_data;
|
||||
m_data = (wxDataObject*) NULL;
|
||||
}
|
||||
|
||||
#if wxUSE_THREADS
|
||||
@@ -444,7 +426,6 @@ void wxClipboard::Clear()
|
||||
}
|
||||
|
||||
m_targetRequested = 0;
|
||||
|
||||
m_formatSupported = FALSE;
|
||||
}
|
||||
|
||||
@@ -474,14 +455,13 @@ bool wxClipboard::AddData( wxDataObject *data )
|
||||
|
||||
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
|
||||
|
||||
/* if clipboard has been cleared before, create new data broker */
|
||||
if (!m_dataBroker) m_dataBroker = new wxDataBroker();
|
||||
// we can only store one wxDataObject
|
||||
Clear();
|
||||
|
||||
/* add new data to list of offered data objects */
|
||||
m_dataBroker->Add( data );
|
||||
|
||||
m_data = data;
|
||||
|
||||
/* get native format id of new data object */
|
||||
GdkAtom format = data->GetFormat().GetAtom();
|
||||
GdkAtom format = data->GetFormat();
|
||||
|
||||
wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
|
||||
|
||||
@@ -570,11 +550,9 @@ void wxClipboard::Close()
|
||||
|
||||
bool wxClipboard::IsSupported( wxDataFormat format )
|
||||
{
|
||||
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
|
||||
|
||||
/* store requested format to be asked for by callbacks */
|
||||
|
||||
m_targetRequested = format.GetAtom();
|
||||
m_targetRequested = format;
|
||||
|
||||
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
|
||||
|
||||
@@ -591,7 +569,7 @@ bool wxClipboard::IsSupported( wxDataFormat format )
|
||||
m_waiting = TRUE;
|
||||
|
||||
gtk_selection_convert( m_targetsWidget,
|
||||
m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
|
||||
m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
|
||||
g_targetsAtom,
|
||||
GDK_CURRENT_TIME );
|
||||
|
||||
@@ -616,7 +594,7 @@ bool wxClipboard::GetData( wxDataObject *data )
|
||||
|
||||
/* store requested format to be asked for by callbacks */
|
||||
|
||||
m_targetRequested = data->GetFormat().GetAtom();
|
||||
m_targetRequested = data->GetFormat();
|
||||
|
||||
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
|
||||
|
||||
@@ -636,7 +614,7 @@ bool wxClipboard::GetData( wxDataObject *data )
|
||||
m_waiting = TRUE;
|
||||
|
||||
gtk_selection_convert( m_clipboardWidget,
|
||||
m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
|
||||
m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
|
||||
m_targetRequested,
|
||||
GDK_CURRENT_TIME );
|
||||
|
||||
|
@@ -26,19 +26,17 @@
|
||||
|
||||
GdkAtom g_textAtom = 0;
|
||||
GdkAtom g_pngAtom = 0;
|
||||
GdkAtom g_fileAtom = 0;
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// wxDataFormat
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS(wxDataFormat, wxObject)
|
||||
|
||||
wxDataFormat::wxDataFormat()
|
||||
{
|
||||
PrepareFormats();
|
||||
m_type = wxDF_INVALID;
|
||||
m_hasAtom = FALSE;
|
||||
m_atom = (GdkAtom) 0;
|
||||
m_format = (GdkAtom) 0;
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( wxDataFormatId type )
|
||||
@@ -59,39 +57,10 @@ wxDataFormat::wxDataFormat( const wxString &id )
|
||||
SetId( id );
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
||||
wxDataFormat::wxDataFormat( NativeFormat format )
|
||||
{
|
||||
PrepareFormats();
|
||||
m_type = format.GetType();
|
||||
m_id = format.GetId();
|
||||
m_hasAtom = TRUE;
|
||||
m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
|
||||
}
|
||||
|
||||
wxDataFormat::wxDataFormat( const GdkAtom atom )
|
||||
{
|
||||
PrepareFormats();
|
||||
m_hasAtom = TRUE;
|
||||
|
||||
m_atom = atom;
|
||||
|
||||
if (m_atom == g_textAtom)
|
||||
{
|
||||
m_type = wxDF_TEXT;
|
||||
} else
|
||||
if (m_atom == GDK_TARGET_BITMAP)
|
||||
{
|
||||
m_type = wxDF_BITMAP;
|
||||
} else
|
||||
{
|
||||
m_type = wxDF_PRIVATE;
|
||||
m_id = gdk_atom_name( m_atom );
|
||||
|
||||
if (m_id == wxT("file:ALL"))
|
||||
{
|
||||
m_type = wxDF_FILENAME;
|
||||
}
|
||||
}
|
||||
SetId( format );
|
||||
}
|
||||
|
||||
void wxDataFormat::SetType( wxDataFormatId type )
|
||||
@@ -99,25 +68,17 @@ void wxDataFormat::SetType( wxDataFormatId type )
|
||||
m_type = type;
|
||||
|
||||
if (m_type == wxDF_TEXT)
|
||||
{
|
||||
m_id = wxT("STRING");
|
||||
}
|
||||
m_format = g_textAtom;
|
||||
else
|
||||
if (m_type == wxDF_BITMAP)
|
||||
{
|
||||
m_id = wxT("image/png");
|
||||
}
|
||||
m_format = g_pngAtom;
|
||||
else
|
||||
if (m_type == wxDF_FILENAME)
|
||||
{
|
||||
m_id = wxT("file:ALL");
|
||||
}
|
||||
m_format = g_fileAtom;
|
||||
else
|
||||
{
|
||||
wxFAIL_MSG( wxT("invalid dataformat") );
|
||||
}
|
||||
|
||||
m_hasAtom = FALSE;
|
||||
}
|
||||
|
||||
wxDataFormatId wxDataFormat::GetType() const
|
||||
@@ -127,152 +88,41 @@ wxDataFormatId wxDataFormat::GetType() const
|
||||
|
||||
wxString wxDataFormat::GetId() const
|
||||
{
|
||||
return m_id;
|
||||
wxString ret( gdk_atom_name( m_format ) ); // this will convert from ascii to Unicode
|
||||
return ret;
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId( NativeFormat format )
|
||||
{
|
||||
m_format = format;
|
||||
|
||||
if (m_format == g_textAtom)
|
||||
m_type = wxDF_TEXT;
|
||||
else
|
||||
if (m_format == g_pngAtom)
|
||||
m_type = wxDF_BITMAP;
|
||||
else
|
||||
if (m_format == g_fileAtom)
|
||||
m_type = wxDF_FILENAME;
|
||||
else
|
||||
m_type = wxDF_PRIVATE;
|
||||
}
|
||||
|
||||
void wxDataFormat::SetId( const wxChar *id )
|
||||
{
|
||||
m_type = wxDF_PRIVATE;
|
||||
m_id = id;
|
||||
m_hasAtom = FALSE;
|
||||
}
|
||||
|
||||
GdkAtom wxDataFormat::GetAtom()
|
||||
{
|
||||
if (!m_hasAtom)
|
||||
{
|
||||
m_hasAtom = TRUE;
|
||||
|
||||
if (m_type == wxDF_TEXT)
|
||||
{
|
||||
m_atom = g_textAtom;
|
||||
}
|
||||
else
|
||||
if (m_type == wxDF_BITMAP)
|
||||
{
|
||||
m_atom = GDK_TARGET_BITMAP;
|
||||
}
|
||||
else
|
||||
if (m_type == wxDF_PRIVATE)
|
||||
{
|
||||
m_atom = gdk_atom_intern( wxMBSTRINGCAST m_id.mbc_str(), FALSE );
|
||||
}
|
||||
else
|
||||
if (m_type == wxDF_FILENAME)
|
||||
{
|
||||
m_atom = gdk_atom_intern( "file:ALL", FALSE );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_hasAtom = FALSE;
|
||||
m_atom = (GdkAtom) 0;
|
||||
}
|
||||
}
|
||||
|
||||
return m_atom;
|
||||
wxString tmp( id );
|
||||
m_format = gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
|
||||
}
|
||||
|
||||
void wxDataFormat::PrepareFormats()
|
||||
{
|
||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
||||
if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// wxDataBroker
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS(wxDataBroker,wxObject)
|
||||
|
||||
wxDataBroker::wxDataBroker()
|
||||
{
|
||||
m_dataObjects.DeleteContents(TRUE);
|
||||
m_preferred = 0;
|
||||
}
|
||||
|
||||
void wxDataBroker::Add( wxDataObject *dataObject, bool preferred )
|
||||
{
|
||||
if (preferred) m_preferred = m_dataObjects.GetCount();
|
||||
m_dataObjects.Append( dataObject );
|
||||
}
|
||||
|
||||
size_t wxDataBroker::GetFormatCount() const
|
||||
{
|
||||
return m_dataObjects.GetCount();
|
||||
}
|
||||
|
||||
wxDataFormatId wxDataBroker::GetPreferredFormat() const
|
||||
{
|
||||
wxNode *node = m_dataObjects.Nth( m_preferred );
|
||||
|
||||
wxASSERT( node );
|
||||
|
||||
wxDataObject* data_obj = (wxDataObject*)node->Data();
|
||||
|
||||
return data_obj->GetFormat().GetType();
|
||||
}
|
||||
|
||||
wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const
|
||||
{
|
||||
wxNode *node = m_dataObjects.Nth( nth );
|
||||
|
||||
wxASSERT( node );
|
||||
|
||||
wxDataObject* data_obj = (wxDataObject*)node->Data();
|
||||
|
||||
return data_obj->GetFormat();
|
||||
}
|
||||
|
||||
bool wxDataBroker::IsSupportedFormat( wxDataFormat &format ) const
|
||||
{
|
||||
wxNode *node = m_dataObjects.First();
|
||||
while (node)
|
||||
{
|
||||
wxDataObject *dobj = (wxDataObject*)node->Data();
|
||||
|
||||
if (dobj->GetFormat().GetAtom() == format.GetAtom())
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size_t wxDataBroker::GetSize( wxDataFormat& format ) const
|
||||
{
|
||||
wxNode *node = m_dataObjects.First();
|
||||
while (node)
|
||||
{
|
||||
wxDataObject *dobj = (wxDataObject*)node->Data();
|
||||
|
||||
if (dobj->GetFormat().GetAtom() == format.GetAtom())
|
||||
{
|
||||
return dobj->GetSize();
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wxDataBroker::WriteData( wxDataFormat& format, void *dest ) const
|
||||
{
|
||||
wxNode *node = m_dataObjects.First();
|
||||
while (node)
|
||||
{
|
||||
wxDataObject *dobj = (wxDataObject*)node->Data();
|
||||
|
||||
if (dobj->GetFormat().GetAtom() == format.GetAtom())
|
||||
{
|
||||
dobj->WriteData( dest );
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
if (!g_textAtom)
|
||||
g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
||||
if (!g_pngAtom)
|
||||
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
|
||||
if (!g_fileAtom)
|
||||
g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@@ -289,26 +139,29 @@ wxDataObject::~wxDataObject()
|
||||
{
|
||||
}
|
||||
|
||||
wxDataFormat &wxDataObject::GetFormat()
|
||||
bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
|
||||
{
|
||||
return m_format;
|
||||
size_t nFormatCount = GetFormatCount();
|
||||
if ( nFormatCount == 1 ) {
|
||||
return format == GetPreferredFormat();
|
||||
}
|
||||
else {
|
||||
wxDataFormat *formats = new wxDataFormat[nFormatCount];
|
||||
GetAllFormats(formats);
|
||||
|
||||
size_t n;
|
||||
for ( n = 0; n < nFormatCount; n++ ) {
|
||||
if ( formats[n] == format )
|
||||
break;
|
||||
}
|
||||
|
||||
delete [] formats;
|
||||
|
||||
// found?
|
||||
return n < nFormatCount;
|
||||
}
|
||||
}
|
||||
|
||||
wxDataFormatId wxDataObject::GetFormatType() const
|
||||
{
|
||||
return m_format.GetType();
|
||||
}
|
||||
|
||||
wxString wxDataObject::GetFormatId() const
|
||||
{
|
||||
return m_format.GetId();
|
||||
}
|
||||
|
||||
GdkAtom wxDataObject::GetFormatAtom() const
|
||||
{
|
||||
GdkAtom ret = ((wxDataObject*) this)->m_format.GetAtom();
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxTextDataObject
|
||||
@@ -316,41 +169,30 @@ GdkAtom wxDataObject::GetFormatAtom() const
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
|
||||
|
||||
wxTextDataObject::wxTextDataObject()
|
||||
{
|
||||
m_format.SetType( wxDF_TEXT );
|
||||
wxTextDataObject::wxTextDataObject()
|
||||
{
|
||||
}
|
||||
|
||||
wxTextDataObject::wxTextDataObject( const wxString& data )
|
||||
{
|
||||
m_format.SetType( wxDF_TEXT );
|
||||
|
||||
m_data = data;
|
||||
wxTextDataObject::wxTextDataObject(const wxString& strText)
|
||||
: m_strText(strText)
|
||||
{
|
||||
}
|
||||
|
||||
void wxTextDataObject::SetText( const wxString& data )
|
||||
{
|
||||
m_data = data;
|
||||
size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
|
||||
{
|
||||
return m_strText.Len() + 1; // +1 for trailing '\0'of course
|
||||
}
|
||||
|
||||
wxString wxTextDataObject::GetText() const
|
||||
{
|
||||
return m_data;
|
||||
bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
|
||||
{
|
||||
memcpy(buf, m_strText.c_str(), GetDataSize(format));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxTextDataObject::WriteData( void *dest ) const
|
||||
{
|
||||
WriteString( m_data, dest );
|
||||
}
|
||||
|
||||
size_t wxTextDataObject::GetSize() const
|
||||
{
|
||||
return m_data.Len() + 1;
|
||||
}
|
||||
|
||||
void wxTextDataObject::WriteString( const wxString &str, void *dest ) const
|
||||
{
|
||||
memcpy( dest, str.mb_str(), str.Len()+1 );
|
||||
bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf)
|
||||
{
|
||||
m_strText = (const wxChar *)buf;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -361,7 +203,6 @@ IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
|
||||
|
||||
wxFileDataObject::wxFileDataObject()
|
||||
{
|
||||
m_format.SetType( wxDF_FILENAME );
|
||||
}
|
||||
|
||||
void wxFileDataObject::AddFile( const wxString &file )
|
||||
@@ -375,16 +216,34 @@ wxString wxFileDataObject::GetFiles() const
|
||||
return m_files;
|
||||
}
|
||||
|
||||
void wxFileDataObject::WriteData( void *dest ) const
|
||||
bool wxFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
|
||||
{
|
||||
memcpy( dest, m_files.mbc_str(), GetSize() );
|
||||
if (format == wxDF_FILENAME)
|
||||
{
|
||||
memcpy( buf, m_files.mbc_str(), m_files.Len() + 1 );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
size_t wxFileDataObject::GetSize() const
|
||||
size_t wxFileDataObject::GetDataSize(const wxDataFormat& format) const
|
||||
{
|
||||
if (format != wxDF_FILENAME) return 0;
|
||||
|
||||
return m_files.Len() + 1;
|
||||
}
|
||||
|
||||
bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf)
|
||||
{
|
||||
if (format != wxDF_FILENAME)
|
||||
return FALSE;
|
||||
|
||||
m_files = (char*)(buf); // this is so ugly, I cannot look at it
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -393,15 +252,13 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject()
|
||||
{
|
||||
m_format.SetType( wxDF_BITMAP );
|
||||
m_pngData = (char*)NULL;
|
||||
m_pngData = (void*)NULL;
|
||||
m_pngSize = 0;
|
||||
}
|
||||
|
||||
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
|
||||
{
|
||||
m_format.SetType( wxDF_BITMAP );
|
||||
m_pngData = (char*)NULL;
|
||||
m_pngData = (void*)NULL;
|
||||
m_pngSize = 0;
|
||||
m_bitmap = bitmap;
|
||||
DoConvertToPng();
|
||||
@@ -409,45 +266,60 @@ wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
|
||||
|
||||
wxBitmapDataObject::~wxBitmapDataObject()
|
||||
{
|
||||
if (m_pngData) delete[] m_pngData;
|
||||
if (m_pngData)
|
||||
delete[] m_pngData;
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
|
||||
{
|
||||
if (m_pngData)
|
||||
delete[] m_pngData;
|
||||
m_pngData = (void*)NULL;
|
||||
m_pngSize = 0;
|
||||
|
||||
m_bitmap = bitmap;
|
||||
DoConvertToPng();
|
||||
}
|
||||
|
||||
wxBitmap wxBitmapDataObject::GetBitmap() const
|
||||
{
|
||||
return m_bitmap;
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::WriteData( void *dest ) const
|
||||
{
|
||||
WriteBitmap( m_bitmap, dest );
|
||||
}
|
||||
|
||||
size_t wxBitmapDataObject::GetSize() const
|
||||
size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
|
||||
{
|
||||
if (format != wxDF_BITMAP) return 0;
|
||||
|
||||
return m_pngSize;
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::WriteBitmap( const wxBitmap &WXUNUSED(bitmap), void *dest ) const
|
||||
bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
|
||||
{
|
||||
// if (m_bitmap == bitmap)
|
||||
memcpy( dest, m_pngData, m_pngSize );
|
||||
if (format != wxDF_BITMAP) return FALSE;
|
||||
|
||||
if (m_pngSize > 0)
|
||||
{
|
||||
memcpy(buf, m_pngData, m_pngSize);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
|
||||
bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf)
|
||||
{
|
||||
if (m_pngData) delete[] m_pngData;
|
||||
m_pngData = (char*) NULL;
|
||||
m_pngSize = pngSize;
|
||||
m_pngData = new char[m_pngSize];
|
||||
memcpy( m_pngData, pngData, m_pngSize );
|
||||
m_pngData = (void*) NULL;
|
||||
m_pngSize = 0;
|
||||
m_bitmap = wxNullBitmap;
|
||||
|
||||
wxMemoryInputStream mstream( pngData, pngSize );
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::SetPngData(const void *buf, size_t size)
|
||||
{
|
||||
if (m_pngData) delete[] m_pngData;
|
||||
m_pngSize = size;
|
||||
m_pngData = (void*) new char[m_pngSize];
|
||||
|
||||
memcpy( m_pngData, buf, m_pngSize );
|
||||
|
||||
wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize );
|
||||
wxImage image;
|
||||
wxPNGHandler handler;
|
||||
handler.LoadFile( &image, mstream );
|
||||
@@ -456,7 +328,7 @@ void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
|
||||
|
||||
void wxBitmapDataObject::DoConvertToPng()
|
||||
{
|
||||
if (m_pngData) delete[] m_pngData;
|
||||
if (!m_bitmap.Ok()) return;
|
||||
|
||||
wxImage image( m_bitmap );
|
||||
wxPNGHandler handler;
|
||||
@@ -464,9 +336,9 @@ void wxBitmapDataObject::DoConvertToPng()
|
||||
wxCountingOutputStream count;
|
||||
handler.SaveFile( &image, count );
|
||||
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
|
||||
m_pngData = new char[m_pngSize];
|
||||
m_pngData = (void*) new char[m_pngSize];
|
||||
|
||||
wxMemoryOutputStream mstream( m_pngData, m_pngSize );
|
||||
wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize );
|
||||
handler.SaveFile( &image, mstream );
|
||||
}
|
||||
|
||||
@@ -474,7 +346,7 @@ void wxBitmapDataObject::DoConvertToPng()
|
||||
// wxPrivateDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
|
||||
IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
|
||||
|
||||
void wxPrivateDataObject::Free()
|
||||
{
|
||||
|
124
src/gtk1/dnd.cpp
124
src/gtk1/dnd.cpp
@@ -380,7 +380,7 @@ bool wxDropTarget::RequestData( wxDataFormat format )
|
||||
/* this should trigger an "drag_data_received" event */
|
||||
gtk_drag_get_data( m_dragWidget,
|
||||
m_dragContext,
|
||||
format.GetAtom(),
|
||||
format,
|
||||
m_dragTime );
|
||||
|
||||
#if wxUSE_THREADS
|
||||
@@ -403,7 +403,7 @@ bool wxDropTarget::IsSupported( wxDataFormat format )
|
||||
// char *name = gdk_atom_name( formatAtom );
|
||||
// if (name) printf( "Format available: %s.\n", name );
|
||||
|
||||
if (formatAtom == format.GetAtom()) return TRUE;
|
||||
if (formatAtom == format) return TRUE;
|
||||
child = child->next;
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ bool wxDropTarget::GetData( wxDataObject *data_object )
|
||||
{
|
||||
if (!m_dragData) return FALSE;
|
||||
|
||||
if (m_dragData->target != data_object->GetFormat().GetAtom()) return FALSE;
|
||||
if (m_dragData->target != data_object->GetFormat()) return FALSE;
|
||||
|
||||
if (data_object->GetFormat().GetType() == wxDF_TEXT)
|
||||
{
|
||||
@@ -521,6 +521,7 @@ bool wxTextDropTarget::OnData( long x, long y )
|
||||
// wxPrivateDropTarget
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
wxPrivateDropTarget::wxPrivateDropTarget()
|
||||
{
|
||||
m_id = wxTheApp->GetAppName();
|
||||
@@ -558,6 +559,7 @@ bool wxPrivateDropTarget::OnData( long x, long y )
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
*/
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// A drop target which accepts files (dragged from File Manager or Explorer)
|
||||
@@ -584,7 +586,7 @@ bool wxFileDropTarget::OnData( long x, long y )
|
||||
wxFileDataObject data;
|
||||
if (!GetData( &data )) return FALSE;
|
||||
|
||||
/* get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 */
|
||||
// get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0
|
||||
size_t number = 0;
|
||||
size_t i;
|
||||
size_t size = data.GetFiles().Length();
|
||||
@@ -630,51 +632,51 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
|
||||
// char *name = gdk_atom_name( selection_data->target );
|
||||
// if (name) printf( "Format requested: %s.\n", name );
|
||||
|
||||
wxNode *node = drop_source->m_data->m_dataObjects.First();
|
||||
while (node)
|
||||
drop_source->m_retValue = wxDragCancel;
|
||||
|
||||
wxDataObject *data = drop_source->m_data;
|
||||
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
if (!data->IsSupportedFormat(selection_data->target))
|
||||
return;
|
||||
|
||||
if (data->GetDataSize(selection_data->target) == 0)
|
||||
return;
|
||||
|
||||
size_t size = data->GetDataSize(selection_data->target);
|
||||
|
||||
// printf( "data size: %d.\n", (int)data_size );
|
||||
|
||||
guchar *d = new guchar[size];
|
||||
|
||||
if (!data->GetDataHere( selection_data->target, (void*)d ))
|
||||
{
|
||||
wxDataObject *data_object = (wxDataObject*) node->Data();
|
||||
if (data_object->GetFormat().GetAtom() == selection_data->target)
|
||||
{
|
||||
// printf( "format found.\n" );
|
||||
|
||||
size_t data_size = data_object->GetSize();
|
||||
|
||||
if (data_size > 0)
|
||||
{
|
||||
// printf( "data size: %d.\n", (int)data_size );
|
||||
|
||||
guchar *buffer = new guchar[data_size];
|
||||
data_object->WriteData( buffer );
|
||||
free( d );
|
||||
return;
|
||||
}
|
||||
|
||||
#if wxUSE_THREADS
|
||||
/* disable GUI threads */
|
||||
wxapp_uninstall_thread_wakeup();
|
||||
/* disable GUI threads */
|
||||
wxapp_uninstall_thread_wakeup();
|
||||
#endif
|
||||
|
||||
gtk_selection_data_set( selection_data,
|
||||
selection_data->target,
|
||||
8, // 8-bit
|
||||
buffer,
|
||||
data_size );
|
||||
d,
|
||||
size );
|
||||
|
||||
#if wxUSE_THREADS
|
||||
/* enable GUI threads */
|
||||
wxapp_install_thread_wakeup();
|
||||
/* enable GUI threads */
|
||||
wxapp_install_thread_wakeup();
|
||||
#endif
|
||||
free( buffer );
|
||||
|
||||
/* so far only copy, no moves. TODO. */
|
||||
drop_source->m_retValue = wxDragCopy;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
drop_source->m_retValue = wxDragCancel;
|
||||
free( d );
|
||||
|
||||
/* so far only copy, no moves. TODO. */
|
||||
drop_source->m_retValue = wxDragCopy;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -733,7 +735,7 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
|
||||
m_widget = win->m_widget;
|
||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||
|
||||
m_data = (wxDataBroker*) NULL;
|
||||
m_data = (wxDataObject*) NULL;
|
||||
m_retValue = wxDragCancel;
|
||||
|
||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||
@@ -755,8 +757,7 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
|
||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||
m_retValue = wxDragCancel;
|
||||
|
||||
m_data = new wxDataBroker;
|
||||
m_data->Add(&data);
|
||||
m_data = &data;
|
||||
|
||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
||||
@@ -767,53 +768,18 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
|
||||
if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
|
||||
}
|
||||
|
||||
wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win )
|
||||
{
|
||||
m_window = win;
|
||||
m_widget = win->m_widget;
|
||||
if (win->m_wxwindow) m_widget = win->m_wxwindow;
|
||||
m_retValue = wxDragCancel;
|
||||
|
||||
m_data = data;
|
||||
|
||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
|
||||
}
|
||||
|
||||
void wxDropSource::SetData( wxDataObject& data )
|
||||
{
|
||||
if ( m_data )
|
||||
if (m_data)
|
||||
delete m_data;
|
||||
|
||||
m_data = new wxDataBroker;
|
||||
m_data->Add(&data);
|
||||
}
|
||||
|
||||
void wxDropSource::SetData( wxDataObject *data )
|
||||
{
|
||||
if (m_data) delete m_data;
|
||||
|
||||
if (data)
|
||||
{
|
||||
m_data = new wxDataBroker();
|
||||
m_data->Add( data );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_data = (wxDataBroker*) NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void wxDropSource::SetData( wxDataBroker *data )
|
||||
{
|
||||
if (m_data) delete m_data;
|
||||
|
||||
m_data = data;
|
||||
m_data = &data;
|
||||
}
|
||||
|
||||
wxDropSource::~wxDropSource()
|
||||
{
|
||||
if (m_data) delete m_data;
|
||||
if (m_data)
|
||||
// delete m_data;
|
||||
|
||||
g_blockEventsOnDrag = FALSE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user