1 /* |
|
2 * Copyright (c) 2008 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 listbox class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #include <aknViewAppUi.h> |
|
24 #include <badesca.h> |
|
25 #include <eiklbx.h> |
|
26 #include <homemedia.mbg> |
|
27 #include <gulicon.h> |
|
28 #include <eikenv.h> |
|
29 #include <eikapp.h> |
|
30 #include <AknsUtils.h> |
|
31 #include <AknIconUtils.h> |
|
32 #include "homemediaappview.h" |
|
33 #include "homemediabaselistbox.h" |
|
34 |
|
35 //CONSTANTS |
|
36 static const TInt KIconGranularity( 3 ); |
|
37 _LIT( KAknHomeMediaMbmFileName, "\\resource\\apps\\HomeMedia.mif" ); |
|
38 |
|
39 // -------------------------------------------------------------------------- |
|
40 // CHomeMediaBaseListbox::CHomeMediaBaseListbox() |
|
41 // -------------------------------------------------------------------------- |
|
42 // |
|
43 CHomeMediaBaseListbox::CHomeMediaBaseListbox() |
|
44 { |
|
45 // No implementation required |
|
46 } |
|
47 |
|
48 // -------------------------------------------------------------------------- |
|
49 // CHomeMediaBaseListbox::~CHomeMediaBaseListbox() |
|
50 // -------------------------------------------------------------------------- |
|
51 // |
|
52 CHomeMediaBaseListbox::~CHomeMediaBaseListbox() |
|
53 { |
|
54 delete iListBox; |
|
55 } |
|
56 |
|
57 // -------------------------------------------------------------------------- |
|
58 // CHomeMediaBaseListbox::ListBox() |
|
59 // -------------------------------------------------------------------------- |
|
60 // |
|
61 CEikListBox& CHomeMediaBaseListbox::ListBox() |
|
62 { |
|
63 return *iListBox; |
|
64 } |
|
65 |
|
66 // -------------------------------------------------------------------------- |
|
67 // CHomeMediaBaseListbox::AddColumnL() |
|
68 // -------------------------------------------------------------------------- |
|
69 // |
|
70 void CHomeMediaBaseListbox::AddColumnL( TRefByValue<const TDesC> aFmt,... ) |
|
71 { |
|
72 // pointer to list of arguments |
|
73 VA_LIST args; |
|
74 // tells the code where to start the list |
|
75 VA_START(args,aFmt); |
|
76 HBufC* data = HBufC::NewLC(KMaxFileName); |
|
77 // create TOverFlowHandler object in case if there is |
|
78 // huge descriptor passed here |
|
79 TOverFlowHandler overFlow; |
|
80 // now format descriptor |
|
81 data->Des().AppendFormatList( aFmt , args , &overFlow ); |
|
82 // add item to list |
|
83 iListBoxItems->AppendL(*data); |
|
84 CleanupStack::PopAndDestroy(data); |
|
85 // sets pointer to zero |
|
86 VA_END(args); |
|
87 // draw listbox |
|
88 iListBox->HandleItemAdditionL(); |
|
89 iListBox->DrawDeferred(); |
|
90 } |
|
91 |
|
92 // -------------------------------------------------------------------------- |
|
93 // CHomeMediaBaseListbox::SizeChanged() |
|
94 // Called by framework when the view size is changed. |
|
95 // -------------------------------------------------------------------------- |
|
96 // |
|
97 void CHomeMediaBaseListbox::SizeChanged() |
|
98 { |
|
99 const TPoint listPosition(0,0); |
|
100 iListBox->SetExtent(listPosition, iListBox->MinimumSize() ); |
|
101 } |
|
102 |
|
103 // -------------------------------------------------------------------------- |
|
104 // CHomeMediaBaseListbox::OfferKeyEventL() |
|
105 // -------------------------------------------------------------------------- |
|
106 // |
|
107 TKeyResponse CHomeMediaBaseListbox::OfferKeyEventL( |
|
108 const TKeyEvent &aKeyEvent, |
|
109 TEventCode aType) |
|
110 { |
|
111 TKeyResponse ret(EKeyWasNotConsumed); |
|
112 if( aType == EEventKey ) |
|
113 { |
|
114 if( aKeyEvent.iCode == EKeyUpArrow |
|
115 || aKeyEvent.iCode == EKeyDownArrow ) |
|
116 { |
|
117 ret = iListBox->OfferKeyEventL(aKeyEvent, aType); |
|
118 } |
|
119 } |
|
120 return ret; |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // CHomeMediaBaseListbox::CountComponentControls() |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 TInt CHomeMediaBaseListbox::CountComponentControls() const |
|
128 { |
|
129 return 1; |
|
130 } |
|
131 |
|
132 // -------------------------------------------------------------------------- |
|
133 // CHomeMediaBaseListbox::ComponentControl() |
|
134 // -------------------------------------------------------------------------- |
|
135 // |
|
136 CCoeControl* CHomeMediaBaseListbox::ComponentControl(TInt aIndex) const |
|
137 { |
|
138 CCoeControl* ret = NULL; |
|
139 switch( aIndex ) |
|
140 { |
|
141 case 0: |
|
142 ret = iListBox; |
|
143 break; |
|
144 } |
|
145 return ret; |
|
146 } |
|
147 |
|
148 // -------------------------------------------------------------------------- |
|
149 // CHomeMediaBaseListbox::BaseConstructL() |
|
150 // -------------------------------------------------------------------------- |
|
151 // |
|
152 void CHomeMediaBaseListbox::BaseConstructL( const TRect& aRect |
|
153 ,CEikTextListBox* aListBox ) |
|
154 { |
|
155 CreateWindowL(); |
|
156 |
|
157 // take the ownership of aListBox |
|
158 iListBox = aListBox; |
|
159 |
|
160 /** This initializes the C-classes of a newly-created @c CEikTextListBox |
|
161 * from supplied arguments. This function fully constructs the associated |
|
162 * list box model and item drawer for this list box, and then invokes |
|
163 * CEikListBox::ConstructL(). |
|
164 */ |
|
165 iListBox->ConstructL(this); |
|
166 |
|
167 /** |
|
168 * Creates an own window for the list box or draws the list box to an old |
|
169 * window defined by the container. |
|
170 */ |
|
171 iListBox->SetContainerWindowL(*this); |
|
172 |
|
173 // add scrollbars to listbox |
|
174 iListBox->CreateScrollBarFrameL(ETrue); |
|
175 |
|
176 /** |
|
177 * Sets the visibility state for both the horizontal and the vertical |
|
178 * scrollbars. This is used when tiling. |
|
179 */ |
|
180 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
181 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOff); |
|
182 |
|
183 // get the pointer to listbox itemTextArray |
|
184 iListBoxItems |
|
185 = static_cast<CDesCArray*>( iListBox->Model()->ItemTextArray() ); |
|
186 |
|
187 //Set icons |
|
188 CAknIconArray* icons = new (ELeave) CAknIconArray( KIconGranularity ); |
|
189 CleanupStack::PushL( icons ); |
|
190 |
|
191 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
192 TFileName iconsPath( AknIconUtils::AvkonIconFileName( ) ); |
|
193 |
|
194 TFileName mbmFileName( KAknHomeMediaMbmFileName ); |
|
195 TFileName dllName |
|
196 = CEikonEnv::Static()->EikAppUi()->Application()->AppFullName(); |
|
197 TBuf<2> drive = dllName.Left( 2 ); // Drive letter followed by ':' |
|
198 mbmFileName.Insert( 0, drive ); |
|
199 |
|
200 // if new static menu item added constant KNumberOfItemsBeforePlugins |
|
201 // has to be changed |
|
202 AppendIconToArrayL( icons, skin, |
|
203 mbmFileName, |
|
204 KAknsIIDDefault, |
|
205 EMbmHomemediaQgn_prop_upnp_browse_home, |
|
206 EMbmHomemediaQgn_prop_upnp_browse_home_mask ); |
|
207 |
|
208 AppendIconToArrayL( icons, skin, |
|
209 mbmFileName, |
|
210 KAknsIIDDefault, |
|
211 EMbmHomemediaQgn_prop_upnp_share_sub, |
|
212 EMbmHomemediaQgn_prop_upnp_share_sub_mask ); |
|
213 |
|
214 static_cast<CEikFormattedCellListBox*>(iListBox)->ItemDrawer()-> |
|
215 FormattedCellData()->SetIconArray(icons); |
|
216 |
|
217 CleanupStack::Pop(icons); |
|
218 |
|
219 // Set the windows size |
|
220 SetRect( aRect ); |
|
221 // Activate the window, which makes it ready to be drawn |
|
222 ActivateL(); |
|
223 } |
|
224 |
|
225 // -------------------------------------------------------------------------- |
|
226 // CHomeMediaBaseListbox::AppendIconToArrayL() |
|
227 // -------------------------------------------------------------------------- |
|
228 // |
|
229 void CHomeMediaBaseListbox::AppendIconToArrayL(CAknIconArray* aArray, |
|
230 MAknsSkinInstance* aSkin, |
|
231 const TDesC& aMbmFile, |
|
232 const TAknsItemID& aID, |
|
233 TInt aBitmapId, |
|
234 TInt aMaskId) |
|
235 { |
|
236 CFbsBitmap* bitmap = NULL; |
|
237 CFbsBitmap* mask = NULL; |
|
238 |
|
239 AknsUtils::CreateIconLC(aSkin, aID, |
|
240 bitmap, mask, aMbmFile, aBitmapId, aMaskId); |
|
241 |
|
242 CGulIcon* icon = CGulIcon::NewL(bitmap, mask); |
|
243 icon->SetBitmapsOwnedExternally(EFalse); |
|
244 |
|
245 // icon now owns the bitmaps, no need to keep on cleanup stack. |
|
246 CleanupStack::Pop(mask); |
|
247 CleanupStack::Pop(bitmap); |
|
248 bitmap = NULL; |
|
249 mask = NULL; |
|
250 |
|
251 CleanupStack::PushL(icon); |
|
252 |
|
253 aArray->AppendL(icon); |
|
254 |
|
255 // aArray now owns the icon, no need to delete. |
|
256 CleanupStack::Pop(icon); |
|
257 } |
|
258 |
|
259 // End of file |
|