📄 bcgtoolbarcomboboxbutton.cpp
字号:
POSITION pos = m_lstItems.FindIndex (iIndex);
if (pos == NULL)
{
return NULL;
}
return m_lstItems.GetAt (pos);
}
//**************************************************************************************
DWORD CBCGToolbarComboBoxButton::GetItemData (int iIndex) const
{
if (iIndex == -1) // Current selection
{
if (m_pWndCombo->GetSafeHwnd () == NULL)
{
return 0;
}
iIndex = m_pWndCombo->GetCurSel ();
}
if (m_pWndCombo->GetSafeHwnd () != NULL)
{
return m_pWndCombo->GetItemData (iIndex);
}
else
{
POSITION pos = m_lstItemData.FindIndex (iIndex);
if (pos == NULL)
{
return 0;
}
return m_lstItemData.GetAt (pos);
}
}
//**************************************************************************************
void CBCGToolbarComboBoxButton::RemoveAllItems ()
{
m_lstItems.RemoveAll ();
m_lstItemData.RemoveAll ();
if (m_pWndCombo->GetSafeHwnd () != NULL)
{
m_pWndCombo->ResetContent ();
}
m_strEdit.Empty ();
}
//**************************************************************************************
int CBCGToolbarComboBoxButton::GetCount () const
{
return m_lstItems.GetCount ();
}
//**************************************************************************************
void CBCGToolbarComboBoxButton::AdjustRect ()
{
if (m_pWndCombo->GetSafeHwnd () == NULL ||
(m_pWndCombo->GetStyle () & WS_VISIBLE) == 0 ||
m_rect.IsRectEmpty ())
{
return;
}
m_pWndCombo->GetWindowRect (&m_rect);
m_pWndCombo->ScreenToClient (&m_rect);
m_pWndCombo->MapWindowPoints (m_pWndCombo->GetParent (), &m_rect);
m_rect.InflateRect (iHorzMargin, 0);
}
//**************************************************************************************
BOOL CBCGToolbarComboBoxButton::NotifyCommand (int iNotifyCode)
{
if (m_pWndCombo->GetSafeHwnd () == NULL)
{
return FALSE;
}
switch (iNotifyCode)
{
case CBN_SELENDOK:
{
m_iSelIndex = m_pWndCombo->GetCurSel ();
if (m_iSelIndex < 0)
{
return FALSE;
}
m_pWndCombo->GetLBText (m_iSelIndex, m_strEdit);
//------------------------------------------------------
// Try set selection in ALL comboboxes with the same ID:
//------------------------------------------------------
CObList listButtons;
if (CBCGToolBar::GetCommandButtons (m_nID, listButtons) > 0)
{
for (POSITION posCombo = listButtons.GetHeadPosition (); posCombo != NULL;)
{
CBCGToolbarComboBoxButton* pCombo =
DYNAMIC_DOWNCAST (CBCGToolbarComboBoxButton, listButtons.GetNext (posCombo));
ASSERT (pCombo != NULL);
if (pCombo != this)
{
pCombo->SelectItem (m_pWndCombo->GetCurSel ());
}
}
}
}
return TRUE;
//////// By Guy Hachlili:
case CBN_KILLFOCUS:
case CBN_EDITUPDATE:
return TRUE;
case CBN_EDITCHANGE:
{
m_pWndCombo->GetWindowText (m_strEdit);
//------------------------------------------------------
// Try set text of ALL comboboxes with the same ID:
//------------------------------------------------------
CObList listButtons;
if (CBCGToolBar::GetCommandButtons (m_nID, listButtons) > 0)
{
for (POSITION posCombo = listButtons.GetHeadPosition (); posCombo !=
NULL;)
{
CBCGToolbarComboBoxButton* pCombo =
DYNAMIC_DOWNCAST (CBCGToolbarComboBoxButton, listButtons.GetNext
(posCombo));
ASSERT (pCombo != NULL);
if (pCombo != this)
{
pCombo->GetComboBox()->SetWindowText(m_strEdit);
pCombo->m_strEdit = m_strEdit;
}
}
}
}
///////////////////////////////////
return TRUE;
}
return FALSE;
}
//**************************************************************************************
void CBCGToolbarComboBoxButton::OnAddToCustomizePage ()
{
CObList listButtons; // Existing buttons with the same command ID
if (CBCGToolBar::GetCommandButtons (m_nID, listButtons) == 0)
{
return;
}
CBCGToolbarComboBoxButton* pOther =
(CBCGToolbarComboBoxButton*) listButtons.GetHead ();
ASSERT_VALID (pOther);
ASSERT_KINDOF (CBCGToolbarComboBoxButton, pOther);
CopyFrom (*pOther);
}
//**************************************************************************************
HBRUSH CBCGToolbarComboBoxButton::OnCtlColor (CDC* pDC, UINT /*nCtlColor*/)
{
pDC->SetTextColor (::GetSysColor (COLOR_WINDOWTEXT));
pDC->SetBkColor (::GetSysColor (COLOR_WINDOW));
return ::GetSysColorBrush (COLOR_WINDOW);
}
//**************************************************************************************
void CBCGToolbarComboBoxButton::OnDraw (CDC* pDC, const CRect& rect, CBCGToolBarImages* pImages,
BOOL bHorz, BOOL bCustomizeMode,
BOOL bHighlight,
BOOL bDrawBorder, BOOL bGrayDisabledButtons)
{
if (m_pWndCombo->GetSafeHwnd () == NULL ||
(m_pWndCombo->GetStyle () & WS_VISIBLE) == 0)
{
CBCGToolbarButton::OnDraw (pDC, rect, pImages,
bHorz, bCustomizeMode,
bHighlight, bDrawBorder, bGrayDisabledButtons);
}
else if ((m_bTextBelow && bHorz) && !m_strText.IsEmpty())
{
//-----------------------------------
// Draw button's text - Guy Hachlili:
//-----------------------------------
BOOL bDisabled = (bCustomizeMode && !IsEditable ()) ||
(!bCustomizeMode && (m_nStyle & TBBS_DISABLED));
pDC->SetTextColor (bDisabled ?
globalData.clrGrayedText :
(bHighlight) ? CBCGToolBar::GetHotTextColor () :
globalData.clrBtnText);
CRect rectText;
rectText.left = (rect.left + rect.right - m_sizeText.cx) / 2;
rectText.right = (rect.left + rect.right + m_sizeText.cx) / 2;
rectText.top = rect.bottom + rect.top;
rectText.bottom = rectText.top + m_sizeText.cy;
pDC->DrawText (m_strText, &rectText, DT_CENTER | DT_WORDBREAK);
}
}
//**************************************************************************************
BOOL CBCGToolbarComboBoxButton::OnClick (CWnd* /*pWnd*/, BOOL /*bDelay*/)
{
return m_pWndCombo->GetSafeHwnd () != NULL &&
(m_pWndCombo->GetStyle () & WS_VISIBLE);
}
//**************************************************************************************
BOOL CBCGToolbarComboBoxButton::SelectItem (int iIndex)
{
if (iIndex < 0 || iIndex >= m_lstItems.GetCount ())
{
return FALSE;
}
m_iSelIndex = iIndex;
if (m_pWndCombo->GetSafeHwnd () == NULL)
{
return TRUE;
}
m_pWndCombo->GetLBText (iIndex, m_strEdit);
return m_pWndCombo->SetCurSel (iIndex) != CB_ERR;
}
//**************************************************************************************
BOOL CBCGToolbarComboBoxButton::SelectItem (DWORD dwData)
{
int iIndex = 0;
for (POSITION pos = m_lstItemData.GetHeadPosition (); pos != NULL; iIndex ++)
{
if (m_lstItemData.GetNext (pos) == dwData)
{
return SelectItem (iIndex);
}
}
return FALSE;
}
//**************************************************************************************
BOOL CBCGToolbarComboBoxButton::SelectItem (LPCTSTR lpszText)
{
ASSERT (lpszText != NULL);
int iIndex = 0;
for (POSITION pos = m_lstItems.GetHeadPosition (); pos != NULL; iIndex ++)
{
if (m_lstItems.GetNext (pos) == lpszText)
{
return SelectItem (iIndex);
}
}
return FALSE;
}
//******************************************************************************************
int CBCGToolbarComboBoxButton::OnDrawOnCustomizeList (
CDC* pDC, const CRect& rect, BOOL bSelected)
{
int iWidth = CBCGToolbarButton::OnDrawOnCustomizeList (pDC, rect, bSelected);
//------------------------------
// Simulate combobox appearance:
//------------------------------
CRect rectCombo = rect;
int iComboWidth = rect.Width () - iWidth;
if (iComboWidth < 20)
{
iComboWidth = 20;
}
rectCombo.left = rectCombo.right - iComboWidth;
rectCombo.DeflateRect (2, 3);
pDC->FillSolidRect (rectCombo, ::GetSysColor (COLOR_WINDOW));
pDC->Draw3dRect (&rectCombo,
globalData.clrBtnDkShadow,
globalData.clrBtnHilite);
rectCombo.DeflateRect (1, 1);
pDC->Draw3dRect (&rectCombo,
globalData.clrBtnShadow,
globalData.clrBtnLight);
CRect rectBtn = rectCombo;
rectBtn.left = rectBtn.right - rectBtn.Height ();
rectBtn.DeflateRect (1, 1);
pDC->FillSolidRect (rectBtn, globalData.clrBtnFace);
pDC->Draw3dRect (&rectBtn,
globalData.clrBtnHilite,
globalData.clrBtnDkShadow);
CPoint pointTriangle (
rectBtn.left + (rectBtn.Width () - CMenuImages::Size ().cx) / 2,
rectBtn.top + (rectBtn.Height () - CMenuImages::Size ().cy) / 2);
CMenuImages::Draw (pDC, CMenuImages::IdArowDown, pointTriangle);
return rect.Width ();
}
//********************************************************************************************
CComboBox* CBCGToolbarComboBoxButton::CreateCombo (CWnd* pWndParent, const CRect& rect)
{
CComboBox* pWndCombo = new CComboBox;
if (!pWndCombo->Create (m_dwStyle, rect, pWndParent, m_nID))
{
delete pWndCombo;
return NULL;
}
return pWndCombo;
}
//****************************************************************************************
void CBCGToolbarComboBoxButton::OnShow (BOOL bShow)
{
if (m_pWndCombo->GetSafeHwnd () != NULL)
{
if (bShow)
{
m_pWndCombo->ShowWindow (SW_SHOWNOACTIVATE);
OnMove ();
}
else
{
m_pWndCombo->ShowWindow (SW_HIDE);
}
}
}
//****************************************************************************************
const CRect CBCGToolbarComboBoxButton::GetInvalidateRect () const
{
//-----------------
// By Guy Hachlili:
//-----------------
if ((m_bTextBelow && m_bHorz) && !m_strText.IsEmpty())
{
CRect rect;
rect.left = (m_rect.left + m_rect.right - m_sizeText.cx) / 2;
rect.right = (m_rect.left + m_rect.right + m_sizeText.cx) / 2;
rect.top = m_rect.top;
rect.bottom = m_rect.bottom + m_rect.top + m_sizeText.cy;
return rect;
}
else
{
return m_rect;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -