tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / i18npool / source / textconversion / textconversionImpl.cxx
blob6f30a990b8dc3aa6c82fb4024e75fa672154f70a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/lang/NoSupportException.hpp>
21 #include <com/sun/star/uno/XComponentContext.hpp>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <textconversionImpl.hxx>
24 #include <localedata.hxx>
26 using namespace com::sun::star::lang;
27 using namespace ::com::sun::star::i18n;
28 using namespace com::sun::star::uno;
30 namespace i18npool {
32 TextConversionResult SAL_CALL
33 TextConversionImpl::getConversions( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
34 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
36 getLocaleSpecificTextConversion(rLocale);
38 sal_Int32 len = aText.getLength() - nStartPos;
39 if (nLength > len)
40 nLength = std::max<sal_Int32>(len, 0);
41 return xTC->getConversions(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
44 OUString SAL_CALL
45 TextConversionImpl::getConversion( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
46 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions)
48 getLocaleSpecificTextConversion(rLocale);
50 sal_Int32 len = aText.getLength() - nStartPos;
51 if (nLength > len)
52 nLength = std::max<sal_Int32>(len, 0);
53 return xTC->getConversion(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions);
56 OUString SAL_CALL
57 TextConversionImpl::getConversionWithOffset( const OUString& aText, sal_Int32 nStartPos, sal_Int32 nLength,
58 const Locale& rLocale, sal_Int16 nConversionType, sal_Int32 nConversionOptions, Sequence< sal_Int32>& offset)
60 getLocaleSpecificTextConversion(rLocale);
62 sal_Int32 len = aText.getLength() - nStartPos;
63 if (nLength > len)
64 nLength = std::max<sal_Int32>(len, 0);
65 return xTC->getConversionWithOffset(aText, nStartPos, nLength, rLocale, nConversionType, nConversionOptions, offset);
68 sal_Bool SAL_CALL
69 TextConversionImpl::interactiveConversion( const Locale& rLocale, sal_Int16 nTextConversionType, sal_Int32 nTextConversionOptions )
71 getLocaleSpecificTextConversion(rLocale);
73 return xTC->interactiveConversion(rLocale, nTextConversionType, nTextConversionOptions);
76 void
77 TextConversionImpl::getLocaleSpecificTextConversion(const Locale& rLocale)
79 if (rLocale != aLocale) {
80 aLocale = rLocale;
82 OUString aPrefix(u"com.sun.star.i18n.TextConversion_"_ustr);
83 Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
84 aPrefix + LocaleDataImpl::getFirstLocaleServiceName( aLocale), m_xContext);
85 if (!xI.is())
87 ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( aLocale));
88 for (auto const& fallback : aFallbacks)
90 xI = m_xContext->getServiceManager()->createInstanceWithContext( aPrefix + fallback, m_xContext);
91 if (xI.is())
92 break;
95 if (xI.is())
96 xTC.set( xI, UNO_QUERY );
97 else if (xTC.is())
98 xTC.clear();
100 if (! xTC.is())
101 throw NoSupportException(); // aLocale is not supported
104 OUString SAL_CALL
105 TextConversionImpl::getImplementationName()
107 return u"com.sun.star.i18n.TextConversion"_ustr;
110 sal_Bool SAL_CALL
111 TextConversionImpl::supportsService(const OUString& rServiceName)
113 return cppu::supportsService(this, rServiceName);
116 Sequence< OUString > SAL_CALL
117 TextConversionImpl::getSupportedServiceNames()
119 return { u"com.sun.star.i18n.TextConversion"_ustr };
124 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
125 com_sun_star_i18n_TextConversion_get_implementation(
126 css::uno::XComponentContext *context,
127 css::uno::Sequence<css::uno::Any> const &)
129 return cppu::acquire(new i18npool::TextConversionImpl(context));
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */