MenubarItemWidget::MenubarItemWidget(MenubarItem *item, MenubarItemSource *source,
                                     TBSelectItemViewer *source_viewer, int index)
    : m_source(source)
    , m_source_viewer(source_viewer)
    , m_index(index)
{
    SetSkinBg(TBIDC("TBSelectItem"));
    SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
    SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
    SetPaintOverflowFadeout(false);

    TBWidget* root = GetContentRoot();

    TBFontDescription fd;
    fd.SetID(TBIDC("Vera"));
    fd.SetSize(12);

    TBTextField* text = new TBTextField();
    text->SetIgnoreInput(true);
    text->SetText(item->str);
    text->SetFontDescription(fd);
    root->AddChild(text);

    if (item->shortcut_.Length())
    {
        TBWidget* spacer = new TBWidget();
        spacer->SetIgnoreInput(true);
        spacer->SetGravity(WIDGET_GRAVITY_LEFT_RIGHT);
        root->AddChild(spacer);

        TBTextField* shortcut = new TBTextField();
        shortcut->SetIgnoreInput(true);
        shortcut->SetText(item->shortcut_.CString());
        shortcut->SetFontDescription(fd);
        shortcut->SetGravity(WIDGET_GRAVITY_RIGHT);
        root->AddChild(shortcut);
    }

}
ListViewItemWidget::ListViewItemWidget(ListViewItem *item, ListViewItemSource *source,
                                       TBSelectItemViewer *sourceviewer, int index)
    : source_(source)
    , sourceviewer_(sourceviewer)
    , index_(index)
    , item_(item)
    , expandBox_(0)
    , textField_(0)
    , icon_(0)
{
    SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
    SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
    SetPaintOverflowFadeout(false);

    item_->widget_ = this;

    for (int i = 0; i < item->depth_; i++)
    {
        LayoutParams lp;
        lp.SetWidth(6);
        lp.SetHeight(4);
        TBWidget* spacer = new TBWidget();
        spacer->SetLayoutParams(lp);
        GetContentRoot()->AddChild(spacer);
    }

    if (item_->children_.Size())
    {
        expandBox_ = new TBCheckBox();
        expandBox_->SetSkinBg(TBIDC("TBCheckBox.uilistview"));
        expandBox_->SetValue(item_->GetExpanded());
        expandBox_->SetID(item->id);
        GetContentRoot()->AddChild(expandBox_);
    }
    else
    {
        LayoutParams lp;
        lp.SetWidth(12);
        lp.SetHeight(4);
        TBWidget* spacer = new TBWidget();
        spacer->SetLayoutParams(lp);
        GetContentRoot()->AddChild(spacer);
    }

    if (item->icon_.Length())
    {
        icon_ = new TBSkinImage(TBIDC(item->icon_.CString()));
        icon_->SetIgnoreInput(true);
        GetContentRoot()->AddChild(icon_);
    }

    TBFontDescription fd;
    fd.SetID(TBIDC("Vera"));
    fd.SetSize(11);

    TBTextField* tfield = textField_ = new TBTextField();
    tfield->SetIgnoreInput(true);

    tfield->SetSkinBg(item->textSkin_.Length() ? TBIDC(item->textSkin_.CString()) : TBIDC("Folder"));
    tfield->SetText(item->str);
    tfield->SetFontDescription(fd);

    SetSkinBg(TBIDC("TBSelectItem"));
    GetContentRoot()->AddChild(tfield);

    SetID(item->id);
}