calendarui/views/src/calenweeklistboxview.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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:   CCalenWeekLBView customized key action of
       
    15  *                CFormattedCellListBoxView, and customized scrolling
       
    16  *                for event indicator.
       
    17  *
       
    18 */
       
    19 
       
    20 
       
    21 //debug
       
    22 #include "calendarui_debug.h"
       
    23 
       
    24 //  INCLUDE FILES
       
    25 #include "calenweeklistboxview.h"
       
    26 #include "calenweeklistboxdata.h"
       
    27 
       
    28 
       
    29 #include <AknUtils.h>
       
    30 
       
    31 
       
    32 //  LOCAL CONSTANTS AND MACROS
       
    33 #define ITEM_EXISTS(x) (((x) > -1) && ((x) < iModel->NumberOfItems()))
       
    34 
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // C++ default constructor can NOT contain any code, that
       
    39 // might leave.
       
    40 //
       
    41 CCalenWeekLBView::CCalenWeekLBView()
       
    42     {
       
    43     TRACE_ENTRY_POINT;
       
    44     TRACE_EXIT_POINT;
       
    45     }
       
    46 
       
    47 // Destructor
       
    48 CCalenWeekLBView::~CCalenWeekLBView()
       
    49     {
       
    50     TRACE_ENTRY_POINT;
       
    51     TRACE_EXIT_POINT;
       
    52     }
       
    53 
       
    54 // ---------------------------------------------------------
       
    55 // CCalenWeekLBView::SetColumn
       
    56 // Sets current Column
       
    57 // (other items were commented in a header).
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 void CCalenWeekLBView::SetColumn( TInt aColumn, TBool aRedraw)
       
    61     {
       
    62     TRACE_ENTRY_POINT;
       
    63     
       
    64     iColumn = aColumn;
       
    65     CFormattedCellListBoxItemDrawer* drawer =
       
    66         static_cast<CFormattedCellListBoxItemDrawer*>( iItemDrawer );
       
    67     CCalenWeekLBData* data =
       
    68         static_cast<CCalenWeekLBData*>( drawer->FormattedCellData() );
       
    69 
       
    70     data->SetHilightedSubCell(iColumn);
       
    71     // Resize highlight size (which is used by highlight animation)
       
    72     TSize size(data->SubCellSize(iColumn + 1));
       
    73     data->SetItemCellSize( size );
       
    74 
       
    75     if (aRedraw && ItemIsVisible(iCurrentItemIndex))
       
    76         {
       
    77         HideMatcherCursor();
       
    78 
       
    79         TRect redrawRect(ItemPos(iCurrentItemIndex),
       
    80                          ItemSize(iCurrentItemIndex));
       
    81         iWin->Invalidate(redrawRect);
       
    82         iWin->BeginRedraw(redrawRect);
       
    83         DrawItem(iCurrentItemIndex);
       
    84         iWin->EndRedraw();
       
    85         DrawMatcherCursor();
       
    86         }
       
    87     
       
    88     TRACE_EXIT_POINT;
       
    89     }
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CCalenWeekLBView::Column
       
    93 // Gets current Column
       
    94 // (other items were commented in a header).
       
    95 // ---------------------------------------------------------
       
    96 //
       
    97 TInt CCalenWeekLBView::Column() const
       
    98     {
       
    99     TRACE_ENTRY_POINT;
       
   100     
       
   101     TRACE_EXIT_POINT;
       
   102     return iColumn;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------
       
   106 // CCalenWeekLBView::DrawHighlightAnimBackground
       
   107 // Callback for drawing highlight background to highlight animation input
       
   108 // layer.
       
   109 // ---------------------------------------------------------
       
   110 //
       
   111 TBool CCalenWeekLBView::DrawHighlightAnimBackground( CFbsBitGc& aGc ) const
       
   112     {
       
   113     TRACE_ENTRY_POINT;
       
   114     
       
   115     CFormattedCellListBoxItemDrawer* drawer =
       
   116         static_cast<CFormattedCellListBoxItemDrawer*>( iItemDrawer );
       
   117     CCalenWeekLBData* data =
       
   118         static_cast<CCalenWeekLBData*>( drawer->FormattedCellData() );
       
   119 
       
   120     aGc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   121     aGc.SetBrushStyle(CGraphicsContext::ENullBrush);
       
   122 
       
   123     TInt index = CurrentItemIndex();
       
   124     if( index < 0 )
       
   125         index = 0;
       
   126 
       
   127     TRect rect;
       
   128     data->CurrentSubCellPos( rect, ItemPos( index ) );
       
   129 
       
   130     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
       
   131     MAknsControlContext* cc = NULL;
       
   132 
       
   133     if((cc = AknsDrawUtils::ControlContextOfParent( data->Control() )) == NULL)
       
   134         {
       
   135         cc = data->SkinBackgroundContext();
       
   136         }
       
   137     
       
   138     TRACE_EXIT_POINT;
       
   139     return AknsDrawUtils::DrawBackground( skin, cc, NULL, aGc, TPoint(0,0), rect, KAknsDrawParamNoClearUnderImage);
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------
       
   143 // CCalenWeekLBView::HorizontalMoveToItemL
       
   144 // Calls form MoveCursorL().Left/Right arrow key handing function
       
   145 // (other items were commented in a header).
       
   146 // ---------------------------------------------------------
       
   147 //
       
   148 void CCalenWeekLBView::HorizontalMoveToItemL( TInt aTargetSubCellIndex, TSelectionMode aSelectionMode)
       
   149     {
       
   150     TRACE_ENTRY_POINT;
       
   151     
       
   152     TInt oldCurrentItemIndex(iColumn);
       
   153     iColumn = aTargetSubCellIndex;
       
   154 
       
   155     if (ColumnExist(iColumn) && !(iColumn == oldCurrentItemIndex))
       
   156         {
       
   157         SetColumn(iColumn, EFalse);
       
   158 
       
   159         CFormattedCellListBoxItemDrawer* drawer =
       
   160             static_cast<CFormattedCellListBoxItemDrawer*>( iItemDrawer );
       
   161         CCalenWeekLBData* data =
       
   162             static_cast<CCalenWeekLBData*>( drawer->FormattedCellData() );
       
   163 
       
   164         TPoint oldPos(data->SubCellPosition(oldCurrentItemIndex + 1));
       
   165         TPoint pos(data->SubCellPosition(iColumn + 1));
       
   166         TSize size(data->SubCellSize(iColumn + 1));
       
   167         TInt left(Min(oldPos.iX, pos.iX));
       
   168         TInt right(Max(oldPos.iX, pos.iX));
       
   169         TInt y(ItemPos(iCurrentItemIndex).iY);
       
   170         TRect redrawRect(left, y, right, y + size.iHeight);
       
   171 
       
   172         iGc->SetClippingRect(redrawRect);
       
   173 
       
   174         iItemDrawer->DrawItem(iCurrentItemIndex,
       
   175                               ItemPos(iCurrentItemIndex), ItemIsSelected(iCurrentItemIndex),
       
   176                               ETrue, (iFlags&EEmphasized) > 0, (iFlags&EDimmed) > 0 );
       
   177 
       
   178         iGc->CancelClippingRect();
       
   179         }
       
   180     UpdateSelectionL(aSelectionMode);
       
   181     
       
   182     TRACE_EXIT_POINT;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------
       
   186 // CCalenWeekLBView::ColumnExist
       
   187 // Check column existence
       
   188 // (other items were commented in a header).
       
   189 // ---------------------------------------------------------
       
   190 //
       
   191 TBool CCalenWeekLBView::ColumnExist(TInt aColumn)  // Column index
       
   192     {
       
   193     TRACE_ENTRY_POINT;
       
   194     
       
   195     CFormattedCellListBoxItemDrawer* drawer =
       
   196         static_cast<CFormattedCellListBoxItemDrawer*>( iItemDrawer );
       
   197     CCalenWeekLBData* data =
       
   198         static_cast<CCalenWeekLBData*>( drawer->FormattedCellData() );
       
   199 
       
   200     if (aColumn >= 0 && aColumn < (data->CellCount() - 1))
       
   201         {
       
   202         TRACE_EXIT_POINT;
       
   203         return ETrue;
       
   204         }
       
   205     
       
   206     TRACE_EXIT_POINT;
       
   207     return EFalse;
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------
       
   211 // CCalenWeekLBView::MoveCursorL
       
   212 // Handling cursor move
       
   213 // (other items were commented in a header).
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void CCalenWeekLBView::MoveCursorL(TCursorMovement aCursorMovement, TSelectionMode aSelectionMode)
       
   217     {
       
   218     TRACE_ENTRY_POINT;
       
   219     
       
   220     switch (aCursorMovement)
       
   221         {
       
   222         case ECursorNextColumn:     // Right cursor was pressed
       
   223             HorizontalMoveToItemL(iColumn + 1, aSelectionMode);
       
   224             break;
       
   225         case ECursorPreviousColumn: // Left cursor was pressed
       
   226             HorizontalMoveToItemL(iColumn - 1, aSelectionMode);
       
   227             break;
       
   228         default:
       
   229             CFormattedCellListBoxView::MoveCursorL(
       
   230                 aCursorMovement, aSelectionMode);
       
   231             break;
       
   232         }
       
   233     
       
   234     TRACE_EXIT_POINT;
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------
       
   238 // CCalenWeekLBView::Draw
       
   239 // Drawing all visible item
       
   240 // (other items were commented in a header).
       
   241 // ---------------------------------------------------------
       
   242 //
       
   243 void CCalenWeekLBView::Draw(const TRect* /*clipRect*/) const
       
   244     {
       
   245     TRACE_ENTRY_POINT;
       
   246     
       
   247     if(RedrawDisabled() || !IsVisible())
       
   248         {
       
   249         return;
       
   250         }
       
   251 
       
   252     if(iModel->NumberOfItems() == 0)
       
   253         {
       
   254         iItemDrawer->ClearRect(iViewRect);
       
   255         }
       
   256     else
       
   257         {
       
   258         TInt firstPotentialItemIndex(iTopItemIndex);
       
   259         TRect rect(iViewRect);
       
   260         TInt lastPotentialItemIndex( iTopItemIndex + NumberOfItemsThatFitInRect(rect) -1 );
       
   261         TInt i(firstPotentialItemIndex);
       
   262 
       
   263         for(; i <= lastPotentialItemIndex; ++i)
       
   264             {
       
   265             if( ITEM_EXISTS(i) )
       
   266                 {
       
   267                 DrawItem( i );
       
   268                 }
       
   269             }
       
   270         }
       
   271     
       
   272     TRACE_EXIT_POINT;
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------
       
   276 // CCalenWeekLBView::DrawItem
       
   277 // Draw item
       
   278 // (other items were commented in a header).
       
   279 // ---------------------------------------------------------
       
   280 //
       
   281 void CCalenWeekLBView::DrawItem(TInt aItemIndex) const     // Item index
       
   282     {
       
   283     TRACE_ENTRY_POINT;
       
   284     
       
   285     if (RedrawDisabled() || !IsVisible())
       
   286         {
       
   287         return;
       
   288         }
       
   289 
       
   290     if ((ITEM_EXISTS(aItemIndex)) && ItemIsVisible(aItemIndex))
       
   291         {
       
   292         iGc->SetClippingRect(iViewRect);
       
   293 
       
   294         iItemDrawer->DrawItem(aItemIndex,
       
   295                               ItemPos(aItemIndex), ItemIsSelected(aItemIndex),
       
   296                               (aItemIndex == iCurrentItemIndex),
       
   297                               (iFlags&EEmphasized) > 0, (iFlags&EDimmed) > 0 );
       
   298 
       
   299         iGc->CancelClippingRect();
       
   300         }
       
   301     
       
   302     TRACE_EXIT_POINT;
       
   303     }
       
   304 
       
   305 
       
   306 // ---------------------------------------------------------
       
   307 // CCalenWeekLBView::PointerMoveToItemL
       
   308 // (other items were commented in a header).
       
   309 // ---------------------------------------------------------
       
   310 //
       
   311 void CCalenWeekLBView::PointerMoveToItemL(TInt aNewColumn)
       
   312     {
       
   313     TRACE_ENTRY_POINT;
       
   314     
       
   315     if(AknLayoutUtils::PenEnabled())
       
   316         {
       
   317         if(aNewColumn >= 0 && aNewColumn != iColumn)
       
   318             HorizontalMoveToItemL(aNewColumn, CListBoxView::ENoSelection);
       
   319         }
       
   320     
       
   321     TRACE_EXIT_POINT;
       
   322     }
       
   323 
       
   324 
       
   325 // End of File