diff options
author | Chris Sherlock <chris.sherlock79@gmail.com> | 2022-08-11 03:56:31 +1000 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-08-25 13:05:25 +0200 |
commit | 9481156090d0b455c6b35eaadd363f47c24b8086 (patch) | |
tree | 5aca78c0cdc95ef1f56c5e8b64ea0b02d98ebc97 /vcl | |
parent | 9ca3c6794ca1969f453ddaa66c4e02ac8c695cc6 (diff) |
vcl: rename GetNonMnemonicString() and make it standalone function
Renamed GetNonMnemonicString() to removeMnemonicFromString()
Change-Id: I272714f97bb6d9174360631c18c4fd9bb485698e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138103
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 1 | ||||
-rw-r--r-- | vcl/source/control/ctrl.cxx | 5 | ||||
-rw-r--r-- | vcl/source/control/tabctrl.cxx | 3 | ||||
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 3 | ||||
-rw-r--r-- | vcl/source/outdev/text.cxx | 46 | ||||
-rw-r--r-- | vcl/source/text/mnemonic.cxx | 53 | ||||
-rw-r--r-- | vcl/source/window/accessibility.cxx | 3 | ||||
-rw-r--r-- | vcl/source/window/menu.cxx | 3 | ||||
-rw-r--r-- | vcl/source/window/menuitemlist.cxx | 4 |
9 files changed, 74 insertions, 47 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index cc5940cf61d0..1faaa57cf336 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -261,6 +261,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/treelist/svlbitm \ vcl/source/treelist/uiobject \ vcl/source/text/ImplLayoutRuns \ + vcl/source/text/mnemonic \ vcl/source/gdi/configsettings \ vcl/source/gdi/cvtgrf \ vcl/source/gdi/embeddedfontshelper \ diff --git a/vcl/source/control/ctrl.cxx b/vcl/source/control/ctrl.cxx index 6cb06bc1191d..0ad2247b5488 100644 --- a/vcl/source/control/ctrl.cxx +++ b/vcl/source/control/ctrl.cxx @@ -22,6 +22,7 @@ #include <vcl/event.hxx> #include <vcl/ctrl.hxx> #include <vcl/decoview.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/settings.hxx> #include <vcl/uitest/logger.hxx> #include <sal/log.hxx> @@ -435,7 +436,7 @@ tools::Rectangle Control::DrawControlText( OutputDevice& _rTargetDevice, const t if (autoacc && !mbShowAccelerator) { - rPStr = GetNonMnemonicString( _rStr ); + rPStr = removeMnemonicFromString( _rStr ); nPStyle &= ~DrawTextFlags::HideMnemonic; } @@ -460,7 +461,7 @@ tools::Rectangle Control::GetControlTextRect( OutputDevice& _rTargetDevice, cons if (autoacc && !mbShowAccelerator) { - rPStr = GetNonMnemonicString( _rStr ); + rPStr = removeMnemonicFromString( _rStr ); nPStyle &= ~DrawTextFlags::HideMnemonic; } diff --git a/vcl/source/control/tabctrl.cxx b/vcl/source/control/tabctrl.cxx index 88088df14954..c55e2820c297 100644 --- a/vcl/source/control/tabctrl.cxx +++ b/vcl/source/control/tabctrl.cxx @@ -30,6 +30,7 @@ #include <vcl/tabctrl.hxx> #include <vcl/toolbox.hxx> #include <vcl/layout.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/toolkit/lstbox.hxx> #include <vcl/settings.hxx> #include <vcl/uitest/uiobject.hxx> @@ -1980,7 +1981,7 @@ OUString TabControl::GetAccessibleName( sal_uInt16 nPageId ) const assert( pItem ); if (!pItem->maAccessibleName.isEmpty()) return pItem->maAccessibleName; - return OutputDevice::GetNonMnemonicString(pItem->maText); + return removeMnemonicFromString(pItem->maText); } void TabControl::SetAccessibleDescription(sal_uInt16 nPageId, const OUString& rDesc) diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 74b7ccdbcf7d..1e8fc7fa5ea9 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -66,6 +66,7 @@ #include <vcl/glyphitemcache.hxx> #include <vcl/lineinfo.hxx> #include <vcl/metric.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/settings.hxx> #include <strhelper.hxx> #include <vcl/svapp.hxx> @@ -6684,7 +6685,7 @@ void PDFWriterImpl::drawText( const tools::Rectangle& rRect, const OUString& rOr OUString aStr = rOrigStr; if ( nStyle & DrawTextFlags::Mnemonic ) - aStr = OutputDevice::GetNonMnemonicString( aStr, nMnemonicPos ); + aStr = removeMnemonicFromString( aStr, nMnemonicPos ); // multiline text if ( nStyle & DrawTextFlags::MultiLine ) diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index 55ddbde7e1a1..6ca2785e3b1f 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -37,6 +37,7 @@ #include <vcl/gdimtf.hxx> #include <vcl/metaact.hxx> #include <vcl/metric.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/textrectinfo.hxx> #include <vcl/virdev.hxx> #include <vcl/sysdata.hxx> @@ -1642,7 +1643,7 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const tools::Recta OUString aStr = rOrigStr; if ( nStyle & DrawTextFlags::Mnemonic ) - aStr = GetNonMnemonicString( aStr, nMnemonicPos ); + aStr = removeMnemonicFromString( aStr, nMnemonicPos ); const bool bDrawMnemonics = !(rTargetDevice.GetSettings().GetStyleSettings().GetOptions() & StyleSettingsOptions::NoMnemonics) && !pVector; @@ -1932,7 +1933,7 @@ tools::Rectangle OutputDevice::GetTextRect( const tools::Rectangle& rRect, OUString aStr = rStr; if ( nStyle & DrawTextFlags::Mnemonic ) - aStr = GetNonMnemonicString( aStr ); + aStr = removeMnemonicFromString( aStr ); if ( nStyle & DrawTextFlags::MultiLine ) { @@ -2226,7 +2227,7 @@ void OutputDevice::DrawCtrlText( const Point& rPos, const OUString& rStr, tools::Long nMnemonicWidth = 0; if ( (nStyle & DrawTextFlags::Mnemonic) && nLen > 1 ) { - aStr = GetNonMnemonicString( aStr, nMnemonicPos ); + aStr = removeMnemonicFromString( aStr, nMnemonicPos ); if ( nMnemonicPos != -1 ) { if( nMnemonicPos < nIndex ) @@ -2335,8 +2336,8 @@ tools::Long OutputDevice::GetCtrlTextWidth( const OUString& rStr, const SalLayou sal_Int32 nLen = rStr.getLength(); sal_Int32 nIndex = 0; - sal_Int32 nMnemonicPos; - OUString aStr = GetNonMnemonicString( rStr, nMnemonicPos ); + sal_Int32 nMnemonicPos; + OUString aStr = removeMnemonicFromString( rStr, nMnemonicPos ); if ( nMnemonicPos != -1 ) { if ( nMnemonicPos < nIndex ) @@ -2347,41 +2348,6 @@ tools::Long OutputDevice::GetCtrlTextWidth( const OUString& rStr, const SalLayou return GetTextWidth( aStr, nIndex, nLen, nullptr, pGlyphs ); } -OUString OutputDevice::GetNonMnemonicString( const OUString& rStr, sal_Int32& rMnemonicPos ) -{ - OUString aStr = rStr; - sal_Int32 nLen = aStr.getLength(); - sal_Int32 i = 0; - - rMnemonicPos = -1; - while ( i < nLen ) - { - if ( aStr[ i ] == '~' ) - { - if ( nLen <= i+1 ) - break; - - if ( aStr[ i+1 ] != '~' ) - { - if ( rMnemonicPos == -1 ) - rMnemonicPos = i; - aStr = aStr.replaceAt( i, 1, u"" ); - nLen--; - } - else - { - aStr = aStr.replaceAt( i, 1, u"" ); - nLen--; - i++; - } - } - else - i++; - } - - return aStr; -} - bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect, const OUString& rStr, sal_Int32 nBase, sal_Int32 nIndex, sal_Int32 nLen, diff --git a/vcl/source/text/mnemonic.cxx b/vcl/source/text/mnemonic.cxx new file mode 100644 index 000000000000..7336032b8d12 --- /dev/null +++ b/vcl/source/text/mnemonic.cxx @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <vcl/mnemonic.hxx> + +OUString removeMnemonicFromString(OUString const& rStr) +{ + sal_Int32 nDummy; + return removeMnemonicFromString(rStr, nDummy); +} + +OUString removeMnemonicFromString(OUString const& rStr, sal_Int32& rMnemonicPos) +{ + OUString aStr = rStr; + sal_Int32 nLen = aStr.getLength(); + sal_Int32 i = 0; + + rMnemonicPos = -1; + while (i < nLen) + { + if (aStr[i] == '~') + { + if (nLen <= i + 1) + break; + + if (aStr[i + 1] != '~') + { + if (rMnemonicPos == -1) + rMnemonicPos = i; + aStr = aStr.replaceAt(i, 1, u""); + nLen--; + } + else + { + aStr = aStr.replaceAt(i, 1, u""); + nLen--; + i++; + } + } + else + i++; + } + + return aStr; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/source/window/accessibility.cxx b/vcl/source/window/accessibility.cxx index a8f65d572eba..89adf9b8ea9e 100644 --- a/vcl/source/window/accessibility.cxx +++ b/vcl/source/window/accessibility.cxx @@ -21,6 +21,7 @@ #include <vcl/toolkit/fixed.hxx> #include <vcl/window.hxx> #include <vcl/menu.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/wrkwin.hxx> #include <window.h> @@ -438,7 +439,7 @@ OUString Window::getDefaultAccessibleName() const break; } - return OutputDevice::GetNonMnemonicString( aAccessibleName ); + return removeMnemonicFromString( aAccessibleName ); } void Window::SetAccessibleDescription( const OUString& rDescription ) diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx index c0222bfdc551..5a9bfaa237d1 100644 --- a/vcl/source/window/menu.cxx +++ b/vcl/source/window/menu.cxx @@ -30,6 +30,7 @@ #include <vcl/toolkit/floatwin.hxx> #include <vcl/decoview.hxx> #include <vcl/menu.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/taskpanelist.hxx> #include <vcl/settings.hxx> #include <vcl/commandinfoprovider.hxx> @@ -1648,7 +1649,7 @@ static void ImplPaintCheckBackground(vcl::RenderContext & rRenderContext, vcl::W static OUString getShortenedString( const OUString& i_rLong, vcl::RenderContext const & rRenderContext, tools::Long i_nMaxWidth ) { sal_Int32 nPos = -1; - OUString aNonMnem(OutputDevice::GetNonMnemonicString(i_rLong, nPos)); + OUString aNonMnem(removeMnemonicFromString(i_rLong, nPos)); aNonMnem = rRenderContext.GetEllipsisString( aNonMnem, i_nMaxWidth, DrawTextFlags::CenterEllipsis); // re-insert mnemonic if (nPos != -1) diff --git a/vcl/source/window/menuitemlist.cxx b/vcl/source/window/menuitemlist.cxx index 0efae5b43b8c..456474d7e610 100644 --- a/vcl/source/window/menuitemlist.cxx +++ b/vcl/source/window/menuitemlist.cxx @@ -23,7 +23,9 @@ #include <salinst.hxx> #include <salmenu.hxx> #include <svdata.hxx> + #include <vcl/i18nhelp.hxx> +#include <vcl/mnemonic.hxx> #include <vcl/settings.hxx> #include <vcl/vcllayout.hxx> #include <vcl/window.hxx> @@ -45,7 +47,7 @@ SalLayoutGlyphs* MenuItemData::GetTextGlyphs(const OutputDevice* pOutputDevice) // Use pre-calculated result. return &aTextGlyphs; - OUString aNonMnemonicString = OutputDevice::GetNonMnemonicString(aText); + OUString aNonMnemonicString = removeMnemonicFromString(aText); std::unique_ptr<SalLayout> pLayout = pOutputDevice->ImplLayout(aNonMnemonicString, 0, aNonMnemonicString.getLength(), Point(0, 0), 0, {}, {}, SalLayoutFlags::GlyphItemsOnly); |