LCOV - code coverage report
Current view: top level - cui/source/dialogs - hangulhanjadlg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 933 0.0 %
Date: 2014-11-03 Functions: 0 150 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10