|
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: Toolbar item |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <AknsUtils.h> |
|
20 #include <barsread.h> |
|
21 #include <aknbutton.h> |
|
22 #include <e32std.h> |
|
23 #include <e32property.h> |
|
24 #include <avkondomainpskeys.h> |
|
25 |
|
26 |
|
27 #include "akntoolbaritem.h" |
|
28 #include "touchtoolbardata.h" |
|
29 |
|
30 |
|
31 // ----------------------------------------------------------------------------- |
|
32 // CAknToolbarItem::CAknToolbarItem |
|
33 // Default constructor |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 CAknToolbarItem::CAknToolbarItem() |
|
37 { |
|
38 } |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CAknToolbarItem::CAknToolbarItem |
|
42 // Constructor |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CAknToolbarItem::CAknToolbarItem( CCoeControl* aControl, TInt aType, |
|
46 TInt aId, TInt aFlags ) |
|
47 : iControl( aControl ), iControlType( aType ), |
|
48 iCommandId( aId ), iFlags( aFlags ) |
|
49 { |
|
50 SetKeyRefuse(); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // Destructor |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CAknToolbarItem::~CAknToolbarItem() |
|
58 { |
|
59 AknsUtils::DeregisterControlPosition( iControl ); |
|
60 delete iControl; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // CAknToolbarItem::ConstructFromResourceL |
|
65 // Constructs one item from resource file |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 void CAknToolbarItem::ConstructFromResourceL( TResourceReader& aReader ) |
|
69 { |
|
70 iControlType = aReader.ReadInt16(); |
|
71 iCommandId = aReader.ReadInt16(); |
|
72 iFlags = aReader.ReadInt16(); |
|
73 aReader.ReadInt16(); // length, not used |
|
74 |
|
75 iControl = EikControlFactory::CreateByTypeL( iControlType ).iControl; |
|
76 |
|
77 if ( iControl ) |
|
78 { |
|
79 iControl->ConstructFromResourceL( aReader ); |
|
80 } |
|
81 |
|
82 SetKeyRefuse(); |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CAknToolbarItem::Control |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CCoeControl* CAknToolbarItem::Control() const |
|
90 { |
|
91 return iControl; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // CAknToolbarItem::ControlType |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 TInt CAknToolbarItem::ControlType() const |
|
99 { |
|
100 return iControlType; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CAknToolbarItem::CommandId |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 TInt CAknToolbarItem::CommandId() const |
|
108 { |
|
109 return iCommandId; |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // CAknToolbarItem::Flags |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 TInt CAknToolbarItem::Flags() const |
|
117 { |
|
118 return iFlags; |
|
119 } |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CAknToolbarItem::IsSelected |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 TBool CAknToolbarItem::IsSelected() const |
|
126 { |
|
127 return iIsSelected; |
|
128 } |
|
129 |
|
130 // ----------------------------------------------------------------------------- |
|
131 // CAknToolbarItem::SetIsSelectedL |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 TBool CAknToolbarItem::SetIsSelectedL( TBool aIsSelected ) |
|
135 { |
|
136 // Toolbar items containing buttons are not set to selected state |
|
137 if ( Control() && ( ControlType() == EAknCtButton || |
|
138 ControlType() == EAknCtToolbarExtension ) ) |
|
139 { |
|
140 return EFalse; |
|
141 } |
|
142 |
|
143 iIsSelected = aIsSelected; |
|
144 |
|
145 // Set item focused, when selected |
|
146 Control()->SetFocus( aIsSelected ); |
|
147 if ( aIsSelected ) |
|
148 { |
|
149 CEikonEnv::Static()->EikAppUi()->AddToStackL( Control(), ECoeStackPriorityDefault, |
|
150 0 ); |
|
151 } |
|
152 else |
|
153 { |
|
154 CEikonEnv::Static()->EikAppUi()->RemoveFromStack( Control() ); |
|
155 } |
|
156 |
|
157 return ETrue; |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CAknToolbarItem::SetCloseOnCommand |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 void CAknToolbarItem::SetCloseOnCommand( const TBool aCloseOnCommand ) |
|
165 { |
|
166 if ( Control() && ( ControlType() == EAknCtButton || |
|
167 ControlType() == EAknCtToolbarExtension ) ) |
|
168 { |
|
169 static_cast<CAknButton*>( Control() )->SetRequestExit( aCloseOnCommand ); |
|
170 } |
|
171 } //lint !e1762 |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CAknToolbarItem::SetHighlightRect |
|
175 // ----------------------------------------------------------------------------- |
|
176 // |
|
177 void CAknToolbarItem::SetHighlightRect( const TRect& aRect ) |
|
178 { |
|
179 iHighlightRect = aRect; |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // CAknToolbarItem::HighlightRect |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 TRect CAknToolbarItem::HighlightRect() const |
|
187 { |
|
188 return iHighlightRect; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CAknToolbarItem::SetFocusL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CAknToolbarItem::SetFocusL( TBool aFocus, TBool aPrepareControl, |
|
196 TDrawNow aDrawNow, const CCoeControl* aParent ) |
|
197 { |
|
198 // Editor is set focused, when it is selected, not here. |
|
199 if ( iControl && ( iControlType == EAknCtButton ) ) |
|
200 { |
|
201 if ( aPrepareControl ) |
|
202 { |
|
203 if ( aFocus ) |
|
204 { |
|
205 TInt state = 0; |
|
206 CTouchToolbarData* data = |
|
207 (CTouchToolbarData*) CAknTransitionUtils::GetData( |
|
208 (TInt) aParent ); |
|
209 if ( data ) |
|
210 { |
|
211 RProperty::Get( KPSUidAvkonDomain, |
|
212 KAknTfxServerRedirectionStatus, |
|
213 state ); |
|
214 data->SetFocusedItem( state ? iControl : NULL ); |
|
215 } |
|
216 if ( state == 0 ) |
|
217 { |
|
218 iControl->PrepareForFocusGainL(); |
|
219 } |
|
220 } |
|
221 else |
|
222 { |
|
223 iControl->PrepareForFocusLossL(); |
|
224 } |
|
225 } |
|
226 |
|
227 iControl->SetFocus( aFocus, aDrawNow ); |
|
228 } |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CAknToolbarItem::RegisterPosition |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 void CAknToolbarItem::RegisterPosition( const TPoint& aParentPosition ) const |
|
236 { |
|
237 AknsUtils::RegisterControlPosition( iControl, aParentPosition + |
|
238 iControl->Position() ); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CAknToolbarItem::IsHidden |
|
243 // ----------------------------------------------------------------------------- |
|
244 // |
|
245 TBool CAknToolbarItem::IsHidden() const |
|
246 { |
|
247 return iHidden; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CAknToolbarItem::SetHidden |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CAknToolbarItem::SetHidden( TBool aHidden ) |
|
255 { |
|
256 iHidden = aHidden; |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CAknToolbarItem::RefusesKeys |
|
261 // ----------------------------------------------------------------------------- |
|
262 // |
|
263 TBool CAknToolbarItem::RefusesKeys() const |
|
264 { |
|
265 return iRefusesKeys; |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CAknToolbarItem::RefusesKeys |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CAknToolbarItem::SetKeyRefuse() |
|
273 { |
|
274 switch ( iControlType ) |
|
275 { |
|
276 case EEikCtEdwin: // fallback done on purpose |
|
277 case EEikCtRichTextEditor: |
|
278 case EEikCtSecretEd: |
|
279 case EEikCtFileNameEd: |
|
280 case EEikCtFolderNameEd: |
|
281 case EEikCtFlPtEd: |
|
282 case EEikCtFxPtEd: |
|
283 case EEikCtTwipsEd: |
|
284 case EEikCtNumberEditor: |
|
285 case EEikCtRangeEditor: |
|
286 case EEikCtTimeEditor: |
|
287 case EEikCtDateEditor: |
|
288 case EEikCtTimeAndDateEditor: |
|
289 case EEikCtDurationEditor: |
|
290 case EEikCtTimeOffsetEditor: |
|
291 case EEikCtGlobalTextEditor: |
|
292 case EAknCtIpFieldEditor: |
|
293 case EEikCtRangeRefEditor: |
|
294 case EEikCtTelephoneNumberEditor: |
|
295 case EAknCtLocationEditor: |
|
296 case EAknCtUnitEditor: |
|
297 iRefusesKeys = ETrue; |
|
298 break; |
|
299 |
|
300 default: |
|
301 iRefusesKeys = EFalse; |
|
302 } |
|
303 } |