1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_SVX_LANGBOX_HXX
20 #define INCLUDED_SVX_LANGBOX_HXX
21 
22 #include <memory>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <svx/svxdllapi.h>
26 #include <vcl/weld.hxx>
27 #include <o3tl/typed_flags_set.hxx>
28 
29 enum class SvxLanguageListFlags
30 {
31     EMPTY             = 0x0000,
32     ALL               = 0x0001,
33     WESTERN           = 0x0002,
34     CTL               = 0x0004,
35     CJK               = 0x0008,
36     FBD_CHARS         = 0x0010,
37     ONLY_KNOWN        = 0x0020,  // list only locales provided by I18N
38     SPELL_USED        = 0x0040,
39 };
40 namespace o3tl
41 {
42     template<> struct typed_flags<SvxLanguageListFlags> : is_typed_flags<SvxLanguageListFlags, 0x007f> {};
43 }
44 
45 // load language strings from resource
46 SVX_DLLPUBLIC OUString    GetDicInfoStr( const OUString& rName, const LanguageType nLang, bool bNeg );
47 
48 class SVX_DLLPUBLIC SvxLanguageBox
49 {
50 public:
51     enum class EditedAndValid
52     {
53         No,
54         Valid,
55         Invalid
56     };
57 
58 private:
59     std::unique_ptr<weld::ComboBox> m_xControl;
60     Link<weld::ComboBox&, void> m_aChangeHdl;
61     OUString const m_aAllString;
62     std::unique_ptr<css::uno::Sequence<sal_Int16>> m_xSpellUsedLang;
63     LanguageType m_eSavedLanguage;
64     EditedAndValid  m_eEditedAndValid;
65     bool m_bHasLangNone;
66     bool m_bLangNoneIsLangAll;
67     bool m_bWithCheckmark;
68 
69     SVX_DLLPRIVATE weld::ComboBoxEntry BuildEntry(const LanguageType nLangType, sal_Int16 nType = css::i18n::ScriptType::WEAK);
70     SVX_DLLPRIVATE void AddLanguages(const std::vector< LanguageType >& rLanguageTypes, SvxLanguageListFlags nLangList,
71                                      std::vector<weld::ComboBoxEntry>& rEntries);
72     SVX_DLLPRIVATE void InsertLanguage(const LanguageType nLangType, sal_Int16 nType);
73 
74     SVX_DLLPRIVATE int ImplTypeToPos(LanguageType eType) const;
75     SVX_DLLPRIVATE void ImplClear();
76     DECL_LINK(ChangeHdl, weld::ComboBox&, void);
77 public:
78     SvxLanguageBox(std::unique_ptr<weld::ComboBox> pControl);
79     void            SetLanguageList( SvxLanguageListFlags nLangList,
80                             bool bHasLangNone, bool bLangNoneIsLangAll = false,
81                             bool bCheckSpellAvail = false );
82     void            InsertLanguage(const LanguageType nLangType);
83     void            InsertDefaultLanguage(sal_Int16 nType);
84 
GetEditedAndValid() const85     EditedAndValid      GetEditedAndValid() const { return m_eEditedAndValid;}
86     sal_Int32           SaveEditedAsEntry();
87 
connect_changed(const Link<weld::ComboBox &,void> & rLink)88     void connect_changed(const Link<weld::ComboBox&, void>& rLink) { m_aChangeHdl = rLink; }
connect_focus_in(const Link<weld::Widget &,void> & rLink)89     void connect_focus_in(const Link<weld::Widget&, void>& rLink) { m_xControl->connect_focus_in(rLink); }
grab_focus()90     void grab_focus() { m_xControl->grab_focus(); }
save_active_id()91     void save_active_id() { m_eSavedLanguage = get_active_id(); }
get_saved_active_id() const92     LanguageType get_saved_active_id() const { return m_eSavedLanguage; }
get_active_id_changed_from_saved() const93     bool get_active_id_changed_from_saved() const { return m_eSavedLanguage != get_active_id(); }
show()94     void show() { m_xControl->show(); }
hide()95     void hide() { m_xControl->hide(); }
set_visible(bool bShow)96     void set_visible(bool bShow) { m_xControl->set_visible(bShow); }
set_sensitive(bool bSensitive)97     void set_sensitive(bool bSensitive) { m_xControl->set_sensitive(bSensitive); }
set_active(int nPos)98     void set_active(int nPos) { m_xControl->set_active(nPos); }
get_active() const99     int get_active() const { return m_xControl->get_active(); }
100     void set_active_id(const LanguageType eLangType);
get_active_text() const101     OUString get_active_text() const { return m_xControl->get_active_text(); }
get_visible() const102     bool get_visible() const { return m_xControl->get_visible(); }
103     LanguageType get_active_id() const;
104     int find_id(const LanguageType eLangType) const;
105     LanguageType get_id(int nPos) const;
106     void set_id(int nPos, const LanguageType eLangType);
107     void remove_id(const LanguageType eLangType);
108     void append(const LanguageType eLangType, const OUString& rStr);
find_text(const OUString & rStr) const109     int find_text(const OUString& rStr) const { return m_xControl->find_text(rStr); }
get_text(int nPos) const110     OUString get_text(int nPos) const { return m_xControl->get_text(nPos); }
get_count() const111     int get_count() const { return m_xControl->get_count(); }
get_widget()112     weld::ComboBox* get_widget() { return m_xControl.get(); }
113 };
114 
115 #endif
116 
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
118