Link to: header | tables
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CTableTitleBar
This class manages table title bars for the Goldenseal
estimating software,
small business management software, construction
project management software and
construction estimating software.
It's the title bar at the top of a table
SUPERCLASS = CTCS_View, CTCS_Listener
Constructor
/*********************************************************************************
CTableTitleBar constructor from stream
*********************************************************************************/
CTableTitleBar::CTableTitleBar(LStream *inStream)
: CTCS_View(inStream)
{
mTableRef = nil;
mIsOffscreen = false;
}
/*********************************************************************************
CTableTitleBar default constructor
*********************************************************************************/
CTableTitleBar::CTableTitleBar()
: CTCS_View(CTCS_Pane::sDefaultPaneInfo, sDefaultViewInfo)
{
mTableRef = nil;
mIsOffscreen = false;
}
Source Code
/*********************************************************************************
SetTable
set the table used by this title bar
*********************************************************************************/
void CTableTitleBar::SetTable(CTCS_Table *aTable)
{
// sanity check
TCS_FailNILMsg(aTable, TCS_GetErrString(errID_BadTable));
// if this is the same table we have already, we just return
if (aTable == mTableRef)
return;
// update our member, and listen to the table
mTableRef = aTable;
mTableRef->AddListener(this);
// set up the captions
RecalcCaptionPositions();
}
/*********************************************************************************
SetColumnTitle TCS 10/7/02
set the title for the given column
*********************************************************************************/
void CTableTitleBar::SetColumnTitle(const TableIndexT column, const CTextString &title)
{
SInt32 paneID = cTitleBarBaseID + column - 1;
CTableColumnCaption *caption = TCS_SAFE_CAST(FindPaneByID(paneID), CTableColumnCaption);
if (caption)
caption->SetCString(title);
}
/*********************************************************************************
RecalcCaptionPositions
recalculate the positions of the captions in the title bar
*********************************************************************************/
void CTableTitleBar::RecalcCaptionPositions()
{
// can't recalculate if no table
if (!mTableRef)
return;
// walk through the columns of the table,
// and resize each caption
SInt32 colLeft = 0,
colWidth;
CTableColumnCaption *caption;
SPaneInfo paneInfo = CTCS_Pane::sDefaultPaneInfo;
CTCS_TextInfo colTextInfo;
paneInfo.superView = this;
for (SInt32 col = 1; col <= mTableRef->GetNumCols(); col++)
{
paneInfo.paneID = cTitleBarBaseID + col - 1;
caption = TCS_SAFE_CAST(FindPaneByID(paneInfo.paneID), CTableColumnCaption);
if (!caption)
{ // couldn't find the caption, attempt to create one
mTableRef->GetColTextInfo(col, &colTextInfo);
caption = NEW CTableColumnCaption(paneInfo, colTextInfo,
mTableRef->GetColTitle(col));
TCS_FailNILMsg(caption, TCS_GetErrString(errID_BadName));
caption->FinishCreate();
caption->SetTable(mTableRef);
}
// we should have a caption by now
TCS_FailNILMsg(caption, TCS_GetErrString(errID_BadName));
// resize and position the caption.
// Note that if we don't get a caption that's ok; it just
// means that the table associated with this titlebar has
// no titles
colWidth = mTableRef->GetColWidth(col);
caption->ResizeFrameTo(colWidth, mFrameSize.height - 1, false);
caption->PlaceInSuperImageAt(colLeft, -1, false);
colLeft += colWidth;
}
}
/*********************************************************************************
ListenToMessage
respond to a message
*********************************************************************************/
void CTableTitleBar::ListenToMessage(MessageT inMessage, void *ioParam)
{
switch (inMessage)
{
case msg_TableColumnsResized:
{ // a column resized message, let's make sure
// this was sent by our table
TCS_ASSERTMsg(ioParam == mTableRef, TCS_GetErrString(errID_BadTable));
// ok, it was our table, resize the captions
RecalcCaptionPositions();
}
break;
}
// there's nothing to pass this along to
}
/*********************************************************************************
WriteTextToOutputStream TCS 12/2/99
write text to a stream. Used for 'save as text'
*********************************************************************************/
void CTableTitleBar::WriteTextToOutputStream(CTextOutputStream &stream)
{
// can't fill titles if no table
if (!mTableRef)
return;
TableIndexT lastCol = mTableRef->GetNumCols();
CTextString titleText;
CTCS_Caption *caption;
SPaneInfo paneInfo = CTCS_Pane::sDefaultPaneInfo;
paneInfo.superView = this;
// fetch title for each column
for (TableIndexT col = 1; col <= lastCol; col++)
{
paneInfo.paneID = cTitleBarBaseID + col - 1;
caption = TCS_SAFE_CAST(FindPaneByID(paneInfo.paneID), CTCS_Caption);
if (caption)
{
// we have a caption, so fetch text from it
titleText = caption->GetCString();
}
else
{ // no caption, so the table can provide the text
titleText = mTableRef->GetColTitle(col);
}
// write the title to the stream
stream.WriteString(titleText);
}
// finish the line
stream.WriteEndOfLine();
}
/*********************************************************************************
MoveOffscreen TCS 11/20/00
move the title bar to offscreen position
*********************************************************************************/
void CTableTitleBar::MoveOffscreen(const Boolean inValue)
{
// sanity check
if (inValue && !mIsOffscreen)
{
MoveBy(0, -50, cRedraw);
}
else if (!inValue && mIsOffscreen)
{
MoveBy(0, 50, cRedraw);
}
mIsOffscreen = inValue;
}
/*********************************************************************************
DrawSelf
draw the title bar
*********************************************************************************/
void CTableTitleBar::DrawSelf()
{
// can't draw anything if there's no table or if we're offscreen
if (!mTableRef || mIsOffscreen)
return;
// Set up the pen
TStColorPenState penSaver;
penSaver.Normalize();
Boolean isEnabled = true; // rev TCS 1/24/01
if (mTableRef)
isEnabled = mTableRef->IsEnabled() && mTableRef->TableCanBeChanged();
if (!isEnabled)
TCS_SetForegroundColor(CTCS_RGBColor::GetGrayColor());
// walk through the table columns, and draw a vertical line to
// the right of each column in the title bar
SInt32 colLeft = 0;
for (SInt32 i = 2; i <= mTableRef->GetNumCols(); i++)
{
colLeft += mTableRef->GetColWidth(i - 1);
TCS_DrawLine(colLeft, 0, colLeft, mFrameSize.height);
}
// draw a horizontal line at the bottom
TCS_PenSize(2, 2);
TCS_DrawLine(0, mFrameSize.height - 2, mFrameSize.width,
mFrameSize.height - 2);
}
/*********************************************************************************
PrintPanelSelf TCS 10/18/00
print the title bar. We override the draw method, since we do NOT want lines
*********************************************************************************/
void CTableTitleBar::PrintPanelSelf(const PanelSpec &/*inPanel*/)
{
}
|