LCOV - code coverage report
Current view: top level - basctl/source/dlged - managelang.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 154 0.0 %
Date: 2014-04-14 Functions: 0 18 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "basidesh.hxx"
      21             : #include "basobj.hxx"
      22             : #include "iderdll.hxx"
      23             : #include "iderid.hxx"
      24             : #include "localizationmgr.hxx"
      25             : #include "managelang.hxx"
      26             : 
      27             : #include "dlgresid.hrc"
      28             : #include "helpid.hrc"
      29             : 
      30             : #include <com/sun/star/i18n/Boundary.hpp>
      31             : #include <com/sun/star/i18n/WordType.hpp>
      32             : #include <com/sun/star/i18n/XBreakIterator.hpp>
      33             : #include <editeng/unolingu.hxx>
      34             : #include <sfx2/bindings.hxx>
      35             : #include <svtools/langtab.hxx>
      36             : #include <svx/langbox.hxx>
      37             : #include <vcl/unohelp.hxx>
      38             : #include <vcl/svapp.hxx>
      39             : #include <vcl/msgbox.hxx>
      40             : #include <vcl/settings.hxx>
      41             : 
      42             : namespace basctl
      43             : {
      44             : 
      45             : using namespace ::com::sun::star::i18n;
      46             : using namespace ::com::sun::star::lang;
      47             : using namespace ::com::sun::star::resource;
      48             : using namespace ::com::sun::star::uno;
      49             : 
      50           0 : bool localesAreEqual( const Locale& rLocaleLeft, const Locale& rLocaleRight )
      51             : {
      52           0 :     bool bRet = ( rLocaleLeft.Language.equals( rLocaleRight.Language ) &&
      53           0 :                   rLocaleLeft.Country.equals( rLocaleRight.Country ) &&
      54           0 :                   rLocaleLeft.Variant.equals( rLocaleRight.Variant ) );
      55           0 :     return bRet;
      56             : }
      57             : 
      58           0 : ManageLanguageDialog::ManageLanguageDialog(Window* pParent, boost::shared_ptr<LocalizationMgr> xLMgr)
      59             :     : ModalDialog(pParent, "ManageLanguagesDialog", "modules/BasicIDE/ui/managelanguages.ui")
      60             :     , m_xLocalizationMgr(xLMgr)
      61             :     , m_sDefLangStr(IDE_RESSTR(RID_STR_DEF_LANG))
      62             :     , m_sDeleteStr(IDE_RESSTR(RID_STR_DELETE))
      63           0 :     , m_sCreateLangStr(IDE_RESSTR(RID_STR_CREATE_LANG))
      64             : {
      65           0 :     get(m_pLanguageLB, "treeview");
      66           0 :     m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10);
      67           0 :     m_pLanguageLB->set_width_request(m_pLanguageLB->approximate_char_width() * 50);
      68           0 :     get(m_pAddPB, "add");
      69           0 :     get(m_pDeletePB, "delete");
      70           0 :     get(m_pMakeDefPB, "default");
      71             : 
      72           0 :     Init();
      73           0 :     FillLanguageBox();
      74           0 :     SelectHdl( NULL );
      75           0 : }
      76             : 
      77           0 : ManageLanguageDialog::~ManageLanguageDialog()
      78             : {
      79           0 :     ClearLanguageBox();
      80           0 : }
      81             : 
      82           0 : void ManageLanguageDialog::Init()
      83             : {
      84             :     // get current IDE
      85           0 :     Shell* pShell = GetShell();
      86           0 :     OUString sLibName = pShell->GetCurLibName();
      87             :     // set dialog title with library name
      88           0 :     OUString sText = GetText();
      89           0 :     sText = sText.replaceAll("$1", sLibName);
      90           0 :     SetText( sText );
      91             :     // set handler
      92           0 :     m_pAddPB->SetClickHdl( LINK( this, ManageLanguageDialog, AddHdl ) );
      93           0 :     m_pDeletePB->SetClickHdl( LINK( this, ManageLanguageDialog, DeleteHdl ) );
      94           0 :     m_pMakeDefPB->SetClickHdl( LINK( this, ManageLanguageDialog, MakeDefHdl ) );
      95           0 :     m_pLanguageLB->SetSelectHdl( LINK( this, ManageLanguageDialog, SelectHdl ) );
      96             : 
      97           0 :     m_pLanguageLB->EnableMultiSelection( true );
      98           0 : }
      99             : 
     100           0 : void ManageLanguageDialog::FillLanguageBox()
     101             : {
     102             :     DBG_ASSERT( m_xLocalizationMgr, "ManageLanguageDialog::FillLanguageBox(): no localization manager" );
     103             : 
     104           0 :     if ( m_xLocalizationMgr->isLibraryLocalized() )
     105             :     {
     106           0 :         SvtLanguageTable aLangTable;
     107           0 :         Locale aDefaultLocale = m_xLocalizationMgr->getStringResourceManager()->getDefaultLocale();
     108           0 :         Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
     109           0 :         const Locale* pLocale = aLocaleSeq.getConstArray();
     110           0 :         sal_Int32 i, nCount = aLocaleSeq.getLength();
     111           0 :         for ( i = 0;  i < nCount;  ++i )
     112             :         {
     113           0 :             bool bIsDefault = localesAreEqual( aDefaultLocale, pLocale[i] );
     114           0 :             LanguageType eLangType = LanguageTag::convertToLanguageType( pLocale[i] );
     115           0 :             OUString sLanguage = aLangTable.GetString( eLangType );
     116           0 :             if ( bIsDefault )
     117             :             {
     118           0 :                 sLanguage += " " + m_sDefLangStr;
     119             :             }
     120           0 :             sal_uInt16 nPos = m_pLanguageLB->InsertEntry( sLanguage );
     121           0 :             m_pLanguageLB->SetEntryData( nPos, new LanguageEntry( sLanguage, pLocale[i], bIsDefault ) );
     122           0 :         }
     123             :     }
     124             :     else
     125           0 :         m_pLanguageLB->InsertEntry( m_sCreateLangStr );
     126           0 : }
     127             : 
     128           0 : void ManageLanguageDialog::ClearLanguageBox()
     129             : {
     130           0 :     sal_uInt16 i, nCount = m_pLanguageLB->GetEntryCount();
     131           0 :     for ( i = 0; i < nCount; ++i )
     132             :     {
     133           0 :         LanguageEntry* pEntry = (LanguageEntry*)( m_pLanguageLB->GetEntryData(i) );
     134           0 :         delete pEntry;
     135             :     }
     136           0 :     m_pLanguageLB->Clear();
     137           0 : }
     138             : 
     139           0 : IMPL_LINK_NOARG(ManageLanguageDialog, AddHdl)
     140             : {
     141           0 :     SetDefaultLanguageDialog aDlg( this, m_xLocalizationMgr );
     142           0 :     if ( RET_OK == aDlg.Execute() )
     143             :     {
     144             :         // add new locales
     145           0 :         Sequence< Locale > aLocaleSeq = aDlg.GetLocales();
     146           0 :         m_xLocalizationMgr->handleAddLocales( aLocaleSeq );
     147             :         // update listbox
     148           0 :         ClearLanguageBox();
     149           0 :         FillLanguageBox();
     150             : 
     151           0 :         if (SfxBindings* pBindings = GetBindingsPtr())
     152           0 :             pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
     153             :     }
     154           0 :     return 1;
     155             : }
     156             : 
     157           0 : IMPL_LINK_NOARG(ManageLanguageDialog, DeleteHdl)
     158             : {
     159           0 :     QueryBox aQBox( this, IDEResId( RID_QRYBOX_LANGUAGE ) );
     160           0 :     aQBox.SetButtonText( RET_OK, m_sDeleteStr );
     161           0 :     if ( aQBox.Execute() == RET_OK )
     162             :     {
     163           0 :         sal_uInt16 i, nCount = m_pLanguageLB->GetSelectEntryCount();
     164           0 :         sal_uInt16 nPos = m_pLanguageLB->GetSelectEntryPos();
     165             :         // remove locales
     166           0 :         Sequence< Locale > aLocaleSeq( nCount );
     167           0 :         for ( i = 0; i < nCount; ++i )
     168             :         {
     169           0 :             sal_uInt16 nSelPos = m_pLanguageLB->GetSelectEntryPos(i);
     170           0 :             LanguageEntry* pEntry = (LanguageEntry*)( m_pLanguageLB->GetEntryData( nSelPos ) );
     171           0 :             if ( pEntry )
     172           0 :                 aLocaleSeq[i] = pEntry->m_aLocale;
     173             :         }
     174           0 :         m_xLocalizationMgr->handleRemoveLocales( aLocaleSeq );
     175             :         // update listbox
     176           0 :         ClearLanguageBox();
     177           0 :         FillLanguageBox();
     178             :         // reset selection
     179           0 :         nCount = m_pLanguageLB->GetEntryCount();
     180           0 :         if ( nCount <= nPos )
     181           0 :             nPos = nCount - 1;
     182           0 :         m_pLanguageLB->SelectEntryPos( nPos );
     183           0 :         SelectHdl( NULL );
     184             :     }
     185           0 :     return 1;
     186             : }
     187             : 
     188           0 : IMPL_LINK_NOARG(ManageLanguageDialog, MakeDefHdl)
     189             : {
     190           0 :     sal_uInt16 nPos = m_pLanguageLB->GetSelectEntryPos();
     191           0 :     LanguageEntry* pSelectEntry = (LanguageEntry*)( m_pLanguageLB->GetEntryData( nPos ) );
     192           0 :     if ( pSelectEntry && !pSelectEntry->m_bIsDefault )
     193             :     {
     194             :         // set new default entry
     195           0 :         m_xLocalizationMgr->handleSetDefaultLocale( pSelectEntry->m_aLocale );
     196             :         // update Listbox
     197           0 :         ClearLanguageBox();
     198           0 :         FillLanguageBox();
     199             :         // reset selection
     200           0 :         m_pLanguageLB->SelectEntryPos( nPos );
     201           0 :         SelectHdl( NULL );
     202             :     }
     203             : 
     204           0 :     return 1;
     205             : }
     206             : 
     207           0 : IMPL_LINK_NOARG(ManageLanguageDialog, SelectHdl)
     208             : {
     209           0 :     sal_uInt16 nCount = m_pLanguageLB->GetEntryCount();
     210           0 :     bool bEmpty = ( !nCount ||
     211           0 :                     m_pLanguageLB->GetEntryPos( m_sCreateLangStr ) != LISTBOX_ENTRY_NOTFOUND );
     212           0 :     bool bSelect = ( m_pLanguageLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND );
     213           0 :     bool bEnable = ( !bEmpty && bSelect != false );
     214             : 
     215           0 :     m_pDeletePB->Enable( bEnable != false );
     216           0 :     m_pMakeDefPB->Enable( bEnable != false && nCount > 1 && m_pLanguageLB->GetSelectEntryCount() == 1 );
     217             : 
     218           0 :     return 1;
     219             : }
     220             : 
     221             : // class SetDefaultLanguageDialog -----------------------------------------------
     222             : 
     223           0 : SetDefaultLanguageDialog::SetDefaultLanguageDialog(Window* pParent, boost::shared_ptr<LocalizationMgr> xLMgr)
     224             :     : ModalDialog(pParent, "DefaultLanguageDialog", "modules/BasicIDE/ui/defaultlanguage.ui")
     225             :     , m_pCheckLangLB(NULL)
     226           0 :     , m_xLocalizationMgr(xLMgr)
     227             : {
     228           0 :     get(m_pLanguageLB, "entries");
     229           0 :     get(m_pCheckLangLB, "checkedentries");
     230           0 :     get(m_pDefinedFT, "defined");
     231           0 :     get(m_pAddedFT, "added");
     232           0 :     get(m_pLanguageFT, "defaultlabel");
     233           0 :     get(m_pCheckLangFT, "checkedlabel");
     234             : 
     235           0 :     m_pLanguageLB->set_height_request(m_pLanguageLB->GetTextHeight() * 10);
     236           0 :     m_pCheckLangLB->set_height_request(m_pCheckLangLB->GetTextHeight() * 10);
     237             : 
     238           0 :     if (m_xLocalizationMgr->isLibraryLocalized())
     239             :     {
     240             :         // change to "Add Interface Language" mode
     241           0 :         m_pLanguageLB->Hide();
     242           0 :         m_pCheckLangLB->Show();
     243           0 :         SetText(get<FixedText>("alttitle")->GetText());
     244           0 :         m_pLanguageFT->Hide();
     245           0 :         m_pCheckLangFT->Show();
     246           0 :         m_pDefinedFT->Hide();
     247           0 :         m_pAddedFT->Show();
     248             :     }
     249             : 
     250           0 :     FillLanguageBox();
     251           0 : }
     252             : 
     253           0 : void SetDefaultLanguageDialog::FillLanguageBox()
     254             : {
     255             :     // fill list with all languages
     256           0 :     m_pLanguageLB->SetLanguageList( LANG_LIST_ALL, false );
     257             :     // remove the already localized languages
     258           0 :     Sequence< Locale > aLocaleSeq = m_xLocalizationMgr->getStringResourceManager()->getLocales();
     259           0 :     const Locale* pLocale = aLocaleSeq.getConstArray();
     260           0 :     sal_Int32 i, nCount = aLocaleSeq.getLength();
     261           0 :     for ( i = 0;  i < nCount;  ++i )
     262           0 :         m_pLanguageLB->RemoveLanguage( LanguageTag::convertToLanguageType( pLocale[i] ) );
     263             : 
     264             :     // fill checklistbox if not in default mode
     265           0 :     if ( m_xLocalizationMgr->isLibraryLocalized() )
     266             :     {
     267           0 :         sal_uInt16 j, nCount_ = m_pLanguageLB->GetEntryCount();
     268           0 :         for ( j = 0;  j < nCount_;  ++j )
     269             :         {
     270             :             m_pCheckLangLB->InsertEntry(
     271           0 :                 m_pLanguageLB->GetEntry(j), LISTBOX_APPEND, m_pLanguageLB->GetEntryData(j) );
     272             :         }
     273           0 :         m_pLanguageLB = NULL;
     274             :     }
     275             :     else
     276             :         // preselect current UI language
     277           0 :         m_pLanguageLB->SelectLanguage( Application::GetSettings().GetUILanguageTag().getLanguageType() );
     278           0 : }
     279             : 
     280           0 : Sequence< Locale > SetDefaultLanguageDialog::GetLocales() const
     281             : {
     282           0 :     bool bNotLocalized = !m_xLocalizationMgr->isLibraryLocalized();
     283           0 :     sal_Int32 nSize = bNotLocalized ? 1 : m_pCheckLangLB->GetCheckedEntryCount();
     284           0 :     Sequence< Locale > aLocaleSeq( nSize );
     285           0 :     if ( bNotLocalized )
     286             :     {
     287           0 :         aLocaleSeq[0] = LanguageTag( m_pLanguageLB->GetSelectLanguage() ).getLocale();
     288             :     }
     289             :     else
     290             :     {
     291           0 :         sal_uInt16 i, nCount = static_cast< sal_uInt16 >( m_pCheckLangLB->GetEntryCount() );
     292           0 :         sal_Int32 j = 0;
     293           0 :         for ( i = 0; i < nCount; ++i )
     294             :         {
     295           0 :             if ( m_pCheckLangLB->IsChecked(i) )
     296             :             {
     297           0 :                 LanguageType eType = LanguageType( (sal_uLong)m_pCheckLangLB->GetEntryData(i) );
     298           0 :                 aLocaleSeq[j++] = LanguageTag::convertToLocale( eType );
     299             :             }
     300             :         }
     301             :         DBG_ASSERT( nSize == j, "SetDefaultLanguageDialog::GetLocales(): invalid indexes" );
     302             :     }
     303           0 :     return aLocaleSeq;
     304             : }
     305             : 
     306             : } // namespace basctl
     307             : 
     308             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10