Implemented wxURLDataObject for wxGTK using text/x-moz-url

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52219 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2008-03-01 17:22:31 +00:00
parent f4a7ec8231
commit d613be55db
4 changed files with 102 additions and 22 deletions

View File

@@ -502,12 +502,13 @@ private:
#if defined(__WXMSW__) #if defined(__WXMSW__)
#include "wx/msw/ole/dataobj2.h" #include "wx/msw/ole/dataobj2.h"
// wxURLDataObject defined in msw/ole/dataobj2.h // wxURLDataObject defined in msw/ole/dataobj2.h
#else // !__WXMSW__ #elif defined(__WXGTK20__)
#if defined(__WXGTK20__) #include "wx/gtk/dataobj2.h"
#include "wx/gtk/dataobj2.h" // wxURLDataObject defined in msw/ole/dataobj2.h
#elif defined(__WXGTK__)
#else
#if defined(__WXGTK__)
#include "wx/gtk1/dataobj2.h" #include "wx/gtk1/dataobj2.h"
#elif defined(__WXX11__) #elif defined(__WXX11__)
#include "wx/x11/dataobj2.h" #include "wx/x11/dataobj2.h"
@@ -533,7 +534,7 @@ private:
wxString GetURL() const { return GetText(); } wxString GetURL() const { return GetText(); }
void SetURL(const wxString& url) { SetText(url); } void SetURL(const wxString& url) { SetText(url); }
}; };
#endif // __WXMSW__/!__WXMSW__ #endif
#endif // wxUSE_DATAOBJ #endif // wxUSE_DATAOBJ

View File

@@ -89,5 +89,26 @@ public:
} }
}; };
// ----------------------------------------------------------------------------
// wxURLDataObject is a specialization of wxDataObject for URLs
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_CORE wxURLDataObject : public wxDataObjectSimple
{
public:
wxURLDataObject(const wxString& url = wxEmptyString);
wxString GetURL() const { return m_url; }
void SetURL(const wxString& url) { m_url = url; }
private:
wxString m_url;
virtual size_t GetDataSize() const;
virtual bool GetDataHere(void *buf) const;
virtual bool SetData(size_t len, const void *buf);
};
#endif // _WX_GTK_DATAOBJ2_H_ #endif // _WX_GTK_DATAOBJ2_H_

View File

@@ -402,4 +402,53 @@ void wxBitmapDataObject::DoConvertToPng()
image.SaveFile(mstream, wxBITMAP_TYPE_PNG); image.SaveFile(mstream, wxBITMAP_TYPE_PNG);
} }
// ----------------------------------------------------------------------------
// wxURLDataObject
// ----------------------------------------------------------------------------
wxURLDataObject::wxURLDataObject(const wxString& url) :
wxDataObjectSimple( wxDataFormat( gdk_atom_intern("text/x-moz-url",FALSE) ) )
{
m_url = url;
}
size_t wxURLDataObject::GetDataSize() const
{
if (m_url.empty())
return 0;
return 2*m_url.Len()+2;
}
bool wxURLDataObject::GetDataHere(void *buf) const
{
if (m_url.empty())
return false;
wxCSConv conv( "UCS2" );
conv.FromWChar( (char*) buf, 2*m_url.Len()+2, m_url.wc_str() );
return true;
}
// copy data from buffer to our data
bool wxURLDataObject::SetData(size_t len, const void *buf)
{
if (len == 0)
{
m_url = wxEmptyString;
return false;
}
wxCSConv conv( "UCS2" );
wxWCharBuffer res = conv.cMB2WC( (const char*) buf );
m_url = res;
int pos = m_url.Find( '\n' );
if (pos != wxNOT_FOUND)
m_url.Remove( pos, m_url.Len() - pos );
return true;
}
#endif // wxUSE_DATAOBJ #endif // wxUSE_DATAOBJ

View File

@@ -196,6 +196,16 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
return FALSE, otherwise call gtk_drag_status() and return FALSE, otherwise call gtk_drag_status() and
return TRUE" */ return TRUE" */
#if 0
wxPrintf( "motion\n" );
GList *tmp_list;
for (tmp_list = context->targets; tmp_list; tmp_list = tmp_list->next)
{
wxString atom = wxString::FromAscii( gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data)) );
wxPrintf( "Atom: %s\n", atom );
}
#endif
/* inform the wxDropTarget about the current GdkDragContext. /* inform the wxDropTarget about the current GdkDragContext.
this is only valid for the duration of this call */ this is only valid for the duration of this call */
drop_target->SetDragContext( context ); drop_target->SetDragContext( context );
@@ -208,27 +218,28 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget),
if (drop_target->GetDefaultAction() == wxDragNone) if (drop_target->GetDefaultAction() == wxDragNone)
{ {
// use default action set by wxDropSource::DoDragDrop() // use default action set by wxDropSource::DoDragDrop()
if ( (gs_flagsForDrag & wxDrag_DefaultMove) == wxDrag_DefaultMove && if ( (gs_flagsForDrag & wxDrag_DefaultMove) == wxDrag_DefaultMove &&
(context->actions & GDK_ACTION_MOVE ) ) (context->actions & GDK_ACTION_MOVE ) )
{
// move is requested by the program and allowed by GTK+ - do it, even
// though suggested_action may be currently wxDragCopy
result = wxDragMove;
}
else // use whatever GTK+ says we should
{
result = ConvertFromGTK(context->suggested_action);
if ( (result == wxDragMove) && !(gs_flagsForDrag & wxDrag_AllowMove) )
{ {
// we're requested to move but we can't // move is requested by the program and allowed by GTK+ - do it, even
result = wxDragCopy; // though suggested_action may be currently wxDragCopy
result = wxDragMove;
}
else // use whatever GTK+ says we should
{
result = ConvertFromGTK(context->suggested_action);
if ( (result == wxDragMove) && !(gs_flagsForDrag & wxDrag_AllowMove) )
{
// we're requested to move but we can't
result = wxDragCopy;
}
} }
}
} }
else if (drop_target->GetDefaultAction() == wxDragMove && else if (drop_target->GetDefaultAction() == wxDragMove &&
(context->actions & GDK_ACTION_MOVE)) (context->actions & GDK_ACTION_MOVE))
{ {
result = wxDragMove; result = wxDragMove;
} }
else else
@@ -293,8 +304,6 @@ static gboolean target_drag_drop( GtkWidget *widget,
the drop, call gtk_drag_finish() with success == FALSE the drop, call gtk_drag_finish() with success == FALSE
otherwise call gtk_drag_data_get()" */ otherwise call gtk_drag_data_get()" */
// printf( "drop.\n" );
/* this seems to make a difference between not accepting /* this seems to make a difference between not accepting
due to wrong target area and due to wrong format. let due to wrong target area and due to wrong format. let
us hope that this is not required.. */ us hope that this is not required.. */