示例#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);
    }
}
示例#2
0
文件: contacts.cpp 项目: xubing/tts
void ContactsReader::Read() {
    app_state_.Reset();
    app_helper_.ReadTitle(&control_tree_, &app_state_);
    // return;
    const TVwsViewId view_id = app_helper_.ReadView(&control_tree_, &app_state_);
    return;
    app_helper_.ReadCba(&control_tree_, &app_state_);
    CEikMenuBar* menu = control_tree_.MenuBar();
    if (menu && menu->IsFocused()) {
        CEikMenuPane* pane = menu->MenuPane();
        app_helper_.ReadMenu(pane, &app_state_);
        if (pane) {
            return;
        }
    }
    // TODO(mikie): move tab reading to AppHelper.
    CAknTabGroup* tabgroup = control_tree_.TabGroup();
    if (tabgroup) {
        app_state_.SetSelectedTabIndex(tabgroup->ActiveTabIndex());
        app_state_.SetTabCount(tabgroup->TabCount());
        const TInt id = tabgroup->ActiveTabId();
        CAknTabGroupAccess* access = (CAknTabGroupAccess*)tabgroup;
        CArrayPtr<CAknTabAccess>* tabs = access->iTabArray;
        for (int i = 0; i < tabs->Count(); ++i) {
            CAknTabAccess* tab = tabs->At(i);
            CCoeControl* tab_control = (CCoeControl*)tab;
            if (tab && tab->iId == id) {
                // Not all tabs have text.
                CEikLabel* label = tab->iLabel;
                if (label) {
                    app_state_.SetSelectedTabText(*label->Text());
                }
                break;
            }
        }
    }
    if (view_id.iAppUid != ForApplication()) {
        return;
    }
    const TUint view = view_id.iViewUid.iUid;
    if (view == 1) {
        // Main contacts view
        CCoeControl* top = control_tree_.TopFocusedControl();
        if (top->CountComponentControls() == 0) return;
        CCoeControl* container = top->ComponentControl(0);
        if (container->CountComponentControls() < 2) return;
        CEikListBox* listbox = (CEikListBox*)container->ComponentControl(0);
        CAknSearchField* field = (CAknSearchField*)container->ComponentControl(1);

        ReadList(listbox, &app_state_);

        HBufC* text = HBufC::NewLC(field->TextLength());
        TPtr16 textp = text->Des();
        field->GetSearchText(textp);
        app_state_.SetSearchFieldText(*text);
        CleanupStack::PopAndDestroy(text);
    } else if (view == 4) {
        // Details (read-only) view
        CCoeControl* top = control_tree_.TopFocusedControl();
        if (top->CountComponentControls() == 0) return;
        CCoeControl* container = top->ComponentControl(0);
        if (container->CountComponentControls() < 1) return;
        CEikListBox* listbox = (CEikListBox*)container->ComponentControl(0);

        ReadList(listbox, &app_state_);
    }
}