// ================================================================================= // CSimlabHierListBox.cp ©1995 J. Rodden, DD/MF & Associates. All rights reserved // ================================================================================= #include #include "RuntimeMessages.h" #include "RuntimeResources.h" #include "CSimlabListRec.h" #include "CSimlabHierListBox.h" #include // ================================================================================= // € CreateFromStream // ================================================================================= CSimlabHierListBox* CSimlabHierListBox::CreateFromStream (LStream *inStream) { return (new CSimlabHierListBox(inStream)); } // ================================================================================= // € CSimlabHierListBox(LStream *inStream) // ================================================================================= CSimlabHierListBox::CSimlabHierListBox(LStream *inStream) : CHierListBox(inStream), mSublists(sizeof(LList*)) { } // ================================================================================= // € ~CSimlabHierListBox() // ================================================================================= CSimlabHierListBox::~CSimlabHierListBox() { LList* theList = nil; short num = mSublists.GetCount(); for ( short i = 1; i <= num; i++) { mSublists.FetchItemAt( i, &theList); delete theList; } } // ================================================================================= // € FinishCreateSelf // ================================================================================= void CSimlabHierListBox::FinishCreateSelf() { CHierListBox::FinishCreateSelf(); Point cellSize = { 16, (*mMacListH)->cellSize.h}; ::LCellSize( cellSize, mMacListH); for ( short i = 1; i <= 3; i++) { LList* newList = new LList(sizeof(Str255)); mSublists.InsertItemsAt( 1, arrayIndex_Last, &newList); } mAcceptsInternalDrags = false; mDrawInsertionLine = false; } // ================================================================================= // € AddSubListElement // ================================================================================= void CSimlabHierListBox::AddSubListElement(short inListNum, Str255 inString) { LList* theList = nil; mSublists.FetchItemAt( inListNum, &theList); if ( theList != nil ) theList->InsertItemsAt( 1, arrayIndex_Last, inString); } // ================================================================================= // € HandleDoubleClick // ================================================================================= // Hook to do something when a cell is double clicked on void CSimlabHierListBox::HandleDoubleClick( const Cell& inCell, const SMouseDownEvent& inMouseDown) { SimlabListTag theTag = ((CSimlabListRec*)GetElementData(inCell))->GetTag(); MessageT theMessage = msg_Nothing; short elementIndex = ( GetElementIndent(inCell) > 0 ) ? GetElementSubIndex(inCell) : 0; switch (theTag) { case tagDescription: if ( elementIndex > 0 ) theMessage = msg_OpenSourceFile; break; case tagSetting: if ( elementIndex > 0 ) theMessage = msg_OpenSettings; break; case tagGraph: if ( elementIndex > 0 ) theMessage = msg_OpenGraph; break; case tagInput: if ( elementIndex == 0 ) theMessage = cmd_ModelInputsWin; break; case tagState: if ( elementIndex == 0 ) theMessage = cmd_StateVarsWin; break; case tagOutput: if ( elementIndex == 0 ) theMessage = cmd_ModelOutputsWin; break; } if ( theMessage != msg_Nothing ) { if (mBroadcastDblClkModifiers) PackModifiersInMessage(theMessage,inMouseDown); BroadcastMessage( theMessage, &elementIndex); } else { CHierListBox::HandleDoubleClick(inCell,inMouseDown); } } // ================================================================================= // € DrawElementData // ================================================================================= void CSimlabHierListBox::DrawElementData( Boolean lSelect, Rect* lRect, Cell lCell, short lDataLen) { CSimlabListRec* theElementData = (CSimlabListRec*) GetElementData(lCell); short indent = GetElementIndent(lCell); if ( indent == 0 ) { ::TextFace(bold); } theElementData->Draw(lRect); } // ================================================================================= // € ExpandElement // ================================================================================= void CSimlabHierListBox::ExpandElement(const Cell& inCell, void* inUserData) { SimlabListTag theTag = ((CSimlabListRec*) inUserData)->GetTag(); short theListIdx = 0; switch ( theTag ) { case tagInput: case tagDescription: theListIdx = 1; break; case tagState: case tagSetting: theListIdx = 2; break; case tagOutput: case tagGraph: theListIdx = 3; break; } if ( theListIdx != 0 ) { LList* theList = nil; mSublists.FetchItemAt( theListIdx, &theList); if ( theList != nil ) { short indent = GetElementIndent(inCell) + 1; short num = theList->GetCount(); Cell theCell = inCell; for ( short i = 1; i <= num ; i++, theCell.v++) { Str255 theString; theList->FetchItemAt( i, theString); CSimlabListRec* newElement = CreateNewListRec( theTag, theString); AddElementData( theCell, (void*) newElement, false, indent); } } } } // ================================================================================= // € CreateNewListRec // ================================================================================= CSimlabListRec* CSimlabHierListBox::CreateNewListRec( SimlabListTag theTag, Str255 theString) { return new CSimlabListRec( theTag, theString); } // =================================================================================