1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <crossrefbookmark.hxx>
32 #include <ndtxt.hxx>
33 
34 using namespace rtl;
35 
36 namespace sw { namespace mark
37 {
38     CrossRefBookmark::CrossRefBookmark(const SwPaM& rPaM,
39         const KeyCode& rCode,
40         const OUString& rName,
41         const OUString& rShortName,
42         const OUString& rPrefix)
43         : Bookmark(rPaM, rCode, rName, rShortName)
44     {
45         if(rPaM.HasMark())
46             OSL_ENSURE((rPaM.GetMark()->nNode == rPaM.GetPoint()->nNode &&
47                 rPaM.Start()->nContent.GetIndex() == 0 &&
48                 rPaM.End()->nContent.GetIndex() == rPaM.GetPoint()->nNode.GetNode().GetTxtNode()->Len()),
49                 "<CrossRefBookmark::CrossRefBookmark(..)>"
50                 "- creation of cross-reference bookmark with an expanded PaM that does not expand over exactly one whole paragraph.");
51         SetMarkPos(*rPaM.Start());
52         if(!rName.getLength())
53             m_aName = MarkBase::GenerateNewName(rPrefix);
54     }
55 
56     void CrossRefBookmark::SetMarkPos(const SwPosition& rNewPos)
57     {
58         OSL_PRECOND(rNewPos.nNode.GetNode().GetTxtNode(),
59             "<SwCrossRefBookmark::SetMarkPos(..)>"
60             " - new bookmark position for cross-reference bookmark doesn't mark text node");
61         OSL_PRECOND(rNewPos.nContent.GetIndex() == 0,
62             "<SwCrossRefBookmark::SetMarkPos(..)>"
63             " - new bookmark position for cross-reference bookmark doesn't mark start of text node");
64         MarkBase::SetMarkPos(rNewPos);
65     }
66 
67     SwPosition& CrossRefBookmark::GetOtherMarkPos() const
68     {
69         OSL_PRECOND(false,
70             "<SwCrossRefBookmark::GetOtherMarkPos(..)>"
71             " - this should never be called!");
72         return *static_cast<SwPosition*>(NULL);
73     }
74 
75     CrossRefHeadingBookmark::CrossRefHeadingBookmark(const SwPaM& rPaM,
76         const KeyCode& rCode,
77         const OUString& rName,
78         const OUString& rShortName)
79         : CrossRefBookmark(rPaM, rCode, rName, rShortName, our_sNamePrefix)
80     { }
81 
82     const ::rtl::OUString CrossRefHeadingBookmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__RefHeading__");
83 
84     bool CrossRefHeadingBookmark::IsLegalName(const ::rtl::OUString& rName)
85     {
86         return rName.match(our_sNamePrefix);
87     }
88 
89     CrossRefNumItemBookmark::CrossRefNumItemBookmark(const SwPaM& rPaM,
90         const KeyCode& rCode,
91         const OUString& rName,
92         const OUString& rShortName)
93         : CrossRefBookmark(rPaM, rCode, rName, rShortName, our_sNamePrefix)
94     { }
95 
96     const ::rtl::OUString CrossRefNumItemBookmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__RefNumPara__");
97 
98     bool CrossRefNumItemBookmark::IsLegalName(const ::rtl::OUString& rName)
99     {
100         return rName.match(our_sNamePrefix);
101     }
102 }}
103