summaryrefslogtreecommitdiff
path: root/cui/source/inc/hangulhanjadlg.hxx
blob: 57c3284d61b378ef81fb2fb422184a783f3291d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#pragma once

#include <vcl/customweld.hxx>
#include <vcl/event.hxx>
#include <vcl/weld.hxx>
#include <editeng/hangulhanja.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
#include <svtools/valueset.hxx>

#include <vector>
#include <memory>

namespace svx
{

    class SuggestionSet : public ValueSet
    {
    public:
        SuggestionSet(std::unique_ptr<weld::ScrolledWindow> xScrolledWindow);

        virtual void    UserDraw( const UserDrawEvent& rUDEvt ) override;
    };

    class SuggestionDisplay
    {
    public:
        SuggestionDisplay(weld::Builder& rBuilder);

        void DisplayListBox( bool bDisplayListBox );

        void SetSelectHdl( const Link<SuggestionDisplay&,void>& rLink );

        void Clear();
        void InsertEntry( const OUString& rStr );
        void SelectEntryPos( sal_uInt16 nPos );

        sal_uInt16 GetEntryCount() const;

        OUString GetEntry( sal_uInt16 nPos ) const;
        OUString GetSelectedEntry() const;

        DECL_LINK( SelectSuggestionListBoxHdl, weld::TreeView&, void );
        DECL_LINK( SelectSuggestionValueSetHdl, ValueSet*, void );
        void SelectSuggestionHdl(bool bListBox);

        void SetHelpIds();

        void set_size_request(int nWidth, int nHeight)
        {
            m_xValueSetWin->set_size_request(nWidth, nHeight);
            m_xListBox->set_size_request(nWidth, nHeight);
        }

    private:
        void implUpdateDisplay();
        weld::Widget& implGetCurrentControl();

    private:
        bool          m_bDisplayListBox; //otherwise ValueSet
        bool          m_bInSelectionUpdate;
        Link<SuggestionDisplay&,void> m_aSelectLink;

        std::unique_ptr<SuggestionSet> m_xValueSet;
        std::unique_ptr<weld::CustomWeld> m_xValueSetWin;
        std::unique_ptr<weld::TreeView> m_xListBox;
    };

    class RubyRadioButton;

    class HangulHanjaConversionDialog : public weld::GenericDialogController
    {
    private:
        /** are we working for a document? This is normally true, but in case
            the user uses the "find" functionality, we switch to working
            with what the user entered, which then does not have any relation to
            the document anymore. Some functionality must be disabled then */
        bool                       m_bDocumentMode;

        Link<LinkParamNone*,void> m_aOptionsChangedLink;
        Link<weld::Toggleable&,void> m_aClickByCharacterLink;

        std::unique_ptr<weld::Button> m_xFind;
        std::unique_ptr<weld::Button> m_xIgnore;
        std::unique_ptr<weld::Button> m_xIgnoreAll;
        std::unique_ptr<weld::Button> m_xReplace;
        std::unique_ptr<weld::Button> m_xReplaceAll;
        std::unique_ptr<weld::Button> m_xOptions;
        std::unique_ptr<SuggestionDisplay> m_xSuggestions;
        std::unique_ptr<weld::RadioButton> m_xSimpleConversion;
        std::unique_ptr<weld::RadioButton> m_xHangulBracketed;
        std::unique_ptr<weld::RadioButton> m_xHanjaBracketed;
        std::unique_ptr<weld::Entry> m_xWordInput;
        std::unique_ptr<weld::Label> m_xOriginalWord;
        std::unique_ptr<RubyRadioButton> m_xHanjaAbove;
        std::unique_ptr<RubyRadioButton> m_xHanjaBelow;
        std::unique_ptr<RubyRadioButton> m_xHangulAbove;
        std::unique_ptr<RubyRadioButton> m_xHangulBelow;
        std::unique_ptr<weld::CheckButton> m_xHangulOnly;
        std::unique_ptr<weld::CheckButton> m_xHanjaOnly;
        std::unique_ptr<weld::CheckButton> m_xReplaceByChar;
    public:
        HangulHanjaConversionDialog(weld::Widget* pParent);
        virtual ~HangulHanjaConversionDialog() override;

    public:
        void    SetOptionsChangedHdl( const Link<LinkParamNone*,void>& _rHdl );
        void    SetIgnoreHdl( const Link<weld::Button&,void>& _rHdl );
        void    SetIgnoreAllHdl( const Link<weld::Button&,void>& _rHdl );
        void    SetChangeHdl( const Link<weld::Button&,void>& _rHdl );
        void    SetChangeAllHdl( const Link<weld::Button&,void>& _rHdl );

        void    SetClickByCharacterHdl( const Link<weld::Toggleable&,void>& _rHdl );
        void    SetConversionFormatChangedHdl( const Link<weld::Toggleable&,void>& _rHdl );
        void    SetFindHdl( const Link<weld::Button&,void>& _rHdl );

        OUString  GetCurrentString( ) const;
        void    SetCurrentString(
                    const OUString& _rNewString,
                    const css::uno::Sequence< OUString >& _rSuggestions,
                    bool _bOriginatesFromDocument
                );

        void    FocusSuggestion( );

        /// retrieves the current suggestion
        OUString  GetCurrentSuggestion( ) const;

        void        SetConversionFormat( editeng::HangulHanjaConversion::ConversionFormat _eType );
        editeng::HangulHanjaConversion::ConversionFormat    GetConversionFormat( ) const;

        void            SetByCharacter( bool _bByCharacter );
        void            SetConversionDirectionState( bool _bTryBothDirections, editeng::HangulHanjaConversion::ConversionDirection _ePrimaryConversionDirection );

        /// should text which does not match the primary conversion direction be ignored?
        bool            GetUseBothDirections( ) const;

        /** get current conversion direction to use
            (return argument if GetUseBothDirections is true) */
        editeng::HangulHanjaConversion::ConversionDirection GetDirection( editeng::HangulHanjaConversion::ConversionDirection eDefaultDirection ) const;

        /// enables or disables the checkboxes for ruby formatted replacements
        void            EnableRubySupport( bool bVal );

    private:
        DECL_LINK( OnOption, weld::Button&, void );
        DECL_LINK( OnSuggestionModified, weld::Entry&, void );
        DECL_LINK( OnSuggestionSelected, SuggestionDisplay&, void );
        DECL_LINK( OnConversionDirectionClicked, weld::Toggleable&, void );
        DECL_LINK( ClickByCharacterHdl, weld::Toggleable&, void );

        /// fill the suggestion list box with suggestions for the actual input
        void FillSuggestions( const css::uno::Sequence< OUString >& _rSuggestions );
    };


    typedef std::vector< css::uno::Reference< css::linguistic2::XConversionDictionary > > HHDictList;

    class HangulHanjaOptionsDialog : public weld::GenericDialogController
    {
    private:
        HHDictList          m_aDictList;
        css::uno::Reference< css::linguistic2::XConversionDictionaryList > m_xConversionDictionaryList;

        std::unique_ptr<weld::TreeView> m_xDictsLB;
        std::unique_ptr<weld::CheckButton> m_xIgnorepostCB;
        std::unique_ptr<weld::CheckButton> m_xShowrecentlyfirstCB;
        std::unique_ptr<weld::CheckButton> m_xAutoreplaceuniqueCB;
        std::unique_ptr<weld::Button> m_xNewPB;
        std::unique_ptr<weld::Button> m_xEditPB;
        std::unique_ptr<weld::Button> m_xDeletePB;
        std::unique_ptr<weld::Button> m_xOkPB;

        DECL_LINK( OkHdl, weld::Button&, void );
        DECL_LINK( DictsLB_SelectHdl, weld::TreeView&, void );
        DECL_LINK( NewDictHdl, weld::Button&, void );
        DECL_LINK( EditDictHdl, weld::Button&, void );
        DECL_LINK( DeleteDictHdl, weld::Button&, void );

        void                Init();       ///< reads settings from core and init controls
    public:
        HangulHanjaOptionsDialog(weld::Window* pParent);
        virtual ~HangulHanjaOptionsDialog() override;

        void                AddDict( const OUString& _rName, bool _bChecked );
    };

    class HangulHanjaNewDictDialog : public weld::GenericDialogController
    {
    private:
        bool m_bEntered;

        std::unique_ptr<weld::Button> m_xOkBtn;
        std::unique_ptr<weld::Entry> m_xDictNameED;

        DECL_LINK(OKHdl, weld::Button&, void);
        DECL_LINK(ModifyHdl, weld::Entry&, void);
    public:
        HangulHanjaNewDictDialog(weld::Window* pParent);
        virtual ~HangulHanjaNewDictDialog() override;

        bool GetName( OUString& _rRetName ) const;
    };

    class SuggestionList;
    class HangulHanjaEditDictDialog;

    class SuggestionEdit
    {
    private:
        HangulHanjaEditDictDialog* m_pParent;
        SuggestionEdit*     m_pPrev;
        SuggestionEdit*     m_pNext;
        weld::ScrolledWindow* m_pScrollBar;
        std::unique_ptr<weld::Entry> m_xEntry;

        bool                ShouldScroll( bool _bUp ) const;
        void                DoJump( bool _bUp );
    public:
        SuggestionEdit(std::unique_ptr<weld::Entry> xEntry, HangulHanjaEditDictDialog* pParent);
        DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
        void init(weld::ScrolledWindow* pScrollBar, SuggestionEdit* pPrev, SuggestionEdit* pNext);

        void grab_focus() { m_xEntry->grab_focus(); }
        void set_text(const OUString& rText) { m_xEntry->set_text(rText); }
        void connect_changed(const Link<weld::Entry&, void>& rLink) { m_xEntry->connect_changed(rLink); }
    };

    class HangulHanjaEditDictDialog : public weld::GenericDialogController
    {
    private:
        const OUString  m_aEditHintText;
        HHDictList&     m_rDictList;
        sal_uInt32      m_nCurrentDict;

        OUString        m_aOriginal;
        std::unique_ptr<SuggestionList> m_xSuggestions;

        sal_uInt16      m_nTopPos;
        bool            m_bModifiedSuggestions;
        bool            m_bModifiedOriginal;

        std::unique_ptr<weld::ComboBox> m_xBookLB;
        std::unique_ptr<weld::ComboBox> m_xOriginalLB;
        std::unique_ptr<SuggestionEdit> m_xEdit1;
        std::unique_ptr<SuggestionEdit> m_xEdit2;
        std::unique_ptr<SuggestionEdit> m_xEdit3;
        std::unique_ptr<SuggestionEdit> m_xEdit4;
        std::unique_ptr<weld::Widget> m_xContents;
        std::unique_ptr<weld::ScrolledWindow> m_xScrollSB;
        std::unique_ptr<weld::Button> m_xNewPB;
        std::unique_ptr<weld::Button> m_xDeletePB;

        DECL_LINK( OriginalModifyHdl, weld::ComboBox&, void );
        DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
        DECL_LINK( EditModifyHdl1, weld::Entry&, void );
        DECL_LINK( EditModifyHdl2, weld::Entry&, void );
        DECL_LINK( EditModifyHdl3, weld::Entry&, void );
        DECL_LINK( EditModifyHdl4, weld::Entry&, void );

        DECL_LINK( BookLBSelectHdl, weld::ComboBox&, void );
        DECL_LINK( NewPBPushHdl, weld::Button&, void );
        DECL_LINK( DeletePBPushHdl, weld::Button&, void );

        void            InitEditDictDialog(sal_uInt32 nSelDict);
        void            UpdateOriginalLB();
        void            UpdateSuggestions();
        void            UpdateButtonStates();

        void            SetEditText( SuggestionEdit& rEdit, sal_uInt16 nEntryNum );
        void            EditModify( const weld::Entry* pEdit, sal_uInt8 nEntryOffset );

        bool            DeleteEntryFromDictionary( const css::uno::Reference< css::linguistic2::XConversionDictionary >& xDict );

    public:
        HangulHanjaEditDictDialog(weld::Window* pParent, HHDictList& rDictList, sal_uInt32 nSelDict);
        virtual ~HangulHanjaEditDictDialog() override;

        void            UpdateScrollbar();
    };
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */