textinput/peninputcommonctrls/src/peninputdropdownlist/peninputlistonerowwithouticon.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  One rows list with icon for drop-down list objects
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Include 
       
    20 #include "peninputlistonerowwithouticon.h"
       
    21 #include "peninputcandidate.h"
       
    22 
       
    23 #include <peninputdropdownlistcontext.h>
       
    24 #include <peninputdropdownlist.h>
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // Implementation of Class CListOneRowWithoutIcon 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CListOneRowWithoutIcon::CListOneRowWithoutIcon
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave
       
    34 // (other items were commented in a header).
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CListOneRowWithoutIcon::CListOneRowWithoutIcon(CListManager* aManager, 
       
    38                                                MFepCtrlDropdownListContext* aOwner)
       
    39 :CList(aManager, aOwner)
       
    40     {
       
    41     iIsMultiRows = EFalse;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CListOneRowWithoutIcon::NewL
       
    46 // factory function
       
    47 // (other items were commented in a header).
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 CListOneRowWithoutIcon* CListOneRowWithoutIcon::NewL(CListManager* aManager,
       
    51                                                      MFepCtrlDropdownListContext* aOwner)
       
    52     {
       
    53     CListOneRowWithoutIcon* self = new (ELeave) CListOneRowWithoutIcon(aManager, aOwner);
       
    54     CleanupStack::PushL(self);
       
    55     self->ConstructL();
       
    56     CleanupStack::Pop();
       
    57     return self;
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CListOneRowWithoutIcon::~CListOneRowWithoutIcon
       
    62 // desstrutor function
       
    63 // (other items were commented in a header).
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CListOneRowWithoutIcon::~CListOneRowWithoutIcon()
       
    67     {   
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CListOneRowWithoutIcon::HandlePointerDownL
       
    72 // handle pointer down 
       
    73 // (other items were commented in a header).
       
    74 // -----------------------------------------------------------------------------
       
    75 //
       
    76 void CListOneRowWithoutIcon::HandlePointerDownL(const TPoint& aPoint)
       
    77     {    
       
    78     // Pass the event first to the base     
       
    79     CList::HandlePointerDownL(aPoint);
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CListOneRowWithoutIcon::HandlePointerDragL
       
    84 // handle pointer drag function
       
    85 // (other items were commented in a header).
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CListOneRowWithoutIcon::HandlePointerDragL(const TPoint& aPoint)
       
    89     { 
       
    90     // Pass the event first to the base
       
    91     CList::HandlePointerDragL(aPoint);
       
    92     
       
    93     // If the mouse have click in the area of DDL
       
    94     if ( iIndicateButtonClicked )  
       
    95         {
       
    96         TInt index = -1;
       
    97         
       
    98         CCandidate* candidate = FindCandidate(aPoint, index);
       
    99         iMoveLatestRect = KEmptyRect;
       
   100         
       
   101         if ( candidate )
       
   102             {
       
   103             iMoveLatestRect.SetRect(candidate->GetRect().iTl, candidate->GetRect().Size());
       
   104             }          
       
   105         
       
   106         // Compare the two rect, then decide draw it or not
       
   107         CompareRect(iMoveLatestRect, iClickedRect);
       
   108         }
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CListOneRowWithoutIcon::HandlePointerUpL
       
   113 // handle pointer up function
       
   114 // (other items were commented in a header).
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 void CListOneRowWithoutIcon::HandlePointerUpL(const TPoint& aPoint)
       
   118     {
       
   119     if ( !iClickedRect.IsEmpty() )
       
   120         {
       
   121         // Find out which rectangle was clicked and save it for 
       
   122         // later usage (HandlePointerUpL)
       
   123         if ( iContentRect.Contains( aPoint ) )
       
   124             {
       
   125             if ( iClickedRect.Contains( aPoint ) )
       
   126                 {
       
   127                 if ( iClickedCandidateIndex != KErrNotFound )
       
   128                     {
       
   129                     // Redraw the selection rect  
       
   130                     DrawSelection( iClickedRect, EFalse );
       
   131                     
       
   132                     // We have selected a candidate
       
   133                     // Send message to plugin         
       
   134                     CCandidate* candidate = iOwner->GetCandidate(iClickedCandidateIndex);
       
   135                     if ( candidate )
       
   136                         {
       
   137                         iOwner->ReportCandidateSelectEventL(candidate->GetCandidate(),
       
   138                                                            iClickedCandidateIndex); 
       
   139                         }
       
   140                            
       
   141                     }                
       
   142                }
       
   143                 
       
   144             iIndicateButtonClicked = EFalse;
       
   145             }
       
   146             
       
   147         iClickedRect = KEmptyRect;               
       
   148         }
       
   149     }
       
   150 
       
   151 // -----------------------------------------------------------------------------
       
   152 // CListOneRowWithoutIcon::Draw
       
   153 // draw the list
       
   154 // (other items were commented in a header).
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void CListOneRowWithoutIcon::Draw()
       
   158     {
       
   159     CList::Draw();
       
   160     
       
   161     // Draw all visible candidates
       
   162     DrawCandidates();
       
   163     DrawSelection(iClickedRect, ETrue);
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CListOneRowWithoutIcon::CalculateAreas
       
   168 // Calculate all kinds of rectangles
       
   169 // (other items were commented in a header).
       
   170 // -----------------------------------------------------------------------------
       
   171 //
       
   172 void CListOneRowWithoutIcon::CalculateAreas()
       
   173     {
       
   174     // Calculate the rect of the list
       
   175     iRect.iTl = iOwner->GetTopLeftPoint();
       
   176     TInt width = iOwner->GetCellWidth() * iOwner->GetColNum() + iOwner->GetNaviWidth() + 
       
   177                  (iOwner->GetColNum() + 2) * iOwner->GetCellHorizontalMargin();
       
   178     TInt height = iOwner->GetCellHeight() + 2 * iOwner->GetCellVerticalMargin();                 
       
   179     
       
   180     iRect.SetSize(TSize(width,height));
       
   181 
       
   182     // Calculate the rect of the content
       
   183     iContentRect.iTl = TPoint(iRect.iTl.iX + iOwner->GetCellHorizontalMargin(),
       
   184                               iRect.iTl.iY + iOwner->GetCellVerticalMargin());
       
   185     iContentRect.SetSize(TSize(width - 2 * iOwner->GetCellHorizontalMargin(),
       
   186                                iOwner->GetCellHeight()));
       
   187 
       
   188     // Calculate the rect of the navigation area
       
   189     iNavigationRect = TRect(0,0,0,0);
       
   190 
       
   191     // Calculate the rect of the down button
       
   192     iNavigationNextRect = TRect(0,0,0,0);
       
   193 
       
   194     // Calculate the rect of the up button
       
   195     iNavigationPreviousRect = TRect(0,0,0,0);
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CListOneRowWithoutIcon::CalculatePositionsL
       
   200 // calculate the position of all visible cells in the list
       
   201 // (other items were commented in a header).
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 TInt CListOneRowWithoutIcon::CalculatePositionsL()
       
   205     {
       
   206     TInt t = 0;
       
   207     TPoint setpoints;
       
   208 
       
   209     const TInt count = iOwner->CandidateCount();
       
   210     
       
   211     // First store the last index
       
   212     iOwner->SetFirstCandidateIndex ( iOwner->GetLastCandidateIndex() );        
       
   213     
       
   214     if ( count > 0 )
       
   215         {
       
   216         // Initial the position to iContentRect
       
   217         /*
       
   218         setpoints.iX = iContentRect.iTl.iX;
       
   219         setpoints.iY = iContentRect.iTl.iY;
       
   220         */
       
   221         TBool candHLToR = (iOwner->CandHDirection() == CFepCtrlDropdownList::ECandFromLToR);
       
   222         candHLToR ? setpoints.SetXY(iContentRect.iTl.iX, iContentRect.iTl.iY) :
       
   223                     setpoints.SetXY(iContentRect.iBr.iX, iContentRect.iTl.iY);
       
   224 
       
   225         TInt cellNumberInOneRow = iOwner->GetColNum() + 1;
       
   226         TInt lastUsedCellCount = 0;
       
   227         TInt currentCellIndex = 0;
       
   228         TInt newCount = 0;
       
   229         
       
   230         newCount = Min(count,iOwner->GetLastCandidateIndex() + cellNumberInOneRow);   
       
   231                 
       
   232         for( t = iOwner->GetLastCandidateIndex(); t < newCount ; t++ )
       
   233             {
       
   234             // setting a position for this candidate 
       
   235             CCandidate* candidate = iOwner->GetCandidate(t);
       
   236 
       
   237             if ( !candidate )
       
   238                 {
       
   239                 continue;
       
   240                 }
       
   241                 
       
   242             lastUsedCellCount = candidate->SetPositionL(setpoints,
       
   243                                                         iOwner->GetCellWidth(),
       
   244                                                         iOwner->GetCellHeight(),
       
   245                                                         iOwner->GetFont(),
       
   246                                                         iOwner->GetCellHorizontalMargin()); 
       
   247             currentCellIndex += lastUsedCellCount;
       
   248             
       
   249             if ( currentCellIndex > ( iOwner->GetColNum() + 1 ) )
       
   250                 {
       
   251                 // If no space to contain other cells 
       
   252                 break;
       
   253                 }
       
   254 
       
   255             // Recalcuate the x position
       
   256             candHLToR? (setpoints.iX += (iOwner->GetCellWidth() + iOwner->GetCellHorizontalMargin()) * lastUsedCellCount) : 
       
   257                        (setpoints.iX -= (iOwner->GetCellWidth() + iOwner->GetCellHorizontalMargin()) * lastUsedCellCount);
       
   258             } // for-loop
       
   259         } // if candidate exist 
       
   260     
       
   261     return t; // as lastCandidateIndex
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CListOneRowWithoutIcon::UpdateList
       
   266 // update the list
       
   267 // (other items were commented in a header).
       
   268 // -----------------------------------------------------------------------------
       
   269 //
       
   270 void CListOneRowWithoutIcon::UpdateListL(TBool aDrawFlag, TBool aRecalculate)
       
   271     {
       
   272     if ( aRecalculate )
       
   273         {
       
   274         // Recalculate the position of all candidates
       
   275         iOwner->SetLastCandidateIndex(CalculatePositionsL());    
       
   276         }
       
   277     if(aDrawFlag)    
       
   278         {
       
   279         Draw();
       
   280         iOwner->Invalidate(iRect);
       
   281         }
       
   282     }
       
   283 
       
   284 // End Of File