DWORD_PTR CUIComboBox::GetItemData(int nItem) { if( m_items.GetSize() == 0 ) { return NULL; } if( nItem < 0 || nItem >= (int)m_items.GetSize()) { return NULL; } CUIControl* pControl = static_cast<CUIControl*>(m_items[nItem]); if (pControl == NULL) { return NULL; } IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem"))); if( pListItem == NULL ) { return NULL; } return pListItem->GetItemData(); }
bool CUIComboBox::SetCurSel(int iIndex) { if( iIndex == m_iCurSel ) return true; if( m_iCurSel >= 0 ) { CUIControl* pControl = static_cast<CUIControl*>(m_items[m_iCurSel]); IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem"))); if( pListItem != NULL ) pListItem->Select(false); m_iCurSel = -1; } if( m_items.GetSize() == 0 ) return false; if( iIndex < 0 ) iIndex = 0; if( iIndex >= m_items.GetSize() ) iIndex = m_items.GetSize() - 1; CUIControl* pControl = static_cast<CUIControl*>(m_items[iIndex]); if( !pControl->IsVisible() ) return false; if( !pControl->IsEnabled() ) return false; IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem"))); if( pListItem == NULL ) return false; m_iCurSel = iIndex; pControl->SetFocus(); pListItem->Select(true); CUIContainer* pContainer = dynamic_cast<CUIContainer*>(pListItem->GetOwner()); if (pContainer) { RECT rcItem = pControl->GetPos(); RECT rcList = pContainer->GetPos(); int iPos = pContainer->GetScrollPos(); if( rcItem.top < rcList.top || rcItem.bottom > rcList.bottom ) { int dx = 0; if( rcItem.top < rcList.top ) dx = rcItem.top - rcList.top; if( rcItem.bottom > rcList.bottom ) dx = rcItem.bottom - rcList.bottom; pContainer->SetScrollPos(pContainer->GetScrollPos() + dx); } } Invalidate(); return true; }
bool CUIComboBox::SetItemData(int nItem, DWORD_PTR dwData) { if( nItem < 0 || nItem >= (int)m_items.GetSize()) { return false; } CUIControl* pControl = static_cast<CUIControl*>(m_items[nItem]); if (pControl == NULL) { return false; } IListItemUI* pListItem = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem"))); if( pListItem == NULL ) { return false; } return pListItem->SetItemData(dwData); }
void CUIComboBox::DoPaint(HDC hDC, const RECT& rcPaint) { // Paint the nice frame int cy = m_rcItem.bottom - m_rcItem.top; ::SetRect(&m_rcButton, m_rcItem.right - cy, m_rcItem.top, m_rcItem.right, m_rcItem.bottom); RECT rcText = { m_rcItem.left + 5, m_rcItem.top, m_rcButton.left + 1, m_rcItem.bottom }; UINT uState = m_uButtonState; if( IsFocused() ) uState |= UISTATE_FOCUSED; if( !IsEnabled() ) uState |= UISTATE_DISABLED; RECT rcPadding = { 0 }; // Paint dropdown button if (m_pImageOwner != NULL) { RECT rcImage = {0}; int nWidth = m_pImageOwner->GetWidth() / 4; int nHeight = m_pImageOwner->GetHeight(); // Draw frame and body if( (uState & UISTATE_DISABLED) != 0 ) { RECT rcTemp = {nWidth *3, 0, nWidth * 4, nHeight}; rcImage = rcTemp; } else if( (uState & UISTATE_PUSHED) != 0 ) { RECT rcTemp ={nWidth *2, 0, nWidth * 3, nHeight}; rcImage = rcTemp; } else if( (uState & UISTATE_HOT) != 0 ) { RECT rcTemp ={nWidth *1, 0, nWidth * 2, nHeight}; rcImage = rcTemp; } else { RECT rcTemp ={nWidth *0, 0, nWidth * 1, nHeight}; rcImage = rcTemp; } CUIBlueRenderEngine::DoFillRect(hDC, m_pManager, m_rcItem, rcImage, m_pImageOwner); } else { CUIBlueRenderEngine::DoPaintButton(hDC, m_pManager, m_rcItem, uState, NULL, 0); } if (m_sText.GetLength() > 0) { UITYPE_COLOR clrText; if( (m_uButtonState & UISTATE_DISABLED) != 0 ) { clrText = UICOLOR_BUTTON_TEXT_DISABLED; } else if( (m_uButtonState & UISTATE_PUSHED) != 0 ) { clrText = UICOLOR_BUTTON_TEXT_PUSHED; } else { clrText = UICOLOR_BUTTON_TEXT_NORMAL; } RECT rcText = m_rcItem; ::InflateRect(&rcText, -1, -1); rcText.left += rcPadding.left; rcText.top += rcPadding.top; rcText.right -= rcPadding.right; rcText.bottom -= rcPadding.bottom; int nLinks = 0; CUIBlueRenderEngine::DoPaintPrettyText(hDC, m_pManager, rcText, m_sText, clrText, UICOLOR__INVALID, NULL, nLinks, 0); } // Paint dropdown edit box ::InflateRect(&rcText, -1, -1); if( m_iCurSel >= 0 ) { CUIControl* pControl = static_cast<CUIControl*>(m_items[m_iCurSel]); IListItemUI* pElement = static_cast<IListItemUI*>(pControl->GetInterface(_T("ListItem"))); if( pElement != NULL ) { // Render item with specific draw-style int nLinks = 0; CUIBlueRenderEngine::DoPaintPrettyText(hDC, m_pManager, rcText, pControl->GetText(), UICOLOR_CONTROL_TEXT_NORMAL, UICOLOR__INVALID, NULL, nLinks, DT_SINGLELINE | DT_VCENTER); } else { //// Allow non-listitems to render as well. RECT rcOldPos = pControl->GetPos(); pControl->SetPos(rcText); pControl->DoPaint(hDC, rcText); pControl->SetPos(rcOldPos); } } }