/***************************************************************************
                          Drag.h  -  description
                             -------------------
    begin                : Tue Mar 14 2000
    copyright            : (C) 2000 by Richard Dale
    email                : Richard_Dale@tipitina.demon.co.uk
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DRAG_H
#define DRAG_H

#include <Foundation/NSObject.h>

#include <qtobjc/QObject.h>
#include <qtobjc/QWidget.h>
#include <qtobjc/QPixmap.h>
#include <qtobjc/QEvent.h>

/* Usually we drag URLs around. Every type of data must have
  a unique ID so that the receiver can decide wether he wants to
  accept the drop or not.
  */
// ???
#define DndNotDnd       -1
// ???
#define DndUnknown      0
// Raw data
#define DndRawData      1
// Dont use that any more
#define DndFile         2
// Dont use that any more
#define DndFiles        3
// ASCII Text
#define DndText         4
// Dont use that any more
#define DndDir          5
// Dont use that any more
#define DndLink         6
// Dont use that any more
#define DndExe          7
// For Offix internal use only
#define DndEND          8

// An URL
#define DndURL          128
#define Dnd_X_Precision 2
#define Dnd_Y_Precision 2

#define kapp -[KApplication getKApplication]

// we need Window and Atom but do not want to include X.h since it
// #defines way too many constants
#define XID 		unsigned long
#define Atom 	unsigned long
#define Window	XID

/**
  *@author Richard Dale
  */

/**
* Icon for KDE Drag 'n Drop. This is the widget that is moved
* around during DND.
*
* @short Icon for KDE Drag 'n Drop
* Derived from the C++ header 'drag.h'
* by Torben Weis (weis@kde.org)
*/
@interface KDNDIcon : QWidget
/**
* Creates an Icon with the specified pixmap. _x and _y are the upper
* left corner in global coordinates.
*/
- initFromPixmap: (QPixmap *) pixmap x: (int) _x y: (int) _y;

- copy;
- (void) dealloc;

- paintEvent: (QPaintEvent *) event;
- resizeEvent: (QResizeEvent *) event;
/**
* The pixmap displayed.
*/
- (QPixmap *) pixmap;
@end

/**
* Drop zone for KDE Drag n Drop.
*
* You can create a DropZone for every widget. When the user makes a
* drop over this widget, the KDNDDropZone takes over control.
*
* The KDE drag and drop classes are based on the Offix Drag and Drop
* protocol, but are not compatible with it yet.
*
* Currently used types are: DndText, DndURL.
*
* @short Drop zone for KDE Drag n Drop.
* Derived from the C++ header 'drag.h'
* by Torben Weis (weis@kde.org)
*/
@interface KDNDDropZone : QObject

/**
* Create a DropZone for the widget _parent.
*
* @param _parent	The parent of this dropzone, usually the widget
*			for which you wish to receive drop events.
* @param _type		The type of Drop events to accept, eg DndURL.
*/
- initFromParent: (QWidget *) _parent type: (int) _type;
- (void) dealloc;

/** When a drop occurs, this function is called. _data is the
   dropped data, _size its size, _type for example DndURL and
   _x and _y are the global coordinates of the drop.
   */

/**
* This function is called when a drop event occurs.
*
* @param _data		A reference to the dropped data.
* @param _size		The length of the data dropped.
* @param _type		The type of the data, eg DndURL means a URL was
*			dropped.
* @param _x,_y		The global coordinates of the drop.
*/
- drop: (NSString *) _data size: (int) _size type: (int) _type x: (int) _x y: (int) _y;

/**
* This function is called when an icon is being dragged over this
* drop zone.
*
* Note that the icon may never have left the drop zone; the user may
* be dragging it around withing this zone and this function would still
* be called.
*
* @param _data		A reference to the dragged data.
* @param _size		The length of the data dragged.
* @param _type		The type of the data, eg DndURL means a URL is
*			being dragged.
* @param _x,_y		The global coordinates of the drag.
*/
- enter: (NSString *) _data size: (int) _size type: (int) _type x: (int) _x y: (int) _y;

/**
* This function is called when the icon being dragged has left
* this drop zone.
*/
- leave;

/**
* Decode the dropped data into a list of URLs. This should only be called
* if the dropped data was of type DndURL.
*
* Note that the contents of this list are only valid till the next
* drop event.
*/
- (NSArray *) getURLList;
/**
* Get dropped data.
*
* @return A reference to the dropped data.
*/
- (NSString *) getData;

/**
* Get dropped data length.
*
* @return the length of the data that was dropped.
*/
- (int) getDataSize;

/**
* Get drop data type.
*
* @return the type of the data dropped.
*/
- (int) getDataType;

/**
* Get the mouse position at which the item was dropped.
*
* @return the X coordinate at which the item was dropped.
* @see #-getMouseY
*/
- (int) getMouseX;

/**
* Get the mouse position at which the item was dropped.
*
* @return the Y coordinate at which the item was dropped.
* @see #-getMouseX
*/
- (int) getMouseY;

/**
* The types of dropped data this drop zone will accept.
*
* @return the types of drops accepted.
*/
- (int) getAcceptType;

/**
* Tests whether this data type will be accepted.
*
* @param _type	the data type to be tested.
* @return YES if this type will be accepted, NO otherwise.
*/
- (BOOL) accepts: (int) _type;

/**
* Get the parent widget.
*
* @return the parent widget for which this object is monitoring drops.
*/
- (QWidget *) getWidget;

/**
* Emitted when a drop has occurred.
*
* The zone into which the drop has occurred is passed as a parameter.
*/
- dropAction: (KDNDDropZone *) zone;

/**
* Emitted when an icon is dragged into and inside this drop zone.
*/
- dropEnter: (KDNDDropZone *) zone;

/**
* Emitted when an icon is dragged out of this drop zone.
*/
- dropLeave: (KDNDDropZone*) zone;
/**
* Fills 'urlList' with the URLs in 'dndData'.
* Works only if 'dndType' is DndURL.
*/
- parseURLList;
@end

/**
* A widget for drag support.
*
* If you require only drop support you dont need this widget, you just need
* KDndDropZone.
*
* @short A widget for drag support.
* Derived from the C++ header 'drag.h'
* by Torben Weis (weis@kde.org)
*/
@interface KDNDWidget : QWidget
- initWithParent: (QWidget *) _parent name: (NSString *) name flags: (WFlags) f;
- (void) dealloc;

/**
* Start a drag.
*
* Call this function when you notice that the user wants to drag something
* around, usually from a dndMouseMoveEvent.
*
* @param _icon	The icon that the user can drag around.
* @param _data	A reference to the data being dragged. A deep copy is
*		made of this data, so you don't need to maintain its
*		value after you call this function.
* @param _size	The length of the data pointed to by _data.
* @param _type	The type of the data that is being dragged, eg DndURL.
* @param _dx,_dy The difference between the icons upper left corner and
*		the mouse reference. For example when the user clicks the
*		mouse over the middle of a pixmap, _dx and _dy would be
*		' - pixmap.width() / 2 ' and ' - pixmap.height() / 2 '.
*		This is just provided for look and feel.
*/
- startDrag: (KDNDIcon *) _icon data: (NSString *) _data size: (int) _size type: (int) _type dx: (int) _dx dy: (int) _dy;

/**
* Finds the root window belonging to the global point p.
*/
- (Window) findRootWindow: (QPoint *) p;

/**
* This function MUST be called by your implementation if you overload it.
*
* In nearly all cases, you probably mean to call dndMouseMoveEvent().
*
* @see #-dndMouseMoveEvent
*/
- mouseMoveEvent: (QMouseEvent *) event;

/**
* This function MUST be called by your implementation if you overload it.
*
* In nearly all cases, you probably mean to call dndMouseReleaseEvent().
*
* @see #-dndMouseReleaseEvent
*/
- mouseReleaseEvent: (QMouseEvent *) event;

/**
* A root drop occurred.
*
* At the point (_x,_y) the user dropped the icon. If there is now window
* below this point, this function is called.  Usually it emits a XEvent,
* so that every application gets informed about this. This function is
* only called if the drag started in this widget.
*
* See KApplication for details on receiving root drop events.
*/
- rootDropEvent: (int) _x : (int) _y;

/**
* Perform internal housekeeping after a root drop event.
*
* If you must overload rootDropEvent(...), call this function at the
* end to do some clean up.
*/
- rootDropEvent;
- dragEndEvent;
- dndMouseMoveEvent: (QMouseEvent *) event;
/**
* Your mouse release event function.
*
* Usually you will only set 'pressed' ( see dndMouseMoveEvent) to FALSE here.
* The function is only called if the release event had nothing to do with
* DND.
*/
- dndMouseReleaseEvent: (QMouseEvent *) event;
@end

#endif

Documentation generated by duke@tipitina on Sat May 6 11:42:52 EDT 2000