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

  1. /* -*- Mode: C++; tab-width: 4; 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.    LocationDrag.cpp -- class definitions for browser location drag source
  20.    Created: Alastair Gourlay(SGI) c/o Dora Hsu<dora@netscape.com>, 26 Nov 1996
  21.  */
  22.  
  23.  
  24.  
  25. // classes:
  26. //      XFE_LocationDrag
  27. //
  28.  
  29. #include <stdio.h>
  30. #include <Xm/Xm.h>
  31. #include <Xm/AtomMgr.h>
  32. #include <Xfe/ButtonP.h>
  33. #include "icondata.h"
  34. #include "LocationDrag.h"
  35.  
  36. #ifdef DEBUG_sgidev
  37. #define XDEBUG(x) x
  38. #else
  39. #define XDEBUG(x)
  40. #endif
  41.  
  42. // constructor
  43.  
  44. XFE_LocationDrag::XFE_LocationDrag(Widget w) : XFE_DragNetscape(w)
  45. {
  46.     _dragDataURL=NULL;
  47. }
  48.  
  49. // destructor
  50.  
  51. XFE_LocationDrag::~XFE_LocationDrag()
  52. {
  53.     if (_dragDataURL) {
  54.         XP_FREE(_dragDataURL);
  55.         _dragDataURL=NULL;
  56.     }
  57. }
  58.  
  59.  
  60. // set drag data, for later use by drag callback
  61.  
  62. void XFE_LocationDrag::setDragData(URL_Struct* u)
  63. {
  64.     if (_dragDataURL)
  65.         XP_FREE(_dragDataURL);
  66.     
  67.     _dragDataURL=((u && u->address) ? XP_STRDUP(u->address) : 0);
  68. }
  69.  
  70.  
  71. // decide if this drag is interesting
  72.  
  73. int XFE_LocationDrag::dragStart(int,int)
  74. {
  75.     if (!_dragDataURL)
  76.         return FALSE;
  77.  
  78.     if (isFileURL(_dragDataURL))
  79.         dragFilesAsLinks(TRUE);
  80.  
  81.     setDragIcon(&LocationProxy);
  82.  
  83.     return TRUE;
  84. }
  85.  
  86. void XFE_LocationDrag::dragComplete()
  87. {
  88.     /*
  89.      * The proxy icon button never received Disarm() and Enter() events 
  90.      * cause the drag and drop event handlers are stealing them.  The 
  91.      * "correct" way to fix this would be to have the XfeButton button 
  92.      * install dnd translations/actions and have the XFE_DragBase class
  93.      * deal with this...but that would involve major work.
  94.      * would also mean that the drag and drop code would have to deal with
  95.      * 
  96.      * The most reasonable course of action is deal with this unique case
  97.      * here by forcing the proxy icon to return to the "normal" state 
  98.      * everytime the drag operation is complete.
  99.      */
  100.     if (XfeIsAlive(_widget) && XfeIsButton(_widget))
  101.     {
  102.         _XfeButtonDisarm(_widget,NULL,NULL,NULL);
  103.         _XfeButtonLeave(_widget,NULL,NULL,NULL);
  104.     }
  105. }
  106.  
  107. // specify types for this particular drag
  108.  
  109. void XFE_LocationDrag::targets()
  110. {
  111.     _numTargets=2;
  112.     _targets=new Atom[_numTargets];
  113.  
  114.     _targets[0]=_XA_NETSCAPE_URL;
  115.     _targets[1]=XA_STRING;
  116.  
  117.     setFileTarget(_XA_NETSCAPE_URL);
  118. }
  119.  
  120. // specify operations for this particular drag
  121.  
  122. void XFE_LocationDrag::operations()
  123. {
  124.     _operations=XmDROP_COPY;
  125. }
  126.  
  127. // provide data for requested target from targets() list
  128.  
  129. char *XFE_LocationDrag::getTargetData(Atom target)
  130. {
  131.     // WARNING - data *must* be allocated with Xt malloc API, or Xt
  132.     // will spring a leak!
  133.  
  134.     if (!_dragDataURL)
  135.         return NULL;
  136.     
  137.     if (target==_XA_NETSCAPE_URL) {
  138.         // translate drag data to NetscapeURL format
  139.         XFE_URLDesktopType urlData;
  140.  
  141.         urlData.createItemList(1);
  142.         urlData.url(0,_dragDataURL);
  143.         return (char*) XtNewString(urlData.getString());
  144.     }
  145.  
  146.     if (target==XA_STRING) {
  147.         // return the URL
  148.         return (char*) XtNewString(_dragDataURL);        
  149.     }
  150.  
  151.     return NULL;
  152. }
  153.  
  154.