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