Link to: header | tables
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CTextListTable
This class manages text list tables for the Goldenseal
estimating software,
small business management software, construction
project management software and
construction estimating software.
It's a table which displays a list of text items as a single pane. It is used for
the list editor, in a few dialog displays, and as the parent for clairvoyant
field tables.
Data is stored in an array of SNameIDInfo structs. That limits this table
to a single column, with a maximum of 31 characters in each row.
HINT-- If you want to display more than 31 characters in a row, use a
CTextWindow instead.
Superclasses: CTCS_Table
Constructor
/******************************************************************************
Stream constructor v1.0, 05-05-97 rev TCS 12/11/00
******************************************************************************/
CTextListTable::CTextListTable(LStream *inStream)
: THE_SUPERCLASS(inStream)
{
Boolean draggable;
inStream->ReadData(&mUseSystemHilite, sizeof(Boolean));
inStream->ReadData(&draggable, sizeof(Boolean));
SetIsDraggable(draggable);
SetCanBeTarget(true); // TCS 1/30/03
}
/******************************************************************************
Param constructor v1.1.2, 12-30-96, 08-22-97 rev TCS 12/11/00
******************************************************************************/
CTextListTable::CTextListTable(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo,
const CTCS_TextInfo & inTextInfo,
const Boolean inSysHilite, const Boolean inCanRearrange)
: THE_SUPERCLASS(inPaneInfo, inViewInfo)
{
TStTextState textSaver;
SetTextInfo(inTextInfo);
InsertCols(1, mFrameSize.width);
// Set the row height based on font height
CTCS_TextInfo::SetPortTextInfo(inTextInfo);
SetRowHeight(TCS_GetTextHeight());
// Set the special options
mUseSystemHilite = inSysHilite;
SetIsDraggable(inCanRearrange);
SetCanBeTarget(true); // TCS 1/30/03
}
Source Code
/******************************************************************************
InsertRows
Append rows to the end of the table v1.0.3, 12-31-96, 08-22-97
******************************************************************************/
void CTextListTable::InsertRows(const TableIndexT howMany, const Boolean redraw)
{
SNameIDInfo info;
info.id = 0;
info.itemName[0] = nil;
SCellFormatInfo cellInfo;
// Do the normal insertion
THE_SUPERCLASS::InsertRows(howMany, redraw);
// Append entries to mListItems array
mListItems.InsertItemsAt(howMany, LArray::index_Last, info);
cellInfo.textInfo = GetTextInfo();
cellInfo.enabled = true;
for (int i = 0; i < howMany; i++)
mCellInfo.Append(cellInfo);
}/******************************************************************************
RemoveRows
Remove rows from the table v1.2.2, 12-31-96, 08-22-97
******************************************************************************/
void CTextListTable::RemoveRows(const TableIndexT howMany, const Boolean redraw)
{
// Do the normal removal
THE_SUPERCLASS::RemoveRows(howMany, redraw);
// we also need to adjust our data and cell format arrays
mListItems.RemoveItemsAt(howMany, mRows + 1);
mCellInfo.RemoveItemsAt(howMany, mRows + 1);
}/******************************************************************************
AppendItem
Append an item to the table v1.0.2, 12-31-96, 01-22-97
******************************************************************************/
void CTextListTable::AppendItem(const CTextString & inText, const SInt32 inID)
{
InsertRow();
SetCellText(LastRow(), 1, inText);
SetCellID(LastRow(), 1, inID);
}/******************************************************************************
AppendClassName TCS 7/6/99 rev 7/22/99 renamed 10/18/99 rev 8/21/01
Append the name of the given class to the table
******************************************************************************/
void CTextListTable::AppendClassName(const SInt32 inID, const Boolean allItems)
{
CTextString className = DB_ClassDescriptor::GetClassNamePlural(inID);
if (allItems)
className.PrependWithSpace(TCS_GetStockString(stockID_All));
AppendItem(className, inID);
}/******************************************************************************
DeleteItem v1.0.1, 05-06-97, 08-22-97
Delete a specific item from the table
******************************************************************************/
void CTextListTable::DeleteItem(const TableIndexT inRow, const Boolean inRedraw)
{
// Do the normal removal
THE_SUPERCLASS::RemoveRows(1, inRedraw);
// Remove the item from the list
mListItems.RemoveItemsAt(1, inRow);
mCellInfo.RemoveItemsAt(1, inRow);
RefreshRows(inRow, LastRow());
// Update the selected cell if necessary & force selection into view
if (ROW(mSelectedCell) > LastRow())
CTCS_Table::SelectCell(LastRow(), 1);
RectifySelectionPosition(inRedraw);
}
#if CAN_USE_MARK
#pragma mark -
#endif
/******************************************************************************
HandleCellDrag v1.0.1, 05-13-97, 08-22-97
Rearrange the table(swap 2 items)
******************************************************************************/
void CTextListTable::HandleCellDrag(const TableCellT & sourceCell,
const TableCellT & targetCell)
{
SInt32 sourceRow = ROW(sourceCell),
targetRow = ROW(targetCell);
// Adjust target cell if it's above the source
if (targetRow < sourceRow)
targetRow++;
// Return if the rows are the same
if (sourceRow == targetRow)
return;
// Move the source data to the target location. We do an
// array move, which shifts all intermediate items rather than
// swapping the two rows.
mListItems.MoveItem(sourceRow, targetRow);
mCellInfo.MoveItem(sourceRow, targetRow);
// refresh the table
Refresh();
}/******************************************************************************
SortRows v1.0.1, 01-20-97, 08-22-97
Sort the table rows alphabetically
Note: Individual cell text info & enabling is cleared
******************************************************************************/
void CTextListTable::SortRows(const Boolean inRefresh, const Boolean clearFormat)
{
SInt32 rowCount = mCellInfo.GetCount();
if (rowCount)
{
mListItems.SortWithComparator(NEW CListNameComparator); // rev TCS 12/11/00, bugfix TCS 6/27/01
if (inRefresh)
Refresh();
// Clear text info & enabled states
if (clearFormat)
{
SCellFormatInfo cellInfo;
cellInfo.textInfo = GetTextInfo();
cellInfo.enabled = true;
for (SInt32 row = 1; row <= rowCount; row++)
{
mCellInfo.AssignItemAt(row, cellInfo);
}
}
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/******************************************************************************
SetListItems
Set the item list for the table v1.1, 02-14-97, 08-22-97
Note: Individual cell text info & enabling is cleared
******************************************************************************/
void CTextListTable::SetListItems(const TNameIDArray &itemArray) // TCS rev 12/11/00
{
SInt32 newCount = itemArray.GetCount();
// We need to use the inherited insert/delete row methods to
// avoid wasted effort maintaining the current items list
if (newCount > mRows)
{
THE_SUPERCLASS::InsertRows(newCount - mRows, cDontRedraw);
}
else if (newCount < mRows)
{
THE_SUPERCLASS::RemoveRows(mRows - newCount, cDontRedraw);
}
// Copy over the array & refresh the view. We already have a comparator
SCellFormatInfo cellInfo;
mListItems = itemArray;
cellInfo.textInfo = GetTextInfo();
cellInfo.enabled = true;
mCellInfo.RemoveAllItems();
mCellInfo.AdjustAllocation(newCount);
for (int i = 0; i < newCount; i++)
{
mCellInfo.Append(cellInfo);
}
Refresh();
}
/******************************************************************************
SelectCell
Selects a cell v1.1.2, 01-07-97, 05-13-97
******************************************************************************/
void CTextListTable::SelectCell(const TableCellT & inCell, const Boolean redraw,
const Boolean /*sendMessages*/)
{
if (!IsSameCell(inCell, mSelectedCell))
{
// we won't select divider bar cells TCS 7/11 rev 7/16/99
if (ROW(inCell) && COL(inCell))
{
CTextString text = GetCellText(ROW(inCell), COL(inCell));
if (text.IsEqualTo(CTextString(cDashChar), cCaseSensitive)) // TCS rev 12/12/03
return;
}
// Optionally unhilite existing selection
if (redraw)
{
// In order to maintain the hilite properly we must
// move the hilite first, then scroll the image
FocusDraw();
HiliteCell(mSelectedCell, false);
mSelectedCell = inCell;
HiliteCell(inCell, true);
RectifySelectionPosition(redraw);
}
else
{
// Just set the selected cell
mSelectedCell = inCell;
}
}
}/******************************************************************************
GetRowFromID
find the row that contains the given id TCS 7/20/98
******************************************************************************/
TableIndexT CTextListTable::GetRowFromID(const TagType inCellID)
{
TNameIDArrayIterator iterator(mListItems);
SNameIDInfo info;
Boolean found = false;
TableIndexT row = 0;
// loop thru table items and try to get a match;
while (!found && iterator.Next(info))
{
found = (info.id == inCellID);
row += 1;
}
// return the found row, if any
if (found)
return row;
else
return 0;
}/******************************************************************************
SelectCellID v1.1, 03-11-97, 05-06-97 rev TCS 6/27/01
Selects the cell with the given ID
******************************************************************************/
Boolean CTextListTable::SelectCellID(const SInt32 inCellID, const Boolean redraw)
{
TableCellT cell;
// Find the cell with the specified ID
COL(cell) = 1;
ROW(cell) = GetRowFromID(inCellID);
// Hilite it
if (ROW(cell))
{
SelectCell(cell, redraw);
return true;
}
return false;
}/******************************************************************************
HiliteCell
Draws a cell with correct hilighting v1.0, 05-05-97
******************************************************************************/
void CTextListTable::HiliteCell(const TableCellT & inCell, const Boolean hiliting)
{
TCS_SetBackgroundColor(CTCS_RGBColor::GetWhiteColor());
THE_SUPERCLASS::HiliteCell(inCell, hiliting);
}
/*********************************************************************************
DrawSelf TCS 9/20/99
draw the text list table
*********************************************************************************/
void CTextListTable::DrawSelf()
{
// inherited method takes care of the usual drawing
THE_SUPERCLASS::DrawSelf();
// white out the area of the frame which does not intersect the image
DrawWhiteArea();
}
/*********************************************************************************
DrawWhiteArea TCS 9/20/99
white out the part of the frame which does not intersect the image
*********************************************************************************/
void CTextListTable::DrawWhiteArea()
{
// get the area of the frame that's outside the image,
// and fill it in with white
TStColorPenState penSaver;
penSaver.Normalize();
TCS_SetForegroundColor(CTCS_RGBColor::GetWhiteColor());
CTCS_Region whiteRegion;
CTCS_View::GetFrameRgnOutsideImage(this, &whiteRegion);
whiteRegion.Fill(TCS_GetSolidPattern()); // bugfix TCS 12/27/03
}
#if CAN_USE_MARK
#pragma mark -
#endif
/******************************************************************************
GetCellText
Returns the text of the specified cell v1.0.4, 12-30-96, 02-14-97
******************************************************************************/
CTextString CTextListTable::GetCellText(const TableIndexT row, const TableIndexT /*col*/) const
{
SNameIDInfo info;
TCS_FailNILMsg(row, TCS_GetErrString(errID_BadRow));
TCS_ASSERTMsg(mListItems.FetchItemAt(row, info),
TCS_GetErrString(errID_BadListItem));
CTextString outText(info.itemName);
return outText;
}/******************************************************************************
SetCellText
Sets the text of the specified cell v1.0.4, 12-30-96, 05-13-97
******************************************************************************/
Boolean CTextListTable::SetCellText(const TableIndexT row, const TableIndexT /*col*/,
const CTextString & cellText,
const Boolean redraw)
{
SNameIDInfo info;
if (mListItems.FetchItemAt(row, info))
{
TCS_BufferFromText(info.itemName, cellText);
mListItems.AssignItemAt(row, info);
if (redraw)
RefreshCell(row, 1);
return true;
}
else
{
return false;
}
}/******************************************************************************
GetSelectedCellText v1.0, 12-30-96 rev TCS 4/29/02
Returns the text of the selected cell
******************************************************************************/
CTextString CTextListTable::GetSelectedCellText() const
{
TableCellT cell = GetSelectedCell();
return GetCellText(ROW(cell), COL(cell));
}
#if CAN_USE_MARK
#pragma mark -
#endif
/******************************************************************************
SetCellID
Sets the ID of the specified cell v1.0.2, 01-06-97, 01-31-97
******************************************************************************/
void CTextListTable::SetCellID(const TableIndexT row, const TableIndexT /*col*/,
const SInt32 inID)
{
SNameIDInfo info;
TCS_ASSERTMsg(mListItems.FetchItemAt(row, info),
TCS_GetErrString(errID_BadListItem));
info.id = inID;
mListItems.AssignItemAt(row, info);
}/******************************************************************************
GetCellID
Returns the ID of the specified cell v1.0, 12-30-96
******************************************************************************/
SInt32 CTextListTable::GetCellID(const TableIndexT row, const TableIndexT /*col*/) const
{
SNameIDInfo info;
TCS_ASSERTMsg(mListItems.FetchItemAt(row, info),
TCS_GetErrString(errID_BadListItem));
return info.id;
}/******************************************************************************
GetSelectedCellID
Returns the ID of the selected cell, v1.01, 12-30-96, 01-06-97
******************************************************************************/
SInt32 CTextListTable::GetSelectedCellID() const
{
TableCellT cell = GetSelectedCell();
if (IsValidCell(cell))
return GetCellID(ROW(cell), COL(cell));
else
return 0;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/******************************************************************************
SetCellTextInfo
Sets the text info for a cell v1.0, 08-22-97
******************************************************************************/
void CTextListTable::SetCellTextInfo(const TableCellT & inCell,
const CTCS_TextInfo & inTextInfo)
{
if (IsValidCell(inCell))
{
SCellFormatInfo cellInfo;
mCellInfo.FetchItemAt(ROW(inCell), cellInfo);
cellInfo.textInfo = inTextInfo;
mCellInfo.AssignItemAt(ROW(inCell), cellInfo);
RefreshCell(ROW(inCell), COL(inCell));
}
}/******************************************************************************
GetCellTextInfo
Returns the text info for a cell to a pointer, v1.0, 08-22-97
******************************************************************************/
void CTextListTable::GetCellTextInfo(const TableCellT & inCell,
CTCS_TextInfo *outTextInfo) const
{
if ((IsValidCell(inCell) && (outTextInfo != nil)))
{
SCellFormatInfo cellInfo;
mCellInfo.FetchItemAt(ROW(inCell), cellInfo);
*outTextInfo = cellInfo.textInfo;
}
}/******************************************************************************
SetCellEnabled
Enables or disables a cell, v1.0, 08-22-97
******************************************************************************/
void CTextListTable::SetCellEnabled(const TableCellT & inCell,
const Boolean inEnabled)
{
if (IsValidCell(inCell))
{
SCellFormatInfo cellInfo;
mCellInfo.FetchItemAt(ROW(inCell), cellInfo);
cellInfo.enabled = inEnabled;
mCellInfo.AssignItemAt(ROW(inCell), cellInfo);
RefreshCell(ROW(inCell), COL(inCell));
}
}/******************************************************************************
GetCellEnabled
Get the enable/disable status of a cell, v1.0, 08-22-97
******************************************************************************/
Boolean CTextListTable::GetCellEnabled(const TableCellT & inCell) const
{
if (IsValidCell(inCell))
{
SCellFormatInfo cellInfo;
// Valid cell, fetch it's auxilliary info
mCellInfo.FetchItemAt(ROW(inCell), cellInfo);
return cellInfo.enabled;
}
else
{
// Invalid cells are not enabled
return false;
}
}
/******************************************************************************
DisableRow TCS 8/23/01
change a row to disabled status
******************************************************************************/
void CTextListTable::DisableRow(const TableIndexT &inRow)
{
CTCS_TextInfo textInfo = CTCS_TextInfo::sDefaultTextInfo;
TableCellT cell;
ROW(cell) = inRow;
COL(cell) = 1;
// Make the item italic & disable its cell
textInfo.SetTextStyle(style_italic);
SetCellTextInfo(cell, textInfo);
SetCellEnabled(cell, false);
} |