fep/aknfep/UiPlugins/AknFepUiInterface/AvkonImpl/src/AknFepUiAvkonCtrlJapanesePredictiveListbox.cpp
changeset 40 2cb9bae34d17
parent 31 f1bdd6b078d1
child 49 37f5d84451bd
equal deleted inserted replaced
31:f1bdd6b078d1 40:2cb9bae34d17
     1 /*
       
     2 * Copyright (c) 2002-2004 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:            Predictive candidate list
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 
       
    27 
       
    28 
       
    29 // INCLUDE FILES
       
    30 #include <eikdef.h>
       
    31 #include <aknViewAppUi.h>
       
    32 #include <avkon.hrh>
       
    33 #include <aknPopup.h>
       
    34 #include <aknlists.h>
       
    35 #include <AknLayout.lag>
       
    36 #include <aknlayoutscalable_avkon.cdl.h>
       
    37 #include <AknFontId.h>
       
    38 
       
    39 #include "AknFepUiInterfacePanic.h"
       
    40 #include "AknFepUIAvkonCtrlJapanesePredictiveListboxView.h"
       
    41 #include "AknFepUIAvkonCtrlJapanesePredictiveListboxItemDrawer.h"
       
    42 #include "AknFepUIAvkonCtrlJapanesePredictiveCellListBoxData.h"
       
    43 #include "AknFepUIAvkonCtrlJapanesePredictiveListBoxModel.h"
       
    44 #include "AknFepUIAvkonCtrlJapanesePredictiveListbox.h"
       
    45 #include "AknFepUIAvkonCtrlJapanesePredictivePane.h"
       
    46 
       
    47 // CONSTANTS
       
    48 const TInt KListboxMarge = 4;
       
    49 const TInt KScrollRightMarge = 5;
       
    50 const TInt KListBoxVisibleRow = 3;
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CAknFepUICtrlJapanesePredictiveListbox::ConstructL
       
    56 // Symbian 2nd phase constructor can leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CAknFepUICtrlJapanesePredictiveListbox::ConstructL(
       
    60         const CCoeControl* aParent,
       
    61         TInt aFlags)
       
    62     {
       
    63     CAknFilteredTextListBoxModel* model =
       
    64             new(ELeave) CAknFepUICtrlJapanesePredictiveListBoxModel;
       
    65     iModel=model;
       
    66     model->ConstructL();
       
    67     CreateItemDrawerL();
       
    68 
       
    69     EnableExtendedDrawingL();
       
    70 
       
    71     iItemDrawer->SetDrawMark(EFalse);
       
    72     CEikListBox::ConstructL(aParent,aFlags);
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // CAknFepUICtrlJapanesePredictiveListbox::SetCurrentCandidateNo
       
    77 // Selecting a candidate number appointed with an argument
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CAknFepUICtrlJapanesePredictiveListbox::SetCurrentCandidateNo(
       
    81         TInt aCandidateNo, TBool aDraw)
       
    82     {
       
    83     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
    84         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
    85     TInt itemIndex = view->SetCurrentCandidateNo(aCandidateNo);
       
    86 
       
    87     if (aDraw)
       
    88         {
       
    89         SetCurrentItemIndexAndDraw(itemIndex);
       
    90         }
       
    91     else
       
    92         {
       
    93         SetCurrentItemIndex(itemIndex);
       
    94         }
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CAknFepUICtrlJapanesePredictiveListbox::CurrentCandidateNo
       
    99 // Returning a selected number
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 TInt CAknFepUICtrlJapanesePredictiveListbox::CurrentCandidateNo()
       
   103     {
       
   104     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   105         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   106     return view->CurrentCandidateNo();
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CAknFepUICtrlJapanesePredictiveListbox::MovePreviousItem
       
   111 // selecting a previous candidate
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 TInt CAknFepUICtrlJapanesePredictiveListbox::MovePreviousItem()
       
   115     {
       
   116     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   117         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   118 
       
   119     TInt candidateNo = view->PreviousItem();
       
   120     SetCurrentCandidateNo(candidateNo, ETrue);
       
   121 
       
   122     return candidateNo;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CAknFepUICtrlJapanesePredictiveListbox::MoveNextItem
       
   127 // selecting a next candidate
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 TInt CAknFepUICtrlJapanesePredictiveListbox::MoveNextItem()
       
   131     {
       
   132     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   133         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   134 
       
   135     TInt candidateNo = view->NextItem();
       
   136     SetCurrentCandidateNo(candidateNo, ETrue);
       
   137 
       
   138     return candidateNo;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CAknFepUICtrlJapanesePredictiveListbox::MovePreviousLineItem
       
   143 // selecting a previous line candidate
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 TInt CAknFepUICtrlJapanesePredictiveListbox::MovePreviousLineItem()
       
   147     {
       
   148     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   149         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   150     TInt candidateNo = view->PreviousLineItem();
       
   151     SetCurrentCandidateNo(candidateNo, ETrue);
       
   152 
       
   153     return candidateNo;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // CAknFepUICtrlJapanesePredictiveListbox::MoveNextLineItem
       
   158 // selecting a next line candidate
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 TInt CAknFepUICtrlJapanesePredictiveListbox::MoveNextLineItem()
       
   162     {
       
   163     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   164         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   165     TInt candidateNo = view->NextLineItem();
       
   166     SetCurrentCandidateNo(candidateNo, ETrue);
       
   167 
       
   168     return candidateNo;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CAknFepUICtrlJapanesePredictiveListbox::SizeChanged
       
   173 // This function is called in case changing size
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CAknFepUICtrlJapanesePredictiveListbox::SizeChanged()
       
   177     {
       
   178     CEikFormattedCellListBox& listBox = *this;
       
   179     CFormattedCellListBoxItemDrawer* itemDrawer = listBox.ItemDrawer();
       
   180 
       
   181     TAknWindowLineLayout textWindowLayout =
       
   182         AKN_LAYOUT_WINDOW_popup_fep_japan_predictive_window(0,0);
       
   183     // setting textbox size in listbox
       
   184     TAknTextLineLayout textLineLayout =
       
   185         AKN_LAYOUT_TEXT_Predictive_candidate_selection_list_texts_Line_1(0,0);
       
   186 
       
   187     TAknTextComponentLayout scal = AknLayoutScalable_Avkon::popup_fep_japan_predictive_window_t1(0);
       
   188     TAknWindowLineLayout scrollLineLayout = AknLayoutScalable_Avkon::scroll_pane_cp29().LayoutLine();
       
   189 
       
   190     TAknLayoutText text;
       
   191     text.LayoutText(textWindowLayout.Rect(), textLineLayout);
       
   192     textWindowLayout.iW = text.TextRect().Width();
       
   193     CAknFepUICtrlJapanesePredictiveListBoxModel* model =
       
   194         static_cast<CAknFepUICtrlJapanesePredictiveListBoxModel*>(Model());
       
   195     TInt maxRows = model->LineInfoArray()->Count();
       
   196     TInt maxVisibleRows = Min(KJapPredictiveVisibleListRowsMax, maxRows);
       
   197     maxVisibleRows = Max(KJapPredictiveVisibleListRowsMin, maxVisibleRows);
       
   198     textWindowLayout.iH = listBox.Size().iHeight / maxVisibleRows;
       
   199 
       
   200     AknListBoxLayouts::SetupStandardListBox(listBox);
       
   201     AknListBoxLayouts::SetupStandardFormListbox(itemDrawer);
       
   202     AknListBoxLayouts::SetupListboxPos(listBox, textWindowLayout);
       
   203     {
       
   204     TRgb color( KRgbBlack );
       
   205     // this does not modify color unless it gets a correct one
       
   206     // no real need to check errors
       
   207     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   208                               color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 );
       
   209     itemDrawer->SetHighlightedTextColor( color );
       
   210     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   211                                color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG7 );
       
   212     iItemDrawer->SetTextColor( color );
       
   213     }
       
   214 
       
   215     textLineLayout.il -= KListboxMarge;
       
   216     textLineLayout.ir = 0;
       
   217     // Baseline must be set to textLineLayout.iB.
       
   218     const CFont* font = AknLayoutUtils::FontFromId(textLineLayout.iFont);
       
   219     TInt baseLineOffset = (textWindowLayout.iH - font->HeightInPixels())/2 + font->AscentInPixels();
       
   220 
       
   221     if( TAknFontId::IsEncodedFont(textLineLayout.FontId()) )
       
   222         {
       
   223         textLineLayout.iB = textWindowLayout.iH - font->DescentInPixels() -1 - baseLineOffset;
       
   224         }
       
   225     else
       
   226         {
       
   227         textLineLayout.iB = baseLineOffset;
       
   228         }
       
   229     TSize itemSize = View()->ItemSize();
       
   230 
       
   231     AknListBoxLayouts::SetupFormAntiFlickerTextCell(listBox, itemDrawer, 0,
       
   232                             textLineLayout,
       
   233                             TPoint(0, 0),
       
   234                             TPoint(itemSize.iWidth, itemSize.iHeight));
       
   235 
       
   236     CEikFormattedCellListBox::SizeChanged();
       
   237 
       
   238     // Scroll bar
       
   239     scrollLineLayout.il = ELayoutEmpty;
       
   240     scrollLineLayout.ir = KScrollRightMarge;
       
   241     scrollLineLayout.it = 0;
       
   242     scrollLineLayout.ib = 0;
       
   243     if (maxRows <= KJapPredictiveVisibleListRowsMax)
       
   244         {
       
   245         scrollLineLayout.iW = 0;
       
   246         }
       
   247     TAknWindowLineLayout laf =
       
   248         AKN_LAYOUT_WINDOW_popup_fep_japan_predictive_window(0,0);
       
   249     TRect scrollBarParent = TRect(TPoint(0, listBox.Rect().iTl.iY),
       
   250                                   TPoint(laf.iW, listBox.Rect().iBr.iY));
       
   251     AknLayoutUtils::LayoutVerticalScrollBar(iSBFrame, scrollBarParent, scrollLineLayout);
       
   252     }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // CAknFepUICtrlJapanesePredictiveListbox::MakeViewClassInstanceL
       
   256 // Creating a view
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 CListBoxView* CAknFepUICtrlJapanesePredictiveListbox::MakeViewClassInstanceL()
       
   260     {
       
   261     return new(ELeave) CAknFepUICtrlJapanesePredictiveListboxView;
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // CAknFepUICtrlJapanesePredictiveListbox::CreateItemDrawerL
       
   266 // Creating a ItemDrawer
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 void CAknFepUICtrlJapanesePredictiveListbox::CreateItemDrawerL()
       
   270     {
       
   271     CAknFepUICtrlJapanesePredictiveCellListBoxData*
       
   272         cellData = CAknFepUICtrlJapanesePredictiveCellListBoxData::NewL();
       
   273     CleanupStack::PushL(cellData);
       
   274 
       
   275     // getting font object
       
   276     TAknTextLineLayout textLineLayout =
       
   277         AKN_LAYOUT_TEXT_Predictive_candidate_selection_list_texts_Line_1(
       
   278             0, 0);
       
   279     const CFont* font = AknLayoutUtils::FontFromId(textLineLayout.iFont);
       
   280 
       
   281     iItemDrawer =
       
   282         new(ELeave) CAknFepUICtrlJapanesePredictiveListboxItemDrawer(
       
   283                         Model(), font, cellData);
       
   284 
       
   285     CleanupStack::Pop(cellData);
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CAknFepUICtrlJapanesePredictiveListbox::UpdateCurrentItem
       
   290 // Update the current index
       
   291 // Notes: The argument of aItemIndex means the current line. (not current candidate index)
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 void CAknFepUICtrlJapanesePredictiveListbox::UpdateCurrentItem(TInt aItemIndex) const
       
   295     {
       
   296     CAknFepUICtrlJapanesePredictiveListBoxModel* model =
       
   297         static_cast<CAknFepUICtrlJapanesePredictiveListBoxModel*>(Model());
       
   298     CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   299         static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   300 
       
   301     TPredictivePopupElement element;
       
   302     TInt curCandi = view->CurrentCandidateNo();
       
   303     TInt oldCandi = view->OldCandidateNo();
       
   304     TInt maxLine = model->LineInfoArray()->Count();
       
   305 
       
   306     TInt oldCurrentItemIndex = view->CurrentItemIndex();
       
   307     if (oldCurrentItemIndex != aItemIndex)
       
   308         {
       
   309         // Set the current line
       
   310         view->SetCurrentItemIndex(aItemIndex);
       
   311 
       
   312         if ( IsReadyToDraw() )
       
   313             {
       
   314             // Draw the old line
       
   315             view->DrawItem(oldCurrentItemIndex);
       
   316             }
       
   317 
       
   318         if (oldCurrentItemIndex+1 < maxLine
       
   319          && oldCurrentItemIndex+1 != aItemIndex)
       
   320             {
       
   321             if (model->SearchElement(oldCurrentItemIndex+1,
       
   322                                      oldCandi, element))
       
   323                 {
       
   324                 view->DrawItem(oldCurrentItemIndex+1);
       
   325                 }
       
   326             }
       
   327         // Set the top position
       
   328         if (!(view->ItemIsVisible(aItemIndex)))
       
   329             {
       
   330             SetTopItemIndex(view->CalcNewTopItemIndexSoItemIsVisible(aItemIndex));
       
   331             DrawNow();
       
   332             }
       
   333         }
       
   334     // Draw the current line
       
   335     DrawItem(aItemIndex);
       
   336     // Check next line including the same candidate
       
   337     TInt nextLine = aItemIndex+1;
       
   338     if (nextLine < maxLine
       
   339      && model->SearchElement(nextLine, curCandi, element))
       
   340         {
       
   341         if (!(view->ItemIsVisible(nextLine)))
       
   342             {
       
   343             SetTopItemIndex(view->CalcNewTopItemIndexSoItemIsVisible(nextLine));
       
   344             DrawNow();
       
   345             }
       
   346         DrawItem(nextLine);
       
   347         }
       
   348     UpdateScrollBarThumbs();
       
   349     }
       
   350 
       
   351 // -----------------------------------------------------------------------------
       
   352 // CAknFepUICtrlJapanesePredictiveListbox::HandlePointerEventL
       
   353 // (other items were commented in a header).
       
   354 // -----------------------------------------------------------------------------
       
   355 void CAknFepUICtrlJapanesePredictiveListbox::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   356     {
       
   357     const TInt old = CurrentItemIndex();
       
   358     CAknSinglePopupMenuStyleListBox::HandlePointerEventL(aPointerEvent);
       
   359     switch (aPointerEvent.iType)
       
   360         {
       
   361         case TPointerEvent::EButton1Up:
       
   362             break;
       
   363         case TPointerEvent::EButton1Down:
       
   364             {
       
   365             CAknFepUICtrlJapanesePredictiveListboxView* view =
       
   366                 static_cast<CAknFepUICtrlJapanesePredictiveListboxView*>(View());
       
   367             TInt oldCandidateNo = view->CurrentCandidateNo();
       
   368             TPoint pos = aPointerEvent.iPosition - Rect().iTl;
       
   369             TInt itemIndex = view->SetCurrentCandidateNo(CurrentItemIndex(), pos);
       
   370             SetCurrentItemIndex(itemIndex);
       
   371             TInt newCandidateNo = view->CurrentCandidateNo();
       
   372 
       
   373             if (oldCandidateNo != newCandidateNo)
       
   374                 {
       
   375                 ReportListBoxEventL(MEikListBoxObserver::EEventItemDraggingActioned);// need draw.
       
   376                 }
       
   377             }
       
   378             break;
       
   379         default:
       
   380             break;
       
   381         }
       
   382     }
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CAknFepUICtrlJapanesePredictiveListbox::HandleScrollEventL
       
   386 // (other items were commented in a header).
       
   387 // -----------------------------------------------------------------------------
       
   388 void CAknFepUICtrlJapanesePredictiveListbox::HandleScrollEventL(
       
   389                                                     CEikScrollBar* aScrollBar,
       
   390                                                     TEikScrollEvent aEventType)
       
   391     {
       
   392     TInt oldThumbPos = (aEventType & KEikScrollEventBarMask) ?
       
   393                                 iView->HScrollOffset() : iView->TopItemIndex();
       
   394     TInt newThumbPos = aScrollBar->ThumbPosition();
       
   395     TInt maxThumbPos = static_cast<CTextListBoxModel*>(Model())->NumberOfItems()
       
   396                                 - KListBoxVisibleRow;
       
   397     TBool update = ETrue;
       
   398     TInt newThumbPosBeforeCorrecting = newThumbPos;
       
   399 
       
   400     if ((aEventType & KEikScrollEventBarMask) == KEikScrollEventFromVBar)
       
   401         {
       
   402         switch (aEventType)
       
   403             {
       
   404             case EEikScrollUp:
       
   405                 if ( oldThumbPos == 0  && (iListBoxFlags & ELoopScrolling))
       
   406                     {
       
   407                     newThumbPos = maxThumbPos;
       
   408                     }
       
   409                 break;
       
   410             case EEikScrollDown:
       
   411                 if ( oldThumbPos == maxThumbPos && (iListBoxFlags & ELoopScrolling) )
       
   412                     {
       
   413                     newThumbPos = 0;
       
   414                     }
       
   415                 break;
       
   416             case EEikScrollPageUp:
       
   417             case EEikScrollPageDown:
       
   418             case EEikScrollThumbDragVert:
       
   419                 break;
       
   420             case EEikScrollThumbReleaseVert:
       
   421                 // in the case of drag events, the scrollbar automatically updates its thumb pos...
       
   422                 if(AknLayoutUtils::PenEnabled())
       
   423                     {
       
   424                     update = EFalse;
       
   425                     }
       
   426                 break;
       
   427 
       
   428             default:
       
   429                 break;
       
   430             }
       
   431         if ( (!AknLayoutUtils::PenEnabled()) || update )
       
   432             {
       
   433             iView->VScrollTo(newThumbPos);
       
   434             if (aEventType != EEikScrollThumbDragVert)
       
   435                 {
       
   436                 aScrollBar->SetModelThumbPosition(iView->TopItemIndex());
       
   437                 }
       
   438             }
       
   439 
       
   440         // if event has changed thumb position, then update scroll bar
       
   441         if ( AknLayoutUtils::PenEnabled() && newThumbPos != newThumbPosBeforeCorrecting )
       
   442             {
       
   443             UpdateScrollBarThumbs();
       
   444             }
       
   445         }
       
   446     }
       
   447 
       
   448 // End of File