// =========================================================================== // CSimlabListBox.cp // ©1995 J. Rodden, DD/MF & Associates. All rights reserved // =========================================================================== #include "RuntimeResources.h" #include "CSimlabListBox.h" #include // ============================================================================ const short kEditFieldPos = 110; // ============================================================================ #define __ListBoxClass CSimlabListBox #define __ListBoxParent CDDListBox #include "CSimlabEditListBox.cc" // ============================================================================ // € CreateFromStream // ============================================================================ CSimlabListBox* CSimlabListBox::CreateFromStream(LStream *inStream) { return (new CSimlabListBox(inStream)); } // ============================================================================ // € CSimlabListBox(LStream*) // ============================================================================ CSimlabListBox::CSimlabListBox( LStream *inStream) : CDDListBox (inStream) { } // ============================================================================ // € ~CSimlabListBox // ============================================================================ CSimlabListBox::~CSimlabListBox () { ClearDisplay(); Destruct(); } // ============================================================================ // € FinishCreateSelf // ============================================================================ void CSimlabListBox::FinishCreateSelf() { SetupListBox(); mFlavorAccepted = 0L; } // ================================================================================= // € ClearDisplay // ================================================================================= void CSimlabListBox::ClearDisplay(Int16 inEmptyStrResID) { SetEmptyStringID(inEmptyStrResID); Cell theCell = { 0, 0}; CSimlabEditListRec* theCellData = nil; short dataLen = sizeof(CSimlabEditListRec*); DetachEditField(); FocusDraw(); ::LSetDrawingMode( false, mMacListH); while ( (**mMacListH).dataBounds.bottom > 0 ) { ::LGetCell( &theCellData, &dataLen, theCell, mMacListH); ::LDelRow( 1, theCell.v, mMacListH); if ( theCellData != nil ) delete theCellData; } ::LSetDrawingMode( true, mMacListH); Refresh(); } // ============================================================================ // € AppendElement // ============================================================================ void CSimlabListBox::AppendElement( ConstStr255Param inString, SimlabListTag inTag) { Cell theCell = { -1, -1}; CSimlabEditListRec* theCellData = new CSimlabEditListRec( inTag, inString); FocusDraw(); AddRowElement( &theCellData, sizeof(CSimlabEditListRec*), theCell); } // ============================================================================ // € SetEmptyStringID // ============================================================================ void CSimlabListBox::SetEmptyStringID(Int16 inEmptyStrResID) { mListEmptyString = inEmptyStrResID; } // ============================================================================ // € LDEFHilite // ============================================================================ void CSimlabListBox::LDEFHilite( Boolean lSelect, Rect *lRect, Cell lCell, short lDataOffset, short lDataLen ) { CSimlabEditListRec* theElementData = nil; ::LGetCell( &theElementData, &lDataLen, lCell, mMacListH ); LDEFHiliteSelf( lSelect, lRect, lCell, lDataOffset, lDataLen, theElementData); } // ============================================================================ // € DrawSelf // ============================================================================ void CSimlabListBox::DrawSelf() { CDDListBox::DrawSelf(); if ( (**mMacListH).dataBounds.bottom != 0 || mListEmptyString == 0 ) return; Str255 theString; FocusDraw(); ::MoveTo(kCellLeft,12); ::TextFace(italic); ::GetIndString( theString, STRx_App_Strs, mListEmptyString); ::DrawString(theString); } // ============================================================================ // € DrawElementSelf // ============================================================================ void CSimlabListBox::DrawElementSelf( Boolean lSelect, Rect *lRect, Cell lCell, short lDataLen ) { CSimlabEditListRec* theElementData = nil; ::LGetCell( &theElementData, &lDataLen, lCell, mMacListH ); if ( theElementData != nil ) { switch ( theElementData->GetTag() ) { case tagConstant: ::TextFace(normal); break; case tagSetupVar: ::TextFace(italic); break; } theElementData->Draw( lRect, kEditFieldPos); } } // ============================================================================ // € AssignEditField // ============================================================================ void CSimlabListBox::AssignEditField( Cell inCell) { CSimlabEditListRec* theCellData; short dataLen = sizeof(CSimlabEditListRec*); ::LGetCell( &theCellData, &dataLen, inCell, mMacListH); AssignEditFieldSelf( inCell, theCellData); } // ============================================================================ // € DrawDragRegion // ============================================================================ // Draw into the drag region, default does nothing void CSimlabListBox::DrawDragRegion () { //::FrameRect(&mLocalFrame); } // ============================================================================ // € AddFlavors // ============================================================================ // Add flavored items to the DragTask. void CSimlabListBox::AddFlavors(DragReference inDragRef) { InstallDragSendData(inDragRef); ::AddDragItemFlavor(inDragRef, kItemRef, 'TEXT', 0L, 0L, 0L); ::AddDragItemFlavor(inDragRef, kItemRef, SimlabDragFlavor, 0L, 0L, 0L); } // ============================================================================ // € DoDragSendData // ============================================================================ // Send a columnized listing of the constants and their values void CSimlabListBox::DoDragSendData( FlavorType inFlavor, ItemReference inItemRef, DragReference inDragRef) { Str255 theString; LHandleStream theDragSendData; Cell theCell = { 0, 0}; short dataLen = sizeof(CSimlabEditListRec*); CSimlabEditListRec* theCellData; do { // Generate a columnized listing of the constants ::LGetCell( &theCellData, &dataLen, theCell, mMacListH); theCellData->GetDescriptor(theString); theString[++theString[0]] = 0x0D; // Carrage Return theDragSendData.WriteData( &theString[1], theString[0]); } while ( ::LNextCell( true, true, &theCell, mMacListH ) ); // Place the listing in the drag data Handle dragSendData = theDragSendData.GetDataHandle(); ::HLock(dragSendData); ::SetDragItemFlavorData( inDragRef, inItemRef, 'TEXT', *dragSendData, GetHandleSize(dragSendData), 0L); ::HUnlock(dragSendData); }