LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - envlop1.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 180 0.0 %
Date: 2012-08-25 Functions: 0 26 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "dbmgr.hxx"
      30                 :            : #include <sfx2/app.hxx>
      31                 :            : #include <vcl/msgbox.hxx>
      32                 :            : #include <swwait.hxx>
      33                 :            : #include <viewopt.hxx>
      34                 :            : 
      35                 :            : #include "wrtsh.hxx"
      36                 :            : #include "cmdid.h"
      37                 :            : #include "helpid.h"
      38                 :            : #include "envfmt.hxx"
      39                 :            : #include "envlop.hxx"
      40                 :            : #include "envprt.hxx"
      41                 :            : #include "fmtcol.hxx"
      42                 :            : #include "poolfmt.hxx"
      43                 :            : #include "view.hxx"
      44                 :            : 
      45                 :            : #include "envlop.hrc"
      46                 :            : #include <comphelper/processfactory.hxx>
      47                 :            : 
      48                 :            : #include <unomid.h>
      49                 :            : 
      50                 :            : using namespace ::com::sun::star::lang;
      51                 :            : using namespace ::com::sun::star::container;
      52                 :            : using namespace ::com::sun::star::uno;
      53                 :            : using namespace ::com::sun::star;
      54                 :            : using namespace ::rtl;
      55                 :            : 
      56                 :            : 
      57                 :            : //impl in envimg.cxx
      58                 :            : extern SW_DLLPUBLIC String MakeSender();
      59                 :            : 
      60                 :          0 : SwEnvPreview::SwEnvPreview(SfxTabPage* pParent, const ResId& rResID) :
      61                 :            : 
      62                 :          0 :     Window(pParent, rResID)
      63                 :            : 
      64                 :            : {
      65                 :          0 :     SetMapMode(MapMode(MAP_PIXEL));
      66                 :          0 : }
      67                 :            : 
      68                 :          0 : SwEnvPreview::~SwEnvPreview()
      69                 :            : {
      70                 :          0 : }
      71                 :            : 
      72                 :          0 : void SwEnvPreview::DataChanged( const DataChangedEvent& rDCEvt )
      73                 :            : {
      74                 :          0 :     Window::DataChanged( rDCEvt );
      75                 :          0 :     if ( DATACHANGED_SETTINGS == rDCEvt.GetType() )
      76                 :          0 :         SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
      77                 :          0 : }
      78                 :            : 
      79                 :          0 : void SwEnvPreview::Paint(const Rectangle &)
      80                 :            : {
      81                 :          0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
      82                 :            : 
      83                 :            :     const SwEnvItem& rItem =
      84                 :          0 :         ((SwEnvDlg*) GetParent()->GetParent()->GetParent())->aEnvItem;
      85                 :            : 
      86                 :          0 :     sal_uInt16 nPageW = (sal_uInt16) Max(rItem.lWidth, rItem.lHeight),
      87                 :          0 :            nPageH = (sal_uInt16) Min(rItem.lWidth, rItem.lHeight);
      88                 :            : 
      89                 :          0 :     float fx = (float)GetOutputSizePixel().Width () / (float)nPageW,
      90                 :          0 :           fy = (float)GetOutputSizePixel().Height() / (float)nPageH,
      91                 :          0 :           f  = 0.8f * ( fx < fy ? fx : fy );
      92                 :            : 
      93                 :          0 :     Color aBack = rSettings.GetWindowColor( );
      94                 :          0 :     Color aFront = SwViewOption::GetFontColor();
      95                 :          0 :     Color aMedium = Color(  ( aBack.GetRed() + aFront.GetRed() ) / 2,
      96                 :          0 :                             ( aBack.GetGreen() + aFront.GetGreen() ) / 2,
      97                 :          0 :                             ( aBack.GetBlue() + aFront.GetBlue() ) / 2
      98                 :          0 :                         );
      99                 :            : 
     100                 :          0 :     SetLineColor( aFront );
     101                 :            : 
     102                 :            :     // Envelope
     103                 :          0 :     long   nW = (sal_uInt16) (f * nPageW),
     104                 :          0 :            nH = (sal_uInt16) (f * nPageH),
     105                 :          0 :            nX = (GetOutputSizePixel().Width () - nW) / 2,
     106                 :          0 :            nY = (GetOutputSizePixel().Height() - nH) / 2;
     107                 :          0 :     SetFillColor( aBack );
     108                 :          0 :     DrawRect(Rectangle(Point(nX, nY), Size(nW, nH)));
     109                 :            : 
     110                 :            :     // Sender
     111                 :          0 :     if (rItem.bSend)
     112                 :            :     {
     113                 :          0 :         long   nSendX = nX + (sal_uInt16) (f * rItem.lSendFromLeft),
     114                 :          0 :                nSendY = nY + (sal_uInt16) (f * rItem.lSendFromTop ),
     115                 :          0 :                nSendW = (sal_uInt16) (f * (rItem.lAddrFromLeft - rItem.lSendFromLeft)),
     116                 :          0 :                nSendH = (sal_uInt16) (f * (rItem.lAddrFromTop  - rItem.lSendFromTop  - 566));
     117                 :          0 :         SetFillColor( aMedium );
     118                 :            : 
     119                 :          0 :         DrawRect(Rectangle(Point(nSendX, nSendY), Size(nSendW, nSendH)));
     120                 :            :     }
     121                 :            : 
     122                 :            :     // Addressee
     123                 :          0 :     long   nAddrX = nX + (sal_uInt16) (f * rItem.lAddrFromLeft),
     124                 :          0 :            nAddrY = nY + (sal_uInt16) (f * rItem.lAddrFromTop ),
     125                 :          0 :            nAddrW = (sal_uInt16) (f * (nPageW - rItem.lAddrFromLeft - 566)),
     126                 :          0 :            nAddrH = (sal_uInt16) (f * (nPageH - rItem.lAddrFromTop  - 566));
     127                 :          0 :     SetFillColor( aMedium );
     128                 :          0 :     DrawRect(Rectangle(Point(nAddrX, nAddrY), Size(nAddrW, nAddrH)));
     129                 :            : 
     130                 :            :     // Stamp
     131                 :          0 :     long   nStmpW = (sal_uInt16) (f * 1417 /* 2,5 cm */),
     132                 :          0 :            nStmpH = (sal_uInt16) (f * 1701 /* 3,0 cm */),
     133                 :          0 :            nStmpX = nX + nW - (sal_uInt16) (f * 566) - nStmpW,
     134                 :          0 :            nStmpY = nY + (sal_uInt16) (f * 566);
     135                 :            : 
     136                 :          0 :     SetFillColor( aBack );
     137                 :          0 :     DrawRect(Rectangle(Point(nStmpX, nStmpY), Size(nStmpW, nStmpH)));
     138                 :          0 : }
     139                 :            : 
     140                 :          0 : SwEnvDlg::SwEnvDlg(Window* pParent, const SfxItemSet& rSet,
     141                 :            :                     SwWrtShell* pWrtSh, Printer* pPrt, sal_Bool bInsert) :
     142                 :            : 
     143                 :            :     SfxTabDialog(pParent, SW_RES(DLG_ENV), &rSet, sal_False, &aEmptyStr),
     144                 :            :     sInsert(SW_RES(ST_INSERT)),
     145                 :            :     sChange(SW_RES(ST_CHANGE)),
     146                 :          0 :     aEnvItem((const SwEnvItem&) rSet.Get(FN_ENVELOP)),
     147                 :            :     pSh(pWrtSh),
     148                 :            :     pPrinter(pPrt),
     149                 :            :     pAddresseeSet(0),
     150                 :          0 :     pSenderSet(0)
     151                 :            : {
     152                 :          0 :     FreeResource();
     153                 :            : 
     154                 :          0 :     GetOKButton().SetText(String(SW_RES(STR_BTN_NEWDOC)));
     155                 :          0 :     GetOKButton().SetHelpId(HID_ENVELOP_PRINT);
     156                 :          0 :     GetOKButton().SetHelpText(aEmptyStr);   // in order for generated help text to get used
     157                 :          0 :     if (GetUserButton())
     158                 :            :     {
     159                 :          0 :         GetUserButton()->SetText(bInsert ? sInsert : sChange);
     160                 :          0 :         GetUserButton()->SetHelpId(HID_ENVELOP_INSERT);
     161                 :            :     }
     162                 :            : 
     163                 :          0 :     AddTabPage(TP_ENV_ENV, SwEnvPage   ::Create, 0);
     164                 :          0 :     AddTabPage(TP_ENV_FMT, SwEnvFmtPage::Create, 0);
     165                 :          0 :     AddTabPage(TP_ENV_PRT, SwEnvPrtPage::Create, 0);
     166                 :          0 : }
     167                 :            : 
     168                 :          0 : SwEnvDlg::~SwEnvDlg()
     169                 :            : {
     170                 :          0 :     delete pAddresseeSet;
     171                 :          0 :     delete pSenderSet;
     172                 :          0 : }
     173                 :            : 
     174                 :          0 : void SwEnvDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
     175                 :            : {
     176                 :          0 :     if (nId == TP_ENV_PRT)
     177                 :            :     {
     178                 :          0 :         ((SwEnvPrtPage*)&rPage)->SetPrt(pPrinter);
     179                 :            :     }
     180                 :          0 : }
     181                 :            : 
     182                 :          0 : short SwEnvDlg::Ok()
     183                 :            : {
     184                 :          0 :     short nRet = SfxTabDialog::Ok();
     185                 :            : 
     186                 :          0 :     if (nRet == RET_OK || nRet == RET_USER)
     187                 :            :     {
     188                 :          0 :         if (pAddresseeSet)
     189                 :            :         {
     190                 :          0 :             SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_JAKETADRESS);
     191                 :          0 :             pColl->SetFmtAttr(*pAddresseeSet);
     192                 :            :         }
     193                 :          0 :         if (pSenderSet)
     194                 :            :         {
     195                 :          0 :             SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_SENDADRESS);
     196                 :          0 :             pColl->SetFmtAttr(*pSenderSet);
     197                 :            :         }
     198                 :            :     }
     199                 :            : 
     200                 :          0 :     return nRet;
     201                 :            : }
     202                 :            : 
     203                 :          0 : SwEnvPage::SwEnvPage(Window* pParent, const SfxItemSet& rSet) :
     204                 :            : 
     205                 :            :     SfxTabPage(pParent, SW_RES(TP_ENV_ENV), rSet),
     206                 :            : 
     207                 :            :     aAddrText      (this, SW_RES(TXT_ADDR   )),
     208                 :            :     aAddrEdit      (this, SW_RES(EDT_ADDR   )),
     209                 :            :     aDatabaseFT    (this, SW_RES(FT_DATABASE)),
     210                 :            :     aDatabaseLB    (this, SW_RES(LB_DATABASE)),
     211                 :            :     aTableFT       (this, SW_RES(FT_TABLE   )),
     212                 :            :     aTableLB       (this, SW_RES(LB_TABLE   )),
     213                 :            :     aInsertBT      (this, SW_RES(BTN_INSERT )),
     214                 :            :     aDBFieldFT     (this, SW_RES(FT_DBFIELD )),
     215                 :            :     aDBFieldLB     (this, SW_RES(LB_DBFIELD )),
     216                 :            :     aSenderBox     (this, SW_RES(BOX_SEND   )),
     217                 :            :     aSenderEdit    (this, SW_RES(EDT_SEND   )),
     218                 :          0 :     aPreview       (this, SW_RES(WIN_PREVIEW))
     219                 :            : 
     220                 :            : {
     221                 :          0 :     FreeResource();
     222                 :          0 :     SetExchangeSupport();
     223                 :          0 :     pSh = GetParent()->pSh;
     224                 :            : 
     225                 :            :     // Install handlers
     226                 :          0 :     aDatabaseLB    .SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl     ));
     227                 :          0 :     aTableLB       .SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl     ));
     228                 :          0 :     aInsertBT      .SetClickHdl (LINK(this, SwEnvPage, FieldHdl        ));
     229                 :          0 :     aSenderBox     .SetClickHdl (LINK(this, SwEnvPage, SenderHdl       ));
     230                 :          0 :     aPreview.SetBorderStyle( WINDOW_BORDER_MONO );
     231                 :            : 
     232                 :          0 :     SwDBData aData = pSh->GetDBData();
     233                 :          0 :     sActDBName = aData.sDataSource;
     234                 :          0 :     sActDBName += DB_DELIM;
     235                 :          0 :     sActDBName += (String)aData.sCommand;
     236                 :          0 :     InitDatabaseBox();
     237                 :          0 : }
     238                 :            : 
     239                 :          0 : SwEnvPage::~SwEnvPage()
     240                 :            : {
     241                 :          0 : }
     242                 :            : 
     243                 :          0 : IMPL_LINK( SwEnvPage, DatabaseHdl, ListBox *, pListBox )
     244                 :            : {
     245                 :          0 :     SwWait aWait( *pSh->GetView().GetDocShell(), sal_True );
     246                 :            : 
     247                 :          0 :     if (pListBox == &aDatabaseLB)
     248                 :            :     {
     249                 :          0 :         sActDBName = pListBox->GetSelectEntry();
     250                 :          0 :         pSh->GetNewDBMgr()->GetTableNames(&aTableLB, sActDBName);
     251                 :          0 :         sActDBName += DB_DELIM;
     252                 :            :     }
     253                 :            :     else
     254                 :          0 :         sActDBName.SetToken(1, DB_DELIM, aTableLB.GetSelectEntry());
     255                 :            :         pSh->GetNewDBMgr()->GetColumnNames(&aDBFieldLB, aDatabaseLB.GetSelectEntry(),
     256                 :          0 :                                            aTableLB.GetSelectEntry());
     257                 :          0 :     return 0;
     258                 :            : }
     259                 :            : 
     260                 :          0 : IMPL_LINK_NOARG(SwEnvPage, FieldHdl)
     261                 :            : {
     262                 :          0 :     rtl::OUStringBuffer aStr;
     263                 :          0 :     aStr.append('<');
     264                 :          0 :     aStr.append(aDatabaseLB.GetSelectEntry());
     265                 :          0 :     aStr.append('.');
     266                 :          0 :     aStr.append(aTableLB.GetSelectEntry());
     267                 :          0 :     aStr.append('.');
     268                 :          0 :     aStr.append(aTableLB.GetEntryData(aTableLB.GetSelectEntryPos()) == 0 ? '0' : '1');
     269                 :          0 :     aStr.append('.');
     270                 :          0 :     aStr.append(aDBFieldLB.GetSelectEntry());
     271                 :          0 :     aStr.append('>');
     272                 :          0 :     aAddrEdit.ReplaceSelected(aStr.makeStringAndClear());
     273                 :          0 :     Selection aSel = aAddrEdit.GetSelection();
     274                 :          0 :     aAddrEdit.GrabFocus();
     275                 :          0 :     aAddrEdit.SetSelection(aSel);
     276                 :          0 :     return 0;
     277                 :            : }
     278                 :            : 
     279                 :          0 : IMPL_LINK_NOARG(SwEnvPage, SenderHdl)
     280                 :            : {
     281                 :          0 :     const sal_Bool bEnable = aSenderBox.IsChecked();
     282                 :          0 :     GetParent()->aEnvItem.bSend = bEnable;
     283                 :          0 :     aSenderEdit.Enable(bEnable);
     284                 :          0 :     if ( bEnable )
     285                 :            :     {
     286                 :          0 :         aSenderEdit.GrabFocus();
     287                 :          0 :         if(!aSenderEdit.GetText().Len())
     288                 :          0 :             aSenderEdit.SetText(MakeSender());
     289                 :            :     }
     290                 :          0 :     aPreview.Invalidate();
     291                 :          0 :     return 0;
     292                 :            : }
     293                 :            : 
     294                 :          0 : void SwEnvPage::InitDatabaseBox()
     295                 :            : {
     296                 :          0 :     if (pSh->GetNewDBMgr())
     297                 :            :     {
     298                 :          0 :         aDatabaseLB.Clear();
     299                 :          0 :         Sequence<OUString> aDataNames = SwNewDBMgr::GetExistingDatabaseNames();
     300                 :          0 :         const OUString* pDataNames = aDataNames.getConstArray();
     301                 :            : 
     302                 :          0 :         for (long i = 0; i < aDataNames.getLength(); i++)
     303                 :          0 :             aDatabaseLB.InsertEntry(pDataNames[i]);
     304                 :            : 
     305                 :          0 :         String sDBName = sActDBName.GetToken( 0, DB_DELIM );
     306                 :          0 :         String sTableName = sActDBName.GetToken( 1, DB_DELIM );
     307                 :          0 :         aDatabaseLB.SelectEntry(sDBName);
     308                 :          0 :         if (pSh->GetNewDBMgr()->GetTableNames(&aTableLB, sDBName))
     309                 :            :         {
     310                 :          0 :             aTableLB.SelectEntry(sTableName);
     311                 :          0 :             pSh->GetNewDBMgr()->GetColumnNames(&aDBFieldLB, sDBName, sTableName);
     312                 :            :         }
     313                 :            :         else
     314                 :          0 :             aDBFieldLB.Clear();
     315                 :            : 
     316                 :            :     }
     317                 :          0 : }
     318                 :            : 
     319                 :          0 : SfxTabPage* SwEnvPage::Create(Window* pParent, const SfxItemSet& rSet)
     320                 :            : {
     321                 :          0 :     return new SwEnvPage(pParent, rSet);
     322                 :            : }
     323                 :            : 
     324                 :          0 : void SwEnvPage::ActivatePage(const SfxItemSet& rSet)
     325                 :            : {
     326                 :          0 :     SfxItemSet aSet(rSet);
     327                 :          0 :     aSet.Put(GetParent()->aEnvItem);
     328                 :          0 :     Reset(aSet);
     329                 :          0 : }
     330                 :            : 
     331                 :          0 : int SwEnvPage::DeactivatePage(SfxItemSet* _pSet)
     332                 :            : {
     333                 :          0 :     FillItem(GetParent()->aEnvItem);
     334                 :          0 :     if( _pSet )
     335                 :          0 :         FillItemSet(*_pSet);
     336                 :          0 :     return SfxTabPage::LEAVE_PAGE;
     337                 :            : }
     338                 :            : 
     339                 :          0 : void SwEnvPage::FillItem(SwEnvItem& rItem)
     340                 :            : {
     341                 :          0 :     rItem.aAddrText = aAddrEdit  .GetText();
     342                 :          0 :     rItem.bSend     = aSenderBox .IsChecked();
     343                 :          0 :     rItem.aSendText = aSenderEdit.GetText();
     344                 :          0 : }
     345                 :            : 
     346                 :          0 : sal_Bool SwEnvPage::FillItemSet(SfxItemSet& rSet)
     347                 :            : {
     348                 :          0 :     FillItem(GetParent()->aEnvItem);
     349                 :          0 :     rSet.Put(GetParent()->aEnvItem);
     350                 :          0 :     return sal_True;
     351                 :            : }
     352                 :            : 
     353                 :          0 : void SwEnvPage::Reset(const SfxItemSet& rSet)
     354                 :            : {
     355                 :          0 :     SwEnvItem aItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
     356                 :          0 :     aAddrEdit  .SetText(convertLineEnd(aItem.aAddrText, GetSystemLineEnd()));
     357                 :          0 :     aSenderEdit.SetText(convertLineEnd(aItem.aSendText, GetSystemLineEnd()));
     358                 :          0 :     aSenderBox .Check  (aItem.bSend);
     359                 :          0 :     aSenderBox.GetClickHdl().Call(&aSenderBox);
     360                 :          0 : }
     361                 :            : 
     362                 :            : 
     363                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10