Link to: header | tables
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CIconTable
This class manages icon tables for the Goldenseal
estimating software,
small business management software, construction
project management software and
construction estimating software.
It's a table which displays all the available account icons in the db, as well
as available icons in the resource fork. We use this in the dialog that
allows users to change the icon for each account, or to set the default
icon for each class of accounts (customers, projects, bank accounts,
employees, equipment etc).
SUPERCLASS = CTCS_Table
Source Code
/*********************************************************************************
FinishCreateSelf
finish creating this table
*********************************************************************************/
void CIconTable::FinishCreateSelf()
{
// must call the inherited method to do any other initialization
THE_SUPERCLASS::FinishCreateSelf();
// fill the table
FillWithIcons();
}/*********************************************************************************
FillWithIcons
fill this table with icons
*********************************************************************************/
void CIconTable::FillWithIcons()
{
// make sure that we have some columns!
SInt32 cols = GetNumCols();
TCS_ASSERTMsg(cols, TCS_GetErrString(errID_BadColumn));
// build the icon id array
BuildIconArray();
// add only as many rows as are necessary to show the icons
RemoveRows(GetNumRows());
InsertRows((mIconIDArray.GetCount() - 1) / cols + 1, cDontRedraw);
Refresh();
}/*********************************************************************************
BuildIconArray
build the array of icon ids which we will use to draw the table cells
*********************************************************************************/
void CIconTable::BuildIconArray()
{
// sanity check
TCS_FailNILMsg(gDBFile, TCS_GetErrString(errID_BadFile));
SInt32 numIconsInDB = gDBFile->GetObjectCount(id_IconSuite),
numIconsInRes = TCS_GetResourceCount(cIconSuiteResType, cCurrResFileOnly);
// now that we've added the rows, we need to fill in our array
// with the number of icons from the db.
DB_Iterator *iterator = gDBFile->GetIterator(id_IconSuite);
TCS_FailNILMsg(iterator, TCS_GetErrString(errID_BadIterator));
iterator->CreateIDArray(mIconIDArray);
TCS_Forget(iterator);
// now we can add the ids of the icons in the resource fork
// TCS moved code 8/1/00 so this can be platform-independent
TCS_AddResourcesToArray(cIconSuiteResType, mIconIDArray, numIconsInRes);
}/*********************************************************************************
DrawCell
draw the cell referred to by TableCellT
*********************************************************************************/
void CIconTable::DrawCell(const TableCellT &inCell)
{
TCS_Rect cellFrame;
ResIDT iconID = GetCellIcon(inCell);
if (iconID && (FetchLocalCellFrame(inCell, &cellFrame)))
{ // get the actual icon object from the database
CIconSuiteGraphic graphic;
if (iconID < cSmallestGraphicID)
{ // it's probably from a resource
graphic.SetResourceID(iconID);
}
else
{ // it's a db icon
graphic.SetDatabaseID(iconID);
}
// generate the rectangle in which the icon will be drawn
TCS_Rect iconRect = { 0, 0, cIconSize, cIconSize };
// need to center the icon in the cell frame rect
// otherwise TCS_PlotIconID will scale the icon, with
// ugly results
{
// mfs_kk 29jul2k2
// Set Pen state to normal before erasing rect
// Without it First Icon in the Icon chooser Dialog
// comes with a transparent backgroung and all other with
// white background.
TStColorPenState penState;
TStColorPenState::Normalize();
TCS_EraseRect(&cellFrame);
// we have placed this code in a separate block
// so that it will not affect any other drawing
}
TCS_CenterRect(&iconRect, cellFrame);
// draw the icon
graphic.DrawInBox(iconRect);
}
}/*********************************************************************************
ClickCell
a cell is clicked. We override to do nothing if the cell contains no icon
*********************************************************************************/
void CIconTable::ClickCell(const TableCellT &inCell,
const SMouseDownEvent &inMouseDown)
{
if (GetCellIcon(inCell))
THE_SUPERCLASS::ClickCell(inCell, inMouseDown);
else
TCS_SysBeep(); // TCS 10/6/99
}
/*********************************************************************************
HiliteCell TCS 12/17/02
hilite the given cell. This is overridden because we we do our
hiliting by framing, not inverting
*********************************************************************************/
void CIconTable::HiliteCell(const TableCellT &inCell, const Boolean hiliting)
{
TStColorPenState penSaver;
penSaver.Normalize();
TCS_Rect cellFrame;
if (IsValidCell(inCell) && FetchLocalCellFrame(inCell, &cellFrame))
{
if (hiliting)
{
TCS_PenSize(4, 4);
TCS_SetPenPattern(TCS_GetGrayPattern());
TCS_InsetRect(&cellFrame, -1, -1);
TCS_FrameRect(&cellFrame);
}
else
{
TCS_SetForegroundColor(mBackground);
TCS_PenSize(4, 4);
TCS_InsetRect(&cellFrame, -1, -1);
TCS_FrameRect(&cellFrame);
}
}
}
/*********************************************************************************
SetSelectedIcon
set the currently selected icon
*********************************************************************************/
void CIconTable::SetSelectedIcon(const SInt32 anIconID)
{
SInt32 cellIndex = mIconIDArray.FetchIndexOf(anIconID);
if (cellIndex)
{ // the icon was found, select that cell
SelectCellIndex(cellIndex);
}
}/*********************************************************************************
GetCellIcon
return the icon corresponding to the given cell
*********************************************************************************/
SInt32 CIconTable::GetCellIcon(const TableCellT &inCell)
{
SInt32 cellIndex = GetCellIndex(inCell),
iconID = 0;
if (cellIndex)
{ // it's a valid cell, we just return the item at this
// index in the icon id array
if (!mIconIDArray.FetchItemAt(cellIndex, iconID))
iconID = 0;
}
return iconID;
}/*********************************************************************************
HandleKeyPress
handle a key press. We override to intercept the delete key
*********************************************************************************/
Boolean CIconTable::HandleKeyPress(const TCS_EventRecord &inKeyEvent)
{
char keyChar = TCS_GetCharFromEvent(inKeyEvent);
switch (keyChar)
{
case char_Backspace:
// the backspace/delete key was hit. We need to remove the
// selected icon from the display list. Let's see if
// the current icon can be removed
if (GetCellIcon(GetSelectedCell()) >= cSmallestGraphicID)
{
// it's a db icon, it can be removed!
if (TCS_UserSureAlert(TCS_GetMsgString(msgID_RUSureDeleteIcon)))
{ // they oked it, let's add the icon to our delete list
// and update our contents
SIGNAL_Debug("Sorry, not yet implemented!");
}
}
return false;
break;
default:
return THE_SUPERCLASS::HandleKeyPress(inKeyEvent);
break;
}
}
|