1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <IDocumentLayoutAccess.hxx>
22 #include <IDocumentStylePoolAccess.hxx>
23 #include <IDocumentState.hxx>
24 #include <lineinfo.hxx>
25 #include <charfmt.hxx>
26 #include <poolfmt.hxx>
27 #include <rootfrm.hxx>
28 #include <osl/diagnose.h>
30 void SwDoc::SetLineNumberInfo( const SwLineNumberInfo
&rNew
)
32 SwRootFrame
* pTmpRoot
= getIDocumentLayoutAccess().GetCurrentLayout();
34 (rNew
.IsCountBlankLines() != mpLineNumberInfo
->IsCountBlankLines() ||
35 rNew
.IsRestartEachPage() != mpLineNumberInfo
->IsRestartEachPage()) )
37 pTmpRoot
->StartAllAction();
38 // FME 2007-08-14 #i80120# Invalidate size, because ChgThisLines()
39 // is only (and may only be) called by the formatting routines
40 //pTmpRoot->InvalidateAllContent( SwInvalidateFlags::LineNum | SwInvalidateFlags::Size );
41 for( auto aLayout
: GetAllLayouts() )
42 aLayout
->InvalidateAllContent( SwInvalidateFlags::LineNum
| SwInvalidateFlags::Size
);
43 pTmpRoot
->EndAllAction();
45 *mpLineNumberInfo
= rNew
;
46 getIDocumentState().SetModified();
49 const SwLineNumberInfo
& SwDoc::GetLineNumberInfo() const
51 return *mpLineNumberInfo
;
54 SwLineNumberInfo::SwLineNumberInfo() :
55 m_nPosFromLeft(o3tl::toTwips(5, o3tl::Length::mm
)),
57 m_nDividerCountBy( 3 ),
58 m_ePos( LINENUMBER_POS_LEFT
),
59 m_bPaintLineNumbers( false ),
60 m_bCountBlankLines( true ),
61 m_bCountInFlys( false ),
62 m_bRestartEachPage( false )
66 SwLineNumberInfo::SwLineNumberInfo(const SwLineNumberInfo
&rCpy
) : SwClient(),
67 m_aType( rCpy
.GetNumType() ),
68 m_aDivider( rCpy
.GetDivider() ),
69 m_nPosFromLeft( rCpy
.GetPosFromLeft() ),
70 m_nCountBy( rCpy
.GetCountBy() ),
71 m_nDividerCountBy( rCpy
.GetDividerCountBy() ),
72 m_ePos( rCpy
.GetPos() ),
73 m_bPaintLineNumbers( rCpy
.IsPaintLineNumbers() ),
74 m_bCountBlankLines( rCpy
.IsCountBlankLines() ),
75 m_bCountInFlys( rCpy
.IsCountInFlys() ),
76 m_bRestartEachPage( rCpy
.IsRestartEachPage() )
78 StartListeningToSameModifyAs(rCpy
);
81 SwLineNumberInfo
& SwLineNumberInfo::operator=(const SwLineNumberInfo
&rCpy
)
83 StartListeningToSameModifyAs(rCpy
);
85 m_aType
= rCpy
.GetNumType();
86 m_aDivider
= rCpy
.GetDivider();
87 m_nPosFromLeft
= rCpy
.GetPosFromLeft();
88 m_nCountBy
= rCpy
.GetCountBy();
89 m_nDividerCountBy
= rCpy
.GetDividerCountBy();
90 m_ePos
= rCpy
.GetPos();
91 m_bPaintLineNumbers
= rCpy
.IsPaintLineNumbers();
92 m_bCountBlankLines
= rCpy
.IsCountBlankLines();
93 m_bCountInFlys
= rCpy
.IsCountInFlys();
94 m_bRestartEachPage
= rCpy
.IsRestartEachPage();
99 SwCharFormat
* SwLineNumberInfo::GetCharFormat( IDocumentStylePoolAccess
& rIDSPA
) const
101 if ( !GetRegisteredIn() )
103 SwCharFormat
* pFormat
= rIDSPA
.GetCharFormatFromPool( RES_POOLCHR_LINENUM
);
104 pFormat
->Add( const_cast<SwLineNumberInfo
*>(this) );
106 return const_cast<SwCharFormat
*>(static_cast<const SwCharFormat
*>(GetRegisteredIn()));
109 void SwLineNumberInfo::SetCharFormat( SwCharFormat
*pChFormat
)
111 OSL_ENSURE( pChFormat
, "SetCharFormat, 0 is not a valid pointer" );
112 pChFormat
->Add( this );
115 void SwLineNumberInfo::SwClientNotify(const SwModify
&, const SfxHint
& rHint
)
117 if (rHint
.GetId() != SfxHintId::SwLegacyModify
)
119 auto pLegacy
= static_cast<const sw::LegacyModifyHint
*>(&rHint
);
120 CheckRegistration( pLegacy
->m_pOld
);
121 SwDoc
*pDoc
= static_cast<SwCharFormat
*>(GetRegisteredIn())->GetDoc();
122 SwRootFrame
* pRoot
= pDoc
->getIDocumentLayoutAccess().GetCurrentLayout();
125 pRoot
->StartAllAction();
126 for( auto aLayout
: pDoc
->GetAllLayouts() )
127 aLayout
->AllAddPaintRect();
128 pRoot
->EndAllAction();
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */