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: The base class for all widgets. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef ALFWIDGET_H |
|
20 #define ALFWIDGET_H |
|
21 |
|
22 #include <osn/osndefines.h> |
|
23 #include <alf/ialfwidget.h> |
|
24 #include <memory> |
|
25 #include <osn/ustring.h> |
|
26 #include "alf/ialfcontainerwidget.h" |
|
27 #include <alf/alfwidgetcontrol.h> |
|
28 |
|
29 #include <vector> |
|
30 |
|
31 |
|
32 class CAlfEnv; |
|
33 class CAlfDisplay; |
|
34 |
|
35 namespace osncore |
|
36 { |
|
37 template <class T> class AlfPtrVector; |
|
38 } |
|
39 |
|
40 using namespace std; |
|
41 using namespace osncore; |
|
42 |
|
43 |
|
44 namespace Alf |
|
45 { |
|
46 |
|
47 //class CAlfWidgetControl; |
|
48 class IAlfModel; |
|
49 class IAlfWidgetFactory; |
|
50 class AlfWidgetImpl; |
|
51 |
|
52 |
|
53 /** |
|
54 * @class AlfWidget alfwidget.h "alf/alfwidget.h" |
|
55 * The base class for widgets. |
|
56 * @see IAlfWidget IAlfContainerWidget IAlfHostApi |
|
57 * |
|
58 * @lib alfwidgetmodel.lib |
|
59 * @since S60 ?S60_version |
|
60 * @status Draft |
|
61 * @interfaces IAlfWidget,IAlfAttributeOwner,IAlfContainerWidget,IAlfWidgetControl,IAlfHostAPI, |
|
62 * All interfaces returned by the elements associated with the widget's control, |
|
63 * All interfaces returned by the layout manager associated widget control , |
|
64 * All interfaces returned by the model assoiated with the widget. |
|
65 */ |
|
66 class AlfWidget : public IAlfContainerWidget |
|
67 { |
|
68 public: |
|
69 /** |
|
70 * Constructor. |
|
71 * |
|
72 * This will create a default control to the widget to enable the widget |
|
73 * containment hierarchy from the beginning. User can replace the default |
|
74 * control with custom control by calling the setControl() - method. |
|
75 * @exception std::bad_alloc |
|
76 * |
|
77 * @see setControl() |
|
78 * |
|
79 * @param aWidgetName The name of the widget. |
|
80 * @param aContainer Container widget that will contain this widget. |
|
81 * @param aEnv Toolkit environment object that will be used to create the |
|
82 * default control. |
|
83 */ |
|
84 OSN_IMPORT AlfWidget(const char* aWidgetName, IAlfContainerWidget& aContainer, CAlfEnv& aEnv); |
|
85 |
|
86 /** |
|
87 * Constructor to be used only by view widget. |
|
88 * All the other widgets should use the other public constructor to ensure |
|
89 * widget hierarchy consistency from start. |
|
90 * @exception std::bad_alloc |
|
91 * |
|
92 * @see AlfWidget(const char*, IAlfContainerWidget&, CAlfEnv&) |
|
93 * |
|
94 * @param aWidgetName The name of the widget. |
|
95 */ |
|
96 OSN_IMPORT AlfWidget(const char* aWidgetName); |
|
97 |
|
98 /** |
|
99 * Destructor. |
|
100 * |
|
101 * It also takes care that all the child widgets contained by this widget |
|
102 * are destroyed correctly, provided that they have been instantiated correctly |
|
103 * (e.g. through widget factory) and thus added to the ALF environment (CAlfEnv). |
|
104 * |
|
105 * In other words, client code does not need to take care of destroying the child |
|
106 * widgets contained by a container widget. |
|
107 */ |
|
108 OSN_IMPORT virtual ~AlfWidget(); |
|
109 |
|
110 /** |
|
111 * Constructor. The new widget is left on the cleanup stack. |
|
112 * |
|
113 * @since S60 ?S60_version |
|
114 * @param aWidgetName The name of the widget. |
|
115 * @return New object. The widgets are owned by Alfred. |
|
116 */ |
|
117 OSN_IMPORT CAlfWidgetControl* control() const; |
|
118 |
|
119 /** |
|
120 * Getter for the parent container. The ownership is not passed. |
|
121 * |
|
122 * @return the parent container or 0 if the widget is the root-widget. |
|
123 */ |
|
124 OSN_IMPORT IAlfContainerWidget* parent() const; |
|
125 |
|
126 /** |
|
127 * Sets new widget control to this widget. |
|
128 * @exception osncore::AlfException Thrown with error code osncore::EInvalidArgument if aControl is |
|
129 * alreasy associated with another widget. |
|
130 * @see IAlfWidget::setControl() |
|
131 * |
|
132 * @since S60 ?S60_version |
|
133 * @param aControl Control to be set to the widget. |
|
134 * @param aDeletePreviousControl If true, the previous widget control is destroyed. |
|
135 */ |
|
136 OSN_IMPORT void setControl(CAlfWidgetControl* aControl, bool aDeletePreviousControl = true); |
|
137 |
|
138 /** |
|
139 * Constructor. The new widget is left on the cleanup stack. |
|
140 * |
|
141 * @since S60 ?S60_version |
|
142 * @param aWidgetName The name of the widget. |
|
143 * @return New object. The widgets are owned by Alfred. |
|
144 */ |
|
145 OSN_IMPORT IAlfModel* model(); |
|
146 |
|
147 /** |
|
148 * Sets the model for the Widget. |
|
149 * |
|
150 * @since S60 ?S60_version |
|
151 * @param aModel Model to be set to this widget. |
|
152 * @param aTakeOwnership Whether takes ownership or not. |
|
153 */ |
|
154 OSN_IMPORT void setModel( IAlfModel* aModel,bool aTakeOwnerShip=true ); |
|
155 |
|
156 /** |
|
157 * Constructor. The new widget is left on the cleanup stack. |
|
158 * |
|
159 * @since S60 ?S60_version |
|
160 * @param aWidgetName The name of the widget. |
|
161 * @return New object. The widgets are owned by Alfred. |
|
162 */ |
|
163 OSN_IMPORT const char* widgetName() const; |
|
164 |
|
165 //From IAlfInterfaceBase |
|
166 /** |
|
167 * Getter for interfaces provided by the widget, the control, |
|
168 * or the model. |
|
169 * |
|
170 * @since S60 ?S60_version |
|
171 * @param aWidget The widget to get the interface for. |
|
172 * @param aType The type id of the queried interface. |
|
173 * @return The queried interface, or NULL if the interface is not |
|
174 * supported or available. |
|
175 */ |
|
176 OSN_IMPORT static IAlfInterfaceBase* makeInterface( AlfWidget* aWidget, const IfId& aType ); |
|
177 |
|
178 /** |
|
179 * Template getter for interfaces provided by the widget, the control, |
|
180 * or the model. The type of the queried interface is specified by the |
|
181 * template parameter. |
|
182 * |
|
183 * @since S60 ?S60_version |
|
184 * @param aWidget The widget to get the interface for. |
|
185 * @return The queried interface, or NULL if the interface is not |
|
186 * supported or available. |
|
187 */ |
|
188 template <class T> |
|
189 static T* makeInterface( AlfWidget* aWidget ); |
|
190 |
|
191 // from base class IAlfInterfaceBase |
|
192 |
|
193 /** |
|
194 * From IAlfInterfaceBase. |
|
195 * Getter for interfaces provided by the widget classes. |
|
196 * Derived classes should always call the base class method |
|
197 * from the overridden MakeInterface. |
|
198 * |
|
199 * @since S60 ?S60_version |
|
200 * @param aType A descriptor to identify the type of the queried interface. |
|
201 * @return The queried interface, or NULL if the interface is not |
|
202 * supported or available. |
|
203 */ |
|
204 OSN_IMPORT virtual IAlfInterfaceBase* makeInterface( const IfId& aType ); |
|
205 |
|
206 // from base class IAlfContainerWidget |
|
207 |
|
208 /** |
|
209 * Returns total number of widgets contained by this container. |
|
210 * |
|
211 * @return int Total number of widgets. |
|
212 */ |
|
213 OSN_IMPORT int widgetCount() const; |
|
214 |
|
215 /** |
|
216 * Adds a child widget to the container. |
|
217 * |
|
218 * @param aWidget Child widget to be added to container. |
|
219 * return void |
|
220 */ |
|
221 OSN_IMPORT void addWidget(IAlfWidget& aWidget); |
|
222 |
|
223 /** |
|
224 * Returns child widget at given index.If index is not found return null. |
|
225 * |
|
226 * @param aIndex Index of widget to be returned. |
|
227 * @return Widget at given index |
|
228 */ |
|
229 OSN_IMPORT IAlfWidget* getWidget(int aIndex) const; |
|
230 |
|
231 /** |
|
232 * Returns the child index, when given the child widget. |
|
233 * |
|
234 * @param aWidget child widget, which index is returned |
|
235 * @return the index of the child widget, or -1, if widget is not child of this container. |
|
236 */ |
|
237 OSN_IMPORT int getWidgetIndex(IAlfWidget& aWidget) const; |
|
238 |
|
239 /** |
|
240 * Removes the child widget from given index. |
|
241 * |
|
242 * @param aIndex Index from which widget has to be removed. |
|
243 * return void |
|
244 */ |
|
245 void removeWidget(int aIndex); |
|
246 |
|
247 /** |
|
248 * Sets the base layout of container widget. |
|
249 * |
|
250 * @param aLayout New base layout of container widget. |
|
251 * return void |
|
252 */ |
|
253 OSN_IMPORT void applyLayout(IAlfLayoutManager& aLayout); |
|
254 |
|
255 //from IAlfWidget |
|
256 |
|
257 /** |
|
258 * Sets/Releases the Focus from child widget of container. |
|
259 * Does not set the actual focused status in roster. |
|
260 * |
|
261 * @since S60 ?S60_version |
|
262 * @param aFocus boolean value for focused status |
|
263 * return void |
|
264 */ |
|
265 OSN_IMPORT void setChildFocus(bool aFocus); |
|
266 |
|
267 /** |
|
268 * Removes the given widget from this widget's child widget |
|
269 * array. Does not modify control connections or control |
|
270 * group containment. |
|
271 * |
|
272 * Does nothing if the given widget is not found from |
|
273 * widget array. |
|
274 * |
|
275 * @param aWidget Reference to a widget that is searched |
|
276 * from the widget array of this widget and removed |
|
277 * of found. |
|
278 */ |
|
279 OSN_IMPORT void removeWidget(IAlfWidget& aWidget); |
|
280 |
|
281 /** |
|
282 * Sets the presentation for the widget using presentation XML file. |
|
283 * Destroys any existing presentation. |
|
284 * @param aFilePath Path to XML file describing the presentation |
|
285 * of the widget. Not Owned. |
|
286 * @exception AlfWidgetException if no visualization node available |
|
287 * in Presentation XML or if no control |
|
288 * is associated with the widget. |
|
289 * @exception bad_alloc |
|
290 * @since S60 ?S60_version |
|
291 * @return void. |
|
292 */ |
|
293 OSN_IMPORT void setPresentation(const char* aFilePath); |
|
294 |
|
295 protected: |
|
296 |
|
297 /** |
|
298 * The protected constructor. |
|
299 * |
|
300 * @since S60 ?S60_version |
|
301 */ |
|
302 OSN_IMPORT AlfWidget(); |
|
303 |
|
304 private: |
|
305 |
|
306 /** |
|
307 * Adds the Common Properties for the widget |
|
308 * |
|
309 * @since S60 ?S60_version |
|
310 */ |
|
311 void addCommonWidgetProperties(); |
|
312 |
|
313 /** |
|
314 * Removes reference from this widget's control to this |
|
315 * widget. |
|
316 */ |
|
317 void removeReferenceFromControl(); |
|
318 |
|
319 private: // data |
|
320 |
|
321 auto_ptr<AlfWidgetImpl> mImpl; |
|
322 }; |
|
323 |
|
324 using namespace osncore; |
|
325 |
|
326 #include "alf/alfwidget.inl" |
|
327 |
|
328 } // namespace Alf |
|
329 |
|
330 #endif // ALFWIDGET_H |
|
331 |
|
332 // End of File |
|