textinput/peninputcommonctrlsjp/src/peninputjapanesecandidatelistbox.cpp
changeset 0 eb1f2e154e89
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Candidate List ListBox
       
    15 *
       
    16 */
       
    17 
       
    18 #include <aknlayoutscalable_avkon.cdl.h>
       
    19 #include "peninputeventjp.h"
       
    20 #include "peninputjapanesecandidatelistbox.h"
       
    21 #include "peninputjapanesecandidatecelllistboxdata.h"
       
    22 
       
    23 // const TInt KLayoutTempValue_2 = 2;   // temporary
       
    24 
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CPeninputJapaneseCandidateListbox::SetMaximumColumns
       
    28 // Set maximum columns in listbox
       
    29 // -----------------------------------------------------------------------------
       
    30 void CPeninputJapaneseCandidateListBox::SetMaximumColumns(
       
    31         const TInt aMaximumColumns)
       
    32     {
       
    33     iMaximumColumns = aMaximumColumns;
       
    34     }
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CPeninputJapaneseCandidateListBox::SetMaximumRows
       
    38 // Set maximum visible rows in listbox
       
    39 // -----------------------------------------------------------------------------
       
    40 void CPeninputJapaneseCandidateListBox::SetMaximumRows(
       
    41         const TInt aMaximumRows)
       
    42     {
       
    43     iMaximumRows = aMaximumRows;
       
    44     }
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CPeninputJapaneseCandidateListBox::HandlePointerEventL
       
    48 // (other items were commented in a header).
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 void CPeninputJapaneseCandidateListBox::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
    52     {
       
    53     const TInt old = CurrentItemIndex();
       
    54     CAknSinglePopupMenuStyleListBox::HandlePointerEventL(aPointerEvent);
       
    55     switch (aPointerEvent.iType)
       
    56         {
       
    57         case TPointerEvent::EButton1Up:
       
    58             break;
       
    59         case TPointerEvent::EButton1Down:
       
    60             {
       
    61             if (CurrentItemIndex() != old)
       
    62                 {
       
    63                 ReportListBoxEventL(MEikListBoxObserver::EEventItemDraggingActioned);// need draw.(not leave)
       
    64                 }
       
    65             }
       
    66             break;
       
    67         default:
       
    68             break;
       
    69         }
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CPeninputJapaneseCandidateListbox::MinimumSize
       
    74 // (other items were commented in a header).
       
    75 // -----------------------------------------------------------------------------
       
    76 // temporary
       
    77 TSize CPeninputJapaneseCandidateListBox::MinimumSize()
       
    78     {
       
    79     TAknTextLineLayout textLineLayout =
       
    80         AknLayoutScalable_Avkon::fep_vkb_top_text_pane_t1().LayoutLine();
       
    81     const CFont* font = AknLayoutUtils::FontFromId(textLineLayout.iFont, NULL);
       
    82     TInt width = CEikListBox::CalcWidthBasedOnRequiredItemWidth(iMaximumColumns * font->AscentInPixels()+KPENINPUT_LAYOUT_VALUE_6);
       
    83     return TSize(width, CEikListBox::CalcHeightBasedOnNumOfItems(iMaximumRows));
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CPeninputJapaneseCandidateListbox::SizeChanged
       
    88 // (other items were commented in a header).
       
    89 // -----------------------------------------------------------------------------
       
    90 void CPeninputJapaneseCandidateListBox::SizeChanged()
       
    91     {
       
    92     CEikFormattedCellListBox& listBox = *this;
       
    93     CFormattedCellListBoxItemDrawer* itemDrawer = listBox.ItemDrawer();
       
    94 
       
    95     TAknWindowLineLayout textWindowLayout =
       
    96         AknLayoutScalable_Avkon::list_single_choice_list_pane(0).LayoutLine();
       
    97 
       
    98     TAknTextLineLayout textLineLayout =
       
    99         AknLayoutScalable_Avkon::fep_vkb_top_text_pane_t1().LayoutLine();
       
   100     const CFont* font = AknLayoutUtils::FontFromId(textLineLayout.iFont, NULL);
       
   101    textWindowLayout.iH = font->AscentInPixels()+KPENINPUT_LAYOUT_VALUE_2;  // control itemheight
       
   102 
       
   103 
       
   104     AknListBoxLayouts::SetupStandardListBox(listBox);  // SetBorder(TGulBorder::ENone)
       
   105     AknListBoxLayouts::SetupStandardFormListbox(itemDrawer); // Set Standard Colors
       
   106 
       
   107     // Scroll bar : before AknListBoxLayouts::SetupListboxPos()
       
   108     TAknWindowLineLayout scrollLineLayout = AknLayoutScalable_Avkon::scroll_pane_cp30().LayoutLine();
       
   109     scrollLineLayout.il = ELayoutEmpty;
       
   110     if (Model()->NumberOfItems() <= iMaximumRows)
       
   111         {
       
   112         scrollLineLayout.iW = 0;
       
   113         }
       
   114     TRect scrollBarParent = TRect(TPoint(listBox.Rect().iTl),
       
   115                                   TSize(listBox.Rect().Width() + scrollLineLayout.iW + scrollLineLayout.ir,
       
   116                                         listBox.Rect().Height()));
       
   117     AknLayoutUtils::LayoutVerticalScrollBar(iSBFrame, scrollBarParent, scrollLineLayout);
       
   118 
       
   119     AknListBoxLayouts::SetupListboxPos(listBox, textWindowLayout);  // ItemDrawer()->SetItemCellSize()
       
   120                                                                     // Draw Scrollbar
       
   121 
       
   122     {
       
   123     TRgb color( KRgbBlack );
       
   124     // this does not modify color unless it gets a correct one
       
   125     // no real need to check errors
       
   126     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   127                               color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG10 );
       
   128     itemDrawer->SetHighlightedTextColor( color );
       
   129     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   130                                color, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG7 );
       
   131     iItemDrawer->SetTextColor( color );
       
   132     }
       
   133 
       
   134     TSize itemSize = View()->ItemSize();
       
   135 
       
   136     // setting text box size in listbox
       
   137     TInt baseline = itemSize.iHeight/2 + font->AscentInPixels() / 2;
       
   138     textLineLayout.iB = ELayoutP - baseline;  // control itemheight
       
   139     AknListBoxLayouts::SetupFormAntiFlickerTextCell(
       
   140             listBox, itemDrawer, 0, textLineLayout,
       
   141             TPoint(0, 0),
       
   142             TPoint(itemSize.iWidth, itemSize.iHeight)); // CheckColor.
       
   143 
       
   144     CEikFormattedCellListBox::SizeChanged();
       
   145     UpdateScrollBarThumbs();
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // CPeninputJapaneseCandidateListBox::CreateItemDrawerL
       
   150 // Create ItemDrawer
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 void CPeninputJapaneseCandidateListBox::CreateItemDrawerL()
       
   154     {
       
   155     CPeninputJapaneseCandidateCellListBoxData* cellData =
       
   156         CPeninputJapaneseCandidateCellListBoxData::NewL();
       
   157     CleanupStack::PushL(cellData);
       
   158 
       
   159     iItemDrawer =
       
   160         new(ELeave) CFormattedCellListBoxItemDrawer(Model(), NULL, cellData);
       
   161     CleanupStack::Pop(cellData);
       
   162     }
       
   163 
       
   164 void CPeninputJapaneseCandidateListBox::HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType)
       
   165     {
       
   166     TInt oldThumbPos = (aEventType & KEikScrollEventBarMask) ? iView->HScrollOffset() : iView->TopItemIndex();
       
   167     TInt newThumbPos = aScrollBar->ThumbPosition();
       
   168     TInt maxThumbPos = static_cast<CTextListBoxModel*>(Model())->NumberOfItems() - iMaximumRows;
       
   169     TBool update = ETrue; // for the case EEikScrollThumbRelease so that after it there is now update.
       
   170     TInt newThumbPosBeforeCorrecting = newThumbPos;
       
   171 
       
   172     switch (aEventType & KEikScrollEventBarMask)
       
   173         {
       
   174     case KEikScrollEventFromVBar:
       
   175         switch (aEventType)
       
   176             {
       
   177         case EEikScrollUp:
       
   178             if ( oldThumbPos == 0  && (iListBoxFlags & ELoopScrolling))
       
   179                 {
       
   180                 newThumbPos = maxThumbPos;              
       
   181                 }
       
   182             break;
       
   183         case EEikScrollDown:
       
   184             if ( oldThumbPos == maxThumbPos && (iListBoxFlags & ELoopScrolling) )
       
   185                 {
       
   186                 newThumbPos = 0;                
       
   187                 }
       
   188             break;
       
   189         case EEikScrollPageUp:
       
   190         case EEikScrollPageDown:
       
   191         case EEikScrollThumbDragVert:
       
   192             break;
       
   193         case EEikScrollThumbReleaseVert:
       
   194             // in the case of drag events, the scrollbar automatically updates its thumb pos...
       
   195             if(AknLayoutUtils::PenEnabled())
       
   196                 {
       
   197                 update = EFalse;
       
   198                 }
       
   199             break;
       
   200 
       
   201         default:
       
   202             break;
       
   203             }
       
   204 
       
   205         if ( (!AknLayoutUtils::PenEnabled()) || update )
       
   206             {
       
   207             iView->VScrollTo(newThumbPos);
       
   208             if (aEventType != EEikScrollThumbDragVert)
       
   209                 {
       
   210                 aScrollBar->SetModelThumbPosition(iView->TopItemIndex());
       
   211                 }
       
   212             }
       
   213 
       
   214         // if event has changed thumb position, then update scroll bar
       
   215         if ( AknLayoutUtils::PenEnabled() && newThumbPos != newThumbPosBeforeCorrecting )
       
   216             {
       
   217             UpdateScrollBarThumbs();
       
   218             }
       
   219         break;
       
   220     default:
       
   221         break;
       
   222         }
       
   223     }
       
   224 // End Of File