LCOV - code coverage report
Current view: top level - sw/source/ui/misc - titlepage.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 186 0.0 %
Date: 2014-04-11 Functions: 0 24 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             : 
      10             : #include <sfx2/viewfrm.hxx>
      11             : #include <vcl/msgbox.hxx>
      12             : #include <view.hxx>
      13             : #include <swmodule.hxx>
      14             : #include <wrtsh.hxx>
      15             : #include <poolfmt.hxx>
      16             : #include <docsh.hxx>
      17             : #include <charfmt.hxx>
      18             : #include <docstyle.hxx>
      19             : 
      20             : #include "fldbas.hxx"
      21             : #include "lineinfo.hxx"
      22             : #include "globals.hrc"
      23             : #include "titlepage.hxx"
      24             : #include "uitool.hxx"
      25             : #include "fmtpdsc.hxx"
      26             : #include "pagedesc.hxx"
      27             : 
      28             : #include <IDocumentStylePoolAccess.hxx>
      29             : 
      30             : namespace
      31             : {
      32           0 :     bool lcl_GetPageDesc(SwWrtShell *pSh, sal_uInt16 &rPageNo, const SwFmtPageDesc **ppPageFmtDesc)
      33             :     {
      34           0 :         bool bRet = false;
      35           0 :         SfxItemSet aSet( pSh->GetAttrPool(), RES_PAGEDESC, RES_PAGEDESC );
      36           0 :         if (pSh->GetCurAttr( aSet ))
      37             :         {
      38           0 :             const SfxPoolItem* pItem(0);
      39           0 :             if (SFX_ITEM_SET == aSet.GetItemState( RES_PAGEDESC, true, &pItem ) && pItem)
      40             :             {
      41           0 :                 ::boost::optional<sal_uInt16> oNumOffset = ((const SwFmtPageDesc *)pItem)->GetNumOffset();
      42           0 :                 if (oNumOffset)
      43           0 :                     rPageNo = oNumOffset.get();
      44           0 :                 if (ppPageFmtDesc)
      45           0 :                     (*ppPageFmtDesc) = (const SwFmtPageDesc *)(pItem->Clone());
      46           0 :                 bRet = true;
      47             :             }
      48             :         }
      49           0 :         return bRet;
      50             :     }
      51             : 
      52           0 :     void lcl_ChangePage(SwWrtShell *pSh, sal_uInt16 nNewNumber,
      53             :         const SwPageDesc *pNewDesc)
      54             :     {
      55           0 :         const sal_uInt16 nCurIdx = pSh->GetCurPageDesc();
      56           0 :         const SwPageDesc &rCurrentDesc = pSh->GetPageDesc( nCurIdx );
      57             : 
      58           0 :         const SwFmtPageDesc *pPageFmtDesc(0);
      59             :         sal_uInt16 nDontCare;
      60           0 :         lcl_GetPageDesc(pSh, nDontCare, &pPageFmtDesc);
      61             : 
      62             :         // If we want a new number then set it, otherwise reuse the existing one
      63             :         sal_uInt16 nPgNo;
      64           0 :         if (nNewNumber)
      65             :         {
      66           0 :             nPgNo = nNewNumber;
      67             :         }
      68             :         else
      69             :         {
      70           0 :             if (pPageFmtDesc)
      71             :             {
      72           0 :                 ::boost::optional<sal_uInt16> oNumOffset = pPageFmtDesc->GetNumOffset();
      73           0 :                 if (oNumOffset)
      74             :                 {
      75           0 :                     nPgNo = oNumOffset.get();
      76             :                 }
      77             :                 else
      78             :                 {
      79           0 :                     nPgNo = 0;
      80           0 :                 }
      81             :             }
      82             :             else
      83             :             {
      84           0 :                 nPgNo = 0;
      85             :             }
      86             :         }
      87             : 
      88             :         // If we want a new descriptior then set it, otherwise reuse the existing one
      89           0 :         if (!pNewDesc)
      90             :         {
      91           0 :             SwFmtPageDesc aPageFmtDesc(pPageFmtDesc ? *pPageFmtDesc : &rCurrentDesc);
      92           0 :             if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
      93           0 :             pSh->SetAttrItem(aPageFmtDesc);
      94             :         }
      95             :         else
      96             :         {
      97           0 :             SwFmtPageDesc aPageFmtDesc(pNewDesc);
      98           0 :             if (nPgNo) aPageFmtDesc.SetNumOffset(nPgNo);
      99           0 :             pSh->SetAttrItem(aPageFmtDesc);
     100             :         }
     101             : 
     102           0 :         delete pPageFmtDesc;
     103           0 :     }
     104             : 
     105           0 :     void lcl_PushCursor(SwWrtShell *pSh)
     106             :     {
     107           0 :         pSh->LockView( sal_True );
     108           0 :         pSh->StartAllAction();
     109           0 :         pSh->SwCrsrShell::Push();
     110           0 :     }
     111             : 
     112           0 :     void lcl_PopCursor(SwWrtShell *pSh)
     113             :     {
     114           0 :         pSh->SwCrsrShell::Pop( sal_False );
     115           0 :         pSh->EndAllAction();
     116           0 :         pSh->LockView( sal_False );
     117           0 :     }
     118             : 
     119           0 :     sal_uInt16 lcl_GetCurrentPage(SwWrtShell *pSh)
     120             :     {
     121           0 :         OUString sDummy;
     122           0 :         sal_uInt16 nPhyNum=1, nVirtNum=1;
     123           0 :         pSh->GetPageNumber(0, true, nPhyNum, nVirtNum, sDummy);
     124           0 :         return nPhyNum;
     125             :     }
     126             : }
     127             : 
     128             : /*
     129             :  * Only include the Index page in the list if the page count implies one
     130             :  * to reduce confusing things
     131             :  */
     132           0 : void SwTitlePageDlg::FillList()
     133             : {
     134           0 :     sal_uInt16 nTitlePages = m_pPageCountNF->GetValue();
     135           0 :     m_pPagePropertiesLB->Clear();
     136           0 :     if (mpTitleDesc)
     137           0 :         m_pPagePropertiesLB->InsertEntry(mpTitleDesc->GetName());
     138           0 :     if (nTitlePages > 1 && mpIndexDesc)
     139           0 :         m_pPagePropertiesLB->InsertEntry(mpIndexDesc->GetName());
     140           0 :     if (mpNormalDesc)
     141           0 :         m_pPagePropertiesLB->InsertEntry(mpNormalDesc->GetName());
     142           0 :     m_pPagePropertiesLB->SelectEntryPos(0);
     143           0 : }
     144             : 
     145           0 : sal_uInt16 SwTitlePageDlg::GetInsertPosition() const
     146             : {
     147           0 :     sal_uInt16 nPage = 1;
     148           0 :     if (m_pPageStartNF->IsEnabled())
     149           0 :         nPage = m_pPageStartNF->GetValue();
     150           0 :     return nPage;
     151             : }
     152             : 
     153           0 : SwTitlePageDlg::SwTitlePageDlg( Window *pParent ) :
     154             :     SfxModalDialog( pParent, "DLG_TITLEPAGE", "modules/swriter/ui/titlepage.ui"),
     155           0 :     mpPageFmtDesc(0)
     156             : {
     157           0 :     get(m_pUseExistingPagesRB, "RB_USE_EXISTING_PAGES");
     158           0 :     get(m_pPageCountNF, "NF_PAGE_COUNT");
     159           0 :     get(m_pDocumentStartRB, "RB_DOCUMENT_START");
     160           0 :     get(m_pPageStartRB, "RB_PAGE_START");
     161           0 :     get(m_pPageStartNF, "NF_PAGE_START");
     162           0 :     get(m_pRestartNumberingCB, "CB_RESTART_NUMBERING");
     163           0 :     get(m_pRestartNumberingNF, "NF_RESTART_NUMBERING");
     164           0 :     get(m_pSetPageNumberCB, "CB_SET_PAGE_NUMBER");
     165           0 :     get(m_pSetPageNumberNF, "NF_SET_PAGE_NUMBER");
     166           0 :     get(m_pPagePropertiesLB, "LB_PAGE_PROPERTIES");
     167           0 :     get(m_pPagePropertiesPB, "PB_PAGE_PROPERTIES");
     168           0 :     get(m_pOkPB, "PB_OK");
     169             : 
     170           0 :     m_pOkPB->SetClickHdl(LINK(this, SwTitlePageDlg, OKHdl));
     171           0 :     m_pRestartNumberingCB->SetClickHdl(LINK(this, SwTitlePageDlg, RestartNumberingHdl));
     172           0 :     m_pSetPageNumberCB->SetClickHdl(LINK(this, SwTitlePageDlg, SetPageNumberHdl));
     173             : 
     174           0 :     sal_uInt16 nSetPage = 1;
     175           0 :     sal_uInt16 nResetPage = 1;
     176           0 :     sal_uInt16 nTitlePages = 1;
     177           0 :     mpSh = ::GetActiveView()->GetWrtShellPtr();
     178           0 :     lcl_PushCursor(mpSh);
     179             : 
     180           0 :     SwView& rView = mpSh->GetView();
     181           0 :     rView.InvalidateRulerPos();
     182             : 
     183           0 :     bool bMaybeResetNumbering = false;
     184             : 
     185           0 :     mpTitleDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_FIRST);
     186           0 :     mpIndexDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_REGISTER);
     187           0 :     mpNormalDesc = mpSh->GetPageDescFromPool(RES_POOLPAGE_STANDARD);
     188             : 
     189           0 :     mpSh->SttDoc();
     190           0 :     if (lcl_GetPageDesc( mpSh, nSetPage, &mpPageFmtDesc ))
     191             :     {
     192           0 :         if (mpPageFmtDesc->GetPageDesc() == mpTitleDesc)
     193             :         {
     194           0 :             while (mpSh->SttNxtPg())
     195             :             {
     196           0 :                 const sal_uInt16 nCurIdx = mpSh->GetCurPageDesc();
     197           0 :                 const SwPageDesc &rPageDesc = mpSh->GetPageDesc( nCurIdx );
     198             : 
     199           0 :                 if (mpIndexDesc != &rPageDesc)
     200             :                 {
     201           0 :                     mpNormalDesc = &rPageDesc;
     202           0 :                     bMaybeResetNumbering = lcl_GetPageDesc(mpSh, nResetPage, NULL);
     203           0 :                     break;
     204             :                 }
     205           0 :                 ++nTitlePages;
     206             :             }
     207             :         }
     208             :     }
     209           0 :     lcl_PopCursor(mpSh);
     210             : 
     211           0 :     m_pUseExistingPagesRB->Check();
     212           0 :     m_pPageCountNF->SetValue(nTitlePages);
     213           0 :     m_pPageCountNF->SetUpHdl(LINK(this, SwTitlePageDlg, UpHdl));
     214           0 :     m_pPageCountNF->SetDownHdl(LINK(this, SwTitlePageDlg, DownHdl));
     215             : 
     216           0 :     m_pDocumentStartRB->Check();
     217           0 :     m_pPageStartNF->Enable(false);
     218           0 :     m_pPageStartNF->SetValue(lcl_GetCurrentPage(mpSh));
     219           0 :     Link aStartPageHdl = LINK(this, SwTitlePageDlg, StartPageHdl);
     220           0 :     m_pDocumentStartRB->SetClickHdl(aStartPageHdl);
     221           0 :     m_pPageStartRB->SetClickHdl(aStartPageHdl);
     222             : 
     223           0 :     if (bMaybeResetNumbering && nResetPage > 0)
     224             :     {
     225           0 :         m_pRestartNumberingCB->Check();
     226           0 :         m_pRestartNumberingNF->SetValue(nResetPage);
     227             :     }
     228           0 :     m_pRestartNumberingNF->Enable(m_pRestartNumberingCB->IsChecked());
     229             : 
     230           0 :     m_pSetPageNumberNF->SetValue(nSetPage);
     231           0 :     if (nSetPage > 1)
     232           0 :         m_pSetPageNumberCB->Check();
     233           0 :     m_pSetPageNumberNF->Enable(m_pSetPageNumberCB->IsChecked());
     234             : 
     235           0 :     FillList();
     236           0 :     m_pPagePropertiesPB->SetClickHdl(LINK(this, SwTitlePageDlg, EditHdl));
     237           0 : }
     238             : 
     239           0 : IMPL_LINK_NOARG(SwTitlePageDlg, UpHdl)
     240             : {
     241           0 :     if (m_pPageCountNF->GetValue() == 2)
     242           0 :         FillList();
     243           0 :     return 0;
     244             : }
     245             : 
     246           0 : IMPL_LINK_NOARG(SwTitlePageDlg, DownHdl)
     247             : {
     248           0 :     if (m_pPageCountNF->GetValue() == 1)
     249           0 :         FillList();
     250           0 :     return 0;
     251             : }
     252             : 
     253           0 : IMPL_LINK_NOARG(SwTitlePageDlg, RestartNumberingHdl)
     254             : {
     255           0 :     m_pRestartNumberingNF->Enable(m_pRestartNumberingCB->IsChecked());
     256           0 :     return 0;
     257             : }
     258             : 
     259           0 : IMPL_LINK_NOARG(SwTitlePageDlg, SetPageNumberHdl)
     260             : {
     261           0 :     m_pSetPageNumberNF->Enable(m_pSetPageNumberCB->IsChecked());
     262           0 :     return 0;
     263             : }
     264             : 
     265           0 : IMPL_LINK_NOARG(SwTitlePageDlg, StartPageHdl)
     266             : {
     267           0 :     m_pPageStartNF->Enable(m_pPageStartRB->IsChecked());
     268           0 :     return 0;
     269             : }
     270             : 
     271           0 : SwTitlePageDlg::~SwTitlePageDlg()
     272             : {
     273           0 :     delete mpPageFmtDesc;
     274           0 : }
     275             : 
     276           0 : IMPL_LINK_NOARG(SwTitlePageDlg, EditHdl)
     277             : {
     278           0 :     SwView& rView = mpSh->GetView();
     279           0 :     rView.GetDocShell()->FormatPage(m_pPagePropertiesLB->GetSelectEntry(), "page", *mpSh);
     280           0 :     rView.InvalidateRulerPos();
     281             : 
     282           0 :     return 0;
     283             : }
     284             : 
     285           0 : IMPL_LINK_NOARG(SwTitlePageDlg, OKHdl)
     286             : {
     287           0 :     lcl_PushCursor(mpSh);
     288             : 
     289           0 :     mpSh->StartUndo();
     290             : 
     291           0 :     SwFmtPageDesc aTitleDesc(mpTitleDesc);
     292             : 
     293           0 :     if (m_pSetPageNumberCB->IsChecked())
     294           0 :         aTitleDesc.SetNumOffset(m_pSetPageNumberNF->GetValue());
     295           0 :     else if (mpPageFmtDesc)
     296           0 :         aTitleDesc.SetNumOffset(mpPageFmtDesc->GetNumOffset());
     297             : 
     298           0 :     sal_uInt16 nNoPages = m_pPageCountNF->GetValue();
     299           0 :     if (!m_pUseExistingPagesRB->IsChecked())
     300             :     {
     301           0 :         mpSh->GotoPage(GetInsertPosition(), false);
     302           0 :         for (sal_uInt16 nI=0; nI < nNoPages; ++nI)
     303           0 :             mpSh->InsertPageBreak();
     304             :     }
     305             : 
     306           0 :     mpSh->GotoPage(GetInsertPosition(), false);
     307           0 :     for (sal_uInt16 nI=1; nI < nNoPages; ++nI)
     308             :     {
     309           0 :         if (mpSh->SttNxtPg())
     310           0 :             lcl_ChangePage(mpSh, 0, mpIndexDesc);
     311             :     }
     312             : 
     313           0 :     mpSh->GotoPage(GetInsertPosition(), false);
     314           0 :     mpSh->SetAttrItem(aTitleDesc);
     315             : 
     316           0 :     if (nNoPages > 1 && mpSh->GotoPage(GetInsertPosition() + nNoPages, false))
     317             :     {
     318           0 :         SwFmtPageDesc aPageFmtDesc(mpNormalDesc);
     319           0 :         mpSh->SetAttrItem(aPageFmtDesc);
     320             :     }
     321             : 
     322           0 :     if (m_pRestartNumberingCB->IsChecked() || nNoPages > 1)
     323             :     {
     324           0 :         sal_uInt16 nPgNo = m_pRestartNumberingCB->IsChecked() ? m_pRestartNumberingNF->GetValue() : 0;
     325           0 :         const SwPageDesc *pNewDesc = nNoPages > 1 ? mpNormalDesc : 0;
     326           0 :         mpSh->GotoPage(GetInsertPosition() + nNoPages, false);
     327           0 :         lcl_ChangePage(mpSh, nPgNo, pNewDesc);
     328             :     }
     329             : 
     330           0 :     mpSh->EndUndo();
     331           0 :     lcl_PopCursor(mpSh);
     332           0 :     if (!m_pUseExistingPagesRB->IsChecked())
     333           0 :         mpSh->GotoPage(GetInsertPosition(), false);
     334           0 :     EndDialog( RET_OK );
     335           0 :     return 0;
     336             : }
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10