summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2023-01-20 12:47:42 +0000
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2023-04-19 17:42:52 +0200
commitc38d91abf7e719e61a51798a7abddc81ba9ff9a9 (patch)
tree39360c005b47158360a4216893a1143bcbd307e0
parent36ed20e4216c618519423ed38e8ad4fbeb4ae265 (diff)
tdf#153784 account for initial vertical offset when toggled into multiline
Initially there is 1 line and the edit is vertically centered in the toolbar Later, if expanded then the vertical position of the edit will remain at that initial position, so when calculating the overall size of the expanded toolbar we have to include that initial offset in order to not make the edit overlap the RESIZE_HOTSPOT_HEIGHT area so that dragging to resize is still possible. also includes: rhbz#2162658 backtrace showing endlessly recursive ScInputWindow::Resize Change-Id: I2d10fd1ebfb1c25cf213ebb68e7d34e39fadde13 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145894 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit 13b2bd1006182637b189bcfa77acfaf03ae028f0) tdf#151682 Fix gap above input bar Remove vertical offset, looks like it's not needed anymore. Change-Id: If0f7f7dce7a7e4249036930b60fe353890b495fc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146179 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbrodt@allotropia.de> (cherry picked from commit f7544650cc4e31da67873898e2d587afa846b9b4) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146199 Reviewed-by: Kohei Yoshida <kohei@libreoffice.org> (cherry picked from commit 9739a874b64e770728d62713b070f37de4ec8328) Change-Id: Ic99e1cf4f3b1ca53c5d6feaa50d8bfac030f8124 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148069 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148075 Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
-rw-r--r--sc/source/ui/app/inputwin.cxx55
-rw-r--r--sc/source/ui/inc/inputwin.hxx11
2 files changed, 33 insertions, 33 deletions
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index db9752da05bf..0b31b816010a 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -82,6 +82,7 @@ const tools::Long LEFT_OFFSET = 5; // Left offset of input line
const tools::Long INPUTWIN_MULTILINES = 6; // Initial number of lines within multiline dropdown
const tools::Long TOOLBOX_WINDOW_HEIGHT = 22; // Height of toolbox window in pixels - TODO: The same on all systems?
const tools::Long POSITION_COMBOBOX_WIDTH = 18; // Width of position combobox in characters
+const int RESIZE_HOTSPOT_HEIGHT = 4;
using com::sun::star::uno::Reference;
using com::sun::star::uno::UNO_QUERY;
@@ -165,6 +166,7 @@ ScInputWindow::ScInputWindow( vcl::Window* pParent, const SfxBindings* pBind ) :
pInputHdl ( nullptr ),
mpViewShell ( nullptr ),
mnMaxY (0),
+ mnStandardItemHeight(0),
bIsOkCancelMode ( false ),
bInResize ( false )
{
@@ -238,6 +240,8 @@ ScInputWindow::ScInputWindow( vcl::Window* pParent, const SfxBindings* pBind ) :
HideItem( SID_INPUT_CANCEL );
HideItem( SID_INPUT_OK );
+
+ mnStandardItemHeight = GetItemRect(SID_INPUT_SUM).GetHeight();
}
SetHelpId( HID_SC_INPUTWIN ); // For the whole input row
@@ -465,31 +469,36 @@ void ScInputWindow::Resize()
{
ToolBox::Resize();
- Size aSize = GetSizePixel();
+ Size aStartSize = GetSizePixel();
+ Size aSize = aStartSize;
+ auto nLines = mxTextWindow->GetNumLines();
//(-10) to allow margin between sidebar and formulabar
tools::Long margin = (comphelper::LibreOfficeKit::isActive()) ? 10 : 0;
Size aTextWindowSize(aSize.Width() - mxTextWindow->GetPosPixel().X() - LEFT_OFFSET - margin,
- mxTextWindow->GetPixelHeightForLines());
+ mxTextWindow->GetPixelHeightForLines(nLines));
mxTextWindow->SetSizePixel(aTextWindowSize);
- aSize.setHeight(CalcWindowSizePixel().Height() + 1);
- ScInputBarGroup* pGroupBar = mxTextWindow.get();
- if (pGroupBar)
- {
- // To ensure smooth display and prevent the items in the toolbar being
- // repositioned (vertically) we lock the vertical positioning of the toolbox
- // items when we are displaying > 1 line.
- // So, we need to adjust the height of the toolbox accordingly. If we don't
- // then the largest item (e.g. the GroupBar window) will actually be
- // positioned such that the toolbar will cut off the bottom of that item
- if (pGroupBar->GetNumLines() > 1)
- {
- Size aGroupBarSize = pGroupBar->GetSizePixel();
- aSize.setHeight(aGroupBarSize.Height() + 2 * (pGroupBar->GetVertOffset() + 1));
- }
+ int nTopOffset = 0;
+ if (nLines > 1)
+ {
+ // Initially there is 1 line and the edit is vertically centered in the toolbar
+ // Later, if expanded then the vertical position of the edit will remain at
+ // that initial position, so when calculating the overall size of the expanded
+ // toolbar we have to include that initial offset in order to not make
+ // the edit overlap the RESIZE_HOTSPOT_HEIGHT area so that dragging to resize
+ // is still possible.
+ int nNormalHeight = mxTextWindow->GetPixelHeightForLines(1);
+ int nInitialTopMargin = (mnStandardItemHeight - nNormalHeight) / 2;
+ if (nInitialTopMargin > 0)
+ nTopOffset = nInitialTopMargin;
}
- SetSizePixel(aSize);
+
+ // add empty space of RESIZE_HOTSPOT_HEIGHT so resize is possible when hovering there
+ aSize.setHeight(CalcWindowSizePixel().Height() + RESIZE_HOTSPOT_HEIGHT + nTopOffset);
+
+ if (aStartSize != aSize)
+ SetSizePixel(aSize);
Invalidate();
}
@@ -712,7 +721,7 @@ void ScInputWindow::DataChanged( const DataChangedEvent& rDCEvt )
bool ScInputWindow::IsPointerAtResizePos()
{
- return GetOutputSizePixel().Height() - GetPointerPosPixel().Y() <= 4;
+ return GetOutputSizePixel().Height() - GetPointerPosPixel().Y() <= RESIZE_HOTSPOT_HEIGHT;
}
void ScInputWindow::MouseMove( const MouseEvent& rMEvt )
@@ -838,7 +847,6 @@ ScInputBarGroup::ScInputBarGroup(vcl::Window* pParent, ScTabViewShell* pViewSh)
, mxTextWndGroup(new ScTextWndGroup(*this, pViewSh))
, mxButtonUp(m_xBuilder->weld_button("up"))
, mxButtonDown(m_xBuilder->weld_button("down"))
- , mnVertOffset(0)
{
InitControlBase(m_xContainer.get());
@@ -1079,12 +1087,6 @@ void ScInputBarGroup::TriggerToolboxLayout()
ScInputWindow &rParent = dynamic_cast<ScInputWindow&>(*w);
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
- // Capture the vertical position of this window in the toolbar, when we increase
- // the size of the toolbar to accommodate expanded line input we need to take this
- // into account
- if ( !mnVertOffset )
- mnVertOffset = rParent.GetItemPosRect( rParent.GetItemCount() - 1 ).Top();
-
if ( !pViewFrm )
return;
@@ -1321,7 +1323,6 @@ const OutputDevice& ScTextWnd::GetEditViewDevice() const
int ScTextWnd::GetPixelHeightForLines(tools::Long nLines)
{
- // add padding (for the borders of the window)
OutputDevice& rDevice = GetDrawingArea()->get_ref_device();
return rDevice.LogicToPixel(Size(0, nLines * rDevice.GetTextHeight())).Height() + 1;
}
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index 12bc461f2836..e3676b6e8d9a 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -261,12 +261,11 @@ public:
void IncrementVerticalSize();
void DecrementVerticalSize();
void NumLinesChanged();
- virtual tools::Long GetNumLines() const override { return mxTextWndGroup->GetNumLines(); }
- tools::Long GetVertOffset() const { return mnVertOffset; }
+ virtual tools::Long GetNumLines() const override { return mxTextWndGroup->GetNumLines(); }
- int GetPixelHeightForLines() const
+ int GetPixelHeightForLines(tools::Long nLines) const
{
- return mxTextWndGroup->GetPixelHeightForLines(GetNumLines());
+ return mxTextWndGroup->GetPixelHeightForLines(nLines);
}
weld::Builder& GetBuilder() { return *m_xBuilder; }
@@ -278,7 +277,6 @@ private:
std::unique_ptr<ScTextWndGroup> mxTextWndGroup;
std::unique_ptr<weld::Button> mxButtonUp;
std::unique_ptr<weld::Button> mxButtonDown;
- tools::Long mnVertOffset;
DECL_LINK(ClickHdl, weld::Button&, void);
};
@@ -348,7 +346,8 @@ private:
VclPtr<ScInputBarGroup> mxTextWindow;
ScInputHandler* pInputHdl;
ScTabViewShell* mpViewShell;
- tools::Long mnMaxY;
+ tools::Long mnMaxY;
+ tools::Long mnStandardItemHeight;
bool bIsOkCancelMode;
bool bInResize;
};