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 <sal/config.h>
21 :
22 : #include <cstdlib>
23 :
24 : #include <IDocumentMarkAccess.hxx>
25 : #include <crossrefbookmark.hxx>
26 : #include <ndtxt.hxx>
27 :
28 : namespace
29 : {
30 : const char CrossRefNumItemBookmark_NamePrefix[] = "__RefNumPara__";
31 : }
32 :
33 : namespace sw { namespace mark
34 : {
35 22 : CrossRefBookmark::CrossRefBookmark(const SwPaM& rPaM,
36 : const vcl::KeyCode& rCode,
37 : const OUString& rName,
38 : const OUString& rShortName,
39 : const OUString& rPrefix)
40 22 : : Bookmark(rPaM, rCode, rName, rShortName)
41 : {
42 : OSL_ENSURE( IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( rPaM ),
43 : "<CrossRefBookmark::CrossRefBookmark(..)>"
44 : "- creation of cross-reference bookmark with an illegal PaM that does not expand over exactly one whole paragraph.");
45 22 : SetMarkPos(*rPaM.Start());
46 22 : if(rName.isEmpty())
47 4 : m_aName = MarkBase::GenerateNewName(rPrefix);
48 22 : }
49 :
50 24 : void CrossRefBookmark::SetMarkPos(const SwPosition& rNewPos)
51 : {
52 : OSL_PRECOND(rNewPos.nNode.GetNode().GetTxtNode(),
53 : "<sw::mark::CrossRefBookmark::SetMarkPos(..)>"
54 : " - new bookmark position for cross-reference bookmark doesn't mark text node");
55 : OSL_PRECOND(rNewPos.nContent.GetIndex() == 0,
56 : "<sw::mark::CrossRefBookmark::SetMarkPos(..)>"
57 : " - new bookmark position for cross-reference bookmark doesn't mark start of text node");
58 24 : MarkBase::SetMarkPos(rNewPos);
59 24 : }
60 :
61 0 : SwPosition& CrossRefBookmark::GetOtherMarkPos() const
62 : {
63 : OSL_PRECOND(false,
64 : "<sw::mark::CrossRefBookmark::GetOtherMarkPos(..)>"
65 : " - this should never be called!");
66 0 : for (;;) { std::abort(); } // avoid "must return a value" warnings
67 : }
68 :
69 4 : CrossRefHeadingBookmark::CrossRefHeadingBookmark(const SwPaM& rPaM,
70 : const vcl::KeyCode& rCode,
71 : const OUString& rName,
72 : const OUString& rShortName)
73 4 : : CrossRefBookmark(rPaM, rCode, rName, rShortName, IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix())
74 4 : { }
75 :
76 8140 : bool CrossRefHeadingBookmark::IsLegalName(const OUString& rName)
77 : {
78 8140 : return rName.match(IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix());
79 : }
80 :
81 18 : CrossRefNumItemBookmark::CrossRefNumItemBookmark(const SwPaM& rPaM,
82 : const vcl::KeyCode& rCode,
83 : const OUString& rName,
84 : const OUString& rShortName)
85 18 : : CrossRefBookmark(rPaM, rCode, rName, rShortName, IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix())
86 18 : { }
87 :
88 8158 : bool CrossRefNumItemBookmark::IsLegalName(const OUString& rName)
89 : {
90 8158 : return rName.match(CrossRefNumItemBookmark_NamePrefix);
91 : }
92 270 : }}
93 :
94 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|