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

Simple Windows (Source Code)

Link to: header | other interface directory

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

Comments

CTCS_SimpleWindow

This class manages simple windows in the
Goldenseal small business accounting software,
project management software, construction accounting software
and construction software.

It's a buffer class for LWindow. Handles basic operations for windows. We use
this for a few windows that don't register with DB_WindowManager.

SUPERCLASS = LWindow

Constructor

/*********************************************************************************
constructor from stream
*********************************************************************************/
CTCS_SimpleWindow::CTCS_SimpleWindow(LStream *inStream)
: THE_SUPERCLASS(inStream)
{
mOffscreenWorld = nil;
mDrawOffscreen = false;
mDrawingSelf = false;
}

Source Code

/*********************************************************************************
MakeWindow (static)

create a window

*********************************************************************************/
CTCS_SimpleWindow *CTCS_SimpleWindow::MakeWindow(const ResIDT windResID, LCommander *inSuper,
const SInt32 windID, const CTextString &inTitle,
const Boolean showWindow)
{
NeoUsed(windID);

// sanity check
if (!TCS_WindowExistsMsg(windResID)) // TCS 6/14/99
return nil;

// create the window
#if TCS_FOR_WINDOWS
// added this branch for Windows mfs_sa 7may2k2
CTCS_SimpleWindow *window =
TCS_SAFE_CAST(LWnd::MakeWindow(windResID, inSuper), CTCS_SimpleWindow);
#else
CTCS_SimpleWindow *window =
TCS_SAFE_CAST(LWindow::MakeWindow(windResID, inSuper), CTCS_SimpleWindow);
// TCS changed this from MakeWindow
#endif
TCS_FailNILMsg(window, TCS_GetErrString(errID_BadWindow));

// set the title, if there is a title
if (inTitle.Length())
CTCS_SimpleWindow::SetWindowTitle(window, inTitle);

if (showWindow)
SHOW_AND_SELECT_WIND(window);

return window;
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

GetWindowTitle renamed TCS 8/10/00

return the window's title as a Cstring

*********************************************************************************/
CTextString CTCS_SimpleWindow::GetWindowTitle(LWindow *aWindow)
{
TCS_FailNILMsg(aWindow, TCS_GetErrString(errID_BadWindow));
Str255 pstring;
aWindow->GetDescriptor(pstring);
return CTextString(pstring);
}/*********************************************************************************

SetWindowTitle renamed TCS 8/10/00

set the window's title
*********************************************************************************/
void CTCS_SimpleWindow::SetWindowTitle(LWindow *aWindow, const CTextString &inString)
{
TCS_FailNILMsg(aWindow, TCS_GetErrString(errID_BadWindow));
Str255 pstring;
inString.GetPString(pstring);
aWindow->SetDescriptor(pstring);
}
/*********************************************************************************

SetIsShaded TCS 7/23/01

set the window's window shading

*********************************************************************************/
void CTCS_SimpleWindow::SetIsShaded(const Boolean isShaded)
{
if (isShaded)
{
TCS_SysBeep();
}

mIsShaded = isShaded;
}
#if CAN_USE_MARK
#pragma mark -
#endif/*********************************************************************************

ResizeTo

resize a window to the given width and height.
Modified TCS 6/24/98 to keep window centered in alert position
rev TCS 3/31/00-- changed params, then back to original TCS 4/5/00

*********************************************************************************/
void CTCS_SimpleWindow::ResizeTo(LWindow *aWindow, SInt16 aWidth, SInt16 aHeight)
{
SInt32 currentWidth, currentHeight,
widthChange, heightChange;

// get the current bounds
TCS_Rect bounds = UWindows::GetWindowStructureRect(aWindow->GetNativeWindow());

// calc the current width and height
currentWidth = bounds.right - bounds.left;
currentHeight = bounds.bottom - bounds.top;

// what is the adjustment to be made?
widthChange = (aWidth - currentWidth);
heightChange = (aHeight - currentHeight);

// adjust the bounds to the height and width
// we do math to avoid digit loss from truncation of odd values
bounds.left -= (widthChange / 2 );
bounds.top -= (heightChange / 3 );
bounds.right += (widthChange - widthChange / 2);
bounds.bottom += (heightChange - heightChange / 3);

// now let's make sure we're not too high
if (bounds.top < cScreenTop)
{
heightChange = cScreenTop - bounds.top;
bounds.top += heightChange;
bounds.bottom += heightChange;
}
aWindow->DoSetBounds(bounds);
//aWindow->AdjustUserBounds(); // added TCS 3/31/00
}
#if CAN_USE_MARK
#pragma mark -
#endif/*********************************************************************************

EstablishPort

establish the drawing port. This is overriden to use the global
offscreen world

*********************************************************************************/
Boolean CTCS_SimpleWindow::EstablishPort()
{
#if TCS_CANUSE_QUICKTIME
if (IsDrawingOffscreen())
{
Boolean portSet = (mOffscreenWorld != nil);

if (mDrawingSelf)
{
if ( portSet &&
(UQDGlobals::GetCurrentPort() != (TCS_GrafPtr) mOffscreenWorld) )
TCS_SetGWorld(mOffscreenWorld, nil);
}
else
portSet = THE_SUPERCLASS::EstablishPort();

return portSet;
}
else
#endif
return THE_SUPERCLASS::EstablishPort();
}/*********************************************************************************

Draw VP 5/21/96

Draw the window, either offscreen or on
*********************************************************************************/
void CTCS_SimpleWindow::Draw(TCS_RgnHandle inSuperDrawRgnH)
{
if (IsDrawingOffscreen())
{
TCS_TRY
{
DrawOffscreen(inSuperDrawRgnH);
}
TCS_CATCH
{
THE_SUPERCLASS::Draw(inSuperDrawRgnH);
}
}
else
THE_SUPERCLASS::Draw(inSuperDrawRgnH);
}/*********************************************************************************

DrawOffscreen major rev TCS 7/31/00

draw the contents of this window offscreen. Note that this is actually not
being used anywhere right now.

*********************************************************************************/
void CTCS_SimpleWindow::DrawOffscreen(TCS_RgnHandle inSuperDrawRgnH)
{
//#if TCS_FOR_MAC
// Don't draw if invisible or unable to put in focus
if (IsVisible() && FocusDraw())
{ // Area of this View to draw is the intersection of inSuperDrawRgnH
// with the Revealed area of this View
TCS_RgnHandle updateRegionHandle = mUpdateRgn; // TCS 7/31/00
TCS_FailNILMsg(updateRegionHandle, TCS_GetErrString(errID_BadWindow));

TCS_RectRgn(updateRegionHandle, &mRevealedRect);
//TCS_RectRgn(mUpdateRgnH, &mRevealedRect);
if (inSuperDrawRgnH != nil)
{
TCS_SectRgn(inSuperDrawRgnH, updateRegionHandle, updateRegionHandle);
//TCS_SectRgn(inSuperDrawRgnH, mUpdateRgnH, mUpdateRgnH);
}
Boolean updateEmpty = TCS_EmptyRgn(updateRegionHandle);
//Boolean updateEmpty = TCS_EmptyRgn(mUpdateRgnH);
if (!updateEmpty)
{ // Some portion needs to be drawn, set up Offscreen World for drawing
// Bounds of Offscreen World are the bounds of the region of this View
// that needs to be redrawn
TCS_Rect offBounds = TCS_GetRegionBounds(updateRegionHandle);
//TCS_Rect offBounds = (**mUpdateRgnH).rgnBBox;
TCS_OffsetRect(&offBounds, mPortOrigin.h, mPortOrigin.v);

// Save portRect of the current Port
TCS_GrafPtr currentPort;
TCS_GetPort(&currentPort);
TCS_Rect onscreenPortRect = TCS_GetPortRect(currentPort);

// Allocate a stack-based Offscreen World
// Subsequent drawing will take place in
// this Offscreen World
StOffscreenGWorld offWorld(offBounds, 8);

// To keep coord systems in synch, set
// the portRect of the Offscreen World
// to that of the original port
mOffscreenWorld = offWorld.GetMacGWorld();
TCS_SetGWorldRect(mOffscreenWorld, onscreenPortRect);

mDrawingSelf = true; // Prevents subpanes from changing Ports
OutOfFocus(nil); // Offscreen World needs to be focused
FocusDraw();
// Draw this view and its subpanes
// into the Offscreen World. Offscreen
// image will be copied to original port
// when offWorld's destructor is called.
TCS_Rect frame;
CalcLocalFrameRect(frame);
if (ExecuteAttachments(msg_DrawOrPrint, &frame)) {
DrawSelf();
}
TArrayIterator<LPane*> iterator(mSubPanes); // rev TCS 7/31/00 LListIterator is obsolete
LPane *theSub;
while (iterator.Next(theSub)) // rev TCS 8/4/00
{
theSub->Draw(updateRegionHandle);
//theSub->Draw(mUpdateRgnH);
}

OutOfFocus(nil); // Make sure Offscreen World is focused
FocusDraw(); // since it will actually draw at the
// end of this scope
mDrawingSelf = false;
}
if (!updateEmpty)
{ // after all the drawing is done, draw the size box
FocusDraw();
DrawSizeBox();
}

TCS_EmptyRgn(updateRegionHandle);
//TCS_SetEmptyRgn(mUpdateRgnH); // Emptying update region frees up memory
// if this region wasn't rectangular
}
//#endif
}/*********************************************************************************

DrawSelf

draw the window.

VP 7/3/96
*********************************************************************************/
void CTCS_SimpleWindow::DrawSelf()
{
if (!IsDrawingOffscreen())
{ // we're not drawing offscreen, so call the inherited
// method to do its thing, which includes drawing the sizebox
THE_SUPERCLASS::DrawSelf();
}
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

Activate

activate this window. We perform the inherited behaviour and then
notify the window manager that we have been selected

*********************************************************************************/
void CTCS_SimpleWindow::Activate()
{
THE_SUPERCLASS::Activate();

// sanity check
TCS_FailNILMsg(gApplication, TCS_GetErrString(errID_BadApplication));


// update menus as well
if (IsOnDuty() && GetUpdateCommandStatus())
gApplication->UpdateMenus();
}

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

DoClose

close the window. We override to first pass along a quit message, which will
get permission from the window contents before closing

*********************************************************************************/
Boolean CTCS_SimpleWindow::DoClose(const Boolean sendMessage)
{
if (AttemptQuit(quit_closewindow))
return THE_SUPERCLASS::DoClose(sendMessage);
else
return false;
}/*********************************************************************************

RestoreTarget

restore the target for this window. We override to update the menus

*********************************************************************************/
void CTCS_SimpleWindow::RestoreTarget()
{
THE_SUPERCLASS::RestoreTarget();

// sanity check
TCS_FailNILMsg(gApplication, TCS_GetErrString(errID_BadApplication));

gApplication->UpdateMenus();
}