Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / crsr / crossrefbookmark.cxx
blob75e63b811680533dd294338ce31bc4ff00da1c18
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <sal/config.h>
22 #include <cstdlib>
24 #include <IDocumentMarkAccess.hxx>
25 #include <crossrefbookmark.hxx>
26 #include <ndtxt.hxx>
27 #include <o3tl/string_view.hxx>
29 namespace
31 constexpr OUStringLiteral CrossRefNumItemBookmark_NamePrefix = u"__RefNumPara__";
34 namespace sw::mark
36 CrossRefBookmark::CrossRefBookmark(const SwPaM& rPaM,
37 const vcl::KeyCode& rCode,
38 const OUString& rName,
39 std::u16string_view rPrefix)
40 : Bookmark(
41 // ensure that m_pPos2 is null by only passing start to super
42 SwPaM(*rPaM.Start()), rCode, rName)
44 assert( IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark(rPaM)
45 && "<CrossRefBookmark::CrossRefBookmark(..)>"
46 "- creation of cross-reference bookmark with an illegal PaM that does not expand over exactly one whole paragraph.");
47 if(rName.isEmpty())
48 m_aName = MarkBase::GenerateNewName(rPrefix);
49 assert(!m_oPos2);
52 void CrossRefBookmark::SetMarkPos(const SwPosition& rNewPos)
54 assert(rNewPos.GetNode().GetTextNode() &&
55 "<sw::mark::CrossRefBookmark::SetMarkPos(..)>"
56 " - new bookmark position for cross-reference bookmark doesn't mark text node");
57 assert(rNewPos.GetContentIndex() == 0 &&
58 "<sw::mark::CrossRefBookmark::SetMarkPos(..)>"
59 " - new bookmark position for cross-reference bookmark doesn't mark start of text node");
60 MarkBase::SetMarkPos(rNewPos);
63 SwPosition& CrossRefBookmark::GetOtherMarkPos() const
65 assert(false &&
66 "<sw::mark::CrossRefBookmark::GetOtherMarkPos(..)>"
67 " - this should never be called!");
68 for (;;) { std::abort(); } // avoid "must return a value" warnings
71 CrossRefHeadingBookmark::CrossRefHeadingBookmark(const SwPaM& rPaM,
72 const vcl::KeyCode& rCode,
73 const OUString& rName)
74 : CrossRefBookmark(rPaM, rCode, rName, Concat2View(IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix()+"_Toc"))
75 { }
77 bool CrossRefHeadingBookmark::IsLegalName(std::u16string_view rName)
79 return o3tl::starts_with(rName, IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix());
82 CrossRefNumItemBookmark::CrossRefNumItemBookmark(const SwPaM& rPaM,
83 const vcl::KeyCode& rCode,
84 const OUString& rName)
85 : CrossRefBookmark(rPaM, rCode, rName, CrossRefNumItemBookmark_NamePrefix)
86 { }
88 bool CrossRefNumItemBookmark::IsLegalName(std::u16string_view rName)
90 return o3tl::starts_with(rName, CrossRefNumItemBookmark_NamePrefix);
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */