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: layoutmanager with focus handling in 1D (next/previous) |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <alf/alfenv.h> |
|
20 #include <alf/alflayout.h> |
|
21 #include <alf/alflayoutmanager.h> |
|
22 #include <alf/alfexceptions.h> |
|
23 #include <alf/alfwidgetcontrol.h> |
|
24 #include <alf/ialfwidgetfactory.h> |
|
25 #include <alf/alfwidgetenvextension.h> |
|
26 #include <osn/ustring.h> |
|
27 #include <osn/osnnew.h> |
|
28 #include "alf/alfwidget.h" |
|
29 #include "alflayoutmanagerimpl.h" |
|
30 |
|
31 using osncore::UString; |
|
32 |
|
33 using namespace Alf; |
|
34 |
|
35 namespace Alf |
|
36 { |
|
37 |
|
38 // ======== MEMBER FUNCTIONS ======== |
|
39 |
|
40 // --------------------------------------------------------------------------- |
|
41 // layout manager constructor |
|
42 // --------------------------------------------------------------------------- |
|
43 // |
|
44 OSN_EXPORT AlfLayoutManager::AlfLayoutManager(TAlfLayoutType aLayoutType) |
|
45 { |
|
46 mData.reset(new (EMM) AlfLayoutManagerImpl(aLayoutType)); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // virtual destructor |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 OSN_EXPORT AlfLayoutManager::~AlfLayoutManager() |
|
54 { |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // returns the owner of the layoutmanager |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 OSN_EXPORT CAlfWidgetControl& AlfLayoutManager::owner() const |
|
62 { |
|
63 return mData->owner(); |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // returns the widget at index aIndex. |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 OSN_EXPORT CAlfWidgetControl* AlfLayoutManager::getControl(int aIndex) const |
|
71 { |
|
72 return mData->getControl(aIndex); |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------------------------- |
|
76 // returns the count of controls in the layoutmanager. |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 OSN_EXPORT int AlfLayoutManager::count() const |
|
80 { |
|
81 return mData->count(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // from IAlfLayoutManager |
|
86 // creates the layout used by this layoutmanager. |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 OSN_EXPORT void AlfLayoutManager::createLayout(CAlfWidgetControl& aOwner, |
|
90 CAlfLayout* aParentLayout, int aLayoutIndex) |
|
91 { |
|
92 mData->createLayout(aOwner, aParentLayout, aLayoutIndex); |
|
93 updateChildrenLayout(); |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // from IAlfLayoutManager |
|
98 // returns the layout used by this layoutmanager. |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 OSN_EXPORT CAlfLayout& AlfLayoutManager::getLayout() const |
|
102 { |
|
103 return mData->getLayout(); |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------------------------- |
|
107 // from IAlfLayoutManager |
|
108 // notifies the layout manager, that the child control's layout |
|
109 // must be updated. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 OSN_EXPORT void AlfLayoutManager::updateChildLayout( |
|
113 CAlfWidgetControl* aControl) |
|
114 { |
|
115 mData->getLayout(); //checks, that the layout exists, throws exception if not. |
|
116 doUpdateChildLayout( aControl ); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // from IAlfLayoutManager |
|
121 // notifies the layout manager, that all the child controls' layouts |
|
122 // must be updated. |
|
123 // --------------------------------------------------------------------------- |
|
124 // |
|
125 OSN_EXPORT void AlfLayoutManager::updateChildrenLayout() |
|
126 { |
|
127 CAlfLayout& layout = mData->getLayout(); |
|
128 mData->updateMainLayout(); |
|
129 |
|
130 // CAlfWidgetControl& container = mData->owner(); |
|
131 const int childrenCount = count(); |
|
132 |
|
133 // go through all the child controls, and update the layout |
|
134 for (int i = 0; i < childrenCount; i++) |
|
135 { |
|
136 doUpdateChildLayout(getControl(i)); |
|
137 } |
|
138 |
|
139 layout.UpdateChildrenLayout(); |
|
140 |
|
141 //doUpdateChildLayout changes the visual size and position. |
|
142 //need to notify all the widgets that size and position might have changed. |
|
143 mData->updateAllWidgetRects(); |
|
144 |
|
145 // Inform parent layout manager about the changed presentation size |
|
146 owner().updateParentLayout(); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // from IAlfLayoutManager |
|
151 // notifies the layout manager, that the control's has been |
|
152 // removed from the layout. |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 OSN_EXPORT void AlfLayoutManager::childRemoved(CAlfWidgetControl* aControl) |
|
156 { |
|
157 mData->childRemoved(aControl); |
|
158 } |
|
159 |
|
160 // --------------------------------------------------------------------------- |
|
161 // notifies the layout manager, that the child control's layout |
|
162 // must be updated. |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 OSN_EXPORT void AlfLayoutManager::doUpdateChildLayout( |
|
166 CAlfWidgetControl* aControl) |
|
167 { |
|
168 mData->doUpdateChildLayout(aControl); |
|
169 } |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // returns the size of the widget. |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 OSN_EXPORT bool AlfLayoutManager::controlRect( |
|
176 CAlfWidgetControl& aControl, TAlfRealRect& aRect) |
|
177 { |
|
178 return mData->controlRect(aControl, aRect); |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // sets the size and position of the widget. |
|
183 // --------------------------------------------------------------------------- |
|
184 // |
|
185 OSN_EXPORT void AlfLayoutManager::setControlRect( |
|
186 CAlfWidgetControl& aControl, const TAlfRealRect &aRect) |
|
187 { |
|
188 AlfWidget* widget = aControl.widget(); |
|
189 if (widget) |
|
190 { |
|
191 const char* name = widget->widgetName(); |
|
192 IAlfWidget* ownerwidget = AlfWidgetEnvExtension::widgetFactory(aControl.Env()).findWidget(name); |
|
193 if (ownerwidget) |
|
194 { |
|
195 mData->setWidgetRect(*ownerwidget, aRect); |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // sets the position of the widget. |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 OSN_EXPORT void AlfLayoutManager::setControlPosition( |
|
205 CAlfWidgetControl& aControl, const TAlfRealPoint& aPos) |
|
206 { |
|
207 AlfWidget* widget = aControl.widget(); |
|
208 if (widget) |
|
209 { |
|
210 const char* name = widget->widgetName(); |
|
211 IAlfWidget* ownerwidget = AlfWidgetEnvExtension::widgetFactory(aControl.Env()).findWidget(name); |
|
212 if (ownerwidget) |
|
213 { |
|
214 mData->setWidgetPosition(*ownerwidget, aPos); |
|
215 } |
|
216 } |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // sets the size of the widget. |
|
221 // --------------------------------------------------------------------------- |
|
222 // |
|
223 OSN_EXPORT void AlfLayoutManager::setControlSize( |
|
224 CAlfWidgetControl& aControl, const TAlfRealPoint &aSize) |
|
225 { |
|
226 AlfWidget* widget = aControl.widget(); |
|
227 if (widget) |
|
228 { |
|
229 const char* name = widget->widgetName(); |
|
230 IAlfWidget* ownerwidget = AlfWidgetEnvExtension::widgetFactory(aControl.Env()).findWidget(name); |
|
231 if (ownerwidget) |
|
232 { |
|
233 mData->setWidgetSize(*ownerwidget, aSize); |
|
234 } |
|
235 } |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // returns layout preferences for aControl |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 OSN_EXPORT const IAlfLayoutPreferences* AlfLayoutManager::getLayoutPreferences( |
|
243 CAlfWidgetControl* aControl) const |
|
244 { |
|
245 return mData->getLayoutPreferences(aControl); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // From class IAlfInterfaceBase. |
|
250 // Getter for interfaces provided by the element. |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 OSN_EXPORT IAlfInterfaceBase* AlfLayoutManager::makeInterface( |
|
254 const IfId& aType ) |
|
255 { |
|
256 UString param(aType.mImplementationId); |
|
257 if (param == IAlfLayoutManager::type().mImplementationId) |
|
258 { |
|
259 return static_cast<IAlfLayoutManager*>(this); |
|
260 } |
|
261 |
|
262 |
|
263 // Let the implementation class try the interface creation |
|
264 return mData->makeInterface(aType); |
|
265 } |
|
266 } // Alf |
|