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

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or 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 MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library 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.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#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												*/
/*																		*/
/************************************************************************/

/*	@C"XGScrollBar"
 *	@D"XGSlider"
 *	@H"XScroll.h"
 *	@I
 *
 *		This is the scrollbar encapsulation.
 */

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

		/*
		 *	Display overrides
		 */
		 
		void					DoDrawView(Rect);
		void					DoActivate(bool);
		
		bool					DoMouseDown(Point,short);
		void					DoMouseMove(Point,short);
		void					DoMouseUp(Point,short);
		
		void					DoSizeView();
		void					DoMoveView();
		void					DoShowHide();
		void					DoEnable();
		
#if OPT_WINOS
		bool					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 Point			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);
		Rect					CalcScrollRect(short);
		void					UpdateTrackValue(Point);
		short					ThumbWidth();

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

/*	@C"XGScrollView"
 *	@D"XGView"
 *	@H"XScroll.h"
 *	@I
 *
 *		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(XGOwner *parent, XGArgStream &s);
								XGScrollView(XGOwner *parent, XGSScrollViewInit &s);
		virtual					~XGScrollView();
		
		enum {
			kClassID = 'scrv'
		};

		/*
		 *	Events
		 */
		
		void					DoDrawView(Rect);
		Rect					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 &);
		
		Rect					CalcHScroll();
		Rect					CalcVScroll();
		Rect					CalcCornerRect();
		Rect					CalcContentRect();
		
		bool					fCorner;
		long					fPixel;
		XGScrollBar				*fHoriz;
		XGScrollBar				*fVert;
};

#endif // PandaWave_XSCROLL
