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 String m_sPrimaryText;
94 : const String m_sSecondaryText;
95 : const RubyPosition m_ePosition;
96 :
97 : public:
98 : PseudoRubyText( const String& _rPrimary, const String& _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 String& _rPrimary, const String& _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 String& _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 );
221 : };
222 :
223 : //-------------------------------------------------------------------------
224 0 : RubyRadioButton::RubyRadioButton( Window* _pParent, const ResId& _rId,
225 : const String& _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 : String sText = *static_cast< String* >( 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< String* >( 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 : String aOneCharacter(RTL_CONSTASCII_USTRINGPARAM("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 XubString& 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 : String* pItemData = new String(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 : XubString SuggestionDisplay::GetEntry( sal_uInt16 nPos ) const
484 : {
485 0 : return m_aListBox.GetEntry( nPos );
486 : }
487 0 : XubString 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 : String sSecondaryHangul( CUI_RES( STR_HANGUL ) );
520 0 : String 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 : String 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().Len();
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( sal_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 : String 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 String& _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 : String 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( static_cast<sal_Bool>(_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( sal_False );
844 0 : m_aHangulOnly.Enable( sal_True );
845 0 : m_aHanjaOnly.Check( sal_False );
846 0 : m_aHanjaOnly.Enable( sal_True );
847 :
848 0 : if (!_bTryBothDirections)
849 : {
850 : CheckBox *pBox = _ePrimaryConversionDirection == HHC::eHangulToHanja?
851 0 : &m_aHangulOnly : &m_aHanjaOnly;
852 0 : pBox->Check( sal_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_aDictsLB.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_aDictsLB.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_aDictsLB.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_aIgnorepostCB.IsChecked() );
1006 0 : aLngCfg.SetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD, aTmp );
1007 :
1008 0 : aTmp <<= bool( m_aShowrecentlyfirstCB.IsChecked() );
1009 0 : aLngCfg.SetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST, aTmp );
1010 :
1011 0 : aTmp <<= bool( m_aAutoreplaceuniqueCB.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_aDictsLB.FirstSelected() != NULL;
1021 :
1022 0 : m_aEditPB.Enable( bSel );
1023 0 : m_aDeletePB.Enable( bSel );
1024 :
1025 0 : return 0;
1026 : }
1027 :
1028 0 : IMPL_LINK_NOARG(HangulHanjaOptionsDialog, NewDictHdl)
1029 : {
1030 0 : String 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( LANGUAGE_KOREAN ).getLocale(), 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_aDictsLB.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_aDictsLB.GetSelectEntryPos() );
1068 0 : aEdDlg.Execute();
1069 : }
1070 0 : return 0L;
1071 : }
1072 :
1073 0 : IMPL_LINK_NOARG(HangulHanjaOptionsDialog, DeleteDictHdl)
1074 : {
1075 0 : sal_uInt16 nSelPos = m_aDictsLB.GetSelectEntryPos();
1076 0 : if( nSelPos != LISTBOX_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 : HHDictList::iterator aIter(m_aDictList.begin());
1090 0 : m_aDictList.erase(aIter+nSelPos );
1091 0 : m_aDictsLB.RemoveEntry( nSelPos );
1092 : }
1093 0 : catch( const ElementExistException& )
1094 : {
1095 : }
1096 0 : catch( const NoSupportException& )
1097 : {
1098 : }
1099 0 : }
1100 0 : }
1101 : }
1102 :
1103 0 : return 0L;
1104 : }
1105 :
1106 0 : HangulHanjaOptionsDialog::HangulHanjaOptionsDialog( Window* _pParent )
1107 0 : :ModalDialog ( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA_OPT ) )
1108 0 : ,m_aUserdefdictFT ( this, CUI_RES( FT_USERDEFDICT ) )
1109 0 : ,m_aDictsLB ( this, CUI_RES( LB_DICTS ) )
1110 0 : ,m_aOptionsFL ( this, CUI_RES( FL_OPTIONS ) )
1111 0 : ,m_aIgnorepostCB ( this, CUI_RES( CB_IGNOREPOST ) )
1112 0 : ,m_aShowrecentlyfirstCB ( this, CUI_RES( CB_SHOWRECENTLYFIRST ) )
1113 0 : ,m_aAutoreplaceuniqueCB ( this, CUI_RES( CB_AUTOREPLACEUNIQUE ) )
1114 0 : ,m_aNewPB ( this, CUI_RES( PB_HHO_NEW ) )
1115 0 : ,m_aEditPB ( this, CUI_RES( PB_HHO_EDIT ) )
1116 0 : ,m_aDeletePB ( this, CUI_RES( PB_HHO_DELETE ) )
1117 0 : ,m_aOkPB ( this, CUI_RES( PB_HHO_OK ) )
1118 0 : ,m_aCancelPB ( this, CUI_RES( PB_HHO_CANCEL ) )
1119 0 : ,m_aHelpPB ( this, CUI_RES( PB_HHO_HELP ) )
1120 :
1121 : ,m_pCheckButtonData ( NULL )
1122 0 : ,m_xConversionDictionaryList( NULL )
1123 : {
1124 0 : m_aDictsLB.SetStyle( m_aDictsLB.GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE );
1125 0 : m_aDictsLB.SetSelectionMode( SINGLE_SELECTION );
1126 0 : m_aDictsLB.SetHighlightRange();
1127 0 : m_aDictsLB.SetSelectHdl( LINK( this, HangulHanjaOptionsDialog, DictsLB_SelectHdl ) );
1128 0 : m_aDictsLB.SetDeselectHdl( LINK( this, HangulHanjaOptionsDialog, DictsLB_SelectHdl ) );
1129 :
1130 0 : m_aOkPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, OkHdl ) );
1131 0 : m_aNewPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, NewDictHdl ) );
1132 0 : m_aEditPB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, EditDictHdl ) );
1133 0 : m_aDeletePB.SetClickHdl( LINK( this, HangulHanjaOptionsDialog, DeleteDictHdl ) );
1134 :
1135 0 : FreeResource();
1136 :
1137 0 : SvtLinguConfig aLngCfg;
1138 0 : Any aTmp;
1139 0 : bool bVal = bool();
1140 0 : aTmp = aLngCfg.GetProperty( UPH_IS_IGNORE_POST_POSITIONAL_WORD );
1141 0 : if( aTmp >>= bVal )
1142 0 : m_aIgnorepostCB.Check( bVal );
1143 :
1144 0 : aTmp = aLngCfg.GetProperty( UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST );
1145 0 : if( aTmp >>= bVal )
1146 0 : m_aShowrecentlyfirstCB.Check( bVal );
1147 :
1148 0 : aTmp = aLngCfg.GetProperty( UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES );
1149 0 : if( aTmp >>= bVal )
1150 0 : m_aAutoreplaceuniqueCB.Check( bVal );
1151 :
1152 0 : Init();
1153 0 : }
1154 :
1155 0 : HangulHanjaOptionsDialog::~HangulHanjaOptionsDialog()
1156 : {
1157 0 : SvTreeListEntry* pEntry = m_aDictsLB.First();
1158 : String* pDel;
1159 0 : while( pEntry )
1160 : {
1161 0 : pDel = ( String* ) pEntry->GetUserData();
1162 0 : if( pDel )
1163 0 : delete pDel;
1164 0 : pEntry = m_aDictsLB.Next( pEntry );
1165 : }
1166 :
1167 0 : if( m_pCheckButtonData )
1168 0 : delete m_pCheckButtonData;
1169 0 : }
1170 :
1171 0 : void HangulHanjaOptionsDialog::AddDict( const String& _rName, bool _bChecked )
1172 : {
1173 0 : SvTreeListEntry* pEntry = m_aDictsLB.SvTreeListBox::InsertEntry( _rName );
1174 0 : m_aDictsLB.SetCheckButtonState( pEntry, _bChecked? SV_BUTTON_CHECKED : SV_BUTTON_UNCHECKED );
1175 0 : pEntry->SetUserData( new String( _rName ) );
1176 0 : }
1177 :
1178 : //=========================================================================
1179 : //= HangulHanjaNewDictDialog
1180 : //=========================================================================
1181 : //-------------------------------------------------------------------------
1182 :
1183 0 : IMPL_LINK_NOARG(HangulHanjaNewDictDialog, OKHdl)
1184 : {
1185 0 : String aName(comphelper::string::stripEnd(m_aDictNameED.GetText(), ' '));
1186 :
1187 0 : m_bEntered = aName.Len() > 0;
1188 0 : if( m_bEntered )
1189 0 : m_aDictNameED.SetText( aName ); // do this in case of trailing chars have been deleted
1190 :
1191 0 : EndDialog( RET_OK );
1192 0 : return 0;
1193 : }
1194 :
1195 0 : IMPL_LINK_NOARG(HangulHanjaNewDictDialog, ModifyHdl)
1196 : {
1197 0 : String aName(comphelper::string::stripEnd(m_aDictNameED.GetText(), ' '));
1198 :
1199 0 : m_aOkBtn.Enable( aName.Len() > 0 );
1200 :
1201 0 : return 0;
1202 : }
1203 :
1204 0 : HangulHanjaNewDictDialog::HangulHanjaNewDictDialog( Window* _pParent )
1205 0 : :ModalDialog ( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA_NEWDICT ) )
1206 0 : ,m_aNewDictFL ( this, CUI_RES( FL_NEWDICT ) )
1207 0 : ,m_aDictNameFT ( this, CUI_RES( FT_DICTNAME ) )
1208 0 : ,m_aDictNameED ( this, CUI_RES( ED_DICTNAME ) )
1209 0 : ,m_aOkBtn ( this, CUI_RES( PB_NEWDICT_OK ) )
1210 0 : ,m_aCancelBtn ( this, CUI_RES( PB_NEWDICT_ESC ) )
1211 0 : ,m_aHelpBtn ( this, CUI_RES( PB_NEWDICT_HLP ) )
1212 :
1213 0 : ,m_bEntered ( false )
1214 : {
1215 0 : m_aOkBtn.SetClickHdl( LINK( this, HangulHanjaNewDictDialog, OKHdl ) );
1216 :
1217 0 : m_aDictNameED.SetModifyHdl( LINK( this, HangulHanjaNewDictDialog, ModifyHdl ) );
1218 :
1219 0 : FreeResource();
1220 0 : }
1221 :
1222 0 : HangulHanjaNewDictDialog::~HangulHanjaNewDictDialog()
1223 : {
1224 0 : }
1225 :
1226 0 : bool HangulHanjaNewDictDialog::GetName( String& _rRetName ) const
1227 : {
1228 0 : if( m_bEntered )
1229 0 : _rRetName = comphelper::string::stripEnd(m_aDictNameED.GetText(), ' ');
1230 :
1231 0 : return m_bEntered;
1232 : }
1233 :
1234 : //=========================================================================
1235 : //= HangulHanjaEditDictDialog
1236 : //=========================================================================
1237 : //-------------------------------------------------------------------------
1238 :
1239 : class SuggestionList
1240 : {
1241 : private:
1242 : protected:
1243 : sal_uInt16 m_nSize;
1244 : String** m_ppElements;
1245 : sal_uInt16 m_nNumOfEntries;
1246 : sal_uInt16 m_nAct;
1247 :
1248 : const String* _Next( void );
1249 : public:
1250 : SuggestionList( sal_uInt16 _nNumOfElements );
1251 : virtual ~SuggestionList();
1252 :
1253 : bool Set( const String& _rElement, sal_uInt16 _nNumOfElement );
1254 : bool Reset( sal_uInt16 _nNumOfElement );
1255 : const String* Get( sal_uInt16 _nNumOfElement ) const;
1256 : void Clear( void );
1257 :
1258 : const String* First( void );
1259 : const String* Next( void );
1260 :
1261 : inline sal_uInt16 GetCount( void ) const;
1262 : };
1263 :
1264 0 : inline sal_uInt16 SuggestionList::GetCount( void ) const
1265 : {
1266 0 : return m_nNumOfEntries;
1267 : }
1268 :
1269 0 : SuggestionList::SuggestionList( sal_uInt16 _nNumOfElements )
1270 : {
1271 0 : if( !_nNumOfElements )
1272 0 : _nNumOfElements = 1;
1273 :
1274 0 : m_nSize = _nNumOfElements;
1275 :
1276 0 : m_ppElements = new String*[ m_nSize ];
1277 0 : m_nAct = m_nNumOfEntries = 0;
1278 :
1279 0 : String** ppNull = m_ppElements;
1280 0 : sal_uInt16 n = _nNumOfElements;
1281 0 : while( n )
1282 : {
1283 0 : *ppNull = NULL;
1284 0 : ++ppNull;
1285 0 : --n;
1286 : }
1287 0 : }
1288 :
1289 0 : SuggestionList::~SuggestionList()
1290 : {
1291 0 : Clear();
1292 0 : delete[] m_ppElements;
1293 0 : }
1294 :
1295 0 : bool SuggestionList::Set( const String& _rElement, sal_uInt16 _nNumOfElement )
1296 : {
1297 0 : bool bRet = _nNumOfElement < m_nSize;
1298 0 : if( bRet )
1299 : {
1300 0 : String** ppElem = m_ppElements + _nNumOfElement;
1301 0 : if( *ppElem )
1302 0 : **ppElem = _rElement;
1303 : else
1304 : {
1305 0 : *ppElem = new String( _rElement );
1306 0 : ++m_nNumOfEntries;
1307 : }
1308 : }
1309 :
1310 0 : return bRet;
1311 : }
1312 :
1313 0 : bool SuggestionList::Reset( sal_uInt16 _nNumOfElement )
1314 : {
1315 0 : bool bRet = _nNumOfElement < m_nSize;
1316 0 : if( bRet )
1317 : {
1318 0 : String** ppElem = m_ppElements + _nNumOfElement;
1319 0 : if( *ppElem )
1320 : {
1321 0 : delete *ppElem;
1322 0 : *ppElem = NULL;
1323 0 : --m_nNumOfEntries;
1324 : }
1325 : }
1326 :
1327 0 : return bRet;
1328 : }
1329 :
1330 0 : const String* SuggestionList::Get( sal_uInt16 _nNumOfElement ) const
1331 : {
1332 : const String* pRet;
1333 :
1334 0 : if( _nNumOfElement < m_nSize )
1335 0 : pRet = m_ppElements[ _nNumOfElement ];
1336 : else
1337 0 : pRet = NULL;
1338 :
1339 0 : return pRet;
1340 : }
1341 :
1342 0 : void SuggestionList::Clear( void )
1343 : {
1344 0 : if( m_nNumOfEntries )
1345 : {
1346 0 : String** ppDel = m_ppElements;
1347 0 : sal_uInt16 nCnt = m_nSize;
1348 0 : while( nCnt )
1349 : {
1350 0 : if( *ppDel )
1351 : {
1352 0 : delete *ppDel;
1353 0 : *ppDel = NULL;
1354 : }
1355 :
1356 0 : ++ppDel;
1357 0 : --nCnt;
1358 : }
1359 :
1360 0 : m_nNumOfEntries = m_nAct = 0;
1361 : }
1362 0 : }
1363 :
1364 0 : const String* SuggestionList::_Next( void )
1365 : {
1366 0 : const String* pRet = NULL;
1367 0 : while( m_nAct < m_nSize && !pRet )
1368 : {
1369 0 : pRet = m_ppElements[ m_nAct ];
1370 0 : if( !pRet )
1371 0 : ++m_nAct;
1372 : }
1373 :
1374 0 : return pRet;
1375 : }
1376 :
1377 0 : const String* SuggestionList::First( void )
1378 : {
1379 0 : m_nAct = 0;
1380 0 : return _Next();
1381 : }
1382 :
1383 0 : const String* SuggestionList::Next( void )
1384 : {
1385 : const String* pRet;
1386 :
1387 0 : if( m_nAct < m_nNumOfEntries )
1388 : {
1389 0 : ++m_nAct;
1390 0 : pRet = _Next();
1391 : }
1392 : else
1393 0 : pRet = NULL;
1394 :
1395 0 : return pRet;
1396 : }
1397 :
1398 :
1399 0 : bool SuggestionEdit::ShouldScroll( bool _bUp ) const
1400 : {
1401 0 : bool bRet = false;
1402 :
1403 0 : if( _bUp )
1404 : {
1405 0 : if( !m_pPrev )
1406 0 : bRet = m_rScrollBar.GetThumbPos() > m_rScrollBar.GetRangeMin();
1407 : }
1408 : else
1409 : {
1410 0 : if( !m_pNext )
1411 0 : bRet = m_rScrollBar.GetThumbPos() < ( m_rScrollBar.GetRangeMax() - 4 );
1412 : }
1413 :
1414 0 : return bRet;
1415 : }
1416 :
1417 0 : void SuggestionEdit::DoJump( bool _bUp )
1418 : {
1419 0 : const Link& rLoseFocusHdl = GetLoseFocusHdl();
1420 0 : if( rLoseFocusHdl.IsSet() )
1421 0 : rLoseFocusHdl.Call( this );
1422 0 : m_rScrollBar.SetThumbPos( m_rScrollBar.GetThumbPos() + ( _bUp? -1 : 1 ) );
1423 :
1424 0 : ( static_cast< HangulHanjaEditDictDialog* >( GetParentDialog() ) )->UpdateScrollbar();
1425 0 : }
1426 :
1427 0 : SuggestionEdit::SuggestionEdit( Window* pParent, const ResId& rResId,
1428 : ScrollBar& _rScrollBar, SuggestionEdit* _pPrev, SuggestionEdit* _pNext )
1429 : :Edit( pParent, rResId )
1430 : ,m_pPrev( _pPrev )
1431 : ,m_pNext( _pNext )
1432 0 : ,m_rScrollBar( _rScrollBar )
1433 : {
1434 0 : }
1435 :
1436 0 : SuggestionEdit::~SuggestionEdit()
1437 : {
1438 0 : }
1439 :
1440 0 : long SuggestionEdit::PreNotify( NotifyEvent& rNEvt )
1441 : {
1442 0 : long nHandled = 0;
1443 0 : if( rNEvt.GetType() == EVENT_KEYINPUT )
1444 : {
1445 0 : const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
1446 0 : const KeyCode& rKeyCode = pKEvt->GetKeyCode();
1447 0 : sal_uInt16 nMod = rKeyCode.GetModifier();
1448 0 : sal_uInt16 nCode = rKeyCode.GetCode();
1449 0 : if( nCode == KEY_TAB && ( !nMod || KEY_SHIFT == nMod ) )
1450 : {
1451 0 : bool bUp = KEY_SHIFT == nMod;
1452 0 : if( ShouldScroll( bUp ) )
1453 : {
1454 0 : DoJump( bUp );
1455 0 : SetSelection( Selection( 0, SELECTION_MAX ) );
1456 : // Tab-travel doesn't really happen, so emulate it by setting a selection manually
1457 0 : nHandled = 1;
1458 0 : }
1459 : }
1460 0 : else if( KEY_UP == nCode || KEY_DOWN == nCode )
1461 : {
1462 0 : bool bUp = KEY_UP == nCode;
1463 0 : if( ShouldScroll( bUp ) )
1464 : {
1465 0 : DoJump( bUp );
1466 0 : nHandled = 1;
1467 : }
1468 0 : else if( bUp )
1469 : {
1470 0 : if( m_pPrev )
1471 : {
1472 0 : m_pPrev->GrabFocus();
1473 0 : nHandled = 1;
1474 : }
1475 : }
1476 0 : else if( m_pNext )
1477 : {
1478 0 : m_pNext->GrabFocus();
1479 0 : nHandled = 1;
1480 : }
1481 : }
1482 : }
1483 :
1484 0 : if( !nHandled )
1485 0 : nHandled = Edit::PreNotify( rNEvt );
1486 0 : return nHandled;
1487 : }
1488 :
1489 :
1490 : namespace
1491 : {
1492 0 : bool GetConversions( Reference< XConversionDictionary > _xDict,
1493 : const OUString& _rOrg,
1494 : Sequence< OUString >& _rEntries )
1495 : {
1496 0 : bool bRet = false;
1497 0 : if( _xDict.is() && !_rOrg.isEmpty() )
1498 : {
1499 : try
1500 : {
1501 0 : _rEntries = _xDict->getConversions( _rOrg,
1502 : 0,
1503 : _rOrg.getLength(),
1504 : ConversionDirection_FROM_LEFT,
1505 0 : ::com::sun::star::i18n::TextConversionOption::NONE );
1506 0 : bRet = _rEntries.getLength() > 0;
1507 : }
1508 0 : catch( const IllegalArgumentException& )
1509 : {
1510 : }
1511 : }
1512 :
1513 0 : return bRet;
1514 : }
1515 : }
1516 :
1517 :
1518 0 : IMPL_LINK_NOARG(HangulHanjaEditDictDialog, ScrollHdl)
1519 : {
1520 0 : UpdateScrollbar();
1521 :
1522 0 : return 0;
1523 : }
1524 :
1525 0 : IMPL_LINK_NOARG(HangulHanjaEditDictDialog, OriginalModifyHdl)
1526 : {
1527 0 : m_bModifiedOriginal = true;
1528 0 : m_aOriginal = comphelper::string::stripEnd(m_aOriginalLB.GetText(), ' ');
1529 :
1530 0 : UpdateSuggestions();
1531 0 : UpdateButtonStates();
1532 :
1533 0 : return 0;
1534 : }
1535 :
1536 0 : IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl1, Edit*, pEdit )
1537 : {
1538 0 : EditModify( pEdit, 0 );
1539 0 : return 0;
1540 : }
1541 :
1542 0 : IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl2, Edit*, pEdit )
1543 : {
1544 0 : EditModify( pEdit, 1 );
1545 0 : return 0;
1546 : }
1547 :
1548 0 : IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl3, Edit*, pEdit )
1549 : {
1550 0 : EditModify( pEdit, 2 );
1551 0 : return 0;
1552 : }
1553 :
1554 0 : IMPL_LINK( HangulHanjaEditDictDialog, EditModifyHdl4, Edit*, pEdit )
1555 : {
1556 0 : EditModify( pEdit, 3 );
1557 0 : return 0;
1558 : }
1559 :
1560 0 : IMPL_LINK_NOARG(HangulHanjaEditDictDialog, BookLBSelectHdl)
1561 : {
1562 0 : InitEditDictDialog( m_aBookLB.GetSelectEntryPos() );
1563 0 : return 0;
1564 : }
1565 :
1566 0 : IMPL_LINK_NOARG(HangulHanjaEditDictDialog, NewPBPushHdl)
1567 : {
1568 : DBG_ASSERT( m_pSuggestions, "-HangulHanjaEditDictDialog::NewPBPushHdl(): no suggestions... search in hell..." );
1569 0 : Reference< XConversionDictionary > xDict = m_rDictList[ m_nCurrentDict ];
1570 0 : if( xDict.is() && m_pSuggestions )
1571 : {
1572 : //delete old entry
1573 0 : bool bRemovedSomething = DeleteEntryFromDictionary( m_aOriginal, xDict );
1574 :
1575 0 : OUString aLeft( m_aOriginal );
1576 0 : const String* pRight = m_pSuggestions->First();
1577 0 : bool bAddedSomething = false;
1578 0 : while( pRight )
1579 : {
1580 : try
1581 : {
1582 : //add new entry
1583 0 : xDict->addEntry( aLeft, *pRight );
1584 0 : bAddedSomething = true;
1585 : }
1586 0 : catch( const IllegalArgumentException& )
1587 : {
1588 : }
1589 0 : catch( const ElementExistException& )
1590 : {
1591 : }
1592 :
1593 0 : pRight = m_pSuggestions->Next();
1594 : }
1595 :
1596 0 : if(bAddedSomething||bRemovedSomething)
1597 0 : InitEditDictDialog( m_nCurrentDict );
1598 : }
1599 : else
1600 : {
1601 : DBG_WARNING( "+HangulHanjaEditDictDialog::NewPBPushHdl(): dictionary faded away..." );
1602 : }
1603 0 : return 0;
1604 : }
1605 :
1606 0 : bool HangulHanjaEditDictDialog::DeleteEntryFromDictionary( const OUString&, const Reference< XConversionDictionary >& xDict )
1607 : {
1608 0 : bool bRemovedSomething = false;
1609 0 : if( xDict.is() )
1610 : {
1611 0 : OUString aOrg( m_aOriginal );
1612 0 : Sequence< OUString > aEntries;
1613 0 : GetConversions( xDict, m_aOriginal, aEntries );
1614 :
1615 0 : sal_uInt32 n = aEntries.getLength();
1616 0 : OUString* pEntry = aEntries.getArray();
1617 0 : while( n )
1618 : {
1619 : try
1620 : {
1621 0 : xDict->removeEntry( aOrg, *pEntry );
1622 0 : bRemovedSomething = true;
1623 : }
1624 0 : catch( const NoSuchElementException& )
1625 : { // can not be...
1626 : }
1627 :
1628 0 : ++pEntry;
1629 0 : --n;
1630 0 : }
1631 : }
1632 0 : return bRemovedSomething;
1633 : }
1634 :
1635 0 : IMPL_LINK_NOARG(HangulHanjaEditDictDialog, DeletePBPushHdl)
1636 : {
1637 0 : if( DeleteEntryFromDictionary( m_aOriginal, m_rDictList[ m_nCurrentDict ] ) )
1638 : {
1639 0 : m_aOriginal.Erase();
1640 0 : m_bModifiedOriginal = true;
1641 0 : InitEditDictDialog( m_nCurrentDict );
1642 : }
1643 0 : return 0;
1644 : }
1645 :
1646 0 : void HangulHanjaEditDictDialog::InitEditDictDialog( sal_uInt32 _nSelDict )
1647 : {
1648 0 : if( m_pSuggestions )
1649 0 : m_pSuggestions->Clear();
1650 :
1651 0 : if( m_nCurrentDict != _nSelDict )
1652 : {
1653 0 : m_nCurrentDict = _nSelDict;
1654 0 : m_aOriginal.Erase();
1655 0 : m_bModifiedOriginal = true;
1656 : }
1657 :
1658 0 : UpdateOriginalLB();
1659 :
1660 0 : m_aOriginalLB.SetText( m_aOriginal.Len()? m_aOriginal : m_aEditHintText, Selection( 0, SELECTION_MAX ) );
1661 0 : m_aOriginalLB.GrabFocus();
1662 :
1663 0 : UpdateSuggestions();
1664 0 : UpdateButtonStates();
1665 0 : }
1666 :
1667 0 : void HangulHanjaEditDictDialog::UpdateOriginalLB( void )
1668 : {
1669 0 : m_aOriginalLB.Clear();
1670 0 : Reference< XConversionDictionary > xDict = m_rDictList[ m_nCurrentDict ];
1671 0 : if( xDict.is() )
1672 : {
1673 0 : Sequence< OUString > aEntries = xDict->getConversionEntries( ConversionDirection_FROM_LEFT );
1674 0 : sal_uInt32 n = aEntries.getLength();
1675 0 : OUString* pEntry = aEntries.getArray();
1676 0 : while( n )
1677 : {
1678 0 : m_aOriginalLB.InsertEntry( *pEntry );
1679 :
1680 0 : ++pEntry;
1681 0 : --n;
1682 0 : }
1683 : }
1684 : else
1685 : {
1686 : DBG_WARNING( "+HangulHanjaEditDictDialog::UpdateOriginalLB(): dictionary faded away..." );
1687 0 : }
1688 0 : }
1689 :
1690 0 : void HangulHanjaEditDictDialog::UpdateButtonStates()
1691 : {
1692 0 : bool bHaveValidOriginalString = m_aOriginal.Len() && m_aOriginal != m_aEditHintText;
1693 0 : bool bNew = bHaveValidOriginalString && m_pSuggestions && m_pSuggestions->GetCount() > 0;
1694 0 : bNew = bNew && (m_bModifiedSuggestions || m_bModifiedOriginal);
1695 :
1696 0 : m_aNewPB.Enable( bNew );
1697 0 : m_aDeletePB.Enable( !m_bModifiedOriginal && bHaveValidOriginalString );
1698 0 : }
1699 :
1700 0 : void HangulHanjaEditDictDialog::UpdateSuggestions( void )
1701 : {
1702 0 : Sequence< OUString > aEntries;
1703 0 : bool bFound = GetConversions( m_rDictList[ m_nCurrentDict ], m_aOriginal, aEntries );
1704 0 : if( bFound )
1705 : {
1706 0 : m_bModifiedOriginal = false;
1707 :
1708 0 : if( m_pSuggestions )
1709 0 : m_pSuggestions->Clear();
1710 :
1711 : //fill found entries into boxes
1712 0 : sal_uInt32 nCnt = aEntries.getLength();
1713 0 : if( nCnt )
1714 : {
1715 0 : if( !m_pSuggestions )
1716 0 : m_pSuggestions = new SuggestionList( MAXNUM_SUGGESTIONS );
1717 :
1718 0 : const OUString* pSugg = aEntries.getConstArray();
1719 0 : sal_uInt32 n = 0;
1720 0 : while( nCnt )
1721 : {
1722 0 : m_pSuggestions->Set( pSugg[ n ], sal_uInt16( n ) );
1723 0 : ++n;
1724 0 : --nCnt;
1725 : }
1726 : }
1727 0 : m_bModifiedSuggestions=false;
1728 : }
1729 :
1730 0 : m_aScrollSB.SetThumbPos( 0 );
1731 0 : UpdateScrollbar(); // will force edits to be filled new
1732 0 : }
1733 :
1734 0 : void HangulHanjaEditDictDialog::SetEditText( Edit& _rEdit, sal_uInt16 _nEntryNum )
1735 : {
1736 0 : String aStr;
1737 0 : if( m_pSuggestions )
1738 : {
1739 0 : const String* p = m_pSuggestions->Get( _nEntryNum );
1740 0 : if( p )
1741 0 : aStr = *p;
1742 : }
1743 :
1744 0 : _rEdit.SetText( aStr );
1745 0 : }
1746 :
1747 0 : void HangulHanjaEditDictDialog::EditModify( Edit* _pEdit, sal_uInt8 _nEntryOffset )
1748 : {
1749 0 : m_bModifiedSuggestions = true;
1750 :
1751 0 : String aTxt( _pEdit->GetText() );
1752 0 : sal_uInt16 nEntryNum = m_nTopPos + _nEntryOffset;
1753 0 : if( aTxt.Len() == 0 )
1754 : {
1755 : //reset suggestion
1756 0 : if( m_pSuggestions )
1757 0 : m_pSuggestions->Reset( nEntryNum );
1758 : }
1759 : else
1760 : {
1761 : //set suggestion
1762 0 : if( !m_pSuggestions )
1763 0 : m_pSuggestions = new SuggestionList( MAXNUM_SUGGESTIONS );
1764 0 : m_pSuggestions->Set( aTxt, nEntryNum );
1765 : }
1766 :
1767 0 : UpdateButtonStates();
1768 0 : }
1769 :
1770 0 : HangulHanjaEditDictDialog::HangulHanjaEditDictDialog( Window* _pParent, HHDictList& _rDictList, sal_uInt32 _nSelDict )
1771 0 : :ModalDialog ( _pParent, CUI_RES( RID_SVX_MDLG_HANGULHANJA_EDIT ) )
1772 0 : ,m_aEditHintText ( CUI_RES( STR_EDITHINT ) )
1773 : ,m_rDictList ( _rDictList )
1774 : ,m_nCurrentDict ( 0xFFFFFFFF )
1775 : ,m_pSuggestions ( NULL )
1776 0 : ,m_aBookFT ( this, CUI_RES( FT_BOOK ) )
1777 0 : ,m_aBookLB ( this, CUI_RES( LB_BOOK ) )
1778 0 : ,m_aOriginalFT ( this, CUI_RES( FT_ORIGINAL ) )
1779 0 : ,m_aOriginalLB ( this, CUI_RES( LB_ORIGINAL ) )
1780 0 : ,m_aSuggestionsFT ( this, CUI_RES( FT_SUGGESTIONS ) )
1781 0 : ,m_aEdit1 ( this, CUI_RES( ED_1 ), m_aScrollSB, NULL, &m_aEdit2 )
1782 0 : ,m_aEdit2 ( this, CUI_RES( ED_2 ), m_aScrollSB, &m_aEdit1, &m_aEdit3 )
1783 0 : ,m_aEdit3 ( this, CUI_RES( ED_3 ), m_aScrollSB, &m_aEdit2, &m_aEdit4 )
1784 0 : ,m_aEdit4 ( this, CUI_RES( ED_4 ), m_aScrollSB, &m_aEdit3, NULL )
1785 0 : ,m_aScrollSB ( this, CUI_RES( SB_SCROLL ) )
1786 0 : ,m_aNewPB ( this, CUI_RES( PB_HHE_NEW ) )
1787 0 : ,m_aDeletePB ( this, CUI_RES( PB_HHE_DELETE ) )
1788 0 : ,m_aHelpPB ( this, CUI_RES( PB_HHE_HELP ) )
1789 0 : ,m_aClosePB ( this, CUI_RES( PB_HHE_CLOSE ) )
1790 : ,m_nTopPos ( 0 )
1791 : ,m_bModifiedSuggestions ( false )
1792 0 : ,m_bModifiedOriginal ( false )
1793 : {
1794 0 : m_aOriginalLB.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, OriginalModifyHdl ) );
1795 :
1796 0 : m_aNewPB.SetClickHdl( LINK( this, HangulHanjaEditDictDialog, NewPBPushHdl ) );
1797 0 : m_aNewPB.Enable( false );
1798 :
1799 0 : m_aDeletePB.SetClickHdl( LINK( this, HangulHanjaEditDictDialog, DeletePBPushHdl ) );
1800 :
1801 0 : m_aDeletePB.Enable( false );
1802 :
1803 : #if( MAXNUM_SUGGESTIONS <= 4 )
1804 : #error number of suggestions should not under-run the value of 5
1805 : #endif
1806 :
1807 0 : Link aScrLk( LINK( this, HangulHanjaEditDictDialog, ScrollHdl ) );
1808 0 : m_aScrollSB.SetScrollHdl( aScrLk );
1809 0 : m_aScrollSB.SetEndScrollHdl( aScrLk );
1810 0 : m_aScrollSB.SetRangeMin( 0 );
1811 0 : m_aScrollSB.SetRangeMax( MAXNUM_SUGGESTIONS );
1812 0 : m_aScrollSB.SetPageSize( 4 ); // because we have 4 edits / page
1813 0 : m_aScrollSB.SetVisibleSize( 4 );
1814 :
1815 0 : m_aEdit1.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl1 ) );
1816 0 : m_aEdit2.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl2 ) );
1817 0 : m_aEdit3.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl3 ) );
1818 0 : m_aEdit4.SetModifyHdl( LINK( this, HangulHanjaEditDictDialog, EditModifyHdl4 ) );
1819 :
1820 0 : m_aBookLB.SetSelectHdl( LINK( this, HangulHanjaEditDictDialog, BookLBSelectHdl ) );
1821 0 : sal_uInt32 nDictCnt = m_rDictList.size();
1822 0 : for( sal_uInt32 n = 0 ; n < nDictCnt ; ++n )
1823 : {
1824 0 : Reference< XConversionDictionary > xDic( m_rDictList[n] );
1825 0 : String aName;
1826 0 : if(xDic.is())
1827 0 : aName = xDic->getName();
1828 0 : m_aBookLB.InsertEntry( aName );
1829 0 : }
1830 0 : m_aBookLB.SelectEntryPos( sal_uInt16( _nSelDict ) );
1831 :
1832 0 : FreeResource();
1833 :
1834 0 : InitEditDictDialog( _nSelDict );
1835 0 : }
1836 :
1837 0 : HangulHanjaEditDictDialog::~HangulHanjaEditDictDialog()
1838 : {
1839 0 : if( m_pSuggestions )
1840 0 : delete m_pSuggestions;
1841 0 : }
1842 :
1843 0 : void HangulHanjaEditDictDialog::UpdateScrollbar( void )
1844 : {
1845 0 : sal_uInt16 nPos = sal_uInt16( m_aScrollSB.GetThumbPos() );
1846 0 : m_nTopPos = nPos;
1847 :
1848 0 : SetEditText( m_aEdit1, nPos++ );
1849 0 : SetEditText( m_aEdit2, nPos++ );
1850 0 : SetEditText( m_aEdit3, nPos++ );
1851 0 : SetEditText( m_aEdit4, nPos );
1852 0 : }
1853 :
1854 : //.............................................................................
1855 0 : } // namespace svx
1856 : //.............................................................................
1857 :
1858 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|