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