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 <IDocumentMarkAccess.hxx>
28 #include <crossrefbookmark.hxx>
29 #include <ndtxt.hxx>
30 
31 using namespace rtl;
32 
33 namespace sw { namespace mark
34 {
CrossRefBookmark(const SwPaM & rPaM,const KeyCode & rCode,const OUString & rName,const OUString & rShortName,const OUString & rPrefix)35     CrossRefBookmark::CrossRefBookmark(const SwPaM& rPaM,
36         const KeyCode& rCode,
37         const OUString& rName,
38         const OUString& rShortName,
39         const OUString& rPrefix)
40         : Bookmark(rPaM, rCode, rName, rShortName)
41     {
42         OSL_ENSURE( IDocumentMarkAccess::IsLegalPaMForCrossRefHeadingBookmark( rPaM ),
43                     "<CrossRefBookmark::CrossRefBookmark(..)>"
44                     "- creation of cross-reference bookmark with an illegal PaM that does not expand over exactly one whole paragraph.");
45         SetMarkPos(*rPaM.Start());
46         if(!rName.getLength())
47             m_aName = MarkBase::GenerateNewName(rPrefix);
48     }
49 
SetMarkPos(const SwPosition & rNewPos)50     void CrossRefBookmark::SetMarkPos(const SwPosition& rNewPos)
51     {
52         OSL_PRECOND(rNewPos.nNode.GetNode().GetTxtNode(),
53             "<SwCrossRefBookmark::SetMarkPos(..)>"
54             " - new bookmark position for cross-reference bookmark doesn't mark text node");
55         OSL_PRECOND(rNewPos.nContent.GetIndex() == 0,
56             "<SwCrossRefBookmark::SetMarkPos(..)>"
57             " - new bookmark position for cross-reference bookmark doesn't mark start of text node");
58         MarkBase::SetMarkPos(rNewPos);
59     }
60 
GetOtherMarkPos() const61     const SwPosition& CrossRefBookmark::GetOtherMarkPos() const
62     {
63         OSL_PRECOND(false,
64             "<SwCrossRefBookmark::GetOtherMarkPos(..)>"
65             " - this should never be called!");
66         return *static_cast<SwPosition*>(NULL);
67     }
68 
CrossRefHeadingBookmark(const SwPaM & rPaM,const KeyCode & rCode,const OUString & rName,const OUString & rShortName)69     CrossRefHeadingBookmark::CrossRefHeadingBookmark(const SwPaM& rPaM,
70         const KeyCode& rCode,
71         const OUString& rName,
72         const OUString& rShortName)
73         : CrossRefBookmark(rPaM, rCode, rName, rShortName, IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix())
74     { }
75 
IsLegalName(const::rtl::OUString & rName)76     bool CrossRefHeadingBookmark::IsLegalName(const ::rtl::OUString& rName)
77     {
78         return rName.match(IDocumentMarkAccess::GetCrossRefHeadingBookmarkNamePrefix());
79     }
80 
CrossRefNumItemBookmark(const SwPaM & rPaM,const KeyCode & rCode,const OUString & rName,const OUString & rShortName)81     CrossRefNumItemBookmark::CrossRefNumItemBookmark(const SwPaM& rPaM,
82         const KeyCode& rCode,
83         const OUString& rName,
84         const OUString& rShortName)
85         : CrossRefBookmark(rPaM, rCode, rName, rShortName, our_sNamePrefix)
86     { }
87 
88     const ::rtl::OUString CrossRefNumItemBookmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__RefNumPara__");
89 
IsLegalName(const::rtl::OUString & rName)90     bool CrossRefNumItemBookmark::IsLegalName(const ::rtl::OUString& rName)
91     {
92         return rName.match(our_sNamePrefix);
93     }
94 }}
95