/*
 *	(c) 1998-99 Sassafras Software Inc.
 *
 *	Multi-column header bar for list views.
 */

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

  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_HEADER
#define SS_HEADER

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

/************************************************************************/
/*																		*/
/*	Events																*/
/*																		*/
/************************************************************************/

#define KHeaderSelect		'hdrs'
#define KHeaderChange		'hdrc'
#define KHeaderGrown		'hdrg'

/************************************************************************/
/*																		*/
/*	Structures															*/
/*																		*/
/************************************************************************/


struct XGHeaderInitRecord {
	XGSViewInitRecord	v;
	short				columns;		/* initial number of columns */
	short				resID;			/* resource ID of label string list */
	bool				leaveroom;		/* leave room for scrollbar */
	bool				resizable;		/* columns can be resized */
	bool				clickable;		/* columns can be selected */
	bool				multiple;		/* more than one column can be selected (NYI) */
	bool				removable;		/* columns can be removed (NYI) */
	bool				changable;		/* colomn order can be changed (NYI) */
};

struct XGHeaderPositionRecord {
	short left;
	short minWidth;
	short maxWidth;
	short hilited;
};

struct XGHeaderChangeRecord {
	short firstCol;
	short lastCol;
	short sizeDelta;
	short posnDelta;
	bool complete;
};

/************************************************************************/
/*																		*/
/*	Header View Class													*/
/*																		*/
/************************************************************************/


class XGHeader : public XGView {
	public:
								XGHeader(XGView *parent, XGArgStream &init);
								XGHeader(XGView *parent, XGHeaderInitRecord &init);
		virtual					~XGHeader();

		enum {
			kClassID = 'head'
		};

		void					AttachView (XGView *view = NULL);

		/*
		 *	Configuration routines
		 */
		void					SetColumnLabel (long, char *);
		long					GrowColumnWidth (long, long, bool shift = true);
		long					SetColumnWidth (long, long, bool shift = true);
		long					GetColumnWidth (long);
		void					GetColumnBox (long, XRect *);

		long					GetColumnMinWidth (long);
		long					GetColumnMaxWidth (long);
		void					SetColumnMinWidth (long, long);
		void					SetColumnMaxWidth (long, long);

		long					GetColumnHilite (void);
		short					GetColumnHilite (long);
		void					SetColumnHilite (long, short);

		long					InsertColumn (long before = -1);
		void					DeleteColumn (long);

		/*
		 *	Standard behaviour routines
		 */
		void					DoDrawView (XRect);
		virtual void			DrawColumn (XGDraw &, XRect &, long, short);

		bool					DoMouseDown (XPoint, short);
		void					DoMouseMove (XPoint, short);
		void					DoMouseUp (XPoint, short);

		void					RecalcAutoLocation (XGView *below = NULL, XGView *beside = NULL, XRect *r = NULL);
		virtual long			GetHeight (void);

	private:
		short					fColumns;
		short					fResID;
		bool					fLeaveRoom;
		bool					fResizable;
		bool					fClickable;
		XGStringList			fLabels;
		XGSDynArray<XGHeaderPositionRecord>		fPositions;

		long					fLastState;
		long					fLastCol;
		XPoint					fLastWhere;
		long					fLastSlop;
		long					fLastWidth;
		XGDispatch *			fLastFocus;

		XGView *				fView;

		long					NearBoundary (XPoint);
		long					InColumn (XPoint);
		void					BroadcastChange (long, long, bool, bool);
		void					IInitView (void);

};

#endif	// SS_HEADER
