From d613be55db6d1100cf38e3c9f666f7ced4db6b65 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 1 Mar 2008 17:22:31 +0000 Subject: [PATCH] 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 --- include/wx/dataobj.h | 13 ++++++----- include/wx/gtk/dataobj2.h | 21 +++++++++++++++++ src/gtk/dataobj.cpp | 49 +++++++++++++++++++++++++++++++++++++++ src/gtk/dnd.cpp | 41 +++++++++++++++++++------------- 4 files changed, 102 insertions(+), 22 deletions(-) diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index b860e208ec..04fbee454f 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -502,12 +502,13 @@ private: #if defined(__WXMSW__) #include "wx/msw/ole/dataobj2.h" - // wxURLDataObject defined in msw/ole/dataobj2.h -#else // !__WXMSW__ - #if defined(__WXGTK20__) - #include "wx/gtk/dataobj2.h" - #elif defined(__WXGTK__) +#elif defined(__WXGTK20__) + #include "wx/gtk/dataobj2.h" + // wxURLDataObject defined in msw/ole/dataobj2.h + +#else + #if defined(__WXGTK__) #include "wx/gtk1/dataobj2.h" #elif defined(__WXX11__) #include "wx/x11/dataobj2.h" @@ -533,7 +534,7 @@ private: wxString GetURL() const { return GetText(); } void SetURL(const wxString& url) { SetText(url); } }; -#endif // __WXMSW__/!__WXMSW__ +#endif #endif // wxUSE_DATAOBJ diff --git a/include/wx/gtk/dataobj2.h b/include/wx/gtk/dataobj2.h index 50f177cf65..250305b177 100644 --- a/include/wx/gtk/dataobj2.h +++ b/include/wx/gtk/dataobj2.h @@ -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_ diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index 6ea3dc4f2f..0791e6e092 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -402,4 +402,53 @@ void wxBitmapDataObject::DoConvertToPng() 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 diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index 431141ef46..2c54f0805d 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -196,6 +196,16 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), return FALSE, otherwise call gtk_drag_status() and 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. this is only valid for the duration of this call */ drop_target->SetDragContext( context ); @@ -208,27 +218,28 @@ static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), if (drop_target->GetDefaultAction() == wxDragNone) { // 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 ) ) - { - // 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 - result = wxDragCopy; + // 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 + result = wxDragCopy; + } } - } } else if (drop_target->GetDefaultAction() == wxDragMove && (context->actions & GDK_ACTION_MOVE)) { + result = wxDragMove; } else @@ -293,8 +304,6 @@ static gboolean target_drag_drop( GtkWidget *widget, the drop, call gtk_drag_finish() with success == FALSE otherwise call gtk_drag_data_get()" */ -// printf( "drop.\n" ); - /* this seems to make a difference between not accepting due to wrong target area and due to wrong format. let us hope that this is not required.. */ -- 2.45.2