Click here to Skip to main content
15,891,567 members
Articles / Desktop Programming / WTL

WTL Docking Windows

Rate me:
Please Sign up or sign in to vote.
4.89/5 (73 votes)
21 Nov 20077 min read 850.3K   14.1K   215  
This is an implementation of docking windows for the WTL library
// Copyright (c) 2002
// Sergey Klimov (kidd@ukr.net)
// WTL Docking windows
//
// This code is provided "as is", with absolutely no warranty expressed
// or implied. Any use is at your own risk.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name is included. If
// the source code in  this file is used in any commercial application
// then a simple email would be nice.

#ifndef WTL_DW_SIMPLESPLITTERBAR_H_INCLUDED_
#define WTL_DW_SIMPLESPLITTERBAR_H_INCLUDED_

#ifndef __ATLMISC_H__
        #error SimpleSplitterBar.h requires atlmisc.h to be included first
#endif

namespace dockwins{

template<long TThickness=5>
class CSimpleSplitterBar :  public CRect
{
public:
	enum{sbThickness=TThickness};

	CSimpleSplitterBar(bool bHorizontal=true)
		:m_bHorizontal(bHorizontal)
	{
	}
	CSimpleSplitterBar(const CSimpleSplitterBar& ref)
		:CRect(ref),m_bHorizontal(ref.IsHorizontal())
	{

	}
	static long GetThickness()
	{
		return sbThickness;
	}
	void SetOrientation(bool bHorizontal)
	{
		m_bHorizontal=bHorizontal;
	}
	bool IsHorizontal() const
	{
		return m_bHorizontal;
	}

	bool IsPtIn(const CPoint& pt) const
	{
		return (PtInRect(pt)!=FALSE);
	}

	HCURSOR GetCursor(const CPoint& pt) const
	{
		HCURSOR hCursor=NULL;
		if(IsPtIn(pt))
		{
			CDWSettings settings;
			 hCursor=((IsHorizontal())
								?settings.HResizeCursor()
								:settings.VResizeCursor());
		}
		return hCursor;
	}

    void Draw(CDC& dc) const
    {
        dc.FillRect(this, (HBRUSH)LongToPtr(COLOR_3DFACE + 1));
    }
	void DrawGhostBar(CDC& dc) const
	{
        CBrush brush = CDCHandle::GetHalftoneBrush();
        if(brush.m_hBrush != NULL)
        {
            HBRUSH hBrushOld = dc.SelectBrush(brush);
            dc.PatBlt(this->left, this->top,this->Width(),this->Height(), PATINVERT);
            dc.SelectBrush(hBrushOld);

        }

	}
	void CleanGhostBar(CDC& dc) const
	{
		DrawGhostBar(dc);
	}
protected:
	bool m_bHorizontal;
};


template<long TThickness=5>
class CSimpleSplitterBarEx: public CSimpleSplitterBar<TThickness>
{
	typedef CSimpleSplitterBar<TThickness> baseClass;
public:
	CSimpleSplitterBarEx(bool bHorizontal=true)
		:baseClass(bHorizontal)
	{
	}
	CSimpleSplitterBarEx(const CSimpleSplitterBarEx& ref)
		:baseClass(ref)
	{

	}

    void Draw(CDC& dc) const
    {
        dc.FillRect(this, (HBRUSH)LongToPtr(COLOR_3DFACE + 1));
		CRect rc(*this);
//		dc.DrawEdge(&rc, EDGE_RAISED, (IsHorizontal()) ? (BF_TOP | BF_BOTTOM) : (BF_LEFT | BF_RIGHT) );
		dc.DrawEdge(&rc, BDR_RAISEDINNER, (IsHorizontal()) ? (BF_TOP | BF_BOTTOM) : (BF_LEFT | BF_RIGHT) );

    }

};

template<class T>
class CSimpleSplitterBarSlider
{
	typedef T CSplitter;
	typedef CSimpleSplitterBarSlider<CSplitter> thisClass;
public:
	CSimpleSplitterBarSlider(CSplitter& splitter)
		:m_splitter(splitter)
	{
		if(!m_splitter.IsHorizontal())
		{
			m_pTop=&m_splitter.left;
			m_pDependant=&m_splitter.right;
		}
		else
		{
			m_pTop=&m_splitter.top;
			m_pDependant=&m_splitter.bottom;
		}
	}
	operator long() const
	{
		return *m_pTop;
	}

	long operator=(long val)
	{
		*m_pDependant=val+m_splitter.GetThickness();
		return *m_pTop=val;
	}

	thisClass& operator += (long val)
	{
		*this=*this+val;
		return *this;
	}
	thisClass& operator -= (long val)
	{
		*this=*this-val;
		return *this;
	}

protected:
	CSplitter& m_splitter;
	long	*m_pTop;
	long	*m_pDependant;
};

}//namespace dockwins

#endif // WTL_DW_SIMPLESPLITTERBAR_H_INCLUDED_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions