示例#1
0
void CMainMenuListContainer::SizeChanged()
{
    CCoeControl::SizeChanged();

    if(iBgContext) {
        iBgContext->SetRect(Rect());
        if (&Window()) {
            iBgContext->SetParentPos(PositionRelativeToScreen());
        }
    }

    CCoeControlArray::TCursor cursor = Components().Find(ETitleLabel);
    CEikLabel* label = cursor.Control<CEikLabel>();
    const TDesC* titleText = label->Text();
    TRect rect = Rect();
    CFont* titleFont = FindLargestPossibleFontL(*titleText, rect.Width(), EAknLogicalFontPrimaryFont);
    label->SetFont(titleFont);
    CEikonEnv::Static()->ScreenDevice()->ReleaseFont(titleFont);

    // Set the size of the label, need to think of the descent as well.
    TSize size = label->MinimumSize();
    size.iWidth = rect.Width();
    TInt descent = label->Font()->DescentInPixels();
    size.iHeight += descent;

    // Set the pos for the listbox, use the height for the label when doing this.
    // Also add the descent in pixels to get some space between the label and the
    // listbox.
    rect.iTl.iY = descent;
    TPoint pos(0, descent);
    label->SetExtent(rect.iTl, size);
    rect.iTl.iY += size.iHeight;

    // As default display both rows and hide the scrollbars
    HideSecondRow(EFalse);
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
            CEikScrollBarFrame::EOff);

    // Need to set the rect to get the listbox to update its values
    iListBox->SetRect(rect);
    TInt listBoxHeight = iListBox->ItemHeight() * iListBox->Model()->NumberOfItems();

    if (listBoxHeight > rect.Height()) {
        // The listbox is to large to fint, hide the row and check again.
        HideSecondRow(ETrue);
        iListBox->SetRect(rect);
        listBoxHeight = iListBox->ItemHeight() * iListBox->Model()->NumberOfItems();
        if (listBoxHeight > rect.Height()) {
            // Show scroll bar only if the height of the listbox is larger then
            // the rect.
            iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,
                    CEikScrollBarFrame::EOn);
            iListBox->UpdateScrollBarsL();
        }
    }
    else {
        // Setting the first item gets the list box positioned correctly on the screen
        iListBox->ScrollToMakeItemVisible(0);
    }
}
void 
CPreviewPopUpContent::SetAvailableWidth(TInt aWidth, TInt aPadding, 
                                        CPreviewPopUpContent::TContentLayout aLayout,
                                        TInt aHeight)
{
   iLayout = aLayout;

   TInt numLabels = iLabelContainer.Count();
   if (numLabels == 0) {
      return;
   }
   
   // The large font header label.
   CEikLabel* labelLa = iLabelContainer[0].iLabel;
   // The small font text label.
   CEikLabel* labelSm = iLabelContainer[1].iLabel;

   // Font height in pixels
   TInt fontHeightLa = labelLa->Font()->HeightInPixels();
   // Font descent in pixels
   TInt descentLa = labelLa->Font()->DescentInPixels();
   // The height of one label
   TInt labelHeightLa = fontHeightLa + descentLa;
   // Font height in pixels
   TInt fontHeightSm = labelSm->Font()->HeightInPixels();
   // Font descent in pixels
   TInt descentSm = labelSm->Font()->DescentInPixels();
   // The height of one label
   TInt labelHeightSm = fontHeightSm + descentSm;

   // totLabelsHeight will hold the total height of all labels that 
   // will be drawn (one large font and the rest small fonts).
   // We additionaly remove a descent on the last line since that 
   // it seems otherwise we're over compensating.
   TInt totLabelsHeight = 
      labelHeightLa + labelHeightSm * (numLabels - 1); // - descentSm;

   // Calculate the image size.
   // This calc will give us the height of two label rows.
   iIconSize = fontHeightLa + fontHeightSm + descentLa;
   TInt iconSize = iIconSize;
   TInt padding = aPadding;
   if (iBitmap) {
      AknIconUtils::SetSize(iBitmap, TSize(iconSize, iconSize), 
                            EAspectRatioPreservedAndUnusedSpaceRemoved);
      iconSize = iBitmap->SizeInPixels().iWidth;
   } else {
      // We have no bitmap set so dont indent the text around the bitmap.
      iconSize = 0;
      padding = 0;
   }

   // controlRect will contain the rect for our control to draw in, 
   // including padding.
   TRect controlRect;
   if (iLayout == EFourLinesIndentedTextImageTopLeft) {
      if (aHeight > 0) {
         controlRect = TRect(TPoint(aPadding, aPadding), 
                             TSize(aWidth, aHeight));
      } else {
         controlRect = TRect(TPoint(aPadding, aPadding), 
                             TSize(aWidth, totLabelsHeight + aPadding));
      }
   } else if (iLayout == EFourLinesTextImageTopLeftAbove) {
      if (aHeight > 0) {
         controlRect = TRect(TPoint(aPadding, aPadding), 
                             TSize(aWidth, aHeight));
      } else {
         controlRect = TRect(TPoint(aPadding, aPadding), 
                             TSize(aWidth, 
                                   totLabelsHeight + iconSize + descentLa + aPadding));
      }
   }

   // iComponentRect will contain the drawing area for our controls 
   // (image and labels).
   iComponentRect = controlRect;
   iComponentRect.Shrink(aPadding, aPadding);

   // Calculate where the text should wrap and
   // calculate the positions and rects for the labels in the control.
   TRect labelRectLa;
   TRect labelRectSm;
   if (iLayout == EFourLinesIndentedTextImageTopLeft) {
      // The first line will bew positioned next to the image and 
      // therefore the width will be a bit shorter.
      iStringLengths->At(0) = (iComponentRect.Width() - (iconSize + padding));
      // The width of the last line should not be wrapped but rather set to 
      // cropped later on.
      iStringLengths->At(1) = (iComponentRect.Width() + 10000);

      // The rect for the first label in the layout mode.
      labelRectLa = TRect(TPoint(iComponentRect.iTl.iX + iconSize + padding, 
                               iComponentRect.iTl.iY),
                          TSize(iComponentRect.Width() - (iconSize + padding), 
                                labelHeightLa));
      // The rect for the labels with small font as well.
      labelRectSm = TRect(TPoint(iComponentRect.iTl.iX + iconSize + padding, 
                               iComponentRect.iTl.iY),
                          TSize(iComponentRect.Width() - (iconSize + padding), 
                                labelHeightLa));
   } else if (iLayout == EFourLinesTextImageTopLeftAbove) {
      // We can use the full length of the container.
      iStringLengths->At(0) = iComponentRect.Width();
      // The width of the last line should not be wrapped but rather set to 
      // cropped later on.
      iStringLengths->At(1) = (iComponentRect.Width() + 10000);

      // The rect for the first label in the layout mode.
      labelRectLa = TRect(TPoint(iComponentRect.iTl.iX, 
                               iComponentRect.iTl.iY + iconSize + descentLa),
                          TSize(iComponentRect.Width(), 
                                labelHeightLa));
      // The rect for the labels with small font as well.
      labelRectSm = TRect(TPoint(iComponentRect.iTl.iX, 
                               iComponentRect.iTl.iY + iconSize + descentLa),
                          TSize(iComponentRect.Width(), 
                                labelHeightLa));
   }

   iLabelContainer[0].SetRect(labelRectLa);
   
   labelRectSm.Move(0, labelHeightLa);
   iLabelContainer[1].SetRect(labelRectSm);

//    if (iLayout == EFourLinesIndentedTextImageTopLeft) {
//       // We need to move back the third label in this layout mode.
//       labelRect.iTl.iX -= (iconSize + padding);
//    }
   labelRectSm.Move(0, labelHeightSm);
   iLabelContainer[2].SetRect(labelRectSm);

   labelRectSm.Move(0, labelHeightSm);
   iLabelContainer[3].SetRect(labelRectSm);
   
   SetRect(controlRect);
}