예제 #1
0
void COleControl::DestroyTracker()
{
	ASSERT(!m_bOpen);
	ASSERT(m_bUIActive);

	if (m_pRectTracker == NULL)
		return;

	UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1;

	// Destroy the tracker.
	delete m_pRectTracker;
	m_pRectTracker = NULL;

	// Restore window to its original (pre-UIActive) size.
	CWnd* pWndOuter = GetOuterWindow();
	CWnd* pWndParent = pWndOuter->GetParent();
	CRect rectWindow;
	CRect rectParent;
	pWndOuter->GetWindowRect(rectWindow);
	pWndParent->GetClientRect(rectParent);
	pWndParent->ClientToScreen(rectParent);
	rectWindow.OffsetRect(-rectParent.left, -rectParent.top);
	rectWindow.InflateRect(-(int)nHandleSize, -(int)nHandleSize);
	::MoveWindow(pWndOuter->m_hWnd, rectWindow.left, rectWindow.top,
		rectWindow.Width(), rectWindow.Height(), TRUE);
}
예제 #2
0
void COleControl::CreateTracker(BOOL bHandles, BOOL bHatching)
{
	ASSERT(bHandles || bHatching);
	ASSERT(!m_bOpen);
	ASSERT(m_bUIActive);
	ASSERT(m_pRectTracker == NULL);

	UINT nStyle = 0;
	if (bHandles)
		nStyle |= CRectTracker::resizeOutside;
	if (bHatching)
		nStyle |= CRectTracker::hatchedBorder;

	ASSERT(nStyle != 0);

	TRY
	{
		// Create the tracker.
		CRect rectTmp = m_rcPos;
		_OffsetTrackerRect(rectTmp, this);
		m_pRectTracker = new CRectTracker(rectTmp, nStyle);
		UINT nHandleSize = m_pRectTracker->m_nHandleSize++;

		// Enlarge window to expose non-client area.
		CWnd* pWndOuter = GetOuterWindow();
		CWnd* pWndParent = pWndOuter->GetParent();
		CRect rectWindow;
		CRect rectParent;
		pWndOuter->GetWindowRect(rectWindow);
		pWndParent->GetClientRect(rectParent);
		pWndParent->ClientToScreen(rectParent);
		rectWindow.OffsetRect(-rectParent.left, -rectParent.top);
		rectWindow.InflateRect(nHandleSize, nHandleSize);
		::MoveWindow(pWndOuter->m_hWnd, rectWindow.left, rectWindow.top,
			rectWindow.Width(), rectWindow.Height(), TRUE);
	}
	CATCH (CException, e)
	{
		// If anything went wrong, just continue without the tracker.
		if (m_pRectTracker != NULL)
		{
			delete m_pRectTracker;
			m_pRectTracker = NULL;
		}
	}
	END_CATCH
}
예제 #3
0
void COleControl::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
	if (m_bOpen || m_pRectTracker == NULL ||
		!(m_pRectTracker->m_nStyle & _nResizeStyle) ||
		(nHitTest == HTHSCROLL) || (nHitTest == HTVSCROLL))
	{
		Default();
		return;
	}

	ScreenToClient(&point);

	AfxLockTempMaps();

	// Setup a (semi-)permanent CWnd for the control's parent window
	CRect rectBefore = m_pRectTracker->m_rect;
	CWnd* pWndClip = CWnd::FromHandle(::GetParent(GetOuterWindow()->m_hWnd));

	// Move or resize the tracker.
	BOOL bTrack = m_pRectTracker->Track(this, point, FALSE, pWndClip);

	AfxUnlockTempMaps();

	if (bTrack)
	{
		ASSERT(m_pInPlaceSite);

		CRect rectAfter = m_pRectTracker->m_rect;
		if (rectBefore != rectAfter)
		{
			// If rectangle changed, adjust the tracker's rectangle and move
			// the control.
			m_pRectTracker->m_rect.OffsetRect(-m_pRectTracker->m_rect.left,
				-m_pRectTracker->m_rect.top);
			CWnd* pWndOuter = GetOuterWindow();
			CWnd* pWndParent = pWndOuter->GetParent();
			CRect rectWindow;
			CRect rectParent;
			pWndOuter->GetWindowRect(rectWindow);
			pWndParent->GetClientRect(rectParent);
			pWndParent->ClientToScreen(rectParent);
			UINT nHandleSize = m_pRectTracker->m_nHandleSize - 1;
			rectAfter.OffsetRect(rectWindow.left - rectParent.left +
				nHandleSize, rectWindow.top - rectParent.top + nHandleSize);

			// Update the control's extents.
			SIZEL szlPixels;
			SIZEL szlHimetric;
			szlPixels.cx = (long)rectAfter.Width();
			szlPixels.cy = (long)rectAfter.Height();
			_AfxXformSizeInPixelsToHimetric(NULL, &szlPixels, &szlHimetric);
			if ((m_cxExtent != szlHimetric.cx) ||
				(m_cyExtent != szlHimetric.cy))
			{
				m_cxExtent = szlHimetric.cx;
				m_cyExtent = szlHimetric.cy;
				SetModifiedFlag();
			}

			// Move/resize the control's window.
			m_pInPlaceSite->OnPosRectChange(rectAfter);
		}
	}
}
예제 #4
0
파일: ctlinplc.cpp 프로젝트: Rupan/winscp
HRESULT COleControl::OnActivateInPlace(BOOL bUIActivate, LPMSG pMsg)
{
#ifdef _AFXDLL
	if (m_bOpen)
	{
		m_pWndOpenFrame->SetActiveWindow();
		SendAdvise(OBJECTCODE_SHOWWINDOW);
		return S_OK;
	}
#endif

	// Initialize pointer to in-place site, if necessary.
	if (m_pInPlaceSite == NULL)
	{
		if (m_pClientSite == NULL)
			return E_UNEXPECTED;

		if ((GetControlFlags() & windowlessActivate) &&
			SUCCEEDED(m_pClientSite->QueryInterface(IID_IOleInPlaceSiteWindowless,
			reinterpret_cast<void**>(&m_pInPlaceSiteWndless))))
		{
			m_bInPlaceSiteWndless = m_bInPlaceSiteEx = TRUE;
		}
		else if ((GetControlFlags() & noFlickerActivate) &&
			SUCCEEDED(m_pClientSite->QueryInterface(IID_IOleInPlaceSiteEx,
			reinterpret_cast<void**>(&m_pInPlaceSiteEx))))
		{
			m_bInPlaceSiteEx = TRUE;
		}
		else if (SUCCEEDED(m_pClientSite->QueryInterface(IID_IOleInPlaceSite,
			reinterpret_cast<void**>(&m_pInPlaceSite))))
		{
			m_bInPlaceSiteEx = FALSE;
		}
		else
		{
			m_pInPlaceSite = NULL;
			return E_FAIL;
		}
	}

	ASSERT(m_pInPlaceSite != NULL);

	if ((m_bInPlaceActive && !bUIActivate) || m_bUIActive)
	{
		CWnd* pWndOuter = GetOuterWindow();
		HWND hwndParent;
		if ((pWndOuter != NULL) &&
			SUCCEEDED(m_pInPlaceSite->GetWindow(&hwndParent)) &&
			(hwndParent == ::GetParent(pWndOuter->m_hWnd)))
		{
			::SetWindowPos(pWndOuter->m_hWnd, NULL, 0, 0, 0, 0,
				SWP_NOZORDER|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
				SWP_SHOWWINDOW);
			OnSetObjectRects(m_rcPos, NULL);
			return S_OK;
		}
	}

	// Check if container allows windowless activation.
	if (m_bInPlaceSiteWndless)
	{
		if (m_pInPlaceSiteWndless->CanWindowlessActivate() != S_OK)
			m_bInPlaceSiteWndless = FALSE;
	}

	HRESULT hr = E_FAIL;
	if (m_pInPlaceSite != NULL)
		hr = m_pInPlaceSite->CanInPlaceActivate();

	if (hr != NOERROR)
	{
		// Site doesn't allow in-place activation.
		return OnOpen(FALSE, pMsg);
	}

	if (!m_bInPlaceActive)
	{
		if (m_bInPlaceSiteEx)
		{
			// flicker-free and/or windowless activation
			BOOL bNoRedraw;
			m_pInPlaceSiteEx->OnInPlaceActivateEx(&bNoRedraw,
				m_bInPlaceSiteWndless ? ACTIVATE_WINDOWLESS : 0);
			if (GetControlFlags() & noFlickerActivate)
				m_bNoRedraw = bNoRedraw;
		}
		else
		{
			// old-style activation
			m_pInPlaceSite->OnInPlaceActivate();
		}
	}

	HWND hwndParent = NULL;

	if (SUCCEEDED(m_pInPlaceSite->GetWindow(&hwndParent)))
	{
		CRect rcClip;
		m_frameInfo.cb = sizeof(OLEINPLACEFRAMEINFO);

		RELEASE(m_pInPlaceFrame);
		RELEASE(m_pInPlaceDoc);

		if (SUCCEEDED(m_pInPlaceSite->GetWindowContext(
						&m_pInPlaceFrame, &m_pInPlaceDoc,
						&m_rcPos, &rcClip, &m_frameInfo)))
		{
			ASSERT(m_pInPlaceFrame != NULL);

			CRect rectClip;
			if (!m_bInPlaceSiteWndless)
			{
				_GetClippingCoordinates(&m_rcPos, &rcClip, rectClip,
					&m_ptOffset);
				m_bInPlaceActive = CreateControlWindow(hwndParent, m_rcPos,
					rectClip);
			}
			else
			{
				m_bInPlaceActive = TRUE;
			}

			if (m_bInPlaceActive)
			{
				if (bUIActivate)
				{
					if (m_bInPlaceSiteEx)
					{
						if (m_pInPlaceSiteEx->RequestUIActivate() != S_OK)
							m_pInPlaceSite->OnUIDeactivate(FALSE);
					}

					BuildSharedMenu();

					m_bUIActive = TRUE;
					m_pInPlaceSite->OnUIActivate();

					m_pInPlaceFrame->SetActiveObject(
						&m_xOleInPlaceActiveObject, NULL);
					if (m_pInPlaceDoc != NULL)
						m_pInPlaceDoc->SetActiveObject(
							&m_xOleInPlaceActiveObject, NULL);

					if (m_hWnd != NULL)
					{
						BOOL bHandles = AmbientShowGrabHandles();
						BOOL bHatching = AmbientShowHatching();

						if (bHandles || bHatching)
							CreateTracker(bHandles, bHatching, rcClip);
					}

					AddFrameLevelUI();

					if (bUIActivate != -1 &&
						(m_hWnd != NULL) && !IsChild(GetFocus()))
					{
						SetFocus();
					}
				}

				// Pass thru the window message that caused us to be activated
				if ((m_hWnd != NULL || m_bInPlaceSiteWndless) && (pMsg != NULL))
					ForwardActivationMsg(pMsg);

				// Send appropriate notifications...
				SendAdvise(OBJECTCODE_SHOWOBJECT);

				return S_OK;
			}
		}
	}

	RELEASE(m_pInPlaceFrame);
	RELEASE(m_pInPlaceDoc);

	return E_FAIL;
}