LCOV - code coverage report
Current view: top level - sw/source/ui/misc - linenum.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 149 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 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 <sfx2/viewfrm.hxx>
      21             : #include <svl/style.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <view.hxx>
      24             : #include <wrtsh.hxx>
      25             : #include <docsh.hxx>
      26             : #include <charfmt.hxx>
      27             : 
      28             : #include <docstyle.hxx>
      29             : 
      30             : #include "fldbas.hxx"
      31             : #include "lineinfo.hxx"
      32             : #include "linenum.hxx"
      33             : #include "uitool.hxx"
      34             : #include <fmtline.hxx>
      35             : #include "poolfmt.hrc"
      36             : 
      37             : #include <IDocumentStylePoolAccess.hxx>
      38             : 
      39           0 : static rtl::Reference<SwDocStyleSheet> lcl_getDocStyleSheet(const OUString& rName, SwWrtShell *pSh)
      40             : {
      41           0 :     sal_uInt16 nFamily = SFX_STYLE_FAMILY_PARA;
      42           0 :     SfxStyleSheetBasePool* mpBase =  pSh->GetView().GetDocShell()->GetStyleSheetPool();
      43           0 :     SfxStyleSheetBase* pStyle = mpBase->Find(rName, (SfxStyleFamily)nFamily);
      44             :     SAL_WARN_IF( !pStyle, "linenumbering.ui", "Style not found" );
      45           0 :     if(!pStyle)
      46           0 :         return NULL;
      47           0 :     return new SwDocStyleSheet(*static_cast<SwDocStyleSheet*>(pStyle));
      48             : }
      49             : 
      50           0 : static void lcl_setLineNumbering(const OUString& rName, SwWrtShell* pSh, bool bLineNumber)
      51             : {
      52           0 :     rtl::Reference<SwDocStyleSheet> xStyleSheet = lcl_getDocStyleSheet(rName, pSh);
      53           0 :     if(!xStyleSheet.is())
      54           0 :         return;
      55           0 :     SfxItemSet& rSet = xStyleSheet->GetItemSet();
      56           0 :     SwFormatLineNumber aFormat;
      57           0 :     aFormat.SetCountLines(bLineNumber);
      58           0 :     rSet.Put(aFormat);
      59           0 :     xStyleSheet->MergeIndentAttrsOfListStyle( rSet );
      60           0 :     xStyleSheet->SetItemSet(rSet, false);
      61             : }
      62             : 
      63           0 : SwLineNumberingDlg::SwLineNumberingDlg(SwView *pVw)
      64           0 :     : SfxModalDialog( &pVw->GetViewFrame()->GetWindow(), "LineNumberingDialog",
      65             :         "modules/swriter/ui/linenumbering.ui" )
      66           0 :     , pSh(pVw->GetWrtShellPtr())
      67             : {
      68           0 :     get(m_pBodyContent, "content");
      69           0 :     get(m_pDivIntervalFT, "every");
      70           0 :     get(m_pDivIntervalNF, "linesspin");
      71           0 :     get(m_pDivRowsFT, "lines");
      72           0 :     get(m_pNumIntervalNF, "intervalspin");
      73           0 :     get(m_pCharStyleLB, "styledropdown");
      74           0 :     get(m_pFormatLB, "formatdropdown");
      75           0 :     get(m_pPosLB, "positiondropdown");
      76           0 :     get(m_pOffsetMF, "spacingspin");
      77           0 :     get(m_pDivisorED, "textentry");
      78           0 :     get(m_pCountEmptyLinesCB, "blanklines");
      79           0 :     get(m_pCountFrameLinesCB, "linesintextframes");
      80           0 :     get(m_pRestartEachPageCB, "restarteverynewpage");
      81           0 :     get(m_pNumberingOnCB, "shownumbering");
      82           0 :     get(m_pNumberingOnFooterHeader, "showfooterheadernumbering");
      83             : 
      84           0 :     OUString sIntervalName = m_pDivIntervalFT->GetAccessibleName();
      85           0 :     sIntervalName += "(";
      86           0 :     sIntervalName += m_pDivRowsFT->GetAccessibleName();
      87           0 :     sIntervalName += ")";
      88           0 :     m_pDivIntervalNF->SetAccessibleName(sIntervalName);
      89             : 
      90           0 :     vcl::Window *pNumIntervalFT = get<vcl::Window>("interval");
      91           0 :     vcl::Window *pNumRowsFT = get<vcl::Window>("intervallines");
      92           0 :     sIntervalName = pNumIntervalFT->GetAccessibleName();
      93           0 :     sIntervalName += "(";
      94           0 :     sIntervalName += pNumRowsFT->GetAccessibleName();
      95           0 :     sIntervalName += ")";
      96           0 :     m_pNumIntervalNF->SetAccessibleName(sIntervalName);
      97             : 
      98             :     // char styles
      99           0 :     ::FillCharStyleListBox(*m_pCharStyleLB, pSh->GetView().GetDocShell());
     100             : 
     101           0 :     const SwLineNumberInfo &rInf = pSh->GetLineNumberInfo();
     102           0 :     IDocumentStylePoolAccess* pIDSPA = pSh->getIDocumentStylePoolAccess();
     103             : 
     104           0 :     OUString sStyleName(rInf.GetCharFormat( *pIDSPA )->GetName());
     105           0 :     const sal_Int32 nPos = m_pCharStyleLB->GetEntryPos(sStyleName);
     106             : 
     107           0 :     if (nPos != LISTBOX_ENTRY_NOTFOUND)
     108           0 :         m_pCharStyleLB->SelectEntryPos(nPos);
     109             :     else
     110             :     {
     111           0 :         if (!sStyleName.isEmpty())
     112             :         {
     113           0 :             m_pCharStyleLB->InsertEntry(sStyleName);
     114           0 :             m_pCharStyleLB->SelectEntry(sStyleName);
     115             :         }
     116             :     }
     117             : 
     118             :     // format
     119           0 :     sal_uInt16 nSelFormat = rInf.GetNumType().GetNumberingType();
     120             : 
     121           0 :     m_pFormatLB->SelectNumberingType(nSelFormat);
     122             : 
     123             :     // position
     124           0 :     m_pPosLB->SelectEntryPos((sal_Int32)rInf.GetPos());
     125             : 
     126             :     // offset
     127           0 :     sal_uInt16 nOffset = rInf.GetPosFromLeft();
     128           0 :     if (nOffset == USHRT_MAX)
     129           0 :         nOffset = 0;
     130             : 
     131           0 :     m_pOffsetMF->SetValue(m_pOffsetMF->Normalize(nOffset), FUNIT_TWIP);
     132             : 
     133             :     // numbering offset
     134           0 :     m_pNumIntervalNF->SetValue(rInf.GetCountBy());
     135             : 
     136             :     // divider
     137           0 :     m_pDivisorED->SetText(rInf.GetDivider());
     138             : 
     139             :     // divider offset
     140           0 :     m_pDivIntervalNF->SetValue(rInf.GetDividerCountBy());
     141             : 
     142             :     // count
     143           0 :     m_pCountEmptyLinesCB->Check(rInf.IsCountBlankLines());
     144           0 :     m_pCountFrameLinesCB->Check(rInf.IsCountInFlys());
     145           0 :     m_pRestartEachPageCB->Check(rInf.IsRestartEachPage());
     146             : 
     147           0 :     m_pNumberingOnCB->Check(rInf.IsPaintLineNumbers());
     148             : 
     149             :     // Header/Footer Line Numbering
     150           0 :     rtl::Reference< SwDocStyleSheet > xStyleSheet = lcl_getDocStyleSheet(SW_RESSTR(STR_POOLCOLL_FOOTER), pSh);
     151           0 :     if(xStyleSheet.is())
     152             :     {
     153           0 :         SfxItemSet& rSet = xStyleSheet->GetItemSet();
     154           0 :         const SwFormatLineNumber &aFormat = static_cast<const SwFormatLineNumber&>(rSet.Get(RES_LINENUMBER));
     155           0 :         if(aFormat.IsCount())
     156           0 :             m_pNumberingOnFooterHeader->SetState(TRISTATE_TRUE);
     157             :         else
     158           0 :             m_pNumberingOnFooterHeader->SetState(TRISTATE_FALSE);
     159             :     }
     160             : 
     161             :     // Line Numbering
     162           0 :     m_pNumberingOnCB->SetClickHdl(LINK(this, SwLineNumberingDlg, LineOnOffHdl));
     163           0 :     m_pDivisorED->SetModifyHdl(LINK(this, SwLineNumberingDlg, ModifyHdl));
     164           0 :     ModifyHdl();
     165           0 :     LineOnOffHdl();
     166             : 
     167           0 :     get<PushButton>("ok")->SetClickHdl(LINK(this, SwLineNumberingDlg, OKHdl));
     168           0 : }
     169             : 
     170           0 : SwLineNumberingDlg::~SwLineNumberingDlg()
     171             : {
     172           0 :     disposeOnce();
     173           0 : }
     174             : 
     175           0 : void SwLineNumberingDlg::dispose()
     176             : {
     177           0 :     m_pBodyContent.clear();
     178           0 :     m_pDivIntervalFT.clear();
     179           0 :     m_pDivIntervalNF.clear();
     180           0 :     m_pDivRowsFT.clear();
     181           0 :     m_pNumIntervalNF.clear();
     182           0 :     m_pCharStyleLB.clear();
     183           0 :     m_pFormatLB.clear();
     184           0 :     m_pPosLB.clear();
     185           0 :     m_pOffsetMF.clear();
     186           0 :     m_pDivisorED.clear();
     187           0 :     m_pCountEmptyLinesCB.clear();
     188           0 :     m_pCountFrameLinesCB.clear();
     189           0 :     m_pRestartEachPageCB.clear();
     190           0 :     m_pNumberingOnCB.clear();
     191           0 :     m_pNumberingOnFooterHeader.clear();
     192           0 :     SfxModalDialog::dispose();
     193           0 : }
     194             : 
     195             : 
     196           0 : IMPL_LINK_NOARG(SwLineNumberingDlg, OKHdl)
     197             : {
     198           0 :     SwLineNumberInfo aInf(pSh->GetLineNumberInfo());
     199             : 
     200             :     // char styles
     201           0 :     OUString sCharFormatName(m_pCharStyleLB->GetSelectEntry());
     202           0 :     SwCharFormat *pCharFormat = pSh->FindCharFormatByName(sCharFormatName);
     203             : 
     204           0 :     if (!pCharFormat)
     205             :     {
     206           0 :         SfxStyleSheetBasePool* pPool = pSh->GetView().GetDocShell()->GetStyleSheetPool();
     207             :         SfxStyleSheetBase* pBase;
     208           0 :         pBase = pPool->Find(sCharFormatName, SFX_STYLE_FAMILY_CHAR);
     209           0 :         if(!pBase)
     210           0 :             pBase = &pPool->Make(sCharFormatName, SFX_STYLE_FAMILY_CHAR);
     211           0 :         pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat();
     212             :     }
     213             : 
     214           0 :     if (pCharFormat)
     215           0 :         aInf.SetCharFormat(pCharFormat);
     216             : 
     217             :     // format
     218           0 :     SvxNumberType aType;
     219           0 :     aType.SetNumberingType(m_pFormatLB->GetSelectedNumberingType());
     220           0 :     aInf.SetNumType(aType);
     221             : 
     222             :     // position
     223           0 :     aInf.SetPos((LineNumberPosition)m_pPosLB->GetSelectEntryPos());
     224             : 
     225             :     // offset
     226           0 :     aInf.SetPosFromLeft((sal_uInt16)m_pOffsetMF->Denormalize(m_pOffsetMF->GetValue(FUNIT_TWIP)));
     227             : 
     228             :     // numbering offset
     229           0 :     aInf.SetCountBy((sal_uInt16)m_pNumIntervalNF->GetValue());
     230             : 
     231             :     // divider
     232           0 :     aInf.SetDivider(m_pDivisorED->GetText());
     233             : 
     234             :     // divider offset
     235           0 :     aInf.SetDividerCountBy((sal_uInt16)m_pDivIntervalNF->GetValue());
     236             : 
     237             :     // count
     238           0 :     aInf.SetCountBlankLines(m_pCountEmptyLinesCB->IsChecked());
     239           0 :     aInf.SetCountInFlys(m_pCountFrameLinesCB->IsChecked());
     240           0 :     aInf.SetRestartEachPage(m_pRestartEachPageCB->IsChecked());
     241             : 
     242           0 :     aInf.SetPaintLineNumbers(m_pNumberingOnCB->IsChecked());
     243             : 
     244           0 :     pSh->SetLineNumberInfo(aInf);
     245             : 
     246             :     // Set LineNumber explicitly for Header and Footer
     247           0 :     lcl_setLineNumbering(SW_RESSTR(STR_POOLCOLL_FOOTER), pSh, m_pNumberingOnFooterHeader->IsChecked());
     248           0 :     lcl_setLineNumbering(SW_RESSTR(STR_POOLCOLL_HEADER), pSh, m_pNumberingOnFooterHeader->IsChecked());
     249           0 :     if( m_pNumberingOnFooterHeader->IsChecked())
     250           0 :        m_pNumberingOnFooterHeader->SetState(TRISTATE_TRUE);
     251             :     else
     252           0 :        m_pNumberingOnFooterHeader->SetState(TRISTATE_FALSE);
     253             : 
     254           0 :     EndDialog( RET_OK );
     255             : 
     256           0 :     return 0;
     257             : }
     258             : 
     259             : // modify
     260           0 : IMPL_LINK_NOARG(SwLineNumberingDlg, ModifyHdl)
     261             : {
     262           0 :     bool bEnable = m_pNumberingOnCB->IsChecked() && !m_pDivisorED->GetText().isEmpty();
     263             : 
     264           0 :     m_pDivIntervalFT->Enable(bEnable);
     265           0 :     m_pDivIntervalNF->Enable(bEnable);
     266           0 :     m_pDivRowsFT->Enable(bEnable);
     267             : 
     268           0 :     return 0;
     269             : }
     270             : 
     271             : // On/Off
     272           0 : IMPL_LINK_NOARG(SwLineNumberingDlg, LineOnOffHdl)
     273             : {
     274           0 :     bool bEnable = m_pNumberingOnCB->IsChecked();
     275           0 :     m_pBodyContent->Enable(bEnable);
     276           0 :     ModifyHdl();
     277           0 :     return 0;
     278           0 : }
     279             : 
     280             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11