suic::Size HeaderedContentControl::ArrangeOverride(const suic::Size& availableSize)
{
    ClearVisualChildren();
    suic::Rect finalRect(0, 0, availableSize.cx, availableSize.cy);

    if (_header)
    {
        finalRect.bottom = finalRect.top + _header->GetDesiredSize().cy;
        finalRect.left += _indent;
        finalRect.right = finalRect.left + _header->GetDesiredSize().cx;

        AddVisualChild(_header.get());
        _header->Arrange(finalRect);

        finalRect.left = 0;
        finalRect.top = finalRect.bottom;
        finalRect.bottom = availableSize.cy;
        finalRect.right = availableSize.cx;
    }

    if (_content && _content->IsVisible())
    {
        AddVisualChild(_content.get());
        _content->Arrange(finalRect);
    }

    return availableSize;
}
Beispiel #2
0
suic::Size TabControl::ArrangeOverride(const suic::Size& size)
{
    ClearVisualChildren();

    _headerPanel.ClearLogicalChildren();

    int iItems = GetItems()->GetCount();
    suic::Rect finalRect(0, 0, size.cx, size.cy);

    if (_isAverage && iItems > 0)
    {
        TabItemPtr tabItem;
        int iWid = size.cx / iItems;
        suic::Size itemSize(iWid, _headerHeight);

        for (int i = 0; i < iItems - 1; ++i)
        {
            tabItem = GetItems()->GetItem(i).get();
            tabItem->SetDesiredSize(itemSize);
        }

        tabItem = GetItems()->GetItem(iItems - 1).get();

        itemSize.cx = size.cx - iWid * (iItems - 1);
        tabItem->SetDesiredSize(itemSize);

        for (int i = 0; i < iItems; ++i)
        {
            tabItem = GetItems()->GetItem(i).get();
            _headerPanel.AddLogicalChild(tabItem.get());
        }

        finalRect.bottom = finalRect.top + _headerHeight;

        AddVisualChild(&_headerPanel);
        _headerPanel.Arrange(finalRect);

        finalRect.top = finalRect.bottom;
        finalRect.bottom = size.cy;
    }

    TabItemPtr focusTab(_focusItem);

    if (focusTab)
    {  
        if (focusTab->GetTabContent())
        {
            AddVisualChild(focusTab->GetTabContent());
            focusTab->GetTabContent()->Arrange(finalRect);
        }
    }

    return size;
}
Beispiel #3
0
suic::Size WrapPanel::ArrangeOverride(const suic::Size& size)
{
    ClearVisualChildren();

    suic::Rect rect;

    int iPerRowCount = size.cx / (_horizontalSpace + _itemWidth);
    int iRight = size.cx - GetBorderThickness().right - _horizontalSpace;
    int iBottom = size.cy - GetBorderThickness().bottom - _verticalSpace;

    if (iPerRowCount == 0)
    {
        ++iPerRowCount;
    }

    int iRowHei = iPerRowCount * (_verticalSpace + _itemHeight);
    int iRowWid = iPerRowCount * (_horizontalSpace + _itemWidth) - _horizontalSpace;

    int iRealCount = 0;

    rect.left = GetBorderThickness().left + _horizontalSpace;
    rect.top = GetBorderThickness().top + _verticalSpace;

    for (int i = 0; i < GetChildrenCount(); ++i)
    {
        suic::Element* pElem = GetChild(i);

        if (pElem->IsVisible())
        {
            ++iRealCount;

            rect.right = rect.left + _itemWidth;
            rect.bottom = rect.top + _itemHeight;

            AddVisualChild(pElem);
            pElem->Arrange(rect);

            rect.left = rect.right + _horizontalSpace;

            if (rect.right >= iRowWid)
            {
                rect.left = GetBorderThickness().left + _horizontalSpace;     
                rect.top = rect.bottom + _verticalSpace;
            }

            if (rect.bottom >= iBottom)
            {
                break;
            }
        }
    }

    return size;
}
Beispiel #4
0
void Slider::OnInitialized()
{
    __super::OnInitialized();

     AddVisualChild(_thumbBtn.get());

    _thumbBtn->SetClassName(_T("Slider.Thumb"));

    _thumbBtn->BeginInit();
    _thumbBtn->EndInit();
}
Beispiel #5
0
suic::Size ScrollViewer::ArrangeOverride(const suic::Size& availableSize)
{
    ClearVisualChildren();

    suic::ElementPtr cont(GetContent());

    if (cont)
    {
        suic::Rect rect;

        rect.right = availableSize.cx;
        rect.bottom = availableSize.cy;

        _vScroll->SetVisible(false);
        _hScroll->SetVisible(false);

        suic::Size desiredSize = cont->GetDesiredSize();

        //
        // 计算是否有滚动条
        //
        _hScroll->UpdateScrollInfo(rect.right, desiredSize.cx, false);
        _vScroll->UpdateScrollInfo(rect.bottom, desiredSize.cy, false);

        ComputeScrollBar(rect.right, rect.bottom, desiredSize.cx, desiredSize.cy);

        suic::PanelPtr lay(cont);

        if (lay)
        {
            lay->SetHorizontalOffset(_hScroll->GetScrollSize());
            lay->SetVerticalOffset(_vScroll->GetScrollSize());
        }

        rect.left += _contentOffset.x;
        rect.top += _contentOffset.y;

        if (rect.bottom > rect.top)
        {
            AddVisualChild(cont.get());
            cont->Arrange(rect);
        }
    }

    return availableSize;
}
Beispiel #6
0
void ComboBox::OnInitialized()
{
    // 
    // 调用基类进行事件分发处理
    //
    __super::OnInitialized();

    AddVisualChild(_textBox.get());
    
    suic::StylePtr style;

    _textBox->SetOwner(this);

    style = GetStyle()->GetStylePart(_textBox->GetClassName());
    _textBox->SetStyle(style);
    _textBox->DoInit();
    
    style = GetStyle()->GetStylePart(_list->GetClassName());
    _list->SetStyle(style);
    _list->DoInit();

    _list->SetMaxHeight(_downHeight);
    _textBox->Enable(IsEnabled());
    _textBox->AddHandler(suic::Element::CursorSetEvent, new suic::CursorEventHandler(this, &ComboBox::OnTextBoxCursor));
    _list->AddHandler(SelectionChangedEvent, new SelectionChangedHandler(this, &ComboBox::OnSelectionChanged));

    suic::ObjectPtr selObj = _list->SelectedItem();

    if (selObj)
    {
        _textBox->SetText(selObj->ToString());
        _list->UnselectAllItems();
    }

    _textBox->SetPadding(suic::Rect());
    _textBox->SetBorderThickness(suic::Rect());
}
Beispiel #7
0
void ItemsControl::OnInitialized()
{
    __super::OnInitialized();

    // 加入可视树
    AddVisualChild(_scrollHost.get());
    AddLogicalChild(_scrollHost.get());

    _itemsHost->WriteFlag(CoreFlags::IsComposition, true);
    _scrollHost->WriteFlag(CoreFlags::IsComposition, true);

    _scrollHost->BeginInit();
    _scrollHost->EndInit();

    _scrollHost->SetHorizontalAlignment(HoriAlignment::Stretch);
    _scrollHost->SetVerticalAlignment(VertAlignment::Stretch);

    _scrollHost->SetMargin(GetMargin());
    _scrollHost->SetFocusable(false);

    _itemsHost->SetFocusable(false);
    _itemsHost->SetPadding(GetPadding());
    SetPadding(suic::Rect());
}
Beispiel #8
0
suic::Size TreeViewItem::ArrangeOverride(const suic::Size& finalSize)
{
    // 先清除可视节点
    ClearVisualChildren();

    const int ITEMSPACE = 2;

    suic::Rect finalRect(0, 0, finalSize.cx, 0);

    // 布局扩展按钮
    if (_expand->IsVisible())
    {
        finalRect.right = finalRect.left + _expand->GetDesiredSize().cx;
        finalRect.top = (_header->GetDesiredSize().cy - _expand->GetDesiredSize().cy) / 2;
        finalRect.bottom = finalRect.top + _expand->GetDesiredSize().cy;

        AddVisualChild(_expand.get());
        _expand->Arrange(finalRect);

        finalRect.left = finalRect.right + 12;
    }

    // 布局选择按钮
    if (_check.IsVisible())
    {
        finalRect.right = finalRect.left + _check.GetDesiredSize().cx;
        finalRect.top = (_header->GetDesiredSize().cy - _check.GetDesiredSize().cy) / 2;
        finalRect.bottom = finalRect.top + _check.GetDesiredSize().cy;

        AddVisualChild(&_check);
        _check.Arrange(finalRect);

        finalRect.left = finalRect.right;
    }

    if (_icon)
    {
        // 布局图标
        suic::Rect rcIcon(_icon->GetContentBrounds());
    }

    finalRect.right = finalRect.left + _header->GetDesiredSize().cx;
    finalRect.top = 0;
    finalRect.bottom = _header->GetDesiredSize().cy;

    AddVisualChild(_header.get());
    _header->Arrange(finalRect);

    finalRect.top = finalRect.bottom;
    finalRect.left = GetIndent();

    if (!IsCollapsed())
    {
        for (int i = 0; i < GetItems()->GetCount(); ++i)
        {
            TreeViewItemPtr item(GetItems()->GetItem(i));

            finalRect.right = finalRect.left + item->GetDesiredSize().cx;
            finalRect.bottom = finalRect.top + item->GetDesiredSize().cy;

            AddVisualChild(item.get());
            item->Arrange(finalRect);

            finalRect.top = finalRect.bottom;
        }
    }

    return finalSize;
}
Beispiel #9
0
suic::Size ScrollBar::ArrangeOverride(const suic::Size& size)
{
    ClearVisualChildren();

    bool bChanged = false;
    suic::Rect finalRect;
    suic::Rect downRect;

    if (GetOrientation() == CoreFlags::Horizontal)
    {
        UpdateScrollVisual(size.cx, false);

        finalRect.bottom = _decreaseBtn.GetDesiredSize().cy;
    }
    else
    {
        UpdateScrollVisual(size.cy, false);

        finalRect.right = _decreaseBtn.GetDesiredSize().cx;
    }

    suic::Rect rcThumb;
    
    if (!_rcTrack.Empty())
    {
        suic::Point ptSelf = PointToScreen(suic::Point());

        rcThumb = _rcTrack;
        rcThumb.Offset(-ptSelf.x, -ptSelf.y);
    }
    else
    {
        rcThumb = GetScrollThumbRect(size);
    }

    if (GetOrientation() == CoreFlags::Horizontal)
    {
        if (_increaseBtn.IsVisible())
        {
            downRect.bottom = _increaseBtn.GetDesiredSize().cy;
            downRect.right = size.cx;
            downRect.left = size.cx - _increaseBtn.GetDesiredSize().cx;
        }

        /*if (size.cx < downRect.Width() + finalRect.Width())
        {
            return size;
        }*/
    }
    else
    {
        if (_increaseBtn.IsVisible())
        {
            downRect.right = _increaseBtn.GetDesiredSize().cx;
            downRect.bottom = size.cy;
            downRect.top = size.cy - _increaseBtn.GetDesiredSize().cy;
        }

        /*if (size.cy < downRect.Height() + finalRect.Height())
        {
            return size;
        }*/
    }

    if (_decreaseBtn.IsVisible())
    {
        finalRect.right = _decreaseBtn.GetDesiredSize().cx;
        finalRect.bottom = _decreaseBtn.GetDesiredSize().cy;

        AddVisualChild(&_decreaseBtn);
        _decreaseBtn.Arrange(finalRect);
    }

    if (!rcThumb.Empty())
    {
        if (GetOrientation() == CoreFlags::Horizontal)
        {
            finalRect.left = finalRect.right;
            finalRect.right = rcThumb.left;

            if (!finalRect.Empty())
            {
                AddVisualChild(&_decreasePage);
                _decreasePage.Arrange(finalRect);
            }

            finalRect.left = rcThumb.left;
            finalRect.right = rcThumb.right;
            AddVisualChild(&_thumb);
            _thumb.Arrange(finalRect);

            finalRect.left = rcThumb.right;
            finalRect.right = size.cx - downRect.Width();
            AddVisualChild(&_increasePage);
            _increasePage.Arrange(finalRect);
        }
        else
        {
            finalRect.top = finalRect.bottom;
            finalRect.bottom = rcThumb.top;

            if (!finalRect.Empty())
            {
                AddVisualChild(&_decreasePage);
                _decreasePage.Arrange(finalRect);
            }

            finalRect.top = rcThumb.top;
            finalRect.bottom = rcThumb.bottom;
            AddVisualChild(&_thumb);
            _thumb.Arrange(finalRect);

            finalRect.top = rcThumb.bottom;
            finalRect.bottom = size.cy - downRect.Height();
            AddVisualChild(&_increasePage);
            _increasePage.Arrange(finalRect);
        }
    }

    if (!downRect.Empty())
    {
        AddVisualChild(&_increaseBtn);
        _increaseBtn.Arrange(downRect);
    }    

    return size;
}
Beispiel #10
0
void ScrollViewer::ComputeScrollBar(long& cxVisual, long& cyVisual, long cxLogic, long cyLogic)
{
    if (_barVisible == eScrollBarVisibility::Hidden)
    {
        return;
    }

    // 出现水平滚动条
    if (cxLogic > cxVisual)
    {
        suic::Rect rcHorz(0, cyVisual - _hScroll->GetDesiredSize().cy, 
            cxVisual, _hScroll->GetDesiredSize().cy);

        _hScroll->SetVisible(true);

        int iVertHei = cyVisual - _hScroll->GetDesiredSize().cy;

        // 垂直滚动条出现
        if (cyLogic > iVertHei)
        {
            _vScroll->SetVisible(true);

            rcHorz.right -= _vScroll->GetDesiredSize().cx;

            suic::Rect rcVert(cxVisual - _vScroll->GetDesiredSize().cx
                , 0, _vScroll->GetDesiredSize().cx, iVertHei);

            cxVisual -= _vScroll->GetDesiredSize().cx;

            AddVisualChild(_vScroll.get());
            _vScroll->Arrange(rcVert);
        }

        // 客户区减去滚动条高度
        cyVisual -= rcHorz.Height();

        AddVisualChild(_hScroll.get());
        _hScroll->Arrange(rcHorz);
    }
    else if (cyLogic > cyVisual)
    {
        suic::Rect rcVert(cxVisual - _vScroll->GetDesiredSize().cx
            , 0, _vScroll->GetDesiredSize().cx, cyVisual);

        _vScroll->SetVisible(true);

        int iHorzWid = cxVisual - _vScroll->GetDesiredSize().cx;

        // 水平滚动条出现
        if (cxLogic > iHorzWid)
        {
            _hScroll->SetVisible(true);

            rcVert.bottom -= _hScroll->GetDesiredSize().cy;

            suic::Rect rcHorz(0, cyVisual - _hScroll->GetDesiredSize().cy
                , iHorzWid, _hScroll->GetDesiredSize().cy);

            cyVisual -= _hScroll->GetDesiredSize().cy;

            AddVisualChild(_hScroll.get());
            _hScroll->Arrange(rcHorz);
        }

        // 客户区减去滚动条高度
        cxVisual -= rcVert.Width();

        AddVisualChild(_vScroll.get());
        _vScroll->Arrange(rcVert);
    }
}