LCOV - code coverage report
Current view: top level - sw/source/ui/misc - docfnote.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 209 0.0 %
Date: 2014-11-03 Functions: 0 26 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 :     ((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_pOffsetFld, "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_pFtnCharAnchorTemplBox, "charanchorstylelb");
     117           0 :     get(m_pFtnCharTextTemplBox, "charstylelb");
     118           0 : }
     119             : 
     120           0 : void SwEndNoteOptionPage::Reset( const SfxItemSet* )
     121             : {
     122           0 :     boost::scoped_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo( pSh->GetEndNoteInfo() )
     123           0 :                                           : new SwFtnInfo( pSh->GetFtnInfo() ));
     124           0 :     SfxObjectShell * pDocSh = SfxObjectShell::Current();
     125             : 
     126           0 :     if (PTR_CAST(SwWebDocShell, pDocSh))
     127           0 :         m_pStylesContainer->Hide();
     128             : 
     129           0 :     if ( bEndNote )
     130             :     {
     131           0 :         bPosDoc = true;
     132             :     }
     133             :     else
     134             :     {
     135           0 :         const SwFtnInfo &rInf = pSh->GetFtnInfo();
     136             :         // set position (page, chapter)
     137           0 :         if ( rInf.ePos == FTNPOS_PAGE )
     138             :         {
     139           0 :             m_pPosPageBox->Check();
     140           0 :             m_pPageTemplLbl->Enable(false);
     141           0 :             m_pPageTemplBox->Enable(false);
     142             :         }
     143             :         else
     144             :         {
     145           0 :             m_pPosChapterBox->Check();
     146           0 :             m_pNumCountBox->RemoveEntry(aNumPage);
     147           0 :             m_pNumCountBox->RemoveEntry(aNumChapter);
     148           0 :             bPosDoc = true;
     149             :         }
     150             :             // reference tests
     151           0 :         m_pContEdit->SetText(rInf.aQuoVadis);
     152           0 :         m_pContFromEdit->SetText(rInf.aErgoSum);
     153             : 
     154             :             // collected
     155           0 :         SelectNumbering(rInf.eNum);
     156             :     }
     157             : 
     158             :         // numbering
     159             :         // art
     160           0 :     m_pNumViewBox->SelectNumberingType( pInf->aFmt.GetNumberingType());
     161           0 :     m_pOffsetFld->SetValue(pInf->nFtnOffset + 1);
     162           0 :     m_pPrefixED->SetText(pInf->GetPrefix().replaceAll("\t", "\\t")); // fdo#65666
     163           0 :     m_pSuffixED->SetText(pInf->GetSuffix().replaceAll("\t", "\\t"));
     164             : 
     165             :     const SwCharFmt* pCharFmt = pInf->GetCharFmt(
     166           0 :                         *pSh->GetView().GetDocShell()->GetDoc());
     167           0 :     m_pFtnCharTextTemplBox->SelectEntry(pCharFmt->GetName());
     168           0 :     m_pFtnCharTextTemplBox->SaveValue();
     169             : 
     170           0 :     pCharFmt = pInf->GetAnchorCharFmt( *pSh->GetDoc() );
     171           0 :     m_pFtnCharAnchorTemplBox->SelectEntry( pCharFmt->GetName() );
     172           0 :     m_pFtnCharAnchorTemplBox->SaveValue();
     173             : 
     174             :         // styles   special regions
     175             :         // paragraph
     176           0 :     SfxStyleSheetBasePool* pStyleSheetPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
     177           0 :     pStyleSheetPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SWSTYLEBIT_EXTRA);
     178           0 :     SfxStyleSheetBase *pStyle = pStyleSheetPool->First();
     179           0 :     while(pStyle)
     180             :     {
     181           0 :         m_pParaTemplBox->InsertEntry(pStyle->GetName());
     182           0 :         pStyle = pStyleSheetPool->Next();
     183             :     }
     184             : 
     185           0 :     OUString sStr;
     186             :     SwStyleNameMapper::FillUIName( static_cast< sal_uInt16 >(bEndNote ? RES_POOLCOLL_ENDNOTE
     187           0 :                            : RES_POOLCOLL_FOOTNOTE), sStr );
     188           0 :     if(LISTBOX_ENTRY_NOTFOUND == m_pParaTemplBox->GetEntryPos( sStr ) )
     189           0 :         m_pParaTemplBox->InsertEntry( sStr );
     190             : 
     191           0 :     SwTxtFmtColl* pColl = pInf->GetFtnTxtColl();
     192           0 :     if( !pColl )
     193           0 :         m_pParaTemplBox->SelectEntry( sStr );      // Default
     194             :     else
     195             :     {
     196             :         OSL_ENSURE(!pColl->IsDefault(), "default style for footnotes is wrong");
     197           0 :         const sal_Int32 nPos = m_pParaTemplBox->GetEntryPos(pColl->GetName());
     198           0 :         if( LISTBOX_ENTRY_NOTFOUND != nPos )
     199           0 :             m_pParaTemplBox->SelectEntryPos( nPos );
     200             :         else
     201             :         {
     202           0 :             m_pParaTemplBox->InsertEntry(pColl->GetName());
     203           0 :             m_pParaTemplBox->SelectEntry(pColl->GetName());
     204             :         }
     205             :     }
     206             : 
     207             :     // page
     208           0 :     for( sal_uInt16 i = RES_POOLPAGE_BEGIN; i < RES_POOLPAGE_END; ++i )
     209           0 :         m_pPageTemplBox->InsertEntry(SwStyleNameMapper::GetUIName( i, OUString() ));
     210             : 
     211           0 :     const sal_uInt16 nCount = pSh->GetPageDescCnt();
     212           0 :     for(sal_uInt16 i = 0; i < nCount; ++i)
     213             :     {
     214           0 :         const SwPageDesc &rPageDesc = pSh->GetPageDesc(i);
     215           0 :         if(LISTBOX_ENTRY_NOTFOUND == m_pPageTemplBox->GetEntryPos(rPageDesc.GetName()))
     216           0 :             m_pPageTemplBox->InsertEntry(rPageDesc.GetName());
     217             :     }
     218             : 
     219           0 :     m_pPageTemplBox->SelectEntry( pInf->GetPageDesc( *pSh->GetDoc() )->GetName());
     220           0 : }
     221             : 
     222           0 : SwEndNoteOptionPage::~SwEndNoteOptionPage()
     223             : {
     224           0 : }
     225             : 
     226           0 : SfxTabPage *SwEndNoteOptionPage::Create( vcl::Window *pParent, const SfxItemSet *rSet )
     227             : {
     228           0 :     return new SwEndNoteOptionPage( pParent, true, *rSet );
     229             : }
     230             : 
     231             : // Different kinds of numbering; because the Listbox has varying numbers of
     232             : // entries, here are functions to set and query the intended kind of numbering.
     233           0 : void SwEndNoteOptionPage::SelectNumbering(int eNum)
     234             : {
     235           0 :     OUString sSelect;
     236           0 :     switch(eNum)
     237             :     {
     238             :         case FTNNUM_DOC:
     239           0 :             sSelect = aNumDoc;
     240           0 :         break;
     241             :         case FTNNUM_PAGE:
     242           0 :             sSelect = aNumPage;
     243           0 :         break;
     244             :         case FTNNUM_CHAPTER:
     245           0 :             sSelect = aNumChapter;
     246           0 :         break;
     247             : #if OSL_DEBUG_LEVEL > 0
     248             :         default:
     249             :             OSL_FAIL("Which numbering type?");
     250             : #endif
     251             :     }
     252           0 :     m_pNumCountBox->SelectEntry(sSelect);
     253           0 :     NumCountHdl(m_pNumCountBox);
     254           0 : }
     255             : 
     256           0 : int SwEndNoteOptionPage::GetNumbering() const
     257             : {
     258           0 :     const sal_Int32 nPos = m_pNumCountBox->GetSelectEntryPos();
     259           0 :     return (int) bPosDoc? nPos + 1: nPos;
     260             : }
     261             : 
     262           0 : void SwEndNoteOptionPage::SetShell( SwWrtShell &rShell )
     263             : {
     264           0 :     pSh = &rShell;
     265             :     // collect character templates
     266           0 :     m_pFtnCharTextTemplBox->Clear();
     267           0 :     m_pFtnCharAnchorTemplBox->Clear();
     268             :     ::FillCharStyleListBox(*m_pFtnCharTextTemplBox,
     269           0 :                         pSh->GetView().GetDocShell());
     270             : 
     271             :     ::FillCharStyleListBox(*m_pFtnCharAnchorTemplBox,
     272           0 :                         pSh->GetView().GetDocShell());
     273           0 : }
     274             : 
     275             : // Handler behind the button to collect the footnote at the page. In this case
     276             : // all kinds of numbering can be used.
     277           0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, PosPageHdl)
     278             : {
     279           0 :     const SwFtnNum eNum = (const SwFtnNum)GetNumbering();
     280           0 :     bPosDoc = false;
     281           0 :     if(LISTBOX_ENTRY_NOTFOUND == m_pNumCountBox->GetEntryPos(aNumPage))
     282             :     {
     283           0 :         m_pNumCountBox->InsertEntry(aNumPage, FTNNUM_PAGE);
     284           0 :         m_pNumCountBox->InsertEntry(aNumChapter, FTNNUM_CHAPTER);
     285           0 :         SelectNumbering(eNum);
     286             :     }
     287           0 :     m_pPageTemplLbl->Enable(false);
     288           0 :     m_pPageTemplBox->Enable(false);
     289             : 
     290           0 :     return 0;
     291             : }
     292             : 
     293           0 : IMPL_LINK_NOARG(SwEndNoteOptionPage, NumCountHdl)
     294             : {
     295           0 :     bool bEnable = true;
     296           0 :     if( m_pNumCountBox->GetEntryCount() - 1 != m_pNumCountBox->GetSelectEntryPos() )
     297             :     {
     298           0 :         bEnable = false;
     299           0 :         m_pOffsetFld->SetValue(1);
     300             :     }
     301           0 :     m_pOffsetLbl->Enable(bEnable);
     302           0 :     m_pOffsetFld->Enable(bEnable);
     303           0 :     return 0;
     304             : }
     305             : 
     306             : // Handler behind the button to collect the footnote at the chapter or end of
     307             : // the document. In this case no pagewise numbering can be used.
     308           0 : IMPL_LINK_NOARG_INLINE_START(SwEndNoteOptionPage, PosChapterHdl)
     309             : {
     310           0 :     if ( !bPosDoc )
     311           0 :         SelectNumbering(FTNNUM_DOC);
     312             : 
     313           0 :     bPosDoc = true;
     314           0 :     m_pNumCountBox->RemoveEntry(aNumPage);
     315           0 :     m_pNumCountBox->RemoveEntry(aNumChapter);
     316           0 :     m_pPageTemplLbl->Enable();
     317           0 :     m_pPageTemplBox->Enable();
     318           0 :     return 0;
     319             : }
     320           0 : IMPL_LINK_NOARG_INLINE_END(SwEndNoteOptionPage, PosChapterHdl)
     321             : 
     322           0 : static SwCharFmt* lcl_GetCharFormat( SwWrtShell* pSh, const OUString& rCharFmtName )
     323             : {
     324           0 :     SwCharFmt* pFmt = 0;
     325           0 :     const sal_uInt16 nChCount = pSh->GetCharFmtCount();
     326           0 :     for(sal_uInt16 i = 0; i< nChCount; i++)
     327             :     {
     328           0 :         SwCharFmt& rChFmt = pSh->GetCharFmt(i);
     329           0 :         if(rChFmt.GetName() == rCharFmtName )
     330             :         {
     331           0 :             pFmt = &rChFmt;
     332           0 :             break;
     333             :         }
     334             :     }
     335           0 :     if(!pFmt)
     336             :     {
     337           0 :         SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
     338             :         SfxStyleSheetBase* pBase;
     339           0 :         pBase = pPool->Find(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
     340           0 :         if(!pBase)
     341           0 :             pBase = &pPool->Make(rCharFmtName, SFX_STYLE_FAMILY_CHAR);
     342           0 :         pFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
     343             :     }
     344           0 :     return pFmt;
     345             : }
     346             : 
     347           0 : bool SwEndNoteOptionPage::FillItemSet( SfxItemSet * )
     348             : {
     349           0 :     boost::scoped_ptr<SwEndNoteInfo> pInf(bEndNote ? new SwEndNoteInfo() : new SwFtnInfo());
     350             : 
     351           0 :     pInf->nFtnOffset = static_cast< sal_uInt16 >(m_pOffsetFld->GetValue() -1);
     352           0 :     pInf->aFmt.SetNumberingType(m_pNumViewBox->GetSelectedNumberingType() );
     353           0 :     pInf->SetPrefix(m_pPrefixED->GetText().replaceAll("\\t", "\t"));
     354           0 :     pInf->SetSuffix(m_pSuffixED->GetText().replaceAll("\\t", "\t"));
     355             : 
     356             :     pInf->SetCharFmt( lcl_GetCharFormat( pSh,
     357           0 :                         m_pFtnCharTextTemplBox->GetSelectEntry() ) );
     358             :     pInf->SetAnchorCharFmt( lcl_GetCharFormat( pSh,
     359           0 :                         m_pFtnCharAnchorTemplBox->GetSelectEntry() ) );
     360             : 
     361             :     // paragraph template
     362           0 :     sal_Int32 nPos = m_pParaTemplBox->GetSelectEntryPos();
     363           0 :     if(LISTBOX_ENTRY_NOTFOUND != nPos)
     364             :     {
     365           0 :         const OUString aFmtName( m_pParaTemplBox->GetSelectEntry() );
     366           0 :         SwTxtFmtColl *pColl = pSh->GetParaStyle(aFmtName, SwWrtShell::GETSTYLE_CREATEANY);
     367             :         OSL_ENSURE(pColl, "paragraph style not found");
     368           0 :         pInf->SetFtnTxtColl(*pColl);
     369             :     }
     370             : 
     371             :     // page template
     372             :     pInf->ChgPageDesc( pSh->FindPageDescByName(
     373           0 :                                 m_pPageTemplBox->GetSelectEntry(), true ) );
     374             : 
     375           0 :     if ( bEndNote )
     376             :     {
     377           0 :         if ( !(*pInf == pSh->GetEndNoteInfo()) )
     378           0 :             pSh->SetEndNoteInfo( *pInf );
     379             :     }
     380             :     else
     381             :     {
     382           0 :         SwFtnInfo *pI = (SwFtnInfo*)pInf.get();
     383           0 :         pI->ePos = m_pPosPageBox->IsChecked() ? FTNPOS_PAGE : FTNPOS_CHAPTER;
     384           0 :         pI->eNum = (SwFtnNum)GetNumbering();
     385           0 :         pI->aQuoVadis = m_pContEdit->GetText();
     386           0 :         pI->aErgoSum = m_pContFromEdit->GetText();
     387           0 :         if ( !(*pI == pSh->GetFtnInfo()) )
     388           0 :             pSh->SetFtnInfo( *pI );
     389             :     }
     390           0 :     return true;
     391             : }
     392             : 
     393           0 : SwFootNoteOptionPage::SwFootNoteOptionPage( vcl::Window *pParent, const SfxItemSet &rSet ) :
     394           0 :     SwEndNoteOptionPage( pParent, false, rSet )
     395             : {
     396           0 : }
     397             : 
     398           0 : SwFootNoteOptionPage::~SwFootNoteOptionPage()
     399             : {
     400           0 : }
     401             : 
     402           0 : SfxTabPage *SwFootNoteOptionPage::Create(vcl::Window *pParent, const SfxItemSet *rSet )
     403             : {
     404           0 :     return new SwFootNoteOptionPage( pParent, *rSet );
     405           0 : }
     406             : 
     407             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10