8#include <control/SListbox.h> 
   10#pragma warning(disable : 4018) 
   11#pragma warning(disable : 4267) 
   33    m_evtSet.addEvent(EVENTID(EventLBSelChanging));
 
   34    m_evtSet.addEvent(EVENTID(EventLBSelChanged));
 
   35    m_evtSet.addEvent(EVENTID(EventLBDbClick));
 
 
   67        if (nOldSelItem != -1)
 
 
   86    if (nIndex < 0 || nIndex >= 
GetCount())
 
 
   95    if (nIndex < 0 || nIndex >= 
GetCount())
 
 
  103    if (nIndex < 0 || nIndex >= 
GetCount())
 
 
  112    if (nIndex < 0 || nIndex >= 
GetCount())
 
 
  121    if (nIndex < 0 || nIndex >= 
GetCount())
 
 
  129    if (nIndex < 0 || nIndex >= 
GetCount())
 
  132    SStringT strRet = 
m_arrItems[nIndex]->strText.GetText(bRawText);
 
 
  150    for (
int i = 0; i < 
GetCount(); i++)
 
 
  166    if (nIndex < 0 || nIndex >= 
GetCount())
 
 
  196    LPLBITEM pItem = 
new LBITEM(
this);
 
 
  206    if (nIndex < 0 || nIndex >= 
GetCount())
 
  213    int iFirstVisible = (m_siVer.nPos + nItemHei - 1) / nItemHei;
 
  214    int nVisibleItems = rcClient.Height() / nItemHei;
 
  215    if (nIndex < iFirstVisible || nIndex > iFirstVisible + nVisibleItems - 1)
 
  217        int nOffset = GetScrollPos(TRUE);
 
  218        if (nIndex < iFirstVisible)
 
  219            nOffset = (nIndex - iFirstVisible) * nItemHei;
 
  221            nOffset = (nIndex - iFirstVisible - nVisibleItems + 1) * nItemHei;
 
  222        nOffset -= nOffset % nItemHei; 
 
  223        OnScroll(TRUE, SB_THUMBPOSITION, nOffset + GetScrollPos(TRUE));
 
 
  232    if (!rcClient.PtInRect(pt))
 
  236    pt2.y -= rcClient.top - m_siVer.nPos;
 
  238    int nRet = pt2.y / nItemHei;
 
  243        pt.x -= rcClient.left;
 
  244        pt.y = pt2.y % nItemHei;
 
 
  254    int iStart = iFindAfter + 1;
 
  255    for (
int i = 0; i < 
m_arrItems.GetCount(); i++)
 
  257        int iTarget = (i + iStart) % 
m_arrItems.GetCount();
 
  258        if (
m_arrItems[iTarget]->strText.GetText(TRUE).StartsWith(pszText))
 
 
  275            LPLBITEM pItemObj = 
new LBITEM(
this);
 
 
  302    if (nIndex == -1 || nIndex > 
GetCount())
 
 
  328    int nPageItems = (rcClient.Height() + nItemHei - 1) / nItemHei + 1;
 
  330    if (iItem >= iFirstVisible && iItem < 
GetCount() && iItem < iFirstVisible + nPageItems)
 
  332        CRect rcItem(0, 0, rcClient.Width(), nItemHei);
 
  333        rcItem.OffsetRect(0, nItemHei * iItem - m_siVer.nPos);
 
  334        rcItem.OffsetRect(rcClient.TopLeft());
 
 
  341    if (iItem < 0 || iItem >= 
GetCount())
 
  344    BOOL bTextColorChanged = FALSE;
 
  346    COLORREF crOldText = RGBA(0xFF, 0xFF, 0xFF, 0xFF);
 
  350    CRect rcIcon, rcText;
 
  360        if (m_pItemSkin != NULL)
 
  370        if (m_pItemSkin != NULL)
 
  379    if (CR_INVALID != crItemBg) 
 
  382    if (m_pItemSkin != NULL) 
 
  383        m_pItemSkin->DrawByIndex(pRT, rc, nBgImg);
 
  385    if (CR_INVALID != crText)
 
  387        bTextColorChanged = TRUE;
 
  392    if (pItem->
nImage != -1 && m_pIconSkin)
 
  395        CSize sizeSkin = m_pIconSkin->GetSkinSize();
 
  396        rcIcon.SetRect(0, 0, sizeSkin.cx, sizeSkin.cy);
 
  399            nOffsetX = nItemHei / 6;
 
  402            nOffsetY = (nItemHei - sizeSkin.cy) / 2; 
 
  404        rcIcon.OffsetRect(rc.left + nOffsetX, rc.top + nOffsetY);
 
  405        m_pIconSkin->DrawByIndex(pRT, rcIcon, pItem->
nImage);
 
  408    UINT align = DT_SINGLELINE;
 
  412        rcText.left = rcIcon.Width() > 0 ? rcIcon.right + nItemHei / 6 : rc.left;
 
  423    if (bTextColorChanged)
 
 
  429    EventLBSelChanging evt1(
this);
 
  430    evt1.bCancel = FALSE;
 
  431    evt1.nOldSel = nOldSel;
 
  432    evt1.nNewSel = nNewSel;
 
  445    EventLBSelChanged evt2(
this);
 
  446    evt2.nOldSel = nOldSel;
 
  447    evt2.nNewSel = nNewSel;
 
 
  458    int nPageItems = (m_rcClient.Height() + nItemHei - 1) / nItemHei + 1;
 
  460    for (
int iItem = iFirstVisible; iItem < 
GetCount() && iItem < iFirstVisible + nPageItems; iItem++)
 
  462        CRect rcItem(0, 0, m_rcClient.Width(), nItemHei);
 
  463        rcItem.OffsetRect(0, nItemHei * iItem - m_siVer.nPos);
 
  464        rcItem.OffsetRect(m_rcClient.TopLeft());
 
 
  473    __baseCls::OnSize(nType, size);
 
 
  479    __baseCls::OnLButtonDown(nFlags, pt);
 
 
  497    __baseCls::OnLButtonUp(nFlags, pt);
 
 
  502    __baseCls::OnLButtonDbClick(nFlags, pt);
 
  507    EventLBDbClick evt2(
this);
 
 
  530    int nNewSelItem = -1;
 
  535        nNewSelItem = iCurSel + 1;
 
  537        nNewSelItem = iCurSel - 1;
 
  539    if (nNewSelItem != -1)
 
  546        if (iHover != -1 && iHover != 
m_iSelItem && iHover != nNewSelItem)
 
 
  555        pOwner->
SSendMessage(WM_CHAR, nChar, MAKELONG(nFlags, nRepCnt));
 
 
  560    return SC_WANTARROWS | SC_WANTCHARS;
 
 
  566    __baseCls::OnDestroy();
 
 
  575    __baseCls::OnShowWindow(bShow, nStatus);
 
 
  580    __baseCls::OnMouseLeave();
 
 
  591    HRESULT hr = __baseCls::OnLanguageChanged();
 
  592    for (
size_t i = 0; i < 
m_arrItems.GetCount(); i++)
 
 
  602    __baseCls::OnScaleChanged(nScale);
 
 
  610    CSize size = rcClient.Size();
 
  612    szView.cx = rcClient.Width();
 
  616    m_wBarVisible = SSB_NULL;
 
  618    if (size.cy < szView.cy)
 
  621        m_wBarVisible |= SSB_VERT;
 
  623        m_siVer.nMax = szView.cy - 1;
 
  624        m_siVer.nPage = size.cy;
 
  625        m_siVer.nPos = smin(m_siVer.nPos, m_siVer.nMax - (
int)m_siVer.nPage);
 
  630        m_siVer.nPage = size.cy;
 
  632        m_siVer.nMax = size.cy - 1;
 
  636    SetScrollPos(TRUE, m_siVer.nPos, FALSE);
 
 
  646    __baseCls::GetDesiredSize(psz, nParentWid, nParentHei);
 
  648    if (pLayoutParam->IsWrapContent(Vert))
 
  652        if (nParentHei > 0 && psz->cy > nParentHei)
 
  653            psz->cy = nParentHei;
 
 
virtual void DrawItem(IRenderTarget *pRT, CRect &rc, int iItem)
Draw an item.
BOOL GetIText(int nIndex, BOOL bRawText, IStringT *str) SCONST OVERRIDE
Get the text of an item.
void EnsureVisible(int nIndex) OVERRIDE
Ensure an item is visible.
int GetItemImage(int nIndex) OVERRIDE
Get the image of an item.
void OnPaint(IRenderTarget *pRT)
Paint the control.
BOOL DeleteString(int nIndex) OVERRIDE
Delete a specific item.
virtual ~SListBox()
Destructor.
int GetCount() SCONST OVERRIDE
Get the number of items in the list box.
int GetTopIndex() SCONST OVERRIDE
Get the index of the top visible item.
virtual UINT WINAPI OnGetDlgCode() const
Get the dialog code.
void SetItemHeight(int nItemHeight) OVERRIDE
Set the height of the items.
int GetItemHeight() SCONST OVERRIDE
Get the height of the items.
void OnMouseMove(UINT nFlags, CPoint pt)
Handle mouse move event.
BOOL SetItemData(int nIndex, LPARAM lParam) OVERRIDE
Set the data associated with an item.
int FindString(int iFindAfter, LPCTSTR pszText) SCONST OVERRIDE
Find a string in the list box.
LPARAM GetItemData(int nIndex) SCONST OVERRIDE
Get the data associated with an item.
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child items from XML configuration.
void UpdateScrollBar()
Update the scroll bar.
BOOL SetTopIndex(int nIndex) OVERRIDE
Set the index of the top visible item.
void LoadItemAttribute(SXmlNode xmlNode, LPLBITEM pItem)
Load attributes for an item from XML.
void OnLButtonDown(UINT nFlags, CPoint pt)
Handle left mouse button down event.
void OnSize(UINT nType, CSize size)
Handle size change event.
int HitTest(CPoint &pt)
Hit test to determine the item under the mouse.
void OnMouseLeave()
Handle mouse leave event.
void NotifySelChange(int nOldSel, int nNewSel)
Notify of selection change.
virtual HRESULT OnLanguageChanged()
Handle language change event.
void OnKeyDown(TCHAR nChar, UINT nRepCnt, UINT nFlags)
Handle key down event.
SArray< LPLBITEM > m_arrItems
void DeleteAll() OVERRIDE
Delete all items in the list box.
void OnScaleChanged(int nScale) override
Handle scale change event.
int AddString(LPCTSTR lpszItem, int nImage=-1, LPARAM lParam=0) OVERRIDE
Add a string to the list box.
int GetCurSel() SCONST OVERRIDE
Get the index of the currently selected item.
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Get the desired size of the control.
int InsertItem(int nIndex, LPLBITEM pItem)
Insert a new item.
void OnLButtonUp(UINT nFlags, CPoint pt)
Handle left mouse button up event.
void OnShowWindow(BOOL bShow, UINT nStatus)
Handle show window event.
int InsertString(int nIndex, LPCTSTR lpszItem, int nImage=-1, LPARAM lParam=0) OVERRIDE
Insert a string into the list box.
void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
Handle character input event.
void RedrawItem(int iItem)
Redraw a specific item.
BOOL SetItemImage(int nIndex, int iImage) OVERRIDE
Set the image of an item.
void OnLButtonDbClick(UINT nFlags, CPoint pt)
Handle left mouse button double-click event.
BOOL SetCurSel(int nIndex, BOOL bNotifyChange=FALSE) OVERRIDE
Set the currently selected item.
void OnDestroy()
Handle destroy event.
Helper class for painting.
virtual CRect GetClientRect() const
Gets the client rectangle.
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handles scroll events.
A class representing an ASCII string.
BOOL IsEmpty() SCONST
Checks if the string is empty.
void SetText(const SStringT &strText, bool bAutoEscape=true)
Sets the text.
SStringT GetText(BOOL bRawText=FALSE) const
Gets the text.
Base class for SOUI DUI windows.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
SWindow * GetOwner() const
Retrieves the current owner of the window.
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
LRESULT SSendMessage(UINT uMsg, WPARAM wParam=0, LPARAM lParam=0, BOOL *pbMsgHandled=NULL) OVERRIDE
Sends a message to the window.
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter)
Prepare rendering environment.
static SStringW GetXmlText(const SXmlNode &xmlNode)
Gets the XML text from a node.
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Restore rendering environment.
ILayoutParam * GetLayoutParam() SCONST OVERRIDE
Retrieves the layout parameter object associated with the window.
void Invalidate() OVERRIDE
Invalidates the entire window.
void GetScaleSkin(SAutoRefPtr< ISkinObj > &pSkin, int nScale)
Retrieves a scaled skin object based on the current scale factor.
const SwndStyle & GetStyle() const
Retrieves the style of the window.
int as_int(int def=0) const
Converts the attribute value to an integer.
unsigned int as_uint(unsigned int def=0) const
Converts the attribute value to an unsigned integer.
const wchar_t * value() const
Gets the attribute value.
Class representing an XML node.
SXmlNode next_sibling() const
Gets the next sibling node in the children list of the parent node.
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
SXmlNode child(const wchar_t *name, bool bCaseSensitive=false) const
Gets the child node, attribute, or next/previous sibling with the specified name.
CRect GetPadding() const
Retrieves the padding rectangle.
Interface for rendering target objects.
HRESULT DrawText(LPCTSTR pszText, int cchLen, LPRECT pRc, UINT uFormat) PURE
Draw text within a rectangle.
HRESULT FillSolidRect(LPCRECT pRect, COLORREF cr) PURE
Fill a rectangle with a solid color.
COLORREF SetTextColor(COLORREF color) PURE
Sets the current text color.