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

Generated by: LCOV version 1.10