[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source
Caolán McNamara
caolanm at redhat.com
Fri Feb 7 05:59:50 PST 2014
include/vcl/builder.hxx | 10 +++++-
include/vcl/toolbox.hxx | 3 ++
vcl/inc/toolbox.h | 7 ++--
vcl/source/window/builder.cxx | 24 ++++++++++++----
vcl/source/window/toolbox.cxx | 61 +++++++++++++++++++++++++++++++++++++----
vcl/source/window/toolbox2.cxx | 28 ++++++++++++++++++
6 files changed, 116 insertions(+), 17 deletions(-)
New commits:
commit 3f1a97eda055f49f0fa5ba84dc4a122f222cc217
Author: Caolán McNamara <caolanm at redhat.com>
Date: Thu Feb 6 16:45:50 2014 +0000
implement expandable toolbox items
Change-Id: I64ace48ed6a72cea670ac2cdd774764b7c586648
diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 9424306..b545df0 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -216,6 +216,12 @@ private:
std::vector<MnemonicWidgetMap> m_aMnemonicWidgetMaps;
std::vector<VclExpander*> m_aExpanderWidgets;
+
+ sal_uInt16 m_nLastToolbarId;
+
+ ParserState()
+ : m_nLastToolbarId(0)
+ {}
};
void loadTranslations(const LanguageTag &rLanguageTag, const OUString &rUri);
@@ -340,8 +346,8 @@ private:
void handleChild(::Window *pParent, xmlreader::XmlReader &reader);
::Window* handleObject(::Window *pParent, xmlreader::XmlReader &reader);
- void handlePacking(::Window *pCurrent, xmlreader::XmlReader &reader);
- void applyPackingProperty(::Window *pCurrent, xmlreader::XmlReader &reader);
+ void handlePacking(::Window *pCurrent, ::Window *pParent, xmlreader::XmlReader &reader);
+ void applyPackingProperty(::Window *pCurrent, ::Window *pParent, xmlreader::XmlReader &reader);
void collectProperty(xmlreader::XmlReader &reader, const OString &rID, stringmap &rVec);
void collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
void collectAtkAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx
index 9c90abb..bcc444e 100644
--- a/include/vcl/toolbox.hxx
+++ b/include/vcl/toolbox.hxx
@@ -402,6 +402,9 @@ public:
void SetItemBits( sal_uInt16 nItemId, ToolBoxItemBits nBits );
ToolBoxItemBits GetItemBits( sal_uInt16 nItemId ) const;
+ void SetItemExpand( sal_uInt16 nItemId, bool bExpand );
+ bool GetItemExpand( sal_uInt16 nItemId ) const;
+
void SetItemData( sal_uInt16 nItemId, void* pNewData );
void* GetItemData( sal_uInt16 nItemId ) const;
void SetItemImage( sal_uInt16 nItemId, const Image& rImage );
diff --git a/vcl/inc/toolbox.h b/vcl/inc/toolbox.h
index d2c2d17..8ea1cb1 100644
--- a/vcl/inc/toolbox.h
+++ b/vcl/inc/toolbox.h
@@ -69,13 +69,14 @@ struct ImplToolItem
ToolBoxItemType meType;
ToolBoxItemBits mnBits;
TriState meState;
- sal_uInt16 mnId;
- sal_Bool mbEnabled:1,
+ sal_uInt16 mnId;
+ sal_Bool mbEnabled:1,
mbVisible:1,
mbEmptyBtn:1,
mbShowWindow:1,
mbBreak:1,
- mbVisibleText:1; // indicates if text will definitely be drawn, influences dropdown pos
+ mbVisibleText:1, // indicates if text will definitely be drawn, influences dropdown pos
+ mbExpand:1;
ImplToolItem();
ImplToolItem( sal_uInt16 nItemId, const Image& rImage,
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 7bf3afe..0bc7bc3 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 c0361a7..e2799ca 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 c29a4a6..aced93f 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 )
More information about the Libreoffice-commits
mailing list