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