/*	XPopup.h
 *
 *		Popup list management
 */

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

  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_XPOPUP
#define PandaWave_XPOPUP

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

/************************************************************************/
/*																		*/
/*	Forwards															*/
/*																		*/
/************************************************************************/

class XGInlinePopup;
class XGPopWindow;
class XGPopControl;
class XGDraw;
class XGFont;

/************************************************************************/
/*																		*/
/*	Class Declarations													*/
/*																		*/
/************************************************************************/

/*$	XGPopMenuView
 *
 *		The view that gets popped up in the XGPopControl popup control.
 */

class XGPopMenuView : public XGView, public XGPeriodic {
	public:
								XGPopMenuView(XGStringList *, short font, short def);
		virtual					~XGPopMenuView();
		
		/*
		 *	Init support
		 */
		
		XPoint					GetPopSize(XGDraw &);
		short					GetLocation()
									{
										return fLocation;
									}
		
		/*
		 *	Events
		 */
		
		void					DoDrawView(XRect);
		void					DoSizeView();
		void					DoMouseMove(XPoint,short);
		
		void					DoPrePeriodic();
		
		/*
		 *	Move the cursor around--this supports keyboard navigation
		 */
		
		void					MoveUp();
		void					MoveDown();
		void					MoveTo(short len, char *ptr);
		
	private:
		short					fDefault;
		short					fLocation;
		short					fFont;
		XGStringList			*fList;
		
		short					fHeight;
		short					fScroll;
		short					fMaxScroll;
		
		bool					fScrollFlag;
		XPoint					fLastPos;
		long					fTime;
		
		void					SetSelect(short);
		void					DrawUDArrow(XGDraw &, bool);
		void					DrawLine(XGDraw &,short,bool);
		void					RecalcScroll();
		bool					ScrollInRange();
};

/*$	XGPopControl
 *
 *		The popup control
 */

class XGPopControl : public XGControl {
	public:
								XGPopControl(XGView *o, XGArgStream &s);
		virtual					~XGPopControl();
		
		enum {
			kClassID = 'popm'
		};
		
		/*
		 *	View event overrides
		 */
		 
		void					DoDrawView(XRect);
		void					DoActivate(bool);
		bool					DoMouseDown(XPoint,short);

		void					DoSizeView();
		void					DoMoveView();
		void					DoShowHide();
		void					DoEnable();
#if OPT_WINOS
		void					SetFocus();
#endif

		/*
		 *	Events
		 */
		
		long					GetValue();
		void					SetValue(long);
		void					DoGainFocus();
		void					DoLoseFocus();
		
		/*
		 *	Lists
		 */
		
		void					GetItem(long,char *) const;
		long					Length() const;
		void					Insert(long,const char *);
		void					Delete(long);
		void					DeleteAll();
		
		DECLAREDISPATCH
		long					DoKey(long,void *);
		long					DoInlineClose(long, void *);

#if OPT_WINOS
		long					DoWInternal(long,void *);
#endif

	private:
		XGInlinePopup			*fPop;
		XGStringList			fList;
		XGFont					*fFont;
		short					fFontID;
		long					fValue;

#if OPT_MACOS
		ControlHandle			fControl;
#endif
#if OPT_WINOS
		HWND					fControl;
#endif

		void					ReloadItems (void);
		void					InitControl (void);

	friend class XGPopMenuView;
};
		
#endif // PandaWave_XPOPUP
