|
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 private implementation of CAlfWidget. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "alfwidgetimpl.h" |
|
20 #include <alf/alfwidgetcontrol.h> |
|
21 #include <alf/alfmodel.h> |
|
22 #include <alf/alfcontrolgroup.h> |
|
23 #include "alf/alfwidget.h" |
|
24 #include "alf/alfattribute.h" |
|
25 #include "alf/alfattributevaluetype.h" |
|
26 #include <alf/alfexceptions.h> |
|
27 #include <libc/string.h> |
|
28 #include <alf/ialfelement.h> |
|
29 |
|
30 #include "alfwidgetattributeownerimpl.h" |
|
31 |
|
32 |
|
33 namespace Alf |
|
34 { |
|
35 |
|
36 AlfWidgetImpl::AlfWidgetImpl() |
|
37 { |
|
38 mControl = NULL; |
|
39 mModel = NULL; |
|
40 mAttributeList.setAutoDelete(true); |
|
41 mWidgets.setAutoDelete(false); |
|
42 mTakesModelOwnership=false; |
|
43 } |
|
44 |
|
45 AlfWidgetImpl::~AlfWidgetImpl() |
|
46 { |
|
47 setControl( NULL, true ); |
|
48 |
|
49 if (mTakesModelOwnership) |
|
50 { |
|
51 delete mModel; |
|
52 mModel = NULL; |
|
53 } |
|
54 mAttributeList.clear(); |
|
55 mWidgets.clear(); |
|
56 } |
|
57 |
|
58 void AlfWidgetImpl::setWidgetName( const UString& aWidgetName ) |
|
59 { |
|
60 mWidgetName = aWidgetName; |
|
61 } |
|
62 |
|
63 const UString& AlfWidgetImpl::widgetName() const |
|
64 { |
|
65 return mWidgetName; |
|
66 } |
|
67 |
|
68 |
|
69 CAlfWidgetControl* AlfWidgetImpl::control() |
|
70 { |
|
71 return mControl; |
|
72 } |
|
73 |
|
74 void AlfWidgetImpl::setControl( CAlfWidgetControl* aControl,bool aDeletePreviousControl) |
|
75 { |
|
76 if ( mControl != aControl ) |
|
77 { |
|
78 if( mControl ) |
|
79 { |
|
80 if( mModel ) |
|
81 { |
|
82 // Remove model change observer from control |
|
83 mModel->removeModelChangeObserver( *mControl ); |
|
84 } |
|
85 if( aDeletePreviousControl ) |
|
86 { |
|
87 // Delete control from possible control group to avoid double deletion |
|
88 if(mControl->ControlGroup()) |
|
89 { |
|
90 mControl->ControlGroup()->Remove(mControl); |
|
91 } |
|
92 // Delete the control |
|
93 delete mControl; |
|
94 mControl = NULL; |
|
95 } |
|
96 } |
|
97 |
|
98 // Set the new control. |
|
99 mControl = aControl; |
|
100 |
|
101 // Add the new control as an observer for model changes. |
|
102 if( mControl ) |
|
103 { |
|
104 if( mModel ) |
|
105 { |
|
106 mModel->addModelChangeObserver( *mControl ); |
|
107 } |
|
108 mAttributeOwnerImpl.reset(new (EMM) AlfWidgetAttributeOwnerImpl(mControl)); |
|
109 } |
|
110 } |
|
111 } |
|
112 |
|
113 IAlfModel* AlfWidgetImpl::model() |
|
114 { |
|
115 return mModel; |
|
116 } |
|
117 |
|
118 void AlfWidgetImpl::setModel( IAlfModel* aModel,bool aTakeOwnerShip ) |
|
119 { |
|
120 if ( mModel != aModel ) |
|
121 { |
|
122 // Release the old model. |
|
123 if (mTakesModelOwnership) |
|
124 { |
|
125 delete mModel; |
|
126 } |
|
127 |
|
128 else if (mModel&&mControl) |
|
129 { |
|
130 mModel->removeModelChangeObserver(*mControl); |
|
131 } |
|
132 |
|
133 // Set the new model. |
|
134 mModel = aModel; |
|
135 mTakesModelOwnership=aTakeOwnerShip; |
|
136 // Add the control as an observer for model changes. |
|
137 if ( mModel && mControl ) |
|
138 { |
|
139 mModel->addModelChangeObserver( *mControl ); |
|
140 } |
|
141 } |
|
142 else // just copy the ownership flag |
|
143 { |
|
144 if (mModel != NULL) |
|
145 { |
|
146 mTakesModelOwnership=aTakeOwnerShip; |
|
147 } |
|
148 } |
|
149 |
|
150 } |
|
151 |
|
152 // --------------------------------------------------------------------------- |
|
153 // --------------------------------------------------------------------------- |
|
154 // |
|
155 void AlfWidgetImpl::addWidget(AlfWidget *aWidget) |
|
156 { |
|
157 for (int i=0 ; i< mWidgets.count(); i++ ) |
|
158 { |
|
159 if (mWidgets.findRef(aWidget) >=0) |
|
160 { |
|
161 //widget already there. |
|
162 return; |
|
163 } |
|
164 } |
|
165 mWidgets.resize(mWidgets.count()+1); |
|
166 mWidgets.insert(mWidgets.count(),aWidget); |
|
167 } |
|
168 |
|
169 int AlfWidgetImpl::widgetCount() |
|
170 { |
|
171 return mWidgets.count(); |
|
172 } |
|
173 |
|
174 AlfWidget* AlfWidgetImpl::getWidget(int aIndex) |
|
175 { |
|
176 if (aIndex>=0 && aIndex < mWidgets.count()) |
|
177 return mWidgets[aIndex]; |
|
178 return 0; |
|
179 } |
|
180 |
|
181 int AlfWidgetImpl::findWidget(AlfWidget* aWidget) |
|
182 { |
|
183 return mWidgets.findRef(aWidget); |
|
184 } |
|
185 |
|
186 void AlfWidgetImpl::removeWidget(int aIndex) |
|
187 { |
|
188 if (aIndex >=0 and aIndex < mWidgets.count()) |
|
189 mWidgets.remove(aIndex); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // Returns attribute owner interface. |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 AlfWidgetAttributeOwnerImpl* AlfWidgetImpl::getAttributeOwner() |
|
197 { |
|
198 return mAttributeOwnerImpl.get(); |
|
199 } |
|
200 |
|
201 } //namespace alf |
|
202 |
|
203 |
|
204 |