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 .
21 #include <vcl/customweld.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/weld.hxx>
24 #include <editeng/hangulhanja.hxx>
25 #include <com/sun/star/uno/Sequence.hxx>
26 #include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
27 #include <svtools/valueset.hxx>
35 class SuggestionSet
: public ValueSet
38 SuggestionSet(std::unique_ptr
<weld::ScrolledWindow
> xScrolledWindow
);
40 virtual void UserDraw( const UserDrawEvent
& rUDEvt
) override
;
43 class SuggestionDisplay
46 SuggestionDisplay(weld::Builder
& rBuilder
);
48 void DisplayListBox( bool bDisplayListBox
);
50 void SetSelectHdl( const Link
<SuggestionDisplay
&,void>& rLink
);
53 void InsertEntry( const OUString
& rStr
);
54 void SelectEntryPos( sal_uInt16 nPos
);
56 sal_uInt16
GetEntryCount() const;
58 OUString
GetEntry( sal_uInt16 nPos
) const;
59 OUString
GetSelectedEntry() const;
61 DECL_LINK( SelectSuggestionListBoxHdl
, weld::TreeView
&, void );
62 DECL_LINK( SelectSuggestionValueSetHdl
, ValueSet
*, void );
63 void SelectSuggestionHdl(bool bListBox
);
67 void set_size_request(int nWidth
, int nHeight
)
69 m_xValueSetWin
->set_size_request(nWidth
, nHeight
);
70 m_xListBox
->set_size_request(nWidth
, nHeight
);
74 void implUpdateDisplay();
75 weld::Widget
& implGetCurrentControl();
78 bool m_bDisplayListBox
; //otherwise ValueSet
79 bool m_bInSelectionUpdate
;
80 Link
<SuggestionDisplay
&,void> m_aSelectLink
;
82 std::unique_ptr
<SuggestionSet
> m_xValueSet
;
83 std::unique_ptr
<weld::CustomWeld
> m_xValueSetWin
;
84 std::unique_ptr
<weld::TreeView
> m_xListBox
;
87 class RubyRadioButton
;
89 class HangulHanjaConversionDialog
: public weld::GenericDialogController
92 /** are we working for a document? This is normally true, but in case
93 the user uses the "find" functionality, we switch to working
94 with what the user entered, which then does not have any relation to
95 the document anymore. Some functionality must be disabled then */
98 Link
<LinkParamNone
*,void> m_aOptionsChangedLink
;
99 Link
<weld::Toggleable
&,void> m_aClickByCharacterLink
;
101 std::unique_ptr
<weld::Button
> m_xFind
;
102 std::unique_ptr
<weld::Button
> m_xIgnore
;
103 std::unique_ptr
<weld::Button
> m_xIgnoreAll
;
104 std::unique_ptr
<weld::Button
> m_xReplace
;
105 std::unique_ptr
<weld::Button
> m_xReplaceAll
;
106 std::unique_ptr
<weld::Button
> m_xOptions
;
107 std::unique_ptr
<SuggestionDisplay
> m_xSuggestions
;
108 std::unique_ptr
<weld::RadioButton
> m_xSimpleConversion
;
109 std::unique_ptr
<weld::RadioButton
> m_xHangulBracketed
;
110 std::unique_ptr
<weld::RadioButton
> m_xHanjaBracketed
;
111 std::unique_ptr
<weld::Entry
> m_xWordInput
;
112 std::unique_ptr
<weld::Label
> m_xOriginalWord
;
113 std::unique_ptr
<RubyRadioButton
> m_xHanjaAbove
;
114 std::unique_ptr
<RubyRadioButton
> m_xHanjaBelow
;
115 std::unique_ptr
<RubyRadioButton
> m_xHangulAbove
;
116 std::unique_ptr
<RubyRadioButton
> m_xHangulBelow
;
117 std::unique_ptr
<weld::CheckButton
> m_xHangulOnly
;
118 std::unique_ptr
<weld::CheckButton
> m_xHanjaOnly
;
119 std::unique_ptr
<weld::CheckButton
> m_xReplaceByChar
;
121 HangulHanjaConversionDialog(weld::Widget
* pParent
);
122 virtual ~HangulHanjaConversionDialog() override
;
125 void SetOptionsChangedHdl( const Link
<LinkParamNone
*,void>& _rHdl
);
126 void SetIgnoreHdl( const Link
<weld::Button
&,void>& _rHdl
);
127 void SetIgnoreAllHdl( const Link
<weld::Button
&,void>& _rHdl
);
128 void SetChangeHdl( const Link
<weld::Button
&,void>& _rHdl
);
129 void SetChangeAllHdl( const Link
<weld::Button
&,void>& _rHdl
);
131 void SetClickByCharacterHdl( const Link
<weld::Toggleable
&,void>& _rHdl
);
132 void SetConversionFormatChangedHdl( const Link
<weld::Toggleable
&,void>& _rHdl
);
133 void SetFindHdl( const Link
<weld::Button
&,void>& _rHdl
);
135 OUString
GetCurrentString( ) const;
136 void SetCurrentString(
137 const OUString
& _rNewString
,
138 const css::uno::Sequence
< OUString
>& _rSuggestions
,
139 bool _bOriginatesFromDocument
142 void FocusSuggestion( );
144 /// retrieves the current suggestion
145 OUString
GetCurrentSuggestion( ) const;
147 void SetConversionFormat( editeng::HangulHanjaConversion::ConversionFormat _eType
);
148 editeng::HangulHanjaConversion::ConversionFormat
GetConversionFormat( ) const;
150 void SetByCharacter( bool _bByCharacter
);
151 void SetConversionDirectionState( bool _bTryBothDirections
, editeng::HangulHanjaConversion::ConversionDirection _ePrimaryConversionDirection
);
153 /// should text which does not match the primary conversion direction be ignored?
154 bool GetUseBothDirections( ) const;
156 /** get current conversion direction to use
157 (return argument if GetUseBothDirections is true) */
158 editeng::HangulHanjaConversion::ConversionDirection
GetDirection( editeng::HangulHanjaConversion::ConversionDirection eDefaultDirection
) const;
160 /// enables or disables the checkboxes for ruby formatted replacements
161 void EnableRubySupport( bool bVal
);
164 DECL_LINK( OnOption
, weld::Button
&, void );
165 DECL_LINK( OnSuggestionModified
, weld::Entry
&, void );
166 DECL_LINK( OnSuggestionSelected
, SuggestionDisplay
&, void );
167 DECL_LINK( OnConversionDirectionClicked
, weld::Toggleable
&, void );
168 DECL_LINK( ClickByCharacterHdl
, weld::Toggleable
&, void );
170 /// fill the suggestion list box with suggestions for the actual input
171 void FillSuggestions( const css::uno::Sequence
< OUString
>& _rSuggestions
);
175 typedef std::vector
< css::uno::Reference
< css::linguistic2::XConversionDictionary
> > HHDictList
;
177 class HangulHanjaOptionsDialog
: public weld::GenericDialogController
180 HHDictList m_aDictList
;
181 css::uno::Reference
< css::linguistic2::XConversionDictionaryList
> m_xConversionDictionaryList
;
183 std::unique_ptr
<weld::TreeView
> m_xDictsLB
;
184 std::unique_ptr
<weld::CheckButton
> m_xIgnorepostCB
;
185 std::unique_ptr
<weld::CheckButton
> m_xShowrecentlyfirstCB
;
186 std::unique_ptr
<weld::CheckButton
> m_xAutoreplaceuniqueCB
;
187 std::unique_ptr
<weld::Button
> m_xNewPB
;
188 std::unique_ptr
<weld::Button
> m_xEditPB
;
189 std::unique_ptr
<weld::Button
> m_xDeletePB
;
190 std::unique_ptr
<weld::Button
> m_xOkPB
;
192 DECL_LINK( OkHdl
, weld::Button
&, void );
193 DECL_LINK( DictsLB_SelectHdl
, weld::TreeView
&, void );
194 DECL_LINK( NewDictHdl
, weld::Button
&, void );
195 DECL_LINK( EditDictHdl
, weld::Button
&, void );
196 DECL_LINK( DeleteDictHdl
, weld::Button
&, void );
198 void Init(); ///< reads settings from core and init controls
200 HangulHanjaOptionsDialog(weld::Window
* pParent
);
201 virtual ~HangulHanjaOptionsDialog() override
;
203 void AddDict( const OUString
& _rName
, bool _bChecked
);
206 class HangulHanjaNewDictDialog
: public weld::GenericDialogController
211 std::unique_ptr
<weld::Button
> m_xOkBtn
;
212 std::unique_ptr
<weld::Entry
> m_xDictNameED
;
214 DECL_LINK(OKHdl
, weld::Button
&, void);
215 DECL_LINK(ModifyHdl
, weld::Entry
&, void);
217 HangulHanjaNewDictDialog(weld::Window
* pParent
);
218 virtual ~HangulHanjaNewDictDialog() override
;
220 bool GetName( OUString
& _rRetName
) const;
223 class SuggestionList
;
224 class HangulHanjaEditDictDialog
;
229 HangulHanjaEditDictDialog
* m_pParent
;
230 SuggestionEdit
* m_pPrev
;
231 SuggestionEdit
* m_pNext
;
232 weld::ScrolledWindow
* m_pScrollBar
;
233 std::unique_ptr
<weld::Entry
> m_xEntry
;
235 bool ShouldScroll( bool _bUp
) const;
236 void DoJump( bool _bUp
);
238 SuggestionEdit(std::unique_ptr
<weld::Entry
> xEntry
, HangulHanjaEditDictDialog
* pParent
);
239 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
240 void init(weld::ScrolledWindow
* pScrollBar
, SuggestionEdit
* pPrev
, SuggestionEdit
* pNext
);
242 void grab_focus() { m_xEntry
->grab_focus(); }
243 void set_text(const OUString
& rText
) { m_xEntry
->set_text(rText
); }
244 void connect_changed(const Link
<weld::Entry
&, void>& rLink
) { m_xEntry
->connect_changed(rLink
); }
247 class HangulHanjaEditDictDialog
: public weld::GenericDialogController
250 const OUString m_aEditHintText
;
251 HHDictList
& m_rDictList
;
252 sal_uInt32 m_nCurrentDict
;
254 OUString m_aOriginal
;
255 std::unique_ptr
<SuggestionList
> m_xSuggestions
;
257 sal_uInt16 m_nTopPos
;
258 bool m_bModifiedSuggestions
;
259 bool m_bModifiedOriginal
;
261 std::unique_ptr
<weld::ComboBox
> m_xBookLB
;
262 std::unique_ptr
<weld::ComboBox
> m_xOriginalLB
;
263 std::unique_ptr
<SuggestionEdit
> m_xEdit1
;
264 std::unique_ptr
<SuggestionEdit
> m_xEdit2
;
265 std::unique_ptr
<SuggestionEdit
> m_xEdit3
;
266 std::unique_ptr
<SuggestionEdit
> m_xEdit4
;
267 std::unique_ptr
<weld::Widget
> m_xContents
;
268 std::unique_ptr
<weld::ScrolledWindow
> m_xScrollSB
;
269 std::unique_ptr
<weld::Button
> m_xNewPB
;
270 std::unique_ptr
<weld::Button
> m_xDeletePB
;
272 DECL_LINK( OriginalModifyHdl
, weld::ComboBox
&, void );
273 DECL_LINK( ScrollHdl
, weld::ScrolledWindow
&, void );
274 DECL_LINK( EditModifyHdl1
, weld::Entry
&, void );
275 DECL_LINK( EditModifyHdl2
, weld::Entry
&, void );
276 DECL_LINK( EditModifyHdl3
, weld::Entry
&, void );
277 DECL_LINK( EditModifyHdl4
, weld::Entry
&, void );
279 DECL_LINK( BookLBSelectHdl
, weld::ComboBox
&, void );
280 DECL_LINK( NewPBPushHdl
, weld::Button
&, void );
281 DECL_LINK( DeletePBPushHdl
, weld::Button
&, void );
283 void InitEditDictDialog(sal_uInt32 nSelDict
);
284 void UpdateOriginalLB();
285 void UpdateSuggestions();
286 void UpdateButtonStates();
288 void SetEditText( SuggestionEdit
& rEdit
, sal_uInt16 nEntryNum
);
289 void EditModify( const weld::Entry
* pEdit
, sal_uInt8 nEntryOffset
);
291 bool DeleteEntryFromDictionary( const css::uno::Reference
< css::linguistic2::XConversionDictionary
>& xDict
);
294 HangulHanjaEditDictDialog(weld::Window
* pParent
, HHDictList
& rDictList
, sal_uInt32 nSelDict
);
295 virtual ~HangulHanjaEditDictDialog() override
;
297 void UpdateScrollbar();
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */