1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #include <crossrefbookmark.hxx>
28 #include <ndtxt.hxx>
29 
30 using namespace rtl;
31 
32 namespace sw { namespace mark
33 {
34     CrossRefBookmark::CrossRefBookmark(const SwPaM& rPaM,
35         const KeyCode& rCode,
36         const OUString& rName,
37         const OUString& rShortName,
38         const OUString& rPrefix)
39         : Bookmark(rPaM, rCode, rName, rShortName)
40     {
41         if(rPaM.HasMark())
42             OSL_ENSURE((rPaM.GetMark()->nNode == rPaM.GetPoint()->nNode &&
43                 rPaM.Start()->nContent.GetIndex() == 0 &&
44                 rPaM.End()->nContent.GetIndex() == rPaM.GetPoint()->nNode.GetNode().GetTxtNode()->Len()),
45                 "<CrossRefBookmark::CrossRefBookmark(..)>"
46                 "- creation of cross-reference bookmark with an expanded PaM that does not expand over exactly one whole paragraph.");
47         SetMarkPos(*rPaM.Start());
48         if(!rName.getLength())
49             m_aName = MarkBase::GenerateNewName(rPrefix);
50     }
51 
52     void CrossRefBookmark::SetMarkPos(const SwPosition& rNewPos)
53     {
54         OSL_PRECOND(rNewPos.nNode.GetNode().GetTxtNode(),
55             "<SwCrossRefBookmark::SetMarkPos(..)>"
56             " - new bookmark position for cross-reference bookmark doesn't mark text node");
57         OSL_PRECOND(rNewPos.nContent.GetIndex() == 0,
58             "<SwCrossRefBookmark::SetMarkPos(..)>"
59             " - new bookmark position for cross-reference bookmark doesn't mark start of text node");
60         MarkBase::SetMarkPos(rNewPos);
61     }
62 
63     SwPosition& CrossRefBookmark::GetOtherMarkPos() const
64     {
65         OSL_PRECOND(false,
66             "<SwCrossRefBookmark::GetOtherMarkPos(..)>"
67             " - this should never be called!");
68         return *static_cast<SwPosition*>(NULL);
69     }
70 
71     CrossRefHeadingBookmark::CrossRefHeadingBookmark(const SwPaM& rPaM,
72         const KeyCode& rCode,
73         const OUString& rName,
74         const OUString& rShortName)
75         : CrossRefBookmark(rPaM, rCode, rName, rShortName, our_sNamePrefix)
76     { }
77 
78     const ::rtl::OUString CrossRefHeadingBookmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__RefHeading__");
79 
80     bool CrossRefHeadingBookmark::IsLegalName(const ::rtl::OUString& rName)
81     {
82         return rName.match(our_sNamePrefix);
83     }
84 
85     CrossRefNumItemBookmark::CrossRefNumItemBookmark(const SwPaM& rPaM,
86         const KeyCode& rCode,
87         const OUString& rName,
88         const OUString& rShortName)
89         : CrossRefBookmark(rPaM, rCode, rName, rShortName, our_sNamePrefix)
90     { }
91 
92     const ::rtl::OUString CrossRefNumItemBookmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__RefNumPara__");
93 
94     bool CrossRefNumItemBookmark::IsLegalName(const ::rtl::OUString& rName)
95     {
96         return rName.match(our_sNamePrefix);
97     }
98 }}
99