/*===============================
Copyright © 1998-2003 Brian Hall

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*===============================*/
#ifndef __BLUGSPRIVATE__
#define __BLUGSPRIVATE__

#ifdef __APPLE_CC__
#include <Carbon/Carbon.h>
#else
#ifndef __CONTROLDEFINITIONS__
	#include <ControlDefinitions.h>
#endif
#ifndef __CONTROLS__
	#include <Controls.h>
#endif
#ifndef __LOWMEM__
	#include <LowMem.h>
#endif
#ifndef __RESOURCES__
	#include <Resources.h>
#endif
#ifndef __TOOLUTILS__
	#include <ToolUtils.h>
#endif
#endif



#pragma mark Debug
// We define __DEBLUG__ to 1 in the prefixes and MPW makefiles if we want debug versions.
#ifndef __DEBLUG__
	#define __DEBLUG__							0
#endif


#if __DEBLUG__
	
	//extern Boolean								gHandlerFlag;
#if TARGET_RT_MAC_MACHO
	#define _StringConstant(s)						s
	#define _AssertStr(x,y)							if (!(x)) printf("%s: %s %d\n",_StringConstant(y),\
																		__FILE__, __LINE__)
#else
	#define _StringConstant(s)						"\p"##s
	#define _AssertStr(x,y)							if (!(x)) DebugStr(_StringConstant(y))
#endif
	#define _SetHandlerFlag(list)					bl_Set((*list)->privateFlags,blSuppressIdle)
	#define _ClearHandlerFlag(list)					bl_Clear((*list)->privateFlags,blSuppressIdle)
	// Yell and scream then execute the return expression
	// Don't need a semicolon!
	#if TARGET_RT_MAC_MACHO
		extern const char*					gHandlerFlagDebugMsg;
		#define _CheckHandlerFlag(list)	\
			if (bl_Test((*list)->privateFlags,blSuppressIdle)) \
			{ printf("%s: %s %d\n",gHandlerFlagDebugMsg,__FILE__, __LINE__);}
	#else
		extern const unsigned char			gHandlerFlagDebugMsg[];
		#define _CheckHandlerFlag(list)	\
			if (bl_Test((*list)->privateFlags,blSuppressIdle)) \
			{ DebugStr(gHandlerFlagDebugMsg); }
	#endif
#else
	#define _AssertStr(x,y)
	//#define _Debug(x)
	#define _SetHandlerFlag
	#define _ClearHandlerFlag
	#define _CheckHandlerFlag(inList)
#endif

#pragma mark Live Scroll Stuff
//===============================
typedef	pascal void (*IndicatorActionProc)(void);
typedef UniversalProcPtr IndicatorActionUPP;

#define NewIndicatorActionProc(userRoutine)		\
	(IndicatorActionUPP) NewRoutineDescriptor((ProcPtr)(userRoutine), kPascalStackBased, GetCurrentArchitecture())

#define CallIndicatorActionProc(userRoutine)	\
		CallUniversalProc((UniversalProcPtr)(userRoutine), kPascalStackBased)


#pragma mark Forward Declarations
typedef struct BlugsRec			/**BlugsPtr,*/ **BlugsHdl;
#define BlugsRef				BlugsHdl
#include "Blugs.h"


#pragma mark Basic Defines
typedef UInt32			BLPixelOffset;

// Use of a Rect could be troublesome when we want to make sure row and column numbers are
//	always positive.
typedef struct
{
	UInt16	top;
	UInt16	left;
	UInt16	bottom;
	UInt16	right;
} BLCellRange;

#pragma mark ¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
/* The horizontal title bar is responsible for drawing the dummy placard at left and right.
The vertical title bar is responsible for the one at its bottom.*/
#pragma mark Title
typedef struct
{
	Handle				data;
	BLContentType		contentType;
	UInt16				flags;
} BLTitleRec, *BLTitlePtr;

typedef BLTitleRec		BLTitleArray[1];
typedef BLTitleArray**	BLTitleArrayHdl;

// Title flags
enum
{
	blTitleTempSelected		= 1 << 0,	// Used internally for processing clicks on titles
	blTitleBeingDragged		= 1 << 1	// Used internally to draw drag feedback
};

// When there are both vertical and horizontal bars, the top left intersection can be turned
//	into a 'widget' by giving it a content handler. The relevant information is stored in the
//	record for the vertical title bar (this is an arbitrary decision).
#pragma mark Title Bar
typedef struct
{
	BLTitleArrayHdl		titles;
	Handle				topLeftStorage;	// Data storage area for top left corner widget.
	BLUID				whichSelected;	// Titles have radio button behavior; only 1 at a time selected.
	BLContentType		topLeftContent;	// Top left corner content type.
	BLContentType		defaultContentType; // Titles are inited to this type.
	ControlFontStyleRec	fontStyle;		// Used by vertical bar; horizontal may want column
										//	data; unsure about correct policy on that.
	UInt16				thickness;
	UInt16				flags;			// Low-order bits are public; high are private
	UInt16				defaultTitleFlags;
} BLTitleBarRec, **BLTitleBarHdl;
#define BLTitleBarRef			BLTitleBarHdl


// Title bar flags
// Always clear the private bits of a flag param when passed or read from a resource
//	to make sure there's no garbage data passed in.
enum
{
	blTitleBarVertical		 = 1 << 15
};


// Row data flags
enum
{	
	blTrianglePressed		= 1 << 6,		// Temporarily set when cell needs to be drawn
											//	with the triangle selected.
	blUndisclosed			= 1 << 7		// Derived. If any parent is collapsed, this is set.
};

#define blAllPublicRowFlags		(blRowHasChildren | blRowIsExpanded | blRowIsTitleRow | \
								blRowDrawBorder | blRowMarkedForMovement | blRowSelectAll)
#define blAllPublicColumnFlags	(blColumnCantSelect | blColumnDrawBorder)


#pragma mark ¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥
#pragma mark BlugsRec
//===============================
typedef struct BlugsRec
{
	BLUID						nextRowID;
	BLUID						nextColID;
	BLUID						rep; // Redirect selection to this column.
	Handle						rowData;
	Handle						colData;
	Handle						vWidgets;
	Handle						hWidgets;
	BLPixelOffset				vScrollLoc;
	BLPixelOffset				hScrollLoc;
	BLPixelOffset				totalHeight;
	BLPixelOffset				totalWidth;
	BLCallbacksRec				callbacks;
	WindowRef					window;
	GWorldPtr					world;		// For drawing the viewRect part of content.
	ControlRef					vScroll;
	ControlRef					hScroll;
	ControlRef					userPane;	// The user pane control that encapsulates this list.
	Handle						userData;
	Handle						cellIndex;
	BLTitleBarHdl				vTitle;
	BLTitleBarHdl				hTitle;
#if __BL_USE_CARBON_API__
	EventLoopTimerRef			timer;
#endif
	UInt32						pendingInlineTime;	// Time of the click that started it
	UInt32						lastClickTime;
	UInt32						lastKeyTime;	// Last time alphanumeric key was directed at list
	UInt32						listFlags;
	Rect						rect;		// Includes scrollbars & titles
	BLCellRange					visCells;
	Point						defaultCellSize;
	BLCellUID					lastClickCell;
	BLCellUID					inlineEditCell;	// If there is an inline going on, this is the cell
	BLUID						primarySortColumn;
	UInt16						nRows;
	UInt16						nColumns;
	UInt16						nVWidgets;
	UInt16						nHWidgets;
	UInt16						nUserEntries;
	UInt16						privateFlags;
	UInt16						dragFlags;
	UInt16						defaultRowFlags;
	UInt16						defaultColumnFlags;
	UInt16						indent;			// Initialized to blDefaultIndent.
	UInt16						disclosureColumn; // Where to draw triangle. If 0, use column 1.
	UInt16						lastInsertionCaretRow;		// Where did we draw it when dragging.
	UInt16						lastInsertionCaretDisclosure;
	Point						lastInsertionCaretPos; // coords of arrow and line
	UInt8						vScrollDistance;	// Set to zero to use defaults.
	UInt8						hScrollDistance;
	BLSortState					sortState;
	Str255						keyString;
} BlugsRec;


#pragma mark List Private Flags
enum
{
	blInlineEditNow		= 1 << 0,	// Set if there is currently an inline edit session happening
	blDraggingHorzTitle	= 1 << 1,	// Set and cleared within BLTrackDrag
	blDraggingVertTitle	= 1 << 2,	// Set and cleared within BLTrackDrag
	blDraggingContent	= 1 << 3,	// Set and cleared within BLTrackDrag
	blFocused			= 1 << 4,	// Set if the list is focused (draw focus ring around list)
	blHaveDoubleClick	= 1 << 5,	// Set if the last click was the second click of a double
									//	click. This way we can identify a triple click.
	blPendingInline		= 1 << 6,	// Set when the handler tracks and accepts an inline edit
									//	click, and we want to wait to see if there are any other
									//	mouse events to prevent the edit from starting.
	blNeedUpdate		= 1 << 7,	// Something needs to be drawn offscreen but autodraw is off.
									//	When autodraw goes back on, we will need to update
									//	the whole offscreen world.
	blHaveDrawnInsertionCaret
						= 1 << 8,
	blHaveDrawnDragHilite
						= 1 << 9,
	blDraggingTitle		= 1 << 10,	// When set, we suspend pinning right column.
	blNeedFocusErase	= 1 << 11,	// When set, local_BLDrawBorder erases focus. Keeps from erasing
									//	except when state changes to 'no focus'.
	blIsInCompositingWindow = 1 << 12,
	blSuppressIdle		= 1 << 13	// We don't want to handle idle timer events when calling handler or click loop.
};


//===============================
// This structure is identical to the title struct
#pragma mark BLIndexRec
typedef struct
{
	Handle			data;
	BLContentType	content;
	UInt16			flags;
} BLIndexRec, *BLIndexPtr;

#pragma mark Cell Index Flags
enum
{
	blSelected				= 1 << 0,
	blCantSelect			= 1 << 1,
	blBeingDragged			= 1 << 2,	// This can be checked in the drawing code to hilite
										//	differently
	blCantEdit				= 1 << 3	// Disables inline editing for this cell.
};


#pragma mark Update Options
//===============================
typedef UInt8	BLUpdateOptions;
enum
{
	blUpdateNoOptions	= 0,
	blUpdateBlit		= 1 << 0,	// Blit to screen
	blUpdateBlitAll		= 1 << 1,	// Blit all (only used for scrolling)
	blUpdateBorder		= 1 << 2,	// Draw or blit list border and focus
	blUpdateCorners		= 1 << 3,	// Draw or blit corners
	blUpdateTriangle	= 1 << 4	// Used only by _BLUpdateCell; draw disclosure triangle
};

//===============================
// These are for specialized drawing needs. Ordinarily we pass blCellDrawNoOptions.
// blCellDrawSuppressTriangle is for toggling the triangle.
// blCellDrawSuppressBorders is for drag images.
typedef UInt8	BLCellDrawOptions;
enum
{
	blCellDrawNoOptions			= 0,
	blCellDrawSuppressTriangle	= 1 << 0,	// Don't draw disclosure triangle.
	blCellDrawSuppressBorders	= 1 << 1	// Don't draw row or column borders.
};

#pragma mark Select Options
//===============================
typedef UInt8	BLSelectOptions;
enum
{
	blSelectNoOptions		= 0,
	blSelectOneCell			= 1 << 0,
	blSelectUpdate			= 1 << 1,
	blSelectMakeVisible		= 1 << 2
};

#pragma mark Recalc Options
//===============================
typedef UInt8	BLRecalcOptions;
enum
{
	blRecalcColOffsets		= 1 << 0,
	blRecalcRowOffsets		= 1 << 1,
	blRecalcOffsets			= (blRecalcColOffsets) + (blRecalcRowOffsets),
	blRecalcVisCells		= 1 << 2,
	blRecalcHScroll			= 1 << 3,
	blRecalcVScroll			= 1 << 4,
	blRecalcScroll			= ((blRecalcHScroll) | (blRecalcVScroll)),
	blRecalcThumb			= 1 << 5,	// Ignored if no scroll bars are being updated
	blRecalcRightPin		= 1 << 6	// Recalculate last column width if it is being pinned.
};

#pragma mark BlugsGlobals
//===============================
typedef struct
{
	CursHandle				rowResizeCursHdl;
	CursHandle				colResizeCursHdl;
	UInt32					flags;
	UInt32					userSettings;
	Handle					handlerTable;		// Hash table for handlers
	UInt16					appearanceVersion;
	UInt16					osVersion;
} BLGlobals;

// Need to declare it here, so all internal files can access globals.
extern BLGlobals	_blGlobals;



#pragma mark Sort State Additions
//===============================
// ORed onto the BLSortState flags defined in Blugs.h,
//	these govern the sort button, and blSortStateNoChange is shorthand for
//	'whatever is already in the list's stored sort state'.
enum
{
	blSortButtonInactive			= 1 << 2,
	blSortButtonPressed				= 1 << 3,
	blSortStateNoChange				= 1 << 4
};


#pragma mark Disclosure Triangle State
/*===============================*/
typedef UInt8		BLDisclosureTriangleState;
enum
{
	blTriStateDownBit			= 0x01,
	blTriStatePressedBit		= 0x02,
	blTriStateIntermediateBit	= 0x04,
	/* Here are composite states: */
	blTriStateRight				= 0,
	blTriStateRightPressed		= blTriStatePressedBit,
	blTriStateIntermediate		= blTriStateIntermediateBit + blTriStatePressedBit,
	blTriStateDownPressed		= blTriStateDownBit + blTriStatePressedBit,
	blTriStateDown				= blTriStateDownBit
};


#pragma mark Scroll/Autoscroll flags
//===============================
enum
{
	blAutoscrollNoH				= 1 << 0,
	blAutoscrollNoV				= 1 << 1,
	blAutoscrollConstSpeed		= 1 << 2,
	blScrollAdjustThumb			= 1 << 3
};



#pragma mark Scroll to __ stuff
//===============================
typedef UInt8 BLScrollTarget;

enum
{
	blScrollTopOrBottomBit	= 1 << 0,
	blScrollToTopBit		= 1 << 1,
	blScrollLeftOrRightBit	= 1 << 2,
	blScrollToLeftBit		= 1 << 3,
	blScrollTop				= blScrollTopOrBottomBit|blScrollToTopBit,
	blScrollBottom			= blScrollTopOrBottomBit,
	blScrollTopLeft			= blScrollTopOrBottomBit|blScrollToTopBit|blScrollLeftOrRightBit|blScrollToLeftBit,
	blScrollTopRight		= blScrollTopOrBottomBit|blScrollToTopBit|blScrollLeftOrRightBit,
	blScrollBottomLeft		= blScrollTopOrBottomBit|blScrollLeftOrRightBit|blScrollToLeftBit,
	blScrollBottomRight		= blScrollTopOrBottomBit|blScrollLeftOrRightBit,
	blScrollLeft			= blScrollLeftOrRightBit|blScrollToLeftBit,
	blScrollRight			= blScrollLeftOrRightBit
};

#define bl_ScrollToTop(target)		(bl_Test(target,blScrollTop))
#define bl_ScrollToBottom(target)	((bl_Test(target,blScrollTopOrBottomBit)) && \
										(!bl_Test(target,blScrollToTopBit)))
#define bl_ScrollToLeft(target)		(bl_Test(target,blScrollLeft))
#define bl_ScrollToRight(target)	((bl_Test(target,blScrollLeftOrRightBit)) && \
										(!bl_Test(target,blScrollToLeftBit)))


#pragma mark Miscellaneous Internal Defines
//===============================
typedef struct
{
	BLCell		cell;
	BlugsRef	list;
} BLDisclosureData, *BLDisclosureDataPtr;

#define	blMaxShort				32767			// max signed short integer
#define	blMinShort				-32768			// min signed short integer
//#define blSInt16Range			0x0000FFFF		// 0-based range of short integers
//#define blSInt16RangeAsDouble	65536.0
#define blDefaultScrollDistance	6
#define blDefaultMinSize		16				// Minimum column width/row height
#define blDefaultMaxSize		300				// Maximum column width/row height
#define blDefaultResizeASDist	20				// When closer than x pixels to edge of list
												//	try to autoscroll


#pragma mark Drag Manager Constants
//===============================
#define blPrivateDragItemRef				1
#define	blReorderMovementPixelThreshold		5	// How many pixels can mouse move before drag starts
#define blDragFlavor_DraggingTitle			'BTit'
#define blDragFlavor_CurrentTitlePosition	'BCti'
#define blDragFlavor_Offset					'BOff'
#define blDragFlavor_OriginList				'BLOr'
#define blDragFlavor_OriginalMouseOffset	'BMou'
#define blDragFlavor_Cell					'BCel'


enum
{
	blDragType_None,		// In case of error.
	blDragType_Content,
	blDragType_HorzTitle,
	blDragType_VertTitle
};




#pragma mark Variable Array Stuff
//===============================
typedef SInt32 (*VASearchProcPtr)( const Ptr arrayDataP, UInt32 searchData, UInt32 refCon );
typedef SInt32 (*VASortProcPtr)( const Ptr data1P, const Ptr data2P, UInt32 refCon );

enum
{
	blSearchDataIsGreater		= -1L,
	blEqual						= 0,
	blSearchDataIsLess			= 1L,
	blFirstIsLess				= -1L,
	blFirstIsGreater			= 1
};


#pragma mark ¥¥¥CARBON/MACHO COMPATIBILITY¥¥¥
//===============================
#if !__BL_USE_CARBON_API__
	// For now let's ignore the param to qd accessors and just resolve to
	//	a pointer to the thing we want.
	#define GetQDGlobalsArrow(x)				(&qd.arrow)
	#define GetQDGlobalsGray(x)					(&qd.gray)
	#define GetQDGlobalsLightGray(x)			(&qd.ltGray)
	#define GetQDGlobalsBlack(x)				(&qd.black)
	#define GetControlBounds(control,rect)		(*rect = (*control)->contrlRect)
	#define SetControlBounds(control,rect)		((*control)->contrlRect = *rect)
	// PixMapHandle from CGrafPtr
	#define GetPortPixMap(port)					(port->portPixMap)
	#define InvalWindowRect						_BLInvalWindowRect
	#define GetPortBounds						_BLGetPortBounds
	#define GetRegionBounds						_BLGetRegionBounds
#else
#if !TARGET_RT_MAC_MACHO
#ifdef UNIVERSAL_INTERFACES_VERSION
enum
{
	// Identify this film quote:
	// "This is 1L-19; I've got a hit-and-run felony."
	kWindowCompositingAttribute  	 	= (1L << 19),
	kEventControlGetClickActivation		= 17,
	kEventControlDragEnter				= 18,
	kEventControlDragWithin				= 19,
	kEventControlDragLeave				= 20,
	kEventControlDragReceive			= 21,
	kEventControlGetSizeConstraints		= 105,
	kEventControlEnabledStateChanged	= 161,
	kEventParamMinimumSize			= 'mnsz',
	kEventParamMaximumSize			= 'mxsz'
};
typedef CGSize	HISize;

#endif
#endif
#endif


#pragma mark ¥¥¥MACROS¥¥¥
//===============================
// 'bl_' is the normal prefix for macros
// 'blp_' is the prefix for macros that take a dereferenced BlugsRef to cut down on indirection
#pragma mark Utility
#define blHiBit						0x80000000
#define blAllButHiBit				0x7FFFFFFF
#define bl_HiBitClear(x)			((x) & blAllButHiBit)
#define bl_HiBitSet(x)				((SInt32)(x) | blHiBit)
#define bl_Abs(x) 					((x) > 0 ? (x) : -(x))
//#define bl_Test(field,features)		((((field) & (features)) == (features)) ? true : false)
#define bl_Test(field,features)		(((field) & (features)) == (features))
#define bl_Set(field,feature)		((field) |= (feature))
#define bl_Clear(field,feature)		((field) &= (~(feature)))
#define bl_Toggle(field,feature)	((field) ^= (feature))

#define bl_CellInRange(cell,list)	((cell.col <= (*list)->nColumns) && \
										(cell.row <= (*list)->nRows))
#define blp_CellInRange(cell,list)	((cell.col <= list->nColumns) && \
										(cell.row <= list->nRows))
#define bl_ValidCell(cell)			((cell.col) && (cell.row))

//#define bl_GotoWindow(list)			SetGWorld( GetWindowPort( (*list)->window ), nil )
#define bl_Width(rect)				(rect.right - rect.left)
#define bl_Height(rect)				(rect.bottom - rect.top)
#define blp_Width(rect)				(rect->right - rect->left)
#define blp_Height(rect)			(rect->bottom - rect->top)

#pragma mark Global Accessors
#if TARGET_RT_MAC_MACHO
#define bl_Appearance				(true)
#define bl_Aqua						(true)
#define bl_DragManager				(true)
#define bl_TranslucentDrags			(true)
#define bl_ControlMgr2				(true)
#define bl_AllegroAppearance		(true)
#elif TARGET_API_MAC_CARBON
#define bl_Appearance				(true)
#define bl_Aqua						bl_Test(_blGlobals.flags,blHasAqua)
#define bl_DragManager				(true)
#define bl_TranslucentDrags			(true)
#define bl_ControlMgr2				bl_Test(_blGlobals.flags,blHasControlMgr2)
#define bl_AllegroAppearance		(bl_ApprVers >= 0x0110)
#else
#define bl_Appearance				bl_Test(_blGlobals.flags,blHasAppearance)
#define bl_Aqua						(false)
#define bl_DragManager				bl_Test(_blGlobals.flags,blHasDragMgr)
#define bl_TranslucentDrags			bl_Test(_blGlobals.flags,blHasTranslucentDrags)
#define bl_ControlMgr2				bl_Test(_blGlobals.flags,blHasControlMgr2)
#define bl_AllegroAppearance		(bl_ApprVers >= 0x0110)
#endif
#define bl_Inited					bl_Test(_blGlobals.flags,blInitialized)
#define bl_TempGWorlds				bl_Test(_blGlobals.userSettings,blTempGWorlds)
#define bl_DumpGWorlds				bl_Test(_blGlobals.userSettings,blDumpGWorldsOnHide)
#define	bl_ApprVers					_blGlobals.appearanceVersion
#define	bl_OSVers					_blGlobals.osVersion
#define bl_Jaguar					(bl_OSVers >= 0x1020)


#pragma mark List Flags Feature Tests
#define bl_CanFocus(list)			bl_Test((*list)->listFlags,blCanFocus)
#define bl_Active(list)				bl_Test((*list)->listFlags,blActive)
#define bl_Visible(list)			bl_Test((*list)->listFlags,blVisible)
#define bl_ResizableHt(list)		bl_Test((*list)->listFlags,blResizableHeight)
#define bl_ResizableWd(list)		bl_Test((*list)->listFlags,blResizableWidth)
#define bl_Autodraw(list)			bl_Test((*list)->listFlags,blAutodraw)
#define bl_HasGrow(list)			bl_Test((*list)->listFlags,blHasGrow)
#define bl_DrawGrow(list)			bl_Test((*list)->listFlags,blDrawGrow)
#define bl_Disclosure(list)			bl_Test((*list)->listFlags,blDisclosure)
#define bl_Border(list)				bl_Test((*list)->listFlags,blDrawBorder)
#define bl_Sortable(list)			bl_Test((*list)->listFlags,blSortable)
#define bl_SortButton(list)			bl_Test((*list)->listFlags,blDrawSortButton)
#define bl_Table(list)				bl_Test((*list)->listFlags,blTable)
#define bl_InlineOnClick(list)		bl_Test((*list)->listFlags,blInlineEditOnClick)
#define bl_LiveScroll(list)			bl_Test((*list)->listFlags,blLiveScroll)
#define bl_OnlyOne(list)			bl_Test((*list)->listFlags,blOnlyOne)
#define bl_NoDisjoint(list)			bl_Test((*list)->listFlags,blNoDisjoint)
#define bl_UseSense(list)			bl_Test((*list)->listFlags,blUseSense)
#define bl_NoExtend(list)			bl_Test((*list)->listFlags,blNoExtend)
#define bl_SmallScroll(list)		bl_Test((*list)->listFlags,blSmallScroll)
#define bl_BorderMetrics(list)		bl_Test((*list)->listFlags,blBorderMetrics)
#define bl_PinRight(list)			bl_Test((*list)->listFlags,blPinRight)
#define bl_IndentTriangles(list)	bl_Test((*list)->listFlags,blIndentTriangles)

#pragma mark Private Feature Tests
#define bl_InlineNow(list)			bl_Test((*list)->privateFlags,blInlineEditNow)
#define bl_Focused(list)			bl_Test((*list)->privateFlags,blFocused)
#define bl_PendingInline(list)		bl_Test((*list)->privateFlags,blPendingInline)
#define bl_NeedUpdate(list)			bl_Test((*list)->privateFlags,blNeedUpdate)
#define bl_SetNeedUpdate(list)		bl_Set((*list)->privateFlags,blNeedUpdate)
#define bl_Sorted(list)				bl_Test((*list)->sortState,blSortStateSorted)
#define bl_SortedBigSmall(list)		bl_Test((*list)->sortState,blSortStateLargeToSmall)


#pragma mark Index Features
#define bl_Selected(indexP)			bl_Test(indexP->flags,blSelected)
#define bl_CantEdit(indexP)			bl_Test(indexP->flags,blCantEdit)


#pragma mark Feature Accessors
#define bl_NRows(list)				(*list)->nRows
#define bl_NCols(list)				(*list)->nColumns
#define bl_CellIndexAddr(cell,list)		(((BLIndexPtr)(*((**list).cellIndex))) \
										+ (((*list)->nColumns) * (cell.row-1) + cell.col-1))
#define bl_NthCellIndexAddr(n,list)	(((BLIndexPtr)(*((**list).cellIndex))) + n-1)
// Takes the index handle instead of getting it from list:
#define bl_CellIndexAddrFromIH(cell,list,ih)	(((BLIndexPtr)(*(ih))) + \
												(((*list)->nColumns) * \
												(cell.row-1) + cell.col-1))

#define bl_NCells(list)				(bl_NRows(list) * bl_NCols(list))
#define bl_DefaultHt(list)			(*list)->defaultCellSize.v
#define bl_DefaultWd(list)			(*list)->defaultCellSize.h
#define bl_TVisRow(list)			(*list)->visCells.top
#define bl_LVisCol(list)			(*list)->visCells.left
#define bl_BVisRow(list)			(*list)->visCells.bottom
#define bl_RVisCol(list)			(*list)->visCells.right
#define bl_Window(list)				(*list)->window
#define bl_Rect(list)				(*list)->rect
#define bl_VScroll(list)			(*list)->vScroll
#define bl_HScroll(list)			(*list)->hScroll
#define bl_UserPane(list)			(*list)->userPane
#define bl_HasVScroll(list)			(bl_VScroll(list) != nil)
#define bl_HasHScroll(list)			(bl_HScroll(list) != nil)
#define bl_Index(list)				(*list)->cellIndex
#define bl_VScrollLoc(list)			(*list)->vScrollLoc
#define bl_HScrollLoc(list)			(*list)->hScrollLoc
#define bl_TotalHt(list)			(*list)->totalHeight
#define bl_TotalWd(list)			(*list)->totalWidth
#define bl_ClickCell(list)			(*list)->lastClickCell
#define bl_ClickTime(list)			(*list)->lastClickTime
#define bl_Indent(list)				(*list)->indent
#define bl_HTitle(list)				(*list)->hTitle
#define bl_VTitle(list)				(*list)->vTitle
#define bl_HasHTitle(list)			(bl_HTitle(list) != nil)
#define bl_HasVTitle(list)			(bl_VTitle(list) != nil)
#define bl_World(list)				(*list)->world
#define bl_InlineCell(list)			(*list)->inlineEditCell
#define bl_Rep(list)				((*list)->rep)

#pragma mark Metrics Calculations
#define bl_HScrollDist(list)		(((*list)->hScrollDistance) ? (*list)->hScrollDistance : blDefaultScrollDistance)
#define bl_VScrollDist(list)		(((*list)->vScrollDistance) ? (*list)->vScrollDistance : blDefaultScrollDistance)


#pragma mark Title Bar Accessors
#define bl_BarVert(tb)				bl_Test((*tb)->flags,blTitleBarVertical)
#define bl_NthTitleAddr(n,bar)		(&((**((*bar)->titles))[n-1]))
#define bl_NthTitleFlags(n,bar)		(bl_NthTitleAddr(n,bar)->flags)

#pragma mark Title Bar Metrics
#define bl_HTitleHt(list)			(*((*list)->hTitle))->thickness
#define bl_VTitleWd(list)			(*((*list)->vTitle))->thickness



#pragma mark ¥¥¥INTERNAL PROTOTYPES¥¥¥

#pragma mark Content Handlers
//===============================
Handle			_BLAllocateHandlerTable( void );
OSErr			_BLGetHandlerFeatures( BLContentType content, UInt32* features );
OSErr			_BLGetCellHandlerFeatures( BLCell cell, UInt32* features, BlugsRef list );
OSErr			_BLCheckValidContentType( BLContentType inContent );
UInt32			_BLCallHandlerForCell( BLMessage inMessage, BLCell inCell,
										BLHandlerParamPtr ioParam, BlugsRef inList );
UInt32			_BLCallHandlerForTitle( BLMessage inMessage, UInt16 inTitle,
										BLHandlerParamPtr ioParam, BLTitleBarHdl inBar,
										BlugsRef inList );
UInt32			_BLCallHandlerForWidget( BLMessage inMessage, Boolean inVertical, UInt16 inWidget,
											BLHandlerParamPtr ioParam, BlugsRef inList );
//void			_BLDeinitializeHandlers( void );


#pragma mark Data
//===============================
//UInt32			_BLCountCellFlavors( BLCell inCell, BlugsRef inList );
BLContentType	_BLGetCellContentType( BLCell inCell, BlugsRef inList );
void			_BLSetCellContentType( BLCell inCell, BLContentType inContent, BlugsRef inList );
void			_BLSetTitleContentType( Boolean inUpdate, UInt16 inTitle, BLContentType inContent,
										BLTitleBarHdl inBar, BlugsRef inList );


#pragma mark Disclosure
//===============================
Rect			_BLTriangleRect( Rect inCellRect, UInt16 inDisclosureLevel, BlugsRef inList );
UInt16			_BLIndent( BLCell inCell, BlugsRef inList );
UInt16			_BLCountDescendants( UInt16 inRow, BlugsRef inList );
Boolean			_BLRowIsDisclosed( UInt16 inRow, BlugsRef inList );
void			_BLRecalcDisclosure( Boolean inDescendantsOnly, UInt16 inStartRow, BlugsRef inList );
void			_BLSetDisclosureLevel( UInt16 inRow, UInt16 inNewLevel, BlugsRef inList );
UInt16			_BLDeepestDisclosureLevel( BlugsRef inList );
Boolean			_BLFindDisclosureRange( UInt16 inStartRow, UInt16 inLevel, UInt16* outRangeStart,
									UInt16* outRangeCount, UInt16* outThisLevelCount, BlugsRef inList );
Handle			_BLGetDisclosedRows( UInt16* outCount, BlugsRef inList );
UInt16			_BLNextDisclosedRow( UInt16 inRow, BlugsRef inList );
UInt16			_BLPreviousDisclosedRow( UInt16 inRow, BlugsRef inList );
Boolean			_BLValidDisclosureTarget( Boolean inMoving, UInt16 inPrevRow,
										UInt16 inDisclosureLevel, UInt16* outMin,
										UInt16* outMax, BlugsRef inList );


#pragma mark Drag And Drop
// Sets up the drag and calls TrackDrag.
// Returns errAENoUserInteraction if the mouse was released before a drag was started.
OSErr			_BLStartDrag( BLCell inCell, UInt32 inWhen, Point inWhereLocal,
								EventModifiers inModifiers, BlugsRef inList );


#pragma mark Drawing
//===============================
void			_BLUpdate( BLUpdateOptions inOptions, RgnHandle inUpdateRgn, BlugsRef inList );
void			_BLDrawSortButton( const Rect* inRect, BLSortState inState, BlugsRef inList );
OSErr			_BLNewWorld( BlugsRef inList );
void			_BLDisposeWorld( BlugsRef inList );
Boolean			_BLGotoWorld( GWorldPtr* outSaveWorld, BlugsRef inList );
Boolean			_BLGotoWindow( GWorldPtr* outSaveWorld, BlugsRef inList );
#if TARGET_RT_MAC_MACHO
#define _BLSwapPort	QDSwapPort
#else
Boolean			_BLSwapPort( CGrafPtr inNewPort, CGrafPtr* outOldPort );
#endif
void			_BLUpdateWorld( BLUpdateOptions inOptions, RgnHandle inUpdateRgn, BlugsRef inList );
void			_BLUpdateCell( BLUpdateOptions inOptions, BLCell inCell, BlugsRef inList );
void			_BLUpdateCellOnscreen( BLCell inCell, const Rect* inCellRect, BlugsRef inList );
void			_BLDrawIntersectingCells( const Rect* inUpdateRect, BlugsRef inList );
void			_BLDrawCell( BLCellDrawOptions inOptions, BLCell inCell, const Rect* inRect, BlugsRef inList );
void			_BLUpdateBarOnly( BLTitleBarHdl inBar, BlugsRef inList );
void			_BLUpdateTitle( UInt16 inTitle, BLTitleBarHdl inBar, BlugsRef inList );
void			_BLUpdateView( BLUpdateOptions inOptions, BlugsRef inList );
void			_BLDrawTitle( UInt16 inTitle, BLTitleBarHdl inBar, BlugsRef inList );
void			_BLDrawDisclosureTriangle( BLCell inCell, Rect inRect,
											BLDisclosureTriangleState inState, Boolean inActive,
											BlugsRef inList );
pascal void		_BLDisclosureEraseProc( const Rect* inRect, BLDisclosureDataPtr inData,
										SInt16 inDepth, Boolean inColor );
void			_BLDrawDragInsertionCaret( SInt16 inH, SInt16 inV, SInt16 inRight );
void			_BLPaintDragHilite( Rect inViewRect, BlugsRef inList );
void			_BLDrawMarquee( PixMapHandle inPixMap, const Rect* inRect );


#pragma mark Initialization
//===============================
void			_BLLoadCursors( void );


#pragma mark Inline Edit
//===============================
Boolean			_BLTrackBeginInlineEdit( UInt32 inWhen, BLCell inCell, Point inMouse,
										const Rect* inCellRect, BlugsRef inList );
void			_BLWaitingForInlineEdit( BlugsRef inList );
Boolean			_BLInlineEditClick( BLCell inCell, Point inMouse, EventModifiers inModifiers,
									BlugsRef inList );
BLKeyResult		_BLInlineEditKey( UInt32 inMessage, EventModifiers inModifiers, BlugsRef inList );
Boolean			_BLNextEditable( BLCell* ioCell, BlugsRef inList );
Boolean			_BLPreviousEditable( BLCell* ioCell, BlugsRef inList );
Boolean			_BLIsCellEditable( BLCell inCell, BlugsRef inList );
void			_BLMoveInlineEdit( Boolean inAdvance, BlugsRef inList );
Boolean			_BLEndInlineEdit( Boolean inSortIfNeeded, BlugsRef inList );


#pragma mark Metrics
//===============================
OSErr			_BLSetRect( const Rect* inRect, BlugsRef inList );
void			_BLMinView( UInt16* outMinWidth, UInt16* outMinHeight, BlugsRef inList );
SInt16			_BLMinScrollSize( BlugsRef inList );
void			_BLAdjustScrollBarSizesAndLocations( BlugsRef inList );
Rect			_BLHScrollAndWidgetsRect( BlugsRef inList );
Rect			_BLHScrollRect( BlugsRef inList );
Rect			_BLVScrollAndWidgetsRect( BlugsRef inList );
Rect			_BLVScrollRect( BlugsRef inList );
OSErr			_BLRowTopBottom( UInt16 inRow, SInt16* outTop, SInt16* outBottom, BlugsRef inList );
OSErr			_BLColumnLeftRight( UInt16 inColumn, SInt16* outLeft, SInt16* outRight, BlugsRef inList );
OSErr			_BLCellRect( BLCell inCell, Rect* outRect, BlugsRef inList );
Rect			_BLViewRect( BlugsRef inList );
Rect			_BLOffscreenRect( BlugsRef inList );
Rect			_BLGrowBoxRect( BlugsRef inList );
UInt16			_BLViewWidth( BlugsRef inList );
UInt16			_BLViewHeight( BlugsRef inList );
void			_BLSetRowHeight( UInt16 inRow, UInt16 inHeight, BlugsRef inList );
void			_BLSetColumnWidth( UInt16 inColumn, UInt16 inWidth, BlugsRef inList );
BLPixelOffset	_BLRowBottom( UInt16 inRow, BlugsRef inList );
BLPixelOffset	_BLRowTop( UInt16 inRow, BlugsRef inList );
BLPixelOffset	_BLColumnRight( UInt16 inColumn, BlugsRef inList );
BLPixelOffset	_BLColumnLeft( UInt16 inColumn, BlugsRef inList );
Boolean			_BLCellIsVisible( BLCell inCell, BlugsRef inList );
Rect			_BLSortButtonRect( BlugsRef inList );
BLCell			_BLPointToCell( Boolean inTreatTitleRowAsOneCol, Point inWhere, BlugsRef inList );
void			_BLRecalc( BLRecalcOptions inOptions, UInt16 startHere, BlugsRef inList );
UInt16			_BLGetColMinimumWidth( UInt16 inColumn, BlugsRef inList );
UInt16			_BLGetRowMinimumHeight( UInt16 inRow, BlugsRef inList );
void			_BLCellRegion( RgnHandle inRgn, BLCell inCell, const Rect* inCellRect, BlugsRef inList );
void			_BLInlineRegion( RgnHandle inRgn, BLCell inCell, const Rect* inCellRect, BlugsRef inList );
void			_BLLocalToGlobalRect( Rect* ioRect );
SInt32			_BLScrollSize( BlugsRef inList );


#pragma mark Rows & Columns
//===============================
OSErr			_BLAllocateRowData( UInt16 inRows, BlugsRef inList );
OSErr			_BLAllocateColumnData( UInt16 inColumns, BlugsRef inList );
void			_BLInitRowData( UInt16 inRow, UInt16 inCount, BlugsRef inList );
void			_BLInitColumnData( UInt16 inColumn, UInt16 inCount, BlugsRef inList );

BLPixelOffset	_BLGetRowOffsetFromTop( UInt16 inRow, BlugsRef inList );
void			_BLSetRowOffsetFromTop( UInt16 inRow, BLPixelOffset inOffset, BlugsRef inList );
UInt16			_BLGetRowDisclosureLevel( UInt16 inRow, BlugsRef inList );
void			_BLSetRowDisclosureLevel( UInt16 inRow, UInt16 inLevel, BlugsRef inList );
UInt16			_BLGetRowFlags( UInt16 inRow, BlugsRef inList );
void			_BLSetRowFlags( UInt16 inRow, UInt16 inWhichFlags, UInt16 inFlags, BlugsRef inList );
UInt16			_BLGetRowHeight( UInt16 inRow, BlugsRef inList );
void			_BLSetRowHeight( UInt16 inRow, UInt16 inHeight, BlugsRef inList );
UInt16			_BLGetRowVisibleHeight( UInt16 inRow, BlugsRef inList );
void			_BLSetRowVisibleHeight( UInt16 inRow, UInt16 inHeight, BlugsRef inList );

BLPixelOffset	_BLGetColumnOffsetFromLeft( UInt16 inColumn, BlugsRef inList );
void			_BLSetColumnOffsetFromLeft( UInt16 inColumn, BLPixelOffset inOffset, BlugsRef inList );
BLContentType	_BLGetColumnContentType( UInt16 inColumn, BlugsRef inList );
void			_BLSetColumnContentType( UInt16 inColumn, BLContentType inType, BlugsRef inList );
void			_BLGetColumnFontStyle( UInt16 inColumn, ControlFontStyleRec* outFontStyle, BlugsRef inList );
void			_BLSetColumnFontStyle( UInt16 inColumn, const ControlFontStyleRec* inFontStyle, BlugsRef inList );
UInt16			_BLGetColumnWidth( UInt16 inColumn, BlugsRef inList );
void			_BLSetColumnWidth( UInt16 inColumn, UInt16 inWidth, BlugsRef inList );
UInt32			_BLGetColumnFlags( UInt16 inColumn, BlugsRef inList );
void			_BLSetColumnFlags( UInt16 inColumn, UInt32 inWhichFlags, UInt32 inFlags, BlugsRef inList );

OSErr			_BLMoveColumns( UInt16 inMoveColumn, UInt16 inAfterThisColumn, UInt16 inCount,
								BlugsRef inList );
OSErr			_BLMoveRows( UInt16 inMoveRow, UInt16 inAfterThisRow, UInt16 inCount,
								UInt16 inDisclosureLevel, BlugsRef inList );
void			_BLRearrangeRowData( UInt16 inSortArray[], BlugsRef inList );


#pragma mark Scrolling
//===============================
void			_BLScroll( UInt8 inFlags, SInt32 inDX, SInt32 inDY, SInt32* outActualDX,
							SInt32* outActualDY, BlugsRef inList );
void			_BLScrollTo( BLScrollTarget inTarget, BlugsRef inList );
void			_BLIndicatorMoved( SInt32 inNewValue, Boolean inHorizontal, BlugsRef inList );
pascal void		_BLVScrollActionProc( ControlRef inControl, ControlPartCode inPart );
pascal void		_BLHScrollActionProc( ControlRef inControl, ControlPartCode inPart );
void			_BLMakeVisible( BLCell inCell, BlugsRef inList );
void			_BLAutoscroll( Point inMouse, Rect inRect, UInt8 inFlags, SInt32* outActualDX,
								SInt32* outActualDY, /*BLScrollLimitPtr inLimit,*/ BlugsRef inList );
#if !TARGET_API_MAC_CARBON
void			_BeginThumbTracking( ControlRef inControl, BlugsRef inList );
void			_EndThumbTracking ( void );
pascal void 	_ScrollThumbActionProc( void );
#endif


#pragma mark Selection
//===============================
BLClickResult	_BLClick( Boolean inHitTestScroll, UInt32 inWhen, Point inWhereLocal,
						EventModifiers inModifiers, BlugsRef inList );
BLPart			_BLHitTest( Boolean inHitTestScroll, Point inWhere, BLHitTestPtr ioHitTest, BlugsRef inList );
void			_BLSelectCell( BLSelectOptions options, BLCell cell, BlugsRef list );
void			_BLDeselectCell( Boolean inUpdate, BLCell inCell, BlugsRef inList );
void			_BLToggleCellSelection( Boolean inUpdate, BLCell inCell, BlugsRef inList );
void			_BLDeselectAll( Boolean inUpdate, BlugsRef inList );
void			_BLDeselectColumn( Boolean inUpdate, UInt16 inColumn, BlugsRef inList );
BLCell			_BLLastSelected( BlugsRef inList );
void			_BLSelectRange( Boolean inUpdate, BLCell inFirstCell, BLCell inLastCell, BlugsRef inList );
void			_BLDeselectRange( Boolean inUpdate, BLCell inFirstCell, BLCell inLastCell, BlugsRef inList );
Boolean			_BLNextCell( BLCell* ioCell, BlugsRef inList );
Boolean			_BLCanSelect( BLCell inCell, BlugsRef inList );


#pragma mark Sorting
//===============================
BLSortState		_BLSortButtonState( BlugsRef inList );
void			_BLSort( BLSortState inState, BlugsRef inList );
OSErr			_BLSearch( UInt16 inColumn, void* inData, UInt32 inDataSize, BLCell* outCell,
							BlugsRef inList );


#pragma mark Title Bar
//===============================
void			_BLDisposeTitleBar( BLTitleBarHdl theBar, BlugsRef list );
void			_BLDisposeTitles( UInt16 count, UInt16 firstTitle, BLTitleBarHdl theBar, BlugsRef list );
OSErr			_BLAddTitles( UInt16 count, UInt16 here, BLTitleBarHdl theBar, BlugsRef list );
BLContentType	_BLGetTitleContentType( UInt16 nthTitle, BLTitleBarHdl theBar );
OSErr			_BLMoveTitles( UInt16 inMoveTitle, UInt16 inAfterThisTitle, UInt16 inCount,
								UInt16 inNTitles, BLTitleBarHdl inTitleBar );
void			_BLTempRemoveFlagTitle( Boolean draw, UInt8 flag, UInt16 n, BLTitleBarHdl theBar,
										BlugsRef list );
Boolean			_BLHTitleBarClick( BLHitTestPtr inHitTest, Point inWhere,
									EventModifiers inModifiers, UInt32 inWhen,
									UInt16* outNewSelection, BlugsRef inList );
void			_BLVTitleBarClick( BLHitTestPtr inHitTest, Point inWhere,
									EventModifiers inModifiers, UInt32 inWhen, BlugsRef inList );
Rect			_BLTitleBarRect( BLTitleBarHdl theBar, BlugsRef list );
Boolean			_BLTitleBarUnclaimedRect( Boolean inVertical, BLTitleBarHdl inBar,
											Rect* outRect, BlugsRef inList );
OSErr			_BLTitleRect( UInt16 inTitle, BLTitleBarHdl inBar, Rect* outRect, BlugsRef list );
UInt16			_BLPointToDropHTitle( SInt16 inTopLeft, UInt16 inTitle, BLTitleBarHdl inBar,
										BlugsRef inList );
UInt16			_BLPointToDropVTitle( SInt16 inTopLeft, UInt16 inTitle, BLTitleBarHdl inBar,
										BlugsRef inList );
UInt16			_BLPointToTitle( Point inWhere, BLTitleBarHdl inBar, BlugsRef inList );


#pragma mark User Pane
//===============================
Rect			_BLUserPaneRect( BlugsRef inList );


#pragma mark Utility
//===============================
#if TARGET_RT_MAC_MACHO
#define _BLTrackMouseLocation(mouse,result) TrackMouseLocation( nil, mouse, result )
#else
void _BLTrackMouseLocation( Point* ioMouse, MouseTrackingResult* outResult );
#endif

// Eric Schlegel says BlockZero is implemented internally (where necessary I guess)
//	in CarbonLib 1.0.4 and later.
#if __BL_USE_CARBON_API__
	#define _BLZeroMemory		BlockZero
#else
	#if defined(__MWERKS__) // Codewarrior
		#define _BLZeroMemory		_BLAsmZeroMemory
		asm void	_BLAsmZeroMemory( register Ptr inData, register UInt32 inBytes );
	#elif defined(__MRC__) // MPW
		#define _BLZeroMemory		_BLAsmZeroMemory
		void	_BLAsmZeroMemory( Ptr inData, UInt32 inBytes );
	#endif
#endif

#if __BL_USE_CARBON_API__
pascal void		_BLTimerProc( EventLoopTimerRef inTimer, void *inUserData );
#endif
UInt32			_BLProcessFlags( UInt32 inWhichFlags, UInt32 inFlags, UInt32 inOldFlags );
UInt32			_BLCellToNthCell( BLCell inCell, BlugsRef inList );
BLCell			_BLNthCellToCell( UInt32 inNthCell, BlugsRef inList );
Boolean			_BLCellToTitle( BLCell inCell, UInt16* outTitle, BLTitleBarHdl* outBar, BlugsRef inList );

#if !__BL_USE_CARBON_API__
OSStatus	_BLInvalWindowRect( WindowRef inWindow, const Rect* inRect );
Rect*		_BLGetPortBounds( CGrafPtr inPort, Rect* outBounds );
Rect*		_BLGetRegionBounds( const RgnHandle inRgn, Rect *outBounds );
#endif

RgnHandle		_BLClipToRectIntersection( const Rect* inRect1, const Rect* inRect2 );
RgnHandle		_BLClipToViewRectIntersection( const Rect* inRect, BlugsRef inList );
void			_BLNewNumberOnMovement( UInt16* ioNumber, UInt16 inCount, UInt16 inMoveThis,
										UInt16 inHere );
void			_BLRgnMinusRect( RgnHandle inRgn, const Rect* inRect );
void			_BLIncrUID( BLUID* ioID );
Boolean			_BLEqualUID( BLUID* inID1, BLUID* inID2 );
Boolean			_BLEqualCellUID( BLCellUID* inID1, BLCellUID* inID2 );

OSErr			_BLValidateList( BlugsRef list );
OSErr			_BLValidateTitleBar( BLTitleBarHdl theBar );
OSErr			_BLValidateTitle( Boolean checkZero, UInt16 inTitle, BLTitleBarHdl inBar,
									BlugsRef inList );
OSErr			_BLValidateRow( UInt16 nthRow, BlugsRef list );
OSErr			_BLValidateColumn( UInt16 nthCol, BlugsRef list );
OSErr			_BLValidateCell( BLCell cell, BlugsRef list );
OSErr			_BLValidateCellOrTitle( BLCell inCell, BlugsRef inList );
OSErr			_BLValidateWidget( Boolean inVertical, UInt16 inWidget, BlugsRef inList );
Handle			_VANew( UInt32 inNItems, UInt32 inItemSize, Boolean inZero );
OSErr			_VAAdd( UInt32 count, UInt32 addHere, UInt32 nItems, UInt32 itemSize,
							Handle arrayH, Boolean zero );
void			_VARemove( UInt32 inCount, UInt32 inItem, UInt32 inNItems, UInt32 inItemSize,
							Handle inArray );
OSErr			_VAMoveAfter( UInt32 inCount, UInt32 inSource, UInt32 inDest, UInt32 inItemSize,
								UInt32 inItemCount, Handle inArray );
UInt32			_VASearch( Handle arrayH, Ptr arrayP, UInt32 nItems, UInt32 itemSize,
							VASearchProcPtr proc, UInt32 refCon, UInt32 searchData, UInt32* next );
void			_VASort( Handle arrayH, Ptr arrayP, UInt32 count, UInt32 itemSize,
							VASortProcPtr proc, UInt32 refCon );
#if __BL_USE_CARBON_API__
#if !TARGET_RT_MAC_MACHO
void*			_BLGetBSDFunctionPtr( CFStringRef inFunction );
void*			_BLGetCarbonFunctionPtr( CFStringRef inFunction );
#endif
#endif

#pragma mark Widgets
//===============================
OSErr			_BLGetWidgetRect( Boolean inVertical, UInt16 inWidget, Rect* outRect, BlugsRef inList );
BLContentType	_BLGetWidgetContentType( Boolean inVertical, UInt16 inWidget, BlugsRef inList );
UInt16			_BLGetWidgetFlags( Boolean inVertical, UInt16 inWidget, BlugsRef inList );
SInt16			_BLWidgetsTotalSize( Boolean inVertical, BlugsRef inList );
BLPart			_BLHitTestWidgets( Boolean inVertical, Point inWhere,
									BLHitTestPtr ioHitTest, BlugsRef inList );
void			_BLTrackWidgetClick( BLHitTestPtr inTest, Point inWhere,
									EventModifiers inModifiers, BlugsRef inList );
void			_BLDrawWidget( Boolean inVertical, UInt16 inTitle, const Rect* inRect,
								ThemeDrawState inState, BlugsRef inList );
Handle			_BLGetWidgetStorage( Boolean inVertical, UInt16 inWidget, BlugsRef inList );
OSErr			_BLSetWidgetStorage( Boolean inVertical, UInt16 inWidget,
										Handle inStorage, BlugsRef inList );

#endif //__BLUGSPRIVATE__