Exemplo n.º 1
0
void CaImMenu::MeasureItem (LPMEASUREITEMSTRUCT lpMeasureItemStruct) {
	MENUITEMINFO iInfo;
	GetMenuItemInfo (lpMeasureItemStruct->CtlID, &iInfo);
	CaImMenuItem* pItem = (CaImMenuItem*)lpMeasureItemStruct->itemData;

	CFont fntDef;
	LOGFONT lfDef;
	CClientDC dc (0);
	CFont* pFont = (CFont *)dc.SelectStockObject (ANSI_VAR_FONT);
	if (pItem->CheckStyle (AMIS_DEFAULT)) {
		CFont* pFnt = dc.GetCurrentFont ();
		pFnt->GetLogFont (&lfDef);
		lfDef.lfWeight = FW_BOLD;
		fntDef.CreateFontIndirect (&lfDef);
		dc.SelectObject (&fntDef);
	}

	if (pItem->CheckStyle (AMIS_BAR))
		lpMeasureItemStruct->itemHeight = 4;
	else
		lpMeasureItemStruct->itemHeight = m_dwHeight;
	lpMeasureItemStruct->itemWidth = 25 + 8 + 8 + 2 + dc.GetTextExtent (pItem->GetText ()).cx;

	dc.SelectObject (pFont);
	if (pItem->CheckStyle (AMIS_DEFAULT))
		fntDef.DeleteObject ();
}
//******************************************************************************
void CBCGPRibbonCommandsListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
	ASSERT (lpMIS != NULL);

	CClientDC dc (this);
	CFont* pOldFont = (CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT);
	ASSERT_VALID (pOldFont);

	TEXTMETRIC tm;
	dc.GetTextMetrics (&tm);

	lpMIS->itemHeight = tm.tmHeight + 6;

	dc.SelectObject (pOldFont);
}
//************************************************************************************************
void CBCGPDateTimeCtrl::AdjustControl (CRect rectClient)
{
	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	CClientDC dc (this);

	CFont* pPrevFont = m_hFont == NULL ?
		(CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) :
		dc.SelectObject (CFont::FromHandle (m_hFont));

	if (m_WidestDate == COleDateTime ())
	{
		BuidWidestDate (&dc);
	}

	SetPartsOrder ();
	
	m_iPartNum = m_bCheckBoxIsAvailable ? 1 : 0;
	m_CurrPartType = m_arPartsOrder [m_iPartNum];

	m_rectText = rectClient;
	m_rectText.InflateRect (0, -2);

	if (m_bAutoResize)
	{
		// Calculate text size:
		TEXTMETRIC tm;

		dc.GetTextMetrics (&tm);

		m_iControlHeight = tm.tmHeight + 6;
	}
	else
	{
		m_iControlHeight = rectClient.Height ();
	}

	if (m_bCheckBoxIsAvailable)
	{
		m_rectCheck = CRect (rectClient.left + 1, rectClient.top + 1, 
			rectClient.left + m_iControlHeight - 1, rectClient.bottom - 1);
		m_rectText.left = m_rectCheck.right + 2;
	}
	
	m_rectText.top = rectClient.top;
	m_rectText.bottom = rectClient.top + m_iControlHeight;

	// Calculate parts:
	CalcPartRects (&dc);

	// Adjust control size:
	m_rectText.right = m_arPartRects [m_iPartsNumber - 1].right + 2;
	m_iControlWidth = m_rectText.right;

	if (m_spinButton)
	{
		m_iControlWidth += iSpinWidth;
	}

	if (!m_bAutoResize)
	{
		m_iControlWidth = rectClient.Width ();
		m_iControlHeight = rectClient.Height ();
	}

	if (m_dropCalendar && m_showDate)
	{
		if (m_bAutoResize)
		{
			m_iControlWidth += iDropButtonWidth;
		}

		int iDropStart = rectClient.left + m_iControlWidth - iDropButtonWidth - 1;
		if (m_spinButton)
		{
			iDropStart -= iSpinWidth + 1;
		}

		m_rectDropButton = CRect (	iDropStart,
									rectClient.top,
									iDropStart + iDropButtonWidth,
									rectClient.top + m_iControlHeight - 2);
	}

	if (m_bAutoResize)
	{
		SetWindowPos (NULL, -1, -1, m_iControlWidth + 2, m_iControlHeight + 2,
			SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
	}

	// Adjust spin button:
	if (m_spinButton)
	{
		if (m_wndSpin.GetSafeHwnd () == NULL)
		{
			m_wndSpin.Create (WS_CHILD | WS_VISIBLE | UDS_ALIGNRIGHT | UDS_AUTOBUDDY,
						CRect (0, 0, 0, 0), this, iSpinID);
		}

		m_wndSpin.SetWindowPos (NULL, 
				rectClient.left + m_iControlWidth - iSpinWidth - 2, rectClient.top,
				iSpinWidth, m_iControlHeight - 2,
				SWP_NOZORDER);
		m_wndSpin.ShowWindow (SW_SHOW);

		m_wndSpin.EnableWindow (IsWindowEnabled () && m_bIsChecked);
	}
	else if (m_wndSpin.GetSafeHwnd () != NULL)
	{
		m_wndSpin.SetWindowPos (NULL, 
				0, 0,
				0, 0,
				SWP_NOZORDER);
		m_wndSpin.ShowWindow (SW_HIDE);
	}

	if (pPrevFont != NULL)
	{
		dc.SelectObject (pPrevFont);
	}

	//-----------------------------
	// Adjust min./max date values:
	//-----------------------------
	COleDateTime minAllowedDate (iFirstAllowedYear, 1, 1, 0, 0, 0);
	COleDateTime maxAllowedDate (iLastAllowedYear, 12, 31, 23, 59, 59);
	COleDateTime emptyDate;

	m_MinDate = max (m_MinDate, minAllowedDate);

	if (m_MaxDate != emptyDate)
	{
		m_MaxDate = min (m_MaxDate, maxAllowedDate);
	}

	else
	{
		m_MaxDate = maxAllowedDate;
	}
}
//*******************************************************************************************
void CLoginBarToolTipCtrl::Track (CRect rect, const CString& strText)
{
	if (GetSafeHwnd () == NULL)
	{
		return;
	}

	if (m_rectLast == rect && m_strText == strText)
	{
		return;
	}

	ASSERT_VALID (m_pWndParent);

	m_rectLast = rect;
	m_strText = strText;

	CClientDC dc (this);

    //ASSERT_VALID(m_pFont);
	CFont* pPrevFont = m_pFont == NULL ?
		(CFont*) dc.SelectStockObject (DEFAULT_GUI_FONT) :
		dc.SelectObject (&theApp.m_font);
	ASSERT (pPrevFont != NULL);

	int nTextHeight = rect.Height () ;
	int nTextWidth = rect.Width ();
	if (m_strText.FindOneOf (_T("\n")) != -1)	// multi-line tooltip
	{
		const int nDefaultHeight = globalData.GetTextHeight () ;
		const int nDefaultWidth = 200;
		CRect rectText (0, 0, nDefaultWidth, nDefaultHeight);
 
		nTextHeight = dc.DrawText (m_strText, rectText, DT_LEFT | /*DT_WORDBREAK | */DT_CALCRECT | DT_NOPREFIX);
		nTextWidth = rectText.Width ();
		nTextHeight += 2 * m_nTextMargin ;
		nTextWidth += 2 * m_nTextMargin;
		nTextHeight += (GetLineCount(m_strText) - 1) * m_nTextMargin; //加上行间距
	}
	else
	{
		nTextWidth = dc.GetTextExtent (m_strText).cx + 2 * m_nTextMargin;
	}

	dc.SelectObject (pPrevFont);

	if (m_pWndParent->GetExStyle () & WS_EX_LAYOUTRTL)
	{
		rect.left = rect.right - nTextWidth;
	}
	else
	{
		rect.right = rect.left + nTextWidth;
	}
	rect.bottom = rect.top + nTextHeight;
	if (rect.Height () < m_rectLast.Height ())
	{
		rect.top = m_rectLast.top;
		rect.bottom = m_rectLast.bottom;
	}

	MONITORINFO mi;
	mi.cbSize = sizeof (MONITORINFO);

	CRect rectScreen;

	if (GetMonitorInfo (MonitorFromPoint (rect.TopLeft (), MONITOR_DEFAULTTONEAREST), &mi))
	{
		rectScreen = mi.rcWork;
	}
	else
	{
		::SystemParametersInfo (SPI_GETWORKAREA, 0, &rectScreen, 0);
	}

	if (rect.Width () > rectScreen.Width ())
	{
		rect.left = rectScreen.left;
		rect.right = rectScreen.right;
	}
	else if (rect.right > rectScreen.right)
	{
		rect.OffsetRect( rectScreen.right - rect.right, 0 );
		//rect.right = rectScreen.right;
		//rect.left = rect.right - nTextWidth;
	}
	else if (rect.left < rectScreen.left)
	{
		rect.OffsetRect( rectScreen.left - rect.left, 0 );
		//rect.left = rectScreen.left;
		//rect.right = rect.left + nTextWidth;
	}

	if (rect.Height () > rectScreen.Height ())
	{
		rect.top = rectScreen.top;
		rect.bottom = rectScreen.bottom;
	}
	else if (rect.bottom > rectScreen.bottom)
	{
		rect.OffsetRect(0,  rectScreen.bottom - rect.bottom);
		//rect.bottom = rectScreen.bottom;
		//rect.top = rect.bottom - nTextHeight;
	}
	else if (rect.top < rectScreen.top)
	{
		rect.OffsetRect(0, rectScreen.top - rect.top);
		//rect.top = rectScreen.top;
		//rect.bottom = rect.bottom + nTextHeight;
	}

	rect.bottom += 3;

	SetWindowPos (&wndTop, rect.left, rect.top, 
		rect.Width (), rect.Height (), SWP_NOACTIVATE | SWP_NOOWNERZORDER);
  
    ShowWindow (SW_SHOWNOACTIVATE);
	Invalidate ();
	UpdateWindow ();

	SetCursor (AfxGetApp ()->LoadStandardCursor (IDC_ARROW));
}