home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / DragDrop.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.6 KB  |  285 lines

  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.    DragDrop.h -- class definitions for drag and drop
  20.    Created: Alastair Gourlay(SGI) c/o Dora Hsu<dora@netscape.com>, 26 Nov 1996
  21.  */
  22.  
  23.  
  24.  
  25. #ifndef _DRAG_DROP_H
  26. #define _DRAG_DROP_H
  27.  
  28. // Classes in this file:
  29. //      XFE_DragBase
  30. //        XFE_DragDesktop
  31. //          XFE_DragNetscape
  32. //      XFE_DropBase
  33. //        XFE_DropDesktop
  34. //          XFE_DropNetscape
  35. //
  36.  
  37.  
  38. #include <stdlib.h>
  39. #include <Xm/XmAll.h>
  40. #include <icondata.h>
  41. #include "DesktopTypes.h"
  42.  
  43. class XFE_DragBase
  44. {
  45. public:
  46.     XFE_DragBase(Widget);
  47.     virtual ~XFE_DragBase();
  48.     void dragThreshold(unsigned int t) { _dragThreshold=t; };
  49.     unsigned int dragThreshold() { return _dragThreshold; };
  50.     void addDragWidget(Widget);
  51.     static void dragWidgetDestroyCb(Widget,XtPointer,XtPointer);
  52.     
  53.     // global drag information
  54.     static Widget _activeDragShell;
  55.  
  56.     // globally useful method
  57.     static char *guessUrlMimeType(const char*);
  58.     
  59.     static Atom _XA_TARGETS;
  60.     static Atom _XA_DELETE;
  61.     static Atom _XA_MULTIPLE;
  62.     static Atom _XA_TIMESTAMP;
  63.     static Atom _XA_NULL;
  64.     static Atom _XA_SGI_ICON;
  65.     static Atom _XA_SGI_ICON_TYPE;
  66.     static Atom _XA_SGI_FILE;
  67.     static Atom _XA_FILE_NAME;
  68.     static Atom _XA_NETSCAPE_URL;
  69. protected:
  70.     Widget _widget;
  71.     unsigned int _dragThreshold;
  72.     int _dragStarted;
  73.     int _buttonPressed;
  74.     int _dragStartX;
  75.     int _dragStartY;
  76.     int _dragEventX;
  77.     int _dragEventY;
  78.     int _dragFilesAsLinks;
  79.     Widget _dragWidget;
  80.     Widget _dragContext;
  81.     Widget _dragIcon;
  82.     XButtonPressedEvent _dragButtonEvent;
  83.  
  84.     Atom *_targets;
  85.     int _numTargets;
  86.     unsigned int _operations;
  87.     struct fe_icon_data *_dragIconData;
  88.     Pixmap _dragIconPixmap;
  89.     Pixmap _dragIconPixmapMask;
  90.     unsigned int _dragIconWidth;
  91.     unsigned int _dragIconHeight;
  92.  
  93.     // drag methods
  94.     void dragInitialize();
  95.     void dragFilesAsLinks(int d) { _dragFilesAsLinks=d; };
  96.     static int isFileURL(const char*);
  97.     void setDragIcon(struct fe_icon_data*);
  98.     void setDragIconForType(const char*);
  99.     
  100.     // methods for derived classes to override
  101.     virtual int dragStart(int,int) { return TRUE; };
  102.     virtual void targets();
  103.     virtual void operations();
  104.     virtual char *getTargetData(Atom);
  105.     virtual void deleteTarget();
  106.     virtual int isFileTarget(Atom) { return FALSE; };
  107.     virtual void getTargetDataAsFileWrapper(Atom,XtPointer*,unsigned long*) { };
  108.     virtual void dragComplete() { };
  109.  
  110.     // callback wrappers
  111.     static void ButtonPressCb(Widget,XtPointer,XEvent*,Boolean*);
  112.     static void ButtonMotionCb(Widget,XtPointer,XEvent*,Boolean*);
  113.     static Boolean DragConvertCb(Widget,Atom*,Atom*,Atom*,XtPointer*,unsigned long*,int*);
  114.     static void OperationChangedCb(Widget,XtPointer,XtPointer);
  115.     static void DragMotionCb(Widget,XtPointer,XtPointer);
  116.     static void DropStartCb(Widget,XtPointer,XtPointer);
  117.     static void DropSiteEnterCb(Widget,XtPointer,XtPointer);
  118.     static void DropSiteLeaveCb(Widget,XtPointer,XtPointer);
  119.     static void DropFinishCb(Widget,XtPointer,XtPointer);
  120.     static void DragDropFinishCb(Widget,XtPointer,XtPointer);
  121.     static void DestroyCb(Widget,XtPointer,XtPointer);
  122.  
  123.     // callback methods
  124.     virtual void buttonPressCb(XButtonPressedEvent*);
  125.     int buttonMotionCb(XMotionEvent*);
  126.     Boolean dragConvertCb(Atom*,Atom*,XtPointer*,unsigned long*,int*);
  127.     void operationChangedCb();
  128.     void dragMotionCb();
  129.     void dropStartCb();
  130.     void dropSiteEnterCb(int);
  131.     void dropSiteLeaveCb();
  132.     void dropFinishCb();
  133.     virtual void dragDropFinishCb();
  134.     
  135. private:
  136. };
  137.  
  138. class XFE_DragDesktop : public XFE_DragBase 
  139. {
  140. public:
  141.     XFE_DragDesktop(Widget);
  142.     ~XFE_DragDesktop();
  143. protected:
  144.     Atom _fileTarget;
  145.  
  146.     // file handler methods    
  147.     void setFileTarget(Atom);
  148.     void getTargetDataAsFileWrapper(Atom,XtPointer*,unsigned long*);
  149.     virtual void dragDropFinishCb();
  150.  
  151.     // methods for derived classes to override
  152.     virtual int isFileTarget(Atom);
  153.     virtual void getTargetDataAsFileList(Atom,char ***,int *);
  154.     virtual const char *getTargetFTRType(Atom);
  155. private:
  156. };
  157.  
  158. class XFE_DragNetscape : public XFE_DragDesktop 
  159. {
  160. public:
  161.     XFE_DragNetscape(Widget);
  162.     ~XFE_DragNetscape();
  163. protected:
  164.     XFE_DesktopType *_desktopFileData;
  165.  
  166.     // drag methods
  167.     virtual void dragDropFinishCb();
  168.     
  169.     // methods for derived classes to override
  170.     virtual void getTargetDataAsFileList(Atom,char ***,int *);
  171.     virtual const char *getTargetFTRType(Atom);
  172. private:
  173. };
  174.  
  175. //
  176. // XFE_DropBase
  177. //
  178.  
  179. class XFE_DropBase
  180. {
  181. public:
  182.     XFE_DropBase(Widget);
  183.     virtual ~XFE_DropBase();
  184.     void enable();
  185.     void disable();
  186.     void update();
  187.     void update(ArgList,Cardinal);
  188.     
  189.     static Atom _XA_NULL;
  190.     static Atom _XA_DELETE;
  191.     static Atom _XA_SGI_FILE;
  192.     static Atom _XA_SGI_ICON;
  193.     static Atom _XA_SGI_URL;
  194.     static Atom _XA_FILE_NAME;
  195.     static Atom _XA_TARGETS;
  196.     static Atom _XA_NETSCAPE_URL;
  197. protected:
  198.     Widget _widget;
  199.     unsigned int _operations;
  200.     Atom *_targets;
  201.     int _numTargets;
  202.     XtCallbackRec _destroyCbList[2];
  203.     Atom _chosenTarget;
  204.  
  205.     int _dropEventX;
  206.     int _dropEventY;
  207.     
  208.     // methods available to derived class
  209.     virtual void operations(); // override to set _operations
  210.     virtual void targets(); // override to set _targets
  211.     virtual void dragIn(); // override to add drag-in feature
  212.     virtual void dragOut(); // override to add drag-out feature
  213.     virtual void dragMotion(); // override to add drag-motion feature
  214.     virtual void operationChanged(); // override to add operation-changed feature
  215.     virtual Atom acceptDrop(unsigned int,Atom*,unsigned int); // override to validate operation and targets
  216.     virtual void dropComplete(); // override to tidy up after drop
  217.     virtual void freeTargetList(); // convenience fn - allow easy cleanup of old targets
  218.     virtual int processTargets(Atom*,const char**,int) { return FALSE; };
  219.     virtual int isFileTarget(Atom) { return FALSE; };
  220.     virtual int processFileTargetWrapper(Atom,XtPointer,unsigned int) { return FALSE; };
  221.     
  222.     // internal processing
  223.     Atom acceptDropWrapper(unsigned int,Widget);
  224.     
  225.     // internal callback stubs
  226.     static void DragProc(Widget,XtPointer,XtPointer);
  227.     static void DropProc(Widget,XtPointer,XtPointer);
  228.     static void DestroyCb(Widget,XtPointer,XtPointer);
  229.     static void TransferProc(Widget,XtPointer,Atom*,Atom*,XtPointer,unsigned long*,int*);
  230.  
  231.     // internal callback methods
  232.     void dragProc(XmDragProcCallbackStruct*);
  233.     void dropProc(XmDropProcCallbackStruct*);
  234.     void handleDrop(XmDropProcCallbackStruct*);
  235.     void transferProc(Widget,Atom,XtPointer,unsigned int);
  236. private:
  237. };
  238.  
  239.  
  240. //
  241. // XFE_DropDesktop
  242. //
  243.  
  244. class XFE_DropDesktop : public XFE_DropBase
  245. {
  246. public:
  247.     XFE_DropDesktop(Widget);
  248.     ~XFE_DropDesktop();
  249. protected:
  250.     // base class methods changed
  251.     int isFileTarget(Atom);
  252.     int processFileTargetWrapper(Atom,XtPointer,unsigned int);
  253.     
  254.     // drop processing
  255.     void acceptFileTargets();
  256.     int processSGI_URL(char*,unsigned int);
  257.     int processSGI_ICON(char*,unsigned int);
  258.     int processFILE_NAME(char*,unsigned int);
  259.  
  260.     // derived class can override to get file drops
  261.     virtual int processDesktopURLTarget(const char*,const char*) { return FALSE; };
  262.     virtual int processFileTarget(const char**,int) { return FALSE; };
  263. private:
  264. };
  265.  
  266. //
  267. // XFE_DropNetscape
  268. //
  269.  
  270. class XFE_DropNetscape : public XFE_DropDesktop 
  271. {
  272. public:
  273.     XFE_DropNetscape(Widget);
  274.     ~XFE_DropNetscape();
  275. protected:
  276.     int processFileTarget(const char**,int);
  277.     int processDesktopURLTarget(const char*,const char*);
  278.  
  279.     // derived class override's processTargets() to receive drop data
  280. private:
  281. };
  282.  
  283.  
  284. #endif // _DRAG_DROP_H
  285.