|
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 // INCLUDE FILES |
|
19 #include "CMCETestUIAppUi.h" |
|
20 #include "CMCETestUIEventView.h" |
|
21 #include "CMCETestUIEventViewContainer.h" |
|
22 #include "CMCETestUIEventViewModel.h" |
|
23 #include "CMCETestUIEngine.h" |
|
24 #include "CMCETestUIEngineProfile.h" |
|
25 #include "CMCETestUIEngineEvent.h" |
|
26 #include "TMCETestUIEngineCmdBase.h" |
|
27 #include <aknviewappui.h> |
|
28 #include <aknview.h> |
|
29 #include <aknpopup.h> |
|
30 |
|
31 |
|
32 |
|
33 // CONSTANTS |
|
34 _LIT( KTab, "\t" ); |
|
35 _LIT( KLeaveMessage, "Command left with value: " ); |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ========================================== |
|
38 |
|
39 CMCETestUIEventViewContainer* CMCETestUIEventViewContainer::NewL( |
|
40 const TRect& aRect, |
|
41 CMCETestUIEventView& aOwningView, |
|
42 CMCETestUIEngine& aEngine, |
|
43 CMCETestUIEngineEvent& aSession ) |
|
44 { |
|
45 CMCETestUIEventViewContainer* self = |
|
46 new(ELeave) CMCETestUIEventViewContainer( |
|
47 aOwningView, |
|
48 aEngine, |
|
49 aEvent ); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL( aRect ); |
|
52 CleanupStack::Pop(self); |
|
53 return self; |
|
54 } |
|
55 |
|
56 CMCETestUIEventViewContainer::CMCETestUIEventViewContainer( |
|
57 CMCETestUIEventView& aOwningView, |
|
58 CMCETestUIEngine& aEngine, |
|
59 CMCETestUIEngineEvent& aEvent ) |
|
60 :iOwningView( aOwningView ), |
|
61 iEngine( aEngine ), |
|
62 iEvent( aEvent ), |
|
63 iContextMenuAlreadyShown( EFalse ) |
|
64 { |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CMCETestUIEventViewContainer::ConstructL(const TRect& aRect) |
|
69 // EPOC two phased constructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CMCETestUIEventViewContainer::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 = CMCETestUIEventViewModel::NewL( iEngine, iEvent ); |
|
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 // CMCETestUIEventViewContainer::~CMCETestUIEventViewContainer() |
|
108 // Destructor |
|
109 // Frees reserved resources |
|
110 // ----------------------------------------------------------------------------- |
|
111 // |
|
112 CMCETestUIEventViewContainer::~CMCETestUIEventViewContainer() |
|
113 { |
|
114 delete iListBox; |
|
115 } |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CMCETestUIEventViewContainer::~CMCETestUISessionViewContainer() |
|
119 // Destructor |
|
120 // Frees reserved resources |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 void CMCETestUIEventViewContainer::ConstructModelL() |
|
124 { |
|
125 iListBoxModel = CMCETestUIEventViewModel::NewL( iEngine, iEvent ); |
|
126 |
|
127 iListBox->Model()->SetItemTextArray( iListBoxModel ); |
|
128 |
|
129 iListBox->Reset(); |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // CMCETestUIEventViewContainer::SizeChanged() |
|
134 // Called by framework when the view size is changed |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 void CMCETestUIEventViewContainer::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 // CMCETestUIEventViewContainer::SizeChangedL() |
|
151 // Methods that can leave and are needed by SizeChanged |
|
152 // are collected into this method. |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 void CMCETestUIEventViewContainer::SizeChangedL() |
|
156 { |
|
157 |
|
158 } |
|
159 |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // CMCETestUIEventViewContainer::CountComponentControls() const |
|
163 // Note! Output window must be ignored. |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 TInt CMCETestUIEventViewContainer::CountComponentControls() const |
|
167 { |
|
168 if ( iListBox ) |
|
169 return 1; |
|
170 return 0; |
|
171 } |
|
172 |
|
173 |
|
174 // ----------------------------------------------------------------------------- |
|
175 // CMCETestUIEventViewContainer::ComponentControl() |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 CCoeControl* CMCETestUIEventViewContainer::ComponentControl(TInt /*aIndex*/) const |
|
179 { |
|
180 return iListBox; |
|
181 } |
|
182 |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CMCETestUIEventViewContainer::HandleListBoxEventL() |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 void CMCETestUIEventViewContainer::HandleListBoxEventL( |
|
188 CEikListBox*/* aListBox*/, |
|
189 TListBoxEvent /*aEventType */) |
|
190 { |
|
191 |
|
192 } |
|
193 |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CMCETestUIEventViewContainer::Draw(const TRect& aRect) const |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 void CMCETestUIEventViewContainer::Draw(const TRect& aRect ) const |
|
200 { |
|
201 CWindowGc& gc = SystemGc(); |
|
202 gc.Clear( aRect ); |
|
203 } |
|
204 |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // CMCETestUIEventViewContainer::HandleControlEventL( |
|
208 // CCoeControl* aControl,TCoeEvent aEventType) |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 void CMCETestUIEventViewContainer::HandleControlEventL( |
|
212 CCoeControl* /*aControl*/, |
|
213 TCoeEvent /*aEventType*/) |
|
214 { |
|
215 // TODO: Add your control event handler code here |
|
216 } |
|
217 |
|
218 |
|
219 // ----------------------------------------------------------------------------- |
|
220 // CMCETestUIEventViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
221 // TEventCode aType) |
|
222 // Handle key event. Only up and down key arrow events are |
|
223 // consumed in order to enable scrolling in output window. |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 TKeyResponse CMCETestUIEventViewContainer::OfferKeyEventL( |
|
227 const TKeyEvent& aKeyEvent, |
|
228 TEventCode aType) |
|
229 { |
|
230 if ( aType == EEventKeyUp ) |
|
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 CMCETestUIEventViewContainer::DoShowMenuL() |
|
247 { |
|
248 if ( iContextMenuAlreadyShown ) |
|
249 { |
|
250 iContextMenuAlreadyShown = EFalse; |
|
251 return; |
|
252 } |
|
253 |
|
254 // Get command provider |
|
255 MMCETestUIEngineCmdProvider& cmdProvider = |
|
256 iListBoxModel->CmdProvider( iListBox->CurrentItemIndex() ); |
|
257 |
|
258 // Get commands |
|
259 const RPointerArray<TMCETestUIEngineCmdBase>& commands = |
|
260 cmdProvider.GetCommandsL(); |
|
261 |
|
262 |
|
263 // Generate list |
|
264 CAknSinglePopupMenuStyleListBox* listBox = |
|
265 new (ELeave) CAknSinglePopupMenuStyleListBox; |
|
266 CleanupStack::PushL( listBox ); |
|
267 |
|
268 CAknPopupList* popup = CAknPopupList::NewL( |
|
269 listBox, |
|
270 R_AVKON_SOFTKEYS_MENU_LIST, |
|
271 AknPopupLayouts::EPopupSNotePopupWindow ); |
|
272 CleanupStack::PushL( popup ); |
|
273 popup->SetTitleL( _L("Available commands") ); |
|
274 |
|
275 listBox->ConstructL( popup, |
|
276 EAknListBoxSelectionList | EAknListBoxLoopScrolling); |
|
277 |
|
278 listBox->CreateScrollBarFrameL( ETrue ); |
|
279 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
280 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
281 |
|
282 CDesCArray* array = new (ELeave) CDesCArrayFlat( 1 ); |
|
283 CleanupStack::PushL( array ); |
|
284 |
|
285 for ( TInt i = 0; i < commands.Count(); ++i ) |
|
286 { |
|
287 TInt itemLength = commands[i]->Caption().Length() + |
|
288 KTab().Length(); |
|
289 HBufC* item = HBufC::NewLC( itemLength ); |
|
290 TPtr itemPtr = item->Des(); |
|
291 itemPtr.Append( commands[i]->Caption() ); |
|
292 itemPtr.Append( KTab ); |
|
293 |
|
294 array->AppendL( *item ); |
|
295 |
|
296 CleanupStack::PopAndDestroy( item ); |
|
297 item = NULL; |
|
298 } |
|
299 |
|
300 CleanupStack::Pop( array ); |
|
301 listBox->Model()->SetItemTextArray( array ); |
|
302 |
|
303 CleanupStack::Pop( popup ); |
|
304 TInt selectedCommand = -1; |
|
305 if ( popup->ExecuteLD() ) |
|
306 { |
|
307 selectedCommand = listBox->CurrentItemIndex(); |
|
308 } |
|
309 |
|
310 CleanupStack::PopAndDestroy( listBox ); |
|
311 |
|
312 if ( selectedCommand != -1 ) |
|
313 { |
|
314 // This will not work... |
|
315 TRAPD( err, commands[ selectedCommand ]->ExecuteL() ); |
|
316 if ( err != KErrNone ) |
|
317 { |
|
318 CEikonEnv* eikonEnv = CEikonEnv::Static(); |
|
319 CMCETestUIAppUi* tempUiPtr = (CMCETestUIAppUi*)eikonEnv->AppUi(); |
|
320 TInt errorLength = KLeaveMessage().Length() + 10; |
|
321 HBufC* error = HBufC::NewL( errorLength ); |
|
322 TPtr errorPtr = error->Des(); |
|
323 errorPtr.Append( KLeaveMessage ); |
|
324 errorPtr.AppendNum( err ); |
|
325 // User::InfoPrint( *error ); |
|
326 tempUiPtr->NotifyUser(*error); |
|
327 delete error; |
|
328 } |
|
329 |
|
330 } |
|
331 } |
|
332 |
|
333 // End of File |