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

Generated by: LCOV version 1.10