2#include "control/SHeaderCtrl.h"
3#include "helper/SDragWnd.h"
18 m_evtSet.addEvent(EVENTID(EventHeaderClick));
19 m_evtSet.addEvent(EVENTID(EventHeaderItemChanged));
20 m_evtSet.addEvent(EVENTID(EventHeaderItemChanging));
21 m_evtSet.addEvent(EVENTID(EventHeaderItemSwap));
22 m_evtSet.addEvent(EVENTID(EventHeaderRelayout));
29int SHeaderCtrl::InsertItem(
int iItem, LPCTSTR pszText,
int nWidth, UINT fmt, LPARAM lParam, BOOL bDpiAware ,
float fWeight )
38 item.fWeight = fWeight;
39 SLayoutSize szWid((
float)nWidth, bDpiAware ? SLayoutSize::dp : SLayoutSize::px);
41 item.bDpiAware = bDpiAware;
43 item.strText.
SetText(pszText,
false);
52 if (i == (
size_t)iItem)
57 EventHeaderRelayout e(
this);
68 if (pItem->mask & SHDI_TEXT && pItem->pszText && pItem->cchMaxText)
70 _tcscpy_s(pItem->pszText, pItem->cchMaxText,
m_arrItems[iItem].strText.GetText(FALSE).c_str());
72 if (pItem->mask & SHDI_WIDTH)
76 if (pItem->mask & SHDI_LPARAM)
78 if (pItem->mask & SHDI_FORMAT)
80 if (pItem->mask & SHDI_ORDER)
82 if (pItem->mask & SHDI_VISIBLE)
84 if (pItem->mask & SHDI_WEIGHT)
96 if (pItem->mask & SHDI_TEXT && pItem->pszText)
98 item.strText.
SetText(pItem->pszText,
false);
100 if (pItem->mask & SHDI_WIDTH)
102 if (pItem->mask & SHDI_LPARAM)
103 item.lParam = pItem->lParam;
104 if (pItem->mask & SHDI_WEIGHT)
105 item.fWeight = pItem->fWeight;
106 if (pItem->mask & SHDI_FORMAT)
107 item.fmt = pItem->fmt;
108 if (pItem->mask & SHDI_VISIBLE)
109 item.bVisible = pItem->bVisible;
120 CRect rcItem(rcClient.left, rcClient.top, rcClient.left, rcClient.bottom);
121 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
125 rcItem.left = rcItem.right;
128 if (rcItem.right >= rcClient.right)
131 if (rcItem.right < rcClient.right)
133 rcItem.left = rcItem.right;
134 rcItem.right = rcClient.right;
143 if (!pItem->bVisible)
146 m_pSkinItem->DrawByState(pRT, rcItem, pItem->state);
147 UINT align = DT_SINGLELINE | DT_VCENTER;
148 if (pItem->fmt & HDF_CENTER)
150 else if (pItem->fmt & HDF_RIGHT)
153 BOOL bDrawSortFlag = (pItem->fmt & SORT_MASK) != 0 &&
m_pSkinSort;
161 rcItem.right -= szSort.cx;
165 ptSort.x = rcItem.right;
166 ptSort.y = rcItem.top + (rcItem.Height() - szSort.cy) / 2;
168 m_pSkinSort->DrawByIndex(pRT, CRect(ptSort, szSort), (pItem->fmt & HDF_SORTUP) ? 0 : 1);
173 if (iItem < 0 || (UINT)iItem >=
m_arrItems.GetCount())
179 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
184 EventHeaderRelayout e(
this);
194 EventHeaderRelayout e(
this);
213 CRect rcItem(rcClient.left, rcClient.top, rcClient.left, rcClient.bottom);
214 for (
int i = 0; i <= iItem && i < (int)
m_arrItems.GetCount(); i++)
218 rcItem.left = rcItem.right;
231 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
290 EventHeaderItemSwap evt(
this);
292 evt.iNewIndex = nPos;
295 EventHeaderRelayout e(
this);
310 EventHeaderClick evt(
this);
318 EventHeaderItemChanged evt(
this);
323 EventHeaderRelayout e(
this);
342 CPoint pt =
m_ptClick - rcItem.TopLeft();
343 SDragWnd::BeginDrag(
m_hDragImg, pt, 0, 128, LWA_ALPHA | LWA_COLORKEY);
359 SDragWnd::DragMove(pt2);
372 float fTotalWeight = 0.0f;
373 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
380 if (fTotalWeight > 0.0f)
382 if (nTotalWid != rc.Width())
384 int nRemain = rc.Width() - nTotalWid;
385 for (UINT i = 0; i <
m_arrItems.GetCount() && nRemain > 0 && fTotalWeight > 0.0f; i++)
389 int nAppend = (int)(nRemain *
m_arrItems[i].fWeight / fTotalWeight);
412 EventHeaderItemChanging evt(
this);
417 EventHeaderRelayout e(
this);
437 WORD iHover = LOWORD(dwHitTest);
469 __baseCls::CreateChildren(xmlNode);
479 item.mask = 0xFFFFFFFF;
480 item.iOrder = iOrder++;
486 item.strText.
SetText(S_CW2T(GETSTRING(strText)));
490 item.bDpiAware = (szItem.unit != SLayoutSize::px);
497 if (strSort == L
"down")
498 item.fmt |= HDF_SORTDOWN;
499 else if (strSort == L
"up")
500 item.fmt |= HDF_SORTUP;
503 if (strAlign == L
"left")
504 item.fmt |= HDF_LEFT;
505 else if (strAlign == L
"center")
506 item.fmt |= HDF_CENTER;
507 else if (strAlign == L
"right")
508 item.fmt |= HDF_RIGHT;
512 if (align & DT_CENTER)
513 item.fmt |= HDF_CENTER;
514 else if (align & DT_RIGHT)
515 item.fmt |= HDF_RIGHT;
517 item.fmt |= HDF_LEFT;
532 if (HIWORD(dwHit) == LOWORD(dwHit))
534 HCURSOR hCursor = GETRESPROVIDER->LoadCursor(IDC_SIZEWE);
543 if (!rcClient.PtInRect(pt))
546 CRect rcItem(rcClient.left, rcClient.top, rcClient.left, rcClient.bottom);
547 int nMargin =
m_bFixWidth ? MARGIN_ADJUST_DISABLE : MARGIN_ADJUST_ENABLE;
548 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
553 rcItem.left = rcItem.right;
555 if (pt.x < rcItem.left + nMargin)
557 int nLeft = i > 0 ? i - 1 : 0;
558 return MAKELONG(nLeft, i);
560 else if (pt.x < rcItem.right - nMargin)
562 return MAKELONG(i, i);
564 else if (pt.x < rcItem.right)
566 WORD nRight = (WORD)i + 1;
569 return MAKELONG(i, nRight);
581 CRect rcItem(0, 0,
GetItemWidth(iItem), rcClient.Height());
584 GETRENDERFACTORY->CreateRenderTarget(&pRT, rcItem.Width(), rcItem.Height());
590 HBITMAP hBmp = CreateBitmap(rcItem.Width(), rcItem.Height(), 1, 32, NULL);
591 HDC hdc = GetDC(NULL);
592 HDC hMemDC = CreateCompatibleDC(hdc);
593 ::SelectObject(hMemDC, hBmp);
594 HDC hdcSrc = pRT->GetDC(0);
595 ::BitBlt(hMemDC, 0, 0, rcItem.Width(), rcItem.Height(), hdcSrc, 0, 0, SRCCOPY);
596 pRT->ReleaseDC(hdcSrc, NULL);
598 ReleaseDC(NULL, hdc);
609 CRect rcItem(rcClient.left, rcClient.top, rcClient.left, rcClient.bottom);
610 int iDragTo = LOWORD(dwDragTo);
614 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
616 if (i != (UINT)iDragFrom)
619 items.InsertAt(iDragTo, iDragFrom);
623 for (UINT i = 0; i < items.GetCount(); i++)
625 rcItem.left = rcItem.right;
627 if (items[i] != (UINT)iDragFrom)
639 float fTotalWeight = 0.0f;
640 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
647 if (!bMinWid && fTotalWeight > 0.0f)
649 return smax(nTotalWidth, rc.Width());
659 if (iItem < 0 || (UINT)iItem >=
m_arrItems.GetCount())
669 if (rc.IsRectEmpty())
675 float fTotalWeight = 0.0f;
677 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
684 int nRemain = rc.Width() - nTotalWidth;
689 for (
int i = 0; i < iItem; i++)
693 int nAppend = (int)(nRemain *
m_arrItems[i].fWeight / fTotalWeight);
697 return item.cx + (int)(nRemain * item.fWeight / fTotalWeight);
723 SASSERT(iItem >= 0 && iItem < (
int)
m_arrItems.GetCount());
725 if ((sortFlag & SORT_MASK) != (
m_arrItems[iItem].fmt & SORT_MASK))
728 m_arrItems[iItem].fmt |= sortFlag & SORT_MASK;
736 __baseCls::OnColorize(cr);
745 __baseCls::OnLanguageChanged();
746 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
758 for (
size_t i = 0; i <
m_arrItems.GetCount(); i++)
770 BOOL bRet = __baseCls::OnRelayout(rcWnd);
773 EventHeaderRelayout e(
this);
781 SASSERT(iItem >= 0 && iItem < (
int)
m_arrItems.GetCount());
786 EventHeaderItemChanged evt(
this);
794 SASSERT(iItem >= 0 && iItem < (
int)
m_arrItems.GetCount());
800 for (UINT i = 0; i <
m_arrItems.GetCount(); i++)
Smart pointer class for managing COM-style reference-counted objects.
void setMutedState(BOOL setting)
设置事件集的静音状态
static bool fequal(float a, float b)
比较两个浮点数是否相等
int toPixelSize(int scale) const
将大小转换为像素值
Helper class for painting.
A class representing an ASCII string.
BOOL IsEmpty() SCONST
Checks if the string is empty.
SStringW & MakeLower()
Converts the string to lowercase.
void SetOwner(SWindow *pOwner)
Sets the owner window.
void SetText(const SStringT &strText, bool bAutoEscape=true)
Sets the text.
SStringT GetText(BOOL bRawText=FALSE) const
Gets the text.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
void OnDestroy()
Handles the destruction of the window.
void ReleaseRenderTarget(IRenderTarget *pRT)
Releases the RenderTarget obtained via GetRenderTarget.
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
virtual void OnScaleChanged(int scale)
Called when the scale of the window changes.
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
virtual CRect GetClientRect() const
Retrieves the client rectangle of 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.
SWND SetCapture() OVERRIDE
Sets the window to capture the mouse.
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Restore rendering environment.
SEventSet * GetEventSet()
Retrieves the event set associated with the window.
void Invalidate() OVERRIDE
Invalidates the entire window.
const SwndStyle & GetStyle() const
Retrieves the style of the window.
HWND GetHostHwnd() OVERRIDE
Retrieves the host window handle.
void BeforePaintEx(IRenderTarget *pRT)
Prepares the drawing environment for the current window's RenderTarget, starting from the top-level w...
BOOL ReleaseCapture() OVERRIDE
Releases the mouse capture from the window.
IRenderTarget * GetRenderTarget(LPCRECT pRc=NULL, GrtFlag gdcFlags=GRT_NODRAW, BOOL bClientRT=TRUE)
Retrieves a memory DC compatible with the SWND window.
float as_float(float def=0) const
Converts the attribute value to a float.
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
unsigned int as_uint(unsigned int def=0) const
Converts the attribute value to an unsigned integer.
bool as_bool(bool def=false) const
Converts the attribute value to a boolean.
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.
BOOL set_userdata(int data) OVERRIDE
Sets user data for the node.
UINT GetTextAlign() const
Retrieves the text alignment.
Interface for rendering target objects.
HRESULT DrawText(LPCTSTR pszText, int cchLen, LPRECT pRc, UINT uFormat) PURE
Draw text within a rectangle.