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

Cursor Spinner (Source Code)

Link to: header | other interface directory

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

Comments

CCursorSpinner

This class spins the cursor for the Goldenseal accounting software,
project management software, construction accounting software
and construction project estimating software.

This class will usually be declared on the stack, so its constructor and destructor will be called
automatically. See comment at end of source for useage.

SUPERCLASS = none

Constructor

/*********************************************************************************
default constructor
*********************************************************************************/
CCursorSpinner::CCursorSpinner()
{
sNumSpinners++;

if (!sCurrentSpinner) // TCS 7/16/02
sCurrentSpinner = this;

Spin();
}
/*********************************************************************************
destructor
*********************************************************************************/
CCursorSpinner::~CCursorSpinner()
{
sNumSpinners--;
if (!sNumSpinners)
{
// reset to the default cursor
Reset();

// reset so the next spinner will spin until told not to TCS 8/21/01
KeepSpinning(true);
}

if (sCurrentSpinner == this) // TCS 7/16/02
sCurrentSpinner = nil;
}

Source Code

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

Spin

advance to the next cursor
*********************************************************************************/
void CCursorSpinner::Spin()
{
// if our spinner is turned off, do nothing
if (!sKeepSpinning)
return;

// set the cursor to the next frame
TCS_SetMouseCursor(sBaseResID + sCurrFrame - 1);
// increment the frame counter so that the next time
// Spin is called the next cursor frame will be used
sCurrFrame++;
if (sCurrFrame > sNumFrames)
{ // need to reset the frame counter as we have
// gone past the last frame
sCurrFrame = 1;
}
}
/*********************************************************************************

KeepSpinning TCS 8/21/01

turn the spinning action on or off. This will reset the static boolean, which
will remain the same until KeepSpinning is called again, or until all
spinners are removed.

If you put up a progress bar for lengthy operations but use a spinner for
short ones, call KeepSpinning(false) when you create the bar, so you don't
get ugly cursor flashing.
*********************************************************************************/
void CCursorSpinner::KeepSpinning(const Boolean inValue)
{
sKeepSpinning = inValue;
}
/*********************************************************************************

operator++

This is the overloaded pre-increment operator, i.e. it should be called
as { CCursorSpinner spinner;
++spinner; // right
spinner++; // WRONG! }
*********************************************************************************/
void CCursorSpinner::operator++ ()
{
Spin();
}/*********************************************************************************

Reset

reset the cursor
*********************************************************************************/
void CCursorSpinner::Reset()
{
TCS_InitMouseCursor();
}
/*********************************************************************************

RememberSpinner

rember this spinner so it can be accessed by outsiders
*********************************************************************************/
void CCursorSpinner::RememberSpinner()
{
sCurrentSpinner = this;
}
/*********************************************************************************

ForgetSpinner

forget this spinner so it can be accessed by outsiders
*********************************************************************************/
void CCursorSpinner::ForgetSpinner()
{
sCurrentSpinner = nil;
}
/* ******************************************************************************
How to use the CursorSpinner-
Usage is simple:

function BusyFunc()
{
CCursorSpinner spinner;

spinner.Spin();

// do stuff

spinner.Spin();

// do stuff

{
// you can create a spinner of exactly the same
// name within a pair of braces... this is legal
// and the class will still keep track
// of how many spinners are in operation!

CCursorSpinner spinner;

// do stuff

spinner.Spin();

// you can call a function which allocates another spinner no problem!

AnotherBusyFunc();

spinner.Spin();
}

// at the end of the function, since the spinners
// have been allocated on the stack, their destructors are
// called. The class will set the cursor back to normal
// if there are no active spinners
}

function AnotherBusyFunc()
{
CCursorSpinner spinner;

spinner.Spin();

// do stuff

spinner.Spin();
}

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