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"
25 #include <xmloff/XMLEventsImportContext.hxx>
27 enum class XMLHintType
30 XML_HINT_REFERENCE
= 2,
31 XML_HINT_HYPERLINK
= 3,
32 // There is no 4 defined here
33 XML_HINT_INDEX_MARK
= 5,
34 XML_HINT_TEXT_FRAME
= 6,
35 // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#)
41 css::uno::Reference
< css::text::XTextRange
> xStart
;
42 css::uno::Reference
< css::text::XTextRange
> xEnd
;
48 XMLHint_Impl( XMLHintType nTyp
,
49 css::uno::Reference
< css::text::XTextRange
> xS
,
50 css::uno::Reference
< css::text::XTextRange
> xE
) :
51 xStart(std::move( xS
)),
52 xEnd(std::move( xE
)),
57 virtual ~XMLHint_Impl() {}
59 const css::uno::Reference
< css::text::XTextRange
> & GetStart() const { return xStart
; }
60 const css::uno::Reference
< css::text::XTextRange
> & GetEnd() const { return xEnd
; }
61 void SetEnd( const css::uno::Reference
< css::text::XTextRange
> & rPos
) { xEnd
= rPos
; }
63 // We don't use virtual methods to differ between the sub classes,
64 // because this seems to be too expensive if compared to inline methods.
65 XMLHintType
GetType() const { return nType
; }
66 bool IsReference() const { return XMLHintType::XML_HINT_REFERENCE
==nType
; }
69 class XMLStyleHint_Impl
: public XMLHint_Impl
75 XMLStyleHint_Impl( OUString aStyleName
,
76 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
77 XMLHint_Impl( XMLHintType::XML_HINT_STYLE
, rPos
, rPos
),
78 sStyleName(std::move( aStyleName
))
82 const OUString
& GetStyleName() const { return sStyleName
; }
85 class XMLReferenceHint_Impl
: public XMLHint_Impl
91 XMLReferenceHint_Impl( OUString aRefName
,
92 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
93 XMLHint_Impl( XMLHintType::XML_HINT_REFERENCE
, rPos
, rPos
),
94 sRefName(std::move( aRefName
))
98 const OUString
& GetRefName() const { return sRefName
; }
101 class XMLHyperlinkHint_Impl
: public XMLHint_Impl
105 OUString sTargetFrameName
;
107 OUString sVisitedStyleName
;
108 rtl::Reference
<XMLEventsImportContext
> mxEvents
;
112 XMLHyperlinkHint_Impl( const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
113 XMLHint_Impl( XMLHintType::XML_HINT_HYPERLINK
, rPos
, rPos
)
117 void SetHRef( const OUString
& s
) { sHRef
= s
; }
118 const OUString
& GetHRef() const { return sHRef
; }
119 void SetName( const OUString
& s
) { sName
= s
; }
120 const OUString
& GetName() const { return sName
; }
121 void SetTargetFrameName( const OUString
& s
) { sTargetFrameName
= s
; }
122 const OUString
& GetTargetFrameName() const { return sTargetFrameName
; }
123 void SetStyleName( const OUString
& s
) { sStyleName
= s
; }
124 const OUString
& GetStyleName() const { return sStyleName
; }
125 void SetVisitedStyleName( const OUString
& s
) { sVisitedStyleName
= s
; }
126 const OUString
& GetVisitedStyleName() const { return sVisitedStyleName
; }
127 XMLEventsImportContext
* GetEventsContext() const
129 return mxEvents
.get();
131 void SetEventsContext( XMLEventsImportContext
* pCtxt
)
137 class XMLIndexMarkHint_Impl
: public XMLHint_Impl
139 const css::uno::Reference
<css::beans::XPropertySet
> xIndexMarkPropSet
;
145 XMLIndexMarkHint_Impl( css::uno::Reference
< css::beans::XPropertySet
> xPropSet
,
146 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
147 XMLHint_Impl( XMLHintType::XML_HINT_INDEX_MARK
, rPos
, rPos
),
148 xIndexMarkPropSet(std::move( xPropSet
)),
153 XMLIndexMarkHint_Impl( css::uno::Reference
< css::beans::XPropertySet
> xPropSet
,
154 const css::uno::Reference
< css::text::XTextRange
> & rPos
,
155 OUString sIDString
) :
156 XMLHint_Impl( XMLHintType::XML_HINT_INDEX_MARK
, rPos
, rPos
),
157 xIndexMarkPropSet(std::move( xPropSet
)),
158 sID(std::move(sIDString
))
162 const css::uno::Reference
<css::beans::XPropertySet
> & GetMark() const
163 { return xIndexMarkPropSet
; }
164 const OUString
& GetID() const { return sID
; }
167 class XMLTextFrameHint_Impl
: public XMLHint_Impl
169 // OD 2004-04-20 #i26791#
170 SvXMLImportContextRef xContext
;
174 XMLTextFrameHint_Impl( SvXMLImportContext
* pContext
,
175 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
176 XMLHint_Impl( XMLHintType::XML_HINT_TEXT_FRAME
, rPos
, rPos
),
181 css::uno::Reference
< css::text::XTextContent
> GetTextContent() const
183 css::uno::Reference
< css::text::XTextContent
> xTxt
;
184 SvXMLImportContext
*pContext
= xContext
.get();
185 if (XMLTextFrameContext
*pFrameContext
= dynamic_cast<XMLTextFrameContext
*>(pContext
))
186 xTxt
= pFrameContext
->GetTextContent();
187 else if (XMLTextFrameHyperlinkContext
*pLinkContext
= dynamic_cast<XMLTextFrameHyperlinkContext
*>(pContext
))
188 xTxt
= pLinkContext
->GetTextContent();
193 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
194 css::uno::Reference
< css::drawing::XShape
> GetShape() const
196 css::uno::Reference
< css::drawing::XShape
> xShape
;
197 SvXMLImportContext
*pContext
= xContext
.get();
198 if (XMLTextFrameContext
*pFrameContext
= dynamic_cast<XMLTextFrameContext
*>(pContext
))
199 xShape
= pFrameContext
->GetShape();
200 else if(XMLTextFrameHyperlinkContext
*pLinkContext
= dynamic_cast<XMLTextFrameHyperlinkContext
*>(pContext
))
201 xShape
= pLinkContext
->GetShape();
206 bool IsBoundAtChar() const
209 SvXMLImportContext
*pContext
= xContext
.get();
210 if (XMLTextFrameContext
*pFrameContext
= dynamic_cast<XMLTextFrameContext
*>(pContext
))
211 bRet
= css::text::TextContentAnchorType_AT_CHARACTER
==
212 pFrameContext
->GetAnchorType();
213 else if (XMLTextFrameHyperlinkContext
*pLinkContext
= dynamic_cast<XMLTextFrameHyperlinkContext
*>(pContext
))
214 bRet
= css::text::TextContentAnchorType_AT_CHARACTER
==
215 pLinkContext
->GetAnchorType();
220 // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#)
221 class XMLDrawHint_Impl
: public XMLHint_Impl
223 rtl::Reference
<SvXMLShapeContext
> xContext
;
227 XMLDrawHint_Impl( SvXMLShapeContext
* pContext
,
228 const css::uno::Reference
< css::text::XTextRange
> & rPos
) :
229 XMLHint_Impl( XMLHintType::XML_HINT_DRAW
, rPos
, rPos
),
234 // Frame "to character": anchor moves from first to last char after saving (#i33242#)
235 css::uno::Reference
< css::drawing::XShape
> const & GetShape() const
237 return xContext
->getShape();
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */