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

Generated by: LCOV version 1.10