1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __MISC_HELPER_HXX_
29 #define __MISC_HELPER_HXX_
30 
31 #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
32 #include <com/sun/star/container/XNameAccess.hpp>
33 #include <com/sun/star/frame/XFrame.hpp>
34 
35 #include <i18npool/lang.h>
36 #include <svl/languageoptions.hxx>
37 #include <rtl/ustring.hxx>
38 #include <fwidllapi.h>
39 
40 #include <set>
41 
42 class SvtLanguageTable;
43 
44 
45 // flags for script types in use within selection
46 #define LS_SCRIPT_LATIN     0x0001
47 #define LS_SCRIPT_ASIAN     0x0002
48 #define LS_SCRIPT_COMPLEX   0x0004
49 
50 
51 namespace framework
52 {
53 
54 // menu ids for language status bar control
55 enum LangMenuIDs
56 {
57     MID_LANG_SEL_1 = 1,     // need to start with 1 since xPopupMenu->execute will return 0 if the menu is cancelled
58     MID_LANG_SEL_2,
59     MID_LANG_SEL_3,
60     MID_LANG_SEL_4,
61     MID_LANG_SEL_5,
62     MID_LANG_SEL_6,
63     MID_LANG_SEL_7,
64     MID_LANG_SEL_8,
65     MID_LANG_SEL_9,
66     MID_LANG_SEL_NONE,
67     MID_LANG_SEL_RESET,
68     MID_LANG_SEL_MORE,
69 
70     MID_LANG_PARA_SEPERATOR,
71     MID_LANG_PARA_STRING,
72 
73     MID_LANG_PARA_1,
74     MID_LANG_PARA_2,
75     MID_LANG_PARA_3,
76     MID_LANG_PARA_4,
77     MID_LANG_PARA_5,
78     MID_LANG_PARA_6,
79     MID_LANG_PARA_7,
80     MID_LANG_PARA_8,
81     MID_LANG_PARA_9,
82     MID_LANG_PARA_NONE,
83     MID_LANG_PARA_RESET,
84     MID_LANG_PARA_MORE,
85 };
86 
87 
88 inline bool IsScriptTypeMatchingToLanguage( sal_Int16 nScriptType, LanguageType nLang )
89 {
90     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
91 }
92 
93 
94 class FWI_DLLPUBLIC LanguageGuessingHelper
95 {
96     mutable ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >    m_xLanguageGuesser;
97     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xServiceManager;
98 
99 public:
100     LanguageGuessingHelper(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceManager) : m_xServiceManager(_xServiceManager){}
101 
102     ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XLanguageGuessing >  GetGuesser() const;
103 };
104 
105 FWI_DLLPUBLIC ::rtl::OUString RetrieveLabelFromCommand( const ::rtl::OUString& aCmdURL
106             ,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&    _xServiceFactory
107             ,::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >&        _xUICommandLabels
108             ,const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame
109             ,::rtl::OUString& _rModuleIdentifier
110             ,sal_Bool& _rIni
111             ,const sal_Char* _pName);
112 
113 FWI_DLLPUBLIC void FillLangItems( std::set< ::rtl::OUString > &rLangItems,
114         const SvtLanguageTable &rLanguageTable,
115         const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame,
116         const LanguageGuessingHelper & rLangGuessHelper,
117         sal_Int16               nScriptType,
118         const ::rtl::OUString & rCurLang,
119         const ::rtl::OUString & rKeyboardLang,
120         const ::rtl::OUString & rGuessedTextLang );
121 
122 } // namespace framework
123 
124 #endif // __MISC_HELPER_HXX_
125 
126