/**************************************************************/
/**  C++ code Copyright (C) Nick V. King <nking@eworld.com>  **/
/**************************************************************/

#include <gui_mac.h>

#include <utils_mac.h>
#include <headers_mac.h>
#include <ids_mac.h>

extern RGBColor redRGB;
extern RGBColor greenRGB;
extern RGBColor blackRGB;
extern RGBColor whiteRGB;
extern RGBColor offwhiteRGB;
extern RGBColor grayRGB;
extern RGBColor lngrayRGB;
extern RGBColor bkgrayRGB;
extern RGBColor tingeArrayRGB[];

/**************************************************************/
/*  Routines to save and restore foreground and background    */
/**************************************************************/

void SaveColors(RGBColor& saveForegroundRGB, RGBColor& saveBackgroundRGB)
{
	GetForeColor(&saveForegroundRGB);
	GetBackColor(&saveBackgroundRGB);
}

void RestoreColors(RGBColor& saveForegroundRGB, RGBColor& saveBackgroundRGB)
{
	RGBForeColor(&saveForegroundRGB);
	RGBBackColor(&saveBackgroundRGB);
}

/**************************************************************/
/*  Routines to draw and erase panels                         */
/**************************************************************/

void DrawPanel(Rect theRect, ConstStr255Param theString, Boolean suspended)
{
	int left = theRect.left;
	int top = theRect.top;
	int right = theRect.right;
	int bottom = theRect.bottom;
	RGBColor foregroundRGB, backgroundRGB;
	SaveColors(foregroundRGB, backgroundRGB);
	if (!suspended)
	{
		RGBForeColor(&blackRGB);
		FrameRect(&theRect);
		RGBForeColor(&whiteRGB);
		MoveTo(left+1, bottom-3);
		LineTo(left+1, top+1);
		LineTo(right-3, top+1);
		RGBForeColor(&lngrayRGB);
		MoveTo(left+1, bottom-2);
		LineTo(right-2, bottom-2);
		LineTo(right-2, top+1);
		InsetRect(&theRect, 2, 2);
		RGBBackColor(&bkgrayRGB);
		EraseRect(&theRect);
		RGBForeColor(&tingeArrayRGB[0]);
	}
	else
	{
		RGBBackColor(&whiteRGB);
		InsetRect(&theRect, 1, 1);
		EraseRect(&theRect);
		RGBForeColor(&blackRGB);
		MoveTo(right-1, top);
		LineTo(right-1, bottom);
	}
	TextFont(geneva);
	TextSize(9);
	MoveTo(left+5, top+12);
	DrawString(theString);
	RestoreColors(foregroundRGB, backgroundRGB);
}

void ErasePanel(Rect theRect)
{
	RGBColor foregroundRGB, backgroundRGB;
	SaveColors(foregroundRGB, backgroundRGB);
	InsetRect(&theRect, 1, 1);
	RGBBackColor(&whiteRGB);
	EraseRect(&theRect);
	RestoreColors(foregroundRGB, backgroundRGB);
}

void ErasePanelOffwhite(Rect theRect)
{
	RGBColor foregroundRGB, backgroundRGB;
	SaveColors(foregroundRGB, backgroundRGB);
	InsetRect(&theRect, 1, 1);
	RGBBackColor(&offwhiteRGB);
	EraseRect(&theRect);
	RestoreColors(foregroundRGB, backgroundRGB);
}

/**************************************************************/
/*  Routine to display status messages                        */
/**************************************************************/

void DisplayStatus(short theStringIndex) 
{
	GDHandle			saveDevice;
	CGrafPtr			savePort;
	extern WindowPtr	mainWindow;
	extern GDHandle		currentDevice;
	extern Str255		statusString;
	extern Rect			statusRect;
	extern Boolean		suspended;
	
	GetGWorld(&savePort, &saveDevice);
	SetGWorld((CGrafPtr)mainWindow, currentDevice);
	GetIndString(statusString, statusStringsID, theStringIndex+1);
	DrawPanel(statusRect, statusString, suspended || (mainWindow != FrontWindow()));
	SetGWorld(savePort, saveDevice);
}

/**************************************************************/
/*  Routine to display progress bar                           */
/**************************************************************/

void DrawProgressBar(short percentageDone)
{
	extern short currentProgress;

	if ((percentageDone == -1) || ((percentageDone == 100) && (currentProgress == -1)))
		return;

	if (percentageDone >= currentProgress)
	{
		CGrafPtr			savePort;
		GDHandle			saveDevice;
		extern WindowPtr	mainWindow;
		extern GDHandle		currentDevice;
		extern Rect			statusRect;
		
		GetGWorld(&savePort, &saveDevice);
		SetGWorld((CGrafPtr)mainWindow, currentDevice);
		RGBColor foregroundRGB, backgroundRGB;
		SaveColors(foregroundRGB, backgroundRGB);
		Rect theBar;
		SetRect(&theBar, 50, statusRect.top+4, 194, statusRect.bottom-4);
		RGBForeColor(&blackRGB);	
		FrameRect(&theBar);
		SetRect(&theBar, 51, statusRect.top+5, 51+(short)(142*percentageDone/100.0), statusRect.bottom-5);
		RGBForeColor(&grayRGB);	
		PaintRect(&theBar);
		SetRect(&theBar, 51+(short)(142*percentageDone/100.0), statusRect.top+5, 193, statusRect.bottom-5);
		RGBBackColor(&tingeArrayRGB[15]);	
		EraseRect(&theBar);
		RestoreColors(foregroundRGB, backgroundRGB);
		SetGWorld(savePort, saveDevice);

		currentProgress = percentageDone == 100 ? -1 : percentageDone;
	}
}

/**************************************************************/
/*  Routine to draw memory usage bar                          */
/**************************************************************/

void DisplayMemoryBar(void)
{
	extern WindowPtr	mainWindow;
	extern GDHandle		currentDevice;
	extern Rect			statusRect;

	CGrafPtr savePort;
	GDHandle saveDevice;
	GetGWorld(&savePort, &saveDevice);
	SetGWorld((CGrafPtr)mainWindow, currentDevice);
	RGBColor foregroundRGB, backgroundRGB;
	SaveColors(foregroundRGB, backgroundRGB);

	ProcessSerialNumber thisProcess = { 0, kCurrentProcess };
	ProcessInfoRec currentInfo;
	currentInfo.processInfoLength = sizeof(ProcessInfoRec);
	currentInfo.processName = 0;
	currentInfo.processAppSpec = 0;
	GetProcessInformation(&thisProcess, &currentInfo);
	float fractionUsed = 1-(currentInfo.processFreeMem/(float)currentInfo.processSize);

	DrawPanel(statusRect, "\pMemory:", false);
	Rect theBar;
	SetRect(&theBar, 50, statusRect.top+4, 194, statusRect.bottom-4);
	RGBForeColor(&blackRGB);	
	FrameRect(&theBar);
	SetRect(&theBar, 51, statusRect.top+5, 51+(short)(142*fractionUsed), statusRect.bottom-5);
	RGBForeColor(currentInfo.processFreeMem < minimumMemoryFree ? &redRGB : &greenRGB);
	PaintRect(&theBar);
	SetRect(&theBar, 51+(short)(142*fractionUsed), statusRect.top+5, 193, statusRect.bottom-5);
	RGBBackColor(&grayRGB);	
	EraseRect(&theBar);
	for (long megaBytes = 1048576; megaBytes < currentInfo.processSize; megaBytes += 1048576)
	{
		float fractionAlong = megaBytes/(float)currentInfo.processSize;
		RGBForeColor(fractionAlong > fractionUsed ? &whiteRGB : &grayRGB);
		MoveTo(51+(short)(142*fractionAlong), statusRect.bottom-6);
		Line(0, -2);
	}

	RestoreColors(foregroundRGB, backgroundRGB);
	SetGWorld(savePort, saveDevice);
}

/**************************************************************/
/*  Routine to draw offscreen info bar                        */
/**************************************************************/

void DisplayOffscreenInfo(void)
{
	extern GWorldPtr	offscreenGWorld;
	extern WindowPtr	mainWindow;
	extern GDHandle		currentDevice;
	extern Rect			statusRect;

	CGrafPtr savePort;
	GDHandle saveDevice;
	GetGWorld(&savePort, &saveDevice);
	SetGWorld((CGrafPtr)mainWindow, currentDevice);

	Str255 widthString, heightString;
	NumToString(offscreenGWorld->portRect.right, widthString);
	NumToString(offscreenGWorld->portRect.bottom, heightString);
	ConcatenateStrings(widthString, "\px");
	ConcatenateStrings(widthString, heightString);
	DrawPanel(statusRect, widthString, false);

	SetGWorld(savePort, saveDevice);
}

/**************************************************************/
/*  Routines to draw GrowIcon                                 */
/**************************************************************/

void ShowGrowBox(WindowPtr theWindow, short theToolbarHeight)
{
	SetPort(theWindow);
	RGBColor foregroundRGB, backgroundRGB;
	SaveColors(foregroundRGB, backgroundRGB);
	RGBForeColor(&blackRGB);
	MoveTo(0, theToolbarHeight-1);
	LineTo((*theWindow).portRect.right, theToolbarHeight-1);
	MoveTo(200, (*theWindow).portRect.bottom);
	LineTo(200, (*theWindow).portRect.bottom-15);
	RgnHandle tempClipRgn = NewRgn();
	GetClip(tempClipRgn);
	Rect growIconClipRect;
	SetRect(&growIconClipRect, 0, theToolbarHeight, (*theWindow).portRect.right, (*theWindow).portRect.bottom);
	ClipRect(&growIconClipRect);
	DrawGrowIcon(theWindow);
	SetClip(tempClipRgn);
	DisposeRgn(tempClipRgn);
	Rect growIconRect;
	SetRect(&growIconRect,
	(*theWindow).portRect.right-14, (*theWindow).portRect.bottom-14,
	(*theWindow).portRect.right, (*theWindow).portRect.bottom);
	ValidRect(&growIconRect);
	RestoreColors(foregroundRGB, backgroundRGB);
}

/**************************************************************/
/*  Routine to draw a color control                           */
/**************************************************************/

void DrawColorControl(int whichControl, Rect *whichRect, int state)
{
	RGBColor foregroundRGB, backgroundRGB;
	
	SaveColors(foregroundRGB, backgroundRGB);
	Rect theRect = *whichRect;
	short right = theRect.right;
	short top = theRect.top;
	short left = theRect.left;
	short bottom = theRect.bottom;
	if (whichControl < upButtonID)
	{
		RGBForeColor(&blackRGB);
		FrameRect(&theRect);
	}
	if ((state == -1) && (whichControl < upButtonID))
	{
		RGBBackColor(&bkgrayRGB);
		InsetRect(&theRect, 1, 1);
		EraseRect(&theRect);
		MoveTo(left, top);
	}
	else if (state == 1)
	{
		RGBForeColor(&lngrayRGB);
		MoveTo(left+1, bottom-2);
		LineTo(left+1, top+1);
		LineTo(right-2, top+1);
		RGBBackColor(&bkgrayRGB);
		InsetRect(&theRect, 2, 2);
		theRect.right += 1;
		theRect.bottom += 1;
		EraseRect(&theRect);
		MoveTo(left+1, top+1);
	}
	else
	{
		RGBForeColor(&whiteRGB);
		MoveTo(left+1, bottom-3);
		LineTo(left+1, top+1);
		LineTo(right-3, top+1);
		RGBForeColor(&lngrayRGB);
		MoveTo(right-2, top+1);
		LineTo(right-2, bottom-2);
		LineTo(left+1, bottom-2);
		RGBBackColor(&bkgrayRGB);
		InsetRect(&theRect, 2, 2);
		EraseRect(&theRect);
		MoveTo(left, top);
	}
	if (whichControl == firstButtonID)
		FirstButton(state);
	else if (whichControl == priorButtonID)
		PriorButton(state);
	else if (whichControl == replotButtonID)
		ReplotButton(state);
	else if (whichControl == nextButtonID)
		NextButton(state);
	else if (whichControl == lastButtonID)
		LastButton(state);
	else if (whichControl == setButtonID)
		SetButton();
	else if (whichControl == upButtonID)
		SmallUpButton(state);
	else if (whichControl == downButtonID)
		SmallDownButton(state);
	PenNormal();
	RestoreColors(foregroundRGB, backgroundRGB);
}

/**************************************************************/
/*  Routines to draw different button types                   */
/**************************************************************/

void FirstButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		PenPat((ConstPatternParam)&qd.gray);
		PenMode(notPatCopy);
	}
	else
		RGBForeColor(&tingeArrayRGB[0]);
	Move(4, 11);
	Line(0, -7);
	Line(1, 0);
	Move(5, 0);
	Line(-3, 3);
	Line(0, 1);
	Line(3, 3);
	if (state != -1)
		RGBForeColor(&tingeArrayRGB[7]);
	Move(-5, 0);
	Line(0, -6);
	Move(5, 0);
	Line(0, 5);
	Move(-1, -1);
	Line(0, -3);
	Move(-1, 1);
	Line(0, 1);
	if (state != -1)
	{
		RGBForeColor(&tingeArrayRGB[15]);
		Move(-2, -4);
		Line(0, 7);
		Move(5, 0);
		Line(0, -7);
	}
}

void PriorButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		PenPat((ConstPatternParam)&qd.gray);
		PenMode(patCopy);
	}
	else
		RGBForeColor(&tingeArrayRGB[0]);
	Move(8, 4);
	Line(-3, 3);
	Line(0, 1);
	Line(3, 3);
	if (state != -1)
		RGBForeColor(&tingeArrayRGB[7]);
	Move(0, -1);
	Line(0, -5);
	Move(-1, 1);
	Line(0, 3);
	Move(-1, -1);
	Line(0, -1);
	if (state != -1)
	{
		RGBForeColor(&tingeArrayRGB[15]);
		Move(3, -3);
		Line(0, 7);
	}
}

void ReplotButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		PenPat((ConstPatternParam)&qd.gray);
		PenMode(notPatCopy);
	}
	else
		RGBForeColor(&tingeArrayRGB[0]);
	Move(7, 7);
	Line(-3, -3);
	Line(7, 0);
	Move(0, 6);
	Line(-7, 0);
	Line(0, 1);
	if (state != -1)
		RGBForeColor(&tingeArrayRGB[7]);
	Move(2, -6);
	Line(4, 0);
	Move(-3, 1);
	Line(2, 0);
	Line(-1, 1);
	Move(-3, 4);
	Line(6, 0);
	if (state != -1)
	{
		RGBForeColor(&tingeArrayRGB[15]);
		Move(1, -1);
		Line(0, 2);
		Line(-8, 0);
		Move(5, -5);
		Line(3, -3);
	}
}

void NextButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		PenPat((ConstPatternParam)&qd.gray);
		PenMode(patCopy);
	}
	else
		RGBForeColor(&tingeArrayRGB[0]);
	Move(6, 4);
	Line(0, 7);
	if (state != -1)
		RGBForeColor(&tingeArrayRGB[7]);
	Move(1, -1);
	Line(0, -5);
	Move(1, 1);
	Line(0, 3);
	Move(1, -1);
	Line(0, -1);
	if (state != -1)
	{
		RGBForeColor(&tingeArrayRGB[15]);
		Move(-2, -3);
		Line(3, 3);
		Line(0, 1);
		Line(-3, 3);
	}
}

void LastButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		PenPat((ConstPatternParam)&qd.gray);
		PenMode(notPatCopy);
	}
	else
		RGBForeColor(&tingeArrayRGB[0]);
	Move(4, 4);
	Line(0, 7);
	Move(6, -7);
	Line(-1, 0);
	Line(0, 7);
	if (state != -1)
		RGBForeColor(&tingeArrayRGB[7]);
	Move(-4, -6);
	Line(0, 5);
	Move(1, -1);
	Line(0, -3);
	Move(1, 1);
	Line(0, 1);
	Move(3, -3);
	Line(0, 6);
	if (state != -1)
	{
		RGBForeColor(&tingeArrayRGB[15]);
		Move(-5, -7);
		Line(3, 3);
		Line(0, 1);
		Line(-3, 3);
		Move(6, 0);
		Line(0, -7);
	}
}

void SetButton(void)
{
	Str255 buttonString;
	GetIndString(buttonString, miscStringsID, setStringIndex); 
	RGBForeColor(&tingeArrayRGB[0]);
	Move(9, 12);
	DrawString(buttonString);
}

void SmallUpButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		Move(3, 4);
		Line(2, -2);
		Line(2, 2);
		Move(-2, 0);
		Line(0, 0);
		return;
	}
	RGBForeColor(&tingeArrayRGB[0]);
	Move(3, 5);
	Line(0, -1);
	Line(2, -2);
	RGBForeColor(&tingeArrayRGB[7]);
	Move(0, 1);
	Line(1, 0);
	Move(1, 1);
	Line(-3, 0);
	Move(0, 1);
	Line(3, 0);
	RGBForeColor(&tingeArrayRGB[15]);
	Move(1, 0);
	Line(0, -1);
	Line(-2, -2);
}

void SmallDownButton(int state)
{
	if (state == -1)
	{
		RGBForeColor(&tingeArrayRGB[7]);
		Move(3, 3);
		Line(2, 2);
		Line(2, -2);
		Move(-2, 0);
		Line(0, 0);
		return;
	}
	RGBForeColor(&tingeArrayRGB[0]);
	Move(7, 2);
	Line(-4, 0);
	Line(0, 1);
	Line(2, 2);
	RGBForeColor(&tingeArrayRGB[7]);
	Move(-1, -2);
	Line(3, 0);
	Move(-1, 1);
	Line(-1, 0);
	RGBForeColor(&tingeArrayRGB[15]);
	Move(1, 1);
	Line(2, -2);
	Line(0, -1);
}

/**************************************************************/
/*  Routine to draw a color panel                             */
/**************************************************************/

void DrawColorPanel(Rect theRect)
{
	RGBForeColor(&whiteRGB);
	MoveTo(theRect.left+1, theRect.bottom-3);
	LineTo(theRect.left+1, theRect.top+1);
	LineTo(theRect.right-3, theRect.top+1);

	RGBForeColor(&lngrayRGB);
	MoveTo(theRect.left+1, theRect.bottom-2);
	LineTo(theRect.right-2, theRect.bottom-2);
	LineTo(theRect.right-2, theRect.top+1);
	
	InsetRect(&theRect, 2, 2);
	RGBBackColor(&bkgrayRGB);
	EraseRect(&theRect);
}

/**************************************************************/
/*  Routine to draw an entire edit field                      */
/**************************************************************/

void DrawEditField(short offset, toolbarFieldRec* toolbarField, Boolean isCurrentEditField)
{
	short titleLength = 5+StringWidth(toolbarField->titleString);
	if (titleLength > 5)
		titleLength += 3;
	short fieldLength = toolbarField->length;
	short unitsLength = 3+StringWidth(toolbarField->unitsString);
	if (unitsLength > 3)
		unitsLength += 3;
	short buttonsLength = 2;
	if (toolbarField->flags & hasButtonsMask)
		buttonsLength += 11;
	short popupLength = 0;
	if (toolbarField->flags & hasPopupMask)
		popupLength += 14;

	SetRect(&toolbarField->bounds, 0, -1, titleLength+fieldLength+unitsLength+popupLength+buttonsLength, 15);
	SetRect(&toolbarField->editBounds, titleLength, -1, titleLength+fieldLength, 15);
	OffsetRect(&toolbarField->bounds, offset, 0);
	OffsetRect(&toolbarField->editBounds, offset, 0);

	if (toolbarField->flags & isButtonMask)
	{
		DrawColorControl(toolbarField->reference, &toolbarField->bounds, (int)toolbarField->contents);
		return;
	}

	RGBColor foregroundRGB, backgroundRGB;
	SaveColors(foregroundRGB, backgroundRGB);

	RGBForeColor(&blackRGB);
	FrameRect(&toolbarField->bounds);
	DrawColorPanel(toolbarField->bounds);

	Boolean isTitleOnly = (toolbarField->flags & hasPopupMask) && (toolbarField->contents == (Ptr)0);

	RGBForeColor(&tingeArrayRGB[0]);
	MoveTo(isTitleOnly ? offset+5+popupLength+2 : offset+5, 11);
	DrawString(toolbarField->titleString);
	if (!isCurrentEditField)
		DrawFieldContents(toolbarField, false);
	RGBForeColor(&tingeArrayRGB[0]);
	MoveTo(offset+titleLength+fieldLength+3, 11);
	DrawString(toolbarField->unitsString);

	if (toolbarField->flags & hasButtonsMask)
	{
		RGBForeColor(&lngrayRGB);
		MoveTo(toolbarField->bounds.right-buttonsLength+1, 0);
		Line(0, 13);
		Rect buttonRect;
		SetRect(&buttonRect, toolbarField->bounds.right-buttonsLength+1, -1, toolbarField->bounds.right, 8); 
		DrawColorControl(upButtonID, &buttonRect, *(long*)toolbarField->contents >= toolbarField->maximum ? -1 : 0);
		SetRect(&buttonRect, toolbarField->bounds.right-buttonsLength+1, 6, toolbarField->bounds.right, 15); 
		DrawColorControl(downButtonID, &buttonRect, *(long*)toolbarField->contents <= toolbarField->minimum ? -1 : 0);
	}

	if (toolbarField->flags & hasPopupMask)
	{
		if (CountMItems(GetMHandle(toolbarField->popupID)) != 1)
		{
			if (isTitleOnly)
			{
				RGBForeColor(&whiteRGB);
				MoveTo(offset+popupLength+2, 0);
				Line(0, 12);
				RGBForeColor(&lngrayRGB);
				Move(-1, -12);
				Line(0, 12);
				MoveTo(offset+popupLength-7, 9);
			}
			else if (!(toolbarField->flags & hasButtonsMask) && (toolbarField->flags & editableMask))
			{
				RGBForeColor(&whiteRGB);
				MoveTo(toolbarField->bounds.right-popupLength-1, 0);
				Line(0, 12);
				RGBForeColor(&lngrayRGB);
				Move(-1, -12);
				Line(0, 12);
				MoveTo(toolbarField->bounds.right-buttonsLength-7, 9);
			}
			else
				MoveTo(toolbarField->bounds.right-buttonsLength-7, 9);
			RGBForeColor(&tingeArrayRGB[0]);
			Line(-3, -3);
			Line(7, 0);
			Line(-3, 3);
			RGBForeColor(&tingeArrayRGB[10]);
			Move(-2, -2);
			Line(3, 0);
			Move(-1, 1);
			Line(-1, 0);
		}
	}

	RestoreColors(foregroundRGB, backgroundRGB);
}

/**************************************************************/
/*  Routine to track buttons                                  */
/**************************************************************/

int TrackButton(Point startPt, Rect theButtonRect, short type, long repeatDelay, Boolean isRepeating)
{
	Boolean hilited = isRepeating;
	Boolean firstTimeAround = true;
	long downTicks = TickCount();
	if (PtInRect(startPt, &theButtonRect))
	{
		while (Button() || firstTimeAround)
		{
			firstTimeAround = false;
			GetMouse(&startPt);
			if (!hilited && PtInRect(startPt, &theButtonRect))
			{
				hilited = true;
				DrawColorControl(type, &theButtonRect, 1);
				PlaySoundEffect(mouseDownSoundID);
				downTicks = TickCount();
			}
			else if (hilited && !PtInRect(startPt, &theButtonRect))
			{
				hilited = false;
				DrawColorControl(type, &theButtonRect, 0);
				PlaySoundEffect(mouseUpSoundID);
			}
			else if (hilited && PtInRect(startPt, &theButtonRect) && repeatDelay && ((TickCount()-downTicks) > repeatDelay))
			{
				InvalRect(&theButtonRect);
				return(2);
			}
		}
		if (hilited)
		{
			InvalRect(&theButtonRect);
			PlaySoundEffect(mouseUpSoundID);
			return(1);
		}
	}
	return(0);
}

/**************************************************************/
/*  Routine to draw field contents only                       */
/**************************************************************/

void DrawFieldContents(toolbarFieldRec* toolbarField, Boolean eraseRequired)
{
	Rect theRect = toolbarField->editBounds;
	if (eraseRequired)
	{
		RGBBackColor(&bkgrayRGB);
		InsetRect(&theRect, 0, 2);
		EraseRect(&theRect);
		InsetRect(&theRect, 0, -2);
	}
	if (toolbarField->contents != 0)
	{
		Str255 tempString;
		if (toolbarField->flags & numericOnlyMask)
		{
			if ((toolbarField->flags & zeroIsAllMask) && (*(long*)toolbarField->contents == 0))
				GetIndString(tempString, miscStringsID, toolbarField->popupID);
			else
				NumToString(*(long*)toolbarField->contents, tempString);
		}
		else
		{
			if ((toolbarField->flags & zeroIsAllMask) && (*(char*)toolbarField->contents == 0))
				GetIndString(tempString, miscStringsID, noneStringIndex);
			else
				BlockMove((Str255)toolbarField->contents, tempString, 256);
		}
		RGBForeColor(&tingeArrayRGB[0]);
		MoveTo(theRect.left+1, theRect.top+12);
		short fieldLength = (theRect.right-theRect.left)-2;
		TruncString(fieldLength, tempString, smTruncEnd);
		DrawString(tempString);
	}
}

/***********/
/**  End  **/
/***********/