LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/misc - numberingtypelistbox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 80 1.2 %
Date: 2012-12-27 Functions: 2 13 15.4 %
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 <numberingtypelistbox.hxx>
      21             : #include <misc.hrc>
      22             : #include <cnttab.hxx>
      23             : #include <com/sun/star/style/NumberingType.hpp>
      24             : #include <com/sun/star/text/DefaultNumberingProvider.hpp>
      25             : #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <com/sun/star/text/XNumberingTypeInfo.hpp>
      28             : 
      29             : #include <unomid.h>
      30             : 
      31             : using namespace com::sun::star;
      32             : 
      33             : using ::rtl::OUString;
      34             : 
      35           0 : struct SwNumberingTypeListBox_Impl
      36             : {
      37             :     uno::Reference<text::XNumberingTypeInfo> xInfo;
      38             : };
      39             : 
      40           0 : SwNumberingTypeListBox::SwNumberingTypeListBox( Window* pWin, const ResId& rResId,
      41             :         sal_uInt16 nTypeFlags ) :
      42             :     ListBox(pWin, rResId),
      43           0 :     pImpl(new SwNumberingTypeListBox_Impl)
      44             : {
      45           0 :     uno::Reference<uno::XComponentContext>          xContext( ::comphelper::getProcessComponentContext() );
      46           0 :     uno::Reference<text::XDefaultNumberingProvider> xDefNum = text::DefaultNumberingProvider::create(xContext);
      47             : 
      48           0 :     pImpl->xInfo = uno::Reference<text::XNumberingTypeInfo>(xDefNum, uno::UNO_QUERY);
      49           0 :     Reload(nTypeFlags);
      50           0 : }
      51             : 
      52           0 : SwNumberingTypeListBox::SwNumberingTypeListBox( Window* pWin, WinBits nStyle ) :
      53             :     ListBox(pWin, nStyle),
      54           0 :     pImpl(new SwNumberingTypeListBox_Impl)
      55             : {
      56           0 :     uno::Reference<uno::XComponentContext>          xContext( ::comphelper::getProcessComponentContext() );
      57           0 :     uno::Reference<text::XDefaultNumberingProvider> xDefNum = text::DefaultNumberingProvider::create(xContext);
      58             : 
      59           0 :     pImpl->xInfo = uno::Reference<text::XNumberingTypeInfo>(xDefNum, uno::UNO_QUERY);
      60           0 : }
      61             : 
      62           0 : bool SwNumberingTypeListBox::set_property(const rtl::OString &rKey, const rtl::OString &rValue)
      63             : {
      64           0 :     if (rKey.equalsL(RTL_CONSTASCII_STRINGPARAM("type")))
      65           0 :         Reload(rValue.toInt32());
      66             :     else
      67           0 :         return ListBox::set_property(rKey, rValue);
      68           0 :     return true;
      69             : }
      70             : 
      71           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwNumberingTypeListBox(Window *pParent, VclBuilder::stringmap &)
      72             : {
      73           0 :     SwNumberingTypeListBox *pListBox = new SwNumberingTypeListBox(pParent, WB_LEFT|WB_DROPDOWN|WB_VCENTER|WB_3DLOOK|WB_TABSTOP);
      74           0 :     pListBox->EnableAutoSize(true);
      75           0 :     return pListBox;
      76             : }
      77             : 
      78           0 : SwNumberingTypeListBox::~SwNumberingTypeListBox()
      79             : {
      80           0 :     delete pImpl;
      81           0 : }
      82             : 
      83           0 : void SwNumberingTypeListBox::Reload(sal_uInt16 nTypeFlags)
      84             : {
      85           0 :     Clear();
      86           0 :     uno::Sequence<sal_Int16> aTypes;
      87           0 :     const sal_Int16* pTypes = NULL;
      88           0 :     if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
      89             :     {
      90           0 :         if(pImpl->xInfo.is())
      91             :         {
      92           0 :             aTypes = pImpl->xInfo->getSupportedNumberingTypes();
      93           0 :             pTypes = aTypes.getConstArray();
      94             :         }
      95             :     }
      96           0 :     SwOLENames aNames(SW_RES(STRRES_NUMTYPES));
      97           0 :     ResStringArray& rNames = aNames.GetNames();
      98           0 :     for(sal_uInt16 i = 0; i < rNames.Count(); i++)
      99             :     {
     100           0 :         long nValue = rNames.GetValue(i);
     101           0 :         sal_Bool bInsert = sal_True;
     102           0 :         sal_uInt16 nPos = LISTBOX_APPEND;
     103           0 :         switch(nValue)
     104             :         {
     105             :             case  style::NumberingType::NUMBER_NONE:
     106           0 :                 bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_NO_NUMBERING);
     107           0 :                 nPos = 0;
     108           0 :              break;
     109           0 :             case  style::NumberingType::CHAR_SPECIAL:   bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BULLET); break;
     110           0 :             case  style::NumberingType::PAGE_DESCRIPTOR:bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_PAGE_STYLE_NUMBERING); break;
     111           0 :             case  style::NumberingType::BITMAP:bInsert = 0 != (nTypeFlags&INSERT_NUM_TYPE_BITMAP ); break;
     112             :             default:
     113           0 :                 if (nValue >  style::NumberingType::CHARS_LOWER_LETTER_N)
     114             :                 {
     115             :                     // Insert only if offered by i18n framework per configuration.
     116           0 :                     bInsert = sal_False;
     117           0 :                     if (pTypes)
     118             :                     {
     119           0 :                         for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
     120             :                         {
     121           0 :                             if (pTypes[nType] == nValue)
     122             :                             {
     123           0 :                                 bInsert = sal_True;
     124           0 :                                 break;  // for
     125             :                             }
     126             :                         }
     127             :                     }
     128             :                 }
     129             :         }
     130           0 :         if(bInsert)
     131             :         {
     132           0 :             sal_uInt16 nEntry = InsertEntry(rNames.GetString(i), nPos);
     133           0 :             SetEntryData( nEntry, (void*)nValue );
     134             :         }
     135             :     }
     136           0 :     if(0 != (nTypeFlags&INSERT_NUM_EXTENDED_TYPES) )
     137             :     {
     138           0 :         if(pTypes)
     139             :         {
     140           0 :             for(sal_Int32 nType = 0; nType < aTypes.getLength(); nType++)
     141             :             {
     142           0 :                 sal_Int16 nCurrent = pTypes[nType];
     143           0 :                 if(nCurrent > style::NumberingType::CHARS_LOWER_LETTER_N)
     144             :                 {
     145           0 :                     if(LISTBOX_ENTRY_NOTFOUND == GetEntryPos((void*)(sal_uLong)nCurrent))
     146             :                     {
     147           0 :                         OUString aIdent = pImpl->xInfo->getNumberingIdentifier( nCurrent );
     148           0 :                         sal_uInt16 nPos = InsertEntry(aIdent);
     149           0 :                         SetEntryData(nPos,(void*)(sal_uLong)nCurrent);
     150             :                     }
     151             :                 }
     152             :             }
     153             :         }
     154           0 :         SelectEntryPos(0);
     155           0 :     }
     156           0 : }
     157             : 
     158           0 : sal_Int16   SwNumberingTypeListBox::GetSelectedNumberingType()
     159             : {
     160           0 :     sal_Int16 nRet = 0;
     161           0 :     sal_uInt16 nSelPos = GetSelectEntryPos();
     162           0 :     if(LISTBOX_ENTRY_NOTFOUND != nSelPos)
     163           0 :         nRet = (sal_Int16)(sal_uLong)GetEntryData(nSelPos);
     164             : #if OSL_DEBUG_LEVEL > 0
     165             :     else
     166             :         OSL_FAIL("SwNumberingTypeListBox not selected");
     167             : #endif
     168           0 :     return nRet;
     169             : }
     170             : 
     171           0 : sal_Bool    SwNumberingTypeListBox::SelectNumberingType(sal_Int16 nType)
     172             : {
     173           0 :     sal_uInt16 nPos = GetEntryPos((void*)(sal_uLong)nType);
     174           0 :     SelectEntryPos( nPos );
     175           0 :     return LISTBOX_ENTRY_NOTFOUND != nPos;
     176          30 : }
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10