phonebookui/Phonebook/View/src/CPbkThumbnailPopupControlSlim.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *       Provides methods for Control for thumbnail popup window.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "CPbkThumbnailPopupControlSlim.h"
       
    22 #include    <PbkView.rsg>
       
    23 #include    <barsread.h> // TResourceReader
       
    24 #include    <coemain.h> // CCoeEnv
       
    25 #include    <eikenv.h>  // CCoeMain
       
    26 #include    <aknappui.h>
       
    27 #include    <PbkDebug.h>
       
    28 
       
    29 #include <aknlayout.cdl.h>
       
    30 #include <applayout.cdl.h>
       
    31 #include <aknlayoutscalable_apps.cdl.h>
       
    32 #include <aknlayoutscalable_avkon.cdl.h>
       
    33 #include <layoutmetadata.cdl.h>
       
    34 
       
    35 
       
    36 // Unnamed namespace for local definitions
       
    37 namespace {
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 inline TRect RectFromCoords(const TRect& aParent, TAknWindowLineLayout& aLayout)
       
    41     {
       
    42     TAknLayoutRect layoutRect;
       
    43     layoutRect.LayoutRect(aParent, aLayout);
       
    44     return layoutRect.Rect();
       
    45     }
       
    46 
       
    47 } // namespace
       
    48 
       
    49 // ================= MEMBER FUNCTIONS =======================
       
    50 
       
    51 CPbkThumbnailPopupControlSlim* CPbkThumbnailPopupControlSlim::NewL()
       
    52     {
       
    53     CPbkThumbnailPopupControlSlim* self = new (ELeave) CPbkThumbnailPopupControlSlim();
       
    54     CleanupStack::PushL(self);
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop();
       
    57     return self;
       
    58     }
       
    59 
       
    60 CPbkThumbnailPopupControlSlim::~CPbkThumbnailPopupControlSlim()
       
    61     {
       
    62     delete iBitmap;
       
    63     }
       
    64 
       
    65 void CPbkThumbnailPopupControlSlim::ChangeBitmap(
       
    66     CFbsBitmap* aBitmap, 
       
    67     CEikListBox* aListBox)
       
    68     {
       
    69     
       
    70     // the is no LAF definitions for thumbnail position on landscape mode,
       
    71     // so the position of a thumbnail bitmap is calculted from the 
       
    72     // material available. Some of the calculations might look a 
       
    73     // bit odd, but those seems to work. 
       
    74     
       
    75     // When the UI specifiers add the thumbnail coordinates to 
       
    76     // LAF documents, and someone does the work on Avkon layout
       
    77     // components, these can, and should be changed to more
       
    78     // appropriate way to get right coordinates.
       
    79 
       
    80 
       
    81     if(aBitmap != iBitmap && aBitmap != NULL )
       
    82         {
       
    83         delete iBitmap;
       
    84         iBitmap = aBitmap;
       
    85         }
       
    86     
       
    87     if (iBitmap && aListBox )
       
    88         {        
       
    89         iDrawNeeded = EFalse;
       
    90 
       
    91         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("Thumbnail size(W:%d H:%d)"), 
       
    92                         iBitmap->SizeInPixels().iWidth, 
       
    93                         iBitmap->SizeInPixels().iHeight);
       
    94 
       
    95         TRect appRect = iAvkonAppUi->ApplicationRect();
       
    96         TAknLayoutRect statusPaneRect;
       
    97         statusPaneRect.LayoutRect(appRect, AknLayout::status_pane(appRect, 0));
       
    98 
       
    99         TSize bitmapSize = iBitmap->SizeInPixels();
       
   100 
       
   101         /// bitmap blit position
       
   102         TPoint controlPoint(0,0);
       
   103 
       
   104         iControlSize.iHeight = bitmapSize.iHeight;
       
   105         iControlSize.iWidth = bitmapSize.iWidth;
       
   106             
       
   107 
       
   108         // bitmap
       
   109         TAknWindowComponentLayout componentThumbnail = 
       
   110             AknLayoutScalable_Apps::popup_phob_thumbnail_window_g1();
       
   111             
       
   112         TAknWindowLineLayout lineThumbnail = componentThumbnail.LayoutLine();
       
   113         TAknLayoutRect aknRectThumbnail;
       
   114         aknRectThumbnail.LayoutRect( TRect(), componentThumbnail );
       
   115 
       
   116         // Shadow size
       
   117                
       
   118         TAknWindowComponentLayout componentThumbnailShadow = 
       
   119             AknLayoutScalable_Apps::popup_phob_thumbnail_window_g2();
       
   120         TAknWindowLineLayout lineThumbnailShadow = componentThumbnailShadow.LayoutLine();
       
   121         TAknLayoutRect aknRectThumbnailShadow;
       
   122         aknRectThumbnailShadow.LayoutRect( TRect(), componentThumbnailShadow );
       
   123             
       
   124         iShadowWidth = aknRectThumbnailShadow.Rect().iTl.iX - aknRectThumbnail.Rect().iTl.iX ;
       
   125         if ( iShadowWidth < 0 )
       
   126             {
       
   127             iShadowWidth  = aknRectThumbnail.Rect().iTl.iX - aknRectThumbnailShadow.Rect().iTl.iX;
       
   128             }
       
   129         iShadowHeight = aknRectThumbnailShadow.Rect().iTl.iY - aknRectThumbnail.Rect().iTl.iY;
       
   130         if ( iShadowHeight < 0 )
       
   131             {
       
   132             iShadowHeight  = aknRectThumbnail.Rect().iTl.iY - aknRectThumbnailShadow.Rect().iTl.iY;          
       
   133             }
       
   134 
       
   135         // increment shadow size
       
   136         iControlSize.iWidth += iShadowWidth;
       
   137         iControlSize.iHeight += iShadowHeight;
       
   138 
       
   139         // x
       
   140         TAknWindowComponentLayout layoutCompScrollPane = AknLayoutScalable_Avkon::scroll_pane_cp15(0);
       
   141         TAknWindowLineLayout layoutLineScrollPane = layoutCompScrollPane.LayoutLine();
       
   142         if ( Layout_Meta_Data::IsMirrored() )
       
   143             {
       
   144             TPoint tlListBox  = aListBox->View()->ViewRect().iTl; 
       
   145             controlPoint.iX += tlListBox.iX;
       
   146             // following "2*" is esthetic addition just to avoid unwanted
       
   147             // error reports 
       
   148             controlPoint.iX += 2 * layoutLineScrollPane.iW;  
       
   149             }
       
   150         else
       
   151             {
       
   152             TPoint brListBox  = aListBox->View()->ViewRect().iBr; 
       
   153             controlPoint.iX += brListBox.iX - iControlSize.iWidth;
       
   154             // following "2*" is esthetic addition just to avoid unwanted
       
   155             // error reports 
       
   156             controlPoint.iX -= 2 * layoutLineScrollPane.iW;              
       
   157             }
       
   158         
       
   159         // y        
       
   160         TAknWindowComponentLayout layoutCompAreaTopPane = AknLayoutScalable_Avkon::area_top_pane(1);
       
   161         TAknWindowLineLayout layoutLineAreaTopPane = layoutCompAreaTopPane.LayoutLine();
       
   162         controlPoint.iY += layoutLineAreaTopPane.iH;
       
   163 
       
   164         TAknWindowComponentLayout layoutCompIndicatorPane = AknLayoutScalable_Avkon::indicator_pane_g1(0);
       
   165         TAknWindowLineLayout layoutLineIndicatorPane = layoutCompIndicatorPane.LayoutLine();
       
   166         controlPoint.iY += layoutLineIndicatorPane.iH;
       
   167                 
       
   168         TInt itemCount = aListBox->CurrentItemIndex() - aListBox->TopItemIndex();
       
   169         TPoint brListBox  = aListBox->View()->ViewRect().iBr; 
       
   170         TInt maxItemCount( aListBox->View()->NumberOfItemsThatFitInRect( aListBox->View()->ViewRect() ) );
       
   171         TInt itemHeight( aListBox->ItemHeight() );
       
   172         TInt yMaxSize( maxItemCount * itemHeight );
       
   173         TSize itemSize = aListBox->View()->ItemSize();
       
   174         if ( iThumbnailDown )
       
   175             {
       
   176             // Add one to itemCount so that we get also the focused one counted to size
       
   177             TInt ypos = ( itemCount + 1 ) * itemHeight;
       
   178             if ( ( yMaxSize - ypos ) < iControlSize.iHeight )
       
   179                 {
       
   180                 iThumbnailDown = EFalse;
       
   181                 iDrawNeeded = ETrue;
       
   182                 }
       
   183             }
       
   184         else
       
   185             {
       
   186             TInt ypos = itemCount * itemHeight;
       
   187             if ( ypos < iControlSize.iHeight )
       
   188                 {
       
   189                 iThumbnailDown = ETrue;
       
   190                 iDrawNeeded = ETrue;
       
   191                 }
       
   192             }
       
   193 
       
   194         if ( iThumbnailDown )        
       
   195             {
       
   196             controlPoint.iY += yMaxSize - iControlSize.iHeight;
       
   197             // The bitmap gets too close to the listbox's bottom line
       
   198             // so lets set the relative distance from edge to same
       
   199             // on sitaution where the bitmap is located upper corner.
       
   200             controlPoint.iY -= layoutLineIndicatorPane.iH;
       
   201             }
       
   202         
       
   203         // set the control size
       
   204         SetExtent(controlPoint, iControlSize);
       
   205         if ( iDrawNeeded )
       
   206             {
       
   207             DrawNow();        
       
   208             }
       
   209         }
       
   210     else // the else branch is for vCard viewer, it does not have a listbox.
       
   211         if (iBitmap && aBitmap )
       
   212         {
       
   213         
       
   214         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("Thumbnail size(W:%d H:%d)"), 
       
   215                         iBitmap->SizeInPixels().iWidth, 
       
   216                         iBitmap->SizeInPixels().iHeight);
       
   217 
       
   218         TRect appRect = iAvkonAppUi->ApplicationRect();
       
   219         TAknLayoutRect mainPaneRect;
       
   220         
       
   221         mainPaneRect.LayoutRect(appRect, AknLayout::main_pane(appRect, 0, 1, 1));
       
   222                 
       
   223         TSize bitmapSize = iBitmap->SizeInPixels();
       
   224 
       
   225         /// bitmap blit position
       
   226         TPoint controlPoint;
       
   227 
       
   228         // bitmap
       
   229         TAknWindowComponentLayout componentThumbnail = 
       
   230             AknLayoutScalable_Apps::popup_phob_thumbnail_window_g1();
       
   231             
       
   232         // center of bitmap
       
   233         TAknWindowComponentLayout componentThumbnailCenter = 
       
   234             AknLayoutScalable_Apps::aid_phob_thumbnail_center_pane();
       
   235 
       
   236         TAknWindowLineLayout lineThumbnail = componentThumbnail.LayoutLine();
       
   237         TAknLayoutRect aknRectThumbnail;
       
   238         aknRectThumbnail.LayoutRect( TRect(), componentThumbnail );
       
   239         
       
   240         TAknWindowLineLayout lineThumbnailCenter = componentThumbnailCenter.LayoutLine();
       
   241         TAknLayoutRect aknRectThumbnailCenter;
       
   242         aknRectThumbnailCenter.LayoutRect( TRect(), componentThumbnailCenter );
       
   243 
       
   244         // Calculate Y position
       
   245         const TInt imageMaxHeight( aknRectThumbnail.Rect().Height() );
       
   246         
       
   247         if ( bitmapSize.iHeight < aknRectThumbnail.Rect().Height() )
       
   248             {
       
   249             controlPoint.iY = aknRectThumbnailCenter.Rect().Height() - bitmapSize.iHeight/2;
       
   250             if (controlPoint.iY < 0)
       
   251                 {
       
   252                 controlPoint.iY = 0;
       
   253                 }
       
   254             iControlSize.iHeight = bitmapSize.iHeight;
       
   255             }
       
   256         else 
       
   257             {
       
   258             controlPoint.iY = 0;
       
   259             iControlSize.iHeight = imageMaxHeight;
       
   260             }
       
   261                                 
       
   262         // calculate the X position of the bitmap
       
   263         const TInt imageMaxWidth( aknRectThumbnail.Rect().Width() );        
       
   264         controlPoint.iX = aknRectThumbnailCenter.Rect().Width() - bitmapSize.iWidth/2;
       
   265         
       
   266         if (controlPoint.iX <= 0)
       
   267             {
       
   268             controlPoint.iX = 0;
       
   269             iControlSize.iWidth = imageMaxWidth;
       
   270             }
       
   271         else 
       
   272             {
       
   273             iControlSize.iWidth = bitmapSize.iWidth;
       
   274             }
       
   275         
       
   276         // calculate the actual bitmap position according to LAF
       
   277         TAknWindowLineLayout popupLayout = AppLayout::popup_pbook_thumbnail_window();
       
   278         TRect popupWindowRect = RectFromCoords(mainPaneRect.Rect(), lineThumbnail);        
       
   279         
       
   280         TAknWindowComponentLayout layoutCompScrollPane = AknLayoutScalable_Avkon::scroll_pane_cp15(0);
       
   281         TAknWindowLineLayout layoutLineScrollPane = layoutCompScrollPane.LayoutLine();        
       
   282         
       
   283         // the x-position of thumbnail is calculated referring to the scroll pane, because
       
   284         // the LAF defines the position of thumbnail in landscape mode to wrong place
       
   285         // ( located on the context pane's position, and the it should be in bottom right
       
   286         // corner), so the LAF coordinates cannot be used.
       
   287         if ( Layout_Meta_Data::IsMirrored() )
       
   288             {                        
       
   289             controlPoint.iX += layoutLineScrollPane.iW + ( layoutLineScrollPane.iW / 2 );                        
       
   290             controlPoint.iY += mainPaneRect.Rect().iBr.iY;
       
   291             controlPoint.iY -= popupWindowRect.iBr.iY;                    
       
   292             }
       
   293         else
       
   294             {
       
   295             controlPoint.iX -= layoutLineScrollPane.iW + ( layoutLineScrollPane.iW / 2 );
       
   296             controlPoint += mainPaneRect.Rect().iBr;
       
   297             controlPoint -= popupWindowRect.iBr;            
       
   298             }
       
   299         
       
   300             
       
   301         // Shadow size
       
   302         TAknWindowComponentLayout componentThumbnailShadow = 
       
   303             AknLayoutScalable_Apps::popup_phob_thumbnail_window_g2();
       
   304         TAknWindowLineLayout lineThumbnailShadow = componentThumbnailShadow.LayoutLine();
       
   305         TAknLayoutRect aknRectThumbnailShadow;
       
   306         aknRectThumbnailShadow.LayoutRect( TRect(), componentThumbnailShadow );
       
   307             
       
   308         iShadowWidth = aknRectThumbnailShadow.Rect().iTl.iX - aknRectThumbnail.Rect().iTl.iX ;
       
   309         if ( iShadowWidth < 0 )
       
   310             {
       
   311             iShadowWidth  = aknRectThumbnail.Rect().iTl.iX - aknRectThumbnailShadow.Rect().iTl.iX;
       
   312             }
       
   313         iShadowHeight = aknRectThumbnailShadow.Rect().iTl.iY - aknRectThumbnail.Rect().iTl.iY;
       
   314         if ( iShadowHeight < 0 )
       
   315             {
       
   316             iShadowHeight  = aknRectThumbnail.Rect().iTl.iY - aknRectThumbnailShadow.Rect().iTl.iY;          
       
   317             }
       
   318 
       
   319         // increment shadow size
       
   320         iControlSize.iWidth += iShadowWidth;
       
   321         iControlSize.iHeight += iShadowHeight;
       
   322         
       
   323         if ( !Layout_Meta_Data::IsMirrored() )
       
   324             {
       
   325             controlPoint.iX -= iShadowWidth;       
       
   326             }
       
   327         
       
   328         // set the control size
       
   329         SetExtent(controlPoint, iControlSize);
       
   330         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("##shadow: %d * %d"), iShadowWidth, iShadowHeight);
       
   331         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("##Thumbnail control size %d * %d"), iControlSize.iWidth, iControlSize.iHeight);
       
   332         DrawNow();            
       
   333         }
       
   334     }
       
   335 
       
   336 void CPbkThumbnailPopupControlSlim::Draw
       
   337         (const TRect& /*aRect*/) const
       
   338     {
       
   339     CWindowGc& gc = SystemGc();
       
   340 
       
   341     if (iBitmap)
       
   342         {   
       
   343         // draw the bitmap
       
   344         PBK_DEBUG_PRINT(PBK_DEBUG_STRING("Thumbnail draw (Left:%d Top:%d Right:%d Bottom:%d)"), 
       
   345                 Position().iX, 
       
   346                 Position().iY, 
       
   347                 Position().iX + iBitmap->SizeInPixels().iWidth,
       
   348                 Position().iY + iBitmap->SizeInPixels().iHeight); 
       
   349       
       
   350         gc.BitBltMasked( TPoint(iShadowWidth, iShadowHeight), 
       
   351                          iThumbBackg, 
       
   352                          TRect(0,0,iThumbBackg->SizeInPixels().iWidth, iThumbBackg->SizeInPixels().iHeight ),
       
   353                          iThumbBackgMask, 
       
   354                          EFalse);
       
   355         gc.BitBlt(TPoint(), iBitmap);
       
   356         }
       
   357     }
       
   358 
       
   359 CPbkThumbnailPopupControlSlim::CPbkThumbnailPopupControlSlim()
       
   360     {
       
   361     }
       
   362 
       
   363 void CPbkThumbnailPopupControlSlim::ConstructL()
       
   364     {
       
   365     CreateWindowL();
       
   366     MakeVisible(EFalse);
       
   367     SetExtent(TPoint(0,0),TSize(0,0));
       
   368     ActivateL();
       
   369     }
       
   370 
       
   371 void CPbkThumbnailPopupControlSlim::SetThumbnailBackg( CFbsBitmap* aThumbBackg, CFbsBitmap* aThumbBackgMask )
       
   372     {
       
   373     iThumbBackg = aThumbBackg;
       
   374     iThumbBackgMask = aThumbBackgMask;
       
   375     }
       
   376 
       
   377 void CPbkThumbnailPopupControlSlim::MakeControlVisible( TBool aVisible )
       
   378     {
       
   379     // make control visible
       
   380     MakeVisible(aVisible);
       
   381     // MakeVisible does not seem to make sure the control is redrawn
       
   382     DrawDeferred();    
       
   383     }
       
   384 
       
   385 //  End of File