1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 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/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 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 . 18 */ 19 #ifndef INCLUDED_XMLOFF_SOURCE_TEXT_TXTPARAIMPHINT_HXX 20 #define INCLUDED_XMLOFF_SOURCE_TEXT_TXTPARAIMPHINT_HXX 21 22 #include <rtl/ustring.hxx> 23 #include "XMLTextFrameContext.hxx" 24 #include "XMLTextFrameHyperlinkContext.hxx" 25 #include <xmloff/XMLEventsImportContext.hxx> 26 27 #define XML_HINT_STYLE 1 28 #define XML_HINT_REFERENCE 2 29 #define XML_HINT_HYPERLINK 3 30 #define XML_HINT_INDEX_MARK 5 31 #define XML_HINT_TEXT_FRAME 6 32 // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#) 33 #define XML_HINT_DRAW 7 34 35 class XMLHint_Impl 36 { 37 css::uno::Reference < css::text::XTextRange > xStart; 38 css::uno::Reference < css::text::XTextRange > xEnd; 39 40 sal_uInt8 const nType; 41 42 public: 43 XMLHint_Impl(sal_uInt8 nTyp,const css::uno::Reference<css::text::XTextRange> & rS,const css::uno::Reference<css::text::XTextRange> & rE)44 XMLHint_Impl( sal_uInt8 nTyp, 45 const css::uno::Reference < css::text::XTextRange > & rS, 46 const css::uno::Reference < css::text::XTextRange > & rE ) : 47 xStart( rS ), 48 xEnd( rE ), 49 nType( nTyp ) 50 { 51 } 52 ~XMLHint_Impl()53 virtual ~XMLHint_Impl() {} 54 GetStart() const55 const css::uno::Reference < css::text::XTextRange > & GetStart() const { return xStart; } GetEnd() const56 const css::uno::Reference < css::text::XTextRange > & GetEnd() const { return xEnd; } SetEnd(const css::uno::Reference<css::text::XTextRange> & rPos)57 void SetEnd( const css::uno::Reference < css::text::XTextRange > & rPos ) { xEnd = rPos; } 58 59 // We don't use virtual methods to differ between the sub classes, 60 // because this seems to be too expensive if compared to inline methods. GetType() const61 sal_uInt8 GetType() const { return nType; } IsReference() const62 bool IsReference() const { return XML_HINT_REFERENCE==nType; } 63 }; 64 65 class XMLStyleHint_Impl : public XMLHint_Impl 66 { 67 OUString const sStyleName; 68 69 public: 70 XMLStyleHint_Impl(const OUString & rStyleName,const css::uno::Reference<css::text::XTextRange> & rPos)71 XMLStyleHint_Impl( const OUString& rStyleName, 72 const css::uno::Reference < css::text::XTextRange > & rPos ) : 73 XMLHint_Impl( XML_HINT_STYLE, rPos, rPos ), 74 sStyleName( rStyleName ) 75 { 76 } 77 GetStyleName() const78 const OUString& GetStyleName() const { return sStyleName; } 79 }; 80 81 class XMLReferenceHint_Impl : public XMLHint_Impl 82 { 83 OUString const sRefName; 84 85 public: 86 XMLReferenceHint_Impl(const OUString & rRefName,const css::uno::Reference<css::text::XTextRange> & rPos)87 XMLReferenceHint_Impl( const OUString& rRefName, 88 const css::uno::Reference < css::text::XTextRange > & rPos ) : 89 XMLHint_Impl( XML_HINT_REFERENCE, rPos, rPos ), 90 sRefName( rRefName ) 91 { 92 } 93 GetRefName() const94 const OUString& GetRefName() const { return sRefName; } 95 }; 96 97 class XMLHyperlinkHint_Impl : public XMLHint_Impl 98 { 99 OUString sHRef; 100 OUString sName; 101 OUString sTargetFrameName; 102 OUString sStyleName; 103 OUString sVisitedStyleName; 104 rtl::Reference<XMLEventsImportContext> mxEvents; 105 106 public: 107 XMLHyperlinkHint_Impl(const css::uno::Reference<css::text::XTextRange> & rPos)108 XMLHyperlinkHint_Impl( const css::uno::Reference < css::text::XTextRange > & rPos ) : 109 XMLHint_Impl( XML_HINT_HYPERLINK, rPos, rPos ) 110 { 111 } 112 SetHRef(const OUString & s)113 void SetHRef( const OUString& s ) { sHRef = s; } GetHRef() const114 const OUString& GetHRef() const { return sHRef; } SetName(const OUString & s)115 void SetName( const OUString& s ) { sName = s; } GetName() const116 const OUString& GetName() const { return sName; } SetTargetFrameName(const OUString & s)117 void SetTargetFrameName( const OUString& s ) { sTargetFrameName = s; } GetTargetFrameName() const118 const OUString& GetTargetFrameName() const { return sTargetFrameName; } SetStyleName(const OUString & s)119 void SetStyleName( const OUString& s ) { sStyleName = s; } GetStyleName() const120 const OUString& GetStyleName() const { return sStyleName; } SetVisitedStyleName(const OUString & s)121 void SetVisitedStyleName( const OUString& s ) { sVisitedStyleName = s; } GetVisitedStyleName() const122 const OUString& GetVisitedStyleName() const { return sVisitedStyleName; } GetEventsContext() const123 XMLEventsImportContext* GetEventsContext() const 124 { 125 return mxEvents.get(); 126 } SetEventsContext(XMLEventsImportContext * pCtxt)127 void SetEventsContext( XMLEventsImportContext* pCtxt ) 128 { 129 mxEvents.set(pCtxt); 130 } 131 }; 132 133 class XMLIndexMarkHint_Impl : public XMLHint_Impl 134 { 135 const css::uno::Reference<css::beans::XPropertySet> xIndexMarkPropSet; 136 137 const OUString sID; 138 139 public: 140 XMLIndexMarkHint_Impl(const css::uno::Reference<css::beans::XPropertySet> & rPropSet,const css::uno::Reference<css::text::XTextRange> & rPos)141 XMLIndexMarkHint_Impl( const css::uno::Reference < css::beans::XPropertySet > & rPropSet, 142 const css::uno::Reference < css::text::XTextRange > & rPos ) : 143 XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ), 144 xIndexMarkPropSet( rPropSet ), 145 sID() 146 { 147 } 148 XMLIndexMarkHint_Impl(const css::uno::Reference<css::beans::XPropertySet> & rPropSet,const css::uno::Reference<css::text::XTextRange> & rPos,const OUString & sIDString)149 XMLIndexMarkHint_Impl( const css::uno::Reference < css::beans::XPropertySet > & rPropSet, 150 const css::uno::Reference < css::text::XTextRange > & rPos, 151 const OUString& sIDString) : 152 XMLHint_Impl( XML_HINT_INDEX_MARK, rPos, rPos ), 153 xIndexMarkPropSet( rPropSet ), 154 sID(sIDString) 155 { 156 } 157 GetMark() const158 const css::uno::Reference<css::beans::XPropertySet> & GetMark() const 159 { return xIndexMarkPropSet; } GetID() const160 const OUString& GetID() const { return sID; } 161 }; 162 163 class XMLTextFrameHint_Impl : public XMLHint_Impl 164 { 165 // OD 2004-04-20 #i26791# 166 SvXMLImportContextRef const xContext; 167 168 public: 169 XMLTextFrameHint_Impl(SvXMLImportContext * pContext,const css::uno::Reference<css::text::XTextRange> & rPos)170 XMLTextFrameHint_Impl( SvXMLImportContext* pContext, 171 const css::uno::Reference < css::text::XTextRange > & rPos ) : 172 XMLHint_Impl( XML_HINT_TEXT_FRAME, rPos, rPos ), 173 xContext( pContext ) 174 { 175 } 176 GetTextContent() const177 css::uno::Reference < css::text::XTextContent > GetTextContent() const 178 { 179 css::uno::Reference < css::text::XTextContent > xTxt; 180 SvXMLImportContext *pContext = xContext.get(); 181 if (XMLTextFrameContext *pFrameContext = dynamic_cast<XMLTextFrameContext*>(pContext)) 182 xTxt = pFrameContext->GetTextContent(); 183 else if (XMLTextFrameHyperlinkContext *pLinkContext = dynamic_cast<XMLTextFrameHyperlinkContext*>(pContext)) 184 xTxt = pLinkContext->GetTextContent(); 185 186 return xTxt; 187 } 188 189 // Frame "to character": anchor moves from first to last char after saving (#i33242#) GetShape() const190 css::uno::Reference < css::drawing::XShape > GetShape() const 191 { 192 css::uno::Reference < css::drawing::XShape > xShape; 193 SvXMLImportContext *pContext = xContext.get(); 194 if (XMLTextFrameContext *pFrameContext = dynamic_cast<XMLTextFrameContext*>(pContext)) 195 xShape = pFrameContext->GetShape(); 196 else if(XMLTextFrameHyperlinkContext *pLinkContext = dynamic_cast<XMLTextFrameHyperlinkContext*>(pContext)) 197 xShape = pLinkContext->GetShape(); 198 199 return xShape; 200 } 201 IsBoundAtChar() const202 bool IsBoundAtChar() const 203 { 204 bool bRet = false; 205 SvXMLImportContext *pContext = xContext.get(); 206 if (XMLTextFrameContext *pFrameContext = dynamic_cast<XMLTextFrameContext*>(pContext)) 207 bRet = css::text::TextContentAnchorType_AT_CHARACTER == 208 pFrameContext->GetAnchorType(); 209 else if (XMLTextFrameHyperlinkContext *pLinkContext = dynamic_cast<XMLTextFrameHyperlinkContext*>(pContext)) 210 bRet = css::text::TextContentAnchorType_AT_CHARACTER == 211 pLinkContext->GetAnchorType(); 212 return bRet; 213 } 214 }; 215 216 // Core impl. of the unification of drawing objects and Writer fly frames (#i26791#) 217 class XMLDrawHint_Impl : public XMLHint_Impl 218 { 219 SvXMLImportContextRef const xContext; 220 221 public: 222 XMLDrawHint_Impl(SvXMLShapeContext * pContext,const css::uno::Reference<css::text::XTextRange> & rPos)223 XMLDrawHint_Impl( SvXMLShapeContext* pContext, 224 const css::uno::Reference < css::text::XTextRange > & rPos ) : 225 XMLHint_Impl( XML_HINT_DRAW, rPos, rPos ), 226 xContext( pContext ) 227 { 228 } 229 230 // Frame "to character": anchor moves from first to last char after saving (#i33242#) GetShape() const231 css::uno::Reference < css::drawing::XShape > const & GetShape() const 232 { 233 return static_cast<SvXMLShapeContext*>(xContext.get())->getShape(); 234 } 235 }; 236 237 #endif 238 239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 240