home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / gui / CIconTextDragTask.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.2 KB  |  156 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. //
  20. // Interface for class that handles dragging an outline of an icon and descriptive text.
  21. // Will do translucent dragging if available (which it almost always should be). It makes
  22. // use of a helper class (CIconTextSuite) to handle building an icon suite and text caption.
  23. // I broke this out to allow more flexibility in how the suite is created (from a resource
  24. // file, from RDF backend, etc).
  25. //
  26. // Hopefully, this (or a derrivative) should be able to meet the needs of any drag and drop
  27. // behavior in the toolbars or the nav center instead of having us reinvent the wheel over
  28. // and over again.
  29. //
  30. // This rather poor first stab is enough functionality to get its first client (the personal
  31. // toolbar) working. It provides a caption to the right of the icon. Translucent
  32. // dragging is broken and commented out. Future versions will also support the ability to
  33. // drag multiple items.
  34. //
  35.  
  36. #pragma once
  37.  
  38.  
  39. #include "CBrowserDragTask.h"
  40. #include "cstring.h"
  41. #include "htrdf.h"
  42.  
  43.  
  44. class LCaption;
  45. class LDragTask;
  46. class LArray;
  47.  
  48.  
  49. //
  50. // CIconTextSuite
  51. //
  52. // A standalone class that is helpful in building a suite of icon and text caption. Classes
  53. // that use this don't need to know how the suite is created (resource, RDF backend, etc),
  54. // how the icon and the text go together (text beside icon, text below icon..), or even the
  55. // size of the icon (16x16, 32x32...)
  56. //
  57.  
  58. class CIconTextSuite {
  59.  
  60. public:
  61.     CIconTextSuite ( ) ;
  62.     CIconTextSuite ( LView* inParent, const Rect & inBounds, ResIDT inIconId, 
  63.                         const cstring & inIconText, const HT_Resource inHTNodeData = nil ) ;
  64.     CIconTextSuite ( const CIconTextSuite & other ) ;
  65.     virtual ~CIconTextSuite ( ) ;
  66.     
  67.     virtual Rect IconRectGlobal ( ) const;
  68.     virtual Rect IconRectLocal ( ) const;
  69.     virtual Rect TextRectGlobal ( ) const;
  70.     virtual Rect TextRectLocal ( ) const;
  71.     virtual Rect BoundingRect ( ) const;
  72.     
  73. //    virtual void DrawIcon ( ) const;
  74. //    virtual void DrawText ( ) const;
  75.     
  76.     // 
  77.     // Accessors/Mutators
  78.     //
  79. #if I_WASNT_IN_SUCH_A_HURRY_TO_CHECK_THIS_IN
  80.     void IconSuite ( Handle inIconSuite ) 
  81.         {  
  82.             ::DisposeIconSuite ( mIconSuite, true );
  83.             mIconSuite = inIconSuite;
  84.         };
  85.     Handle IconSuite ( ) const { return mIconSuite; } ;
  86.     void IconText ( const cstring & inIconText )  { mIconText = inIconText; } ;
  87.     cstring & IconText ( ) { return mIconText; } ;
  88.     LView* Parent ( ) const { return mParent; } ;
  89. #endif
  90.     
  91.     const HT_Resource GetHTNodeData ( ) const { return mHTNodeData; }
  92.     
  93.  protected:
  94.  
  95.     Handle mIconSuite;
  96.     cstring mIconText;
  97.     Rect mBounds;
  98.     LCaption* mDisplayText;
  99.     LView* mParent;
  100.     
  101.     const HT_Resource mHTNodeData;        // pointer to HT_Resource in RDF
  102.  
  103. }; // CIconTextSuite
  104.  
  105.  
  106. //
  107. // CIconTextDragTask
  108. //
  109. // Use this class when you need to drag a bookmark (or something url-ish) in the browser window. It
  110. // handles building the drag region and registering the appropriate drag flavors for all drag
  111. // items provided.
  112. //
  113. // The |inLocalFrame| parameter to the constructor is currently not used....soon it may just
  114. // become a point, but we'll see how the translucent dragging stuff goes after feature complete date...
  115. //
  116.  
  117. class CIconTextDragTask : public CBrowserDragTask
  118. {
  119. public:
  120.     typedef CBrowserDragTask super;
  121.     
  122.     CIconTextDragTask ( const EventRecord& inEventRecord, const LArray & inDragItems, 
  123.                             const Rect& inLocalFrame );
  124.     CIconTextDragTask ( const EventRecord& inEventRecord, const CIconTextSuite* inItem, 
  125.                             const Rect& inLocalFrame );
  126.     CIconTextDragTask ( const EventRecord& inEventRecord, const Rect& inLocalFrame );
  127.     virtual ~CIconTextDragTask ( ) ;
  128.     
  129.     // dispatch to do either normal or translucent dragging
  130.     virtual OSErr DoDrag();
  131.     
  132.     // for adding drag items one by one after drag task created
  133.     void AddDragItem ( const CIconTextSuite * inItem ) ;
  134.         // void AddDragItem ( const LArray & inItems ) ; maybe? probably not needed....
  135.     
  136. protected:
  137.  
  138.     virtual    void DoNormalDrag();
  139.     virtual    void DoTranslucentDrag();
  140.     
  141.     // coordinate with the multiple CIconTextSuites to create a drag region
  142.     virtual void MakeDragRegion ( DragReference inDragRef, RgnHandle inDragRegion ) ;
  143.  
  144.     // add drag flavor info for multiple items
  145.     virtual void AddFlavors ( DragReference inDragRef ) ;
  146.  
  147.     virtual void AddFlavorForItem ( DragReference inDragRef, ItemReference inItemRef,
  148.                                         const CIconTextSuite* inItem ) ;
  149.  
  150.     virtual void AddFlavorHTNode ( ItemReference inItemRef, const HT_Resource inNode ) ;
  151.     
  152.     Rect mFrame;
  153.     LArray mDragItems; 
  154.  
  155. }; // CIconTextDragTask
  156.