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