home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / CBrowserDragTask.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  4.8 KB  |  157 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. //    CBrowserDragTask.cp
  20.  
  21.  
  22.  
  23. #include "CBrowserDragTask.h"
  24.  
  25. #include "resgui.h"
  26.  
  27. // ---------------------------------------------------------------------------
  28. //        Ñ CBrowserDragTask
  29. // ---------------------------------------------------------------------------
  30.  
  31. CBrowserDragTask::CBrowserDragTask(
  32.     const EventRecord&        inEventRecord)
  33.     :    super(inEventRecord)
  34. {
  35. }    
  36.  
  37. // ---------------------------------------------------------------------------
  38. //        Ñ ~CBrowserDragTask
  39. // ---------------------------------------------------------------------------
  40.                                             
  41. CBrowserDragTask::~CBrowserDragTask()
  42. {
  43. }    
  44.  
  45.  
  46. //
  47. // AddFlavorBookmark
  48. //
  49. // This flavor is currently used by the Proxy Icon and the Personal Toolbar
  50. // to shuttle around url/title information. The data format is plain text in
  51. // the form of URL<cr>Title.
  52. //
  53. // This flavor may or may not contain data. The proxy icon, for example, would want to 
  54. // include the data so that if it is dropped in the NavCenter, the NC could 
  55. // determine if the drop was allowable based on the URL.
  56. //
  57. // NOTE: THIS FLAVOR WILL NOT BE USED BY THE PERSONAL TOOLBAR IN THE FUTURE
  58. // AND WILL ONLY BE USED BY THE PROXY ICON. AS A RESULT, IT WILL BE MOVED
  59. // INTO CProxyDragTask.
  60. //
  61. void
  62. CBrowserDragTask::AddFlavorBookmark(ItemReference inItemRef, const char* inData)
  63. {
  64.     OSErr theErr = ::AddDragItemFlavor(
  65.                                     mDragRef,
  66.                                     inItemRef,
  67.                                     emBookmarkDrag,
  68.                                     inData,            
  69.                                     inData ? strlen(inData) + 1 : 0,
  70.                                     flavorSenderTranslated | flavorSenderOnly);
  71.     ThrowIfOSErr_(theErr);
  72. }                            
  73.  
  74.  
  75. //
  76. // AddFlavorBookmarkFile
  77. //
  78. // This flavor is used for creating a bookmark file in the Finder instead of a clipping when
  79. // icons are dragged to the desktop.
  80. //
  81. // The data will be fulfilled in a DoSendData proc.
  82. // 
  83. void
  84. CBrowserDragTask::AddFlavorBookmarkFile(ItemReference inItemRef)
  85. {    
  86.     // Promise a file of type emBookmarkFile
  87.     
  88.     PromiseHFSFlavor promise;
  89.     
  90.     promise.fileType         = emBookmarkFile;
  91.     promise.fileCreator     = emSignature;
  92.     promise.fdFlags         = 0;
  93.     promise.promisedFlavor    = emBookmarkFileDrag;
  94.  
  95.     // Promise to create a file for the emBookmark flavor, where the actual
  96.     // FSSpec is promised in the emBookmark flavor below
  97.     
  98.     OSErr theErr = ::AddDragItemFlavor(
  99.                                     mDragRef,
  100.                                     inItemRef,
  101.                                     flavorTypePromiseHFS,
  102.                                     &promise,
  103.                                     sizeof(PromiseHFSFlavor),
  104.                                     0);
  105.     ThrowIfOSErr_(theErr);
  106.     
  107.     theErr = ::AddDragItemFlavor(
  108.                                     mDragRef,
  109.                                     inItemRef,
  110.                                     emBookmarkFileDrag,
  111.                                     nil,
  112.                                     0,
  113.                                     flavorNotSaved | flavorSenderTranslated);
  114.     ThrowIfOSErr_(theErr);
  115. }    
  116.  
  117.  
  118. //
  119. // AddFlavorURL
  120. //
  121. // This flavor is used to communicate the current URL with other applications, such
  122. // as text editors, etc. It is basically the 'TEXT' flavor.
  123. //
  124. // No data is sent with this flavor, relying on a DoDragSendData() to get it out later.
  125. // This prevents us from running into an odd problem where the CTheadView class wants to
  126. // interpret the data as something that it isn't. This won't happen when no data is sent.
  127. //
  128. void
  129. CBrowserDragTask::AddFlavorURL(ItemReference inItemRef)
  130. {
  131.     // TEXT flavor (drag an URL within Netscape). Set flavorSenderTranslated
  132.     // so that the Finder *won't* try to put this in a clipping file.
  133.     // We'd rather save the file itself.
  134.  
  135.     OSErr theErr = ::AddDragItemFlavor(
  136.                                     mDragRef,
  137.                                     inItemRef,
  138.                                     'TEXT',
  139.                                     nil,
  140.                                     0,
  141.                                     flavorSenderTranslated);
  142.     ThrowIfOSErr_(theErr);
  143. }    
  144.  
  145. // ---------------------------------------------------------------------------
  146. //        Ñ AddFlavors
  147. // ---------------------------------------------------------------------------
  148.  
  149. void
  150. CBrowserDragTask::AddFlavors( DragReference inDragRef )
  151. {        
  152. // NOTE: I'm passing |this| as the item ref because that's the way it was in the past
  153. //            and i don't want to break anything.
  154.     AddFlavorBookmark(static_cast<ItemReference>(this));
  155.     AddFlavorBookmarkFile(static_cast<ItemReference>(this));
  156.     AddFlavorURL(static_cast<ItemReference>(this));
  157. }