LCOV - code coverage report
Current view: top level - svx/source/dialog - txencbox.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 99 1.0 %
Date: 2014-11-03 Functions: 2 14 14.3 %
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/builder.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 : extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeSvxTextEncodingBox(vcl::Window *pParent, VclBuilder::stringmap &rMap)
      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 :     SvxTextEncodingBox *pListBox = new SvxTextEncodingBox(pParent, nWinBits);
      52           0 :     if (bDropdown)
      53           0 :         pListBox->EnableAutoSize(true);
      54             : 
      55           0 :     return pListBox;
      56             : }
      57             : 
      58             : 
      59             : 
      60           0 : SvxTextEncodingBox::~SvxTextEncodingBox()
      61             : {
      62           0 :     delete m_pEncTable;
      63           0 : }
      64             : 
      65             : 
      66             : 
      67           0 : sal_Int32 SvxTextEncodingBox::EncodingToPos_Impl( rtl_TextEncoding nEnc ) const
      68             : {
      69           0 :     sal_Int32 nCount = GetEntryCount();
      70           0 :     for ( sal_Int32 i=0; i<nCount; i++ )
      71             :     {
      72           0 :         if ( nEnc == rtl_TextEncoding( reinterpret_cast<sal_uIntPtr>(GetEntryData(i)) ) )
      73           0 :             return i;
      74             :     }
      75           0 :     return LISTBOX_ENTRY_NOTFOUND;
      76             : }
      77             : 
      78             : 
      79             : 
      80           0 : void SvxTextEncodingBox::FillFromTextEncodingTable(
      81             :         bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags,
      82             :         sal_uInt32 nButIncludeInfoFlags )
      83             : {
      84             :     rtl_TextEncodingInfo aInfo;
      85           0 :     aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
      86           0 :     sal_uInt32 nCount = m_pEncTable->Count();
      87           0 :     for ( sal_uInt32 j=0; j<nCount; j++ )
      88             :     {
      89           0 :         bool bInsert = true;
      90           0 :         rtl_TextEncoding nEnc = rtl_TextEncoding( m_pEncTable->GetValue( j ) );
      91           0 :         if ( nExcludeInfoFlags )
      92             :         {
      93           0 :             if ( !rtl_getTextEncodingInfo( nEnc, &aInfo ) )
      94           0 :                 bInsert = false;
      95             :             else
      96             :             {
      97           0 :                 if ( (aInfo.Flags & nExcludeInfoFlags) == 0 )
      98             :                 {
      99           0 :                     if ( (nExcludeInfoFlags & RTL_TEXTENCODING_INFO_UNICODE) &&
     100           0 :                             ((nEnc == RTL_TEXTENCODING_UCS2) ||
     101             :                             nEnc == RTL_TEXTENCODING_UCS4) )
     102           0 :                         bInsert = false;    // InfoFlags don't work for Unicode :-(
     103             :                 }
     104           0 :                 else if ( (aInfo.Flags & nButIncludeInfoFlags) == 0 )
     105           0 :                     bInsert = false;
     106             :             }
     107             :         }
     108           0 :         if ( bInsert )
     109             :         {
     110           0 :             if ( bExcludeImportSubsets )
     111             :             {
     112           0 :                 switch ( nEnc )
     113             :                 {
     114             :                     // subsets of RTL_TEXTENCODING_GB_18030
     115             :                     case RTL_TEXTENCODING_GB_2312 :
     116             :                     case RTL_TEXTENCODING_GBK :
     117             :                     case RTL_TEXTENCODING_MS_936 :
     118           0 :                         bInsert = false;
     119           0 :                     break;
     120             :                 }
     121             :             }
     122           0 :             if ( bInsert )
     123           0 :                 InsertTextEncoding( nEnc, m_pEncTable->GetString( j ) );
     124             :         }
     125             :     }
     126           0 : }
     127             : 
     128             : 
     129             : 
     130           0 : void SvxTextEncodingBox::FillFromDbTextEncodingMap(
     131             :         bool bExcludeImportSubsets, sal_uInt32 nExcludeInfoFlags,
     132             :         sal_uInt32 nButIncludeInfoFlags )
     133             : {
     134             : #if !HAVE_FEATURE_DBCONNECTIVITY
     135             :     (void)bExcludeImportSubsets;
     136             :     (void)nExcludeInfoFlags;
     137             :     (void)nButIncludeInfoFlags;
     138             : #else
     139             :     rtl_TextEncodingInfo aInfo;
     140           0 :     aInfo.StructSize = sizeof(rtl_TextEncodingInfo);
     141           0 :     svxform::ODataAccessCharsetHelper aCSH;
     142           0 :     ::std::vector< rtl_TextEncoding > aEncs;
     143           0 :     sal_Int32 nCount = aCSH.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         594 : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10