LibreOffice Module sw (master) 1
crossrefbookmark.cxx
Go to the documentation of this file.
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
25#include <crossrefbookmark.hxx>
26#include <ndtxt.hxx>
27#include <o3tl/string_view.hxx>
28
29namespace
30{
31 constexpr OUStringLiteral CrossRefNumItemBookmark_NamePrefix = u"__RefNumPara__";
32}
33
34namespace sw::mark
35{
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)
43 {
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())
49 assert(!m_oPos2);
50 }
51
53 {
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);
61 }
62
64 {
65 assert(false &&
66 "<sw::mark::CrossRefBookmark::GetOtherMarkPos(..)>"
67 " - this should never be called!");
68 for (;;) { std::abort(); } // avoid "must return a value" warnings
69 }
70
72 const vcl::KeyCode& rCode,
73 const OUString& rName)
74 : CrossRefBookmark(rPaM, rCode, rName, Concat2View(IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix()+"_Toc"))
75 { }
76
77 bool CrossRefHeadingBookmark::IsLegalName(std::u16string_view rName)
78 {
80 }
81
83 const vcl::KeyCode& rCode,
84 const OUString& rName)
85 : CrossRefBookmark(rPaM, rCode, rName, CrossRefNumItemBookmark_NamePrefix)
86 { }
87
88 bool CrossRefNumItemBookmark::IsLegalName(std::u16string_view rName)
89 {
90 return o3tl::starts_with(rName, CrossRefNumItemBookmark_NamePrefix);
91 }
92}
93
94/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Provides access to the marks of a document.
static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix()
Definition: docbm.cxx:536
static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark(const SwPaM &rPaM)
Definition: docbm.cxx:541
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
CrossRefBookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName, std::u16string_view rPrefix)
virtual void SetMarkPos(const SwPosition &rNewPos) override
virtual SwPosition & GetOtherMarkPos() const override
static bool IsLegalName(std::u16string_view rName)
CrossRefHeadingBookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
CrossRefNumItemBookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
static bool IsLegalName(std::u16string_view rName)
std::optional< SwPosition > m_oPos2
virtual void SetMarkPos(const SwPosition &rNewPos)
static OUString GenerateNewName(std::u16string_view rPrefix)
float u
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
Marks a position in the document model.
Definition: pam.hxx:38
SwNode & GetNode() const
Definition: pam.hxx:81
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85