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

Generated by: LCOV version 1.10