Accounting Software
Small Business Software Estimating Software
Project Management SoftwareProject Estimating SoftwareProject Tracking SoftwareInventory Tracking SoftwareCustomer Tracking SoftwareCustomer Management SoftwareBusiness Management Software

Label Icons (Source Code)

Link to: header | other interface directory

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

Comments

CLabelIcon

This class manages label icons for the
Goldenseal estimating software, project management software,
construction estimating software
and construction software.

It's a class for implementing a standard icon with a label. The label may be
drawn below, above, or to the left or right of the icon. The icon is
obtained from an Icon Family('ICxx') resource.
This class also supports suppression of either the icon or the label
when drawing, allowing text-button lists and simple icons(ie, alerts).

The label is now drawn in condensed style if it is too wide to fit
within its frame.
SUPERCLASS = CTCS_Control

Constructor

/******************************************************************************
constructor v2.1.1, 11-03-95, 01-28-97
*******************************************************************************/
CLabelIcon::CLabelIcon(const SPaneInfo & paneInfo,
const SLabelIconInfo & iconInfo,
const Boolean inUseDBIcon)
: CTCS_Control(paneInfo, cmd_Nothing, Button_Off, Button_Off, Button_On)
{
mIndent = iconInfo.indent;
mLabelPosition = iconInfo.labelPosition;
mViewType = iconInfo.viewType;
mLabel = iconInfo.label;
mTextInfo = iconInfo.textInfo;
mSelectedStyle = iconInfo.selectedStyle;
mClickMessage = msg_LabelIconSelected; // Default broadcast messages
mDblClkMessage = msg_LabelIconDoubleClicked;
if (inUseDBIcon)
mIconSuite.SetDatabaseID(iconInfo.iconID);
else
mIconSuite.SetResourceID(iconInfo.iconID);
SetUserCon(class_ID);
}
/******************************************************************************
Destructor
*******************************************************************************/
CLabelIcon::~CLabelIcon()
{
}

Source Code

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

SetLabel

Set the icon's label v1.0, 11-03-95

*******************************************************************************/
void CLabelIcon::SetLabel(const CTextString & inLabel, Boolean inRefresh)
{
mLabel = inLabel;
if (inRefresh)
Refresh();
}
/******************************************************************************

SetIconID

Set the ID of the icon to use, v2.1, ??-??-95, 11-14-96
inUseDBIcon specifies whether the icon is in the DB or the resource fork

*******************************************************************************/
void CLabelIcon::SetIconID(SInt32 inIconID, Boolean redraw, Boolean inUseDBIcon)
{
// We must manually unload the current graphic before adding one
mIconSuite.UnloadGraphic();
if (inUseDBIcon)
mIconSuite.SetDatabaseID(inIconID);
else
mIconSuite.SetResourceID(inIconID);
// Optionally refresh
if (redraw)
Refresh();
}
/******************************************************************************

SetViewType

Set the icon's view type v1.02, 10-??-95, 11-14-96

*******************************************************************************/
void CLabelIcon::SetViewType(IconViewType aViewType)
{
mViewType = aViewType;
}
/******************************************************************************

SetValue

Set the icon's value v1.21, 11-03-95, 05-21-96
Override to redraw after value change

*******************************************************************************/
void CLabelIcon::SetValue(SInt32 inValue)
{
if (inValue != mValue)
{
CTCS_Control::SetValue(inValue);
Draw(nil);
DontRefresh();

// mfs_kk rev 25sep2k2, then cancelled 10oct2k2
}
}
/******************************************************************************

ClickSelf

respond to mouse click, v1.0, 11-03-95, 12-22-95
Just broadcast a message to let everyone know we've been clicked.

*******************************************************************************/
void CLabelIcon::ClickSelf(const SMouseDownEvent &/*inMouseDown*/)
{
if (LPane::sClickCount > 1) // double-click!
BroadcastMessage(mDblClkMessage,(void *) this);
else
{
BroadcastMessage(mClickMessage,(void *) this);
SetValue(Button_On);
}// else ends
}// ClickSelf(const SMouseDownEvent &) ends
/******************************************************************************

DrawSelf

draw the contents of the pane v2.2.6, 11-03-95, 11-30-97

*******************************************************************************/
void CLabelIcon::DrawSelf()
{
TStTextState portSaver; // stack-based object takes care of
TStClipRgnState clipSaver; // saving and restoring port characteristics
CTCS_TextInfo oldInfo = mTextInfo;
TCS_Rect textBox, iconBox,
frameRect;

// Calculate the frame, clip to it, and erase
// As of 12-11-96 we force the background to white. This will cause
// problems if we ever need to draw icons on a gray background...
CalcLocalFrameRect(frameRect);
clipSaver.ClipToIntersection(frameRect);
TCS_SetBackgroundColor(CTCS_RGBColor::GetWhiteColor());

if (mEraseFirst) // TCS 12/15/00
TCS_EraseRect(&frameRect);
// We may need to adjust the text traits for label-only view
// For other views we set icon hiliting
if (mViewType == icon_NoIcon)
{
if (mValue != Button_Off)
mTextInfo.SetTextStyle(mSelectedStyle);
}
else
{
if (mValue != Button_Off)
{
mIconSuite.SetTransform(iconTransform_Selected);
}
else
{
mIconSuite.SetTransform(iconTransform_None);
}
}
// Now we set the ports text traits and get the destination rects
CTCS_TextInfo::SetPortTextInfo(mTextInfo);
CalcBoxes(&iconBox, &textBox);
if (mViewType != icon_NoIcon)
mIconSuite.DrawInBox(iconBox, kCenterIcon);

// Now, we draw the label, unless it's been suppressed
// First we have to see if it fits. If not we display it condensed
CStringGraphic labelGraphic(mLabel); // TCS rev 9/17/02

if (mLabelPosition != icon_DontShowLabel)
{
if (textBox.right > frameRect.right)
{
mTextInfo.SetTextStyle(style_condense);
CTCS_TextInfo::SetPortTextInfo(mTextInfo);
// Adjust the text box
SInt32 width = labelGraphic.GetWidth();

textBox.right = textBox.left + width;
if ((mLabelPosition == icon_LabelOnTop) ||
(mLabelPosition == icon_LabelOnBottom) ||
(mLabelPosition == icon_CenterLabel))
{
textBox.left = frameRect.left + mIndent +
TCS_MAX(((frameRect.right - frameRect.left - width) / 2), 0);
textBox.right = textBox.left + width;
}
}
TCS_MoveTo(textBox.left, textBox.bottom - 2);

// now we can draw the graphic
labelGraphic.Draw();

if (mValue != Button_Off)
if (mViewType == icon_NoIcon)
{
// Invert whole frame for list view
// We use the system hilite color for this
// UDrawingUtils::SetHiliteModeOn(); // Disabled per TCS
TCS_InvertRect(&frameRect);
}
else
{
// Extend text box a bit for hilight
TCS_InsetRect(&textBox, -2, 0);
//textBox.bottom += 0; // TCS changed from 2 4/23/98
TCS_InvertRect(&textBox);
}
}
// Finally, we restore the label's style
mTextInfo = oldInfo;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/******************************************************************************

PointIsInFrame

Check if point is within pane v1.0, 11-03-95, 11-08-95

*******************************************************************************/
Boolean CLabelIcon::PointIsInFrame(SInt32 inHorizPort, SInt32 inVertPort) const
{
// this line is for temporary use only!!

return LPane::PointIsInFrame(inHorizPort, inVertPort);

/*
TCS_Rect textBox,
iconBox;
TCS_Point localPt;

localPt.h = inHorizPort;
localPt.v = inVertPort;

CalcBoxes(&textBox, &iconBox);
return ( PtInRect(localPt, &textBox) || PtInRect(localPt, &iconBox) );
*/
}
/******************************************************************************

CalcBoxes v2.1.1, 11-03-95, 01-22-97

Determine positioning of icon and label

*******************************************************************************/
void CLabelIcon::CalcBoxes(TCS_Rect *iconRect, TCS_Rect *labelRect)
{
TCS_Rect frameRect;

CalcLocalFrameRect(frameRect);

CStringGraphic labelGraphic(mLabel); // TCS rev 9/17/02

SInt32 textHeight = labelGraphic.GetHeight(),
textWidth = labelGraphic.GetWidth();

*iconRect = *labelRect = frameRect;

switch (mLabelPosition)
{
case icon_LabelOnBottom :
switch (mViewType)
{
case icon_LargeIcon :
iconRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - cIconSize) / 2);
iconRect->bottom = iconRect->top + cIconSize;
iconRect->right = iconRect->left + cIconSize;
break;
case icon_SmallIcon :
iconRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - cSicnSize) / 2);
iconRect->bottom = iconRect->top + cSicnSize;
iconRect->right = iconRect->left + cSicnSize;
break;
case icon_NoIcon :
TCS_SetRect(iconRect, 0, -1, 0, -1);
break;
}
labelRect->top = iconRect->bottom + 1;
labelRect->bottom = labelRect->top + textHeight;
labelRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - textWidth) / 2);
labelRect->right = labelRect->left + textWidth;
break;
case icon_LabelOnTop :
switch (mViewType)
{
case icon_LargeIcon :
iconRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - cIconSize) / 2);
iconRect->top = iconRect->bottom - cIconSize;
iconRect->right = iconRect->left + cIconSize;
break;
case icon_SmallIcon :
iconRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - cSicnSize) / 2);
iconRect->top = iconRect->bottom - cSicnSize;
iconRect->right = iconRect->left + cSicnSize;
break;
case icon_NoIcon :
TCS_SetRect(iconRect, 0, 0, 0, 0);
break;
}
labelRect->top = frameRect.top;
labelRect->bottom = labelRect->top + textHeight;
labelRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - textWidth) / 2);
labelRect->right = labelRect->left + textWidth;
break;
case icon_LabelOnRight :
iconRect->left = frameRect.left + mIndent;
switch (mViewType)
{
case icon_LargeIcon :
iconRect->top = frameRect.top +
((frameRect.bottom - frameRect.top - cIconSize) / 2);
iconRect->bottom = iconRect->top + cIconSize;
iconRect->right = iconRect->left + cIconSize;
break;
case icon_SmallIcon :
iconRect->top = frameRect.top +
((frameRect.bottom - frameRect.top - cSicnSize) / 2);
iconRect->bottom = iconRect->top + cSicnSize;
iconRect->right = iconRect->left + cSicnSize;
break;
case icon_NoIcon :
TCS_SetRect(iconRect, frameRect.left + mIndent - 5, 0,
frameRect.left + mIndent - 5, 0);
break;
}
labelRect->left = iconRect->right + 5;
labelRect->right = labelRect->left + textWidth;
if (mViewType != icon_NoIcon) // Only center up/down if icon is shown
labelRect->top += ((frameRect.bottom - frameRect.top - textHeight) / 2) - 1;
labelRect->bottom = labelRect->top + textHeight;
break;
case icon_LabelOnLeft :
iconRect->right = frameRect.right - mIndent;
switch (mViewType)
{
case icon_LargeIcon :
iconRect->top = frameRect.top +
((frameRect.bottom - frameRect.top - cIconSize) / 2);
iconRect->bottom = iconRect->top + cIconSize;
iconRect->left = iconRect->right - cIconSize;
break;
case icon_SmallIcon :
iconRect->top = frameRect.top +
((frameRect.bottom - frameRect.top - cSicnSize) / 2);
iconRect->bottom = iconRect->top + cSicnSize;
iconRect->left = iconRect->right - cSicnSize;
break;
case icon_NoIcon :
TCS_SetRect(iconRect, frameRect.right, 0, frameRect.right, 0);
break;
}
labelRect->right = iconRect->left - 5;
labelRect->left = labelRect->right - textWidth;
if (mViewType != icon_NoIcon) // Only center up/down if icon is shown
labelRect->top += ((frameRect.bottom - frameRect.top - textHeight) / 2) - 1;
labelRect->bottom = labelRect->top + textHeight;
break;
case icon_CenterLabel :
switch (mViewType)
{
case icon_LargeIcon :
iconRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - cIconSize) / 2);
iconRect->bottom = iconRect->top + cIconSize;
iconRect->right = iconRect->left + cIconSize;
break;
case icon_SmallIcon :
iconRect->left = frameRect.left + mIndent +
((frameRect.right - frameRect.left - cSicnSize) / 2);
iconRect->bottom = iconRect->top + cSicnSize;
iconRect->right = iconRect->left + cSicnSize;
break;
case icon_NoIcon :
TCS_SetRect(iconRect, 0, 0, 0, 0);
break;
}
labelRect->left = (frameRect.left + frameRect.right - textWidth) / 2;
labelRect->right = labelRect->left + textWidth;
labelRect->top = (frameRect.top + frameRect.bottom - textHeight) / 2;
labelRect->bottom = labelRect->top + textHeight;
break;
}
}
/******************************************************************************

GetOptimalFrameSize v1.0, 12-10-96

Returns the optimal frame size for the icon. Either of the pointer
params can be nil, if you only want one value.

*******************************************************************************/
void CLabelIcon::GetOptimalFrameSize(IconViewType inViewType,
IconLabelPos inLabelPos,
const CTCS_TextInfo & inTextInfo,
const CTextString & inLabel,
SInt32 *outWidth, SInt32 *outHeight)
{
TStTextState textSaver;
SInt8 iconSize = 0;
// Get the text size
CTCS_TextInfo::SetPortTextInfo(inTextInfo);

CStringGraphic labelGraphic(inLabel); // TCS rev 9/17/02

SInt32 textWidth = labelGraphic.GetWidth(),
textHeight = labelGraphic.GetHeight();

if (inViewType != icon_NoIcon)
{
textHeight += 6;
textWidth += 4;
}
// Get the icon's size
switch (inViewType)
{
case icon_LargeIcon :
iconSize = cIconSize;
break;
case icon_SmallIcon :
iconSize = cSicnSize;
break;
default :
iconSize = 0;
break;
}
// Check the label position
switch (inLabelPos)
{
case icon_LabelOnTop :
case icon_LabelOnBottom :
if (outWidth != nil)
*outWidth = TCS_MAX(textWidth, iconSize);
if (outHeight != nil)
*outHeight = iconSize + textHeight;
break;
case icon_LabelOnLeft :
case icon_LabelOnRight :
if (outWidth != nil)
*outWidth = iconSize + textWidth + cHorizSeparation;
if (outHeight != nil)
*outHeight = TCS_MAX(iconSize, textHeight);
break;
case icon_CenterLabel :
if (outWidth != nil)
*outWidth = TCS_MAX(iconSize, textWidth);
if (outHeight != nil)
*outHeight = TCS_MAX(iconSize, textHeight);
break;
default :
THROW_SIGNAL("Oops, unknown label position!");
break;
}
}
/******************************************************************************

MakeRegionOutline

Create an outline of the icon and its label, v2.02, 11-03-95, 05-30-96

*******************************************************************************/
void CLabelIcon::MakeRegionOutline(CTCS_Region *aRegion)
{
TCS_Rect iconRect,
labelRect;
CTCS_Region textOutline;
// Calculate destination boxes for icon & text
FocusDraw();
CTCS_TextInfo::SetPortTextInfo(mTextInfo);
CalcBoxes(&iconRect, &labelRect);
// We want to pin the region at(2, 0) so the outline appears on
// top of the actual icon when we begin to drag
TCS_Point loc;
loc.h = mFrameLocation.h;
loc.v = mFrameLocation.v;
PortToLocalPoint(loc);
TCS_OffsetRect(&labelRect, mFrameLocation.h - loc.h, mFrameLocation.v - loc.v);
TCS_OffsetRect(&iconRect, mFrameLocation.h - loc.h, mFrameLocation.v - loc.v);
// Get an outline of the icon
if (mViewType != icon_NoIcon)
{
mIconSuite.GetOutlineRgn(aRegion, iconRect);
}
// Outline the text
if (mLabelPosition != icon_DontShowLabel)
{
textOutline.StartRecording();
TCS_FrameRect(&labelRect);
TCS_InsetRect(&labelRect, 1, 1);
TCS_FrameRect(&labelRect);
textOutline.StopRecording();
}
// Add the text outline to the icon's region
*aRegion += textOutline;
}