// ================================================================================= // CFSSpecListBox.cp ©1995 J. Rodden, DD/MF & Associates. All rights reserved // ================================================================================= #include "CFSSpecListBox.h" #include #include #include // --------------------------------------------------------------------------------- // € CreateFromStream // --------------------------------------------------------------------------------- CFSSpecListBox* CFSSpecListBox::CreateFromStream( LStream *inStream ) { return (new CFSSpecListBox(inStream)); } // --------------------------------------------------------------------------------- // € CFSSpecListBox // --------------------------------------------------------------------------------- CFSSpecListBox::CFSSpecListBox() : CDDListBox(), mFileTypeList(sizeof(OSType)) { } // --------------------------------------------------------------------------------- // € CFSSpecListBox(LStream*) // --------------------------------------------------------------------------------- CFSSpecListBox::CFSSpecListBox( LStream *inStream ) : CDDListBox(inStream), mFileTypeList(sizeof(OSType)) { } // ================================================================================= // € FinishCreateSelf // ================================================================================= void CFSSpecListBox::FinishCreateSelf() { CDDListBox::FinishCreateSelf(); mAcceptFolders = kAcceptFolder | kOpenFolder; mFlavorAccepted = flavorTypeHFS; mUseDefaultRect = true; } // --------------------------------------------------------------------------------- // € AddFileType // --------------------------------------------------------------------------------- // Add to the list of file types accepted as drop items void CFSSpecListBox::AddFileType(OSType inType) { mFileTypeList.InsertItemsAt( 1, arrayIndex_Last, &inType); } // --------------------------------------------------------------------------------- // € RemoveFileType // --------------------------------------------------------------------------------- // Remove from the list of file types accepted as drop items void CFSSpecListBox::RemoveFileType(OSType inType) { short num = mFileTypeList.GetCount(); for ( short i = 1; i <= num; i++ ) { OSType theType; mFileTypeList.FetchItemAt( i, &theType); if ( theType != inType ) continue; else { mFileTypeList.RemoveItemsAt( 1, i); return; } } } // --------------------------------------------------------------------------------- // € AddRowElement // --------------------------------------------------------------------------------- // Adds a new item to the end of the list. void CFSSpecListBox::AddRowElement(const FSSpec& inFSSpec, Cell& inCell) { CBetterListBox::AddRowElement( &inFSSpec, sizeof(FSSpec), inCell); } // --------------------------------------------------------------------------------- // € AddColElement // --------------------------------------------------------------------------------- // Adds a new item to the end of the list. void CFSSpecListBox::AddColElement(const FSSpec& inFSSpec, Cell& inCell) { CBetterListBox::AddColElement( &inFSSpec, sizeof(FSSpec), inCell); } // --------------------------------------------------------------------------------- // € CopyCell // --------------------------------------------------------------------------------- // You MUST override this routine in order to do internal list dragging void CFSSpecListBox::CopyCell( Cell inSrcCell, Cell inDestCell) { FSSpec theFSSpec; short theSize = sizeof(FSSpec); ::LGetCell( &theFSSpec, &theSize, inSrcCell, mMacListH); ::LSetCell( &theFSSpec, theSize, inDestCell, mMacListH); } // --------------------------------------------------------------------------- // € GetDescriptor // --------------------------------------------------------------------------- FSSpec* CFSSpecListBox::GetDescriptor( FSSpec& outFSSpec) const { Cell firstSelection = {0, 0}; if (::LGetSelect(true, &firstSelection, mMacListH)) { Int16 dataLen = sizeof(FSSpec); ::LGetCell(&outFSSpec, &dataLen, firstSelection, mMacListH); } return &outFSSpec; } // --------------------------------------------------------------------------------- // € LDEFHilite // --------------------------------------------------------------------------------- void CFSSpecListBox::LDEFHilite( Boolean lSelect, Rect *lRect, Cell lCell, short lDataOffset, short lDataLen ) { FSSpec theFSSpec; short dataLen = sizeof(FSSpec); ::LGetCell( &theFSSpec, &dataLen, lCell, mMacListH); lRect->left += kTextGap; lRect->right = lRect->left + StringWidth(theFSSpec.name) + 2 * kTextSelSlop; CBetterListBox::LDEFHilite( lSelect, lRect, lCell, lDataOffset, lDataLen ); } // --------------------------------------------------------------------------------- // € DrawElementSelf // --------------------------------------------------------------------------------- void CFSSpecListBox::DrawElementSelf( Boolean lSelect, Rect *lRect, Cell lCell, short lDataLen ) { FontInfo fInfo; ::GetFontInfo( &fInfo); FSSpec theFSSpec; ::LGetCell(&theFSSpec, &lDataLen, lCell, mMacListH); Int16 textBottom = (lRect->bottom - lRect->top)/2 - fInfo.ascent/2; ::EraseRect(lRect); ::MoveTo( lRect->left + kTextGap + kTextSelSlop, lRect->bottom - textBottom); ::DrawText( theFSSpec.name, 1, theFSSpec.name[0]); lRect->left += kTextGap; lRect->right = lRect->left + StringWidth(theFSSpec.name) + 2 * kTextSelSlop; } // --------------------------------------------------------------------------------- // € HFSItemIsAcceptable // --------------------------------------------------------------------------------- Boolean CFSSpecListBox::HFSItemIsAcceptable(HFSFlavor& inHFSFlavorData, Boolean& inTargetIsFolder) { // If the file type array is not empty, we want to restrict which file types are // accepted, otherwise just let the inheited routine do its thing. short num = mFileTypeList.GetCount(); for ( short i = 1; i <= num; i++ ) { OSType theType; mFileTypeList.FetchItemAt( i, &theType); if ( theType != inHFSFlavorData.fileType && !( IsBitOn( mAcceptFolders, kAcceptFolder) && inTargetIsFolder ) ) continue; else return true; } return true; } // --------------------------------------------------------------------------------- // € DrawDragRegion // --------------------------------------------------------------------------------- // Draw into the drag region, default does nothing void CFSSpecListBox::DrawDragRegion () { short visibleTop, cellHeight; Rect cellRect; Cell theCell = {0, 0}; FSSpec curItem; short lDataLen = sizeof (FSSpec); if (::LGetSelect(true, &theCell, mMacListH)) { ::LGetCell( &curItem, &lDataLen, theCell, mMacListH ); ::LRect( &cellRect, theCell, mMacListH); LocalToPortPoint(topLeft(cellRect)); LocalToPortPoint(botRight(cellRect)); PortToGlobalPoint(topLeft(cellRect)); PortToGlobalPoint(botRight(cellRect)); cellRect.left += kTextGap; cellRect.right = cellRect.left + StringWidth (curItem.name) + 2 * kTextSelSlop; cellRect.top += 1; cellRect.bottom -= 1; ::FrameRect( &cellRect ); } }