Link to: header | other interface
directory
Copyright Turtle Creek Software 1996-2006. All Rights Reserved.
Comments
CTCS_View
This class manages windows views in the
Goldenseal small business estimating software,
project management software, construction
estimating software
and construction software.
It's a buffer class for LView. In PowerPlant a view is the same as a TCL
panorama, a thing that can be scrolled and that contains subpanes.
This class contains some static utilities for managing view contents.
SUPERCLASS = LView
Source Code
/*********************************************************************************
InsertSubviews
Insert the subviews identified by viewRes in destView
*********************************************************************************/
void CTCS_View::InsertSubviews(ResIDT viewRes, LView *destView,
LCommander *superCommander,
Boolean resizeDest)
{
// sanity check
TCS_FailNILMsg( destView, TCS_GetErrString(errID_BadView));
TCS_FailNILMsg( superCommander, TCS_GetErrString(errID_BadView));
TCS_FailNILMsg( viewRes, TCS_GetErrString(errID_BadView));
// create the source view from the Constructor resource
LView *sourceView = UReanimator::CreateView(viewRes, destView,
superCommander);
SDimension16 sourceFrameSize;
if (resizeDest)
{ // next get the size of the source view, so
// we can resize the destination view if necessary
sourceView->GetFrameSize(sourceFrameSize);
}
// now place the sourceView and its subviews inside destView.
// We pass TRUE as the last parameter to StealSubviews to
// ensure that the sourceView is deleted
StealSubviews(sourceView, destView, true);
if (resizeDest)
{ // now resize the destView to accomodate the source view.
destView->ResizeImageTo(sourceFrameSize.width, sourceFrameSize.height, true);
}
}/*********************************************************************************
StealSubviews
This routine takes the subviews of sourceView, and places them all in
destView- effectively 'stealing' them. If killSource is TRUE(default),
the sourceView is destroyed.
*********************************************************************************/
void CTCS_View::StealSubviews(LView *sourceView, LView *destView,
const Boolean killSource)
{
TArrayIterator<LPane*> iterator(sourceView->GetSubPanes(), iter_from_end); // rev TCS 7/31/00
LPane *subpane;
while (iterator.Previous(subpane)) // rev TCS 8/4/00
{
subpane->PutInside(destView, true);
}
if (killSource)
TCS_Forget(sourceView); // TCS rev 11/5/00
destView->Refresh();
}/*********************************************************************************
GetFrameRgnOutsideImage
This gets the area of the frame which is not in the image, and puts
it into the passed region. If the entire frame is inside the image,
this routine returns false and region is empty
*********************************************************************************/
Boolean CTCS_View::GetFrameRgnOutsideImage(LView *view, CTCS_Region *region)
{
// sanity check
TCS_FailNILMsg(view, TCS_GetErrString(errID_BadView));
TCS_FailNILMsg(region, TCS_GetErrString(errID_BadView));
// get the current frame as a long value (currently unused)
TCS_LongRect fullFrameR;
view->CalcFullFrameRect(fullFrameR);
// get the current frame
TCS_Rect frameR;
view->CalcLocalFrameRect(frameR);
// get the image size
SDimension32 imageSize;
view->GetImageSize(imageSize);
// if the image is too large, we just give up right now.
// We'll eventually need to write a version of TCS_GetIntersection
// which handles TCS_LongRect inputs TCS 9/15/02
SInt32 maxImageSize = cMaxShortValue / 2;
if (imageSize.height > maxImageSize || imageSize.width > maxImageSize)
return false;
TCS_Rect imageR;
TCS_SetRect(&imageR, 0, 0, imageSize.width, imageSize.height);
// ok, now we have frame and image rectangles. Let's get
// the intersection of these two rectangles
TCS_Rect intersect;
if (TCS_GetIntersection(&intersect, frameR, imageR))
{ // there is an intersection. We generate two rectangles:
// one below the common area, one to the right of
// the common area
TCS_Rect rect1, rect2; // BUG FIX - mfs_sa 11dec2k2
TCS_SetRect(&rect1, frameR.left, intersect.bottom, // One pixel was being left on
intersect.right, frameR.bottom); // top and bottom
TCS_SetRect(&rect2, intersect.right, frameR.top,
frameR.right, frameR.bottom);
// add these two rectangles together to make the region
*region = CTCS_Region(rect1) + CTCS_Region(rect2);
}
else
{ // no intersection! the entire frame is outside the image
*region = frameR;
}
// we return true if the region is not empty
return !region->IsEmpty();
}/*********************************************************************************
GetRectEnclosingSubviews (static) rev TCS 1/5/00
return the rectangle enclosing all subviews of the given view. This is used
when sizing layouts (e.g. to show or print variable-size table), and when
resizing layouts in the Layout Editor.
Note that the rect starts at 0,0 even if panes don't extend that far up or left.
*********************************************************************************/
void CTCS_View::GetRectEnclosingSubviews(LView &view, TCS_Rect *outRect)
{
// sanity check
TCS_FailNILMsg(outRect, TCS_GetErrString(errID_BadGraphic));
// start with a rectangle with absurd sizes
TCS_SetRect(outRect, 0, 0, 0, 0); // formerly used max_Int16 for left & top
// walk through the view's subviews, and expand the result rect
// by the right & bottom edges of each subview, so that
// the result rect contains the subview
const SInt32 cPadding = 1;
TArrayIterator<LPane*> iterator(view.GetSubPanes());
LPane *subPane = nil;
//TCS_Rect paneRect;
SDimension16 paneSize;
SPoint32 paneLocation, viewLocation;
view.GetFrameLocation(viewLocation);
SInt32 rightmost, bottommost;
while (iterator.Next(subPane))
{
// fetch pane size and location
TCS_FailNILMsg(subPane, TCS_GetErrString(errID_BadPane));
//subPane->CalcLocalFrameRect(paneRect);
subPane->GetFrameSize(paneSize);
subPane->GetFrameLocation(paneLocation);
// calculate the far right point
//rightmost = paneRect.right;
rightmost = paneLocation.h + paneSize.width -
viewLocation.h;
if (rightmost < 0) // added 3/29/98
rightmost = 0;
// calculate the far bottom point
//bottommost = paneRect.bottom;
bottommost = paneLocation.v + paneSize.height -
viewLocation.v;
if (bottommost < 0)
bottommost = 0;
// if this pane extends beyond outRect,
// stretch outRect
if (rightmost + cPadding > outRect->right)
outRect->right = rightmost + cPadding;
if (bottommost + cPadding > outRect->bottom)
outRect->bottom = bottommost + cPadding;
}
// done walking the subviews- at this point the outRect
// should just enclose all subviews
}/*********************************************************************************
SetSubpaneText
set the text of the given subpane to the given string. This handles either
edit fields or captions, or indeed anything that is a cstring manager
*********************************************************************************/
Boolean CTCS_View::SetSubpaneText(LView *theView, SInt32 paneID,
const CTextString &cstring)
{
TCS_FailNILMsg(theView, TCS_GetErrString(errID_BadView));
LPane *subPane = theView->FindPaneByID(paneID); // rev TCS 8/30/01
if (subPane)
{
subPane->SetCString(cstring);
return true;
}
else
return false;
}/*********************************************************************************
GetSubpaneText
set the text of the given subpane to the given string. This handles either
edit fields or captions, or indeed anything that is a cstring manager
*********************************************************************************/
CTextString CTCS_View::GetSubpaneText(LView *theView, SInt32 paneID)
{
TCS_FailNILMsg(theView, TCS_GetErrString(errID_BadView));
LPane *subPane = theView->FindPaneByID(paneID); // rev TCS 8/30/01
if (subPane)
{
CTextString cstring;
subPane->GetCString(&cstring);
return cstring;
}
else
return "";
}
/*********************************************************************************
GetSubpane (static) TCS 8/1/03
get the subpane with the given ID in the given view
*********************************************************************************/
LPane *CTCS_View::GetSubpane(LView *theView, SInt32 paneID)
{
TCS_FailNILMsg(theView, TCS_GetErrString(errID_BadView));
return theView->FindPaneByID(paneID);
}
/*********************************************************************************
SetSubpaneValue (static)
set the value of the given subpane
*********************************************************************************/
Boolean CTCS_View::SetSubpaneValue(LView *theView, SInt32 paneID,
const SInt32 newValue)
{
TCS_FailNILMsg(theView, TCS_GetErrString(errID_BadView));
LPane *subPane = theView->FindPaneByID(paneID);
if (subPane)
{
subPane->SetValue(newValue);
return true;
}
else
return false;
}/*********************************************************************************
GetSubpaneValue (static)
get the value of the given subpane.
*********************************************************************************/
SInt32 CTCS_View::GetSubpaneValue(LView *theView, SInt32 paneID)
{
TCS_FailNILMsg(theView, TCS_GetErrString(errID_BadView));
LPane *subPane = theView->FindPaneByID(paneID);
return subPane ? subPane->GetValue() : 0;
}/*********************************************************************************
ShowSubpane (static)
show/hide the subpane with the requested id. Return true if the operation
was successful, false otherwise
*********************************************************************************/
Boolean CTCS_View::ShowSubpane(LView &theView, SInt32 paneID, Boolean show)
{
LPane *subPane = theView.FindPaneByID(paneID);
if (subPane)
{
if (show)
subPane->Show();
else
subPane->Hide();
return true;
}
else
return false;
}/*********************************************************************************
EnableSubpane (static)
enable/disable the subpane with the requested id. Return true if the operation
was successful, false otherwise
*********************************************************************************/
Boolean CTCS_View::EnableSubpane(LView &theView, SInt32 paneID,
Boolean enable, Boolean refresh)
{
LPane *subPane = theView.FindPaneByID(paneID);
if (subPane)
{
if (refresh)
subPane->Refresh();
if (enable)
subPane->Enable();
else
subPane->Disable();
return true;
}
else
return false;
}
#pragma mark -
/*********************************************************************************
ClickIsInImage
return whether or not the click occurred inside the image.
Note that this relies on inMouseDown.whereLocal, which is set to local
coordinates in LPane::Click. Don't call this before that happens! TCS note 12/24/02
*********************************************************************************/
Boolean CTCS_View::ClickIsInImage(const SMouseDownEvent &inMouseDown)
{
TCS_Rect imageRect;
TCS_SetRect(&imageRect, 0, 0, mImageSize.width, mImageSize.height);
return TCS_PtInRect(inMouseDown.whereLocal, imageRect);
}/*********************************************************************************
AdjustMouseSelf
adjust the cursor for this view. This just calls the superview's
AdjustCursor
*********************************************************************************/
void CTCS_View::AdjustMouseSelf(TCS_Point inPortPt, const TCS_EventRecord &inMacEvent,
TCS_RgnHandle outMouseRgn)
{
if (mSuperView)
mSuperView->AdjustMouseSelf(inPortPt, inMacEvent, outMouseRgn);
}
|