3#include "animation/SInterpolatorImpl.h"
10 DEF_SOBJECT(
SWindow, L
"tabslider")
13 STabSlider(STabCtrl *pTabCtrl,
int iFrom,
int iTo,
int nSteps,
int nType, IInterpolator *pInterpolator)
14 : m_pTabCtrl(pTabCtrl)
15 , m_aniInterpoloator(pInterpolator)
20 SASSERT(pInterpolator);
31 m_bVertical = pTabCtrl->
m_nTabAlign == STabCtrl::AlignLeft || pTabCtrl->
m_nTabAlign == STabCtrl::AlignRight;
34 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, rcPage.Width(), rcPage.Height() * 2);
38 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, rcPage.Width() * 2, rcPage.Height());
50 m_nTo = rcPage.Height();
54 pt.x = 0, pt.y = rcPage.Height();
55 m_ptOffset.y = rcPage.Height();
56 m_nFrom = rcPage.Height();
66 m_nTo = rcPage.Width();
70 pt.x = rcPage.Width(), pt.y = 0;
71 m_ptOffset.x = rcPage.Width();
72 m_nFrom = rcPage.Width();
76 pt -= rcPage.TopLeft();
77 m_memRT->SetViewportOrg(pt);
86 pt.x = 0, pt.y = rcPage.Height();
97 pt.x = rcPage.Width(), pt.y = 0;
105 pt -= rcPage.TopLeft();
106 m_memRT->SetViewportOrg(pt);
111 m_memRT->SetViewportOrg(CPoint());
123 m_bVertical = pTabCtrl->
m_nTabAlign == STabCtrl::AlignLeft || pTabCtrl->
m_nTabAlign == STabCtrl::AlignRight;
126 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, rcPage.Width(), rcPage.Height() * 2);
130 GETRENDERFACTORY->CreateRenderTarget(&m_memRT, rcPage.Width() * 2, rcPage.Height());
132 m_memRT->BeginDraw();
141 m_nTo = rcPage.Height();
145 pt.x = 0, pt.y = rcPage.Height();
146 m_ptOffset.y = rcPage.Height();
147 m_nFrom = rcPage.Height();
157 m_nTo = rcPage.Width();
161 pt.x = rcPage.Width(), pt.y = 0;
162 m_ptOffset.x = rcPage.Width();
163 m_nFrom = rcPage.Width();
167 pt -= rcPage.TopLeft();
168 m_memRT->SetViewportOrg(pt);
177 pt.x = 0, pt.y = rcPage.Height();
188 pt.x = rcPage.Width(), pt.y = 0;
196 pt -= rcPage.TopLeft();
197 m_memRT->SetViewportOrg(pt);
202 m_memRT->SetViewportOrg(CPoint());
210 virtual ~STabSlider()
214 STDMETHOD_(
void, OnNextFrame)(THIS_) OVERRIDE
216 if (++m_iStep > m_nSteps)
222 float fPos = m_aniInterpoloator->getInterpolation(m_iStep * 1.0f / m_nSteps);
223 int nOffset = m_nFrom + (int)(fPos * (m_nTo - m_nFrom));
225 m_ptOffset.y = nOffset;
227 m_ptOffset.x = nOffset;
234 m_pTabCtrl->OnSliderFinish();
238 virtual void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer)
247 void OnPaint(IRenderTarget *pRT)
250 CRect rcSrc(m_ptOffset.x, m_ptOffset.y, m_ptOffset.x + rcWnd.Width(), m_ptOffset.y + rcWnd.Height());
254 void OnSize(UINT fType, CSize sz)
268 SAutoRefPtr<IRenderTarget> m_memRT;
274 SAutoRefPtr<IInterpolator> m_aniInterpoloator;
275 STabCtrl *m_pTabCtrl;
277 MSG_WM_PAINT_EX(OnPaint)
279 MSG_WM_DESTROY(OnDestroy)
288 ,
m_pSkinTab(GETBUILTINSKIN(SKIN_SYS_TAB_PAGE))
298 , m_txtDir(Text_Horz)
308 m_evtSet.addEvent(EVENTID(EventTabSelChanging));
309 m_evtSet.addEvent(EVENTID(EventTabSelChanged));
310 m_evtSet.addEvent(EVENTID(EventTabItemHover));
311 m_evtSet.addEvent(EVENTID(EventTabItemLeave));
321 if (!rcTitle.IsRectEmpty())
323 CRect rcItem, rcItemPrev;
338 if (rcItem.IsRectEmpty())
347 rcSplit.top = rcItemPrev.bottom;
352 rcSplit.left = rcItemPrev.right;
374 rc.DeflateRect(2, 2);
384 rcRet.DeflateRect(
GetStyle().GetPadding());
406 int iClickItem =
HitTest(point);
459 for (
int i = 0; i < nTabCount; i++)
463 if (rcItem.PtInRect(point))
478 EventTabItemLeave evt(
this);
479 evt.iLeave = nOldHover;
489 EventTabItemHover evt(
this);
503 __baseCls::OnDestroy();
517 for (UINT i = 0; i <
m_lstPages.GetCount(); i++)
519 if (_tcscmp(
m_lstPages[i]->GetTitle(), pszName) == 0)
526 for (UINT i = 0; i <
m_lstPages.GetCount(); i++)
550void STabCtrl::OnSliderFinish()
552 SASSERT(m_tabSlider);
555 STabPage *pPage = m_lstPages[m_nCurrentPage];
566 EventTabSelChanging evt(
this);
568 evt.uOldSel = nOldPage;
569 evt.uNewSel = nIndex;
593 GetItem(nOldPage)->SetVisible(FALSE, TRUE);
597 GetItem(nIndex)->SetVisible(TRUE, TRUE);
604 EventTabSelChanged evt2(
this);
605 evt2.uNewSel = nIndex;
606 evt2.uOldSel = nOldPage;
668 if (!xmlDoc.
load_buffer(lpContent, wcslen(lpContent) *
sizeof(
wchar_t), xml_parse_default,
sizeof(
wchar_t) == 2 ? enc_utf16 : enc_utf32))
675 if (_wcsicmp(xmlNode.
name(), L
"include") == 0)
679 if (!LOADXML(xmlDoc, strSrc))
685 STabPage *pChild = CreatePageFromXml(xmlNode);
701 pChild->
Move(&rcPage);
755 rcItem.IntersectRect(rcItem, rcTitle);
761 if (rcItem.IsRectEmpty())
764 m_pSkinTab->DrawByState(pRT, rcItem, dwState);
767 IFontPtr font =
m_style.GetTextFont(iState);
768 COLORREF crTxt =
m_style.GetTextColor(iState);
773 if (crTxt != CR_INVALID)
779 rcIcon.right = rcIcon.left +
m_pSkinIcon->GetSkinSize().cx;
780 rcIcon.bottom = rcIcon.top +
m_pSkinIcon->GetSkinSize().cy;
781 int iIcon =
GetItem(iItem)->GetIconIndex();
789 if (m_txtDir == Text_Horz)
796 CRect rcText = rcItem;
797 UINT alignStyle =
m_style.GetTextAlign();
798 UINT align = alignStyle;
802 align = alignStyle & (DT_CENTER | DT_RIGHT | DT_SINGLELINE | DT_END_ELLIPSIS);
807 align = alignStyle & (DT_VCENTER | DT_BOTTOM | DT_SINGLELINE | DT_END_ELLIPSIS);
810 if (m_txtDir == Text_Horz)
819 if (crTxt != CR_INVALID)
839 if (nChar == VK_LEFT || nChar == VK_UP)
844 else if (nChar == VK_RIGHT || nChar == VK_DOWN)
849 else if (nChar == VK_HOME)
853 else if (nChar == VK_END)
862 for (
int i = 0; i < nTabCount; i++)
867 if (rcItem.PtInRect(pt))
875void STabCtrl::OnInitFinished(THIS_
IXmlNode *xmlNode)
879 SIZE sz = m_pSkinTab->GetSkinSize();
881 m_szTab[0] =
SLayoutSize((
float)sz.cx, SLayoutSize::defUnit);
883 m_szTab[1] =
SLayoutSize((
float)sz.cy, SLayoutSize::defUnit);
891 for (
size_t i = 0; i <
m_lstPages.GetCount(); i++)
899 IFontPtr pFont =
m_style.GetTextFont(0);
903 COLORREF crTxt =
m_style.GetTextColor(0);
904 if (crTxt != CR_INVALID)
910 SStringT strTmp = strText;
911 LPTSTR p = strTmp.GetBuffer(0);
914 LPTSTR p2 = SStringT::_tchar_traits::CharNext(p);
917 pRT->
TextOut(x, y, p, (
int)(p2 - p));
921 strTmp.ReleaseBuffer();
926 SIZE szRet = { 0, 0 };
927 SStringT strTmp = strText;
928 LPTSTR p = strTmp.GetBuffer(0);
931 LPTSTR p2 = SStringT::_tchar_traits::CharNext(p);
934 szRet.cx = smax(szRet.cx, szWord.cx);
935 szRet.cy += szWord.cy;
938 strTmp.ReleaseBuffer();
946 TextOutV(pRT, rcText.left + (rcText.Width() - szText.cx) / 2, rcText.top + (rcText.Height() - szText.cy) / 2, strText);
951 __baseCls::OnColorize(cr);
964 __baseCls::OnScaleChanged(nScale);
977 __baseCls::OnLanguageChanged();
978 for (
int i = 0; i < (int)
m_lstPages.GetCount(); i++)
Definition of the STabCtrl and related classes.
Smart pointer class for managing COM-style reference-counted objects.
static bool fequal(float a, float b)
比较两个浮点数是否相等
LPCWSTR GetName() SCONST OVERRIDE
static LPCWSTR GetClassName()
Helper class for painting.
SAutoRefPtr< IFontS > oldFont
static SApplication & getSingleton(void)
static int GetDefIndex(DWORD dwState, bool checkAsPushdown=false)
Gets the default index for a given state.
A class representing an ASCII string.
SAutoRefPtr< ISkinObj > m_pSkinTabInter
virtual void OnItemInserted(STabPage *pItem)
Handles the insertion of a tab page.
void UpdateChildrenPosition() OVERRIDE
Updates the positions of child windows.
STabPage * GetItem(int iPage)
Gets a tab page by index.
BOOL SetCurSel(int nIndex) OVERRIDE
Sets the currently selected tab page.
virtual void OnItemRemoved(STabPage *pItem)
Handles the removal of a tab page.
SIZE MeasureTextV(IRenderTarget *pRT, const SStringT &strText)
Measures text vertically.
BOOL CreateChildren(SXmlNode xmlNode)
Creates tab pages from an XML node.
void OnDestroy()
Handles the destroy event.
virtual void OnColorize(COLORREF cr)
Adjusts the color tone of the window.
virtual HRESULT OnLanguageChanged()
Called when the language of the window changes.
SAutoRefPtr< ISkinObj > m_pSkinFrame
int GetCurSel() SCONST OVERRIDE
Gets the index of the currently selected tab page.
void TextOutV(IRenderTarget *pRT, int x, int y, const SStringT &strText)
Outputs text vertically.
SArray< STabPage * > m_lstPages
int GetItemCount() SCONST OVERRIDE
Gets the number of tab pages.
void RemoveAllItems() OVERRIDE
Removes all tab pages.
STabCtrl()
Constructor for STabCtrl.
SAutoRefPtr< ISkinObj > m_pSkinIcon
int HitTest(CPoint pt)
Performs a hit test on the tab control.
int GetPageIndex(LPCTSTR pszName, BOOL bTitle) OVERRIDE
Gets the index of a tab page by name or title.
virtual CRect GetTitleRect()
Gets the rectangle of the tab header.
virtual BOOL GetItemRect(int nIndex, CRect &rcItem)
Gets the rectangle of a specified tab item.
void GetChildrenLayoutRect(RECT *prc) SCONST OVERRIDE
Gets the layout rectangle for child windows.
void DrawTextV(IRenderTarget *pRT, CRect rcText, const SStringT &strText)
Draws text vertically.
IWindow * GetPage(int nIndex) OVERRIDE
Gets a tab page by index.
virtual void OnScaleChanged(int nScale)
Called when the scale of the window changes.
BOOL RemoveItem(int nIndex, int iSelPage=0) OVERRIDE
Removes a tab page by index.
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter)
Prepares the rendering target for painting the current window.
void OnMouseMove(UINT nFlags, CPoint point)
Handles the mouse move event.
SLayoutSize m_nTabInterSize
void OnLButtonDown(UINT nFlags, CPoint point)
Handles the left mouse button down event.
int InsertItem(LPCWSTR lpContent, int iInsert=-1) OVERRIDE
Inserts a new tab page.
BOOL SetItemTitle(int nIndex, LPCTSTR lpszTitle) OVERRIDE
Sets the title of a tab page.
virtual void DrawItem(IRenderTarget *pRT, const CRect &rcItem, int iItem, DWORD dwState)
Draws a tab item.
virtual BOOL UpdateToolTip(CPoint pt, SwndToolTipInfo &tipInfo)
Handle tooltip updates.
void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
Handles the key down event.
SAutoRefPtr< ISkinObj > m_pSkinTab
void OnPaint(IRenderTarget *pRT)
Handles the paint event.
A tab page within a tab control.
void SetTitle(LPCTSTR lpszTitle) OVERRIDE
Sets the title of the tab page.
void TranslateText()
Translates the text.
Base class for SOUI DUI windows.
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
BOOL DestroyChild(SWindow *pChild)
Destroys a child window.
virtual void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer)
Called when the container of the window changes.
SWindow * GetParent() const
Retrieves the parent window.
void SetVisible(BOOL bVisible, BOOL bUpdate=FALSE) OVERRIDE
Sets the visibility of the window.
void OnDestroy()
Handles the destruction of the window.
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
CRect GetWindowRect() const
Retrieves the bounding rectangle of the window.
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
void PaintForeground(IRenderTarget *pRT, LPRECT pRc, SWindow *pStartFrom=NULL)
Draws the foreground content of the window.
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
BOOL IsFocused() SCONST OVERRIDE
Checks if the window has focus.
void PaintBackground(IRenderTarget *pRT, LPRECT pRc)
Draws the background content of the window.
void GetChildrenLayoutRect(RECT *prc) SCONST OVERRIDE
Retrieves the layout rectangle of the children.
void OnSize(UINT nType, CSize size)
Handles the resizing of the window.
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.
SWindow * GetRoot() const
Retrieves the root window in the hierarchy.
virtual void BeforePaint(IRenderTarget *pRT, SPainter &painter)
Prepare rendering environment.
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
void UpdateLayout() OVERRIDE
Updates the layout of the window.
virtual SWindow * CreateChildByName(LPCWSTR pszName)
Create child window by name.
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
virtual void AfterPaint(IRenderTarget *pRT, SPainter &painter)
Restore rendering environment.
ILayoutParam * GetLayoutParam() SCONST OVERRIDE
Retrieves the layout parameter object associated with the window.
void DrawDefFocusRect(IRenderTarget *pRT, CRect rc)
Draws the default focus rectangle.
BOOL IsFocusable() SCONST OVERRIDE
Checks if the window is focusable.
void Invalidate() OVERRIDE
Invalidates the entire window.
virtual SStringT GetToolTipText()
Retrieves the tooltip text of the window.
void GetScaleSkin(SAutoRefPtr< ISkinObj > &pSkin, int nScale)
Retrieves a scaled skin object based on the current scale factor.
BOOL InitFromXml(IXmlNode *pNode) OVERRIDE
Initializes the window from an XML node.
const SwndStyle & GetStyle() const
Retrieves the style of the window.
SWND m_swnd
Member variables representing various properties of the window.
void Move(LPCRECT prect) OVERRIDE
Moves the window to a new position and size.
const wchar_t * value() const
Gets the attribute value.
Implementation of IXmlDoc.
SXmlNode root() const
Retrieves the root node of the document.
bool load_buffer(const void *contents, size_t size, unsigned int options=xml_parse_default, XmlEncoding encoding=enc_auto)
Loads the document from a buffer.
Class representing an XML node.
SXmlNode next_sibling() const
Gets the next sibling node in the children list of the parent node.
SXmlNode first_child() const
Gets the first child node of the node.
const wchar_t * name() const
Gets the name of the node.
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
Base class for all renderable objects.
Interface for rendering target objects.
HRESULT DrawText(LPCTSTR pszText, int cchLen, LPRECT pRc, UINT uFormat) PURE
Draw text within a rectangle.
HRESULT AlphaBlend(LPCRECT pRcDest, IRenderTarget *pRTSrc, LPCRECT pRcSrc, BYTE byAlpha) PURE
Performs an alpha-blended transfer from one render target to another.
HRESULT SelectObject(IRenderObj *pObj, IRenderObj **pOldObj=NULL) PURE
Selects a new rendering object and optionally retrieves the previous one.
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 TextOut(int x, int y, LPCTSTR lpszString, int nCount) PURE
Output text at a specified position.
COLORREF SetTextColor(COLORREF color) PURE
Sets the current text color.
HRESULT MeasureText(LPCTSTR pszText, int cchLen, SIZE *psz) PURE
Measure the size of the text.
BOOL RegisterTimelineHandler(ITimelineHandler *pHandler) PURE
Registers an animation frame handler.
BOOL UnregisterTimelineHandler(ITimelineHandler *pHandler) PURE
Unregisters an animation frame handler.