1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <rtl/ustring.hxx>
22 #include "XMLTextFrameContext.hxx"
23 #include "XMLTextFrameHyperlinkContext.hxx"
24 #include <xmloff/XMLEventsImportContext.hxx>
26 #define XML_HINT_STYLE 1
27 #define XML_HINT_REFERENCE 2
28 #define XML_HINT_HYPERLINK 3
29 #define XML_HINT_INDEX_MARK 5
30 #define XML_HINT_TEXT_FRAME 6
31 // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#)
32 #define XML_HINT_DRAW 7
36 css::uno::Reference
< css::text::XTextRange
> xStart
;
37 css::uno::Reference
< css::text::XTextRange
> xEnd
;
43 XMLHint_Impl( sal_uInt8 nTyp
,
44 const css::uno::Reference
< css::text::XTextRange
> & rS
,
45 const css::uno::Reference
< css::text::XTextRange
> & rE
) :
52 virtual ~XMLHint_Impl() {}
54 const css::uno::Reference
< css::text::XTextRange
> & GetStart() const { return xStart
; }
55 const css::uno::Reference
< css::text::XTextRange
> & GetEnd() const { return xEnd
; }
56 void SetEnd( const css::uno::Reference
< css::text::XTextRange
> & rPos
) { xEnd
= rPos
; }
58 // We don't use virtual methods to differ between the sub classes,
59 // because this seems to be too expensive if compared to inline methods.
60 sal_uInt8
GetType() const { return nType
; }
61 bool IsReference() const { return XML_HINT_REFERENCE
==nType
; }
64 class XMLStyleHint_Impl
: public XMLHint_Impl
70 XMLStyleHint_Impl( const OUString
& rStyleName
,
71 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
72 XMLHint_Impl( XML_HINT_STYLE
, rPos
, rPos
),
73 sStyleName( rStyleName
)
77 const OUString
& GetStyleName() const { return sStyleName
; }
80 class XMLReferenceHint_Impl
: public XMLHint_Impl
86 XMLReferenceHint_Impl( const OUString
& rRefName
,
87 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
88 XMLHint_Impl( XML_HINT_REFERENCE
, rPos
, rPos
),
93 const OUString
& GetRefName() const { return sRefName
; }
96 class XMLHyperlinkHint_Impl
: public XMLHint_Impl
100 OUString sTargetFrameName
;
102 OUString sVisitedStyleName
;
103 rtl::Reference
<XMLEventsImportContext
> mxEvents
;
107 XMLHyperlinkHint_Impl( const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
108 XMLHint_Impl( XML_HINT_HYPERLINK
, rPos
, rPos
)
112 void SetHRef( const OUString
& s
) { sHRef
= s
; }
113 const OUString
& GetHRef() const { return sHRef
; }
114 void SetName( const OUString
& s
) { sName
= s
; }
115 const OUString
& GetName() const { return sName
; }
116 void SetTargetFrameName( const OUString
& s
) { sTargetFrameName
= s
; }
117 const OUString
& GetTargetFrameName() const { return sTargetFrameName
; }
118 void SetStyleName( const OUString
& s
) { sStyleName
= s
; }
119 const OUString
& GetStyleName() const { return sStyleName
; }
120 void SetVisitedStyleName( const OUString
& s
) { sVisitedStyleName
= s
; }
121 const OUString
& GetVisitedStyleName() const { return sVisitedStyleName
; }
122 XMLEventsImportContext
* GetEventsContext() const
124 return mxEvents
.get();
126 void SetEventsContext( XMLEventsImportContext
* pCtxt
)
132 class XMLIndexMarkHint_Impl
: public XMLHint_Impl
134 const css::uno::Reference
<css::beans::XPropertySet
> xIndexMarkPropSet
;
140 XMLIndexMarkHint_Impl( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
141 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
142 XMLHint_Impl( XML_HINT_INDEX_MARK
, rPos
, rPos
),
143 xIndexMarkPropSet( rPropSet
),
148 XMLIndexMarkHint_Impl( const css::uno::Reference
< css::beans::XPropertySet
> & rPropSet
,
149 const css::uno::Reference
< css::text::XTextRange
> & rPos
,
150 const OUString
& sIDString
) :
151 XMLHint_Impl( XML_HINT_INDEX_MARK
, rPos
, rPos
),
152 xIndexMarkPropSet( rPropSet
),
157 const css::uno::Reference
<css::beans::XPropertySet
> & GetMark() const
158 { return xIndexMarkPropSet
; }
159 const OUString
& GetID() const { return sID
; }
162 class XMLTextFrameHint_Impl
: public XMLHint_Impl
164 // OD 2004-04-20 #i26791#
165 SvXMLImportContextRef xContext
;
169 XMLTextFrameHint_Impl( SvXMLImportContext
* pContext
,
170 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
171 XMLHint_Impl( XML_HINT_TEXT_FRAME
, rPos
, rPos
),
176 css::uno::Reference
< css::text::XTextContent
> GetTextContent() const
178 css::uno::Reference
< css::text::XTextContent
> xTxt
;
179 SvXMLImportContext
*pContext
= xContext
.get();
180 if (XMLTextFrameContext
*pFrameContext
= dynamic_cast<XMLTextFrameContext
*>(pContext
))
181 xTxt
= pFrameContext
->GetTextContent();
182 else if (XMLTextFrameHyperlinkContext
*pLinkContext
= dynamic_cast<XMLTextFrameHyperlinkContext
*>(pContext
))
183 xTxt
= pLinkContext
->GetTextContent();
188 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
189 css::uno::Reference
< css::drawing::XShape
> GetShape() const
191 css::uno::Reference
< css::drawing::XShape
> xShape
;
192 SvXMLImportContext
*pContext
= xContext
.get();
193 if (XMLTextFrameContext
*pFrameContext
= dynamic_cast<XMLTextFrameContext
*>(pContext
))
194 xShape
= pFrameContext
->GetShape();
195 else if(XMLTextFrameHyperlinkContext
*pLinkContext
= dynamic_cast<XMLTextFrameHyperlinkContext
*>(pContext
))
196 xShape
= pLinkContext
->GetShape();
201 bool IsBoundAtChar() const
204 SvXMLImportContext
*pContext
= xContext
.get();
205 if (XMLTextFrameContext
*pFrameContext
= dynamic_cast<XMLTextFrameContext
*>(pContext
))
206 bRet
= css::text::TextContentAnchorType_AT_CHARACTER
==
207 pFrameContext
->GetAnchorType();
208 else if (XMLTextFrameHyperlinkContext
*pLinkContext
= dynamic_cast<XMLTextFrameHyperlinkContext
*>(pContext
))
209 bRet
= css::text::TextContentAnchorType_AT_CHARACTER
==
210 pLinkContext
->GetAnchorType();
215 // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#)
216 class XMLDrawHint_Impl
: public XMLHint_Impl
218 SvXMLImportContextRef xContext
;
222 XMLDrawHint_Impl( SvXMLShapeContext
* pContext
,
223 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
224 XMLHint_Impl( XML_HINT_DRAW
, rPos
, rPos
),
229 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
230 css::uno::Reference
< css::drawing::XShape
> const & GetShape() const
232 return static_cast<SvXMLShapeContext
*>(xContext
.get())->getShape();
236 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */