textinput/peninputcommonctrls/src/peninputlabel/peninputlabel.cpp
changeset 27 694fa80c203c
parent 24 fc42a86c98e3
child 35 0f326f2e628e
equal deleted inserted replaced
24:fc42a86c98e3 27:694fa80c203c
     1 /*
       
     2 * Copyright (c) 2006-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:  Implementation for button base and dragbar
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <AknsUtils.h>
       
    20 
       
    21 #include "peninputlabel.h"
       
    22 #include "peninputlayout.h"
       
    23 
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CAknFepCtrlLabel::NewL
       
    27 // factory function
       
    28 // (other items were commented in a header).
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 EXPORT_C CAknFepCtrlLabel* CAknFepCtrlLabel::NewL(CFepUiLayout* aUiLayout, TInt aCtrlId)
       
    32     {
       
    33     CAknFepCtrlLabel* lable=new (ELeave) CAknFepCtrlLabel(aUiLayout,aCtrlId);
       
    34 
       
    35     CleanupStack::PushL(lable);
       
    36     lable->BaseConstructL();
       
    37     CleanupStack::Pop(lable);
       
    38 
       
    39     return lable;    
       
    40     }
       
    41     
       
    42 // ---------------------------------------------------------------------------
       
    43 // CAknFepCtrlLabel::CAknFepCtrlLabel
       
    44 // C++ default constructor
       
    45 // (other items were commented in a header).
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CAknFepCtrlLabel::CAknFepCtrlLabel(CFepUiLayout* aUiLayout, TInt aCtrlId)
       
    49     :CFepUiBaseCtrl(TRect(0,0,0,0),aUiLayout,aCtrlId),
       
    50     iBaseline(-1),
       
    51     iFontColor(KRgbWhite),
       
    52     iAlignment(CGraphicsContext::ECenter)
       
    53     {
       
    54     SetControlType(EUserCtrlBase | ECtrlBaseCtrl);
       
    55     
       
    56 #ifdef __ALPHA_TRANCEPARENCY__
       
    57     const TRgb KDefaultButtonBackCol = TRgb(30,30,30);
       
    58 #else
       
    59     const TRgb KDefaultButtonBackCol = TRgb(230,230,230);
       
    60 #endif
       
    61     
       
    62     SetBkColor(KDefaultButtonBackCol);
       
    63    }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CAknFepCtrlLabel::~CAknFepCtrlLabel
       
    67 // Destructor
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C CAknFepCtrlLabel::~CAknFepCtrlLabel()
       
    71     {  
       
    72     delete iText;
       
    73     
       
    74     //font
       
    75     if(iFontOwnership && iFont)
       
    76         {
       
    77         BitmapDevice()->ReleaseFont(iFont);
       
    78         iFont = NULL;    
       
    79         }        
       
    80    }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CAknFepCtrlLabel::Draw
       
    84 // Draw the control
       
    85 // (other items were commented in a header).
       
    86 // ---------------------------------------------------------------------------
       
    87 //    
       
    88 EXPORT_C void CAknFepCtrlLabel::Draw()
       
    89     {
       
    90 	if(!AbleToDraw())
       
    91         return;
       
    92 
       
    93     TRect rect = Rect();
       
    94     CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());
       
    95     gc->Activate(MaskBitmapDevice());
       
    96 
       
    97     //clear the rect
       
    98     gc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
    99     gc->SetBrushColor(TRgb(KOpaqueColor));//non transparency
       
   100     gc->SetPenStyle(CGraphicsContext::ENullPen);
       
   101     gc->DrawRect(rect);
       
   102 
       
   103     gc->Activate(BitmapDevice());
       
   104 
       
   105     if (BackgroundBmp())
       
   106         {
       
   107         if (BkMaskBmp())
       
   108             {
       
   109             gc->DrawBitmapMasked(rect, BackgroundBmp(), BackgroundBmp()->SizeInPixels(), 
       
   110                                  BkMaskBmp(), ETrue);
       
   111             }
       
   112         else
       
   113             {
       
   114             gc->DrawBitmap(rect, BackgroundBmp(), BackgroundBmp()->SizeInPixels());
       
   115             }    
       
   116         }
       
   117 
       
   118     //draw caption if there is
       
   119     if(iText && iFont)
       
   120         {
       
   121         CFbsBitGc* gc = static_cast<CFbsBitGc*>(BitGc());        
       
   122         
       
   123         //use font
       
   124         gc->UseFont(iFont);
       
   125         gc->SetBrushStyle(CGraphicsContext::ENullBrush); 
       
   126         gc->SetPenStyle(CGraphicsContext::ESolidPen);                        
       
   127        
       
   128         TRect rect(iRect);
       
   129         
       
   130         //draw text shadow first
       
   131         rect.Move(1,1);
       
   132         
       
   133         TInt baseLine = iFont->AscentInPixels()/2 + iRect.Height()/2;
       
   134         gc->SetPenColor(iFontColor);              
       
   135         gc->DrawText(*iText, iRect, baseLine, iAlignment);
       
   136         
       
   137         gc->DiscardFont();
       
   138         }
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CAknFepCtrlLabel::SetBitmapL
       
   143 // Set bitmap for given status
       
   144 // (other items were commented in a header).
       
   145 // ---------------------------------------------------------------------------
       
   146 //    
       
   147 EXPORT_C void CAknFepCtrlLabel::SetBitmapL(CFbsBitmap* aBitmap)
       
   148     {
       
   149     if(!aBitmap)
       
   150         {
       
   151         return;
       
   152         }
       
   153         
       
   154     SetBackgroundBitmapL(aBitmap);    
       
   155     }  
       
   156    
       
   157 // ---------------------------------------------------------------------------
       
   158 // CAknFepCtrlLabel::SetMaskBitmapL
       
   159 // Set mask bitmap for given status
       
   160 // (other items were commented in a header).
       
   161 // ---------------------------------------------------------------------------
       
   162 //    
       
   163 EXPORT_C void CAknFepCtrlLabel::SetMaskBitmapL(CFbsBitmap* aBmp)
       
   164     {   
       
   165     if(!aBmp)
       
   166         {
       
   167         return;   
       
   168         }
       
   169         
       
   170     SetBackgroundMaskBitmapL(aBmp); 
       
   171     }
       
   172   
       
   173 // ---------------------------------------------------------------------------
       
   174 // CAknFepCtrlLabel::SetFont
       
   175 // Set caption font
       
   176 // (other items were commented in a header).
       
   177 // ---------------------------------------------------------------------------
       
   178 //        
       
   179 EXPORT_C void CAknFepCtrlLabel::SetFont(const TFontSpec& aFontSpec)
       
   180     {
       
   181     iFontSpec = aFontSpec;
       
   182     //release old font
       
   183     if(iFontOwnership && iFont)
       
   184         {
       
   185         BitmapDevice()->ReleaseFont(iFont);
       
   186         iFont = NULL;    
       
   187         }    
       
   188         
       
   189     iFontOwnership = ETrue;    
       
   190     if(BitmapDevice())
       
   191         {
       
   192         if (KErrNone != BitmapDevice()->GetNearestFontInPixels(iFont,iFontSpec))
       
   193             iFont = NULL;
       
   194         }      
       
   195     }        
       
   196     
       
   197 // ---------------------------------------------------------------------------
       
   198 // CAknFepCtrlLabel::SetFont
       
   199 // Set caption font
       
   200 // (other items were commented in a header).
       
   201 // ---------------------------------------------------------------------------
       
   202 //        
       
   203 EXPORT_C void CAknFepCtrlLabel::SetFont(const CFont* aFont)
       
   204     {
       
   205     if(iFontOwnership && iFont)
       
   206         {
       
   207         BitmapDevice()->ReleaseFont(iFont);
       
   208         }    
       
   209 
       
   210     iFontOwnership = EFalse;    
       
   211     iFont = const_cast<CFont*>(aFont);
       
   212 
       
   213     if(iFont)
       
   214         {
       
   215         iFontSpec = iFont->FontSpecInTwips();
       
   216         }
       
   217     }        
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CAknFepCtrlEventButton::SetFontColor
       
   221 // (other items were commented in a header).
       
   222 // -----------------------------------------------------------------------------
       
   223 //
       
   224 EXPORT_C void CAknFepCtrlLabel::SetFontColor(const TRgb aColor)
       
   225     {
       
   226     iFontColor = aColor;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CAknFepCtrlEventButton::SetText
       
   231 // (other items were commented in a header).
       
   232 // -----------------------------------------------------------------------------
       
   233 //    
       
   234 EXPORT_C void CAknFepCtrlLabel::SetText(const TDesC& aText)
       
   235     {
       
   236  
       
   237     delete iText;
       
   238     iText = NULL;
       
   239     
       
   240     TRAP_IGNORE( iText = aText.AllocL());
       
   241     
       
   242     Draw();
       
   243     }    
       
   244     
       
   245 // ---------------------------------------------------------------------------
       
   246 // CAknFepCtrlLabel::SizeChanged
       
   247 // This methods shall be called by the container's SizeChanged handler
       
   248 // (other items were commented in a header).
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C void CAknFepCtrlLabel::SizeChanged(TRect aNewRect, TBool aIsReloadImages)
       
   252     {
       
   253     if (aNewRect.Size().iWidth == 0 || aNewRect.Size().iHeight == 0)
       
   254         {
       
   255    	    return;
       
   256         }
       
   257     
       
   258     SetRect(aNewRect);
       
   259 
       
   260     if (aIsReloadImages)
       
   261         {
       
   262         ResizeBitmaps(aNewRect.Size());	
       
   263         }
       
   264 
       
   265     Draw();
       
   266     UpdateArea(Rect(), EFalse);
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // CAknFepCtrlLabel::ResizeBitmaps
       
   271 // This methods shall be called by the container's SizeChanged handler
       
   272 // (other items were commented in a header).
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CAknFepCtrlLabel::ResizeBitmaps(TSize aSize)
       
   276     {
       
   277     if (BkMaskBmp() && 
       
   278         BkMaskBmp()->SizeInPixels() != aSize)
       
   279         {
       
   280        	AknIconUtils::SetSize(BkMaskBmp(), aSize, EAspectRatioNotPreserved);
       
   281         }
       
   282 
       
   283     if (BackgroundBmp() && 
       
   284         BackgroundBmp()->SizeInPixels() != aSize)
       
   285         {
       
   286        	AknIconUtils::SetSize(BackgroundBmp(), aSize, EAspectRatioNotPreserved);
       
   287         }
       
   288     }
       
   289     
       
   290 // ---------------------------------------------------------------------------
       
   291 // CAknFepCtrlLabel::SetTextAlignment
       
   292 // This methods shall be called by the container's SizeChanged handler
       
   293 // (other items were commented in a header).
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C void CAknFepCtrlLabel::SetTextAlignment(CGraphicsContext::TTextAlign aAlignment)
       
   297     {
       
   298     iAlignment = aAlignment;
       
   299     }        
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // CAknFepCtrlLabel::TextAlignment
       
   303 // This methods shall be called by the container's SizeChanged handler
       
   304 // (other items were commented in a header).
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 EXPORT_C CGraphicsContext::TTextAlign CAknFepCtrlLabel::TextAlignment()    
       
   308     {
       
   309     return iAlignment;
       
   310     }    
       
   311 
       
   312 // End Of File