Made wxGTK compile and link again. Broke wxMSW a little.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4098 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "wx/dataobj.h"
|
||||
#include "wx/utils.h"
|
||||
#include "wx/log.h"
|
||||
|
||||
#include "glib.h"
|
||||
#include "gdk/gdk.h"
|
||||
@@ -148,9 +149,11 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
clipboard->m_waiting = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
wxDataFormat format( selection_data->target );
|
||||
|
||||
/* make sure we got the data in the correct format */
|
||||
if (data_object->GetFormat() != selection_data->target)
|
||||
if (!data_object->IsSupportedFormat( format ) )
|
||||
{
|
||||
clipboard->m_waiting = FALSE;
|
||||
return;
|
||||
@@ -159,7 +162,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
/* make sure we got the data in the correct form (selection type).
|
||||
if so, copy data to target object */
|
||||
|
||||
switch (data_object->GetFormat().GetType())
|
||||
switch (format.GetType())
|
||||
{
|
||||
case wxDF_TEXT:
|
||||
{
|
||||
@@ -188,7 +191,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
|
||||
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
|
||||
|
||||
bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length );
|
||||
bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data );
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -201,9 +204,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
||||
return;
|
||||
}
|
||||
|
||||
wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object;
|
||||
|
||||
private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length );
|
||||
data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data );
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -271,9 +272,11 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
||||
|
||||
wxDataObject *data = wxTheClipboard->m_data;
|
||||
|
||||
if (!data->IsSupportedFormat( selection_data->target )) return;
|
||||
wxDataFormat format( selection_data->target );
|
||||
|
||||
if (!data->IsSupportedFormat( format )) return;
|
||||
|
||||
if (data->GetFormat().GetType() == wxDF_TEXT)
|
||||
if (format.GetType() == wxDF_TEXT)
|
||||
{
|
||||
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
||||
wxString text( text_object->GetText() );
|
||||
@@ -295,23 +298,23 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
||||
return;
|
||||
}
|
||||
|
||||
if (data->GetFormat().GetType() == wxDF_BITMAP)
|
||||
if (format.GetType() == wxDF_BITMAP)
|
||||
{
|
||||
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
|
||||
|
||||
if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return;
|
||||
if (bitmap_object->GetDataSize() == 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) );
|
||||
(unsigned char*) bitmap_object->GetPngData(),
|
||||
(int) bitmap_object->GetDataSize() );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int size = data->GetDataSize( selection_data->target );
|
||||
int size = data->GetDataSize( format );
|
||||
|
||||
if (size == 0) return;
|
||||
|
||||
@@ -456,54 +459,46 @@ 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 native format id of new data object */
|
||||
GdkAtom format = data->GetFormat();
|
||||
|
||||
wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
|
||||
|
||||
/* This should happen automatically, but to be on the safe side */
|
||||
m_ownsClipboard = FALSE;
|
||||
m_ownsPrimarySelection = FALSE;
|
||||
|
||||
/* Add handlers if someone requests data */
|
||||
/* get formats from wxDataObjects */
|
||||
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
|
||||
m_data->GetAllFormats( array );
|
||||
|
||||
for (size_t i = 0; i < m_data->GetFormatCount(); i++)
|
||||
{
|
||||
GdkAtom atom = array[i];
|
||||
wxLogDebug( wxT("Clipboard Supported atom %s"), gdk_atom_name( atom ) );
|
||||
|
||||
#if (GTK_MINOR_VERSION > 0)
|
||||
|
||||
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
|
||||
/* Add handlers if someone requests data. We currently always
|
||||
offer data to the clipboard and the primary selection. Maybe
|
||||
we should make that depend on the usePrimary flag */
|
||||
|
||||
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
|
||||
GDK_SELECTION_PRIMARY,
|
||||
format,
|
||||
atom,
|
||||
0 ); /* what is info ? */
|
||||
|
||||
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
|
||||
gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget),
|
||||
g_clipboardAtom,
|
||||
format,
|
||||
atom,
|
||||
0 ); /* what is info ? */
|
||||
}
|
||||
|
||||
delete[] array;
|
||||
|
||||
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
|
||||
"selection_get",
|
||||
GTK_SIGNAL_FUNC(selection_handler),
|
||||
(gpointer) NULL );
|
||||
|
||||
#else
|
||||
|
||||
gtk_selection_add_handler( m_clipboardWidget,
|
||||
g_clipboardAtom,
|
||||
format,
|
||||
selection_handler,
|
||||
(gpointer) NULL );
|
||||
|
||||
gtk_selection_add_handler( m_clipboardWidget,
|
||||
GDK_SELECTION_PRIMARY,
|
||||
format,
|
||||
selection_handler,
|
||||
(gpointer) NULL );
|
||||
#endif
|
||||
|
||||
#if wxUSE_THREADS
|
||||
/* disable GUI threads */
|
||||
wxapp_uninstall_thread_wakeup();
|
||||
@@ -585,47 +580,56 @@ bool wxClipboard::GetData( wxDataObject& data )
|
||||
{
|
||||
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
|
||||
|
||||
/* is data supported by clipboard ? */
|
||||
/* get formats from wxDataObjects */
|
||||
wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ];
|
||||
data.GetAllFormats( array );
|
||||
|
||||
if (!IsSupported( data->GetFormat() )) return FALSE;
|
||||
for (size_t i = 0; i < data.GetFormatCount(); i++)
|
||||
{
|
||||
/* is data supported by clipboard ? */
|
||||
if (!IsSupported( array[i] ))
|
||||
continue;
|
||||
|
||||
/* store pointer to data object to be filled up by callbacks */
|
||||
/* store pointer to data object to be filled up by callbacks */
|
||||
m_receivedData = &data;
|
||||
|
||||
m_receivedData = data;
|
||||
|
||||
/* store requested format to be asked for by callbacks */
|
||||
|
||||
m_targetRequested = data->GetFormat();
|
||||
/* store requested format to be asked for by callbacks */
|
||||
m_targetRequested = array[i];
|
||||
|
||||
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
|
||||
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
|
||||
|
||||
/* start query */
|
||||
|
||||
m_formatSupported = FALSE;
|
||||
/* start query */
|
||||
m_formatSupported = FALSE;
|
||||
|
||||
/* ask for clipboard contents. this will set
|
||||
m_formatSupported to TRUE if m_targetRequested
|
||||
is supported.
|
||||
also, we have to wait for the "answer" from the
|
||||
clipboard owner which is an asynchronous process.
|
||||
therefore we set m_waiting = TRUE here and wait
|
||||
until the callback "targets_selection_received"
|
||||
sets it to FALSE */
|
||||
/* ask for clipboard contents. this will set
|
||||
m_formatSupported to TRUE if m_targetRequested
|
||||
is supported.
|
||||
also, we have to wait for the "answer" from the
|
||||
clipboard owner which is an asynchronous process.
|
||||
therefore we set m_waiting = TRUE here and wait
|
||||
until the callback "targets_selection_received"
|
||||
sets it to FALSE */
|
||||
|
||||
m_waiting = TRUE;
|
||||
m_waiting = TRUE;
|
||||
|
||||
gtk_selection_convert( m_clipboardWidget,
|
||||
gtk_selection_convert( m_clipboardWidget,
|
||||
m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
|
||||
m_targetRequested,
|
||||
GDK_CURRENT_TIME );
|
||||
|
||||
while (m_waiting) gtk_main_iteration();
|
||||
while (m_waiting) gtk_main_iteration();
|
||||
|
||||
/* this is a true error as we checked for the presence of such data before */
|
||||
|
||||
wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
|
||||
/* this is a true error as we checked for the presence of such data before */
|
||||
wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") );
|
||||
|
||||
/* return success */
|
||||
delete[] array;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
/* return failure */
|
||||
delete[] array;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -128,25 +128,19 @@ void wxDataFormat::PrepareFormats()
|
||||
// wxDataObject
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
|
||||
|
||||
wxDataObject::wxDataObject()
|
||||
{
|
||||
}
|
||||
|
||||
wxDataObject::~wxDataObject()
|
||||
bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) const
|
||||
{
|
||||
}
|
||||
|
||||
bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
|
||||
{
|
||||
size_t nFormatCount = GetFormatCount();
|
||||
size_t nFormatCount = GetFormatCount(dir);
|
||||
if ( nFormatCount == 1 ) {
|
||||
return format == GetPreferredFormat();
|
||||
}
|
||||
else {
|
||||
wxDataFormat *formats = new wxDataFormat[nFormatCount];
|
||||
GetAllFormats(formats);
|
||||
GetAllFormats(formats,dir);
|
||||
|
||||
size_t n;
|
||||
for ( n = 0; n < nFormatCount; n++ ) {
|
||||
@@ -167,7 +161,14 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
|
||||
|
||||
bool wxFileDataObject::GetDataHere(void *buf) const
|
||||
{
|
||||
const wxString& filenames = GetFilenames();
|
||||
wxString filenames;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
filenames += m_filenames[i];
|
||||
filenames += (wxChar) 0;
|
||||
}
|
||||
|
||||
memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 );
|
||||
|
||||
return TRUE;
|
||||
@@ -175,16 +176,33 @@ bool wxFileDataObject::GetDataHere(void *buf) const
|
||||
|
||||
size_t wxFileDataObject::GetDataSize() const
|
||||
{
|
||||
return GetFilenames().Len() + 1;
|
||||
size_t res = 0;
|
||||
|
||||
for (size_t i = 0; i < m_filenames.GetCount(); i++)
|
||||
{
|
||||
res += m_filenames[i].Len();
|
||||
res += 1;
|
||||
}
|
||||
|
||||
return res + 1;
|
||||
}
|
||||
|
||||
bool wxFileDataObject::SetData(const void *buf)
|
||||
bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf)
|
||||
{
|
||||
SetFilenames((const wxChar *)buf);
|
||||
/* TODO */
|
||||
|
||||
wxString file( (const char *)buf ); /* char, not wxChar */
|
||||
|
||||
AddFile( file );
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void wxFileDataObject::AddFile( const wxString &filename )
|
||||
{
|
||||
m_filenames.Add( filename );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxBitmapDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -248,6 +266,8 @@ bool wxBitmapDataObject::SetData(size_t size, const void *buf)
|
||||
}
|
||||
|
||||
m_bitmap = image.ConvertToBitmap();
|
||||
|
||||
return m_bitmap.Ok();
|
||||
}
|
||||
|
||||
void wxBitmapDataObject::DoConvertToPng()
|
||||
@@ -268,51 +288,4 @@ void wxBitmapDataObject::DoConvertToPng()
|
||||
handler.SaveFile( &image, mstream );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxPrivateDataObject
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
|
||||
|
||||
void wxPrivateDataObject::Free()
|
||||
{
|
||||
if ( m_data )
|
||||
free(m_data);
|
||||
}
|
||||
|
||||
wxPrivateDataObject::wxPrivateDataObject()
|
||||
{
|
||||
wxString id = wxT("application/");
|
||||
id += wxTheApp->GetAppName();
|
||||
|
||||
m_format.SetId( id );
|
||||
|
||||
m_size = 0;
|
||||
m_data = (void *)NULL;
|
||||
}
|
||||
|
||||
void wxPrivateDataObject::SetData( const void *data, size_t size )
|
||||
{
|
||||
Free();
|
||||
|
||||
m_size = size;
|
||||
m_data = malloc(size);
|
||||
|
||||
memcpy( m_data, data, size );
|
||||
}
|
||||
|
||||
void wxPrivateDataObject::WriteData( void *dest ) const
|
||||
{
|
||||
WriteData( m_data, dest );
|
||||
}
|
||||
|
||||
size_t wxPrivateDataObject::GetSize() const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
|
||||
{
|
||||
memcpy( dest, data, GetSize() );
|
||||
}
|
||||
|
||||
|
@@ -349,35 +349,27 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
|
||||
// wxDropTarget
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
wxDropTarget::wxDropTarget( wxDataObject *data )
|
||||
wxDropTarget::wxDropTarget( wxDataObject *data )
|
||||
: wxDropTargetBase( data )
|
||||
{
|
||||
m_firstMotion = TRUE;
|
||||
m_dragContext = (GdkDragContext*) NULL;
|
||||
m_dragWidget = (GtkWidget*) NULL;
|
||||
m_dragData = (GtkSelectionData*) NULL;
|
||||
m_dragTime = 0;
|
||||
m_data = data;
|
||||
}
|
||||
|
||||
wxDropTarget::~wxDropTarget()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
{
|
||||
if (!m_data)
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
|
||||
return (GetMatchingPair() != (GdkAtom) 0);
|
||||
}
|
||||
|
||||
void wxDropTarget::OnLeave()
|
||||
{
|
||||
}
|
||||
|
||||
bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
{
|
||||
if (!m_data)
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
|
||||
return (GetMatchingPair() != (GdkAtom) 0);
|
||||
@@ -385,7 +377,7 @@ bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
|
||||
bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
{
|
||||
if (!m_data)
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
|
||||
return (GetMatchingPair() != (GdkAtom) 0);
|
||||
@@ -393,7 +385,7 @@ bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
|
||||
bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
{
|
||||
if (!m_data)
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
|
||||
if (GetMatchingPair() == (GdkAtom) 0)
|
||||
@@ -404,7 +396,7 @@ bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) )
|
||||
|
||||
GdkAtom wxDropTarget::GetMatchingPair()
|
||||
{
|
||||
if (!m_data)
|
||||
if (!m_dataObject)
|
||||
return (GdkAtom) 0;
|
||||
|
||||
if (!m_dragContext)
|
||||
@@ -420,7 +412,7 @@ GdkAtom wxDropTarget::GetMatchingPair()
|
||||
char *name = gdk_atom_name( formatAtom );
|
||||
if (name) wxLogDebug( "Drop target: drag has format: %s", name );
|
||||
#endif
|
||||
if (m_data->IsSupportedFormat( format ))
|
||||
if (m_dataObject->IsSupportedFormat( format ))
|
||||
return formatAtom;
|
||||
|
||||
child = child->next;
|
||||
@@ -434,25 +426,25 @@ bool wxDropTarget::GetData()
|
||||
if (!m_dragData)
|
||||
return FALSE;
|
||||
|
||||
if (!m_data)
|
||||
if (!m_dataObject)
|
||||
return FALSE;
|
||||
|
||||
wxDataFormat dragFormat( m_dragData->target );
|
||||
|
||||
if (!m_data->IsSupportedFormat( dragFormat ))
|
||||
if (!m_dataObject->IsSupportedFormat( dragFormat ))
|
||||
return FALSE;
|
||||
|
||||
if (dragFormat.GetType() == wxDF_TEXT)
|
||||
{
|
||||
wxTextDataObject *text_object = (wxTextDataObject*)m_data;
|
||||
wxTextDataObject *text_object = (wxTextDataObject*)m_dataObject;
|
||||
text_object->SetText( (const char*)m_dragData->data );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (dragFormat.GetType() == wxDF_FILENAME)
|
||||
{
|
||||
wxFileDataObject *file_object = (wxFileDataObject*)m_data;
|
||||
file_object->SetFiles( (const char*)m_dragData->data );
|
||||
wxFileDataObject *file_object = (wxFileDataObject*)m_dataObject;
|
||||
file_object->SetData( 0, (const char*)m_dragData->data );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -633,7 +625,6 @@ 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 = (wxDataObject*) NULL;
|
||||
m_retValue = wxDragCancel;
|
||||
|
||||
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
|
||||
@@ -649,14 +640,14 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
|
||||
const wxIcon &go, const wxIcon &stop )
|
||||
{
|
||||
m_waiting = TRUE;
|
||||
|
||||
SetData( data );
|
||||
|
||||
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 );
|
||||
|
||||
@@ -666,19 +657,8 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
|
||||
if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
|
||||
}
|
||||
|
||||
void wxDropSource::SetData( wxDataObject& data )
|
||||
{
|
||||
if (m_data)
|
||||
delete m_data;
|
||||
|
||||
m_data = &data;
|
||||
}
|
||||
|
||||
wxDropSource::~wxDropSource()
|
||||
{
|
||||
if (m_data)
|
||||
// delete m_data;
|
||||
|
||||
g_blockEventsOnDrag = FALSE;
|
||||
}
|
||||
|
||||
@@ -701,7 +681,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
||||
GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
|
||||
|
||||
wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ];
|
||||
m_data->GetAllFormats( array, TRUE );
|
||||
m_data->GetAllFormats( array );
|
||||
for (size_t i = 0; i < m_data->GetFormatCount(); i++)
|
||||
{
|
||||
GdkAtom atom = array[i];
|
||||
|
Reference in New Issue
Block a user