From 6ff6fb198959588ad5dd64bad0825f6a363d2acc Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Tue, 26 Jun 2018 11:24:43 +0300 Subject: tdf#86612: statusbar: hide some elements if width is not sufficient new statusbar element property mandatory=true/false to determine if this element can be hidden if total statusbar width is not enough to fit all elements. marked some calc, draw, writer and impress statusbar elements as not mandatory. Reviewed-on: https://gerrit.libreoffice.org/56443 Reviewed-on: https://gerrit.libreoffice.org/56719 Reviewed-on: https://gerrit.libreoffice.org/56859 Tested-by: Jenkins Reviewed-by: Thorsten Behrens Conflicts: framework/source/fwe/classes/addonsoptions.cxx framework/source/uielement/statusbarmerger.cxx sc/uiconfig/scalc/statusbar/statusbar.xml sd/uiconfig/sdraw/statusbar/statusbar.xml sd/uiconfig/simpress/statusbar/statusbar.xml vcl/source/window/status.cxx Change-Id: I9a634fd7aa7cfa502e445aa3d8ef1c035c21cca8 Reviewed-on: https://gerrit.libreoffice.org/56932 Reviewed-by: Thorsten Behrens Tested-by: Thorsten Behrens --- framework/dtd/statusbar.dtd | 1 + framework/inc/xml/statusbardocumenthandler.hxx | 1 + framework/source/fwe/classes/addonsoptions.cxx | 14 +++-- .../source/fwe/xml/statusbardocumenthandler.cxx | 29 +++++++++- framework/source/uielement/statusbarmanager.cxx | 3 ++ framework/source/uielement/statusbarmerger.cxx | 6 +++ include/vcl/status.hxx | 3 +- offapi/com/sun/star/ui/ItemStyle.idl | 7 +++ offapi/com/sun/star/ui/XStatusbarItem.idl | 1 + .../schema/org/openoffice/Office/Addons.xcs | 6 +++ sc/uiconfig/scalc/statusbar/statusbar.xml | 6 +-- sd/uiconfig/sdraw/statusbar/statusbar.xml | 4 +- sd/uiconfig/simpress/statusbar/statusbar.xml | 4 +- sw/uiconfig/swriter/statusbar/statusbar.xml | 18 +++---- vcl/source/window/status.cxx | 61 +++++++++++++++++----- 15 files changed, 128 insertions(+), 36 deletions(-) diff --git a/framework/dtd/statusbar.dtd b/framework/dtd/statusbar.dtd index 22513df9250e..9f4e9e2a35c3 100644 --- a/framework/dtd/statusbar.dtd +++ b/framework/dtd/statusbar.dtd @@ -33,6 +33,7 @@ statusbar:align %alignment; "center" statusbar:style %style; "in" statusbar:autosize %boolean; "false" + statusbar:mandatory %boolean; "true" statusbar:ownerdraw %boolean; "false" statusbar:width %numeric; "0" statusbar:offset %numeric; "5" diff --git a/framework/inc/xml/statusbardocumenthandler.hxx b/framework/inc/xml/statusbardocumenthandler.hxx index 141e559f4cc0..dc632755bb78 100644 --- a/framework/inc/xml/statusbardocumenthandler.hxx +++ b/framework/inc/xml/statusbardocumenthandler.hxx @@ -51,6 +51,7 @@ class FWE_DLLPUBLIC OReadStatusBarDocumentHandler : SB_ATTRIBUTE_WIDTH, SB_ATTRIBUTE_OFFSET, SB_ATTRIBUTE_HELPURL, + SB_ATTRIBUTE_MANDATORY, SB_XML_ENTRY_COUNT }; diff --git a/framework/source/fwe/classes/addonsoptions.cxx b/framework/source/fwe/classes/addonsoptions.cxx index 406e4663bcf1..c9530121b444 100644 --- a/framework/source/fwe/classes/addonsoptions.cxx +++ b/framework/source/fwe/classes/addonsoptions.cxx @@ -71,7 +71,8 @@ using namespace ::com::sun::star; #define INDEX_ALIGN 8 #define INDEX_AUTOSIZE 9 #define INDEX_OWNERDRAW 10 -#define PROPERTYCOUNT_INDEX 11 +#define INDEX_MANDATORY 11 +#define PROPERTYCOUNT_INDEX 12 // The following order is mandatory. Please add properties at the end! #define PROPERTYCOUNT_MENUITEM 6 @@ -100,14 +101,15 @@ using namespace ::com::sun::star; #define OFFSET_TOOLBARITEM_WIDTH 6 // The following order is mandatory. Please add properties at the end! -#define PROPERTYCOUNT_STATUSBARITEM 7 +#define PROPERTYCOUNT_STATUSBARITEM 8 #define OFFSET_STATUSBARITEM_URL 0 #define OFFSET_STATUSBARITEM_TITLE 1 #define OFFSET_STATUSBARITEM_CONTEXT 2 #define OFFSET_STATUSBARITEM_ALIGN 3 #define OFFSET_STATUSBARITEM_AUTOSIZE 4 #define OFFSET_STATUSBARITEM_OWNERDRAW 5 -#define OFFSET_STATUSBARITEM_WIDTH 6 +#define OFFSET_STATUSBARITEM_MANDATORY 6 +#define OFFSET_STATUSBARITEM_WIDTH 7 // The following order is mandatory. Please add properties at the end! #define PROPERTYCOUNT_IMAGES 8 @@ -331,6 +333,7 @@ AddonsOptions_Impl::AddonsOptions_Impl() m_aPropNames[ INDEX_ALIGN ] = "Alignment"; m_aPropNames[ INDEX_AUTOSIZE ] = "AutoSize"; m_aPropNames[ INDEX_OWNERDRAW ] = "OwnerDraw"; + m_aPropNames[ INDEX_MANDATORY ] = "Mandatory"; // initialize array with fixed images property names m_aPropImagesNames[ OFFSET_IMAGES_SMALL ] = "ImageSmall"; @@ -1002,6 +1005,7 @@ bool AddonsOptions_Impl::ReadMergeStatusbarData( aStatusbarItem[ OFFSET_STATUSBARITEM_ALIGN ].Name = m_aPropNames[ INDEX_ALIGN ]; aStatusbarItem[ OFFSET_STATUSBARITEM_AUTOSIZE ].Name = m_aPropNames[ INDEX_AUTOSIZE ]; aStatusbarItem[ OFFSET_STATUSBARITEM_OWNERDRAW ].Name = m_aPropNames[ INDEX_OWNERDRAW ]; + aStatusbarItem[ OFFSET_STATUSBARITEM_MANDATORY ].Name = m_aPropNames[ INDEX_MANDATORY ]; aStatusbarItem[ OFFSET_STATUSBARITEM_WIDTH ].Name = m_aPropNames[ INDEX_WIDTH ]; sal_uInt32 nCount = aAddonStatusbarItemSetNodeSeq.getLength(); @@ -1040,6 +1044,7 @@ bool AddonsOptions_Impl::ReadStatusBarItem( aStatusbarItem[ OFFSET_STATUSBARITEM_ALIGN ].Value <<= aStatusbarItemNodePropValues[ OFFSET_STATUSBARITEM_ALIGN ]; aStatusbarItem[ OFFSET_STATUSBARITEM_AUTOSIZE ].Value <<= aStatusbarItemNodePropValues[ OFFSET_STATUSBARITEM_AUTOSIZE ]; aStatusbarItem[ OFFSET_STATUSBARITEM_OWNERDRAW ].Value <<= aStatusbarItemNodePropValues[ OFFSET_STATUSBARITEM_OWNERDRAW ]; + aStatusbarItem[ OFFSET_STATUSBARITEM_MANDATORY ].Value <<= aStatusbarItemNodePropValues[ OFFSET_STATUSBARITEM_MANDATORY ]; // Configuration uses hyper for long. Therefore transform into sal_Int32 sal_Int64 nValue( 0 ); @@ -1449,7 +1454,8 @@ Sequence< ::rtl::OUString > AddonsOptions_Impl::GetPropertyNamesStatusbarItem( lResult[3] = ::rtl::OUString( aPropertyRootNode + m_aPropNames[ INDEX_ALIGN ] ); lResult[4] = ::rtl::OUString( aPropertyRootNode + m_aPropNames[ INDEX_AUTOSIZE ] ); lResult[5] = ::rtl::OUString( aPropertyRootNode + m_aPropNames[ INDEX_OWNERDRAW ] ); - lResult[6] = ::rtl::OUString( aPropertyRootNode + m_aPropNames[ INDEX_WIDTH ] ); + lResult[6] = ::rtl::OUString( aPropertyRootNode + m_aPropNames[ INDEX_MANDATORY ] ); + lResult[7] = ::rtl::OUString( aPropertyRootNode + m_aPropNames[ INDEX_WIDTH ] ); return lResult; } diff --git a/framework/source/fwe/xml/statusbardocumenthandler.cxx b/framework/source/fwe/xml/statusbardocumenthandler.cxx index 1640db19d4a1..94cbd56725be 100644 --- a/framework/source/fwe/xml/statusbardocumenthandler.cxx +++ b/framework/source/fwe/xml/statusbardocumenthandler.cxx @@ -55,6 +55,7 @@ using namespace ::com::sun::star::container; #define ATTRIBUTE_AUTOSIZE "autosize" #define ATTRIBUTE_OWNERDRAW "ownerdraw" #define ATTRIBUTE_HELPURL "helpid" +#define ATTRIBUTE_MANDATORY "mandatory" #define ELEMENT_NS_STATUSBAR "statusbar:statusbar" #define ELEMENT_NS_STATUSBARITEM "statusbar:statusbaritem" @@ -139,7 +140,8 @@ StatusBarEntryProperty StatusBarEntries[OReadStatusBarDocumentHandler::SB_XML_EN { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_OWNERDRAW }, { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_WIDTH }, { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_OFFSET }, - { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_HELPURL } + { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_HELPURL }, + { OReadStatusBarDocumentHandler::SB_NS_STATUSBAR, ATTRIBUTE_MANDATORY } }; OReadStatusBarDocumentHandler::OReadStatusBarDocumentHandler( @@ -240,7 +242,7 @@ throw( SAXException, RuntimeException, std::exception ) OUString aCommandURL; OUString aHelpURL; - sal_Int16 nItemBits( ItemStyle::ALIGN_CENTER|ItemStyle::DRAW_IN3D ); + sal_Int16 nItemBits( ItemStyle::ALIGN_CENTER|ItemStyle::DRAW_IN3D|ItemStyle::MANDATORY ); sal_Int16 nWidth( 0 ); sal_Int16 nOffset( STATUSBAR_OFFSET ); bool bCommandURL( false ); @@ -358,6 +360,21 @@ throw( SAXException, RuntimeException, std::exception ) } break; + case SB_ATTRIBUTE_MANDATORY: + { + if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_TRUE ) + nItemBits |= ItemStyle::MANDATORY; + else if ( xAttribs->getValueByIndex( n ) == ATTRIBUTE_BOOLEAN_FALSE ) + nItemBits &= ~ItemStyle::MANDATORY; + else + { + OUString aErrorMessage = getErrorLineString(); + aErrorMessage += "Attribute statusbar:mandatory must have value 'true' or 'false'!"; + throw SAXException( aErrorMessage, Reference< XInterface >(), Any() ); + } + } + break; + default: break; } @@ -648,6 +665,14 @@ throw ( SAXException, RuntimeException ) OUString::number( nOffset ) ); } + // mandatory (default sal_True) + if ( !( nStyle & ItemStyle::MANDATORY ) ) + { + pList->AddAttribute( m_aXMLStatusBarNS + ATTRIBUTE_MANDATORY, + m_aAttributeType, + ATTRIBUTE_BOOLEAN_FALSE ); + } + m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); m_xWriteDocumentHandler->startElement( ELEMENT_NS_STATUSBARITEM, xList ); m_xWriteDocumentHandler->ignorableWhitespace( OUString() ); diff --git a/framework/source/uielement/statusbarmanager.cxx b/framework/source/uielement/statusbarmanager.cxx index 6fb88bf10a4b..12e1a6f3f6c8 100644 --- a/framework/source/uielement/statusbarmanager.cxx +++ b/framework/source/uielement/statusbarmanager.cxx @@ -123,6 +123,9 @@ StatusBarItemBits impl_convertItemStyleToItemBits( sal_Int16 nStyle ) if ( nStyle & css::ui::ItemStyle::OWNER_DRAW ) nItemBits |= StatusBarItemBits::UserDraw; + if ( nStyle & css::ui::ItemStyle::MANDATORY ) + nItemBits |= StatusBarItemBits::Mandatory; + return nItemBits; } diff --git a/framework/source/uielement/statusbarmerger.cxx b/framework/source/uielement/statusbarmerger.cxx index 9459acc8e61b..710062670a26 100644 --- a/framework/source/uielement/statusbarmerger.cxx +++ b/framework/source/uielement/statusbarmerger.cxx @@ -32,6 +32,7 @@ static const char MERGE_STATUSBAR_CONTEXT[] = "Context"; static const char MERGE_STATUSBAR_ALIGN[] = "Alignment"; static const char MERGE_STATUSBAR_AUTOSIZE[] = "AutoSize"; static const char MERGE_STATUSBAR_OWNERDRAW[] = "OwnerDraw"; +static const char MERGE_STATUSBAR_MANDATORY[] = "Mandatory"; static const char MERGE_STATUSBAR_WIDTH[] = "Width"; static const char STATUSBAR_ALIGN_CENTER[] = "center"; @@ -53,6 +54,7 @@ void lcl_ConvertSequenceToValues( OUString sAlignment; bool bAutoSize = false; bool bOwnerDraw = false; + bool bMandatory = true; PropertyValue aPropVal; for ( sal_Int32 i = 0; i < rSequence.getLength(); i++ ) @@ -70,6 +72,8 @@ void lcl_ConvertSequenceToValues( aPropVal.Value >>= bAutoSize; else if ( aPropVal.Name == MERGE_STATUSBAR_OWNERDRAW ) aPropVal.Value >>= bOwnerDraw; + else if ( aPropVal.Name == MERGE_STATUSBAR_MANDATORY ) + aPropVal.Value >>= bMandatory; else if ( aPropVal.Name == MERGE_STATUSBAR_WIDTH ) { sal_Int32 aWidth = 0; @@ -83,6 +87,8 @@ void lcl_ConvertSequenceToValues( nItemBits |= StatusBarItemBits::AutoSize; if ( bOwnerDraw ) nItemBits |= StatusBarItemBits::UserDraw; + if ( bMandatory ) + nItemBits |= StatusBarItemBits::Mandatory; if ( sAlignment == STATUSBAR_ALIGN_CENTER ) nItemBits |= StatusBarItemBits::Center; else if ( sAlignment == STATUSBAR_ALIGN_RIGHT ) diff --git a/include/vcl/status.hxx b/include/vcl/status.hxx index e31a6944f938..42a8df40a3e5 100644 --- a/include/vcl/status.hxx +++ b/include/vcl/status.hxx @@ -46,10 +46,11 @@ enum class StatusBarItemBits { Flat = 0x0020, AutoSize = 0x0040, UserDraw = 0x0080, + Mandatory = 0x0100, }; namespace o3tl { - template<> struct typed_flags : is_typed_flags {}; + template<> struct typed_flags : is_typed_flags {}; } #define STATUSBAR_APPEND ((sal_uInt16)0xFFFF) diff --git a/offapi/com/sun/star/ui/ItemStyle.idl b/offapi/com/sun/star/ui/ItemStyle.idl index 8479bbc15a75..966a4f4e19dc 100644 --- a/offapi/com/sun/star/ui/ItemStyle.idl +++ b/offapi/com/sun/star/ui/ItemStyle.idl @@ -149,6 +149,13 @@ constants ItemStyle icon+text)

*/ const short TEXT = 2048; + + /** marks always visible element which can not be removed when statusbar + width is not sufficient. + + @since LibreOffice 6.2 + */ + const short MANDATORY = 4096; }; }; }; }; }; diff --git a/offapi/com/sun/star/ui/XStatusbarItem.idl b/offapi/com/sun/star/ui/XStatusbarItem.idl index adec214ec5b6..faed72d9021f 100644 --- a/offapi/com/sun/star/ui/XStatusbarItem.idl +++ b/offapi/com/sun/star/ui/XStatusbarItem.idl @@ -64,6 +64,7 @@ interface XStatusbarItem
  • com::sun::star::ui::ItemStyle::AUTO_SIZE
  • com::sun::star::ui::ItemStyle::OWNER_DRAW
  • +
  • com::sun::star::ui::ItemStyle::MANDATORY (@since LibreOffice 6.2)
  • @see com::sun::star::ui::ItemStyle diff --git a/officecfg/registry/schema/org/openoffice/Office/Addons.xcs b/officecfg/registry/schema/org/openoffice/Office/Addons.xcs index 38496934f97d..fb1c36420ba6 100644 --- a/officecfg/registry/schema/org/openoffice/Office/Addons.xcs +++ b/officecfg/registry/schema/org/openoffice/Office/Addons.xcs @@ -282,6 +282,12 @@ false + + + Specifies whether the element can be hidden (false) or not (true) if status bar width is not sufficient to fit all elements. + + true + A property to define the size of a status bar item. diff --git a/sc/uiconfig/scalc/statusbar/statusbar.xml b/sc/uiconfig/scalc/statusbar/statusbar.xml index 79a746fa2e99..5c0835e3c554 100644 --- a/sc/uiconfig/scalc/statusbar/statusbar.xml +++ b/sc/uiconfig/scalc/statusbar/statusbar.xml @@ -19,13 +19,13 @@ --> - + - + - + diff --git a/sd/uiconfig/sdraw/statusbar/statusbar.xml b/sd/uiconfig/sdraw/statusbar/statusbar.xml index 78042ef3d523..26dd393b7129 100644 --- a/sd/uiconfig/sdraw/statusbar/statusbar.xml +++ b/sd/uiconfig/sdraw/statusbar/statusbar.xml @@ -18,8 +18,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - - + + diff --git a/sd/uiconfig/simpress/statusbar/statusbar.xml b/sd/uiconfig/simpress/statusbar/statusbar.xml index 78042ef3d523..26dd393b7129 100644 --- a/sd/uiconfig/simpress/statusbar/statusbar.xml +++ b/sd/uiconfig/simpress/statusbar/statusbar.xml @@ -18,8 +18,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - - + + diff --git a/sw/uiconfig/swriter/statusbar/statusbar.xml b/sw/uiconfig/swriter/statusbar/statusbar.xml index 8b3b9cc9b2b3..f85f07daa068 100644 --- a/sw/uiconfig/swriter/statusbar/statusbar.xml +++ b/sw/uiconfig/swriter/statusbar/statusbar.xml @@ -18,16 +18,16 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . --> - + - - - - - - + + + + + + - - + + diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx index 187770a55137..09ab700d7a5e 100644 --- a/vcl/source/window/status.cxx +++ b/vcl/source/window/status.cxx @@ -230,23 +230,58 @@ void StatusBar::ImplFormat() long nExtraWidth; long nExtraWidth2; long nX; - sal_uInt16 nAutoSizeItems = 0; + sal_uInt16 nAutoSizeItems; + bool bChanged; + + do { + // sum up widths + nAutoSizeItems = 0; + mnItemsWidth = STATUSBAR_OFFSET_X; + bChanged = false; + long nOffset = 0; + for ( const auto & pItem : *mpItemList ) { + if ( pItem->mbVisible ) + { + if ( pItem->mnBits & StatusBarItemBits::AutoSize ) { + nAutoSizeItems++; + } - // sum up widths - mnItemsWidth = STATUSBAR_OFFSET_X; - long nOffset = 0; - for (ImplStatusItem* i : *mpItemList) { - pItem = i; - if ( pItem->mbVisible ) - { - if ( pItem->mnBits & StatusBarItemBits::AutoSize ) { - nAutoSizeItems++; + mnItemsWidth += pItem->mnWidth + nOffset; + nOffset = pItem->mnOffset; } + } - mnItemsWidth += pItem->mnWidth + nOffset; - nOffset = pItem->mnOffset; + if ( mnDX > 0 && mnDX < mnItemsWidth ) + { + // Total width of items is more than available width + // Try to hide secondary elements, if any + for ( auto & pItem : *mpItemList ) + { + if ( pItem->mbVisible && !(pItem->mnBits & StatusBarItemBits::Mandatory) ) + { + pItem->mbVisible = false; + bChanged = true; + break; + } + } } - } + else if ( mnDX > mnItemsWidth ) + { + // Width of statusbar is sufficient. + // Try to restore hidden items, if any + for ( auto & pItem : *mpItemList ) + { + if ( !pItem->mbVisible && + !(pItem->mnBits & StatusBarItemBits::Mandatory) && + pItem->mnWidth + nOffset + mnItemsWidth < mnDX ) + { + pItem->mbVisible = true; + bChanged = true; + break; + } + } + } + } while ( bChanged ); if ( GetStyle() & WB_RIGHT ) { -- cgit