uifw/AvKon/src/aknPopup.cpp
changeset 0 2f259fa3e83a
child 7 08e69e956a8c
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 // AknPopup.cpp
       
    19 //
       
    20 // Copyright (c) 1997-2001 Symbian Ltd.  All rights reserved.
       
    21 //
       
    22 
       
    23 #include <aknPopupHeadingPane.h>
       
    24 #include <AknPanic.h>
       
    25 #include <aknsfld.h>
       
    26 #include <AknsFrameBackgroundControlContext.h>
       
    27 #include <eikfrlbd.h>
       
    28 #include <eikmop.h>
       
    29 #include <aknlayoutscalable_avkon.cdl.h>
       
    30 #include <skinlayout.cdl.h>
       
    31 #include <aknglobalpopupprioritycontroller.h>
       
    32 #include <touchfeedback.h>
       
    33 
       
    34 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
    35 #include <gfxtranseffect/gfxtranseffect.h>
       
    36 #include <akntransitionutils.h>
       
    37 #endif
       
    38 
       
    39 #include <AknTasHook.h>
       
    40 
       
    41 #include "aknPopup.h"
       
    42 #include "akntrace.h"
       
    43 #include "aknitemactionmenuregister.h"
       
    44 
       
    45 const TInt KSpaceBelowTitle=7;
       
    46 const TInt KSoftkeyHeightUndefined = -1;
       
    47 
       
    48 enum TPopUpListFlags
       
    49     {    
       
    50     EPopupHandlingPointerEvent    = 0x01,
       
    51     EPopupAcceptAfterPointerEvent = 0x02,
       
    52     
       
    53     //EFTG-7HWDP6.
       
    54     //When portrait is initial model, and 'Full screen QWERTY keyboard' is default input method,
       
    55     //the behavior that double tap edit's area quickly may be treated by different control.
       
    56     //Findpane deals with first tapping, the Fep will be invoked,Then the model will changed from portrait to landscape.
       
    57     //Popuplist deals with second tapping. It invoke AttemptExitL( Efalse ) because pointer is outside of the popuplist.
       
    58     //The result is 'Full Screen QWERTY Keyboard' colsed. So we must prevent popuplist's exit in this case.
       
    59     //EPopupFepStartEvent will prevent popuplist's exit.        
       
    60     //EPopupLayoutSwitchEvent is a flag that decide EPopupFepStartEvent is valid or not.
       
    61     EPopupFepStartEvent           = 0x04,   
       
    62     EPopupLayoutSwitchEvent       = 0x08,
       
    63     
       
    64     // Multiselect popup list should not close when delay highlight happen 
       
    65     EPopupDelayHighlight          = 0x10,
       
    66     EPopupCancelAfterPointerEvent = 0x20,
       
    67     // Popup application is single click enabled.
       
    68     EPopupSingleClickEnabled      = 0x40
       
    69     };
       
    70  
       
    71 
       
    72 /**
       
    73 * Calculates and returns softkey rectangle.
       
    74 */
       
    75 static TRect SoftkeyRect()
       
    76     {
       
    77     TRect screen;
       
    78     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen );
       
    79            
       
    80     TAknLayoutRect softkeyRect;
       
    81     softkeyRect.LayoutRect( screen, 
       
    82         AknLayoutScalable_Avkon::popup_sk_window( 0 ).LayoutLine() );
       
    83     
       
    84     return softkeyRect.Rect();
       
    85     }
       
    86 
       
    87  
       
    88 NONSHARABLE_CLASS(CAknPopupListExtension): public CBase
       
    89     {
       
    90     public:
       
    91         CAknPopupListExtension();
       
    92         ~CAknPopupListExtension();
       
    93 
       
    94         /**
       
    95          * Returns ETrue if popup pointer event is accepted otherwise EFalse.
       
    96          * 
       
    97          * @param aListBox Popup list listbox.
       
    98          * @return ETrue if event is accepted.
       
    99          */
       
   100         TBool AcceptPointerEvent( CEikListBox* aListBox ) const;
       
   101 
       
   102         /**
       
   103          * Returns ETrue if list box event is accepted otherwise EFalse.
       
   104          * 
       
   105          * @param aListBox Popup list listbox.
       
   106          * @param aEventType List event type.
       
   107          * @return ETrue if event is accepted.
       
   108          */
       
   109         TBool AcceptListBoxEvent(
       
   110                 CEikListBox* aListBox,
       
   111                 MEikListBoxObserver::TListBoxEvent aEventType ) const;
       
   112 
       
   113     public:
       
   114         CAknSearchField* iSearchControl;    // owned
       
   115         CAknsFrameBackgroundControlContext* iBgContext;        
       
   116  
       
   117         TInt  iFlags;    
       
   118         TBool iItemDraggingActioned;  
       
   119     };
       
   120 
       
   121 CAknPopupListExtension::CAknPopupListExtension()
       
   122     {
       
   123     if ( AknLayoutUtils::PenEnabled() )
       
   124         {
       
   125         iFlags = 0;
       
   126         }
       
   127     }
       
   128 
       
   129 CAknPopupListExtension::~CAknPopupListExtension()
       
   130     {
       
   131     delete iBgContext;
       
   132     }
       
   133 
       
   134 
       
   135 TBool CAknPopupListExtension::AcceptPointerEvent(
       
   136         CEikListBox* aListBox ) const
       
   137     {
       
   138     TBool accept( EFalse );
       
   139     if ( aListBox )
       
   140         {
       
   141         // Do not accept if multiselection
       
   142         // or flag does not allow accepting
       
   143         // or highlight is disabled (list is view only)
       
   144         accept = !aListBox->IsMultiselection()
       
   145             && ( iFlags & EPopupAcceptAfterPointerEvent
       
   146             || iFlags & EPopupCancelAfterPointerEvent )
       
   147             && !( aListBox->View()->ItemDrawer()->Flags()
       
   148                     & CListItemDrawer::EDisableHighlight );
       
   149         }
       
   150     return accept;
       
   151     }
       
   152 
       
   153 TBool CAknPopupListExtension::AcceptListBoxEvent(
       
   154         CEikListBox* aListBox,
       
   155         MEikListBoxObserver::TListBoxEvent aEventType ) const
       
   156     {
       
   157     TBool accept( EFalse );
       
   158     if ( aListBox )
       
   159         {
       
   160         switch ( aEventType )
       
   161             {
       
   162             case ( MEikListBoxObserver::EEventItemClicked ):
       
   163             case ( MEikListBoxObserver::EEventItemSingleClicked ):
       
   164                 {
       
   165                 if ( iItemDraggingActioned
       
   166                         || aListBox->IsMultiselection()
       
   167                         || ( !( iFlags & EPopupSingleClickEnabled )
       
   168                                 && !AknLayoutUtils::PenEnabled() ) )
       
   169                     {
       
   170                     break;
       
   171                     }
       
   172                 } // Fall through
       
   173             case ( MEikListBoxObserver::EEventEnterKeyPressed ):
       
   174                 {
       
   175                 accept = ETrue;
       
   176                 break;
       
   177                 }
       
   178             default:
       
   179                 {
       
   180                 break;
       
   181                 }
       
   182             }
       
   183         }
       
   184     return accept;
       
   185     }
       
   186 
       
   187 
       
   188 /**
       
   189 * Constructor
       
   190 *
       
   191 */
       
   192 EXPORT_C CAknPopupList::CAknPopupList()
       
   193     {
       
   194     SetMopParent(iEikonEnv->EikAppUi());
       
   195 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   196     GfxTransEffect::Register( this, KGfxContextMenuControlUid );
       
   197 #endif
       
   198     }
       
   199 
       
   200 /**
       
   201 * Destructor
       
   202 *
       
   203 */
       
   204 EXPORT_C CAknPopupList::~CAknPopupList()
       
   205     {
       
   206     _AKNTRACE_FUNC_ENTER;
       
   207     AKNTASHOOK_REMOVE();
       
   208     if ( iPopoutCba )
       
   209         {
       
   210         iPopoutCba->MakeVisible( EFalse );
       
   211         }
       
   212 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   213     // prevent drawing when Deregistering
       
   214     MakeVisible( EFalse ); 
       
   215     GfxTransEffect::Deregister( this );
       
   216 #endif
       
   217     if (iCoeEnv && iEikonEnv)
       
   218         {
       
   219         iEikonEnv->RemoveFromStack(this);
       
   220         if (iAppBroughtForwards)
       
   221             iEikonEnv->BringForwards(EFalse);
       
   222         }
       
   223     if (iReturn)
       
   224         {
       
   225         FadeBehindPopup(EFalse);
       
   226         }
       
   227     AknGlobalPopupPriorityController::RemovePopupPriority(*this);
       
   228     delete iTitle;
       
   229     delete iPopoutCba;
       
   230     delete iIdle;
       
   231     if (FindBox())
       
   232         {
       
   233         delete FindBox();
       
   234         }
       
   235     delete iPopupListExtension;
       
   236     // Only stop the scheduler if a return value has been set -
       
   237     // otherwise the construction failed before the scheduler started.
       
   238     // The iReturn value is a convienient value to use since it is the
       
   239     // last member ste before the actiave scheduler is started.
       
   240 
       
   241     // Reset action menu register
       
   242     AknItemActionMenuRegister::SetConstructingMenuBarOwnerL( NULL );
       
   243     _AKNTRACE_FUNC_EXIT;
       
   244     }
       
   245 
       
   246 EXPORT_C void CAknPopupList::CloseState()
       
   247     {
       
   248     _AKNTRACE_FUNC_ENTER;
       
   249     CancelPopup();
       
   250     _AKNTRACE_FUNC_EXIT;
       
   251     }
       
   252 
       
   253 
       
   254 EXPORT_C void CAknPopupList::SetMaximumHeight(TInt aItems)
       
   255     {
       
   256     _AKNTRACE("CAknPopupList::SetMaximumHeight aItems=%d", aItems);
       
   257     iLayout.iMaximumHeight = aItems;
       
   258     }
       
   259 
       
   260 /**
       
   261 * Creates the pop-up list
       
   262 *
       
   263 * @param        aListBox        Pre-existing listbox-derived class
       
   264 * @param        aCbaResource        Softkey pane to display while pop-up is active
       
   265 */
       
   266 EXPORT_C CAknPopupList* CAknPopupList::NewL(CEikListBox* aListBox, TInt aCbaResource, AknPopupLayouts::TAknPopupLayouts aType)
       
   267     {
       
   268     _AKNTRACE_FUNC_ENTER;
       
   269     CAknPopupList* self = new(ELeave)CAknPopupList();        
       
   270     CleanupStack::PushL(self);
       
   271     self->ConstructL(aListBox, aCbaResource, aType);
       
   272     CleanupStack::Pop();        // self
       
   273     AKNTASHOOK_ADDL( self, "CAknPopupList" );
       
   274     _AKNTRACE_FUNC_EXIT;
       
   275     return self;
       
   276     }
       
   277 
       
   278 /**
       
   279 * 2nd phase construction
       
   280 *
       
   281 */
       
   282 EXPORT_C void CAknPopupList::ConstructL(CEikListBox* aListBox, TInt aCbaResource, AknPopupLayouts::TAknPopupLayouts aType)
       
   283     {
       
   284     _AKNTRACE_FUNC_ENTER;
       
   285     CreateWindowL();
       
   286     Window().SetPointerGrab(ETrue);
       
   287     if( CAknEnv::Static()->TransparencyEnabled() )
       
   288         {
       
   289         Window().SetRequiredDisplayMode( EColor16MA );
       
   290         TInt err = Window().SetTransparencyAlphaChannel();
       
   291 
       
   292         if ( err == KErrNone )
       
   293             {
       
   294             Window().SetBackgroundColor(~0);
       
   295             }
       
   296         }
       
   297 
       
   298     iListBox = aListBox;
       
   299     iWindowType = aType;
       
   300     // Set a popout-type border
       
   301 
       
   302     iBorder.SetType(TGulBorder::ENone);
       
   303     iListBox->SetBorder(TGulBorder::ENone);
       
   304 
       
   305     // Create extension class
       
   306     if (!iPopupListExtension)
       
   307         iPopupListExtension = new (ELeave) CAknPopupListExtension(); 
       
   308 
       
   309     CAknAppUi* appUi = static_cast<CAknAppUi*>( iEikonEnv->EikAppUi() );
       
   310     if ( appUi && appUi->IsSingleClickCompatible() )
       
   311         {
       
   312         iPopupListExtension->iFlags |= EPopupSingleClickEnabled;
       
   313         }
       
   314 
       
   315     // If the system 'markable' CBA's are used, flag the listbox
       
   316     // as markable. (This allows it to update the CBA when the selected item
       
   317     // is changed).
       
   318     if (aCbaResource == R_AVKON_SOFTKEYS_MARK_BACK ||
       
   319         aCbaResource == R_AVKON_SOFTKEYS_UNMARK_BACK)
       
   320         iMarkable = ETrue;
       
   321 
       
   322     iCurrentResource = aCbaResource;
       
   323 
       
   324     // Create a CBA for use with the popup
       
   325 
       
   326     TUint flags = CEikButtonGroupContainer::EAddToStack;
       
   327 
       
   328     // Embedded CBA only in touch layout
       
   329     if ( AknLayoutUtils::PenEnabled() )
       
   330         {
       
   331         flags |= CEikButtonGroupContainer::EIsEmbedded;
       
   332         flags |= CEikButtonGroupContainer::EDelayActivation;
       
   333         }
       
   334     
       
   335     // Notify action menu register though popup list has no menubar.
       
   336     // This way item action menu and list is linked correctly and item
       
   337     // specific softkey state is changed according to list highlight.
       
   338     AknItemActionMenuRegister::SetConstructingMenuBarOwnerL( this );
       
   339     iPopoutCba = CEikButtonGroupContainer::NewL(
       
   340                 CEikButtonGroupContainer::ECba,
       
   341                 CEikButtonGroupContainer::EHorizontal,
       
   342                 this, iCurrentResource, *this, flags );
       
   343     
       
   344     // non visible CBA's do not recieve keys
       
   345     iPopoutCba->MakeVisible(EFalse);
       
   346 
       
   347 	AknGlobalPopupPriorityController::AddSubPopupL(*this, *iPopoutCba->ButtonGroup()->AsControl());
       
   348 
       
   349     iPopupListExtension->iBgContext = NULL;
       
   350  
       
   351     SetGloballyCapturing( ETrue );
       
   352     SetPointerCapture( ETrue );
       
   353 
       
   354     _AKNTRACE_FUNC_EXIT;
       
   355     }
       
   356 
       
   357 /**
       
   358 * Set the title for the selection list
       
   359 *
       
   360 * @param        aTitle        Title to be displayed
       
   361 */
       
   362 EXPORT_C void CAknPopupList::SetTitleL(const TDesC& aTitle)
       
   363     {
       
   364     _AKNTRACE("CAknPopupList::SetTitleL: aTitle=%S",&aTitle);
       
   365     if (!iTitle)
       
   366         {
       
   367         iTitle = new(ELeave)CAknPopupHeadingPane;
       
   368         iTitle->SetContainerWindowL(*this);
       
   369         iTitle->ConstructL(aTitle);
       
   370         } 
       
   371     else 
       
   372         {
       
   373         iTitle->SetTextL(aTitle);
       
   374         }
       
   375     }
       
   376 
       
   377 /**
       
   378 * Executes the pop-up selection list. Only returns when the user can accepted
       
   379 * or cancelled the pop-up.
       
   380 *
       
   381 * @return        ETrue if the popup was accepted. EFalse if the popup was cancelled
       
   382 */
       
   383 EXPORT_C TBool CAknPopupList::ExecuteLD()
       
   384     {
       
   385     _AKNTRACE_FUNC_ENTER;
       
   386     __ASSERT_DEBUG(iListBox,Panic(EAknPanicListboxUndefined));
       
   387     iPopoutCba->SetBoundingRect(TRect(iAvkonAppUi->ApplicationRect().Size()));
       
   388     
       
   389     // Disable item specific menu just before the popup is about to be shown.
       
   390     // It can't be done earlier since CAknPopupList doesn't know whether the
       
   391     // embedded listbox is fully constructed when passed to its constructor or
       
   392     // not.
       
   393     iListBox->DisableItemSpecificMenu();
       
   394 
       
   395     // Technically it's wrong to disable findbox here, but doing so improves
       
   396     // compatibility with the old CAknEnv::ExecuteEmptyPopupListL implementation.
       
   397     // This code block can be removed to make the findbox permanently visible
       
   398     // (as is the case with main pane lists that use a fixed findbox).
       
   399     if ( FindBox() && iListBox->Model()->NumberOfItems() == 0 )
       
   400         {
       
   401         STATIC_CAST(CAknFilteredTextListBoxModel*,
       
   402                     ListBox()->Model())->Filter()->SetSearchField( NULL );
       
   403         FindBox()->Editor().SetFocus( EFalse );                    
       
   404         delete iPopupListExtension->iSearchControl;
       
   405         iPopupListExtension->iSearchControl = NULL;
       
   406         }
       
   407 
       
   408     if (FindBox())
       
   409         {
       
   410         SetupWindowLayout(AknPopupLayouts::TAknPopupLayouts(EAknPopupLayoutsFind + iWindowType));
       
   411         }        
       
   412     else
       
   413         {
       
   414         SetupWindowLayout(iWindowType);
       
   415         }
       
   416 
       
   417     iListBox->SetListBoxObserver(this);        
       
   418     iPopoutCba->MakeVisible(ETrue);
       
   419 
       
   420     AknGlobalPopupPriorityController::AddPopupToControlStackL(*this,ECoeStackPriorityDialog);
       
   421     AknGlobalPopupPriorityController::AddPopupToControlStackL(*iPopoutCba->ButtonGroup()->AsControl(),
       
   422         ECoeStackPriorityCba, ECoeStackFlagRefusesFocus );
       
   423     SetFocus(ETrue);
       
   424 
       
   425     if (iMarkable)
       
   426         {
       
   427         // If markable, set the popup to observe event change events.
       
   428         // Call HandleControlEvent to set the CBA appropriate to the 1st item
       
   429         iListBox->SetObserver(this);
       
   430         HandleControlEventL(iListBox, EEventStateChanged);
       
   431         }
       
   432 
       
   433     FadeBehindPopup( ETrue );
       
   434     
       
   435     
       
   436     #ifdef RD_UI_TRANSITION_EFFECTS_PHASE2	
       
   437     // this code finds out if this control belongs to focused window group
       
   438     // this is done to find out if popuplist is shown behind another dialog
       
   439     // (this happens in wlan setup queries) If popuplist is not on foreground
       
   440     // the transition effect is skipped
       
   441     RWsSession& wsSession = CEikonEnv::Static()->WsSession();
       
   442 	
       
   443 	TInt focusGroup = wsSession.GetFocusWindowGroup();
       
   444 		
       
   445     TInt count = wsSession.NumWindowGroups(0);
       
   446     TBool thisIsFocused( EFalse );
       
   447     
       
   448     CArrayFixFlat<TInt>* wgIds=new(ELeave) CArrayFixFlat<TInt>(count);
       
   449     CleanupStack::PushL(wgIds);
       
   450     // Get list of window group ids from WServ
       
   451     wsSession.WindowGroupList(0,wgIds);
       
   452     // Select the first in the list (which will always be the forground app)
       
   453     TInt wgId = (*wgIds)[0];
       
   454     
       
   455     if( focusGroup == wgId )
       
   456         thisIsFocused = ETrue;
       
   457         
       
   458     CleanupStack::PopAndDestroy();  // wgIds;
       
   459     
       
   460     
       
   461 	#endif //RD_UI_TRANSITION_EFFECTS_PHASE2
       
   462 	
       
   463 	
       
   464 
       
   465 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   466 	if( GfxTransEffect::IsRegistered(this) && thisIsFocused )
       
   467 		{
       
   468     MakeVisible( EFalse );
       
   469     CAknTransitionUtils::MakeVisibleSubComponents( this,
       
   470                                         CAknTransitionUtils::EForceInvisible );
       
   471 		}
       
   472 #endif
       
   473 
       
   474     ActivateL();
       
   475     iPopoutCba->ActivateL();
       
   476 
       
   477     // this is required here to make code like
       
   478     // iList->SetCurrentItemIndex( last item of the list );
       
   479     // iPopupList->ExecuteLD();
       
   480     // to work as it used to. Without this current item of the
       
   481     // list would be topmost item, and there would be unused empty
       
   482     // space below that.
       
   483     iListBox->UpdateScrollBarsL();
       
   484     
       
   485 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   486     if(GfxTransEffect::IsRegistered(this) && thisIsFocused )
       
   487         {
       
   488         CAknTransitionUtils::SetAllParents(this);
       
   489 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   490         // sequence support
       
   491         GfxTransEffect::NotifyExternalState(EInternalHandleSequence, (const TDesC8*)this);
       
   492 #endif
       
   493         GfxTransEffect::Begin(this, KGfxControlAppearAction);
       
   494         GfxTransEffect::NotifyExternalState(ECaptureComponentsBegin, (const TDesC8*)this);
       
   495         
       
   496         TRect demarcation;
       
   497         CAknTransitionUtils::GetDemarcation(CAknTransitionUtils::EPopup, demarcation);
       
   498         GfxTransEffect::SetDemarcation(this, demarcation);
       
   499 
       
   500         MakeVisible(ETrue);
       
   501         CAknTransitionUtils::MakeVisibleSubComponents( this,
       
   502                                         CAknTransitionUtils::EForceVisible );
       
   503 
       
   504         GfxTransEffect::NotifyExternalState(ECaptureComponentsEnd, (const TDesC8*)this);
       
   505         GfxTransEffect::End(this);
       
   506         }
       
   507     else
       
   508         {
       
   509         MakeVisible(ETrue);
       
   510         }
       
   511 #endif        
       
   512     
       
   513     if (!iAppBroughtForwards)
       
   514         {
       
   515         iEikonEnv->BringForwards(ETrue);
       
   516         iAppBroughtForwards = ETrue;
       
   517         AknGlobalPopupPriorityController::ShowPopup(*this, ETrue);
       
   518         }
       
   519 
       
   520     TBool returnValue;
       
   521     iReturn = &returnValue;
       
   522     iWait.Start();
       
   523     delete this;
       
   524     _AKNTRACE_FUNC_EXIT;
       
   525     return returnValue;
       
   526     }
       
   527 
       
   528 EXPORT_C void CAknPopupList::FadeBehindPopup(TBool aFade)
       
   529     {
       
   530     // Real fade state is only set on when the dialog is visible
       
   531     if (!IsVisible())
       
   532         aFade = EFalse;
       
   533 
       
   534 	AknGlobalPopupPriorityController::FadeBehindPopup(*this, iPopupFader, *this, aFade);
       
   535     }
       
   536 
       
   537 
       
   538 EXPORT_C TSize CAknPopupList::MinimumSize()
       
   539     {
       
   540     iListBox->View()->CalcDataWidth();
       
   541     TInt minWidth = iListBox->CalcWidthBasedOnRequiredItemWidth(iListBox->View()->DataWidth());
       
   542     if (Heading())
       
   543         {
       
   544         minWidth = Max(minWidth, Heading()->MinimumSize().iWidth);
       
   545         }
       
   546     TInt minHeight = iListBox->MinimumSize().iHeight;
       
   547     if (Heading())
       
   548         {
       
   549         minHeight += KSpaceBelowTitle + Heading()->MinimumSize().iHeight;
       
   550         }
       
   551     return TSize(minWidth,minHeight);
       
   552     }
       
   553 
       
   554 
       
   555 EXPORT_C void CAknPopupList::Draw(const TRect& /*aRect*/) const
       
   556     {
       
   557     _AKNTRACE_FUNC_ENTER;
       
   558     CWindowGc& gc = SystemGc();
       
   559     gc.Clear();
       
   560 
       
   561     AknPopupLayouts::HandleDraw(iEikonEnv, gc, Layout(), iListBox, Heading());
       
   562     _AKNTRACE_FUNC_EXIT;
       
   563     }
       
   564 
       
   565 // Get component controls into a table
       
   566 const TInt KMaxPopupListControls = 6;
       
   567 
       
   568 static TInt ComponentControls( CEikListBox* aListBox,
       
   569     CAknPopupHeadingPane* aHeading, CAknSearchField* aFindBox,
       
   570     CCoeControl* aCba,
       
   571     CCoeControl* aControls[KMaxPopupListControls] )
       
   572     {
       
   573     TInt i = 0;
       
   574     aControls[i++] = aListBox;
       
   575     if (aHeading)
       
   576         {
       
   577         aControls[i++] = aHeading;
       
   578         }
       
   579     if (aFindBox)
       
   580         {
       
   581         aControls[i++] = aFindBox;
       
   582         }
       
   583 
       
   584     if ( aCba )
       
   585         {
       
   586         aControls[i++] = aCba;
       
   587         }
       
   588     
       
   589     // In order to support non-window owning scroll bar, it is returned as a
       
   590     // component of CAknPopupList. It is also component of CEikListBox. This
       
   591     // does not cause any harm. Otherwise drawing would not work as scroll
       
   592     // bars are outside of list box rectangle.
       
   593     CEikScrollBarFrame* scrollBarFrame = aListBox->ScrollBarFrame();
       
   594     if (scrollBarFrame)
       
   595         {
       
   596         CEikScrollBar* scrollBar = scrollBarFrame->GetScrollBarHandle(
       
   597             CEikScrollBar::EVertical);
       
   598         if (scrollBar && !scrollBar->OwnsWindow())
       
   599             {
       
   600             aControls[i++] = scrollBar;
       
   601             }
       
   602         scrollBar = scrollBarFrame->GetScrollBarHandle(
       
   603             CEikScrollBar::EHorizontal);
       
   604         if (scrollBar && !scrollBar->OwnsWindow())
       
   605             {
       
   606             aControls[i++] = scrollBar;
       
   607             }
       
   608         }
       
   609     return i;
       
   610     }
       
   611 
       
   612 EXPORT_C TInt CAknPopupList::CountComponentControls() const
       
   613     {
       
   614      CCoeControl* controls[KMaxPopupListControls];
       
   615 
       
   616      return ComponentControls( iListBox, 
       
   617                                Heading(), 
       
   618                                FindBox(), 
       
   619                                iPopoutCba->ButtonGroup()->AsControl(), 
       
   620                                controls );
       
   621     }
       
   622 
       
   623 EXPORT_C CCoeControl* CAknPopupList::ComponentControl(TInt aIndex) const
       
   624     {
       
   625      CCoeControl* controls[KMaxPopupListControls];
       
   626 
       
   627      TInt cnt = ComponentControls( iListBox, 
       
   628                                    Heading(), 
       
   629                                    FindBox(), 
       
   630                                    iPopoutCba->ButtonGroup()->AsControl(),
       
   631                                    controls );
       
   632 
       
   633      if (aIndex < cnt)
       
   634         {
       
   635         return controls[aIndex];
       
   636         }
       
   637     else
       
   638         {
       
   639         return NULL;
       
   640         }
       
   641     }
       
   642 
       
   643 /**
       
   644 * Processes events from the softkeys. Responds to EAknSoftkeyOk and EAknSoftkeyBack
       
   645 * to accept or cancel the pop-up.
       
   646 *
       
   647 * @param        aCommandId        Event Id from the soft-key
       
   648 */
       
   649 EXPORT_C void CAknPopupList::ProcessCommandL(TInt aCommandId)
       
   650     {
       
   651     _AKNTRACE_FUNC_ENTER;
       
   652     _AKNTRACE("ProcessCommandL: aCommandId=%d", aCommandId);
       
   653     // Respond to softkey events
       
   654     switch (aCommandId)
       
   655         {
       
   656         case EAknSoftkeySelect:
       
   657         case EAknSoftkeyYes:
       
   658         case EAknSoftkeyOk:
       
   659         case EAknSoftkeyDone:
       
   660             iPopupListExtension->iFlags &= ~EPopupFepStartEvent;
       
   661             AttemptExitL(ETrue);
       
   662             break;
       
   663         case EAknSoftkeyExit:
       
   664         case EAknSoftkeyClose:
       
   665         case EAknSoftkeyNo:
       
   666         case EAknSoftkeyCancel:
       
   667         case EAknSoftkeyBack:
       
   668             iPopupListExtension->iFlags &= ~EPopupFepStartEvent;
       
   669             AttemptExitL(EFalse);
       
   670             break;
       
   671             // Deal with markable lists
       
   672         case EAknSoftkeyMark:
       
   673             {
       
   674             TInt index = iListBox->CurrentItemIndex();
       
   675             iListBox->View()->SelectItemL(index);
       
   676             if (iMarkable && iPopoutCba)
       
   677                 {
       
   678                 iPopoutCba->SetCommandSetL(R_AVKON_SOFTKEYS_UNMARK_BACK);
       
   679                 iPopoutCba->DrawNow();
       
   680                 iCurrentResource = R_AVKON_SOFTKEYS_UNMARK_BACK;
       
   681                 }
       
   682             }
       
   683             break;
       
   684         case EAknSoftkeyUnmark:
       
   685             {
       
   686             TInt index = iListBox->CurrentItemIndex();
       
   687             iListBox->View()->DeselectItem(index);
       
   688             if (iMarkable && iPopoutCba)
       
   689                 {
       
   690                 iPopoutCba->SetCommandSetL(R_AVKON_SOFTKEYS_MARK_BACK);
       
   691                 iPopoutCba->DrawNow();
       
   692                 iCurrentResource = R_AVKON_SOFTKEYS_MARK_BACK;
       
   693                 }
       
   694             }
       
   695             break;
       
   696         default:
       
   697             break;
       
   698         }
       
   699     _AKNTRACE_FUNC_EXIT;
       
   700     }
       
   701 
       
   702 /**
       
   703 * Processes key events from the listbox. Respnds to EEventEnterKeyPressed to accept
       
   704 * the pop-up.
       
   705 *
       
   706 * @param        aListBox        Listbox being observed
       
   707 * @param        aEventType        Event observed
       
   708 */
       
   709 EXPORT_C void CAknPopupList::HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType)
       
   710     {
       
   711     _AKNTRACE_FUNC_ENTER;
       
   712     // Respond to events from listbox
       
   713     if (aListBox == iListBox)
       
   714         {
       
   715         // if left softkey is empty, we do not handle enter key either.
       
   716         if (iPopoutCba && iPopoutCba->ButtonGroup())
       
   717             if (iPopoutCba->ButtonGroup()->CommandId(0) != 0) // CommandId(0) is left softkey.
       
   718                 {
       
   719                 switch ( aEventType )
       
   720                     {
       
   721                     case MEikListBoxObserver::EEventPenDownOnItem:
       
   722                         iPopupListExtension->iItemDraggingActioned = EFalse;
       
   723                         break;
       
   724                         
       
   725                     case MEikListBoxObserver::EEventItemDraggingActioned:
       
   726                     case MEikListBoxObserver::EEventPanningStarted:
       
   727                     case MEikListBoxObserver::EEventFlickStarted:
       
   728                         iPopupListExtension->iItemDraggingActioned = ETrue;
       
   729                         break;
       
   730                     
       
   731                     default:
       
   732                         break;
       
   733                     }
       
   734                 
       
   735                 if ( iPopupListExtension->AcceptListBoxEvent( iListBox, aEventType ) )
       
   736                     {
       
   737                     // Ok / Enter key pressed, so remove popup
       
   738                     AttemptExitL(ETrue);                    
       
   739                     }
       
   740                 }
       
   741         }
       
   742     _AKNTRACE_FUNC_EXIT;
       
   743     }
       
   744 /**
       
   745 * Processes state changed events from the listbox.
       
   746 *
       
   747 * @param        aControl        Control being observed
       
   748 * @param        aEventType        Event observed
       
   749 */
       
   750 EXPORT_C void CAknPopupList::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
       
   751     {
       
   752     _AKNTRACE_FUNC_ENTER;    
       
   753     if (aControl == iListBox)
       
   754         {
       
   755         if (aEventType == EEventStateChanged)
       
   756             {
       
   757             TInt index = iListBox->CurrentItemIndex();
       
   758             TKeyArrayFix key(0, ECmpTInt);        
       
   759             TInt pos;
       
   760             TBool unmarked = iListBox->View()->SelectionIndexes()->Find(index, key, pos);
       
   761             if (unmarked)
       
   762                 {
       
   763                 if (iCurrentResource != R_AVKON_SOFTKEYS_MARK_BACK)
       
   764                     {
       
   765                     if (iPopoutCba)
       
   766                         {
       
   767                         iPopoutCba->SetCommandSetL(R_AVKON_SOFTKEYS_MARK_BACK);
       
   768                         iPopoutCba->DrawNow();
       
   769                         }
       
   770                     iCurrentResource = R_AVKON_SOFTKEYS_MARK_BACK;
       
   771                     }
       
   772                 }
       
   773             else
       
   774                 {
       
   775                 if (iCurrentResource != R_AVKON_SOFTKEYS_UNMARK_BACK)
       
   776                     {
       
   777                     if (iPopoutCba)
       
   778                         {
       
   779                         iPopoutCba->SetCommandSetL(R_AVKON_SOFTKEYS_UNMARK_BACK);
       
   780                         iPopoutCba->DrawNow();
       
   781                         }
       
   782                     iCurrentResource = R_AVKON_SOFTKEYS_UNMARK_BACK;
       
   783                     }
       
   784                 }
       
   785             }
       
   786         }
       
   787     _AKNTRACE_FUNC_EXIT;
       
   788     }
       
   789 
       
   790 /**
       
   791 * Called when the user accepts or cancels the listbox. Default implementation
       
   792 * sets the return value and exists. If there is no return value it means that
       
   793 * the construction has failed so we don't care about setting the return value
       
   794 * anyway.
       
   795 *
       
   796 * @param        aAccept        ETrue if the user accepted. EFalse if the user cancelled.
       
   797 */
       
   798 EXPORT_C void CAknPopupList::AttemptExitL(TBool aAccept)
       
   799     {
       
   800     _AKNTRACE_FUNC_ENTER;
       
   801     //EFTG-7HWDP6.
       
   802     if( FindBox()
       
   803         && !( FindBox()->Editor().AknEdwinFlags() & EAknEditorFlagTouchInputModeOpened )
       
   804         && ( iPopupListExtension->iFlags & EPopupLayoutSwitchEvent ) )
       
   805         {
       
   806         iPopupListExtension->iFlags &= ~EPopupFepStartEvent;
       
   807         }
       
   808 
       
   809     // if exiting is tried to do when pointer event handling is on, then 
       
   810     // do it after pointer event handling is over. 
       
   811     if ( (iPopupListExtension->iFlags & EPopupHandlingPointerEvent) && AknLayoutUtils::PenEnabled() )
       
   812         {
       
   813         // Set flag to correspond correct action. 
       
   814         if ( aAccept )
       
   815             {            
       
   816             iPopupListExtension->iFlags |= EPopupAcceptAfterPointerEvent;
       
   817             }
       
   818         else 
       
   819             {
       
   820             iPopupListExtension->iFlags |= EPopupCancelAfterPointerEvent;
       
   821             }
       
   822         }
       
   823     else if( !(iPopupListExtension->iFlags & EPopupFepStartEvent) )
       
   824         {  
       
   825 #ifdef RD_UI_TRANSITION_EFFECTS_POPUPS
       
   826         // no transition if accepted
       
   827         if( IsVisible() && GfxTransEffect::IsRegistered(this) && !aAccept )
       
   828             {
       
   829             //If still visible, do a transition to invisible state.
       
   830             CAknTransitionUtils::SetAllParents(this);
       
   831             GfxTransEffect::Begin(this, KGfxControlDisappearAction);
       
   832             GfxTransEffect::NotifyExternalState(ECaptureComponentsBegin, (const TDesC8*)this);
       
   833 
       
   834             TRect demarcation;
       
   835             CAknTransitionUtils::GetDemarcation(CAknTransitionUtils::EPopup, 
       
   836                                                 demarcation);
       
   837             GfxTransEffect::SetDemarcation(this, demarcation);
       
   838 
       
   839             MakeVisible(EFalse);
       
   840             CAknTransitionUtils::MakeVisibleSubComponents( this,
       
   841                                         CAknTransitionUtils::EForceInvisible );
       
   842 
       
   843             GfxTransEffect::NotifyExternalState(ECaptureComponentsEnd, (const TDesC8*)this);
       
   844             GfxTransEffect::End(this);
       
   845             }
       
   846         GfxTransEffect::Deregister(this); //Always deregister in destructor.
       
   847 #endif
       
   848 
       
   849         ListBox()->MakeVisible(EFalse);
       
   850         CEikScrollBarFrame* sbframe = ListBox()->ScrollBarFrame();
       
   851         if ( sbframe && sbframe->VerticalScrollBar() )
       
   852             {
       
   853             sbframe->VerticalScrollBar()->MakeVisible(EFalse);
       
   854             }
       
   855         RemoveFindFiltering();
       
   856         if (iReturn) //Always not null unless ExecuteLD leaves
       
   857             *iReturn = aAccept;
       
   858         
       
   859         CAknEnv::StopSchedulerWaitWithBusyMessage(iWait);
       
   860         }
       
   861     _AKNTRACE_FUNC_EXIT;
       
   862     }
       
   863 
       
   864 /** 
       
   865 * Returns the listbox being used
       
   866 *
       
   867 * @return        Listbox contained in the pop-up
       
   868 */
       
   869 EXPORT_C CEikListBox* CAknPopupList::ListBox() const
       
   870     {
       
   871     return iListBox;
       
   872     }
       
   873 
       
   874 
       
   875 /**
       
   876 * Cancels the current popup. The popup ExecuteLD will return with EFalse.
       
   877 *
       
   878 */
       
   879 EXPORT_C void CAknPopupList::CancelPopup()
       
   880     {
       
   881     _AKNTRACE_FUNC_ENTER;
       
   882     // Attempt to cancel. Ignore any error.
       
   883     TRAP_IGNORE(AttemptExitL(EFalse));
       
   884     _AKNTRACE_FUNC_EXIT;
       
   885     }
       
   886 
       
   887 
       
   888 EXPORT_C void CAknPopupList::SetupWindowLayout(AknPopupLayouts::TAknPopupLayouts aType)
       
   889     {
       
   890     _AKNTRACE_FUNC_ENTER;
       
   891     // A linked list for HandleSizeChanged().
       
   892     TAknPopupLayoutsNode list = { 0, EListNode, ListBox() };
       
   893     TAknPopupLayoutsNode heading = { &list, EHeadingNode, Heading() };
       
   894     TAknPopupLayoutsNode windowOwning = { &heading, EWindowOwningNode, this };
       
   895     TAknPopupLayoutsNode findPane = { &windowOwning, EFindBoxNode, FindBox() };
       
   896     TAknPopupLayoutsNode *listBegin = &findPane;
       
   897 
       
   898     AknPopupLayouts::HandleSizeChanged( Layout(), aType, listBegin);
       
   899 
       
   900     // create skin context for popuplist (list itemdrawer uses normal list skinning)
       
   901     TRect windowRect(Rect());
       
   902 
       
   903     TAknLayoutRect topLeft;
       
   904     topLeft.LayoutRect(windowRect, SkinLayout::Popup_windows_skin_placing__frame_general__Line_2());
       
   905 
       
   906     TAknLayoutRect bottomRight;
       
   907     bottomRight.LayoutRect(windowRect, SkinLayout::Popup_windows_skin_placing__frame_general__Line_5());
       
   908 
       
   909     TRect outerRect(topLeft.Rect().iTl, bottomRight.Rect().iBr);
       
   910     TRect innerRect(topLeft.Rect().iBr, bottomRight.Rect().iTl);
       
   911     
       
   912     TInt softkeyHeight( KSoftkeyHeightUndefined );
       
   913 
       
   914     if (!iPopupListExtension->iBgContext)
       
   915         {
       
   916         TRAP_IGNORE( iPopupListExtension->iBgContext = CAknsFrameBackgroundControlContext::NewL(
       
   917             KAknsIIDQsnFrPopup, outerRect, innerRect, ETrue ) );
       
   918         iPopupListExtension->iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   919         iPopupListExtension->iBgContext->SetBitmap(KAknsIIDQsnFrPopupCenter);
       
   920         }
       
   921     else
       
   922         {
       
   923         iPopupListExtension->iBgContext->SetFrameRects( outerRect, innerRect );
       
   924         iPopupListExtension->iBgContext->SetParentPos( PositionRelativeToScreen() );
       
   925         }
       
   926 
       
   927     if ( FindBox() )
       
   928         {
       
   929         TInt headingVariety( 1 );
       
   930         
       
   931         if ( Heading() )
       
   932             {
       
   933             headingVariety = 0;
       
   934             }
       
   935             
       
   936         // When softkeys are embedded inside popup we need to move the FindBox
       
   937         // upwards by the height of softkeys. There is no layout data available 
       
   938         // for embedded version, so we must do it with calculation.
       
   939         if ( AknLayoutUtils::PenEnabled() )
       
   940             {
       
   941             softkeyHeight = SoftkeyRect().Height(); 
       
   942             windowRect.Move( 0, -softkeyHeight );            
       
   943             }
       
   944    
       
   945         AknLayoutUtils::LayoutControl( FindBox(), windowRect,
       
   946             AknLayoutScalable_Avkon::find_popup_pane_cp2( headingVariety ) );
       
   947         }
       
   948 
       
   949     if ( AknLayoutUtils::PenEnabled() )
       
   950         {
       
   951         CEikCba* cba = static_cast<CEikCba*>( iPopoutCba->ButtonGroup() );
       
   952             
       
   953         if ( !cba->IsEmpty() )
       
   954             {
       
   955             TRect rect( Rect() );
       
   956             
       
   957             if ( softkeyHeight == KSoftkeyHeightUndefined )
       
   958                 {
       
   959                 softkeyHeight = SoftkeyRect().Height();
       
   960                 }
       
   961                     
       
   962             // softkeys are located on bottom of the rect
       
   963             cba->SetRect( TRect( rect.iTl.iX,
       
   964                 rect.iBr.iY - softkeyHeight,
       
   965                 rect.iBr.iX,
       
   966                 rect.iBr.iY) );
       
   967             }
       
   968         }
       
   969 
       
   970 
       
   971     // we can safely use FormattedCellData only if normal popup layouts are in use
       
   972     switch(iWindowType)
       
   973         {
       
   974         case AknPopupLayouts::EMenuUnknownColumnWindow:
       
   975         case AknPopupLayouts::EMenuUnknownFormattedCellWindow:
       
   976             break;
       
   977         default:  
       
   978             {
       
   979             CFormattedCellListBoxData *boxData =
       
   980                 ((CEikFormattedCellListBox*)ListBox())->ItemDrawer()->FormattedCellData();
       
   981 
       
   982             boxData->SetSkinPopupFrame(&KAknsIIDQsnFrPopup,&KAknsIIDQsnFrPopupCenter);
       
   983             boxData->SetSkinPopupFramePosition(outerRect,innerRect);
       
   984             }
       
   985             break;
       
   986         }
       
   987     _AKNTRACE_FUNC_EXIT;
       
   988     }
       
   989 
       
   990 EXPORT_C TAknPopupWindowLayoutDef &CAknPopupList::Layout()
       
   991     {
       
   992     return iLayout;
       
   993     }
       
   994 
       
   995 EXPORT_C const TAknPopupWindowLayoutDef &CAknPopupList::Layout() const
       
   996     {
       
   997     return iLayout;
       
   998     }
       
   999 
       
  1000 EXPORT_C CEikButtonGroupContainer *CAknPopupList::ButtonGroupContainer()
       
  1001     {
       
  1002     return iPopoutCba;
       
  1003     }
       
  1004 
       
  1005 EXPORT_C CAknPopupHeadingPane *CAknPopupList::Heading() const
       
  1006     {
       
  1007     return CONST_CAST(CAknPopupList*,this)->Heading();
       
  1008     }
       
  1009 EXPORT_C CAknPopupHeadingPane *CAknPopupList::Heading()
       
  1010     {
       
  1011     // This if statement will remove the heading if
       
  1012     // the string from resource is "".
       
  1013     if (iTitle && iTitle->Prompt())
       
  1014         return iTitle;
       
  1015     return 0;
       
  1016     }
       
  1017 
       
  1018 EXPORT_C CEikListBox *CAknPopupList::ListBox()
       
  1019     {
       
  1020     return iListBox;
       
  1021     }
       
  1022 
       
  1023 
       
  1024 EXPORT_C TKeyResponse CAknPopupList::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
       
  1025     {
       
  1026     _AKNTRACE_FUNC_ENTER;
       
  1027     /* this must be first check, since window will be faded when fast
       
  1028     * swap window is visible */
       
  1029     if (aType==EEventKey && aKeyEvent.iCode == EKeyEscape)
       
  1030         {
       
  1031         AttemptExitL(EFalse);
       
  1032         return EKeyWasConsumed;
       
  1033         }
       
  1034 
       
  1035     if ( Window().IsFaded() )
       
  1036         {
       
  1037         /* this happens, when popuplist has a findbox, and user
       
  1038         * presses shift to launch fep menu. Fep menu has priority menu
       
  1039         * in control stack, but we have dialog priority. As result,
       
  1040         * keyevents will get here first. If we return
       
  1041         * EKeyWasNotConsumed, fep menu will catch those events
       
  1042         * next. */
       
  1043         return EKeyWasNotConsumed;
       
  1044         }
       
  1045 
       
  1046     TBool needRefresh = EFalse;
       
  1047     TKeyResponse res = AknFind::HandleFindOfferKeyEventL(aKeyEvent, aType, this, ListBox(), FindBox(), EFalse, needRefresh);
       
  1048 
       
  1049     if (needRefresh && FindBox())
       
  1050         {
       
  1051         DrawNow();
       
  1052         }
       
  1053 
       
  1054     if ( res == EKeyWasConsumed )
       
  1055         {
       
  1056         return res;
       
  1057         }
       
  1058     
       
  1059     TKeyResponse response = iListBox->OfferKeyEventL(aKeyEvent, aType);
       
  1060     _AKNTRACE_FUNC_EXIT;
       
  1061     return response;
       
  1062     }
       
  1063 
       
  1064 EXPORT_C void CAknPopupList::FocusChanged(TDrawNow aDrawNow)
       
  1065     {
       
  1066     if (iListBox)
       
  1067         iListBox->SetFocus(IsFocused(), aDrawNow);
       
  1068     if ( FindBox() )
       
  1069         FindBox()->SetFocus(IsFocused(), aDrawNow);
       
  1070     }
       
  1071 
       
  1072 EXPORT_C TTypeUid::Ptr CAknPopupList::MopSupplyObject(TTypeUid aId)
       
  1073     {
       
  1074     if (aId.iUid == CAknPopupList::ETypeId)
       
  1075         {
       
  1076         return aId.MakePtr(this);
       
  1077         }
       
  1078     if (aId.iUid == MAknsControlContext::ETypeId)
       
  1079         {
       
  1080         if (iPopupListExtension && iPopupListExtension->iBgContext)
       
  1081             {
       
  1082             return MAknsControlContext::SupplyMopObject(aId, iPopupListExtension->iBgContext);
       
  1083             }
       
  1084         else if ( iListBox && 
       
  1085                   iListBox->View() &&
       
  1086                   iListBox->View()->ItemDrawer() )
       
  1087             {
       
  1088             return aId.MakePtr(iListBox->View()->ItemDrawer()->SkinBackgroundControlContext());
       
  1089             }
       
  1090         else
       
  1091             {
       
  1092             return TTypeUid::Null();
       
  1093             }
       
  1094         }
       
  1095     if (!iPopoutCba) return CEikBorderedControl::MopSupplyObject(aId);
       
  1096     return SupplyMopObject(aId, iPopoutCba);
       
  1097     }
       
  1098 
       
  1099 EXPORT_C TInt CAknPopupList::CountFadedComponents()
       
  1100     {
       
  1101     return 2;
       
  1102     }
       
  1103 
       
  1104 EXPORT_C CCoeControl* CAknPopupList::FadedComponent(TInt aIndex)
       
  1105     {
       
  1106     switch (aIndex)
       
  1107         {
       
  1108         case 0:
       
  1109             return this;
       
  1110 
       
  1111         case 1:
       
  1112             return iPopoutCba;
       
  1113 
       
  1114         default:
       
  1115             return NULL;
       
  1116         }
       
  1117     }
       
  1118 
       
  1119 //----------------------------------------------------------------------------
       
  1120 // CAknPopupList::HandlePointerEventL()
       
  1121 // Handles pointer events Button1Up and Button1Down that happens outside 
       
  1122 // of list rect by closing and canceling selection. 
       
  1123 // Other pointerevents are handled in CEikListbox
       
  1124 //----------------------------------------------------------------------------
       
  1125 //
       
  1126 EXPORT_C void CAknPopupList::HandlePointerEventL(const TPointerEvent& aPointerEvent) 
       
  1127     {
       
  1128     _AKNTRACE_FUNC_ENTER;
       
  1129     _AKNTRACE("HandlePointerEventL: aPointerEvent.iPosition=(%d,%d)", 
       
  1130             aPointerEvent.iPosition.iX, aPointerEvent.iPosition.iY);
       
  1131     
       
  1132     if ( AknLayoutUtils::PenEnabled() )
       
  1133         {
       
  1134         iPopupListExtension->iFlags |= EPopupHandlingPointerEvent;
       
  1135 
       
  1136         TInt index;
       
  1137         TBool pointerOnItem = iListBox->View()->XYPosToItemIndex( aPointerEvent.iPosition, index );
       
  1138         if ( aPointerEvent.iType == TPointerEvent::EButton1Down
       
  1139                 && pointerOnItem )
       
  1140             {
       
  1141             iListBox->View()->ItemDrawer()->SetFlags(
       
  1142                     CListItemDrawer::EPressedDownState );
       
  1143             }
       
  1144 
       
  1145         CCoeControl::HandlePointerEventL( aPointerEvent );
       
  1146         
       
  1147         iPopupListExtension->iFlags &= ~EPopupHandlingPointerEvent;
       
  1148         
       
  1149         switch ( aPointerEvent.iType )
       
  1150             {
       
  1151             case TPointerEvent::EButton1Up:
       
  1152                 {
       
  1153                 _AKNTRACE("CAknPopupList::HandlePointerEventL: TPointerEvent::EButton1Up");
       
  1154                 TBool accepted(
       
  1155                         iPopupListExtension->AcceptPointerEvent( iListBox ) );
       
  1156                 
       
  1157                 if ( accepted )
       
  1158                     {
       
  1159                     if ( Rect().Contains( aPointerEvent.iPosition )
       
  1160                             && ( iPopupListExtension->iFlags
       
  1161                                     & EPopupAcceptAfterPointerEvent ) )
       
  1162                         {
       
  1163                         AttemptExitL( ETrue );
       
  1164                         }
       
  1165                     else
       
  1166                         {
       
  1167                         AttemptExitL( EFalse );
       
  1168                         }
       
  1169                     }
       
  1170 
       
  1171                 //EFTG-7HWDP6. 
       
  1172                 //If model didn't change from portrait to landscape, 
       
  1173                 //EPopupFepStartEvent should be deleted.
       
  1174                 else if( !(iPopupListExtension->iFlags & EPopupLayoutSwitchEvent) )
       
  1175                     {
       
  1176                     iPopupListExtension->iFlags &= ~EPopupFepStartEvent;
       
  1177                     }
       
  1178                 }
       
  1179                 break;
       
  1180             case TPointerEvent::EButton1Down:
       
  1181                 _AKNTRACE("CAknPopupList::HandlePointerEventL: TPointerEvent::EButton1Down");
       
  1182                 // as in comments close popup if pointer goes outside of the popup list
       
  1183                 if ( !Rect().Contains( aPointerEvent.iPosition ) )
       
  1184                     {
       
  1185                     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
  1186                     if ( feedback )
       
  1187                         {
       
  1188                         feedback->InstantFeedback( ETouchFeedbackPopUp );
       
  1189                         }
       
  1190                     AttemptExitL( EFalse );                	
       
  1191                     }
       
  1192                 else 
       
  1193                     {
       
  1194                     if( FindBox() 
       
  1195                         && ( FindBox()->Editor().Rect().Contains( aPointerEvent.iPosition ) ) 
       
  1196                         && !( iPopupListExtension->iFlags & EPopupLayoutSwitchEvent ) )
       
  1197                         {
       
  1198                         iPopupListExtension->iFlags |= EPopupFepStartEvent;
       
  1199                         }
       
  1200                     }
       
  1201                 break;
       
  1202             case TPointerEvent::EDrag:
       
  1203                 _AKNTRACE("CAknPopupList::HandlePointerEventL: TPointerEvent::EDrag");
       
  1204                 if ( !iListBox->Rect().Contains( aPointerEvent.iPosition ))
       
  1205                     {
       
  1206                     iPopupListExtension->iItemDraggingActioned = ETrue;
       
  1207                     }
       
  1208             default:
       
  1209                 // do nothing with the rest of the events
       
  1210                 break;
       
  1211             }
       
  1212         }
       
  1213     _AKNTRACE_FUNC_EXIT;
       
  1214     }
       
  1215 
       
  1216 EXPORT_C void* CAknPopupList::ExtensionInterface( TUid /*aInterface*/ ) 
       
  1217     { 
       
  1218     return NULL;
       
  1219     }
       
  1220     
       
  1221 EXPORT_C TBool CAknPopupList::EnableFind(TBool /*aEnable*/)
       
  1222     {
       
  1223     if (!iPopupListExtension)
       
  1224         return EFalse; // no extension class, failed
       
  1225     if (!iPopupListExtension->iSearchControl)
       
  1226         {
       
  1227         CAknSearchField::TSearchFieldStyle flags = CAknSearchField::EPopupWindow;
       
  1228         TRAPD(err,
       
  1229               iPopupListExtension->iSearchControl = CAknSearchField::NewL( *this, flags, 0, 40 );
       
  1230               STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->CreateFilterL(ListBox(),FindBox());
       
  1231             ); // end TRAP
       
  1232         if (err != KErrNone) // error in creating findbox, do nothing
       
  1233             return EFalse;
       
  1234         
       
  1235         // Do layout only if visible, otherwise it would be done both here
       
  1236         // and in ExecuteLD.
       
  1237         if ( iReturn )
       
  1238             {
       
  1239             AknPopupLayouts::TAknPopupLayouts layout =
       
  1240                 AknPopupLayouts::TAknPopupLayouts(EAknPopupLayoutsFind + iWindowType);
       
  1241             SetupWindowLayout(layout);
       
  1242             }
       
  1243 
       
  1244         // set layout for fixed find box in popup window - this makes highlights working
       
  1245         STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->SetParentControl(this);
       
  1246         
       
  1247         // popup_find_window overlaps listbox, but this doesn't matter because findbox
       
  1248         // doesn't draw background
       
  1249         }
       
  1250 
       
  1251     return ETrue;
       
  1252     }
       
  1253     
       
  1254 EXPORT_C TBool CAknPopupList::EnableAdaptiveFind(TBool /*aEnable*/)
       
  1255     {
       
  1256     if (!iPopupListExtension)
       
  1257         return EFalse; // no extension class, failed
       
  1258     if (!iPopupListExtension->iSearchControl)
       
  1259         {
       
  1260         CAknSearchField::TSearchFieldStyle flags = CAknSearchField::EPopupAdaptiveSearchWindow;
       
  1261         TRAPD(err,
       
  1262               iPopupListExtension->iSearchControl = CAknSearchField::NewL( *this, flags, 0, 40 );
       
  1263               STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->CreateFilterL(ListBox(),FindBox());
       
  1264             ); // end TRAP
       
  1265         if (err != KErrNone) // error in creating findbox, do nothing
       
  1266             return EFalse;
       
  1267         
       
  1268         // Do layout only if visible, otherwise it would be done both here
       
  1269         // and in ExecuteLD.
       
  1270         if ( iReturn )
       
  1271             {
       
  1272             AknPopupLayouts::TAknPopupLayouts layout =
       
  1273                 AknPopupLayouts::TAknPopupLayouts(EAknPopupLayoutsFind + iWindowType);
       
  1274             SetupWindowLayout(layout);
       
  1275             }
       
  1276 
       
  1277         // set layout for fixed find box in popup window - this makes highlights working
       
  1278         STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->SetParentControl(this);
       
  1279         
       
  1280         // popup_find_window overlaps listbox, but this doesn't matter because findbox
       
  1281         // doesn't draw background
       
  1282         }
       
  1283 
       
  1284     return ETrue;
       
  1285     }    
       
  1286     
       
  1287 
       
  1288 EXPORT_C CAknSearchField* CAknPopupList::FindBox() const
       
  1289     {
       
  1290     if (iPopupListExtension)
       
  1291         return iPopupListExtension->iSearchControl;
       
  1292     return NULL;
       
  1293     }
       
  1294 
       
  1295 void CAknPopupList::RemoveFindFiltering()
       
  1296     {
       
  1297     if (FindBox())
       
  1298         { // this removes filtering from popup list so that listboxes state is valid for application to read.
       
  1299         TInt currentItemIndex = ListBox()->CurrentItemIndex();
       
  1300         TInt realCurrentItemIndex = currentItemIndex >= 0 ? STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->FilteredItemIndex(currentItemIndex) : -1;
       
  1301         TRAP_IGNORE( FindBox()->SetSearchTextL(_L("")) );
       
  1302         TRAP_IGNORE( STATIC_CAST(CAknFilteredTextListBoxModel*,ListBox()->Model())->Filter()->HandleOfferkeyEventL() );
       
  1303         if (realCurrentItemIndex >= 0)
       
  1304             ListBox()->SetCurrentItemIndex(realCurrentItemIndex);
       
  1305         }
       
  1306     }
       
  1307 
       
  1308 EXPORT_C void CAknPopupList::HandleResourceChange(TInt aType)
       
  1309     {
       
  1310     _AKNTRACE_FUNC_ENTER;
       
  1311     if( aType == KEikDynamicLayoutVariantSwitch )
       
  1312         {
       
  1313         
       
  1314         //EFTG-7HWDP6. 
       
  1315         //Tapping Edit'area can arouse the CAknPopupList::HandleResourceChange()
       
  1316         //when portrait is initial model, and 'Full screen QWERTY keyboard' is default input method.
       
  1317         //Just then, EPopupLayoutSwitchEvent will be setted once.
       
  1318         if( ( iPopupListExtension->iFlags & EPopupFepStartEvent ) && 
       
  1319             !( iPopupListExtension->iFlags & EPopupLayoutSwitchEvent ) )
       
  1320             {
       
  1321             iPopupListExtension->iFlags |= EPopupLayoutSwitchEvent;
       
  1322             }
       
  1323         else
       
  1324             {
       
  1325             iPopupListExtension->iFlags &= ~EPopupFepStartEvent;
       
  1326             iPopupListExtension->iFlags &= ~EPopupLayoutSwitchEvent;    
       
  1327             }
       
  1328         
       
  1329         iPopoutCba->SetBoundingRect(TRect(iAvkonAppUi->ApplicationRect().Size()));
       
  1330         CCoeControl::HandleResourceChange(aType);
       
  1331 
       
  1332         if ( FindBox() )
       
  1333             {
       
  1334             SetupWindowLayout( AknPopupLayouts::TAknPopupLayouts(EAknPopupLayoutsFind + iWindowType) );
       
  1335             }
       
  1336         else
       
  1337             {
       
  1338             //ELWG-7KH94H 
       
  1339             //When layout is changed, CEikListView::ScrollToMakeItemVisible
       
  1340             //may be called before list box background's area update  
       
  1341             //occasionally and it will incur flicker. 
       
  1342             iListBox->View()->SetDisableRedraw( ETrue );
       
  1343             SetupWindowLayout( iWindowType );
       
  1344             iListBox->View()->SetDisableRedraw( EFalse );
       
  1345             }
       
  1346         }
       
  1347     else
       
  1348         {
       
  1349         CCoeControl::HandleResourceChange(aType);
       
  1350         }
       
  1351     // EFLU-7HH5DA. CEikListBox::HandleResourceChange will re-set layout of scrollbar 
       
  1352     // when skin is changed. So we need to set it back to correct.
       
  1353     if( aType == KEikMessageColorSchemeChange || aType == KAknsMessageSkinChange )
       
  1354         {
       
  1355         if ( FindBox() )
       
  1356             {
       
  1357             SetupWindowLayout( AknPopupLayouts::TAknPopupLayouts(EAknPopupLayoutsFind + iWindowType) );
       
  1358             }
       
  1359         else
       
  1360             {
       
  1361             SetupWindowLayout( iWindowType );
       
  1362             }
       
  1363         }
       
  1364     _AKNTRACE_FUNC_EXIT;
       
  1365     }
       
  1366 // End of File