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 
24 #include <IDocumentMarkAccess.hxx>
25 #include <crossrefbookmark.hxx>
26 #include <ndtxt.hxx>
27 #include <o3tl/string_view.hxx>
28 
29 namespace
30 {
31  constexpr OUStringLiteral CrossRefNumItemBookmark_NamePrefix = u"__RefNumPara__";
32 }
33 
34 namespace 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_pPos2);
50  }
51 
53  {
54  assert(rNewPos.nNode.GetNode().GetTextNode() &&
55  "<sw::mark::CrossRefBookmark::SetMarkPos(..)>"
56  " - new bookmark position for cross-reference bookmark doesn't mark text node");
57  assert(rNewPos.nContent.GetIndex() == 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, OUStringConcatenation(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: */
static bool IsLegalName(std::u16string_view rName)
Marks a position in the document model.
Definition: pam.hxx:36
virtual SwPosition & GetOtherMarkPos() const override
CrossRefHeadingBookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
SwNodeIndex nNode
Definition: pam.hxx:38
Provides access to the marks of a document.
CrossRefNumItemBookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
SwNode & GetNode() const
Definition: ndindex.hxx:128
CrossRefBookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName, std::u16string_view rPrefix)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
static SW_DLLPUBLIC OUString GetCrossRefHeadingBookmarkNamePrefix()
Definition: docbm.cxx:508
static SW_DLLPUBLIC bool IsLegalPaMForCrossRefHeadingBookmark(const SwPaM &rPaM)
Definition: docbm.cxx:513
SwIndex nContent
Definition: pam.hxx:39
std::unique_ptr< SwPosition > m_pPos2
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
float u
static OUString GenerateNewName(std::u16string_view rPrefix)
sal_Int32 GetIndex() const
Definition: index.hxx:91
static bool IsLegalName(std::u16string_view rName)
virtual void SetMarkPos(const SwPosition &rNewPos)
virtual void SetMarkPos(const SwPosition &rNewPos) override
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864