made dnd cursors/icons slightly more usable (and much more documented)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7305 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-04-28 12:45:15 +00:00
parent 61dfd2bea1
commit 23cf28b3db
15 changed files with 363 additions and 72 deletions

View File

@@ -37,12 +37,31 @@ enum wxDragResult
\membersection{wxDropSource::wxDropSource}\label{wxdropsourcewxdropsource} \membersection{wxDropSource::wxDropSource}\label{wxdropsourcewxdropsource}
\func{}{wxDropSource}{\param{wxWindow*}{ win = NULL}} \func{}{wxDropSource}{\param{wxWindow*}{ win = NULL},\param{const wxIconOrCursor\& }{iconCopy = wxNullIconOrCursor}, \param{const wxIconOrCursor\& }{iconCopy = wxNullIconOrCursor}, \param{const wxIconOrCursor\& }{iconNone = wxNullIconOrCursor}}
Default/wxGTK-specific constructor. If you use the default constructor you must \func{}{wxDropSource}{\param{wxDataObject\&}{ data}, \param{wxWindow*}{ win = NULL},\param{const wxIconOrCursor\& }{iconCopy = wxNullIconOrCursor}, \param{const wxIconOrCursor\& }{iconCopy = wxNullIconOrCursor}, \param{const wxIconOrCursor\& }{iconNone = wxNullIconOrCursor}}
call \helpref{SetData}{wxdropsourcesetdata} later.
Note that {\it win} is required by the GTK port and therefore should always be set. The constructors for wxDataObject.
If you use the constructor without {\it data} parameter you must call
\helpref{SetData}{wxdropsourcesetdata} later.
Note that the exact type of {\it iconCopy} and subsequent parameters differs
between wxMSW and wxGTK: these are cursors under Windows but icons for GTK.
You should use the macro \helpref{wxDROP\_ICON}{wxdropicon} in portable
programs instead of directly using either of these types.
\wxheading{Parameters}
\docparam{win}{The window which initiates the drag and drop operation.}
\docparam{iconCopy}{The icon or cursor used for feedback for copy operation.}
\docparam{iconMove}{The icon or cursor used for feedback for move operation.}
\docparam{iconNone}{The icon or cursor used for feedback when operation can't be done.}
{\it win} is the window which initiates the drag and drop operation.
\membersection{wxDropSource::\destruct{wxDropSource}}\label{wxdropsourcedtor} \membersection{wxDropSource::\destruct{wxDropSource}}\label{wxdropsourcedtor}

View File

@@ -1100,6 +1100,21 @@ The clipboard must have previously been opened for this call to succeed.
\section{Miscellaneous functions}\label{miscellany} \section{Miscellaneous functions}\label{miscellany}
\membersection{::wxDROP\_ICON}{wxdropicon}
\func{wxIconOrCursor}{wxDROP\_ICON}{\param{const char *}{name}}
This macro creates either a cursor (MSW) or an icon (elsewhere) with the given
name. Under MSW, the cursor is loaded from the resource file and the icon is
loaded from XPM file under other platforms.
This macro should be used with
\helpref{wxDropSource constructor}{wxdropsourcewxdropsource}.
\wxheading{Include files}
<wx/dnd.h>
\membersection{::wxNewId} \membersection{::wxNewId}
\func{long}{wxNewId}{\void} \func{long}{wxNewId}{\void}

View File

@@ -36,6 +36,16 @@ class wxFileDropTarget;
class wxDropSource; class wxDropSource;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// this macro may be used instead for wxDropSource ctor arguments: it will use
// the icon 'name' from an XPM file under GTK, but will expand to something
// else under MSW. If you don't use it, you will have to use #ifdef in the
// application code.
#define wxDROP_ICON(name) wxICON(name)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropTarget // wxDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -78,12 +88,16 @@ class wxDropSource: public wxDropSourceBase
public: public:
/* constructor. set data later with SetData() */ /* constructor. set data later with SetData() */
wxDropSource( wxWindow *win = (wxWindow *)NULL, wxDropSource( wxWindow *win = (wxWindow *)NULL,
const wxIcon &go = wxNullIcon ); const wxIcon &copy = wxNullIcon,
const wxIcon &move = wxNullIcon,
const wxIcon &none = wxNullIcon);
/* constructor for setting one data object */ /* constructor for setting one data object */
wxDropSource( wxDataObject& data, wxDropSource( wxDataObject& data,
wxWindow *win, wxWindow *win,
const wxIcon &go = wxNullIcon ); const wxIcon &copy = wxNullIcon,
const wxIcon &move = wxNullIcon,
const wxIcon &none = wxNullIcon);
~wxDropSource(); ~wxDropSource();
@@ -94,7 +108,7 @@ public:
void RegisterWindow(); void RegisterWindow();
void UnregisterWindow(); void UnregisterWindow();
void PrepareIcon( int hot_x, int hot_y, GdkDragContext *context ); void PrepareIcon( int action, GdkDragContext *context );
GtkWidget *m_widget; GtkWidget *m_widget;
GtkWidget *m_iconWindow; GtkWidget *m_iconWindow;
@@ -102,9 +116,17 @@ public:
wxWindow *m_window; wxWindow *m_window;
wxDragResult m_retValue; wxDragResult m_retValue;
wxIcon m_icon; wxIcon m_iconCopy,
m_iconMove,
m_iconNone;
bool m_waiting; bool m_waiting;
private:
// common part of both ctors
void SetIcons(const wxIcon& copy,
const wxIcon& move,
const wxIcon& none);
}; };
#endif #endif

View File

@@ -36,6 +36,16 @@ class wxFileDropTarget;
class wxDropSource; class wxDropSource;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// this macro may be used instead for wxDropSource ctor arguments: it will use
// the icon 'name' from an XPM file under GTK, but will expand to something
// else under MSW. If you don't use it, you will have to use #ifdef in the
// application code.
#define wxDROP_ICON(name) wxICON(name)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDropTarget // wxDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -78,12 +88,16 @@ class wxDropSource: public wxDropSourceBase
public: public:
/* constructor. set data later with SetData() */ /* constructor. set data later with SetData() */
wxDropSource( wxWindow *win = (wxWindow *)NULL, wxDropSource( wxWindow *win = (wxWindow *)NULL,
const wxIcon &go = wxNullIcon ); const wxIcon &copy = wxNullIcon,
const wxIcon &move = wxNullIcon,
const wxIcon &none = wxNullIcon);
/* constructor for setting one data object */ /* constructor for setting one data object */
wxDropSource( wxDataObject& data, wxDropSource( wxDataObject& data,
wxWindow *win, wxWindow *win,
const wxIcon &go = wxNullIcon ); const wxIcon &copy = wxNullIcon,
const wxIcon &move = wxNullIcon,
const wxIcon &none = wxNullIcon);
~wxDropSource(); ~wxDropSource();
@@ -94,7 +108,7 @@ public:
void RegisterWindow(); void RegisterWindow();
void UnregisterWindow(); void UnregisterWindow();
void PrepareIcon( int hot_x, int hot_y, GdkDragContext *context ); void PrepareIcon( int action, GdkDragContext *context );
GtkWidget *m_widget; GtkWidget *m_widget;
GtkWidget *m_iconWindow; GtkWidget *m_iconWindow;
@@ -102,9 +116,17 @@ public:
wxWindow *m_window; wxWindow *m_window;
wxDragResult m_retValue; wxDragResult m_retValue;
wxIcon m_icon; wxIcon m_iconCopy,
m_iconMove,
m_iconNone;
bool m_waiting; bool m_waiting;
private:
// common part of both ctors
void SetIcons(const wxIcon& copy,
const wxIcon& move,
const wxIcon& none);
}; };
#endif #endif

View File

@@ -28,6 +28,16 @@ class wxIDropSource;
class WXDLLEXPORT wxDataObject; class WXDLLEXPORT wxDataObject;
class WXDLLEXPORT wxWindow; class WXDLLEXPORT wxWindow;
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// this macro may be used instead for wxDropSource ctor arguments: it will use
// the cursor 'name' from the resources under MSW, but will expand to
// something else under GTK. If you don't use it, you will have to use #ifdef
// in the application code.
#define wxDROP_ICON(name) wxCursor(#name)
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxDropSource is used to start the drag-&-drop operation on associated // wxDropSource is used to start the drag-&-drop operation on associated
// wxDataObject object. It's responsible for giving UI feedback while dragging. // wxDataObject object. It's responsible for giving UI feedback while dragging.

View File

@@ -46,6 +46,10 @@
#if defined(__WXGTK__) || defined(__WXMOTIF__) #if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm" #include "mondrian.xpm"
#include "dnd_copy.xpm"
#include "dnd_move.xpm"
#include "dnd_none.xpm"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -1065,16 +1069,10 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
textData.AddFile( "/file1.txt" ); textData.AddFile( "/file1.txt" );
textData.AddFile( "/file2.txt" ); textData.AddFile( "/file2.txt" );
*/ */
wxDropSource source(textData, this wxDropSource source(textData, this,
wxDROP_ICON(dnd_copy),
#ifdef __WXMSW__ wxDROP_ICON(dnd_move),
,wxCURSOR_PENCIL, // for copy wxDROP_ICON(dnd_none));
wxCURSOR_SPRAYCAN, // for move
wxCURSOR_QUESTION_ARROW // for nothing
#elif defined(__WXGTK__)
,wxICON(mondrian)
#endif
);
const char *pc; const char *pc;

View File

@@ -1,3 +1,6 @@
mondrian ICON "mondrian.ico" mondrian ICON "mondrian.ico"
#include "wx/msw/wx.rc" #include "wx/msw/wx.rc"
dnd_copy CURSOR "dnd_copy.cur"
dnd_move CURSOR "dnd_move.cur"
dnd_none CURSOR "dnd_none.cur"

BIN
samples/dnd/dnd_copy.cur Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

45
samples/dnd/dnd_copy.xpm Normal file
View File

@@ -0,0 +1,45 @@
/* XPM */
static char * dnd_copy_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 6 1",
/* colors */
" s None c None",
". c black",
"X c wheat",
"o c tan",
"O c #6699FF",
"r c red",
/* pixels */
" ................... r ",
" .XXXXXXXXXXXXXXXXX.. r ",
" .XXXXXXXXXXXXXXXXX.o.rrrrrrr",
" .XXXXXXXXXXXXXXXXX.oo. r ",
" .XXXXXXXXXXXXXXXXX.ooo. r ",
" .XXXXXXXXXXXXXXXXX.oooo. ",
" .XXXXXXXXXXXXXXXXX....... ",
" .XXXXXOOOOOOOOOOXXXooooo. ",
" .XXXXXXXXXXXXXXXXXXooooo. ",
" .XXXXXOOOOOOOOOOXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXOOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXOOOOOOOOOOXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXOOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXOOOOOOOOOOXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXOOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXOOOOOOOXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" ......................... "};

BIN
samples/dnd/dnd_move.cur Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

44
samples/dnd/dnd_move.xpm Normal file
View File

@@ -0,0 +1,44 @@
/* XPM */
static char * dnd_move_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 5 1",
/* colors */
" s None c None",
". c black",
"X c wheat",
"o c tan",
"O c #6699FF",
/* pixels */
" ................... ",
" .XXXXXXXXXXXXXXXXX.. ",
" .XXXXXXXXXXXXXXXXX.o. ",
" .XXXXXXXXXXXXXXXXX.oo. ",
" .XXXXXXXXXXXXXXXXX.ooo. ",
" .XXXXXXXXXXXXXXXXX.oooo. ",
" .XXXXXXXXXXXXXXXXX....... ",
" .XXXXXOOOOOOOOOOXXXooooo. ",
" .XXXXXXXXXXXXXXXXXXooooo. ",
" .XXXXXOOOOOOOOOOXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXOOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXOOOOOOOOOOXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXOOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXOOOOOOOOOOXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXOOOOOOOOOOXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXOOOOOOOXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" ......................... "};

BIN
samples/dnd/dnd_none.cur Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 B

45
samples/dnd/dnd_none.xpm Normal file
View File

@@ -0,0 +1,45 @@
/* XPM */
static char * dnd_none_xpm[] = {
/* width height ncolors chars_per_pixel */
"32 32 6 1",
/* colors */
" s None c None",
". c black",
"X c wheat",
"o c tan",
"O c #6699FF",
"r c red",
/* pixels */
" ................... ",
" .XXXXXXXXXXXXXXXXX.. ",
" .XXXXXXXXXXXXXXXXX.o. ",
" .XXXXXXXXXXXXXXXXX.oo. ",
" .XXXXXXXXXXXXXXXXX.ooo. ",
" .XXXXXXXXXXXXXXXXX.oooo. ",
" .XXXXXXXXXXXXXXXXX....... ",
" .rXXXXOOOOOOOOOOXXXoooor. ",
" .XrXXXXXXXXXXXXXXXXoooro. ",
" .XXrXXOOOOOOOOOOXXXXXrXX. ",
" .XXXrXXXXXXXXXXXXXXXrXXX. ",
" .XXXXrXXOOOOOOOOOXXrXXXX. ",
" .XXXXXrXXXXXXXXXXXrXXXXX. ",
" .XXXXXXrOOOOOOOOOrXXXXXX. ",
" .XXXXXXXrXXXXXXXrXXXXXXX. ",
" .XXXXXOOOrOOOOOrXXXXXXXX. ",
" .XXXXXXXXXrXXXrXXXXXXXXX. ",
" .XXXXXXXOOOrOrOOOXXXXXXX. ",
" .XXXXXXXXXXXrXXXXXXXXXXX. ",
" .XXXXXXOOOOrOrOOOXXXXXXX. ",
" .XXXXXXXXXrXXXrXXXXXXXXX. ",
" .XXXXXOOOrOOOOOrXXXXXXXX. ",
" .XXXXXXXrXXXXXXXrXXXXXXX. ",
" .XXXXXXrOOOOOOOOOrXXXXXX. ",
" .XXXXXrXXXXXXXXXXXrXXXXX. ",
" .XXXXrOOOOOOOXXXXXXrXXXX. ",
" .XXXrXXXXXXXXXXXXXXXrXXX. ",
" .XXrXXXXXXXXXXXXXXXXXrXX. ",
" .XrXXXXXXXXXXXXXXXXXXXrX. ",
" .rXXXXXXXXXXXXXXXXXXXXXr. ",
" .XXXXXXXXXXXXXXXXXXXXXXX. ",
" ......................... "};

View File

@@ -620,7 +620,10 @@ gtk_dnd_window_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigur
// wxDropSource // wxDropSource
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxDropSource::wxDropSource( wxWindow *win, const wxIcon &icon ) wxDropSource::wxDropSource(wxWindow *win,
const wxIcon &iconCopy,
const wxIcon &iconMove,
const wxIcon &iconNone)
{ {
m_waiting = TRUE; m_waiting = TRUE;
@@ -632,11 +635,14 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &icon )
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_icon = icon; SetIcons(iconCopy, iconMove, iconNone);
if (wxNullIcon == icon) m_icon = wxIcon( page_xpm );
} }
wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &icon ) wxDropSource::wxDropSource(wxDataObject& data,
wxWindow *win,
const wxIcon &iconCopy,
const wxIcon &iconMove,
const wxIcon &iconNone)
{ {
m_waiting = TRUE; m_waiting = TRUE;
@@ -650,19 +656,47 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &ico
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_icon = icon; SetIcons(iconCopy, iconMove, iconNone);
if (wxNullIcon == icon) m_icon = wxIcon( page_xpm ); }
void wxDropSource::SetIcons(const wxIcon &iconCopy,
const wxIcon &iconMove,
const wxIcon &iconNone)
{
m_iconCopy = iconCopy;
m_iconMove = iconMove;
m_iconNone = iconNone;
if ( !m_iconCopy.Ok() )
m_iconCopy = wxIcon(page_xpm);
if ( !m_iconMove.Ok() )
m_iconMove = m_iconCopy;
if ( !m_iconNone.Ok() )
m_iconNone = m_iconCopy;
} }
wxDropSource::~wxDropSource() wxDropSource::~wxDropSource()
{ {
} }
void wxDropSource::PrepareIcon( int hot_x, int hot_y, GdkDragContext *context ) void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
{ {
GdkBitmap *mask = (GdkBitmap *) NULL; // get the right icon to display
if (m_icon.GetMask()) mask = m_icon.GetMask()->GetBitmap(); wxIcon *icon = NULL;
GdkPixmap *pixmap = m_icon.GetPixmap(); if ( action & GDK_ACTION_MOVE )
icon = &m_iconMove;
else if ( action & GDK_ACTION_COPY )
icon = &m_iconCopy;
else
icon = &m_iconNone;
GdkBitmap *mask;
if ( icon->GetMask() )
mask = icon->GetMask()->GetBitmap();
else
mask = (GdkBitmap *)NULL;
GdkPixmap *pixmap = icon->GetPixmap();
gint width,height; gint width,height;
gdk_window_get_size (pixmap, &width, &height); gdk_window_get_size (pixmap, &width, &height);
@@ -689,7 +723,7 @@ void wxDropSource::PrepareIcon( int hot_x, int hot_y, GdkDragContext *context )
if (mask) if (mask)
gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0); gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);
gtk_drag_set_icon_widget( context, m_iconWindow, hot_x, hot_y ); gtk_drag_set_icon_widget( context, m_iconWindow, 0, 0 );
} }
wxDragResult wxDropSource::DoDragDrop( bool allowMove ) wxDragResult wxDropSource::DoDragDrop( bool allowMove )
@@ -746,22 +780,22 @@ wxDragResult wxDropSource::DoDragDrop( bool allowMove )
if (button_number) if (button_number)
{ {
GdkDragAction action = GDK_ACTION_COPY; GdkDragAction action = GDK_ACTION_COPY;
if (allowMove) action = (GdkDragAction)(GDK_ACTION_MOVE|GDK_ACTION_COPY); if (allowMove) action = (GdkDragAction)(GDK_ACTION_MOVE|GDK_ACTION_COPY);
GdkDragContext *context = gtk_drag_begin( m_widget, GdkDragContext *context = gtk_drag_begin( m_widget,
target_list, target_list,
action, action,
button_number, /* number of mouse button which started drag */ button_number, /* number of mouse button which started drag */
(GdkEvent*) &event ); (GdkEvent*) &event );
m_dragContext = context; m_dragContext = context;
PrepareIcon( 0, 0, context ); PrepareIcon( action, context );
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
if (context->action == GDK_ACTION_COPY) if (context->action == GDK_ACTION_COPY)
m_retValue = wxDragCopy; m_retValue = wxDragCopy;
if (context->action == GDK_ACTION_MOVE) if (context->action == GDK_ACTION_MOVE)
m_retValue = wxDragMove; m_retValue = wxDragMove;
} }

View File

@@ -620,7 +620,10 @@ gtk_dnd_window_configure_callback( GtkWidget *WXUNUSED(widget), GdkEventConfigur
// wxDropSource // wxDropSource
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
wxDropSource::wxDropSource( wxWindow *win, const wxIcon &icon ) wxDropSource::wxDropSource(wxWindow *win,
const wxIcon &iconCopy,
const wxIcon &iconMove,
const wxIcon &iconNone)
{ {
m_waiting = TRUE; m_waiting = TRUE;
@@ -632,11 +635,14 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &icon )
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_icon = icon; SetIcons(iconCopy, iconMove, iconNone);
if (wxNullIcon == icon) m_icon = wxIcon( page_xpm );
} }
wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &icon ) wxDropSource::wxDropSource(wxDataObject& data,
wxWindow *win,
const wxIcon &iconCopy,
const wxIcon &iconMove,
const wxIcon &iconNone)
{ {
m_waiting = TRUE; m_waiting = TRUE;
@@ -650,19 +656,47 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &ico
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_icon = icon; SetIcons(iconCopy, iconMove, iconNone);
if (wxNullIcon == icon) m_icon = wxIcon( page_xpm ); }
void wxDropSource::SetIcons(const wxIcon &iconCopy,
const wxIcon &iconMove,
const wxIcon &iconNone)
{
m_iconCopy = iconCopy;
m_iconMove = iconMove;
m_iconNone = iconNone;
if ( !m_iconCopy.Ok() )
m_iconCopy = wxIcon(page_xpm);
if ( !m_iconMove.Ok() )
m_iconMove = m_iconCopy;
if ( !m_iconNone.Ok() )
m_iconNone = m_iconCopy;
} }
wxDropSource::~wxDropSource() wxDropSource::~wxDropSource()
{ {
} }
void wxDropSource::PrepareIcon( int hot_x, int hot_y, GdkDragContext *context ) void wxDropSource::PrepareIcon( int action, GdkDragContext *context )
{ {
GdkBitmap *mask = (GdkBitmap *) NULL; // get the right icon to display
if (m_icon.GetMask()) mask = m_icon.GetMask()->GetBitmap(); wxIcon *icon = NULL;
GdkPixmap *pixmap = m_icon.GetPixmap(); if ( action & GDK_ACTION_MOVE )
icon = &m_iconMove;
else if ( action & GDK_ACTION_COPY )
icon = &m_iconCopy;
else
icon = &m_iconNone;
GdkBitmap *mask;
if ( icon->GetMask() )
mask = icon->GetMask()->GetBitmap();
else
mask = (GdkBitmap *)NULL;
GdkPixmap *pixmap = icon->GetPixmap();
gint width,height; gint width,height;
gdk_window_get_size (pixmap, &width, &height); gdk_window_get_size (pixmap, &width, &height);
@@ -689,7 +723,7 @@ void wxDropSource::PrepareIcon( int hot_x, int hot_y, GdkDragContext *context )
if (mask) if (mask)
gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0); gtk_widget_shape_combine_mask (m_iconWindow, mask, 0, 0);
gtk_drag_set_icon_widget( context, m_iconWindow, hot_x, hot_y ); gtk_drag_set_icon_widget( context, m_iconWindow, 0, 0 );
} }
wxDragResult wxDropSource::DoDragDrop( bool allowMove ) wxDragResult wxDropSource::DoDragDrop( bool allowMove )
@@ -746,22 +780,22 @@ wxDragResult wxDropSource::DoDragDrop( bool allowMove )
if (button_number) if (button_number)
{ {
GdkDragAction action = GDK_ACTION_COPY; GdkDragAction action = GDK_ACTION_COPY;
if (allowMove) action = (GdkDragAction)(GDK_ACTION_MOVE|GDK_ACTION_COPY); if (allowMove) action = (GdkDragAction)(GDK_ACTION_MOVE|GDK_ACTION_COPY);
GdkDragContext *context = gtk_drag_begin( m_widget, GdkDragContext *context = gtk_drag_begin( m_widget,
target_list, target_list,
action, action,
button_number, /* number of mouse button which started drag */ button_number, /* number of mouse button which started drag */
(GdkEvent*) &event ); (GdkEvent*) &event );
m_dragContext = context; m_dragContext = context;
PrepareIcon( 0, 0, context ); PrepareIcon( action, context );
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
if (context->action == GDK_ACTION_COPY) if (context->action == GDK_ACTION_COPY)
m_retValue = wxDragCopy; m_retValue = wxDragCopy;
if (context->action == GDK_ACTION_MOVE) if (context->action == GDK_ACTION_MOVE)
m_retValue = wxDragMove; m_retValue = wxDragMove;
} }