|
1 /* |
|
2 * Copyright (c) 2002 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: Container class of main view. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include "CProfileMainContainer.h" |
|
22 |
|
23 #include <AknDef.h> |
|
24 #include <aknlists.h> |
|
25 #include <AknUtils.h> // AknTextUtils |
|
26 #include <featmgr.h> |
|
27 #include <CProfileEngineHandler.h> |
|
28 #include <CProfileIndexHandler.h> |
|
29 #include <mprofileengineextended.h> |
|
30 #include <mprofilesnamesarray.h> |
|
31 #include <csxhelp/mode.hlp.hrh> |
|
32 #include <profileeng.hrh> |
|
33 |
|
34 #include "CProfileMainView.h" |
|
35 #include "CProfileDocument.h" |
|
36 #include "CProfileApplication.h" |
|
37 #include "ProfileApp.hrh" |
|
38 #include "profileengineconstants.h" |
|
39 |
|
40 // CONSTANTS |
|
41 _LIT( KTabChar, "\t" ); |
|
42 const TInt KProfileNameArrayGranularity( 5 ); |
|
43 |
|
44 // ============================ MEMBER FUNCTIONS =============================== |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CProfileMainContainer::CProfileMainContainer |
|
48 // C++ constructor can NOT contain any code, that might leave. |
|
49 // ----------------------------------------------------------------------------- |
|
50 // |
|
51 CProfileMainContainer::CProfileMainContainer( |
|
52 CProfileEngineHandler& aEngineHandler, |
|
53 CProfileIndexHandler& aIndexHandler, |
|
54 CAknView& aView ) |
|
55 : iEngineHandler( aEngineHandler ), |
|
56 iIndexHandler( aIndexHandler ), |
|
57 iView( aView ) |
|
58 { |
|
59 SetMopParent( &aView ); |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CProfileMainContainer::ConstructL |
|
64 // Symbian 2nd phase constructor can leave. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void CProfileMainContainer::ConstructL( const TRect& aRect ) |
|
68 { |
|
69 CreateWindowL(); |
|
70 |
|
71 iListBox = new( ELeave ) CAknSingleStyleListBox(); |
|
72 iListBox->ConstructL( this ); |
|
73 iListBox->SetListBoxObserver( this ); |
|
74 iListBox->CreateScrollBarFrameL( ETrue ); |
|
75 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
76 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
77 |
|
78 SetRect( aRect ); |
|
79 ActivateL(); |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CProfileMainContainer::NewL |
|
84 // Two-phased constructor. |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 CProfileMainContainer* CProfileMainContainer::NewL( |
|
88 CProfileEngineHandler& aEngineHandler, |
|
89 CProfileIndexHandler& aIndexHandler, |
|
90 CAknView& aView ) |
|
91 { |
|
92 CProfileMainContainer* self = new( ELeave ) CProfileMainContainer( |
|
93 aEngineHandler, aIndexHandler, aView ); |
|
94 CleanupStack::PushL( self ); |
|
95 self->ConstructL( aView.ClientRect() ); |
|
96 CleanupStack::Pop( self ); |
|
97 return self; |
|
98 } |
|
99 |
|
100 // Destructor |
|
101 CProfileMainContainer::~CProfileMainContainer() |
|
102 { |
|
103 delete iListBox; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CProfileMainContainer::PopulateListBoxL |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 void CProfileMainContainer::PopulateListBoxL( TInt aTopItemIndex ) |
|
111 { |
|
112 // Transfer decorated array ownership for listbox model |
|
113 CDesCArrayFlat* decoratedArray = |
|
114 new( ELeave ) CDesCArrayFlat( KProfileNameArrayGranularity ); |
|
115 CTextListBoxModel* model = iListBox->Model(); |
|
116 model->SetOwnershipType( ELbmOwnsItemArray ); |
|
117 model->SetItemTextArray( decoratedArray ); |
|
118 |
|
119 MProfilesNamesArray* array = iEngineHandler.IdArray(); |
|
120 |
|
121 // Populate the decorated array for listbox |
|
122 TInt count( array->MdcaCount() ); |
|
123 TBuf<PROFILES_MAX_NAME_LENGTH + 1> name; // + 1 for tab character |
|
124 for( TInt index( 0 ); index < count; index++ ) |
|
125 { |
|
126 name.Copy( KTabChar ); |
|
127 TBuf< KProfileMaxNameLength > tmpName( array->MdcaPoint( index ) ); |
|
128 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( tmpName ); |
|
129 AknTextUtils::ReplaceCharacters( tmpName, KAknReplaceListControlChars, |
|
130 TChar( ' ' ) ); |
|
131 name.Append( tmpName ); |
|
132 decoratedArray->AppendL( name ); |
|
133 } |
|
134 |
|
135 // Update listbox |
|
136 iListBox->HandleItemAdditionL(); |
|
137 |
|
138 // Update view |
|
139 if( aTopItemIndex >= 0 ) |
|
140 { |
|
141 iListBox->SetTopItemIndex( aTopItemIndex ); |
|
142 } |
|
143 iListBox->SetCurrentItemIndex( iIndexHandler.CurrentProfileIndex() ); |
|
144 iListBox->DrawNow(); |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CProfileMainContainer::TopItemIndex |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CProfileMainContainer::TopItemIndex() const |
|
152 { |
|
153 return iListBox->TopItemIndex(); |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CProfileMainContainer::CountComponentControls |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 TInt CProfileMainContainer::CountComponentControls() const |
|
161 { |
|
162 return KMainContainerSubControlCount; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CProfileMainContainer::ComponentControl |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 CCoeControl* CProfileMainContainer::ComponentControl( TInt aIndex ) const |
|
170 { |
|
171 switch( aIndex ) |
|
172 { |
|
173 case 0: |
|
174 { |
|
175 return iListBox; |
|
176 } |
|
177 default: |
|
178 { |
|
179 return NULL; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 // ----------------------------------------------------------------------------- |
|
185 // CProfileMainContainer::SizeChanged |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 void CProfileMainContainer::SizeChanged() |
|
189 { |
|
190 if( iListBox ) |
|
191 { |
|
192 iListBox->SetRect( Rect() ); // Set container's rect to listbox |
|
193 // Force refreshing of iListBox: |
|
194 TRAP_IGNORE( iListBox->HandleItemAdditionL() ); |
|
195 } |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CProfileMainContainer::OfferKeyEventL |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 TKeyResponse CProfileMainContainer::OfferKeyEventL( |
|
203 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
204 { |
|
205 if( aType != EEventKey ) |
|
206 { |
|
207 return EKeyWasNotConsumed; |
|
208 } |
|
209 |
|
210 switch( aKeyEvent.iCode ) |
|
211 { |
|
212 case EKeyUpArrow: // flow through, both change focus |
|
213 case EKeyDownArrow: |
|
214 { |
|
215 TKeyResponse response( iListBox->OfferKeyEventL( aKeyEvent, aType ) ); |
|
216 iIndexHandler.SetCurrentProfileIndex( iListBox->CurrentItemIndex() ); |
|
217 return response; |
|
218 } |
|
219 case EKeyBackspace: // Clear key |
|
220 { |
|
221 if( ( FeatureManager::FeatureSupported( KFeatureIdDynamicProfiles ) ) && |
|
222 ( !iEngineHandler.Engine()->IsDefaultProfile( |
|
223 iEngineHandler.IdForIndex( iIndexHandler.CurrentProfileIndex() ) ) ) ) |
|
224 { |
|
225 // If dynamic profiles feature is supported and none of |
|
226 // the default profiles is focused, try to delete a profile. |
|
227 iView.HandleCommandL( EProfileCmdDelete ); |
|
228 return EKeyWasConsumed; |
|
229 } |
|
230 break; |
|
231 } |
|
232 default: |
|
233 { |
|
234 break; |
|
235 } |
|
236 } |
|
237 return iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CProfileMainContainer::HandleListBoxEventL |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void CProfileMainContainer::HandleListBoxEventL( |
|
245 CEikListBox* /* aListBox */, TListBoxEvent aEventType ) |
|
246 { |
|
247 if( ( aEventType == EEventEnterKeyPressed ) || |
|
248 |
|
249 ( aEventType == EEventItemSingleClicked ) ) |
|
250 { |
|
251 iIndexHandler.SetCurrentProfileIndex( iListBox->CurrentItemIndex() ); |
|
252 iView.HandleCommandL( EProfileCmdContextSpecificOptionsMenu ); |
|
253 } |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CProfileMainContainer::GetHelpContext |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 void CProfileMainContainer::GetHelpContext( TCoeHelpContext& aContext ) const |
|
261 { |
|
262 aContext.iMajor = KUidProfileApp; |
|
263 aContext.iContext = KMODE_HLP_PROFILES_LIST; |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CProfileMainContainer::HandleResourceChange |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CProfileMainContainer::HandleResourceChange( TInt aType ) |
|
271 { |
|
272 if ( aType == KEikDynamicLayoutVariantSwitch || |
|
273 aType == KAknsMessageSkinChange ) |
|
274 { |
|
275 (static_cast <CProfileMainView *> (&iView))->UpdateClientRect(); |
|
276 } |
|
277 |
|
278 CCoeControl::HandleResourceChange( aType ); |
|
279 } |
|
280 |
|
281 // ----------------------------------------------------------------------------- |
|
282 // CProfileMainContainer::FocusChanged |
|
283 // ----------------------------------------------------------------------------- |
|
284 // |
|
285 void CProfileMainContainer::FocusChanged( TDrawNow aDrawNow ) |
|
286 { |
|
287 if( iListBox ) |
|
288 { |
|
289 iListBox->SetFocus( IsFocused(), aDrawNow ); |
|
290 } |
|
291 } |
|
292 |
|
293 // End of File |