diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-02-06 16:45:50 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-02-07 13:59:04 +0000 |
commit | 3f1a97eda055f49f0fa5ba84dc4a122f222cc217 (patch) | |
tree | 3309472a767a319b6516e6a00e7815542f897484 /vcl/source | |
parent | f6245d5bcb18dff2721d5975cd84711559cefe65 (diff) |
implement expandable toolbox items
Change-Id: I64ace48ed6a72cea670ac2cdd774764b7c586648
Diffstat (limited to 'vcl/source')
-rw-r--r-- | vcl/source/window/builder.cxx | 24 | ||||
-rw-r--r-- | vcl/source/window/toolbox.cxx | 61 | ||||
-rw-r--r-- | vcl/source/window/toolbox2.cxx | 28 |
3 files changed, 101 insertions, 12 deletions
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 7bf3afe2fd98..0bc7bc36066f 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -1525,6 +1525,8 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri if (!extractVisible(rMap)) pToolBox->HideItem(nItemId); + m_pParserState->m_nLastToolbarId = nItemId; + return NULL; // no widget to be created } } @@ -1917,7 +1919,7 @@ void VclBuilder::handleChild(Window *pParent, xmlreader::XmlReader &reader) } else if (name.equals("packing")) { - handlePacking(pCurrentChild, reader); + handlePacking(pCurrentChild, pParent, reader); } else ++nLevel; @@ -2639,7 +2641,7 @@ Window* VclBuilder::handleObject(Window *pParent, xmlreader::XmlReader &reader) return pCurrentChild; } -void VclBuilder::handlePacking(Window *pCurrent, xmlreader::XmlReader &reader) +void VclBuilder::handlePacking(Window *pCurrent, Window *pParent, xmlreader::XmlReader &reader) { xmlreader::Span name; int nsId; @@ -2658,7 +2660,7 @@ void VclBuilder::handlePacking(Window *pCurrent, xmlreader::XmlReader &reader) { ++nLevel; if (name.equals("property")) - applyPackingProperty(pCurrent, reader); + applyPackingProperty(pCurrent, pParent, reader); } if (res == xmlreader::XmlReader::RESULT_END) @@ -2672,15 +2674,20 @@ void VclBuilder::handlePacking(Window *pCurrent, xmlreader::XmlReader &reader) } void VclBuilder::applyPackingProperty(Window *pCurrent, + Window *pParent, xmlreader::XmlReader &reader) { if (!pCurrent) return; + ToolBox *pToolBox = NULL; + if (pCurrent == pParent) + pToolBox = dynamic_cast<ToolBox*>(pParent); + xmlreader::Span name; int nsId; - if (pCurrent->GetType() == WINDOW_SCROLLWINDOW) + if (pCurrent && pCurrent->GetType() == WINDOW_SCROLLWINDOW) { std::map<Window*, Window*>::iterator aFind = m_pParserState->m_aRedundantParentWidgets.find(pCurrent); if (aFind != m_pParserState->m_aRedundantParentWidgets.end()) @@ -2704,9 +2711,14 @@ void VclBuilder::applyPackingProperty(Window *pCurrent, if (sKey == "expand") { bool bTrue = (sValue[0] == 't' || sValue[0] == 'T' || sValue[0] == '1'); - pCurrent->set_expand(bTrue); + if (pCurrent) + pCurrent->set_expand(bTrue); + if (pToolBox) + pToolBox->SetItemExpand(m_pParserState->m_nLastToolbarId, bTrue); + continue; } - else if (sKey == "fill") + + if (sKey == "fill") { bool bTrue = (sValue[0] == 't' || sValue[0] == 'T' || sValue[0] == '1'); pCurrent->set_fill(bTrue); diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index c0361a759ae3..e2799ca0c892 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -2254,7 +2254,6 @@ static void lcl_hideDoubleSeparators( std::vector< ImplToolItem >& rItems ) void ToolBox::ImplFormat( sal_Bool bResize ) { - // Has to re-formatted if ( !mbFormat ) return; @@ -4212,14 +4211,66 @@ void ToolBox::Resize() // invalidate everything to have gradient backgrounds properly drawn Invalidate(); + // If we have any expandable entries, then force a reformat first using + // their optimal sizes, then share out the excess space evenly across those + // expandables and reformat again + std::vector<size_t> aExpandables; + for (size_t i = 0; i < mpData->m_aItems.size(); ++i) + { + if (mpData->m_aItems[i].mbExpand) + { + Window *pWindow = mpData->m_aItems[i].mpWindow; + SAL_WARN_IF(!pWindow, "vcl.layout", "only tabitems with window supported at the moment"); + if (!pWindow) + continue; + Size aWinSize(pWindow->GetSizePixel()); + Size aPrefSize(pWindow->get_preferred_size()); + aWinSize.Width() = aPrefSize.Width(); + pWindow->SetSizePixel(aWinSize); + aExpandables.push_back(i); + } + } + // re-format or re-draw - if ( mbScroll ) + if ( mbScroll || !aExpandables.empty() ) { - if ( !mbFormat ) + if ( !mbFormat || !aExpandables.empty() ) { mbFormat = true; - if( IsReallyVisible() ) - ImplFormat( sal_True ); + if( IsReallyVisible() || !aExpandables.empty() ) + { + ImplFormat(true); + + if (!aExpandables.empty()) + { + //Get how big the optimal size is + Rectangle aBounds; + for (size_t i = 0; i < mpData->m_aItems.size(); ++i) + { + aBounds.Union( mpData->m_aItems[i].maRect ); + } + + long nOptimalWidth = aBounds.GetWidth(); + long nDiff = aSize.Width() - nOptimalWidth; + nDiff /= aExpandables.size(); + + //share out the diff from optimal to real across + //expandable entries + for (size_t i = 0; i < aExpandables.size(); ++i) + { + size_t nIndex = aExpandables[i]; + Window *pWindow = mpData->m_aItems[nIndex].mpWindow; + Size aWinSize(pWindow->GetSizePixel()); + Size aPrefSize(pWindow->get_preferred_size()); + aWinSize.Width() = aPrefSize.Width() + nDiff; + pWindow->SetSizePixel(aWinSize); + } + + //now reformat with final sizes + mbFormat = true; + ImplFormat(true); + } + } } } diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index c29a4a679071..aced93fe6617 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -115,6 +115,7 @@ void ImplToolItem::init(sal_uInt16 nItemId, ToolBoxItemBits nItemBits, mnImageAngle = 0; mbMirrorMode = false; mbVisibleText = false; + mbExpand = false; } ImplToolItem::ImplToolItem() @@ -180,7 +181,8 @@ ImplToolItem::ImplToolItem( const ImplToolItem& rItem ) : mbEmptyBtn ( rItem.mbEmptyBtn ), mbShowWindow ( rItem.mbShowWindow ), mbBreak ( rItem.mbBreak ), - mbVisibleText ( rItem.mbVisibleText ) + mbVisibleText ( rItem.mbVisibleText ), + mbExpand ( rItem.mbExpand ) { } @@ -213,6 +215,7 @@ ImplToolItem& ImplToolItem::operator=( const ImplToolItem& rItem ) maMinimalItemSize = rItem.maMinimalItemSize; maItemSize = rItem.maItemSize; mbVisibleText = rItem.mbVisibleText; + mbExpand = rItem.mbExpand; meType = rItem.meType; mnBits = rItem.mnBits; meState = rItem.meState; @@ -1318,6 +1321,29 @@ ToolBoxItemBits ToolBox::GetItemBits( sal_uInt16 nItemId ) const return 0; } +void ToolBox::SetItemExpand( sal_uInt16 nItemId, bool bExpand ) +{ + ImplToolItem* pItem = ImplGetItem( nItemId ); + if (!pItem) + return; + + if (pItem->mbExpand != bExpand) + { + pItem->mbExpand = bExpand; + ImplInvalidate(true, true); + } +} + +// ----------------------------------------------------------------------- + +bool ToolBox::GetItemExpand( sal_uInt16 nItemId ) const +{ + ImplToolItem* pItem = ImplGetItem( nItemId ); + if (!pItem) + return false; + return pItem->mbExpand; +} + // ----------------------------------------------------------------------- void ToolBox::SetItemData( sal_uInt16 nItemId, void* pNewData ) |