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

Generated by: LCOV version 1.10