|
1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CMCETestUIAppUi.h" |
|
21 #include "CMCETestUISessionView.h" |
|
22 #include "CMCETestUISessionViewContainer.h" |
|
23 #include "CMCETestUISessionViewModel.h" |
|
24 #include "CMCETestUIEngine.h" |
|
25 #include "CMCETestUIEngineProfile.h" |
|
26 #include "CMCETestUIEngineSession.h" |
|
27 #include "TMCETestUIEngineCmdBase.h" |
|
28 #include <aknviewappui.h> |
|
29 #include <aknview.h> |
|
30 #include <aknpopup.h> |
|
31 |
|
32 |
|
33 |
|
34 // CONSTANTS |
|
35 |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ========================================== |
|
38 |
|
39 CMCETestUISessionViewContainer* CMCETestUISessionViewContainer::NewL( |
|
40 const TRect& aRect, |
|
41 CMCETestUISessionView& aOwningView, |
|
42 CMCETestUIEngine& aEngine, |
|
43 CMCETestUIEngineSession& aSession ) |
|
44 { |
|
45 CMCETestUISessionViewContainer* self = |
|
46 new(ELeave) CMCETestUISessionViewContainer( |
|
47 aOwningView, |
|
48 aEngine, |
|
49 aSession ); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL( aRect ); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CMCETestUISessionViewContainer::CMCETestUISessionViewContainer( |
|
57 CMCETestUISessionView& aOwningView, |
|
58 CMCETestUIEngine& aEngine, |
|
59 CMCETestUIEngineSession& aSession ) |
|
60 :iOwningView( aOwningView ), |
|
61 iEngine( aEngine ), |
|
62 iSession( aSession ), |
|
63 iContextMenuAlreadyShown( EFalse ) |
|
64 { |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CMCETestUISessionViewContainer::ConstructL(const TRect& aRect) |
|
69 // EPOC two phased constructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CMCETestUISessionViewContainer::ConstructL(const TRect& aRect) |
|
73 { |
|
74 CreateWindowL(); |
|
75 //Window().SetShadowDisabled(EFalse); |
|
76 |
|
77 iListBox = new (ELeave) CAknDoubleStyleListBox(); |
|
78 |
|
79 iListBox->SetContainerWindowL(*this); |
|
80 iListBox->ConstructL( this, |
|
81 EAknListBoxSelectionList | EAknListBoxLoopScrolling); |
|
82 iListBox->SetListBoxObserver(this); |
|
83 iListBox->SetMopParent(this); |
|
84 |
|
85 iListBoxModel = CMCETestUISessionViewModel::NewL( iEngine, iSession ); |
|
86 |
|
87 iListBox->Model()->SetItemTextArray( iListBoxModel ); |
|
88 |
|
89 SetRect(aRect); |
|
90 |
|
91 iListBox->SetRect(Rect()); |
|
92 |
|
93 //Set up the listbox to use a scroll bar |
|
94 iListBox->CreateScrollBarFrameL(ETrue); |
|
95 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
96 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
97 |
|
98 ConstructModelL(); |
|
99 |
|
100 ActivateL(); |
|
101 |
|
102 //iListBox->HandleItemAdditionL(); |
|
103 |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CMCETestUISessionViewContainer::~CMCETestUISessionViewContainer() |
|
108 // Destructor |
|
109 // Frees reserved resources |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 CMCETestUISessionViewContainer::~CMCETestUISessionViewContainer() |
|
113 { |
|
114 delete iListBox; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CMCETestUISessionViewContainer::~CMCETestUISessionViewContainer() |
|
119 // Destructor |
|
120 // Frees reserved resources |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CMCETestUISessionViewContainer::ConstructModelL() |
|
124 { |
|
125 iListBoxModel = CMCETestUISessionViewModel::NewL( iEngine, iSession ); |
|
126 |
|
127 iListBox->Model()->SetItemTextArray( iListBoxModel ); |
|
128 |
|
129 iListBox->Reset(); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CMCETestUISessionViewContainer::SizeChanged() |
|
134 // Called by framework when the view size is changed |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CMCETestUISessionViewContainer::SizeChanged() |
|
138 { |
|
139 TInt error; |
|
140 |
|
141 // TRAP methods that can leave. |
|
142 TRAP(error, SizeChangedL()); |
|
143 if(error != KErrNone) |
|
144 { |
|
145 User::Panic( KNullDesC16, 0 ); |
|
146 } |
|
147 } |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CMCETestUISessionViewContainer::SizeChangedL() |
|
151 // Methods that can leave and are needed by SizeChanged |
|
152 // are collected into this method. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CMCETestUISessionViewContainer::SizeChangedL() |
|
156 { |
|
157 |
|
158 } |
|
159 |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CMCETestUISessionViewContainer::CountComponentControls() const |
|
163 // Note! Output window must be ignored. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CMCETestUISessionViewContainer::CountComponentControls() const |
|
167 { |
|
168 if ( iListBox ) |
|
169 return 1; |
|
170 return 0; |
|
171 } |
|
172 |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CMCETestUISessionViewContainer::ComponentControl() |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 CCoeControl* CMCETestUISessionViewContainer::ComponentControl(TInt /*aIndex*/) const |
|
179 { |
|
180 return iListBox; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CMCETestUISessionViewContainer::HandleListBoxEventL() |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CMCETestUISessionViewContainer::HandleListBoxEventL( |
|
188 CEikListBox* aListBox, |
|
189 TListBoxEvent aEventType ) |
|
190 { |
|
191 TInt selectedIndex = iListBox->CurrentItemIndex(); |
|
192 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
193 CMCETestUIAppUi* tempUiPtr = (CMCETestUIAppUi*)eikonEnv->AppUi(); |
|
194 |
|
195 tempUiPtr->iCurrentStreamViewIndex = KErrNone; |
|
196 if ( aListBox == iListBox ) |
|
197 { |
|
198 if ( aEventType == EEventEnterKeyPressed || aEventType == EEventItemDoubleClicked ) |
|
199 { |
|
200 |
|
201 iOwningView.ChangeToStreamViewL(selectedIndex); |
|
202 tempUiPtr->iCurrentStreamViewIndex = selectedIndex; |
|
203 // TODO: Add changes to event and refer views |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CMCETestUISessionViewContainer::Draw(const TRect& aRect) const |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CMCETestUISessionViewContainer::Draw(const TRect& aRect ) const |
|
214 { |
|
215 CWindowGc& gc = SystemGc(); |
|
216 gc.Clear( aRect ); |
|
217 } |
|
218 |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CMCETestUISessionViewContainer::HandleControlEventL( |
|
222 // CCoeControl* aControl,TCoeEvent aEventType) |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CMCETestUISessionViewContainer::HandleControlEventL( |
|
226 CCoeControl* /*aControl*/, |
|
227 TCoeEvent /*aEventType*/) |
|
228 { |
|
229 // TODO: Add your control event handler code here |
|
230 } |
|
231 |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CMCETestUISessionViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
235 // TEventCode aType) |
|
236 // Handle key event. Only up and down key arrow events are |
|
237 // consumed in order to enable scrolling in output window. |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 TKeyResponse CMCETestUISessionViewContainer::OfferKeyEventL( |
|
241 const TKeyEvent& aKeyEvent, |
|
242 TEventCode aType) |
|
243 { |
|
244 if ( aType == EEventKeyUp ) |
|
245 { |
|
246 |
|
247 if ( aKeyEvent.iCode == 0 && aKeyEvent.iScanCode == 164 ) // EAknSoftkeyOptions? |
|
248 { |
|
249 DoShowMenuL(); |
|
250 |
|
251 return EKeyWasConsumed; |
|
252 } |
|
253 } |
|
254 return iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 // ----------------------------------------------------------------------------- |
|
260 // |
|
261 void CMCETestUISessionViewContainer::DoShowMenuL() |
|
262 { |
|
263 if ( iContextMenuAlreadyShown ) |
|
264 { |
|
265 iContextMenuAlreadyShown = EFalse; |
|
266 return; |
|
267 } |
|
268 |
|
269 // Get command provider |
|
270 MMCETestUIEngineCmdProvider& cmdProvider = |
|
271 iListBoxModel->CmdProvider( iListBox->CurrentItemIndex() ); |
|
272 |
|
273 // Get commands |
|
274 const RPointerArray<TMCETestUIEngineCmdBase>& commands = |
|
275 cmdProvider.GetCommandsL(); |
|
276 |
|
277 |
|
278 // Generate list |
|
279 CAknSinglePopupMenuStyleListBox* listBox = |
|
280 new (ELeave) CAknSinglePopupMenuStyleListBox; |
|
281 CleanupStack::PushL( listBox ); |
|
282 |
|
283 CAknPopupList* popup = CAknPopupList::NewL( |
|
284 listBox, |
|
285 R_AVKON_SOFTKEYS_MENU_LIST, |
|
286 AknPopupLayouts::EPopupSNotePopupWindow ); |
|
287 CleanupStack::PushL( popup ); |
|
288 popup->SetTitleL( _L("Available commands") ); |
|
289 |
|
290 listBox->ConstructL( popup, |
|
291 EAknListBoxSelectionList | EAknListBoxLoopScrolling); |
|
292 |
|
293 listBox->CreateScrollBarFrameL( ETrue ); |
|
294 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
295 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
296 |
|
297 CDesCArray* array = new (ELeave) CDesCArrayFlat( 1 ); |
|
298 CleanupStack::PushL( array ); |
|
299 |
|
300 for ( TInt i = 0; i < commands.Count(); ++i ) |
|
301 { |
|
302 TInt itemLength = commands[i]->Caption().Length() + |
|
303 KTab().Length(); |
|
304 HBufC* item = HBufC::NewLC( itemLength ); |
|
305 TPtr itemPtr = item->Des(); |
|
306 itemPtr.Append( commands[i]->Caption() ); |
|
307 itemPtr.Append( KTab ); |
|
308 |
|
309 array->AppendL( *item ); |
|
310 |
|
311 CleanupStack::PopAndDestroy( item ); |
|
312 item = NULL; |
|
313 } |
|
314 |
|
315 CleanupStack::Pop( array ); |
|
316 listBox->Model()->SetItemTextArray( array ); |
|
317 |
|
318 CleanupStack::Pop( popup ); |
|
319 TInt selectedCommand = -1; |
|
320 if ( popup->ExecuteLD() ) |
|
321 { |
|
322 selectedCommand = listBox->CurrentItemIndex(); |
|
323 } |
|
324 |
|
325 CleanupStack::PopAndDestroy( listBox ); |
|
326 |
|
327 if ( selectedCommand != -1 ) |
|
328 { |
|
329 // This will not work... |
|
330 TRAPD( err, commands[ selectedCommand ]->ExecuteL() ); |
|
331 if ( err != KErrNone ) |
|
332 { |
|
333 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
334 CMCETestUIAppUi* tempUiPtr = (CMCETestUIAppUi*)eikonEnv->AppUi(); |
|
335 TInt errorLength = KLeaveMessage().Length() + 10; |
|
336 HBufC* error = HBufC::NewL( errorLength ); |
|
337 TPtr errorPtr = error->Des(); |
|
338 errorPtr.Append( KLeaveMessage ); |
|
339 errorPtr.AppendNum( err ); |
|
340 // User::InfoPrint( *error ); |
|
341 tempUiPtr->NotifyUser(*error); |
|
342 delete error; |
|
343 } |
|
344 |
|
345 } |
|
346 } |
|
347 |
|
348 // End of File |