LCOV - code coverage report
Current view: top level - sw/source/ui/envelp - envlop1.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 186 0.0 %
Date: 2014-04-11 Functions: 0 28 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 "dbmgr.hxx"
      21             : #include <sfx2/app.hxx>
      22             : #include <vcl/builder.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <vcl/settings.hxx>
      25             : 
      26             : #include <swwait.hxx>
      27             : #include <viewopt.hxx>
      28             : 
      29             : #include "wrtsh.hxx"
      30             : #include "cmdid.h"
      31             : #include "helpid.h"
      32             : #include "envfmt.hxx"
      33             : #include "envlop.hxx"
      34             : #include "envprt.hxx"
      35             : #include "fmtcol.hxx"
      36             : #include "poolfmt.hxx"
      37             : #include "view.hxx"
      38             : 
      39             : #include <comphelper/processfactory.hxx>
      40             : #include <comphelper/string.hxx>
      41             : 
      42             : #include <unomid.h>
      43             : 
      44             : using namespace ::com::sun::star::lang;
      45             : using namespace ::com::sun::star::container;
      46             : using namespace ::com::sun::star::uno;
      47             : using namespace ::com::sun::star;
      48             : using namespace ::rtl;
      49             : 
      50             : //impl in envimg.cxx
      51             : extern SW_DLLPUBLIC OUString MakeSender();
      52             : 
      53           0 : SwEnvPreview::SwEnvPreview(Window* pParent, WinBits nStyle)
      54           0 :     : Window(pParent, nStyle)
      55             : {
      56           0 :     SetMapMode(MapMode(MAP_PIXEL));
      57           0 : }
      58             : 
      59           0 : Size SwEnvPreview::GetOptimalSize() const
      60             : {
      61           0 :     return LogicToPixel(Size(84 , 63), MAP_APPFONT);
      62             : }
      63             : 
      64           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwEnvPreview(Window *pParent, VclBuilder::stringmap &)
      65             : {
      66           0 :     return new SwEnvPreview(pParent, 0);
      67             : }
      68             : 
      69           0 : void SwEnvPreview::DataChanged( const DataChangedEvent& rDCEvt )
      70             : {
      71           0 :     Window::DataChanged( rDCEvt );
      72           0 :     if ( DATACHANGED_SETTINGS == rDCEvt.GetType() )
      73           0 :         SetBackground( GetSettings().GetStyleSettings().GetDialogColor() );
      74           0 : }
      75             : 
      76           0 : void SwEnvPreview::Paint(const Rectangle &)
      77             : {
      78           0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
      79             : 
      80             :     const SwEnvItem& rItem =
      81           0 :         ((SwEnvDlg*) GetParentDialog())->aEnvItem;
      82             : 
      83           0 :     const long nPageW = std::max(rItem.lWidth, rItem.lHeight);
      84           0 :     const long nPageH = std::min(rItem.lWidth, rItem.lHeight);
      85             : 
      86           0 :     const float f = 0.8 * std::min(
      87           0 :         static_cast<float>(GetOutputSizePixel().Width())/static_cast<float>(nPageW),
      88           0 :         static_cast<float>(GetOutputSizePixel().Height())/static_cast<float>(nPageH));
      89             : 
      90           0 :     Color aBack = rSettings.GetWindowColor( );
      91           0 :     Color aFront = SwViewOption::GetFontColor();
      92           0 :     Color aMedium = Color(  ( aBack.GetRed() + aFront.GetRed() ) / 2,
      93           0 :                             ( aBack.GetGreen() + aFront.GetGreen() ) / 2,
      94           0 :                             ( aBack.GetBlue() + aFront.GetBlue() ) / 2
      95           0 :                         );
      96             : 
      97           0 :     SetLineColor( aFront );
      98             : 
      99             :     // Envelope
     100           0 :     const long nW = static_cast<long>(f * nPageW);
     101           0 :     const long nH = static_cast<long>(f * nPageH);
     102           0 :     const long nX = (GetOutputSizePixel().Width () - nW) / 2;
     103           0 :     const long nY = (GetOutputSizePixel().Height() - nH) / 2;
     104           0 :     SetFillColor( aBack );
     105           0 :     DrawRect(Rectangle(Point(nX, nY), Size(nW, nH)));
     106             : 
     107             :     // Sender
     108           0 :     if (rItem.bSend)
     109             :     {
     110           0 :         const long nSendX = nX + static_cast<long>(f * rItem.lSendFromLeft);
     111           0 :         const long nSendY = nY + static_cast<long>(f * rItem.lSendFromTop );
     112           0 :         const long nSendW = static_cast<long>(f * (rItem.lAddrFromLeft - rItem.lSendFromLeft));
     113           0 :         const long nSendH = static_cast<long>(f * (rItem.lAddrFromTop  - rItem.lSendFromTop  - 566));
     114           0 :         SetFillColor( aMedium );
     115             : 
     116           0 :         DrawRect(Rectangle(Point(nSendX, nSendY), Size(nSendW, nSendH)));
     117             :     }
     118             : 
     119             :     // Addressee
     120           0 :     const long nAddrX = nX + static_cast<long>(f * rItem.lAddrFromLeft);
     121           0 :     const long nAddrY = nY + static_cast<long>(f * rItem.lAddrFromTop );
     122           0 :     const long nAddrW = static_cast<long>(f * (nPageW - rItem.lAddrFromLeft - 566));
     123           0 :     const long nAddrH = static_cast<long>(f * (nPageH - rItem.lAddrFromTop  - 566));
     124           0 :     SetFillColor( aMedium );
     125           0 :     DrawRect(Rectangle(Point(nAddrX, nAddrY), Size(nAddrW, nAddrH)));
     126             : 
     127             :     // Stamp
     128           0 :     const long nStmpW = static_cast<long>(f * 1417 /* 2,5 cm */);
     129           0 :     const long nStmpH = static_cast<long>(f * 1701 /* 3,0 cm */);
     130           0 :     const long nStmpX = nX + nW - static_cast<long>(f * 566) - nStmpW;
     131           0 :     const long nStmpY = nY + static_cast<long>(f * 566);
     132             : 
     133           0 :     SetFillColor( aBack );
     134           0 :     DrawRect(Rectangle(Point(nStmpX, nStmpY), Size(nStmpW, nStmpH)));
     135           0 : }
     136             : 
     137           0 : SwEnvDlg::SwEnvDlg(Window* pParent, const SfxItemSet& rSet,
     138             :                     SwWrtShell* pWrtSh, Printer* pPrt, sal_Bool bInsert)
     139             :     : SfxTabDialog(pParent, "EnvDialog",
     140             :         "modules/swriter/ui/envdialog.ui", &rSet)
     141           0 :     , aEnvItem((const SwEnvItem&) rSet.Get(FN_ENVELOP))
     142             :     , pSh(pWrtSh)
     143             :     , pPrinter(pPrt)
     144             :     , pAddresseeSet(0)
     145             :     , pSenderSet(0)
     146           0 :     , m_nEnvPrintId(0)
     147             : {
     148           0 :     if (!bInsert)
     149             :     {
     150           0 :         GetUserButton()->SetText(get<PushButton>("modify")->GetText());
     151             :     }
     152             : 
     153           0 :     AddTabPage("envelope", SwEnvPage   ::Create, 0);
     154           0 :     AddTabPage("format", SwEnvFmtPage::Create, 0);
     155           0 :     m_nEnvPrintId = AddTabPage("printer", SwEnvPrtPage::Create, 0);
     156           0 : }
     157             : 
     158           0 : SwEnvDlg::~SwEnvDlg()
     159             : {
     160           0 :     delete pAddresseeSet;
     161           0 :     delete pSenderSet;
     162           0 : }
     163             : 
     164           0 : void SwEnvDlg::PageCreated(sal_uInt16 nId, SfxTabPage &rPage)
     165             : {
     166           0 :     if (nId == m_nEnvPrintId)
     167             :     {
     168           0 :         ((SwEnvPrtPage*)&rPage)->SetPrt(pPrinter);
     169             :     }
     170           0 : }
     171             : 
     172           0 : short SwEnvDlg::Ok()
     173             : {
     174           0 :     short nRet = SfxTabDialog::Ok();
     175             : 
     176           0 :     if (nRet == RET_OK || nRet == RET_USER)
     177             :     {
     178           0 :         if (pAddresseeSet)
     179             :         {
     180           0 :             SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_JAKETADRESS);
     181           0 :             pColl->SetFmtAttr(*pAddresseeSet);
     182             :         }
     183           0 :         if (pSenderSet)
     184             :         {
     185           0 :             SwTxtFmtColl* pColl = pSh->GetTxtCollFromPool(RES_POOLCOLL_SENDADRESS);
     186           0 :             pColl->SetFmtAttr(*pSenderSet);
     187             :         }
     188             :     }
     189             : 
     190           0 :     return nRet;
     191             : }
     192             : 
     193           0 : SwEnvPage::SwEnvPage(Window* pParent, const SfxItemSet& rSet)
     194             :     : SfxTabPage(pParent, "EnvAddressPage",
     195           0 :         "modules/swriter/ui/envaddresspage.ui", rSet)
     196             : {
     197           0 :     get(m_pAddrEdit, "addredit");
     198           0 :     get(m_pDatabaseLB, "database");
     199           0 :     get(m_pTableLB, "table");
     200           0 :     get(m_pDBFieldLB, "field");
     201           0 :     get(m_pInsertBT, "insert");
     202           0 :     get(m_pSenderBox, "sender");
     203           0 :     get(m_pSenderEdit, "senderedit");
     204           0 :     get(m_pPreview, "preview");
     205             : 
     206           0 :     long nTextBoxHeight(m_pAddrEdit->GetTextHeight() * 10);
     207           0 :     long nTextBoxWidth(m_pAddrEdit->approximate_char_width() * 25);
     208             : 
     209           0 :     m_pAddrEdit->set_height_request(nTextBoxHeight);
     210           0 :     m_pAddrEdit->set_width_request(nTextBoxWidth);
     211           0 :     m_pSenderEdit->set_height_request(nTextBoxHeight);
     212           0 :     m_pSenderEdit->set_width_request(nTextBoxWidth);
     213             : 
     214           0 :     long nListBoxWidth = approximate_char_width() * 30;
     215           0 :     m_pTableLB->set_width_request(nListBoxWidth);
     216           0 :     m_pDatabaseLB->set_width_request(nListBoxWidth);
     217           0 :     m_pDBFieldLB->set_width_request(nListBoxWidth);
     218             : 
     219           0 :     SetExchangeSupport();
     220           0 :     pSh = GetParentSwEnvDlg()->pSh;
     221             : 
     222             :     // Install handlers
     223           0 :     m_pDatabaseLB->SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl     ));
     224           0 :     m_pTableLB->SetSelectHdl(LINK(this, SwEnvPage, DatabaseHdl     ));
     225           0 :     m_pInsertBT->SetClickHdl (LINK(this, SwEnvPage, FieldHdl        ));
     226           0 :     m_pSenderBox->SetClickHdl (LINK(this, SwEnvPage, SenderHdl       ));
     227           0 :     m_pPreview->SetBorderStyle( WINDOW_BORDER_MONO );
     228             : 
     229           0 :     SwDBData aData = pSh->GetDBData();
     230           0 :     sActDBName = aData.sDataSource + OUString(DB_DELIM) + aData.sCommand;
     231           0 :     InitDatabaseBox();
     232           0 : }
     233             : 
     234           0 : SwEnvPage::~SwEnvPage()
     235             : {
     236           0 : }
     237             : 
     238           0 : IMPL_LINK( SwEnvPage, DatabaseHdl, ListBox *, pListBox )
     239             : {
     240           0 :     SwWait aWait( *pSh->GetView().GetDocShell(), true );
     241             : 
     242           0 :     if (pListBox == m_pDatabaseLB)
     243             :     {
     244           0 :         sActDBName = pListBox->GetSelectEntry();
     245           0 :         pSh->GetNewDBMgr()->GetTableNames(m_pTableLB, sActDBName);
     246           0 :         sActDBName += OUString(DB_DELIM);
     247             :     }
     248             :     else
     249             :     {
     250           0 :         sActDBName = comphelper::string::setToken(sActDBName, 1, DB_DELIM, m_pTableLB->GetSelectEntry());
     251             :     }
     252             :     pSh->GetNewDBMgr()->GetColumnNames(m_pDBFieldLB, m_pDatabaseLB->GetSelectEntry(),
     253           0 :                                        m_pTableLB->GetSelectEntry());
     254           0 :     return 0;
     255             : }
     256             : 
     257           0 : IMPL_LINK_NOARG(SwEnvPage, FieldHdl)
     258             : {
     259           0 :     OUString aStr("<" + m_pDatabaseLB->GetSelectEntry() + "." +
     260           0 :                   m_pTableLB->GetSelectEntry() + "." +
     261           0 :                   OUString(m_pTableLB->GetEntryData(m_pTableLB->GetSelectEntryPos()) == 0 ? '0' : '1') + "." +
     262           0 :                   m_pDBFieldLB->GetSelectEntry() + ">");
     263           0 :     m_pAddrEdit->ReplaceSelected(aStr);
     264           0 :     Selection aSel = m_pAddrEdit->GetSelection();
     265           0 :     m_pAddrEdit->GrabFocus();
     266           0 :     m_pAddrEdit->SetSelection(aSel);
     267           0 :     return 0;
     268             : }
     269             : 
     270           0 : IMPL_LINK_NOARG(SwEnvPage, SenderHdl)
     271             : {
     272           0 :     const sal_Bool bEnable = m_pSenderBox->IsChecked();
     273           0 :     GetParentSwEnvDlg()->aEnvItem.bSend = bEnable;
     274           0 :     m_pSenderEdit->Enable(bEnable);
     275           0 :     if ( bEnable )
     276             :     {
     277           0 :         m_pSenderEdit->GrabFocus();
     278           0 :         if(m_pSenderEdit->GetText().isEmpty())
     279           0 :             m_pSenderEdit->SetText(MakeSender());
     280             :     }
     281           0 :     m_pPreview->Invalidate();
     282           0 :     return 0;
     283             : }
     284             : 
     285           0 : void SwEnvPage::InitDatabaseBox()
     286             : {
     287           0 :     if (pSh->GetNewDBMgr())
     288             :     {
     289           0 :         m_pDatabaseLB->Clear();
     290           0 :         Sequence<OUString> aDataNames = SwNewDBMgr::GetExistingDatabaseNames();
     291           0 :         const OUString* pDataNames = aDataNames.getConstArray();
     292             : 
     293           0 :         for (sal_Int32 i = 0; i < aDataNames.getLength(); i++)
     294           0 :             m_pDatabaseLB->InsertEntry(pDataNames[i]);
     295             : 
     296           0 :         OUString sDBName = sActDBName.getToken( 0, DB_DELIM );
     297           0 :         OUString sTableName = sActDBName.getToken( 1, DB_DELIM );
     298           0 :         m_pDatabaseLB->SelectEntry(sDBName);
     299           0 :         if (pSh->GetNewDBMgr()->GetTableNames(m_pTableLB, sDBName))
     300             :         {
     301           0 :             m_pTableLB->SelectEntry(sTableName);
     302           0 :             pSh->GetNewDBMgr()->GetColumnNames(m_pDBFieldLB, sDBName, sTableName);
     303             :         }
     304             :         else
     305           0 :             m_pDBFieldLB->Clear();
     306             : 
     307             :     }
     308           0 : }
     309             : 
     310           0 : SfxTabPage* SwEnvPage::Create(Window* pParent, const SfxItemSet& rSet)
     311             : {
     312           0 :     return new SwEnvPage(pParent, rSet);
     313             : }
     314             : 
     315           0 : void SwEnvPage::ActivatePage(const SfxItemSet& rSet)
     316             : {
     317           0 :     SfxItemSet aSet(rSet);
     318           0 :     aSet.Put(GetParentSwEnvDlg()->aEnvItem);
     319           0 :     Reset(aSet);
     320           0 : }
     321             : 
     322           0 : int SwEnvPage::DeactivatePage(SfxItemSet* _pSet)
     323             : {
     324           0 :     FillItem(GetParentSwEnvDlg()->aEnvItem);
     325           0 :     if( _pSet )
     326           0 :         FillItemSet(*_pSet);
     327           0 :     return SfxTabPage::LEAVE_PAGE;
     328             : }
     329             : 
     330           0 : void SwEnvPage::FillItem(SwEnvItem& rItem)
     331             : {
     332           0 :     rItem.aAddrText = m_pAddrEdit->GetText();
     333           0 :     rItem.bSend     = m_pSenderBox->IsChecked();
     334           0 :     rItem.aSendText = m_pSenderEdit->GetText();
     335           0 : }
     336             : 
     337           0 : bool SwEnvPage::FillItemSet(SfxItemSet& rSet)
     338             : {
     339           0 :     FillItem(GetParentSwEnvDlg()->aEnvItem);
     340           0 :     rSet.Put(GetParentSwEnvDlg()->aEnvItem);
     341           0 :     return true;
     342             : }
     343             : 
     344           0 : void SwEnvPage::Reset(const SfxItemSet& rSet)
     345             : {
     346           0 :     SwEnvItem aItem = (const SwEnvItem&) rSet.Get(FN_ENVELOP);
     347           0 :     m_pAddrEdit->SetText(convertLineEnd(aItem.aAddrText, GetSystemLineEnd()));
     348           0 :     m_pSenderEdit->SetText(convertLineEnd(aItem.aSendText, GetSystemLineEnd()));
     349           0 :     m_pSenderBox->Check  (aItem.bSend);
     350           0 :     m_pSenderBox->GetClickHdl().Call(m_pSenderBox);
     351           0 : }
     352             : 
     353             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10