/src/libreoffice/svx/source/unodialogs/textconversiondlgs/chinese_dictionarydialog.hxx
Line | Count | Source |
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 | | |
20 | | #pragma once |
21 | | |
22 | | #include <vcl/weld/Button.hxx> |
23 | | #include <vcl/weld/CheckButton.hxx> |
24 | | #include <vcl/weld/ComboBox.hxx> |
25 | | #include <vcl/weld/DialogController.hxx> |
26 | | #include <vcl/weld/Entry.hxx> |
27 | | #include <vcl/weld/RadioButton.hxx> |
28 | | #include <vcl/weld/TreeView.hxx> |
29 | | #include <vcl/weld/Window.hxx> |
30 | | #include <com/sun/star/uno/XComponentContext.hpp> |
31 | | #include <com/sun/star/linguistic2/XConversionDictionary.hpp> |
32 | | |
33 | | #include <vector> |
34 | | |
35 | | namespace textconversiondlgs |
36 | | { |
37 | | |
38 | | struct DictionaryEntry final |
39 | | { |
40 | | DictionaryEntry( OUString rTerm, OUString aMapping |
41 | | , sal_Int16 nConversionPropertyType //linguistic2::ConversionPropertyType |
42 | | , bool bNewEntry = false ); |
43 | | |
44 | | ~DictionaryEntry(); |
45 | | |
46 | | OUString m_aTerm; |
47 | | OUString m_aMapping; |
48 | | sal_Int16 m_nConversionPropertyType; //linguistic2::ConversionPropertyType |
49 | | |
50 | | bool m_bNewEntry; |
51 | | }; |
52 | | |
53 | | class DictionaryList |
54 | | { |
55 | | public: |
56 | | DictionaryList(std::unique_ptr<weld::TreeView> xTreeView); |
57 | | |
58 | | void init(const css::uno::Reference< css::linguistic2::XConversionDictionary>& xDictionary, |
59 | | weld::Entry *pED_Term, weld::Entry *pED_Mapping, weld::ComboBox *pLB_Property); |
60 | | |
61 | | void deleteAll(); |
62 | | void refillFromDictionary( sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ ); |
63 | | void save(); |
64 | | |
65 | | DictionaryEntry* getTermEntry( std::u16string_view rTerm ) const; |
66 | | bool hasTerm( std::u16string_view rTerm ) const; |
67 | | |
68 | | void addEntry( const OUString& rTerm, const OUString& rMapping |
69 | | , sal_Int16 nConversionPropertyType /*linguistic2::ConversionPropertyType*/, int nPos = -1); |
70 | | int deleteEntries( std::u16string_view rTerm ); //return lowest position of deleted entries or -1 if no entry was deleted |
71 | | void deleteEntryOnPos( sal_Int32 nPos ); |
72 | | DictionaryEntry* getEntryOnPos( sal_Int32 nPos ) const; |
73 | | DictionaryEntry* getFirstSelectedEntry() const; |
74 | | |
75 | 0 | void set_size_request(int nWidth, int nHeight) { m_xControl->set_size_request(nWidth, nHeight); } |
76 | 0 | void hide() { m_xControl->hide(); } |
77 | 0 | void show() { m_xControl->show(); } |
78 | | void connect_changed(const Link<weld::ItemView&, void>& rLink) |
79 | 0 | { |
80 | 0 | m_xControl->connect_selection_changed(rLink); |
81 | 0 | } |
82 | | void connect_column_header_clicked(const Link<int, void>& rLink) |
83 | 0 | { |
84 | 0 | m_xControl->connect_column_header_clicked(rLink); |
85 | 0 | } |
86 | 0 | bool get_sort_order() const { return m_xControl->get_sort_order(); } |
87 | 0 | void set_sort_order(bool bAscending) { return m_xControl->set_sort_order(bAscending); } |
88 | 0 | void set_sort_column(int nColumn) { return m_xControl->set_sort_column(nColumn); } |
89 | 0 | int get_sort_column() const { return m_xControl->get_sort_column(); } |
90 | 0 | int get_selected_index() const { return m_xControl->get_selected_index(); } |
91 | 0 | int get_height_rows(int nRows) const { return m_xControl->get_height_rows(nRows); } |
92 | 0 | bool get_visible() const { return m_xControl->get_visible(); } |
93 | 0 | void set_sort_indicator(TriState eState, int nColumn) { m_xControl->set_sort_indicator(eState, nColumn); } |
94 | 0 | weld::TreeView& get_widget() const { return *m_xControl; } |
95 | | |
96 | | private: |
97 | | OUString getPropertyTypeName( sal_Int16 nConversionPropertyType /*linguistic2::ConversionPropertyType*/ ) const; |
98 | | |
99 | | public: |
100 | | css::uno::Reference<css::linguistic2::XConversionDictionary> m_xDictionary; |
101 | | |
102 | | private: |
103 | | std::unique_ptr<weld::TreeView> m_xControl; |
104 | | std::unique_ptr<weld::TreeIter> m_xIter; |
105 | | weld::Entry* m_pED_Term; |
106 | | weld::Entry* m_pED_Mapping; |
107 | | weld::ComboBox* m_pLB_Property; |
108 | | |
109 | | std::vector< DictionaryEntry* > m_aToBeDeleted; |
110 | | }; |
111 | | |
112 | | class ChineseDictionaryDialog : public weld::GenericDialogController |
113 | | { |
114 | | public: |
115 | | explicit ChineseDictionaryDialog(weld::Window* pParent); |
116 | | virtual ~ChineseDictionaryDialog() override; |
117 | | |
118 | | //this method should be called once before calling execute |
119 | | void setDirectionAndTextConversionOptions( bool bDirectionToSimplified, sal_Int32 nTextConversionOptions /*i18n::TextConversionOption*/ ); |
120 | | |
121 | | virtual short run() override; |
122 | | |
123 | | private: |
124 | | DECL_LINK( DirectionHdl, weld::Toggleable&, void ); |
125 | | DECL_LINK(EditFieldsHdl, weld::TextWidget&, void); |
126 | | DECL_LINK( EditFieldsListBoxHdl, weld::ComboBox&, void ); |
127 | | DECL_LINK(MappingSelectHdl, weld::ItemView&, void); |
128 | | DECL_LINK( AddHdl, weld::Button&, void ); |
129 | | DECL_LINK( ModifyHdl, weld::Button&, void ); |
130 | | DECL_LINK( DeleteHdl, weld::Button&, void ); |
131 | | static void HeaderBarClick(DictionaryList& rList, int nColumn); |
132 | | DECL_LINK(ToSimplifiedHeaderBarClick, int, void); |
133 | | DECL_LINK(ToTraditionalHeaderBarClick, int, void); |
134 | | DECL_LINK(SizeAllocHdl, const Size&, void); |
135 | | |
136 | | void initDictionaryControl(DictionaryList *pList, |
137 | | const css::uno::Reference< css::linguistic2::XConversionDictionary>& xDictionary); |
138 | | |
139 | | void updateAfterDirectionChange(); |
140 | | void updateButtons(); |
141 | | |
142 | | bool isEditFieldsHaveContent() const; |
143 | | bool isEditFieldsContentEqualsSelectedListContent() const; |
144 | | |
145 | | DictionaryList& getActiveDictionary(); |
146 | | DictionaryList& getReverseDictionary(); |
147 | | |
148 | | const DictionaryList& getActiveDictionary() const; |
149 | | const DictionaryList& getReverseDictionary() const; |
150 | | |
151 | | private: |
152 | | sal_Int32 m_nTextConversionOptions; //i18n::TextConversionOption |
153 | | |
154 | | std::unique_ptr<weld::RadioButton> m_xRB_To_Simplified; |
155 | | std::unique_ptr<weld::RadioButton> m_xRB_To_Traditional; |
156 | | |
157 | | std::unique_ptr<weld::CheckButton> m_xCB_Reverse; |
158 | | |
159 | | std::unique_ptr<weld::Entry> m_xED_Term; |
160 | | |
161 | | std::unique_ptr<weld::Entry> m_xED_Mapping; |
162 | | |
163 | | std::unique_ptr<weld::ComboBox> m_xLB_Property; |
164 | | |
165 | | std::unique_ptr<DictionaryList> m_xCT_DictionaryToSimplified; |
166 | | std::unique_ptr<DictionaryList> m_xCT_DictionaryToTraditional; |
167 | | |
168 | | std::unique_ptr<weld::Button> m_xPB_Add; |
169 | | std::unique_ptr<weld::Button> m_xPB_Modify; |
170 | | std::unique_ptr<weld::Button> m_xPB_Delete; |
171 | | }; |
172 | | |
173 | | |
174 | | } //end namespace |
175 | | |
176 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |