1 /* |
|
2 * Copyright (c) 2002-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: Base class for Psln's view containers. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 // General services. |
|
21 #include <barsread.h> |
|
22 #include <akntitle.h> |
|
23 #include <eiktxlbm.h> |
|
24 #include <AknUtils.h> |
|
25 |
|
26 // Psln framework. |
|
27 #include <mpslnfwmsklabelobserver.h> |
|
28 |
|
29 // Psln specific. |
|
30 #include "PslnModel.h" |
|
31 #include "PslnBaseContainer.h" |
|
32 #include "PslnUi.h" |
|
33 |
|
34 // MEMBER FUNCTIONS |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // C++ default constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CPslnBaseContainer::CPslnBaseContainer() |
|
41 { |
|
42 iModel = static_cast<CPslnUi*>( ControlEnv()->AppUi() )->Model(); |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // CPslnBaseContainer::BaseConstructL |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 void CPslnBaseContainer::BaseConstructL( const TRect& aRect, TInt aResLbxId ) |
|
50 { |
|
51 CreateWindowL(); // Makes the control a window-owning control |
|
52 iListBox->SetContainerWindowL( *this ); |
|
53 |
|
54 iListBox->ConstructL( this, EAknListBoxSelectionList ); |
|
55 iItemArray = static_cast<CDesCArray*> |
|
56 ( iListBox->Model()->ItemTextArray() ); |
|
57 |
|
58 ConstructListBoxL( aResLbxId ); |
|
59 iListBox->CreateScrollBarFrameL( ETrue ); |
|
60 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
61 CEikScrollBarFrame::EOff, |
|
62 CEikScrollBarFrame::EAuto ); |
|
63 SetRect( aRect ); |
|
64 ActivateL(); |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CPslnBaseContainer::BaseConstructL |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 void CPslnBaseContainer::BaseConstructL( |
|
72 const TRect& aRect, TInt aResTitleId, TInt aResLbxId ) |
|
73 { |
|
74 // Set title |
|
75 if ( aResTitleId ) |
|
76 { |
|
77 CEikStatusPane* sp = |
|
78 iAvkonAppUi->StatusPane(); |
|
79 if ( sp ) |
|
80 { |
|
81 CAknTitlePane* title = static_cast<CAknTitlePane*>( |
|
82 sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
83 if ( title ) |
|
84 { |
|
85 TResourceReader rReader; |
|
86 iCoeEnv->CreateResourceReaderLC( rReader, aResTitleId ); |
|
87 title->SetFromResourceL( rReader ); |
|
88 CleanupStack::PopAndDestroy(); //rReader |
|
89 } |
|
90 } |
|
91 } |
|
92 BaseConstructL( aRect, aResLbxId ); |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------------------------- |
|
96 // Destructor |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 CPslnBaseContainer::~CPslnBaseContainer() |
|
100 { |
|
101 delete iListBox; |
|
102 } |
|
103 |
|
104 // --------------------------------------------------------------------------- |
|
105 // CPslnBaseContainer::SetListBoxObserver |
|
106 // --------------------------------------------------------------------------- |
|
107 // |
|
108 void CPslnBaseContainer::SetListBoxObserver( MEikListBoxObserver* aObserver ) |
|
109 { |
|
110 iListBox->SetListBoxObserver( aObserver ); |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CPslnBaseContainer::CurrentItemIndex |
|
115 // --------------------------------------------------------------------------- |
|
116 // |
|
117 TInt CPslnBaseContainer::CurrentItemIndex() const |
|
118 { |
|
119 return iListBox->CurrentItemIndex(); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CPslnBaseContainer::SetCurrentItemIndexAndDraw |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CPslnBaseContainer::SetCurrentItemIndexAndDraw( TInt aNewIndex ) |
|
127 { |
|
128 if( ( aNewIndex >= 0 ) && |
|
129 ( aNewIndex < iListBox->Model()->NumberOfItems() ) ) |
|
130 { |
|
131 iListBox->SetCurrentItemIndexAndDraw( aNewIndex ); |
|
132 } |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // CPslnBaseContainer::SetCurrentItemIndex |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CPslnBaseContainer::SetCurrentItemIndex( TInt aNewIndex ) |
|
140 { |
|
141 if( ( aNewIndex >= 0 ) && |
|
142 ( aNewIndex < iListBox->Model()->NumberOfItems() ) ) |
|
143 { |
|
144 iListBox->SetCurrentItemIndex( aNewIndex ); |
|
145 } |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // CPslnBaseContainer::GetMiddleSoftkeyObserver |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 MPslnFWMSKObserver* CPslnBaseContainer::GetMiddleSoftkeyObserver() |
|
153 { |
|
154 return iMSKObserver; |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // Sets observer for MSK label updations. |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CPslnBaseContainer::SetMiddleSoftkeyObserver( MPslnFWMSKObserver* aObserver ) |
|
162 { |
|
163 if ( !iMSKObserver && aObserver ) |
|
164 { |
|
165 iMSKObserver = aObserver; |
|
166 } |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CPslnBaseContainer::UpdateListBoxL |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CPslnBaseContainer::UpdateListBoxL() |
|
174 { |
|
175 // Update items. |
|
176 CreateListBoxItemsL(); |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // Called when a key is pressed. |
|
181 // --------------------------------------------------------------------------- |
|
182 |
|
183 TKeyResponse CPslnBaseContainer::OfferKeyEventL( |
|
184 const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
185 { |
|
186 switch ( aKeyEvent.iCode ) |
|
187 { |
|
188 case EKeyUpArrow: |
|
189 case EKeyDownArrow: |
|
190 { |
|
191 TKeyResponse listboxResp = |
|
192 iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
193 if ( iMSKObserver ) |
|
194 { |
|
195 iMSKObserver->CheckMiddleSoftkeyLabelL(); |
|
196 } |
|
197 return listboxResp; |
|
198 } |
|
199 case EKeyLeftArrow: |
|
200 case EKeyRightArrow: |
|
201 // Listbox takes all events even if it doesn't use them |
|
202 return EKeyWasNotConsumed; |
|
203 default: |
|
204 break; |
|
205 } |
|
206 |
|
207 return iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
208 } |
|
209 |
|
210 // --------------------------------------------------------------------------- |
|
211 // Called by framwork when the view size is changed. |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 void CPslnBaseContainer::SizeChanged() |
|
215 { |
|
216 if ( iListBox ) |
|
217 { |
|
218 iListBox->SetRect( Rect() ); |
|
219 } |
|
220 } |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CPslnBaseContainer::CountComponentControls |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CPslnBaseContainer::CountComponentControls() const |
|
227 { |
|
228 return 1; //magic |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // CPslnBaseContainer::ComponentControl |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 CCoeControl* CPslnBaseContainer::ComponentControl( TInt /*aIndex*/ ) const |
|
236 { |
|
237 return iListBox; |
|
238 } //lint !e1763 Member intentionally exposed through const method |
|
239 |
|
240 // --------------------------------------------------------------------------- |
|
241 // CPslnBaseContainer::HandleResourceChange |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 void CPslnBaseContainer::HandleResourceChange( TInt aType ) |
|
245 { |
|
246 CCoeControl::HandleResourceChange( aType ); |
|
247 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
248 { |
|
249 TRect mainPaneRect; |
|
250 AknLayoutUtils::LayoutMetricsRect( |
|
251 AknLayoutUtils::EMainPane, |
|
252 mainPaneRect ); |
|
253 SetRect( mainPaneRect ); |
|
254 } |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // CPslnBaseContainer::FocusChanged |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 void CPslnBaseContainer::FocusChanged( TDrawNow aDrawNow ) |
|
262 { |
|
263 // Pass focus changed event to listbox. |
|
264 if ( iListBox ) |
|
265 { |
|
266 iListBox->SetFocus( IsFocused(), aDrawNow ); |
|
267 } |
|
268 } |
|
269 |
|
270 // End of File |
|