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

Generated by: LCOV version 1.10