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

Generated by: LCOV version 1.10