/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     2000/02/08
// RCS-ID:      $Id: newsash.h,v 1.2 2001/03/14 13:48:11 aleksandras Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:   	GPL (version 2.0 or later)
/////////////////////////////////////////////////////////////////////////////

#ifndef __NEWSASH_G__
#define __NEWSASH_G__

#include "wx/laywin.h"

/*
 * wxSashWindow flags
 */

#define wxSW_CLOSE_BOX        0x0040
#define wxSW_DRAG_HINT        0x0080
#define wxSW_NO_DRAG          0x0100

class wxNewSashLayoutWindow : public wxSashLayoutWindow
{
	DECLARE_CLASS(wxNewSashLayoutWindow)
public:
    wxNewSashLayoutWindow( wxWindow *parent, wxWindowID id = -1, 
						   const wxPoint& pos = wxDefaultPosition,
						   const wxSize& size = wxDefaultSize, 
						   long style = wxSW_3D|wxCLIP_CHILDREN|wxSW_DRAG_HINT|wxSW_CLOSE_BOX, 
						   const wxString& name = "newLayoutWindow");

	// a convenience method, reduces code for resizing sashes
	// in the containing frame:

	void HandleSashDrag( wxSashEvent& event );
	void ChangeEdgePosition( wxLayoutAlignment align );

	void OnPaint( wxPaintEvent& event );
	void OnLeftDown( wxMouseEvent& event );
	void OnLeftUp( wxMouseEvent& event );
	void OnMotion( wxMouseEvent& event );
	void OnRightUp( wxMouseEvent& event );
	void OnSize( wxSizeEvent& event );

	DECLARE_EVENT_TABLE()


protected:

	void TrackGhostRect( wxMouseEvent& event );
	void HideGhostRect();

	// can be overriden to change drawing behaviour
	virtual void DrawBox( wxDC& dc, const wxRect& area );
	virtual void DrawDragHint( wxDC& dc, const wxRect& area );
	virtual void DrawGhostRect( wxDC& dc, const wxRect& area, bool isInversed = FALSE );
	virtual int  GetHintWidth();
	virtual wxSize GetBoxSize(); 
	virtual int  GetDragHintWidth();

	virtual wxRect CalcBoxArea( const wxRect& innerRect );
	virtual wxRect CalcDragHintArea( const wxRect& innerRect );
	virtual void DrawDecorations( wxDC& dc );

	// utilities

	wxRect GetInnerRect();
	wxRect GetSashlessRect();
	bool HasBox();
	bool HasDragHint();
	bool CanBeDragged();
	bool IsVertical();
	bool IsWithinDragArea( wxMouseEvent& event );

	wxPoint ToScreen( const wxPoint& localPoint );
	wxRect  ToScreen( const wxRect& localRect );
	wxRect  GetParentRect();

	bool TestNearestEdge( int& edge, const wxPoint& mousePos, bool& hitsMouse, int rqEdge );
	void FindNearestEdge( int& edge, const wxPoint& mousePos, bool& hitsMouse );
	wxRect GetAlignedRect( int edge );
	bool RectContains( const wxRect& rect, const wxPoint& point );

	virtual void RelayoutParent();

protected:
	long    mStyleFlags;
	wxPoint mDragOrigin;
	wxPoint mRelativeOrigin;

	int     mCurDragAlignment;
	wxRect  mCurGhostRect;
	wxSize  mCurGhostSize;
	wxRect  mPrevGhostRect;
	bool    mGhostDrawn;
	bool    mDragStarted;
	bool    mButtonDragStarted;
	bool    mPressed;
	int     mGhostRectBorderWidth; // default: 6
	int     mMinOverlap;           // default: 20
};

#endif // __NEWSASH_G__