3#include "control/SListCtrl.h"
5#pragma warning(disable : 4267 4018)
33 m_evtSet.addEvent(EVENTID(EventLCSelChanging));
34 m_evtSet.addEvent(EVENTID(EventLCSelChanged));
35 m_evtSet.addEvent(EVENTID(EventLCDbClick));
36 m_evtSet.addEvent(EVENTID(EventLCItemDeleted));
47 int nRet =
m_pHeader->InsertItem(nIndex, pszText, nWidth, fmt, lParam);
66 if (!__baseCls::CreateChildren(xmlNode))
88 subItem.
strText = _tcsdup(pszText);
124 if (plv->
mask & S_LVIF_TEXT)
131 if (plv->
mask & S_LVIF_IMAGE)
133 if (plv->
mask & S_LVIF_INDENT)
145 if (plv->
mask & S_LVIF_TEXT)
149 if (plv->
mask & S_LVIF_IMAGE)
151 if (plv->
mask & S_LVIF_INDENT)
169 lvi.
strText = _tcsdup(pszText);
210 if (nItems < nOldCount)
213 BOOL bRet =
m_arrItems.SetCount(nItems, nGrowBy);
216 for (
int i = nOldCount; i < nItems; i++)
243 szView.cx =
m_pHeader->GetTotalWidth(
false);
244 int nMinWid =
m_pHeader->GetTotalWidth(
true);
250 if (rcClient.bottom < rcClient.top)
251 rcClient.bottom = rcClient.top;
252 CSize size = rcClient.Size();
254 m_wBarVisible = SSB_NULL;
256 if (size.cy < szView.cy || (size.cy < szView.cy +
GetSbWidth() && size.cx < szView.cx))
259 m_wBarVisible |= SSB_VERT;
261 m_siVer.nMax = szView.cy - 1;
262 m_siVer.nPage = rcClient.Height();
265 if (horzSize < nMinWid)
268 m_wBarVisible |= SSB_HORZ;
272 m_siHoz.nMax = szView.cx - 1;
277 if (horzSize < szView.cx || m_pHeader->IsAutoResize())
279 CRect rcHead =
m_pHeader->GetWindowRect();
280 rcHead.right = rcHead.left + horzSize;
282 szView.cx = horzSize;
285 m_siHoz.nPage = szView.cx;
287 m_siHoz.nMax = m_siHoz.nPage - 1;
294 m_siVer.nPage = size.cy;
296 m_siVer.nMax = size.cy - 1;
299 if (size.cx < nMinWid)
302 m_wBarVisible |= SSB_HORZ;
304 m_siHoz.nMax = szView.cx - 1;
305 m_siHoz.nPage = size.cx;
309 if (size.cx < szView.cx ||
m_pHeader->IsAutoResize())
311 CRect rcHead =
m_pHeader->GetWindowRect();
312 rcHead.right = rcHead.left + size.cx;
317 m_siHoz.nPage = szView.cx;
319 m_siHoz.nMax = m_siHoz.nPage - 1;
325 if (
HasScrollBar(FALSE) && m_siHoz.nPos + m_siHoz.nPage > szView.cx)
327 m_siHoz.nPos = szView.cx - m_siHoz.nPage;
330 if (
HasScrollBar(TRUE) && m_siVer.nPos + m_siVer.nPage > szView.cy)
332 m_siVer.nPos = szView.cy - m_siVer.nPage;
349 CRect rcHeader(rcClient);
362 EventLCItemDeleted evt2(
this);
384 int nColumnCount =
m_pHeader->GetItemCount();
390 if (0 == nColumnCount)
392 EventLCItemDeleted evt2(
this);
414 EventLCItemDeleted evt2(
this);
445 SHDITEM hdi = { SHDI_WIDTH | SHDI_ORDER, 0 };
448 rcItem.left = rcItem.right;
449 rcItem.right = rcItem.left + hdi.cx;
450 if (hdi.iOrder == nSubItem)
456 rcItem.OffsetRect(rcList.TopLeft());
491 if (nItem >= nTopItem && nItem <
GetItemCount() && nItem <= nTopItem + nPageItems)
495 rcItem.OffsetRect(rcList.TopLeft());
497 rcDC.IntersectRect(rcItem, rcList);
515 return smax((
int)(bPartial && divHeight.rem > 0 ? divHeight.quot + 1 : divHeight.quot), 1);
533 CRect rcItem(rcList);
535 rcItem.bottom = rcItem.top;
537 for (
int nItem = nTopItem; nItem <= (nTopItem +
GetCountPerPage(TRUE)) && nItem <
GetItemCount(); rcItem.top = rcItem.bottom, nItem++)
553 rect.left += ITEM_MARGIN;
559 rcCheck.SetRect(0, 0, sizeSkin.cx, sizeSkin.cy);
560 rcCheck.OffsetRect(rect.left + nOffsetX, 0);
562 if (pt.x >= rcCheck.left && pt.x <= rcCheck.right)
569 BOOL bTextColorChanged = FALSE;
571 COLORREF crOldText = RGBA(0xFF, 0xFF, 0xFF, 0xFF);
575 CRect rcIcon, rcText;
615 if (CR_INVALID != crItemBg)
622 rcItem.left += ITEM_MARGIN;
624 if (CR_INVALID != crText)
626 bTextColorChanged = TRUE;
631 rcCol.right = rcCol.left;
638 SHDITEM hdi = { SHDI_WIDTH | SHDI_ORDER, 0 };
640 rcCol.left = rcCol.right;
641 rcCol.right = rcCol.left + hdi.cx;
643 rcVisiblePart.IntersectRect(rcItem, rcCol);
645 if (rcVisiblePart.IsRectEmpty())
655 rcCheck.SetRect(0, 0, sizeSkin.cx, sizeSkin.cy);
656 rcCheck.OffsetRect(rcCol.left + nOffsetX, rcCol.top + nOffsetY);
659 rcCol.left = sizeSkin.cx + 6 + rcCol.left;
669 rcIcon.SetRect(0, 0, sizeSkin.cx, sizeSkin.cy);
677 rcIcon.OffsetRect(rcCol.left + nOffsetX, rcCol.top + nOffsetY);
681 UINT align = DT_SINGLELINE;
685 rcText.left = rcIcon.Width() > 0 ? rcIcon.right +
m_nItemHeight / 6 : rcCol.left;
687 rcText.left = rcCol.left +
m_ptText.x;
692 rcText.top = rcCol.top +
m_ptText.y;
697 if (bTextColorChanged)
705 __baseCls::OnDestroy();
723 EventLCSelChanging evt1(
this);
724 evt1.bCancel = FALSE;
725 evt1.nOldSel = nOldSel;
726 evt1.nNewSel = nNewSel;
761 int imax = (nOldSel > nNewSel) ? nOldSel : nNewSel;
762 int imin = (imax == nOldSel) ? nNewSel : nOldSel;
767 if (i >= imin && i <= imax)
786 if (i != nNewSel && lvItem.
checked)
804 EventLCSelChanged evt2(
this);
805 evt2.nOldSel = nOldSel;
806 evt2.nNewSel = nNewSel;
812 BOOL bRet = __baseCls::OnScroll(bVertical, uCode, nPos);
826 if (uCode == SB_THUMBTRACK)
834 __baseCls::OnLButtonDown(nFlags, pt);
852 EventLCDbClick evt2(
this);
859 __baseCls::OnLButtonUp(nFlags, pt);
864 __baseCls::UpdateChildrenPosition();
870 __baseCls::OnSize(nType, size);
912 __baseCls::OnMouseLeave();
virtual BOOL CreateChildren(SXmlNode xmlNode)
Create child items from XML configuration.
void OnLButtonUp(UINT nFlags, CPoint pt)
Handle left mouse button up event.
void SetSelectedItem(int nItem)
Set the selected item.
BOOL SetSubItemText(int nItem, int nSubItem, LPCTSTR pszText)
Set the text of a subitem.
int GetLastCheckedItem()
Get the last checked item.
BOOL SetSubItem(int nItem, int nSubItem, const DXLVSUBITEM *plv)
Set a subitem.
int GetSelectedItem()
Get the selected item.
void OnLButtonDown(UINT nFlags, CPoint pt)
Handle left mouse button down event.
BOOL SetItemCount(int nItems, int nGrowBy)
Set the total number of items.
int GetTopIndex() const
Get the index of the top visible item.
void UpdateChildrenPosition() OVERRIDE
Update the position of child items.
SStringT GetSubItemText(int nItem, int nSubItem) const
Get the text of a subitem.
void NotifySelChange(int nOldSel, int nNewSel, BOOL checkBox=FALSE)
Notify of selection change.
int InsertItem(int nItem, LPCTSTR pszText, int nImage=-1)
Insert an item.
BOOL SortItems(PFNLVCOMPAREEX pfnCompare, void *pContext)
Sort items using a comparison function.
void OnMouseLeave()
Handle mouse leave event.
int GetFirstCheckedItem()
Get the first checked item.
virtual ~SListCtrl()
Destructor.
virtual BOOL OnScroll(BOOL bVertical, UINT uCode, int nPos)
Handle scroll event.
SAutoRefPtr< ISkinObj > m_pItemSkin
int InsertColumn(int nIndex, LPCTSTR pszText, int nWidth, UINT fmt, LPARAM lParam=0)
Insert a column.
void UpdateHeaderCtrl()
Update the header control.
void OnMouseMove(UINT nFlags, CPoint pt)
Handle mouse move event.
BOOL GetCheckState(int nItem)
Get the check state of an item.
void OnPaint(IRenderTarget *pRT)
Paint the control.
CRect GetItemRect(int nItem, int nSubItem=0)
Get the rectangle of an item.
BOOL OnHeaderSizeChanging(IEvtArgs *pEvt)
Handle header size changing event.
BOOL HitCheckBox(const CPoint &pt)
Hit test to determine if the point is on a checkbox.
void DeleteAllItems()
Delete all items.
LPARAM GetItemData(int nItem)
Get the data associated with an item.
void OnSize(UINT nType, CSize size)
Handle size change event.
void RedrawItem(int nItem)
Redraw a specific item.
void OnDestroy()
Handle destroy event.
SHeaderCtrl * GetHeaderCtrl() const
Get the header control.
virtual void DrawItem(IRenderTarget *pRT, CRect rcItem, int nItem)
Draw an item.
BOOL OnHeaderSwap(IEvtArgs *pEvt)
Handle header swap event.
SAutoRefPtr< ISkinObj > m_pCheckSkin
SAutoRefPtr< ISkinObj > m_pIconSkin
int GetItemCount() const
Get the total number of items.
int HitTest(const CPoint &pt)
Hit test to determine the item under the mouse.
void DeleteItem(int nItem)
Delete a specific item.
void UpdateScrollBar()
Update the scroll bar.
BOOL SetCheckState(int nItem, BOOL bCheck)
Set the check state of an item.
void OnLButtonDbClick(UINT nFlags, CPoint pt)
Handle left mouse button double-click event.
int GetColumnCount() const
Get the total number of columns.
BOOL GetSubItem(int nItem, int nSubItem, DXLVSUBITEM *plv) const
Get a subitem.
int GetCheckedItemCount()
Get the number of checked items.
BOOL OnHeaderClick(IEvtArgs *pEvt)
Handle header click event.
BOOL SetItemData(int nItem, LPARAM dwData)
Set the data associated with an item.
void DeleteColumn(int iCol)
Delete a specific column.
int GetCountPerPage(BOOL bPartial)
Get the number of items per page.
CRect GetListRect()
Get the rectangle of the list.
static LPCWSTR GetClassName()
Helper class for painting.
virtual CRect GetClientRect() const
Gets the client rectangle.
int GetSbWidth() const
Gets the width of the scrollbar.
BOOL HasScrollBar(BOOL bVertical) SCONST OVERRIDE
Checks if a scrollbar is present.
BOOL SetScrollPos(BOOL bVertical, int nNewPos, BOOL bRedraw) OVERRIDE
Sets the scroll position for a scrollbar.
void ScrollUpdate()
Updates the scrollbar.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
void ReleaseRenderTarget(IRenderTarget *pRT)
Releases the RenderTarget obtained via GetRenderTarget.
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
void InsertChild(SWindow *pNewChild, SWindow *pInsertAfter=NULL)
Inserts a child window into the window tree.
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.
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
virtual SWindow * CreateChildByName(LPCWSTR pszName)
Create child window by name.
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Restore rendering environment.
void Invalidate() OVERRIDE
Invalidates the entire window.
IRenderTarget * GetRenderTarget(LPCRECT pRc=NULL, GrtFlag gdcFlags=GRT_NODRAW, BOOL bClientRT=TRUE)
Retrieves a memory DC compatible with the SWND window.
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
Class representing an XML 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.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
Interface for rendering target objects.
HRESULT DrawText(LPCTSTR pszText, int cchLen, LPRECT pRc, UINT uFormat) PURE
Draw text within a rectangle.
HRESULT PushClipRect(LPCRECT pRect, UINT mode=RGN_AND) PURE
Push a rectangular clip region.
HRESULT PopClip() PURE
Pop the last clip region from the stack.
HRESULT FillSolidRect(LPCRECT pRect, COLORREF cr) PURE
Fill a rectangle with a solid color.
COLORREF SetTextColor(COLORREF color) PURE
Sets the current text color.