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

Popup Tables (Source Code)

Link to: header | tables directory

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

Comments

CPopupTable

This class manages popup tables for the Goldenseal estimating software,
small business management software, construction project management software and
construction estimating software.

It's a table that's used in a popup menu. A popup table highlights the selected cell
by framing it, rather than inverting the contents.

This class is the superclass for things like color and pattern selection popups

SUPERCLASS = CTCS_Table

Constructor

/******************************************************************************
Stream constructor
*******************************************************************************/
CPopupTable::CPopupTable(LStream *inStream)
: CTCS_Table(inStream)
{
}
/******************************************************************************
Param constructor
*******************************************************************************/
CPopupTable::CPopupTable(const SPaneInfo &inPaneInfo, const SViewInfo &inViewInfo)
: CTCS_Table(inPaneInfo, inViewInfo)
{
}

Source Code

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

PopupTableSelect (static)

implement the popup table. Display and track while the mouse is down

*********************************************************************************/
Boolean CPopupTable::PopupTableSelect(ResIDT windResID, SInt32 tableViewID,
UInt8 startIndex, const TCS_Point popupPosition,
TableFunc TableInitFunc,
TableFunc TrackEndedFunc,
void *param1, void *param2)
{
Boolean success = false;

// Check if the mouse is down long enough to show the table
TCS_Delay(delay_popuptable);

// if the mouse is still down, we have a popup to create.
if (TCS_MouseStillDown())
{
// save the current target
LCommander *saveTarget = LCommander::GetTarget();

// create the window TCS rev 9/16/02
CTCS_SimpleWindow *popupWindow = CTCS_SimpleWindow::MakeWindow(windResID, gDocument);
// CTCS_Window *popupWindow = CTCS_Window::MakeSimpleWindow(windResID, gDocument);
TCS_FailNILMsg(popupWindow, TCS_GetErrString(errID_BadWindow));

// get the table inside the window
CPopupTable *table =
TCS_SAFE_CAST(popupWindow->FindPaneByID(tableViewID), CPopupTable);
TCS_FailNILMsg(table, TCS_GetErrString(errID_BadTable));

// set the initial selection TCS 1/8/03
TableCellT startCell;
table->GetCellFromIndex(startIndex, &startCell);
table->SelectCell(startCell);

// set up callback so caller can do any initialization
// on the table
if (TableInitFunc)
(*TableInitFunc)(table, param1, param2);

// ok, we're all set to position the window.
popupWindow->DoSetPosition(popupPosition);
popupWindow->Show();

// need to force a draw as the palette isn't
// going to get the update event!
table->UpdatePort();
success = table->TrackPopup();
if (success && TrackEndedFunc)
(*TrackEndedFunc)(table, param1, param2);

#if TCS_FOR_WINDOWS
// mfs_sa 12jun2k2
// we can't delete any window directly, call LWnd::DoClose
// instead
popupWindow->DoClose(false);
#else
// delete the palette window and the color table
TCS_Forget(popupWindow);
#endif

// go back to the original target
LCommander::SwitchTarget(saveTarget);
}
return success;
}
/*********************************************************************************

TrackPopup moved TCS 10/26/01

while the mouse is down, track the table like a menu

*********************************************************************************/
Boolean CPopupTable::TrackPopup()
{
TableCellT cell = { 0, 0 };

FocusDraw();

while (TCS_MouseStillDown())
{
// select the cell under the mouse
cell = FetchCellHitBy(TCS_GetMouse()); // rev TCS 12/24/02
SelectCell(cell);
}

GetSelectedCell(&cell);

// we accept the action if a valid cell is selected. Note that we no
// longer return false if the same cell is selected again- since that
// was sometimes blocking action inappropriately TCS rev 10/26/01
return (IsValidCell(cell));
}
/*********************************************************************************

SelectCell

select the given cell. We override because we need to make sure to erase
the previous selection, if any

*********************************************************************************/
void CPopupTable::SelectCell(const TableCellT &inCell, const Boolean redraw,
const Boolean /*sendMessages*/)
{
if (!IsSameCell(inCell, mSelectedCell))
{
if (redraw)
{ // we must first erase the previously selected cell
FocusDraw();
HiliteCell(mSelectedCell, false); // rev TCS 1/4/03
}
mSelectedCell = inCell;

if (redraw)
{ // now draw the new cell
HiliteCell(inCell);
}
}
}/*********************************************************************************

HiliteCell

hilite the given cell. This is overridden because we we do our
hiliting by framing, not inverting

*********************************************************************************/
void CPopupTable::HiliteCell(const TableCellT &inCell, const Boolean hiliting)
{
TCS_Rect cellFrame;
if (IsValidCell(inCell) && FetchLocalCellFrame(inCell, &cellFrame))
{
TStColorPenState penSaver; // TCS 1/4/03
penSaver.Normalize();

if (!hiliting)
TCS_SetForegroundColor(CTCS_RGBColor::GetWhiteColor());

TCS_PenSize(2, 2);
TCS_InsetRect(&cellFrame, -1, -1);
TCS_FrameRect(&cellFrame);
}
}