📄 bcgpproplist.cpp
字号:
GetHeaderCtrl ().ShowWindow (SW_HIDE);
}
::SelectObject (dc.GetSafeHdc (), hfontOld);
m_rectList = rectClient;
m_rectList.top += m_nHeaderHeight;
if (m_bDescriptionArea && m_nDescrHeight != -1)
{
m_nDescrHeight = max (m_nDescrHeight, m_nRowHeight);
m_nDescrHeight = min (m_nDescrHeight, rectClient.Height () - m_nRowHeight);
m_rectList.bottom -= m_nDescrHeight;
}
int cxScroll = ::GetSystemMetrics (SM_CXHSCROLL);
SetScrollSizes ();
if (m_nVertScrollTotal > 0)
{
m_rectList.right -= cxScroll;
m_wndScrollVert.SetWindowPos (NULL, m_rectList.right, m_rectList.top,
cxScroll, m_rectList.Height (), SWP_NOZORDER | SWP_NOACTIVATE);
}
else
{
m_wndScrollVert.SetWindowPos (NULL, 0, 0,
0, 0, SWP_NOZORDER | SWP_NOACTIVATE);
}
ReposProperties ();
if (m_pSel != NULL && m_pSel->HasButton ())
{
ASSERT_VALID (m_pSel);
m_pSel->m_rectButton = m_pSel->m_Rect;
m_pSel->m_rectButton.top++;
m_pSel->m_rectButton.left = m_pSel->m_rectButton.right - m_pSel->m_rectButton.Height () + 2;
}
RedrawWindow ();
}
//******************************************************************************************
void CBCGPPropList::ReposProperties ()
{
ASSERT_VALID (this);
m_lstTerminalProps.RemoveAll ();
if (m_ToolTip.GetSafeHwnd () != NULL)
{
while (m_nTooltipsCount > 0)
{
m_ToolTip.DelTool (this, m_nTooltipsCount);
m_nTooltipsCount--;
}
}
int y = m_rectList.top - m_nRowHeight * m_nVertScrollOffset - 1;
if (!m_bAlphabeticMode)
{
for (POSITION pos = m_lstProps.GetHeadPosition (); pos != NULL;)
{
CBCGPProp* pProp = m_lstProps.GetNext (pos);
ASSERT_VALID (pProp);
pProp->Repos (y);
}
return;
}
// Get sorted list of terminal properties:
for (POSITION pos = m_lstProps.GetHeadPosition (); pos != NULL;)
{
CBCGPProp* pProp = m_lstProps.GetNext (pos);
ASSERT_VALID (pProp);
pProp->AddTerminalProp (m_lstTerminalProps);
}
for (pos = m_lstTerminalProps.GetHeadPosition (); pos != NULL;)
{
CBCGPProp* pProp = m_lstTerminalProps.GetNext (pos);
ASSERT_VALID (pProp);
pProp->Repos (y);
}
}
//******************************************************************************************
void CBCGPPropList::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
EndEditItem (FALSE);
m_nLeftColumnWidth = cx / 2;
AdjustLayout ();
}
//******************************************************************************************
LRESULT CBCGPPropList::OnSetFont (WPARAM wParam, LPARAM /*lParam*/)
{
m_hFont = (HFONT) wParam;
CreateBoldFont ();
AdjustLayout ();
return 0;
}
//******************************************************************************************
LRESULT CBCGPPropList::OnGetFont (WPARAM, LPARAM)
{
return (LRESULT) (m_hFont != NULL ? m_hFont : ::GetStockObject (DEFAULT_GUI_FONT));
}
//******************************************************************************************
void CBCGPPropList::CreateBoldFont ()
{
if (m_fontBold.GetSafeHandle () != NULL)
{
m_fontBold.DeleteObject ();
}
CFont* pFont = CFont::FromHandle (
m_hFont != NULL ? m_hFont : (HFONT) ::GetStockObject (DEFAULT_GUI_FONT));
ASSERT_VALID (pFont);
LOGFONT lf;
memset (&lf, 0, sizeof (LOGFONT));
pFont->GetLogFont (&lf);
lf.lfWeight = FW_BOLD;
m_fontBold.CreateFontIndirect (&lf);
}
//******************************************************************************************
void CBCGPPropList::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
{
CWnd::OnSettingChange(uFlags, lpszSection);
AdjustLayout ();
}
//******************************************************************************************
HFONT CBCGPPropList::SetFont (CDC* pDC)
{
ASSERT_VALID (pDC);
return (HFONT) ::SelectObject (pDC->GetSafeHdc (),
m_hFont != NULL ? m_hFont : ::GetStockObject (DEFAULT_GUI_FONT));
}
//******************************************************************************************
void CBCGPPropList::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (globalData.m_nBitsPerPixel <= 8)
{
m_clrGray = m_bControlBarColors ?
globalData.clrBarShadow : globalData.clrBtnShadow;
}
else
{
m_clrGray = CBCGPDrawManager::PixelAlpha (
m_bControlBarColors ? globalData.clrBarFace : globalData.clrBtnFace, 94);
}
CRect rectClip;
dc.GetClipBox (rectClip);
CRect rectClient;
GetClientRect (rectClient);
CDC* pDC = &dc;
BOOL bMemDC = FALSE;
CDC dcMem;
CBitmap bmp;
CBitmap* pOldBmp = NULL;
if (dcMem.CreateCompatibleDC (&dc) &&
bmp.CreateCompatibleBitmap (&dc, rectClient.Width (),
rectClient.Height ()))
{
//-------------------------------------------------------------
// Off-screen DC successfully created. Better paint to it then!
//-------------------------------------------------------------
bMemDC = TRUE;
pOldBmp = dcMem.SelectObject (&bmp);
pDC = &dcMem;
}
pDC->FillRect (rectClient, &globalData.brWindow);
HFONT hfontOld = SetFont (pDC);
pDC->SetTextColor (globalData.clrWindowText);
pDC->SetBkMode (TRANSPARENT);
OnDrawList (pDC);
if (m_bDescriptionArea)
{
CRect rectDescr = rectClient;
rectDescr.top = m_rectList.bottom;
rectDescr.DeflateRect (1, 1);
OnDrawDescription (pDC, rectDescr);
}
::SelectObject (pDC->GetSafeHdc (), hfontOld);
if (bMemDC)
{
//--------------------------------------
// Copy the results to the on-screen DC:
//--------------------------------------
dc.BitBlt (rectClip.left, rectClip.top, rectClip.Width(), rectClip.Height(),
&dcMem, rectClip.left, rectClip.top, SRCCOPY);
dcMem.SelectObject(pOldBmp);
}
}
//******************************************************************************************
void CBCGPPropList::OnDrawBorder (CDC* /*pDC*/)
{
ASSERT (FALSE); // This method is obsolete
}
//******************************************************************************************
void CBCGPPropList::OnDrawList (CDC* pDC)
{
ASSERT_VALID (this);
ASSERT_VALID (pDC);
COLORREF clrShadow = m_bControlBarColors ?
globalData.clrBarShadow : globalData.clrBtnShadow;
CPen penLine (PS_SOLID, 1, m_bVSDotNetLook ?
m_clrGray : clrShadow);
CPen* pOldPen = pDC->SelectObject (&penLine);
int nXCenter = m_rectList.left + m_nLeftColumnWidth;
pDC->MoveTo (nXCenter, m_rectList.top - 1);
pDC->LineTo (nXCenter, m_rectList.bottom);
const CList<CBCGPProp*, CBCGPProp*>& lst = m_bAlphabeticMode ?
m_lstTerminalProps : m_lstProps;
for (POSITION pos = lst.GetHeadPosition (); pos != NULL;)
{
CBCGPProp* pProp = lst.GetNext (pos);
ASSERT_VALID (pProp);
if (!OnDrawProperty (pDC, pProp))
{
break;
}
}
pDC->SelectObject (pOldPen);
}
//****************************************************************************************
void CBCGPPropList::OnDrawDescription (CDC* pDC, CRect rect)
{
ASSERT_VALID (this);
ASSERT_VALID (pDC);
pDC->FillRect (rect,
m_bControlBarColors ? &globalData.brBarFace : &globalData.brBtnFace);
rect.top += TEXT_MARGIN;
COLORREF clrShadow = m_bControlBarColors ?
globalData.clrBarShadow : globalData.clrBtnShadow;
pDC->Draw3dRect (rect, clrShadow, clrShadow);
if (m_pSel == NULL)
{
return;
}
rect.DeflateRect (TEXT_MARGIN, TEXT_MARGIN);
ASSERT_VALID (m_pSel);
HFONT hOldFont = hOldFont = (HFONT) ::SelectObject (pDC->GetSafeHdc (), m_fontBold.GetSafeHandle ());
int nHeight = pDC->DrawText (m_pSel->m_strName, rect, DT_SINGLELINE | DT_NOPREFIX);
::SelectObject (pDC->GetSafeHdc (), hOldFont);
rect.top += nHeight + 2;
pDC->DrawText (m_pSel->m_strDescr, rect, DT_WORDBREAK | DT_NOPREFIX | DT_END_ELLIPSIS);
}
//******************************************************************************************
BOOL CBCGPPropList::OnDrawProperty (CDC* pDC, CBCGPProp* pProp) const
{
ASSERT_VALID (this);
ASSERT_VALID (pDC);
ASSERT_VALID (pProp);
if (!pProp->m_Rect.IsRectEmpty ())
{
if (pProp->m_Rect.top >= m_rectList.bottom)
{
return FALSE;
}
if (pProp->m_Rect.bottom >= m_rectList.top)
{
const int nXCenter = m_rectList.left + m_nLeftColumnWidth;
COLORREF clrTextOld = (COLORREF)-1;
if (m_bVSDotNetLook)
{
CRect rectLeft = pProp->m_Rect;
if (!pProp->IsGroup ())
{
rectLeft.right = rectLeft.left;
}
rectLeft.left = m_rectList.left;
rectLeft.bottom = min (rectLeft.bottom, m_rectList.bottom);
if (rectLeft.left < rectLeft.right)
{
CBrush br (m_clrGray);
pDC->FillRect (rectLeft, &br);
}
}
if (!pProp->IsEnabled ())
{
clrTextOld = pDC->SetTextColor (globalData.clrGrayedText);
}
CRect rectName = pProp->m_Rect;
if (!pProp->IsGroup () || !m_bGroupNameFullWidth)
{
if (!pProp->IsGroup () && pProp->HasValueField ())
{
rectName.right = nXCenter;
}
}
if (pProp->IsGroup ())
{
if (m_bGroupNameFullWidth && !m_bVSDotNetLook)
{
CRect rectFill = rectName;
rectFill.top++;
pDC->FillRect (rectFill, &globalData.brWindow);
}
CRect rectExpand = rectName;
rectName.left += m_nRowHeight;
rectExpand.right = rectName.left;
CRgn rgnClipExpand;
CRect rectExpandClip = rectExpand;
rectExpandClip.bottom = min (rectExpandClip.bottom, m_rectList.bottom);
rgnClipExpand.CreateRectRgnIndirect (&rectExpandClip);
pDC->SelectClipRgn (&rgnClipExpand);
pProp->OnDrawExpandBox (pDC, rectExpand);
}
else if (!pProp->HasValueField ())
{
CRect rectFill = rectName;
rectFill.top++;
pDC->FillRect (rectFill, &globalData.brWindow);
}
if (rectName.right > rectName.left)
{
CRgn rgnClipName;
CRect rectNameClip = rectName;
rectNameClip.bottom = min (rectNameClip.bottom, m_rectList.bottom);
rgnClipName.CreateRectRgnIndirect (&rectNameClip);
pDC->SelectClipRgn (&rgnClipName);
HFONT hOldFont = NULL;
if (pProp->IsGroup ())
{
hOldFont = (HFONT) ::SelectObject (pDC->GetSafeHdc (), m_fontBold.GetSafeHandle ());
}
pProp->OnDrawName (pDC, rectName);
if (hOldFont != NULL)
{
::SelectObject (pDC->GetSafeHdc (), hOldFont);
}
}
CRect rectValue = pProp->m_Rect;
rectValue.left = nXCenter + 1;
CRgn rgnClipVal;
CRect rectValClip = rectValue;
rectValClip.bottom = min (rectValClip.bottom, m_rectList.bottom);
rgnClipVal.CreateRectRgnIndirect (&rectValClip);
pDC->SelectClipRgn (&rgnClipVal);
pProp->OnDrawValue (pDC, rectValue);
if (!pProp->m_rectButton.IsRectEmpty ())
{
pProp->OnDrawButton (pDC, pProp->m_rectButton);
}
pDC->SelectClipRgn (NULL);
pDC->MoveTo (m_rectList.left, pProp->m_Rect.bottom);
pDC->LineTo (m_rectList.right, pProp->m_Rect.bottom);
if (clrTextOld != (COLORREF)-1)
{
pDC->SetTextColor (clrTextOld);
}
}
}
if (pProp->IsExpanded () || m_bAlphabeticMode)
{
for (POSITION pos = pProp->m_lstSubItems.GetHeadPosition (); pos != NULL;)
{
if (!OnDrawProperty (pDC, pProp->m_lstSubItems.GetNext (pos)))
{
return FALSE;
}
}
}
return TRUE;
}
//****************************************************************************************
void CBCGPPropList::OnPropertyChanged (CBCGPProp* pProp) const
{
ASSERT_VALID (this);
ASSERT_VALID (pProp);
GetOwner ()->SendMessage (BCGM_PROPERTY_CHANGED, GetDlgCtrlID (),
LPARAM (pProp));
}
//*******************************************************************************************
BOOL CBCGPPropList::OnEraseBkgnd(CDC* /*pDC*/)
{
return TRUE;
}
//******************************************************************************************
void CBCGPPropList::OnHeaderItemChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NMHEADER* pHeader = (NMHEADER*) pNMHDR;
if (pHeader->iItem == 0)
{
HDITEM hdItem;
hdItem.mask = HDI_WIDTH;
GetHeaderCtrl ().GetItem (0, &hdItem);
m_nLeftColumnWidth = hdItem.cxy - 2;
ReposProperties ();
InvalidateRect (m_rectList);
UpdateWindow ();
}
*pResult = 0;
}
//******************************************************************************************
void CBCGPPropList::EnableHeaderCtrl (BOOL bEnable, LPCTSTR lpszLeftColumn,
LPCTSTR lpszRightColumn)
{
ASSERT_VALID (this);
ASSERT (lpszLeftColumn != NULL);
ASSERT (lpszRightColumn != NULL);
CBCGPProp* pProp = GetCurSel ();
if (pProp != NULL)
{
pProp->OnEndEdit ();
}
m_bHeaderCtrl = bEnable;
if (m_bHeaderCtrl)
{
HDITEM hdItem;
hdItem.mask = HDI_TEXT;
hdItem.pszText = (LPTSTR) lpszLeftColumn;
hdItem.cchTextMax = lstrlen (lpszLeftColumn) + 1;
GetHeaderCtrl ().SetItem (0, &hdItem);
hdItem.pszText = (LPTSTR) lpszRightColumn;
hdItem.cchTextMax = lstrlen (lpszRightColumn) + 1;
GetHeaderCtrl ().SetItem (1, &hdItem);
}
AdjustLayout ();
RedrawWindow ();
}
//******************************************************************************************
void CBCGPPropList::EnableDescriptionArea (BOOL bEnable)
{
ASSERT_VALID (this);
m_bDescriptionArea = bEnable;
AdjustLayout ();
if (GetSafeHwnd () != NULL)
{
RedrawWindow ();
}
}
//*****************************************************************************************
void CBCGPPropList::OnHeaderTrack(NMHDR* pNMHDR, LRESULT* pResult)
{
NMHEADER* pHeader = (NMHEADER*) pNMHDR;
pHeader->pitem->cxy = min (pHeader->pitem->cxy, m_rectList.Width ());
TrackHeader (pHeader->pitem->cxy);
*pResult = 0;
}
//******************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -