1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #ifndef INCLUDED_SVX_LANGBOX_HXX
20 #define INCLUDED_SVX_LANGBOX_HXX
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <svx/svxdllapi.h>
25 #include <vcl/image.hxx>
26 #include <vcl/lstbox.hxx>
27 #include <vcl/combobox.hxx>
28 #include <vcl/weld.hxx>
29 #include <o3tl/typed_flags_set.hxx>
32 enum class SvxLanguageListFlags
40 ONLY_KNOWN
= 0x0020, // list only locales provided by I18N
45 template<> struct typed_flags
<SvxLanguageListFlags
> : is_typed_flags
<SvxLanguageListFlags
, 0x007f> {};
48 // load language strings from resource
49 SVX_DLLPUBLIC OUString
GetDicInfoStr( const OUString
& rName
, const LanguageType nLang
, bool bNeg
);
51 class SVX_DLLPUBLIC SvxLanguageBoxBase
54 SvxLanguageBoxBase(const SvxLanguageBoxBase
&) = delete;
55 SvxLanguageBoxBase
& operator=(const SvxLanguageBoxBase
&) = delete;
57 explicit SvxLanguageBoxBase();
58 virtual ~SvxLanguageBoxBase();
60 void SetLanguageList( SvxLanguageListFlags nLangList
,
62 bool bCheckSpellAvail
);
64 void AddLanguages( const std::vector
< LanguageType
>& rLanguageTypes
, SvxLanguageListFlags nLangList
);
66 sal_Int32
InsertLanguage( const LanguageType eLangType
);
67 void InsertDefaultLanguage( sal_Int16 nType
);
68 void InsertSystemLanguage();
69 void InsertLanguage( const LanguageType eLangType
,
71 void SelectLanguage( const LanguageType eLangType
);
72 LanguageType
GetSelectedLanguage() const;
73 bool IsLanguageSelected( const LanguageType eLangType
) const;
76 Image m_aNotCheckedImage
;
77 Image m_aCheckedImage
;
78 std::unique_ptr
<css::uno::Sequence
< sal_Int16
>>
80 bool m_bWithCheckmark
;
82 SVX_DLLPRIVATE
void ImplLanguageBoxBaseInit();
83 SVX_DLLPRIVATE sal_Int32
ImplInsertLanguage(LanguageType
, sal_Int32 nPos
, sal_Int16 nType
);
84 SVX_DLLPRIVATE sal_Int32
ImplTypeToPos( LanguageType eType
) const;
86 SVX_DLLPRIVATE
virtual sal_Int32
ImplInsertImgEntry( const OUString
& rEntry
, sal_Int32 nPos
, bool bChecked
) = 0;
88 SVX_DLLPRIVATE
virtual void ImplClear() = 0;
89 SVX_DLLPRIVATE
virtual sal_Int32
ImplInsertEntry( const OUString
& rEntry
, sal_Int32 nPos
) = 0;
90 SVX_DLLPRIVATE
virtual void ImplSetEntryData( sal_Int32 nPos
, void* pData
) = 0;
91 SVX_DLLPRIVATE
virtual sal_Int32
ImplGetSelectedEntryPos() const = 0;
92 SVX_DLLPRIVATE
virtual void* ImplGetEntryData( sal_Int32 nPos
) const = 0;
93 SVX_DLLPRIVATE
virtual void ImplSelectEntryPos( sal_Int32 nPos
, bool bSelect
) = 0;
94 SVX_DLLPRIVATE
virtual bool ImplIsEntryPosSelected( sal_Int32 nPos
) const = 0;
95 SVX_DLLPRIVATE
virtual sal_Int32
ImplGetEntryPos( const void* pData
) const = 0;
99 class SVX_DLLPUBLIC SvxLanguageBox
: public ListBox
, public SvxLanguageBoxBase
102 SvxLanguageBox( vcl::Window
* pParent
, WinBits nBits
);
105 SVX_DLLPRIVATE
virtual sal_Int32
ImplInsertImgEntry( const OUString
& rEntry
, sal_Int32 nPos
, bool bChecked
) override
;
107 SVX_DLLPRIVATE
virtual void ImplClear() override
;
108 SVX_DLLPRIVATE
virtual sal_Int32
ImplInsertEntry( const OUString
& rEntry
, sal_Int32 nPos
) override
;
109 SVX_DLLPRIVATE
virtual void ImplSetEntryData( sal_Int32 nPos
, void* pData
) override
;
110 SVX_DLLPRIVATE
virtual sal_Int32
ImplGetSelectedEntryPos() const override
;
111 SVX_DLLPRIVATE
virtual void* ImplGetEntryData( sal_Int32 nPos
) const override
;
112 SVX_DLLPRIVATE
virtual void ImplSelectEntryPos( sal_Int32 nPos
, bool bSelect
) override
;
113 SVX_DLLPRIVATE
virtual bool ImplIsEntryPosSelected( sal_Int32 nPos
) const override
;
114 SVX_DLLPRIVATE
virtual sal_Int32
ImplGetEntryPos( const void* pData
) const override
;
117 class SVX_DLLPUBLIC LanguageBox
120 enum class EditedAndValid
128 std::unique_ptr
<weld::ComboBox
> m_xControl
;
129 Link
<weld::ComboBox
&, void> m_aChangeHdl
;
130 OUString
const m_aAllString
;
131 std::unique_ptr
<css::uno::Sequence
<sal_Int16
>> m_xSpellUsedLang
;
132 LanguageType m_eSavedLanguage
;
133 EditedAndValid m_eEditedAndValid
;
135 bool m_bLangNoneIsLangAll
;
136 bool m_bWithCheckmark
;
138 SVX_DLLPRIVATE
weld::ComboBoxEntry
BuildEntry(const LanguageType nLangType
);
139 SVX_DLLPRIVATE
void AddLanguages(const std::vector
< LanguageType
>& rLanguageTypes
, SvxLanguageListFlags nLangList
,
140 std::vector
<weld::ComboBoxEntry
>& rEntries
);
142 SVX_DLLPRIVATE
int ImplTypeToPos(LanguageType eType
) const;
143 SVX_DLLPRIVATE
void ImplClear();
144 DECL_LINK(ChangeHdl
, weld::ComboBox
&, void);
146 LanguageBox(std::unique_ptr
<weld::ComboBox
> pControl
);
147 void SetLanguageList( SvxLanguageListFlags nLangList
,
148 bool bHasLangNone
, bool bLangNoneIsLangAll
= false,
149 bool bCheckSpellAvail
= false );
150 void InsertLanguage(const LanguageType nLangType
);
152 EditedAndValid
GetEditedAndValid() const { return m_eEditedAndValid
;}
153 sal_Int32
SaveEditedAsEntry();
155 void connect_changed(const Link
<weld::ComboBox
&, void>& rLink
) { m_aChangeHdl
= rLink
; }
156 void connect_focus_in(const Link
<weld::Widget
&, void>& rLink
) { m_xControl
->connect_focus_in(rLink
); }
157 void save_active_id() { m_eSavedLanguage
= get_active_id(); }
158 LanguageType
get_saved_active_id() const { return m_eSavedLanguage
; }
159 bool get_active_id_changed_from_saved() const { return m_eSavedLanguage
!= get_active_id(); }
160 void show() { m_xControl
->show(); }
161 void hide() { m_xControl
->hide(); }
162 void set_visible(bool bShow
) { m_xControl
->set_visible(bShow
); }
163 void set_sensitive(bool bSensitive
) { m_xControl
->set_sensitive(bSensitive
); }
164 void set_active(int nPos
) { m_xControl
->set_active(nPos
); }
165 int get_active() const { return m_xControl
->get_active(); }
166 void set_active_id(const LanguageType eLangType
);
167 OUString
get_active_text() const { return m_xControl
->get_active_text(); }
168 bool get_visible() const { return m_xControl
->get_visible(); }
169 LanguageType
get_active_id() const;
170 int find_id(const LanguageType eLangType
) const;
171 LanguageType
get_id(int nPos
) const;
172 void set_id(int nPos
, const LanguageType eLangType
);
173 void remove_id(const LanguageType eLangType
);
174 void append(const LanguageType eLangType
, const OUString
& rStr
);
175 int find_text(const OUString
& rStr
) const { return m_xControl
->find_text(rStr
); }
176 OUString
get_text(int nPos
) const { return m_xControl
->get_text(nPos
); }
177 int get_count() const { return m_xControl
->get_count(); }
178 const weld::ComboBox
* get_widget() const { return m_xControl
.get(); }
181 class SVX_DLLPUBLIC SvxLanguageComboBox
: public ComboBox
, public SvxLanguageBoxBase
184 SvxLanguageComboBox( vcl::Window
* pParent
, WinBits nBits
);
186 enum class EditedAndValid
194 EditedAndValid meEditedAndValid
;
196 SVX_DLLPRIVATE
virtual sal_Int32
ImplInsertImgEntry( const OUString
& rEntry
, sal_Int32 nPos
, bool bChecked
) override
;
198 SVX_DLLPRIVATE
virtual void ImplClear() override
;
199 SVX_DLLPRIVATE
virtual sal_Int32
ImplInsertEntry( const OUString
& rEntry
, sal_Int32 nPos
) override
;
200 SVX_DLLPRIVATE
virtual void ImplSetEntryData( sal_Int32 nPos
, void* pData
) override
;
201 SVX_DLLPRIVATE
virtual sal_Int32
ImplGetSelectedEntryPos() const override
;
202 SVX_DLLPRIVATE
virtual void* ImplGetEntryData( sal_Int32 nPos
) const override
;
203 SVX_DLLPRIVATE
virtual void ImplSelectEntryPos( sal_Int32 nPos
, bool bSelect
) override
;
204 SVX_DLLPRIVATE
virtual bool ImplIsEntryPosSelected( sal_Int32 nPos
) const override
;
205 SVX_DLLPRIVATE
virtual sal_Int32
ImplGetEntryPos( const void* pData
) const override
;
207 DECL_LINK( EditModifyHdl
, Edit
&, void );
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */