xref: /aoo41x/main/cui/source/inc/hangulhanjadlg.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef SVX_HANGUL_HANJA_DLG_HXX
28 #define SVX_HANGUL_HANJA_DLG_HXX
29 
30 #include <vcl/dialog.hxx>
31 #include <vcl/button.hxx>
32 #include <vcl/lstbox.hxx>
33 #include <vcl/combobox.hxx>
34 #include <vcl/fixed.hxx>
35 #include <vcl/scrbar.hxx>
36 #include <svx/checklbx.hxx>
37 #include <editeng/hangulhanja.hxx>
38 #include <com/sun/star/uno/Sequence.hxx>
39 #include <editeng/unolingu.hxx>
40 #include <com/sun/star/linguistic2/XConversionDictionaryList.hpp>
41 #include <svtools/valueset.hxx>
42 
43 #include <vector>
44 #include <memory>	// for auto_ptr
45 
46 class SvxCommonLinguisticControl;
47 //.............................................................................
48 namespace svx
49 {
50 //.............................................................................
51 
52 	//=========================================================================
53 	//= HangulHanjaConversionDialog
54 	//=========================================================================
55 
56     class SuggestionSet : public ValueSet
57     {
58     public:
59         SuggestionSet( Window* pParent );
60         virtual ~SuggestionSet();
61 
62         virtual void    UserDraw( const UserDrawEvent& rUDEvt );
63         void            ClearSet();
64     };
65 
66     class SuggestionDisplay : public Control
67     {
68     public:
69         SuggestionDisplay( Window* pParent, const ResId& rResId );
70         virtual ~SuggestionDisplay();
71 
72         void DisplayListBox( bool bDisplayListBox );
73 
74         void SetSelectHdl( const Link& rLink );
75 
76         void Clear();
77         void InsertEntry( const XubString& rStr );
78         void SelectEntryPos( sal_uInt16 nPos );
79 
80         sal_uInt16 GetEntryCount() const;
81 
82         XubString GetEntry( sal_uInt16 nPos ) const;
83         XubString GetSelectEntry() const;
84 
85         virtual void StateChanged( StateChangedType nStateChange );
86 
87         virtual void KeyInput( const KeyEvent& rKEvt );
88         virtual void KeyUp( const KeyEvent& rKEvt );
89         virtual void Activate();
90         virtual void Deactivate();
91         virtual void GetFocus();
92         virtual void LoseFocus();
93         virtual void Command( const CommandEvent& rCEvt );
94 
95         DECL_LINK( SelectSuggestionHdl, Control* );
96 
97         void SetHelpIds();
98 
99     private:
100         void implUpdateDisplay();
101         Control& implGetCurrentControl();
102 
103     private:
104         bool          m_bDisplayListBox;//otherwise ValueSet
105         SuggestionSet m_aValueSet;
106         ListBox       m_aListBox;
107 
108         Link		  m_aSelectLink;
109         bool          m_bInSelectionUpdate;
110     };
111 
112 	class HangulHanjaConversionDialog : public  ModalDialog
113 	{
114 	private:
115 		::std::auto_ptr< SvxCommonLinguisticControl >
116 					m_pPlayground;					// order matters: before all other controls!
117 
118 		PushButton		m_aFind;
119         SuggestionDisplay   m_aSuggestions;
120 		FixedText		m_aFormat;
121 		RadioButton		m_aSimpleConversion;
122 		RadioButton		m_aHangulBracketed;
123 		RadioButton		m_aHanjaBracketed;
124 		::std::auto_ptr< RadioButton >	m_pHanjaAbove;
125 		::std::auto_ptr< RadioButton >	m_pHanjaBelow;
126 		::std::auto_ptr< RadioButton >	m_pHangulAbove;
127 		::std::auto_ptr< RadioButton >	m_pHangulBelow;
128 		FixedText		m_aConversion;
129 		CheckBox		m_aHangulOnly;
130 		CheckBox		m_aHanjaOnly;
131 		CheckBox		m_aReplaceByChar;
132 
133 		CheckBox*		m_pIgnoreNonPrimary;
134 		bool			m_bDocumentMode;
135 							// are we working for a document? This is normally true, but in case
136 							// the user uses the "find" functionality, we switch to working
137 							// with what the user entered, which then does not have any relation to
138 							// the document anymore. Some functionality must be disabled then
139 
140         Link			m_aOptionsChangedLink;
141         Link			m_aClickByCharacterLink;
142 
143 	public:
144         HangulHanjaConversionDialog(
145                 Window* _pParent,
146                 editeng::HangulHanjaConversion::ConversionDirection _ePrimaryDirection );
147 		~HangulHanjaConversionDialog( );
148 
149 	public:
150         void	SetOptionsChangedHdl( const Link& _rHdl );
151 		void	SetIgnoreHdl( const Link& _rHdl );
152 		void	SetIgnoreAllHdl( const Link& _rHdl );
153 		void	SetChangeHdl( const Link& _rHdl );
154 		void	SetChangeAllHdl( const Link& _rHdl );
155 
156 		void	SetClickByCharacterHdl( const Link& _rHdl );
157 		void	SetConversionFormatChangedHdl( const Link& _rHdl );
158 		void	SetFindHdl( const Link& _rHdl );
159 
160 		String	GetCurrentString( ) const;
161 		void	SetCurrentString(
162 					const String& _rNewString,
163 					const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rSuggestions,
164 					bool _bOriginatesFromDocument = true
165 				);
166 
167 		void	FocusSuggestion( );
168 
169 		// retrieves the current suggestion
170 		String	GetCurrentSuggestion( ) const;
171 
172         void        SetConversionFormat( editeng::HangulHanjaConversion::ConversionFormat _eType );
173         editeng::HangulHanjaConversion::ConversionFormat    GetConversionFormat( ) const;
174 
175 		void			SetByCharacter( sal_Bool _bByCharacter );
176 		void			SetConversionDirectionState( sal_Bool _bTryBothDirections, editeng::HangulHanjaConversion::ConversionDirection _ePrimaryConversionDirection );
177 
178 		// should text which does not match the primary conversion direction be ignored?
179 		sal_Bool		GetUseBothDirections( ) const;
180 
181 		// get current conversion direction to use
182 		// (return argument if GetUseBothDirections is true)
183 		editeng::HangulHanjaConversion::ConversionDirection	GetDirection( editeng::HangulHanjaConversion::ConversionDirection eDefaultDirection ) const;
184 
185         // enables or disbales the checkboxes for ruby formatted replacements
186         void            EnableRubySupport( sal_Bool bVal );
187 
188 	private:
189 		DECL_LINK( OnClose, void* );
190 		DECL_LINK( OnOption, void* );
191 		DECL_LINK( OnSuggestionModified, void* );
192 		DECL_LINK( OnSuggestionSelected, void* );
193 		DECL_LINK( OnConversionDirectionClicked, CheckBox* );
194         DECL_LINK( ClickByCharacterHdl, CheckBox* );
195 
196 		// fill the suggestion list box with suggestions for the actual input
197 		void FillSuggestions( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rSuggestions );
198 	};
199 
200 
201     typedef ::std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XConversionDictionary > > HHDictList;
202 
203 	class HangulHanjaOptionsDialog : public ModalDialog
204 	{
205 	private:
206 		FixedText			m_aUserdefdictFT;
207 		SvxCheckListBox		m_aDictsLB;
208 		FixedLine			m_aOptionsFL;
209 		CheckBox			m_aIgnorepostCB;
210 		CheckBox			m_aShowrecentlyfirstCB;
211 		CheckBox			m_aAutoreplaceuniqueCB;
212 		PushButton			m_aNewPB;
213 		PushButton			m_aEditPB;
214 		PushButton			m_aDeletePB;
215 		OKButton			m_aOkPB;
216 		CancelButton		m_aCancelPB;
217 		HelpButton			m_aHelpPB;
218 
219 		SvLBoxButtonData*	m_pCheckButtonData;
220 
221 		HHDictList			m_aDictList;
222         ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XConversionDictionaryList > m_xConversionDictionaryList;
223 
224 		DECL_LINK( OkHdl, void* );
225 		DECL_LINK( OnNew, void* );
226 		DECL_LINK( OnEdit, void* );
227 		DECL_LINK( OnDelete, void* );
228 		DECL_LINK( DictsLB_SelectHdl, void* );
229 		DECL_LINK( NewDictHdl, void* );
230 		DECL_LINK( EditDictHdl, void* );
231 		DECL_LINK( DeleteDictHdl, void* );
232 
233 		void				Init( void );		// reads settings from core and init controls
234 	public:
235 							HangulHanjaOptionsDialog( Window* _pParent );
236 		virtual				~HangulHanjaOptionsDialog();
237 
238 		void				AddDict( const String& _rName, bool _bChecked );
239 	};
240 
241 
242 	class HangulHanjaNewDictDialog : public ModalDialog
243 	{
244 	private:
245 		FixedLine			m_aNewDictFL;
246 		FixedText			m_aDictNameFT;
247 		Edit				m_aDictNameED;
248 		OKButton			m_aOkBtn;
249 		CancelButton		m_aCancelBtn;
250 		HelpButton			m_aHelpBtn;
251 
252 		bool				m_bEntered;
253 
254 		DECL_LINK( OKHdl, void* );
255 		DECL_LINK( ModifyHdl, void* );
256 	protected:
257 	public:
258 							HangulHanjaNewDictDialog( Window* _pParent );
259 		virtual				~HangulHanjaNewDictDialog();
260 
261 		bool				GetName( String& _rRetName ) const;
262 	};
263 
264 
265 	class SuggestionList;
266 
267 	class SuggestionEdit : public Edit
268 	{
269 	private:
270 		SuggestionEdit*		m_pPrev;
271 		SuggestionEdit*		m_pNext;
272 		ScrollBar&			m_rScrollBar;
273 
274 		bool				ShouldScroll( bool _bUp ) const;
275 		void				DoJump( bool _bUp );
276 	public:
277 							SuggestionEdit( Window* pParent, const ResId& rResId,
278 									ScrollBar& _rScrollBar,
279 									SuggestionEdit* _pPrev, SuggestionEdit* _pNext );
280 		virtual				~SuggestionEdit();
281 		virtual long		PreNotify( NotifyEvent& rNEvt );
282 	};
283 
284 
285 	class HangulHanjaEditDictDialog : public ModalDialog
286 	{
287 	private:
288 		const String	m_aEditHintText;
289 		HHDictList&		m_rDictList;
290 		sal_uInt32		m_nCurrentDict;
291 
292 		String			m_aOriginal;
293 		SuggestionList*	m_pSuggestions;
294 
295 		FixedText		m_aBookFT;
296 		ListBox			m_aBookLB;
297 		FixedText		m_aOriginalFT;
298 		ComboBox		m_aOriginalLB;
299 		FixedText		m_aSuggestionsFT;
300 		SuggestionEdit	m_aEdit1;
301 		SuggestionEdit	m_aEdit2;
302 		SuggestionEdit	m_aEdit3;
303 		SuggestionEdit	m_aEdit4;
304 		ScrollBar		m_aScrollSB;
305 		PushButton		m_aNewPB;
306 		PushButton		m_aDeletePB;
307 		HelpButton		m_aHelpPB;
308 		CancelButton	m_aClosePB;
309 
310         sal_uInt16		m_nTopPos;
311         bool            m_bModifiedSuggestions;
312 		bool			m_bModifiedOriginal;
313 
314 		DECL_LINK( OriginalModifyHdl, void* );
315 		DECL_LINK( ScrollHdl, void* );
316 		DECL_LINK( EditModifyHdl1, Edit* );
317 		DECL_LINK( EditModifyHdl2, Edit* );
318 		DECL_LINK( EditModifyHdl3, Edit* );
319 		DECL_LINK( EditModifyHdl4, Edit* );
320 
321 		DECL_LINK( BookLBSelectHdl, void* );
322 		DECL_LINK( NewPBPushHdl, void* );
323 		DECL_LINK( DeletePBPushHdl, void* );
324 
325 		void			InitEditDictDialog( sal_uInt32 _nSelDict );
326 		void			UpdateOriginalLB( void );
327 		void			UpdateSuggestions( void );
328 		void            UpdateButtonStates();
329 
330 		void			SetEditText( Edit& _rEdit, sal_uInt16 _nEntryNum );
331 		void			EditModify( Edit* _pEdit, sal_uInt8 _nEntryOffset );
332 		void			EditFocusLost( Edit* _pEdit, sal_uInt8 _nEntryOffset );
333 
334 		bool			DeleteEntryFromDictionary( const ::rtl::OUString& rEntry, const ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XConversionDictionary >& xDict );
335 
336 	public:
337 						HangulHanjaEditDictDialog( Window* _pParent, HHDictList& _rDictList, sal_uInt32 _nSelDict );
338 						~HangulHanjaEditDictDialog();
339 
340 		void			UpdateScrollbar( void );
341 	};
342 
343 //.............................................................................
344 }	// namespace svx
345 //.............................................................................
346 
347 #endif // SVX_HANGUL_HANJA_HXX
348