mpxplugins/viewplugins/views/commoncontainer/src/mpxcommoncontainerssearchfieldwrapper.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Wrapper class for Search Field. Handles search field
       
    15 *                activation, deactivation and size. Wrapper is a window owning
       
    16 *                control.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #include <aknutils.h>
       
    22 #include <aknlayoutscalable_avkon.cdl.h>
       
    23 #include "mpxcommoncontainersearchfieldwrapper.h"
       
    24 #include "mpxcommoncontainersearchfield.h"
       
    25 
       
    26 // CONSTANTS
       
    27 _LIT( KMPXCommonContainerPanic, "MPX Common Container" );
       
    28 
       
    29 // --------------------------------------------------------------------------
       
    30 //
       
    31 // --------------------------------------------------------------------------
       
    32 //
       
    33 CMPXCommonContainerSearchFieldWrapper::CMPXCommonContainerSearchFieldWrapper(
       
    34     MMPXCommonContainerSearchFieldObserver* aObserver )
       
    35     : iObserver( aObserver )
       
    36     {
       
    37     }
       
    38 
       
    39 // --------------------------------------------------------------------------
       
    40 //
       
    41 // --------------------------------------------------------------------------
       
    42 //
       
    43 CMPXCommonContainerSearchFieldWrapper* CMPXCommonContainerSearchFieldWrapper::NewL(
       
    44     MMPXCommonContainerSearchFieldObserver* aObserver )
       
    45     {
       
    46     CMPXCommonContainerSearchFieldWrapper* self
       
    47         = new (ELeave) CMPXCommonContainerSearchFieldWrapper( aObserver );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL();
       
    50     CleanupStack::Pop( self );
       
    51     return self;
       
    52     }
       
    53 
       
    54 // --------------------------------------------------------------------------
       
    55 //
       
    56 // --------------------------------------------------------------------------
       
    57 //
       
    58 void CMPXCommonContainerSearchFieldWrapper::ConstructL()
       
    59     {
       
    60     CreateWindowL();
       
    61     iSearchField = CMPXCommonContainerSearchField::NewL( this );
       
    62     }
       
    63 
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 // --------------------------------------------------------------------------
       
    67 //
       
    68 CMPXCommonContainerSearchFieldWrapper
       
    69         ::~CMPXCommonContainerSearchFieldWrapper()
       
    70     {
       
    71     if ( iSearchField )
       
    72         {
       
    73         if ( IsSearchFieldActive() )
       
    74             {
       
    75             CCoeEnv::Static()->AppUi()->RemoveFromStack( iSearchField );
       
    76             }
       
    77         }
       
    78     delete iSearchField;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 TBool CMPXCommonContainerSearchFieldWrapper::IsSearchFieldActive()
       
    86     {
       
    87     return iSearchField->IsVisible();
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 //
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 void CMPXCommonContainerSearchFieldWrapper::ActivateSearchFieldL()
       
    95     {
       
    96     MakeVisible( ETrue );
       
    97     CCoeEnv::Static()->AppUi()->RemoveFromStack( iSearchField );
       
    98     CCoeEnv::Static()->AppUi()->AddToStackL( iSearchField,
       
    99             ECoeStackPriorityMenu );
       
   100     iSearchField->ActivateL();
       
   101     iSearchField->MakeVisible( ETrue );
       
   102     iSearchField->SetFocus( ETrue );
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 //
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 void CMPXCommonContainerSearchFieldWrapper::DeactivateSearchField()
       
   110     {
       
   111     iSearchField->MakeVisible( EFalse );
       
   112     iSearchField->SetFocus( EFalse );
       
   113     MakeVisible( EFalse );
       
   114     CCoeEnv::Static()->AppUi()->RemoveFromStack( iSearchField );
       
   115     TRAP_IGNORE( FindKeywordL( KNullDesC ) );
       
   116     }
       
   117 
       
   118 // --------------------------------------------------------------------------
       
   119 // Returns rectangle for list, based on view's client rectangle. Handles both
       
   120 // the case when Search Field is visible and the case when it's invisible.
       
   121 // --------------------------------------------------------------------------
       
   122 //
       
   123 TRect CMPXCommonContainerSearchFieldWrapper::GetListRect(
       
   124         TBool aSearchVisible, TRect aClientRect )
       
   125     {
       
   126     TRect listRect = aClientRect;
       
   127 
       
   128     SetClientRect( aClientRect ); // Update stored client rect.
       
   129 
       
   130     if ( aSearchVisible )
       
   131         {
       
   132         TAknWindowLineLayout layout =
       
   133             AknLayoutScalable_Avkon::popup_find_window().LayoutLine();
       
   134 
       
   135         // Height of list is reduced from bottom with size of Search Field.
       
   136         listRect.iBr.iY -= layout.iH;
       
   137 
       
   138         __ASSERT_DEBUG( listRect.iBr.iY > 0 && layout.iH > 0,
       
   139                         User::Panic( KMPXCommonContainerPanic, 1 ) );
       
   140         }
       
   141 
       
   142     return listRect;
       
   143     }
       
   144 
       
   145 // --------------------------------------------------------------------------
       
   146 // Returns rectangle for Search Field, based on view's client rectangle.
       
   147 // Handles both the case when Search Field is visible and the case when it's
       
   148 // invisible.
       
   149 // --------------------------------------------------------------------------
       
   150 //
       
   151 TRect CMPXCommonContainerSearchFieldWrapper::GetSearchFieldRect(
       
   152         TBool aSearchVisible, TRect aClientRect )
       
   153     {
       
   154     TRect searchRect = TRect( 0, 0, 0, 0 );
       
   155 
       
   156     SetClientRect( aClientRect ); // Update stored client rect.
       
   157 
       
   158     if ( aSearchVisible )
       
   159         {
       
   160         TAknWindowLineLayout layout =
       
   161             AknLayoutScalable_Avkon::popup_find_window().LayoutLine();
       
   162 
       
   163         // TopLeft of Search Field is based on list's bottom, see GetListRect
       
   164         searchRect.iTl.iX = aClientRect.iTl.iX;
       
   165         searchRect.iTl.iY = aClientRect.iBr.iY - layout.iH;
       
   166 
       
   167         // BottomRight of Search Field is at the end of client rectangle.
       
   168         searchRect.iBr.iX = aClientRect.iBr.iX;
       
   169         searchRect.iBr.iY = aClientRect.iBr.iY;
       
   170 
       
   171         __ASSERT_DEBUG( searchRect.iTl.iX < searchRect.iBr.iX &&
       
   172                         searchRect.iTl.iY < searchRect.iBr.iY &&
       
   173                         searchRect.iBr.iX > 0 &&
       
   174                         searchRect.iBr.iY > 0 &&
       
   175                         layout.iH > 0,
       
   176                         User::Panic( KMPXCommonContainerPanic, 2 ) );
       
   177         }
       
   178 
       
   179     return searchRect;
       
   180     }
       
   181 
       
   182 // --------------------------------------------------------------------------
       
   183 //
       
   184 // --------------------------------------------------------------------------
       
   185 //
       
   186 void CMPXCommonContainerSearchFieldWrapper::FindKeywordL(
       
   187         const TDesC& aFindWord )
       
   188     {
       
   189     if ( iObserver )
       
   190         {
       
   191         iObserver->NewFilteringWordL( aFindWord );
       
   192         }
       
   193     }
       
   194 
       
   195 // --------------------------------------------------------------------------
       
   196 //
       
   197 // --------------------------------------------------------------------------
       
   198 //
       
   199 CCoeControl *CMPXCommonContainerSearchFieldWrapper::ComponentControl(
       
   200         TInt /*aIndex*/ ) const
       
   201     {
       
   202     return iSearchField;
       
   203     }
       
   204 
       
   205 // --------------------------------------------------------------------------
       
   206 //
       
   207 // --------------------------------------------------------------------------
       
   208 //
       
   209 TInt CMPXCommonContainerSearchFieldWrapper::CountComponentControls() const
       
   210     {
       
   211     return 1;
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 //
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 TRect& CMPXCommonContainerSearchFieldWrapper::ClientRect()
       
   219     {
       
   220     return iClientRect;
       
   221     }
       
   222 
       
   223 // --------------------------------------------------------------------------
       
   224 //
       
   225 // --------------------------------------------------------------------------
       
   226 //
       
   227 void CMPXCommonContainerSearchFieldWrapper::SetClientRect(
       
   228         const TRect& aClientRect )
       
   229     {
       
   230     iClientRect = aClientRect;
       
   231     }
       
   232 
       
   233 // --------------------------------------------------------------------------
       
   234 //
       
   235 // --------------------------------------------------------------------------
       
   236 //
       
   237 void CMPXCommonContainerSearchFieldWrapper::SizeChanged()
       
   238     {
       
   239     iSearchField->HandleFindSizeChanged();
       
   240     }