1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __MISC_HELPER_HXX_
25 #define __MISC_HELPER_HXX_
26 
27 #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
28 #include <com/sun/star/container/XNameAccess.hpp>
29 #include <com/sun/star/frame/XFrame.hpp>
30 
31 #include <i18npool/lang.h>
32 #include <svl/languageoptions.hxx>
33 #include <rtl/ustring.hxx>
34 #include <fwidllapi.h>
35 
36 #include <set>
37 
38 class SvtLanguageTable;
39 
40 
41 // flags for script types in use within selection
42 #define LS_SCRIPT_LATIN     0x0001
43 #define LS_SCRIPT_ASIAN     0x0002
44 #define LS_SCRIPT_COMPLEX   0x0004
45 
46 
47 namespace framework
48 {
49 
50 // menu ids for language status bar control
51 enum LangMenuIDs
52 {
53     MID_LANG_SEL_1 = 1,     // need to start with 1 since xPopupMenu->execute will return 0 if the menu is cancelled
54     MID_LANG_SEL_2,
55     MID_LANG_SEL_3,
56     MID_LANG_SEL_4,
57     MID_LANG_SEL_5,
58     MID_LANG_SEL_6,
59     MID_LANG_SEL_7,
60     MID_LANG_SEL_8,
61     MID_LANG_SEL_9,
62     MID_LANG_SEL_NONE,
63     MID_LANG_SEL_RESET,
64     MID_LANG_SEL_MORE,
65 
66     MID_LANG_PARA_SEPERATOR,
67     MID_LANG_PARA_STRING,
68 
69     MID_LANG_PARA_1,
70     MID_LANG_PARA_2,
71     MID_LANG_PARA_3,
72     MID_LANG_PARA_4,
73     MID_LANG_PARA_5,
74     MID_LANG_PARA_6,
75     MID_LANG_PARA_7,
76     MID_LANG_PARA_8,
77     MID_LANG_PARA_9,
78     MID_LANG_PARA_NONE,
79     MID_LANG_PARA_RESET,
80     MID_LANG_PARA_MORE,
81 };
82 
83 
84 inline bool IsScriptTypeMatchingToLanguage( sal_Int16 nScriptType, LanguageType nLang )
85 {
86     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
87 }
88 
89 
90 class FWI_DLLPUBLIC LanguageGuessingHelper
91 {
92     mutable ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >    m_xLanguageGuesser;
93     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
94 
95 public:
96     LanguageGuessingHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager) : m_xServiceManager(_xServiceManager){}
97 
98     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >  GetGuesser() const;
99 };
100 
101 FWI_DLLPUBLIC ::rtl::OUString RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL
102             ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&    _xServiceFactory
103             ,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >&        _xUICommandLabels
104             ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame
105             ,::rtl::OUString& _rModuleIdentifier
106             ,sal_Bool& _rIni
107             ,const sal_Char* _pName);
108 
109 FWI_DLLPUBLIC void FillLangItems( std::set< ::rtl::OUString > &rLangItems,
110         const SvtLanguageTable &rLanguageTable,
111         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame,
112         const LanguageGuessingHelper & rLangGuessHelper,
113         sal_Int16               nScriptType,
114         const ::rtl::OUString & rCurLang,
115         const ::rtl::OUString & rKeyboardLang,
116         const ::rtl::OUString & rGuessedTextLang );
117 
118 } // namespace framework
119 
120 #endif // __MISC_HELPER_HXX_
121 
122