fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / fwi / helper / mischelper.cxx
bloba3f09309b51f808a2a155b424ffaf235dc606cf8
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/XMultiServiceFactory.hpp>
21 #include <com/sun/star/document/XDocumentLanguages.hpp>
22 #include <com/sun/star/frame/ModuleManager.hpp>
23 #include <com/sun/star/frame/theUICommandDescription.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/linguistic2/LanguageGuessing.hpp>
27 #include <tools/debug.hxx>
28 #include <vcl/settings.hxx>
29 #include <vcl/svapp.hxx>
30 #include <i18nlangtag/languagetag.hxx>
31 #include <svtools/langtab.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <helper/mischelper.hxx>
34 #include <services.h>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::frame;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::container;
41 using namespace ::com::sun::star::lang;
43 namespace framework
46 uno::Reference< linguistic2::XLanguageGuessing > LanguageGuessingHelper::GetGuesser() const
48 if (!m_xLanguageGuesser.is())
50 try
52 m_xLanguageGuesser = linguistic2::LanguageGuessing::create( m_xContext );
54 catch (const uno::Exception &)
56 DBG_ASSERT( false, "failed to get language guessing component" );
59 return m_xLanguageGuesser;
62 OUString RetrieveLabelFromCommand(
63 const OUString& aCmdURL,
64 const uno::Reference< uno::XComponentContext >& _xContext,
65 uno::Reference< container::XNameAccess >& _xUICommandLabels,
66 const uno::Reference< frame::XFrame >& _xFrame,
67 OUString& _rModuleIdentifier,
68 bool& _rIni,
69 const sal_Char* _pName)
71 OUString aLabel;
73 // Retrieve popup menu labels
74 if ( !_xUICommandLabels.is() )
76 try
78 if ( !_rIni )
80 _rIni = true;
81 Reference< XModuleManager2 > xModuleManager = ModuleManager::create( _xContext );
83 try
85 _rModuleIdentifier = xModuleManager->identify( _xFrame );
87 catch( const Exception& )
92 Reference< XNameAccess > xNameAccess = frame::theUICommandDescription::get( _xContext );
93 xNameAccess->getByName( _rModuleIdentifier ) >>= _xUICommandLabels;
95 catch ( const Exception& )
100 if ( _xUICommandLabels.is() )
104 if ( !aCmdURL.isEmpty() )
106 OUString aStr;
107 Sequence< PropertyValue > aPropSeq;
108 if( _xUICommandLabels->hasByName( aCmdURL ) )
110 if ( _xUICommandLabels->getByName( aCmdURL ) >>= aPropSeq )
112 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
114 if ( aPropSeq[i].Name.equalsAscii( _pName/*"Label"*/ ))
116 aPropSeq[i].Value >>= aStr;
117 break;
122 aLabel = aStr;
125 catch ( const com::sun::star::uno::Exception& )
130 return aLabel;
133 void FillLangItems( std::set< OUString > &rLangItems,
134 const uno::Reference< frame::XFrame > & rxFrame,
135 const LanguageGuessingHelper & rLangGuessHelper,
136 SvtScriptType nScriptType,
137 const OUString & rCurLang,
138 const OUString & rKeyboardLang,
139 const OUString & rGuessedTextLang )
141 rLangItems.clear();
143 //1--add current language
144 if( !rCurLang.isEmpty() &&
145 LANGUAGE_DONTKNOW != SvtLanguageTable::GetLanguageType( rCurLang ))
146 rLangItems.insert( rCurLang );
148 //2--System
149 const AllSettings& rAllSettings = Application::GetSettings();
150 LanguageType rSystemLanguage = rAllSettings.GetLanguageTag().getLanguageType();
151 if( rSystemLanguage != LANGUAGE_DONTKNOW )
153 if ( IsScriptTypeMatchingToLanguage( nScriptType, rSystemLanguage ))
154 rLangItems.insert( OUString( SvtLanguageTable::GetLanguageString( rSystemLanguage )) );
157 //3--UI
158 LanguageType rUILanguage = rAllSettings.GetUILanguageTag().getLanguageType();
159 if( rUILanguage != LANGUAGE_DONTKNOW )
161 if ( IsScriptTypeMatchingToLanguage( nScriptType, rUILanguage ))
162 rLangItems.insert( OUString( SvtLanguageTable::GetLanguageString( rUILanguage )) );
165 //4--guessed language
166 uno::Reference< linguistic2::XLanguageGuessing > xLangGuesser( rLangGuessHelper.GetGuesser() );
167 if ( xLangGuesser.is() && !rGuessedTextLang.isEmpty())
169 ::com::sun::star::lang::Locale aLocale(xLangGuesser->guessPrimaryLanguage( rGuessedTextLang, 0, rGuessedTextLang.getLength()) );
170 LanguageType nLang = LanguageTag( aLocale ).makeFallback().getLanguageType();
171 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_NONE && nLang != LANGUAGE_SYSTEM
172 && IsScriptTypeMatchingToLanguage( nScriptType, nLang ))
173 rLangItems.insert( SvtLanguageTable::GetLanguageString( nLang ));
176 //5--keyboard language
177 if( !rKeyboardLang.isEmpty() )
179 if ( IsScriptTypeMatchingToLanguage( nScriptType, SvtLanguageTable::GetLanguageType( rKeyboardLang )))
180 rLangItems.insert( rKeyboardLang );
183 //6--all languages used in current document
184 Reference< com::sun::star::frame::XModel > xModel;
185 if ( rxFrame.is() )
187 Reference< com::sun::star::frame::XController > xController( rxFrame->getController(), UNO_QUERY );
188 if ( xController.is() )
189 xModel = xController->getModel();
191 Reference< document::XDocumentLanguages > xDocumentLanguages( xModel, UNO_QUERY );
192 /*the description of nScriptType
193 LATIN : 0x001
194 ASIAN : 0x002
195 COMPLEX: 0x004
197 const sal_Int16 nMaxCount = 7;
198 if ( xDocumentLanguages.is() )
200 Sequence< Locale > rLocales( xDocumentLanguages->getDocumentLanguages( static_cast<sal_Int16>(nScriptType), nMaxCount ));
201 if ( rLocales.getLength() > 0 )
203 for ( sal_uInt16 i = 0; i < rLocales.getLength(); ++i )
205 if ( rLangItems.size() == static_cast< size_t >(nMaxCount) )
206 break;
207 const Locale& rLocale=rLocales[i];
208 if( IsScriptTypeMatchingToLanguage( nScriptType, SvtLanguageTable::GetLanguageType( rLocale.Language )))
209 rLangItems.insert( OUString( rLocale.Language ) );
215 } // namespace framework
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */