xref: /AOO41X/main/cui/source/dialogs/hangulhanjadlg.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_cui.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "hangulhanjadlg.hxx"
32*cdf0e10cSrcweir #include "hangulhanjadlg.hrc"
33*cdf0e10cSrcweir #include "commonlingui.hxx"
34*cdf0e10cSrcweir #include <dialmgr.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include <cuires.hrc>
37*cdf0e10cSrcweir #include "helpid.hrc"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include <algorithm>
40*cdf0e10cSrcweir #include <tools/urlobj.hxx>
41*cdf0e10cSrcweir #include <vcl/controllayout.hxx>
42*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
43*cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
44*cdf0e10cSrcweir #include <unotools/linguprops.hxx>
45*cdf0e10cSrcweir #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/linguistic2/ConversionDirection.hdl>
47*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/i18n/TextConversionOption.hdl>
49*cdf0e10cSrcweir #include <com/sun/star/util/XFlushable.hpp>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #define HHC editeng::HangulHanjaConversion
54*cdf0e10cSrcweir #define LINE_CNT        static_cast< sal_uInt16 >(2)
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //.............................................................................
57*cdf0e10cSrcweir namespace svx
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir //.............................................................................
60*cdf0e10cSrcweir /*
61*cdf0e10cSrcweir 	using HangulHanjaConversion::eSimpleConversion;
62*cdf0e10cSrcweir 	using HangulHanjaConversion::eHangulBracketed;
63*cdf0e10cSrcweir 	using HangulHanjaConversion::eHanjaBracketed;
64*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHanjaAbove;
65*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHanjaBelow;
66*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHangulAbove;
67*cdf0e10cSrcweir 	using HangulHanjaConversion::eRubyHangulBelow;
68*cdf0e10cSrcweir */
69*cdf0e10cSrcweir 	using namespace ::com::sun::star;
70*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
71*cdf0e10cSrcweir 	using namespace ::com::sun::star::linguistic2;
72*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
73*cdf0e10cSrcweir 	using namespace ::com::sun::star::container;
74*cdf0e10cSrcweir 	using ::rtl::OUString;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
77*cdf0e10cSrcweir 	namespace
78*cdf0e10cSrcweir 	{
79*cdf0e10cSrcweir 		class FontSwitch
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir 		private:
82*cdf0e10cSrcweir 			OutputDevice& m_rDev;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 		public:
85*cdf0e10cSrcweir 			inline FontSwitch( OutputDevice& _rDev, const Font& _rTemporaryFont )
86*cdf0e10cSrcweir 				:m_rDev( _rDev )
87*cdf0e10cSrcweir 			{
88*cdf0e10cSrcweir 				m_rDev.Push( PUSH_FONT );
89*cdf0e10cSrcweir 				m_rDev.SetFont( _rTemporaryFont );
90*cdf0e10cSrcweir 			}
91*cdf0e10cSrcweir 			inline ~FontSwitch( )
92*cdf0e10cSrcweir 			{
93*cdf0e10cSrcweir 				m_rDev.Pop( );
94*cdf0e10cSrcweir 			}
95*cdf0e10cSrcweir 		};
96*cdf0e10cSrcweir 	}
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	//=========================================================================
99*cdf0e10cSrcweir 	//= PseudoRubyText
100*cdf0e10cSrcweir 	//=========================================================================
101*cdf0e10cSrcweir 	/** a class which allows to draw two texts in a pseudo-ruby way (which basically
102*cdf0e10cSrcweir 		means one text above or below the other, and a little bit smaller)
103*cdf0e10cSrcweir 	*/
104*cdf0e10cSrcweir 	class PseudoRubyText
105*cdf0e10cSrcweir 	{
106*cdf0e10cSrcweir 	public:
107*cdf0e10cSrcweir 		enum RubyPosition
108*cdf0e10cSrcweir 		{
109*cdf0e10cSrcweir 			eAbove, eBelow
110*cdf0e10cSrcweir 		};
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 	protected:
113*cdf0e10cSrcweir 		const String		m_sPrimaryText;
114*cdf0e10cSrcweir 		const String		m_sSecondaryText;
115*cdf0e10cSrcweir 		const RubyPosition	m_ePosition;
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir 	public:
118*cdf0e10cSrcweir 		PseudoRubyText( const String& _rPrimary, const String& _rSecondary, const RubyPosition _ePosition );
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 	public:
121*cdf0e10cSrcweir 		void Paint( OutputDevice& _rDevice, const Rectangle& _rRect, sal_uInt16 _nTextStyle,
122*cdf0e10cSrcweir 			Rectangle* _pPrimaryLocation = NULL, Rectangle* _pSecondaryLocation = NULL,
123*cdf0e10cSrcweir 			::vcl::ControlLayoutData* _pLayoutData = NULL );
124*cdf0e10cSrcweir 	};
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
127*cdf0e10cSrcweir 	PseudoRubyText::PseudoRubyText( const String& _rPrimary, const String& _rSecondary, const RubyPosition _ePosition )
128*cdf0e10cSrcweir 		:m_sPrimaryText( _rPrimary )
129*cdf0e10cSrcweir 		,m_sSecondaryText( _rSecondary )
130*cdf0e10cSrcweir 		,m_ePosition( _ePosition )
131*cdf0e10cSrcweir 	{
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
135*cdf0e10cSrcweir 	void PseudoRubyText::Paint( OutputDevice& _rDevice, const Rectangle& _rRect, sal_uInt16 _nTextStyle,
136*cdf0e10cSrcweir 		Rectangle* _pPrimaryLocation, Rectangle* _pSecondaryLocation, ::vcl::ControlLayoutData* _pLayoutData )
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		bool			bLayoutOnly	 = NULL != _pLayoutData;
139*cdf0e10cSrcweir 		MetricVector*	pTextMetrics = bLayoutOnly ? &_pLayoutData->m_aUnicodeBoundRects : NULL;
140*cdf0e10cSrcweir 		String*			pDisplayText = bLayoutOnly ? &_pLayoutData->m_aDisplayText		 : NULL;
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 		Size aPlaygroundSize( _rRect.GetSize() );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 		// the font for the secondary text:
145*cdf0e10cSrcweir 		Font aSmallerFont( _rDevice.GetFont() );
146*cdf0e10cSrcweir 		// heuristic: 80% of the original size
147*cdf0e10cSrcweir 		aSmallerFont.SetHeight( (long)( 0.8 * aSmallerFont.GetHeight() ) );
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 		// let's calculate the size of our two texts
150*cdf0e10cSrcweir 		Rectangle aPrimaryRect = _rDevice.GetTextRect( _rRect, m_sPrimaryText, _nTextStyle );
151*cdf0e10cSrcweir 		Rectangle aSecondaryRect;
152*cdf0e10cSrcweir 		{
153*cdf0e10cSrcweir 			FontSwitch aFontRestore( _rDevice, aSmallerFont );
154*cdf0e10cSrcweir 			aSecondaryRect = _rDevice.GetTextRect( _rRect, m_sSecondaryText, _nTextStyle );
155*cdf0e10cSrcweir 		}
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 		// position these rectangles properly
158*cdf0e10cSrcweir 		// x-axis:
159*cdf0e10cSrcweir 		sal_Int32 nCombinedWidth = ::std::max( aSecondaryRect.GetWidth(), aPrimaryRect.GetWidth() );
160*cdf0e10cSrcweir 			// the rectangle where both texts will reside is as high as possible, and as wide as the
161*cdf0e10cSrcweir 			// widest of both text rects
162*cdf0e10cSrcweir 		aPrimaryRect.Left() = aSecondaryRect.Left() = _rRect.Left();
163*cdf0e10cSrcweir 		aPrimaryRect.Right() = aSecondaryRect.Right() = _rRect.Left() + nCombinedWidth;
164*cdf0e10cSrcweir 		if ( TEXT_DRAW_RIGHT & _nTextStyle )
165*cdf0e10cSrcweir 		{
166*cdf0e10cSrcweir 			// move the rectangles to the right
167*cdf0e10cSrcweir 			aPrimaryRect.Move( aPlaygroundSize.Width() - nCombinedWidth, 0 );
168*cdf0e10cSrcweir 			aSecondaryRect.Move( aPlaygroundSize.Width() - nCombinedWidth, 0 );
169*cdf0e10cSrcweir 		}
170*cdf0e10cSrcweir 		else if ( TEXT_DRAW_CENTER & _nTextStyle )
171*cdf0e10cSrcweir 		{
172*cdf0e10cSrcweir 			// center the rectangles
173*cdf0e10cSrcweir 			aPrimaryRect.Move( ( aPlaygroundSize.Width() - nCombinedWidth ) / 2, 0 );
174*cdf0e10cSrcweir 			aSecondaryRect.Move( ( aPlaygroundSize.Width() - nCombinedWidth ) / 2, 0 );
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 		// y-axis:
178*cdf0e10cSrcweir 		sal_Int32 nCombinedHeight = aPrimaryRect.GetHeight() + aSecondaryRect.GetHeight();
179*cdf0e10cSrcweir 		// align to the top, for the moment
180*cdf0e10cSrcweir 		aPrimaryRect.Move( 0, _rRect.Top() - aPrimaryRect.Top() );
181*cdf0e10cSrcweir 		aSecondaryRect.Move( 0, aPrimaryRect.Top() + aPrimaryRect.GetHeight() - aSecondaryRect.Top() );
182*cdf0e10cSrcweir 		if ( TEXT_DRAW_BOTTOM & _nTextStyle )
183*cdf0e10cSrcweir 		{
184*cdf0e10cSrcweir 			// move the rects to the bottom
185*cdf0e10cSrcweir 			aPrimaryRect.Move( 0, aPlaygroundSize.Height() - nCombinedHeight );
186*cdf0e10cSrcweir 			aSecondaryRect.Move( 0, aPlaygroundSize.Height() - nCombinedHeight );
187*cdf0e10cSrcweir 		}
188*cdf0e10cSrcweir 		else if ( TEXT_DRAW_VCENTER & _nTextStyle )
189*cdf0e10cSrcweir 		{
190*cdf0e10cSrcweir 			// move the rects to the bottom
191*cdf0e10cSrcweir 			aPrimaryRect.Move( 0, ( aPlaygroundSize.Height() - nCombinedHeight ) / 2 );
192*cdf0e10cSrcweir 			aSecondaryRect.Move( 0, ( aPlaygroundSize.Height() - nCombinedHeight ) / 2 );
193*cdf0e10cSrcweir 		}
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 		// 'til here, everything we did assumes that the secondary text is painted _below_ the primary
196*cdf0e10cSrcweir 		// text. If this isn't the case, we need to correct the rectangles
197*cdf0e10cSrcweir 		if ( eAbove == m_ePosition )
198*cdf0e10cSrcweir 		{
199*cdf0e10cSrcweir 			sal_Int32 nVertDistance = aSecondaryRect.Top() - aPrimaryRect.Top();
200*cdf0e10cSrcweir 			aSecondaryRect.Move( 0, -nVertDistance );
201*cdf0e10cSrcweir 			aPrimaryRect.Move( 0, nCombinedHeight - nVertDistance );
202*cdf0e10cSrcweir 		}
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 		// now draw the texts
205*cdf0e10cSrcweir 		// as we already calculated the precise rectangles for the texts, we don't want to
206*cdf0e10cSrcweir 		// use the alignment flags given - within it's rect, every text is centered
207*cdf0e10cSrcweir 		sal_uInt16 nDrawTextStyle( _nTextStyle );
208*cdf0e10cSrcweir 		nDrawTextStyle &= ~( TEXT_DRAW_RIGHT | TEXT_DRAW_LEFT | TEXT_DRAW_BOTTOM | TEXT_DRAW_TOP );
209*cdf0e10cSrcweir 		nDrawTextStyle |= TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER;
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 		_rDevice.DrawText( aPrimaryRect, m_sPrimaryText, nDrawTextStyle, pTextMetrics, pDisplayText );
212*cdf0e10cSrcweir 		{
213*cdf0e10cSrcweir 			FontSwitch aFontRestore( _rDevice, aSmallerFont );
214*cdf0e10cSrcweir 			_rDevice.DrawText( aSecondaryRect, m_sSecondaryText, nDrawTextStyle, pTextMetrics, pDisplayText );
215*cdf0e10cSrcweir 		}
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 		// outta here
218*cdf0e10cSrcweir 		if ( _pPrimaryLocation )
219*cdf0e10cSrcweir 			*_pPrimaryLocation = aPrimaryRect;
220*cdf0e10cSrcweir 		if ( _pSecondaryLocation )
221*cdf0e10cSrcweir 			*_pSecondaryLocation = aSecondaryRect;
222*cdf0e10cSrcweir 	}
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir 	//=========================================================================
225*cdf0e10cSrcweir 	//= RubyRadioButton
226*cdf0e10cSrcweir 	//=========================================================================
227*cdf0e10cSrcweir 	class RubyRadioButton	:public RadioButton
228*cdf0e10cSrcweir 							,protected PseudoRubyText
229*cdf0e10cSrcweir 	{
230*cdf0e10cSrcweir 		using svx::PseudoRubyText::Paint;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	public:
233*cdf0e10cSrcweir 		RubyRadioButton(
234*cdf0e10cSrcweir 			Window* _pParent,
235*cdf0e10cSrcweir 			const ResId& _rId,			// the text in the resource will be taken as primary text
236*cdf0e10cSrcweir 			const String& _rSecondary,	// this will be the secondary text which will be printed somewhat smaller
237*cdf0e10cSrcweir 			const PseudoRubyText::RubyPosition _ePosition );
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	protected:
240*cdf0e10cSrcweir 		virtual void	Paint( const Rectangle& _rRect );
241*cdf0e10cSrcweir 	};
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
244*cdf0e10cSrcweir 	RubyRadioButton::RubyRadioButton( Window* _pParent, const ResId& _rId,
245*cdf0e10cSrcweir 		const String& _rSecondary, const PseudoRubyText::RubyPosition _ePosition )
246*cdf0e10cSrcweir 		:RadioButton( _pParent, _rId )
247*cdf0e10cSrcweir 		,PseudoRubyText( RadioButton::GetText(), _rSecondary, _ePosition )
248*cdf0e10cSrcweir 	{
249*cdf0e10cSrcweir 	}
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
252*cdf0e10cSrcweir 	void RubyRadioButton::Paint( const Rectangle& )
253*cdf0e10cSrcweir 	{
254*cdf0e10cSrcweir 		HideFocus();
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 		// calculate the size of the radio image - we're to paint our text _after_ this image
257*cdf0e10cSrcweir 		DBG_ASSERT( !GetModeRadioImage(), "RubyRadioButton::Paint: images not supported!" );
258*cdf0e10cSrcweir 		Size aImageSize = GetRadioImage( GetSettings(), 0 ).GetSizePixel();
259*cdf0e10cSrcweir 		aImageSize.Width()  = CalcZoom( aImageSize.Width() );
260*cdf0e10cSrcweir 		aImageSize.Height()  = CalcZoom( aImageSize.Height() );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 		Rectangle aOverallRect( Point( 0, 0 ), GetOutputSizePixel() );
263*cdf0e10cSrcweir 		aOverallRect.Left() += aImageSize.Width() + 4;	// 4 is the separator between the image and the text
264*cdf0e10cSrcweir 		// inflate the rect a little bit (because the VCL radio button does the same)
265*cdf0e10cSrcweir 		Rectangle aTextRect( aOverallRect );
266*cdf0e10cSrcweir 		++aTextRect.Left(); --aTextRect.Right();
267*cdf0e10cSrcweir 		++aTextRect.Top(); --aTextRect.Bottom();
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 		// calculate the text flags for the painting
270*cdf0e10cSrcweir 		sal_uInt16 nTextStyle = TEXT_DRAW_MNEMONIC;
271*cdf0e10cSrcweir 		WinBits nStyle = GetStyle( );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 		// the horizontal alignment
274*cdf0e10cSrcweir 		if ( nStyle & WB_RIGHT )
275*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_RIGHT;
276*cdf0e10cSrcweir 		else if ( nStyle & WB_CENTER )
277*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_CENTER;
278*cdf0e10cSrcweir 		else
279*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_LEFT;
280*cdf0e10cSrcweir 		// the vertical alignment
281*cdf0e10cSrcweir 		if ( nStyle & WB_BOTTOM )
282*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_BOTTOM;
283*cdf0e10cSrcweir 		else if ( nStyle & WB_VCENTER )
284*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_VCENTER;
285*cdf0e10cSrcweir 		else
286*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_TOP;
287*cdf0e10cSrcweir 		// mnemonics
288*cdf0e10cSrcweir 		if ( 0 == ( nStyle & WB_NOLABEL ) )
289*cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_MNEMONIC;
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 		// paint the ruby text
292*cdf0e10cSrcweir 		Rectangle aPrimaryTextLocation, aSecondaryTextLocation;
293*cdf0e10cSrcweir 		PseudoRubyText::Paint( *this, aTextRect, nTextStyle, &aPrimaryTextLocation, &aSecondaryTextLocation );
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 		// the focus rectangle is to be painted around both texts
296*cdf0e10cSrcweir 		Rectangle aCombinedRect( aPrimaryTextLocation );
297*cdf0e10cSrcweir 		aCombinedRect.Union( aSecondaryTextLocation );
298*cdf0e10cSrcweir 		SetFocusRect( aCombinedRect );
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 		// let the base class paint the radio button
301*cdf0e10cSrcweir 		// for this, give it the proper location to paint the image (vertically centered, relative to our text)
302*cdf0e10cSrcweir 		Rectangle aImageLocation( Point( 0, 0 ), aImageSize );
303*cdf0e10cSrcweir 		sal_Int32 nTextHeight = aSecondaryTextLocation.Bottom() - aPrimaryTextLocation.Top();
304*cdf0e10cSrcweir 		aImageLocation.Top() = aPrimaryTextLocation.Top() + ( nTextHeight - aImageSize.Height() ) / 2;
305*cdf0e10cSrcweir 		aImageLocation.Bottom() = aImageLocation.Top() + aImageSize.Height();
306*cdf0e10cSrcweir 		SetStateRect( aImageLocation );
307*cdf0e10cSrcweir 		DrawRadioButtonState( );
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 		// mouse clicks should be recognized in a rect which is one pixel larger in each direction, plus
310*cdf0e10cSrcweir 		// includes the image
311*cdf0e10cSrcweir 		aCombinedRect.Left() = aImageLocation.Left(); ++aCombinedRect.Right();
312*cdf0e10cSrcweir 		--aCombinedRect.Top(); ++aCombinedRect.Bottom();
313*cdf0e10cSrcweir 		SetMouseRect( aCombinedRect );
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 		// paint the focus rect, if necessary
316*cdf0e10cSrcweir 		if ( HasFocus() )
317*cdf0e10cSrcweir 			ShowFocus( aTextRect );
318*cdf0e10cSrcweir 	}
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir     //=========================================================================
321*cdf0e10cSrcweir 	//= SuggestionSet
322*cdf0e10cSrcweir 	//=========================================================================
323*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir     SuggestionSet::SuggestionSet( Window* pParent )
326*cdf0e10cSrcweir                     : ValueSet( pParent, pParent->GetStyle() | WB_BORDER )
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir     SuggestionSet::~SuggestionSet()
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         ClearSet();
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     void SuggestionSet::UserDraw( const UserDrawEvent& rUDEvt )
337*cdf0e10cSrcweir     {
338*cdf0e10cSrcweir         OutputDevice*  pDev = rUDEvt.GetDevice();
339*cdf0e10cSrcweir         Rectangle aRect = rUDEvt.GetRect();
340*cdf0e10cSrcweir         sal_uInt16  nItemId = rUDEvt.GetItemId();
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir         String sText = *static_cast< String* >( GetItemData( nItemId ) );
343*cdf0e10cSrcweir         pDev->DrawText( aRect, sText, TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER );
344*cdf0e10cSrcweir     }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     void SuggestionSet::ClearSet()
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         sal_uInt16 i, nCount = GetItemCount();
349*cdf0e10cSrcweir         for ( i = 0; i < nCount; ++i )
350*cdf0e10cSrcweir             delete static_cast< String* >( GetItemData(i) );
351*cdf0e10cSrcweir         Clear();
352*cdf0e10cSrcweir     }
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     //=========================================================================
355*cdf0e10cSrcweir 	//= SuggestionDisplay
356*cdf0e10cSrcweir 	//=========================================================================
357*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
358*cdf0e10cSrcweir 
359*cdf0e10cSrcweir     SuggestionDisplay::SuggestionDisplay( Window* pParent, const ResId& rResId )
360*cdf0e10cSrcweir         : Control( pParent, rResId )
361*cdf0e10cSrcweir         , m_bDisplayListBox(true)
362*cdf0e10cSrcweir         , m_aValueSet(this)
363*cdf0e10cSrcweir         , m_aListBox(this,GetStyle() | WB_BORDER )
364*cdf0e10cSrcweir         , m_bInSelectionUpdate(false)
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         m_aValueSet.SetSelectHdl( LINK( this, SuggestionDisplay, SelectSuggestionHdl ) );
367*cdf0e10cSrcweir         m_aListBox.SetSelectHdl( LINK( this, SuggestionDisplay, SelectSuggestionHdl ) );
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir         m_aValueSet.SetLineCount( LINE_CNT );
370*cdf0e10cSrcweir         m_aValueSet.SetStyle( m_aValueSet.GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_VSCROLL );
371*cdf0e10cSrcweir         m_aValueSet.SetBorderStyle( WINDOW_BORDER_MONO );
372*cdf0e10cSrcweir         String aOneCharacter(RTL_CONSTASCII_STRINGPARAM("AU"));
373*cdf0e10cSrcweir         long nItemWidth = 2*GetTextWidth( aOneCharacter );
374*cdf0e10cSrcweir         m_aValueSet.SetItemWidth( nItemWidth );
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir         Point aPos(0,0);
377*cdf0e10cSrcweir         Size aSize(GetSizePixel());
378*cdf0e10cSrcweir         m_aValueSet.SetSizePixel(aSize);
379*cdf0e10cSrcweir         m_aListBox.SetSizePixel(aSize);
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir         implUpdateDisplay();
382*cdf0e10cSrcweir     }
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir     SuggestionDisplay::~SuggestionDisplay()
385*cdf0e10cSrcweir     {
386*cdf0e10cSrcweir     }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     void SuggestionDisplay::implUpdateDisplay()
389*cdf0e10cSrcweir     {
390*cdf0e10cSrcweir         bool bShowBox = IsVisible() && m_bDisplayListBox;
391*cdf0e10cSrcweir         bool bShowSet = IsVisible() && !m_bDisplayListBox;
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir         m_aListBox.Show(bShowBox);
394*cdf0e10cSrcweir         m_aValueSet.Show(bShowSet);
395*cdf0e10cSrcweir     }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir     void SuggestionDisplay::StateChanged( StateChangedType nStateChange )
398*cdf0e10cSrcweir     {
399*cdf0e10cSrcweir         if( STATE_CHANGE_VISIBLE == nStateChange )
400*cdf0e10cSrcweir             implUpdateDisplay();
401*cdf0e10cSrcweir     }
402*cdf0e10cSrcweir 
403*cdf0e10cSrcweir     Control& SuggestionDisplay::implGetCurrentControl()
404*cdf0e10cSrcweir     {
405*cdf0e10cSrcweir         if( m_bDisplayListBox )
406*cdf0e10cSrcweir             return m_aListBox;
407*cdf0e10cSrcweir         return m_aValueSet;
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir     void SuggestionDisplay::KeyInput( const KeyEvent& rKEvt )
411*cdf0e10cSrcweir     {
412*cdf0e10cSrcweir         implGetCurrentControl().KeyInput( rKEvt );
413*cdf0e10cSrcweir     }
414*cdf0e10cSrcweir     void SuggestionDisplay::KeyUp( const KeyEvent& rKEvt )
415*cdf0e10cSrcweir     {
416*cdf0e10cSrcweir         implGetCurrentControl().KeyUp( rKEvt );
417*cdf0e10cSrcweir     }
418*cdf0e10cSrcweir     void SuggestionDisplay::Activate()
419*cdf0e10cSrcweir     {
420*cdf0e10cSrcweir         implGetCurrentControl().Activate();
421*cdf0e10cSrcweir     }
422*cdf0e10cSrcweir     void SuggestionDisplay::Deactivate()
423*cdf0e10cSrcweir     {
424*cdf0e10cSrcweir         implGetCurrentControl().Deactivate();
425*cdf0e10cSrcweir     }
426*cdf0e10cSrcweir     void SuggestionDisplay::GetFocus()
427*cdf0e10cSrcweir     {
428*cdf0e10cSrcweir         implGetCurrentControl().GetFocus();
429*cdf0e10cSrcweir     }
430*cdf0e10cSrcweir 	void SuggestionDisplay::LoseFocus()
431*cdf0e10cSrcweir     {
432*cdf0e10cSrcweir         implGetCurrentControl().LoseFocus();
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir     void SuggestionDisplay::Command( const CommandEvent& rCEvt )
435*cdf0e10cSrcweir     {
436*cdf0e10cSrcweir         implGetCurrentControl().Command( rCEvt );
437*cdf0e10cSrcweir     }
438*cdf0e10cSrcweir 
439*cdf0e10cSrcweir     void SuggestionDisplay::DisplayListBox( bool bDisplayListBox )
440*cdf0e10cSrcweir     {
441*cdf0e10cSrcweir         if( m_bDisplayListBox != bDisplayListBox )
442*cdf0e10cSrcweir         {
443*cdf0e10cSrcweir             Control& rOldControl = implGetCurrentControl();
444*cdf0e10cSrcweir             sal_Bool bHasFocus = rOldControl.HasFocus();
445*cdf0e10cSrcweir 
446*cdf0e10cSrcweir             m_bDisplayListBox = bDisplayListBox;
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir             if( bHasFocus )
449*cdf0e10cSrcweir             {
450*cdf0e10cSrcweir                 Control& rNewControl = implGetCurrentControl();
451*cdf0e10cSrcweir                 rNewControl.GrabFocus();
452*cdf0e10cSrcweir             }
453*cdf0e10cSrcweir 
454*cdf0e10cSrcweir             implUpdateDisplay();
455*cdf0e10cSrcweir         }
456*cdf0e10cSrcweir     }
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     IMPL_LINK( SuggestionDisplay, SelectSuggestionHdl, Control*, pControl )
459*cdf0e10cSrcweir     {
460*cdf0e10cSrcweir         if( m_bInSelectionUpdate )
461*cdf0e10cSrcweir             return 0L;
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir         m_bInSelectionUpdate = true;
464*cdf0e10cSrcweir         if(pControl==&m_aListBox)
465*cdf0e10cSrcweir         {
466*cdf0e10cSrcweir             sal_uInt16 nPos = m_aListBox.GetSelectEntryPos();
467*cdf0e10cSrcweir             m_aValueSet.SelectItem( nPos+1 ); //itemid == pos+1 (id 0 has special meaning)
468*cdf0e10cSrcweir         }
469*cdf0e10cSrcweir         else
470*cdf0e10cSrcweir         {
471*cdf0e10cSrcweir             sal_uInt16 nPos = m_aValueSet.GetSelectItemId()-1; //itemid == pos+1 (id 0 has special meaning)
472*cdf0e10cSrcweir             m_aListBox.SelectEntryPos( nPos );
473*cdf0e10cSrcweir         }
474*cdf0e10cSrcweir         m_bInSelectionUpdate = false;
475*cdf0e10cSrcweir         m_aSelectLink.Call(this);
476*cdf0e10cSrcweir         return 0L;
477*cdf0e10cSrcweir     }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir     void SuggestionDisplay::SetSelectHdl( const Link& rLink )
480*cdf0e10cSrcweir     {
481*cdf0e10cSrcweir         m_aSelectLink = rLink;
482*cdf0e10cSrcweir     }
483*cdf0e10cSrcweir     void SuggestionDisplay::Clear()
484*cdf0e10cSrcweir     {
485*cdf0e10cSrcweir         m_aListBox.Clear();
486*cdf0e10cSrcweir         m_aValueSet.Clear();
487*cdf0e10cSrcweir     }
488*cdf0e10cSrcweir     void SuggestionDisplay::InsertEntry( const XubString& rStr )
489*cdf0e10cSrcweir     {
490*cdf0e10cSrcweir         sal_uInt16 nItemId = m_aListBox.InsertEntry( rStr ) + 1; //itemid == pos+1 (id 0 has special meaning)
491*cdf0e10cSrcweir         m_aValueSet.InsertItem( nItemId );
492*cdf0e10cSrcweir         String* pItemData = new String(rStr);
493*cdf0e10cSrcweir         m_aValueSet.SetItemData( nItemId, pItemData );
494*cdf0e10cSrcweir     }
495*cdf0e10cSrcweir     void SuggestionDisplay::SelectEntryPos( sal_uInt16 nPos )
496*cdf0e10cSrcweir     {
497*cdf0e10cSrcweir         m_aListBox.SelectEntryPos( nPos );
498*cdf0e10cSrcweir         m_aValueSet.SelectItem( nPos+1 ); //itemid == pos+1 (id 0 has special meaning)
499*cdf0e10cSrcweir     }
500*cdf0e10cSrcweir     sal_uInt16 SuggestionDisplay::GetEntryCount() const
501*cdf0e10cSrcweir     {
502*cdf0e10cSrcweir         return m_aListBox.GetEntryCount();
503*cdf0e10cSrcweir     }
504*cdf0e10cSrcweir     XubString SuggestionDisplay::GetEntry( sal_uInt16 nPos ) const
505*cdf0e10cSrcweir     {
506*cdf0e10cSrcweir         return m_aListBox.GetEntry( nPos );
507*cdf0e10cSrcweir     }
508*cdf0e10cSrcweir     XubString SuggestionDisplay::GetSelectEntry() const
509*cdf0e10cSrcweir     {
510*cdf0e10cSrcweir         return m_aListBox.GetSelectEntry();
511*cdf0e10cSrcweir     }
512*cdf0e10cSrcweir     void SuggestionDisplay::SetHelpIds()
513*cdf0e10cSrcweir     {
514*cdf0e10cSrcweir         this->SetHelpId( HID_HANGULDLG_SUGGESTIONS );
515*cdf0e10cSrcweir         m_aValueSet.SetHelpId( HID_HANGULDLG_SUGGESTIONS_GRID );
516*cdf0e10cSrcweir         m_aListBox.SetHelpId( HID_HANGULDLG_SUGGESTIONS_LIST );
517*cdf0e10cSrcweir     }
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir     //=========================================================================
520*cdf0e10cSrcweir 	//= HangulHanjaConversionDialog
521*cdf0e10cSrcweir 	//=========================================================================
522*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
523*cdf0e10cSrcweir     HangulHanjaConversionDialog::HangulHanjaConversionDialog( Window* _pParent, HHC::ConversionDirection _ePrimaryDirection )
524*cdf0e10cSrcweir 		:ModalDialog( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA ) )
525*cdf0e10cSrcweir 		,m_pPlayground( new SvxCommonLinguisticControl( this ) )
526*cdf0e10cSrcweir 		,m_aFind			( m_pPlayground.get(), CUI_RES( PB_FIND ) )
527*cdf0e10cSrcweir 		,m_aSuggestions		( m_pPlayground.get(), CUI_RES( CTL_SUGGESTIONS ) )
528*cdf0e10cSrcweir 		,m_aFormat			( m_pPlayground.get(), CUI_RES( FT_FORMAT ) )
529*cdf0e10cSrcweir 		,m_aSimpleConversion( m_pPlayground.get(), CUI_RES( RB_SIMPLE_CONVERSION ) )
530*cdf0e10cSrcweir 		,m_aHangulBracketed	( m_pPlayground.get(), CUI_RES( RB_HANJA_HANGUL_BRACKETED ) )
531*cdf0e10cSrcweir 		,m_aHanjaBracketed	( m_pPlayground.get(), CUI_RES( RB_HANGUL_HANJA_BRACKETED ) )
532*cdf0e10cSrcweir 		,m_aConversion		( m_pPlayground.get(), CUI_RES( FT_CONVERSION ) )
533*cdf0e10cSrcweir 		,m_aHangulOnly		( m_pPlayground.get(), CUI_RES( CB_HANGUL_ONLY ) )
534*cdf0e10cSrcweir 		,m_aHanjaOnly		( m_pPlayground.get(), CUI_RES( CB_HANJA_ONLY ) )
535*cdf0e10cSrcweir 		,m_aReplaceByChar	( m_pPlayground.get(), CUI_RES( CB_REPLACE_BY_CHARACTER ) )
536*cdf0e10cSrcweir 		,m_pIgnoreNonPrimary( NULL )
537*cdf0e10cSrcweir 		,m_bDocumentMode( true )
538*cdf0e10cSrcweir 	{
539*cdf0e10cSrcweir 		// special creation of the 4 pseudo-ruby radio buttons
540*cdf0e10cSrcweir 		String sSecondaryHangul( CUI_RES( STR_HANGUL ) );
541*cdf0e10cSrcweir 		String sSecondaryHanja( CUI_RES( STR_HANJA ) );
542*cdf0e10cSrcweir 		m_pHanjaAbove.reset( new RubyRadioButton( m_pPlayground.get(), CUI_RES( RB_HANGUL_HANJA_ABOVE ), sSecondaryHanja, PseudoRubyText::eAbove ) );
543*cdf0e10cSrcweir 		m_pHanjaBelow.reset( new RubyRadioButton( m_pPlayground.get(), CUI_RES( RB_HANGUL_HANJA_BELOW ), sSecondaryHanja, PseudoRubyText::eBelow ) );
544*cdf0e10cSrcweir 		m_pHangulAbove.reset( new RubyRadioButton( m_pPlayground.get(), CUI_RES( RB_HANJA_HANGUL_ABOVE ), sSecondaryHangul, PseudoRubyText::eAbove ) );
545*cdf0e10cSrcweir 		m_pHangulBelow.reset( new RubyRadioButton( m_pPlayground.get(), CUI_RES( RB_HANJA_HANGUL_BELOW ), sSecondaryHangul, PseudoRubyText::eBelow ) );
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir 		// since these 4 buttons are not created within the other members, they have a wrong initial Z-Order
548*cdf0e10cSrcweir 		// correct this
549*cdf0e10cSrcweir 		m_pHanjaAbove->SetZOrder( &m_aHanjaBracketed, WINDOW_ZORDER_BEHIND );
550*cdf0e10cSrcweir 		m_pHanjaBelow->SetZOrder( m_pHanjaAbove.get(), WINDOW_ZORDER_BEHIND );
551*cdf0e10cSrcweir 		m_pHangulAbove->SetZOrder( m_pHanjaBelow.get(), WINDOW_ZORDER_BEHIND );
552*cdf0e10cSrcweir 		m_pHangulBelow->SetZOrder( m_pHangulAbove.get(), WINDOW_ZORDER_BEHIND );
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 		// VCL automatically sets the WB_GROUP bit, if the previous sibling (at the moment of creation)
555*cdf0e10cSrcweir 		// is no radion button
556*cdf0e10cSrcweir 		m_pHanjaAbove->SetStyle( m_pHanjaAbove->GetStyle() & ~WB_GROUP );
557*cdf0e10cSrcweir 
558*cdf0e10cSrcweir 		// the "Find" button and the word input control may not have the proper distance/extensions
559*cdf0e10cSrcweir 		// -> correct this
560*cdf0e10cSrcweir 		Point aDistance = LogicToPixel( Point( 3, 0 ), MAP_APPFONT );
561*cdf0e10cSrcweir 		sal_Int32 nTooLargeByPixels =
562*cdf0e10cSrcweir 			// right margin of the word input control
563*cdf0e10cSrcweir 			(	m_pPlayground->GetWordInputControl().GetPosPixel().X()
564*cdf0e10cSrcweir 			+	m_pPlayground->GetWordInputControl().GetSizePixel().Width()
565*cdf0e10cSrcweir 			)
566*cdf0e10cSrcweir 			// minus left margin of the find button
567*cdf0e10cSrcweir 			-	m_aFind.GetPosPixel().X()
568*cdf0e10cSrcweir 			// plus desired distance between the both
569*cdf0e10cSrcweir 			+	aDistance.X();
570*cdf0e10cSrcweir 		// make the word input control smaller
571*cdf0e10cSrcweir 		Size aSize = m_pPlayground->GetWordInputControl().GetSizePixel();
572*cdf0e10cSrcweir 		aSize.Width() -= nTooLargeByPixels;
573*cdf0e10cSrcweir 		m_pPlayground->GetWordInputControl().SetSizePixel( aSize );
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir 		// additionall, the playground is not wide enough (in it's default size)
576*cdf0e10cSrcweir 		sal_Int32 nEnlargeWidth = 0;
577*cdf0e10cSrcweir 		{
578*cdf0e10cSrcweir 			FixedText aBottomAnchor( m_pPlayground.get(), CUI_RES( FT_RESIZE_ANCHOR ) );
579*cdf0e10cSrcweir 			Point aAnchorPos = aBottomAnchor.GetPosPixel();
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 			nEnlargeWidth = aAnchorPos.X() - m_pPlayground->GetActionButtonsLocation().X();
582*cdf0e10cSrcweir 		}
583*cdf0e10cSrcweir 		m_pPlayground->Enlarge( nEnlargeWidth, 0 );
584*cdf0e10cSrcweir 
585*cdf0e10cSrcweir 		// insert our controls into the z-order of the playground
586*cdf0e10cSrcweir 		m_pPlayground->InsertControlGroup( m_aFind, m_aFind, SvxCommonLinguisticControl::eLeftRightWords );
587*cdf0e10cSrcweir 		m_pPlayground->InsertControlGroup( m_aSuggestions, m_aHanjaOnly, SvxCommonLinguisticControl::eSuggestionLabel );
588*cdf0e10cSrcweir 		m_pPlayground->InsertControlGroup( m_aReplaceByChar, m_aReplaceByChar, SvxCommonLinguisticControl::eActionButtons );
589*cdf0e10cSrcweir 
590*cdf0e10cSrcweir 		m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eClose, LINK( this, HangulHanjaConversionDialog, OnClose ) );
591*cdf0e10cSrcweir 		m_pPlayground->GetWordInputControl().SetModifyHdl( LINK( this,  HangulHanjaConversionDialog, OnSuggestionModified ) );
592*cdf0e10cSrcweir 		m_aSuggestions.SetSelectHdl( LINK( this,  HangulHanjaConversionDialog, OnSuggestionSelected ) );
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir         m_aReplaceByChar.SetClickHdl( LINK( this, HangulHanjaConversionDialog, ClickByCharacterHdl ) );
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 		m_aHangulOnly.SetClickHdl( LINK( this,  HangulHanjaConversionDialog, OnConversionDirectionClicked ) );
597*cdf0e10cSrcweir 		m_aHanjaOnly.SetClickHdl(  LINK( this,  HangulHanjaConversionDialog, OnConversionDirectionClicked ) );
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 		m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eOptions,
600*cdf0e10cSrcweir 										LINK( this, HangulHanjaConversionDialog, OnOption ) );
601*cdf0e10cSrcweir 		m_pPlayground->GetButton( SvxCommonLinguisticControl::eOptions )->Show();
602*cdf0e10cSrcweir //		m_pPlayground->EnableButton( SvxCommonLinguisticControl::eOptions, true );
603*cdf0e10cSrcweir 
604*cdf0e10cSrcweir 		if ( editeng::HangulHanjaConversion::eHangulToHanja == _ePrimaryDirection )
605*cdf0e10cSrcweir 		{
606*cdf0e10cSrcweir //			m_aHanjaOnly.Enable( sal_False );
607*cdf0e10cSrcweir 			m_pIgnoreNonPrimary = &m_aHangulOnly;
608*cdf0e10cSrcweir 		}
609*cdf0e10cSrcweir 		else
610*cdf0e10cSrcweir 		{
611*cdf0e10cSrcweir //			m_aHangulOnly.Enable( sal_False );
612*cdf0e10cSrcweir 			m_pIgnoreNonPrimary = &m_aHanjaOnly;
613*cdf0e10cSrcweir 		}
614*cdf0e10cSrcweir //        m_pIgnoreNonPrimary->Check();
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir 		// initial focus
617*cdf0e10cSrcweir 		FocusSuggestion( );
618*cdf0e10cSrcweir 
619*cdf0e10cSrcweir 		// initial control values
620*cdf0e10cSrcweir 		m_aSimpleConversion.Check();
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir         m_pPlayground->GetButton(SvxCommonLinguisticControl::eClose     )->SetHelpId(HID_HANGULDLG_BUTTON_CLOSE    );
623*cdf0e10cSrcweir         m_pPlayground->GetButton(SvxCommonLinguisticControl::eIgnore    )->SetHelpId(HID_HANGULDLG_BUTTON_IGNORE   );
624*cdf0e10cSrcweir         m_pPlayground->GetButton(SvxCommonLinguisticControl::eIgnoreAll )->SetHelpId(HID_HANGULDLG_BUTTON_IGNOREALL);
625*cdf0e10cSrcweir         m_pPlayground->GetButton(SvxCommonLinguisticControl::eChange    )->SetHelpId(HID_HANGULDLG_BUTTON_CHANGE   );
626*cdf0e10cSrcweir         m_pPlayground->GetButton(SvxCommonLinguisticControl::eChangeAll )->SetHelpId(HID_HANGULDLG_BUTTON_CHANGEALL);
627*cdf0e10cSrcweir 		m_pPlayground->GetButton(SvxCommonLinguisticControl::eOptions   )->SetHelpId(HID_HANGULDLG_BUTTON_OPTIONS  );
628*cdf0e10cSrcweir         m_pPlayground->GetWordInputControl().SetHelpId(HID_HANGULDLG_EDIT_NEWWORD);
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir         FreeResource();
631*cdf0e10cSrcweir 
632*cdf0e10cSrcweir         m_aSuggestions.SetHelpIds();
633*cdf0e10cSrcweir 	}
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
636*cdf0e10cSrcweir 	HangulHanjaConversionDialog::~HangulHanjaConversionDialog( )
637*cdf0e10cSrcweir 	{
638*cdf0e10cSrcweir 	}
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
641*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::FillSuggestions( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rSuggestions )
642*cdf0e10cSrcweir 	{
643*cdf0e10cSrcweir 		m_aSuggestions.Clear();
644*cdf0e10cSrcweir 
645*cdf0e10cSrcweir 		const ::rtl::OUString* pSuggestions = _rSuggestions.getConstArray();
646*cdf0e10cSrcweir 		const ::rtl::OUString* pSuggestionsEnd = _rSuggestions.getConstArray() + _rSuggestions.getLength();
647*cdf0e10cSrcweir 		while ( pSuggestions != pSuggestionsEnd )
648*cdf0e10cSrcweir 			m_aSuggestions.InsertEntry( *pSuggestions++ );
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 		// select the first suggestion, and fill in the suggestion edit field
651*cdf0e10cSrcweir 		String sFirstSuggestion;
652*cdf0e10cSrcweir 		if ( m_aSuggestions.GetEntryCount() )
653*cdf0e10cSrcweir 		{
654*cdf0e10cSrcweir 			sFirstSuggestion = m_aSuggestions.GetEntry( 0 );
655*cdf0e10cSrcweir 			m_aSuggestions.SelectEntryPos( 0 );
656*cdf0e10cSrcweir 		}
657*cdf0e10cSrcweir 		m_pPlayground->GetWordInputControl().SetText( sFirstSuggestion );
658*cdf0e10cSrcweir 		m_pPlayground->GetWordInputControl().SaveValue();
659*cdf0e10cSrcweir 		OnSuggestionModified( &m_pPlayground->GetWordInputControl() );
660*cdf0e10cSrcweir 	}
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir     //-------------------------------------------------------------------------
663*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetOptionsChangedHdl( const Link& _rHdl )
664*cdf0e10cSrcweir 	{
665*cdf0e10cSrcweir 		m_aOptionsChangedLink = _rHdl;
666*cdf0e10cSrcweir 	}
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
669*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetIgnoreHdl( const Link& _rHdl )
670*cdf0e10cSrcweir 	{
671*cdf0e10cSrcweir 		m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eIgnore, _rHdl );
672*cdf0e10cSrcweir 	}
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
675*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetIgnoreAllHdl( const Link& _rHdl )
676*cdf0e10cSrcweir 	{
677*cdf0e10cSrcweir 		m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eIgnoreAll, _rHdl );
678*cdf0e10cSrcweir 	}
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
681*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetChangeHdl( const Link& _rHdl )
682*cdf0e10cSrcweir 	{
683*cdf0e10cSrcweir 		m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eChange, _rHdl );
684*cdf0e10cSrcweir 	}
685*cdf0e10cSrcweir 
686*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
687*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetChangeAllHdl( const Link& _rHdl )
688*cdf0e10cSrcweir 	{
689*cdf0e10cSrcweir 		m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eChangeAll, _rHdl );
690*cdf0e10cSrcweir 	}
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
693*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetFindHdl( const Link& _rHdl )
694*cdf0e10cSrcweir 	{
695*cdf0e10cSrcweir 		m_aFind.SetClickHdl( _rHdl );
696*cdf0e10cSrcweir 	}
697*cdf0e10cSrcweir 
698*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
699*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetConversionFormatChangedHdl( const Link& _rHdl )
700*cdf0e10cSrcweir 	{
701*cdf0e10cSrcweir 		m_aSimpleConversion.SetClickHdl( _rHdl );
702*cdf0e10cSrcweir 		m_aHangulBracketed.SetClickHdl( _rHdl );
703*cdf0e10cSrcweir 		m_aHanjaBracketed.SetClickHdl( _rHdl );
704*cdf0e10cSrcweir 		m_pHanjaAbove->SetClickHdl( _rHdl );
705*cdf0e10cSrcweir 		m_pHanjaBelow->SetClickHdl( _rHdl );
706*cdf0e10cSrcweir 		m_pHangulAbove->SetClickHdl( _rHdl );
707*cdf0e10cSrcweir 		m_pHangulBelow->SetClickHdl( _rHdl );
708*cdf0e10cSrcweir 	}
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
711*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetClickByCharacterHdl( const Link& _rHdl )
712*cdf0e10cSrcweir 	{
713*cdf0e10cSrcweir         m_aClickByCharacterLink = _rHdl;
714*cdf0e10cSrcweir 	}
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
717*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversionDialog, OnSuggestionSelected, void*, EMPTYARG )
718*cdf0e10cSrcweir 	{
719*cdf0e10cSrcweir 		m_pPlayground->GetWordInputControl().SetText( m_aSuggestions.GetSelectEntry() );
720*cdf0e10cSrcweir 		OnSuggestionModified( NULL );
721*cdf0e10cSrcweir 		return 0L;
722*cdf0e10cSrcweir 	}
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
725*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversionDialog, OnSuggestionModified, void*, EMPTYARG )
726*cdf0e10cSrcweir 	{
727*cdf0e10cSrcweir 		m_aFind.Enable( m_pPlayground->GetWordInputControl().GetSavedValue() != m_pPlayground->GetWordInputControl().GetText() );
728*cdf0e10cSrcweir 
729*cdf0e10cSrcweir 		bool bSameLen = m_pPlayground->GetWordInputControl().GetText().Len() == m_pPlayground->GetCurrentText().Len();
730*cdf0e10cSrcweir 		m_pPlayground->EnableButton( SvxCommonLinguisticControl::eChange, m_bDocumentMode && bSameLen );
731*cdf0e10cSrcweir 		m_pPlayground->EnableButton( SvxCommonLinguisticControl::eChangeAll, m_bDocumentMode && bSameLen );
732*cdf0e10cSrcweir 
733*cdf0e10cSrcweir 		return 0L;
734*cdf0e10cSrcweir 	}
735*cdf0e10cSrcweir 
736*cdf0e10cSrcweir     //-------------------------------------------------------------------------
737*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversionDialog, ClickByCharacterHdl, CheckBox *, pBox )
738*cdf0e10cSrcweir     {
739*cdf0e10cSrcweir         m_aClickByCharacterLink.Call(pBox);
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir         bool bByCharacter = pBox->IsChecked();
742*cdf0e10cSrcweir         m_aSuggestions.DisplayListBox( !bByCharacter );
743*cdf0e10cSrcweir 
744*cdf0e10cSrcweir         return 0L;
745*cdf0e10cSrcweir     }
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
748*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversionDialog, OnConversionDirectionClicked, CheckBox *, pBox )
749*cdf0e10cSrcweir 	{
750*cdf0e10cSrcweir 		CheckBox *pOtherBox = 0;
751*cdf0e10cSrcweir 		if (pBox == &m_aHangulOnly)
752*cdf0e10cSrcweir 			pOtherBox = &m_aHanjaOnly;
753*cdf0e10cSrcweir 		else if (pBox == &m_aHanjaOnly)
754*cdf0e10cSrcweir 			pOtherBox = &m_aHangulOnly;
755*cdf0e10cSrcweir 		if (pBox && pOtherBox)
756*cdf0e10cSrcweir 		{
757*cdf0e10cSrcweir 			sal_Bool bBoxChecked = pBox->IsChecked();
758*cdf0e10cSrcweir 			if (bBoxChecked)
759*cdf0e10cSrcweir 				pOtherBox->Check( sal_False );
760*cdf0e10cSrcweir 			pOtherBox->Enable( !bBoxChecked );
761*cdf0e10cSrcweir 		}
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir 		return 0L;
764*cdf0e10cSrcweir 	}
765*cdf0e10cSrcweir 
766*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
767*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversionDialog, OnClose, void*, EMPTYARG )
768*cdf0e10cSrcweir 	{
769*cdf0e10cSrcweir 		Close();
770*cdf0e10cSrcweir 		return 0L;
771*cdf0e10cSrcweir 	}
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaConversionDialog, OnOption, void*, EMPTYARG )
774*cdf0e10cSrcweir 	{
775*cdf0e10cSrcweir 		HangulHanjaOptionsDialog		aOptDlg( this );
776*cdf0e10cSrcweir 		aOptDlg.Execute();
777*cdf0e10cSrcweir         m_aOptionsChangedLink.Call(this);
778*cdf0e10cSrcweir 		return 0L;
779*cdf0e10cSrcweir 	}
780*cdf0e10cSrcweir 
781*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
782*cdf0e10cSrcweir 	String HangulHanjaConversionDialog::GetCurrentString( ) const
783*cdf0e10cSrcweir 	{
784*cdf0e10cSrcweir 		return m_pPlayground->GetCurrentText( );
785*cdf0e10cSrcweir 	}
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
788*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::FocusSuggestion( )
789*cdf0e10cSrcweir 	{
790*cdf0e10cSrcweir 		m_pPlayground->GetWordInputControl().GrabFocus();
791*cdf0e10cSrcweir 	}
792*cdf0e10cSrcweir 
793*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
794*cdf0e10cSrcweir 	namespace
795*cdf0e10cSrcweir 	{
796*cdf0e10cSrcweir 		void lcl_modifyWindowStyle( Window* _pWin, WinBits _nSet, WinBits _nReset )
797*cdf0e10cSrcweir 		{
798*cdf0e10cSrcweir 			DBG_ASSERT( 0 == ( _nSet & _nReset ), "lcl_modifyWindowStyle: set _and_ reset the same bit?" );
799*cdf0e10cSrcweir 			if ( _pWin )
800*cdf0e10cSrcweir 				_pWin->SetStyle( ( _pWin->GetStyle() | _nSet ) & ~_nReset );
801*cdf0e10cSrcweir 		}
802*cdf0e10cSrcweir 	}
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
805*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetCurrentString( const String& _rNewString,
806*cdf0e10cSrcweir 		const Sequence< ::rtl::OUString >& _rSuggestions, bool _bOriginatesFromDocument )
807*cdf0e10cSrcweir 	{
808*cdf0e10cSrcweir 		m_pPlayground->SetCurrentText( _rNewString );
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir 		bool bOldDocumentMode = m_bDocumentMode;
811*cdf0e10cSrcweir 		m_bDocumentMode = _bOriginatesFromDocument;	// before FillSuggestions!
812*cdf0e10cSrcweir 		FillSuggestions( _rSuggestions );
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 		m_pPlayground->EnableButton( SvxCommonLinguisticControl::eIgnoreAll, m_bDocumentMode );
815*cdf0e10cSrcweir 			// all other buttons have been implicitly enabled or disabled during filling in the suggestions
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir 		// switch the def button depending if we're working for document text
818*cdf0e10cSrcweir 		if ( bOldDocumentMode != m_bDocumentMode )
819*cdf0e10cSrcweir 		{
820*cdf0e10cSrcweir 			Window* pOldDefButton = NULL;
821*cdf0e10cSrcweir 			Window* pNewDefButton = NULL;
822*cdf0e10cSrcweir 			if ( m_bDocumentMode )
823*cdf0e10cSrcweir 			{
824*cdf0e10cSrcweir 				pOldDefButton = &m_aFind;
825*cdf0e10cSrcweir 				pNewDefButton = m_pPlayground->GetButton( SvxCommonLinguisticControl::eChange );
826*cdf0e10cSrcweir 			}
827*cdf0e10cSrcweir 			else
828*cdf0e10cSrcweir 			{
829*cdf0e10cSrcweir 				pOldDefButton = m_pPlayground->GetButton( SvxCommonLinguisticControl::eChange );
830*cdf0e10cSrcweir 				pNewDefButton = &m_aFind;
831*cdf0e10cSrcweir 			}
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir 			DBG_ASSERT( WB_DEFBUTTON == ( pOldDefButton->GetStyle( ) & WB_DEFBUTTON ),
834*cdf0e10cSrcweir 				"HangulHanjaConversionDialog::SetCurrentString: wrong previous default button (1)!" );
835*cdf0e10cSrcweir 			DBG_ASSERT( 0 == ( pNewDefButton->GetStyle( ) & WB_DEFBUTTON ),
836*cdf0e10cSrcweir 				"HangulHanjaConversionDialog::SetCurrentString: wrong previous default button (2)!" );
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir 			lcl_modifyWindowStyle( pOldDefButton, 0, WB_DEFBUTTON );
839*cdf0e10cSrcweir 			lcl_modifyWindowStyle( pNewDefButton, WB_DEFBUTTON, 0 );
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir 			// give the focus to the new def button temporarily - VCL is somewhat peculiar
842*cdf0e10cSrcweir 			// in recognizing a new default button
843*cdf0e10cSrcweir 			sal_uInt32 nSaveFocusId = Window::SaveFocus();
844*cdf0e10cSrcweir 			pNewDefButton->GrabFocus();
845*cdf0e10cSrcweir 			Window::EndSaveFocus( nSaveFocusId );
846*cdf0e10cSrcweir 		}
847*cdf0e10cSrcweir 	}
848*cdf0e10cSrcweir 
849*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
850*cdf0e10cSrcweir 	String HangulHanjaConversionDialog::GetCurrentSuggestion( ) const
851*cdf0e10cSrcweir 	{
852*cdf0e10cSrcweir 		return m_pPlayground->GetWordInputControl().GetText();
853*cdf0e10cSrcweir 	}
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
856*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetByCharacter( sal_Bool _bByCharacter )
857*cdf0e10cSrcweir 	{
858*cdf0e10cSrcweir 		m_aReplaceByChar.Check( _bByCharacter );
859*cdf0e10cSrcweir 		m_aSuggestions.DisplayListBox( !_bByCharacter );
860*cdf0e10cSrcweir 	}
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
863*cdf0e10cSrcweir 	void HangulHanjaConversionDialog::SetConversionDirectionState(
864*cdf0e10cSrcweir 			sal_Bool _bTryBothDirections,
865*cdf0e10cSrcweir 			HHC::ConversionDirection _ePrimaryConversionDirection )
866*cdf0e10cSrcweir 	{
867*cdf0e10cSrcweir 		// default state: try both direction
868*cdf0e10cSrcweir 		m_aHangulOnly.Check( sal_False );
869*cdf0e10cSrcweir 		m_aHangulOnly.Enable( sal_True );
870*cdf0e10cSrcweir 		m_aHanjaOnly.Check( sal_False );
871*cdf0e10cSrcweir 		m_aHanjaOnly.Enable( sal_True );
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir 		if (!_bTryBothDirections)
874*cdf0e10cSrcweir 		{
875*cdf0e10cSrcweir 			CheckBox *pBox = _ePrimaryConversionDirection == HHC::eHangulToHanja?
876*cdf0e10cSrcweir 									&m_aHangulOnly : &m_aHanjaOnly;
877*cdf0e10cSrcweir 			pBox->Check( sal_True );
878*cdf0e10cSrcweir 			OnConversionDirectionClicked( pBox );
879*cdf0e10cSrcweir 		}
880*cdf0e10cSrcweir 	}
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
883*cdf0e10cSrcweir 	sal_Bool HangulHanjaConversionDialog::GetUseBothDirections( ) const
884*cdf0e10cSrcweir 	{
885*cdf0e10cSrcweir //		DBG_ASSERT( m_pIgnoreNonPrimary, "HangulHanjaConversionDialog::GetUseBothDirections: where's the check box pointer?" );
886*cdf0e10cSrcweir //		return m_pIgnoreNonPrimary ? !m_pIgnoreNonPrimary->IsChecked( ) : sal_True;
887*cdf0e10cSrcweir 		return !m_aHangulOnly.IsChecked() && !m_aHanjaOnly.IsChecked();
888*cdf0e10cSrcweir 	}
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
891*cdf0e10cSrcweir 	HHC::ConversionDirection HangulHanjaConversionDialog::GetDirection(
892*cdf0e10cSrcweir 			HHC::ConversionDirection eDefaultDirection ) const
893*cdf0e10cSrcweir 	{
894*cdf0e10cSrcweir 		HHC::ConversionDirection eDirection = eDefaultDirection;
895*cdf0e10cSrcweir 		if (m_aHangulOnly.IsChecked() && !m_aHanjaOnly.IsChecked())
896*cdf0e10cSrcweir 			eDirection = HHC::eHangulToHanja;
897*cdf0e10cSrcweir 		else if (!m_aHangulOnly.IsChecked() && m_aHanjaOnly.IsChecked())
898*cdf0e10cSrcweir 			eDirection = HHC::eHanjaToHangul;
899*cdf0e10cSrcweir 		return eDirection;
900*cdf0e10cSrcweir 	}
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
903*cdf0e10cSrcweir     void HangulHanjaConversionDialog::SetConversionFormat( HHC::ConversionFormat _eType )
904*cdf0e10cSrcweir 	{
905*cdf0e10cSrcweir 		switch ( _eType )
906*cdf0e10cSrcweir 		{
907*cdf0e10cSrcweir             case HHC::eSimpleConversion: m_aSimpleConversion.Check(); break;
908*cdf0e10cSrcweir             case HHC::eHangulBracketed: m_aHangulBracketed.Check(); break;
909*cdf0e10cSrcweir             case HHC::eHanjaBracketed:  m_aHanjaBracketed.Check(); break;
910*cdf0e10cSrcweir             case HHC::eRubyHanjaAbove:  m_pHanjaAbove->Check(); break;
911*cdf0e10cSrcweir             case HHC::eRubyHanjaBelow:  m_pHanjaBelow->Check(); break;
912*cdf0e10cSrcweir             case HHC::eRubyHangulAbove: m_pHangulAbove->Check(); break;
913*cdf0e10cSrcweir             case HHC::eRubyHangulBelow: m_pHangulBelow->Check(); break;
914*cdf0e10cSrcweir 		default:
915*cdf0e10cSrcweir 			DBG_ERROR( "HangulHanjaConversionDialog::SetConversionFormat: unknown type!" );
916*cdf0e10cSrcweir 		}
917*cdf0e10cSrcweir 	}
918*cdf0e10cSrcweir 
919*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
920*cdf0e10cSrcweir     HHC::ConversionFormat HangulHanjaConversionDialog::GetConversionFormat( ) const
921*cdf0e10cSrcweir 	{
922*cdf0e10cSrcweir 		if ( m_aSimpleConversion.IsChecked() )
923*cdf0e10cSrcweir             return HHC::eSimpleConversion;
924*cdf0e10cSrcweir 		if ( m_aHangulBracketed.IsChecked() )
925*cdf0e10cSrcweir             return HHC::eHangulBracketed;
926*cdf0e10cSrcweir 		if ( m_aHanjaBracketed.IsChecked() )
927*cdf0e10cSrcweir             return HHC::eHanjaBracketed;
928*cdf0e10cSrcweir 		if ( m_pHanjaAbove->IsChecked() )
929*cdf0e10cSrcweir             return HHC::eRubyHanjaAbove;
930*cdf0e10cSrcweir 		if ( m_pHanjaBelow->IsChecked() )
931*cdf0e10cSrcweir             return HHC::eRubyHanjaBelow;
932*cdf0e10cSrcweir 		if ( m_pHangulAbove->IsChecked() )
933*cdf0e10cSrcweir             return HHC::eRubyHangulAbove;
934*cdf0e10cSrcweir 		if ( m_pHangulBelow->IsChecked() )
935*cdf0e10cSrcweir             return HHC::eRubyHangulBelow;
936*cdf0e10cSrcweir 
937*cdf0e10cSrcweir 		DBG_ERROR( "HangulHanjaConversionDialog::GetConversionFormat: no radio checked?" );
938*cdf0e10cSrcweir         return HHC::eSimpleConversion;
939*cdf0e10cSrcweir 	}
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir     //-------------------------------------------------------------------------
942*cdf0e10cSrcweir     void HangulHanjaConversionDialog::EnableRubySupport( sal_Bool bVal )
943*cdf0e10cSrcweir     {
944*cdf0e10cSrcweir         m_pHanjaAbove->Enable( bVal );
945*cdf0e10cSrcweir         m_pHanjaBelow->Enable( bVal );
946*cdf0e10cSrcweir         m_pHangulAbove->Enable( bVal );
947*cdf0e10cSrcweir         m_pHangulBelow->Enable( bVal );
948*cdf0e10cSrcweir     }
949*cdf0e10cSrcweir 
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir 	//=========================================================================
952*cdf0e10cSrcweir 	//= HangulHanjaOptionsDialog
953*cdf0e10cSrcweir 	//=========================================================================
954*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
955*cdf0e10cSrcweir 
956*cdf0e10cSrcweir 	void HangulHanjaOptionsDialog::Init( void )
957*cdf0e10cSrcweir 	{
958*cdf0e10cSrcweir         if( !m_xConversionDictionaryList.is() )
959*cdf0e10cSrcweir         {
960*cdf0e10cSrcweir             Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
961*cdf0e10cSrcweir 		    if( xMgr.is() )
962*cdf0e10cSrcweir 		    {
963*cdf0e10cSrcweir 			    m_xConversionDictionaryList = Reference< XConversionDictionaryList >( xMgr->createInstance(
964*cdf0e10cSrcweir 				    OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.ConversionDictionaryList")) ),
965*cdf0e10cSrcweir 				    UNO_QUERY );
966*cdf0e10cSrcweir 		    }
967*cdf0e10cSrcweir         }
968*cdf0e10cSrcweir 
969*cdf0e10cSrcweir 		m_aDictList.clear();
970*cdf0e10cSrcweir         m_aDictsLB.Clear();
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir 		if( m_xConversionDictionaryList.is() )
973*cdf0e10cSrcweir 		{
974*cdf0e10cSrcweir 			Reference< XNameContainer >	xNameCont = m_xConversionDictionaryList->getDictionaryContainer();
975*cdf0e10cSrcweir 			Reference< XNameAccess >	xNameAccess = Reference< XNameAccess >( xNameCont, UNO_QUERY );
976*cdf0e10cSrcweir 			if( xNameAccess.is() )
977*cdf0e10cSrcweir 			{
978*cdf0e10cSrcweir 				Sequence< ::rtl::OUString >		aDictNames( xNameAccess->getElementNames() );
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir 				const ::rtl::OUString*			pDic = aDictNames.getConstArray();
981*cdf0e10cSrcweir 				sal_Int32						nCount = aDictNames.getLength();
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir 				sal_Int32						i;
984*cdf0e10cSrcweir 				for( i = 0 ; i < nCount ; ++i )
985*cdf0e10cSrcweir 				{
986*cdf0e10cSrcweir 					Any									aAny( xNameAccess->getByName( pDic[ i ] ) );
987*cdf0e10cSrcweir 					Reference< XConversionDictionary >	xDic;
988*cdf0e10cSrcweir 					if( ( aAny >>= xDic ) && xDic.is() )
989*cdf0e10cSrcweir                     {
990*cdf0e10cSrcweir                         if( LANGUAGE_KOREAN == SvxLocaleToLanguage( xDic->getLocale() ) )
991*cdf0e10cSrcweir                         {
992*cdf0e10cSrcweir                             m_aDictList.push_back( xDic );
993*cdf0e10cSrcweir                             AddDict( xDic->getName(), xDic->isActive() );
994*cdf0e10cSrcweir                         }
995*cdf0e10cSrcweir                     }
996*cdf0e10cSrcweir 				}
997*cdf0e10cSrcweir 			}
998*cdf0e10cSrcweir 		}
999*cdf0e10cSrcweir 	}
1000*cdf0e10cSrcweir 
1001*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaOptionsDialog, OkHdl, void*, EMPTYARG )
1002*cdf0e10cSrcweir 	{
1003*cdf0e10cSrcweir 		sal_uInt32				nCnt = m_aDictList.size();
1004*cdf0e10cSrcweir 		sal_uInt32				n = 0;
1005*cdf0e10cSrcweir 		sal_uInt32				nActiveDics = 0;
1006*cdf0e10cSrcweir 	    Sequence< OUString >	aActiveDics;
1007*cdf0e10cSrcweir 
1008*cdf0e10cSrcweir 		aActiveDics.realloc( nCnt );
1009*cdf0e10cSrcweir 		OUString*				pActActiveDic = aActiveDics.getArray();
1010*cdf0e10cSrcweir 
1011*cdf0e10cSrcweir 		while( nCnt )
1012*cdf0e10cSrcweir 		{
1013*cdf0e10cSrcweir             Reference< XConversionDictionary >	xDict = m_aDictList[ n ];
1014*cdf0e10cSrcweir 			SvLBoxEntry*						pEntry = m_aDictsLB.SvTreeListBox::GetEntry( n );
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir 			DBG_ASSERT( xDict.is(), "-HangulHanjaOptionsDialog::OkHdl(): someone is evaporated..." );
1017*cdf0e10cSrcweir 			DBG_ASSERT( pEntry, "-HangulHanjaOptionsDialog::OkHdl(): no one there in list?" );
1018*cdf0e10cSrcweir 
1019*cdf0e10cSrcweir 			bool	bActive = m_aDictsLB.GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED;
1020*cdf0e10cSrcweir 			xDict->setActive( bActive );
1021*cdf0e10cSrcweir             Reference< util::XFlushable > xFlush( xDict, uno::UNO_QUERY );
1022*cdf0e10cSrcweir             if( xFlush.is() )
1023*cdf0e10cSrcweir                 xFlush->flush();
1024*cdf0e10cSrcweir 
1025*cdf0e10cSrcweir 			if( bActive )
1026*cdf0e10cSrcweir 			{
1027*cdf0e10cSrcweir 				pActActiveDic[ nActiveDics ] = xDict->getName();
1028*cdf0e10cSrcweir 				++nActiveDics;
1029*cdf0e10cSrcweir 			}
1030*cdf0e10cSrcweir 
1031*cdf0e10cSrcweir 			++n;
1032*cdf0e10cSrcweir 			--nCnt;
1033*cdf0e10cSrcweir 		}
1034*cdf0e10cSrcweir 
1035*cdf0e10cSrcweir 		// save configuration
1036*cdf0e10cSrcweir 		aActiveDics.realloc( nActiveDics );
1037*cdf0e10cSrcweir 		Any				aTmp;
1038*cdf0e10cSrcweir 		SvtLinguConfig	aLngCfg;
1039*cdf0e10cSrcweir 		aTmp <<= aActiveDics;
1040*cdf0e10cSrcweir 		aLngCfg.SetProperty( UPH_ACTIVE_CONVERSION_DICTIONARIES, aTmp );
1041*cdf0e10cSrcweir 
1042*cdf0e10cSrcweir 		aTmp <<= bool( m_aIgnorepostCB.IsChecked() );
1043*cdf0e10cSrcweir 		aLngCfg.SetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD, aTmp );
1044*cdf0e10cSrcweir 
1045*cdf0e10cSrcweir 		aTmp <<= bool( m_aShowrecentlyfirstCB.IsChecked() );
1046*cdf0e10cSrcweir 		aLngCfg.SetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST, aTmp );
1047*cdf0e10cSrcweir 
1048*cdf0e10cSrcweir 		aTmp <<= bool( m_aAutoreplaceuniqueCB.IsChecked() );
1049*cdf0e10cSrcweir 		aLngCfg.SetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES, aTmp );
1050*cdf0e10cSrcweir 
1051*cdf0e10cSrcweir 		EndDialog( RET_OK );
1052*cdf0e10cSrcweir 		return 0;
1053*cdf0e10cSrcweir 	}
1054*cdf0e10cSrcweir 
1055*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaOptionsDialog, DictsLB_SelectHdl, void*, EMPTYARG )
1056*cdf0e10cSrcweir 	{
1057*cdf0e10cSrcweir 		bool	bSel = m_aDictsLB.FirstSelected() != NULL;
1058*cdf0e10cSrcweir 
1059*cdf0e10cSrcweir 		m_aEditPB.Enable( bSel );
1060*cdf0e10cSrcweir 		m_aDeletePB.Enable( bSel );
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir 		return 0;
1063*cdf0e10cSrcweir 	}
1064*cdf0e10cSrcweir 
1065*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaOptionsDialog, NewDictHdl, void*, EMPTYARG )
1066*cdf0e10cSrcweir 	{
1067*cdf0e10cSrcweir 		String						aName;
1068*cdf0e10cSrcweir 		HangulHanjaNewDictDialog	aNewDlg( this );
1069*cdf0e10cSrcweir 		aNewDlg.Execute();
1070*cdf0e10cSrcweir 		if( aNewDlg.GetName( aName ) )
1071*cdf0e10cSrcweir 		{
1072*cdf0e10cSrcweir 			if( m_xConversionDictionaryList.is() )
1073*cdf0e10cSrcweir 			{
1074*cdf0e10cSrcweir 				try
1075*cdf0e10cSrcweir 				{
1076*cdf0e10cSrcweir                     Reference< XConversionDictionary >	xDic =
1077*cdf0e10cSrcweir                         m_xConversionDictionaryList->addNewDictionary( aName, SvxCreateLocale( LANGUAGE_KOREAN ), ConversionDictionaryType::HANGUL_HANJA );
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir                     if( xDic.is() )
1080*cdf0e10cSrcweir                     {
1081*cdf0e10cSrcweir                         //adapt local caches:
1082*cdf0e10cSrcweir                         m_aDictList.push_back( xDic );
1083*cdf0e10cSrcweir                         AddDict( xDic->getName(), xDic->isActive() );
1084*cdf0e10cSrcweir                     }
1085*cdf0e10cSrcweir 				}
1086*cdf0e10cSrcweir 				catch( const ElementExistException& )
1087*cdf0e10cSrcweir 				{
1088*cdf0e10cSrcweir 				}
1089*cdf0e10cSrcweir 				catch( const NoSupportException& )
1090*cdf0e10cSrcweir 				{
1091*cdf0e10cSrcweir 				}
1092*cdf0e10cSrcweir 			}
1093*cdf0e10cSrcweir 		}
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir 		return 0L;
1096*cdf0e10cSrcweir 	}
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaOptionsDialog, EditDictHdl, void*, EMPTYARG )
1099*cdf0e10cSrcweir 	{
1100*cdf0e10cSrcweir 		SvLBoxEntry*	pEntry = m_aDictsLB.FirstSelected();
1101*cdf0e10cSrcweir 		DBG_ASSERT( pEntry, "+HangulHanjaEditDictDialog::EditDictHdl(): call of edit should not be possible with no selection!" );
1102*cdf0e10cSrcweir 		if( pEntry )
1103*cdf0e10cSrcweir 		{
1104*cdf0e10cSrcweir 			HangulHanjaEditDictDialog	aEdDlg( this, m_aDictList, m_aDictsLB.GetSelectEntryPos() );
1105*cdf0e10cSrcweir 			aEdDlg.Execute();
1106*cdf0e10cSrcweir 		}
1107*cdf0e10cSrcweir 		return 0L;
1108*cdf0e10cSrcweir 	}
1109*cdf0e10cSrcweir 
1110*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaOptionsDialog, DeleteDictHdl, void*, EMPTYARG )
1111*cdf0e10cSrcweir 	{
1112*cdf0e10cSrcweir         sal_uInt16 nSelPos = m_aDictsLB.GetSelectEntryPos();
1113*cdf0e10cSrcweir 		if( nSelPos != LISTBOX_ENTRY_NOTFOUND )
1114*cdf0e10cSrcweir 		{
1115*cdf0e10cSrcweir             Reference< XConversionDictionary >	xDic( m_aDictList[ nSelPos ] );
1116*cdf0e10cSrcweir 			if( m_xConversionDictionaryList.is() && xDic.is() )
1117*cdf0e10cSrcweir 			{
1118*cdf0e10cSrcweir 				Reference< XNameContainer >		xNameCont = m_xConversionDictionaryList->getDictionaryContainer();
1119*cdf0e10cSrcweir 				if( xNameCont.is() )
1120*cdf0e10cSrcweir 				{
1121*cdf0e10cSrcweir 					try
1122*cdf0e10cSrcweir 					{
1123*cdf0e10cSrcweir 						xNameCont->removeByName( xDic->getName() );
1124*cdf0e10cSrcweir 
1125*cdf0e10cSrcweir                         //adapt local caches:
1126*cdf0e10cSrcweir                         HHDictList::iterator aIter(m_aDictList.begin());
1127*cdf0e10cSrcweir                         m_aDictList.erase(aIter+nSelPos );
1128*cdf0e10cSrcweir                         m_aDictsLB.RemoveEntry( nSelPos );
1129*cdf0e10cSrcweir 					}
1130*cdf0e10cSrcweir 					catch( const ElementExistException& )
1131*cdf0e10cSrcweir 					{
1132*cdf0e10cSrcweir 					}
1133*cdf0e10cSrcweir 					catch( const NoSupportException& )
1134*cdf0e10cSrcweir 					{
1135*cdf0e10cSrcweir 					}
1136*cdf0e10cSrcweir 				}
1137*cdf0e10cSrcweir 			}
1138*cdf0e10cSrcweir 		}
1139*cdf0e10cSrcweir 
1140*cdf0e10cSrcweir 		return 0L;
1141*cdf0e10cSrcweir 	}
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir 	HangulHanjaOptionsDialog::HangulHanjaOptionsDialog( Window* _pParent )
1144*cdf0e10cSrcweir 		:ModalDialog			( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA_OPT ) )
1145*cdf0e10cSrcweir 		,m_aUserdefdictFT		( this, CUI_RES( FT_USERDEFDICT ) )
1146*cdf0e10cSrcweir 		,m_aDictsLB				( this, CUI_RES( LB_DICTS ) )
1147*cdf0e10cSrcweir 		,m_aOptionsFL			( this, CUI_RES( FL_OPTIONS ) )
1148*cdf0e10cSrcweir 		,m_aIgnorepostCB		( this, CUI_RES( CB_IGNOREPOST ) )
1149*cdf0e10cSrcweir 		,m_aShowrecentlyfirstCB	( this, CUI_RES( CB_SHOWRECENTLYFIRST ) )
1150*cdf0e10cSrcweir 		,m_aAutoreplaceuniqueCB	( this, CUI_RES( CB_AUTOREPLACEUNIQUE ) )
1151*cdf0e10cSrcweir 		,m_aNewPB				( this, CUI_RES( PB_HHO_NEW ) )
1152*cdf0e10cSrcweir 		,m_aEditPB				( this, CUI_RES( PB_HHO_EDIT ) )
1153*cdf0e10cSrcweir 		,m_aDeletePB			( this, CUI_RES( PB_HHO_DELETE ) )
1154*cdf0e10cSrcweir 		,m_aOkPB				( this, CUI_RES( PB_HHO_OK ) )
1155*cdf0e10cSrcweir 		,m_aCancelPB			( this, CUI_RES( PB_HHO_CANCEL ) )
1156*cdf0e10cSrcweir 		,m_aHelpPB				( this, CUI_RES( PB_HHO_HELP ) )
1157*cdf0e10cSrcweir 
1158*cdf0e10cSrcweir 		,m_pCheckButtonData		( NULL )
1159*cdf0e10cSrcweir         ,m_xConversionDictionaryList( NULL )
1160*cdf0e10cSrcweir 	{
1161*cdf0e10cSrcweir 		m_aDictsLB.SetStyle( m_aDictsLB.GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE );
1162*cdf0e10cSrcweir 		m_aDictsLB.SetSelectionMode( SINGLE_SELECTION );
1163*cdf0e10cSrcweir 		m_aDictsLB.SetHighlightRange();
1164*cdf0e10cSrcweir //		m_aDictsLB.SetHelpId( xxx );
1165*cdf0e10cSrcweir 		m_aDictsLB.SetSelectHdl( LINK( this, HangulHanjaOptionsDialog, DictsLB_SelectHdl ) );
1166*cdf0e10cSrcweir 		m_aDictsLB.SetDeselectHdl( LINK( this, HangulHanjaOptionsDialog, DictsLB_SelectHdl ) );
1167*cdf0e10cSrcweir 
1168*cdf0e10cSrcweir 		m_aOkPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, OkHdl ) );
1169*cdf0e10cSrcweir 		m_aNewPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, NewDictHdl ) );
1170*cdf0e10cSrcweir 		m_aEditPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, EditDictHdl ) );
1171*cdf0e10cSrcweir 		m_aDeletePB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, DeleteDictHdl ) );
1172*cdf0e10cSrcweir 
1173*cdf0e10cSrcweir 		FreeResource();
1174*cdf0e10cSrcweir 
1175*cdf0e10cSrcweir 		SvtLinguConfig	aLngCfg;
1176*cdf0e10cSrcweir 		Any				aTmp;
1177*cdf0e10cSrcweir 		bool			bVal = bool();
1178*cdf0e10cSrcweir 		aTmp = aLngCfg.GetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD );
1179*cdf0e10cSrcweir 		if( aTmp >>= bVal )
1180*cdf0e10cSrcweir 			m_aIgnorepostCB.Check( bVal );
1181*cdf0e10cSrcweir 
1182*cdf0e10cSrcweir 		aTmp = aLngCfg.GetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST );
1183*cdf0e10cSrcweir 		if( aTmp >>= bVal )
1184*cdf0e10cSrcweir 			m_aShowrecentlyfirstCB.Check( bVal );
1185*cdf0e10cSrcweir 
1186*cdf0e10cSrcweir 		aTmp = aLngCfg.GetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES );
1187*cdf0e10cSrcweir 		if( aTmp >>= bVal )
1188*cdf0e10cSrcweir 			m_aAutoreplaceuniqueCB.Check( bVal );
1189*cdf0e10cSrcweir 
1190*cdf0e10cSrcweir 		Init();
1191*cdf0e10cSrcweir 	}
1192*cdf0e10cSrcweir 
1193*cdf0e10cSrcweir 	HangulHanjaOptionsDialog::~HangulHanjaOptionsDialog()
1194*cdf0e10cSrcweir 	{
1195*cdf0e10cSrcweir 		SvLBoxEntry*	pEntry = m_aDictsLB.First();
1196*cdf0e10cSrcweir 		String*			pDel;
1197*cdf0e10cSrcweir 		while( pEntry )
1198*cdf0e10cSrcweir 		{
1199*cdf0e10cSrcweir 			pDel = ( String* ) pEntry->GetUserData();
1200*cdf0e10cSrcweir 			if( pDel )
1201*cdf0e10cSrcweir 				delete pDel;
1202*cdf0e10cSrcweir 			pEntry = m_aDictsLB.Next( pEntry );
1203*cdf0e10cSrcweir 		}
1204*cdf0e10cSrcweir 
1205*cdf0e10cSrcweir 		if( m_pCheckButtonData )
1206*cdf0e10cSrcweir 			delete m_pCheckButtonData;
1207*cdf0e10cSrcweir 	}
1208*cdf0e10cSrcweir 
1209*cdf0e10cSrcweir 	void HangulHanjaOptionsDialog::AddDict( const String& _rName, bool _bChecked )
1210*cdf0e10cSrcweir 	{
1211*cdf0e10cSrcweir 		SvLBoxEntry*	pEntry = m_aDictsLB.SvTreeListBox::InsertEntry( _rName );
1212*cdf0e10cSrcweir 		m_aDictsLB.SetCheckButtonState( pEntry, _bChecked? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
1213*cdf0e10cSrcweir 		pEntry->SetUserData( new String( _rName ) );
1214*cdf0e10cSrcweir 	}
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir 	//=========================================================================
1217*cdf0e10cSrcweir 	//= HangulHanjaNewDictDialog
1218*cdf0e10cSrcweir 	//=========================================================================
1219*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1220*cdf0e10cSrcweir 
1221*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaNewDictDialog, OKHdl, void*, EMPTYARG )
1222*cdf0e10cSrcweir 	{
1223*cdf0e10cSrcweir 		String	aName( m_aDictNameED.GetText() );
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir 		aName.EraseTrailingChars();
1226*cdf0e10cSrcweir 		m_bEntered = aName.Len() > 0;
1227*cdf0e10cSrcweir 		if( m_bEntered )
1228*cdf0e10cSrcweir 			m_aDictNameED.SetText( aName );		// do this in case of trailing chars have been deleted
1229*cdf0e10cSrcweir 
1230*cdf0e10cSrcweir 		EndDialog( RET_OK );
1231*cdf0e10cSrcweir 		return 0;
1232*cdf0e10cSrcweir 	}
1233*cdf0e10cSrcweir 
1234*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaNewDictDialog, ModifyHdl, void*, EMPTYARG )
1235*cdf0e10cSrcweir 	{
1236*cdf0e10cSrcweir 		String	aName( m_aDictNameED.GetText() );
1237*cdf0e10cSrcweir 
1238*cdf0e10cSrcweir 		aName.EraseTrailingChars();
1239*cdf0e10cSrcweir 		m_aOkBtn.Enable( aName.Len() > 0 );
1240*cdf0e10cSrcweir 
1241*cdf0e10cSrcweir 		return 0;
1242*cdf0e10cSrcweir 	}
1243*cdf0e10cSrcweir 
1244*cdf0e10cSrcweir 	HangulHanjaNewDictDialog::HangulHanjaNewDictDialog( Window* _pParent )
1245*cdf0e10cSrcweir 		:ModalDialog	( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA_NEWDICT ) )
1246*cdf0e10cSrcweir 		,m_aNewDictFL	( this, CUI_RES( FL_NEWDICT ) )
1247*cdf0e10cSrcweir 		,m_aDictNameFT	( this, CUI_RES( FT_DICTNAME ) )
1248*cdf0e10cSrcweir 		,m_aDictNameED	( this, CUI_RES( ED_DICTNAME ) )
1249*cdf0e10cSrcweir 		,m_aOkBtn		( this, CUI_RES( PB_NEWDICT_OK ) )
1250*cdf0e10cSrcweir 		,m_aCancelBtn	( this, CUI_RES( PB_NEWDICT_ESC ) )
1251*cdf0e10cSrcweir 		,m_aHelpBtn		( this, CUI_RES( PB_NEWDICT_HLP ) )
1252*cdf0e10cSrcweir 
1253*cdf0e10cSrcweir 		,m_bEntered		( false )
1254*cdf0e10cSrcweir 	{
1255*cdf0e10cSrcweir 		m_aOkBtn.SetClickHdl( LINK( this, HangulHanjaNewDictDialog, OKHdl ) );
1256*cdf0e10cSrcweir 
1257*cdf0e10cSrcweir 		m_aDictNameED.SetModifyHdl( LINK( this, HangulHanjaNewDictDialog, ModifyHdl ) );
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir 		FreeResource();
1260*cdf0e10cSrcweir 	}
1261*cdf0e10cSrcweir 
1262*cdf0e10cSrcweir 	HangulHanjaNewDictDialog::~HangulHanjaNewDictDialog()
1263*cdf0e10cSrcweir 	{
1264*cdf0e10cSrcweir 	}
1265*cdf0e10cSrcweir 
1266*cdf0e10cSrcweir 	bool HangulHanjaNewDictDialog::GetName( String& _rRetName ) const
1267*cdf0e10cSrcweir 	{
1268*cdf0e10cSrcweir 		if( m_bEntered )
1269*cdf0e10cSrcweir 		{
1270*cdf0e10cSrcweir 			_rRetName = m_aDictNameED.GetText();
1271*cdf0e10cSrcweir 			_rRetName.EraseTrailingChars();
1272*cdf0e10cSrcweir 		}
1273*cdf0e10cSrcweir 
1274*cdf0e10cSrcweir 		return m_bEntered;
1275*cdf0e10cSrcweir 	}
1276*cdf0e10cSrcweir 
1277*cdf0e10cSrcweir 	//=========================================================================
1278*cdf0e10cSrcweir 	//= HangulHanjaEditDictDialog
1279*cdf0e10cSrcweir 	//=========================================================================
1280*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
1281*cdf0e10cSrcweir 
1282*cdf0e10cSrcweir 	class SuggestionList
1283*cdf0e10cSrcweir 	{
1284*cdf0e10cSrcweir 	private:
1285*cdf0e10cSrcweir 	protected:
1286*cdf0e10cSrcweir 		sal_uInt16			m_nSize;
1287*cdf0e10cSrcweir 		String**			m_ppElements;
1288*cdf0e10cSrcweir 		sal_uInt16			m_nNumOfEntries;
1289*cdf0e10cSrcweir 		sal_uInt16			m_nAct;
1290*cdf0e10cSrcweir 
1291*cdf0e10cSrcweir 		const String*		_Next( void );
1292*cdf0e10cSrcweir 	public:
1293*cdf0e10cSrcweir 							SuggestionList( sal_uInt16 _nNumOfElements );
1294*cdf0e10cSrcweir 		virtual				~SuggestionList();
1295*cdf0e10cSrcweir 
1296*cdf0e10cSrcweir 		bool				Set( const String& _rElement, sal_uInt16 _nNumOfElement );
1297*cdf0e10cSrcweir 		bool				Reset( sal_uInt16 _nNumOfElement );
1298*cdf0e10cSrcweir 		const String*		Get( sal_uInt16 _nNumOfElement ) const;
1299*cdf0e10cSrcweir 		void				Clear( void );
1300*cdf0e10cSrcweir 
1301*cdf0e10cSrcweir 		const String*		First( void );
1302*cdf0e10cSrcweir 		const String*		Next( void );
1303*cdf0e10cSrcweir 
1304*cdf0e10cSrcweir 		inline sal_uInt16	GetCount( void ) const;
1305*cdf0e10cSrcweir 	};
1306*cdf0e10cSrcweir 
1307*cdf0e10cSrcweir 	inline sal_uInt16 SuggestionList::GetCount( void ) const
1308*cdf0e10cSrcweir 	{
1309*cdf0e10cSrcweir 		return m_nNumOfEntries;
1310*cdf0e10cSrcweir 	}
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir 	SuggestionList::SuggestionList( sal_uInt16 _nNumOfElements )
1313*cdf0e10cSrcweir 	{
1314*cdf0e10cSrcweir 		if( !_nNumOfElements )
1315*cdf0e10cSrcweir 			_nNumOfElements = 1;
1316*cdf0e10cSrcweir 
1317*cdf0e10cSrcweir 		m_nSize = _nNumOfElements;
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir 		m_ppElements = new String*[ m_nSize ];
1320*cdf0e10cSrcweir 		m_nAct = m_nNumOfEntries = 0;
1321*cdf0e10cSrcweir 
1322*cdf0e10cSrcweir 		String**	ppNull = m_ppElements;
1323*cdf0e10cSrcweir 		sal_uInt16	n = _nNumOfElements;
1324*cdf0e10cSrcweir 		while( n )
1325*cdf0e10cSrcweir 		{
1326*cdf0e10cSrcweir 			*ppNull = NULL;
1327*cdf0e10cSrcweir 			++ppNull;
1328*cdf0e10cSrcweir 			--n;
1329*cdf0e10cSrcweir 		}
1330*cdf0e10cSrcweir 	}
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir 	SuggestionList::~SuggestionList()
1333*cdf0e10cSrcweir 	{
1334*cdf0e10cSrcweir 		Clear();
1335*cdf0e10cSrcweir 	}
1336*cdf0e10cSrcweir 
1337*cdf0e10cSrcweir 	bool SuggestionList::Set( const String& _rElement, sal_uInt16 _nNumOfElement )
1338*cdf0e10cSrcweir 	{
1339*cdf0e10cSrcweir 		bool	bRet = _nNumOfElement < m_nSize;
1340*cdf0e10cSrcweir 		if( bRet )
1341*cdf0e10cSrcweir 		{
1342*cdf0e10cSrcweir 			String**	ppElem = m_ppElements + _nNumOfElement;
1343*cdf0e10cSrcweir 			if( *ppElem )
1344*cdf0e10cSrcweir 				**ppElem = _rElement;
1345*cdf0e10cSrcweir 			else
1346*cdf0e10cSrcweir 			{
1347*cdf0e10cSrcweir 				*ppElem = new String( _rElement );
1348*cdf0e10cSrcweir 				++m_nNumOfEntries;
1349*cdf0e10cSrcweir 			}
1350*cdf0e10cSrcweir 		}
1351*cdf0e10cSrcweir 
1352*cdf0e10cSrcweir 		return bRet;
1353*cdf0e10cSrcweir 	}
1354*cdf0e10cSrcweir 
1355*cdf0e10cSrcweir 	bool SuggestionList::Reset( sal_uInt16 _nNumOfElement )
1356*cdf0e10cSrcweir 	{
1357*cdf0e10cSrcweir 		bool	bRet = _nNumOfElement < m_nSize;
1358*cdf0e10cSrcweir 		if( bRet )
1359*cdf0e10cSrcweir 		{
1360*cdf0e10cSrcweir 			String**	ppElem = m_ppElements + _nNumOfElement;
1361*cdf0e10cSrcweir 			if( *ppElem )
1362*cdf0e10cSrcweir 			{
1363*cdf0e10cSrcweir 				delete *ppElem;
1364*cdf0e10cSrcweir 				*ppElem = NULL;
1365*cdf0e10cSrcweir 				--m_nNumOfEntries;
1366*cdf0e10cSrcweir 			}
1367*cdf0e10cSrcweir 		}
1368*cdf0e10cSrcweir 
1369*cdf0e10cSrcweir 		return bRet;
1370*cdf0e10cSrcweir 	}
1371*cdf0e10cSrcweir 
1372*cdf0e10cSrcweir 	const String* SuggestionList::Get( sal_uInt16 _nNumOfElement ) const
1373*cdf0e10cSrcweir 	{
1374*cdf0e10cSrcweir 		const String*	pRet;
1375*cdf0e10cSrcweir 
1376*cdf0e10cSrcweir 		if( _nNumOfElement < m_nSize )
1377*cdf0e10cSrcweir 			pRet = m_ppElements[ _nNumOfElement ];
1378*cdf0e10cSrcweir 		else
1379*cdf0e10cSrcweir 			pRet = NULL;
1380*cdf0e10cSrcweir 
1381*cdf0e10cSrcweir 		return pRet;
1382*cdf0e10cSrcweir 	}
1383*cdf0e10cSrcweir 
1384*cdf0e10cSrcweir 	void SuggestionList::Clear( void )
1385*cdf0e10cSrcweir 	{
1386*cdf0e10cSrcweir 		if( m_nNumOfEntries )
1387*cdf0e10cSrcweir 		{
1388*cdf0e10cSrcweir 			String**	ppDel = m_ppElements;
1389*cdf0e10cSrcweir 			sal_uInt16	nCnt = m_nSize;
1390*cdf0e10cSrcweir 			while( nCnt )
1391*cdf0e10cSrcweir 			{
1392*cdf0e10cSrcweir 				if( *ppDel )
1393*cdf0e10cSrcweir 				{
1394*cdf0e10cSrcweir 					delete *ppDel;
1395*cdf0e10cSrcweir 					*ppDel = NULL;
1396*cdf0e10cSrcweir 				}
1397*cdf0e10cSrcweir 
1398*cdf0e10cSrcweir 				++ppDel;
1399*cdf0e10cSrcweir 				--nCnt;
1400*cdf0e10cSrcweir 			}
1401*cdf0e10cSrcweir 
1402*cdf0e10cSrcweir 			m_nNumOfEntries = m_nAct = 0;
1403*cdf0e10cSrcweir 		}
1404*cdf0e10cSrcweir 	}
1405*cdf0e10cSrcweir 
1406*cdf0e10cSrcweir 	const String* SuggestionList::_Next( void )
1407*cdf0e10cSrcweir 	{
1408*cdf0e10cSrcweir 		const String*	pRet = NULL;
1409*cdf0e10cSrcweir 		while( m_nAct < m_nSize && !pRet )
1410*cdf0e10cSrcweir 		{
1411*cdf0e10cSrcweir 			pRet = m_ppElements[ m_nAct ];
1412*cdf0e10cSrcweir 			if( !pRet )
1413*cdf0e10cSrcweir 				++m_nAct;
1414*cdf0e10cSrcweir 		}
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir 		return pRet;
1417*cdf0e10cSrcweir 	}
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir 	const String* SuggestionList::First( void )
1420*cdf0e10cSrcweir 	{
1421*cdf0e10cSrcweir 		m_nAct = 0;
1422*cdf0e10cSrcweir 		return _Next();
1423*cdf0e10cSrcweir 	}
1424*cdf0e10cSrcweir 
1425*cdf0e10cSrcweir 	const String* SuggestionList::Next( void )
1426*cdf0e10cSrcweir 	{
1427*cdf0e10cSrcweir 		const String*	pRet;
1428*cdf0e10cSrcweir 
1429*cdf0e10cSrcweir 		if( m_nAct < m_nNumOfEntries )
1430*cdf0e10cSrcweir 		{
1431*cdf0e10cSrcweir 			++m_nAct;
1432*cdf0e10cSrcweir 			pRet = _Next();
1433*cdf0e10cSrcweir 		}
1434*cdf0e10cSrcweir 		else
1435*cdf0e10cSrcweir 			pRet = NULL;
1436*cdf0e10cSrcweir 
1437*cdf0e10cSrcweir 		return pRet;
1438*cdf0e10cSrcweir 	}
1439*cdf0e10cSrcweir 
1440*cdf0e10cSrcweir 
1441*cdf0e10cSrcweir 	bool SuggestionEdit::ShouldScroll( bool _bUp ) const
1442*cdf0e10cSrcweir 	{
1443*cdf0e10cSrcweir 		bool	bRet = false;
1444*cdf0e10cSrcweir 
1445*cdf0e10cSrcweir 		if( _bUp )
1446*cdf0e10cSrcweir 		{
1447*cdf0e10cSrcweir 			if( !m_pPrev )
1448*cdf0e10cSrcweir 				bRet = m_rScrollBar.GetThumbPos() > m_rScrollBar.GetRangeMin();
1449*cdf0e10cSrcweir 		}
1450*cdf0e10cSrcweir 		else
1451*cdf0e10cSrcweir 		{
1452*cdf0e10cSrcweir 			if( !m_pNext )
1453*cdf0e10cSrcweir 				bRet = m_rScrollBar.GetThumbPos() < ( m_rScrollBar.GetRangeMax() - 4 );
1454*cdf0e10cSrcweir 		}
1455*cdf0e10cSrcweir 
1456*cdf0e10cSrcweir 		return bRet;
1457*cdf0e10cSrcweir 	}
1458*cdf0e10cSrcweir 
1459*cdf0e10cSrcweir 	void SuggestionEdit::DoJump( bool _bUp )
1460*cdf0e10cSrcweir 	{
1461*cdf0e10cSrcweir 		const Link& 	rLoseFocusHdl = GetLoseFocusHdl();
1462*cdf0e10cSrcweir 		if( rLoseFocusHdl.IsSet() )
1463*cdf0e10cSrcweir 			rLoseFocusHdl.Call( this );
1464*cdf0e10cSrcweir 		m_rScrollBar.SetThumbPos( m_rScrollBar.GetThumbPos() + ( _bUp? -1 : 1 ) );
1465*cdf0e10cSrcweir 
1466*cdf0e10cSrcweir 		( static_cast< HangulHanjaEditDictDialog* >( GetParent() ) )->UpdateScrollbar();
1467*cdf0e10cSrcweir 	}
1468*cdf0e10cSrcweir 
1469*cdf0e10cSrcweir 	SuggestionEdit::SuggestionEdit( Window* pParent, const ResId& rResId,
1470*cdf0e10cSrcweir 		ScrollBar& _rScrollBar, SuggestionEdit* _pPrev, SuggestionEdit* _pNext  )
1471*cdf0e10cSrcweir 		:Edit( pParent, rResId )
1472*cdf0e10cSrcweir 		,m_pPrev( _pPrev )
1473*cdf0e10cSrcweir 		,m_pNext( _pNext )
1474*cdf0e10cSrcweir 		,m_rScrollBar( _rScrollBar )
1475*cdf0e10cSrcweir 	{
1476*cdf0e10cSrcweir 	}
1477*cdf0e10cSrcweir 
1478*cdf0e10cSrcweir 	SuggestionEdit::~SuggestionEdit()
1479*cdf0e10cSrcweir 	{
1480*cdf0e10cSrcweir 	}
1481*cdf0e10cSrcweir 
1482*cdf0e10cSrcweir 	long SuggestionEdit::PreNotify( NotifyEvent& rNEvt )
1483*cdf0e10cSrcweir 	{
1484*cdf0e10cSrcweir 		long	nHandled = 0;
1485*cdf0e10cSrcweir 		if( rNEvt.GetType() == EVENT_KEYINPUT )
1486*cdf0e10cSrcweir 		{
1487*cdf0e10cSrcweir 			const KeyEvent*				pKEvt = rNEvt.GetKeyEvent();
1488*cdf0e10cSrcweir 			const KeyCode&				rKeyCode = pKEvt->GetKeyCode();
1489*cdf0e10cSrcweir 			sal_uInt16						nMod = rKeyCode.GetModifier();
1490*cdf0e10cSrcweir 			sal_uInt16						nCode = rKeyCode.GetCode();
1491*cdf0e10cSrcweir 			if( nCode == KEY_TAB && ( !nMod || KEY_SHIFT == nMod ) )
1492*cdf0e10cSrcweir 			{
1493*cdf0e10cSrcweir 				bool		bUp = KEY_SHIFT == nMod;
1494*cdf0e10cSrcweir 				if( ShouldScroll( bUp ) )
1495*cdf0e10cSrcweir 				{
1496*cdf0e10cSrcweir 					DoJump( bUp );
1497*cdf0e10cSrcweir 					SetSelection( Selection( 0, SELECTION_MAX ) );
1498*cdf0e10cSrcweir 						// Tab-travel doesn't really happen, so emulate it by setting a selection manually
1499*cdf0e10cSrcweir 					nHandled = 1;
1500*cdf0e10cSrcweir 				}
1501*cdf0e10cSrcweir 			}
1502*cdf0e10cSrcweir 			else if( KEY_UP == nCode || KEY_DOWN == nCode )
1503*cdf0e10cSrcweir 			{
1504*cdf0e10cSrcweir 				bool		bUp = KEY_UP == nCode;
1505*cdf0e10cSrcweir 				if( ShouldScroll( bUp ) )
1506*cdf0e10cSrcweir 				{
1507*cdf0e10cSrcweir 					DoJump( bUp );
1508*cdf0e10cSrcweir 					nHandled = 1;
1509*cdf0e10cSrcweir 				}
1510*cdf0e10cSrcweir 				else if( bUp )
1511*cdf0e10cSrcweir 				{
1512*cdf0e10cSrcweir 					if( m_pPrev )
1513*cdf0e10cSrcweir 					{
1514*cdf0e10cSrcweir 						m_pPrev->GrabFocus();
1515*cdf0e10cSrcweir 						nHandled = 1;
1516*cdf0e10cSrcweir 					}
1517*cdf0e10cSrcweir 				}
1518*cdf0e10cSrcweir 				else if( m_pNext )
1519*cdf0e10cSrcweir 				{
1520*cdf0e10cSrcweir 					m_pNext->GrabFocus();
1521*cdf0e10cSrcweir 					nHandled = 1;
1522*cdf0e10cSrcweir 				}
1523*cdf0e10cSrcweir 			}
1524*cdf0e10cSrcweir 		}
1525*cdf0e10cSrcweir 
1526*cdf0e10cSrcweir 		if( !nHandled )
1527*cdf0e10cSrcweir 			nHandled = Edit::PreNotify( rNEvt );
1528*cdf0e10cSrcweir 		return nHandled;
1529*cdf0e10cSrcweir 	}
1530*cdf0e10cSrcweir 
1531*cdf0e10cSrcweir 
1532*cdf0e10cSrcweir 	namespace
1533*cdf0e10cSrcweir 	{
1534*cdf0e10cSrcweir 		bool GetConversions(	Reference< XConversionDictionary >	_xDict,
1535*cdf0e10cSrcweir 								const OUString& _rOrg,
1536*cdf0e10cSrcweir 								Sequence< OUString >& _rEntries )
1537*cdf0e10cSrcweir 		{
1538*cdf0e10cSrcweir 			bool	bRet = false;
1539*cdf0e10cSrcweir 			if( _xDict.is() && _rOrg.getLength() )
1540*cdf0e10cSrcweir 			{
1541*cdf0e10cSrcweir 				try
1542*cdf0e10cSrcweir 				{
1543*cdf0e10cSrcweir 					_rEntries = _xDict->getConversions(	_rOrg,
1544*cdf0e10cSrcweir 														0,
1545*cdf0e10cSrcweir 														_rOrg.getLength(),
1546*cdf0e10cSrcweir 														ConversionDirection_FROM_LEFT,
1547*cdf0e10cSrcweir 														::com::sun::star::i18n::TextConversionOption::NONE );
1548*cdf0e10cSrcweir 					bRet = _rEntries.getLength() > 0;
1549*cdf0e10cSrcweir 				}
1550*cdf0e10cSrcweir 				catch( const IllegalArgumentException& )
1551*cdf0e10cSrcweir 				{
1552*cdf0e10cSrcweir 				}
1553*cdf0e10cSrcweir 			}
1554*cdf0e10cSrcweir 
1555*cdf0e10cSrcweir 			return bRet;
1556*cdf0e10cSrcweir 		}
1557*cdf0e10cSrcweir 	}
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir 
1560*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, ScrollHdl, void*, EMPTYARG )
1561*cdf0e10cSrcweir 	{
1562*cdf0e10cSrcweir 		UpdateScrollbar();
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir 		return 0;
1565*cdf0e10cSrcweir 	}
1566*cdf0e10cSrcweir 
1567*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, OriginalModifyHdl, void*, EMPTYARG )
1568*cdf0e10cSrcweir 	{
1569*cdf0e10cSrcweir         m_bModifiedOriginal = true;
1570*cdf0e10cSrcweir 		m_aOriginal = m_aOriginalLB.GetText();
1571*cdf0e10cSrcweir 		m_aOriginal.EraseTrailingChars();
1572*cdf0e10cSrcweir 
1573*cdf0e10cSrcweir         UpdateSuggestions();
1574*cdf0e10cSrcweir 		UpdateButtonStates();
1575*cdf0e10cSrcweir 
1576*cdf0e10cSrcweir 		return 0;
1577*cdf0e10cSrcweir 	}
1578*cdf0e10cSrcweir 
1579*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl1, Edit*, pEdit )
1580*cdf0e10cSrcweir 	{
1581*cdf0e10cSrcweir 		EditModify( pEdit, 0 );
1582*cdf0e10cSrcweir 		return 0;
1583*cdf0e10cSrcweir 	}
1584*cdf0e10cSrcweir 
1585*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl2, Edit*, pEdit )
1586*cdf0e10cSrcweir 	{
1587*cdf0e10cSrcweir 		EditModify( pEdit, 1 );
1588*cdf0e10cSrcweir 		return 0;
1589*cdf0e10cSrcweir 	}
1590*cdf0e10cSrcweir 
1591*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl3, Edit*, pEdit )
1592*cdf0e10cSrcweir 	{
1593*cdf0e10cSrcweir 		EditModify( pEdit, 2 );
1594*cdf0e10cSrcweir 		return 0;
1595*cdf0e10cSrcweir 	}
1596*cdf0e10cSrcweir 
1597*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl4, Edit*, pEdit )
1598*cdf0e10cSrcweir 	{
1599*cdf0e10cSrcweir 		EditModify( pEdit, 3 );
1600*cdf0e10cSrcweir 		return 0;
1601*cdf0e10cSrcweir 	}
1602*cdf0e10cSrcweir 
1603*cdf0e10cSrcweir     IMPL_LINK( HangulHanjaEditDictDialog, BookLBSelectHdl, void*, EMPTYARG )
1604*cdf0e10cSrcweir 	{
1605*cdf0e10cSrcweir 		InitEditDictDialog( m_aBookLB.GetSelectEntryPos() );
1606*cdf0e10cSrcweir 		return 0;
1607*cdf0e10cSrcweir 	}
1608*cdf0e10cSrcweir 
1609*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, NewPBPushHdl, void*, EMPTYARG )
1610*cdf0e10cSrcweir 	{
1611*cdf0e10cSrcweir 		DBG_ASSERT( m_pSuggestions, "-HangulHanjaEditDictDialog::NewPBPushHdl(): no suggestions... search in hell..." );
1612*cdf0e10cSrcweir 		Reference< XConversionDictionary >	xDict = m_rDictList[ m_nCurrentDict ];
1613*cdf0e10cSrcweir 		if( xDict.is() && m_pSuggestions )
1614*cdf0e10cSrcweir 		{
1615*cdf0e10cSrcweir 			//delete old entry
1616*cdf0e10cSrcweir 			bool bRemovedSomething = DeleteEntryFromDictionary( m_aOriginal, xDict );
1617*cdf0e10cSrcweir 
1618*cdf0e10cSrcweir 			OUString				aLeft( m_aOriginal );
1619*cdf0e10cSrcweir 			const String*			pRight = m_pSuggestions->First();
1620*cdf0e10cSrcweir             bool bAddedSomething = false;
1621*cdf0e10cSrcweir 			while( pRight )
1622*cdf0e10cSrcweir 			{
1623*cdf0e10cSrcweir 				try
1624*cdf0e10cSrcweir 				{
1625*cdf0e10cSrcweir 					//add new entry
1626*cdf0e10cSrcweir 					xDict->addEntry( aLeft, *pRight );
1627*cdf0e10cSrcweir                     bAddedSomething = true;
1628*cdf0e10cSrcweir 				}
1629*cdf0e10cSrcweir 				catch( const IllegalArgumentException& )
1630*cdf0e10cSrcweir 				{
1631*cdf0e10cSrcweir 				}
1632*cdf0e10cSrcweir 				catch( const ElementExistException& )
1633*cdf0e10cSrcweir 				{
1634*cdf0e10cSrcweir 				}
1635*cdf0e10cSrcweir 
1636*cdf0e10cSrcweir 				pRight = m_pSuggestions->Next();
1637*cdf0e10cSrcweir 			}
1638*cdf0e10cSrcweir 
1639*cdf0e10cSrcweir             if(bAddedSomething||bRemovedSomething)
1640*cdf0e10cSrcweir     		    InitEditDictDialog( m_nCurrentDict );
1641*cdf0e10cSrcweir 		}
1642*cdf0e10cSrcweir 		else
1643*cdf0e10cSrcweir 		{
1644*cdf0e10cSrcweir 			DBG_WARNING( "+HangulHanjaEditDictDialog::NewPBPushHdl(): dictionary faded away..." );
1645*cdf0e10cSrcweir 		}
1646*cdf0e10cSrcweir 		return 0;
1647*cdf0e10cSrcweir 	}
1648*cdf0e10cSrcweir 
1649*cdf0e10cSrcweir 	bool HangulHanjaEditDictDialog::DeleteEntryFromDictionary( const OUString&, const Reference< XConversionDictionary >& xDict  )
1650*cdf0e10cSrcweir 	{
1651*cdf0e10cSrcweir 		bool bRemovedSomething = false;
1652*cdf0e10cSrcweir 		if( xDict.is() )
1653*cdf0e10cSrcweir 		{
1654*cdf0e10cSrcweir 			OUString				aOrg( m_aOriginal );
1655*cdf0e10cSrcweir 			Sequence< OUString >	aEntries;
1656*cdf0e10cSrcweir             GetConversions( xDict, m_aOriginal, aEntries );
1657*cdf0e10cSrcweir 
1658*cdf0e10cSrcweir 			sal_uInt32	n = aEntries.getLength();
1659*cdf0e10cSrcweir 			OUString*	pEntry = aEntries.getArray();
1660*cdf0e10cSrcweir 			while( n )
1661*cdf0e10cSrcweir 			{
1662*cdf0e10cSrcweir 				try
1663*cdf0e10cSrcweir 				{
1664*cdf0e10cSrcweir 					xDict->removeEntry( aOrg, *pEntry );
1665*cdf0e10cSrcweir                     bRemovedSomething = true;
1666*cdf0e10cSrcweir 				}
1667*cdf0e10cSrcweir 				catch( const NoSuchElementException& )
1668*cdf0e10cSrcweir 				{	// can not be...
1669*cdf0e10cSrcweir 				}
1670*cdf0e10cSrcweir 
1671*cdf0e10cSrcweir 				++pEntry;
1672*cdf0e10cSrcweir 				--n;
1673*cdf0e10cSrcweir 			}
1674*cdf0e10cSrcweir 		}
1675*cdf0e10cSrcweir 		return bRemovedSomething;
1676*cdf0e10cSrcweir 	}
1677*cdf0e10cSrcweir 
1678*cdf0e10cSrcweir 	IMPL_LINK( HangulHanjaEditDictDialog, DeletePBPushHdl, void*, EMPTYARG )
1679*cdf0e10cSrcweir 	{
1680*cdf0e10cSrcweir 		if( DeleteEntryFromDictionary( m_aOriginal, m_rDictList[ m_nCurrentDict ] ) )
1681*cdf0e10cSrcweir         {
1682*cdf0e10cSrcweir             m_aOriginal.Erase();
1683*cdf0e10cSrcweir             m_bModifiedOriginal = true;
1684*cdf0e10cSrcweir             InitEditDictDialog( m_nCurrentDict );
1685*cdf0e10cSrcweir         }
1686*cdf0e10cSrcweir 		return 0;
1687*cdf0e10cSrcweir 	}
1688*cdf0e10cSrcweir 
1689*cdf0e10cSrcweir 	void HangulHanjaEditDictDialog::InitEditDictDialog( sal_uInt32 _nSelDict )
1690*cdf0e10cSrcweir 	{
1691*cdf0e10cSrcweir         if( m_pSuggestions )
1692*cdf0e10cSrcweir 		    m_pSuggestions->Clear();
1693*cdf0e10cSrcweir 
1694*cdf0e10cSrcweir 		if( m_nCurrentDict != _nSelDict )
1695*cdf0e10cSrcweir 		{
1696*cdf0e10cSrcweir 			m_nCurrentDict = _nSelDict;
1697*cdf0e10cSrcweir 			m_aOriginal.Erase();
1698*cdf0e10cSrcweir             m_bModifiedOriginal = true;
1699*cdf0e10cSrcweir 		}
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir 		UpdateOriginalLB();
1702*cdf0e10cSrcweir 
1703*cdf0e10cSrcweir 		m_aOriginalLB.SetText( m_aOriginal.Len()? m_aOriginal : m_aEditHintText, Selection( 0, SELECTION_MAX ) );
1704*cdf0e10cSrcweir 		m_aOriginalLB.GrabFocus();
1705*cdf0e10cSrcweir 
1706*cdf0e10cSrcweir         UpdateSuggestions();
1707*cdf0e10cSrcweir 		UpdateButtonStates();
1708*cdf0e10cSrcweir 	}
1709*cdf0e10cSrcweir 
1710*cdf0e10cSrcweir 	void HangulHanjaEditDictDialog::UpdateOriginalLB( void )
1711*cdf0e10cSrcweir 	{
1712*cdf0e10cSrcweir 		m_aOriginalLB.Clear();
1713*cdf0e10cSrcweir 		Reference< XConversionDictionary >	xDict = m_rDictList[ m_nCurrentDict ];
1714*cdf0e10cSrcweir 		if( xDict.is() )
1715*cdf0e10cSrcweir 		{
1716*cdf0e10cSrcweir 			Sequence< OUString >	aEntries = xDict->getConversionEntries( ConversionDirection_FROM_LEFT );
1717*cdf0e10cSrcweir 			sal_uInt32				n = aEntries.getLength();
1718*cdf0e10cSrcweir 			OUString*				pEntry = aEntries.getArray();
1719*cdf0e10cSrcweir 			while( n )
1720*cdf0e10cSrcweir 			{
1721*cdf0e10cSrcweir 				m_aOriginalLB.InsertEntry( *pEntry );
1722*cdf0e10cSrcweir 
1723*cdf0e10cSrcweir 				++pEntry;
1724*cdf0e10cSrcweir 				--n;
1725*cdf0e10cSrcweir 			}
1726*cdf0e10cSrcweir 		}
1727*cdf0e10cSrcweir 		else
1728*cdf0e10cSrcweir 		{
1729*cdf0e10cSrcweir 			DBG_WARNING( "+HangulHanjaEditDictDialog::UpdateOriginalLB(): dictionary faded away..." );
1730*cdf0e10cSrcweir 		}
1731*cdf0e10cSrcweir 	}
1732*cdf0e10cSrcweir 
1733*cdf0e10cSrcweir     void HangulHanjaEditDictDialog::UpdateButtonStates()
1734*cdf0e10cSrcweir     {
1735*cdf0e10cSrcweir         bool bHaveValidOriginalString = m_aOriginal.Len() && m_aOriginal != m_aEditHintText;
1736*cdf0e10cSrcweir         bool bNew = bHaveValidOriginalString && m_pSuggestions && m_pSuggestions->GetCount() > 0;
1737*cdf0e10cSrcweir         bNew = bNew && (m_bModifiedSuggestions || m_bModifiedOriginal);
1738*cdf0e10cSrcweir 
1739*cdf0e10cSrcweir         m_aNewPB.Enable( bNew );
1740*cdf0e10cSrcweir         m_aDeletePB.Enable( !m_bModifiedOriginal && bHaveValidOriginalString );
1741*cdf0e10cSrcweir     }
1742*cdf0e10cSrcweir 
1743*cdf0e10cSrcweir 	void HangulHanjaEditDictDialog::UpdateSuggestions( void )
1744*cdf0e10cSrcweir 	{
1745*cdf0e10cSrcweir         Sequence< OUString > aEntries;
1746*cdf0e10cSrcweir         bool bFound = GetConversions( m_rDictList[ m_nCurrentDict ], m_aOriginal, aEntries );
1747*cdf0e10cSrcweir 		if( bFound )
1748*cdf0e10cSrcweir 		{
1749*cdf0e10cSrcweir             m_bModifiedOriginal = false;
1750*cdf0e10cSrcweir 
1751*cdf0e10cSrcweir 			if( m_pSuggestions )
1752*cdf0e10cSrcweir 			    m_pSuggestions->Clear();
1753*cdf0e10cSrcweir 
1754*cdf0e10cSrcweir             //fill found entries into boxes
1755*cdf0e10cSrcweir 		    sal_uInt32 nCnt = aEntries.getLength();
1756*cdf0e10cSrcweir 		    sal_uInt32 n = 0;
1757*cdf0e10cSrcweir 		    if( nCnt )
1758*cdf0e10cSrcweir 		    {
1759*cdf0e10cSrcweir 			    if( !m_pSuggestions )
1760*cdf0e10cSrcweir 				    m_pSuggestions = new SuggestionList( MAXNUM_SUGGESTIONS );
1761*cdf0e10cSrcweir 
1762*cdf0e10cSrcweir 			    const OUString* pSugg = aEntries.getConstArray();
1763*cdf0e10cSrcweir 			    while( nCnt )
1764*cdf0e10cSrcweir 			    {
1765*cdf0e10cSrcweir 				    m_pSuggestions->Set( pSugg[ n ], sal_uInt16( n ) );
1766*cdf0e10cSrcweir 				    ++n;
1767*cdf0e10cSrcweir 				    --nCnt;
1768*cdf0e10cSrcweir 			    }
1769*cdf0e10cSrcweir 		    }
1770*cdf0e10cSrcweir             m_bModifiedSuggestions=false;
1771*cdf0e10cSrcweir 		}
1772*cdf0e10cSrcweir 
1773*cdf0e10cSrcweir         m_aScrollSB.SetThumbPos( 0 );
1774*cdf0e10cSrcweir 		UpdateScrollbar();				// will force edits to be filled new
1775*cdf0e10cSrcweir 	}
1776*cdf0e10cSrcweir 
1777*cdf0e10cSrcweir 	void HangulHanjaEditDictDialog::SetEditText( Edit& _rEdit, sal_uInt16 _nEntryNum )
1778*cdf0e10cSrcweir 	{
1779*cdf0e10cSrcweir 		String	aStr;
1780*cdf0e10cSrcweir 		if( m_pSuggestions )
1781*cdf0e10cSrcweir 		{
1782*cdf0e10cSrcweir 			const String*	p = m_pSuggestions->Get( _nEntryNum );
1783*cdf0e10cSrcweir 			if( p )
1784*cdf0e10cSrcweir 				aStr = *p;
1785*cdf0e10cSrcweir 		}
1786*cdf0e10cSrcweir 
1787*cdf0e10cSrcweir 		_rEdit.SetText( aStr );
1788*cdf0e10cSrcweir 	}
1789*cdf0e10cSrcweir 
1790*cdf0e10cSrcweir 	void HangulHanjaEditDictDialog::EditModify( Edit* _pEdit, sal_uInt8 _nEntryOffset )
1791*cdf0e10cSrcweir 	{
1792*cdf0e10cSrcweir         m_bModifiedSuggestions = true;
1793*cdf0e10cSrcweir 
1794*cdf0e10cSrcweir         String	aTxt( _pEdit->GetText() );
1795*cdf0e10cSrcweir         sal_uInt16 nEntryNum = m_nTopPos + _nEntryOffset;
1796*cdf0e10cSrcweir         if( aTxt.Len() == 0 )
1797*cdf0e10cSrcweir 		{
1798*cdf0e10cSrcweir             //reset suggestion
1799*cdf0e10cSrcweir             if( m_pSuggestions )
1800*cdf0e10cSrcweir 			    m_pSuggestions->Reset( nEntryNum );
1801*cdf0e10cSrcweir         }
1802*cdf0e10cSrcweir         else
1803*cdf0e10cSrcweir         {
1804*cdf0e10cSrcweir             //set suggestion
1805*cdf0e10cSrcweir             if( !m_pSuggestions )
1806*cdf0e10cSrcweir 			    m_pSuggestions = new SuggestionList( MAXNUM_SUGGESTIONS );
1807*cdf0e10cSrcweir 		    m_pSuggestions->Set( aTxt, nEntryNum );
1808*cdf0e10cSrcweir         }
1809*cdf0e10cSrcweir 
1810*cdf0e10cSrcweir         UpdateButtonStates();
1811*cdf0e10cSrcweir 	}
1812*cdf0e10cSrcweir 
1813*cdf0e10cSrcweir 	HangulHanjaEditDictDialog::HangulHanjaEditDictDialog( Window* _pParent, HHDictList& _rDictList, sal_uInt32 _nSelDict )
1814*cdf0e10cSrcweir 		:ModalDialog			( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA_EDIT ) )
1815*cdf0e10cSrcweir 		,m_aEditHintText		( CUI_RES( STR_EDITHINT ) )
1816*cdf0e10cSrcweir 		,m_rDictList			( _rDictList )
1817*cdf0e10cSrcweir 		,m_nCurrentDict			( 0xFFFFFFFF )
1818*cdf0e10cSrcweir 		,m_pSuggestions			( NULL )
1819*cdf0e10cSrcweir 		,m_aBookFT				( this, CUI_RES( FT_BOOK ) )
1820*cdf0e10cSrcweir 		,m_aBookLB				( this, CUI_RES( LB_BOOK ) )
1821*cdf0e10cSrcweir 		,m_aOriginalFT			( this, CUI_RES( FT_ORIGINAL ) )
1822*cdf0e10cSrcweir 		,m_aOriginalLB			( this, CUI_RES( LB_ORIGINAL ) )
1823*cdf0e10cSrcweir 		,m_aSuggestionsFT		( this, CUI_RES( FT_SUGGESTIONS ) )
1824*cdf0e10cSrcweir 		,m_aEdit1				( this, CUI_RES( ED_1 ), m_aScrollSB, NULL, &m_aEdit2 )
1825*cdf0e10cSrcweir 		,m_aEdit2				( this, CUI_RES( ED_2 ), m_aScrollSB, &m_aEdit1, &m_aEdit3 )
1826*cdf0e10cSrcweir 		,m_aEdit3				( this, CUI_RES( ED_3 ), m_aScrollSB, &m_aEdit2, &m_aEdit4 )
1827*cdf0e10cSrcweir 		,m_aEdit4				( this, CUI_RES( ED_4 ), m_aScrollSB, &m_aEdit3, NULL )
1828*cdf0e10cSrcweir 		,m_aScrollSB			( this, CUI_RES( SB_SCROLL ) )
1829*cdf0e10cSrcweir 		,m_aNewPB				( this, CUI_RES( PB_HHE_NEW ) )
1830*cdf0e10cSrcweir 		,m_aDeletePB			( this, CUI_RES( PB_HHE_DELETE ) )
1831*cdf0e10cSrcweir 		,m_aHelpPB				( this, CUI_RES( PB_HHE_HELP ) )
1832*cdf0e10cSrcweir 		,m_aClosePB				( this, CUI_RES( PB_HHE_CLOSE ) )
1833*cdf0e10cSrcweir 		,m_nTopPos				( 0 )
1834*cdf0e10cSrcweir 		,m_bModifiedSuggestions ( false )
1835*cdf0e10cSrcweir 		,m_bModifiedOriginal    ( false )
1836*cdf0e10cSrcweir 	{
1837*cdf0e10cSrcweir 		m_aOriginalLB.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, OriginalModifyHdl ) );
1838*cdf0e10cSrcweir 
1839*cdf0e10cSrcweir 		m_aNewPB.SetClickHdl( LINK( this, HangulHanjaEditDictDialog, NewPBPushHdl ) );
1840*cdf0e10cSrcweir 		m_aNewPB.Enable( false );
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir 		m_aDeletePB.SetClickHdl( LINK( this, HangulHanjaEditDictDialog, DeletePBPushHdl ) );
1843*cdf0e10cSrcweir 
1844*cdf0e10cSrcweir 		m_aDeletePB.Enable( false );
1845*cdf0e10cSrcweir 
1846*cdf0e10cSrcweir 	#if( MAXNUM_SUGGESTIONS <= 4 )
1847*cdf0e10cSrcweir 		#error number of suggestions should not under-run the value of 5
1848*cdf0e10cSrcweir 	#endif
1849*cdf0e10cSrcweir 
1850*cdf0e10cSrcweir 		Link	aScrLk( LINK( this, HangulHanjaEditDictDialog, ScrollHdl ) );
1851*cdf0e10cSrcweir 		m_aScrollSB.SetScrollHdl( aScrLk );
1852*cdf0e10cSrcweir 		m_aScrollSB.SetEndScrollHdl( aScrLk );
1853*cdf0e10cSrcweir 		m_aScrollSB.SetRangeMin( 0 );
1854*cdf0e10cSrcweir 		m_aScrollSB.SetRangeMax( MAXNUM_SUGGESTIONS );
1855*cdf0e10cSrcweir 		m_aScrollSB.SetPageSize( 4 );		// because we have 4 edits / page
1856*cdf0e10cSrcweir 		m_aScrollSB.SetVisibleSize( 4 );
1857*cdf0e10cSrcweir 
1858*cdf0e10cSrcweir 		m_aEdit1.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl1 ) );
1859*cdf0e10cSrcweir 		m_aEdit2.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl2 ) );
1860*cdf0e10cSrcweir 		m_aEdit3.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl3 ) );
1861*cdf0e10cSrcweir 		m_aEdit4.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl4 ) );
1862*cdf0e10cSrcweir 
1863*cdf0e10cSrcweir 		m_aBookLB.SetSelectHdl( LINK( this, HangulHanjaEditDictDialog, BookLBSelectHdl ) );
1864*cdf0e10cSrcweir 		sal_uInt32	nDictCnt = m_rDictList.size();
1865*cdf0e10cSrcweir 		for( sal_uInt32 n = 0 ; n < nDictCnt ; ++n )
1866*cdf0e10cSrcweir         {
1867*cdf0e10cSrcweir             Reference< XConversionDictionary >	xDic( m_rDictList[n] );
1868*cdf0e10cSrcweir             String aName;
1869*cdf0e10cSrcweir             if(xDic.is())
1870*cdf0e10cSrcweir                 aName = xDic->getName();
1871*cdf0e10cSrcweir             m_aBookLB.InsertEntry( aName );
1872*cdf0e10cSrcweir         }
1873*cdf0e10cSrcweir 		m_aBookLB.SelectEntryPos( sal_uInt16( _nSelDict ) );
1874*cdf0e10cSrcweir 
1875*cdf0e10cSrcweir 		FreeResource();
1876*cdf0e10cSrcweir 
1877*cdf0e10cSrcweir 		InitEditDictDialog( _nSelDict );
1878*cdf0e10cSrcweir 	}
1879*cdf0e10cSrcweir 
1880*cdf0e10cSrcweir 	HangulHanjaEditDictDialog::~HangulHanjaEditDictDialog()
1881*cdf0e10cSrcweir 	{
1882*cdf0e10cSrcweir 		if( m_pSuggestions )
1883*cdf0e10cSrcweir 			delete m_pSuggestions;
1884*cdf0e10cSrcweir 	}
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir 	void HangulHanjaEditDictDialog::UpdateScrollbar( void )
1887*cdf0e10cSrcweir 	{
1888*cdf0e10cSrcweir 		sal_uInt16	nPos = sal_uInt16( m_aScrollSB.GetThumbPos() );
1889*cdf0e10cSrcweir 		m_nTopPos = nPos;
1890*cdf0e10cSrcweir 
1891*cdf0e10cSrcweir 		SetEditText( m_aEdit1, nPos++ );
1892*cdf0e10cSrcweir 		SetEditText( m_aEdit2, nPos++ );
1893*cdf0e10cSrcweir 		SetEditText( m_aEdit3, nPos++ );
1894*cdf0e10cSrcweir 		SetEditText( m_aEdit4, nPos );
1895*cdf0e10cSrcweir 	}
1896*cdf0e10cSrcweir 
1897*cdf0e10cSrcweir //.............................................................................
1898*cdf0e10cSrcweir }	// namespace svx
1899*cdf0e10cSrcweir //.............................................................................
1900