diff options
author | Caolán McNamara <caolanm@redhat.com> | 2013-01-11 16:35:17 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-01-11 19:42:51 +0000 |
commit | d19eab221f168aed12249ffc8a36a9f1aca5a94e (patch) | |
tree | 713c9d392df3dc69f8b24003572e29f018a1ad90 /vcl | |
parent | 823ab0f98c81e68847b7a0e0667329c679b37f6c (diff) |
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
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/vcl/combobox.hxx | 11 | ||||
-rw-r--r-- | vcl/source/control/combobox.cxx | 107 |
2 files changed, 73 insertions, 45 deletions
diff --git a/vcl/inc/vcl/combobox.hxx b/vcl/inc/vcl/combobox.hxx index d1704dcc9efe..72478c59a713 100644 --- a/vcl/inc/vcl/combobox.hxx +++ b/vcl/inc/vcl/combobox.hxx @@ -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* ); diff --git a/vcl/source/control/combobox.cxx b/vcl/source/control/combobox.cxx index a0f8982e9ec6..389929c34b53 100644 --- a/vcl/source/control/combobox.cxx +++ b/vcl/source/control/combobox.cxx @@ -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: */ |