2011-11-09 22:58:42 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Caolán McNamara <caolanm@redhat.com> (Red Hat, Inc.)
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011 the
|
|
|
|
* Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Caolán McNamara <caolanm@redhat.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
|
|
|
|
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
|
|
|
|
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
|
|
|
|
* instead of those above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <vcl/layout.hxx>
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
Size VclBox::calculateRequisition() const
|
2011-11-09 22:58:42 +00:00
|
|
|
{
|
|
|
|
long nMaxChildDimension = 0;
|
|
|
|
|
|
|
|
sal_uInt16 nVisibleChildren = 0;
|
|
|
|
|
|
|
|
Size aSize;
|
|
|
|
sal_uInt16 nChildren = GetChildCount();
|
|
|
|
for (sal_uInt16 i = 0; i < nChildren; ++i)
|
|
|
|
{
|
|
|
|
Window *pChild = GetChild(i);
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
++nVisibleChildren;
|
2012-02-06 14:57:38 +01:00
|
|
|
Size aChildSize = pChild->get_preferred_size();
|
2011-11-09 22:58:42 +00:00
|
|
|
long nSecondaryDimension = getSecondaryDimension(aChildSize);
|
|
|
|
if (nSecondaryDimension > getSecondaryDimension(aSize))
|
|
|
|
setSecondaryDimension(aSize, nSecondaryDimension);
|
|
|
|
if (m_bHomogeneous)
|
|
|
|
{
|
|
|
|
long nPrimaryDimension = getPrimaryDimension(aChildSize);
|
|
|
|
if (nPrimaryDimension > nMaxChildDimension)
|
|
|
|
nMaxChildDimension = nPrimaryDimension;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long nPrimaryDimension = getPrimaryDimension(aSize);
|
|
|
|
setPrimaryDimension(aSize, nPrimaryDimension + getPrimaryDimension(aChildSize));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nVisibleChildren)
|
|
|
|
{
|
|
|
|
long nPrimaryDimension = getPrimaryDimension(aSize);
|
|
|
|
if (m_bHomogeneous)
|
2011-11-15 16:38:47 +00:00
|
|
|
nPrimaryDimension += nMaxChildDimension * nVisibleChildren;
|
2011-11-09 22:58:42 +00:00
|
|
|
setPrimaryDimension(aSize, nPrimaryDimension + m_nSpacing * (nVisibleChildren-1));
|
|
|
|
}
|
|
|
|
|
2011-11-17 22:42:33 +00:00
|
|
|
rtl::OString sBorderWidth(RTL_CONSTASCII_STRINGPARAM("border-width"));
|
|
|
|
sal_Int32 nBorderWidth = getWidgetProperty<sal_Int32>(sBorderWidth);
|
|
|
|
|
|
|
|
aSize.Width() += nBorderWidth*2;
|
|
|
|
aSize.Height() += nBorderWidth*2;
|
|
|
|
|
2011-11-09 22:58:42 +00:00
|
|
|
return aSize;
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
Size VclBox::GetOptimalSize(WindowSizeType eType) const
|
2011-11-09 22:58:42 +00:00
|
|
|
{
|
|
|
|
if (eType == WINDOWSIZE_MAXIMUM)
|
|
|
|
return Window::GetOptimalSize(eType);
|
|
|
|
return calculateRequisition();
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
void VclBox::setAllocation(const Size &rAllocation)
|
2011-11-09 22:58:42 +00:00
|
|
|
{
|
|
|
|
sal_uInt16 nChildren = GetChildCount();
|
|
|
|
if (!nChildren)
|
|
|
|
return;
|
|
|
|
|
2011-11-15 09:50:11 +00:00
|
|
|
rtl::OString sExpand(RTL_CONSTASCII_STRINGPARAM("expand"));
|
|
|
|
|
2011-11-15 16:38:47 +00:00
|
|
|
sal_uInt16 nVisibleChildren = 0, nExpandChildren = 0;
|
2011-11-09 22:58:42 +00:00
|
|
|
for (sal_uInt16 i = 0; i < nChildren; ++i)
|
|
|
|
{
|
|
|
|
Window *pChild = GetChild(i);
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
++nVisibleChildren;
|
2011-11-17 21:24:33 +00:00
|
|
|
bool bExpand = pChild->getWidgetProperty<sal_Bool>(sExpand);
|
2011-11-14 16:56:25 +00:00
|
|
|
if (bExpand)
|
2011-11-09 22:58:42 +00:00
|
|
|
++nExpandChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nVisibleChildren)
|
|
|
|
return;
|
|
|
|
|
2011-11-17 22:42:33 +00:00
|
|
|
rtl::OString sBorderWidth(RTL_CONSTASCII_STRINGPARAM("border-width"));
|
|
|
|
sal_Int32 nBorderWidth = getWidgetProperty<sal_Int32>(sBorderWidth);
|
|
|
|
|
|
|
|
Size aAllocation = rAllocation;
|
|
|
|
aAllocation.Width() -= nBorderWidth*2;
|
|
|
|
aAllocation.Height() -= nBorderWidth*2;
|
2011-11-09 22:58:42 +00:00
|
|
|
|
2011-11-17 22:42:33 +00:00
|
|
|
long nAllocPrimaryDimension = getPrimaryDimension(aAllocation);
|
2011-11-15 09:50:11 +00:00
|
|
|
|
2011-11-09 22:58:42 +00:00
|
|
|
long nHomogeneousDimension, nExtraSpace = 0;
|
|
|
|
if (m_bHomogeneous)
|
|
|
|
{
|
2011-11-15 16:38:47 +00:00
|
|
|
nHomogeneousDimension = ((nAllocPrimaryDimension -
|
|
|
|
(nVisibleChildren - 1) * m_nSpacing)) / nVisibleChildren;
|
2011-11-09 22:58:42 +00:00
|
|
|
}
|
|
|
|
else if (nExpandChildren)
|
|
|
|
{
|
|
|
|
Size aRequisition = calculateRequisition();
|
2011-11-17 22:42:33 +00:00
|
|
|
aRequisition.Width() -= nBorderWidth*2;
|
|
|
|
aRequisition.Height() -= nBorderWidth*2;
|
|
|
|
nExtraSpace = (getPrimaryDimension(aAllocation) - getPrimaryDimension(aRequisition)) / nExpandChildren;
|
2011-11-09 22:58:42 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 09:50:11 +00:00
|
|
|
rtl::OString sPadding(RTL_CONSTASCII_STRINGPARAM("padding"));
|
|
|
|
rtl::OString sPackType(RTL_CONSTASCII_STRINGPARAM("pack-type"));
|
|
|
|
rtl::OString sFill(RTL_CONSTASCII_STRINGPARAM("fill"));
|
2011-11-14 16:56:25 +00:00
|
|
|
|
2011-11-15 09:50:11 +00:00
|
|
|
for (sal_Int32 ePackType = VCL_PACK_START; ePackType <= VCL_PACK_END; ++ePackType)
|
|
|
|
{
|
2012-03-29 10:27:27 +01:00
|
|
|
Point aPos(nBorderWidth, nBorderWidth);
|
2011-11-15 09:50:11 +00:00
|
|
|
if (ePackType == VCL_PACK_END)
|
2011-11-09 22:58:42 +00:00
|
|
|
{
|
2011-11-15 09:50:11 +00:00
|
|
|
long nPrimaryCoordinate = getPrimaryCoordinate(aPos);
|
|
|
|
setPrimaryCoordinate(aPos, nPrimaryCoordinate + nAllocPrimaryDimension);
|
2011-11-09 22:58:42 +00:00
|
|
|
}
|
|
|
|
|
2011-11-15 09:50:11 +00:00
|
|
|
for (sal_uInt16 i = 0; i < nChildren; ++i)
|
2011-11-09 22:58:42 +00:00
|
|
|
{
|
2011-11-15 09:50:11 +00:00
|
|
|
Window *pChild = GetChild(i);
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
|
2011-11-17 21:24:33 +00:00
|
|
|
sal_Int32 ePacking = pChild->getWidgetProperty<sal_Int32>(sPackType);
|
2011-11-15 09:50:11 +00:00
|
|
|
|
|
|
|
if (ePacking != ePackType)
|
|
|
|
continue;
|
|
|
|
|
2011-11-17 21:24:33 +00:00
|
|
|
long nPadding = pChild->getWidgetProperty<sal_Int32>(sPadding);
|
2011-11-15 09:50:11 +00:00
|
|
|
|
|
|
|
Size aBoxSize;
|
|
|
|
if (m_bHomogeneous)
|
|
|
|
setPrimaryDimension(aBoxSize, nHomogeneousDimension);
|
|
|
|
else
|
|
|
|
{
|
2012-02-06 14:57:38 +01:00
|
|
|
aBoxSize = pChild->get_preferred_size();
|
2011-11-15 09:50:11 +00:00
|
|
|
long nPrimaryDimension = getPrimaryDimension(aBoxSize);
|
|
|
|
nPrimaryDimension += nPadding;
|
2011-11-17 21:24:33 +00:00
|
|
|
bool bExpand = pChild->getWidgetProperty<bool>(sExpand);
|
2011-11-15 09:50:11 +00:00
|
|
|
if (bExpand)
|
|
|
|
setPrimaryDimension(aBoxSize, nPrimaryDimension + nExtraSpace);
|
|
|
|
}
|
2011-11-17 22:42:33 +00:00
|
|
|
setSecondaryDimension(aBoxSize, getSecondaryDimension(aAllocation));
|
2011-11-15 09:50:11 +00:00
|
|
|
|
|
|
|
Point aChildPos(aPos);
|
|
|
|
Size aChildSize(aBoxSize);
|
|
|
|
long nPrimaryCoordinate = getPrimaryCoordinate(aPos);
|
|
|
|
|
2011-11-17 21:24:33 +00:00
|
|
|
bool bFill = pChild->getWidgetProperty<sal_Bool>(sFill, sal_True);
|
2011-11-15 09:50:11 +00:00
|
|
|
if (bFill)
|
|
|
|
{
|
|
|
|
setPrimaryDimension(aChildSize, std::max(static_cast<long>(1),
|
|
|
|
getPrimaryDimension(aBoxSize) - nPadding * 2));
|
|
|
|
|
|
|
|
setPrimaryCoordinate(aChildPos, nPrimaryCoordinate + nPadding);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setPrimaryDimension(aChildSize,
|
2012-02-06 14:57:38 +01:00
|
|
|
getPrimaryDimension(pChild->get_preferred_size()));
|
2011-11-15 09:50:11 +00:00
|
|
|
|
|
|
|
setPrimaryCoordinate(aChildPos, nPrimaryCoordinate +
|
|
|
|
(getPrimaryDimension(aBoxSize) - getPrimaryDimension(aChildSize)) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
long nDiff = getPrimaryDimension(aBoxSize) + m_nSpacing;
|
|
|
|
if (ePackType == VCL_PACK_START)
|
|
|
|
setPrimaryCoordinate(aPos, nPrimaryCoordinate + nDiff);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
setPrimaryCoordinate(aPos, nPrimaryCoordinate - nDiff);
|
|
|
|
setPrimaryCoordinate(aChildPos, getPrimaryCoordinate(aChildPos) -
|
2012-03-29 10:27:27 +01:00
|
|
|
getPrimaryDimension(aBoxSize));
|
2011-11-15 09:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pChild->SetPosSizePixel(aChildPos, aChildSize);
|
2011-11-09 22:58:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
void VclBox::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
|
2011-11-09 22:58:42 +00:00
|
|
|
{
|
|
|
|
Window::SetPosSizePixel(rAllocPos, rAllocation);
|
|
|
|
setAllocation(rAllocation);
|
|
|
|
}
|
|
|
|
|
2011-11-17 11:46:16 +00:00
|
|
|
#define DEFAULT_CHILD_INTERNAL_PAD_X 4
|
|
|
|
#define DEFAULT_CHILD_INTERNAL_PAD_Y 0
|
2011-11-17 21:24:33 +00:00
|
|
|
#define DEFAULT_CHILD_MIN_WIDTH 85
|
|
|
|
#define DEFAULT_CHILD_MIN_HEIGHT 27
|
2011-11-17 11:46:16 +00:00
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
Size VclButtonBox::calculateRequisition() const
|
2011-11-17 11:46:16 +00:00
|
|
|
{
|
2011-11-17 21:24:33 +00:00
|
|
|
sal_uInt16 nVisibleChildren = 0;
|
2011-11-17 11:46:16 +00:00
|
|
|
|
2011-11-17 21:24:33 +00:00
|
|
|
rtl::OString sChildMinWidth(RTL_CONSTASCII_STRINGPARAM("child-min-width"));
|
|
|
|
sal_Int32 nChildMinWidth = getWidgetStyleProperty<sal_Int32>(sChildMinWidth, DEFAULT_CHILD_MIN_WIDTH);
|
|
|
|
rtl::OString sChildMinHeight(RTL_CONSTASCII_STRINGPARAM("child-min-height"));
|
|
|
|
sal_Int32 nChildMinHeight = getWidgetStyleProperty<sal_Int32>(sChildMinHeight, DEFAULT_CHILD_MIN_HEIGHT);
|
|
|
|
Size aSize(nChildMinWidth, nChildMinHeight);
|
2011-11-17 11:46:16 +00:00
|
|
|
|
|
|
|
sal_uInt16 nChildren = GetChildCount();
|
|
|
|
for (sal_uInt16 i = 0; i < nChildren; ++i)
|
|
|
|
{
|
|
|
|
Window *pChild = GetChild(i);
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
2011-11-17 21:24:33 +00:00
|
|
|
++nVisibleChildren;
|
2012-02-06 14:57:38 +01:00
|
|
|
Size aChildSize = pChild->get_preferred_size();
|
2011-11-17 21:24:33 +00:00
|
|
|
if (aChildSize.Width() > aSize.Width())
|
|
|
|
aSize.Width() = aChildSize.Width();
|
|
|
|
if (aChildSize.Height() > aSize.Height())
|
|
|
|
aSize.Height() = aChildSize.Height();
|
2011-11-17 11:46:16 +00:00
|
|
|
}
|
|
|
|
|
2011-11-17 21:24:33 +00:00
|
|
|
if (!nVisibleChildren)
|
|
|
|
return Size();
|
|
|
|
|
|
|
|
rtl::OString sChildInternalPadX(RTL_CONSTASCII_STRINGPARAM("child-internal-pad-x"));
|
|
|
|
sal_Int32 nChildInternalPadX = getWidgetStyleProperty<sal_Int32>(sChildInternalPadX, DEFAULT_CHILD_INTERNAL_PAD_X);
|
|
|
|
rtl::OString sChildInternalPadY(RTL_CONSTASCII_STRINGPARAM("child-internal-pad-y"));
|
|
|
|
sal_Int32 nChildInternalPadY = getWidgetStyleProperty<sal_Int32>(sChildInternalPadY, DEFAULT_CHILD_INTERNAL_PAD_Y);
|
|
|
|
Size aChildPad(nChildInternalPadX, nChildInternalPadY);
|
|
|
|
|
|
|
|
long nPrimaryDimension =
|
|
|
|
(getPrimaryDimension(aSize) * nVisibleChildren) +
|
|
|
|
(m_nSpacing * (nVisibleChildren-1)) +
|
|
|
|
((getPrimaryDimension(aChildPad)*2) * nVisibleChildren);
|
|
|
|
setPrimaryDimension(aSize, nPrimaryDimension + m_nSpacing);
|
|
|
|
|
2011-11-17 11:46:16 +00:00
|
|
|
long nSecondaryDimension = getSecondaryDimension(aSize);
|
|
|
|
setSecondaryDimension(aSize, nSecondaryDimension + getSecondaryDimension(aChildPad)*2);
|
|
|
|
|
|
|
|
return aSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
void VclButtonBox::setAllocation(const Size &rAllocation)
|
2011-11-15 16:38:47 +00:00
|
|
|
{
|
|
|
|
sal_uInt16 nChildren = GetChildCount();
|
|
|
|
if (!nChildren)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sal_uInt16 nVisibleChildren = 0;
|
|
|
|
for (sal_uInt16 i = 0; i < nChildren; ++i)
|
|
|
|
{
|
|
|
|
Window *pChild = GetChild(i);
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
++nVisibleChildren;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nVisibleChildren)
|
|
|
|
return;
|
|
|
|
|
2011-11-17 11:46:16 +00:00
|
|
|
rtl::OString sChildInternalPadX(RTL_CONSTASCII_STRINGPARAM("child-internal-pad-x"));
|
|
|
|
sal_Int32 nChildInternalPadX = getWidgetStyleProperty<sal_Int32>(sChildInternalPadX, DEFAULT_CHILD_INTERNAL_PAD_X);
|
|
|
|
rtl::OString sChildInternalPadY(RTL_CONSTASCII_STRINGPARAM("child-internal-pad-y"));
|
|
|
|
sal_Int32 nChildInternalPadY = getWidgetStyleProperty<sal_Int32>(sChildInternalPadY, DEFAULT_CHILD_INTERNAL_PAD_Y);
|
|
|
|
Size aChildPad(nChildInternalPadX, nChildInternalPadY);
|
|
|
|
|
2011-11-15 16:38:47 +00:00
|
|
|
Size aSize = rAllocation;
|
|
|
|
|
|
|
|
long nAllocPrimaryDimension = getPrimaryDimension(rAllocation);
|
|
|
|
Size aRequisition = calculateRequisition();
|
|
|
|
long nHomogeneousDimension = ((getPrimaryDimension(aRequisition) -
|
|
|
|
(nVisibleChildren - 1) * m_nSpacing)) / nVisibleChildren;
|
|
|
|
|
2011-11-17 11:46:16 +00:00
|
|
|
nHomogeneousDimension = nHomogeneousDimension - getPrimaryDimension(aChildPad) * 2;
|
|
|
|
|
|
|
|
Point aPos(nChildInternalPadX, nChildInternalPadY);
|
2011-11-15 16:38:47 +00:00
|
|
|
long nPrimaryCoordinate = getPrimaryCoordinate(aPos);
|
|
|
|
setPrimaryCoordinate(aPos, nPrimaryCoordinate + nAllocPrimaryDimension
|
|
|
|
- getPrimaryDimension(aRequisition));
|
|
|
|
|
|
|
|
for (sal_uInt16 i = 0; i < nChildren; ++i)
|
|
|
|
{
|
|
|
|
Window *pChild = GetChild(i);
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Size aChildSize;
|
|
|
|
setSecondaryDimension(aChildSize, getSecondaryDimension(aSize));
|
|
|
|
setPrimaryDimension(aChildSize, nHomogeneousDimension);
|
|
|
|
|
|
|
|
pChild->SetPosSizePixel(aPos, aChildSize);
|
|
|
|
|
|
|
|
nPrimaryCoordinate = getPrimaryCoordinate(aPos);
|
2011-11-17 11:46:16 +00:00
|
|
|
setPrimaryCoordinate(aPos, nPrimaryCoordinate + nHomogeneousDimension + m_nSpacing +
|
|
|
|
getPrimaryDimension(aChildPad) * 2);
|
2011-11-15 16:38:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
VclGrid::array_type VclGrid::assembleGrid() const
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
array_type A;
|
|
|
|
|
|
|
|
rtl::OString sLeftAttach(RTL_CONSTASCII_STRINGPARAM("left-attach"));
|
|
|
|
rtl::OString sWidth(RTL_CONSTASCII_STRINGPARAM("width"));
|
|
|
|
rtl::OString sTopAttach(RTL_CONSTASCII_STRINGPARAM("top-attach"));
|
|
|
|
rtl::OString sHeight(RTL_CONSTASCII_STRINGPARAM("height"));
|
|
|
|
|
|
|
|
for (Window* pChild = GetWindow(WINDOW_FIRSTCHILD); pChild;
|
|
|
|
pChild = pChild->GetWindow(WINDOW_NEXT))
|
|
|
|
{
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sal_Int32 nLeftAttach = pChild->getWidgetProperty<sal_Int32>(sLeftAttach);
|
|
|
|
sal_Int32 nWidth = pChild->getWidgetProperty<sal_Int32>(sWidth, 1);
|
|
|
|
sal_Int32 nMaxXPos = nLeftAttach+nWidth-1;
|
|
|
|
|
|
|
|
sal_Int32 nTopAttach = pChild->getWidgetProperty<sal_Int32>(sTopAttach);
|
|
|
|
sal_Int32 nHeight = pChild->getWidgetProperty<sal_Int32>(sHeight, 1);
|
|
|
|
sal_Int32 nMaxYPos = nTopAttach+nHeight-1;
|
|
|
|
|
|
|
|
sal_Int32 nCurrentMaxXPos = A.shape()[0]-1;
|
|
|
|
sal_Int32 nCurrentMaxYPos = A.shape()[1]-1;
|
|
|
|
if (nMaxXPos > nCurrentMaxXPos || nMaxYPos > nCurrentMaxYPos)
|
|
|
|
{
|
|
|
|
nCurrentMaxXPos = std::max(nMaxXPos, nCurrentMaxXPos);
|
|
|
|
nCurrentMaxYPos = std::max(nMaxYPos, nCurrentMaxYPos);
|
|
|
|
A.resize(boost::extents[nCurrentMaxXPos+1][nCurrentMaxYPos+1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
A[nLeftAttach][nTopAttach] = pChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
return A;
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
bool VclGrid::isNullGrid(const array_type &A) const
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
sal_Int32 nMaxX = A.shape()[0];
|
|
|
|
sal_Int32 nMaxY = A.shape()[1];
|
|
|
|
|
|
|
|
if (!nMaxX || !nMaxY)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
void VclGrid::calcMaxs(const array_type &A, std::vector<long> &rWidths, std::vector<long> &rHeights) const
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
sal_Int32 nMaxX = A.shape()[0];
|
|
|
|
sal_Int32 nMaxY = A.shape()[1];
|
|
|
|
|
|
|
|
rWidths.resize(nMaxX);
|
|
|
|
rHeights.resize(nMaxY);
|
|
|
|
|
2012-02-01 10:49:43 +00:00
|
|
|
rtl::OString sWidth(RTL_CONSTASCII_STRINGPARAM("width"));
|
|
|
|
rtl::OString sHeight(RTL_CONSTASCII_STRINGPARAM("height"));
|
|
|
|
|
2012-02-01 10:12:42 +00:00
|
|
|
for (sal_Int32 x = 0; x < nMaxX; ++x)
|
|
|
|
{
|
|
|
|
for (sal_Int32 y = 0; y < nMaxY; ++y)
|
|
|
|
{
|
|
|
|
const Window *pChild = A[x][y];
|
|
|
|
if (!pChild)
|
|
|
|
continue;
|
2012-02-06 14:57:38 +01:00
|
|
|
Size aChildSize = pChild->get_preferred_size();
|
2012-02-01 10:49:43 +00:00
|
|
|
|
|
|
|
sal_Int32 nWidth = pChild->getWidgetProperty<sal_Int32>(sWidth, 1);
|
|
|
|
for (sal_Int32 nSpanX = 0; nSpanX < nWidth; ++nSpanX)
|
|
|
|
rWidths[x+nSpanX] = std::max(rWidths[x+nSpanX], aChildSize.Width()/nWidth);
|
|
|
|
|
|
|
|
sal_Int32 nHeight = pChild->getWidgetProperty<sal_Int32>(sHeight, 1);
|
|
|
|
for (sal_Int32 nSpanY = 0; nSpanY < nHeight; ++nSpanY)
|
|
|
|
rHeights[y+nSpanY] = std::max(rHeights[y+nSpanY], aChildSize.Height()/nHeight);
|
2012-02-01 10:12:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
Size VclGrid::GetOptimalSize(WindowSizeType eType) const
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
if (eType == WINDOWSIZE_MAXIMUM)
|
|
|
|
return Window::GetOptimalSize(eType);
|
|
|
|
return calculateRequisition();
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
Size VclGrid::calculateRequisition() const
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
array_type A = assembleGrid();
|
|
|
|
|
|
|
|
if (isNullGrid(A))
|
|
|
|
return Size();
|
|
|
|
|
|
|
|
std::vector<long> aWidths;
|
|
|
|
std::vector<long> aHeights;
|
|
|
|
calcMaxs(A, aWidths, aHeights);
|
|
|
|
|
|
|
|
long nTotalWidth = 0;
|
|
|
|
if (get_column_homogeneous())
|
|
|
|
{
|
|
|
|
nTotalWidth = *std::max_element(aWidths.begin(), aWidths.end());
|
|
|
|
nTotalWidth *= aWidths.size();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nTotalWidth = std::accumulate(aWidths.begin(), aWidths.end(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nTotalWidth += get_column_spacing() * (aWidths.size()-1);
|
|
|
|
|
|
|
|
long nTotalHeight = 0;
|
|
|
|
if (get_row_homogeneous())
|
|
|
|
{
|
|
|
|
nTotalHeight = *std::max_element(aHeights.begin(), aHeights.end());
|
|
|
|
nTotalHeight *= aHeights.size();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nTotalHeight = std::accumulate(aHeights.begin(), aHeights.end(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
nTotalHeight += get_row_spacing() * (aHeights.size()-1);
|
|
|
|
|
|
|
|
return Size(nTotalWidth, nTotalHeight);
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
void VclGrid::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
Window::SetPosSizePixel(rAllocPos, rAllocation);
|
|
|
|
setAllocation(rAllocation);
|
|
|
|
}
|
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
void VclGrid::setAllocation(const Size& rAllocation)
|
2012-02-01 10:12:42 +00:00
|
|
|
{
|
|
|
|
array_type A = assembleGrid();
|
|
|
|
|
|
|
|
if (isNullGrid(A))
|
|
|
|
return;
|
|
|
|
|
|
|
|
sal_Int32 nMaxX = A.shape()[0];
|
|
|
|
sal_Int32 nMaxY = A.shape()[1];
|
|
|
|
|
|
|
|
Size aRequisition;
|
|
|
|
std::vector<long> aWidths(nMaxX);
|
|
|
|
std::vector<long> aHeights(nMaxY);
|
|
|
|
if (!get_column_homogeneous() || !get_row_homogeneous())
|
|
|
|
{
|
|
|
|
aRequisition = calculateRequisition();
|
|
|
|
calcMaxs(A, aWidths, aHeights);
|
|
|
|
}
|
|
|
|
|
|
|
|
long nAvailableWidth = rAllocation.Width() - (get_column_spacing() * nMaxX);
|
|
|
|
if (get_column_homogeneous())
|
|
|
|
std::fill(aWidths.begin(), aWidths.end(), nAvailableWidth/nMaxX);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long nExtraWidth = (rAllocation.Width() - aRequisition.Width()) / nMaxX;
|
|
|
|
for (sal_Int32 x = 0; x < nMaxX; ++x)
|
|
|
|
aWidths[x] += nExtraWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
long nAvailableHeight = rAllocation.Height() - (get_row_spacing() * nMaxY);
|
|
|
|
if (get_row_homogeneous())
|
|
|
|
std::fill(aHeights.begin(), aHeights.end(), nAvailableHeight/nMaxY);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
long nExtraHeight = (rAllocation.Height() - aRequisition.Height()) / nMaxY;
|
|
|
|
for (sal_Int32 y = 0; y < nMaxY; ++y)
|
|
|
|
aHeights[y] += nExtraHeight;
|
|
|
|
}
|
|
|
|
|
2012-02-01 10:49:43 +00:00
|
|
|
rtl::OString sWidth(RTL_CONSTASCII_STRINGPARAM("width"));
|
|
|
|
rtl::OString sHeight(RTL_CONSTASCII_STRINGPARAM("height"));
|
|
|
|
|
2012-02-01 10:12:42 +00:00
|
|
|
Point aPosition(0, 0);
|
|
|
|
for (sal_Int32 x = 0; x < nMaxX; ++x)
|
|
|
|
{
|
|
|
|
for (sal_Int32 y = 0; y < nMaxY; ++y)
|
|
|
|
{
|
|
|
|
Window *pChild = A[x][y];
|
|
|
|
if (pChild)
|
2012-02-01 10:49:43 +00:00
|
|
|
{
|
|
|
|
sal_Int32 nWidth = pChild->getWidgetProperty<sal_Int32>(sWidth, 1);
|
|
|
|
sal_Int32 nHeight = pChild->getWidgetProperty<sal_Int32>(sHeight, 1);
|
|
|
|
pChild->SetPosSizePixel(aPosition, Size(aWidths[x]*nWidth, aHeights[y]*nHeight));
|
|
|
|
}
|
2012-02-01 10:12:42 +00:00
|
|
|
aPosition.Y() += aHeights[y] + get_row_spacing();
|
|
|
|
}
|
|
|
|
aPosition.X() += aWidths[x] + get_column_spacing();
|
|
|
|
aPosition.Y() = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-06 19:30:22 +00:00
|
|
|
void setGridAttach(Window &rWidget, sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nWidth, sal_Int32 nHeight)
|
|
|
|
{
|
|
|
|
rtl::OString sLeftAttach(RTL_CONSTASCII_STRINGPARAM("left-attach"));
|
|
|
|
rWidget.setChildProperty<sal_Int32>(sLeftAttach, nLeft);
|
|
|
|
rtl::OString sTopAttach(RTL_CONSTASCII_STRINGPARAM("top-attach"));
|
|
|
|
rWidget.setChildProperty<sal_Int32>(sTopAttach, nTop);
|
|
|
|
rtl::OString sWidth(RTL_CONSTASCII_STRINGPARAM("width"));
|
|
|
|
rWidget.setChildProperty<sal_Int32>(sWidth, nWidth);
|
|
|
|
rtl::OString sHeight(RTL_CONSTASCII_STRINGPARAM("height"));
|
|
|
|
rWidget.setChildProperty<sal_Int32>(sHeight, nHeight);
|
|
|
|
}
|
|
|
|
|
2011-12-01 11:49:36 +00:00
|
|
|
Size getLegacyBestSizeForChildren(const Window &rWindow)
|
|
|
|
{
|
|
|
|
Rectangle aBounds;
|
|
|
|
|
|
|
|
for (Window* pChild = rWindow.GetWindow(WINDOW_FIRSTCHILD); pChild;
|
|
|
|
pChild = pChild->GetWindow(WINDOW_NEXT))
|
|
|
|
{
|
|
|
|
if (!pChild->IsVisible())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Rectangle aChildBounds(pChild->GetPosPixel(), pChild->GetSizePixel());
|
|
|
|
aBounds.Union(aChildBounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aBounds.IsEmpty())
|
|
|
|
return rWindow.GetSizePixel();
|
|
|
|
|
|
|
|
Size aRet(aBounds.GetSize());
|
|
|
|
Point aTopLeft(aBounds.TopLeft());
|
|
|
|
aRet.Width() += aTopLeft.X()*2;
|
|
|
|
aRet.Height() += aTopLeft.Y()*2;
|
|
|
|
|
|
|
|
return aRet;
|
|
|
|
}
|
2011-11-15 16:38:47 +00:00
|
|
|
|
2012-03-21 11:26:30 +00:00
|
|
|
Window* getLegacyNonLayoutParent(Window *pParent)
|
|
|
|
{
|
|
|
|
while (pParent && dynamic_cast<const VclContainer*>(pParent))
|
|
|
|
{
|
|
|
|
pParent = pParent->GetParent();
|
|
|
|
}
|
|
|
|
return pParent;
|
|
|
|
}
|
|
|
|
|
2011-11-09 22:58:42 +00:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|