// ================================================================================= // CSimlabEditListBox.cc ©1995 J. Rodden, DD/MF & Associates. All rights reserved // ================================================================================= // Common Code module for CSimlabConstListBox and CSimlabHierListBox // May not be suitable for young programmers. // // The following are a series of macro-ized common routines for the listboxes in // Simlab. Macro-ized routines were used to consolodate the common code in one // place and eliminate the hassles of supporting two sets of identical code. // // This tactic seemed the best way to deal with two classes that share a lot of // common routines yet have slightly different inheritance structures that couldn't // be resolved by multiple inheritance with virtual base class(es). // // There are two reasons why a virtual base class does not work well in this type of // situation: 1) FindPaneByID would be rendered useless because you cannot cast a // virtual base class into a derrived class (this problem should be alieviated by // RTTI). 2) Pane classes with virtual bases don't seem to work currently. // ================================================================================= #pragma once #ifndef __ListBoxClass #error __ListBoxClass is undefined #endif #ifndef __ListBoxParent #error __ListBoxParent is undefined #endif // ================================================================================= // € Destruct // ================================================================================= void __ListBoxClass::Destruct() { if (mEditFieldOwner) mEditFieldOwner->DetachEditField(); if (mEditField) delete mEditField; } // ================================================================================= // € SetupListBox // ================================================================================= void __ListBoxClass::SetupListBox() { __ListBoxParent::FinishCreateSelf(); mAllowDeleteKey = false; Point cellSize = { 16, (*mMacListH)->cellSize.h}; ::LCellSize( cellSize, mMacListH); SPaneInfo thePaneInfo = kSimlabEditBoxPaneInfo; thePaneInfo.superView = mSuperView; mEditFieldOwner = nil; mEditField = new LEditField( thePaneInfo, "\p0", Txtr_Geneva9, 255, true, false, ::RealField, this); } // ================================================================================= // € SelectOneCell // ================================================================================= void __ListBoxClass::SelectOneCell( Cell inCell) { DetachEditField(); __ListBoxParent::SelectOneCell(inCell); } // ================================================================================= // € ResizeFrameBy // ================================================================================= void __ListBoxClass::ResizeFrameBy( Int16 inWidthDelta, Int16 inHeightDelta, Boolean inRefresh) { __ListBoxParent::ResizeFrameBy( inWidthDelta, inHeightDelta, inRefresh); SDimension16 editFieldSize; mEditField->GetFrameSize(editFieldSize); mEditField->ResizeFrameTo( (**mMacListH).cellSize.h - kEditFieldPos, editFieldSize.height, inRefresh); } // ================================================================================= // € LDEFHiliteSelf // ================================================================================= void __ListBoxClass::LDEFHiliteSelf( Boolean lSelect, Rect *lRect, Cell lCell, short lDataOffset, short lDataLen, CSimlabEditListRec* inElementData) { if ( mEditFieldOwner == inElementData ) lRect->right = kEditFieldPos; __ListBoxParent::LDEFHilite( lSelect, lRect, lCell, lDataOffset, lDataLen ); } // ================================================================================= // € ClickSelf // ================================================================================= void __ListBoxClass::ClickSelf( const SMouseDownEvent &inMouseDown) { DetachEditField(); __ListBoxParent::ClickSelf(inMouseDown); } // ================================================================================= // € ClickInScrollBar // ================================================================================= // Hook to do something when scrollbar is clicked on, // default lets List Manager handle click in scrollbar void __ListBoxClass::ClickInScrollBar(Point& inLocalPt, short inModifiers) { Cell theCell; if ( GetLastSelectedCell(theCell) ) ::LDraw( theCell, mMacListH); __ListBoxParent::ClickInScrollBar( inLocalPt, inModifiers); } // ================================================================================= // € HandleDoubleClick // ================================================================================= // Hook to do something when a cell is double clicked on void __ListBoxClass::HandleDoubleClick( const Cell& inCell, const SMouseDownEvent& inMouseDown) { if ( inMouseDown.whereLocal.h > kEditFieldPos ) AssignEditField(inCell); __ListBoxParent::HandleDoubleClick( inCell, inMouseDown); } // ================================================================================= // € DetachEditField // ================================================================================= void __ListBoxClass::DetachEditField() { if (mEditFieldOwner) { mEditFieldOwner->DetachEditField(); mEditFieldOwner = nil; } } // ============================================================================ // € AssignEditFieldSelf // ============================================================================ void __ListBoxClass::AssignEditFieldSelf( Cell inCell, CSimlabEditListRec* inCellData) { FocusDraw(); Rect cellRect; ::LRect( &cellRect, inCell, mMacListH); cellRect.left = kEditFieldPos; ::EraseRect(&cellRect); mEditFieldOwner = inCellData; if (mEditFieldOwner) { mEditFieldOwner->AttachEditField(mEditField); mEditFieldOwner->DrawEditField( kEditFieldPos, cellRect.top); mEditField->SelectAll(); } }