support max-width-chars property for labels
Change-Id: I23245919c5180035fedb308fb5cc97bf3238ec07
This commit is contained in:
parent
34638df699
commit
cd5d41470d
@ -44,6 +44,8 @@ class UserDrawEvent;
|
||||
class VCL_DLLPUBLIC FixedText : public Control
|
||||
{
|
||||
private:
|
||||
sal_Int32 m_nMaxWidthChars;
|
||||
|
||||
using Control::ImplInitSettings;
|
||||
using Window::ImplInit;
|
||||
SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle );
|
||||
@ -71,10 +73,14 @@ public:
|
||||
virtual void StateChanged( StateChangedType nType );
|
||||
virtual void DataChanged( const DataChangedEvent& rDCEvt );
|
||||
|
||||
static Size CalcMinimumTextSize( Control const* pControl, long nMaxWidth = 0 );
|
||||
Size CalcMinimumSize( long nMaxWidth = 0 ) const;
|
||||
void setMaxWidthChars(sal_Int32 nWidth);
|
||||
sal_Int32 getMaxWidthChars() const { return m_nMaxWidthChars; }
|
||||
static Size CalcMinimumTextSize(Control const* pControl, long nMaxWidth = 0x7fffffff);
|
||||
static Size getTextDimensions(Control const *pControl, const OUString &rTxt, long nMaxWidth);
|
||||
Size CalcMinimumSize(long nMaxWidth = 0x7fffffff) const;
|
||||
virtual Size GetOptimalSize(WindowSizeType eType) const;
|
||||
virtual void take_properties(Window &rOther);
|
||||
virtual bool set_property(const rtl::OString &rKey, const rtl::OString &rValue);
|
||||
};
|
||||
|
||||
// -------------
|
||||
|
@ -1748,7 +1748,7 @@ Size PushButton::GetOptimalSize(WindowSizeType eType) const
|
||||
|
||||
bool PushButton::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
|
||||
{
|
||||
if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("has-default")))
|
||||
if (rKey == "has-default")
|
||||
{
|
||||
WinBits nBits = GetStyle();
|
||||
nBits &= ~(WB_DEFBUTTON);
|
||||
@ -2912,7 +2912,7 @@ void RadioButton::SetState( sal_Bool bCheck )
|
||||
|
||||
bool RadioButton::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
|
||||
{
|
||||
if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("active")))
|
||||
if (rKey == "active")
|
||||
SetState(toBool(rValue));
|
||||
else
|
||||
return Window::set_property(rKey, rValue);
|
||||
@ -3885,7 +3885,7 @@ void CheckBox::SetState( TriState eState )
|
||||
|
||||
bool CheckBox::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
|
||||
{
|
||||
if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("active")))
|
||||
if (rKey == "active")
|
||||
SetState(toBool(rValue) ? STATE_CHECK : STATE_NOCHECK);
|
||||
else
|
||||
return Window::set_property(rKey, rValue);
|
||||
|
@ -154,16 +154,18 @@ void FixedText::ImplInitSettings( sal_Bool bFont,
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
FixedText::FixedText( Window* pParent, WinBits nStyle ) :
|
||||
Control( WINDOW_FIXEDTEXT )
|
||||
FixedText::FixedText( Window* pParent, WinBits nStyle )
|
||||
: Control(WINDOW_FIXEDTEXT)
|
||||
, m_nMaxWidthChars(-1)
|
||||
{
|
||||
ImplInit( pParent, nStyle );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
FixedText::FixedText( Window* pParent, const ResId& rResId ) :
|
||||
Control( WINDOW_FIXEDTEXT )
|
||||
FixedText::FixedText( Window* pParent, const ResId& rResId )
|
||||
: Control(WINDOW_FIXEDTEXT)
|
||||
, m_nMaxWidthChars(-1)
|
||||
{
|
||||
rResId.SetRT( RSC_TEXT );
|
||||
WinBits nStyle = ImplInitRes( rResId );
|
||||
@ -188,8 +190,9 @@ void FixedText::take_properties(Window &rOther)
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
FixedText::FixedText( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabelForRelation ) :
|
||||
Control( WINDOW_FIXEDTEXT )
|
||||
FixedText::FixedText( Window* pParent, const ResId& rResId, bool bDisableAccessibleLabelForRelation )
|
||||
: Control( WINDOW_FIXEDTEXT )
|
||||
, m_nMaxWidthChars(-1)
|
||||
{
|
||||
rResId.SetRT( RSC_TEXT );
|
||||
WinBits nStyle = ImplInitRes( rResId );
|
||||
@ -397,14 +400,20 @@ void FixedText::DataChanged( const DataChangedEvent& rDCEvt )
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
Size FixedText::CalcMinimumTextSize( Control const *pControl, long nMaxWidth )
|
||||
Size FixedText::getTextDimensions(Control const *pControl, const OUString &rTxt, long nMaxWidth)
|
||||
{
|
||||
sal_uInt16 nStyle = ImplGetTextStyle( pControl->GetStyle() );
|
||||
if ( !( pControl->GetStyle() & WB_NOLABEL ) )
|
||||
nStyle |= TEXT_DRAW_MNEMONIC;
|
||||
|
||||
Size aSize = pControl->GetTextRect( Rectangle( Point(), Size( (nMaxWidth ? nMaxWidth : 0x7fffffff), 0x7fffffff ) ),
|
||||
pControl->GetText(), nStyle ).GetSize();
|
||||
return pControl->GetTextRect(Rectangle( Point(), Size(nMaxWidth, 0x7fffffff)),
|
||||
rTxt, nStyle).GetSize();
|
||||
}
|
||||
|
||||
|
||||
Size FixedText::CalcMinimumTextSize( Control const *pControl, long nMaxWidth )
|
||||
{
|
||||
Size aSize = getTextDimensions(pControl, pControl->GetText(), nMaxWidth);
|
||||
|
||||
if ( pControl->GetStyle() & WB_EXTRAOFFSET )
|
||||
aSize.Width() += 2;
|
||||
@ -426,22 +435,48 @@ Size FixedText::CalcMinimumSize( long nMaxWidth ) const
|
||||
|
||||
Size FixedText::GetOptimalSize(WindowSizeType eType) const
|
||||
{
|
||||
switch (eType) {
|
||||
case WINDOWSIZE_MINIMUM:
|
||||
return CalcMinimumSize();
|
||||
default:
|
||||
return Control::GetOptimalSize( eType );
|
||||
switch (eType)
|
||||
{
|
||||
case WINDOWSIZE_MINIMUM:
|
||||
{
|
||||
sal_Int32 nMaxAvailWidth = 0x7fffffff;
|
||||
const OUString &rTxt = GetText();
|
||||
if (m_nMaxWidthChars != -1 && m_nMaxWidthChars < rTxt.getLength())
|
||||
{
|
||||
nMaxAvailWidth = getTextDimensions(this,
|
||||
rTxt.copy(0, m_nMaxWidthChars), 0x7fffffff).Width();
|
||||
}
|
||||
return CalcMinimumSize(nMaxAvailWidth);
|
||||
}
|
||||
default:
|
||||
return Control::GetOptimalSize( eType );
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
void FixedText::FillLayoutData() const
|
||||
void FixedText::FillLayoutData() const
|
||||
{
|
||||
mpControlData->mpLayoutData = new vcl::ControlLayoutData();
|
||||
ImplDraw( const_cast<FixedText*>(this), 0, Point(), GetOutputSizePixel(), true );
|
||||
}
|
||||
|
||||
void FixedText::setMaxWidthChars(sal_Int32 nWidth)
|
||||
{
|
||||
m_nMaxWidthChars = nWidth;
|
||||
queue_resize();
|
||||
}
|
||||
|
||||
bool FixedText::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
|
||||
{
|
||||
if (rKey == "max-width-chars")
|
||||
{
|
||||
setMaxWidthChars(rValue.toInt32());
|
||||
}
|
||||
else
|
||||
return Control::set_property(rKey, rValue);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
|
||||
void FixedLine::ImplInit( Window* pParent, WinBits nStyle )
|
||||
@ -705,7 +740,7 @@ Size FixedLine::GetOptimalSize(WindowSizeType eType) const
|
||||
{
|
||||
switch (eType) {
|
||||
case WINDOWSIZE_MINIMUM:
|
||||
return CalcWindowSize( FixedText::CalcMinimumTextSize ( this ) );
|
||||
return CalcWindowSize( FixedText::CalcMinimumTextSize ( this, 0x7fffffff ) );
|
||||
default:
|
||||
return Control::GetOptimalSize( eType );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user