/*	XScroll.h
 *
 *		Scroll bar and scrolling support
 */

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

  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 PandaWave_XSCROLL
#define PandaWave_XSCROLL

#include <XConfig.h>
#include <XControls.h>

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


struct XGSScrollInitRecord {
	XGSViewInitRecord	view;

	long				fValue;
	long				fMinValue;
	long				fMaxValue;
	long				fStepValue;
	long				fPageValue;	
};

struct XGSScrollViewInit {
	XGSViewInitRecord	view;

	bool				fHScroll;
	bool				fVScroll;
	bool				fCorner;
};

/************************************************************************/
/*																		*/
/*	Scroll bar declaration												*/
/*																		*/
/************************************************************************/

/*$	XGScrollBar
 *
 *		This is the scrollbar encapsulation.
 */

class XGScrollBar : public XGSlider {
	public:
								XGScrollBar(XGView *, XGSScrollInitRecord &);
								XGScrollBar(XGView *, XGArgStream &);
		virtual					~XGScrollBar();
		
		enum {
			kClassID = 'scrb'
		};

		/*
		 *	Display overrides
		 */
		 
		void					DoDrawView(XRect);
		void					DoActivate(bool);
		
		bool					DoMouseDown(XPoint,short);
		void					DoMouseMove(XPoint,short);
		void					DoMouseUp(XPoint,short);
		
		void					DoSizeView();
		void					DoMoveView();
		void					DoShowHide();
		void					DoEnable();
		
#if OPT_WINOS
		void					SetFocus();
#endif
		 
		/*
		 *	Value management
		 */
		
		long					GetValue();
		long					GetMinValue();
		long					GetMaxValue();
		long					GetStepSize(void);
		long					GetPageSize(void);

		void					SetValue(long);
		void					SetMinValue(long);
		void					SetMaxValue(long);
		void					SetStepSize(long);
		void					SetPageSize(long);
		
		/*
		 *	Default sizes
		 */
		
		static XPoint			GetDefaultSize();
		
		/*
		 *	Event management
		 */
		
#if OPT_WINOS
		DECLAREDISPATCH
		long					DoWInternal(long,void *);
#endif

	protected:
		long					fPage;
		long					fStep;
		long					fValue;
		long					fMinValue;
		long					fMaxValue;
		
		void					InitScrollBar(XGSScrollInitRecord &);
		
#if OPT_MACOS
		static pascal void		Track(ControlHandle,short);
		void					AdjustScale();
		void					LoadControl();
		
		long					fScale;
		ControlHandle			fControl;
#endif

#if OPT_WINOS
		void					AdjustScale();
		void					LoadControl();
		
		long					fScale;
		HWND					fControl;
#endif

#if OPT_XWIN
		void					DrawScrollBar(short part = -1);
		XRect					CalcScrollRect(short);
		void					UpdateTrackValue(XPoint);
		short					ThumbWidth();

		bool					fDown;
		short					fTrack;				// what am I down on?
#endif
};

/*$	XGScrollView
 *
 *		This is a view container; this contains one or two scrollbars and
 *	one or more views which are sent scrolling commands from those scrollbars
 */

class XGScrollView : public XGView {
	public:
								XGScrollView(XGView *parent, XGArgStream &s);
								XGScrollView(XGView *parent, XGSScrollViewInit &s);
		virtual					~XGScrollView();
		
		enum {
			kClassID = 'scrv'
		};

		/*
		 *	Events
		 */
		
		void					DoDrawView(XRect);
		void					DoSizeView();
		XRect					CalcChildPos(XGView *);
		
		/*
		 *	Controls
		 */
		
		void					SetScrollValue(long,long);
		void					SetMinValue(long,long);
		void					SetMaxValue(long,long);
		void					SetStepSize(long);
		void					SetPageSize(long,long);
		void					SetPixelStep(long x)
									{
										fPixel = x;
									}
		
		void					GetScrollValue(long *, long *);
		void					GetMinValue(long *, long *);
		void					GetMaxValue(long *, long *);
		long					GetStepSize();
		void					GetPageSize(long *, long *);
		long					GetPixelStep()
									{
										return fPixel;
									}

		/*
		 *	Events
		 */
		
		DECLAREDISPATCH
		long					DoSliderStart(long,void *);
		long					DoSliderValue(long,void *);

	private:
		void					InitScrollView(XGSScrollViewInit &);
		
		XRect					CalcHScroll();
		XRect					CalcVScroll();
		XRect					CalcCornerRect();
		XRect					CalcContentRect();
		
		bool					fCorner;
		long					fPixel;
		XGScrollBar				*fHoriz;
		XGScrollBar				*fVert;
};

#endif // PandaWave_XSCROLL
