LCOV - code coverage report
Current view: top level - sw/source/uibase/envelp - envimg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 200 0.5 %
Date: 2015-06-13 12:38:46 Functions: 1 19 5.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 <hintids.hxx>
      21             : #include <comphelper/string.hxx>
      22             : #include <tools/stream.hxx>
      23             : #include <tools/resid.hxx>
      24             : #include <sfx2/app.hxx>
      25             : #include <editeng/paperinf.hxx>
      26             : #include <com/sun/star/uno/Sequence.hxx>
      27             : #include <unotools/useroptions.hxx>
      28             : #include <swmodule.hxx>
      29             : #include <swtypes.hxx>
      30             : #include <envimg.hxx>
      31             : 
      32             : #include <cmdid.h>
      33             : #include <envelp.hrc>
      34             : 
      35             : #include <unomid.h>
      36             : 
      37             : #ifdef WNT
      38             : #define NEXTLINE  OUString("\r\n")
      39             : #else
      40             : #define NEXTLINE  '\n'
      41             : #endif
      42             : 
      43             : using namespace utl;
      44             : using namespace ::com::sun::star::uno;
      45             : 
      46          59 : TYPEINIT1_AUTOFACTORY( SwEnvItem, SfxPoolItem );
      47             : 
      48           0 : OUString MakeSender()
      49             : {
      50           0 :     SvtUserOptions& rUserOpt = SW_MOD()->GetUserOptions();
      51             : 
      52           0 :     OUString sRet;
      53           0 :     OUString sSenderToken(SW_RES(STR_SENDER_TOKENS));
      54           0 :     sal_Int32 nTokenCount = comphelper::string::getTokenCount(sSenderToken, ';');
      55           0 :     sal_Int32 nSttPos = 0;
      56           0 :     bool bLastLength = true;
      57           0 :     for( sal_Int32 i = 0; i < nTokenCount; i++ )
      58             :     {
      59           0 :         OUString sToken = sSenderToken.getToken( 0, ';', nSttPos );
      60           0 :         if (sToken == "COMPANY")
      61             :         {
      62           0 :             sal_Int32 nOldLen = sRet.getLength();
      63           0 :             sRet += rUserOpt.GetCompany();
      64           0 :             bLastLength = sRet.getLength() != nOldLen;
      65             :         }
      66           0 :         else if (sToken == "CR")
      67             :         {
      68           0 :             if(bLastLength)
      69           0 :                 sRet += OUString(NEXTLINE);
      70           0 :             bLastLength = true;
      71             :         }
      72           0 :         else if (sToken == "FIRSTNAME")
      73           0 :             sRet += rUserOpt.GetFirstName();
      74           0 :         else if (sToken == "LASTNAME")
      75           0 :             sRet += rUserOpt.GetLastName();
      76           0 :         else if (sToken == "ADDRESS")
      77           0 :             sRet += rUserOpt.GetStreet();
      78           0 :         else if (sToken == "COUNTRY")
      79           0 :             sRet += rUserOpt.GetCountry();
      80           0 :         else if (sToken == "POSTALCODE")
      81           0 :             sRet += rUserOpt.GetZip();
      82           0 :         else if (sToken == "CITY")
      83           0 :             sRet += rUserOpt.GetCity();
      84           0 :         else if (sToken == "STATEPROV")
      85           0 :             sRet += rUserOpt.GetState();
      86           0 :         else if (!sToken.isEmpty()) //spaces
      87           0 :             sRet += sToken;
      88           0 :     }
      89           0 :     return sRet;
      90             : }
      91             : 
      92           0 : SwEnvItem::SwEnvItem() :
      93           0 :     SfxPoolItem(FN_ENVELOP)
      94             : {
      95           0 :     aAddrText       = aEmptyOUStr;
      96           0 :     bSend           = true;
      97           0 :     aSendText       = MakeSender();
      98           0 :     lSendFromLeft   = 566; // 1 cm
      99           0 :     lSendFromTop    = 566; // 1 cm
     100           0 :     Size aEnvSz     = SvxPaperInfo::GetPaperSize(PAPER_ENV_C65);
     101           0 :     lWidth          = aEnvSz.Width();
     102           0 :     lHeight         = aEnvSz.Height();
     103           0 :     eAlign          = ENV_HOR_LEFT;
     104           0 :     bPrintFromAbove = true;
     105           0 :     lShiftRight     = 0;
     106           0 :     lShiftDown      = 0;
     107             : 
     108           0 :     lAddrFromLeft   = std::max(lWidth, lHeight) / 2;
     109           0 :     lAddrFromTop    = std::min(lWidth, lHeight) / 2;
     110           0 : }
     111             : 
     112           0 : SwEnvItem::SwEnvItem(const SwEnvItem& rItem) :
     113             :     SfxPoolItem(FN_ENVELOP),
     114             :     aAddrText      (rItem.aAddrText),
     115             :     bSend          (rItem.bSend),
     116             :     aSendText      (rItem.aSendText),
     117             :     lAddrFromLeft  (rItem.lAddrFromLeft),
     118             :     lAddrFromTop   (rItem.lAddrFromTop),
     119             :     lSendFromLeft  (rItem.lSendFromLeft),
     120             :     lSendFromTop   (rItem.lSendFromTop),
     121             :     lWidth         (rItem.lWidth),
     122             :     lHeight        (rItem.lHeight),
     123             :     eAlign         (rItem.eAlign),
     124             :     bPrintFromAbove(rItem.bPrintFromAbove),
     125             :     lShiftRight    (rItem.lShiftRight),
     126           0 :     lShiftDown     (rItem.lShiftDown)
     127             : {
     128           0 : }
     129             : 
     130           0 : SwEnvItem& SwEnvItem::operator =(const SwEnvItem& rItem)
     131             : {
     132           0 :     aAddrText       = rItem.aAddrText;
     133           0 :     bSend           = rItem.bSend;
     134           0 :     aSendText       = rItem.aSendText;
     135           0 :     lSendFromLeft   = rItem.lSendFromLeft;
     136           0 :     lSendFromTop    = rItem.lSendFromTop;
     137           0 :     lAddrFromLeft   = rItem.lAddrFromLeft;
     138           0 :     lAddrFromTop    = rItem.lAddrFromTop;
     139           0 :     lWidth          = rItem.lWidth;
     140           0 :     lHeight         = rItem.lHeight;
     141           0 :     eAlign          = rItem.eAlign;
     142           0 :     bPrintFromAbove = rItem.bPrintFromAbove;
     143           0 :     lShiftRight     = rItem.lShiftRight;
     144           0 :     lShiftDown      = rItem.lShiftDown;
     145           0 :     return *this;
     146             : }
     147             : 
     148           0 : bool SwEnvItem::operator ==(const SfxPoolItem& rItem) const
     149             : {
     150           0 :     const SwEnvItem& rEnv = static_cast<const SwEnvItem&>( rItem);
     151             : 
     152           0 :     return aAddrText       == rEnv.aAddrText       &&
     153           0 :            bSend           == rEnv.bSend           &&
     154           0 :            aSendText       == rEnv.aSendText       &&
     155           0 :            lSendFromLeft   == rEnv.lSendFromLeft   &&
     156           0 :            lSendFromTop    == rEnv.lSendFromTop    &&
     157           0 :            lAddrFromLeft   == rEnv.lAddrFromLeft   &&
     158           0 :            lAddrFromTop    == rEnv.lAddrFromTop    &&
     159           0 :            lWidth          == rEnv.lWidth          &&
     160           0 :            lHeight         == rEnv.lHeight         &&
     161           0 :            eAlign          == rEnv.eAlign          &&
     162           0 :            bPrintFromAbove == rEnv.bPrintFromAbove &&
     163           0 :            lShiftRight     == rEnv.lShiftRight     &&
     164           0 :            lShiftDown      == rEnv.lShiftDown;
     165             : }
     166             : 
     167           0 : SfxPoolItem* SwEnvItem::Clone(SfxItemPool*) const
     168             : {
     169           0 :     return new SwEnvItem(*this);
     170             : }
     171             : 
     172           0 : SwEnvCfgItem::SwEnvCfgItem() :
     173           0 :     ConfigItem("Office.Writer/Envelope")
     174             : {
     175           0 :     Sequence<OUString> aNames = GetPropertyNames();
     176           0 :     Sequence<Any> aValues = GetProperties(aNames);
     177           0 :     EnableNotification(aNames);
     178           0 :     const Any* pValues = aValues.getConstArray();
     179             :     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
     180           0 :     if(aValues.getLength() == aNames.getLength())
     181             :     {
     182           0 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     183             :         {
     184           0 :             if(pValues[nProp].hasValue())
     185             :             {
     186           0 :                 switch(nProp)
     187             :                 {
     188           0 :                     case  0: pValues[nProp] >>= aEnvItem.aAddrText; break;// "Inscription/Addressee",
     189           0 :                     case  1: pValues[nProp] >>= aEnvItem.aSendText; break;// "Inscription/Sender",
     190           0 :                     case  2: aEnvItem.bSend = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;// "Inscription/UseSender",
     191             :                     case  3:
     192           0 :                         pValues[nProp] >>= aEnvItem.lAddrFromLeft;// "Format/AddresseeFromLeft",
     193           0 :                         aEnvItem.lAddrFromLeft = convertMm100ToTwip(aEnvItem.lAddrFromLeft);
     194           0 :                     break;
     195             :                     case  4:
     196           0 :                         pValues[nProp] >>= aEnvItem.lAddrFromTop;  // "Format/AddresseeFromTop",
     197           0 :                         aEnvItem.lAddrFromTop = convertMm100ToTwip(aEnvItem.lAddrFromTop);
     198           0 :                     break;
     199             :                     case  5:
     200           0 :                         pValues[nProp] >>= aEnvItem.lSendFromLeft; // "Format/SenderFromLeft",
     201           0 :                         aEnvItem.lSendFromLeft = convertMm100ToTwip(aEnvItem.lSendFromLeft);
     202           0 :                     break;
     203             :                     case  6:
     204           0 :                         pValues[nProp] >>= aEnvItem.lSendFromTop;// "Format/SenderFromTop",
     205           0 :                         aEnvItem.lSendFromTop = convertMm100ToTwip(aEnvItem.lSendFromTop);
     206           0 :                     break;
     207             :                     case  7:
     208           0 :                         pValues[nProp] >>= aEnvItem.lWidth; // "Format/Width",
     209           0 :                         aEnvItem.lWidth = convertMm100ToTwip(aEnvItem.lWidth);
     210           0 :                     break;
     211             :                     case  8:
     212           0 :                         pValues[nProp] >>= aEnvItem.lHeight; // "Format/Height",
     213           0 :                         aEnvItem.lHeight = convertMm100ToTwip(aEnvItem.lHeight);
     214           0 :                     break;
     215             :                     case  9:
     216             :                     {
     217           0 :                         sal_Int32 nTemp = 0;
     218           0 :                         pValues[nProp] >>= nTemp; aEnvItem.eAlign = (SwEnvAlign)nTemp; break;// "Print/Alignment",
     219             :                     }
     220           0 :                     case 10: aEnvItem.bPrintFromAbove = *static_cast<sal_Bool const *>(pValues[nProp].getValue()); break;// "Print/FromAbove",
     221             :                     case 11:
     222           0 :                         pValues[nProp] >>= aEnvItem.lShiftRight;
     223           0 :                         aEnvItem.lShiftRight = convertMm100ToTwip(aEnvItem.lShiftRight);// "Print/Right",
     224           0 :                     break;
     225             :                     case 12:
     226           0 :                         pValues[nProp] >>= aEnvItem.lShiftDown;
     227           0 :                         aEnvItem.lShiftDown = convertMm100ToTwip(aEnvItem.lShiftDown);
     228           0 :                     break;// "Print/Down"
     229             :                 }
     230             :             }
     231             :         }
     232           0 :     }
     233           0 : }
     234             : 
     235           0 : SwEnvCfgItem::~SwEnvCfgItem()
     236             : {
     237           0 : }
     238             : 
     239           0 : void SwEnvCfgItem::ImplCommit()
     240             : {
     241           0 :     Sequence<OUString> aNames = GetPropertyNames();
     242           0 :     Sequence<Any> aValues(aNames.getLength());
     243           0 :     Any* pValues = aValues.getArray();
     244             : 
     245           0 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     246             :     {
     247           0 :         switch(nProp)
     248             :         {
     249           0 :             case  0: pValues[nProp] <<= aEnvItem.aAddrText; break;// "Inscription/Addressee",
     250           0 :             case  1: pValues[nProp] <<= aEnvItem.aSendText; break;// "Inscription/Sender",
     251           0 :             case  2: pValues[nProp] <<= aEnvItem.bSend; break;// "Inscription/UseSender",
     252           0 :             case  3: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lAddrFromLeft)) ; break;// "Format/AddresseeFromLeft",
     253           0 :             case  4: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lAddrFromTop))  ; break;// "Format/AddresseeFromTop",
     254           0 :             case  5: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lSendFromLeft)) ; break;// "Format/SenderFromLeft",
     255           0 :             case  6: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lSendFromTop))  ; break;// "Format/SenderFromTop",
     256           0 :             case  7: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lWidth))  ; break;// "Format/Width",
     257           0 :             case  8: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lHeight)) ; break;// "Format/Height",
     258           0 :             case  9: pValues[nProp] <<= sal_Int32(aEnvItem.eAlign); break;// "Print/Alignment",
     259           0 :             case 10: pValues[nProp] <<= aEnvItem.bPrintFromAbove; break;// "Print/FromAbove",
     260           0 :             case 11: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lShiftRight));break; // "Print/Right",
     261           0 :             case 12: pValues[nProp] <<= static_cast <sal_Int32>(convertTwipToMm100(aEnvItem.lShiftDown)); break;// "Print/Down"
     262             :         }
     263             :     }
     264           0 :     PutProperties(aNames, aValues);
     265           0 : }
     266             : 
     267           0 : void SwEnvCfgItem::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
     268             : 
     269           0 : Sequence<OUString> SwEnvCfgItem::GetPropertyNames()
     270             : {
     271             :     static const char* aPropNames[] =
     272             :     {
     273             :         "Inscription/Addressee",    //  0
     274             :         "Inscription/Sender",       //  1
     275             :         "Inscription/UseSender",    //  2
     276             :         "Format/AddresseeFromLeft", //  3
     277             :         "Format/AddresseeFromTop",  //  4
     278             :         "Format/SenderFromLeft",    //  5
     279             :         "Format/SenderFromTop",     //  6
     280             :         "Format/Width",             //  7
     281             :         "Format/Height",            //  8
     282             :         "Print/Alignment",          //  9
     283             :         "Print/FromAbove",          // 10
     284             :         "Print/Right",              // 11
     285             :         "Print/Down"                // 12
     286             :     };
     287           0 :     const int nCount = 13;
     288           0 :     Sequence<OUString> aNames(nCount);
     289           0 :     OUString* pNames = aNames.getArray();
     290             : 
     291           0 :     for(int i = 0; i < nCount; i++)
     292           0 :         pNames[i] = OUString::createFromAscii(aPropNames[i]);
     293             : 
     294           0 :     return aNames;
     295             : }
     296             : 
     297           0 : bool SwEnvItem::QueryValue( Any& rVal, sal_uInt8 nMemberId ) const
     298             : {
     299           0 :     bool bRet = true;
     300           0 :     switch(nMemberId & ~CONVERT_TWIPS)
     301             :     {
     302           0 :         case MID_ENV_ADDR_TEXT : rVal <<= aAddrText; break;
     303           0 :         case MID_ENV_SEND : rVal <<= bSend; break;
     304           0 :         case MID_SEND_TEXT : rVal <<= aSendText; break;
     305           0 :         case MID_ENV_ADDR_FROM_LEFT : rVal <<= lAddrFromLeft; break;
     306           0 :         case MID_ENV_ADDR_FROM_TOP : rVal <<= lAddrFromTop; break;
     307           0 :         case MID_ENV_SEND_FROM_LEFT : rVal <<= lSendFromLeft; break;
     308           0 :         case MID_ENV_SEND_FROM_TOP : rVal <<= lSendFromTop; break;
     309           0 :         case MID_ENV_WIDTH : rVal <<= lWidth; break;
     310           0 :         case MID_ENV_HEIGHT : rVal <<= lHeight; break;
     311           0 :         case MID_ENV_ALIGN            : rVal <<= (sal_Int16) eAlign; break;
     312           0 :         case MID_ENV_PRINT_FROM_ABOVE  : rVal <<= bPrintFromAbove; break;
     313           0 :         case MID_ENV_SHIFT_RIGHT      : rVal <<= lShiftRight; break;
     314           0 :         case MID_ENV_SHIFT_DOWN       : rVal <<= lShiftDown; break;
     315             :         default:
     316             :             OSL_FAIL("Wrong memberId");
     317           0 :             bRet = false;
     318             :     }
     319           0 :     return bRet;
     320             : }
     321             : 
     322           0 : bool SwEnvItem::PutValue(const Any& rVal, sal_uInt8 nMemberId)
     323             : {
     324           0 :     bool bRet = false;
     325           0 :     switch(nMemberId  & ~CONVERT_TWIPS)
     326             :     {
     327           0 :         case MID_ENV_ADDR_TEXT : bRet = (rVal >>= aAddrText); break;
     328           0 :         case MID_ENV_SEND : bRet = (rVal >>= bSend); break;
     329           0 :         case MID_SEND_TEXT : bRet = (rVal >>= aSendText); break;
     330           0 :         case MID_ENV_ADDR_FROM_LEFT : bRet = (rVal >>= lAddrFromLeft); break;
     331           0 :         case MID_ENV_ADDR_FROM_TOP : bRet = (rVal >>= lAddrFromTop); break;
     332           0 :         case MID_ENV_SEND_FROM_LEFT : bRet = (rVal >>= lSendFromLeft); break;
     333           0 :         case MID_ENV_SEND_FROM_TOP : bRet = (rVal >>= lSendFromTop); break;
     334           0 :         case MID_ENV_WIDTH : bRet = (rVal >>= lWidth); break;
     335           0 :         case MID_ENV_HEIGHT : bRet = (rVal >>= lHeight); break;
     336             :         case MID_ENV_ALIGN :
     337             :         {
     338           0 :             sal_Int16 nTemp = 0;
     339           0 :             bRet = (rVal >>= nTemp);
     340           0 :             if (bRet)
     341           0 :                 eAlign = SwEnvAlign(nTemp);
     342           0 :             break;
     343             :         }
     344           0 :         case MID_ENV_PRINT_FROM_ABOVE  : bRet = (rVal >>= bPrintFromAbove); break;
     345           0 :         case MID_ENV_SHIFT_RIGHT      : bRet = (rVal >>= lShiftRight); break;
     346           0 :         case MID_ENV_SHIFT_DOWN       : bRet = (rVal >>= lShiftDown); break;
     347             :         default:
     348             :             OSL_FAIL("Wrong memberId");
     349             :     }
     350           0 :     return bRet;
     351             : }
     352             : 
     353             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11