LCOV - code coverage report
Current view: top level - cui/source/dialogs - thesdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 360 0.0 %
Date: 2012-08-25 Functions: 0 51 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 802 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "thesdlg.hrc"
      30                 :            : #include "thesdlg.hxx"
      31                 :            : #include "thesdlg_impl.hxx"
      32                 :            : #include "cuires.hrc"
      33                 :            : #include "dialmgr.hxx"
      34                 :            : 
      35                 :            : #include <tools/shl.hxx>
      36                 :            : #include <svl/lngmisc.hxx>
      37                 :            : #include <svtools/filter.hxx>
      38                 :            : #include <svtools/svlbitm.hxx>
      39                 :            : #include <svtools/svtreebx.hxx>
      40                 :            : #include <vcl/wrkwin.hxx>
      41                 :            : #include <vcl/msgbox.hxx>
      42                 :            : #include <vcl/svapp.hxx>
      43                 :            : #include <thesdlg.hxx>
      44                 :            : #include <svx/dlgutil.hxx>
      45                 :            : #include <svx/dialmgr.hxx>
      46                 :            : #include <svx/svxerr.hxx>
      47                 :            : #include <editeng/unolingu.hxx>
      48                 :            : #include <svx/langbox.hxx>
      49                 :            : #include <svtools/langtab.hxx>
      50                 :            : #include <unotools/lingucfg.hxx>
      51                 :            : #include <i18npool/mslangid.hxx>
      52                 :            : #include <comphelper/processfactory.hxx>
      53                 :            : #include <comphelper/string.hxx>
      54                 :            : #include <osl/file.hxx>
      55                 :            : 
      56                 :            : #include <stack>
      57                 :            : #include <algorithm>
      58                 :            : 
      59                 :            : #include <com/sun/star/linguistic2/XThesaurus.hpp>
      60                 :            : #include <com/sun/star/linguistic2/XMeaning.hpp>
      61                 :            : #include <com/sun/star/linguistic2/XLinguServiceManager.hpp>
      62                 :            : 
      63                 :            : using namespace ::com::sun::star;
      64                 :            : using ::rtl::OUString;
      65                 :            : 
      66                 :            : // class LookUpComboBox_Impl --------------------------------------------------
      67                 :            : 
      68                 :          0 : LookUpComboBox_Impl::LookUpComboBox_Impl(
      69                 :            :     Window *pParent, const ResId &rResId, SvxThesaurusDialog_Impl &rImpl ) :
      70                 :            :     ComboBox        (pParent, rResId),
      71         [ #  # ]:          0 :     m_rDialogImpl( rImpl )
      72                 :            : {
      73         [ #  # ]:          0 :     m_aModifyTimer.SetTimeoutHdl( LINK( this, LookUpComboBox_Impl, ModifyTimer_Hdl ) );
      74         [ #  # ]:          0 :     m_aModifyTimer.SetTimeout( 500 );
      75                 :            : 
      76         [ #  # ]:          0 :     EnableAutocomplete( sal_False );
      77                 :          0 : }
      78                 :            : 
      79         [ #  # ]:          0 : LookUpComboBox_Impl::~LookUpComboBox_Impl()
      80                 :            : {
      81         [ #  # ]:          0 : }
      82                 :            : 
      83                 :          0 : void LookUpComboBox_Impl::Modify()
      84                 :            : {
      85                 :          0 :     m_aModifyTimer.Start();
      86                 :          0 : }
      87                 :            : 
      88                 :          0 : IMPL_LINK( LookUpComboBox_Impl, ModifyTimer_Hdl, Timer *, EMPTYARG /*pTimer*/ )
      89                 :            : {
      90         [ #  # ]:          0 :     m_rDialogImpl.LookUp( GetText() );
      91                 :          0 :     m_aModifyTimer.Stop();
      92                 :          0 :     return 0;
      93                 :            : }
      94                 :            : 
      95                 :            : // class ReplaceEdit_Impl --------------------------------------------------
      96                 :            : 
      97                 :          0 : ReplaceEdit_Impl::ReplaceEdit_Impl( Window *pParent, const ResId &rResId )
      98                 :            :     : Edit(pParent, rResId)
      99                 :          0 :     , m_pBtn(NULL)
     100                 :            : {
     101                 :          0 : }
     102                 :            : 
     103                 :          0 : ReplaceEdit_Impl::~ReplaceEdit_Impl()
     104                 :            : {
     105         [ #  # ]:          0 : }
     106                 :            : 
     107                 :          0 : void ReplaceEdit_Impl::Modify()
     108                 :            : {
     109         [ #  # ]:          0 :     if (m_pBtn)
     110         [ #  # ]:          0 :         m_pBtn->Enable( GetText().Len() > 0 );
     111                 :          0 : }
     112                 :            : 
     113                 :          0 : void ReplaceEdit_Impl::SetText( const XubString& rStr )
     114                 :            : {
     115                 :          0 :     Edit::SetText( rStr );
     116                 :          0 :     Modify();
     117                 :          0 : }
     118                 :            : 
     119                 :          0 : void ReplaceEdit_Impl::SetText( const XubString& rStr, const Selection& rNewSelection )
     120                 :            : {
     121                 :          0 :     Edit::SetText( rStr, rNewSelection );
     122                 :          0 :     Modify();
     123                 :          0 : }
     124                 :            : 
     125                 :            : // class ThesaurusAlternativesCtrl_Impl ----------------------------------
     126                 :            : 
     127                 :          0 : AlternativesString_Impl::AlternativesString_Impl(
     128                 :            :     ThesaurusAlternativesCtrl_Impl &rControl,
     129                 :            :     SvLBoxEntry* pEntry, sal_uInt16 nFlags, const String& rStr ) :
     130                 :            : 
     131                 :            :     SvLBoxString( pEntry, nFlags, rStr ),
     132         [ #  # ]:          0 :     m_rControlImpl( rControl )
     133                 :            : {
     134                 :          0 : }
     135                 :            : 
     136                 :          0 : void AlternativesString_Impl::Paint(
     137                 :            :     const Point& rPos,
     138                 :            :     SvLBox& rDev, sal_uInt16,
     139                 :            :     SvLBoxEntry* pEntry )
     140                 :            : {
     141         [ #  # ]:          0 :     AlternativesExtraData* pData = m_rControlImpl.GetExtraData( pEntry );
     142                 :          0 :     Point aPos( rPos );
     143         [ #  # ]:          0 :     Font aOldFont( rDev.GetFont());
     144 [ #  # ][ #  # ]:          0 :     if (pData && pData->IsHeader())
                 [ #  # ]
     145                 :            :     {
     146         [ #  # ]:          0 :         Font aFont( aOldFont );
     147         [ #  # ]:          0 :         aFont.SetWeight( WEIGHT_BOLD );
     148         [ #  # ]:          0 :         rDev.SetFont( aFont );
     149         [ #  # ]:          0 :         aPos.X() = 0;
     150                 :            :     }
     151                 :            :     else
     152                 :          0 :         aPos.X() += 5;
     153 [ #  # ][ #  # ]:          0 :     rDev.DrawText( aPos, GetText() );
                 [ #  # ]
     154 [ #  # ][ #  # ]:          0 :     rDev.SetFont( aOldFont );
     155                 :          0 : }
     156                 :            : 
     157                 :          0 : ThesaurusAlternativesCtrl_Impl::ThesaurusAlternativesCtrl_Impl(
     158                 :            :         Window* pParent,
     159                 :            :         SvxThesaurusDialog_Impl &rImpl ) :
     160                 :          0 :     SvxCheckListBox( pParent, CUI_RES( CT_THES_ALTERNATIVES ) ),
     161 [ #  # ][ #  # ]:          0 :     m_rDialogImpl( rImpl )
     162                 :            : {
     163 [ #  # ][ #  # ]:          0 :     SetStyle( GetStyle() | WB_CLIPCHILDREN | WB_HSCROLL | WB_FORCE_MAKEVISIBLE );
     164         [ #  # ]:          0 :     SetHighlightRange();
     165                 :          0 : }
     166                 :            : 
     167                 :          0 : ThesaurusAlternativesCtrl_Impl::~ThesaurusAlternativesCtrl_Impl()
     168                 :            : {
     169         [ #  # ]:          0 :     ClearExtraData();
     170         [ #  # ]:          0 : }
     171                 :            : 
     172                 :          0 : void ThesaurusAlternativesCtrl_Impl::ClearExtraData()
     173                 :            : {
     174         [ #  # ]:          0 :     UserDataMap_t   aEmpty;
     175         [ #  # ]:          0 :     m_aUserData.swap( aEmpty );
     176                 :          0 : }
     177                 :            : 
     178                 :          0 : void ThesaurusAlternativesCtrl_Impl::SetExtraData(
     179                 :            :     const SvLBoxEntry *pEntry,
     180                 :            :     const AlternativesExtraData &rData )
     181                 :            : {
     182         [ #  # ]:          0 :     if (!pEntry)
     183                 :          0 :         return;
     184                 :            : 
     185         [ #  # ]:          0 :     UserDataMap_t::iterator aIt( m_aUserData.find( pEntry ) );
     186         [ #  # ]:          0 :     if (aIt != m_aUserData.end())
     187         [ #  # ]:          0 :         aIt->second = rData;
     188                 :            :     else
     189 [ #  # ][ #  # ]:          0 :         m_aUserData[ pEntry ] = rData;
     190                 :            : }
     191                 :            : 
     192                 :          0 : AlternativesExtraData * ThesaurusAlternativesCtrl_Impl::GetExtraData(
     193                 :            :     const SvLBoxEntry *pEntry )
     194                 :            : {
     195                 :          0 :     AlternativesExtraData *pRes = NULL;
     196         [ #  # ]:          0 :     UserDataMap_t::iterator aIt( m_aUserData.find( pEntry ) );
     197         [ #  # ]:          0 :     if (aIt != m_aUserData.end())
     198                 :          0 :         pRes = &aIt->second;
     199                 :          0 :     return pRes;
     200                 :            : }
     201                 :            : 
     202                 :          0 : SvLBoxEntry * ThesaurusAlternativesCtrl_Impl::AddEntry( sal_Int32 nVal, const String &rText, bool bIsHeader )
     203                 :            : {
     204 [ #  # ][ #  # ]:          0 :     SvLBoxEntry* pEntry = new SvLBoxEntry;
     205         [ #  # ]:          0 :     String aText;
     206 [ #  # ][ #  # ]:          0 :     if (bIsHeader && nVal >= 0)
     207                 :            :     {
     208 [ #  # ][ #  # ]:          0 :         aText = String::CreateFromInt32( nVal );
                 [ #  # ]
     209         [ #  # ]:          0 :         aText += rtl::OUString(". ");
     210                 :            :     }
     211 [ #  # ][ #  # ]:          0 :     pEntry->AddItem( new SvLBoxString( pEntry, 0, String() ) ); // add empty column
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     212         [ #  # ]:          0 :     aText += rText;
     213 [ #  # ][ #  # ]:          0 :     pEntry->AddItem( new SvLBoxContextBmp( pEntry, 0, Image(), Image(), 0 ) );  // otherwise crash
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     214 [ #  # ][ #  # ]:          0 :     pEntry->AddItem( new AlternativesString_Impl( *this, pEntry, 0, aText ) );
                 [ #  # ]
     215                 :            : 
     216 [ #  # ][ #  # ]:          0 :     SetExtraData( pEntry, AlternativesExtraData( rText, bIsHeader ) );
                 [ #  # ]
     217         [ #  # ]:          0 :     GetModel()->Insert( pEntry );
     218                 :            : 
     219         [ #  # ]:          0 :     if (bIsHeader)
     220         [ #  # ]:          0 :         GetViewDataEntry( pEntry )->SetSelectable( false );
     221                 :            : 
     222         [ #  # ]:          0 :     return pEntry;
     223                 :            : }
     224                 :            : 
     225                 :          0 : void ThesaurusAlternativesCtrl_Impl::KeyInput( const KeyEvent& rKEvt )
     226                 :            : {
     227                 :          0 :     const KeyCode& rKey = rKEvt.GetKeyCode();
     228                 :            : 
     229 [ #  # ][ #  # ]:          0 :     if (rKey.GetCode() == KEY_RETURN || rKey.GetCode() == KEY_ESCAPE)
                 [ #  # ]
     230                 :          0 :         GetParent()->KeyInput( rKEvt ); // parent will close dialog...
     231         [ #  # ]:          0 :     else if (rKey.GetCode() == KEY_SPACE)
     232                 :          0 :         m_rDialogImpl.AlternativesDoubleClickHdl_Impl( this ); // look up current selected entry
     233         [ #  # ]:          0 :     else if (GetEntryCount())
     234                 :          0 :         SvxCheckListBox::KeyInput( rKEvt );
     235                 :          0 : }
     236                 :            : 
     237                 :          0 : void ThesaurusAlternativesCtrl_Impl::Paint( const Rectangle& rRect )
     238                 :            : {
     239         [ #  # ]:          0 :     if (!m_rDialogImpl.m_bWordFound)
     240                 :            :     {
     241 [ #  # ][ #  # ]:          0 :         Size aTextSize( GetTextWidth( m_rDialogImpl.aErrStr ), GetTextHeight() );
     242         [ #  # ]:          0 :         aTextSize  = LogicToPixel( aTextSize );
     243                 :          0 :         Point aPos;
     244         [ #  # ]:          0 :         aPos.X() += GetSizePixel().Width() / 2  - aTextSize.Width() / 2;
     245         [ #  # ]:          0 :         aPos.Y() += GetSizePixel().Height() / 2;
     246         [ #  # ]:          0 :         aPos = PixelToLogic( aPos );
     247         [ #  # ]:          0 :         DrawText( aPos, m_rDialogImpl.aErrStr );
     248                 :            : 
     249                 :            :     }
     250                 :            :     else
     251                 :          0 :         SvxCheckListBox::Paint( rRect );
     252                 :          0 : }
     253                 :            : 
     254                 :            : // struct SvxThesaurusDialog_Impl ----------------------------------------
     255                 :            : 
     256                 :          0 : SvxThesaurusDialog_Impl::SvxThesaurusDialog_Impl( SvxThesaurusDialog * pDialog ) :
     257                 :            :     m_pDialog       ( pDialog ),
     258                 :          0 :     aVendorImageFI  ( pDialog, CUI_RES( IMG_VENDOR ) ),
     259         [ #  # ]:          0 :     aLeftBtn        ( pDialog, CUI_RES( BTN_LEFT ) ),
     260         [ #  # ]:          0 :     aWordText       ( pDialog, CUI_RES( FT_WORD ) ),
     261         [ #  # ]:          0 :     aWordCB         ( pDialog, CUI_RES( CB_WORD ), *this ),
     262         [ #  # ]:          0 :     m_aAlternativesText  ( pDialog, CUI_RES( FT_THES_ALTERNATIVES ) ),
     263         [ #  # ]:          0 :     m_pAlternativesCT    ( new ThesaurusAlternativesCtrl_Impl( pDialog, *this ) ),
     264         [ #  # ]:          0 :     aReplaceText    ( pDialog, CUI_RES( FT_REPL ) ),
     265         [ #  # ]:          0 :     aReplaceEdit    ( pDialog, CUI_RES( ED_REPL ) ),
     266         [ #  # ]:          0 :     aFL             ( pDialog, CUI_RES( FL_VAR ) ),
     267         [ #  # ]:          0 :     aHelpBtn        ( pDialog, CUI_RES( BTN_THES_HELP ) ),
     268         [ #  # ]:          0 :     aLangMBtn       ( pDialog, CUI_RES( MB_LANGUAGE ) ),
     269         [ #  # ]:          0 :     aReplaceBtn     ( pDialog, CUI_RES( BTN_THES_OK ) ),
     270         [ #  # ]:          0 :     aCancelBtn      ( pDialog, CUI_RES( BTN_THES_CANCEL ) ),
     271         [ #  # ]:          0 :     aErrStr                 ( CUI_RES( STR_ERR_TEXTNOTFOUND ) ),
     272         [ #  # ]:          0 :     aVendorDefaultImage     ( CUI_RES( IMG_DEFAULT_VENDOR ) ),
     273                 :            :     xThesaurus      ( NULL ),
     274                 :            :     aLookUpText     (),
     275                 :            :     nLookUpLanguage ( LANGUAGE_NONE ),
     276 [ #  # ][ #  # ]:          0 :     m_bWordFound( false )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     277                 :            : {
     278                 :            :     // note: FreeResource must only be called in the c-tor of SvxThesaurusDialog
     279                 :            : 
     280                 :          0 :     aReplaceEdit.SetButton( &aReplaceBtn );
     281                 :            : 
     282         [ #  # ]:          0 :     aLeftBtn.SetClickHdl( LINK( this, SvxThesaurusDialog_Impl, LeftBtnHdl_Impl ) );
     283         [ #  # ]:          0 :     aWordCB.SetSelectHdl( LINK( this, SvxThesaurusDialog_Impl, WordSelectHdl_Impl ) );
     284         [ #  # ]:          0 :     aLangMBtn.SetSelectHdl( LINK( this, SvxThesaurusDialog_Impl, LanguageHdl_Impl ) );
     285         [ #  # ]:          0 :     m_pAlternativesCT->SetSelectHdl( LINK( this, SvxThesaurusDialog_Impl, AlternativesSelectHdl_Impl ));
     286         [ #  # ]:          0 :     m_pAlternativesCT->SetDoubleClickHdl( LINK( this, SvxThesaurusDialog_Impl, AlternativesDoubleClickHdl_Impl ));
     287                 :            : 
     288 [ #  # ][ #  # ]:          0 :     Application::PostUserEvent( STATIC_LINK( this, SvxThesaurusDialog_Impl, VendorImageInitHdl ) );
     289                 :          0 : }
     290                 :            : 
     291 [ #  # ][ #  # ]:          0 : SvxThesaurusDialog_Impl::~SvxThesaurusDialog_Impl()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     292                 :            : {
     293 [ #  # ][ #  # ]:          0 :     delete aLangMBtn.GetPopupMenu();
     294                 :          0 : }
     295                 :            : 
     296                 :          0 : uno::Sequence< uno::Reference< linguistic2::XMeaning > > SAL_CALL SvxThesaurusDialog_Impl::queryMeanings_Impl(
     297                 :            :         OUString& rTerm,
     298                 :            :         const lang::Locale& rLocale,
     299                 :            :         const beans::PropertyValues& rProperties )
     300                 :            :     throw(lang::IllegalArgumentException, uno::RuntimeException)
     301                 :            : {
     302                 :            :     uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeanings(
     303                 :          0 :             xThesaurus->queryMeanings( rTerm, rLocale, rProperties ) );
     304                 :            : 
     305                 :            :     // text with '.' at the end?
     306   [ #  #  #  # ]:          0 :     if ( 0 == aMeanings.getLength() && !rTerm.isEmpty() &&
         [ #  # ][ #  # ]
     307                 :          0 :         rTerm.getStr()[ rTerm.getLength() - 1 ] == '.')
     308                 :            :     {
     309                 :            :         // try again without trailing '.' chars. It may be a word at the
     310                 :            :         // end of a sentence and not an abbreviation...
     311 [ #  # ][ #  # ]:          0 :         String aTxt(comphelper::string::stripEnd(rTerm, '.'));
     312 [ #  # ][ #  # ]:          0 :         aMeanings = xThesaurus->queryMeanings( aTxt, rLocale, rProperties );
         [ #  # ][ #  # ]
                 [ #  # ]
     313         [ #  # ]:          0 :         if (aMeanings.getLength())
     314                 :            :         {
     315         [ #  # ]:          0 :             rTerm = aTxt;
     316         [ #  # ]:          0 :         }
     317                 :            :     }
     318                 :            : 
     319                 :          0 :     return aMeanings;
     320                 :            : }
     321                 :            : 
     322                 :          0 : bool SvxThesaurusDialog_Impl::UpdateAlternativesBox_Impl()
     323                 :            : {
     324         [ #  # ]:          0 :     lang::Locale aLocale( SvxCreateLocale( nLookUpLanguage ) );
     325                 :            :     uno::Sequence< uno::Reference< linguistic2::XMeaning > > aMeanings = queryMeanings_Impl(
     326 [ #  # ][ #  # ]:          0 :             aLookUpText, aLocale, uno::Sequence< beans::PropertyValue >() );
                 [ #  # ]
     327                 :          0 :     const sal_Int32 nMeanings = aMeanings.getLength();
     328                 :          0 :     const uno::Reference< linguistic2::XMeaning > *pMeanings = aMeanings.getConstArray();
     329                 :            : 
     330         [ #  # ]:          0 :     m_pAlternativesCT->SetUpdateMode( sal_False );
     331                 :            : 
     332                 :            :     // clear old user data of control before creating new ones via AddEntry below
     333         [ #  # ]:          0 :     m_pAlternativesCT->ClearExtraData();
     334                 :            : 
     335         [ #  # ]:          0 :     m_pAlternativesCT->Clear();
     336         [ #  # ]:          0 :     for (sal_Int32 i = 0;  i < nMeanings;  ++i)
     337                 :            :     {
     338 [ #  # ][ #  # ]:          0 :         OUString rMeaningTxt = pMeanings[i]->getMeaning();
     339 [ #  # ][ #  # ]:          0 :         uno::Sequence< OUString > aSynonyms( pMeanings[i]->querySynonyms() );
     340                 :          0 :         const sal_Int32 nSynonyms = aSynonyms.getLength();
     341                 :          0 :         const OUString *pSynonyms = aSynonyms.getConstArray();
     342                 :            :         DBG_ASSERT( !rMeaningTxt.isEmpty(), "meaning with empty text" );
     343                 :            :         DBG_ASSERT( nSynonyms > 0, "meaning without synonym" );
     344                 :            : 
     345 [ #  # ][ #  # ]:          0 :         m_pAlternativesCT->AddEntry( i + 1, rMeaningTxt, true );
                 [ #  # ]
     346         [ #  # ]:          0 :         for (sal_Int32 k = 0;  k < nSynonyms;  ++k)
     347 [ #  # ][ #  # ]:          0 :             m_pAlternativesCT->AddEntry( -1, pSynonyms[k], false );
                 [ #  # ]
     348         [ #  # ]:          0 :     }
     349                 :            : 
     350         [ #  # ]:          0 :     m_pAlternativesCT->SetUpdateMode( sal_True );
     351                 :            : 
     352         [ #  # ]:          0 :     return nMeanings > 0;
     353                 :            : }
     354                 :            : 
     355                 :          0 : void SvxThesaurusDialog_Impl::LookUp( const String &rText )
     356                 :            : {
     357 [ #  # ][ #  # ]:          0 :     if (rText != aWordCB.GetText()) // avoid moving of the cursor if the text is the same
     358                 :          0 :         aWordCB.SetText( rText );
     359                 :          0 :     LookUp_Impl();
     360                 :          0 : }
     361                 :            : 
     362                 :          0 : IMPL_LINK( SvxThesaurusDialog_Impl, LeftBtnHdl_Impl, Button *, pBtn )
     363                 :            : {
     364 [ #  # ][ #  # ]:          0 :     if (pBtn && aLookUpHistory.size() >= 2)
                 [ #  # ]
     365                 :            :     {
     366                 :          0 :         aLookUpHistory.pop();                       // remove current look up word from stack
     367         [ #  # ]:          0 :         aWordCB.SetText( aLookUpHistory.top() );    // retrieve previous look up word
     368                 :          0 :         aLookUpHistory.pop();
     369                 :          0 :         LookUp_Impl();
     370                 :            :     }
     371                 :          0 :     return 0;
     372                 :            : }
     373                 :            : 
     374                 :          0 : IMPL_LINK( SvxThesaurusDialog_Impl, LanguageHdl_Impl, MenuButton *, pBtn )
     375                 :            : {
     376                 :          0 :     PopupMenu *pMenu = aLangMBtn.GetPopupMenu();
     377 [ #  # ][ #  # ]:          0 :     if (pMenu && pBtn)
     378                 :            :     {
     379                 :          0 :         sal_uInt16 nItem = pBtn->GetCurItemId();
     380         [ #  # ]:          0 :         String aLangText( pMenu->GetItemText( nItem ) );
     381 [ #  # ][ #  # ]:          0 :         LanguageType nLang = SvtLanguageTable().GetType( aLangText );
                 [ #  # ]
     382                 :            :         DBG_ASSERT( nLang != LANGUAGE_NONE && nLang != LANGUAGE_DONTKNOW, "failed to get language" );
     383 [ #  # ][ #  # ]:          0 :         if (xThesaurus->hasLocale( SvxCreateLocale( nLang ) ))
         [ #  # ][ #  # ]
     384                 :          0 :             nLookUpLanguage = nLang;
     385         [ #  # ]:          0 :         m_pDialog->SetWindowTitle( nLang );
     386         [ #  # ]:          0 :         UpdateVendorImage();
     387 [ #  # ][ #  # ]:          0 :         LookUp_Impl();
     388                 :            :     }
     389                 :          0 :     return 0;
     390                 :            : }
     391                 :            : 
     392                 :          0 : void SvxThesaurusDialog_Impl::LookUp_Impl()
     393                 :            : {
     394         [ #  # ]:          0 :     String aText( aWordCB.GetText() );
     395                 :            : 
     396         [ #  # ]:          0 :     aLookUpText = OUString( aText );
     397 [ #  # ][ #  #  :          0 :     if (!aLookUpText.isEmpty() &&
             #  #  #  # ]
     398         [ #  # ]:          0 :             (aLookUpHistory.empty() || aLookUpText != aLookUpHistory.top()))
     399         [ #  # ]:          0 :         aLookUpHistory.push( aLookUpText );
     400                 :            : 
     401         [ #  # ]:          0 :     m_bWordFound = UpdateAlternativesBox_Impl();
     402         [ #  # ]:          0 :     m_pAlternativesCT->Enable( m_bWordFound );
     403                 :            : 
     404 [ #  # ][ #  # ]:          0 :     if ( aWordCB.GetEntryPos( aText ) == LISTBOX_ENTRY_NOTFOUND )
     405         [ #  # ]:          0 :         aWordCB.InsertEntry( aText );
     406                 :            : 
     407 [ #  # ][ #  # ]:          0 :     aReplaceEdit.SetText( String() );
                 [ #  # ]
     408 [ #  # ][ #  # ]:          0 :     aLeftBtn.Enable( aLookUpHistory.size() > 1 );
     409                 :          0 : }
     410                 :            : 
     411                 :          0 : IMPL_LINK( SvxThesaurusDialog_Impl, WordSelectHdl_Impl, ComboBox *, pBox )
     412                 :            : {
     413 [ #  # ][ #  # ]:          0 :     if (pBox && !aWordCB.IsTravelSelect())  // act only upon return key and not when traveling with cursor keys
                 [ #  # ]
     414                 :            :     {
     415         [ #  # ]:          0 :         sal_uInt16 nPos = pBox->GetSelectEntryPos();
     416         [ #  # ]:          0 :         String aStr( pBox->GetEntry( nPos ) );
     417 [ #  # ][ #  # ]:          0 :         aStr = linguistic::GetThesaurusReplaceText( aStr );
                 [ #  # ]
     418         [ #  # ]:          0 :         aWordCB.SetText( aStr );
     419 [ #  # ][ #  # ]:          0 :         LookUp_Impl();
     420                 :            :     }
     421                 :            : 
     422                 :          0 :     return 0;
     423                 :            : }
     424                 :            : 
     425                 :          0 : IMPL_LINK( SvxThesaurusDialog_Impl, AlternativesSelectHdl_Impl, SvxCheckListBox *, pBox )
     426                 :            : {
     427         [ #  # ]:          0 :     SvLBoxEntry *pEntry = pBox ? pBox->GetCurEntry() : NULL;
     428         [ #  # ]:          0 :     if (pEntry)
     429                 :            :     {
     430         [ #  # ]:          0 :         AlternativesExtraData * pData = m_pAlternativesCT->GetExtraData( pEntry );
     431         [ #  # ]:          0 :         String aStr;
     432 [ #  # ][ #  # ]:          0 :         if (pData && !pData->IsHeader())
                 [ #  # ]
     433                 :            :         {
     434         [ #  # ]:          0 :             aStr = pData->GetText();
     435 [ #  # ][ #  # ]:          0 :             aStr = linguistic::GetThesaurusReplaceText( aStr );
                 [ #  # ]
     436                 :            :         }
     437 [ #  # ][ #  # ]:          0 :         aReplaceEdit.SetText( aStr );
     438                 :            :     }
     439                 :          0 :     return 0;
     440                 :            : }
     441                 :            : 
     442                 :          0 : IMPL_LINK( SvxThesaurusDialog_Impl, AlternativesDoubleClickHdl_Impl, SvxCheckListBox *, pBox )
     443                 :            : {
     444         [ #  # ]:          0 :     SvLBoxEntry *pEntry = pBox ? pBox->GetCurEntry() : NULL;
     445         [ #  # ]:          0 :     if (pEntry)
     446                 :            :     {
     447         [ #  # ]:          0 :         AlternativesExtraData * pData = m_pAlternativesCT->GetExtraData( pEntry );
     448         [ #  # ]:          0 :         String aStr;
     449 [ #  # ][ #  # ]:          0 :         if (pData && !pData->IsHeader())
                 [ #  # ]
     450                 :            :         {
     451         [ #  # ]:          0 :             aStr = pData->GetText();
     452 [ #  # ][ #  # ]:          0 :             aStr = linguistic::GetThesaurusReplaceText( aStr );
                 [ #  # ]
     453                 :            :         }
     454                 :            : 
     455         [ #  # ]:          0 :         aWordCB.SetText( aStr );
     456         [ #  # ]:          0 :         if (aStr.Len() > 0)
     457 [ #  # ][ #  # ]:          0 :             LookUp_Impl();
     458                 :            :     }
     459                 :            : 
     460                 :            :     //! workaround to set the selection since calling SelectEntryPos within
     461                 :            :     //! the double click handler does not work
     462         [ #  # ]:          0 :     Application::PostUserEvent( STATIC_LINK( this, SvxThesaurusDialog_Impl, SelectFirstHdl_Impl ), pBox );
     463                 :          0 :     return 0;
     464                 :            : }
     465                 :            : 
     466                 :          0 : IMPL_STATIC_LINK( SvxThesaurusDialog_Impl, SelectFirstHdl_Impl, SvxCheckListBox *, pBox )
     467                 :            : {
     468                 :            :     (void) pThis;
     469 [ #  # ][ #  # ]:          0 :     if (pBox && pBox->GetEntryCount() >= 2)
                 [ #  # ]
     470                 :          0 :         pBox->SelectEntryPos( 1 );  // pos 0 is a 'header' that is not selectable
     471                 :          0 :     return 0;
     472                 :            : }
     473                 :            : 
     474                 :            : ////////////////////////////////////////////////////////////
     475                 :            : 
     476                 :          0 : static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
     477                 :            : {
     478         [ #  # ]:          0 :     Image aRes;
     479                 :            : 
     480                 :          0 :     OUString aTmp;
     481         [ #  # ]:          0 :     osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
     482                 :            : 
     483         [ #  # ]:          0 :     Graphic aGraphic;
     484         [ #  # ]:          0 :     const String aFilterName( RTL_CONSTASCII_USTRINGPARAM( IMP_PNG ) );
     485 [ #  # ][ #  # ]:          0 :     if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic, NULL, NULL ) )
         [ #  # ][ #  # ]
     486                 :            :     {
     487 [ #  # ][ #  # ]:          0 :         aRes = Image( aGraphic.GetBitmapEx() );
         [ #  # ][ #  # ]
                 [ #  # ]
     488                 :            :     }
     489 [ #  # ][ #  # ]:          0 :     return aRes;
     490                 :            : }
     491                 :            : 
     492                 :          0 : static String lcl_GetThesImplName( const lang::Locale &rLocale )
     493                 :            : {
     494         [ #  # ]:          0 :     String aRes;
     495                 :            : 
     496                 :          0 :     uno::Reference< linguistic2::XLinguServiceManager >     xLngMgr;
     497                 :            :     try
     498                 :            :     {
     499 [ #  # ][ #  # ]:          0 :         uno::Reference< lang::XMultiServiceFactory >  xMSF( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
     500         [ #  # ]:          0 :         xLngMgr = uno::Reference< linguistic2::XLinguServiceManager >( xMSF->createInstance(
     501                 :            :                 OUString( RTL_CONSTASCII_USTRINGPARAM(
     502 [ #  # ][ #  # ]:          0 :                     "com.sun.star.linguistic2.LinguServiceManager" ))), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     503                 :            : 
     504                 :            :         DBG_ASSERT( xLngMgr.is(), "LinguServiceManager missing" );
     505         [ #  # ]:          0 :         if (xLngMgr.is())
     506                 :            :         {
     507         [ #  # ]:          0 :             uno::Sequence< OUString > aServiceNames = xLngMgr->getConfiguredServices(
     508 [ #  # ][ #  # ]:          0 :                     OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.linguistic2.Thesaurus")), rLocale );
     509                 :            :             // there should be at most one thesaurus configured for each language
     510                 :            :             DBG_ASSERT( aServiceNames.getLength() <= 1, "more than one thesaurus found. Should not be possible" );
     511         [ #  # ]:          0 :             if (aServiceNames.getLength() == 1)
     512 [ #  # ][ #  # ]:          0 :                 aRes = aServiceNames[0];
                 [ #  # ]
     513         [ #  # ]:          0 :         }
     514                 :            :     }
     515         [ #  # ]:          0 :     catch (uno::Exception &e)
     516                 :            :     {
     517                 :            :         (void) e;
     518                 :            :         DBG_ASSERT( 0, "failed to get thesaurus" );
     519                 :            :     }
     520                 :            : 
     521                 :          0 :     return aRes;
     522                 :            : }
     523                 :            : 
     524                 :          0 : void SvxThesaurusDialog_Impl::UpdateVendorImage()
     525                 :            : {
     526         [ #  # ]:          0 :     m_pDialog->SetUpdateMode( sal_False );
     527                 :            : 
     528         [ #  # ]:          0 :     SvtLinguConfig aCfg;
     529 [ #  # ][ #  # ]:          0 :     if (aCfg.HasVendorImages( "ThesaurusDialogImage" ))
     530                 :            :     {
     531         [ #  # ]:          0 :         Image aImage;
     532 [ #  # ][ #  # ]:          0 :         String sThesImplName( lcl_GetThesImplName( SvxCreateLocale( nLookUpLanguage ) ) );
     533 [ #  # ][ #  # ]:          0 :         OUString aThesDialogImageUrl( aCfg.GetThesaurusDialogImage( sThesImplName ) );
     534 [ #  # ][ #  # ]:          0 :         if (sThesImplName.Len() > 0 && !aThesDialogImageUrl.isEmpty())
                 [ #  # ]
     535 [ #  # ][ #  # ]:          0 :             aImage = Image( lcl_GetImageFromPngUrl( aThesDialogImageUrl ) );
                 [ #  # ]
     536                 :            :         else
     537         [ #  # ]:          0 :             aImage = aVendorDefaultImage;
     538 [ #  # ][ #  # ]:          0 :         aVendorImageFI.SetImage( aImage );
                 [ #  # ]
     539                 :            :     }
     540                 :            : 
     541 [ #  # ][ #  # ]:          0 :     m_pDialog->SetUpdateMode( sal_True );
     542                 :          0 : }
     543                 :            : 
     544                 :          0 : IMPL_STATIC_LINK( SvxThesaurusDialog_Impl, VendorImageInitHdl, SvxThesaurusDialog_Impl *, EMPTYARG )
     545                 :            : {
     546         [ #  # ]:          0 :     pThis->m_pDialog->SetUpdateMode( sal_False );
     547                 :            : 
     548         [ #  # ]:          0 :     SvtLinguConfig aCfg;
     549 [ #  # ][ #  # ]:          0 :     if (aCfg.HasVendorImages( "ThesaurusDialogImage" ))
     550                 :            :     {
     551         [ #  # ]:          0 :         Image aImage( pThis->aVendorDefaultImage );
     552         [ #  # ]:          0 :         pThis->aVendorImageFI.SetImage( aImage );
     553         [ #  # ]:          0 :         pThis->aVendorImageFI.Show();
     554                 :            : 
     555                 :            :         // move down visible controls according to the vendor images height
     556         [ #  # ]:          0 :         Size aVendorSize = pThis->aVendorImageFI.GetSizePixel();
     557         [ #  # ]:          0 :         Size aImageSize  = pThis->aVendorImageFI.GetImage().GetSizePixel();
     558         [ #  # ]:          0 :         if (aImageSize.Height())
     559                 :            :         {
     560                 :          0 :             aVendorSize.Height() = aImageSize.Height();
     561         [ #  # ]:          0 :             if(aVendorSize.Width() < aImageSize.Width())
     562                 :          0 :                 aVendorSize.Width() = aImageSize.Width();
     563         [ #  # ]:          0 :             pThis->aVendorImageFI.SetSizePixel( aVendorSize );
     564                 :            :         }
     565                 :          0 :         const sal_Int32 nDiff = aVendorSize.Height();
     566         [ #  # ]:          0 :         pThis->aVendorImageFI.SetSizePixel( aVendorSize );
     567                 :            :         Control* aControls[] = {
     568                 :            :             &pThis->aLeftBtn,
     569                 :            :             &pThis->aWordText,
     570                 :            :             &pThis->aWordCB,
     571                 :            :             &pThis->m_aAlternativesText,
     572                 :          0 :             pThis->m_pAlternativesCT.get(),
     573                 :            :             &pThis->aReplaceText,
     574                 :            :             &pThis->aReplaceEdit,
     575                 :            :             &pThis->aFL,
     576                 :            :             &pThis->aHelpBtn,
     577                 :            :             &pThis->aLangMBtn,
     578                 :            :             &pThis->aReplaceBtn,
     579                 :            :             &pThis->aCancelBtn,
     580                 :            :             0
     581                 :          0 :         };
     582                 :          0 :         sal_Int32 nControl = 0;
     583         [ #  # ]:          0 :         while (aControls[nControl])
     584                 :            :         {
     585         [ #  # ]:          0 :             Point aPos = aControls[nControl]->GetPosPixel();
     586                 :          0 :             aPos.Y() += nDiff;
     587         [ #  # ]:          0 :             aControls[nControl]->SetPosPixel(aPos);
     588                 :          0 :             ++nControl;
     589                 :            :         }
     590         [ #  # ]:          0 :         Size aDlgSize = pThis->m_pDialog->GetSizePixel();
     591                 :          0 :         aDlgSize.Height() += nDiff;
     592         [ #  # ]:          0 :         pThis->m_pDialog->SetSizePixel( aDlgSize );
     593 [ #  # ][ #  # ]:          0 :         pThis->m_pDialog->Invalidate();
     594                 :            :     }
     595                 :            : 
     596         [ #  # ]:          0 :     pThis->UpdateVendorImage();
     597         [ #  # ]:          0 :     pThis->m_pDialog->SetUpdateMode( sal_True );
     598                 :            : 
     599         [ #  # ]:          0 :     return 0;
     600                 :            : };
     601                 :            : 
     602                 :            : // class SvxThesaurusDialog ----------------------------------------------
     603                 :            : 
     604                 :          0 : SvxThesaurusDialog::SvxThesaurusDialog(
     605                 :            :     Window* pParent,
     606                 :            :     uno::Reference< linguistic2::XThesaurus >  xThes,
     607                 :            :     const String &rWord,
     608                 :            :     LanguageType nLanguage ) :
     609                 :            : 
     610         [ #  # ]:          0 :     SvxStandardDialog( pParent, CUI_RES( RID_SVXDLG_THESAURUS ) )
     611                 :            : {
     612 [ #  # ][ #  # ]:          0 :     m_pImpl = std::auto_ptr< SvxThesaurusDialog_Impl >(new SvxThesaurusDialog_Impl( this ));
                 [ #  # ]
     613                 :            : 
     614         [ #  # ]:          0 :     m_pImpl->xThesaurus = xThes;
     615         [ #  # ]:          0 :     m_pImpl->aLookUpText = OUString( rWord );
     616                 :          0 :     m_pImpl->nLookUpLanguage = nLanguage;
     617         [ #  # ]:          0 :     if (rWord.Len() > 0)
     618 [ #  # ][ #  # ]:          0 :         m_pImpl->aLookUpHistory.push( rWord );
     619                 :            : 
     620         [ #  # ]:          0 :     FreeResource();
     621                 :            : 
     622         [ #  # ]:          0 :     OUString aTmp( rWord );
     623         [ #  # ]:          0 :     linguistic::RemoveHyphens( aTmp );
     624         [ #  # ]:          0 :     linguistic::ReplaceControlChars( aTmp );
     625         [ #  # ]:          0 :     String aTmp2( aTmp );
     626         [ #  # ]:          0 :     m_pImpl->aReplaceEdit.SetText( aTmp2 );
     627         [ #  # ]:          0 :     m_pImpl->aWordCB.InsertEntry( aTmp2 );
     628                 :            : 
     629         [ #  # ]:          0 :     m_pImpl->LookUp( aTmp2 );
     630         [ #  # ]:          0 :     m_pImpl->m_pAlternativesCT->GrabFocus();
     631         [ #  # ]:          0 :     m_pImpl->aLeftBtn.Enable( sal_False );
     632                 :            : 
     633                 :            :     // fill language menu button list
     634         [ #  # ]:          0 :     SvtLanguageTable aLangTab;
     635         [ #  # ]:          0 :     uno::Sequence< lang::Locale > aLocales;
     636         [ #  # ]:          0 :     if (m_pImpl->xThesaurus.is())
     637 [ #  # ][ #  # ]:          0 :         aLocales = m_pImpl->xThesaurus->getLocales();
         [ #  # ][ #  # ]
     638                 :          0 :     const sal_Int32 nLocales = aLocales.getLength();
     639                 :          0 :     const lang::Locale *pLocales = aLocales.getConstArray();
     640 [ #  # ][ #  # ]:          0 :     delete m_pImpl->aLangMBtn.GetPopupMenu();
     641 [ #  # ][ #  # ]:          0 :     PopupMenu* pMenu = new PopupMenu;
     642                 :          0 :     pMenu->SetMenuFlags( MENU_FLAG_NOAUTOMNEMONICS );
     643         [ #  # ]:          0 :     std::vector< OUString > aLangVec;
     644         [ #  # ]:          0 :     for (sal_Int32 i = 0;  i < nLocales;  ++i )
     645                 :            :     {
     646         [ #  # ]:          0 :         const LanguageType nLang = SvxLocaleToLanguage( pLocales[i] );
     647                 :            :         DBG_ASSERT( nLang != LANGUAGE_NONE && nLang != LANGUAGE_DONTKNOW, "failed to get language" );
     648 [ #  # ][ #  # ]:          0 :         aLangVec.push_back( aLangTab.GetString( nLang ) );
     649                 :            :     }
     650         [ #  # ]:          0 :     std::sort( aLangVec.begin(), aLangVec.end() );
     651         [ #  # ]:          0 :     for (size_t i = 0;  i < aLangVec.size();  ++i)
     652 [ #  # ][ #  # ]:          0 :         pMenu->InsertItem( (sal_uInt16)i+1, aLangVec[i] );  // menu items should be enumerated from 1 and not 0
                 [ #  # ]
     653         [ #  # ]:          0 :     m_pImpl->aLangMBtn.SetPopupMenu( pMenu );
     654                 :            : 
     655         [ #  # ]:          0 :     SetWindowTitle( nLanguage );
     656                 :            : 
     657                 :            :     // disable controls if service is missing
     658         [ #  # ]:          0 :     if (!m_pImpl->xThesaurus.is())
     659 [ #  # ][ #  # ]:          0 :         Enable( sal_False );
         [ #  # ][ #  # ]
     660                 :          0 : }
     661                 :            : 
     662         [ #  # ]:          0 : SvxThesaurusDialog::~SvxThesaurusDialog()
     663                 :            : {
     664         [ #  # ]:          0 : }
     665                 :            : 
     666                 :          0 : void SvxThesaurusDialog::SetWindowTitle( LanguageType nLanguage )
     667                 :            : {
     668                 :            :     // adjust language
     669         [ #  # ]:          0 :     String aStr( GetText() );
     670 [ #  # ][ #  # ]:          0 :     aStr.Erase( aStr.Search( sal_Unicode( '(' ) ) - 1 );
     671 [ #  # ][ #  # ]:          0 :     aStr.Append( rtl::OUString(" (") );
                 [ #  # ]
     672 [ #  # ][ #  # ]:          0 :     aStr += SvtLanguageTable().GetLanguageString( nLanguage );
         [ #  # ][ #  # ]
                 [ #  # ]
     673         [ #  # ]:          0 :     aStr.Append( sal_Unicode( ')' ) );
     674 [ #  # ][ #  # ]:          0 :     SetText( aStr );    // set window title
     675                 :          0 : }
     676                 :            : 
     677                 :          0 : String SvxThesaurusDialog::GetWord()
     678                 :            : {
     679                 :          0 :     return m_pImpl->aReplaceEdit.GetText();
     680                 :            : }
     681                 :            : 
     682                 :          0 : sal_uInt16 SvxThesaurusDialog::GetLanguage() const
     683                 :            : {
     684                 :          0 :     return m_pImpl->nLookUpLanguage;
     685                 :            : }
     686                 :            : 
     687                 :          0 : void SvxThesaurusDialog::Apply()
     688                 :            : {
     689                 :          0 : }
     690                 :            : 
     691                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10