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