fep/aknfep/UiPlugins/AknFepUiInterface/AvkonImpl/src/AknFepUiAvkonCtrlExactWordPopupContent.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2007 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:             Contents of the exact word tooltip shown above inline editor
       
    15 *                when the exact word differs from the inline word in Western
       
    16 *                QWERTY predictive mode.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 
       
    30 
       
    31 #include <eiklabel.h>
       
    32 #include <AknUtils.h>
       
    33 #include <AknsUtils.h>
       
    34 #include <AknPreviewPopUpController.h>
       
    35 #include "AknFepUiAvkonCtrlExactWordPopupContent.h"
       
    36 
       
    37 
       
    38 const TInt KArrowWidth = 10;
       
    39 const TInt KArrowHeight = 5;
       
    40 
       
    41 CAknFepExactWordPopupContent* CAknFepExactWordPopupContent::NewL()
       
    42     {
       
    43     CAknFepExactWordPopupContent* self = new (ELeave) CAknFepExactWordPopupContent;
       
    44     CleanupStack::PushL(self);
       
    45     self->ConstructL();
       
    46     CleanupStack::Pop(self);
       
    47     return self;
       
    48     }
       
    49     
       
    50     
       
    51 CAknFepExactWordPopupContent::CAknFepExactWordPopupContent()
       
    52     : iIsPopUpVisible(EFalse)
       
    53     , iLabel( NULL )
       
    54     , iPopupController( NULL )
       
    55     , iArrowDirection( EUpwards )
       
    56     {
       
    57     }
       
    58 
       
    59 
       
    60 void CAknFepExactWordPopupContent::ConstructL()
       
    61     {
       
    62     iLabel = new (ELeave) CEikLabel;
       
    63     iLabel->SetTextL(KNullDesC);
       
    64 
       
    65   	const CFont* font = AknLayoutUtils::FontFromId( AknLayout::Link_shortcut_title_texts_Line_1().FontId() );
       
    66     iLabel->SetFont(font);
       
    67 
       
    68     TRgb textColor(KRgbBlack);
       
    69     iLabel->GetColor(EColorLabelText, textColor);
       
    70     AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), textColor, 
       
    71                               KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG20);
       
    72     TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL(*iLabel, EColorLabelText, textColor) );
       
    73     
       
    74     TRect screenRect;
       
    75  	AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
    76     iLabel->SetRect( screenRect );
       
    77     SetRect( screenRect ); 
       
    78      
       
    79     iPopupController = CAknPreviewPopUpController::NewL( *this, 
       
    80                                                         CAknPreviewPopUpController::EPermanentMode );
       
    81     iPopupController->SetPopUpShowDelay(0);   
       
    82     }
       
    83 
       
    84 MAknFepUiWordPopupContent::~MAknFepUiWordPopupContent()
       
    85 	{
       
    86 		
       
    87 	}
       
    88     
       
    89 CAknFepExactWordPopupContent::~CAknFepExactWordPopupContent()
       
    90     {
       
    91     delete iLabel;
       
    92     delete iPopupController;
       
    93     }
       
    94     
       
    95         
       
    96 void CAknFepExactWordPopupContent::SetTextL( const TDesC& aText )
       
    97     {
       
    98     iLabel->SetTextL(aText);
       
    99     }
       
   100 
       
   101 
       
   102 void CAknFepExactWordPopupContent::SetArrowDirection( MAknFepUiWordPopupContent::TArrowDirection aDirection )
       
   103     {
       
   104     iArrowDirection = aDirection;
       
   105     }
       
   106 
       
   107 
       
   108 TSize CAknFepExactWordPopupContent::MinimumSize()
       
   109     {
       
   110     // Ensure we are on top. Otherwise the popup would be left on background in many applications
       
   111     // (e.g. Notes, ActiveNotes, Messaging, Contacts).
       
   112     Window().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
       
   113 
       
   114     TSize minSize = iLabel->MinimumSize();
       
   115     //minSize.iHeight *= 2;
       
   116     return minSize;
       
   117     }
       
   118     
       
   119         
       
   120 void CAknFepExactWordPopupContent::Draw( const TRect& aRect ) const
       
   121     {
       
   122     TRect labelRect(aRect);
       
   123 
       
   124     if ( iPopupController )
       
   125         {
       
   126         labelRect.SetSize( iPopupController->Size() );
       
   127         }
       
   128     
       
   129     // Reserve some space for the arrow, if it is going to be shown below the text
       
   130     if ( iArrowDirection == EUpwards )
       
   131         {
       
   132         labelRect.iTl.iY -= KArrowHeight;
       
   133         }
       
   134         
       
   135     iLabel->SetRect( labelRect );
       
   136     iLabel->Draw( labelRect );
       
   137 
       
   138     TRAP_IGNORE( DrawArrowL( aRect ) );
       
   139     }
       
   140         
       
   141 
       
   142 void CAknFepExactWordPopupContent::DrawArrowL( const TRect& aTextRect ) const
       
   143     {
       
   144     CWindowGc& gc = SystemGc();
       
   145     gc.SetPenColor( iEikonEnv->ControlColor(EColorLabelText,*this) );
       
   146     gc.SetBrushColor( iEikonEnv->ControlColor(EColorControlBackground,*this) );
       
   147     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   148             
       
   149     CArrayFix<TPoint>* arrow = new (ELeave) CArrayFixFlat<TPoint>(3);
       
   150     CleanupStack::PushL(arrow);
       
   151 
       
   152     TPoint offset( aTextRect.iTl.iX + aTextRect.Width()/2 - KArrowWidth/2, 0 );
       
   153 
       
   154     TPoint angle1;
       
   155     TPoint angle2;
       
   156     TPoint angle3;
       
   157 
       
   158 
       
   159     if ( iArrowDirection == EDownwards )
       
   160         {
       
   161         offset.iY = aTextRect.iTl.iY - KArrowHeight;
       
   162         angle1.SetXY( 0, 0 );
       
   163         angle2.SetXY( KArrowWidth, 0 );
       
   164         angle3.SetXY( KArrowWidth/2, KArrowHeight );
       
   165         }
       
   166     else // EUpwards
       
   167         {
       
   168         offset.iY = aTextRect.iBr.iY;
       
   169         angle1.SetXY( 0, KArrowHeight );
       
   170         angle2.SetXY( KArrowWidth, KArrowHeight );
       
   171         angle3.SetXY( KArrowWidth/2, 0 );
       
   172         }
       
   173 
       
   174     arrow->AppendL( angle1 + offset );
       
   175     arrow->AppendL( angle2 + offset );
       
   176     arrow->AppendL( angle3 + offset );
       
   177 
       
   178     gc.DrawPolygon(arrow);
       
   179     CleanupStack::PopAndDestroy(arrow);
       
   180     }
       
   181 
       
   182 void CAknFepExactWordPopupContent::SetPopUpShowDelay( const TTimeIntervalMicroSeconds32& aDelay )
       
   183 	{
       
   184 	iPopupController->SetPopUpShowDelay( aDelay );
       
   185 	}
       
   186 void CAknFepExactWordPopupContent::ShowPopUp()
       
   187 	{
       
   188 	iIsPopUpVisible = ETrue;
       
   189 	iPopupController->ShowPopUp();
       
   190 	}
       
   191 void CAknFepExactWordPopupContent::HidePopUp()
       
   192 	{
       
   193 	iIsPopUpVisible = EFalse;
       
   194 	iPopupController->HidePopUp();	
       
   195 	}
       
   196 void CAknFepExactWordPopupContent::SetPosition( const TPoint& aPoint )
       
   197 	{
       
   198 	iPopupController->SetPosition( aPoint );
       
   199 	}
       
   200 void CAknFepExactWordPopupContent::UpdateContentSize()
       
   201 	{
       
   202 	iPopupController->UpdateContentSize();	
       
   203 	}
       
   204 TSize CAknFepExactWordPopupContent::Size() const 
       
   205 	{
       
   206 	return iPopupController->Size();
       
   207 	}
       
   208 TBool CAknFepExactWordPopupContent::IsPopUpVisible()
       
   209 	{
       
   210 	return iIsPopUpVisible;	
       
   211 	}
       
   212 	
       
   213 void CAknFepExactWordPopupContent::HandlePointerEventL( const TPointerEvent& aPointerEvent )	
       
   214 	{
       
   215 	if( !AknLayoutUtils::PenEnabled() )
       
   216 		{
       
   217 		return;
       
   218 		}
       
   219 
       
   220 	if (TPointerEvent::EButton1Down == aPointerEvent.iType)
       
   221 		{
       
   222        	TKeyEvent keyUp = {EKeyUpArrow, EStdKeyUpArrow, 0, 0};
       
   223     	CCoeEnv::Static()->WsSession().SimulateKeyEvent(keyUp);
       
   224 		}
       
   225 	}