tdf#136905 NBB: let ValueSetWithTextControl set optimal height

There was no way to specify a "good font size" to use
for .uno:AttributePageSize in the notebookbar.
The font "resized to match to size of the box"
which is hard-coded to aSize(250, 300).

(Even if ValueSet::SetOptimalSize worked, it would set an
inadequate height.)

So it seems like the best thing to do is simply add a function
that allows the box height to be modified.

Using the fontsize from GetDefaultFont is not correct.
Use the OS-defined label font size instead, which seems to be
the most common choice - GetPushButtonFont would has also worked.

I verified that the label font size is controled by
the OS' font preference.

The ability to define the box's optimal height
is still (somewhat) necessary. It isn't good enough
to just "use the system font size".
I tested with an OS font size of 48 (instead of 11),
and in that case the box height was too small
(but with the font only using 4/9's of a 12pt space,
even a 24pt font looked OK without adjusting optimal height).

Change-Id: I0a0774dea9c2a6c21a8e84439318a94f39783413
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154286
Tested-by: Jenkins
Reviewed-by: Justin Luth <jluth@mail.com>
This commit is contained in:
Justin Luth 2023-07-10 15:27:29 -04:00
parent ef1484c731
commit 1876feb8a8
3 changed files with 11 additions and 0 deletions

View file

@ -40,6 +40,7 @@ public:
SVX_DLLPRIVATE virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
void SetOptimalDrawingAreaHeight();
void AddItem(const OUString& rItemText, const OUString& rItemText2);
SVX_DLLPRIVATE virtual void UserDraw(const UserDrawEvent& rUDEvt) override;

View file

@ -43,6 +43,15 @@ void ValueSetWithTextControl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
SetColCount();
}
void ValueSetWithTextControl::SetOptimalDrawingAreaHeight()
{
const vcl::Font aFont(Application::GetSettings().GetStyleSettings().GetLabelFont());
const sal_Int32 nRowHeight = aFont.GetFontSize().Height() * 9 / 4; // see UserDraw()
const Size aSize(GetOutputSizePixel().Width(), nRowHeight * maItems.size());
GetDrawingArea()->set_size_request(aSize.Width(), aSize.Height());
SetOutputSizePixel(aSize);
}
void ValueSetWithTextControl::AddItem(
const OUString& rItemText,
const OUString& rItemText2 )

View file

@ -165,6 +165,7 @@ PageSizeControl::PageSizeControl(PageSizePopup* pControl, weld::Widget* pParent)
}
mxSizeValueSet->SetNoSelection();
mxSizeValueSet->SetSelectHdl( LINK(this, PageSizeControl, ImplSizeHdl ) );
mxSizeValueSet->SetOptimalDrawingAreaHeight();
mxSizeValueSet->Show();
mxSizeValueSet->Resize();