Accounting Software
Small Business Software Estimating Software
Time Tracking SoftwareTime Management SoftwareTime Billing SoftwareContact Management SoftwareCustomer Management SoftwareProject Management SoftwareBusiness Management Software

Multiple Text Lists (Source Code)

Link to: header | tables directory

Copyright Turtle Creek Software 1996-2006. All Rights Reserved.

Comments

CMultipleTextListTable

This class manages multiple text list tables for the Goldenseal accounting software,
small business management software, construction project management software and
construction accounting software.

It's a text list table that allows multiple items to be selected, via shift-click
or command-click.

Superclasses: CTextListTable

Constructor

/******************************************************************************
Stream constructor
******************************************************************************/
CMultipleTextListTable::CMultipleTextListTable(LStream *inStream)
: CTextListTable(inStream)
{
mAnchorRow = nil;
}/******************************************************************************
Param constructor
******************************************************************************/
CMultipleTextListTable::CMultipleTextListTable(const SPaneInfo &inPaneInfo,
const SViewInfo &inViewInfo,
const CTCS_TextInfo & inTextInfo,
Boolean inSysHilite, Boolean inCanRearrange)
: CTextListTable(inPaneInfo, inViewInfo, inTextInfo, inSysHilite, inCanRearrange)
{
mAnchorRow = nil;
}/******************************************************************************
Destructor
******************************************************************************/
CMultipleTextListTable::~CMultipleTextListTable()
{
}

Source Code

/******************************************************************************

RectifySelectionPosition

Scrolls selection into view if appropriate

******************************************************************************/
Boolean CMultipleTextListTable::RectifySelectionPosition(const Boolean /*redraw*/)
{
// since we have multiple selection, we override and do nothing,
// so we don't get confusing jumps in the list
return false;
}/******************************************************************************

SelectCellArray TCS 9/24/98

Select cells that are listed in an input array of row indices

******************************************************************************/
void CMultipleTextListTable::SelectCellArray(TUInt32Array &inCellArray,
const Boolean redraw)
{
TUInt32ArrayIterator iterator(inCellArray);
TableIndexT row;
while (iterator.Next(row))
{
SelectRow(row, redraw);
}
}/******************************************************************************

GetSelectedCellIDArray TCS 7/20/98

return an array of selected cell tags

******************************************************************************/
TTagArray CMultipleTextListTable::GetSelectedTagArray()
{
TTagArray tagArray;

TTagArrayIterator iterator(mSelectedRows);
TableIndexT row;
TagType tag;

while (iterator.Next(row))
{
if (row) // rev TCS 7/28/99
{
tag = GetCellID(row);
tagArray.Append(tag);
}
}

return tagArray;
}/******************************************************************************

GetSelectedCellArray TCS 9/24/98

return an array of selected cell indices

******************************************************************************/
TTagArray CMultipleTextListTable::GetSelectedCellArray()
{
return mSelectedRows;
}/******************************************************************************

SelectCell

What we do when a single cell is clicked on.

******************************************************************************/
void CMultipleTextListTable::SelectCell(const TableCellT &inCell,
const Boolean /*redraw*/, const Boolean /*sendMessages*/)
{
// add the cell to the array
SelectRow(ROW(inCell));

// and make it the anchor cell so we can properly track
// subsequent shift-clicks
mAnchorRow = ROW(inCell);
}
#if CAN_USE_MARK
#pragma mark -
#endif/*********************************************************************************

ClickCell rev TCS 7/31/01

a cell is clicked. We override to handle command and shift key selections
of multiple items. Note that we ignore double-clicks.

*********************************************************************************/
void CMultipleTextListTable::ClickCell(const TableCellT &inCell,
const SMouseDownEvent &inMouseDown)
{
TableIndexT thisRow = ROW(inCell);
SetClickedCell(inCell);

if (TCS_CommandIsDown(inMouseDown.macEvent) || TCS_OptionIsDown(inMouseDown.macEvent) ||
TCS_ControlIsDown(inMouseDown.macEvent))
{ // for command click, switch the status of clicked cell
if (RowIsSelected(thisRow))
SelectRow(thisRow, false);
else
SelectRow(thisRow, true);

} // for shift click, select all items between here and anchor
else if (TCS_ShiftIsDown(inMouseDown.macEvent) && mAnchorRow)
{
ClearAllRows();

if (thisRow >= mAnchorRow)
{
for (TableIndexT row = mAnchorRow; row <= thisRow; row++)
{
SelectRow(row, true);
}
}
else
{
for (TableIndexT row = thisRow; row <= mAnchorRow; row++)
{
SelectRow(row, true);
}
}
}
else // a regular single click with no modifier keys
{
// clear the array, and add this item
ClearAllRows();
SelectRow(ROW(inCell), true);
// mark this row as the anchor row
mAnchorRow = ROW(inCell);
}
// when done we broadcast changed msg
BroadcastMessage(msg_TableChanged, this);
}
/*********************************************************************************

ClearAllRows

erase all selected items from the array

*********************************************************************************/
void CMultipleTextListTable::ClearAllRows()
{
// first erase hiliting on all selected rows
if (mSelectedRows.GetCount() > 0)
{
TUInt32ArrayIterator iterator(mSelectedRows);
TableIndexT row;

while (iterator.Next(row))
{
HiliteRow(row, false);
}
// clear the array
mSelectedRows.RemoveAllItems();
}
}
/*********************************************************************************

RowIsSelected

return whether a row is already selected

*********************************************************************************/
Boolean CMultipleTextListTable::RowIsSelected(const TableIndexT row)
{
if (mSelectedRows.GetCount() > 0)
return mSelectedRows.ContainsItem(row);
else
return false; // if no selected items, this one isn't selected
}/*********************************************************************************

HiliteRow

change the hilite condition of a row

*********************************************************************************/
void CMultipleTextListTable::HiliteRow(const TableIndexT row, const Boolean select)
{
FocusDraw(); // we need to reset focus so we survive scrolls etc

TableCellT cell;
cell.h = 1;
cell.v = row;
HiliteCell(cell, select);
}/******************************************************************************

DrawCellHilites

Draw the hiliting of selected cell(s). We override to draw multiple selections

*******************************************************************************/
void CMultipleTextListTable::DrawCellHilites()
{
TableCellT cell;
cell.h = 1;

// loop thru selection array and hilite each cell
TUInt32ArrayIterator iterator(mSelectedRows);
TableIndexT row;
while (iterator.Next(row))
{
cell.v = row;
HiliteCell(cell);
}
}/*********************************************************************************

SelectRow

change the selection condition of a row

*********************************************************************************/
void CMultipleTextListTable::SelectRow(const TableIndexT row, const Boolean select)
{
if (!select)
{ // remove the selection from our array
SInt32 arrayIndex = mSelectedRows.FetchIndexOf(row);
if (arrayIndex != LArray::index_Bad)
{
mSelectedRows.RemoveItemsAt(1, arrayIndex); // remove one row
}
HiliteRow(row, false);
}
else if (row) // rev TCS 12/21/01
{ // add the selection to our array
MarkAsSelected(row);

HiliteRow(row, true);
}
else
{ // selecting the zeroth row is the same as deselecting all
mSelectedRows.RemoveAllItems();
HiliteRow(row, true);
}
}/*********************************************************************************

MarkAsSelected

add the given row to our array of selected items

*********************************************************************************/
void CMultipleTextListTable::MarkAsSelected(const TableIndexT row)
{
// add the selection to our array
if (!RowIsSelected(row))
{
mSelectedRows.Append(row);
}
}