uifw/AvKon/src/aknlistquerydialog.cpp
changeset 0 2f259fa3e83a
child 4 8ca85d2f0db7
child 45 667edd0b8678
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-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 <eikcapc.h>
       
    19 #include <AknMediatorFacade.h>
       
    20 #include <MediatorEventProvider.h>
       
    21 #include <MediatorDomainUIDs.h>
       
    22 #include <SecondaryDisplay/AknSecondaryDisplayDefs.h>
       
    23 
       
    24 #include "aknPopupHeadingPane.h"
       
    25 #include "aknlistquerycontrol.h"
       
    26 #include "aknlistquerysearchcontrol.h"
       
    27 #include "aknlists.h"
       
    28 
       
    29 #include "aknenv.h"
       
    30 #include "aknborders.h"
       
    31 #include "aknconsts.h"
       
    32 
       
    33 #include "avkon.hrh"
       
    34 #include <avkon.rsg>
       
    35 #include <avkon.mbg>
       
    36 
       
    37 #include "aknlistquerydialog.h"
       
    38 #include <AknIconUtils.h>
       
    39 #include <AknIconArray.h>
       
    40 
       
    41 #include <aknsfld.h>
       
    42 #include "aknmessagequerycontrol.h"
       
    43 
       
    44 #include <skinlayout.cdl.h>
       
    45 
       
    46 #include <AknLayout2ScalableDef.h>
       
    47 #include <aknlayoutscalable_avkon.cdl.h>
       
    48 
       
    49 #include <gfxtranseffect/gfxtranseffect.h>
       
    50 #include <akntransitionutils.h>
       
    51 #include <avkondomainpskeys.h>
       
    52 #include <e32property.h>
       
    53 #include <touchfeedback.h>
       
    54 
       
    55 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    56 #include <uikon/eikenvinterface.h>
       
    57 #endif
       
    58 
       
    59 #include <AknTasHook.h> // for testability hooks
       
    60 NONSHARABLE_CLASS(CAknListQueryMediatorObserver): public CBase, public MAknDialogMediatorObserver
       
    61     {
       
    62 public:
       
    63     CAknListQueryMediatorObserver(CArrayFixFlat<TInt>* aItemIdArray, CAknListQueryDialog& aOwner)
       
    64         :iItemIdArray(aItemIdArray), iOwner(aOwner)
       
    65         {}
       
    66     
       
    67     ~CAknListQueryMediatorObserver()
       
    68         {
       
    69         NotifyMediatorExit();
       
    70         delete iItemIdArray;
       
    71         }
       
    72         
       
    73     void SetExternalObserver(MAknDialogMediatorObserver* aObs)
       
    74         {
       
    75         iExternalObserver = aObs;
       
    76         }
       
    77         
       
    78     // From MAknDialogMediatorObserver
       
    79     TAknDialogMediatorObserverCommand MediatorCommandL( TUid aDomain,
       
    80                                        TUid aCategory, 
       
    81                                        TInt aCommandId,
       
    82                                        const TDesC8& aData );
       
    83     
       
    84     void UpdateL(TInt aSelectionIndex);
       
    85     
       
    86     void NotifyMediatorExit()
       
    87         {
       
    88         if (iExternalObserver)
       
    89             iExternalObserver->NotifyMediatorExit();
       
    90         }
       
    91             
       
    92 private:
       
    93     CArrayFixFlat<TInt>* iItemIdArray;
       
    94     CAknListQueryDialog& iOwner;
       
    95     MAknDialogMediatorObserver* iExternalObserver;
       
    96     };
       
    97     
       
    98 TAknDialogMediatorObserverCommand CAknListQueryMediatorObserver::MediatorCommandL( TUid aDomain,
       
    99                                        TUid aCategory, 
       
   100                                        TInt aCommandId,
       
   101                                        const TDesC8& aData )
       
   102     {
       
   103     TAknDialogMediatorObserverCommand ret = EHandleAsNormal;
       
   104     if (iExternalObserver)
       
   105         {
       
   106         ret = iExternalObserver->MediatorCommandL(aDomain, aCategory, aCommandId, aData);
       
   107         }
       
   108     
       
   109     if (ret == EHandleAsNormal && aData.Length() >= sizeof(SAknIntegerUpdate))
       
   110         {
       
   111         SAknIntegerUpdate* params = (SAknIntegerUpdate*) &aData;
       
   112         
       
   113         if (params->iCmd == EAknListQueryUpdateSelection)
       
   114             {
       
   115             TInt newSelectionId = params->iId;
       
   116             for (TInt i = iItemIdArray->Count()-1; i >= 0; i--)
       
   117                 {
       
   118                 if (newSelectionId == iItemIdArray->At(i))
       
   119                     {
       
   120                     CEikListBox* listBox = iOwner.ListBox();
       
   121                     if (listBox)
       
   122                         {
       
   123                         listBox->SetCurrentItemIndex( i );                        
       
   124                         }
       
   125     
       
   126                     break;
       
   127                     }
       
   128                 }
       
   129             return EDoNothingWithThisCommand;
       
   130             }
       
   131         
       
   132         }
       
   133     
       
   134     return EHandleAsNormal;
       
   135     }
       
   136 
       
   137 void CAknListQueryMediatorObserver::UpdateL(TInt aSelectionIndex)
       
   138     {
       
   139     CAknMediatorFacade* dialogClient = AknMediatorFacade(&iOwner);
       
   140     if (dialogClient)
       
   141         {
       
   142         if (aSelectionIndex < iItemIdArray->Count())
       
   143             {
       
   144             SAknIntegerUpdate s = 
       
   145                 {
       
   146                 EAknListQueryUpdateSelection,
       
   147                 iItemIdArray->At(aSelectionIndex)
       
   148                 };
       
   149             
       
   150             TPckg<SAknIntegerUpdate> pck(s);
       
   151             dialogClient->ResetBuffer();
       
   152             dialogClient->BufStream() << pck;
       
   153             dialogClient->BufStream().CommitL();
       
   154             dialogClient->PostUpdatedDataL();
       
   155             }
       
   156         }
       
   157     
       
   158     }
       
   159 
       
   160 EXPORT_C CAknListQueryDialog::CAknListQueryDialog(TInt* aIndex)
       
   161 	: CAknQueryDialog(ENoTone)
       
   162     {
       
   163     iIndex = aIndex;
       
   164     iEnterKeyPressed = EFalse;
       
   165 
       
   166     GfxTransEffect::Register(this,KGfxContextMenuControlUid);
       
   167     AKNTASHOOK_ADD( this, "CAknListQueryDialog" );
       
   168     }
       
   169 
       
   170 
       
   171 EXPORT_C CAknListQueryDialog::CAknListQueryDialog(CListBoxView::CSelectionIndexArray* aSelectionIndexArray)
       
   172 	: CAknQueryDialog(ENoTone)
       
   173 	{
       
   174     iSelectionIndexArray = aSelectionIndexArray;
       
   175     iEnterKeyPressed = EFalse;
       
   176 
       
   177     GfxTransEffect::Register(this,KGfxContextMenuControlUid);
       
   178     AKNTASHOOK_ADD( this, "CAknListQueryDialog" );
       
   179     }
       
   180 
       
   181 EXPORT_C CAknListQueryDialog::~CAknListQueryDialog()
       
   182     {
       
   183     AKNTASHOOK_REMOVE();
       
   184     if (iMediatorObs)
       
   185         CEikDialog::SetMediatorObserver(0); // Cover UI support cannot handle dialog it self as external observer  
       
   186     
       
   187     delete iMediatorObs;
       
   188 	delete iIdle;
       
   189     }
       
   190 
       
   191 EXPORT_C CEikListBox *CAknListQueryDialog::ListBox() const 
       
   192     {
       
   193     return ListControl()->Listbox();
       
   194     }
       
   195 
       
   196 
       
   197 EXPORT_C CAknListQueryControl* CAknListQueryDialog::ListControl() const
       
   198 	{
       
   199 	CCoeControl* controlPtr = FindControlOnAnyPageWithControlType(EAknCtListQueryControl);
       
   200 	if (controlPtr)
       
   201 		return STATIC_CAST(CAknListQueryControl*,controlPtr);
       
   202 	return 0;
       
   203 	}
       
   204 
       
   205 EXPORT_C CAknMessageQueryControl* CAknListQueryDialog::MessageBox() const
       
   206 	{
       
   207     CAknMessageQueryControl* msgCtrl = NULL;
       
   208     CAknListQueryControl* listControl = ListControl();
       
   209     if (listControl)
       
   210         {
       
   211         msgCtrl = listControl->MessageBox();
       
   212         if (msgCtrl) return msgCtrl;
       
   213         }
       
   214 		
       
   215     //if not found let's try dialog (old resources)
       
   216     //this only corrects scrollbar height though
       
   217     CCoeControl* controlPtr = FindControlOnAnyPageWithControlType(EAknCtMessageQuery);
       
   218     if (controlPtr)
       
   219         return STATIC_CAST(CAknMessageQueryControl*,controlPtr);
       
   220     return 0;
       
   221 	}
       
   222 
       
   223 EXPORT_C CAknPopupHeadingPane* CAknListQueryDialog::QueryHeading() const
       
   224 	{
       
   225 	CAknListQueryControl* listControl = ListControl();
       
   226 	if (listControl)
       
   227 		return listControl->Heading();
       
   228 	
       
   229 	return NULL;
       
   230 	}
       
   231 
       
   232 
       
   233 EXPORT_C void CAknListQueryDialog::PreLayoutDynInitL()
       
   234     {
       
   235 	CAknListQuerySearchControl *control1 = (CAknListQuerySearchControl*)ControlOrNull(EFindControl);
       
   236     CAknSearchField *control = NULL;
       
   237     CAknSearchField::TSearchFieldStyle flags = CAknSearchField::EPopupWindow;
       
   238 
       
   239     if (control1)
       
   240         {
       
   241         control = CAknSearchField::NewL( *control1, flags, 0, 40 );
       
   242         control1->iFind = control;
       
   243         }
       
   244     
       
   245     CAknDialog::PreLayoutDynInitL();
       
   246 
       
   247     CEikListBox* listbox = ListBox();
       
   248 	if (listbox)
       
   249 		{
       
   250 		listbox->CreateScrollBarFrameL(ETrue, EFalse, EFalse);
       
   251 		listbox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, 
       
   252                                                         CEikScrollBarFrame::EAuto);
       
   253         listbox->ScrollBarFrame()->DrawBackground( EFalse, EFalse );
       
   254 		listbox->SetListBoxObserver(this);
       
   255     
       
   256 		CAknListQueryControl* listControl = ListControl();
       
   257 		if (listControl)
       
   258 			listControl->SetLayout(&iLayout);
       
   259 		}
       
   260 
       
   261     if (FindBox())
       
   262         {
       
   263         STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->CreateFilterL(ListBox(),FindBox());
       
   264 
       
   265 		// The next line is needed so that drawing order of list query control and find pane becomes
       
   266 		// correct. Seems that dialog page draws focused line last.
       
   267 		SetLineNonFocusing(EListQueryControl);
       
   268 		Line(EFindControl)->SetDrawNoWhiteBackground(ETrue);
       
   269         }        
       
   270 	}
       
   271 
       
   272 EXPORT_C void CAknListQueryDialog::SetIconArrayL(CArrayPtr<CGulIcon>* aIcons)
       
   273     {
       
   274 	CEikFormattedCellListBox* listbox = STATIC_CAST(CEikFormattedCellListBox*,ListBox());
       
   275     CArrayPtr<CGulIcon>* oldicons = listbox->ItemDrawer()->FormattedCellData()->IconArray();
       
   276     
       
   277 	if (oldicons)
       
   278         {
       
   279         oldicons->ResetAndDestroy();
       
   280         delete oldicons;
       
   281         }
       
   282     listbox->ItemDrawer()->FormattedCellData()->SetIconArrayL(aIcons);
       
   283     }
       
   284 
       
   285 EXPORT_C void CAknListQueryDialog::PostLayoutDynInitL()
       
   286     {
       
   287 	CEikFormattedCellListBox* listbox = STATIC_CAST(CEikFormattedCellListBox*,ListBox());
       
   288     
       
   289 	// Now we'll load default icons if existing icon array does not exists.
       
   290     if (!listbox->ItemDrawer()->FormattedCellData()->IconArray())
       
   291         {
       
   292 		CArrayPtr<CGulIcon>* icons = new(ELeave) CAknIconArray(10);
       
   293         CleanupStack::PushL(icons);
       
   294 
       
   295 /* This macro leaves the "icon" on the cleanupstack as "icons" does NOT take 
       
   296 ownership of them.
       
   297 */
       
   298 #define __ADD_ICON_C__(NAME) {CGulIcon* icon = CGulIcon::NewLC();\
       
   299         	                 CFbsBitmap* bitmap = 0;\
       
   300                         	 CFbsBitmap* mask = 0;\
       
   301                              AknIconUtils::CreateIconL( bitmap, mask, KAvkonBitmapFile,\
       
   302 							 NAME, NAME ## _mask);\
       
   303                              icon->SetBitmap(bitmap);\
       
   304                              icon->SetMask(mask);\
       
   305 							 icons->AppendL(icon);\
       
   306 							}
       
   307 
       
   308 		// for every icon added by __ADD_ICON_C, add a CleanupStack::Pop at the bottom.
       
   309 		__ADD_ICON_C__(EMbmAvkonQgn_prop_checkbox_on)
       
   310 		__ADD_ICON_C__(EMbmAvkonQgn_prop_checkbox_off)
       
   311 
       
   312 #undef __ADD_ICON_C__
       
   313 
       
   314         listbox->ItemDrawer()->FormattedCellData()->SetIconArrayL(icons);
       
   315         CleanupStack::Pop(); // icon for EMbmAvkonQgn_prop_checkbox_off
       
   316         CleanupStack::Pop(); // icon for EMbmAvkonQgn_prop_checkbox_on
       
   317         CleanupStack::Pop(); // icons array
       
   318         }
       
   319     }
       
   320 
       
   321 EXPORT_C void CAknListQueryDialog::SetSizeAndPosition(const TSize & /*aSize*/)
       
   322     {
       
   323     AknPopupLayouts::TAknPopupLayouts layout = AknPopupLayouts::EMenuWindow;
       
   324     CAknListQueryControl *control = ListControl();
       
   325     
       
   326     switch(control->Listtype())
       
   327         {
       
   328         case EAknCtSinglePopupMenuListBox:
       
   329             layout = AknPopupLayouts::EMenuWindow;
       
   330             break;
       
   331         case EAknCtSingleGraphicPopupMenuListBox:
       
   332             layout = AknPopupLayouts::EMenuGraphicWindow;
       
   333             break;
       
   334         case EAknCtSingleGraphicHeadingPopupMenuListBox:
       
   335             layout = AknPopupLayouts::EMenuGraphicHeadingWindow;
       
   336             break;
       
   337         case EAknCtMenuDoublePopupMenuListBox:
       
   338             layout = AknPopupLayouts::EMenuDoubleWindow;
       
   339             break;
       
   340         case EAknCtDoubleLargeGraphicPopupMenuListBox:
       
   341             layout = AknPopupLayouts::EMenuDoubleLargeGraphicWindow;
       
   342             break;
       
   343         case EAknCtSingleHeadingPopupMenuListBox:
       
   344             layout = AknPopupLayouts::EMenuGraphicHeadingWindow;
       
   345             break;
       
   346         case EAknCtDouble2PopupMenuListBox:
       
   347             layout = AknPopupLayouts::EMenuDoubleLargeGraphicWindow;
       
   348             break;
       
   349         case EAknCtSingle2GraphicPopupMenuListBox:
       
   350             layout = AknPopupLayouts::EMenuWindow;
       
   351             break;
       
   352         case EAknCtDoubleGraphicPopupMenuListBox:
       
   353             layout = AknPopupLayouts::EMenuDoubleWindow;
       
   354             break;
       
   355         
       
   356         default:
       
   357             __ASSERT_DEBUG(0,Panic(EAknPanicListBoxNotSupportedByListQuery));
       
   358         }
       
   359 
       
   360 	// A linked list for HandleSizeChanged().
       
   361 	TAknPopupLayoutsNode list = { 0, EListNode, control->Listbox() };
       
   362 	TAknPopupLayoutsNode heading = { &list, EHeadingNode, QueryHeading() };
       
   363 	TAknPopupLayoutsNode windowOwning = { &heading, EWindowOwningNode, this };
       
   364 	TAknPopupLayoutsNode messageBox = { &windowOwning, EMessageBoxNode, MessageBox() };
       
   365 	TAknPopupLayoutsNode *listBegin = &messageBox;		
       
   366 
       
   367 	if (FindBox())
       
   368         {
       
   369 		layout = AknPopupLayouts::TAknPopupLayouts(EAknPopupLayoutsFind + layout);
       
   370 		AknPopupLayouts::HandleSizeChanged( iLayout, layout, listBegin);
       
   371         // set layout for fixed find box in popup window - this makes highlights working
       
   372         STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->SetParentControl(this);
       
   373         TRect parentrect = Rect();
       
   374         if ( AknLayoutUtils::PenEnabled() )
       
   375             {
       
   376             TRect screen;
       
   377             TAknLayoutRect cbaRect;
       
   378             AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
   379             cbaRect.LayoutRect( screen, 
       
   380                             AknLayoutScalable_Avkon::popup_sk_window( 0  ).LayoutLine() );
       
   381             TSize size( parentrect.Size() );
       
   382             // subtract softkey height
       
   383             size.iHeight -= cbaRect.Rect().Height();
       
   384             parentrect.SetSize(size);
       
   385             }
       
   386         
       
   387         // popup_find_window overlaps listbox, but this doesn't matter because findbox
       
   388         // doesn't draw background
       
   389         AknLayoutUtils::LayoutControl(FindBox(), parentrect, AknLayoutScalable_Avkon::find_popup_pane_cp2(0).LayoutLine());
       
   390 	    Line(EFindControl)->SetRect(FindBox()->Rect());
       
   391 	    } 
       
   392 	
       
   393     AknPopupLayouts::HandleSizeChanged( iLayout, layout, listBegin);	
       
   394 		
       
   395     CFormattedCellListBoxData *boxData =
       
   396         ((CEikFormattedCellListBox*)ListBox())->ItemDrawer()->FormattedCellData();
       
   397 
       
   398     TRect windowRect = Rect();
       
   399 
       
   400     TAknLayoutRect topLeft;
       
   401     topLeft.LayoutRect(windowRect, SkinLayout::Popup_windows_skin_placing__frame_general__Line_2());
       
   402 
       
   403     TAknLayoutRect bottomRight;
       
   404     bottomRight.LayoutRect(windowRect, SkinLayout::Popup_windows_skin_placing__frame_general__Line_5());
       
   405 
       
   406     TRect outerRect = TRect(topLeft.Rect().iTl, bottomRight.Rect().iBr);
       
   407     TRect innerRect = TRect(topLeft.Rect().iBr, bottomRight.Rect().iTl);
       
   408 
       
   409     boxData->SetSkinPopupFrame(&KAknsIIDQsnFrPopup,&KAknsIIDQsnFrPopupCenter);
       
   410     boxData->SetSkinPopupFramePosition(outerRect,innerRect);
       
   411 
       
   412     }
       
   413     
       
   414 EXPORT_C void CAknListQueryDialog::HandleListBoxEventL(CEikListBox* aListBox, 
       
   415                                                        TListBoxEvent aEventType)
       
   416     {
       
   417     if ( AknLayoutUtils::PenEnabled() )
       
   418         {
       
   419         switch(aEventType)
       
   420             {
       
   421             case EEventEnterKeyPressed:
       
   422                 {
       
   423                 iEnterKeyPressed = ETrue;
       
   424                 break;
       
   425                 }
       
   426             case EEventPenDownOnItem:
       
   427                 {
       
   428                 iDragActioned = 0;
       
   429                 }
       
   430                 break;
       
   431             case EEventItemDraggingActioned:
       
   432             case EEventPanningStarted:
       
   433             case EEventFlickStarted:
       
   434                 {
       
   435                 iDragActioned = 1;
       
   436                 }
       
   437                 break;
       
   438             case EEventItemClicked:
       
   439             case EEventItemSingleClicked:
       
   440                 {
       
   441                 if( !iIdle && !aListBox->IsMultiselection() && !iDragActioned)
       
   442                     {                
       
   443                     iIdle = CIdle::NewL(CActive::EPriorityIdle);                
       
   444                     if (iIdle)
       
   445                         {                    
       
   446                         iIdle->Start(TCallBack(ClosePopupAcceptingChanges, this));
       
   447                         }
       
   448                     }  
       
   449                 }
       
   450                 break;
       
   451             default:
       
   452                 {
       
   453                 break;
       
   454                 }
       
   455             }
       
   456         }
       
   457     else
       
   458         {
       
   459         switch(aEventType)
       
   460     		{
       
   461     		case EEventEnterKeyPressed:
       
   462     			{
       
   463     			iEnterKeyPressed = ETrue;
       
   464     			break;
       
   465     			}
       
   466     		case EEventItemDoubleClicked:
       
   467     		default:
       
   468     			{
       
   469     			break;
       
   470     			}
       
   471     		}
       
   472         }
       
   473     }
       
   474 
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 // If a parent to the supplied control has its Gc set, this function will find 
       
   478 // it and return it.
       
   479 // -----------------------------------------------------------------------------
       
   480 //
       
   481 LOCAL_C CWindowGc* FindRedirGc(const CCoeControl* aControl)
       
   482 	{
       
   483 	const CCoeControl* parent = aControl;
       
   484 	CWindowGc* gc = NULL;
       
   485 	while(parent)
       
   486 		{
       
   487 		if(NULL != (gc = parent->GetGc()))
       
   488 			{
       
   489 			return gc;
       
   490 			}
       
   491 		parent = parent->Parent();
       
   492 		}
       
   493 	return NULL;
       
   494 	}
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // CleanupItem to enable redraws again on the listbox view.
       
   498 // -----------------------------------------------------------------------------
       
   499 //
       
   500 LOCAL_C void CleanupDisableRedraw( TAny *aView )
       
   501     {
       
   502     ((CListBoxView*)aView)->SetDisableRedraw(EFalse);
       
   503     }
       
   504 
       
   505 EXPORT_C TKeyResponse CAknListQueryDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent,
       
   506                                                           TEventCode aType)
       
   507     {
       
   508     if (aType==EEventKey && aKeyEvent.iCode == EKeyEscape)
       
   509         {
       
   510         CloseState();
       
   511         return EKeyWasConsumed;
       
   512         }
       
   513     
       
   514 	TBool needRefresh = EFalse;
       
   515     TKeyResponse res = AknFind::HandleFindOfferKeyEventL(aKeyEvent, aType, this, ListBox(), FindBox(), EFalse, needRefresh);
       
   516     if (needRefresh && FindBox())
       
   517     	{
       
   518 	    DrawNow();
       
   519 	    }
       
   520     if ( res == EKeyWasConsumed ) 
       
   521 		return res;
       
   522 
       
   523 	CEikListBox* listbox = ListBox();
       
   524 	
       
   525     if (listbox)
       
   526         {
       
   527 		TInt redirstate = 0;
       
   528 		TBool redrawdisabled = EFalse;
       
   529 		CWindowGc* redirgc = NULL;
       
   530 	    RProperty::Get(KPSUidAvkonDomain, KAknTfxServerRedirectionStatus,redirstate);
       
   531 	    if (redirstate & ETfxScreenRedirected)
       
   532 	        {
       
   533 	        //If screen is redirected
       
   534 		    redirgc = FindRedirGc(this);
       
   535 		    if(redirgc) 
       
   536 		    	{
       
   537 		    	//And this dialog has a redirgc, we assume its in transition
       
   538 		    	if(EFalse == listbox->View()->RedrawDisabled())
       
   539 		    		{
       
   540 		    		//Then we turn of redraws, since listbox view, when navigating, handles its gc in 
       
   541 		    		// a way that is incompatible with the redirection gc.
       
   542 					listbox->View()->SetDisableRedraw(ETrue);
       
   543 					CleanupStack::PushL(TCleanupItem(CleanupDisableRedraw, listbox->View()));
       
   544 					redrawdisabled = ETrue;
       
   545 		    		}
       
   546 		    	}
       
   547 	        }
       
   548 
       
   549         TInt currentSelection = listbox->CurrentItemIndex();
       
   550         if( currentSelection == KErrNotFound )
       
   551             {
       
   552             MakeLeftSoftkeyVisible(EFalse);
       
   553             }
       
   554         else
       
   555             {
       
   556             MakeLeftSoftkeyVisible(ETrue);
       
   557             }
       
   558             
       
   559         TKeyResponse response = listbox->OfferKeyEventL( aKeyEvent, aType);
       
   560         if (currentSelection != listbox->CurrentItemIndex() && iMediatorObs)
       
   561             {
       
   562             iMediatorObs->UpdateL(listbox->CurrentItemIndex());
       
   563             }
       
   564 
       
   565         if (iEnterKeyPressed)
       
   566             TryExitL(EAknSoftkeyOk);
       
   567         
       
   568 	if(redrawdisabled) 
       
   569 		{
       
   570 		CleanupStack::PopAndDestroy(); //enables redraw again
       
   571 		}
       
   572         return response;
       
   573            
       
   574         }
       
   575         
       
   576     return CAknQueryDialog::OfferKeyEventL(aKeyEvent,aType);
       
   577     }
       
   578 
       
   579 
       
   580 
       
   581 EXPORT_C void CAknListQueryDialog::SetItemTextArray(MDesCArray* aItemTextArray)
       
   582     {
       
   583     STATIC_CAST(CTextListBoxModel*,ListBox()->Model())->SetItemTextArray(aItemTextArray);
       
   584     }
       
   585 
       
   586 EXPORT_C void CAknListQueryDialog::SetOwnershipType(TListBoxModelItemArrayOwnership aOwnershipType)
       
   587     {
       
   588     STATIC_CAST(CTextListBoxModel*,ListBox()->Model())->SetOwnershipType(aOwnershipType);
       
   589     }
       
   590 
       
   591 EXPORT_C TBool CAknListQueryDialog::OkToExitL(TInt aButtonId)
       
   592     {   
       
   593     CEikListBox* listbox = ListBox();
       
   594 
       
   595     if(aButtonId == GetLeftCBAShortKeyPress() || aButtonId == EEikBidOk)
       
   596         {
       
   597         if(iIndex)
       
   598             {
       
   599             *iIndex = listbox->CurrentItemIndex();
       
   600             if (FindBox())
       
   601         	    {
       
   602 	            if (*iIndex != -1)
       
   603 	            *iIndex = STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->FilteredItemIndex(*iIndex);
       
   604 	            }
       
   605             }
       
   606         else if(iSelectionIndexArray)
       
   607             {
       
   608             const CArrayFix<TInt> *array = ListBox()->SelectionIndexes();
       
   609 
       
   610         	if (FindBox())
       
   611 	            {
       
   612 	            STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->UpdateSelectionIndexesL();
       
   613 	            array = STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->SelectionIndexes();
       
   614 	            }
       
   615 	        TInt numberOfItems(array->Count());
       
   616 	        iSelectionIndexArray->Reset();
       
   617 	        for(TInt i(0); i<numberOfItems; i++)
       
   618 	            iSelectionIndexArray->AppendL(array->At(i));
       
   619             }
       
   620         return ETrue;
       
   621         }
       
   622     else if(aButtonId == GetRightCBAShortKeyPress())
       
   623         return ETrue;
       
   624     return EFalse;
       
   625     }
       
   626 
       
   627 EXPORT_C TInt CAknListQueryDialog::BorderStyle()
       
   628     {
       
   629 #ifndef RD_NO_DIALOG_BORDERS
       
   630     return QueryHeading() ? AknBorderId::EAknBorderPopupsWithHeading : AknBorderId::EAknBorderPopups;
       
   631 #else
       
   632     return TGulBorder::ENone;
       
   633 #endif
       
   634     }
       
   635 
       
   636 EXPORT_C void CAknListQueryDialog::CloseState()
       
   637     {
       
   638     TRAP_IGNORE(TryExitL(EAknSoftkeyCancel));
       
   639     }
       
   640 
       
   641 EXPORT_C void CAknListQueryDialog::ActivateL()
       
   642     {
       
   643     TBool notShowingPopup = ListBox()->Model()->NumberOfItems() == 0;
       
   644     if (notShowingPopup)
       
   645         {
       
   646         // We do not show if there's no list items.
       
   647         MakeVisible(EFalse);
       
   648 
       
   649 		// Stops transition
       
   650 		GfxTransEffect::Deregister(this);
       
   651 
       
   652     	if (QueryHeading() && QueryHeading()->Prompt())
       
   653             {
       
   654             TPtr headTitle= QueryHeading()->PromptText();
       
   655   	        iAvkonEnv->ExecuteEmptyPopupListL(ListBox()->View()->EmptyListText(), &headTitle); // show empty popup.
       
   656             }
       
   657         else 
       
   658             {
       
   659             const TDesC *title = 0; // use default if not found
       
   660   	        iAvkonEnv->ExecuteEmptyPopupListL(ListBox()->View()->EmptyListText(), title); // show empty popup.
       
   661             }
       
   662 
       
   663         delete iIdle;
       
   664         iIdle = NULL;
       
   665         iIdle = CIdle::NewL(-20);
       
   666         if (iIdle)
       
   667             iIdle->Start(TCallBack(ClosePopup, this));
       
   668         }
       
   669     else
       
   670         {
       
   671         CAknQueryDialog::ActivateL();
       
   672         }
       
   673     }
       
   674 
       
   675 TInt CAknListQueryDialog::ClosePopup(TAny *aObj)
       
   676     {
       
   677     CAknListQueryDialog *popup = (CAknListQueryDialog*)aObj;
       
   678     delete popup->iIdle;
       
   679     popup->iIdle = 0;
       
   680     popup->CloseState();
       
   681     return EFalse;
       
   682     }
       
   683     
       
   684 EXPORT_C void CAknListQueryDialog::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
   685     {
       
   686     // list query is dismissed if tapped outside
       
   687     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   688         {
       
   689         if( !Rect().Contains( aPointerEvent.iPosition ) )
       
   690             {
       
   691             if ( !iIdle )
       
   692                 {
       
   693                 MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   694                 if ( feedback )
       
   695                     {
       
   696                     feedback->InstantFeedback( ETouchFeedbackPopUp );
       
   697                     }
       
   698                 iIdle = CIdle::NewL(CActive::EPriorityIdle);
       
   699                 iIdle->Start(TCallBack(ClosePopup, this));
       
   700                 return;
       
   701                 }
       
   702             }
       
   703         
       
   704         TInt index;
       
   705         if ( ListBox()->View()->XYPosToItemIndex( aPointerEvent.iPosition, index ) )
       
   706             {
       
   707             ListBox()->View()->ItemDrawer()->SetFlags( 
       
   708                         CListItemDrawer::EPressedDownState );
       
   709             }
       
   710         }
       
   711     
       
   712     CAknQueryDialog::HandlePointerEventL( aPointerEvent );
       
   713     }    
       
   714 
       
   715 // ---------------------------------------------------------
       
   716 // CAknListQueryDialog::ClosePopupAcceptingChanges
       
   717 // Callback function for CIdle to close and accept changes
       
   718 // ---------------------------------------------------------
       
   719 //
       
   720 
       
   721 TInt CAknListQueryDialog::ClosePopupAcceptingChanges(TAny *aObj)
       
   722     {    
       
   723     if ( AknLayoutUtils::PenEnabled() ) 
       
   724         {
       
   725         CAknListQueryDialog *popup = (CAknListQueryDialog*)aObj;
       
   726         delete popup->iIdle;
       
   727         popup->iIdle = NULL;
       
   728         TRAP_IGNORE( popup->TryExitL( EAknSoftkeyOk ) );
       
   729         return EFalse;
       
   730         }
       
   731     else
       
   732         {
       
   733         return EFalse;
       
   734         }
       
   735     }
       
   736 
       
   737 
       
   738 EXPORT_C void* CAknListQueryDialog::ExtensionInterface( TUid /*aInterface*/ ) 
       
   739     { 
       
   740     return NULL;
       
   741     }
       
   742 
       
   743 EXPORT_C void CAknListQueryDialog::CEikDialog_Reserved_1()
       
   744 	{
       
   745 	}
       
   746 
       
   747 EXPORT_C void CAknListQueryDialog::CEikDialog_Reserved_2()
       
   748 	{
       
   749 	}
       
   750 
       
   751 EXPORT_C void CAknListQueryDialog::CAknDialog_Reserved()
       
   752 	{
       
   753 	}
       
   754 
       
   755 EXPORT_C void CAknListQueryDialog::CAknQueryDialog_Reserved()
       
   756 	{
       
   757 	}
       
   758 
       
   759 EXPORT_C CAknSearchField *CAknListQueryDialog::FindBox() const
       
   760     {
       
   761     CAknListQuerySearchControl *control = (CAknListQuerySearchControl*)ControlOrNull(EFindControl);
       
   762     if (control) { return control->iFind; }
       
   763     return NULL;
       
   764     }
       
   765 
       
   766 EXPORT_C void CAknListQueryDialog::SetTone(TInt aTone)
       
   767 	{
       
   768 	iTone = (TTone)aTone;
       
   769 	}
       
   770 
       
   771 EXPORT_C void CAknListQueryDialog::HandleResourceChange(TInt aType)
       
   772 	{
       
   773 	if (aType==KEikDynamicLayoutVariantSwitch)
       
   774 	    {
       
   775 	    if (MessageBox())
       
   776 	        {
       
   777 	        MessageBox()->SizeChanged();	    
       
   778 	        }		
       
   779 	    }	    
       
   780 	CAknQueryDialog::HandleResourceChange(aType);	
       
   781 	}
       
   782     
       
   783 EXPORT_C void CAknListQueryDialog::PublishDialogL(TInt aDialogIndex, TUid aCatUid, CArrayFixFlat<TInt>* aItemIds)
       
   784     {
       
   785     CEikDialog::PublishDialogL(aDialogIndex, aCatUid);
       
   786     delete iMediatorObs;
       
   787     iMediatorObs = 0;
       
   788 
       
   789     if (aItemIds)
       
   790         {
       
   791         CAknMediatorFacade* coverData = AknMediatorFacade(this);
       
   792         if (coverData) // cover functionality enabled
       
   793             {
       
   794             // publish dialog resets the buffer -> Just append data
       
   795             TInt count = aItemIds->Count();
       
   796             coverData->BufStream().WriteInt32L(EAknListQueryItemsInfo);            
       
   797             coverData->BufStream().WriteInt32L(count);
       
   798             for(TInt i = 0;i < count; i++)
       
   799                 {
       
   800                 coverData->BufStream().WriteInt32L(aItemIds->At(i));
       
   801                 }
       
   802             coverData->BufStream().CommitL(); // make sure that this data was added ok
       
   803             iMediatorObs = new (ELeave) CAknListQueryMediatorObserver(aItemIds, *this); // take ownership after other leaving 
       
   804             CEikDialog::SetMediatorObserver(iMediatorObs);                              // methods so we don't cause 
       
   805             }                                                                           // double deletion in case of leave
       
   806         else
       
   807             {
       
   808             delete aItemIds; // we own these currently, as we don't use info, delete directly   
       
   809             }
       
   810         }
       
   811     }	
       
   812 	
       
   813 EXPORT_C void CAknListQueryDialog::SetMediatorObserver(MAknDialogMediatorObserver* aObserver)
       
   814     {
       
   815     if (iMediatorObs) // built in update channel is in use
       
   816         {
       
   817         iMediatorObs->SetExternalObserver(aObserver);
       
   818         }
       
   819     else 
       
   820         {
       
   821         CEikDialog::SetMediatorObserver(aObserver);
       
   822         }
       
   823     }
       
   824 
       
   825 // End of File
       
   826