split out the ComboBox code that determines the positioning of subwidgets

and re-use it to get a better calculation of the optimal size of a
widget, rather than taking the current position of the subedit

Change-Id: I85cb3ff98f23d21d7cfdcc28188e36616a19b5e8
This commit is contained in:
Caolán McNamara
2013-01-11 16:35:17 +00:00
parent 823ab0f98c
commit d19eab221f
2 changed files with 73 additions and 45 deletions

View File

@@ -50,9 +50,20 @@ private:
Link maSelectHdl;
Link maDoubleClickHdl;
struct ComboBoxBounds
{
Point aSubEditPos;
Size aSubEditSize;
Point aButtonPos;
Size aButtonSize;
};
private:
SAL_DLLPRIVATE void ImplInitComboBoxData();
SAL_DLLPRIVATE void ImplUpdateFloatSelection();
SAL_DLLPRIVATE ComboBoxBounds calcComboBoxDropDownComponentBounds(
const Size &rOutSize, const Size &rBorderOutSize) const;
DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* );
DECL_DLLPRIVATE_LINK( ImplCancelHdl, void* );

View File

@@ -597,50 +597,10 @@ void ComboBox::Resize()
Size aOutSz = GetOutputSizePixel();
if( IsDropDownBox() )
{
long nTop = 0;
long nBottom = aOutSz.Height();
Window *pBorder = GetWindow( WINDOW_BORDER );
ImplControlValue aControlValue;
Point aPoint;
Rectangle aContent, aBound;
// use the full extent of the control
Rectangle aArea( aPoint, pBorder->GetOutputSizePixel() );
if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_BUTTON_DOWN,
aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
{
// convert back from border space to local coordinates
aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) );
aContent.Move(-aPoint.X(), -aPoint.Y());
mpBtn->setPosSizePixel( aContent.Left(), nTop, aContent.getWidth(), (nBottom-nTop) );
// adjust the size of the edit field
if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_SUB_EDIT,
aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
{
// convert back from border space to local coordinates
aContent.Move(-aPoint.X(), -aPoint.Y());
// use the themes drop down size
mpSubEdit->SetPosSizePixel( aContent.TopLeft(), aContent.GetSize() );
}
else
{
// use the themes drop down size for the button
aOutSz.Width() -= aContent.getWidth();
mpSubEdit->SetSizePixel( aOutSz );
}
}
else
{
long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
nSBWidth = CalcZoom( nSBWidth );
mpSubEdit->SetPosSizePixel( Point( 0, 0 ), Size( aOutSz.Width() - nSBWidth, aOutSz.Height() ) );
mpBtn->setPosSizePixel( aOutSz.Width() - nSBWidth, nTop, nSBWidth, (nBottom-nTop) );
}
ComboBoxBounds aBounds(calcComboBoxDropDownComponentBounds(aOutSz,
GetWindow(WINDOW_BORDER)->GetOutputSizePixel()));
mpSubEdit->SetPosSizePixel(aBounds.aSubEditPos, aBounds.aSubEditSize);
mpBtn->SetPosSizePixel(aBounds.aButtonPos, aBounds.aButtonSize);
}
else
{
@@ -1106,12 +1066,15 @@ Size ComboBox::CalcMinimumSize() const
else
{
aSz.Height() = Edit::CalcMinimumSizeForText(GetText()).Height();
aSz.Width() = mpImplLB->GetMaxEntryWidth();
aSz.Width() += getMaxWidthScrollBarAndDownButton();
ComboBoxBounds aBounds(calcComboBoxDropDownComponentBounds(
Size(0xFFFF, 0xFFFF), Size(0xFFFF, 0xFFFF)));
aSz.Width() += aBounds.aSubEditPos.X()*2;
}
aSz.Width() += ImplGetExtraOffset() * 2;
aSz.Width() += mpSubEdit->GetPosPixel().X();
aSz = CalcWindowSize( aSz );
return aSz;
@@ -1529,4 +1492,58 @@ long ComboBox::GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const
return nIndex;
}
ComboBox::ComboBoxBounds ComboBox::calcComboBoxDropDownComponentBounds(const Size &rOutSz,
const Size &rBorderOutSz) const
{
ComboBoxBounds aBounds;
long nTop = 0;
long nBottom = rOutSz.Height();
Window *pBorder = GetWindow( WINDOW_BORDER );
ImplControlValue aControlValue;
Point aPoint;
Rectangle aContent, aBound;
// use the full extent of the control
Rectangle aArea( aPoint, rBorderOutSz );
if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_BUTTON_DOWN,
aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
{
// convert back from border space to local coordinates
aPoint = pBorder->ScreenToOutputPixel( OutputToScreenPixel( aPoint ) );
aContent.Move(-aPoint.X(), -aPoint.Y());
aBounds.aButtonPos = Point(aContent.Left(), nTop);
aBounds.aButtonSize = Size(aContent.getWidth(), (nBottom-nTop));
// adjust the size of the edit field
if ( GetNativeControlRegion(CTRL_COMBOBOX, PART_SUB_EDIT,
aArea, 0, aControlValue, rtl::OUString(), aBound, aContent) )
{
// convert back from border space to local coordinates
aContent.Move(-aPoint.X(), -aPoint.Y());
// use the themes drop down size
aBounds.aSubEditPos = aContent.TopLeft();
aBounds.aSubEditSize = aContent.GetSize();
}
else
{
// use the themes drop down size for the button
aBounds.aSubEditSize = Size(rOutSz.Width() - aContent.getWidth(), rOutSz.Height());
}
}
else
{
long nSBWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
nSBWidth = CalcZoom( nSBWidth );
aBounds.aSubEditSize = Size(rOutSz.Width() - nSBWidth, rOutSz.Height());
aBounds.aButtonPos = Point(rOutSz.Width() - nSBWidth, nTop);
aBounds.aButtonSize = Size(nSBWidth, (nBottom-nTop));
}
return aBounds;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */