/** \file
	\author Matthew Allen
	\brief A button control
 */

#ifndef _GBUTTON_H_
#define _GBUTTON_H_

#ifdef MAC
#define GBUTTON_MIN_X	28
#else
#define GBUTTON_MIN_X	16
#endif

/// \brief A clickable button
///
/// When the user clicks a LButton the OnNotify() event of the GetNotify() or 
/// GetParent() view will be called with this control as the parameter. Allowing
/// action to be taken in response to the click. This event by default bubbles up
/// to the top level window unless some other view intercepts it on the way up
/// the chain of parent views.
class LgiClass LButton :
	#if WINNATIVE && !XP_BUTTON
	public LControl,
	#else
	public LView,
	#endif
	public ResObject
{
	class LButtonPrivate *d;

public:
    /// The extra pixels beyond the size of the text needed
    /// to display the button;
    static LPoint Overhead;

	/// Construct the control
	LButton
	(
		/// The control's ID
		int id,
		/// x coord
		int x = 0,
		/// y coord
		int y = 0,
		/// width
		int cx = -1,
		/// height
		int cy = -1,
		/// Initial text
		const char *name = NULL
	);
	~LButton();
	
	const char *GetClass() override { return "LButton"; }
	
	/// True if the button is the default action on the dialog
	bool Default();
	/// Sets the button to be the default action on the dialog
	void Default(bool b);
	/// True if the button is down.
	int64 Value() override;
	/// Sets the button to down.
	void Value(int64 i) override;

	/// Returns true if the button is set to toggle mode
	bool GetIsToggle();
	/// Set the button's toggle mode
	void SetIsToggle(bool toggle);

	/// Returns the icon
	LSurface *GetImage();
	/// Sets the icon using a filename
	bool SetImage(const char *FileName);
	/// Sets the icon
	bool SetImage(LSurface *Img, bool OwnIt);

    /// Sets the control to it's preferred size for it's text &| image
    void SetPreferredSize(int x = -1, int y = -1);

	// Events
	LMessage::Result OnEvent(LMessage *Msg) override;
	void OnMouseClick(LMouse &m) override;
	void OnMouseEnter(LMouse &m) override;
	void OnMouseExit(LMouse &m) override;
	bool OnKey(LKey &k) override;
	void OnFocus(bool f) override;
	void OnPaint(LSurface *pDC) override;
	void OnCreate() override;
	void OnAttach() override;
	void OnStyleChange();
	virtual void OnClick(const LMouse &m);

	// Impl
	const char *Name() override { return LView::Name(); }
	const char16 *NameW() override { return LView::NameW(); }
	bool Name(const char *n) override;
	bool NameW(const char16 *n) override;
	void SetFont(LFont *Fnt, bool OwnIt = false) override;
	int OnNotify(LViewI *Ctrl, LNotification n) override;

	#if WINNATIVE && !XP_BUTTON
	int SysOnNotify(int Msg, int Code);
	#else
	bool OnLayout(LViewLayoutInfo &Inf) override;
	#endif
};

#endif
