/*
 *	(c) 1998-99 Sassafras Software Inc.
 *
 *	Mondo-useful List view.  Meant to be subclassed to handle
 *	your specific list contents.
 */

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

  YAAF is Copyright 1997-1999 by William Woody.

  Redistribution and use in source and binary forms, with or without 
  modification, are permitted provided that the following conditions 
  are met:

  Redistributions of source code must retain the above copyright notice, 
  this list of conditions and the following disclaimer.

  Neither the name of the copyright holder or other contributors may
  be used to promote products derived from this software without
  specific written prior permission.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
  SOFTWARE.
  
  Contact:   woody@alumni.caltech.edu
  Web page:  http://www.pandawave.com/yaaf/

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

#ifndef SS_LISZTVIEW
#define SS_LISZTVIEW

#include <XHandle.h>
#include <XView.h>
#include <XTimer.h>
#include <XHeader.h>

#define KLisztSelect		'lsts'
#define KLisztDoubleClick	'lstd'

enum XGLisztSelect {
	KLisztSelectOff,
	KLisztSelectOn,
	KLisztSelectChange
};

struct XGLisztRec {
	bool	selected;
	bool	shown;
	long	index;
	void	*data;
};

/*$	XGLisztView
 *
 *		must fill this blank in eventually.
 */

class XGLisztView : public XGView {
	public:
								XGLisztView (XGView *, XGArgStream &);
		virtual					~XGLisztView ();

		long					GetSelect (void);
		bool					GetSelect (long);
		long					GetSelect (long *);
		void					SetSelect (XGLisztSelect);				/* change all */
		void					SetSelect (long, long, XGLisztSelect);	/* change a range */
		void					SetSelect (long, XGLisztSelect);		/* change one */
		void					SetSelect (long, long *, XGLisztSelect);	/* change a list */
		void					SelectOne (long);

		bool					Reveal (long, bool center = true);

		long					ListCount (void);
		void					ListExpand (long);
		long					ListInsert (void *, long before = -1);
		void					ListDelete (long);
		void *					ListGetData (long);
		void					ListSetData (void *, long);
		long					ListGetIndex (long);

		XRect					GetCellRect (long, long count = 1);

		void					AttachHeader (XGHeader *);

		void					DoSorting (bool sortOn = true);
		void					DoDrawing (bool drawOn = true);
		void					DoDrawHilite (XGDraw &, XRect &, bool selected = false);
		void					DoDrawView (XRect);
		void					DoSizeView (void);
		bool					DoMouseDown (XPoint, short);
		void					DoMouseMove (XPoint, short);
		void					DoMouseUp (XPoint, short);

		virtual bool			DoDragStart (XPoint, short);

		virtual void			DrawItem (XGDraw &, XRect, XRect, long, void *, bool);
		virtual XRect			GetColumn (long, XRect *r = NULL);
		virtual long			GetCellHeight (void) { return(fHeight); }
		virtual void			SetCellHeight (long height) { fHeight = height; }
		virtual long 			DoTypeAhead (char *, long);

		void					Sort (bool resort = false);
		virtual long			CompareItems (long, long, void *, void *);

		DECLAREDISPATCH
		long					DoKey (long,void *);

	private:
		XGHeader				*fHeader;
		XGSDynArray<XGLisztRec>	fList;
		long					fHeight;

		long					fDrawing;
		long					fSorting;
		bool					fMultiSel;
		bool					fDouble;
		long					fAnchor;
		long					fLastCell;
		XGTimer					fTypeAheadTimer;
		long					fTypeAheadLen;
		char					fTypeAhead[32];

		long					PointToCell (long, long hpos = 0);
		long					PointToCell (XPoint pt) { return(PointToCell(pt.v)); }
		void					RecalcScroll();
};

#endif	// SS_LISZTVIEW
