soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SStackView.cpp
1#include <souistd.h>
3
4SNSBEGIN
5
7 : m_iSel(-2)
8 , m_animator(this)
9 , m_aniStyle(kAniNone)
10 , m_bVertAni(FALSE)
11 , m_isSamePageSize(TRUE)
12{
13 m_bClipClient = true;
14 m_animator.addListener(this);
15}
16
20
21BOOL SStackView::SelectPage(int iSel, BOOL enableAnimate)
22{
23 if (iSel < -2 || iSel >= (int)GetChildrenCount())
24 {
25 return FALSE;
26 }
27 if (m_animator.isStarted())
28 m_animator.end();
29 if (iSel == m_iSel)
30 return TRUE;
31 if (!IsVisible(TRUE))
32 enableAnimate = FALSE;
33 if (m_iSel == -2)
34 {
35 for (UINT i = 0; i < GetChildrenCount(); i++)
36 {
37 IWindow *pChild = GetPage(i);
38 pChild->SetVisible(FALSE, FALSE);
39 }
40 Invalidate();
41 }
42 m_animator.SetFrom(m_iSel);
43 m_animator.SetTo(iSel);
44 m_iSel = iSel;
45 if (m_iSel != -2)
46 {
48 {
49 CRect rcLayout;
50 GetChildrenLayoutRect(&rcLayout);
51 IWindow *pPage = GetSelPage();
52 if (pPage)
53 {
54 CSize szPage = GetChildSize(pPage);
55 m_animator.SetOwnerSizeRange(rcLayout.Size(), szPage);
56 }
57 }
58 else
59 {
60 m_animator.DisableOwnerResize();
61 }
62 m_animator.start(GetContainer());
63 if (!enableAnimate)
64 {
65 m_animator.end();
66 }
67 }
68 else
69 {
70 for (UINT i = 0; i < GetChildrenCount(); i++)
71 {
72 IWindow *pChild = GetPage(i);
73 pChild->SetVisible(TRUE, FALSE);
74 }
75 Invalidate();
76 }
77 return TRUE;
78}
79
80IWindow *SStackView::GetSelPage(CTHIS) const
81{
82 if (m_iSel < 0)
83 return NULL;
84 return GetPage(m_iSel);
85}
86
87IWindow *SStackView::GetPage(CTHIS_ int iPage) const
88{
89 if (iPage < 0 || iPage >= (int)m_childs.GetCount())
90 return NULL;
91 return m_childs[iPage];
92}
93
95{
96 CRect rc;
98 if (m_animator.isRunning())
99 {
100 m_animator.OnNextFrame();
101 if (m_animator.GetAniStyle() == kFadeInOut)
102 {
103 IWindow *pFrom = GetPage(m_animator.GetFrom());
104 if (pFrom)
105 {
106 CSize szPage = GetChildSize(pFrom);
107 pFrom->Move(CRect(rc.TopLeft(), szPage));
108 }
109 IWindow *pTo = GetPage(m_animator.GetTo());
110 if (pTo)
111 {
112 CSize szPage = GetChildSize(pTo);
113 pTo->Move(CRect(rc.TopLeft(), szPage));
114 }
115 }
116 return;
117 }
118 if (m_iSel == -2)
119 {
120 for (UINT i = 0; i < m_childs.GetCount(); i++)
121 {
122 CSize szPage = GetChildSize(m_childs[i]);
123 CRect rcPage(rc.TopLeft(), szPage);
124 m_childs[i]->Move(&rcPage);
125 }
126 }
127 else
128 {
129 IWindow *pPage = GetSelPage();
130 if (pPage)
131 {
132 pPage->Move(&rc);
133 }
134 }
135}
136
138{
139 m_animator.end();
140 __baseCls::OnDestroy();
141}
142
144{
145 m_animator.end();
146 __baseCls::OnContainerChanged(pOldContainer, pNewContainer);
147}
148
149void SStackView::OnSize(UINT nType, CSize size)
150{
151 __baseCls::OnSize(nType, size);
152 m_animator.OnOwnerResize();
153}
154
155void SStackView::onAnimationEnd(THIS_ IValueAnimator *pAnimator)
156{
157 SASSERT(m_iSel != -2);
158 IWindow *pFrom = GetPage(m_animator.GetFrom());
159 if (pFrom)
160 pFrom->SetVisible(FALSE, TRUE);
161}
162
163void SStackView::SetAniStyle(THIS_ StackViewAniStyle aniStyle)
164{
165 m_aniStyle = aniStyle;
166}
167
168void SStackView::SetAniDir(THIS_ BOOL bVert)
169{
170 m_bVertAni = bVert;
171}
172
173SIZE SStackView::MeasureChildren(int nParentWid, int nParentHei)
174{
175 if (!m_isSamePageSize)
176 {
177 if (m_animator.isRunning())
178 {
179 return m_animator.GetOwnerSize();
180 }
181 else
182 {
183 IWindow *pPage = GetSelPage();
184 SIZE szRet = { 0 };
185 pPage->GetDesiredSize(&szRet, nParentWid, nParentHei);
186 return szRet;
187 }
188 }
189 else
190 {
191 SIZE ret = { 0 };
193 BOOL getSize = FALSE;
194 while (pChild)
195 {
196 if (!pChild->GetLayoutParam()->IsMatchParent(Both))
197 {
198 SIZE szChild;
199 pChild->GetDesiredSize(&szChild, nParentWid, nParentHei);
200 if (ret.cx < szChild.cx)
201 ret.cx = szChild.cx;
202 if (ret.cy < szChild.cy)
203 ret.cy = szChild.cy;
204 getSize = TRUE;
205 }
206 pChild = pChild->GetWindow(GSW_NEXTSIBLING);
207 }
208 if (!getSize)
209 {
211 if (pChild)
212 {
213 pChild->GetDesiredSize(&ret, nParentWid, nParentHei);
214 }
215 }
216 return ret;
217 }
218}
219
221{
222 BOOL bRet = __baseCls::CreateChildren(xmlNode);
223 if (!bRet)
224 return FALSE;
225 if (m_iSel != -2)
226 {
227 int idx = 0;
229 while (pChild)
230 {
231 pChild->SetVisible(idx == m_iSel);
232 pChild = pChild->GetWindow(GSW_NEXTSIBLING);
233 idx++;
234 }
235 }
236 BuildChildsArray(FALSE);
237 return TRUE;
238}
239
241{
242 // set default size to match parent
243 if (m_isLoading)
244 return;
245
246 BuildChildsArray(TRUE);
247}
248
250{
251 BuildChildsArray(TRUE);
252}
253
255{
256 if (m_animator.isStarted())
257 m_animator.end();
258 IWindow *pSel = GetSelPage();
259 int nChilds = GetChildrenCount();
260 m_childs.SetCount(nChilds);
261 int iSel = -1;
263 for (int i = 0; i < nChilds; i++)
264 {
265 SASSERT(pChild);
266 m_childs[i] = pChild;
267 if (pSel == pChild)
268 iSel = i;
269 pChild = pChild->GetWindow(GSW_NEXTSIBLING);
270 }
271 if (updateSel)
272 {
273 if (iSel != -1)
274 {
275 m_iSel = iSel;
276 }
277 else if (m_iSel >= 0)
278 {
279 m_iSel = -1;
280 }
281 }
282}
283
284IWindow *SStackView::GetIChild(THIS_ int iChild) const
285{
286 if (iChild < 0 || iChild > (int)m_childs.GetCount())
287 return NULL;
288 if (iChild == 0)
289 return (IWindow *)this;
290 return m_childs[iChild - 1];
291}
292
293StackViewAniStyle SStackView::GetChildAnimateStyle(int iChild) const
294{
295 IWindow *pChild = GetPage(iChild);
296 if (!pChild)
297 return kAniNone;
298 SStackPage *pPage = sobj_cast<SStackPage>(pChild);
299 if (pPage)
300 return pPage->GetAnimateStyle();
301 else
302 return m_aniStyle;
303}
304
305BOOL SStackView::IsVertChildAnimate(int iChild) const
306{
307 IWindow *pChild = GetPage(iChild);
308 if (!pChild)
309 return FALSE;
310 SStackPage *pPage = sobj_cast<SStackPage>(pChild);
311 if (pPage)
312 return pPage->IsVertAnimate();
313 else
314 return m_bVertAni;
315}
316
317CSize SStackView::GetChildSize(IWindow *pPage) const
318{
319 CRect rc;
321 CSize szPage = rc.Size();
322 if (!m_isSamePageSize)
323 {
324 ILayoutParam *pLayoutParam = GetLayoutParam();
325 SASSERT(pPage);
326 if (pLayoutParam->IsWrapContent(Any))
327 {
328 int nParentWid = -1, nParentHei = -1;
329 if (!pLayoutParam->IsWrapContent(Horz))
330 nParentWid = rc.Width();
331 if (!pLayoutParam->IsWrapContent(Vert))
332 nParentHei = rc.Height();
333 pPage->GetDesiredSize(&szPage, nParentWid, nParentHei);
334 }
335 }
336 return szPage;
337}
338
339//////////////////////////////////////////////////////////////////////////
340void SViewSwitchAnimator::start(THIS_ ITimelineHandlersMgr *pTimerlineMgr)
341{
342 if (isStarted())
343 end();
344 CRect rc;
345 m_pOwner->GetChildrenLayoutRect(&rc);
346 m_pFrom = m_pOwner->GetPage(m_iFrom);
347 m_pTo = m_pOwner->GetPage(m_iTo);
348 if (m_pTo)
349 {
350 m_pTo->SetVisible(TRUE, FALSE);
351 }
352 m_aniStyle = m_pOwner->GetChildAnimateStyle(m_iTo);
353 m_bVertAni = m_pOwner->IsVertChildAnimate(m_iTo);
354
355 if (m_aniStyle != kFadeInOut && m_aniStyle != kAniNone)
356 {
357 if (m_pTo)
358 m_pTo->SetAlpha(255);
359 if (m_pFrom)
360 m_pFrom->SetAlpha(255);
361 }
362 else
363 {
364 if (m_pTo)
365 m_pTo->Move(rc);
366 }
368 __baseCls::start(pTimerlineMgr);
369 if (m_aniStyle == kAniNone)
370 {
371 // end it right now.
372 __baseCls::end();
373 }
374}
375
376void SViewSwitchAnimator::onEvaluateValue(THIS_ float fraction)
377{
378 if (m_isOwnerResize)
379 {
380 m_pOwner->RequestRelayout();
381 }
382 if (m_aniStyle == kAniNone)
383 return;
384 if (m_aniStyle == kFadeInOut)
385 {
386 BYTE a = m_evalAlphaFrom.evaluate(fraction);
387 if (m_pFrom)
388 m_pFrom->SetAlpha(a);
389 BYTE a2 = m_evalAlphaTo.evaluate(fraction);
390 if (m_pTo)
391 m_pTo->SetAlpha(a2);
392 }
393 else
394 {
395 RECT rc1 = m_evalRcFrom.evaluate(fraction);
396 if (m_pFrom)
397 m_pFrom->Move(&rc1);
398 RECT rc2 = m_evalRcTo.evaluate(fraction);
399 if (m_pTo)
400 {
401 m_pTo->Move(&rc2);
402 }
403 }
404}
405
407{
408 if (!isStarted())
409 return;
411}
412
414{
415 CRect rc;
416 m_pOwner->GetChildrenLayoutRect(&rc);
417
418 if (m_aniStyle == kFadeInOut)
419 {
420 m_evalAlphaFrom.setRange(255, 0);
421 m_evalAlphaTo.setRange(0, 255);
422 }
423 else if (m_aniStyle == kMoveInOut)
424 {
425 if (m_bVertAni)
426 {
427 if (m_iFrom < m_iTo)
428 {
429 // to => from => hide
430 CRect rc2 = rc;
431 rc2.top = rc2.bottom;
432 m_evalRcFrom.setRange(rc, rc2);
433 CRect rc3 = rc;
434 rc3.bottom = rc3.top;
435 m_evalRcTo.setRange(rc3, rc);
436 }
437 else
438 {
439 // hide <= from <= to
440 CRect rc2 = rc;
441 rc2.bottom = rc2.top;
442 m_evalRcFrom.setRange(rc, rc2);
443 CRect rc3 = rc;
444 rc3.top = rc3.bottom;
445 m_evalRcTo.setRange(rc3, rc);
446 }
447 }
448 else
449 {
450 if (m_iFrom < m_iTo)
451 {
452 // to => from => hide
453 CRect rc2 = rc;
454 rc2.left = rc2.right;
455 m_evalRcFrom.setRange(rc, rc2);
456 CRect rc3 = rc;
457 rc3.right = rc3.left;
458 m_evalRcTo.setRange(rc3, rc);
459 }
460 else
461 {
462 // hide <= from <= to
463 CRect rc2 = rc;
464 rc2.right = rc2.left;
465 m_evalRcFrom.setRange(rc, rc2);
466 CRect rc3 = rc;
467 rc3.left = rc3.right;
468 m_evalRcTo.setRange(rc3, rc);
469 }
470 }
471 }
472 else if (m_aniStyle == kPushInOut)
473 {
474 if (m_bVertAni)
475 {
476 if (m_iFrom < m_iTo)
477 {
478 CRect rc2 = rc;
479 rc2.OffsetRect(0, rc.Height());
480 m_evalRcFrom.setRange(rc, rc2);
481 CRect rc3 = rc;
482 rc3.OffsetRect(0, -rc.Height());
483 m_evalRcTo.setRange(rc3, rc);
484 }
485 else
486 {
487 CRect rc2 = rc;
488 rc2.OffsetRect(0, -rc.Height());
489 m_evalRcFrom.setRange(rc, rc2);
490 CRect rc3 = rc;
491 rc3.OffsetRect(0, rc.Height());
492 m_evalRcTo.setRange(rc3, rc);
493 }
494 }
495 else
496 {
497 if (m_iFrom < m_iTo)
498 {
499 CRect rc2 = rc;
500 rc2.OffsetRect(rc.Width(), 0);
501 m_evalRcFrom.setRange(rc, rc2);
502 CRect rc3 = rc;
503 rc3.OffsetRect(-rc.Width(), 0);
504 m_evalRcTo.setRange(rc3, rc);
505 }
506 else
507 {
508 CRect rc2 = rc;
509 rc2.OffsetRect(-rc.Width(), 0);
510 m_evalRcFrom.setRange(rc, rc2);
511 CRect rc3 = rc;
512 rc3.OffsetRect(rc.Width(), 0);
513 m_evalRcTo.setRange(rc3, rc);
514 }
515 }
516 }
517}
518
519void SViewSwitchAnimator::SetOwnerSizeRange(SIZE szFrom, SIZE szTo)
520{
521 m_evalOwnerSize.setRange(szFrom, szTo);
522 m_isOwnerResize = szFrom.cx != szTo.cx || szFrom.cy != szTo.cy;
523}
524
526{
527 return m_evalOwnerSize.evaluate(getAnimatedFraction());
528}
529
530SNSEND
Definition of the SStackView and related classes.
@ GSW_FIRSTCHILD
Definition SWnd.h:195
@ GSW_NEXTSIBLING
Definition SWnd.h:198
A page within a stack view.
Definition SStackView.h:173
BOOL IsVertAnimate() const
Checks if vertical animation is enabled.
Definition SStackView.h:200
StackViewAniStyle GetAnimateStyle() const
Gets the animation style.
Definition SStackView.h:191
BOOL IsVertChildAnimate(int iChild) const
Checks if vertical animation is enabled for a child.
SIZE MeasureChildren(int nParentWid, int nParentHei) override
Measures the size of child windows.
IWindow * GetIChild(int iChild) SCONST OVERRIDE
Gets a child window by index.
void OnSize(UINT nType, CSize size)
Handles the size change of the window.
void OnDestroy()
Handles the destruction of the window.
SViewSwitchAnimator m_animator
Definition SStackView.h:412
BOOL m_bVertAni
Definition SStackView.h:415
IWindow * GetSelPage() SCONST OVERRIDE
Gets the selected page.
void BuildChildsArray(BOOL updateSel)
Builds the array of child windows.
BOOL SelectPage(int iView, BOOL enableAnimate=TRUE) OVERRIDE
Selects a page.
StackViewAniStyle GetChildAnimateStyle(int iChild) const
Gets the animation style of a child.
~SStackView(void)
Destructor for SStackView.
StackViewAniStyle m_aniStyle
Definition SStackView.h:416
BOOL CreateChildren(SXmlNode xmlNode) override
Creates child windows from an XML node.
SArray< SWindow * > m_childs
Definition SStackView.h:413
void OnContainerChanged(ISwndContainer *pOldContainer, ISwndContainer *pNewContainer) override
Handles the change of the container.
void OnAfterRemoveChild(SWindow *pChild) override
Handles the removal of a child window.
void SetAniStyle(StackViewAniStyle aniStyle) OVERRIDE
Sets the animation style.
void OnAfterInsertChild(SWindow *pChild) override
Handles the insertion of a child window.
SStackView(void)
Constructor for SStackView.
Definition SStackView.cpp:6
CSize GetChildSize(IWindow *pPage) const
Gets the size of a child window.
BOOL m_isSamePageSize
Definition SStackView.h:417
IWindow * GetPage(int iPage) SCONST OVERRIDE
Gets a page by index.
void onAnimationEnd(IValueAnimator *pAnimator) OVERRIDE
Handles the end of an animation.
void SetAniDir(BOOL bVert) OVERRIDE
Sets the animation direction.
void UpdateChildrenPosition() OVERRIDE
Updates the positions of child windows.
BOOL isStarted() SCONST OVERRIDE
Checks if the animation has been started.
float getAnimatedFraction() SCONST OVERRIDE
Returns the current animation fraction.
void end() OVERRIDE
Ends the animation.
void initEvaluator()
Initializes the evaluators.
void onEvaluateValue(float fraction) OVERRIDE
Evaluates the value at a given fraction.
StackViewAniStyle m_aniStyle
Definition SStackView.h:156
void start(ITimelineHandlersMgr *pTimerlineMgr) OVERRIDE
Starts the animation.
TypeEvaluator< SIZE > m_evalOwnerSize
Definition SStackView.h:163
void SetOwnerSizeRange(SIZE szFrom, SIZE szTo)
Sets the owner size range.
SStackView * m_pOwner
Definition SStackView.h:153
TypeEvaluator< RECT > m_evalRcTo
Definition SStackView.h:161
SAutoRefPtr< IWindow > m_pFrom
Definition SStackView.h:158
void OnOwnerResize()
Handles owner resize.
SAutoRefPtr< IWindow > m_pTo
Definition SStackView.h:159
SIZE GetOwnerSize() const
Gets the owner size.
TypeEvaluator< BYTE > m_evalAlphaTo
Definition SStackView.h:162
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Retrieves the desired size of the window.
Definition Swnd.cpp:1839
void SetVisible(BOOL bVisible, BOOL bUpdate=FALSE) OVERRIDE
Sets the visibility of the window.
Definition Swnd.cpp:655
BOOL m_isLoading
Definition SWnd.h:2614
UINT GetChildrenCount() SCONST OVERRIDE
Retrieves the number of child windows.
Definition Swnd.cpp:533
BOOL IsVisible(BOOL bCheckParent=FALSE) SCONST OVERRIDE
Checks if the window is visible.
Definition Swnd.cpp:646
ISwndContainer * GetContainer() OVERRIDE
Retrieves the container associated with this window.
Definition Swnd.cpp:679
void GetChildrenLayoutRect(RECT *prc) SCONST OVERRIDE
Retrieves the layout rectangle of the children.
Definition Swnd.cpp:2181
SWindow()
Constructor.
Definition Swnd.cpp:104
ILayoutParam * GetLayoutParam() SCONST OVERRIDE
Retrieves the layout parameter object associated with the window.
Definition SWnd.h:405
SWindow * GetWindow(int uCode) const
Retrieves a window based on a given code.
Definition Swnd.cpp:3456
void Invalidate() OVERRIDE
Invalidates the entire window.
Definition Swnd.cpp:1437
BOOL m_bClipClient
Definition SWnd.h:2607
Class representing an XML node.
Definition SXml.h:352
SOUI Window Container Interface.