151 |
152 |
152 return TPtrC(iCurrentTitleString); |
153 return TPtrC(iCurrentTitleString); |
153 } |
154 } |
154 |
155 |
155 // --------------------------------------------------------------------------- |
156 // --------------------------------------------------------------------------- |
156 // CGlxSingleGraphicPopupMenuStyleListBox::IsVisible |
157 // CGlxMediaListAdaptor::IsStaticItemSelected |
157 // --------------------------------------------------------------------------- |
158 // --------------------------------------------------------------------------- |
158 // |
159 TBool CGlxMediaListAdaptor::IsStaticItemSelected() |
159 TBool CGlxSingleGraphicPopupMenuStyleListBox::IsVisible(TInt aItemIndex) |
160 { |
160 { |
161 TRACER("CGlxMediaListAdaptor::IsStaticItemSelected"); |
161 TRACER("CGlxSingleGraphicPopupMenuStyleListBox::IsVisible"); |
162 return iStaticItemSelected; |
162 return (TopItemIndex() <= aItemIndex && aItemIndex <= BottomItemIndex()); |
163 } |
163 } |
164 |
164 |
165 // --------------------------------------------------------------------------- |
165 // --------------------------------------------------------------------------- |
166 // CGlxMediaListAdaptor::SetStaticItemSelected |
166 // CGlxSingleGraphicPopupMenuStyleListBox::OfferKeyEventL() |
167 // --------------------------------------------------------------------------- |
167 // --------------------------------------------------------------------------- |
168 void CGlxMediaListAdaptor::SetStaticItemSelected(TBool aSelected) |
168 // |
169 { |
169 EXPORT_C TKeyResponse CGlxSingleGraphicPopupMenuStyleListBox::OfferKeyEventL( |
170 TRACER("CGlxMediaListAdaptor::SetStaticItemSelected"); |
170 const TKeyEvent& aKeyEvent, TEventCode aType) |
171 iStaticItemSelected = aSelected; |
171 { |
172 } |
172 TRACER("CGlxSingleGraphicPopupMenuStyleListBox::OfferKeyEventL"); |
173 |
173 __ASSERT_DEBUG(dynamic_cast< CGlxMediaListAdaptor*>(Model()->ItemTextArray()), Panic(EGlxPanicCastFailed)); |
174 //--------------------------------------------------------------------------- |
174 |
175 // CGlxSingleGraphicPopupMenuStyleList::NewL |
175 if (aKeyEvent.iCode == EKeyOK && iView) |
176 //--------------------------------------------------------------------------- |
176 { |
177 CGlxSingleGraphicPopupMenuStyleList* CGlxSingleGraphicPopupMenuStyleList::NewL( |
177 CGlxMediaListAdaptor* mediaListAdaptor = |
178 CEikListBox* aListBox, TInt aCbaResource, |
178 static_cast<CGlxMediaListAdaptor*> (Model()->ItemTextArray()); |
179 AknPopupLayouts::TAknPopupLayouts aType) |
179 |
180 { |
180 if (mediaListAdaptor->MultiSelectionEnabled() |
181 TRACER("CGlxSingleGraphicPopupMenuStyleList::NewL"); |
181 && View()->CurrentItemIndex() >= 0) |
182 |
182 { |
183 CGlxSingleGraphicPopupMenuStyleList* self = |
183 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item( |
184 new (ELeave) CGlxSingleGraphicPopupMenuStyleList; |
184 View()->CurrentItemIndex()); |
185 CleanupStack::PushL(self); |
185 // Reset the observer to populist |
186 self->ConstructL(aListBox, aCbaResource, aType); |
186 SetListBoxObserver(iPopupList); |
187 CleanupStack::Pop(self); |
187 if (item.IsStatic()) |
188 return self; |
188 { |
189 } |
189 iListBoxFlags &= (~EMultipleSelection); // turn off multiple selection |
190 |
190 } |
191 // --------------------------------------------------------------------------- |
191 else |
192 // CGlxSingleGraphicPopupMenuStyleList::HandleListBoxEventL() |
192 { |
193 // --------------------------------------------------------------------------- |
193 iListBoxFlags |= EMultipleSelection; // turn on multiple selection |
194 // |
194 } |
195 void CGlxSingleGraphicPopupMenuStyleList::HandleListBoxEventL( |
195 } |
196 CEikListBox *aListBox, TListBoxEvent aEventType) |
196 } |
197 { |
197 |
198 TRACER("CGlxSingleGraphicPopupMenuStyleList::HandleListBoxEventL"); |
198 return CAknSingleGraphicPopupMenuStyleListBox::OfferKeyEventL(aKeyEvent, |
199 |
199 aType); |
200 CAknSingleGraphicPopupMenuStyleListBox* listBox = |
200 } |
201 static_cast<CAknSingleGraphicPopupMenuStyleListBox*> (aListBox); |
201 |
202 |
202 // --------------------------------------------------------------------------- |
203 CGlxMediaListAdaptor |
203 // CGlxSingleGraphicPopupMenuStyleListBox::HandleListBoxEventL() |
204 * mediaListAdaptor = |
204 // --------------------------------------------------------------------------- |
205 static_cast<CGlxMediaListAdaptor*> (listBox->Model()->ItemTextArray()); |
205 // |
206 |
206 void CGlxSingleGraphicPopupMenuStyleListBox::HandleListBoxEventL( |
207 TBool staticItemSelected = EFalse; |
207 CEikListBox *aListBox, TListBoxEvent aEventType) |
208 TInt currItemIndx = listBox->View()->CurrentItemIndex(); |
208 { |
209 |
209 TRACER("CGlxSingleGraphicPopupMenuStyleListBox::HandleListBoxEventL"); |
|
210 switch (aEventType) |
210 switch (aEventType) |
211 { |
211 { |
212 case EEventItemClicked: |
212 case EEventItemClicked: |
213 case EEventItemSingleClicked: |
213 case EEventItemSingleClicked: |
214 { |
214 { |
215 CGlxMediaListAdaptor |
215 |
216 * mediaListAdaptor = |
216 if (mediaListAdaptor->MultiSelectionEnabled() && currItemIndx >= 0) |
217 static_cast<CGlxMediaListAdaptor*> (Model()->ItemTextArray()); |
|
218 if (mediaListAdaptor->MultiSelectionEnabled() |
|
219 && View()->CurrentItemIndex() >= 0) |
|
220 { |
217 { |
221 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item( |
218 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item( |
222 View()->CurrentItemIndex()); |
219 currItemIndx); |
223 if (item.IsStatic()) |
220 |
|
221 //Check if media item is user-defined or static |
|
222 staticItemSelected = item.IsStatic(); |
|
223 mediaListAdaptor->SetStaticItemSelected(staticItemSelected); |
|
224 if (!staticItemSelected) |
224 { |
225 { |
225 // when the user marks a non-static item and then clicks on |
226 //Mark or UnMark the user-defined item |
226 // a static item without moving highlight, the control comes here. |
227 TBool isMarked = listBox->View()->ItemIsSelected(currItemIndx); |
227 iListBoxFlags &= (~EMultipleSelection); // turn off multiple selection |
228 (isMarked == (TBool) ETrue) ? (listBox->View()->DeselectItem( |
|
229 currItemIndx)) |
|
230 : (listBox->View()->SelectItemL(currItemIndx)); |
228 } |
231 } |
229 else |
232 |
230 { |
233 //Show Command Set based on selected items |
231 iListBoxFlags |= EMultipleSelection; // turn on multiple selection |
234 TInt selectCount = listBox->View()->SelectionIndexes()->Count(); |
232 |
235 CEikButtonGroupContainer* cbaContainer = ButtonGroupContainer(); |
233 TBool isMarked = View()->ItemIsSelected( |
236 //Show 'OK' only if a static item or more than |
234 View()->CurrentItemIndex()); |
237 //1 user-defined item is selected |
235 (isMarked == (TBool) ETrue) |
238 if(staticItemSelected || selectCount) |
236 ? (View()->DeselectItem( |
239 { |
237 View()->CurrentItemIndex())) |
240 cbaContainer->SetCommandSetL(R_GLX_SOFTKEYS_OK_CANCEL); |
238 : (View()->SelectItemL( |
241 } |
239 View()->CurrentItemIndex())); |
242 else |
240 } |
243 { |
|
244 cbaContainer->SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL); |
|
245 } |
|
246 cbaContainer->DrawDeferred(); |
|
247 |
241 } |
248 } |
242 aListBox->DrawDeferred(); |
249 listBox->DrawDeferred(); |
|
250 |
|
251 //Forward for default processing, if static item is selected(i.e. For Tags) |
|
252 //or if List Box's Multiple selection is Disabled(i.e. For Albums) |
|
253 if (staticItemSelected |
|
254 || (!mediaListAdaptor->MultiSelectionEnabled())) |
|
255 { |
|
256 CAknPopupList::HandleListBoxEventL( aListBox, aEventType); |
|
257 } |
|
258 |
|
259 //After Scrolling, then Select "New Tag" i.e Static item is selected |
|
260 if (staticItemSelected) |
|
261 { |
|
262 ProcessCommandL(EAknSoftkeyOk); |
|
263 } |
|
264 |
243 break; |
265 break; |
244 } |
266 } |
245 default: |
267 default: |
246 break; |
268 { |
247 } |
269 CAknPopupList::HandleListBoxEventL( aListBox, aEventType); |
248 } |
270 break; |
249 |
271 } |
250 // --------------------------------------------------------------------------- |
272 } |
251 // CGlxSingleGraphicPopupMenuStyleListBox::HandlePointerEventL() |
273 } |
252 // --------------------------------------------------------------------------- |
274 |
253 // |
275 // --------------------------------------------------------------------------- |
254 void CGlxSingleGraphicPopupMenuStyleListBox::HandlePointerEventL( |
276 // CGlxSingleGraphicPopupMenuStyleList::HandlePointerEventL() |
255 const TPointerEvent& aPointerEvent) |
277 // --------------------------------------------------------------------------- |
256 { |
278 // |
257 TRACER("CGlxSingleGraphicPopupMenuStyleListBox::HandlePointerEventL"); |
279 void CGlxSingleGraphicPopupMenuStyleList::HandlePointerEventL( |
258 CGlxMediaListAdaptor* mediaListAdaptor = |
280 const TPointerEvent& aPointerEvent) |
259 static_cast<CGlxMediaListAdaptor*> (Model()->ItemTextArray()); |
281 { |
260 if (mediaListAdaptor->MultiSelectionEnabled()) |
282 TRACER("CGlxSingleGraphicPopupMenuStyleList::HandlePointerEventL"); |
261 { |
283 |
262 // Need to handle the case when the highlight is on one item |
284 CAknSingleGraphicPopupMenuStyleListBox* listBox = |
263 // and the user clicks on another media item. The notification |
285 static_cast<CAknSingleGraphicPopupMenuStyleListBox*> (ListBox()); |
264 // of changed item index is received very late. In order to |
286 CGlxMediaListAdaptor |
265 // handle this, checking if the index has changed. |
287 * mediaListAdaptor = |
266 TInt changedItemIndex = -1; |
288 static_cast<CGlxMediaListAdaptor*> (listBox->Model()->ItemTextArray()); |
267 TInt itemIndex = View()->CurrentItemIndex(); |
289 |
268 TBool isItemChanged = View()->XYPosToItemIndex( |
290 //Check for MultipleSelection is Disbaled |
269 aPointerEvent.iPosition, changedItemIndex); |
291 if ( !(mediaListAdaptor->MultiSelectionEnabled()) ) |
270 if (isItemChanged) |
292 { |
271 { |
293 //checking if the index has changed & has valid item available |
272 itemIndex = changedItemIndex; |
294 TInt changedItemIndex = KErrNotFound; |
273 } |
295 TBool isItemAvailable = listBox->View()->XYPosToItemIndex( |
274 const TGlxMedia& item = |
296 aPointerEvent.iPosition, changedItemIndex); |
275 mediaListAdaptor->MediaList()->Item(itemIndex); |
297 if(isItemAvailable) |
276 if (item.IsStatic()) |
298 { |
277 { |
299 //Check if Selected item is static |
278 // A static item is not markable. Turn off multiple selection |
300 const TGlxMedia& item = mediaListAdaptor->MediaList()->Item( |
279 // Set the listbox observer to default that is CAknPopupList |
301 changedItemIndex); |
280 // object, which will process it further. |
302 mediaListAdaptor->SetStaticItemSelected( item.IsStatic() ); |
281 iListBoxFlags &= (~EMultipleSelection); |
303 } |
282 SetListBoxObserver(iPopupList); |
304 } |
283 } |
305 |
284 else |
306 //Forward for default processing |
285 { |
307 CAknPopupList::HandlePointerEventL( aPointerEvent); |
286 // Markable object. The event is handled in HandleListBoxEventL() |
308 |
287 // Set the listbox observer to the current object. |
|
288 SetListBoxObserver(this); |
|
289 } |
|
290 |
|
291 CAknSingleGraphicPopupMenuStyleListBox::HandlePointerEventL( |
|
292 aPointerEvent); |
|
293 |
|
294 const CListBoxView::CSelectionIndexArray* selectionIndices = |
|
295 View()->SelectionIndexes(); |
|
296 CEikButtonGroupContainer* cbaContainer = |
|
297 iPopupList->ButtonGroupContainer(); |
|
298 if (selectionIndices->Count() || item.IsStatic()) |
|
299 { |
|
300 cbaContainer->SetCommandSetL(R_GLX_SOFTKEYS_OK_CANCEL); |
|
301 } |
|
302 else |
|
303 { |
|
304 cbaContainer->SetCommandSetL(R_AVKON_SOFTKEYS_CANCEL); |
|
305 } |
|
306 cbaContainer->DrawDeferred(); |
|
307 } |
|
308 else |
|
309 { |
|
310 CAknSingleGraphicPopupMenuStyleListBox::HandlePointerEventL( |
|
311 aPointerEvent); |
|
312 } |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------------------------- |
|
316 // CGlxSingleGraphicPopupMenuStyleListBox::SetPopupList() |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 void CGlxSingleGraphicPopupMenuStyleListBox::SetPopupList( |
|
320 CAknPopupList* aPopupList) |
|
321 { |
|
322 TRACER("CGlxSingleGraphicPopupMenuStyleListBox::SetPopupList"); |
|
323 iPopupList = aPopupList; |
|
324 } |
309 } |
325 |
310 |
326 // --------------------------------------------------------------------------- |
311 // --------------------------------------------------------------------------- |
327 // Constructor |
312 // Constructor |
328 // --------------------------------------------------------------------------- |
313 // --------------------------------------------------------------------------- |
839 // |
826 // |
840 void CGlxMediaSelectionPopup::ConstructPopupListL(TBool aMultiSelection) |
827 void CGlxMediaSelectionPopup::ConstructPopupListL(TBool aMultiSelection) |
841 { |
828 { |
842 TRACER("CGlxMediaSelectionPopup::ConstructPopupListL"); |
829 TRACER("CGlxMediaSelectionPopup::ConstructPopupListL"); |
843 // create the list box |
830 // create the list box |
844 iListBox = new (ELeave) CGlxSingleGraphicPopupMenuStyleListBox; |
831 iListBox = new (ELeave) CAknSingleGraphicPopupMenuStyleListBox; |
845 |
832 |
846 // create the popup list |
833 // create the popup list |
847 iPopupList = CAknPopupList::NewL(iListBox, R_AVKON_SOFTKEYS_CANCEL); |
834 iPopupList = CGlxSingleGraphicPopupMenuStyleList::NewL( iListBox, R_AVKON_SOFTKEYS_CANCEL) ; |
848 |
835 |
849 // set the title of the popup |
836 // set the title of the popup |
850 __ASSERT_DEBUG(iSelectMediaPopupTitle, Panic(EGlxPanicNullPointer)); |
837 __ASSERT_DEBUG(iSelectMediaPopupTitle, Panic(EGlxPanicNullPointer)); |
851 |
838 |
852 iPopupList->SetTitleL(*iSelectMediaPopupTitle); |
839 iPopupList->SetTitleL(*iSelectMediaPopupTitle); |
853 |
840 |
854 iListBox ->ConstructL(iPopupList, |
841 iListBox ->ConstructL(iPopupList, |
855 aMultiSelection |
842 aMultiSelection |
856 ? EAknListBoxMultiselectionList |
843 ? EAknListBoxMultiselectionList |
857 : EAknListBoxMenuList); |
844 : EAknListBoxMenuList); |
858 iListBox->CreateScrollBarFrameL(); |
845 iListBox->CreateScrollBarFrameL(); |
859 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
846 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
860 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
847 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
861 // create the listbox model |
848 // create the listbox model |
862 iListBox->Model()->SetItemTextArray(iMediaListAdaptor); |
849 iListBox->Model()->SetItemTextArray(iMediaListAdaptor); |
863 iListBox->View()->CalcBottomItemIndex(); |
850 iListBox->View()->CalcBottomItemIndex(); |
864 iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); |
851 iListBox->Model()->SetOwnershipType(ELbmDoesNotOwnItemArray); |
865 |
852 |
866 // Store the pointer of AknPopupList |
853 //set 'iPopupList' as List Box observer |
867 iListBox->SetPopupList(iPopupList); |
854 iListBox->SetListBoxObserver(iPopupList); |
868 } |
855 } |
869 |
856 |
|
857 //----------------------------------------------------------------------------- |
|
858 // CGlxMediaSelectionPopup::IsListBoxItemVisible |
|
859 //----------------------------------------------------------------------------- |
|
860 TBool CGlxMediaSelectionPopup::IsListBoxItemVisible(TInt aIndex) |
|
861 { |
|
862 TRACER("CGlxMediaSelectionPopup::IsListBoxItemVisible"); |
|
863 return iListBox && (iListBox->TopItemIndex() <= aIndex && |
|
864 aIndex <= iListBox->BottomItemIndex()); |
|
865 } |