LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/fldui - fldpage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 156 0.0 %
Date: 2012-12-27 Functions: 0 17 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 <vcl/lstbox.hxx>
      21             : #include <svl/stritem.hxx>
      22             : #include <sfx2/request.hxx>
      23             : #include <svx/htmlmode.hxx>
      24             : #include <dbfld.hxx>
      25             : #include <flddat.hxx>
      26             : #include <fmtfld.hxx>
      27             : #include <viewopt.hxx>
      28             : #include <fldedt.hxx>
      29             : #include <docsh.hxx>
      30             : #include <swmodule.hxx>
      31             : #include <view.hxx>
      32             : #include <wrtsh.hxx>
      33             : #include <expfld.hxx>
      34             : #include <fldtdlg.hxx>
      35             : #include <fldpage.hxx>
      36             : #include <docufld.hxx>
      37             : #include <cmdid.h>
      38             : #include <globals.hrc>
      39             : #include <sfx2/bindings.hxx>
      40             : #include <switerator.hxx>
      41             : 
      42             : using namespace ::com::sun::star;
      43             : 
      44           0 : SwFldPage::SwFldPage( Window *pParent, const ResId &rId,
      45             :                         const SfxItemSet &rAttrSet )
      46             :     :SfxTabPage     (pParent, rId, rAttrSet),
      47             :     m_pCurFld       (0),
      48             :     m_pWrtShell     (0),
      49           0 :     m_nPageId       ( static_cast< sal_uInt16 >(rId.GetId()) ),
      50             :     m_nTypeSel      (LISTBOX_ENTRY_NOTFOUND),
      51             :     m_nSelectionSel (LISTBOX_ENTRY_NOTFOUND),
      52             :     m_bFldEdit      (sal_False),
      53             :     m_bInsert           (sal_True),
      54             :     m_bFldDlgHtmlMode   (sal_False),
      55             :     m_bRefresh          (sal_False),
      56           0 :     m_bFirstHTMLInit    (sal_True)
      57             : {
      58             : 
      59           0 : }
      60             : 
      61           0 : SwFldPage::~SwFldPage()
      62             : {
      63           0 : }
      64             : 
      65             : /*--------------------------------------------------------------------
      66             :     Description: initialise TabPage
      67             :  --------------------------------------------------------------------*/
      68             : 
      69           0 : void SwFldPage::Init()
      70             : {
      71           0 :     SwDocShell* pDocSh = (SwDocShell*)SfxObjectShell::Current();
      72           0 :     sal_Bool bNewMode = 0 != (::GetHtmlMode(pDocSh) & HTMLMODE_ON);
      73             : 
      74           0 :     m_bFldEdit = 0 == GetTabDialog();
      75             : 
      76             :     // newly initialise FieldManager. important for
      77             :     // Dok-Switch (fldtdlg:ReInitTabPage)
      78           0 :     m_pCurFld = m_aMgr.GetCurFld();
      79             : 
      80           0 :     if( bNewMode != m_bFldDlgHtmlMode )
      81             :     {
      82           0 :         m_bFldDlgHtmlMode = bNewMode;
      83             : 
      84             :         // initialise Rangelistbox
      85           0 :         if( m_bFldDlgHtmlMode && m_bFirstHTMLInit )
      86             :         {
      87           0 :             m_bFirstHTMLInit = sal_False;
      88           0 :             SwWrtShell *pSh = m_pWrtShell;
      89           0 :             if(! pSh)
      90           0 :                 pSh = ::GetActiveWrtShell();
      91           0 :             if(pSh)
      92             :             {
      93           0 :                 SwDoc* pDoc = pSh->GetDoc();
      94             :                 pSh->InsertFldType( SwSetExpFieldType( pDoc,
      95           0 :                                     rtl::OUString("HTML_ON"), 1));
      96             :                 pSh->InsertFldType( SwSetExpFieldType(pDoc,
      97           0 :                                     rtl::OUString("HTML_OFF"), 1));
      98             :             }
      99             :         }
     100             :     }
     101           0 : }
     102             : 
     103             : /*--------------------------------------------------------------------
     104             :      Description: newly initialise page
     105             :  --------------------------------------------------------------------*/
     106             : 
     107           0 : void SwFldPage::ActivatePage()
     108             : {
     109           0 :     EnableInsert(m_bInsert);
     110           0 : }
     111             : 
     112             : /*--------------------------------------------------------------------
     113             :      Description: complete reset; edit new field
     114             :  --------------------------------------------------------------------*/
     115             : 
     116           0 : void SwFldPage::EditNewField( sal_Bool bOnlyActivate )
     117             : {
     118           0 :     if( !bOnlyActivate )
     119             :     {
     120           0 :         m_nTypeSel = LISTBOX_ENTRY_NOTFOUND;
     121             :     }
     122           0 :     m_nSelectionSel = LISTBOX_ENTRY_NOTFOUND;
     123           0 :     m_bRefresh = sal_True;
     124           0 :     Reset(*(SfxItemSet*)0);
     125           0 :     m_bRefresh = sal_False;
     126           0 : }
     127             : 
     128             : /*--------------------------------------------------------------------
     129             :      Description: insert field
     130             :  --------------------------------------------------------------------*/
     131             : 
     132           0 : sal_Bool SwFldPage::InsertFld(sal_uInt16 nTypeId, sal_uInt16 nSubType, const String& rPar1,
     133             :                             const String& rPar2, sal_uLong nFormatId,
     134             :                             sal_Unicode cSeparator, sal_Bool bIsAutomaticLanguage)
     135             : {
     136           0 :     sal_Bool bRet = sal_False;
     137           0 :     SwView* pView = GetActiveView();
     138           0 :     SwWrtShell *pSh = m_pWrtShell ? m_pWrtShell : pView->GetWrtShellPtr();
     139             : 
     140           0 :     if (!IsFldEdit())   // insert new field
     141             :     {
     142           0 :         SwInsertFld_Data aData(nTypeId, nSubType, rPar1, rPar2, nFormatId, 0, cSeparator, bIsAutomaticLanguage );
     143             :         //#i26566# provide parent for SwWrtShell::StartInputFldDlg
     144           0 :         aData.pParent = &GetTabDialog()->GetOKButton();
     145           0 :         bRet = m_aMgr.InsertFld( aData );
     146             : 
     147             :         uno::Reference< frame::XDispatchRecorder > xRecorder =
     148           0 :                 pView->GetViewFrame()->GetBindings().GetRecorder();
     149           0 :         if ( xRecorder.is() )
     150             :         {
     151             :             sal_Bool bRecordDB = TYP_DBFLD == nTypeId ||
     152             :                             TYP_DBSETNUMBERFLD == nTypeId ||
     153             :                             TYP_DBNUMSETFLD == nTypeId ||
     154             :                             TYP_DBNEXTSETFLD == nTypeId ||
     155           0 :                             TYP_DBNAMEFLD == nTypeId ;
     156             : 
     157             :             SfxRequest aReq( pView->GetViewFrame(),
     158           0 :                     bRecordDB ?  FN_INSERT_DBFIELD : FN_INSERT_FIELD );
     159           0 :             if(bRecordDB)
     160             :             {
     161             :                 aReq.AppendItem(SfxStringItem
     162           0 :                         (FN_INSERT_DBFIELD,rPar1.GetToken(0, DB_DELIM)));
     163             :                 aReq.AppendItem(SfxStringItem
     164           0 :                         (FN_PARAM_1,rPar1.GetToken(1, DB_DELIM)));
     165             :                 aReq.AppendItem(SfxInt32Item
     166           0 :                         (FN_PARAM_3,rPar1.GetToken(1, DB_DELIM).ToInt32()));
     167             :                 aReq.AppendItem(SfxStringItem
     168           0 :                         (FN_PARAM_2,rPar1.GetToken(3, DB_DELIM)));
     169             :             }
     170             :             else
     171             :             {
     172           0 :                 aReq.AppendItem(SfxStringItem(FN_INSERT_FIELD, rPar1));
     173             :                 aReq.AppendItem(SfxStringItem
     174           0 :                         (FN_PARAM_3, rtl::OUString(cSeparator)));
     175           0 :                 aReq.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_SUBTYPE, nSubType));
     176             :             }
     177           0 :             aReq.AppendItem(SfxUInt16Item(FN_PARAM_FIELD_TYPE   , nTypeId));
     178           0 :             aReq.AppendItem(SfxStringItem(FN_PARAM_FIELD_CONTENT, rPar2));
     179           0 :             aReq.AppendItem(SfxUInt32Item(FN_PARAM_FIELD_FORMAT , nFormatId));
     180           0 :             aReq.Done();
     181           0 :         }
     182             : 
     183             :     }
     184             :     else    // change field
     185             :     {
     186           0 :         SwField *const pTmpFld = m_pCurFld->CopyField();
     187             : 
     188           0 :         String sPar1(rPar1);
     189           0 :         String sPar2(rPar2);
     190           0 :         switch( nTypeId )
     191             :         {
     192             :         case TYP_DATEFLD:
     193             :         case TYP_TIMEFLD:
     194             :             nSubType = static_cast< sal_uInt16 >(((nTypeId == TYP_DATEFLD) ? DATEFLD : TIMEFLD) |
     195           0 :                        ((nSubType == DATE_VAR) ? 0 : FIXEDFLD));
     196           0 :             break;
     197             : 
     198             :         case TYP_DBNAMEFLD:
     199             :         case TYP_DBNEXTSETFLD:
     200             :         case TYP_DBNUMSETFLD:
     201             :         case TYP_DBSETNUMBERFLD:
     202             :             {
     203           0 :                 xub_StrLen nPos = 0;
     204           0 :                 SwDBData aData;
     205             : 
     206           0 :                 aData.sDataSource = rPar1.GetToken(0, DB_DELIM, nPos);
     207           0 :                 aData.sCommand = rPar1.GetToken(0, DB_DELIM, nPos);
     208           0 :                 aData.nCommandType = rPar1.GetToken(0, DB_DELIM, nPos).ToInt32();
     209           0 :                 sPar1 = rPar1.Copy(nPos);
     210             : 
     211           0 :                 ((SwDBNameInfField*)pTmpFld)->SetDBData(aData);
     212             :             }
     213           0 :             break;
     214             : 
     215             :         case TYP_DBFLD:
     216             :             {
     217           0 :                 SwDBData aData;
     218           0 :                 aData.sDataSource = rPar1.GetToken(0, DB_DELIM);
     219           0 :                 aData.sCommand = rPar1.GetToken(1, DB_DELIM);
     220           0 :                 aData.nCommandType = rPar1.GetToken(2, DB_DELIM).ToInt32();
     221           0 :                 String sColumn = rPar1.GetToken(3, DB_DELIM);
     222             : 
     223           0 :                 SwDBFieldType* pOldTyp = (SwDBFieldType*)pTmpFld->GetTyp();
     224             :                 SwDBFieldType* pTyp = (SwDBFieldType*)pSh->InsertFldType(
     225           0 :                         SwDBFieldType(pSh->GetDoc(), sColumn, aData));
     226             : 
     227           0 :                 SwIterator<SwFmtFld,SwFieldType> aIter( *pOldTyp );
     228             : 
     229           0 :                 for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
     230             :                 {
     231           0 :                     if( pFmtFld->GetFld() == m_pCurFld)
     232             :                     {
     233           0 :                         pFmtFld->RegisterToFieldType(*pTyp);
     234           0 :                         pTmpFld->ChgTyp(pTyp);
     235           0 :                         break;
     236             :                     }
     237           0 :                 }
     238             :             }
     239           0 :             break;
     240             : 
     241             :         case TYP_SEQFLD:
     242             :             {
     243           0 :                 SwSetExpFieldType* pTyp = (SwSetExpFieldType*)pTmpFld->GetTyp();
     244           0 :                 pTyp->SetOutlineLvl( static_cast< sal_uInt8 >(nSubType & 0xff));
     245           0 :                 pTyp->SetDelimiter(rtl::OUString(cSeparator));
     246             : 
     247           0 :                 nSubType = nsSwGetSetExpType::GSE_SEQ;
     248             :             }
     249           0 :             break;
     250             : 
     251             :         case TYP_INPUTFLD:
     252             :             {
     253             :                 // User- or SetField ?
     254           0 :                 if (m_aMgr.GetFldType(RES_USERFLD, sPar1) == 0 &&
     255           0 :                 !(pTmpFld->GetSubType() & INP_TXT)) // SETEXPFLD
     256             :                 {
     257           0 :                     SwSetExpField* pFld = (SwSetExpField*)pTmpFld;
     258           0 :                     pFld->SetPromptText(sPar2);
     259           0 :                     sPar2 = pFld->GetPar2();
     260             :                 }
     261             :             }
     262           0 :             break;
     263             :         case TYP_DOCINFOFLD:
     264             :             {
     265           0 :                 if( nSubType == nsSwDocInfoSubType::DI_CUSTOM )
     266             :                 {
     267           0 :                     SwDocInfoField* pDocInfo = static_cast<SwDocInfoField*>( pTmpFld );
     268           0 :                     pDocInfo->SetName( rPar1 );
     269             :                 }
     270             :             }
     271           0 :             break;
     272             :         }
     273             : 
     274           0 :         pSh->StartAllAction();
     275             : 
     276           0 :         pTmpFld->SetSubType(nSubType);
     277           0 :         pTmpFld->SetAutomaticLanguage(bIsAutomaticLanguage);
     278             : 
     279           0 :         m_aMgr.UpdateCurFld( nFormatId, sPar1, sPar2, pTmpFld );
     280             : 
     281           0 :         m_pCurFld = m_aMgr.GetCurFld();
     282             : 
     283           0 :         switch (nTypeId)
     284             :         {
     285             :             case TYP_HIDDENTXTFLD:
     286             :             case TYP_HIDDENPARAFLD:
     287           0 :                 m_aMgr.EvalExpFlds(pSh);
     288           0 :                 break;
     289             :         }
     290             : 
     291           0 :         pSh->SetUndoNoResetModified();
     292           0 :         pSh->EndAllAction();
     293             :     }
     294             : 
     295           0 :     return bRet;
     296             : }
     297             : 
     298           0 : void SwFldPage::SavePos( const ListBox* pLst1, const ListBox* pLst2,
     299             :                          const ListBox* pLst3 )
     300             : {
     301           0 :     const ListBox* aLBArr [ coLBCount ] = { pLst1, pLst2, pLst3 };
     302             : 
     303           0 :     const ListBox** ppLB = aLBArr;
     304           0 :     for( int i = 0; i < coLBCount; ++i, ++ppLB )
     305           0 :         if( (*ppLB) && (*ppLB)->GetEntryCount() )
     306           0 :             m_aLstStrArr[ i ] = (*ppLB)->GetSelectEntry();
     307             :         else
     308           0 :             m_aLstStrArr[ i ].Erase();
     309           0 : }
     310             : 
     311           0 : void SwFldPage::RestorePos(ListBox* pLst1, ListBox* pLst2, ListBox* pLst3)
     312             : {
     313           0 :     sal_uInt16 nPos = 0;
     314           0 :     ListBox* aLBArr [ coLBCount ] = { pLst1, pLst2, pLst3 };
     315           0 :     ListBox** ppLB = aLBArr;
     316           0 :     for( int i = 0; i < coLBCount; ++i, ++ppLB )
     317           0 :         if( (*ppLB) && (*ppLB)->GetEntryCount() && m_aLstStrArr[ i ].Len() &&
     318             :             LISTBOX_ENTRY_NOTFOUND !=
     319           0 :                         ( nPos = (*ppLB)->GetEntryPos(m_aLstStrArr[ i ] ) ) )
     320           0 :             (*ppLB)->SelectEntryPos( nPos );
     321           0 : }
     322             : 
     323             : /*--------------------------------------------------------------------
     324             :      Description: Insert new fields
     325             :  --------------------------------------------------------------------*/
     326             : 
     327           0 : IMPL_LINK( SwFldPage, InsertHdl, Button *, pBtn )
     328             : {
     329           0 :     SwFldDlg *pDlg = (SwFldDlg*)GetTabDialog();
     330             : 
     331           0 :     if (pDlg)
     332             :     {
     333           0 :         pDlg->InsertHdl();
     334             : 
     335           0 :         if (pBtn)
     336           0 :             pBtn->GrabFocus();  // because of InputField-Dlg
     337             :     }
     338             :     else
     339             :     {
     340           0 :         SwFldEditDlg *pEditDlg = (SwFldEditDlg *)GetParent();
     341           0 :         pEditDlg->InsertHdl();
     342             :     }
     343             : 
     344           0 :     return 0;
     345             : }
     346             : 
     347             : /*--------------------------------------------------------------------
     348             :      Description: enable/disable "Insert"-Button
     349             :  --------------------------------------------------------------------*/
     350             : 
     351           0 : void SwFldPage::EnableInsert(sal_Bool bEnable)
     352             : {
     353           0 :     SwFldDlg *pDlg = (SwFldDlg*)GetTabDialog();
     354             : 
     355           0 :     if (pDlg)
     356             :     {
     357           0 :         if (pDlg->GetCurPageId() == m_nPageId)
     358           0 :             pDlg->EnableInsert(bEnable);
     359             :     }
     360             :     else
     361             :     {
     362           0 :         SwFldEditDlg *pEditDlg = (SwFldEditDlg *)GetParent();
     363           0 :         pEditDlg->EnableInsert(bEnable);
     364             :     }
     365             : 
     366           0 :     m_bInsert = bEnable;
     367           0 : }
     368             : 
     369           0 : IMPL_LINK_NOARG(SwFldPage, NumFormatHdl)
     370             : {
     371           0 :     InsertHdl();
     372             : 
     373           0 :     return 0;
     374             : }
     375             : 
     376           0 : void SwFldPage::SetWrtShell( SwWrtShell* pShell )
     377             : {
     378           0 :     m_pWrtShell = pShell;
     379           0 :     m_aMgr.SetWrtShell( pShell );
     380           0 : }
     381             : 
     382             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10