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

Generated by: LCOV version 1.11