Update ooo320-m1
[ooovba.git] / svx / source / cui / hangulhanjadlg.cxx
blob1ee49881f0b02790400665b0e57842a2b9a730f4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hangulhanjadlg.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
37 #include "hangulhanjadlg.hxx"
38 #ifndef SVX_HANGUL_HANJA_DLG_HRC
39 #include "hangulhanjadlg.hrc"
40 #endif
41 #include "commonlingui.hxx"
42 #include <svx/dialmgr.hxx>
44 #include <svx/dialogs.hrc>
45 #include "helpid.hrc"
47 #include <algorithm>
48 #include <tools/urlobj.hxx>
49 #include <vcl/controllayout.hxx>
50 #include <vcl/msgbox.hxx>
51 #include <svtools/lingucfg.hxx>
52 #include <svtools/linguprops.hxx>
53 //#ifndef _COM_SUN_STAR_FRAME_XSTORABLE_HPP_
54 //#include <com/sun/star/frame/XStorable.hpp>
55 //#endif
56 #ifndef _COM_SUN_STAR_LINGUISTIC2_CONVERSIONDICTIONARYTYPE_HPP_
57 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
58 #ifndef _COM_SUN_STAR_LINGUISTIC2_CONVERSIONDIRECTION_HDL_
59 #include <com/sun/star/linguistic2/ConversionDirection.hdl>
60 #endif
61 #endif
62 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
63 #ifndef _COM_SUN_STAR_I18N_TEXTCONVERSIONOPTION_HDL_
64 #include <com/sun/star/i18n/TextConversionOption.hdl>
65 #endif
66 #include <com/sun/star/util/XFlushable.hpp>
68 #include <comphelper/processfactory.hxx>
69 //#include <ucbhelper/content.hxx>
72 #define HHC HangulHanjaConversion
73 #define LINE_CNT static_cast< USHORT >(2)
75 //.............................................................................
76 namespace svx
78 //.............................................................................
80 using HangulHanjaConversion::eSimpleConversion;
81 using HangulHanjaConversion::eHangulBracketed;
82 using HangulHanjaConversion::eHanjaBracketed;
83 using HangulHanjaConversion::eRubyHanjaAbove;
84 using HangulHanjaConversion::eRubyHanjaBelow;
85 using HangulHanjaConversion::eRubyHangulAbove;
86 using HangulHanjaConversion::eRubyHangulBelow;
88 using namespace ::com::sun::star;
89 using namespace ::com::sun::star::uno;
90 using namespace ::com::sun::star::linguistic2;
91 using namespace ::com::sun::star::lang;
92 using namespace ::com::sun::star::container;
93 using ::rtl::OUString;
95 //-------------------------------------------------------------------------
96 namespace
98 class FontSwitch
100 private:
101 OutputDevice& m_rDev;
103 public:
104 inline FontSwitch( OutputDevice& _rDev, const Font& _rTemporaryFont )
105 :m_rDev( _rDev )
107 m_rDev.Push( PUSH_FONT );
108 m_rDev.SetFont( _rTemporaryFont );
110 inline ~FontSwitch( )
112 m_rDev.Pop( );
117 //=========================================================================
118 //= PseudoRubyText
119 //=========================================================================
120 /** a class which allows to draw two texts in a pseudo-ruby way (which basically
121 means one text above or below the other, and a little bit smaller)
123 class PseudoRubyText
125 public:
126 enum RubyPosition
128 eAbove, eBelow
131 protected:
132 const String m_sPrimaryText;
133 const String m_sSecondaryText;
134 const RubyPosition m_ePosition;
136 public:
137 PseudoRubyText( const String& _rPrimary, const String& _rSecondary, const RubyPosition _ePosition );
139 public:
140 void Paint( OutputDevice& _rDevice, const Rectangle& _rRect, USHORT _nTextStyle,
141 Rectangle* _pPrimaryLocation = NULL, Rectangle* _pSecondaryLocation = NULL,
142 ::vcl::ControlLayoutData* _pLayoutData = NULL );
145 //-------------------------------------------------------------------------
146 PseudoRubyText::PseudoRubyText( const String& _rPrimary, const String& _rSecondary, const RubyPosition _ePosition )
147 :m_sPrimaryText( _rPrimary )
148 ,m_sSecondaryText( _rSecondary )
149 ,m_ePosition( _ePosition )
153 //-------------------------------------------------------------------------
154 void PseudoRubyText::Paint( OutputDevice& _rDevice, const Rectangle& _rRect, USHORT _nTextStyle,
155 Rectangle* _pPrimaryLocation, Rectangle* _pSecondaryLocation, ::vcl::ControlLayoutData* _pLayoutData )
157 bool bLayoutOnly = NULL != _pLayoutData;
158 MetricVector* pTextMetrics = bLayoutOnly ? &_pLayoutData->m_aUnicodeBoundRects : NULL;
159 String* pDisplayText = bLayoutOnly ? &_pLayoutData->m_aDisplayText : NULL;
161 Size aPlaygroundSize( _rRect.GetSize() );
163 // the font for the secondary text:
164 Font aSmallerFont( _rDevice.GetFont() );
165 // heuristic: 80% of the original size
166 aSmallerFont.SetHeight( (long)( 0.8 * aSmallerFont.GetHeight() ) );
168 // let's calculate the size of our two texts
169 Rectangle aPrimaryRect = _rDevice.GetTextRect( _rRect, m_sPrimaryText, _nTextStyle );
170 Rectangle aSecondaryRect;
172 FontSwitch aFontRestore( _rDevice, aSmallerFont );
173 aSecondaryRect = _rDevice.GetTextRect( _rRect, m_sSecondaryText, _nTextStyle );
176 // position these rectangles properly
177 // x-axis:
178 sal_Int32 nCombinedWidth = ::std::max( aSecondaryRect.GetWidth(), aPrimaryRect.GetWidth() );
179 // the rectangle where both texts will reside is as high as possible, and as wide as the
180 // widest of both text rects
181 aPrimaryRect.Left() = aSecondaryRect.Left() = _rRect.Left();
182 aPrimaryRect.Right() = aSecondaryRect.Right() = _rRect.Left() + nCombinedWidth;
183 if ( TEXT_DRAW_RIGHT & _nTextStyle )
185 // move the rectangles to the right
186 aPrimaryRect.Move( aPlaygroundSize.Width() - nCombinedWidth, 0 );
187 aSecondaryRect.Move( aPlaygroundSize.Width() - nCombinedWidth, 0 );
189 else if ( TEXT_DRAW_CENTER & _nTextStyle )
191 // center the rectangles
192 aPrimaryRect.Move( ( aPlaygroundSize.Width() - nCombinedWidth ) / 2, 0 );
193 aSecondaryRect.Move( ( aPlaygroundSize.Width() - nCombinedWidth ) / 2, 0 );
196 // y-axis:
197 sal_Int32 nCombinedHeight = aPrimaryRect.GetHeight() + aSecondaryRect.GetHeight();
198 // align to the top, for the moment
199 aPrimaryRect.Move( 0, _rRect.Top() - aPrimaryRect.Top() );
200 aSecondaryRect.Move( 0, aPrimaryRect.Top() + aPrimaryRect.GetHeight() - aSecondaryRect.Top() );
201 if ( TEXT_DRAW_BOTTOM & _nTextStyle )
203 // move the rects to the bottom
204 aPrimaryRect.Move( 0, aPlaygroundSize.Height() - nCombinedHeight );
205 aSecondaryRect.Move( 0, aPlaygroundSize.Height() - nCombinedHeight );
207 else if ( TEXT_DRAW_VCENTER & _nTextStyle )
209 // move the rects to the bottom
210 aPrimaryRect.Move( 0, ( aPlaygroundSize.Height() - nCombinedHeight ) / 2 );
211 aSecondaryRect.Move( 0, ( aPlaygroundSize.Height() - nCombinedHeight ) / 2 );
214 // 'til here, everything we did assumes that the secondary text is painted _below_ the primary
215 // text. If this isn't the case, we need to correct the rectangles
216 if ( eAbove == m_ePosition )
218 sal_Int32 nVertDistance = aSecondaryRect.Top() - aPrimaryRect.Top();
219 aSecondaryRect.Move( 0, -nVertDistance );
220 aPrimaryRect.Move( 0, nCombinedHeight - nVertDistance );
223 // now draw the texts
224 // as we already calculated the precise rectangles for the texts, we don't want to
225 // use the alignment flags given - within it's rect, every text is centered
226 USHORT nDrawTextStyle( _nTextStyle );
227 nDrawTextStyle &= ~( TEXT_DRAW_RIGHT | TEXT_DRAW_LEFT | TEXT_DRAW_BOTTOM | TEXT_DRAW_TOP );
228 nDrawTextStyle |= TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER;
230 _rDevice.DrawText( aPrimaryRect, m_sPrimaryText, nDrawTextStyle, pTextMetrics, pDisplayText );
232 FontSwitch aFontRestore( _rDevice, aSmallerFont );
233 _rDevice.DrawText( aSecondaryRect, m_sSecondaryText, nDrawTextStyle, pTextMetrics, pDisplayText );
236 // outta here
237 if ( _pPrimaryLocation )
238 *_pPrimaryLocation = aPrimaryRect;
239 if ( _pSecondaryLocation )
240 *_pSecondaryLocation = aSecondaryRect;
243 //=========================================================================
244 //= RubyRadioButton
245 //=========================================================================
246 class RubyRadioButton :public RadioButton
247 ,protected PseudoRubyText
249 using svx::PseudoRubyText::Paint;
251 public:
252 RubyRadioButton(
253 Window* _pParent,
254 const ResId& _rId, // the text in the resource will be taken as primary text
255 const String& _rSecondary, // this will be the secondary text which will be printed somewhat smaller
256 const PseudoRubyText::RubyPosition _ePosition );
258 protected:
259 virtual void Paint( const Rectangle& _rRect );
262 //-------------------------------------------------------------------------
263 RubyRadioButton::RubyRadioButton( Window* _pParent, const ResId& _rId,
264 const String& _rSecondary, const PseudoRubyText::RubyPosition _ePosition )
265 :RadioButton( _pParent, _rId )
266 ,PseudoRubyText( RadioButton::GetText(), _rSecondary, _ePosition )
270 //-------------------------------------------------------------------------
271 void RubyRadioButton::Paint( const Rectangle& )
273 HideFocus();
275 // calculate the size of the radio image - we're to paint our text _after_ this image
276 DBG_ASSERT( !GetModeRadioImage(), "RubyRadioButton::Paint: images not supported!" );
277 Size aImageSize = GetRadioImage( GetSettings(), 0 ).GetSizePixel();
278 aImageSize.Width() = CalcZoom( aImageSize.Width() );
279 aImageSize.Height() = CalcZoom( aImageSize.Height() );
281 Rectangle aOverallRect( Point( 0, 0 ), GetOutputSizePixel() );
282 aOverallRect.Left() += aImageSize.Width() + 4; // 4 is the separator between the image and the text
283 // inflate the rect a little bit (because the VCL radio button does the same)
284 Rectangle aTextRect( aOverallRect );
285 ++aTextRect.Left(); --aTextRect.Right();
286 ++aTextRect.Top(); --aTextRect.Bottom();
288 // calculate the text flags for the painting
289 USHORT nTextStyle = TEXT_DRAW_MNEMONIC;
290 WinBits nStyle = GetStyle( );
292 // the horizontal alignment
293 if ( nStyle & WB_RIGHT )
294 nTextStyle |= TEXT_DRAW_RIGHT;
295 else if ( nStyle & WB_CENTER )
296 nTextStyle |= TEXT_DRAW_CENTER;
297 else
298 nTextStyle |= TEXT_DRAW_LEFT;
299 // the vertical alignment
300 if ( nStyle & WB_BOTTOM )
301 nTextStyle |= TEXT_DRAW_BOTTOM;
302 else if ( nStyle & WB_VCENTER )
303 nTextStyle |= TEXT_DRAW_VCENTER;
304 else
305 nTextStyle |= TEXT_DRAW_TOP;
306 // mnemonics
307 if ( 0 == ( nStyle & WB_NOLABEL ) )
308 nTextStyle |= TEXT_DRAW_MNEMONIC;
310 // paint the ruby text
311 Rectangle aPrimaryTextLocation, aSecondaryTextLocation;
312 PseudoRubyText::Paint( *this, aTextRect, nTextStyle, &aPrimaryTextLocation, &aSecondaryTextLocation );
314 // the focus rectangle is to be painted around both texts
315 Rectangle aCombinedRect( aPrimaryTextLocation );
316 aCombinedRect.Union( aSecondaryTextLocation );
317 SetFocusRect( aCombinedRect );
319 // let the base class paint the radio button
320 // for this, give it the proper location to paint the image (vertically centered, relative to our text)
321 Rectangle aImageLocation( Point( 0, 0 ), aImageSize );
322 sal_Int32 nTextHeight = aSecondaryTextLocation.Bottom() - aPrimaryTextLocation.Top();
323 aImageLocation.Top() = aPrimaryTextLocation.Top() + ( nTextHeight - aImageSize.Height() ) / 2;
324 aImageLocation.Bottom() = aImageLocation.Top() + aImageSize.Height();
325 SetStateRect( aImageLocation );
326 DrawRadioButtonState( );
328 // mouse clicks should be recognized in a rect which is one pixel larger in each direction, plus
329 // includes the image
330 aCombinedRect.Left() = aImageLocation.Left(); ++aCombinedRect.Right();
331 --aCombinedRect.Top(); ++aCombinedRect.Bottom();
332 SetMouseRect( aCombinedRect );
334 // paint the focus rect, if necessary
335 if ( HasFocus() )
336 ShowFocus( aTextRect );
339 //=========================================================================
340 //= SuggestionSet
341 //=========================================================================
342 //-------------------------------------------------------------------------
344 SuggestionSet::SuggestionSet( Window* pParent )
345 : ValueSet( pParent, pParent->GetStyle() | WB_BORDER )
350 SuggestionSet::~SuggestionSet()
352 ClearSet();
355 void SuggestionSet::UserDraw( const UserDrawEvent& rUDEvt )
357 OutputDevice* pDev = rUDEvt.GetDevice();
358 Rectangle aRect = rUDEvt.GetRect();
359 USHORT nItemId = rUDEvt.GetItemId();
361 String sText = *static_cast< String* >( GetItemData( nItemId ) );
362 pDev->DrawText( aRect, sText, TEXT_DRAW_CENTER | TEXT_DRAW_VCENTER );
365 void SuggestionSet::ClearSet()
367 USHORT i, nCount = GetItemCount();
368 for ( i = 0; i < nCount; ++i )
369 delete static_cast< String* >( GetItemData(i) );
370 Clear();
373 //=========================================================================
374 //= SuggestionDisplay
375 //=========================================================================
376 //-------------------------------------------------------------------------
378 SuggestionDisplay::SuggestionDisplay( Window* pParent, const ResId& rResId )
379 : Control( pParent, rResId )
380 , m_bDisplayListBox(true)
381 , m_aValueSet(this)
382 , m_aListBox(this,GetStyle() | WB_BORDER )
383 , m_bInSelectionUpdate(false)
385 m_aValueSet.SetSelectHdl( LINK( this, SuggestionDisplay, SelectSuggestionHdl ) );
386 m_aListBox.SetSelectHdl( LINK( this, SuggestionDisplay, SelectSuggestionHdl ) );
388 m_aValueSet.SetLineCount( LINE_CNT );
389 m_aValueSet.SetStyle( m_aValueSet.GetStyle() | WB_ITEMBORDER | WB_FLATVALUESET | WB_VSCROLL );
390 m_aValueSet.SetBorderStyle( WINDOW_BORDER_MONO );
391 String aOneCharacter(RTL_CONSTASCII_STRINGPARAM("AU"));
392 long nItemWidth = 2*GetTextWidth( aOneCharacter );
393 m_aValueSet.SetItemWidth( nItemWidth );
395 Point aPos(0,0);
396 Size aSize(GetSizePixel());
397 m_aValueSet.SetSizePixel(aSize);
398 m_aListBox.SetSizePixel(aSize);
400 implUpdateDisplay();
403 SuggestionDisplay::~SuggestionDisplay()
407 void SuggestionDisplay::implUpdateDisplay()
409 bool bShowBox = IsVisible() && m_bDisplayListBox;
410 bool bShowSet = IsVisible() && !m_bDisplayListBox;
412 m_aListBox.Show(bShowBox);
413 m_aValueSet.Show(bShowSet);
416 void SuggestionDisplay::StateChanged( StateChangedType nStateChange )
418 if( STATE_CHANGE_VISIBLE == nStateChange )
419 implUpdateDisplay();
422 Control& SuggestionDisplay::implGetCurrentControl()
424 if( m_bDisplayListBox )
425 return m_aListBox;
426 return m_aValueSet;
429 void SuggestionDisplay::KeyInput( const KeyEvent& rKEvt )
431 implGetCurrentControl().KeyInput( rKEvt );
433 void SuggestionDisplay::KeyUp( const KeyEvent& rKEvt )
435 implGetCurrentControl().KeyUp( rKEvt );
437 void SuggestionDisplay::Activate()
439 implGetCurrentControl().Activate();
441 void SuggestionDisplay::Deactivate()
443 implGetCurrentControl().Deactivate();
445 void SuggestionDisplay::GetFocus()
447 implGetCurrentControl().GetFocus();
449 void SuggestionDisplay::LoseFocus()
451 implGetCurrentControl().LoseFocus();
453 void SuggestionDisplay::Command( const CommandEvent& rCEvt )
455 implGetCurrentControl().Command( rCEvt );
458 void SuggestionDisplay::DisplayListBox( bool bDisplayListBox )
460 if( m_bDisplayListBox != bDisplayListBox )
462 Control& rOldControl = implGetCurrentControl();
463 BOOL bHasFocus = rOldControl.HasFocus();
465 m_bDisplayListBox = bDisplayListBox;
467 if( bHasFocus )
469 Control& rNewControl = implGetCurrentControl();
470 rNewControl.GrabFocus();
473 implUpdateDisplay();
477 IMPL_LINK( SuggestionDisplay, SelectSuggestionHdl, Control*, pControl )
479 if( m_bInSelectionUpdate )
480 return 0L;
482 m_bInSelectionUpdate = true;
483 if(pControl==&m_aListBox)
485 USHORT nPos = m_aListBox.GetSelectEntryPos();
486 m_aValueSet.SelectItem( nPos+1 ); //itemid == pos+1 (id 0 has special meaning)
488 else
490 USHORT nPos = m_aValueSet.GetSelectItemId()-1; //itemid == pos+1 (id 0 has special meaning)
491 m_aListBox.SelectEntryPos( nPos );
493 m_bInSelectionUpdate = false;
494 m_aSelectLink.Call(this);
495 return 0L;
498 void SuggestionDisplay::SetSelectHdl( const Link& rLink )
500 m_aSelectLink = rLink;
502 void SuggestionDisplay::Clear()
504 m_aListBox.Clear();
505 m_aValueSet.Clear();
507 void SuggestionDisplay::InsertEntry( const XubString& rStr )
509 USHORT nItemId = m_aListBox.InsertEntry( rStr ) + 1; //itemid == pos+1 (id 0 has special meaning)
510 m_aValueSet.InsertItem( nItemId );
511 String* pItemData = new String(rStr);
512 m_aValueSet.SetItemData( nItemId, pItemData );
514 void SuggestionDisplay::SelectEntryPos( USHORT nPos )
516 m_aListBox.SelectEntryPos( nPos );
517 m_aValueSet.SelectItem( nPos+1 ); //itemid == pos+1 (id 0 has special meaning)
519 USHORT SuggestionDisplay::GetEntryCount() const
521 return m_aListBox.GetEntryCount();
523 XubString SuggestionDisplay::GetEntry( USHORT nPos ) const
525 return m_aListBox.GetEntry( nPos );
527 XubString SuggestionDisplay::GetSelectEntry() const
529 return m_aListBox.GetSelectEntry();
531 void SuggestionDisplay::SetHelpIds()
533 this->SetHelpId( HID_HANGULDLG_SUGGESTIONS );
534 m_aValueSet.SetHelpId( HID_HANGULDLG_SUGGESTIONS_GRID );
535 m_aListBox.SetHelpId( HID_HANGULDLG_SUGGESTIONS_LIST );
538 //=========================================================================
539 //= HangulHanjaConversionDialog
540 //=========================================================================
541 //-------------------------------------------------------------------------
542 HangulHanjaConversionDialog::HangulHanjaConversionDialog( Window* _pParent, HHC::ConversionDirection _ePrimaryDirection )
543 :ModalDialog( _pParent, SVX_RES( RID_SVX_MDLG_HANGULHANJA ) )
544 ,m_pPlayground( new SvxCommonLinguisticControl( this ) )
545 ,m_aFind ( m_pPlayground.get(), SVX_RES( PB_FIND ) )
546 ,m_aSuggestions ( m_pPlayground.get(), SVX_RES( CTL_SUGGESTIONS ) )
547 ,m_aFormat ( m_pPlayground.get(), SVX_RES( FT_FORMAT ) )
548 ,m_aSimpleConversion( m_pPlayground.get(), SVX_RES( RB_SIMPLE_CONVERSION ) )
549 ,m_aHangulBracketed ( m_pPlayground.get(), SVX_RES( RB_HANJA_HANGUL_BRACKETED ) )
550 ,m_aHanjaBracketed ( m_pPlayground.get(), SVX_RES( RB_HANGUL_HANJA_BRACKETED ) )
551 ,m_aConversion ( m_pPlayground.get(), SVX_RES( FT_CONVERSION ) )
552 ,m_aHangulOnly ( m_pPlayground.get(), SVX_RES( CB_HANGUL_ONLY ) )
553 ,m_aHanjaOnly ( m_pPlayground.get(), SVX_RES( CB_HANJA_ONLY ) )
554 ,m_aReplaceByChar ( m_pPlayground.get(), SVX_RES( CB_REPLACE_BY_CHARACTER ) )
555 ,m_pIgnoreNonPrimary( NULL )
556 ,m_bDocumentMode( true )
558 // special creation of the 4 pseudo-ruby radio buttons
559 String sSecondaryHangul( SVX_RES( STR_HANGUL ) );
560 String sSecondaryHanja( SVX_RES( STR_HANJA ) );
561 m_pHanjaAbove.reset( new RubyRadioButton( m_pPlayground.get(), SVX_RES( RB_HANGUL_HANJA_ABOVE ), sSecondaryHanja, PseudoRubyText::eAbove ) );
562 m_pHanjaBelow.reset( new RubyRadioButton( m_pPlayground.get(), SVX_RES( RB_HANGUL_HANJA_BELOW ), sSecondaryHanja, PseudoRubyText::eBelow ) );
563 m_pHangulAbove.reset( new RubyRadioButton( m_pPlayground.get(), SVX_RES( RB_HANJA_HANGUL_ABOVE ), sSecondaryHangul, PseudoRubyText::eAbove ) );
564 m_pHangulBelow.reset( new RubyRadioButton( m_pPlayground.get(), SVX_RES( RB_HANJA_HANGUL_BELOW ), sSecondaryHangul, PseudoRubyText::eBelow ) );
566 // since these 4 buttons are not created within the other members, they have a wrong initial Z-Order
567 // correct this
568 m_pHanjaAbove->SetZOrder( &m_aHanjaBracketed, WINDOW_ZORDER_BEHIND );
569 m_pHanjaBelow->SetZOrder( m_pHanjaAbove.get(), WINDOW_ZORDER_BEHIND );
570 m_pHangulAbove->SetZOrder( m_pHanjaBelow.get(), WINDOW_ZORDER_BEHIND );
571 m_pHangulBelow->SetZOrder( m_pHangulAbove.get(), WINDOW_ZORDER_BEHIND );
573 // VCL automatically sets the WB_GROUP bit, if the previous sibling (at the moment of creation)
574 // is no radion button
575 m_pHanjaAbove->SetStyle( m_pHanjaAbove->GetStyle() & ~WB_GROUP );
577 // the "Find" button and the word input control may not have the proper distance/extensions
578 // -> correct this
579 Point aDistance = LogicToPixel( Point( 3, 0 ), MAP_APPFONT );
580 sal_Int32 nTooLargeByPixels =
581 // right margin of the word input control
582 ( m_pPlayground->GetWordInputControl().GetPosPixel().X()
583 + m_pPlayground->GetWordInputControl().GetSizePixel().Width()
585 // minus left margin of the find button
586 - m_aFind.GetPosPixel().X()
587 // plus desired distance between the both
588 + aDistance.X();
589 // make the word input control smaller
590 Size aSize = m_pPlayground->GetWordInputControl().GetSizePixel();
591 aSize.Width() -= nTooLargeByPixels;
592 m_pPlayground->GetWordInputControl().SetSizePixel( aSize );
594 // additionall, the playground is not wide enough (in it's default size)
595 sal_Int32 nEnlargeWidth = 0;
597 FixedText aBottomAnchor( m_pPlayground.get(), SVX_RES( FT_RESIZE_ANCHOR ) );
598 Point aAnchorPos = aBottomAnchor.GetPosPixel();
600 nEnlargeWidth = aAnchorPos.X() - m_pPlayground->GetActionButtonsLocation().X();
602 m_pPlayground->Enlarge( nEnlargeWidth, 0 );
604 // insert our controls into the z-order of the playground
605 m_pPlayground->InsertControlGroup( m_aFind, m_aFind, SvxCommonLinguisticControl::eLeftRightWords );
606 m_pPlayground->InsertControlGroup( m_aSuggestions, m_aHanjaOnly, SvxCommonLinguisticControl::eSuggestionLabel );
607 m_pPlayground->InsertControlGroup( m_aReplaceByChar, m_aReplaceByChar, SvxCommonLinguisticControl::eActionButtons );
609 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eClose, LINK( this, HangulHanjaConversionDialog, OnClose ) );
610 m_pPlayground->GetWordInputControl().SetModifyHdl( LINK( this, HangulHanjaConversionDialog, OnSuggestionModified ) );
611 m_aSuggestions.SetSelectHdl( LINK( this, HangulHanjaConversionDialog, OnSuggestionSelected ) );
613 m_aReplaceByChar.SetClickHdl( LINK( this, HangulHanjaConversionDialog, ClickByCharacterHdl ) );
615 m_aHangulOnly.SetClickHdl( LINK( this, HangulHanjaConversionDialog, OnConversionDirectionClicked ) );
616 m_aHanjaOnly.SetClickHdl( LINK( this, HangulHanjaConversionDialog, OnConversionDirectionClicked ) );
618 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eOptions,
619 LINK( this, HangulHanjaConversionDialog, OnOption ) );
620 m_pPlayground->GetButton( SvxCommonLinguisticControl::eOptions )->Show();
621 // m_pPlayground->EnableButton( SvxCommonLinguisticControl::eOptions, true );
623 if ( HangulHanjaConversion::eHangulToHanja == _ePrimaryDirection )
625 // m_aHanjaOnly.Enable( sal_False );
626 m_pIgnoreNonPrimary = &m_aHangulOnly;
628 else
630 // m_aHangulOnly.Enable( sal_False );
631 m_pIgnoreNonPrimary = &m_aHanjaOnly;
633 // m_pIgnoreNonPrimary->Check();
635 // initial focus
636 FocusSuggestion( );
638 // initial control values
639 m_aSimpleConversion.Check();
641 m_pPlayground->GetButton(SvxCommonLinguisticControl::eClose )->SetHelpId(HID_HANGULDLG_BUTTON_CLOSE );
642 m_pPlayground->GetButton(SvxCommonLinguisticControl::eIgnore )->SetHelpId(HID_HANGULDLG_BUTTON_IGNORE );
643 m_pPlayground->GetButton(SvxCommonLinguisticControl::eIgnoreAll )->SetHelpId(HID_HANGULDLG_BUTTON_IGNOREALL);
644 m_pPlayground->GetButton(SvxCommonLinguisticControl::eChange )->SetHelpId(HID_HANGULDLG_BUTTON_CHANGE );
645 m_pPlayground->GetButton(SvxCommonLinguisticControl::eChangeAll )->SetHelpId(HID_HANGULDLG_BUTTON_CHANGEALL);
646 m_pPlayground->GetButton(SvxCommonLinguisticControl::eOptions )->SetHelpId(HID_HANGULDLG_BUTTON_OPTIONS );
647 m_pPlayground->GetWordInputControl().SetHelpId(HID_HANGULDLG_EDIT_NEWWORD);
649 FreeResource();
651 m_aSuggestions.SetHelpIds();
654 //-------------------------------------------------------------------------
655 HangulHanjaConversionDialog::~HangulHanjaConversionDialog( )
659 //-------------------------------------------------------------------------
660 void HangulHanjaConversionDialog::FillSuggestions( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rSuggestions )
662 m_aSuggestions.Clear();
664 const ::rtl::OUString* pSuggestions = _rSuggestions.getConstArray();
665 const ::rtl::OUString* pSuggestionsEnd = _rSuggestions.getConstArray() + _rSuggestions.getLength();
666 while ( pSuggestions != pSuggestionsEnd )
667 m_aSuggestions.InsertEntry( *pSuggestions++ );
669 // select the first suggestion, and fill in the suggestion edit field
670 String sFirstSuggestion;
671 if ( m_aSuggestions.GetEntryCount() )
673 sFirstSuggestion = m_aSuggestions.GetEntry( 0 );
674 m_aSuggestions.SelectEntryPos( 0 );
676 m_pPlayground->GetWordInputControl().SetText( sFirstSuggestion );
677 m_pPlayground->GetWordInputControl().SaveValue();
678 OnSuggestionModified( &m_pPlayground->GetWordInputControl() );
681 //-------------------------------------------------------------------------
682 void HangulHanjaConversionDialog::SetOptionsChangedHdl( const Link& _rHdl )
684 m_aOptionsChangedLink = _rHdl;
687 //-------------------------------------------------------------------------
688 void HangulHanjaConversionDialog::SetIgnoreHdl( const Link& _rHdl )
690 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eIgnore, _rHdl );
693 //-------------------------------------------------------------------------
694 void HangulHanjaConversionDialog::SetIgnoreAllHdl( const Link& _rHdl )
696 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eIgnoreAll, _rHdl );
699 //-------------------------------------------------------------------------
700 void HangulHanjaConversionDialog::SetChangeHdl( const Link& _rHdl )
702 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eChange, _rHdl );
705 //-------------------------------------------------------------------------
706 void HangulHanjaConversionDialog::SetChangeAllHdl( const Link& _rHdl )
708 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eChangeAll, _rHdl );
711 //-------------------------------------------------------------------------
712 void HangulHanjaConversionDialog::SetOptionsHdl( const Link& _rHdl )
714 m_pPlayground->SetButtonHandler( SvxCommonLinguisticControl::eOptions, _rHdl );
717 //-------------------------------------------------------------------------
718 void HangulHanjaConversionDialog::SetFindHdl( const Link& _rHdl )
720 m_aFind.SetClickHdl( _rHdl );
723 //-------------------------------------------------------------------------
724 void HangulHanjaConversionDialog::SetConversionFormatChangedHdl( const Link& _rHdl )
726 m_aSimpleConversion.SetClickHdl( _rHdl );
727 m_aHangulBracketed.SetClickHdl( _rHdl );
728 m_aHanjaBracketed.SetClickHdl( _rHdl );
729 m_pHanjaAbove->SetClickHdl( _rHdl );
730 m_pHanjaBelow->SetClickHdl( _rHdl );
731 m_pHangulAbove->SetClickHdl( _rHdl );
732 m_pHangulBelow->SetClickHdl( _rHdl );
735 //-------------------------------------------------------------------------
736 void HangulHanjaConversionDialog::SetClickByCharacterHdl( const Link& _rHdl )
738 m_aClickByCharacterLink = _rHdl;
741 //-------------------------------------------------------------------------
742 IMPL_LINK( HangulHanjaConversionDialog, OnSuggestionSelected, void*, EMPTYARG )
744 m_pPlayground->GetWordInputControl().SetText( m_aSuggestions.GetSelectEntry() );
745 OnSuggestionModified( NULL );
746 return 0L;
749 //-------------------------------------------------------------------------
750 IMPL_LINK( HangulHanjaConversionDialog, OnSuggestionModified, void*, EMPTYARG )
752 m_aFind.Enable( m_pPlayground->GetWordInputControl().GetSavedValue() != m_pPlayground->GetWordInputControl().GetText() );
754 bool bSameLen = m_pPlayground->GetWordInputControl().GetText().Len() == m_pPlayground->GetCurrentText().Len();
755 m_pPlayground->EnableButton( SvxCommonLinguisticControl::eChange, m_bDocumentMode && bSameLen );
756 m_pPlayground->EnableButton( SvxCommonLinguisticControl::eChangeAll, m_bDocumentMode && bSameLen );
758 return 0L;
761 //-------------------------------------------------------------------------
762 IMPL_LINK( HangulHanjaConversionDialog, ClickByCharacterHdl, CheckBox *, pBox )
764 m_aClickByCharacterLink.Call(pBox);
766 bool bByCharacter = pBox->IsChecked();
767 m_aSuggestions.DisplayListBox( !bByCharacter );
769 return 0L;
772 //-------------------------------------------------------------------------
773 IMPL_LINK( HangulHanjaConversionDialog, OnConversionDirectionClicked, CheckBox *, pBox )
775 CheckBox *pOtherBox = 0;
776 if (pBox == &m_aHangulOnly)
777 pOtherBox = &m_aHanjaOnly;
778 else if (pBox == &m_aHanjaOnly)
779 pOtherBox = &m_aHangulOnly;
780 if (pBox && pOtherBox)
782 BOOL bBoxChecked = pBox->IsChecked();
783 if (bBoxChecked)
784 pOtherBox->Check( FALSE );
785 pOtherBox->Enable( !bBoxChecked );
788 return 0L;
791 //-------------------------------------------------------------------------
792 IMPL_LINK( HangulHanjaConversionDialog, OnClose, void*, EMPTYARG )
794 Close();
795 return 0L;
798 IMPL_LINK( HangulHanjaConversionDialog, OnOption, void*, EMPTYARG )
800 HangulHanjaOptionsDialog aOptDlg( this );
801 aOptDlg.Execute();
802 m_aOptionsChangedLink.Call(this);
803 return 0L;
806 //-------------------------------------------------------------------------
807 String HangulHanjaConversionDialog::GetCurrentString( ) const
809 return m_pPlayground->GetCurrentText( );
812 //-------------------------------------------------------------------------
813 void HangulHanjaConversionDialog::FocusSuggestion( )
815 m_pPlayground->GetWordInputControl().GrabFocus();
818 //-------------------------------------------------------------------------
819 namespace
821 void lcl_modifyWindowStyle( Window* _pWin, WinBits _nSet, WinBits _nReset )
823 DBG_ASSERT( 0 == ( _nSet & _nReset ), "lcl_modifyWindowStyle: set _and_ reset the same bit?" );
824 if ( _pWin )
825 _pWin->SetStyle( ( _pWin->GetStyle() | _nSet ) & ~_nReset );
829 //-------------------------------------------------------------------------
830 void HangulHanjaConversionDialog::SetCurrentString( const String& _rNewString,
831 const Sequence< ::rtl::OUString >& _rSuggestions, bool _bOriginatesFromDocument )
833 m_pPlayground->SetCurrentText( _rNewString );
835 bool bOldDocumentMode = m_bDocumentMode;
836 m_bDocumentMode = _bOriginatesFromDocument; // before FillSuggestions!
837 FillSuggestions( _rSuggestions );
839 m_pPlayground->EnableButton( SvxCommonLinguisticControl::eIgnoreAll, m_bDocumentMode );
840 // all other buttons have been implicitly enabled or disabled during filling in the suggestions
842 // switch the def button depending if we're working for document text
843 if ( bOldDocumentMode != m_bDocumentMode )
845 Window* pOldDefButton = NULL;
846 Window* pNewDefButton = NULL;
847 if ( m_bDocumentMode )
849 pOldDefButton = &m_aFind;
850 pNewDefButton = m_pPlayground->GetButton( SvxCommonLinguisticControl::eChange );
852 else
854 pOldDefButton = m_pPlayground->GetButton( SvxCommonLinguisticControl::eChange );
855 pNewDefButton = &m_aFind;
858 DBG_ASSERT( WB_DEFBUTTON == ( pOldDefButton->GetStyle( ) & WB_DEFBUTTON ),
859 "HangulHanjaConversionDialog::SetCurrentString: wrong previous default button (1)!" );
860 DBG_ASSERT( 0 == ( pNewDefButton->GetStyle( ) & WB_DEFBUTTON ),
861 "HangulHanjaConversionDialog::SetCurrentString: wrong previous default button (2)!" );
863 lcl_modifyWindowStyle( pOldDefButton, 0, WB_DEFBUTTON );
864 lcl_modifyWindowStyle( pNewDefButton, WB_DEFBUTTON, 0 );
866 // give the focus to the new def button temporarily - VCL is somewhat peculiar
867 // in recognizing a new default button
868 sal_uInt32 nSaveFocusId = Window::SaveFocus();
869 pNewDefButton->GrabFocus();
870 Window::EndSaveFocus( nSaveFocusId );
874 //-------------------------------------------------------------------------
875 String HangulHanjaConversionDialog::GetCurrentSuggestion( ) const
877 return m_pPlayground->GetWordInputControl().GetText();
880 //-------------------------------------------------------------------------
881 void HangulHanjaConversionDialog::SetByCharacter( sal_Bool _bByCharacter )
883 m_aReplaceByChar.Check( _bByCharacter );
884 m_aSuggestions.DisplayListBox( !_bByCharacter );
887 //-------------------------------------------------------------------------
888 sal_Bool HangulHanjaConversionDialog::GetByCharacter( ) const
890 return m_aReplaceByChar.IsChecked();
892 //-------------------------------------------------------------------------
893 void HangulHanjaConversionDialog::SetConversionDirectionState(
894 sal_Bool _bTryBothDirections,
895 HHC::ConversionDirection _ePrimaryConversionDirection )
897 // default state: try both direction
898 m_aHangulOnly.Check( FALSE );
899 m_aHangulOnly.Enable( TRUE );
900 m_aHanjaOnly.Check( FALSE );
901 m_aHanjaOnly.Enable( TRUE );
903 if (!_bTryBothDirections)
905 CheckBox *pBox = _ePrimaryConversionDirection == HHC::eHangulToHanja?
906 &m_aHangulOnly : &m_aHanjaOnly;
907 pBox->Check( sal_True );
908 OnConversionDirectionClicked( pBox );
912 //-------------------------------------------------------------------------
913 sal_Bool HangulHanjaConversionDialog::GetUseBothDirections( ) const
915 // DBG_ASSERT( m_pIgnoreNonPrimary, "HangulHanjaConversionDialog::GetUseBothDirections: where's the check box pointer?" );
916 // return m_pIgnoreNonPrimary ? !m_pIgnoreNonPrimary->IsChecked( ) : sal_True;
917 return !m_aHangulOnly.IsChecked() && !m_aHanjaOnly.IsChecked();
920 //-------------------------------------------------------------------------
921 HHC::ConversionDirection HangulHanjaConversionDialog::GetDirection(
922 HHC::ConversionDirection eDefaultDirection ) const
924 HHC::ConversionDirection eDirection = eDefaultDirection;
925 if (m_aHangulOnly.IsChecked() && !m_aHanjaOnly.IsChecked())
926 eDirection = HHC::eHangulToHanja;
927 else if (!m_aHangulOnly.IsChecked() && m_aHanjaOnly.IsChecked())
928 eDirection = HHC::eHanjaToHangul;
929 return eDirection;
932 //-------------------------------------------------------------------------
933 void HangulHanjaConversionDialog::SetConversionFormat( HHC::ConversionFormat _eType )
935 switch ( _eType )
937 case HHC::eSimpleConversion: m_aSimpleConversion.Check(); break;
938 case HHC::eHangulBracketed: m_aHangulBracketed.Check(); break;
939 case HHC::eHanjaBracketed: m_aHanjaBracketed.Check(); break;
940 case HHC::eRubyHanjaAbove: m_pHanjaAbove->Check(); break;
941 case HHC::eRubyHanjaBelow: m_pHanjaBelow->Check(); break;
942 case HHC::eRubyHangulAbove: m_pHangulAbove->Check(); break;
943 case HHC::eRubyHangulBelow: m_pHangulBelow->Check(); break;
944 default:
945 DBG_ERROR( "HangulHanjaConversionDialog::SetConversionFormat: unknown type!" );
949 //-------------------------------------------------------------------------
950 HHC::ConversionFormat HangulHanjaConversionDialog::GetConversionFormat( ) const
952 if ( m_aSimpleConversion.IsChecked() )
953 return HHC::eSimpleConversion;
954 if ( m_aHangulBracketed.IsChecked() )
955 return HHC::eHangulBracketed;
956 if ( m_aHanjaBracketed.IsChecked() )
957 return HHC::eHanjaBracketed;
958 if ( m_pHanjaAbove->IsChecked() )
959 return HHC::eRubyHanjaAbove;
960 if ( m_pHanjaBelow->IsChecked() )
961 return HHC::eRubyHanjaBelow;
962 if ( m_pHangulAbove->IsChecked() )
963 return HHC::eRubyHangulAbove;
964 if ( m_pHangulBelow->IsChecked() )
965 return HHC::eRubyHangulBelow;
967 DBG_ERROR( "HangulHanjaConversionDialog::GetConversionFormat: no radio checked?" );
968 return HHC::eSimpleConversion;
971 //-------------------------------------------------------------------------
972 void HangulHanjaConversionDialog::EnableRubySupport( sal_Bool bVal )
974 m_pHanjaAbove->Enable( bVal );
975 m_pHanjaBelow->Enable( bVal );
976 m_pHangulAbove->Enable( bVal );
977 m_pHangulBelow->Enable( bVal );
981 //=========================================================================
982 //= HangulHanjaOptionsDialog
983 //=========================================================================
984 //-------------------------------------------------------------------------
986 void HangulHanjaOptionsDialog::Init( void )
988 if( !m_xConversionDictionaryList.is() )
990 Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
991 if( xMgr.is() )
993 m_xConversionDictionaryList = Reference< XConversionDictionaryList >( xMgr->createInstance(
994 OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.ConversionDictionaryList")) ),
995 UNO_QUERY );
999 m_aDictList.clear();
1000 m_aDictsLB.Clear();
1002 if( m_xConversionDictionaryList.is() )
1004 Reference< XNameContainer > xNameCont = m_xConversionDictionaryList->getDictionaryContainer();
1005 Reference< XNameAccess > xNameAccess = Reference< XNameAccess >( xNameCont, UNO_QUERY );
1006 if( xNameAccess.is() )
1008 Sequence< ::rtl::OUString > aDictNames( xNameAccess->getElementNames() );
1010 const ::rtl::OUString* pDic = aDictNames.getConstArray();
1011 sal_Int32 nCount = aDictNames.getLength();
1013 sal_Int32 i;
1014 for( i = 0 ; i < nCount ; ++i )
1016 Any aAny( xNameAccess->getByName( pDic[ i ] ) );
1017 Reference< XConversionDictionary > xDic;
1018 if( ( aAny >>= xDic ) && xDic.is() )
1020 if( LANGUAGE_KOREAN == SvxLocaleToLanguage( xDic->getLocale() ) )
1022 m_aDictList.push_back( xDic );
1023 AddDict( xDic->getName(), xDic->isActive() );
1031 IMPL_LINK( HangulHanjaOptionsDialog, OkHdl, void*, EMPTYARG )
1033 sal_uInt32 nCnt = m_aDictList.size();
1034 sal_uInt32 n = 0;
1035 sal_uInt32 nActiveDics = 0;
1036 Sequence< OUString > aActiveDics;
1038 aActiveDics.realloc( nCnt );
1039 OUString* pActActiveDic = aActiveDics.getArray();
1041 while( nCnt )
1043 Reference< XConversionDictionary > xDict = m_aDictList[ n ];
1044 SvLBoxEntry* pEntry = m_aDictsLB.SvTreeListBox::GetEntry( n );
1046 DBG_ASSERT( xDict.is(), "-HangulHanjaOptionsDialog::OkHdl(): someone is evaporated..." );
1047 DBG_ASSERT( pEntry, "-HangulHanjaOptionsDialog::OkHdl(): no one there in list?" );
1049 bool bActive = m_aDictsLB.GetCheckButtonState( pEntry ) == SV_BUTTON_CHECKED;
1050 xDict->setActive( bActive );
1051 Reference< util::XFlushable > xFlush( xDict, uno::UNO_QUERY );
1052 if( xFlush.is() )
1053 xFlush->flush();
1055 if( bActive )
1057 pActActiveDic[ nActiveDics ] = xDict->getName();
1058 ++nActiveDics;
1061 ++n;
1062 --nCnt;
1065 // save configuration
1066 aActiveDics.realloc( nActiveDics );
1067 Any aTmp;
1068 SvtLinguConfig aLngCfg;
1069 aTmp <<= aActiveDics;
1070 aLngCfg.SetProperty( UPH_ACTIVE_CONVERSION_DICTIONARIES, aTmp );
1072 aTmp <<= bool( m_aIgnorepostCB.IsChecked() );
1073 aLngCfg.SetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD, aTmp );
1075 aTmp <<= bool( m_aShowrecentlyfirstCB.IsChecked() );
1076 aLngCfg.SetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST, aTmp );
1078 aTmp <<= bool( m_aAutoreplaceuniqueCB.IsChecked() );
1079 aLngCfg.SetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES, aTmp );
1081 EndDialog( RET_OK );
1082 return 0;
1085 IMPL_LINK( HangulHanjaOptionsDialog, DictsLB_SelectHdl, void*, EMPTYARG )
1087 bool bSel = m_aDictsLB.FirstSelected() != NULL;
1089 m_aEditPB.Enable( bSel );
1090 m_aDeletePB.Enable( bSel );
1092 return 0;
1095 IMPL_LINK( HangulHanjaOptionsDialog, NewDictHdl, void*, EMPTYARG )
1097 String aName;
1098 HangulHanjaNewDictDialog aNewDlg( this );
1099 aNewDlg.Execute();
1100 if( aNewDlg.GetName( aName ) )
1102 if( m_xConversionDictionaryList.is() )
1106 Reference< XConversionDictionary > xDic =
1107 m_xConversionDictionaryList->addNewDictionary( aName, SvxCreateLocale( LANGUAGE_KOREAN ), ConversionDictionaryType::HANGUL_HANJA );
1109 if( xDic.is() )
1111 //adapt local caches:
1112 m_aDictList.push_back( xDic );
1113 AddDict( xDic->getName(), xDic->isActive() );
1116 catch( const ElementExistException& )
1119 catch( const NoSupportException& )
1125 return 0L;
1128 IMPL_LINK( HangulHanjaOptionsDialog, EditDictHdl, void*, EMPTYARG )
1130 SvLBoxEntry* pEntry = m_aDictsLB.FirstSelected();
1131 DBG_ASSERT( pEntry, "+HangulHanjaEditDictDialog::EditDictHdl(): call of edit should not be possible with no selection!" );
1132 if( pEntry )
1134 HangulHanjaEditDictDialog aEdDlg( this, m_aDictList, m_aDictsLB.GetSelectEntryPos() );
1135 aEdDlg.Execute();
1137 return 0L;
1140 IMPL_LINK( HangulHanjaOptionsDialog, DeleteDictHdl, void*, EMPTYARG )
1142 USHORT nSelPos = m_aDictsLB.GetSelectEntryPos();
1143 if( nSelPos != LISTBOX_ENTRY_NOTFOUND )
1145 Reference< XConversionDictionary > xDic( m_aDictList[ nSelPos ] );
1146 if( m_xConversionDictionaryList.is() && xDic.is() )
1148 Reference< XNameContainer > xNameCont = m_xConversionDictionaryList->getDictionaryContainer();
1149 if( xNameCont.is() )
1153 xNameCont->removeByName( xDic->getName() );
1155 //adapt local caches:
1156 HHDictList::iterator aIter(m_aDictList.begin());
1157 m_aDictList.erase(aIter+nSelPos );
1158 m_aDictsLB.RemoveEntry( nSelPos );
1160 catch( const ElementExistException& )
1163 catch( const NoSupportException& )
1170 return 0L;
1173 HangulHanjaOptionsDialog::HangulHanjaOptionsDialog( Window* _pParent )
1174 :ModalDialog ( _pParent, SVX_RES( RID_SVX_MDLG_HANGULHANJA_OPT ) )
1175 ,m_aUserdefdictFT ( this, SVX_RES( FT_USERDEFDICT ) )
1176 ,m_aDictsLB ( this, SVX_RES( LB_DICTS ) )
1177 ,m_aOptionsFL ( this, SVX_RES( FL_OPTIONS ) )
1178 ,m_aIgnorepostCB ( this, SVX_RES( CB_IGNOREPOST ) )
1179 ,m_aShowrecentlyfirstCB ( this, SVX_RES( CB_SHOWRECENTLYFIRST ) )
1180 ,m_aAutoreplaceuniqueCB ( this, SVX_RES( CB_AUTOREPLACEUNIQUE ) )
1181 ,m_aNewPB ( this, SVX_RES( PB_HHO_NEW ) )
1182 ,m_aEditPB ( this, SVX_RES( PB_HHO_EDIT ) )
1183 ,m_aDeletePB ( this, SVX_RES( PB_HHO_DELETE ) )
1184 ,m_aOkPB ( this, SVX_RES( PB_HHO_OK ) )
1185 ,m_aCancelPB ( this, SVX_RES( PB_HHO_CANCEL ) )
1186 ,m_aHelpPB ( this, SVX_RES( PB_HHO_HELP ) )
1188 ,m_pCheckButtonData ( NULL )
1189 ,m_xConversionDictionaryList( NULL )
1191 m_aDictsLB.SetWindowBits( WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE );
1192 m_aDictsLB.SetSelectionMode( SINGLE_SELECTION );
1193 m_aDictsLB.SetHighlightRange();
1194 // m_aDictsLB.SetHelpId( xxx );
1195 m_aDictsLB.SetSelectHdl( LINK( this, HangulHanjaOptionsDialog, DictsLB_SelectHdl ) );
1196 m_aDictsLB.SetDeselectHdl( LINK( this, HangulHanjaOptionsDialog, DictsLB_SelectHdl ) );
1198 m_aOkPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, OkHdl ) );
1199 m_aNewPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, NewDictHdl ) );
1200 m_aEditPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, EditDictHdl ) );
1201 m_aDeletePB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, DeleteDictHdl ) );
1203 FreeResource();
1205 SvtLinguConfig aLngCfg;
1206 Any aTmp;
1207 bool bVal = bool();
1208 aTmp = aLngCfg.GetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD );
1209 if( aTmp >>= bVal )
1210 m_aIgnorepostCB.Check( bVal );
1212 aTmp = aLngCfg.GetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST );
1213 if( aTmp >>= bVal )
1214 m_aShowrecentlyfirstCB.Check( bVal );
1216 aTmp = aLngCfg.GetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES );
1217 if( aTmp >>= bVal )
1218 m_aAutoreplaceuniqueCB.Check( bVal );
1220 Init();
1223 HangulHanjaOptionsDialog::~HangulHanjaOptionsDialog()
1225 SvLBoxEntry* pEntry = m_aDictsLB.First();
1226 String* pDel;
1227 while( pEntry )
1229 pDel = ( String* ) pEntry->GetUserData();
1230 if( pDel )
1231 delete pDel;
1232 pEntry = m_aDictsLB.Next( pEntry );
1235 if( m_pCheckButtonData )
1236 delete m_pCheckButtonData;
1239 void HangulHanjaOptionsDialog::AddDict( const String& _rName, bool _bChecked )
1241 SvLBoxEntry* pEntry = m_aDictsLB.SvTreeListBox::InsertEntry( _rName );
1242 m_aDictsLB.SetCheckButtonState( pEntry, _bChecked? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
1243 pEntry->SetUserData( new String( _rName ) );
1246 //=========================================================================
1247 //= HangulHanjaNewDictDialog
1248 //=========================================================================
1249 //-------------------------------------------------------------------------
1251 IMPL_LINK( HangulHanjaNewDictDialog, OKHdl, void*, EMPTYARG )
1253 String aName( m_aDictNameED.GetText() );
1255 aName.EraseTrailingChars();
1256 m_bEntered = aName.Len() > 0;
1257 if( m_bEntered )
1258 m_aDictNameED.SetText( aName ); // do this in case of trailing chars have been deleted
1260 EndDialog( RET_OK );
1261 return 0;
1264 IMPL_LINK( HangulHanjaNewDictDialog, ModifyHdl, void*, EMPTYARG )
1266 String aName( m_aDictNameED.GetText() );
1268 aName.EraseTrailingChars();
1269 m_aOkBtn.Enable( aName.Len() > 0 );
1271 return 0;
1274 HangulHanjaNewDictDialog::HangulHanjaNewDictDialog( Window* _pParent )
1275 :ModalDialog ( _pParent, SVX_RES( RID_SVX_MDLG_HANGULHANJA_NEWDICT ) )
1276 ,m_aNewDictFL ( this, SVX_RES( FL_NEWDICT ) )
1277 ,m_aDictNameFT ( this, SVX_RES( FT_DICTNAME ) )
1278 ,m_aDictNameED ( this, SVX_RES( ED_DICTNAME ) )
1279 ,m_aOkBtn ( this, SVX_RES( PB_NEWDICT_OK ) )
1280 ,m_aCancelBtn ( this, SVX_RES( PB_NEWDICT_ESC ) )
1281 ,m_aHelpBtn ( this, SVX_RES( PB_NEWDICT_HLP ) )
1283 ,m_bEntered ( false )
1285 m_aOkBtn.SetClickHdl( LINK( this, HangulHanjaNewDictDialog, OKHdl ) );
1287 m_aDictNameED.SetModifyHdl( LINK( this, HangulHanjaNewDictDialog, ModifyHdl ) );
1289 FreeResource();
1292 HangulHanjaNewDictDialog::~HangulHanjaNewDictDialog()
1296 bool HangulHanjaNewDictDialog::GetName( String& _rRetName ) const
1298 if( m_bEntered )
1300 _rRetName = m_aDictNameED.GetText();
1301 _rRetName.EraseTrailingChars();
1304 return m_bEntered;
1307 //=========================================================================
1308 //= HangulHanjaEditDictDialog
1309 //=========================================================================
1310 //-------------------------------------------------------------------------
1312 class SuggestionList
1314 private:
1315 protected:
1316 sal_uInt16 m_nSize;
1317 String** m_ppElements;
1318 sal_uInt16 m_nNumOfEntries;
1319 sal_uInt16 m_nAct;
1321 const String* _Next( void );
1322 public:
1323 SuggestionList( sal_uInt16 _nNumOfElements );
1324 virtual ~SuggestionList();
1326 bool Set( const String& _rElement, sal_uInt16 _nNumOfElement );
1327 bool Reset( sal_uInt16 _nNumOfElement );
1328 const String* Get( sal_uInt16 _nNumOfElement ) const;
1329 void Clear( void );
1331 const String* First( void );
1332 const String* Next( void );
1334 inline sal_uInt16 GetCount( void ) const;
1337 inline sal_uInt16 SuggestionList::GetCount( void ) const
1339 return m_nNumOfEntries;
1342 SuggestionList::SuggestionList( sal_uInt16 _nNumOfElements )
1344 if( !_nNumOfElements )
1345 _nNumOfElements = 1;
1347 m_nSize = _nNumOfElements;
1349 m_ppElements = new String*[ m_nSize ];
1350 m_nAct = m_nNumOfEntries = 0;
1352 String** ppNull = m_ppElements;
1353 sal_uInt16 n = _nNumOfElements;
1354 while( n )
1356 *ppNull = NULL;
1357 ++ppNull;
1358 --n;
1362 SuggestionList::~SuggestionList()
1364 Clear();
1367 bool SuggestionList::Set( const String& _rElement, sal_uInt16 _nNumOfElement )
1369 bool bRet = _nNumOfElement < m_nSize;
1370 if( bRet )
1372 String** ppElem = m_ppElements + _nNumOfElement;
1373 if( *ppElem )
1374 **ppElem = _rElement;
1375 else
1377 *ppElem = new String( _rElement );
1378 ++m_nNumOfEntries;
1382 return bRet;
1385 bool SuggestionList::Reset( sal_uInt16 _nNumOfElement )
1387 bool bRet = _nNumOfElement < m_nSize;
1388 if( bRet )
1390 String** ppElem = m_ppElements + _nNumOfElement;
1391 if( *ppElem )
1393 delete *ppElem;
1394 *ppElem = NULL;
1395 --m_nNumOfEntries;
1399 return bRet;
1402 const String* SuggestionList::Get( sal_uInt16 _nNumOfElement ) const
1404 const String* pRet;
1406 if( _nNumOfElement < m_nSize )
1407 pRet = m_ppElements[ _nNumOfElement ];
1408 else
1409 pRet = NULL;
1411 return pRet;
1414 void SuggestionList::Clear( void )
1416 if( m_nNumOfEntries )
1418 String** ppDel = m_ppElements;
1419 sal_uInt16 nCnt = m_nSize;
1420 while( nCnt )
1422 if( *ppDel )
1424 delete *ppDel;
1425 *ppDel = NULL;
1428 ++ppDel;
1429 --nCnt;
1432 m_nNumOfEntries = m_nAct = 0;
1436 const String* SuggestionList::_Next( void )
1438 const String* pRet = NULL;
1439 while( m_nAct < m_nSize && !pRet )
1441 pRet = m_ppElements[ m_nAct ];
1442 if( !pRet )
1443 ++m_nAct;
1446 return pRet;
1449 const String* SuggestionList::First( void )
1451 m_nAct = 0;
1452 return _Next();
1455 const String* SuggestionList::Next( void )
1457 const String* pRet;
1459 if( m_nAct < m_nNumOfEntries )
1461 ++m_nAct;
1462 pRet = _Next();
1464 else
1465 pRet = NULL;
1467 return pRet;
1471 bool SuggestionEdit::ShouldScroll( bool _bUp ) const
1473 bool bRet = false;
1475 if( _bUp )
1477 if( !m_pPrev )
1478 bRet = m_rScrollBar.GetThumbPos() > m_rScrollBar.GetRangeMin();
1480 else
1482 if( !m_pNext )
1483 bRet = m_rScrollBar.GetThumbPos() < ( m_rScrollBar.GetRangeMax() - 4 );
1486 return bRet;
1489 void SuggestionEdit::DoJump( bool _bUp )
1491 const Link& rLoseFocusHdl = GetLoseFocusHdl();
1492 if( rLoseFocusHdl.IsSet() )
1493 rLoseFocusHdl.Call( this );
1494 m_rScrollBar.SetThumbPos( m_rScrollBar.GetThumbPos() + ( _bUp? -1 : 1 ) );
1496 ( static_cast< HangulHanjaEditDictDialog* >( GetParent() ) )->UpdateScrollbar();
1499 SuggestionEdit::SuggestionEdit( Window* pParent, const ResId& rResId,
1500 ScrollBar& _rScrollBar, SuggestionEdit* _pPrev, SuggestionEdit* _pNext )
1501 :Edit( pParent, rResId )
1502 ,m_pPrev( _pPrev )
1503 ,m_pNext( _pNext )
1504 ,m_rScrollBar( _rScrollBar )
1508 SuggestionEdit::~SuggestionEdit()
1512 long SuggestionEdit::PreNotify( NotifyEvent& rNEvt )
1514 long nHandled = 0;
1515 if( rNEvt.GetType() == EVENT_KEYINPUT )
1517 const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1518 const KeyCode& rKeyCode = pKEvt->GetKeyCode();
1519 USHORT nMod = rKeyCode.GetModifier();
1520 USHORT nCode = rKeyCode.GetCode();
1521 if( nCode == KEY_TAB && ( !nMod || KEY_SHIFT == nMod ) )
1523 bool bUp = KEY_SHIFT == nMod;
1524 if( ShouldScroll( bUp ) )
1526 DoJump( bUp );
1527 SetSelection( Selection( 0, SELECTION_MAX ) );
1528 // Tab-travel doesn't really happen, so emulate it by setting a selection manually
1529 nHandled = 1;
1532 else if( KEY_UP == nCode || KEY_DOWN == nCode )
1534 bool bUp = KEY_UP == nCode;
1535 if( ShouldScroll( bUp ) )
1537 DoJump( bUp );
1538 nHandled = 1;
1540 else if( bUp )
1542 if( m_pPrev )
1544 m_pPrev->GrabFocus();
1545 nHandled = 1;
1548 else if( m_pNext )
1550 m_pNext->GrabFocus();
1551 nHandled = 1;
1556 if( !nHandled )
1557 nHandled = Edit::PreNotify( rNEvt );
1558 return nHandled;
1562 namespace
1564 bool GetConversions( Reference< XConversionDictionary > _xDict,
1565 const OUString& _rOrg,
1566 Sequence< OUString >& _rEntries )
1568 bool bRet = false;
1569 if( _xDict.is() && _rOrg.getLength() )
1573 _rEntries = _xDict->getConversions( _rOrg,
1575 _rOrg.getLength(),
1576 ConversionDirection_FROM_LEFT,
1577 ::com::sun::star::i18n::TextConversionOption::NONE );
1578 bRet = _rEntries.getLength() > 0;
1580 catch( const IllegalArgumentException& )
1585 return bRet;
1590 IMPL_LINK( HangulHanjaEditDictDialog, ScrollHdl, void*, EMPTYARG )
1592 UpdateScrollbar();
1594 return 0;
1597 IMPL_LINK( HangulHanjaEditDictDialog, OriginalModifyHdl, void*, EMPTYARG )
1599 m_bModifiedOriginal = true;
1600 m_aOriginal = m_aOriginalLB.GetText();
1601 m_aOriginal.EraseTrailingChars();
1603 UpdateSuggestions();
1604 UpdateButtonStates();
1606 return 0;
1609 IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl1, Edit*, pEdit )
1611 EditModify( pEdit, 0 );
1612 return 0;
1615 IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl2, Edit*, pEdit )
1617 EditModify( pEdit, 1 );
1618 return 0;
1621 IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl3, Edit*, pEdit )
1623 EditModify( pEdit, 2 );
1624 return 0;
1627 IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl4, Edit*, pEdit )
1629 EditModify( pEdit, 3 );
1630 return 0;
1633 IMPL_LINK( HangulHanjaEditDictDialog, BookLBSelectHdl, void*, EMPTYARG )
1635 InitEditDictDialog( m_aBookLB.GetSelectEntryPos() );
1636 return 0;
1639 IMPL_LINK( HangulHanjaEditDictDialog, NewPBPushHdl, void*, EMPTYARG )
1641 DBG_ASSERT( m_pSuggestions, "-HangulHanjaEditDictDialog::NewPBPushHdl(): no suggestions... search in hell..." );
1642 Reference< XConversionDictionary > xDict = m_rDictList[ m_nCurrentDict ];
1643 if( xDict.is() && m_pSuggestions )
1645 //delete old entry
1646 bool bRemovedSomething = DeleteEntryFromDictionary( m_aOriginal, xDict );
1648 OUString aLeft( m_aOriginal );
1649 const String* pRight = m_pSuggestions->First();
1650 bool bAddedSomething = false;
1651 while( pRight )
1655 //add new entry
1656 xDict->addEntry( aLeft, *pRight );
1657 bAddedSomething = true;
1659 catch( const IllegalArgumentException& )
1662 catch( const ElementExistException& )
1666 pRight = m_pSuggestions->Next();
1669 if(bAddedSomething||bRemovedSomething)
1670 InitEditDictDialog( m_nCurrentDict );
1672 else
1674 DBG_WARNING( "+HangulHanjaEditDictDialog::NewPBPushHdl(): dictionary faded away..." );
1676 return 0;
1679 bool HangulHanjaEditDictDialog::DeleteEntryFromDictionary( const OUString&, const Reference< XConversionDictionary >& xDict )
1681 bool bRemovedSomething = false;
1682 if( xDict.is() )
1684 OUString aOrg( m_aOriginal );
1685 Sequence< OUString > aEntries;
1686 GetConversions( xDict, m_aOriginal, aEntries );
1688 sal_uInt32 n = aEntries.getLength();
1689 OUString* pEntry = aEntries.getArray();
1690 while( n )
1694 xDict->removeEntry( aOrg, *pEntry );
1695 bRemovedSomething = true;
1697 catch( const NoSuchElementException& )
1698 { // can not be...
1701 ++pEntry;
1702 --n;
1705 return bRemovedSomething;
1708 IMPL_LINK( HangulHanjaEditDictDialog, DeletePBPushHdl, void*, EMPTYARG )
1710 if( DeleteEntryFromDictionary( m_aOriginal, m_rDictList[ m_nCurrentDict ] ) )
1712 m_aOriginal.Erase();
1713 m_bModifiedOriginal = true;
1714 InitEditDictDialog( m_nCurrentDict );
1716 return 0;
1719 void HangulHanjaEditDictDialog::InitEditDictDialog( sal_uInt32 _nSelDict )
1721 if( m_pSuggestions )
1722 m_pSuggestions->Clear();
1724 if( m_nCurrentDict != _nSelDict )
1726 m_nCurrentDict = _nSelDict;
1727 m_aOriginal.Erase();
1728 m_bModifiedOriginal = true;
1731 UpdateOriginalLB();
1733 m_aOriginalLB.SetText( m_aOriginal.Len()? m_aOriginal : m_aEditHintText, Selection( 0, SELECTION_MAX ) );
1734 m_aOriginalLB.GrabFocus();
1736 UpdateSuggestions();
1737 UpdateButtonStates();
1740 void HangulHanjaEditDictDialog::UpdateOriginalLB( void )
1742 m_aOriginalLB.Clear();
1743 Reference< XConversionDictionary > xDict = m_rDictList[ m_nCurrentDict ];
1744 if( xDict.is() )
1746 Sequence< OUString > aEntries = xDict->getConversionEntries( ConversionDirection_FROM_LEFT );
1747 sal_uInt32 n = aEntries.getLength();
1748 OUString* pEntry = aEntries.getArray();
1749 while( n )
1751 m_aOriginalLB.InsertEntry( *pEntry );
1753 ++pEntry;
1754 --n;
1757 else
1759 DBG_WARNING( "+HangulHanjaEditDictDialog::UpdateOriginalLB(): dictionary faded away..." );
1763 void HangulHanjaEditDictDialog::UpdateButtonStates()
1765 bool bHaveValidOriginalString = m_aOriginal.Len() && m_aOriginal != m_aEditHintText;
1766 bool bNew = bHaveValidOriginalString && m_pSuggestions && m_pSuggestions->GetCount() > 0;
1767 bNew = bNew && (m_bModifiedSuggestions || m_bModifiedOriginal);
1769 m_aNewPB.Enable( bNew );
1770 m_aDeletePB.Enable( !m_bModifiedOriginal && bHaveValidOriginalString );
1773 void HangulHanjaEditDictDialog::UpdateSuggestions( void )
1775 Sequence< OUString > aEntries;
1776 bool bFound = GetConversions( m_rDictList[ m_nCurrentDict ], m_aOriginal, aEntries );
1777 if( bFound )
1779 m_bModifiedOriginal = false;
1781 if( m_pSuggestions )
1782 m_pSuggestions->Clear();
1784 //fill found entries into boxes
1785 sal_uInt32 nCnt = aEntries.getLength();
1786 sal_uInt32 n = 0;
1787 if( nCnt )
1789 if( !m_pSuggestions )
1790 m_pSuggestions = new SuggestionList( MAXNUM_SUGGESTIONS );
1792 const OUString* pSugg = aEntries.getConstArray();
1793 while( nCnt )
1795 m_pSuggestions->Set( pSugg[ n ], sal_uInt16( n ) );
1796 ++n;
1797 --nCnt;
1800 m_bModifiedSuggestions=false;
1803 m_aScrollSB.SetThumbPos( 0 );
1804 UpdateScrollbar(); // will force edits to be filled new
1807 void HangulHanjaEditDictDialog::SetEditText( Edit& _rEdit, sal_uInt16 _nEntryNum )
1809 String aStr;
1810 if( m_pSuggestions )
1812 const String* p = m_pSuggestions->Get( _nEntryNum );
1813 if( p )
1814 aStr = *p;
1817 _rEdit.SetText( aStr );
1820 void HangulHanjaEditDictDialog::EditModify( Edit* _pEdit, sal_uInt8 _nEntryOffset )
1822 m_bModifiedSuggestions = true;
1824 String aTxt( _pEdit->GetText() );
1825 sal_uInt16 nEntryNum = m_nTopPos + _nEntryOffset;
1826 if( aTxt.Len() == 0 )
1828 //reset suggestion
1829 if( m_pSuggestions )
1830 m_pSuggestions->Reset( nEntryNum );
1832 else
1834 //set suggestion
1835 if( !m_pSuggestions )
1836 m_pSuggestions = new SuggestionList( MAXNUM_SUGGESTIONS );
1837 m_pSuggestions->Set( aTxt, nEntryNum );
1840 UpdateButtonStates();
1843 HangulHanjaEditDictDialog::HangulHanjaEditDictDialog( Window* _pParent, HHDictList& _rDictList, sal_uInt32 _nSelDict )
1844 :ModalDialog ( _pParent, SVX_RES( RID_SVX_MDLG_HANGULHANJA_EDIT ) )
1845 ,m_aEditHintText ( SVX_RES( STR_EDITHINT ) )
1846 ,m_rDictList ( _rDictList )
1847 ,m_nCurrentDict ( 0xFFFFFFFF )
1848 ,m_pSuggestions ( NULL )
1849 ,m_aBookFT ( this, SVX_RES( FT_BOOK ) )
1850 ,m_aBookLB ( this, SVX_RES( LB_BOOK ) )
1851 ,m_aOriginalFT ( this, SVX_RES( FT_ORIGINAL ) )
1852 ,m_aOriginalLB ( this, SVX_RES( LB_ORIGINAL ) )
1853 ,m_aSuggestionsFT ( this, SVX_RES( FT_SUGGESTIONS ) )
1854 ,m_aEdit1 ( this, SVX_RES( ED_1 ), m_aScrollSB, NULL, &m_aEdit2 )
1855 ,m_aEdit2 ( this, SVX_RES( ED_2 ), m_aScrollSB, &m_aEdit1, &m_aEdit3 )
1856 ,m_aEdit3 ( this, SVX_RES( ED_3 ), m_aScrollSB, &m_aEdit2, &m_aEdit4 )
1857 ,m_aEdit4 ( this, SVX_RES( ED_4 ), m_aScrollSB, &m_aEdit3, NULL )
1858 ,m_aScrollSB ( this, SVX_RES( SB_SCROLL ) )
1859 ,m_aNewPB ( this, SVX_RES( PB_HHE_NEW ) )
1860 ,m_aDeletePB ( this, SVX_RES( PB_HHE_DELETE ) )
1861 ,m_aHelpPB ( this, SVX_RES( PB_HHE_HELP ) )
1862 ,m_aClosePB ( this, SVX_RES( PB_HHE_CLOSE ) )
1863 ,m_nTopPos ( 0 )
1864 ,m_bModifiedSuggestions ( false )
1865 ,m_bModifiedOriginal ( false )
1867 m_aOriginalLB.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, OriginalModifyHdl ) );
1869 m_aNewPB.SetClickHdl( LINK( this, HangulHanjaEditDictDialog, NewPBPushHdl ) );
1870 m_aNewPB.Enable( false );
1872 m_aDeletePB.SetClickHdl( LINK( this, HangulHanjaEditDictDialog, DeletePBPushHdl ) );
1874 m_aDeletePB.Enable( false );
1876 #if( MAXNUM_SUGGESTIONS <= 4 )
1877 #error number of suggestions should not under-run the value of 5
1878 #endif
1880 Link aScrLk( LINK( this, HangulHanjaEditDictDialog, ScrollHdl ) );
1881 m_aScrollSB.SetScrollHdl( aScrLk );
1882 m_aScrollSB.SetEndScrollHdl( aScrLk );
1883 m_aScrollSB.SetRangeMin( 0 );
1884 m_aScrollSB.SetRangeMax( MAXNUM_SUGGESTIONS );
1885 m_aScrollSB.SetPageSize( 4 ); // because we have 4 edits / page
1886 m_aScrollSB.SetVisibleSize( 4 );
1888 m_aEdit1.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl1 ) );
1889 m_aEdit2.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl2 ) );
1890 m_aEdit3.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl3 ) );
1891 m_aEdit4.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl4 ) );
1893 m_aBookLB.SetSelectHdl( LINK( this, HangulHanjaEditDictDialog, BookLBSelectHdl ) );
1894 sal_uInt32 nDictCnt = m_rDictList.size();
1895 for( sal_uInt32 n = 0 ; n < nDictCnt ; ++n )
1897 Reference< XConversionDictionary > xDic( m_rDictList[n] );
1898 String aName;
1899 if(xDic.is())
1900 aName = xDic->getName();
1901 m_aBookLB.InsertEntry( aName );
1903 m_aBookLB.SelectEntryPos( USHORT( _nSelDict ) );
1905 FreeResource();
1907 InitEditDictDialog( _nSelDict );
1910 HangulHanjaEditDictDialog::~HangulHanjaEditDictDialog()
1912 if( m_pSuggestions )
1913 delete m_pSuggestions;
1916 void HangulHanjaEditDictDialog::UpdateScrollbar( void )
1918 sal_uInt16 nPos = sal_uInt16( m_aScrollSB.GetThumbPos() );
1919 m_nTopPos = nPos;
1921 SetEditText( m_aEdit1, nPos++ );
1922 SetEditText( m_aEdit2, nPos++ );
1923 SetEditText( m_aEdit3, nPos++ );
1924 SetEditText( m_aEdit4, nPos );
1927 //.............................................................................
1928 } // namespace svx
1929 //.............................................................................