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

Windows (Source Code)

Link to: header | other interface directory

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

Comments

CTCS_Window

This class manages 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 screen windows.

SUPERCLASS = LWindow

Constructor

/*********************************************************************************
constructor from stream
*********************************************************************************/
CTCS_Window::CTCS_Window(LStream *inStream)
: THE_SUPERCLASS(inStream)
{
#if TCS_CANUSE_QUICKTIME
mOffscreenWorld = nil;
#endif
mDrawOffscreen = false;
mDrawingSelf = false;

mWindowBounds.top = 0;
mWindowBounds.left = 0;
mWindowBounds.right = 0;
mWindowBounds.bottom = 0;

mDockedWindowBounds = mWindowBounds; // TCS 9/23/02

mUserIsClosing = false;
}/*********************************************************************************
destructor
*********************************************************************************/
CTCS_Window::~CTCS_Window()
{
// rev TCS 12/24/00, rev 1/19/01
DB_WindowManager::WindowClosing(this, mUserIsClosing);
}

Source Code

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

create a window

*********************************************************************************/
CTCS_Window *CTCS_Window::MakeWindow(const ResIDT windResID, LCommander *inSuper,
const SInt32 windID, const CTextString &inTitle,
const Boolean showWindow, const Boolean registerWindow)
{
// 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_Window *window =
TCS_SAFE_CAST(LMDIChildWnd::MakeWindow(windResID, inSuper), CTCS_Window);
#else
CTCS_Window *window =
TCS_SAFE_CAST(LWindow::MakeWindow(windResID, inSuper), CTCS_Window);
// 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_Window::SetWindowTitle(window, inTitle);

// register the window- which adds it to menus, etc
if (registerWindow) // rev TCS 12/28/00
DB_WindowManager::RegisterWindow(window, 0, windID, 0);

if (showWindow)
SHOW_AND_SELECT_WIND(window);

return window;
}
/*********************************************************************************

GetWindowTitle (static) renamed TCS 8/10/00

return the window's title as a Cstring

*********************************************************************************/
CTextString CTCS_Window::GetWindowTitle(LWindow *aWindow)
{
if (aWindow) // rev TCS 12/2/02
{
Str255 pstring;
aWindow->GetDescriptor(pstring);
return CTextString(pstring);
}
else
return cEmptyString;
}
/*********************************************************************************

GetTitleBarHeight TCS 12/11/02

get the window's title bar size. Note that we assume this is a standard
window. No provision is made right now for windows that don't have a title bar.

*********************************************************************************/
SInt16 CTCS_Window::GetTitleBarHeight() const
{
#if TCS_FOR_MAC
// on the Mac, we need to offset the window by its title bar height
return 20;
#else
// on windows we use a smaller offset TCS 12/13/02
return 5;
#endif
}#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

SetWindowTitle (static) renamed TCS 8/10/00

set the window's title
*********************************************************************************/
void CTCS_Window::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_Window::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_Window::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
}
/*********************************************************************************

EstablishPort

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

*********************************************************************************/
Boolean CTCS_Window::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();
}
#if CAN_USE_MARK
#pragma mark -
#endif
/*********************************************************************************

Draw VP 5/21/96

Draw the window, either offscreen or on
*********************************************************************************/
void CTCS_Window::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_Window::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_Window::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_Window::Activate()
{
THE_SUPERCLASS::Activate();

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

// let the window manager know a window is being activated
DB_WindowManager::WindowComingToFront(this);

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

HideSelf

this notifies the window mgr that we are being hidden

*********************************************************************************/
void CTCS_Window::HideSelf()
{
THE_SUPERCLASS::HideSelf();

DB_WindowManager::WindowHiding(this);
}
/******************************************************************************

AttemptClose TCS removed 10/25/00, restored/revised 12/24/00

close a Window as a result of direct user action such as choosing the Close
menu command, or clicking the Close box.

We set a flag so the window position will be saved upon window destructor.
Note that upon quit, we go straight to DoClose so the menus are NOT updated
and window position is NOT saved(we do the latter in SaveWindowPositions instead)

*******************************************************************************/
Boolean CTCS_Window::AttemptClose()
{
// we set the flag so position info will be saved
mUserIsClosing = true;

// close the window
Boolean windowClosed = DoClose(true);

// if there were problems closing the window, reset the flag
if (!windowClosed)
mUserIsClosing = false;

return windowClosed;
}
/*********************************************************************************

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_Window::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_Window::RestoreTarget()
{
THE_SUPERCLASS::RestoreTarget();

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

gApplication->UpdateMenus();
}