home *** CD-ROM | disk | FTP | other *** search
- /*==================================================================
- File: FileSelectionGroupView.cp
-
- Contains: Class that extends the standard PowerPlant
- group box to allow for drag and drop of files.
-
- Written by: Eric Traut
-
- Copyright: 2000-2001 Connectix Corporation
-
- This source has been placed into the public domain by
- Connectix Corporation. You have the right to modify,
- distribute or use this code without any legal limitations
- or finanicial/licensing requirements. Connectix is not
- liable for any problems that result from the use of this
- code.
-
- If you have comments, feedback, questions, or would like
- to submit bug fixes or updates to this code, please email
- opensource@connectix.com.
- ==================================================================*/
-
- #include "FileSelectionGroupView.h"
-
- #include <Drag.h>
-
-
- // ---------------------------------------------------------------------------
- // • FileSelectionGroupView Stream Constructor [public]
- // ---------------------------------------------------------------------------
-
- FileSelectionGroupView::FileSelectionGroupView(
- LStream * inStream)
- : LTextGroupBox(inStream),
- LDragAndDrop(LPane::GetDefaultView()->GetMacPort(), this)
- {
-
- }
-
-
- // ---------------------------------------------------------------------------
- // • ~FileSelectionGroupView Destructor [public]
- // ---------------------------------------------------------------------------
-
- FileSelectionGroupView::~FileSelectionGroupView()
- {
- }
-
-
- // ---------------------------------------------------------------------------
- // • ItemIsAcceptable [protected]
- // ---------------------------------------------------------------------------
-
- Boolean
- FileSelectionGroupView::ItemIsAcceptable(
- DragReference inDragRef,
- ItemReference inItemRef)
- {
- HFSFlavor hfsFlavor;
- Size dragDataSize = sizeof(HFSFlavor);
- Boolean itemIsOK = false;
-
- if (::GetFlavorData(inDragRef, inItemRef, flavorTypeHFS, &hfsFlavor, &dragDataSize, 0) == noErr)
- {
- // An HFS flavor of 'MACS' indicates it's a file system construct
- // other than a file (e.g. a directory or volume). We're only interested
- // in files.
- itemIsOK = (hfsFlavor.fileCreator != 'MACS');
- }
-
- return itemIsOK;
- }
-
-
- // ---------------------------------------------------------------------------
- // • HiliteDropArea [protected]
- // ---------------------------------------------------------------------------
- // We override this method so we can specify a slightly different
- // hilite area.
-
- void
- FileSelectionGroupView::HiliteDropArea(
- DragReference inDragRef)
- {
- mPane->ApplyForeAndBackColors();
-
- Rect dropRect;
- mPane->CalcLocalFrameRect(dropRect);
- dropRect.top += 9;
- ::MacInsetRect(&dropRect, 3, 3);
- StRegion dropRgn(dropRect);
-
- ::ShowDragHilite(inDragRef, dropRgn, true);
- }
-
-
- // ---------------------------------------------------------------------------
- // • ReceiveDragItem [protected]
- // ---------------------------------------------------------------------------
-
- void
- FileSelectionGroupView::ReceiveDragItem(
- DragReference inDragRef,
- DragAttributes inDragAttrs,
- ItemReference inItemRef,
- Rect & inItemBounds)
- {
- #pragma unused (inDragAttrs, inItemBounds)
-
- HFSFlavor hfsFlavor;
- Size dragDataSize = sizeof(HFSFlavor);
- Boolean itemIsOK = false;
-
- // Send a message indicating the drop occurred. We're mixing
- // metaphores a little here by assuming the pane ID should be
- // used as the message, but that's OK.
- if (::GetFlavorData(inDragRef, inItemRef, flavorTypeHFS, &hfsFlavor, &dragDataSize, 0) == noErr)
- BroadcastMessage(GetPaneID(), &hfsFlavor.fileSpec);
- }
-
-
-