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

Generated by: LCOV version 1.10