Beispiel #1
0
void CXTPDockBar::DockCommandBar(CXTPToolBar* pBar, LPCRECT lpRect)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pBar);
	ASSERT_KINDOF(CXTPToolBar, pBar);

	CRect rectBar;
	pBar->GetWindowRect(&rectBar);
	if (pBar->m_pDockBar == this && (lpRect == NULL || rectBar == *lpRect))
	{
		// already docked and no change in position
		return;
	}

	int nPos = -1;
	if (lpRect != NULL)
	{
		// insert into appropriate row
		CRect rect(lpRect);
		ScreenToClient(&rect);
		CPoint ptMid(rect.left + rect.Width()/2, rect.top + rect.Height()/2);
		nPos = Insert(pBar, rect, ptMid);

		pBar->m_pDockContext->m_rectMRUDockPos = rect;
	}
	else
	{
		// always add on current row, then create new one
		m_arrBars.Add(pBar);
		m_arrBars.Add(NULL);

		pBar->m_pDockContext->m_rectMRUDockPos.SetRectEmpty();
	}

	// attach it to the docking site
	if (pBar->GetParent() != this)
		pBar->SetParent(this);
	if (pBar->m_pDockBar == this)
		pBar->m_pDockBar->RemoveCommandBar(pBar, nPos);
	else if (pBar->m_pDockBar != NULL)
		pBar->m_pDockBar->RemoveCommandBar(pBar, -1);
	pBar->m_pDockBar = this;

	AdjustStretchBars();

	// get parent frame for recalc layout
	m_pCommandBars->RecalcFrameLayout(TRUE);
}
Beispiel #2
0
bool CTrack::Move(int x, int y)
{
	if (m_bDisabled)
		return false;

	if (!m_iHandleGrabbed)
		return false;

	// Prevent any accidental moves on the first click
	if (m_iHandleGrabbed == H_MOVE && !m_bMoved)
	{
		#define CLOSENESS 10 // pixels
		int dx = m_iLastDownX - x;
		int dy = m_iLastDownY - y;
		if (dx >= -CLOSENESS && dx <= CLOSENESS && dy >= -CLOSENESS && dy <= CLOSENESS)
			return false;
	}

	if (m_bShear)
		ConstrainXY(&x, &y, true/*bButtonDown*/, false/*bInit*/, m_bShear/*bActive*/);

	x = bound(x, m_BoundRectScreen.left, m_BoundRectScreen.right);
	y = bound(y, m_BoundRectScreen.top, m_BoundRectScreen.bottom);

	CPoint pt(x, y);
	m_ViewToDeviceMatrix.Inverse().Transform(pt);
	x = pt.x;
	y = pt.y;

	if (x == m_iLastX && y == m_iLastY)
		return false;

	m_bMoved = true;
	Draw(false/*bOn*/);

	switch (m_iHandleGrabbed)
	{
		case H_UL:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.top, m_Distort.Rect.right, m_Distort.Rect.bottom, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_UR:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.top, m_Distort.Rect.left, m_Distort.Rect.bottom, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_LR:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.right, m_Distort.Rect.bottom, m_Distort.Rect.left, m_Distort.Rect.top, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_LL:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY);
			else
				Scale(pt.x, pt.y, m_Distort.Rect.left, m_Distort.Rect.bottom, m_Distort.Rect.right, m_Distort.Rect.top, m_bConstrainAspect ^ CONTROL);
			break;
		}

		case H_TOP:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midx = (m_Distort.Rect.left + m_Distort.Rect.right)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, midx, m_Distort.Rect.top, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(midx, m_Distort.Rect.top);
				long dummy;
				m_Matrix.Transform(ptMid, pt.x, dummy);
				Scale(pt.x, pt.y, midx, m_Distort.Rect.top, midx, m_Distort.Rect.bottom, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_RIGHT:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midy = (m_Distort.Rect.top + m_Distort.Rect.bottom)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.right, midy, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(m_Distort.Rect.right, midy);
				long dummy;
				m_Matrix.Transform(ptMid, dummy, pt.y);
				Scale(pt.x, pt.y, m_Distort.Rect.right, midy, m_Distort.Rect.left, midy, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_BOTTOM:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midx = (m_Distort.Rect.left + m_Distort.Rect.right)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, midx, m_Distort.Rect.bottom, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(midx, m_Distort.Rect.bottom);
				long dummy;
				m_Matrix.Transform(ptMid, pt.x, dummy);
				Scale(pt.x, pt.y, midx, m_Distort.Rect.bottom, midx, m_Distort.Rect.top, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_LEFT:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			int midy = (m_Distort.Rect.top + m_Distort.Rect.bottom)/2;

			if (m_bShear)
				Shear(pt.x, pt.y, m_Distort.Rect.left, midy, m_bConstrainX, m_bConstrainY);
			else
			{
				CPoint ptMid(m_Distort.Rect.left, midy);
				long dummy;
				m_Matrix.Transform(ptMid, dummy, pt.y);
				Scale(pt.x, pt.y, m_Distort.Rect.left, midy, m_Distort.Rect.right, midy, false/*bConstrainAspect*/);
			}
			break;
		}

		case H_CENTER:
		{
			// transform points to transformed position
			m_Matrix.Transform(m_ptCenter);
			m_Matrix.Transform(m_ptRotate);
			int dx = pt.x - m_ptCenter.x;
			int dy = pt.y - m_ptCenter.y;
			m_ptRotate.x += dx;
			m_ptRotate.y += dy;
			m_ptCenter = pt;
			// transform points back to untransformed position
			m_Matrix.Inverse().Transform(m_ptCenter);
			m_Matrix.Inverse().Transform(m_ptRotate);
			break;
		}

		case H_CORNER_UL:
		case H_CORNER_UR:
		case H_CORNER_LR:
		case H_CORNER_LL:
		{
			m_Grid.Snap(pt);
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_ROTATE))
				Mode(m_iWhatCanDo & ~TR_ROTATE, false/*fDisplay*/);

			// transform the new point back to its untransformed position
			CPoint ptTemp = pt;
			m_Matrix.Inverse().Transform(ptTemp);
			int i = m_iHandleGrabbed - H_CORNER_UL;
			m_Distort.p[i] = ptTemp;

			// Update the m_Distort.Rect rectangle
			m_Distort.Rect.left   = min(min(min(m_Distort.p[0].x, m_Distort.p[1].x), m_Distort.p[2].x), m_Distort.p[3].x);
			m_Distort.Rect.right  = max(max(max(m_Distort.p[0].x, m_Distort.p[1].x), m_Distort.p[2].x), m_Distort.p[3].x);
			m_Distort.Rect.top    = min(min(min(m_Distort.p[0].y, m_Distort.p[1].y), m_Distort.p[2].y), m_Distort.p[3].y);
			m_Distort.Rect.bottom = max(max(max(m_Distort.p[0].y, m_Distort.p[1].y), m_Distort.p[2].y), m_Distort.p[3].y);
			break;
		}

		case H_ROTATE:
		{
			m_bMoveOnly = false;
			if (m_bExclusive && (m_iWhatCanDo & TR_SIZE))
				Mode(m_iWhatCanDo & ~TR_SIZE, false/*fDisplay*/);

			// transform points to transformed position
			Rotate(pt.x, pt.y, m_iStartRotateX, m_iStartRotateY);
			m_ptRotate = pt;
			// transform points back to untransformed position
			m_Matrix.Inverse().Transform(m_ptRotate);
			break;
		}

		case H_MOVE:
		{
			// Calculate how far we SHOULD move
			CPoint delta1(pt.x - m_iLastX, pt.y - m_iLastY);

			// Calculate where we are right now
			CRect rect = m_Distort.Rect;
			m_Matrix.Transform(rect);

			// Calculate the new top-left point
			CPoint ptNewTL(rect.left + delta1.x, rect.top + delta1.y);

			// Snap it to the grid
			m_Grid.Snap(ptNewTL);

			if (m_iWhatCanDo & TR_BOUNDTOSYMBOL)
			{
				int delta;
				delta = ptNewTL.x - m_BoundRect.left;
				if (delta < 0)
					ptNewTL.x -= delta;
				delta = ptNewTL.y - m_BoundRect.top;
				if (delta < 0)
					ptNewTL.y -= delta;
				delta = (ptNewTL.x + rect.Width()) - m_BoundRect.right;
				if (delta > 0)
					ptNewTL.x -= delta;
				delta = (ptNewTL.y + rect.Height()) - m_BoundRect.bottom;
				if (delta > 0)
					ptNewTL.y -= delta;
			}

			// Calculate how far we WILL move
			CPoint delta2(ptNewTL.x - rect.left, ptNewTL.y - rect.top);

			// Adjust the point for the next time around
			x -= (delta1.x - delta2.x);
			y -= (delta1.y - delta2.y);

			m_Matrix.Translate(delta2.x, delta2.y);
			break;
		}

		default:
			return false;
		}

	if (m_pDrawProc && m_pAGDC)
	{
		HDC hDC = m_pAGDC->GetHDC();
		m_pDrawProc(hDC, false/*bOn*/, TOOLCODE_UPDATE, m_pData);
	}

	Draw(true/*bOn*/);
	m_iLastX = x;
	m_iLastY = y;

	return true;
}
Beispiel #3
0
void CExtDockBar::_SlideDockControlBar(
	CControlBar* pBar,
	LPCRECT lpRect,
	BOOL bMovingEnabled
	)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pBar);
	ASSERT_KINDOF(CControlBar, pBar);

CRect rcBar;
	pBar->GetWindowRect(&rcBar);
	if(	pBar->m_pDockBar == this
		&& (lpRect == NULL || rcBar == *lpRect)
		)
	{
		// already docked and no change in position
		return;
	}

	// set CBRS_FLOAT_MULTI style if docking bar has it
	if(	m_bFloating
		&& (pBar->m_dwDockStyle & CBRS_FLOAT_MULTI)
		)
		m_dwStyle |= CBRS_FLOAT_MULTI;

	m_dwStyle &= ~(CBRS_SIZE_FIXED | CBRS_SIZE_DYNAMIC);
	m_dwStyle |=
		pBar->m_dwStyle & (CBRS_SIZE_FIXED | CBRS_SIZE_DYNAMIC);

	if( !(m_dwStyle & CBRS_FLOAT_MULTI) )
	{
		TCHAR szTitle[_MAX_PATH];
		pBar->GetWindowText(szTitle, _countof(szTitle));
		AfxSetWindowText(m_hWnd, szTitle);
	}

	// align correctly and turn on all borders
DWORD dwStyle = pBar->GetBarStyle();
	dwStyle &= ~(CBRS_ALIGN_ANY);
	dwStyle |=  (m_dwStyle & CBRS_ALIGN_ANY) | CBRS_BORDER_ANY;

	if( m_bFloating )
		dwStyle |= CBRS_FLOATING;
	else
		dwStyle &= ~CBRS_FLOATING;

	pBar->SetBarStyle( dwStyle );

/*
	// hide first if changing to a new docking site to avoid flashing
BOOL bShow = FALSE;
	if( pBar->m_pDockBar != this && pBar->IsWindowVisible() )
	{
		pBar->SetWindowPos(NULL, 0, 0, 0, 0,
			SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_HIDEWINDOW);
		bShow = TRUE;
	}
*/

int nPos = -1;
	if( lpRect != NULL )
	{
		// insert into appropriate row
		CRect rc( lpRect );
		ScreenToClient( &rc );
		CPoint ptMid(
			rc.left + rc.Width()/2,
			rc.top + rc.Height()/2
			);
		nPos = Insert( pBar, rc, ptMid );

		// position at requested position
		if( bMovingEnabled )
			pBar->SetWindowPos(
				NULL,
				rc.left, rc.top, rc.Width(), rc.Height(),
				SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS
					|SWP_NOREDRAW|SWP_NOSENDCHANGING
				);
	}
	else
	{
		// always add on current row, then create new one
		m_arrBars.Add(pBar);
		m_arrBars.Add(NULL);

		// align off the edge initially
		if( bMovingEnabled )
			pBar->SetWindowPos(
				NULL,
				-afxData.cxBorder2, -afxData.cyBorder2,
				0, 0,
				SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS
					|SWP_NOREDRAW|SWP_NOSENDCHANGING
				);
	}

	// attach it to the docking site
	if( pBar->GetParent() != this )
		pBar->SetParent(this);
	if( pBar->m_pDockBar == this )
		pBar->m_pDockBar->
			RemoveControlBar(pBar, nPos);
	else if( pBar->m_pDockBar != NULL )
		pBar->m_pDockBar->
			RemoveControlBar(
				pBar,
				-1,
				m_bFloating && !pBar->m_pDockBar->m_bFloating
				);
	pBar->m_pDockBar = this;

/*
	if( bShow )
	{
		ASSERT(!pBar->IsWindowVisible());
		pBar->SetWindowPos(NULL, 0, 0, 0, 0,
			SWP_NOSIZE|SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
	}
*/
	// remove any place holder for pBar in this dockbar
	RemovePlaceHolder( pBar );

/*
	// get parent frame for recalc layout
CFrameWnd* pFrameWnd = GetDockingFrame();
	pFrameWnd->DelayRecalcLayout();
*/
}
Beispiel #4
0
void CDockBar::DockControlBar(CControlBar* pBar, LPCRECT lpRect)
{
	ASSERT_VALID(this);
	ASSERT_VALID(pBar);
	ASSERT(pBar->IsKindOf(RUNTIME_CLASS(CControlBar)));

	// set CBRS_FLOAT_MULTI style if docking bar has it
	if (m_bFloating && (pBar->m_dwDockStyle & CBRS_FLOAT_MULTI))
		m_dwStyle |= CBRS_FLOAT_MULTI;

	CRect rectBar;
	pBar->GetWindowRect(&rectBar);
	if (pBar->m_pDockBar == this && (lpRect == NULL || rectBar == *lpRect))
	{
		// already docked and no change in position
		return;
	}

	if (!(m_dwStyle & CBRS_FLOAT_MULTI))
	{
		CString strTitle;
		pBar->GetWindowText(strTitle);
		AfxSetWindowText(m_hWnd, strTitle);
	}

	// align correctly and turn on all borders
	pBar->m_dwStyle &= ~(CBRS_ALIGN_ANY);
	pBar->m_dwStyle |= (m_dwStyle & CBRS_ALIGN_ANY) | CBRS_BORDER_ANY;

	int nPos = -1;
	if (lpRect != NULL)
	{
		// insert into appropriate row
		CRect rect(lpRect);
		ScreenToClient(&rect);
		CPoint ptMid(rect.left + rect.Width()/2, rect.top + rect.Height()/2);
		nPos = Insert(pBar, rect, ptMid);

		// position at requested position
		pBar->SetWindowPos(NULL, rect.left, rect.top, rect.Width(),
			rect.Height(), SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS);
	}
	else
	{
		// always add on current row, then create new one
		m_arrBars.Add(pBar);
		m_arrBars.Add(NULL);

		// align off the edge initially
		pBar->SetWindowPos(NULL, -afxData.cxBorder2, -afxData.cyBorder2, 0, 0,
			SWP_NOSIZE|SWP_NOZORDER|SWP_NOCOPYBITS);
	}

	// attach it to the docking site
	if (pBar->GetParent() != this)
		pBar->SetParent(this);
	if (pBar->m_pDockBar == this)
		pBar->m_pDockBar->RemoveControlBar(pBar, nPos);
	else if (pBar->m_pDockBar != NULL)
		pBar->m_pDockBar->RemoveControlBar(pBar);
	pBar->m_pDockBar = this;

	// get parent frame for recalc layout
	CFrameWnd* pFrameWnd = GetDockingFrame();
	pFrameWnd->DelayRecalcLayout();
}