From a3e7d24d21f5371c88caffe4a85c8e4a5362db3f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 19 Oct 1999 15:12:11 +0000 Subject: [PATCH] Changed two conflicting defines in defs.h DnD multiformat fine-tuning git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4069 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 28 ++++++------ include/wx/gtk/dnd.h | 16 +++++-- include/wx/gtk1/dnd.h | 16 +++++-- samples/dnd/dnd.cpp | 1 + samples/scroll/scroll.cpp | 19 +++++--- src/gtk/dnd.cpp | 94 +++++++++++++++++++-------------------- src/gtk1/dnd.cpp | 94 +++++++++++++++++++-------------------- 7 files changed, 147 insertions(+), 121 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index ed28273f39..fac7781467 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -973,19 +973,19 @@ enum wxStretch /* * wxSpinButton flags */ -#define wxSP_VERTICAL 0x0004 -#define wxSP_HORIZONTAL 0x0008 -#define wxSP_ARROW_KEYS 0x0010 -#define wxSP_WRAP 0x0020 +#define wxSP_HORIZONTAL wxHORIZONTAL // 4 +#define wxSP_VERTICAL wxVERTICAL // 8 +#define wxSP_ARROW_KEYS 0x0010 +#define wxSP_WRAP 0x0020 /* * wxSplitterWindow flags */ -#define wxSP_NOBORDER 0x0000 -#define wxSP_3D 0x0004 -#define wxSP_BORDER 0x0008 -#define wxSP_PERMIT_UNSPLIT 0x0010 -#define wxSP_LIVE_UPDATE 0x0020 +#define wxSP_NOBORDER 0x0000 +#define wxSP_3D 0x0010 +#define wxSP_BORDER 0x0020 +#define wxSP_PERMIT_UNSPLIT 0x0040 +#define wxSP_LIVE_UPDATE 0x0080 /* * wxFrame extra flags @@ -997,14 +997,14 @@ enum wxStretch * wxTabCtrl flags */ #define wxTC_MULTILINE 0x0000 -#define wxTC_RIGHTJUSTIFY 0x0004 -#define wxTC_FIXEDWIDTH 0x0008 -#define wxTC_OWNERDRAW 0x0010 +#define wxTC_RIGHTJUSTIFY 0x0010 +#define wxTC_FIXEDWIDTH 0x0020 +#define wxTC_OWNERDRAW 0x0040 /* * wxNotebook flags */ -#define wxNB_FIXEDWIDTH 0x0008 +#define wxNB_FIXEDWIDTH 0x0010 #define wxNB_LEFT 0x0020 #define wxNB_RIGHT 0x0040 #define wxNB_BOTTOM 0x0080 @@ -1012,7 +1012,7 @@ enum wxStretch /* * wxStatusBar95 flags */ -#define wxST_SIZEGRIP 0x0002 +#define wxST_SIZEGRIP 0x0010 /* * wxStaticLine flags diff --git a/include/wx/gtk/dnd.h b/include/wx/gtk/dnd.h index 225c809209..52a4c8550b 100644 --- a/include/wx/gtk/dnd.h +++ b/include/wx/gtk/dnd.h @@ -79,6 +79,9 @@ public: /* fill data with data from the dragging source */ bool GetData( wxDataObject *data ); + virtual size_t GetFormatCount() const = 0; + virtual wxDataFormat GetFormat(size_t n) const = 0; + // implementation void RegisterWidget( GtkWidget *widget ); @@ -106,13 +109,15 @@ public: wxTextDropTarget() {} - virtual bool OnMove( long x, long y ); - virtual bool OnDrop( long x, long y ); virtual bool OnData( long x, long y ); /* you have to override OnDropData to get at the text */ virtual bool OnDropText( long x, long y, const wxChar *text ) = 0; + virtual size_t GetFormatCount() const + { return 1; } + virtual wxDataFormat GetFormat(size_t n) const + { return wxDF_TEXT; } }; //------------------------------------------------------------------------- @@ -152,11 +157,14 @@ public: wxFileDropTarget() {} - virtual bool OnMove( long x, long y ); - virtual bool OnDrop( long x, long y ); virtual bool OnData( long x, long y ); virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; + + virtual size_t GetFormatCount() const + { return 1; } + virtual wxDataFormat GetFormat(size_t n) const + { return wxDF_FILENAME; } }; //------------------------------------------------------------------------- diff --git a/include/wx/gtk1/dnd.h b/include/wx/gtk1/dnd.h index 225c809209..52a4c8550b 100644 --- a/include/wx/gtk1/dnd.h +++ b/include/wx/gtk1/dnd.h @@ -79,6 +79,9 @@ public: /* fill data with data from the dragging source */ bool GetData( wxDataObject *data ); + virtual size_t GetFormatCount() const = 0; + virtual wxDataFormat GetFormat(size_t n) const = 0; + // implementation void RegisterWidget( GtkWidget *widget ); @@ -106,13 +109,15 @@ public: wxTextDropTarget() {} - virtual bool OnMove( long x, long y ); - virtual bool OnDrop( long x, long y ); virtual bool OnData( long x, long y ); /* you have to override OnDropData to get at the text */ virtual bool OnDropText( long x, long y, const wxChar *text ) = 0; + virtual size_t GetFormatCount() const + { return 1; } + virtual wxDataFormat GetFormat(size_t n) const + { return wxDF_TEXT; } }; //------------------------------------------------------------------------- @@ -152,11 +157,14 @@ public: wxFileDropTarget() {} - virtual bool OnMove( long x, long y ); - virtual bool OnDrop( long x, long y ); virtual bool OnData( long x, long y ); virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; + + virtual size_t GetFormatCount() const + { return 1; } + virtual wxDataFormat GetFormat(size_t n) const + { return wxDF_FILENAME; } }; //------------------------------------------------------------------------- diff --git a/samples/dnd/dnd.cpp b/samples/dnd/dnd.cpp index 99267a4a72..9ce9518b12 100644 --- a/samples/dnd/dnd.cpp +++ b/samples/dnd/dnd.cpp @@ -1064,6 +1064,7 @@ DnDShape *DnDShapeDialog::GetShape() const bool DnDShapeDialog::TransferDataToWindow() { + if ( m_shape ) { m_radio->SetSelection(m_shape->GetKind()); diff --git a/samples/scroll/scroll.cpp b/samples/scroll/scroll.cpp index 3567376359..d1a03c1ab6 100644 --- a/samples/scroll/scroll.cpp +++ b/samples/scroll/scroll.cpp @@ -96,7 +96,7 @@ IMPLEMENT_DYNAMIC_CLASS(MyCanvas, wxScrolledWindow) BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) EVT_PAINT( MyCanvas::OnPaint) - EVT_LEFT_DOWN( MyCanvas::OnMouseDown) + EVT_MOUSE_EVENTS( MyCanvas::OnMouseDown) EVT_BUTTON( ID_QUERYPOS, MyCanvas::OnQueryPosition) EVT_BUTTON( ID_ADDBUTTON, MyCanvas::OnAddButton) EVT_BUTTON( ID_DELBUTTON, MyCanvas::OnDeleteButton) @@ -178,10 +178,19 @@ MyCanvas::~MyCanvas() void MyCanvas::OnMouseDown( wxMouseEvent &event ) { - wxPoint pt( event.GetPosition() ); - int x,y; - CalcUnscrolledPosition( pt.x, pt.y, &x, &y ); - wxLogMessage( "Mouse down event at: %d %d, scrolled: %d %d", pt.x, pt.y, x, y ); + if (event.LeftDown()) + { + wxPoint pt( event.GetPosition() ); + int x,y; + CalcUnscrolledPosition( pt.x, pt.y, &x, &y ); + wxLogMessage( "Mouse down event at: %d %d, scrolled: %d %d", pt.x, pt.y, x, y ); + } + + if (event.LeftIsDown() && + event.LeftDown()) + { + wxLogMessage( "Error: both LeftDown() and LeftIsDown() are TRUE!" ); + } } void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index dbf3456d02..d8ba14eba0 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -289,7 +289,6 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), /* Owen Taylor: "call gtk_drag_finish() with success == TRUE" */ -// printf( "data received.\n" ); if ((data->length <= 0) || (data->format != 8)) { @@ -297,11 +296,11 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), qualifies for junk */ gtk_drag_finish (context, FALSE, FALSE, time); -// printf( "no data.\n" ); - return; } + wxLogDebug( wxT( "Drop target: data received") ); + /* inform the wxDropTarget about the current GtkSelectionData. this is only valid for the duration of this call */ drop_target->SetDragData( data ); @@ -348,11 +347,32 @@ void wxDropTarget::OnLeave() bool wxDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) { - return TRUE; + if (GetFormatCount() == 0) + return FALSE; + + for (size_t i = 0; i < GetFormatCount(); i++) + { + if (IsSupported( GetFormat(i) )) + return TRUE; + } + + return FALSE; } bool wxDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) { + if (GetFormatCount() == 0) + return FALSE; + + for (size_t i = 0; i < GetFormatCount(); i++) + { + if (IsSupported( GetFormat(i) )) + { + RequestData( GetFormat(i) ); + return TRUE; + } + } + return FALSE; } @@ -400,8 +420,10 @@ bool wxDropTarget::IsSupported( wxDataFormat format ) { GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data); -// char *name = gdk_atom_name( formatAtom ); -// if (name) printf( "Format available: %s.\n", name ); +#ifdef __WXDEBUG__ + char *name = gdk_atom_name( formatAtom ); + if (name) wxLogDebug( "Drop target: drag has format: %s", name ); +#endif if (formatAtom == format) return TRUE; child = child->next; @@ -491,22 +513,6 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) // wxTextDropTarget //------------------------------------------------------------------------- -bool wxTextDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) -{ - return IsSupported( wxDF_TEXT ); -} - -bool wxTextDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) -{ - if (IsSupported( wxDF_TEXT )) - { - RequestData( wxDF_TEXT ); - return TRUE; - } - - return FALSE; -} - bool wxTextDropTarget::OnData( long x, long y ) { wxTextDataObject data; @@ -565,22 +571,6 @@ bool wxPrivateDropTarget::OnData( long x, long y ) // A drop target which accepts files (dragged from File Manager or Explorer) //---------------------------------------------------------------------------- -bool wxFileDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) -{ - return IsSupported( wxDF_FILENAME ); -} - -bool wxFileDropTarget::OnDrop( long x, long y ) -{ - if (IsSupported( wxDF_FILENAME )) - { - RequestData( wxDF_FILENAME ); - return TRUE; - } - - return FALSE; -} - bool wxFileDropTarget::OnData( long x, long y ) { wxFileDataObject data; @@ -627,10 +617,10 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget), { if (g_isIdle) wxapp_install_idle_handler(); -// printf( "Provide data!\n" ); - -// char *name = gdk_atom_name( selection_data->target ); -// if (name) printf( "Format requested: %s.\n", name ); +#ifdef __WXDEBUG__ + char *name = gdk_atom_name( selection_data->target ); + if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name ); +#endif drop_source->m_retValue = wxDragCancel; @@ -788,19 +778,29 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) { wxASSERT_MSG( m_data, wxT("wxDragSource: no data") ); - if (!m_data) return (wxDragResult) wxDragNone; + if (!m_data) + return (wxDragResult) wxDragNone; + if (m_data->GetFormatCount() == 0) + return (wxDragResult) wxDragNone; + g_blockEventsOnDrag = TRUE; RegisterWindow(); m_waiting = TRUE; - GdkAtom atom = gdk_atom_intern( "STRING", FALSE ); -// printf( "atom id: %d.\n", (int)atom ); - GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); - gtk_target_list_add( target_list, atom, 0, 0 ); + + wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; + m_data->GetAllFormats( array, TRUE ); + for (size_t i = 0; i < m_data->GetFormatCount(); i++) + { + GdkAtom atom = array[i]; + wxLogDebug( wxT("Supported atom %s"), gdk_atom_name( atom ) ); + gtk_target_list_add( target_list, atom, 0, 0 ); + } + delete[] array; GdkEventMotion event; event.window = m_widget->window; diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index dbf3456d02..d8ba14eba0 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -289,7 +289,6 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), /* Owen Taylor: "call gtk_drag_finish() with success == TRUE" */ -// printf( "data received.\n" ); if ((data->length <= 0) || (data->format != 8)) { @@ -297,11 +296,11 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), qualifies for junk */ gtk_drag_finish (context, FALSE, FALSE, time); -// printf( "no data.\n" ); - return; } + wxLogDebug( wxT( "Drop target: data received") ); + /* inform the wxDropTarget about the current GtkSelectionData. this is only valid for the duration of this call */ drop_target->SetDragData( data ); @@ -348,11 +347,32 @@ void wxDropTarget::OnLeave() bool wxDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) { - return TRUE; + if (GetFormatCount() == 0) + return FALSE; + + for (size_t i = 0; i < GetFormatCount(); i++) + { + if (IsSupported( GetFormat(i) )) + return TRUE; + } + + return FALSE; } bool wxDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) { + if (GetFormatCount() == 0) + return FALSE; + + for (size_t i = 0; i < GetFormatCount(); i++) + { + if (IsSupported( GetFormat(i) )) + { + RequestData( GetFormat(i) ); + return TRUE; + } + } + return FALSE; } @@ -400,8 +420,10 @@ bool wxDropTarget::IsSupported( wxDataFormat format ) { GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data); -// char *name = gdk_atom_name( formatAtom ); -// if (name) printf( "Format available: %s.\n", name ); +#ifdef __WXDEBUG__ + char *name = gdk_atom_name( formatAtom ); + if (name) wxLogDebug( "Drop target: drag has format: %s", name ); +#endif if (formatAtom == format) return TRUE; child = child->next; @@ -491,22 +513,6 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget ) // wxTextDropTarget //------------------------------------------------------------------------- -bool wxTextDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) -{ - return IsSupported( wxDF_TEXT ); -} - -bool wxTextDropTarget::OnDrop( long WXUNUSED(x), long WXUNUSED(y) ) -{ - if (IsSupported( wxDF_TEXT )) - { - RequestData( wxDF_TEXT ); - return TRUE; - } - - return FALSE; -} - bool wxTextDropTarget::OnData( long x, long y ) { wxTextDataObject data; @@ -565,22 +571,6 @@ bool wxPrivateDropTarget::OnData( long x, long y ) // A drop target which accepts files (dragged from File Manager or Explorer) //---------------------------------------------------------------------------- -bool wxFileDropTarget::OnMove( long WXUNUSED(x), long WXUNUSED(y) ) -{ - return IsSupported( wxDF_FILENAME ); -} - -bool wxFileDropTarget::OnDrop( long x, long y ) -{ - if (IsSupported( wxDF_FILENAME )) - { - RequestData( wxDF_FILENAME ); - return TRUE; - } - - return FALSE; -} - bool wxFileDropTarget::OnData( long x, long y ) { wxFileDataObject data; @@ -627,10 +617,10 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget), { if (g_isIdle) wxapp_install_idle_handler(); -// printf( "Provide data!\n" ); - -// char *name = gdk_atom_name( selection_data->target ); -// if (name) printf( "Format requested: %s.\n", name ); +#ifdef __WXDEBUG__ + char *name = gdk_atom_name( selection_data->target ); + if (name) wxLogDebug( wxT("Drop source: format requested: %s"), name ); +#endif drop_source->m_retValue = wxDragCancel; @@ -788,19 +778,29 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) { wxASSERT_MSG( m_data, wxT("wxDragSource: no data") ); - if (!m_data) return (wxDragResult) wxDragNone; + if (!m_data) + return (wxDragResult) wxDragNone; + if (m_data->GetFormatCount() == 0) + return (wxDragResult) wxDragNone; + g_blockEventsOnDrag = TRUE; RegisterWindow(); m_waiting = TRUE; - GdkAtom atom = gdk_atom_intern( "STRING", FALSE ); -// printf( "atom id: %d.\n", (int)atom ); - GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); - gtk_target_list_add( target_list, atom, 0, 0 ); + + wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; + m_data->GetAllFormats( array, TRUE ); + for (size_t i = 0; i < m_data->GetFormatCount(); i++) + { + GdkAtom atom = array[i]; + wxLogDebug( wxT("Supported atom %s"), gdk_atom_name( atom ) ); + gtk_target_list_add( target_list, atom, 0, 0 ); + } + delete[] array; GdkEventMotion event; event.window = m_widget->window; -- 2.45.2