|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Viewport visual. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "uiacceltk/huiviewportlayout.h" // Class definition |
|
21 |
|
22 #include <uiacceltk/HuiControl.h> |
|
23 #include <uiacceltk/HuiUtil.h> |
|
24 |
|
25 |
|
26 EXPORT_C CHuiViewportLayout* CHuiViewportLayout::AddNewL(CHuiControl& aOwnerControl, CHuiLayout* aParentLayout) |
|
27 { |
|
28 CHuiViewportLayout* layout = new (ELeave) CHuiViewportLayout(aOwnerControl); |
|
29 CleanupStack::PushL(layout); |
|
30 layout->ConstructL(); |
|
31 aOwnerControl.AppendL(layout, aParentLayout); |
|
32 CleanupStack::Pop(layout); |
|
33 return layout; |
|
34 } |
|
35 |
|
36 |
|
37 CHuiViewportLayout::CHuiViewportLayout(MHuiVisualOwner& aOwner) |
|
38 : CHuiLayout(aOwner) |
|
39 { |
|
40 iVirtualSize = THuiRealSize(1.0f, 1.0f); |
|
41 iViewportSize = THuiRealSize(1.0f, 1.0f); |
|
42 iViewportPos = THuiRealPoint(0.0f, 0.0f); |
|
43 |
|
44 iWrappingFlags = 0; |
|
45 } |
|
46 |
|
47 |
|
48 void CHuiViewportLayout::ConstructL() |
|
49 { |
|
50 CHuiLayout::ConstructL(); |
|
51 SetClipping(ETrue); |
|
52 } |
|
53 |
|
54 CHuiViewportLayout::~CHuiViewportLayout() |
|
55 { |
|
56 } |
|
57 |
|
58 EXPORT_C void CHuiViewportLayout::SetVirtualSize(const THuiRealSize& aSize, TInt aTransitionTime) |
|
59 { |
|
60 if ( !HuiUtil::RealCompare( iVirtualSize.iHeight, aSize.iHeight ) || |
|
61 !HuiUtil::RealCompare( iVirtualSize.iWidth, aSize.iWidth ) ) |
|
62 { |
|
63 iVirtualSize = aSize; |
|
64 |
|
65 UpdateChildrenLayout(aTransitionTime); |
|
66 |
|
67 SetChanged(); |
|
68 } |
|
69 } |
|
70 |
|
71 |
|
72 EXPORT_C void CHuiViewportLayout::SetViewportSize(const THuiRealSize& aSize, TInt aTransitionTime) |
|
73 { |
|
74 // Divide by zero will be caught later. |
|
75 if ( !HuiUtil::RealCompare( iViewportSize.iHeight, aSize.iHeight ) || |
|
76 !HuiUtil::RealCompare( iViewportSize.iWidth, aSize.iWidth ) ) |
|
77 { |
|
78 iViewportSize = aSize; |
|
79 |
|
80 UpdateChildrenLayout(aTransitionTime); |
|
81 |
|
82 SetChanged(); |
|
83 } |
|
84 } |
|
85 |
|
86 EXPORT_C void CHuiViewportLayout::SetViewportPos(const THuiRealPoint& aPos, TInt aTransitionTime) |
|
87 { |
|
88 if ( !HuiUtil::RealCompare( iViewportPos.iY, aPos.iY ) || |
|
89 !HuiUtil::RealCompare( iViewportPos.iX, aPos.iX ) ) |
|
90 { |
|
91 iViewportPos = aPos; |
|
92 |
|
93 UpdateChildrenLayout(aTransitionTime); |
|
94 |
|
95 SetChanged(); |
|
96 } |
|
97 } |
|
98 |
|
99 void CHuiViewportLayout::SetSize(const THuiRealSize& aSize, TInt aTransitionTime) |
|
100 { |
|
101 CHuiLayout::SetSize(aSize, aTransitionTime); |
|
102 UpdateChildrenLayout(aTransitionTime); |
|
103 } |
|
104 |
|
105 |
|
106 TBool CHuiViewportLayout::ChildSize(TInt /*aOrdinal*/, TSize& aSize) |
|
107 { |
|
108 THuiRealSize mysize = Size().Target().AsSize(); |
|
109 |
|
110 if ((iViewportSize.iWidth == 0.0) || (iViewportSize.iHeight == 0.0)) |
|
111 { |
|
112 // Could not obtain new size because of divide by zero error. |
|
113 return EFalse; |
|
114 } |
|
115 |
|
116 aSize.iWidth = HUI_ROUND_FLOAT_TO_INT((iVirtualSize.iWidth / iViewportSize.iWidth) * mysize.iWidth); |
|
117 aSize.iHeight = HUI_ROUND_FLOAT_TO_INT((iVirtualSize.iHeight / iViewportSize.iHeight) * mysize.iHeight); |
|
118 |
|
119 return ETrue; |
|
120 } |
|
121 |
|
122 |
|
123 TBool CHuiViewportLayout::ChildPos(TInt /*aOrdinal*/, TPoint& aPos) |
|
124 { |
|
125 THuiRealSize mysize = Size().RealTarget().AsSize(); |
|
126 |
|
127 if ((iViewportSize.iWidth == 0.0) || (iViewportSize.iHeight == 0.0)) |
|
128 { |
|
129 // Could not obtain new size because of divide by zero error. |
|
130 return EFalse; |
|
131 } |
|
132 |
|
133 aPos.iX = HUI_ROUND_FLOAT_TO_INT( -iViewportPos.iX * mysize.iWidth / iViewportSize.iWidth ); |
|
134 aPos.iY = HUI_ROUND_FLOAT_TO_INT( -iViewportPos.iY * mysize.iHeight / iViewportSize.iHeight ); |
|
135 |
|
136 return ETrue; |
|
137 } |
|
138 |
|
139 EXPORT_C TInt CHuiViewportLayout::ChildRect(TInt /*aOrdinal*/, THuiRealRect& /*aPos*/) |
|
140 { |
|
141 return THuiLayoutChildRectNotImplemented; |
|
142 } |