LCOV - code coverage report
Current view: top level - sw/source/ui/fldui - fldtdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 150 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 20 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 <cmdid.h>
      21             : #include <swtypes.hxx>
      22             : #include <unotools/confignode.hxx>
      23             : #include <comphelper/processfactory.hxx>
      24             : #include <sfx2/basedlgs.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <vcl/msgbox.hxx>
      27             : #include <sfx2/htmlmode.hxx>
      28             : #include <viewopt.hxx>
      29             : #include <docsh.hxx>
      30             : #include <fldwrap.hxx>
      31             : #include <flddb.hxx>
      32             : #include <flddinf.hxx>
      33             : #include <fldvar.hxx>
      34             : #include <flddok.hxx>
      35             : #include <fldfunc.hxx>
      36             : #include <fldref.hxx>
      37             : #include <wrtsh.hxx>
      38             : #include <view.hxx>
      39             : #include <fldtdlg.hxx>
      40             : #include <swmodule.hxx>
      41             : 
      42             : #include <helpid.h>
      43             : #include <fldui.hrc>
      44             : #include <globals.hrc>
      45             : 
      46             : #include <com/sun/star/document/XDocumentProperties.hpp>
      47             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      48             : 
      49             : // carrier of the dialog
      50           0 : SwFieldDlg::SwFieldDlg(SfxBindings* pB, SwChildWinWrapper* pCW, vcl::Window *pParent)
      51             :     : SfxTabDialog(pParent, "FieldDialog", "modules/swriter/ui/fielddialog.ui")
      52             :     , m_pChildWin(pCW)
      53             :     , m_pBindings(pB)
      54             :     , m_bDataBaseMode(false)
      55             :     , m_nDokId(0)
      56             :     , m_nVarId(0)
      57             :     , m_nDokInf(0)
      58             :     , m_nRefId(0)
      59             :     , m_nFuncId(0)
      60           0 :     , m_nDbId(0)
      61             : {
      62           0 :     SetStyle(GetStyle()|WB_STDMODELESS);
      63           0 :     m_bHtmlMode = (::GetHtmlMode(static_cast<SwDocShell*>(SfxObjectShell::Current())) & HTMLMODE_ON) != 0;
      64             : 
      65           0 :     GetCancelButton().SetClickHdl(LINK(this, SwFieldDlg, CancelHdl));
      66             : 
      67           0 :     GetOKButton().SetClickHdl(LINK(this, SwFieldDlg, OKHdl));
      68             : 
      69           0 :     m_nDokId = AddTabPage("document", SwFieldDokPage::Create, 0);
      70           0 :     m_nVarId = AddTabPage("variables", SwFieldVarPage::Create, 0);
      71           0 :     m_nDokInf = AddTabPage("docinfo", SwFieldDokInfPage::Create, 0);
      72             : 
      73           0 :     if (!m_bHtmlMode)
      74             :     {
      75           0 :         m_nRefId = AddTabPage("ref", SwFieldRefPage::Create, 0);
      76           0 :         m_nFuncId = AddTabPage("functions", SwFieldFuncPage::Create, 0);
      77             : 
      78             :         utl::OConfigurationTreeRoot aCfgRoot
      79             :             = utl::OConfigurationTreeRoot::createWithComponentContext(
      80             :                 ::comphelper::getProcessComponentContext(),
      81             :                 OUString(
      82             :                         "/org.openoffice.Office.DataAccess/Policies/Features/Writer" ),
      83             :                 -1,
      84           0 :                 utl::OConfigurationTreeRoot::CM_READONLY);
      85             : 
      86           0 :         bool bDatabaseFields = true;
      87             :         aCfgRoot.getNodeValue(
      88           0 :             OUString("DatabaseFields")) >>= bDatabaseFields;
      89             : 
      90           0 :         if (bDatabaseFields)
      91           0 :             m_nDbId = AddTabPage("database", SwFieldDBPage::Create, 0);
      92             :         else
      93           0 :             RemoveTabPage("database");
      94             :     }
      95             :     else
      96             :     {
      97           0 :         RemoveTabPage("ref");
      98           0 :         RemoveTabPage("functions");
      99           0 :         RemoveTabPage("database");
     100             :     }
     101           0 : }
     102             : 
     103           0 : SwFieldDlg::~SwFieldDlg()
     104             : {
     105           0 : }
     106             : 
     107           0 : bool SwFieldDlg::Close()
     108             : {
     109             :     m_pBindings->GetDispatcher()->
     110             :         Execute(m_bDataBaseMode ? FN_INSERT_FIELD_DATA_ONLY : FN_INSERT_FIELD,
     111           0 :         SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
     112           0 :     return true;
     113             : }
     114             : 
     115           0 : void SwFieldDlg::Initialize(SfxChildWinInfo *pInfo)
     116             : {
     117           0 :     Point aPos;
     118           0 :     Size aSize;
     119             : 
     120           0 :     if ( pInfo->aSize.Width() != 0 && pInfo->aSize.Height() != 0 )
     121             :     {
     122           0 :         aPos = pInfo->aPos;
     123           0 :         if ( GetStyle() & WB_SIZEABLE )
     124           0 :             SetSizePixel( pInfo->aSize );
     125             : 
     126             :         // remember initial size from pInfo
     127           0 :         aSize = GetSizePixel();
     128             : 
     129             :         // should the FloatingWindow get zoomed?
     130           0 :         if ( pInfo->nFlags & SfxChildWindowFlags::ZOOMIN )
     131           0 :             RollUp();
     132             :     }
     133             :     else
     134             :     {
     135             :         // remember initial size from resource or ctor
     136           0 :         aSize = GetSizePixel();
     137             : 
     138           0 :         Size aParentSize = GetParent()->GetOutputSizePixel();
     139           0 :         aPos.X() += ( aParentSize.Width() - aSize.Width() ) / 2;
     140           0 :         aPos.Y() += ( aParentSize.Height() - aSize.Height() ) / 2;
     141             :     }
     142             : 
     143           0 :     Point aPoint;
     144           0 :     Rectangle aRect = GetDesktopRectPixel();
     145           0 :     aPoint.X() = aRect.Right() - aSize.Width();
     146           0 :     aPoint.Y() = aRect.Bottom() - aSize.Height();
     147             : 
     148           0 :     aPoint = OutputToScreenPixel( aPoint );
     149             : 
     150           0 :     if ( aPos.X() > aPoint.X() )
     151           0 :         aPos.X() = aPoint.X() ;
     152           0 :     if ( aPos.Y() > aPoint.Y() )
     153           0 :         aPos.Y() = aPoint.Y();
     154             : 
     155           0 :     if ( aPos.X() < 0 ) aPos.X() = 0;
     156           0 :     if ( aPos.Y() < 0 ) aPos.Y() = 0;
     157             : 
     158           0 :     SetPosPixel( aPos );
     159           0 : }
     160             : 
     161           0 : SfxItemSet* SwFieldDlg::CreateInputItemSet( sal_uInt16 nID  )
     162             : {
     163           0 :     if ( nID == m_nDokInf )
     164             :     {
     165           0 :         SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
     166           0 :         SfxItemSet* pISet = new SfxItemSet( pDocSh->GetPool(), SID_DOCINFO, SID_DOCINFO );
     167             :         using namespace ::com::sun::star;
     168             :         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     169           0 :             pDocSh->GetModel(), uno::UNO_QUERY_THROW);
     170             :         uno::Reference<document::XDocumentProperties> xDocProps
     171           0 :             = xDPS->getDocumentProperties();
     172             :         uno::Reference< beans::XPropertySet > xUDProps(
     173           0 :             xDocProps->getUserDefinedProperties(),
     174           0 :             uno::UNO_QUERY_THROW);
     175           0 :         pISet->Put( SfxUnoAnyItem( SID_DOCINFO, uno::makeAny(xUDProps) ) );
     176           0 :         return pISet;
     177             :     }
     178             :     else
     179           0 :         return 0;
     180             : }
     181             : 
     182             : // kick off inserting of new fields
     183           0 : IMPL_LINK_NOARG(SwFieldDlg, OKHdl)
     184             : {
     185           0 :     if (GetOKButton().IsEnabled())
     186             :     {
     187           0 :         SfxTabPage* pPage = GetTabPage(GetCurPageId());
     188           0 :         pPage->FillItemSet(0);
     189             : 
     190           0 :         GetOKButton().GrabFocus();  // because of InputField-Dlg
     191             :     }
     192             : 
     193           0 :     return 0;
     194             : }
     195             : 
     196           0 : IMPL_LINK_NOARG(SwFieldDlg, CancelHdl)
     197             : {
     198           0 :     Close();
     199           0 :     return 0;
     200             : }
     201             : 
     202             : // newly initialise dialog after Doc-Switch
     203           0 : void SwFieldDlg::ReInitDlg()
     204             : {
     205           0 :     SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
     206           0 :     bool bNewMode = (::GetHtmlMode(pDocSh) & HTMLMODE_ON) != 0;
     207             : 
     208           0 :     if (bNewMode != m_bHtmlMode)
     209             :     {
     210             :         SfxViewFrame::Current()->GetDispatcher()->
     211           0 :             Execute(FN_INSERT_FIELD, SfxCallMode::ASYNCHRON|SfxCallMode::RECORD);
     212           0 :         Close();
     213             :     }
     214             : 
     215           0 :     SwView* pActiveView = ::GetActiveView();
     216           0 :     if(!pActiveView)
     217           0 :         return;
     218           0 :     const SwWrtShell& rSh = pActiveView->GetWrtShell();
     219           0 :     GetOKButton().Enable( !rSh.IsReadOnlyAvailable() ||
     220           0 :                           !rSh.HasReadonlySel() );
     221             : 
     222           0 :     ReInitTabPage(m_nDokId);
     223           0 :     ReInitTabPage(m_nVarId);
     224           0 :     ReInitTabPage(m_nDokInf);
     225             : 
     226           0 :     if (!m_bHtmlMode)
     227             :     {
     228           0 :         ReInitTabPage(m_nRefId);
     229           0 :         ReInitTabPage(m_nFuncId);
     230           0 :         ReInitTabPage(m_nDbId);
     231             :     }
     232             : 
     233           0 :     m_pChildWin->SetOldDocShell(pDocSh);
     234             : }
     235             : 
     236             : // newly initialise TabPage after Doc-Switch
     237           0 : void SwFieldDlg::ReInitTabPage( sal_uInt16 nPageId, bool bOnlyActivate )
     238             : {
     239           0 :     SwFieldPage* pPage = static_cast<SwFieldPage* >(GetTabPage(nPageId));
     240           0 :     if ( pPage )
     241           0 :         pPage->EditNewField( bOnlyActivate );   // newly initialise TabPage
     242           0 : }
     243             : 
     244             : // newly initialise after activation of a few TabPages
     245           0 : void SwFieldDlg::Activate()
     246             : {
     247           0 :     SwView* pView = ::GetActiveView();
     248           0 :     if( pView )
     249             :     {
     250           0 :         bool bHtmlMode = (::GetHtmlMode(static_cast<SwDocShell*>(SfxObjectShell::Current())) & HTMLMODE_ON) != 0;
     251           0 :         const SwWrtShell& rSh = pView->GetWrtShell();
     252           0 :         GetOKButton().Enable( !rSh.IsReadOnlyAvailable() ||
     253           0 :                               !rSh.HasReadonlySel() );
     254             : 
     255           0 :         ReInitTabPage(m_nVarId, true);
     256             : 
     257           0 :         if( !bHtmlMode )
     258             :         {
     259           0 :             ReInitTabPage(m_nRefId, true);
     260           0 :             ReInitTabPage(m_nFuncId, true);
     261             :         }
     262             :     }
     263           0 : }
     264             : 
     265           0 : void SwFieldDlg::EnableInsert(bool bEnable)
     266             : {
     267           0 :     if( bEnable )
     268             :     {
     269           0 :         SwView* pView = ::GetActiveView();
     270             :         OSL_ENSURE(pView, "no view found");
     271           0 :         if( !pView ||
     272           0 :                 (pView->GetWrtShell().IsReadOnlyAvailable() &&
     273           0 :                     pView->GetWrtShell().HasReadonlySel()) )
     274           0 :             bEnable = false;
     275             :     }
     276           0 :     GetOKButton().Enable(bEnable);
     277           0 : }
     278             : 
     279           0 : void SwFieldDlg::InsertHdl()
     280             : {
     281           0 :     GetOKButton().Click();
     282           0 : }
     283             : 
     284           0 : void SwFieldDlg::ActivateDatabasePage()
     285             : {
     286           0 :     m_bDataBaseMode = true;
     287           0 :     ShowPage(m_nDbId);
     288           0 :     SfxTabPage* pDBPage = GetTabPage(m_nDbId);
     289           0 :     if( pDBPage )
     290             :     {
     291           0 :         static_cast<SwFieldDBPage*>(pDBPage)->ActivateMailMergeAddress();
     292             :     }
     293             :     //remove all other pages
     294           0 :     RemoveTabPage("document");
     295           0 :     RemoveTabPage("variables");
     296           0 :     RemoveTabPage("docinfo");
     297           0 :     RemoveTabPage("ref");
     298           0 :     RemoveTabPage("functions");
     299           0 : }
     300             : 
     301           0 : void SwFieldDlg::ShowReferencePage()
     302             : {
     303           0 :     ShowPage(m_nRefId);
     304           0 : }
     305             : 
     306           0 : void SwFieldDlg::PageCreated(sal_uInt16 nId, SfxTabPage& rPage)
     307             : {
     308           0 :     if (nId == m_nDbId)
     309             :     {
     310           0 :         SfxDispatcher* pDispatch = m_pBindings->GetDispatcher();
     311           0 :         SfxViewFrame* pViewFrame = pDispatch ? pDispatch->GetFrame() : 0;
     312           0 :         if(pViewFrame)
     313             :         {
     314           0 :             const TypeId aSwViewTypeId = TYPE(SwView);
     315           0 :             SfxViewShell* pViewShell = SfxViewShell::GetFirst( &aSwViewTypeId );
     316           0 :             while(pViewShell && pViewShell->GetViewFrame() != pViewFrame)
     317             :             {
     318           0 :                 pViewShell = SfxViewShell::GetNext( *pViewShell, &aSwViewTypeId );
     319             :             }
     320           0 :             if(pViewShell)
     321           0 :                 static_cast<SwFieldDBPage&>(rPage).SetWrtShell(static_cast<SwView*>(pViewShell)->GetWrtShell());
     322             :         }
     323             :     }
     324           0 : }
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11