/////////////////////////////////////////////////////////////////////////
//
// CSizingControlBar Version 2.43
//
// Created: Jan 24, 1998 Last Modified: August 03, 2000
//
// See the official site at www.datamekanix.com for documentation and
// the latest news.
//
/////////////////////////////////////////////////////////////////////////
// Copyright (C) 1998-2000 by Cristi Posea. All rights reserved.
//
// This code is free for personal and commercial use, providing this
// notice remains intact in the source files and all eventual changes are
// clearly marked with comments.
//
// You must obtain the author's consent before you can include this code
// in a software library.
//
// No warrantee of any kind, express or implied, is included with this
// software; use at your own risk, responsibility for damages (if any) to
// anyone resulting from the use of this software rests entirely with the
// user.
//
// Send bug reports, bug fixes, enhancements, requests, flames, etc. to
// [email protected] or post them at the message board at the site.
//
// The sources and a short version of the docs are also available at
// www.codeproject.com . Look for a "Docking Windows" section and check
// the version to be sure you get the latest one ;)
//
// Hint: These classes are intended to be used as base classes. Do not
// simply add your code to these file - instead create a new class
// derived from one of CSizingControlBarXX classes and put there what
// you need. See CMyBar classes in the demo projects for examples.
// Modify this file only to fix bugs, and don't forget to send me a copy.
/////////////////////////////////////////////////////////////////////////
// Acknowledgements:
// o Thanks to Harlan R. Seymour for his continuous support during
// development of this code.
// o Thanks to Dundas Software for the opportunity
// to test this code on real-life applications.
// o Some ideas for the gripper came from the CToolBarEx flat toolbar
// by Joerg Koenig. Thanks, Joerg!
// o Thanks to Robert Wolpow for the code on which CDockContext based
// dialgonal resizing is based.
// o Thanks to the following people for various bug fixes and/or
// enhancements: Chris Maunder, Jakawan Ratiwanich, Udo Schaefer,
// Anatoly Ivasyuk, Peter Hauptmann.
// o And, of course, many thanks to all of you who used this code,
// for the invaluable feedback I received.
/////////////////////////////////////////////////////////////////////////
// sizecbar.cpp : implementation file
//
#include "stdafx.h"
#include "sizecbar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////
// CSizingControlBar
IMPLEMENT_DYNAMIC(CSizingControlBar, baseCSizingControlBar);
CSizingControlBar::CSizingControlBar()
{
m_szMinHorz = CSize(33, 32);
m_szMinVert = CSize(33, 32);
m_szMinFloat = CSize(37, 32);
m_szHorz = CSize(200, 200);
m_szVert = CSize(200, 200);
m_szFloat = CSize(200, 200);
m_bTracking = FALSE;
m_bKeepSize = FALSE;
m_bParentSizing = FALSE;
m_cxEdge = 5;
m_bDragShowContent = FALSE;
m_nDockBarID = 0;
m_dwSCBStyle = 0;
}
CSizingControlBar::~CSizingControlBar()
{
}
BEGIN_MESSAGE_MAP(CSizingControlBar, baseCSizingControlBar)
//{{AFX_MSG_MAP(CSizingControlBar)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_NCPAINT()
ON_WM_NCCALCSIZE()
ON_WM_WINDOWPOSCHANGING()
ON_WM_CAPTURECHANGED()
ON_WM_SETTINGCHANGE()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_NCLBUTTONDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDOWN()
ON_WM_NCMOUSEMOVE()
ON_WM_NCHITTEST()
ON_WM_CLOSE()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_SETTEXT, OnSetText)
END_MESSAGE_MAP()
// old creation method, still here for compatibility reasons
BOOL CSizingControlBar::Create(LPCTSTR lpszWindowName, CWnd* pParentWnd,
CSize sizeDefault, BOOL bHasGripper,
UINT nID, DWORD dwStyle)
{
UNUSED_ALWAYS(bHasGripper);
m_szHorz = m_szVert = m_szFloat = sizeDefault;
return Create(lpszWindowName, pParentWnd, nID, dwStyle);
}
// preffered creation method
BOOL CSizingControlBar::Create(LPCTSTR lpszWindowName,
CWnd* pParentWnd, UINT nID,
DWORD dwStyle)
{
// must have a parent
ASSERT_VALID(pParentWnd);
// cannot be both fixed and dynamic
// (CBRS_SIZE_DYNAMIC is used for resizng when floating)
ASSERT (!((dwStyle & CBRS_SIZE_FIXED) &&
(dwStyle & CBRS_SIZE_DYNAMIC)));
m_dwStyle = dwStyle & CBRS_ALL; // save the control bar styles
// register and create the window - skip CControlBar::Create()
CString wndclass = ::AfxRegisterWndClass(CS_DBLCLKS,
::LoadCursor(NULL, IDC_ARROW),
::GetSysColorBrush(COLOR_BTNFACE), 0);
dwStyle &= ~CBRS_ALL; // keep only the generic window styles
dwStyle |= WS_CLIPCHILDREN; // prevents flashing
if (!CWnd::Create(wndclass, lpszWindowName, dwStyle,
CRect(0, 0, 0, 0), pParentWnd, nID))
return FALSE;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
// CSizingControlBar operations
#if defined(_SCB_REPLACE_MINIFRAME) && !defined(_SCB_MINIFRAME_CAPTION)
void CSizingControlBar::EnableDocking(DWORD dwDockStyle)
{
// must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
// cannot have the CBRS_FLOAT_MULTI style
ASSERT((dwDockStyle & CBRS_FLOAT_MULTI) == 0);
// the bar must have CBRS_SIZE_DYNAMIC style
ASSERT((m_dwStyle & CBRS_SIZE_DYNAMIC) != 0);
m_dwDockStyle = dwDockStyle;
if (m_pDockContext == NULL)
m_pDockContext = new CSCBDockContext(this);
// permanently wire the bar's owner to its current parent
if (m_hWndOwner == NULL)
m_hWndOwner = ::GetParent(m_hWnd);
}
#endif
/////////////////////////////////////////////////////////////////////////
// CSizingControlBar message handlers
int CSizingControlBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (baseCSizingControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
// query SPI_GETDRAGFULLWINDOWS system parameter
// OnSettingChange() will update m_bDragShowContent
m_bDragShowContent = FALSE;
::SystemParametersInfo(SPI_GETDRAGFULLWINDOWS, 0,
&m_bDragShowContent, 0);
// uncomment this line if you want raised borders
// m_dwSCBStyle |= SCBS_SHOWEDGES;
return 0;
}
LRESULT CSizingControlBar::OnSetText(WPARAM wParam, LPARAM lParam)
{
UNUSED_ALWAYS(wParam);
LRESULT lResult = CWnd::Default();
if (IsFloating() &&
GetParentFrame()->IsKindOf(RUNTIME_CLASS(CMiniDockFrameWnd)))
{
m_pDockBar->SetWindowText((LPCTSTR) lParam); // update dockbar
GetParentFrame()->DelayRecalcLayout(); // refresh miniframe
}
return lResult;
}
const BOOL CSizingControlBar::IsFloating() const
{
return !IsHorzDocked() && !IsVertDocked();
}
const BOOL CSizingControlBar::IsHorzDocked() const
{
return (m_nDockBarID == AFX_IDW_DOCKBAR_TOP ||
m_nDockBarID == AFX_IDW_DOCKBAR_BOTTOM);
}
const BOOL CSizingControlBar::IsVertDocked() const
{
return (m_nDockBarID == AFX_IDW_DOCKBAR_LEFT ||
m_nDockBarID == AFX_IDW_DOCKBAR_RIGHT);
}
const BOOL CSizingControlBar::IsSideTracking() const
{
// don't call this when not tracking
ASSERT(m_bTracking && !IsFloating());
return (m_htEdge == HTLEFT || m_htEdge == HTRIGHT) ?
IsHorzDocked() : IsVertDocked()