1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "hangulhanjadlg.hxx"
21 #include "hangulhanjadlg.hrc"
22 #include "commonlingui.hxx"
23 #include <dialmgr.hxx>
29 #include <vcl/controllayout.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <unotools/lingucfg.hxx>
32 #include <unotools/linguprops.hxx>
33 #include <com/sun/star/linguistic2/ConversionDictionaryType.hpp>
34 #include <com/sun/star/linguistic2/ConversionDirection.hpp>
35 #include <com/sun/star/linguistic2/ConversionDictionaryList.hpp>
36 #include <com/sun/star/i18n/TextConversionOption.hpp>
37 #include <com/sun/star/util/XFlushable.hpp>
39 #include <comphelper/processfactory.hxx>
40 #include <comphelper/string.hxx>
41 #include "svtools/treelistentry.hxx"
43 #define HHC editeng::HangulHanjaConversion
44 #define LINE_CNT static_cast< sal_uInt16 >(2)
46 //.............................................................................
49 //.............................................................................
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::linguistic2
;
53 using namespace ::com::sun::star::lang
;
54 using namespace ::com::sun::star::container
;
56 //-------------------------------------------------------------------------
65 inline FontSwitch( OutputDevice
& _rDev
, const Font
& _rTemporaryFont
)
68 m_rDev
.Push( PUSH_FONT
);
69 m_rDev
.SetFont( _rTemporaryFont
);
78 //=========================================================================
80 //=========================================================================
81 /** a class which allows to draw two texts in a pseudo-ruby way (which basically
82 means one text above or below the other, and a little bit smaller)
93 const String m_sPrimaryText
;
94 const String m_sSecondaryText
;
95 const RubyPosition m_ePosition
;
98 PseudoRubyText( const String
& _rPrimary
, const String
& _rSecondary
, const RubyPosition _ePosition
);
101 void Paint( OutputDevice
& _rDevice
, const Rectangle
& _rRect
, sal_uInt16 _nTextStyle
,
102 Rectangle
* _pPrimaryLocation
= NULL
, Rectangle
* _pSecondaryLocation
= NULL
,
103 ::vcl::ControlLayoutData
* _pLayoutData
= NULL
);
106 //-------------------------------------------------------------------------
107 PseudoRubyText::PseudoRubyText( const String
& _rPrimary
, const String
& _rSecondary
, const RubyPosition _ePosition
)
108 :m_sPrimaryText( _rPrimary
)
109 ,m_sSecondaryText( _rSecondary
)
110 ,m_ePosition( _ePosition
)
114 //-------------------------------------------------------------------------
115 void PseudoRubyText::Paint( OutputDevice
& _rDevice
, const Rectangle
& _rRect
, sal_uInt16 _nTextStyle
,
116 Rectangle
* _pPrimaryLocation
, Rectangle
* _pSecondaryLocation
, ::vcl::ControlLayoutData
* _pLayoutData
)
118 bool bLayoutOnly
= NULL
!= _pLayoutData
;
119 MetricVector
* pTextMetrics
= bLayoutOnly
? &_pLayoutData
->m_aUnicodeBoundRects
: NULL
;
120 OUString
* pDisplayText
= bLayoutOnly
? &_pLayoutData
->m_aDisplayText
: NULL
;
122 Size
aPlaygroundSize( _rRect
.GetSize() );
124 // the font for the secondary text:
125 Font
aSmallerFont( _rDevice
.GetFont() );
126 // heuristic: 80% of the original size
127 aSmallerFont
.SetHeight( (long)( 0.8 * aSmallerFont
.GetHeight() ) );
129 // let's calculate the size of our two texts
130 Rectangle aPrimaryRect
= _rDevice
.GetTextRect( _rRect
, m_sPrimaryText
, _nTextStyle
);
131 Rectangle aSecondaryRect
;
133 FontSwitch
aFontRestore( _rDevice
, aSmallerFont
);
134 aSecondaryRect
= _rDevice
.GetTextRect( _rRect
, m_sSecondaryText
, _nTextStyle
);
137 // position these rectangles properly
139 sal_Int32 nCombinedWidth
= ::std::max( aSecondaryRect
.GetWidth(), aPrimaryRect
.GetWidth() );
140 // the rectangle where both texts will reside is as high as possible, and as wide as the
141 // widest of both text rects
142 aPrimaryRect
.Left() = aSecondaryRect
.Left() = _rRect
.Left();
143 aPrimaryRect
.Right() = aSecondaryRect
.Right() = _rRect
.Left() + nCombinedWidth
;
144 if ( TEXT_DRAW_RIGHT
& _nTextStyle
)
146 // move the rectangles to the right
147 aPrimaryRect
.Move( aPlaygroundSize
.Width() - nCombinedWidth
, 0 );
148 aSecondaryRect
.Move( aPlaygroundSize
.Width() - nCombinedWidth
, 0 );
150 else if ( TEXT_DRAW_CENTER
& _nTextStyle
)
152 // center the rectangles
153 aPrimaryRect
.Move( ( aPlaygroundSize
.Width() - nCombinedWidth
) / 2, 0 );
154 aSecondaryRect
.Move( ( aPlaygroundSize
.Width() - nCombinedWidth
) / 2, 0 );
158 sal_Int32 nCombinedHeight
= aPrimaryRect
.GetHeight() + aSecondaryRect
.GetHeight();
159 // align to the top, for the moment
160 aPrimaryRect
.Move( 0, _rRect
.Top() - aPrimaryRect
.Top() );
161 aSecondaryRect
.Move( 0, aPrimaryRect
.Top() + aPrimaryRect
.GetHeight() - aSecondaryRect
.Top() );
162 if ( TEXT_DRAW_BOTTOM
& _nTextStyle
)
164 // move the rects to the bottom
165 aPrimaryRect
.Move( 0, aPlaygroundSize
.Height() - nCombinedHeight
);
166 aSecondaryRect
.Move( 0, aPlaygroundSize
.Height() - nCombinedHeight
);
168 else if ( TEXT_DRAW_VCENTER
& _nTextStyle
)
170 // move the rects to the bottom
171 aPrimaryRect
.Move( 0, ( aPlaygroundSize
.Height() - nCombinedHeight
) / 2 );
172 aSecondaryRect
.Move( 0, ( aPlaygroundSize
.Height() - nCombinedHeight
) / 2 );
175 // 'til here, everything we did assumes that the secondary text is painted _below_ the primary
176 // text. If this isn't the case, we need to correct the rectangles
177 if ( eAbove
== m_ePosition
)
179 sal_Int32 nVertDistance
= aSecondaryRect
.Top() - aPrimaryRect
.Top();
180 aSecondaryRect
.Move( 0, -nVertDistance
);
181 aPrimaryRect
.Move( 0, nCombinedHeight
- nVertDistance
);
184 // now draw the texts
185 // as we already calculated the precise rectangles for the texts, we don't want to
186 // use the alignment flags given - within it's rect, every text is centered
187 sal_uInt16
nDrawTextStyle( _nTextStyle
);
188 nDrawTextStyle
&= ~( TEXT_DRAW_RIGHT
| TEXT_DRAW_LEFT
| TEXT_DRAW_BOTTOM
| TEXT_DRAW_TOP
);
189 nDrawTextStyle
|= TEXT_DRAW_CENTER
| TEXT_DRAW_VCENTER
;
191 _rDevice
.DrawText( aPrimaryRect
, m_sPrimaryText
, nDrawTextStyle
, pTextMetrics
, pDisplayText
);
193 FontSwitch
aFontRestore( _rDevice
, aSmallerFont
);
194 _rDevice
.DrawText( aSecondaryRect
, m_sSecondaryText
, nDrawTextStyle
, pTextMetrics
, pDisplayText
);
198 if ( _pPrimaryLocation
)
199 *_pPrimaryLocation
= aPrimaryRect
;
200 if ( _pSecondaryLocation
)
201 *_pSecondaryLocation
= aSecondaryRect
;
204 //=========================================================================
206 //=========================================================================
207 class RubyRadioButton
:public RadioButton
208 ,protected PseudoRubyText
210 using svx::PseudoRubyText::Paint
;
215 const ResId
& _rId
, // the text in the resource will be taken as primary text
216 const String
& _rSecondary
, // this will be the secondary text which will be printed somewhat smaller
217 const PseudoRubyText::RubyPosition _ePosition
);
220 virtual void Paint( const Rectangle
& _rRect
);
223 //-------------------------------------------------------------------------
224 RubyRadioButton::RubyRadioButton( Window
* _pParent
, const ResId
& _rId
,
225 const String
& _rSecondary
, const PseudoRubyText::RubyPosition _ePosition
)
226 :RadioButton( _pParent
, _rId
)
227 ,PseudoRubyText( RadioButton::GetText(), _rSecondary
, _ePosition
)
231 //-------------------------------------------------------------------------
232 void RubyRadioButton::Paint( const Rectangle
& )
236 // calculate the size of the radio image - we're to paint our text _after_ this image
237 DBG_ASSERT( !GetModeRadioImage(), "RubyRadioButton::Paint: images not supported!" );
238 Size aImageSize
= GetRadioImage( GetSettings(), 0 ).GetSizePixel();
239 aImageSize
.Width() = CalcZoom( aImageSize
.Width() );
240 aImageSize
.Height() = CalcZoom( aImageSize
.Height() );
242 Rectangle
aOverallRect( Point( 0, 0 ), GetOutputSizePixel() );
243 aOverallRect
.Left() += aImageSize
.Width() + 4; // 4 is the separator between the image and the text
244 // inflate the rect a little bit (because the VCL radio button does the same)
245 Rectangle
aTextRect( aOverallRect
);
246 ++aTextRect
.Left(); --aTextRect
.Right();
247 ++aTextRect
.Top(); --aTextRect
.Bottom();
249 // calculate the text flags for the painting
250 sal_uInt16 nTextStyle
= TEXT_DRAW_MNEMONIC
;
251 WinBits nStyle
= GetStyle( );
253 // the horizontal alignment
254 if ( nStyle
& WB_RIGHT
)
255 nTextStyle
|= TEXT_DRAW_RIGHT
;
256 else if ( nStyle
& WB_CENTER
)
257 nTextStyle
|= TEXT_DRAW_CENTER
;
259 nTextStyle
|= TEXT_DRAW_LEFT
;
260 // the vertical alignment
261 if ( nStyle
& WB_BOTTOM
)
262 nTextStyle
|= TEXT_DRAW_BOTTOM
;
263 else if ( nStyle
& WB_VCENTER
)
264 nTextStyle
|= TEXT_DRAW_VCENTER
;
266 nTextStyle
|= TEXT_DRAW_TOP
;
268 if ( 0 == ( nStyle
& WB_NOLABEL
) )
269 nTextStyle
|= TEXT_DRAW_MNEMONIC
;
271 // paint the ruby text
272 Rectangle aPrimaryTextLocation
, aSecondaryTextLocation
;
273 PseudoRubyText::Paint( *this, aTextRect
, nTextStyle
, &aPrimaryTextLocation
, &aSecondaryTextLocation
);
275 // the focus rectangle is to be painted around both texts
276 Rectangle
aCombinedRect( aPrimaryTextLocation
);
277 aCombinedRect
.Union( aSecondaryTextLocation
);
278 SetFocusRect( aCombinedRect
);
280 // let the base class paint the radio button
281 // for this, give it the proper location to paint the image (vertically centered, relative to our text)
282 Rectangle
aImageLocation( Point( 0, 0 ), aImageSize
);
283 sal_Int32 nTextHeight
= aSecondaryTextLocation
.Bottom() - aPrimaryTextLocation
.Top();
284 aImageLocation
.Top() = aPrimaryTextLocation
.Top() + ( nTextHeight
- aImageSize
.Height() ) / 2;
285 aImageLocation
.Bottom() = aImageLocation
.Top() + aImageSize
.Height();
286 SetStateRect( aImageLocation
);
287 DrawRadioButtonState( );
289 // mouse clicks should be recognized in a rect which is one pixel larger in each direction, plus
290 // includes the image
291 aCombinedRect
.Left() = aImageLocation
.Left(); ++aCombinedRect
.Right();
292 --aCombinedRect
.Top(); ++aCombinedRect
.Bottom();
293 SetMouseRect( aCombinedRect
);
295 // paint the focus rect, if necessary
297 ShowFocus( aTextRect
);
300 //=========================================================================
302 //=========================================================================
303 //-------------------------------------------------------------------------
305 SuggestionSet::SuggestionSet( Window
* pParent
)
306 : ValueSet( pParent
, pParent
->GetStyle() | WB_BORDER
)
311 SuggestionSet::~SuggestionSet()
316 void SuggestionSet::UserDraw( const UserDrawEvent
& rUDEvt
)
318 OutputDevice
* pDev
= rUDEvt
.GetDevice();
319 Rectangle aRect
= rUDEvt
.GetRect();
320 sal_uInt16 nItemId
= rUDEvt
.GetItemId();
322 String sText
= *static_cast< String
* >( GetItemData( nItemId
) );
323 pDev
->DrawText( aRect
, sText
, TEXT_DRAW_CENTER
| TEXT_DRAW_VCENTER
);
326 void SuggestionSet::ClearSet()
328 sal_uInt16 i
, nCount
= GetItemCount();
329 for ( i
= 0; i
< nCount
; ++i
)
330 delete static_cast< String
* >( GetItemData(i
) );
334 //=========================================================================
335 //= SuggestionDisplay
336 //=========================================================================
337 //-------------------------------------------------------------------------
339 SuggestionDisplay::SuggestionDisplay( Window
* pParent
, const ResId
& rResId
)
340 : Control( pParent
, rResId
)
341 , m_bDisplayListBox(true)
343 , m_aListBox(this,GetStyle() | WB_BORDER
)
344 , m_bInSelectionUpdate(false)
346 m_aValueSet
.SetSelectHdl( LINK( this, SuggestionDisplay
, SelectSuggestionHdl
) );
347 m_aListBox
.SetSelectHdl( LINK( this, SuggestionDisplay
, SelectSuggestionHdl
) );
349 m_aValueSet
.SetLineCount( LINE_CNT
);
350 m_aValueSet
.SetStyle( m_aValueSet
.GetStyle() | WB_ITEMBORDER
| WB_FLATVALUESET
| WB_VSCROLL
);
351 m_aValueSet
.SetBorderStyle( WINDOW_BORDER_MONO
);
352 String
aOneCharacter(RTL_CONSTASCII_USTRINGPARAM("AU"));
353 long nItemWidth
= 2*GetTextWidth( aOneCharacter
);
354 m_aValueSet
.SetItemWidth( nItemWidth
);
356 Size
aSize(GetSizePixel());
357 m_aValueSet
.SetSizePixel(aSize
);
358 m_aListBox
.SetSizePixel(aSize
);
363 SuggestionDisplay::~SuggestionDisplay()
367 void SuggestionDisplay::implUpdateDisplay()
369 bool bShowBox
= IsVisible() && m_bDisplayListBox
;
370 bool bShowSet
= IsVisible() && !m_bDisplayListBox
;
372 m_aListBox
.Show(bShowBox
);
373 m_aValueSet
.Show(bShowSet
);
376 void SuggestionDisplay::StateChanged( StateChangedType nStateChange
)
378 if( STATE_CHANGE_VISIBLE
== nStateChange
)
382 Control
& SuggestionDisplay::implGetCurrentControl()
384 if( m_bDisplayListBox
)
389 void SuggestionDisplay::KeyInput( const KeyEvent
& rKEvt
)
391 implGetCurrentControl().KeyInput( rKEvt
);
393 void SuggestionDisplay::KeyUp( const KeyEvent
& rKEvt
)
395 implGetCurrentControl().KeyUp( rKEvt
);
397 void SuggestionDisplay::Activate()
399 implGetCurrentControl().Activate();
401 void SuggestionDisplay::Deactivate()
403 implGetCurrentControl().Deactivate();
405 void SuggestionDisplay::GetFocus()
407 implGetCurrentControl().GetFocus();
409 void SuggestionDisplay::LoseFocus()
411 implGetCurrentControl().LoseFocus();
413 void SuggestionDisplay::Command( const CommandEvent
& rCEvt
)
415 implGetCurrentControl().Command( rCEvt
);
418 void SuggestionDisplay::DisplayListBox( bool bDisplayListBox
)
420 if( m_bDisplayListBox
!= bDisplayListBox
)
422 Control
& rOldControl
= implGetCurrentControl();
423 sal_Bool bHasFocus
= rOldControl
.HasFocus();
425 m_bDisplayListBox
= bDisplayListBox
;
429 Control
& rNewControl
= implGetCurrentControl();
430 rNewControl
.GrabFocus();
437 IMPL_LINK( SuggestionDisplay
, SelectSuggestionHdl
, Control
*, pControl
)
439 if( m_bInSelectionUpdate
)
442 m_bInSelectionUpdate
= true;
443 if(pControl
==&m_aListBox
)
445 sal_uInt16 nPos
= m_aListBox
.GetSelectEntryPos();
446 m_aValueSet
.SelectItem( nPos
+1 ); //itemid == pos+1 (id 0 has special meaning)
450 sal_uInt16 nPos
= m_aValueSet
.GetSelectItemId()-1; //itemid == pos+1 (id 0 has special meaning)
451 m_aListBox
.SelectEntryPos( nPos
);
453 m_bInSelectionUpdate
= false;
454 m_aSelectLink
.Call(this);
458 void SuggestionDisplay::SetSelectHdl( const Link
& rLink
)
460 m_aSelectLink
= rLink
;
462 void SuggestionDisplay::Clear()
467 void SuggestionDisplay::InsertEntry( const XubString
& rStr
)
469 sal_uInt16 nItemId
= m_aListBox
.InsertEntry( rStr
) + 1; //itemid == pos+1 (id 0 has special meaning)
470 m_aValueSet
.InsertItem( nItemId
);
471 String
* pItemData
= new String(rStr
);
472 m_aValueSet
.SetItemData( nItemId
, pItemData
);
474 void SuggestionDisplay::SelectEntryPos( sal_uInt16 nPos
)
476 m_aListBox
.SelectEntryPos( nPos
);
477 m_aValueSet
.SelectItem( nPos
+1 ); //itemid == pos+1 (id 0 has special meaning)
479 sal_uInt16
SuggestionDisplay::GetEntryCount() const
481 return m_aListBox
.GetEntryCount();
483 XubString
SuggestionDisplay::GetEntry( sal_uInt16 nPos
) const
485 return m_aListBox
.GetEntry( nPos
);
487 XubString
SuggestionDisplay::GetSelectEntry() const
489 return m_aListBox
.GetSelectEntry();
491 void SuggestionDisplay::SetHelpIds()
493 this->SetHelpId( HID_HANGULDLG_SUGGESTIONS
);
494 m_aValueSet
.SetHelpId( HID_HANGULDLG_SUGGESTIONS_GRID
);
495 m_aListBox
.SetHelpId( HID_HANGULDLG_SUGGESTIONS_LIST
);
498 //=========================================================================
499 //= HangulHanjaConversionDialog
500 //=========================================================================
501 //-------------------------------------------------------------------------
502 HangulHanjaConversionDialog::HangulHanjaConversionDialog( Window
* _pParent
, HHC::ConversionDirection _ePrimaryDirection
)
503 :ModalDialog( _pParent
, CUI_RES( RID_SVX_MDLG_HANGULHANJA
) )
504 ,m_pPlayground( new SvxCommonLinguisticControl( this ) )
505 ,m_aFind ( m_pPlayground
.get(), CUI_RES( PB_FIND
) )
506 ,m_aSuggestions ( m_pPlayground
.get(), CUI_RES( CTL_SUGGESTIONS
) )
507 ,m_aFormat ( m_pPlayground
.get(), CUI_RES( FT_FORMAT
) )
508 ,m_aSimpleConversion( m_pPlayground
.get(), CUI_RES( RB_SIMPLE_CONVERSION
) )
509 ,m_aHangulBracketed ( m_pPlayground
.get(), CUI_RES( RB_HANJA_HANGUL_BRACKETED
) )
510 ,m_aHanjaBracketed ( m_pPlayground
.get(), CUI_RES( RB_HANGUL_HANJA_BRACKETED
) )
511 ,m_aConversion ( m_pPlayground
.get(), CUI_RES( FT_CONVERSION
) )
512 ,m_aHangulOnly ( m_pPlayground
.get(), CUI_RES( CB_HANGUL_ONLY
) )
513 ,m_aHanjaOnly ( m_pPlayground
.get(), CUI_RES( CB_HANJA_ONLY
) )
514 ,m_aReplaceByChar ( m_pPlayground
.get(), CUI_RES( CB_REPLACE_BY_CHARACTER
) )
515 ,m_pIgnoreNonPrimary( NULL
)
516 ,m_bDocumentMode( true )
518 // special creation of the 4 pseudo-ruby radio buttons
519 String
sSecondaryHangul( CUI_RES( STR_HANGUL
) );
520 String
sSecondaryHanja( CUI_RES( STR_HANJA
) );
521 m_pHanjaAbove
.reset( new RubyRadioButton( m_pPlayground
.get(), CUI_RES( RB_HANGUL_HANJA_ABOVE
), sSecondaryHanja
, PseudoRubyText::eAbove
) );
522 m_pHanjaBelow
.reset( new RubyRadioButton( m_pPlayground
.get(), CUI_RES( RB_HANGUL_HANJA_BELOW
), sSecondaryHanja
, PseudoRubyText::eBelow
) );
523 m_pHangulAbove
.reset( new RubyRadioButton( m_pPlayground
.get(), CUI_RES( RB_HANJA_HANGUL_ABOVE
), sSecondaryHangul
, PseudoRubyText::eAbove
) );
524 m_pHangulBelow
.reset( new RubyRadioButton( m_pPlayground
.get(), CUI_RES( RB_HANJA_HANGUL_BELOW
), sSecondaryHangul
, PseudoRubyText::eBelow
) );
526 // since these 4 buttons are not created within the other members, they have a wrong initial Z-Order
528 m_pHanjaAbove
->SetZOrder( &m_aHanjaBracketed
, WINDOW_ZORDER_BEHIND
);
529 m_pHanjaBelow
->SetZOrder( m_pHanjaAbove
.get(), WINDOW_ZORDER_BEHIND
);
530 m_pHangulAbove
->SetZOrder( m_pHanjaBelow
.get(), WINDOW_ZORDER_BEHIND
);
531 m_pHangulBelow
->SetZOrder( m_pHangulAbove
.get(), WINDOW_ZORDER_BEHIND
);
533 // VCL automatically sets the WB_GROUP bit, if the previous sibling (at the moment of creation)
534 // is no radion button
535 m_pHanjaAbove
->SetStyle( m_pHanjaAbove
->GetStyle() & ~WB_GROUP
);
537 // the "Find" button and the word input control may not have the proper distance/extensions
539 Point aDistance
= LogicToPixel( Point( 3, 0 ), MAP_APPFONT
);
540 sal_Int32 nTooLargeByPixels
=
541 // right margin of the word input control
542 ( m_pPlayground
->GetWordInputControl().GetPosPixel().X()
543 + m_pPlayground
->GetWordInputControl().GetSizePixel().Width()
545 // minus left margin of the find button
546 - m_aFind
.GetPosPixel().X()
547 // plus desired distance between the both
549 // make the word input control smaller
550 Size aSize
= m_pPlayground
->GetWordInputControl().GetSizePixel();
551 aSize
.Width() -= nTooLargeByPixels
;
552 m_pPlayground
->GetWordInputControl().SetSizePixel( aSize
);
554 // additionall, the playground is not wide enough (in it's default size)
555 sal_Int32 nEnlargeWidth
= 0;
557 FixedText
aBottomAnchor( m_pPlayground
.get(), CUI_RES( FT_RESIZE_ANCHOR
) );
558 Point aAnchorPos
= aBottomAnchor
.GetPosPixel();
560 nEnlargeWidth
= aAnchorPos
.X() - m_pPlayground
->GetActionButtonsLocation().X();
562 m_pPlayground
->Enlarge( nEnlargeWidth
, 0 );
564 // insert our controls into the z-order of the playground
565 m_pPlayground
->InsertControlGroup( m_aFind
, m_aFind
, SvxCommonLinguisticControl::eLeftRightWords
);
566 m_pPlayground
->InsertControlGroup( m_aSuggestions
, m_aHanjaOnly
, SvxCommonLinguisticControl::eSuggestionLabel
);
567 m_pPlayground
->InsertControlGroup( m_aReplaceByChar
, m_aReplaceByChar
, SvxCommonLinguisticControl::eActionButtons
);
569 m_pPlayground
->SetButtonHandler( SvxCommonLinguisticControl::eClose
, LINK( this, HangulHanjaConversionDialog
, OnClose
) );
570 m_pPlayground
->GetWordInputControl().SetModifyHdl( LINK( this, HangulHanjaConversionDialog
, OnSuggestionModified
) );
571 m_aSuggestions
.SetSelectHdl( LINK( this, HangulHanjaConversionDialog
, OnSuggestionSelected
) );
573 m_aReplaceByChar
.SetClickHdl( LINK( this, HangulHanjaConversionDialog
, ClickByCharacterHdl
) );
575 m_aHangulOnly
.SetClickHdl( LINK( this, HangulHanjaConversionDialog
, OnConversionDirectionClicked
) );
576 m_aHanjaOnly
.SetClickHdl( LINK( this, HangulHanjaConversionDialog
, OnConversionDirectionClicked
) );
578 m_pPlayground
->SetButtonHandler( SvxCommonLinguisticControl::eOptions
,
579 LINK( this, HangulHanjaConversionDialog
, OnOption
) );
580 m_pPlayground
->GetButton( SvxCommonLinguisticControl::eOptions
)->Show();
582 if ( editeng::HangulHanjaConversion::eHangulToHanja
== _ePrimaryDirection
)
584 m_pIgnoreNonPrimary
= &m_aHangulOnly
;
588 m_pIgnoreNonPrimary
= &m_aHanjaOnly
;
594 // initial control values
595 m_aSimpleConversion
.Check();
597 m_pPlayground
->GetButton(SvxCommonLinguisticControl::eClose
)->SetHelpId(HID_HANGULDLG_BUTTON_CLOSE
);
598 m_pPlayground
->GetButton(SvxCommonLinguisticControl::eIgnore
)->SetHelpId(HID_HANGULDLG_BUTTON_IGNORE
);
599 m_pPlayground
->GetButton(SvxCommonLinguisticControl::eIgnoreAll
)->SetHelpId(HID_HANGULDLG_BUTTON_IGNOREALL
);
600 m_pPlayground
->GetButton(SvxCommonLinguisticControl::eChange
)->SetHelpId(HID_HANGULDLG_BUTTON_CHANGE
);
601 m_pPlayground
->GetButton(SvxCommonLinguisticControl::eChangeAll
)->SetHelpId(HID_HANGULDLG_BUTTON_CHANGEALL
);
602 m_pPlayground
->GetButton(SvxCommonLinguisticControl::eOptions
)->SetHelpId(HID_HANGULDLG_BUTTON_OPTIONS
);
603 m_pPlayground
->GetWordInputControl().SetHelpId(HID_HANGULDLG_EDIT_NEWWORD
);
607 m_aSuggestions
.SetHelpIds();
610 //-------------------------------------------------------------------------
611 HangulHanjaConversionDialog::~HangulHanjaConversionDialog( )
615 //-------------------------------------------------------------------------
616 void HangulHanjaConversionDialog::FillSuggestions( const ::com::sun::star::uno::Sequence
< OUString
>& _rSuggestions
)
618 m_aSuggestions
.Clear();
620 const OUString
* pSuggestions
= _rSuggestions
.getConstArray();
621 const OUString
* pSuggestionsEnd
= _rSuggestions
.getConstArray() + _rSuggestions
.getLength();
622 while ( pSuggestions
!= pSuggestionsEnd
)
623 m_aSuggestions
.InsertEntry( *pSuggestions
++ );
625 // select the first suggestion, and fill in the suggestion edit field
626 String sFirstSuggestion
;
627 if ( m_aSuggestions
.GetEntryCount() )
629 sFirstSuggestion
= m_aSuggestions
.GetEntry( 0 );
630 m_aSuggestions
.SelectEntryPos( 0 );
632 m_pPlayground
->GetWordInputControl().SetText( sFirstSuggestion
);
633 m_pPlayground
->GetWordInputControl().SaveValue();
634 OnSuggestionModified( &m_pPlayground
->GetWordInputControl() );
637 //-------------------------------------------------------------------------
638 void HangulHanjaConversionDialog::SetOptionsChangedHdl( const Link
& _rHdl
)
640 m_aOptionsChangedLink
= _rHdl
;
643 //-------------------------------------------------------------------------
644 void HangulHanjaConversionDialog::SetIgnoreHdl( const Link
& _rHdl
)
646 m_pPlayground
->SetButtonHandler( SvxCommonLinguisticControl::eIgnore
, _rHdl
);
649 //-------------------------------------------------------------------------
650 void HangulHanjaConversionDialog::SetIgnoreAllHdl( const Link
& _rHdl
)
652 m_pPlayground
->SetButtonHandler( SvxCommonLinguisticControl::eIgnoreAll
, _rHdl
);
655 //-------------------------------------------------------------------------
656 void HangulHanjaConversionDialog::SetChangeHdl( const Link
& _rHdl
)
658 m_pPlayground
->SetButtonHandler( SvxCommonLinguisticControl::eChange
, _rHdl
);
661 //-------------------------------------------------------------------------
662 void HangulHanjaConversionDialog::SetChangeAllHdl( const Link
& _rHdl
)
664 m_pPlayground
->SetButtonHandler( SvxCommonLinguisticControl::eChangeAll
, _rHdl
);
667 //-------------------------------------------------------------------------
668 void HangulHanjaConversionDialog::SetFindHdl( const Link
& _rHdl
)
670 m_aFind
.SetClickHdl( _rHdl
);
673 //-------------------------------------------------------------------------
674 void HangulHanjaConversionDialog::SetConversionFormatChangedHdl( const Link
& _rHdl
)
676 m_aSimpleConversion
.SetClickHdl( _rHdl
);
677 m_aHangulBracketed
.SetClickHdl( _rHdl
);
678 m_aHanjaBracketed
.SetClickHdl( _rHdl
);
679 m_pHanjaAbove
->SetClickHdl( _rHdl
);
680 m_pHanjaBelow
->SetClickHdl( _rHdl
);
681 m_pHangulAbove
->SetClickHdl( _rHdl
);
682 m_pHangulBelow
->SetClickHdl( _rHdl
);
685 //-------------------------------------------------------------------------
686 void HangulHanjaConversionDialog::SetClickByCharacterHdl( const Link
& _rHdl
)
688 m_aClickByCharacterLink
= _rHdl
;
691 //-------------------------------------------------------------------------
692 IMPL_LINK_NOARG(HangulHanjaConversionDialog
, OnSuggestionSelected
)
694 m_pPlayground
->GetWordInputControl().SetText( m_aSuggestions
.GetSelectEntry() );
695 OnSuggestionModified( NULL
);
699 //-------------------------------------------------------------------------
700 IMPL_LINK_NOARG(HangulHanjaConversionDialog
, OnSuggestionModified
)
702 m_aFind
.Enable( m_pPlayground
->GetWordInputControl().GetSavedValue() != m_pPlayground
->GetWordInputControl().GetText() );
704 bool bSameLen
= m_pPlayground
->GetWordInputControl().GetText().getLength() == m_pPlayground
->GetCurrentText().Len();
705 m_pPlayground
->EnableButton( SvxCommonLinguisticControl::eChange
, m_bDocumentMode
&& bSameLen
);
706 m_pPlayground
->EnableButton( SvxCommonLinguisticControl::eChangeAll
, m_bDocumentMode
&& bSameLen
);
711 //-------------------------------------------------------------------------
712 IMPL_LINK( HangulHanjaConversionDialog
, ClickByCharacterHdl
, CheckBox
*, pBox
)
714 m_aClickByCharacterLink
.Call(pBox
);
716 bool bByCharacter
= pBox
->IsChecked();
717 m_aSuggestions
.DisplayListBox( !bByCharacter
);
722 //-------------------------------------------------------------------------
723 IMPL_LINK( HangulHanjaConversionDialog
, OnConversionDirectionClicked
, CheckBox
*, pBox
)
725 CheckBox
*pOtherBox
= 0;
726 if (pBox
== &m_aHangulOnly
)
727 pOtherBox
= &m_aHanjaOnly
;
728 else if (pBox
== &m_aHanjaOnly
)
729 pOtherBox
= &m_aHangulOnly
;
730 if (pBox
&& pOtherBox
)
732 sal_Bool bBoxChecked
= pBox
->IsChecked();
734 pOtherBox
->Check( sal_False
);
735 pOtherBox
->Enable( !bBoxChecked
);
741 //-------------------------------------------------------------------------
742 IMPL_LINK_NOARG(HangulHanjaConversionDialog
, OnClose
)
748 IMPL_LINK_NOARG(HangulHanjaConversionDialog
, OnOption
)
750 HangulHanjaOptionsDialog
aOptDlg( this );
752 m_aOptionsChangedLink
.Call(this);
756 //-------------------------------------------------------------------------
757 String
HangulHanjaConversionDialog::GetCurrentString( ) const
759 return m_pPlayground
->GetCurrentText( );
762 //-------------------------------------------------------------------------
763 void HangulHanjaConversionDialog::FocusSuggestion( )
765 m_pPlayground
->GetWordInputControl().GrabFocus();
768 //-------------------------------------------------------------------------
771 void lcl_modifyWindowStyle( Window
* _pWin
, WinBits _nSet
, WinBits _nReset
)
773 DBG_ASSERT( 0 == ( _nSet
& _nReset
), "lcl_modifyWindowStyle: set _and_ reset the same bit?" );
775 _pWin
->SetStyle( ( _pWin
->GetStyle() | _nSet
) & ~_nReset
);
779 //-------------------------------------------------------------------------
780 void HangulHanjaConversionDialog::SetCurrentString( const String
& _rNewString
,
781 const Sequence
< OUString
>& _rSuggestions
, bool _bOriginatesFromDocument
)
783 m_pPlayground
->SetCurrentText( _rNewString
);
785 bool bOldDocumentMode
= m_bDocumentMode
;
786 m_bDocumentMode
= _bOriginatesFromDocument
; // before FillSuggestions!
787 FillSuggestions( _rSuggestions
);
789 m_pPlayground
->EnableButton( SvxCommonLinguisticControl::eIgnoreAll
, m_bDocumentMode
);
790 // all other buttons have been implicitly enabled or disabled during filling in the suggestions
792 // switch the def button depending if we're working for document text
793 if ( bOldDocumentMode
!= m_bDocumentMode
)
795 Window
* pOldDefButton
= NULL
;
796 Window
* pNewDefButton
= NULL
;
797 if ( m_bDocumentMode
)
799 pOldDefButton
= &m_aFind
;
800 pNewDefButton
= m_pPlayground
->GetButton( SvxCommonLinguisticControl::eChange
);
804 pOldDefButton
= m_pPlayground
->GetButton( SvxCommonLinguisticControl::eChange
);
805 pNewDefButton
= &m_aFind
;
808 DBG_ASSERT( WB_DEFBUTTON
== ( pOldDefButton
->GetStyle( ) & WB_DEFBUTTON
),
809 "HangulHanjaConversionDialog::SetCurrentString: wrong previous default button (1)!" );
810 DBG_ASSERT( 0 == ( pNewDefButton
->GetStyle( ) & WB_DEFBUTTON
),
811 "HangulHanjaConversionDialog::SetCurrentString: wrong previous default button (2)!" );
813 lcl_modifyWindowStyle( pOldDefButton
, 0, WB_DEFBUTTON
);
814 lcl_modifyWindowStyle( pNewDefButton
, WB_DEFBUTTON
, 0 );
816 // give the focus to the new def button temporarily - VCL is somewhat peculiar
817 // in recognizing a new default button
818 sal_uInt32 nSaveFocusId
= Window::SaveFocus();
819 pNewDefButton
->GrabFocus();
820 Window::EndSaveFocus( nSaveFocusId
);
824 //-------------------------------------------------------------------------
825 String
HangulHanjaConversionDialog::GetCurrentSuggestion( ) const
827 return m_pPlayground
->GetWordInputControl().GetText();
830 //-------------------------------------------------------------------------
831 void HangulHanjaConversionDialog::SetByCharacter( bool _bByCharacter
)
833 m_aReplaceByChar
.Check( static_cast<sal_Bool
>(_bByCharacter
) );
834 m_aSuggestions
.DisplayListBox( !_bByCharacter
);
837 //-------------------------------------------------------------------------
838 void HangulHanjaConversionDialog::SetConversionDirectionState(
839 bool _bTryBothDirections
,
840 HHC::ConversionDirection _ePrimaryConversionDirection
)
842 // default state: try both direction
843 m_aHangulOnly
.Check( sal_False
);
844 m_aHangulOnly
.Enable( sal_True
);
845 m_aHanjaOnly
.Check( sal_False
);
846 m_aHanjaOnly
.Enable( sal_True
);
848 if (!_bTryBothDirections
)
850 CheckBox
*pBox
= _ePrimaryConversionDirection
== HHC::eHangulToHanja
?
851 &m_aHangulOnly
: &m_aHanjaOnly
;
852 pBox
->Check( sal_True
);
853 OnConversionDirectionClicked( pBox
);
857 //-------------------------------------------------------------------------
858 bool HangulHanjaConversionDialog::GetUseBothDirections( ) const
860 return !m_aHangulOnly
.IsChecked() && !m_aHanjaOnly
.IsChecked();
863 //-------------------------------------------------------------------------
864 HHC::ConversionDirection
HangulHanjaConversionDialog::GetDirection(
865 HHC::ConversionDirection eDefaultDirection
) const
867 HHC::ConversionDirection eDirection
= eDefaultDirection
;
868 if (m_aHangulOnly
.IsChecked() && !m_aHanjaOnly
.IsChecked())
869 eDirection
= HHC::eHangulToHanja
;
870 else if (!m_aHangulOnly
.IsChecked() && m_aHanjaOnly
.IsChecked())
871 eDirection
= HHC::eHanjaToHangul
;
875 //-------------------------------------------------------------------------
876 void HangulHanjaConversionDialog::SetConversionFormat( HHC::ConversionFormat _eType
)
880 case HHC::eSimpleConversion
: m_aSimpleConversion
.Check(); break;
881 case HHC::eHangulBracketed
: m_aHangulBracketed
.Check(); break;
882 case HHC::eHanjaBracketed
: m_aHanjaBracketed
.Check(); break;
883 case HHC::eRubyHanjaAbove
: m_pHanjaAbove
->Check(); break;
884 case HHC::eRubyHanjaBelow
: m_pHanjaBelow
->Check(); break;
885 case HHC::eRubyHangulAbove
: m_pHangulAbove
->Check(); break;
886 case HHC::eRubyHangulBelow
: m_pHangulBelow
->Check(); break;
888 OSL_FAIL( "HangulHanjaConversionDialog::SetConversionFormat: unknown type!" );
892 //-------------------------------------------------------------------------
893 HHC::ConversionFormat
HangulHanjaConversionDialog::GetConversionFormat( ) const
895 if ( m_aSimpleConversion
.IsChecked() )
896 return HHC::eSimpleConversion
;
897 if ( m_aHangulBracketed
.IsChecked() )
898 return HHC::eHangulBracketed
;
899 if ( m_aHanjaBracketed
.IsChecked() )
900 return HHC::eHanjaBracketed
;
901 if ( m_pHanjaAbove
->IsChecked() )
902 return HHC::eRubyHanjaAbove
;
903 if ( m_pHanjaBelow
->IsChecked() )
904 return HHC::eRubyHanjaBelow
;
905 if ( m_pHangulAbove
->IsChecked() )
906 return HHC::eRubyHangulAbove
;
907 if ( m_pHangulBelow
->IsChecked() )
908 return HHC::eRubyHangulBelow
;
910 OSL_FAIL( "HangulHanjaConversionDialog::GetConversionFormat: no radio checked?" );
911 return HHC::eSimpleConversion
;
914 //-------------------------------------------------------------------------
915 void HangulHanjaConversionDialog::EnableRubySupport( bool bVal
)
917 m_pHanjaAbove
->Enable( bVal
);
918 m_pHanjaBelow
->Enable( bVal
);
919 m_pHangulAbove
->Enable( bVal
);
920 m_pHangulBelow
->Enable( bVal
);
924 //=========================================================================
925 //= HangulHanjaOptionsDialog
926 //=========================================================================
927 //-------------------------------------------------------------------------
929 void HangulHanjaOptionsDialog::Init( void )
931 if( !m_xConversionDictionaryList
.is() )
933 m_xConversionDictionaryList
= ConversionDictionaryList::create( ::comphelper::getProcessComponentContext() );
939 Reference
< XNameContainer
> xNameCont
= m_xConversionDictionaryList
->getDictionaryContainer();
940 Reference
< XNameAccess
> xNameAccess
= Reference
< XNameAccess
>( xNameCont
, UNO_QUERY
);
941 if( xNameAccess
.is() )
943 Sequence
< OUString
> aDictNames( xNameAccess
->getElementNames() );
945 const OUString
* pDic
= aDictNames
.getConstArray();
946 sal_Int32 nCount
= aDictNames
.getLength();
949 for( i
= 0 ; i
< nCount
; ++i
)
951 Any
aAny( xNameAccess
->getByName( pDic
[ i
] ) );
952 Reference
< XConversionDictionary
> xDic
;
953 if( ( aAny
>>= xDic
) && xDic
.is() )
955 if( LANGUAGE_KOREAN
== LanguageTag( xDic
->getLocale() ).getLanguageType() )
957 m_aDictList
.push_back( xDic
);
958 AddDict( xDic
->getName(), xDic
->isActive() );
965 IMPL_LINK_NOARG(HangulHanjaOptionsDialog
, OkHdl
)
967 sal_uInt32 nCnt
= m_aDictList
.size();
969 sal_uInt32 nActiveDics
= 0;
970 Sequence
< OUString
> aActiveDics
;
972 aActiveDics
.realloc( nCnt
);
973 OUString
* pActActiveDic
= aActiveDics
.getArray();
977 Reference
< XConversionDictionary
> xDict
= m_aDictList
[ n
];
978 SvTreeListEntry
* pEntry
= m_aDictsLB
.SvTreeListBox::GetEntry( n
);
980 DBG_ASSERT( xDict
.is(), "-HangulHanjaOptionsDialog::OkHdl(): someone is evaporated..." );
981 DBG_ASSERT( pEntry
, "-HangulHanjaOptionsDialog::OkHdl(): no one there in list?" );
983 bool bActive
= m_aDictsLB
.GetCheckButtonState( pEntry
) == SV_BUTTON_CHECKED
;
984 xDict
->setActive( bActive
);
985 Reference
< util::XFlushable
> xFlush( xDict
, uno::UNO_QUERY
);
991 pActActiveDic
[ nActiveDics
] = xDict
->getName();
999 // save configuration
1000 aActiveDics
.realloc( nActiveDics
);
1002 SvtLinguConfig aLngCfg
;
1003 aTmp
<<= aActiveDics
;
1004 aLngCfg
.SetProperty( UPH_ACTIVE_CONVERSION_DICTIONARIES
, aTmp
);
1006 aTmp
<<= bool( m_aIgnorepostCB
.IsChecked() );
1007 aLngCfg
.SetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD
, aTmp
);
1009 aTmp
<<= bool( m_aShowrecentlyfirstCB
.IsChecked() );
1010 aLngCfg
.SetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
, aTmp
);
1012 aTmp
<<= bool( m_aAutoreplaceuniqueCB
.IsChecked() );
1013 aLngCfg
.SetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
, aTmp
);
1015 EndDialog( RET_OK
);
1019 IMPL_LINK_NOARG(HangulHanjaOptionsDialog
, DictsLB_SelectHdl
)
1021 bool bSel
= m_aDictsLB
.FirstSelected() != NULL
;
1023 m_aEditPB
.Enable( bSel
);
1024 m_aDeletePB
.Enable( bSel
);
1029 IMPL_LINK_NOARG(HangulHanjaOptionsDialog
, NewDictHdl
)
1032 HangulHanjaNewDictDialog
aNewDlg( this );
1034 if( aNewDlg
.GetName( aName
) )
1036 if( m_xConversionDictionaryList
.is() )
1040 Reference
< XConversionDictionary
> xDic
=
1041 m_xConversionDictionaryList
->addNewDictionary( aName
, LanguageTag( LANGUAGE_KOREAN
).getLocale(), ConversionDictionaryType::HANGUL_HANJA
);
1045 //adapt local caches:
1046 m_aDictList
.push_back( xDic
);
1047 AddDict( xDic
->getName(), xDic
->isActive() );
1050 catch( const ElementExistException
& )
1053 catch( const NoSupportException
& )
1062 IMPL_LINK_NOARG(HangulHanjaOptionsDialog
, EditDictHdl
)
1064 SvTreeListEntry
* pEntry
= m_aDictsLB
.FirstSelected();
1065 DBG_ASSERT( pEntry
, "+HangulHanjaEditDictDialog::EditDictHdl(): call of edit should not be possible with no selection!" );
1068 HangulHanjaEditDictDialog
aEdDlg( this, m_aDictList
, m_aDictsLB
.GetSelectEntryPos() );
1074 IMPL_LINK_NOARG(HangulHanjaOptionsDialog
, DeleteDictHdl
)
1076 sal_uInt16 nSelPos
= m_aDictsLB
.GetSelectEntryPos();
1077 if( nSelPos
!= LISTBOX_ENTRY_NOTFOUND
)
1079 Reference
< XConversionDictionary
> xDic( m_aDictList
[ nSelPos
] );
1080 if( m_xConversionDictionaryList
.is() && xDic
.is() )
1082 Reference
< XNameContainer
> xNameCont
= m_xConversionDictionaryList
->getDictionaryContainer();
1083 if( xNameCont
.is() )
1087 xNameCont
->removeByName( xDic
->getName() );
1089 //adapt local caches:
1090 HHDictList::iterator
aIter(m_aDictList
.begin());
1091 m_aDictList
.erase(aIter
+nSelPos
);
1092 m_aDictsLB
.RemoveEntry( nSelPos
);
1094 catch( const ElementExistException
& )
1097 catch( const NoSupportException
& )
1107 HangulHanjaOptionsDialog::HangulHanjaOptionsDialog( Window
* _pParent
)
1108 :ModalDialog ( _pParent
, CUI_RES( RID_SVX_MDLG_HANGULHANJA_OPT
) )
1109 ,m_aUserdefdictFT ( this, CUI_RES( FT_USERDEFDICT
) )
1110 ,m_aDictsLB ( this, CUI_RES( LB_DICTS
) )
1111 ,m_aOptionsFL ( this, CUI_RES( FL_OPTIONS
) )
1112 ,m_aIgnorepostCB ( this, CUI_RES( CB_IGNOREPOST
) )
1113 ,m_aShowrecentlyfirstCB ( this, CUI_RES( CB_SHOWRECENTLYFIRST
) )
1114 ,m_aAutoreplaceuniqueCB ( this, CUI_RES( CB_AUTOREPLACEUNIQUE
) )
1115 ,m_aNewPB ( this, CUI_RES( PB_HHO_NEW
) )
1116 ,m_aEditPB ( this, CUI_RES( PB_HHO_EDIT
) )
1117 ,m_aDeletePB ( this, CUI_RES( PB_HHO_DELETE
) )
1118 ,m_aOkPB ( this, CUI_RES( PB_HHO_OK
) )
1119 ,m_aCancelPB ( this, CUI_RES( PB_HHO_CANCEL
) )
1120 ,m_aHelpPB ( this, CUI_RES( PB_HHO_HELP
) )
1122 ,m_pCheckButtonData ( NULL
)
1123 ,m_xConversionDictionaryList( NULL
)
1125 m_aDictsLB
.SetStyle( m_aDictsLB
.GetStyle() | WB_CLIPCHILDREN
| WB_HSCROLL
| WB_FORCE_MAKEVISIBLE
);
1126 m_aDictsLB
.SetSelectionMode( SINGLE_SELECTION
);
1127 m_aDictsLB
.SetHighlightRange();
1128 m_aDictsLB
.SetSelectHdl( LINK( this, HangulHanjaOptionsDialog
, DictsLB_SelectHdl
) );
1129 m_aDictsLB
.SetDeselectHdl( LINK( this, HangulHanjaOptionsDialog
, DictsLB_SelectHdl
) );
1131 m_aOkPB
.SetClickHdl( LINK( this, HangulHanjaOptionsDialog
, OkHdl
) );
1132 m_aNewPB
.SetClickHdl( LINK( this, HangulHanjaOptionsDialog
, NewDictHdl
) );
1133 m_aEditPB
.SetClickHdl( LINK( this, HangulHanjaOptionsDialog
, EditDictHdl
) );
1134 m_aDeletePB
.SetClickHdl( LINK( this, HangulHanjaOptionsDialog
, DeleteDictHdl
) );
1138 SvtLinguConfig aLngCfg
;
1141 aTmp
= aLngCfg
.GetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD
);
1143 m_aIgnorepostCB
.Check( bVal
);
1145 aTmp
= aLngCfg
.GetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
);
1147 m_aShowrecentlyfirstCB
.Check( bVal
);
1149 aTmp
= aLngCfg
.GetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
);
1151 m_aAutoreplaceuniqueCB
.Check( bVal
);
1156 HangulHanjaOptionsDialog::~HangulHanjaOptionsDialog()
1158 SvTreeListEntry
* pEntry
= m_aDictsLB
.First();
1162 pDel
= ( String
* ) pEntry
->GetUserData();
1165 pEntry
= m_aDictsLB
.Next( pEntry
);
1168 if( m_pCheckButtonData
)
1169 delete m_pCheckButtonData
;
1172 void HangulHanjaOptionsDialog::AddDict( const String
& _rName
, bool _bChecked
)
1174 SvTreeListEntry
* pEntry
= m_aDictsLB
.SvTreeListBox::InsertEntry( _rName
);
1175 m_aDictsLB
.SetCheckButtonState( pEntry
, _bChecked
? SV_BUTTON_CHECKED
: SV_BUTTON_UNCHECKED
);
1176 pEntry
->SetUserData( new String( _rName
) );
1179 //=========================================================================
1180 //= HangulHanjaNewDictDialog
1181 //=========================================================================
1182 //-------------------------------------------------------------------------
1184 IMPL_LINK_NOARG(HangulHanjaNewDictDialog
, OKHdl
)
1186 String
aName(comphelper::string::stripEnd(m_aDictNameED
.GetText(), ' '));
1188 m_bEntered
= aName
.Len() > 0;
1190 m_aDictNameED
.SetText( aName
); // do this in case of trailing chars have been deleted
1192 EndDialog( RET_OK
);
1196 IMPL_LINK_NOARG(HangulHanjaNewDictDialog
, ModifyHdl
)
1198 String
aName(comphelper::string::stripEnd(m_aDictNameED
.GetText(), ' '));
1200 m_aOkBtn
.Enable( aName
.Len() > 0 );
1205 HangulHanjaNewDictDialog::HangulHanjaNewDictDialog( Window
* _pParent
)
1206 :ModalDialog ( _pParent
, CUI_RES( RID_SVX_MDLG_HANGULHANJA_NEWDICT
) )
1207 ,m_aNewDictFL ( this, CUI_RES( FL_NEWDICT
) )
1208 ,m_aDictNameFT ( this, CUI_RES( FT_DICTNAME
) )
1209 ,m_aDictNameED ( this, CUI_RES( ED_DICTNAME
) )
1210 ,m_aOkBtn ( this, CUI_RES( PB_NEWDICT_OK
) )
1211 ,m_aCancelBtn ( this, CUI_RES( PB_NEWDICT_ESC
) )
1212 ,m_aHelpBtn ( this, CUI_RES( PB_NEWDICT_HLP
) )
1214 ,m_bEntered ( false )
1216 m_aOkBtn
.SetClickHdl( LINK( this, HangulHanjaNewDictDialog
, OKHdl
) );
1218 m_aDictNameED
.SetModifyHdl( LINK( this, HangulHanjaNewDictDialog
, ModifyHdl
) );
1223 HangulHanjaNewDictDialog::~HangulHanjaNewDictDialog()
1227 bool HangulHanjaNewDictDialog::GetName( String
& _rRetName
) const
1230 _rRetName
= comphelper::string::stripEnd(m_aDictNameED
.GetText(), ' ');
1235 //=========================================================================
1236 //= HangulHanjaEditDictDialog
1237 //=========================================================================
1238 //-------------------------------------------------------------------------
1240 class SuggestionList
1245 String
** m_ppElements
;
1246 sal_uInt16 m_nNumOfEntries
;
1249 const String
* _Next( void );
1251 SuggestionList( sal_uInt16 _nNumOfElements
);
1252 virtual ~SuggestionList();
1254 bool Set( const String
& _rElement
, sal_uInt16 _nNumOfElement
);
1255 bool Reset( sal_uInt16 _nNumOfElement
);
1256 const String
* Get( sal_uInt16 _nNumOfElement
) const;
1259 const String
* First( void );
1260 const String
* Next( void );
1262 inline sal_uInt16
GetCount( void ) const;
1265 inline sal_uInt16
SuggestionList::GetCount( void ) const
1267 return m_nNumOfEntries
;
1270 SuggestionList::SuggestionList( sal_uInt16 _nNumOfElements
)
1272 if( !_nNumOfElements
)
1273 _nNumOfElements
= 1;
1275 m_nSize
= _nNumOfElements
;
1277 m_ppElements
= new String
*[ m_nSize
];
1278 m_nAct
= m_nNumOfEntries
= 0;
1280 String
** ppNull
= m_ppElements
;
1281 sal_uInt16 n
= _nNumOfElements
;
1290 SuggestionList::~SuggestionList()
1293 delete[] m_ppElements
;
1296 bool SuggestionList::Set( const String
& _rElement
, sal_uInt16 _nNumOfElement
)
1298 bool bRet
= _nNumOfElement
< m_nSize
;
1301 String
** ppElem
= m_ppElements
+ _nNumOfElement
;
1303 **ppElem
= _rElement
;
1306 *ppElem
= new String( _rElement
);
1314 bool SuggestionList::Reset( sal_uInt16 _nNumOfElement
)
1316 bool bRet
= _nNumOfElement
< m_nSize
;
1319 String
** ppElem
= m_ppElements
+ _nNumOfElement
;
1331 const String
* SuggestionList::Get( sal_uInt16 _nNumOfElement
) const
1335 if( _nNumOfElement
< m_nSize
)
1336 pRet
= m_ppElements
[ _nNumOfElement
];
1343 void SuggestionList::Clear( void )
1345 if( m_nNumOfEntries
)
1347 String
** ppDel
= m_ppElements
;
1348 sal_uInt16 nCnt
= m_nSize
;
1361 m_nNumOfEntries
= m_nAct
= 0;
1365 const String
* SuggestionList::_Next( void )
1367 const String
* pRet
= NULL
;
1368 while( m_nAct
< m_nSize
&& !pRet
)
1370 pRet
= m_ppElements
[ m_nAct
];
1378 const String
* SuggestionList::First( void )
1384 const String
* SuggestionList::Next( void )
1388 if( m_nAct
< m_nNumOfEntries
)
1400 bool SuggestionEdit::ShouldScroll( bool _bUp
) const
1407 bRet
= m_rScrollBar
.GetThumbPos() > m_rScrollBar
.GetRangeMin();
1412 bRet
= m_rScrollBar
.GetThumbPos() < ( m_rScrollBar
.GetRangeMax() - 4 );
1418 void SuggestionEdit::DoJump( bool _bUp
)
1420 const Link
& rLoseFocusHdl
= GetLoseFocusHdl();
1421 if( rLoseFocusHdl
.IsSet() )
1422 rLoseFocusHdl
.Call( this );
1423 m_rScrollBar
.SetThumbPos( m_rScrollBar
.GetThumbPos() + ( _bUp
? -1 : 1 ) );
1425 ( static_cast< HangulHanjaEditDictDialog
* >( GetParentDialog() ) )->UpdateScrollbar();
1428 SuggestionEdit::SuggestionEdit( Window
* pParent
, const ResId
& rResId
,
1429 ScrollBar
& _rScrollBar
, SuggestionEdit
* _pPrev
, SuggestionEdit
* _pNext
)
1430 :Edit( pParent
, rResId
)
1433 ,m_rScrollBar( _rScrollBar
)
1437 SuggestionEdit::~SuggestionEdit()
1441 long SuggestionEdit::PreNotify( NotifyEvent
& rNEvt
)
1444 if( rNEvt
.GetType() == EVENT_KEYINPUT
)
1446 const KeyEvent
* pKEvt
= rNEvt
.GetKeyEvent();
1447 const KeyCode
& rKeyCode
= pKEvt
->GetKeyCode();
1448 sal_uInt16 nMod
= rKeyCode
.GetModifier();
1449 sal_uInt16 nCode
= rKeyCode
.GetCode();
1450 if( nCode
== KEY_TAB
&& ( !nMod
|| KEY_SHIFT
== nMod
) )
1452 bool bUp
= KEY_SHIFT
== nMod
;
1453 if( ShouldScroll( bUp
) )
1456 SetSelection( Selection( 0, SELECTION_MAX
) );
1457 // Tab-travel doesn't really happen, so emulate it by setting a selection manually
1461 else if( KEY_UP
== nCode
|| KEY_DOWN
== nCode
)
1463 bool bUp
= KEY_UP
== nCode
;
1464 if( ShouldScroll( bUp
) )
1473 m_pPrev
->GrabFocus();
1479 m_pNext
->GrabFocus();
1486 nHandled
= Edit::PreNotify( rNEvt
);
1493 bool GetConversions( Reference
< XConversionDictionary
> _xDict
,
1494 const OUString
& _rOrg
,
1495 Sequence
< OUString
>& _rEntries
)
1498 if( _xDict
.is() && !_rOrg
.isEmpty() )
1502 _rEntries
= _xDict
->getConversions( _rOrg
,
1505 ConversionDirection_FROM_LEFT
,
1506 ::com::sun::star::i18n::TextConversionOption::NONE
);
1507 bRet
= _rEntries
.getLength() > 0;
1509 catch( const IllegalArgumentException
& )
1519 IMPL_LINK_NOARG(HangulHanjaEditDictDialog
, ScrollHdl
)
1526 IMPL_LINK_NOARG(HangulHanjaEditDictDialog
, OriginalModifyHdl
)
1528 m_bModifiedOriginal
= true;
1529 m_aOriginal
= comphelper::string::stripEnd(m_aOriginalLB
.GetText(), ' ');
1531 UpdateSuggestions();
1532 UpdateButtonStates();
1537 IMPL_LINK( HangulHanjaEditDictDialog
, EditModifyHdl1
, Edit
*, pEdit
)
1539 EditModify( pEdit
, 0 );
1543 IMPL_LINK( HangulHanjaEditDictDialog
, EditModifyHdl2
, Edit
*, pEdit
)
1545 EditModify( pEdit
, 1 );
1549 IMPL_LINK( HangulHanjaEditDictDialog
, EditModifyHdl3
, Edit
*, pEdit
)
1551 EditModify( pEdit
, 2 );
1555 IMPL_LINK( HangulHanjaEditDictDialog
, EditModifyHdl4
, Edit
*, pEdit
)
1557 EditModify( pEdit
, 3 );
1561 IMPL_LINK_NOARG(HangulHanjaEditDictDialog
, BookLBSelectHdl
)
1563 InitEditDictDialog( m_aBookLB
.GetSelectEntryPos() );
1567 IMPL_LINK_NOARG(HangulHanjaEditDictDialog
, NewPBPushHdl
)
1569 DBG_ASSERT( m_pSuggestions
, "-HangulHanjaEditDictDialog::NewPBPushHdl(): no suggestions... search in hell..." );
1570 Reference
< XConversionDictionary
> xDict
= m_rDictList
[ m_nCurrentDict
];
1571 if( xDict
.is() && m_pSuggestions
)
1574 bool bRemovedSomething
= DeleteEntryFromDictionary( m_aOriginal
, xDict
);
1576 OUString
aLeft( m_aOriginal
);
1577 const String
* pRight
= m_pSuggestions
->First();
1578 bool bAddedSomething
= false;
1584 xDict
->addEntry( aLeft
, *pRight
);
1585 bAddedSomething
= true;
1587 catch( const IllegalArgumentException
& )
1590 catch( const ElementExistException
& )
1594 pRight
= m_pSuggestions
->Next();
1597 if(bAddedSomething
||bRemovedSomething
)
1598 InitEditDictDialog( m_nCurrentDict
);
1602 DBG_WARNING( "+HangulHanjaEditDictDialog::NewPBPushHdl(): dictionary faded away..." );
1607 bool HangulHanjaEditDictDialog::DeleteEntryFromDictionary( const OUString
&, const Reference
< XConversionDictionary
>& xDict
)
1609 bool bRemovedSomething
= false;
1612 OUString
aOrg( m_aOriginal
);
1613 Sequence
< OUString
> aEntries
;
1614 GetConversions( xDict
, m_aOriginal
, aEntries
);
1616 sal_uInt32 n
= aEntries
.getLength();
1617 OUString
* pEntry
= aEntries
.getArray();
1622 xDict
->removeEntry( aOrg
, *pEntry
);
1623 bRemovedSomething
= true;
1625 catch( const NoSuchElementException
& )
1633 return bRemovedSomething
;
1636 IMPL_LINK_NOARG(HangulHanjaEditDictDialog
, DeletePBPushHdl
)
1638 if( DeleteEntryFromDictionary( m_aOriginal
, m_rDictList
[ m_nCurrentDict
] ) )
1640 m_aOriginal
.Erase();
1641 m_bModifiedOriginal
= true;
1642 InitEditDictDialog( m_nCurrentDict
);
1647 void HangulHanjaEditDictDialog::InitEditDictDialog( sal_uInt32 _nSelDict
)
1649 if( m_pSuggestions
)
1650 m_pSuggestions
->Clear();
1652 if( m_nCurrentDict
!= _nSelDict
)
1654 m_nCurrentDict
= _nSelDict
;
1655 m_aOriginal
.Erase();
1656 m_bModifiedOriginal
= true;
1661 m_aOriginalLB
.SetText( m_aOriginal
.Len()? m_aOriginal
: m_aEditHintText
, Selection( 0, SELECTION_MAX
) );
1662 m_aOriginalLB
.GrabFocus();
1664 UpdateSuggestions();
1665 UpdateButtonStates();
1668 void HangulHanjaEditDictDialog::UpdateOriginalLB( void )
1670 m_aOriginalLB
.Clear();
1671 Reference
< XConversionDictionary
> xDict
= m_rDictList
[ m_nCurrentDict
];
1674 Sequence
< OUString
> aEntries
= xDict
->getConversionEntries( ConversionDirection_FROM_LEFT
);
1675 sal_uInt32 n
= aEntries
.getLength();
1676 OUString
* pEntry
= aEntries
.getArray();
1679 m_aOriginalLB
.InsertEntry( *pEntry
);
1687 DBG_WARNING( "+HangulHanjaEditDictDialog::UpdateOriginalLB(): dictionary faded away..." );
1691 void HangulHanjaEditDictDialog::UpdateButtonStates()
1693 bool bHaveValidOriginalString
= m_aOriginal
.Len() && m_aOriginal
!= m_aEditHintText
;
1694 bool bNew
= bHaveValidOriginalString
&& m_pSuggestions
&& m_pSuggestions
->GetCount() > 0;
1695 bNew
= bNew
&& (m_bModifiedSuggestions
|| m_bModifiedOriginal
);
1697 m_aNewPB
.Enable( bNew
);
1698 m_aDeletePB
.Enable( !m_bModifiedOriginal
&& bHaveValidOriginalString
);
1701 void HangulHanjaEditDictDialog::UpdateSuggestions( void )
1703 Sequence
< OUString
> aEntries
;
1704 bool bFound
= GetConversions( m_rDictList
[ m_nCurrentDict
], m_aOriginal
, aEntries
);
1707 m_bModifiedOriginal
= false;
1709 if( m_pSuggestions
)
1710 m_pSuggestions
->Clear();
1712 //fill found entries into boxes
1713 sal_uInt32 nCnt
= aEntries
.getLength();
1716 if( !m_pSuggestions
)
1717 m_pSuggestions
= new SuggestionList( MAXNUM_SUGGESTIONS
);
1719 const OUString
* pSugg
= aEntries
.getConstArray();
1723 m_pSuggestions
->Set( pSugg
[ n
], sal_uInt16( n
) );
1728 m_bModifiedSuggestions
=false;
1731 m_aScrollSB
.SetThumbPos( 0 );
1732 UpdateScrollbar(); // will force edits to be filled new
1735 void HangulHanjaEditDictDialog::SetEditText( Edit
& _rEdit
, sal_uInt16 _nEntryNum
)
1738 if( m_pSuggestions
)
1740 const String
* p
= m_pSuggestions
->Get( _nEntryNum
);
1745 _rEdit
.SetText( aStr
);
1748 void HangulHanjaEditDictDialog::EditModify( Edit
* _pEdit
, sal_uInt8 _nEntryOffset
)
1750 m_bModifiedSuggestions
= true;
1752 String
aTxt( _pEdit
->GetText() );
1753 sal_uInt16 nEntryNum
= m_nTopPos
+ _nEntryOffset
;
1754 if( aTxt
.Len() == 0 )
1757 if( m_pSuggestions
)
1758 m_pSuggestions
->Reset( nEntryNum
);
1763 if( !m_pSuggestions
)
1764 m_pSuggestions
= new SuggestionList( MAXNUM_SUGGESTIONS
);
1765 m_pSuggestions
->Set( aTxt
, nEntryNum
);
1768 UpdateButtonStates();
1771 HangulHanjaEditDictDialog::HangulHanjaEditDictDialog( Window
* _pParent
, HHDictList
& _rDictList
, sal_uInt32 _nSelDict
)
1772 :ModalDialog ( _pParent
, CUI_RES( RID_SVX_MDLG_HANGULHANJA_EDIT
) )
1773 ,m_aEditHintText ( CUI_RES( STR_EDITHINT
) )
1774 ,m_rDictList ( _rDictList
)
1775 ,m_nCurrentDict ( 0xFFFFFFFF )
1776 ,m_pSuggestions ( NULL
)
1777 ,m_aBookFT ( this, CUI_RES( FT_BOOK
) )
1778 ,m_aBookLB ( this, CUI_RES( LB_BOOK
) )
1779 ,m_aOriginalFT ( this, CUI_RES( FT_ORIGINAL
) )
1780 ,m_aOriginalLB ( this, CUI_RES( LB_ORIGINAL
) )
1781 ,m_aSuggestionsFT ( this, CUI_RES( FT_SUGGESTIONS
) )
1782 ,m_aEdit1 ( this, CUI_RES( ED_1
), m_aScrollSB
, NULL
, &m_aEdit2
)
1783 ,m_aEdit2 ( this, CUI_RES( ED_2
), m_aScrollSB
, &m_aEdit1
, &m_aEdit3
)
1784 ,m_aEdit3 ( this, CUI_RES( ED_3
), m_aScrollSB
, &m_aEdit2
, &m_aEdit4
)
1785 ,m_aEdit4 ( this, CUI_RES( ED_4
), m_aScrollSB
, &m_aEdit3
, NULL
)
1786 ,m_aScrollSB ( this, CUI_RES( SB_SCROLL
) )
1787 ,m_aNewPB ( this, CUI_RES( PB_HHE_NEW
) )
1788 ,m_aDeletePB ( this, CUI_RES( PB_HHE_DELETE
) )
1789 ,m_aHelpPB ( this, CUI_RES( PB_HHE_HELP
) )
1790 ,m_aClosePB ( this, CUI_RES( PB_HHE_CLOSE
) )
1792 ,m_bModifiedSuggestions ( false )
1793 ,m_bModifiedOriginal ( false )
1795 m_aOriginalLB
.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog
, OriginalModifyHdl
) );
1797 m_aNewPB
.SetClickHdl( LINK( this, HangulHanjaEditDictDialog
, NewPBPushHdl
) );
1798 m_aNewPB
.Enable( false );
1800 m_aDeletePB
.SetClickHdl( LINK( this, HangulHanjaEditDictDialog
, DeletePBPushHdl
) );
1802 m_aDeletePB
.Enable( false );
1804 #if( MAXNUM_SUGGESTIONS <= 4 )
1805 #error number of suggestions should not under-run the value of 5
1808 Link
aScrLk( LINK( this, HangulHanjaEditDictDialog
, ScrollHdl
) );
1809 m_aScrollSB
.SetScrollHdl( aScrLk
);
1810 m_aScrollSB
.SetEndScrollHdl( aScrLk
);
1811 m_aScrollSB
.SetRangeMin( 0 );
1812 m_aScrollSB
.SetRangeMax( MAXNUM_SUGGESTIONS
);
1813 m_aScrollSB
.SetPageSize( 4 ); // because we have 4 edits / page
1814 m_aScrollSB
.SetVisibleSize( 4 );
1816 m_aEdit1
.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog
, EditModifyHdl1
) );
1817 m_aEdit2
.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog
, EditModifyHdl2
) );
1818 m_aEdit3
.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog
, EditModifyHdl3
) );
1819 m_aEdit4
.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog
, EditModifyHdl4
) );
1821 m_aBookLB
.SetSelectHdl( LINK( this, HangulHanjaEditDictDialog
, BookLBSelectHdl
) );
1822 sal_uInt32 nDictCnt
= m_rDictList
.size();
1823 for( sal_uInt32 n
= 0 ; n
< nDictCnt
; ++n
)
1825 Reference
< XConversionDictionary
> xDic( m_rDictList
[n
] );
1828 aName
= xDic
->getName();
1829 m_aBookLB
.InsertEntry( aName
);
1831 m_aBookLB
.SelectEntryPos( sal_uInt16( _nSelDict
) );
1835 InitEditDictDialog( _nSelDict
);
1838 HangulHanjaEditDictDialog::~HangulHanjaEditDictDialog()
1840 if( m_pSuggestions
)
1841 delete m_pSuggestions
;
1844 void HangulHanjaEditDictDialog::UpdateScrollbar( void )
1846 sal_uInt16 nPos
= sal_uInt16( m_aScrollSB
.GetThumbPos() );
1849 SetEditText( m_aEdit1
, nPos
++ );
1850 SetEditText( m_aEdit2
, nPos
++ );
1851 SetEditText( m_aEdit3
, nPos
++ );
1852 SetEditText( m_aEdit4
, nPos
);
1855 //.............................................................................
1857 //.............................................................................
1859 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */