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

Generated by: LCOV version 1.10