LCOV - code coverage report
Current view: top level - sw/source/ui/misc - docfnote.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 231 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 27 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 <svl/style.hxx>
      21             : #include <wrtsh.hxx>
      22             : #include <view.hxx>
      23             : #include <docsh.hxx>
      24             : #include <docfnote.hxx>
      25             : #include <impfnote.hxx>
      26             : #include <ftninfo.hxx>
      27             : #include <fmtcol.hxx>
      28             : #include <pagedesc.hxx>
      29             : #include <charfmt.hxx>
      30             : #include <docstyle.hxx>
      31             : #include <wdocsh.hxx>
      32             : #include <uitool.hxx>
      33             : #include <poolfmt.hxx>
      34             : #include <swstyle.h>
      35             : #include <helpid.h>
      36             : #include <misc.hrc>
      37             : #include <frmui.hrc>
      38             : #include <SwStyleNameMapper.hxx>
      39             : #include <boost/scoped_ptr.hpp>
      40             : 
      41           0 : SwFootNoteOptionDlg::SwFootNoteOptionDlg(vcl::Window *pParent, SwWrtShell &rS)
      42             :     : SfxTabDialog(pParent, "FootEndnoteDialog", "modules/swriter/ui/footendnotedialog.ui")
      43           0 :     , rSh( rS )
      44             : {
      45           0 :     RemoveResetButton();
      46             : 
      47           0 :     aOldOkHdl = GetOKButton().GetClickHdl();
      48           0 :     GetOKButton().SetClickHdl( LINK( this, SwFootNoteOptionDlg, OkHdl ) );
      49             : 
      50           0 :     m_nFootNoteId = AddTabPage( "footnotes", SwFootNoteOptionPage::Create, 0 );
      51           0 :     m_nEndNoteId = AddTabPage( "endnotes",  SwEndNoteOptionPage::Create, 0 );
      52           0 : }
      53             : 
      54           0 : void SwFootNoteOptionDlg::PageCreated( sal_uInt16 /*nId*/, SfxTabPage &rPage )
      55             : {
      56           0 :     static_cast<SwEndNoteOptionPage&>(rPage).SetShell( rSh );
      57           0 : }
      58             : 
      59           0 : IMPL_LINK( SwFootNoteOptionDlg, OkHdl, Button *, pBtn )
      60             : {
      61           0 :     SfxItemSet aDummySet(rSh.GetAttrPool(), 1, 1 );
      62           0 :     SfxTabPage *pPage = GetTabPage( m_nFootNoteId );
      63           0 :     if ( pPage )
      64           0 :         pPage->FillItemSet( &aDummySet );
      65           0 :     pPage = GetTabPage( m_nEndNoteId );
      66           0 :     if ( pPage )
      67           0 :         pPage->FillItemSet( &aDummySet );
      68           0 :     aOldOkHdl.Call( pBtn );
      69           0 :     return 0;
      70             : }
      71             : 
      72           0 : SwEndNoteOptionPage::SwEndNoteOptionPage(vcl::Window *pParent, bool bEN,
      73             :     const SfxItemSet &rSet)
      74             :     : SfxTabPage(pParent,
      75             :         bEN ? OString("EndnotePage") : OString("FootnotePage"),
      76             :         bEN ? OUString("modules/swriter/ui/endnotepage.ui") : OUString("modules/swriter/ui/footnotepage.ui"),
      77             :         &rSet)
      78             :     , m_pNumCountBox(NULL)
      79             :     , m_pPosFT(NULL)
      80             :     , m_pPosPageBox(NULL)
      81             :     , m_pPosChapterBox(NULL)
      82             :     , m_pContEdit(NULL)
      83             :     , m_pContFromEdit(NULL)
      84             :     , pSh(0)
      85             :     , bPosDoc(false)
      86           0 :     , bEndNote(bEN)
      87             : {
      88           0 :     get(m_pNumViewBox, "numberinglb");
      89           0 :     get(m_pOffsetLbl, "offset");
      90           0 :     get(m_pOffsetField, "offsetnf");
      91           0 :     get(m_pPrefixED, "prefix");
      92           0 :     get(m_pSuffixED, "suffix");
      93             : 
      94           0 :     if (!bEndNote)
      95             :     {
      96           0 :         get(m_pNumCountBox, "countinglb");
      97           0 :         m_pNumCountBox->SetSelectHdl(LINK(this, SwEndNoteOptionPage, NumCountHdl));
      98           0 :         aNumDoc = m_pNumCountBox->GetEntry(FTNNUM_DOC);
      99           0 :         aNumPage = m_pNumCountBox->GetEntry(FTNNUM_PAGE);
     100           0 :         aNumChapter = m_pNumCountBox->GetEntry(FTNNUM_CHAPTER);
     101           0 :         get(m_pPosPageBox, "pospagecb");
     102           0 :         m_pPosPageBox->SetClickHdl(LINK(this, SwEndNoteOptionPage, PosPageHdl));
     103           0 :         get(m_pPosChapterBox, "posdoccb");
     104           0 :         m_pPosChapterBox->SetClickHdl(LINK(this, SwEndNoteOptionPage, PosChapterHdl));
     105           0 :         get(m_pPosFT, "pos");
     106           0 :         m_pPosPageBox->SetAccessibleRelationMemberOf(m_pPosFT);
     107           0 :         m_pPosChapterBox->SetAccessibleRelationMemberOf(m_pPosFT);
     108           0 :         get(m_pContEdit, "conted");
     109           0 :         get(m_pContFromEdit, "contfromed");
     110             :     }
     111             : 
     112           0 :     get(m_pStylesContainer, "allstyles");
     113           0 :     get(m_pParaTemplBox, "parastylelb");
     114           0 :     get(m_pPageTemplLbl, "pagestyleft");
     115           0 :     get(m_pPageTemplBox, "pagestylelb");
     116           0 :     get(m_pFootnoteCharAnchorTemplBox, "charanchorstylelb");
     117           0 :     get(m_pFootnoteCharTextTemplBox, "charstylelb");
     118           0 : }
     119             : 
     120           0 : SwEndNoteOptionPage::~SwEndNoteOptionPage()
     121             : {
     122           0 :     disposeOnce();
     123           0 : }
     124             : 
     125           0 : void SwEndNoteOptionPage::dispose()
     126             : {
     127           0 :     m_pNumViewBox.clear();
     128           0 :     m_pOffsetLbl.clear();
     129           0 :     m_pOffsetField.clear();
     130           0 :     m_pNumCountBox.clear();
     131           0 :     m_pPrefixED.clear();
     132           0 :     m_pSuffixED.clear();
     133           0 :     m_pPosFT.clear();
     134           0 :     m_pPosPageBox.clear();
     135           0 :     m_pPosChapterBox.clear();
     136           0 :     m_pStylesContainer.clear();
     137           0 :     m_pParaTemplBox.clear();
     138           0 :     m_pPageTemplLbl.clear();
     139           0 :     m_pPageTemplBox.clear();
     140           0 :     m_pFootnoteCharAnchorTemplBox.clear();
     141           0 :     m_pFootnoteCharTextTemplBox.clear();
     142           0 :     m_pContEdit.clear();
     143           0 :     m_pContFromEdit.clear();
     144           0 :     SfxTabPage::dispose();
     145           0 : }
     146             : 
     147           0 : void SwEndNoteOptionPage::Reset( const SfxItemSet* )
     148             : {
     149           0 :     boost::scoped_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
     150           0 :                                           : new SwFootnoteInfo( pSh->GetFootnoteInfo() ));
     151           0 :     SfxObjectShell * pDocSh = SfxObjectShell::Current();
     152             : 
     153           0 :     if (PTR_CAST(SwWebDocShell, pDocSh))
     154           0 :         m_pStylesContainer->Hide();
     155             : 
     156           0 :     if ( bEndNote )
     157             :     {
     158           0 :         bPosDoc = true;
     159             :     }
     160             :     else
     161             :     {
     162           0 :         const SwFootnoteInfo &rInf = pSh->GetFootnoteInfo();
     163             :         // set position (page, chapter)
     164           0 :         if ( rInf.ePos == FTNPOS_PAGE )
     165             :         {
     166           0 :             m_pPosPageBox->Check();
     167           0 :             m_pPageTemplLbl->Enable(false);
     168           0 :             m_pPageTemplBox->Enable(false);
     169             :         }
     170             :         else
     171             :         {
     172           0 :             m_pPosChapterBox->Check();
     173           0 :             m_pNumCountBox->RemoveEntry(aNumPage);
     174           0 :             m_pNumCountBox->RemoveEntry(aNumChapter);
     175           0 :             bPosDoc = true;
     176             :         }
     177             :             // reference tests
     178           0 :         m_pContEdit->SetText(rInf.aQuoVadis);
     179           0 :         m_pContFromEdit->SetText(rInf.aErgoSum);
     180             : 
     181             :             // collected
     182           0 :         SelectNumbering(rInf.eNum);
     183             :     }
     184             : 
     185             :         // numbering
     186             :         // art
     187           0 :     m_pNumViewBox->SelectNumberingType( pInf->aFormat.GetNumberingType());
     188           0 :     m_pOffsetField->SetValue(pInf->nFootnoteOffset + 1);
     189           0 :     m_pPrefixED->SetText(pInf->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
     190           0 :     m_pSuffixED->SetText(pInf->GetSuffix().replaceAll("\t", "\\t"));
     191             : 
     192             :     const SwCharFormat* pCharFormat = pInf->GetCharFormat(
     193           0 :                         *pSh->GetView().GetDocShell()->GetDoc());
     194           0 :     m_pFootnoteCharTextTemplBox->SelectEntry(pCharFormat->GetName());
     195           0 :     m_pFootnoteCharTextTemplBox->SaveValue();
     196             : 
     197           0 :     pCharFormat = pInf->GetAnchorCharFormat( *pSh->GetDoc() );
     198           0 :     m_pFootnoteCharAnchorTemplBox->SelectEntry( pCharFormat->GetName() );
     199           0 :     m_pFootnoteCharAnchorTemplBox->SaveValue();
     200             : 
     201             :         // styles   special regions
     202             :         // paragraph
     203           0 :     SfxStyleSheetBasePool* pStyleSheetPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
     204           0 :     pStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SWSTYLEBIT_EXTRA);
     205           0 :     SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
     206           0 :     while(pStyle)
     207             :     {
     208           0 :         m_pParaTemplBox->InsertEntry(pStyle->GetName());
     209           0 :         pStyle = pStyleSheetPool->Next();
     210             :     }
     211             : 
     212           0 :     OUString sStr;
     213             :     SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
     214           0 :                            : RES_POOLCOLL_FOOTNOTE), sStr );
     215           0 :     if(LISTBOX_ENTRY_NOTFOUND == m_pParaTemplBox->GetEntryPos( sStr ) )
     216           0 :         m_pParaTemplBox->InsertEntry( sStr );
     217             : 
     218           0 :     SwTextFormatColl* pColl = pInf->GetFootnoteTextColl();
     219           0 :     if( !pColl )
     220           0 :         m_pParaTemplBox->SelectEntry( sStr );      // Default
     221             :     else
     222             :     {
     223             :         OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
     224           0 :         const sal_Int32 nPos = m_pParaTemplBox->GetEntryPos(pColl->GetName());
     225           0 :         if( LISTBOX_ENTRY_NOTFOUND != nPos )
     226           0 :             m_pParaTemplBox->SelectEntryPos( nPos );
     227             :         else
     228             :         {
     229           0 :             m_pParaTemplBox->InsertEntry(pColl->GetName());
     230           0 :             m_pParaTemplBox->SelectEntry(pColl->GetName());
     231             :         }
     232             :     }
     233             : 
     234             :     // page
     235           0 :     for( sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i )
     236           0 :         m_pPageTemplBox->InsertEntry(SwStyleNameMapper::GetUIName( i, OUString() ));
     237             : 
     238           0 :     const size_t nCount = pSh->GetPageDescCnt();
     239           0 :     for(size_t i = 0; i < nCount; ++i)
     240             :     {
     241           0 :         const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
     242           0 :         if(LISTBOX_ENTRY_NOTFOUND == m_pPageTemplBox->GetEntryPos(rPageDesc.GetName()))
     243           0 :             m_pPageTemplBox->InsertEntry(rPageDesc.GetName());
     244             :     }
     245             : 
     246           0 :     m_pPageTemplBox->SelectEntry( pInf->GetPageDesc( *pSh->GetDoc() )->GetName());
     247           0 : }
     248             : 
     249           0 : VclPtr<SfxTabPage> SwEndNoteOptionPage::Create( vcl::Window *pParent, const SfxItemSet *rSet )
     250             : {
     251           0 :     return VclPtr<SwEndNoteOptionPage>::Create( pParent, true, *rSet );
     252             : }
     253             : 
     254             : // Different kinds of numbering; because the Listbox has varying numbers of
     255             : // entries, here are functions to set and query the intended kind of numbering.
     256           0 : void SwEndNoteOptionPage::SelectNumbering(int eNum)
     257             : {
     258           0 :     OUString sSelect;
     259           0 :     switch(eNum)
     260             :     {
     261             :         case FTNNUM_DOC:
     262           0 :             sSelect = aNumDoc;
     263           0 :         break;
     264             :         case FTNNUM_PAGE:
     265           0 :             sSelect = aNumPage;
     266           0 :         break;
     267             :         case FTNNUM_CHAPTER:
     268           0 :             sSelect = aNumChapter;
     269           0 :         break;
     270             : #if OSL_DEBUG_LEVEL > 0
     271             :         default:
     272             :             OSL_FAIL("Which numbering type?");
     273             : #endif
     274             :     }
     275           0 :     m_pNumCountBox->SelectEntry(sSelect);
     276           0 :     NumCountHdl(m_pNumCountBox);
     277           0 : }
     278             : 
     279           0 : int SwEndNoteOptionPage::GetNumbering() const
     280             : {
     281           0 :     const sal_Int32 nPos = m_pNumCountBox->GetSelectEntryPos();
     282           0 :     return (int) bPosDoc? nPos + 1: nPos;
     283             : }
     284             : 
     285           0 : void SwEndNoteOptionPage::SetShell( SwWrtShell &rShell )
     286             : {
     287           0 :     pSh = &rShell;
     288             :     // collect character templates
     289           0 :     m_pFootnoteCharTextTemplBox->Clear();
     290           0 :     m_pFootnoteCharAnchorTemplBox->Clear();
     291           0 :     ::FillCharStyleListBox(*m_pFootnoteCharTextTemplBox,
     292           0 :                         pSh->GetView().GetDocShell());
     293             : 
     294           0 :     ::FillCharStyleListBox(*m_pFootnoteCharAnchorTemplBox,
     295           0 :                         pSh->GetView().GetDocShell());
     296           0 : }
     297             : 
     298             : // Handler behind the button to collect the footnote at the page. In this case
     299             : // all kinds of numbering can be used.
     300           0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, PosPageHdl)
     301             : {
     302           0 :     const SwFootnoteNum eNum = (const SwFootnoteNum)GetNumbering();
     303           0 :     bPosDoc = false;
     304           0 :     if(LISTBOX_ENTRY_NOTFOUND == m_pNumCountBox->GetEntryPos(aNumPage))
     305             :     {
     306           0 :         m_pNumCountBox->InsertEntry(aNumPage, FTNNUM_PAGE);
     307           0 :         m_pNumCountBox->InsertEntry(aNumChapter, FTNNUM_CHAPTER);
     308           0 :         SelectNumbering(eNum);
     309             :     }
     310           0 :     m_pPageTemplLbl->Enable(false);
     311           0 :     m_pPageTemplBox->Enable(false);
     312             : 
     313           0 :     return 0;
     314             : }
     315             : 
     316           0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, NumCountHdl)
     317             : {
     318           0 :     bool bEnable = true;
     319           0 :     if( m_pNumCountBox->GetEntryCount() - 1 != m_pNumCountBox->GetSelectEntryPos() )
     320             :     {
     321           0 :         bEnable = false;
     322           0 :         m_pOffsetField->SetValue(1);
     323             :     }
     324           0 :     m_pOffsetLbl->Enable(bEnable);
     325           0 :     m_pOffsetField->Enable(bEnable);
     326           0 :     return 0;
     327             : }
     328             : 
     329             : // Handler behind the button to collect the footnote at the chapter or end of
     330             : // the document. In this case no pagewise numbering can be used.
     331           0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, PosChapterHdl)
     332             : {
     333           0 :     if ( !bPosDoc )
     334           0 :         SelectNumbering(FTNNUM_DOC);
     335             : 
     336           0 :     bPosDoc = true;
     337           0 :     m_pNumCountBox->RemoveEntry(aNumPage);
     338           0 :     m_pNumCountBox->RemoveEntry(aNumChapter);
     339           0 :     m_pPageTemplLbl->Enable();
     340           0 :     m_pPageTemplBox->Enable();
     341           0 :     return 0;
     342             : }
     343             : 
     344           0 : static SwCharFormat* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFormatName )
     345             : {
     346           0 :     SwCharFormat* pFormat = 0;
     347           0 :     const sal_uInt16 nChCount = pSh->GetCharFormatCount();
     348           0 :     for(sal_uInt16 i = 0; i< nChCount; i++)
     349             :     {
     350           0 :         SwCharFormat& rChFormat = pSh->GetCharFormat(i);
     351           0 :         if(rChFormat.GetName() == rCharFormatName )
     352             :         {
     353           0 :             pFormat = &rChFormat;
     354           0 :             break;
     355             :         }
     356             :     }
     357           0 :     if(!pFormat)
     358             :     {
     359           0 :         SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
     360             :         SfxStyleSheetBase* pBase;
     361           0 :         pBase = pPool->Find(rCharFormatName, SFX_STYLE_FAMILY_CHAR);
     362           0 :         if(!pBase)
     363           0 :             pBase = &pPool->Make(rCharFormatName, SFX_STYLE_FAMILY_CHAR);
     364           0 :         pFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
     365             :     }
     366           0 :     return pFormat;
     367             : }
     368             : 
     369           0 : bool SwEndNoteOptionPage::FillItemSet( SfxItemSet * )
     370             : {
     371           0 :     boost::scoped_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo() : new SwFootnoteInfo());
     372             : 
     373           0 :     pInf->nFootnoteOffset = static_cast< sal_uInt16 >(m_pOffsetField->GetValue() -1);
     374           0 :     pInf->aFormat.SetNumberingType(m_pNumViewBox->GetSelectedNumberingType() );
     375           0 :     pInf->SetPrefix(m_pPrefixED->GetText().replaceAll("\\t", "\t"));
     376           0 :     pInf->SetSuffix(m_pSuffixED->GetText().replaceAll("\\t", "\t"));
     377             : 
     378             :     pInf->SetCharFormat( lcl_GetCharFormat( pSh,
     379           0 :                         m_pFootnoteCharTextTemplBox->GetSelectEntry() ) );
     380             :     pInf->SetAnchorCharFormat( lcl_GetCharFormat( pSh,
     381           0 :                         m_pFootnoteCharAnchorTemplBox->GetSelectEntry() ) );
     382             : 
     383             :     // paragraph template
     384           0 :     sal_Int32 nPos = m_pParaTemplBox->GetSelectEntryPos();
     385           0 :     if(LISTBOX_ENTRY_NOTFOUND != nPos)
     386             :     {
     387           0 :         const OUString aFormatName( m_pParaTemplBox->GetSelectEntry() );
     388           0 :         SwTextFormatColl *pColl = pSh->GetParaStyle(aFormatName, SwWrtShell::GETSTYLE_CREATEANY);
     389             :         OSL_ENSURE(pColl, "paragraph style not found");
     390           0 :         pInf->SetFootnoteTextColl(*pColl);
     391             :     }
     392             : 
     393             :     // page template
     394             :     pInf->ChgPageDesc( pSh->FindPageDescByName(
     395           0 :                                 m_pPageTemplBox->GetSelectEntry(), true ) );
     396             : 
     397           0 :     if ( bEndNote )
     398             :     {
     399           0 :         if ( !(*pInf == pSh->GetEndNoteInfo()) )
     400           0 :             pSh->SetEndNoteInfo( *pInf );
     401             :     }
     402             :     else
     403             :     {
     404           0 :         SwFootnoteInfo *pI = static_cast<SwFootnoteInfo*>(pInf.get());
     405           0 :         pI->ePos = m_pPosPageBox->IsChecked() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
     406           0 :         pI->eNum = (SwFootnoteNum)GetNumbering();
     407           0 :         pI->aQuoVadis = m_pContEdit->GetText();
     408           0 :         pI->aErgoSum = m_pContFromEdit->GetText();
     409           0 :         if ( !(*pI == pSh->GetFootnoteInfo()) )
     410           0 :             pSh->SetFootnoteInfo( *pI );
     411             :     }
     412           0 :     return true;
     413             : }
     414             : 
     415           0 : SwFootNoteOptionPage::SwFootNoteOptionPage( vcl::Window *pParent, const SfxItemSet &rSet ) :
     416           0 :     SwEndNoteOptionPage( pParent, false, rSet )
     417             : {
     418           0 : }
     419             : 
     420           0 : SwFootNoteOptionPage::~SwFootNoteOptionPage()
     421             : {
     422           0 : }
     423             : 
     424           0 : VclPtr<SfxTabPage> SwFootNoteOptionPage::Create(vcl::Window *pParent, const SfxItemSet *rSet )
     425             : {
     426           0 :     return VclPtr<SwFootNoteOptionPage>::Create( pParent, *rSet );
     427           0 : }
     428             : 
     429             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11