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

Generated by: LCOV version 1.10