home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / Sessions / Traut / ZStrings / Source / MacOS / GraphicalTool / FileSelectionGroupView.cp < prev    next >
Encoding:
Text File  |  2001-06-23  |  3.6 KB  |  122 lines

  1. /*==================================================================
  2.     File:        FileSelectionGroupView.cp
  3.  
  4.     Contains:    Class that extends the standard PowerPlant
  5.                 group box to allow for drag and drop of files.
  6.  
  7.     Written by:    Eric Traut
  8.  
  9.     Copyright:    2000-2001 Connectix Corporation
  10.     
  11.     This source has been placed into the public domain by
  12.     Connectix Corporation. You have the right to modify, 
  13.     distribute or use this code without any legal limitations
  14.     or finanicial/licensing requirements. Connectix is not 
  15.     liable for any problems that result from the use of this 
  16.     code.
  17.     
  18.     If you have comments, feedback, questions, or would like
  19.     to submit bug fixes or updates to this code, please email
  20.     opensource@connectix.com.
  21. ==================================================================*/
  22.  
  23. #include "FileSelectionGroupView.h"
  24.  
  25. #include <Drag.h>
  26.  
  27.  
  28. // ---------------------------------------------------------------------------
  29. //    • FileSelectionGroupView                Stream Constructor          [public]
  30. // ---------------------------------------------------------------------------
  31.  
  32. FileSelectionGroupView::FileSelectionGroupView(
  33.     LStream *        inStream)
  34.     :    LTextGroupBox(inStream),
  35.         LDragAndDrop(LPane::GetDefaultView()->GetMacPort(), this)
  36. {
  37.     
  38. }
  39.         
  40.  
  41. // ---------------------------------------------------------------------------
  42. //    • ~FileSelectionGroupView                Destructor                  [public]
  43. // ---------------------------------------------------------------------------
  44.  
  45. FileSelectionGroupView::~FileSelectionGroupView()
  46. {
  47. }
  48.  
  49.  
  50. // ---------------------------------------------------------------------------
  51. //    • ItemIsAcceptable                                            [protected]
  52. // ---------------------------------------------------------------------------
  53.  
  54. Boolean
  55. FileSelectionGroupView::ItemIsAcceptable(
  56.     DragReference        inDragRef,
  57.     ItemReference        inItemRef)
  58. {
  59.     HFSFlavor            hfsFlavor;
  60.     Size                dragDataSize = sizeof(HFSFlavor);
  61.     Boolean                itemIsOK = false;
  62.  
  63.     if (::GetFlavorData(inDragRef, inItemRef, flavorTypeHFS, &hfsFlavor, &dragDataSize, 0) == noErr)
  64.     {
  65.         // An HFS flavor of 'MACS' indicates it's a file system construct
  66.         // other than a file (e.g. a directory or volume). We're only interested
  67.         // in files.
  68.         itemIsOK = (hfsFlavor.fileCreator != 'MACS');
  69.     }
  70.  
  71.     return itemIsOK;
  72. }
  73.  
  74.  
  75. // ---------------------------------------------------------------------------
  76. //    • HiliteDropArea                                               [protected]
  77. // ---------------------------------------------------------------------------
  78. //    We override this method so we can specify a slightly different
  79. //    hilite area.
  80.  
  81. void
  82. FileSelectionGroupView::HiliteDropArea(
  83.     DragReference    inDragRef)
  84. {
  85.     mPane->ApplyForeAndBackColors();
  86.  
  87.     Rect    dropRect;
  88.     mPane->CalcLocalFrameRect(dropRect);
  89.     dropRect.top += 9;
  90.     ::MacInsetRect(&dropRect, 3, 3);
  91.     StRegion    dropRgn(dropRect);
  92.     
  93.     ::ShowDragHilite(inDragRef, dropRgn, true);
  94. }
  95.  
  96.  
  97. // ---------------------------------------------------------------------------
  98. //    • ReceiveDragItem                                               [protected]
  99. // ---------------------------------------------------------------------------
  100.  
  101. void
  102. FileSelectionGroupView::ReceiveDragItem(
  103.     DragReference        inDragRef,
  104.     DragAttributes        inDragAttrs,
  105.     ItemReference        inItemRef,
  106.     Rect &                inItemBounds)
  107. {
  108.     #pragma unused (inDragAttrs, inItemBounds)
  109.  
  110.     HFSFlavor            hfsFlavor;
  111.     Size                dragDataSize = sizeof(HFSFlavor);
  112.     Boolean                itemIsOK = false;
  113.  
  114.     // Send a message indicating the drop occurred. We're mixing
  115.     // metaphores a little here by assuming the pane ID should be
  116.     // used as the message, but that's OK.
  117.     if (::GetFlavorData(inDragRef, inItemRef, flavorTypeHFS, &hfsFlavor, &dragDataSize, 0) == noErr)
  118.         BroadcastMessage(GetPaneID(), &hfsFlavor.fileSpec);
  119. }
  120.  
  121.  
  122.