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