LCOV - code coverage report
Current view: top level - svx/source/dialog - txencbox.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 103 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 13 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 <config_features.h>
      21             : 
      22             : #include "svx/txencbox.hxx"
      23             : #include "svx/txenctab.hxx"
      24             : #include <svx/dialogs.hrc>
      25             : #if HAVE_FEATURE_DBCONNECTIVITY
      26             : #include "svx/dbcharsethelper.hxx"
      27             : #endif
      28             : #include <vcl/builderfactory.hxx>
      29             : #include <vcl/svapp.hxx>
      30             : #include <vcl/settings.hxx>
      31             : #include <rtl/tencinfo.h>
      32             : #include <rtl/locale.h>
      33             : #include <rtl/strbuf.hxx>
      34             : #include <osl/nlsupport.h>
      35             : 
      36           0 : SvxTextEncodingBox::SvxTextEncodingBox( vcl::Window* pParent, WinBits nBits )
      37           0 :     : ListBox( pParent, nBits )
      38             : {
      39           0 :     m_pEncTable = new SvxTextEncodingTable;
      40           0 : }
      41             : 
      42           0 : VCL_BUILDER_DECL_FACTORY(SvxTextEncodingBox)
      43             : {
      44           0 :     WinBits nWinBits = WB_LEFT|WB_VCENTER|WB_3DLOOK|WB_SIMPLEMODE;
      45           0 :     bool bDropdown = VclBuilder::extractDropdown(rMap);
      46           0 :     if (bDropdown)
      47           0 :         nWinBits |= WB_DROPDOWN;
      48           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      49           0 :     if (!sBorder.isEmpty())
      50           0 :         nWinBits |= WB_BORDER;
      51           0 :     VclPtrInstance<SvxTextEncodingBox> pListBox(pParent, nWinBits);
      52           0 :     if (bDropdown)
      53           0 :         pListBox->EnableAutoSize(true);
      54           0 :     rRet = pListBox;
      55           0 : }
      56             : 
      57           0 : SvxTextEncodingBox::~SvxTextEncodingBox()
      58             : {
      59           0 :     disposeOnce();
      60           0 : }
      61             : 
      62           0 : void SvxTextEncodingBox::dispose()
      63             : {
      64           0 :     delete m_pEncTable;
      65           0 :     ListBox::dispose();
      66           0 : }
      67             : 
      68           0 : sal_Int32 SvxTextEncodingBox::EncodingToPos_Impl( rtl_TextEncoding nEnc ) const
      69             : {
      70           0 :     sal_Int32 nCount = GetEntryCount();
      71           0 :     for ( sal_Int32 i=0; i<nCount; i++ )
      72             :     {
      73           0 :         if ( nEnc == rtl_TextEncoding( reinterpret_cast<sal_uIntPtr>(GetEntryData(i)) ) )
      74           0 :             return i;
      75             :     }
      76           0 :     return LISTBOX_ENTRY_NOTFOUND;
      77             : }
      78             : 
      79             : 
      80             : 
      81           0 : void SvxTextEncodingBox::FillFromTextEncodingTable(
      82             :         bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags,
      83             :         sal_uInt32 nButIncludeInfoFlags )
      84             : {
      85             :     rtl_TextEncodingInfo aInfo;
      86           0 :     aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
      87           0 :     sal_uInt32 nCount = m_pEncTable->Count();
      88           0 :     for ( sal_uInt32 j=0; j<nCount; j++ )
      89             :     {
      90           0 :         bool bInsert = true;
      91           0 :         rtl_TextEncoding nEnc = rtl_TextEncoding( m_pEncTable->GetValue( j ) );
      92           0 :         if ( nExcludeInfoFlags )
      93             :         {
      94           0 :             if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
      95           0 :                 bInsert = false;
      96             :             else
      97             :             {
      98           0 :                 if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
      99             :                 {
     100           0 :                     if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
     101           0 :                             ((nEnc == RTL_TEXTENCODING_UCS2) ||
     102             :                             nEnc == RTL_TEXTENCODING_UCS4) )
     103           0 :                         bInsert = false;    // InfoFlags don't work for Unicode :-(
     104             :                 }
     105           0 :                 else if ( (aInfo.Flags & nButIncludeInfoFlags) == 0 )
     106           0 :                     bInsert = false;
     107             :             }
     108             :         }
     109           0 :         if ( bInsert )
     110             :         {
     111           0 :             if ( bExcludeImportSubsets )
     112             :             {
     113           0 :                 switch ( nEnc )
     114             :                 {
     115             :                     // subsets of RTL_TEXTENCODING_GB_18030
     116             :                     case RTL_TEXTENCODING_GB_2312 :
     117             :                     case RTL_TEXTENCODING_GBK :
     118             :                     case RTL_TEXTENCODING_MS_936 :
     119           0 :                         bInsert = false;
     120           0 :                     break;
     121             :                 }
     122             :             }
     123           0 :             if ( bInsert )
     124           0 :                 InsertTextEncoding( nEnc, m_pEncTable->GetString( j ) );
     125             :         }
     126             :     }
     127           0 : }
     128             : 
     129             : 
     130             : 
     131           0 : void SvxTextEncodingBox::FillFromDbTextEncodingMap(
     132             :         bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags,
     133             :         sal_uInt32 nButIncludeInfoFlags )
     134             : {
     135             : #if !HAVE_FEATURE_DBCONNECTIVITY
     136             :     (void)bExcludeImportSubsets;
     137             :     (void)nExcludeInfoFlags;
     138             :     (void)nButIncludeInfoFlags;
     139             : #else
     140             :     rtl_TextEncodingInfo aInfo;
     141           0 :     aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
     142           0 :     ::std::vector< rtl_TextEncoding > aEncs;
     143           0 :     sal_Int32 nCount = svxform::charset_helper::getSupportedTextEncodings( aEncs );
     144           0 :     for ( sal_Int32 j=0; j<nCount; j++ )
     145             :     {
     146           0 :         bool bInsert = true;
     147           0 :         rtl_TextEncoding nEnc = rtl_TextEncoding( aEncs[j] );
     148           0 :         if ( nExcludeInfoFlags )
     149             :         {
     150           0 :             if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
     151           0 :                 bInsert = false;
     152             :             else
     153             :             {
     154           0 :                 if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
     155             :                 {
     156           0 :                     if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
     157           0 :                             ((nEnc == RTL_TEXTENCODING_UCS2) ||
     158             :                             nEnc == RTL_TEXTENCODING_UCS4) )
     159           0 :                         bInsert = false;    // InfoFlags don't work for Unicode :-(
     160             :                 }
     161           0 :                 else if ( (aInfo.Flags & nButIncludeInfoFlags) == 0 )
     162           0 :                     bInsert = false;
     163             :             }
     164             :         }
     165           0 :         if ( bInsert )
     166             :         {
     167           0 :             if ( bExcludeImportSubsets )
     168             :             {
     169           0 :                 switch ( nEnc )
     170             :                 {
     171             :                     // subsets of RTL_TEXTENCODING_GB_18030
     172             :                     case RTL_TEXTENCODING_GB_2312 :
     173             :                     case RTL_TEXTENCODING_GBK :
     174             :                     case RTL_TEXTENCODING_MS_936 :
     175           0 :                         bInsert = false;
     176           0 :                     break;
     177             :                 }
     178             :             }
     179             :             // CharsetMap offers a RTL_TEXTENCODING_DONTKNOW for internal use,
     180             :             // makes no sense here and would result in an empty string as list
     181             :             // entry.
     182           0 :             if ( bInsert && nEnc != RTL_TEXTENCODING_DONTKNOW )
     183           0 :                 InsertTextEncoding( nEnc );
     184             :         }
     185           0 :     }
     186             : #endif
     187           0 : }
     188             : 
     189             : 
     190             : 
     191           0 : void SvxTextEncodingBox::FillWithMimeAndSelectBest()
     192             : {
     193           0 :     FillFromTextEncodingTable( false, 0xffffffff, RTL_TEXTENCODING_INFO_MIME );
     194           0 :     rtl_TextEncoding nEnc = SvtSysLocale::GetBestMimeEncoding();
     195           0 :     SelectTextEncoding( nEnc );
     196           0 : }
     197             : 
     198             : 
     199             : 
     200           0 : void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc,
     201             :             const OUString& rEntry, sal_Int32 nPos )
     202             : {
     203           0 :     sal_Int32 nAt = InsertEntry( rEntry, nPos );
     204           0 :     SetEntryData( nAt, reinterpret_cast<void*>(nEnc) );
     205           0 : }
     206             : 
     207             : 
     208             : 
     209           0 : void SvxTextEncodingBox::InsertTextEncoding( const rtl_TextEncoding nEnc, sal_Int32 nPos )
     210             : {
     211           0 :     const OUString& rEntry = m_pEncTable->GetTextString( nEnc );
     212           0 :     if ( !rEntry.isEmpty() )
     213           0 :         InsertTextEncoding( nEnc, rEntry, nPos );
     214             :     else
     215           0 :         SAL_WARN( "svx.dialog", "SvxTextEncodingBox::InsertTextEncoding: no resource string for text encoding: " << static_cast<sal_Int32>( nEnc ) );
     216           0 : }
     217             : 
     218             : 
     219             : 
     220           0 : rtl_TextEncoding SvxTextEncodingBox::GetSelectTextEncoding() const
     221             : {
     222           0 :     sal_Int32 nPos = GetSelectEntryPos();
     223             : 
     224           0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     225           0 :         return rtl_TextEncoding( reinterpret_cast<sal_uIntPtr>(GetEntryData(nPos)) );
     226             :     else
     227           0 :         return RTL_TEXTENCODING_DONTKNOW;
     228             : }
     229             : 
     230             : 
     231             : 
     232           0 : void SvxTextEncodingBox::SelectTextEncoding( const rtl_TextEncoding nEnc, bool bSelect )
     233             : {
     234           0 :     sal_Int32 nAt = EncodingToPos_Impl( nEnc );
     235             : 
     236           0 :     if ( nAt != LISTBOX_ENTRY_NOTFOUND )
     237           0 :         SelectEntryPos( nAt, bSelect );
     238           0 : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11