Ejemplo n.º 1
0
BOOL CInPlaceFrame::CanGetBorderSpace(
    LPCRECT lpRectBorder, LPOLEINPLACEUIWINDOW lpUIWindow, BOOL bFrame)
{
    ASSERT_VALID(this);
    ASSERT(lpRectBorder == NULL ||
        AfxIsValidAddress(lpRectBorder, sizeof(RECT), FALSE));
    ASSERT(lpUIWindow != NULL);

    // use IOleInPlaceUIWindow::GetBorder if no border given
    CRect rectBorder;
    if (lpRectBorder != NULL)
        rectBorder.CopyRect(lpRectBorder);
    else
        lpUIWindow->GetBorder(&rectBorder);

    // get CWnd* for the OLE window
    HWND hwnd;
    VERIFY(lpUIWindow->GetWindow(&hwnd) == NOERROR);
    CWnd* pWnd = CWnd::FromHandle(hwnd);
    ASSERT(pWnd != NULL);
  
    // see how much space we need by calling reposition bars
    CRect rectNeeded = rectBorder;
    pWnd->RepositionBars(0, 0xFFFF, 0, CWnd::reposQuery, &rectNeeded, &rectBorder);
    CRect rectRequest;

    // request the border space from the container
    rectRequest.SetRect(
        rectNeeded.left - rectBorder.left,
        rectNeeded.top - rectBorder.top,
        rectBorder.right - rectNeeded.right,
        rectBorder.bottom - rectNeeded.bottom);
    CRect rectTemp;
    rectTemp = rectRequest;

    // if no border space, just call SetBorderSpace
    if (rectRequest.IsRectNull())
        goto RequestFailed;

    if (lpUIWindow->RequestBorderSpace(&rectTemp) != NOERROR)
        goto RequestFailed;

    return TRUE;

RequestFailed:

	return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// CBCGPOleServerDoc commands
void CBCGPOleServerDoc::OnResizeBorder( LPCRECT lpRectBorder, LPOLEINPLACEUIWINDOW lpUIWindow, BOOL bFrame )
{
	ASSERT_VALID (this);
	ASSERT (lpUIWindow != NULL);
	
	if (!bFrame)
	{
		COleServerDoc::OnResizeBorder (lpRectBorder, lpUIWindow, bFrame);
		return;
	}

	CBCGPOleCntrFrameWnd* pMainFrame = NULL;

	CBCGPOleDocIPFrameWnd* p_IpDocFrame = 
						DYNAMIC_DOWNCAST(CBCGPOleDocIPFrameWnd, m_pInPlaceFrame);

	if (p_IpDocFrame != NULL)
	{
		pMainFrame =  p_IpDocFrame->GetContainerFrameWindow ();
	}
	else
	{
		CBCGPOleIPFrameWnd* p_IpFrame = 
						DYNAMIC_DOWNCAST (CBCGPOleIPFrameWnd, m_pInPlaceFrame);

		if (p_IpFrame != NULL)
		{
			pMainFrame = p_IpFrame->GetContainerFrameWindow ();
		}
		else
		{
			return;
		}
	}

	if (pMainFrame == NULL)
	{
		return;
	}

	CBCGPDockManager* pDockManager = pMainFrame->GetDockManager ();
	ASSERT_VALID (pDockManager);

	CRect rcCurBorders;

	if (lpRectBorder == NULL)
	{
		if (lpUIWindow->GetBorder(&rcCurBorders) != S_OK)
		{
			lpUIWindow->SetBorderSpace (NULL);
			return;
		}
	}
	else
	{
		rcCurBorders = *lpRectBorder;
	}

	if (AfxGetThread()->m_pActiveWnd == m_pInPlaceFrame)
		OnShowControlBars(pMainFrame, TRUE);


	pDockManager->m_rectInPlace = rcCurBorders; 
	pDockManager->AdjustDockingLayout ();

	CRect rectClient = pDockManager->GetClientAreaBounds ();

	CRect rectRequest (
		abs (rectClient.left - rcCurBorders.left),
		abs (rectClient.top - rcCurBorders.top),
		abs (rectClient.right - rcCurBorders.right),
		abs (rectClient.bottom  - rcCurBorders.bottom)); // v.8.6 removed -1 to make it work in Excel

	CRect rectTemp;
	rectTemp = rectRequest;
	
	if (!rectRequest.IsRectNull() ||
		lpUIWindow->RequestBorderSpace(&rectTemp) == S_OK)
	{
		lpUIWindow->SetBorderSpace (&rectRequest);
		pDockManager->AdjustDockingLayout ();
	}
	else
	{
		OnShowControlBars (pMainFrame, FALSE);
		CRect rect (0,0,0,0);
		lpUIWindow->SetBorderSpace(&rect);
	}
}