1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_editeng.hxx"
30*cdf0e10cSrcweir #include <editeng/hangulhanja.hxx>
31*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
32*cdf0e10cSrcweir #include <vcl/button.hxx>
33*cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
34*cdf0e10cSrcweir #include <unotools/linguprops.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <set>
37*cdf0e10cSrcweir #include <map>
38*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
39*cdf0e10cSrcweir #include <com/sun/star/i18n/XBreakIterator.hpp>
40*cdf0e10cSrcweir #include <com/sun/star/i18n/ScriptType.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/i18n/UnicodeScript.hpp>
42*cdf0e10cSrcweir #include <com/sun/star/i18n/XTextConversion.hpp>
43*cdf0e10cSrcweir #include <com/sun/star/i18n/XExtendedTextConversion.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionType.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionOption.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/i18n/WordType.hpp>
47*cdf0e10cSrcweir #include <vcl/stdtext.hxx>
48*cdf0e10cSrcweir #include <unotools/charclass.hxx>
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <editeng/edtdlg.hxx>
51*cdf0e10cSrcweir #include <editeng/editrids.hrc>
52*cdf0e10cSrcweir #include <editeng/unolingu.hxx>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #define HHC HangulHanjaConversion
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //.............................................................................
57*cdf0e10cSrcweir namespace editeng
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir //.............................................................................
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
62*cdf0e10cSrcweir 	using namespace ::com::sun::star::i18n;
63*cdf0e10cSrcweir     using namespace ::com::sun::star::i18n::TextConversionOption;
64*cdf0e10cSrcweir     using namespace ::com::sun::star::i18n::TextConversionType;
65*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
66*cdf0e10cSrcweir /*
67*cdf0e10cSrcweir 	using HangulHanjaConversion::ReplacementAction;
68*cdf0e10cSrcweir 	using HangulHanjaConversion::eExchange;
69*cdf0e10cSrcweir 	using HangulHanjaConversion::eReplacementBracketed;
70*cdf0e10cSrcweir 	using HangulHanjaConversion::eOriginalBracketed;
71*cdf0e10cSrcweir 	using HangulHanjaConversion::eReplacementAbove;
72*cdf0e10cSrcweir 	using HangulHanjaConversion::eOriginalAbove;
73*cdf0e10cSrcweir 	using HangulHanjaConversion::eReplacementBelow;
74*cdf0e10cSrcweir 	using HangulHanjaConversion::eOriginalBelow;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	using HangulHanjaConversion::eHangulToHanja;
77*cdf0e10cSrcweir 	using HangulHanjaConversion::eHanjaToHangul;
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	using HangulHanjaConversion::eSimpleConversion;
80*cdf0e10cSrcweir 	using HangulHanjaConversion::eHangulBracketed;
81*cdf0e10cSrcweir 	using HangulHanjaConversion::eHanjaBracketed;
82*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHanjaAbove;
83*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHanjaBelow;
84*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHangulAbove;
85*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHangulBelow;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	using ::com::sun::star::i18n::TextConversionType::TO_HANJA;
88*cdf0e10cSrcweir 	using ::com::sun::star::i18n::TextConversionType::TO_HANGUL;
89*cdf0e10cSrcweir 	using ::com::sun::star::i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
90*cdf0e10cSrcweir 	using ::com::sun::star::i18n::TextConversionOption::NONE;
91*cdf0e10cSrcweir */
92*cdf0e10cSrcweir 	//=========================================================================
93*cdf0e10cSrcweir 	//= HangulHanjaConversion_Impl
94*cdf0e10cSrcweir 	//=========================================================================
95*cdf0e10cSrcweir     //using HangulHanjaConversion::ConversionFormat;
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 	class HangulHanjaConversion_Impl
98*cdf0e10cSrcweir 	{
99*cdf0e10cSrcweir 	private:
100*cdf0e10cSrcweir 		typedef	::std::set< ::rtl::OUString, ::std::less< ::rtl::OUString > >					StringBag;
101*cdf0e10cSrcweir 		typedef ::std::map< ::rtl::OUString, ::rtl::OUString, ::std::less< ::rtl::OUString > >	StringMap;
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	private:
104*cdf0e10cSrcweir         StringBag               m_sIgnoreList;
105*cdf0e10cSrcweir         StringMap               m_aChangeList;
106*cdf0e10cSrcweir         static StringMap        m_aRecentlyUsedList;
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 		// general
109*cdf0e10cSrcweir 		AbstractHangulHanjaConversionDialog* //CHINA001 HangulHanjaConversionDialog*
110*cdf0e10cSrcweir 								m_pConversionDialog;	// the dialog to display for user interaction
111*cdf0e10cSrcweir 		Window*					m_pUIParent;			// the parent window for any UI we raise
112*cdf0e10cSrcweir 		Reference< XMultiServiceFactory >
113*cdf0e10cSrcweir 								m_xORB;					// the service factory to use
114*cdf0e10cSrcweir 		Reference< XTextConversion >
115*cdf0e10cSrcweir 								m_xConverter;			// the text conversion service
116*cdf0e10cSrcweir         Locale                  m_aSourceLocale;        // the locale we're working with
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir         // additions for Chinese simplified / traditional conversion
119*cdf0e10cSrcweir 		HHC::ConversionType     m_eConvType;		// conversion type (Hangul/Hanja, simplified/traditional Chinese,...)
120*cdf0e10cSrcweir 		LanguageType            m_nSourceLang;      // just a 'copy' of m_aSourceLocale in order in order to
121*cdf0e10cSrcweir                                                     // save the applications from always converting to this
122*cdf0e10cSrcweir                                                     // type in their implementations
123*cdf0e10cSrcweir         LanguageType            m_nTargetLang;      // target language of new replacement text
124*cdf0e10cSrcweir         const Font*             m_pTargetFont;      // target font of new replacement text
125*cdf0e10cSrcweir         sal_Int32               m_nConvOptions;     // text conversion options (as used by 'getConversions')
126*cdf0e10cSrcweir         sal_Bool                m_bIsInteractive;   // specifies if the conversion requires user interaction
127*cdf0e10cSrcweir                                                     // (and likeley a specialised dialog) or if it is to run
128*cdf0e10cSrcweir                                                     // automatically without any user interaction.
129*cdf0e10cSrcweir                                                     // True for Hangul / Hanja conversion
130*cdf0e10cSrcweir                                                     // False for Chinese simlified / traditional conversion
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 		HangulHanjaConversion*	m_pAntiImpl;			// our "anti-impl" instance
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 		// options
135*cdf0e10cSrcweir         sal_Bool                    m_bByCharacter;                 // are we in "by character" mode currently?
136*cdf0e10cSrcweir         HHC::ConversionFormat       m_eConversionFormat;            // the current format for the conversion
137*cdf0e10cSrcweir         HHC::ConversionDirection    m_ePrimaryConversionDirection;  // the primary conversion direction
138*cdf0e10cSrcweir         HHC::ConversionDirection    m_eCurrentConversionDirection;  // the primary conversion direction
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir         //options from Hangul/Hanja Options dialog (also saved to configuration)
141*cdf0e10cSrcweir         bool                    m_bIgnorePostPositionalWord;
142*cdf0e10cSrcweir         bool                    m_bShowRecentlyUsedFirst;
143*cdf0e10cSrcweir         bool                    m_bAutoReplaceUnique;
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 		// state
146*cdf0e10cSrcweir         ::rtl::OUString                m_sCurrentPortion;      // the text which we are currently working on
147*cdf0e10cSrcweir         LanguageType            m_nCurrentPortionLang;  // language of m_sCurrentPortion found
148*cdf0e10cSrcweir 		sal_Int32				m_nCurrentStartIndex;	// the start index within m_sCurrentPortion of the current convertible portion
149*cdf0e10cSrcweir 		sal_Int32				m_nCurrentEndIndex;		// the end index (excluding) within m_sCurrentPortion of the current convertible portion
150*cdf0e10cSrcweir 		sal_Int32				m_nReplacementBaseIndex;// index which ReplaceUnit-calls need to be relative to
151*cdf0e10cSrcweir         sal_Int32               m_nCurrentConversionOption;
152*cdf0e10cSrcweir         sal_Int16               m_nCurrentConversionType;
153*cdf0e10cSrcweir         Sequence< ::rtl::OUString >
154*cdf0e10cSrcweir 								m_aCurrentSuggestions;	// the suggestions for the current unit
155*cdf0e10cSrcweir 														// (means for the text [m_nCurrentStartIndex, m_nCurrentEndIndex) in m_sCurrentPortion)
156*cdf0e10cSrcweir         sal_Bool                m_bTryBothDirections;   // specifies if other conversion directions should be tried when looking for convertible characters
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 	public:
160*cdf0e10cSrcweir 		HangulHanjaConversion_Impl(
161*cdf0e10cSrcweir 			Window* _pUIParent,
162*cdf0e10cSrcweir 			const Reference< XMultiServiceFactory >& _rxORB,
163*cdf0e10cSrcweir             const Locale& _rSourceLocale,
164*cdf0e10cSrcweir             const Locale& _rTargetLocale,
165*cdf0e10cSrcweir             const Font* _pTargetFont,
166*cdf0e10cSrcweir             sal_Int32 _nConvOptions,
167*cdf0e10cSrcweir             sal_Bool _bIsInteractive,
168*cdf0e10cSrcweir 			HangulHanjaConversion* _pAntiImpl );
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 	public:
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 		static void			SetUseSavedConversionDirectionState( sal_Bool bVal );
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 				void		DoDocumentConversion( );
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 		inline	sal_Bool	IsByCharacter( ) const { return m_bByCharacter; }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 		inline	sal_Bool	IsValid() const { return m_xConverter.is(); }
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir         inline LanguageType GetSourceLang() const   { return m_nSourceLang; }
181*cdf0e10cSrcweir         inline LanguageType GetTargetLang() const   { return m_nTargetLang; }
182*cdf0e10cSrcweir         inline const Font * GetTargetFont() const   { return m_pTargetFont; }
183*cdf0e10cSrcweir         inline sal_Int32    GetConvOptions() const  { return m_nConvOptions; }
184*cdf0e10cSrcweir         inline sal_Bool     IsInteractive() const   { return m_bIsInteractive; }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 	protected:
187*cdf0e10cSrcweir 		void	createDialog();
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 		/** continue with the conversion, return <TRUE/> if and only if the complete conversion is done
190*cdf0e10cSrcweir 			@param _bRepeatCurrentUnit
191*cdf0e10cSrcweir 				if <TRUE/>, an implNextConvertible will be called initially to advance to the next convertible.
192*cdf0e10cSrcweir 				if <FALSE/>, the method will initially work with the current convertible unit
193*cdf0e10cSrcweir 		*/
194*cdf0e10cSrcweir 		sal_Bool ContinueConversion( bool _bRepeatCurrentUnit );
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 	private:
197*cdf0e10cSrcweir         DECL_LINK( OnOptionsChanged, void* );
198*cdf0e10cSrcweir 		DECL_LINK( OnIgnore, void* );
199*cdf0e10cSrcweir 		DECL_LINK( OnIgnoreAll, void* );
200*cdf0e10cSrcweir 		DECL_LINK( OnChange, void* );
201*cdf0e10cSrcweir 		DECL_LINK( OnChangeAll, void* );
202*cdf0e10cSrcweir 		DECL_LINK( OnByCharClicked, CheckBox* );
203*cdf0e10cSrcweir 		DECL_LINK( OnConversionTypeChanged, void* );
204*cdf0e10cSrcweir 		DECL_LINK( OnFind, void* );
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 		/** proceed, after the current convertible has been handled
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 			<p><b>Attention:</b>
209*cdf0e10cSrcweir 				When returning from this method, the dialog may have been deleted!</p>
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 			@param _bRepeatCurrentUnit
212*cdf0e10cSrcweir 				will be passed to the <member>ContinueConversion</member> call
213*cdf0e10cSrcweir 		*/
214*cdf0e10cSrcweir 		void	implProceed( bool _bRepeatCurrentUnit );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 		// change the current convertible, and do _not_ proceed
217*cdf0e10cSrcweir 		void	implChange( const ::rtl::OUString& _rChangeInto );
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 		/** find the next convertible piece of text, with possibly advancing to the next portion
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 			@see HangulHanjaConversion::GetNextPortion
222*cdf0e10cSrcweir 		*/
223*cdf0e10cSrcweir 		sal_Bool	implNextConvertible( bool _bRepeatUnit );
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 		/** find the next convertible unit within the current portion
226*cdf0e10cSrcweir 			@param _bRepeatUnit
227*cdf0e10cSrcweir 				if <TRUE/>, the search will start at the beginning of the current unit,
228*cdf0e10cSrcweir 				if <FALSE/>, it will start at the end of the current unit
229*cdf0e10cSrcweir 		*/
230*cdf0e10cSrcweir 		bool		implNextConvertibleUnit( const sal_Int32 _nStartAt );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 		/** retrieves the next portion, with setting the index members properly
233*cdf0e10cSrcweir 			@return
234*cdf0e10cSrcweir 				<TRUE/> if and only if there is a next portion
235*cdf0e10cSrcweir 		*/
236*cdf0e10cSrcweir 		bool		implRetrieveNextPortion( );
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 		/** determine the ConversionDirection for m_sCurrentPortion
239*cdf0e10cSrcweir 			@return
240*cdf0e10cSrcweir 				<FALSE/> if and only if something went wrong
241*cdf0e10cSrcweir 		*/
242*cdf0e10cSrcweir 		bool		implGetConversionDirectionForCurrentPortion( HHC::ConversionDirection& rDirection );
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir         /** member m_aCurrentSuggestions and m_nCurrentEndIndex are updated according to the other settings and current dictionaries
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir             if _bAllowSearchNextConvertibleText is true _nStartAt is used as starting point to search the next
247*cdf0e10cSrcweir             convertible text portion. This may result in changing of the member m_nCurrentStartIndex additionally.
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir             @return
250*cdf0e10cSrcweir 				<TRUE/> if Suggestions were found
251*cdf0e10cSrcweir         */
252*cdf0e10cSrcweir         bool        implUpdateSuggestions( const bool _bAllowSearchNextConvertibleText=false, const sal_Int32 _nStartAt=-1 );
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir         /** reads the options from Hangul/Hanja Options dialog that are saved to configuration
255*cdf0e10cSrcweir         */
256*cdf0e10cSrcweir         void implReadOptionsFromConfiguration();
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir         /** get the string currently considered to be replaced or ignored
259*cdf0e10cSrcweir         */
260*cdf0e10cSrcweir         ::rtl::OUString GetCurrentUnit() const;
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir         /** read options from configuration, update suggestion list and dialog content
263*cdf0e10cSrcweir         */
264*cdf0e10cSrcweir         void implUpdateData();
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir         /** get the conversion direction dependent from m_eConvType and m_eCurrentConversionDirection
267*cdf0e10cSrcweir             in case of switching the direction is allowed this can be triggered with parameter bSwitchDirection
268*cdf0e10cSrcweir         */
269*cdf0e10cSrcweir         sal_Int16 implGetConversionType( bool bSwitchDirection=false ) const;
270*cdf0e10cSrcweir 	};
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	//=========================================================================
273*cdf0e10cSrcweir 	//= HangulHanjaConversion_Impl
274*cdf0e10cSrcweir 	//=========================================================================
275*cdf0e10cSrcweir     //-------------------------------------------------------------------------
276*cdf0e10cSrcweir     // static member initialization
277*cdf0e10cSrcweir     HangulHanjaConversion_Impl::StringMap HangulHanjaConversion_Impl::m_aRecentlyUsedList = HangulHanjaConversion_Impl::StringMap();
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
280*cdf0e10cSrcweir 	HangulHanjaConversion_Impl::HangulHanjaConversion_Impl( Window* _pUIParent,
281*cdf0e10cSrcweir         const Reference< XMultiServiceFactory >& _rxORB,
282*cdf0e10cSrcweir         const Locale& _rSourceLocale,
283*cdf0e10cSrcweir         const Locale& _rTargetLocale,
284*cdf0e10cSrcweir         const Font* _pTargetFont,
285*cdf0e10cSrcweir         sal_Int32 _nOptions,
286*cdf0e10cSrcweir         sal_Bool _bIsInteractive,
287*cdf0e10cSrcweir         HangulHanjaConversion* _pAntiImpl )
288*cdf0e10cSrcweir : m_pConversionDialog( NULL )
289*cdf0e10cSrcweir , m_pUIParent( _pUIParent )
290*cdf0e10cSrcweir , m_xORB( _rxORB )
291*cdf0e10cSrcweir , m_aSourceLocale( _rSourceLocale )
292*cdf0e10cSrcweir , m_nSourceLang( SvxLocaleToLanguage( _rSourceLocale ) )
293*cdf0e10cSrcweir , m_nTargetLang( SvxLocaleToLanguage( _rTargetLocale ) )
294*cdf0e10cSrcweir , m_pTargetFont( _pTargetFont )
295*cdf0e10cSrcweir , m_bIsInteractive( _bIsInteractive )
296*cdf0e10cSrcweir , m_pAntiImpl( _pAntiImpl )
297*cdf0e10cSrcweir , m_nCurrentPortionLang( LANGUAGE_NONE )
298*cdf0e10cSrcweir , m_nCurrentStartIndex( 0 )
299*cdf0e10cSrcweir , m_nCurrentEndIndex( 0 )
300*cdf0e10cSrcweir , m_nReplacementBaseIndex( 0 )
301*cdf0e10cSrcweir , m_nCurrentConversionOption( TextConversionOption::NONE )
302*cdf0e10cSrcweir , m_nCurrentConversionType( -1 ) // not yet known
303*cdf0e10cSrcweir , m_bTryBothDirections( sal_True )
304*cdf0e10cSrcweir 	{
305*cdf0e10cSrcweir         implReadOptionsFromConfiguration();
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 		DBG_ASSERT( m_xORB.is(), "HangulHanjaConversion_Impl::HangulHanjaConversion_Impl: no ORB!" );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 		// determine conversion type
310*cdf0e10cSrcweir 		if (m_nSourceLang == LANGUAGE_KOREAN && m_nTargetLang == LANGUAGE_KOREAN)
311*cdf0e10cSrcweir             m_eConvType = HHC::eConvHangulHanja;
312*cdf0e10cSrcweir 		else if ( (m_nSourceLang == LANGUAGE_CHINESE_TRADITIONAL && m_nTargetLang == LANGUAGE_CHINESE_SIMPLIFIED)  ||
313*cdf0e10cSrcweir 				 (m_nSourceLang == LANGUAGE_CHINESE_SIMPLIFIED  && m_nTargetLang == LANGUAGE_CHINESE_TRADITIONAL) )
314*cdf0e10cSrcweir             m_eConvType = HHC::eConvSimplifiedTraditional;
315*cdf0e10cSrcweir 		else
316*cdf0e10cSrcweir 		{
317*cdf0e10cSrcweir 			DBG_ERROR( "failed to determine conversion type from languages" );
318*cdf0e10cSrcweir 		}
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir 		// set remaining conversion parameters to their default values
321*cdf0e10cSrcweir 		m_nConvOptions		= _nOptions;
322*cdf0e10cSrcweir 		m_bByCharacter		= 0 != (_nOptions & CHARACTER_BY_CHARACTER);
323*cdf0e10cSrcweir         m_eConversionFormat = HHC::eSimpleConversion;
324*cdf0e10cSrcweir         m_ePrimaryConversionDirection = HHC::eHangulToHanja;	// used for eConvHangulHanja
325*cdf0e10cSrcweir         m_eCurrentConversionDirection = HHC::eHangulToHanja;	// used for eConvHangulHanja
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 		if ( m_xORB.is() )
328*cdf0e10cSrcweir 		{
329*cdf0e10cSrcweir 			::rtl::OUString sTextConversionService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.i18n.TextConversion" ) );
330*cdf0e10cSrcweir 			m_xConverter = m_xConverter.query( m_xORB->createInstance( sTextConversionService ) );
331*cdf0e10cSrcweir 			if ( !m_xConverter.is() )
332*cdf0e10cSrcweir 				ShowServiceNotAvailableError( m_pUIParent, sTextConversionService, sal_True );
333*cdf0e10cSrcweir 		}
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir 	}
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
338*cdf0e10cSrcweir 	void HangulHanjaConversion_Impl::createDialog()
339*cdf0e10cSrcweir 	{
340*cdf0e10cSrcweir 		DBG_ASSERT( m_bIsInteractive, "createDialog when the conversion should not be interactive?" );
341*cdf0e10cSrcweir 		if ( m_bIsInteractive && !m_pConversionDialog )
342*cdf0e10cSrcweir 		{
343*cdf0e10cSrcweir 			EditAbstractDialogFactory* pFact = EditAbstractDialogFactory::Create();
344*cdf0e10cSrcweir 			if(pFact)
345*cdf0e10cSrcweir 			{
346*cdf0e10cSrcweir 				m_pConversionDialog = pFact->CreateHangulHanjaConversionDialog(m_pUIParent, m_ePrimaryConversionDirection );
347*cdf0e10cSrcweir 				DBG_ASSERT(m_pConversionDialog, "Dialogdiet fail!");//CHINA001
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir                 m_pConversionDialog->EnableRubySupport( m_pAntiImpl->HasRubySupport() );
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir 				m_pConversionDialog->SetByCharacter( m_bByCharacter );
352*cdf0e10cSrcweir 				m_pConversionDialog->SetConversionFormat( m_eConversionFormat );
353*cdf0e10cSrcweir                 m_pConversionDialog->SetConversionDirectionState( m_bTryBothDirections, m_ePrimaryConversionDirection );
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 				// the handlers
356*cdf0e10cSrcweir                 m_pConversionDialog->SetOptionsChangedHdl( LINK( this, HangulHanjaConversion_Impl, OnOptionsChanged ) );
357*cdf0e10cSrcweir 				m_pConversionDialog->SetIgnoreHdl( LINK( this, HangulHanjaConversion_Impl, OnIgnore ) );
358*cdf0e10cSrcweir 				m_pConversionDialog->SetIgnoreAllHdl( LINK( this, HangulHanjaConversion_Impl, OnIgnoreAll ) );
359*cdf0e10cSrcweir 				m_pConversionDialog->SetChangeHdl( LINK( this, HangulHanjaConversion_Impl, OnChange ) );
360*cdf0e10cSrcweir 				m_pConversionDialog->SetChangeAllHdl( LINK( this, HangulHanjaConversion_Impl, OnChangeAll ) );
361*cdf0e10cSrcweir 				m_pConversionDialog->SetClickByCharacterHdl( LINK( this, HangulHanjaConversion_Impl, OnByCharClicked ) );
362*cdf0e10cSrcweir 				m_pConversionDialog->SetConversionFormatChangedHdl( LINK( this, HangulHanjaConversion_Impl, OnConversionTypeChanged ) );
363*cdf0e10cSrcweir 				m_pConversionDialog->SetFindHdl( LINK( this, HangulHanjaConversion_Impl, OnFind ) );
364*cdf0e10cSrcweir 			}
365*cdf0e10cSrcweir 		}
366*cdf0e10cSrcweir 	}
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir     //-------------------------------------------------------------------------
369*cdf0e10cSrcweir     sal_Int16 HangulHanjaConversion_Impl::implGetConversionType( bool bSwitchDirection ) const
370*cdf0e10cSrcweir     {
371*cdf0e10cSrcweir         sal_Int16 nConversionType = -1;
372*cdf0e10cSrcweir         if (m_eConvType == HHC::eConvHangulHanja)
373*cdf0e10cSrcweir             nConversionType = HHC::eHangulToHanja == ( m_eCurrentConversionDirection && !bSwitchDirection ) ? TO_HANJA : TO_HANGUL;
374*cdf0e10cSrcweir         else if (m_eConvType == HHC::eConvSimplifiedTraditional)
375*cdf0e10cSrcweir             nConversionType = LANGUAGE_CHINESE_SIMPLIFIED == m_nTargetLang ? TO_SCHINESE : TO_TCHINESE;
376*cdf0e10cSrcweir         DBG_ASSERT( nConversionType != -1, "unexpected conversion type" );
377*cdf0e10cSrcweir         return nConversionType;
378*cdf0e10cSrcweir     }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir     //-------------------------------------------------------------------------
381*cdf0e10cSrcweir     bool HangulHanjaConversion_Impl::implUpdateSuggestions( bool _bAllowSearchNextConvertibleText, const sal_Int32 _nStartAt )
382*cdf0e10cSrcweir     {
383*cdf0e10cSrcweir         // parameters for the converter
384*cdf0e10cSrcweir         sal_Int32 nStartSearch = m_nCurrentStartIndex;
385*cdf0e10cSrcweir         if( _bAllowSearchNextConvertibleText )
386*cdf0e10cSrcweir             nStartSearch = _nStartAt;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir         sal_Int32 nLength = m_sCurrentPortion.getLength() - nStartSearch;
389*cdf0e10cSrcweir         m_nCurrentConversionType = implGetConversionType();
390*cdf0e10cSrcweir         m_nCurrentConversionOption = IsByCharacter() ? CHARACTER_BY_CHARACTER : NONE;
391*cdf0e10cSrcweir         if( m_bIgnorePostPositionalWord )
392*cdf0e10cSrcweir             m_nCurrentConversionOption = m_nCurrentConversionOption | IGNORE_POST_POSITIONAL_WORD;
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir 		// no need to check both directions for chinese conversion (saves time)
395*cdf0e10cSrcweir 		if (m_eConvType == HHC::eConvSimplifiedTraditional)
396*cdf0e10cSrcweir 			m_bTryBothDirections = sal_False;
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir         sal_Bool bFoundAny = sal_True;
399*cdf0e10cSrcweir 		try
400*cdf0e10cSrcweir 		{
401*cdf0e10cSrcweir 			TextConversionResult aResult = m_xConverter->getConversions(
402*cdf0e10cSrcweir 				m_sCurrentPortion,
403*cdf0e10cSrcweir 				nStartSearch,
404*cdf0e10cSrcweir 				nLength,
405*cdf0e10cSrcweir                 m_aSourceLocale,
406*cdf0e10cSrcweir                 m_nCurrentConversionType,
407*cdf0e10cSrcweir                 m_nCurrentConversionOption
408*cdf0e10cSrcweir 			);
409*cdf0e10cSrcweir             sal_Bool bFoundPrimary = aResult.Boundary.startPos < aResult.Boundary.endPos;
410*cdf0e10cSrcweir 			bFoundAny = bFoundPrimary;
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 			if ( m_bTryBothDirections )
413*cdf0e10cSrcweir 			{	// see if we find another convertible when assuming the other direction
414*cdf0e10cSrcweir 				TextConversionResult aSecondResult = m_xConverter->getConversions(
415*cdf0e10cSrcweir 					m_sCurrentPortion,
416*cdf0e10cSrcweir 					nStartSearch,
417*cdf0e10cSrcweir 					nLength,
418*cdf0e10cSrcweir                     m_aSourceLocale,
419*cdf0e10cSrcweir                     implGetConversionType( true ), // switched!
420*cdf0e10cSrcweir                     m_nCurrentConversionOption
421*cdf0e10cSrcweir 				);
422*cdf0e10cSrcweir 				if ( aSecondResult.Boundary.startPos < aSecondResult.Boundary.endPos )
423*cdf0e10cSrcweir 				{	// we indeed found such a convertible
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir 					// in case the first attempt (with the original conversion direction)
426*cdf0e10cSrcweir 					// didn't find anything
427*cdf0e10cSrcweir 					if	(	!bFoundPrimary
428*cdf0e10cSrcweir 						// or if the second location is _before_ the first one
429*cdf0e10cSrcweir 						||	( aSecondResult.Boundary.startPos < aResult.Boundary.startPos )
430*cdf0e10cSrcweir 						)
431*cdf0e10cSrcweir 					{
432*cdf0e10cSrcweir 						// then use the second finding
433*cdf0e10cSrcweir 						aResult = aSecondResult;
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 						// our current conversion direction changed now
436*cdf0e10cSrcweir                         m_eCurrentConversionDirection = ( HHC::eHangulToHanja == m_eCurrentConversionDirection )
437*cdf0e10cSrcweir                             ? HHC::eHanjaToHangul : HHC::eHangulToHanja;
438*cdf0e10cSrcweir 						bFoundAny = sal_True;
439*cdf0e10cSrcweir 					}
440*cdf0e10cSrcweir 				}
441*cdf0e10cSrcweir 			}
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir             if( _bAllowSearchNextConvertibleText )
444*cdf0e10cSrcweir             {
445*cdf0e10cSrcweir                 //this might change the current position
446*cdf0e10cSrcweir 			    m_aCurrentSuggestions = aResult.Candidates;
447*cdf0e10cSrcweir 			    m_nCurrentStartIndex = aResult.Boundary.startPos;
448*cdf0e10cSrcweir 			    m_nCurrentEndIndex = aResult.Boundary.endPos;
449*cdf0e10cSrcweir             }
450*cdf0e10cSrcweir             else
451*cdf0e10cSrcweir             {
452*cdf0e10cSrcweir                 //the change of starting position is not allowed
453*cdf0e10cSrcweir                 if( m_nCurrentStartIndex == aResult.Boundary.startPos
454*cdf0e10cSrcweir                     && aResult.Boundary.endPos != aResult.Boundary.startPos )
455*cdf0e10cSrcweir                 {
456*cdf0e10cSrcweir                     m_aCurrentSuggestions = aResult.Candidates;
457*cdf0e10cSrcweir                     m_nCurrentEndIndex = aResult.Boundary.endPos;
458*cdf0e10cSrcweir                 }
459*cdf0e10cSrcweir                 else
460*cdf0e10cSrcweir                 {
461*cdf0e10cSrcweir                     m_aCurrentSuggestions.realloc( 0 );
462*cdf0e10cSrcweir                     if( m_sCurrentPortion.getLength() >= m_nCurrentStartIndex+1 )
463*cdf0e10cSrcweir                         m_nCurrentEndIndex = m_nCurrentStartIndex+1;
464*cdf0e10cSrcweir                 }
465*cdf0e10cSrcweir             }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir             //put recently used string to front:
468*cdf0e10cSrcweir             if( m_bShowRecentlyUsedFirst && m_aCurrentSuggestions.getLength()>1 )
469*cdf0e10cSrcweir             {
470*cdf0e10cSrcweir                 ::rtl::OUString sCurrentUnit( GetCurrentUnit() );
471*cdf0e10cSrcweir                 StringMap::const_iterator aRecentlyUsed = m_aRecentlyUsedList.find( sCurrentUnit );
472*cdf0e10cSrcweir                 bool bUsedBefore = aRecentlyUsed != m_aRecentlyUsedList.end();
473*cdf0e10cSrcweir                 if( bUsedBefore && m_aCurrentSuggestions[0] != aRecentlyUsed->second )
474*cdf0e10cSrcweir                 {
475*cdf0e10cSrcweir                     sal_Int32 nCount = m_aCurrentSuggestions.getLength();
476*cdf0e10cSrcweir                     Sequence< ::rtl::OUString > aTmp(nCount);
477*cdf0e10cSrcweir                     aTmp[0]=aRecentlyUsed->second;
478*cdf0e10cSrcweir                     sal_Int32 nDiff = 1;
479*cdf0e10cSrcweir                     for( sal_Int32 n=1; n<nCount; n++)//we had 0 already
480*cdf0e10cSrcweir                     {
481*cdf0e10cSrcweir                         if( nDiff && m_aCurrentSuggestions[n-nDiff]==aRecentlyUsed->second )
482*cdf0e10cSrcweir                             nDiff=0;
483*cdf0e10cSrcweir                         aTmp[n]=m_aCurrentSuggestions[n-nDiff];
484*cdf0e10cSrcweir                     }
485*cdf0e10cSrcweir                     m_aCurrentSuggestions = aTmp;
486*cdf0e10cSrcweir                 }
487*cdf0e10cSrcweir             }
488*cdf0e10cSrcweir 		}
489*cdf0e10cSrcweir 		catch( const Exception& )
490*cdf0e10cSrcweir 		{
491*cdf0e10cSrcweir 			DBG_ERROR( "HangulHanjaConversion_Impl::implNextConvertibleUnit: caught an exception!" );
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir 			//!!! at least we want to move on in the text in order
494*cdf0e10cSrcweir 			//!!! to avoid an endless loop...
495*cdf0e10cSrcweir 			return false;
496*cdf0e10cSrcweir 		}
497*cdf0e10cSrcweir         return bFoundAny;
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
501*cdf0e10cSrcweir 	bool HangulHanjaConversion_Impl::implNextConvertibleUnit( const sal_Int32 _nStartAt )
502*cdf0e10cSrcweir 	{
503*cdf0e10cSrcweir 		m_aCurrentSuggestions.realloc( 0 );
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir 		// ask the TextConversion service for the next convertible piece of text
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 		// get current values from dialog
508*cdf0e10cSrcweir 		if( m_eConvType == HHC::eConvHangulHanja && m_pConversionDialog )
509*cdf0e10cSrcweir 		{
510*cdf0e10cSrcweir 			m_bTryBothDirections = m_pConversionDialog->GetUseBothDirections();
511*cdf0e10cSrcweir 			HHC::ConversionDirection eDialogDirection = HHC::eHangulToHanja;
512*cdf0e10cSrcweir 			eDialogDirection = m_pConversionDialog->GetDirection( eDialogDirection );
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 			if( !m_bTryBothDirections && eDialogDirection != m_eCurrentConversionDirection )
515*cdf0e10cSrcweir 			{
516*cdf0e10cSrcweir 				m_eCurrentConversionDirection = eDialogDirection;
517*cdf0e10cSrcweir 			}
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 			// save curently used value for possible later use
520*cdf0e10cSrcweir 			m_pAntiImpl->m_bTryBothDirectionsSave = m_bTryBothDirections;
521*cdf0e10cSrcweir 			m_pAntiImpl->m_ePrimaryConversionDirectionSave = m_eCurrentConversionDirection;
522*cdf0e10cSrcweir 		}
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir 		bool bFoundAny = implUpdateSuggestions( true, _nStartAt );
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir         return  bFoundAny &&
527*cdf0e10cSrcweir                 (m_nCurrentStartIndex < m_sCurrentPortion.getLength());
528*cdf0e10cSrcweir 	}
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
531*cdf0e10cSrcweir 	bool HangulHanjaConversion_Impl::implRetrieveNextPortion( )
532*cdf0e10cSrcweir 	{
533*cdf0e10cSrcweir         sal_Bool bAllowImplicitChanges = m_eConvType == HHC::eConvSimplifiedTraditional;
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 		m_sCurrentPortion = ::rtl::OUString();
536*cdf0e10cSrcweir         m_nCurrentPortionLang = LANGUAGE_NONE;
537*cdf0e10cSrcweir         m_pAntiImpl->GetNextPortion( m_sCurrentPortion, m_nCurrentPortionLang, bAllowImplicitChanges );
538*cdf0e10cSrcweir 		m_nReplacementBaseIndex = 0;
539*cdf0e10cSrcweir 		m_nCurrentStartIndex = m_nCurrentEndIndex = 0;
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir 		bool bRet = 0 != m_sCurrentPortion.getLength();
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir 		if (m_eConvType == HHC::eConvHangulHanja && m_bTryBothDirections)
544*cdf0e10cSrcweir 			implGetConversionDirectionForCurrentPortion( m_eCurrentConversionDirection );
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir 		return bRet;
547*cdf0e10cSrcweir 	}
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
550*cdf0e10cSrcweir 	sal_Bool HangulHanjaConversion_Impl::implNextConvertible( bool _bRepeatUnit )
551*cdf0e10cSrcweir 	{
552*cdf0e10cSrcweir 		if ( _bRepeatUnit || ( m_nCurrentEndIndex < m_sCurrentPortion.getLength() ) )
553*cdf0e10cSrcweir 		{
554*cdf0e10cSrcweir 			if ( implNextConvertibleUnit(
555*cdf0e10cSrcweir 						_bRepeatUnit
556*cdf0e10cSrcweir 					?	( IsByCharacter() ? m_nCurrentStartIndex : m_nCurrentStartIndex )
557*cdf0e10cSrcweir 					:	m_nCurrentEndIndex
558*cdf0e10cSrcweir 				) )
559*cdf0e10cSrcweir 				return sal_True;
560*cdf0e10cSrcweir 		}
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir 		// no convertible text in the current portion anymore
563*cdf0e10cSrcweir 		// -> advance to the next portion
564*cdf0e10cSrcweir 		do
565*cdf0e10cSrcweir 		{
566*cdf0e10cSrcweir 			// next portion
567*cdf0e10cSrcweir 			if ( implRetrieveNextPortion( ) )
568*cdf0e10cSrcweir 			{	// there is a next portion
569*cdf0e10cSrcweir 				// -> find the next convertible unit in the current portion
570*cdf0e10cSrcweir 				if ( implNextConvertibleUnit( 0 ) )
571*cdf0e10cSrcweir 					return sal_True;
572*cdf0e10cSrcweir 			}
573*cdf0e10cSrcweir 		}
574*cdf0e10cSrcweir 		while ( m_sCurrentPortion.getLength() );
575*cdf0e10cSrcweir 
576*cdf0e10cSrcweir 		// no more portions
577*cdf0e10cSrcweir 		return sal_False;
578*cdf0e10cSrcweir 	}
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
581*cdf0e10cSrcweir     ::rtl::OUString HangulHanjaConversion_Impl::GetCurrentUnit() const
582*cdf0e10cSrcweir     {
583*cdf0e10cSrcweir         DBG_ASSERT( m_nCurrentStartIndex < m_sCurrentPortion.getLength(),
584*cdf0e10cSrcweir 			"HangulHanjaConversion_Impl::GetCurrentUnit: invalid index into current portion!" );
585*cdf0e10cSrcweir         DBG_ASSERT( m_nCurrentEndIndex <= m_sCurrentPortion.getLength(),
586*cdf0e10cSrcweir 			"HangulHanjaConversion_Impl::GetCurrentUnit: invalid index into current portion!" );
587*cdf0e10cSrcweir 		DBG_ASSERT( m_nCurrentStartIndex <= m_nCurrentEndIndex,
588*cdf0e10cSrcweir 			"HangulHanjaConversion_Impl::GetCurrentUnit: invalid interval!" );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir         ::rtl::OUString sCurrentUnit = m_sCurrentPortion.copy( m_nCurrentStartIndex, m_nCurrentEndIndex - m_nCurrentStartIndex );
591*cdf0e10cSrcweir         return sCurrentUnit;
592*cdf0e10cSrcweir     }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir     //-------------------------------------------------------------------------
595*cdf0e10cSrcweir 	sal_Bool HangulHanjaConversion_Impl::ContinueConversion( bool _bRepeatCurrentUnit )
596*cdf0e10cSrcweir 	{
597*cdf0e10cSrcweir 		sal_Bool bNeedUserInteraction = sal_False;	// when we leave here, do we need user interaction?
598*cdf0e10cSrcweir 		sal_Bool bDocumentDone = sal_False;			// did we already check the whole document?
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir 		while ( !bDocumentDone && !bNeedUserInteraction && implNextConvertible( _bRepeatCurrentUnit ) )
601*cdf0e10cSrcweir 		{
602*cdf0e10cSrcweir 			::rtl::OUString sCurrentUnit( GetCurrentUnit() );
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 			// do we need to ignore it?
605*cdf0e10cSrcweir 			sal_Bool bAlwaysIgnoreThis = m_sIgnoreList.end() != m_sIgnoreList.find( sCurrentUnit );
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 			// do we need to change it?
608*cdf0e10cSrcweir 			StringMap::const_iterator aChangeListPos = m_aChangeList.find( sCurrentUnit );
609*cdf0e10cSrcweir 			sal_Bool bAlwaysChangeThis = m_aChangeList.end() != aChangeListPos;
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 			// do we automatically change this?
612*cdf0e10cSrcweir 			sal_Bool bAutoChange = m_bAutoReplaceUnique && m_aCurrentSuggestions.getLength() == 1;
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir             if (!m_bIsInteractive)
615*cdf0e10cSrcweir 			{
616*cdf0e10cSrcweir                 // silent conversion (e.g. for simplified/traditional Chinese)...
617*cdf0e10cSrcweir                 if(m_aCurrentSuggestions.getLength()>0)
618*cdf0e10cSrcweir 				    implChange( m_aCurrentSuggestions.getConstArray()[0] );
619*cdf0e10cSrcweir 			}
620*cdf0e10cSrcweir 			else if (bAutoChange)
621*cdf0e10cSrcweir 			{
622*cdf0e10cSrcweir 				implChange( m_aCurrentSuggestions.getConstArray()[0] );
623*cdf0e10cSrcweir 			}
624*cdf0e10cSrcweir 			else if ( bAlwaysChangeThis )
625*cdf0e10cSrcweir 			{
626*cdf0e10cSrcweir 				implChange( aChangeListPos->second );
627*cdf0e10cSrcweir 			}
628*cdf0e10cSrcweir 			else if ( !bAlwaysIgnoreThis )
629*cdf0e10cSrcweir 			{
630*cdf0e10cSrcweir 				// here we need to ask the user for what to do with the text
631*cdf0e10cSrcweir 				// for this, allow derivees to highlight the current text unit in a possible document view
632*cdf0e10cSrcweir 				m_pAntiImpl->HandleNewUnit( m_nCurrentStartIndex - m_nReplacementBaseIndex, m_nCurrentEndIndex - m_nReplacementBaseIndex );
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir                 DBG_ASSERT( m_pConversionDialog, "we should always have a dialog here!" );
635*cdf0e10cSrcweir                 if( m_pConversionDialog )
636*cdf0e10cSrcweir 				    m_pConversionDialog->SetCurrentString( sCurrentUnit, m_aCurrentSuggestions );
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir 				// do not look for the next convertible: We have to wait for the user to interactivly
639*cdf0e10cSrcweir 				// decide what happens with the current convertible
640*cdf0e10cSrcweir 				bNeedUserInteraction = sal_True;
641*cdf0e10cSrcweir 			}
642*cdf0e10cSrcweir 		}
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir 		/*
645*cdf0e10cSrcweir 		if ( bDocumentDone )
646*cdf0e10cSrcweir 			return sal_True;			// we explicitly know that the complete document is done
647*cdf0e10cSrcweir 		else if ( bNeedUserInteraction )
648*cdf0e10cSrcweir 			return sal_False;			// the doc is not done, we found a convertible, but need the user to decide
649*cdf0e10cSrcweir 		else
650*cdf0e10cSrcweir 			return sal_True;			// we did not find a next convertible, so the document is implicitly done
651*cdf0e10cSrcweir 		*/
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir 		return	bDocumentDone || !bNeedUserInteraction;
654*cdf0e10cSrcweir 	}
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
657*cdf0e10cSrcweir 	bool HangulHanjaConversion_Impl::implGetConversionDirectionForCurrentPortion( HHC::ConversionDirection& rDirection )
658*cdf0e10cSrcweir 	{
659*cdf0e10cSrcweir 		// - For eConvHangulHanja the direction is determined by
660*cdf0e10cSrcweir 		// the first encountered Korean character.
661*cdf0e10cSrcweir 		// - For eConvSimplifiedTraditional the conversion direction
662*cdf0e10cSrcweir 		// is already specified by the source language.
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir 		bool bSuccess = true;
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir         if (m_eConvType == HHC::eConvHangulHanja)
667*cdf0e10cSrcweir 		{
668*cdf0e10cSrcweir 			bSuccess = false;
669*cdf0e10cSrcweir 			try
670*cdf0e10cSrcweir 			{
671*cdf0e10cSrcweir 				// get the break iterator service
672*cdf0e10cSrcweir 				::rtl::OUString sBreakIteratorService( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.i18n.BreakIterator" ) );
673*cdf0e10cSrcweir 				Reference< XInterface > xBI( m_xORB->createInstance( ::rtl::OUString( sBreakIteratorService ) ) );
674*cdf0e10cSrcweir 				Reference< XBreakIterator > xBreakIter( xBI, UNO_QUERY );
675*cdf0e10cSrcweir 				if ( !xBreakIter.is() )
676*cdf0e10cSrcweir 				{
677*cdf0e10cSrcweir 					ShowServiceNotAvailableError( m_pUIParent, sBreakIteratorService, sal_True );
678*cdf0e10cSrcweir 				}
679*cdf0e10cSrcweir 				else
680*cdf0e10cSrcweir 				{
681*cdf0e10cSrcweir 					sal_Int32 nNextAsianScript = xBreakIter->beginOfScript( m_sCurrentPortion, m_nCurrentStartIndex, com::sun::star::i18n::ScriptType::ASIAN );
682*cdf0e10cSrcweir 					if ( -1 == nNextAsianScript )
683*cdf0e10cSrcweir 						nNextAsianScript = xBreakIter->nextScript( m_sCurrentPortion, m_nCurrentStartIndex, com::sun::star::i18n::ScriptType::ASIAN );
684*cdf0e10cSrcweir 					if ( ( nNextAsianScript >= m_nCurrentStartIndex ) && ( nNextAsianScript < m_sCurrentPortion.getLength() ) )
685*cdf0e10cSrcweir 					{	// found asian text
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir 						// determine if it's Hangul
688*cdf0e10cSrcweir 						CharClass aCharClassificaton( m_xORB, m_aSourceLocale );
689*cdf0e10cSrcweir 						sal_Int16 nScript = aCharClassificaton.getScript( m_sCurrentPortion, sal::static_int_cast< sal_uInt16 >(nNextAsianScript) );
690*cdf0e10cSrcweir 						if	(	( UnicodeScript_kHangulJamo == nScript )
691*cdf0e10cSrcweir 							||	( UnicodeScript_kHangulCompatibilityJamo == nScript )
692*cdf0e10cSrcweir 							||	( UnicodeScript_kHangulSyllable == nScript )
693*cdf0e10cSrcweir 							)
694*cdf0e10cSrcweir 						{
695*cdf0e10cSrcweir 							rDirection = HHC::eHangulToHanja;
696*cdf0e10cSrcweir 						}
697*cdf0e10cSrcweir 						else
698*cdf0e10cSrcweir 						{
699*cdf0e10cSrcweir 							rDirection = HHC::eHanjaToHangul;
700*cdf0e10cSrcweir 						}
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 						bSuccess = true;
703*cdf0e10cSrcweir 					}
704*cdf0e10cSrcweir 				}
705*cdf0e10cSrcweir 			}
706*cdf0e10cSrcweir 			catch( const Exception& )
707*cdf0e10cSrcweir 			{
708*cdf0e10cSrcweir 				DBG_ERROR( "HangulHanjaConversion_Impl::implGetConversionDirectionForCurrentPortion: caught an exception!" );
709*cdf0e10cSrcweir 			}
710*cdf0e10cSrcweir 		}
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir 		return bSuccess;
713*cdf0e10cSrcweir 	}
714*cdf0e10cSrcweir 
715*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
716*cdf0e10cSrcweir 	void HangulHanjaConversion_Impl::DoDocumentConversion( )
717*cdf0e10cSrcweir 	{
718*cdf0e10cSrcweir 		// clear the change-all list - it's to be re-initialized for every single document
719*cdf0e10cSrcweir         {
720*cdf0e10cSrcweir             StringMap aEmpty;
721*cdf0e10cSrcweir             m_aChangeList.swap( aEmpty );
722*cdf0e10cSrcweir         }
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 		// first of all, we need to guess the direction of our conversion - it is determined by the first
725*cdf0e10cSrcweir 		// hangul or hanja character in the first text
726*cdf0e10cSrcweir 		if ( !implRetrieveNextPortion() )
727*cdf0e10cSrcweir 		{
728*cdf0e10cSrcweir             DBG_WARNING( "HangulHanjaConversion_Impl::DoDocumentConversion: why did you call me if you do have nothing to convert?" );
729*cdf0e10cSrcweir 			// nothing to do
730*cdf0e10cSrcweir 			return;
731*cdf0e10cSrcweir 		}
732*cdf0e10cSrcweir 		if( m_eConvType == HHC::eConvHangulHanja )
733*cdf0e10cSrcweir 		{
734*cdf0e10cSrcweir 			//init conversion direction from saved value
735*cdf0e10cSrcweir 			HHC::ConversionDirection eDirection = HHC::eHangulToHanja;
736*cdf0e10cSrcweir 			if(!implGetConversionDirectionForCurrentPortion( eDirection ))
737*cdf0e10cSrcweir 				// something went wrong, has already been asserted
738*cdf0e10cSrcweir 				return;
739*cdf0e10cSrcweir 
740*cdf0e10cSrcweir 			if (m_pAntiImpl->IsUseSavedConversionDirectionState())
741*cdf0e10cSrcweir 			{
742*cdf0e10cSrcweir 				m_ePrimaryConversionDirection = m_pAntiImpl->m_ePrimaryConversionDirectionSave;
743*cdf0e10cSrcweir 				m_bTryBothDirections = m_pAntiImpl->m_bTryBothDirectionsSave;
744*cdf0e10cSrcweir 				if( m_bTryBothDirections )
745*cdf0e10cSrcweir 					m_eCurrentConversionDirection = eDirection;
746*cdf0e10cSrcweir 				else
747*cdf0e10cSrcweir 					m_eCurrentConversionDirection = m_ePrimaryConversionDirection;
748*cdf0e10cSrcweir 			}
749*cdf0e10cSrcweir 			else
750*cdf0e10cSrcweir 			{
751*cdf0e10cSrcweir 				m_ePrimaryConversionDirection = eDirection;
752*cdf0e10cSrcweir 				m_eCurrentConversionDirection = eDirection;
753*cdf0e10cSrcweir 			}
754*cdf0e10cSrcweir 		}
755*cdf0e10cSrcweir 
756*cdf0e10cSrcweir 		if (m_bIsInteractive  &&  m_eConvType == HHC::eConvHangulHanja)
757*cdf0e10cSrcweir 		{
758*cdf0e10cSrcweir 			//always open dialog if at least having a hangul or hanja text portion
759*cdf0e10cSrcweir 			createDialog();
760*cdf0e10cSrcweir 			if(m_pAntiImpl->IsUseSavedConversionDirectionState())
761*cdf0e10cSrcweir 				ContinueConversion( sal_False );
762*cdf0e10cSrcweir 			else
763*cdf0e10cSrcweir 				implUpdateData();
764*cdf0e10cSrcweir 			m_pConversionDialog->Execute();
765*cdf0e10cSrcweir 			DELETEZ( m_pConversionDialog );
766*cdf0e10cSrcweir 		}
767*cdf0e10cSrcweir 		else
768*cdf0e10cSrcweir 		{
769*cdf0e10cSrcweir #ifdef DBG_UTIL
770*cdf0e10cSrcweir 			sal_Bool bCompletelyDone =
771*cdf0e10cSrcweir #endif
772*cdf0e10cSrcweir 			ContinueConversion( sal_False );
773*cdf0e10cSrcweir 			DBG_ASSERT( bCompletelyDone, "HangulHanjaConversion_Impl::DoDocumentConversion: ContinueConversion should have returned true here!" );
774*cdf0e10cSrcweir 		}
775*cdf0e10cSrcweir 	}
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
778*cdf0e10cSrcweir 	void HangulHanjaConversion_Impl::implProceed( bool _bRepeatCurrentUnit )
779*cdf0e10cSrcweir 	{
780*cdf0e10cSrcweir 		if ( ContinueConversion( _bRepeatCurrentUnit ) )
781*cdf0e10cSrcweir 		{	// we're done with the whole document
782*cdf0e10cSrcweir             DBG_ASSERT( !m_bIsInteractive || m_pConversionDialog, "HangulHanjaConversion_Impl::implProceed: we should not reach this here without dialog!" );
783*cdf0e10cSrcweir 			if ( m_pConversionDialog )
784*cdf0e10cSrcweir 				m_pConversionDialog->EndDialog( RET_OK );
785*cdf0e10cSrcweir 		}
786*cdf0e10cSrcweir 	}
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
789*cdf0e10cSrcweir 	void HangulHanjaConversion_Impl::implChange( const ::rtl::OUString& _rChangeInto )
790*cdf0e10cSrcweir 	{
791*cdf0e10cSrcweir         if( !_rChangeInto.getLength() )
792*cdf0e10cSrcweir             return;
793*cdf0e10cSrcweir 
794*cdf0e10cSrcweir 		// translate the conversion format into a replacement action
795*cdf0e10cSrcweir 		// this translation depends on whether we have a Hangul original, or a Hanja original
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir         HHC::ReplacementAction eAction( HHC::eExchange );
798*cdf0e10cSrcweir 
799*cdf0e10cSrcweir 		if (m_eConvType == HHC::eConvHangulHanja)
800*cdf0e10cSrcweir 		{
801*cdf0e10cSrcweir 			// is the original we're about to change in Hangul?
802*cdf0e10cSrcweir 			sal_Bool bOriginalIsHangul = HHC::eHangulToHanja == m_eCurrentConversionDirection;
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir 			switch ( m_eConversionFormat )
805*cdf0e10cSrcweir 			{
806*cdf0e10cSrcweir 				case HHC::eSimpleConversion: eAction = HHC::eExchange; break;
807*cdf0e10cSrcweir 				case HHC::eHangulBracketed:  eAction = bOriginalIsHangul ? HHC::eOriginalBracketed : HHC::eReplacementBracketed; break;
808*cdf0e10cSrcweir 				case HHC::eHanjaBracketed:   eAction = bOriginalIsHangul ? HHC::eReplacementBracketed : HHC::eOriginalBracketed; break;
809*cdf0e10cSrcweir 				case HHC::eRubyHanjaAbove:   eAction = bOriginalIsHangul ? HHC::eReplacementAbove : HHC::eOriginalAbove; break;
810*cdf0e10cSrcweir 				case HHC::eRubyHanjaBelow:   eAction = bOriginalIsHangul ? HHC::eReplacementBelow : HHC::eOriginalBelow; break;
811*cdf0e10cSrcweir 				case HHC::eRubyHangulAbove:  eAction = bOriginalIsHangul ? HHC::eOriginalAbove : HHC::eReplacementAbove; break;
812*cdf0e10cSrcweir 				case HHC::eRubyHangulBelow:  eAction = bOriginalIsHangul ? HHC::eOriginalBelow : HHC::eReplacementBelow; break;
813*cdf0e10cSrcweir 				default:
814*cdf0e10cSrcweir 					DBG_ERROR( "HangulHanjaConversion_Impl::implChange: invalid/unexpected conversion format!" );
815*cdf0e10cSrcweir 			}
816*cdf0e10cSrcweir 		}
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir 		// the proper indicies (the wrapper implementation needs indicies relative to the
819*cdf0e10cSrcweir 		// previous replacement)
820*cdf0e10cSrcweir 		DBG_ASSERT( ( m_nReplacementBaseIndex <= m_nCurrentStartIndex ) && ( m_nReplacementBaseIndex <= m_nCurrentEndIndex ),
821*cdf0e10cSrcweir 			"HangulHanjaConversion_Impl::implChange: invalid replacement base!" );
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir 		sal_Int32 nStartIndex = m_nCurrentStartIndex - m_nReplacementBaseIndex;
824*cdf0e10cSrcweir 		sal_Int32 nEndIndex = m_nCurrentEndIndex - m_nReplacementBaseIndex;
825*cdf0e10cSrcweir 
826*cdf0e10cSrcweir         //remind this decision
827*cdf0e10cSrcweir         m_aRecentlyUsedList[ GetCurrentUnit() ] = _rChangeInto;
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir         LanguageType *pNewUnitLang = 0;
830*cdf0e10cSrcweir         LanguageType  nNewUnitLang = LANGUAGE_NONE;
831*cdf0e10cSrcweir         if (m_eConvType == HHC::eConvSimplifiedTraditional)
832*cdf0e10cSrcweir         {
833*cdf0e10cSrcweir             // check if language needs to be changed
834*cdf0e10cSrcweir             if ( m_pAntiImpl->GetTargetLanguage() == LANGUAGE_CHINESE_TRADITIONAL &&
835*cdf0e10cSrcweir                 !m_pAntiImpl->IsTraditional( m_nCurrentPortionLang ))
836*cdf0e10cSrcweir                 nNewUnitLang = LANGUAGE_CHINESE_TRADITIONAL;
837*cdf0e10cSrcweir             else if ( m_pAntiImpl->GetTargetLanguage() == LANGUAGE_CHINESE_SIMPLIFIED &&
838*cdf0e10cSrcweir                      !m_pAntiImpl->IsSimplified( m_nCurrentPortionLang ))
839*cdf0e10cSrcweir                 nNewUnitLang = LANGUAGE_CHINESE_SIMPLIFIED;
840*cdf0e10cSrcweir             if (nNewUnitLang != LANGUAGE_NONE)
841*cdf0e10cSrcweir                 pNewUnitLang = &nNewUnitLang;
842*cdf0e10cSrcweir         }
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir         // according to FT we should not (yet) bother about Hangul/Hanja conversion here
845*cdf0e10cSrcweir         //
846*cdf0e10cSrcweir         // aOffsets is needed in ReplaceUnit below in order to to find out
847*cdf0e10cSrcweir         // exactly which characters are really changed in order to keep as much
848*cdf0e10cSrcweir         // from attributation for the text as possible.
849*cdf0e10cSrcweir         Sequence< sal_Int32 > aOffsets;
850*cdf0e10cSrcweir         Reference< XExtendedTextConversion > xExtConverter( m_xConverter, UNO_QUERY );
851*cdf0e10cSrcweir         if (m_eConvType == HHC::eConvSimplifiedTraditional && xExtConverter.is())
852*cdf0e10cSrcweir 		{
853*cdf0e10cSrcweir             try
854*cdf0e10cSrcweir             {
855*cdf0e10cSrcweir                 ::rtl::OUString aConvText = xExtConverter->getConversionWithOffset(
856*cdf0e10cSrcweir                     m_sCurrentPortion,
857*cdf0e10cSrcweir                     m_nCurrentStartIndex,
858*cdf0e10cSrcweir                     m_nCurrentEndIndex - m_nCurrentStartIndex,
859*cdf0e10cSrcweir                     m_aSourceLocale,
860*cdf0e10cSrcweir                     m_nCurrentConversionType,
861*cdf0e10cSrcweir                     m_nCurrentConversionOption,
862*cdf0e10cSrcweir                     aOffsets
863*cdf0e10cSrcweir                 );
864*cdf0e10cSrcweir             }
865*cdf0e10cSrcweir             catch( const Exception& )
866*cdf0e10cSrcweir             {
867*cdf0e10cSrcweir                 DBG_ERROR( "HangulHanjaConversion_Impl::implChange: caught unexpected exception!" );
868*cdf0e10cSrcweir                 aOffsets.realloc(0);
869*cdf0e10cSrcweir             }
870*cdf0e10cSrcweir 		}
871*cdf0e10cSrcweir 
872*cdf0e10cSrcweir         // do the replacement
873*cdf0e10cSrcweir         m_pAntiImpl->ReplaceUnit( nStartIndex, nEndIndex, m_sCurrentPortion,
874*cdf0e10cSrcweir                 _rChangeInto, aOffsets, eAction, pNewUnitLang );
875*cdf0e10cSrcweir 
876*cdf0e10cSrcweir 
877*cdf0e10cSrcweir 		// adjust the replacement base
878*cdf0e10cSrcweir 		m_nReplacementBaseIndex = m_nCurrentEndIndex;
879*cdf0e10cSrcweir 	}
880*cdf0e10cSrcweir 
881*cdf0e10cSrcweir     //-------------------------------------------------------------------------
882*cdf0e10cSrcweir     void HangulHanjaConversion_Impl::implReadOptionsFromConfiguration()
883*cdf0e10cSrcweir     {
884*cdf0e10cSrcweir         SvtLinguConfig	aLngCfg;
885*cdf0e10cSrcweir         aLngCfg.GetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD ) >>= m_bIgnorePostPositionalWord;
886*cdf0e10cSrcweir         aLngCfg.GetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST ) >>= m_bShowRecentlyUsedFirst;
887*cdf0e10cSrcweir         aLngCfg.GetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES ) >>= m_bAutoReplaceUnique;
888*cdf0e10cSrcweir     }
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir     //-------------------------------------------------------------------------
891*cdf0e10cSrcweir     void HangulHanjaConversion_Impl::implUpdateData()
892*cdf0e10cSrcweir     {
893*cdf0e10cSrcweir         implReadOptionsFromConfiguration();
894*cdf0e10cSrcweir         implUpdateSuggestions();
895*cdf0e10cSrcweir 
896*cdf0e10cSrcweir         if(m_pConversionDialog)
897*cdf0e10cSrcweir         {
898*cdf0e10cSrcweir             ::rtl::OUString sCurrentUnit( GetCurrentUnit() );
899*cdf0e10cSrcweir 
900*cdf0e10cSrcweir             m_pConversionDialog->SetCurrentString( sCurrentUnit, m_aCurrentSuggestions );
901*cdf0e10cSrcweir             m_pConversionDialog->FocusSuggestion();
902*cdf0e10cSrcweir         }
903*cdf0e10cSrcweir 
904*cdf0e10cSrcweir         m_pAntiImpl->HandleNewUnit( m_nCurrentStartIndex - m_nReplacementBaseIndex, m_nCurrentEndIndex - m_nReplacementBaseIndex );
905*cdf0e10cSrcweir     }
906*cdf0e10cSrcweir 
907*cdf0e10cSrcweir     //-------------------------------------------------------------------------
908*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnOptionsChanged, void*, EMPTYARG )
909*cdf0e10cSrcweir 	{
910*cdf0e10cSrcweir         //options and dictionaries might have been changed
911*cdf0e10cSrcweir         //-> update our internal settings and the dialog
912*cdf0e10cSrcweir         implUpdateData();
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir         return 0L;
915*cdf0e10cSrcweir 	}
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
918*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnIgnore, void*, EMPTYARG )
919*cdf0e10cSrcweir 	{
920*cdf0e10cSrcweir 		// simply ignore, and proceed
921*cdf0e10cSrcweir 		implProceed( sal_False );
922*cdf0e10cSrcweir 		return 0L;
923*cdf0e10cSrcweir 	}
924*cdf0e10cSrcweir 
925*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
926*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnIgnoreAll, void*, EMPTYARG )
927*cdf0e10cSrcweir 	{
928*cdf0e10cSrcweir 		DBG_ASSERT( m_pConversionDialog, "HangulHanjaConversion_Impl::OnIgnoreAll: no dialog! How this?" );
929*cdf0e10cSrcweir 
930*cdf0e10cSrcweir 		if ( m_pConversionDialog )
931*cdf0e10cSrcweir 		{
932*cdf0e10cSrcweir 			String sCurrentUnit = m_pConversionDialog->GetCurrentString();
933*cdf0e10cSrcweir 			DBG_ASSERT( m_sIgnoreList.end() == m_sIgnoreList.find( sCurrentUnit ),
934*cdf0e10cSrcweir 				"HangulHanjaConversion_Impl, OnIgnoreAll: shouldn't this have been ignored before" );
935*cdf0e10cSrcweir 
936*cdf0e10cSrcweir 			// put into the "ignore all" list
937*cdf0e10cSrcweir 			m_sIgnoreList.insert( sCurrentUnit );
938*cdf0e10cSrcweir 
939*cdf0e10cSrcweir 			// and proceed
940*cdf0e10cSrcweir 			implProceed( sal_False );
941*cdf0e10cSrcweir 		}
942*cdf0e10cSrcweir 
943*cdf0e10cSrcweir 		return 0L;
944*cdf0e10cSrcweir 	}
945*cdf0e10cSrcweir 
946*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
947*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnChange, void*, EMPTYARG )
948*cdf0e10cSrcweir 	{
949*cdf0e10cSrcweir 		// change
950*cdf0e10cSrcweir         DBG_ASSERT( m_pConversionDialog, "we should always have a dialog here!" );
951*cdf0e10cSrcweir         if( m_pConversionDialog )
952*cdf0e10cSrcweir 		    implChange( m_pConversionDialog->GetCurrentSuggestion( ) );
953*cdf0e10cSrcweir 		// and proceed
954*cdf0e10cSrcweir 		implProceed( sal_False );
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir 		return 0L;
957*cdf0e10cSrcweir 	}
958*cdf0e10cSrcweir 
959*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
960*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnChangeAll, void*, EMPTYARG )
961*cdf0e10cSrcweir 	{
962*cdf0e10cSrcweir 		DBG_ASSERT( m_pConversionDialog, "HangulHanjaConversion_Impl::OnChangeAll: no dialog! How this?" );
963*cdf0e10cSrcweir 		if ( m_pConversionDialog )
964*cdf0e10cSrcweir 		{
965*cdf0e10cSrcweir 			::rtl::OUString sCurrentUnit( m_pConversionDialog->GetCurrentString() );
966*cdf0e10cSrcweir 			::rtl::OUString sChangeInto( m_pConversionDialog->GetCurrentSuggestion( ) );
967*cdf0e10cSrcweir 
968*cdf0e10cSrcweir             if( sChangeInto.getLength() )
969*cdf0e10cSrcweir             {
970*cdf0e10cSrcweir 			    // change the current occurence
971*cdf0e10cSrcweir 			    implChange( sChangeInto );
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir 			    // put into the "change all" list
974*cdf0e10cSrcweir 			    m_aChangeList.insert( StringMap::value_type( sCurrentUnit, sChangeInto ) );
975*cdf0e10cSrcweir             }
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir 			// and proceed
978*cdf0e10cSrcweir 			implProceed( sal_False );
979*cdf0e10cSrcweir 		}
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir 		return 0L;
982*cdf0e10cSrcweir 	}
983*cdf0e10cSrcweir 
984*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
985*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnByCharClicked, CheckBox*, _pBox )
986*cdf0e10cSrcweir 	{
987*cdf0e10cSrcweir 		m_bByCharacter = _pBox->IsChecked();
988*cdf0e10cSrcweir 
989*cdf0e10cSrcweir 		// continue conversion, without advancing to the next unit, but instead continuing with the current unit
990*cdf0e10cSrcweir 		implProceed( sal_True );
991*cdf0e10cSrcweir 		return 0L;
992*cdf0e10cSrcweir 	}
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
995*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnConversionTypeChanged, void*, EMPTYARG )
996*cdf0e10cSrcweir 	{
997*cdf0e10cSrcweir         DBG_ASSERT( m_pConversionDialog, "we should always have a dialog here!" );
998*cdf0e10cSrcweir         if( m_pConversionDialog )
999*cdf0e10cSrcweir 		    m_eConversionFormat = m_pConversionDialog->GetConversionFormat( );
1000*cdf0e10cSrcweir 		return 0L;
1001*cdf0e10cSrcweir 	}
1002*cdf0e10cSrcweir 
1003*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1004*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversion_Impl, OnFind, void*, EMPTYARG )
1005*cdf0e10cSrcweir 	{
1006*cdf0e10cSrcweir 		DBG_ASSERT( m_pConversionDialog, "HangulHanjaConversion_Impl::OnFind: where did this come from?" );
1007*cdf0e10cSrcweir 		if ( m_pConversionDialog )
1008*cdf0e10cSrcweir 		{
1009*cdf0e10cSrcweir 			try
1010*cdf0e10cSrcweir 			{
1011*cdf0e10cSrcweir 				::rtl::OUString sNewOriginal( m_pConversionDialog->GetCurrentSuggestion( ) );
1012*cdf0e10cSrcweir 				Sequence< ::rtl::OUString > aSuggestions;
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir 				DBG_ASSERT( m_xConverter.is(), "HangulHanjaConversion_Impl::OnFind: no converter!" );
1015*cdf0e10cSrcweir 				TextConversionResult aToHanja = m_xConverter->getConversions(
1016*cdf0e10cSrcweir 					sNewOriginal,
1017*cdf0e10cSrcweir 					0, sNewOriginal.getLength(),
1018*cdf0e10cSrcweir                     m_aSourceLocale,
1019*cdf0e10cSrcweir 					TextConversionType::TO_HANJA,
1020*cdf0e10cSrcweir 					TextConversionOption::NONE
1021*cdf0e10cSrcweir 				);
1022*cdf0e10cSrcweir 				TextConversionResult aToHangul = m_xConverter->getConversions(
1023*cdf0e10cSrcweir 					sNewOriginal,
1024*cdf0e10cSrcweir 					0, sNewOriginal.getLength(),
1025*cdf0e10cSrcweir                     m_aSourceLocale,
1026*cdf0e10cSrcweir 					TextConversionType::TO_HANGUL,
1027*cdf0e10cSrcweir 					TextConversionOption::NONE
1028*cdf0e10cSrcweir 				);
1029*cdf0e10cSrcweir 
1030*cdf0e10cSrcweir 				bool bHaveToHanja = ( aToHanja.Boundary.startPos < aToHanja.Boundary.endPos );
1031*cdf0e10cSrcweir 				bool bHaveToHangul = ( aToHangul.Boundary.startPos < aToHangul.Boundary.endPos );
1032*cdf0e10cSrcweir 
1033*cdf0e10cSrcweir 				TextConversionResult* pResult = NULL;
1034*cdf0e10cSrcweir 				if ( bHaveToHanja && bHaveToHangul )
1035*cdf0e10cSrcweir 				{	// it found convertibles in both directions -> use the first
1036*cdf0e10cSrcweir 					if ( aToHangul.Boundary.startPos < aToHanja.Boundary.startPos )
1037*cdf0e10cSrcweir 						pResult = &aToHangul;
1038*cdf0e10cSrcweir 					else
1039*cdf0e10cSrcweir 						pResult = &aToHanja;
1040*cdf0e10cSrcweir 				}
1041*cdf0e10cSrcweir 				else if ( bHaveToHanja )
1042*cdf0e10cSrcweir 				{	// only found toHanja
1043*cdf0e10cSrcweir 					pResult = &aToHanja;
1044*cdf0e10cSrcweir 				}
1045*cdf0e10cSrcweir 				else
1046*cdf0e10cSrcweir 				{	// only found toHangul
1047*cdf0e10cSrcweir 					pResult = &aToHangul;
1048*cdf0e10cSrcweir 				}
1049*cdf0e10cSrcweir 				if ( pResult )
1050*cdf0e10cSrcweir 					aSuggestions = pResult->Candidates;
1051*cdf0e10cSrcweir 
1052*cdf0e10cSrcweir 				m_pConversionDialog->SetCurrentString( sNewOriginal, aSuggestions, false );
1053*cdf0e10cSrcweir 				m_pConversionDialog->FocusSuggestion();
1054*cdf0e10cSrcweir 			}
1055*cdf0e10cSrcweir 			catch( const Exception& )
1056*cdf0e10cSrcweir 			{
1057*cdf0e10cSrcweir 				DBG_ERROR( "HangulHanjaConversion_Impl::OnFind: caught an exception!" );
1058*cdf0e10cSrcweir 			}
1059*cdf0e10cSrcweir 		}
1060*cdf0e10cSrcweir 		return 0L;
1061*cdf0e10cSrcweir 	}
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir 	//=========================================================================
1064*cdf0e10cSrcweir 	//= HangulHanjaConversion
1065*cdf0e10cSrcweir 	//=========================================================================
1066*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1067*cdf0e10cSrcweir 
1068*cdf0e10cSrcweir 	// static member initialization
1069*cdf0e10cSrcweir 	sal_Bool	HangulHanjaConversion::m_bUseSavedValues		= sal_False;
1070*cdf0e10cSrcweir 	sal_Bool	HangulHanjaConversion::m_bTryBothDirectionsSave	= sal_False;
1071*cdf0e10cSrcweir     HHC::ConversionDirection HangulHanjaConversion::m_ePrimaryConversionDirectionSave	= HHC::eHangulToHanja;
1072*cdf0e10cSrcweir 
1073*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1074*cdf0e10cSrcweir     HangulHanjaConversion::HangulHanjaConversion( Window* _pUIParent,
1075*cdf0e10cSrcweir         const Reference< XMultiServiceFactory >& _rxORB,
1076*cdf0e10cSrcweir         const Locale& _rSourceLocale, const Locale& _rTargetLocale,
1077*cdf0e10cSrcweir         const Font* _pTargetFont,
1078*cdf0e10cSrcweir         sal_Int32 _nOptions, sal_Bool _bIsInteractive)
1079*cdf0e10cSrcweir         :m_pImpl( new HangulHanjaConversion_Impl( _pUIParent, _rxORB, _rSourceLocale, _rTargetLocale, _pTargetFont, _nOptions, _bIsInteractive, this ) )
1080*cdf0e10cSrcweir 	{
1081*cdf0e10cSrcweir 	}
1082*cdf0e10cSrcweir 
1083*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1084*cdf0e10cSrcweir 	HangulHanjaConversion::~HangulHanjaConversion( )
1085*cdf0e10cSrcweir 	{
1086*cdf0e10cSrcweir 	}
1087*cdf0e10cSrcweir 
1088*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1089*cdf0e10cSrcweir 	void HangulHanjaConversion::SetUseSavedConversionDirectionState( sal_Bool bVal )
1090*cdf0e10cSrcweir 	{
1091*cdf0e10cSrcweir 		m_bUseSavedValues = bVal;
1092*cdf0e10cSrcweir 	}
1093*cdf0e10cSrcweir 
1094*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1095*cdf0e10cSrcweir 	sal_Bool HangulHanjaConversion::IsUseSavedConversionDirectionState()
1096*cdf0e10cSrcweir 	{
1097*cdf0e10cSrcweir 		return m_bUseSavedValues;
1098*cdf0e10cSrcweir 	}
1099*cdf0e10cSrcweir 
1100*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1101*cdf0e10cSrcweir     LanguageType HangulHanjaConversion::GetSourceLanguage( ) const
1102*cdf0e10cSrcweir     {
1103*cdf0e10cSrcweir         return m_pImpl->GetSourceLang();
1104*cdf0e10cSrcweir     }
1105*cdf0e10cSrcweir 
1106*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1107*cdf0e10cSrcweir     LanguageType HangulHanjaConversion::GetTargetLanguage( ) const
1108*cdf0e10cSrcweir     {
1109*cdf0e10cSrcweir         return m_pImpl->GetTargetLang();
1110*cdf0e10cSrcweir     }
1111*cdf0e10cSrcweir 
1112*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1113*cdf0e10cSrcweir     const Font * HangulHanjaConversion::GetTargetFont( ) const
1114*cdf0e10cSrcweir     {
1115*cdf0e10cSrcweir         return m_pImpl->GetTargetFont();
1116*cdf0e10cSrcweir     }
1117*cdf0e10cSrcweir 
1118*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1119*cdf0e10cSrcweir     sal_Int32 HangulHanjaConversion::GetConversionOptions( ) const
1120*cdf0e10cSrcweir     {
1121*cdf0e10cSrcweir         return m_pImpl->GetConvOptions();
1122*cdf0e10cSrcweir     }
1123*cdf0e10cSrcweir 
1124*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1125*cdf0e10cSrcweir     sal_Bool HangulHanjaConversion::IsInteractive( ) const
1126*cdf0e10cSrcweir     {
1127*cdf0e10cSrcweir         return m_pImpl->IsInteractive();
1128*cdf0e10cSrcweir     }
1129*cdf0e10cSrcweir 
1130*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1131*cdf0e10cSrcweir 	void HangulHanjaConversion::HandleNewUnit( const sal_Int32, const sal_Int32 )
1132*cdf0e10cSrcweir 	{
1133*cdf0e10cSrcweir 		// nothing to do, only derived classes need this.
1134*cdf0e10cSrcweir 	}
1135*cdf0e10cSrcweir 
1136*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1137*cdf0e10cSrcweir     void HangulHanjaConversion::GetNextPortion( ::rtl::OUString&, LanguageType&, sal_Bool )
1138*cdf0e10cSrcweir 	{
1139*cdf0e10cSrcweir 		DBG_ERROR( "HangulHanjaConversion::GetNextPortion: to be overridden!" );
1140*cdf0e10cSrcweir 	}
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1143*cdf0e10cSrcweir     void HangulHanjaConversion::ReplaceUnit(
1144*cdf0e10cSrcweir             const sal_Int32, const sal_Int32,
1145*cdf0e10cSrcweir             const ::rtl::OUString&,
1146*cdf0e10cSrcweir             const ::rtl::OUString&,
1147*cdf0e10cSrcweir             const ::com::sun::star::uno::Sequence< sal_Int32 > &,
1148*cdf0e10cSrcweir             ReplacementAction,
1149*cdf0e10cSrcweir             LanguageType * )
1150*cdf0e10cSrcweir 	{
1151*cdf0e10cSrcweir 		DBG_ERROR( "HangulHanjaConversion::ReplaceUnit: to be overridden!" );
1152*cdf0e10cSrcweir 	}
1153*cdf0e10cSrcweir 
1154*cdf0e10cSrcweir     //-------------------------------------------------------------------------
1155*cdf0e10cSrcweir     sal_Bool HangulHanjaConversion::HasRubySupport() const
1156*cdf0e10cSrcweir     {
1157*cdf0e10cSrcweir         DBG_ERROR( "HangulHanjaConversion::HasRubySupport: to be overridden!" );
1158*cdf0e10cSrcweir         return sal_False;
1159*cdf0e10cSrcweir     }
1160*cdf0e10cSrcweir 
1161*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1162*cdf0e10cSrcweir 	void HangulHanjaConversion::ConvertDocument()
1163*cdf0e10cSrcweir 	{
1164*cdf0e10cSrcweir 		if ( m_pImpl->IsValid() )
1165*cdf0e10cSrcweir 			m_pImpl->DoDocumentConversion( );
1166*cdf0e10cSrcweir 	}
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir //.............................................................................
1169*cdf0e10cSrcweir }	// namespace svx
1170*cdf0e10cSrcweir //.............................................................................
1171*cdf0e10cSrcweir 
1172