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

Generated by: LCOV version 1.10