| 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_SW_INC_UNOCRSRHELPER_HXX |
| 20 | #define INCLUDED_SW_INC_UNOCRSRHELPER_HXX |
| 21 | |
| 22 | #include "swtypes.hxx" |
| 23 | #include "flyenum.hxx" |
| 24 | #include "pam.hxx" |
| 25 | |
| 26 | #include <optional> |
| 27 | #include <map> |
| 28 | #include <string_view> |
| 29 | |
| 30 | class SfxItemSet; |
| 31 | class SfxItemPropertySet; |
| 32 | struct SfxItemPropertyMapEntry; |
| 33 | class SdrObject; |
| 34 | class SwTextNode; |
| 35 | class SwCursor; |
| 36 | class SwUnoCursor; |
| 37 | class SwUnoTableCursor; |
| 38 | class SwFormatColl; |
| 39 | struct SwSortOptions; |
| 40 | class SwDoc; |
| 41 | class SwRootFrame; |
| 42 | class ProgName; |
| 43 | |
| 44 | namespace sw::mark { class MarkBase; } |
| 45 | |
| 46 | namespace com::sun::star{ |
| 47 | namespace beans{ |
| 48 | struct PropertyValue; |
| 49 | enum class PropertyState; |
| 50 | } |
| 51 | namespace text { |
| 52 | class XTextContent; |
| 53 | class XFlatParagraphIterator; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | enum SwGetPropertyStatesCaller |
| 58 | { |
| 59 | SW_PROPERTY_STATE_CALLER_DEFAULT, |
| 60 | SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION, |
| 61 | SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY, |
| 62 | SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT |
| 63 | }; |
| 64 | |
| 65 | namespace SwUnoCursorHelper |
| 66 | { |
| 67 | class SwAnyMapHelper |
| 68 | { |
| 69 | private: |
| 70 | // keep Any's mapped by (WhichId << 16 ) + (MemberId) |
| 71 | std::map<sal_uInt32, css::uno::Any> m_Map; |
| 72 | |
| 73 | public: |
| 74 | void SetValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const css::uno::Any& rAny ); |
| 75 | bool FillValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const css::uno::Any*& pAny ); |
| 76 | }; |
| 77 | |
| 78 | css::uno::Reference< css::text::XTextContent > |
| 79 | GetNestedTextContent(SwTextNode const & rTextNode, sal_Int32 const nIndex, |
| 80 | bool const bParent); |
| 81 | |
| 82 | bool getCursorPropertyValue(const SfxItemPropertyMapEntry& rEntry |
| 83 | , SwPaM& rPam |
| 84 | , css::uno::Any *pAny |
| 85 | , css::beans::PropertyState& eState |
| 86 | , const SwTextNode* pNode = nullptr ); |
| 87 | |
| 88 | void GetCurPageStyle(SwPaM const & rPaM, ProgName &rString); |
| 89 | |
| 90 | inline bool IsStartOfPara(SwPaM& rUnoCursor) |
| 91 | { return rUnoCursor.GetPoint()->GetContentIndex() == 0;} |
| 92 | inline bool IsEndOfPara(SwPaM& rUnoCursor) |
| 93 | { return rUnoCursor.GetPointContentNode() && |
| 94 | rUnoCursor.GetPoint()->GetContentIndex() == rUnoCursor.GetPointContentNode()->Len();} |
| 95 | |
| 96 | void resetCursorPropertyValue(const SfxItemPropertyMapEntry& rEntry, SwPaM& rPam); |
| 97 | /// @throws css::lang::IllegalArgumentException |
| 98 | /// @throws css::io::IOException |
| 99 | /// @throws css::uno::RuntimeException |
| 100 | void InsertFile(SwUnoCursor* pUnoCursor, |
| 101 | const OUString& rURL, |
| 102 | const css::uno::Sequence< css::beans::PropertyValue >& rOptions); |
| 103 | |
| 104 | void getNumberingProperty( |
| 105 | SwPaM& rPam, |
| 106 | css::beans::PropertyState& eState, |
| 107 | css::uno::Any *pAny ); |
| 108 | |
| 109 | void setNumberingProperty( |
| 110 | const css::uno::Any& rValue, |
| 111 | SwPaM& rPam); |
| 112 | |
| 113 | sal_Int16 IsNodeNumStart( |
| 114 | SwPaM const & rPam, |
| 115 | css::beans::PropertyState& eState); |
| 116 | |
| 117 | bool DocInsertStringSplitCR( SwDoc &rDoc, |
| 118 | const SwPaM &rNewCursor, std::u16string_view aText, |
| 119 | const bool bForceExpandHints ); |
| 120 | /// @throws css::lang::IllegalArgumentException |
| 121 | /// @throws css::uno::RuntimeException |
| 122 | void makeRedline( SwPaM const & rPaM, std::u16string_view RedlineType, |
| 123 | const css::uno::Sequence< css::beans::PropertyValue >& RedlineProperties ); |
| 124 | |
| 125 | /// @throws css::lang::IllegalArgumentException |
| 126 | /// @throws css::uno::RuntimeException |
| 127 | void makeTableRowRedline( SwTableLine& rTableLine, std::u16string_view RedlineType, |
| 128 | const css::uno::Sequence< css::beans::PropertyValue >& RedlineProperties ); |
| 129 | |
| 130 | /// @throws css::lang::IllegalArgumentException |
| 131 | /// @throws css::uno::RuntimeException |
| 132 | SW_DLLPUBLIC void makeTableCellRedline( SwTableBox& rTableBox, std::u16string_view RedlineType, |
| 133 | const css::uno::Sequence< css::beans::PropertyValue >& RedlineProperties ); |
| 134 | |
| 135 | /// @param bTableMode: attributes should be applied to a table selection |
| 136 | void SetCursorAttr(SwPaM & rPam, const SfxItemSet & rSet, |
| 137 | const SetAttrMode nAttrMode, |
| 138 | const bool bTableMode = false); |
| 139 | void GetCursorAttr(SwPaM & rPam, SfxItemSet & rSet, |
| 140 | const bool bOnlyTextAttr = false, |
| 141 | const bool bGetFromChrFormat = true); |
| 142 | void GetTextFromPam(SwPaM & rPam, OUString & rBuffer, SwRootFrame const* pLayout = nullptr); |
| 143 | SwFormatColl * GetCurTextFormatColl(SwPaM & rPam, const bool bConditional); |
| 144 | |
| 145 | void SelectPam(SwPaM & rPam, const bool bExpand); |
| 146 | void SetString(SwCursor & rCursor, std::u16string_view aString); |
| 147 | |
| 148 | css::uno::Sequence< css::beans::PropertyValue > |
| 149 | CreateSortDescriptor(const bool bFromTable); |
| 150 | bool ConvertSortProperties( |
| 151 | const css::uno::Sequence< css::beans::PropertyValue >& rDescriptor, |
| 152 | SwSortOptions & rSortOpt); |
| 153 | |
| 154 | /// @throws css::beans::UnknownPropertyException |
| 155 | /// @throws css::beans::PropertyVetoException |
| 156 | /// @throws css::lang::IllegalArgumentException |
| 157 | /// @throws css::lang::WrappedTargetException |
| 158 | /// @throws css::uno::RuntimeException |
| 159 | void SetPropertyValue( |
| 160 | SwPaM& rPaM, |
| 161 | const SfxItemPropertySet & rPropSet, |
| 162 | const OUString & rPropertyName, |
| 163 | const css::uno::Any & rValue, |
| 164 | const SetAttrMode nAttrMode = SetAttrMode::DEFAULT); |
| 165 | /// @throws css::beans::UnknownPropertyException |
| 166 | /// @throws css::beans::PropertyVetoException |
| 167 | /// @throws css::lang::IllegalArgumentException |
| 168 | /// @throws css::lang::WrappedTargetException |
| 169 | /// @throws css::uno::RuntimeException |
| 170 | void SetPropertyValues( |
| 171 | SwPaM& rPaM, |
| 172 | const SfxItemPropertySet & rPropSet, |
| 173 | const css::uno::Sequence< css::beans::PropertyValue > & |
| 174 | rPropertyValues, |
| 175 | const SetAttrMode nAttrMode = SetAttrMode::DEFAULT); |
| 176 | void SetPropertyValues( |
| 177 | SwPaM& rPaM, |
| 178 | const SfxItemPropertySet & rPropSet, |
| 179 | std::span< const css::beans::PropertyValue > aPropertyValues, |
| 180 | const SetAttrMode nAttrMode = SetAttrMode::DEFAULT); |
| 181 | /// @throws css::beans::UnknownPropertyException |
| 182 | /// @throws css::lang::WrappedTargetException |
| 183 | /// @throws css::uno::RuntimeException |
| 184 | css::uno::Any GetPropertyValue( |
| 185 | SwPaM& rPaM, |
| 186 | const SfxItemPropertySet & rPropSet, |
| 187 | std::u16string_view rPropertyName); |
| 188 | /// @throws css::beans::UnknownPropertyException |
| 189 | /// @throws css::uno::RuntimeException |
| 190 | css::uno::Sequence< css::beans::PropertyState > GetPropertyStates( |
| 191 | SwPaM & rPaM, |
| 192 | const SfxItemPropertySet & rPropSet, |
| 193 | const css::uno::Sequence< OUString >& |
| 194 | rPropertyNames, |
| 195 | const SwGetPropertyStatesCaller eCaller = |
| 196 | SW_PROPERTY_STATE_CALLER_DEFAULT); |
| 197 | /// @throws css::beans::UnknownPropertyException |
| 198 | /// @throws css::uno::RuntimeException |
| 199 | css::beans::PropertyState GetPropertyState( |
| 200 | SwPaM & rPaM, |
| 201 | const SfxItemPropertySet & rPropSet, |
| 202 | const OUString & rPropertyName); |
| 203 | /// @throws css::beans::UnknownPropertyException |
| 204 | /// @throws css::uno::RuntimeException |
| 205 | void SetPropertyToDefault( |
| 206 | SwPaM & rPaM, |
| 207 | const SfxItemPropertySet & rPropSet, |
| 208 | std::u16string_view rPropertyName); |
| 209 | /// @throws css::beans::UnknownPropertyException |
| 210 | /// @throws css::lang::WrappedTargetException |
| 211 | /// @throws css::uno::RuntimeException |
| 212 | css::uno::Any GetPropertyDefault( |
| 213 | SwPaM const & rPaM, |
| 214 | const SfxItemPropertySet & rPropSet, |
| 215 | std::u16string_view rPropertyName); |
| 216 | |
| 217 | bool SetPageDesc( |
| 218 | const css::uno::Any& rValue, |
| 219 | SwDoc & rDoc, SfxItemSet & rSet); |
| 220 | /// @throws css::lang::IllegalArgumentException |
| 221 | /// @throws css::uno::RuntimeException |
| 222 | void SetTextFormatColl(const css::uno::Any & rAny, SwPaM & rPaM); |
| 223 | /// @throws css::lang::IllegalArgumentException |
| 224 | /// @throws css::uno::RuntimeException |
| 225 | /// @throws css::uno::DeploymentException |
| 226 | bool SetCursorPropertyValue( |
| 227 | SfxItemPropertyMapEntry const& rEntry, |
| 228 | css::uno::Any const& rValue, |
| 229 | SwPaM & rPam, SfxItemSet & rItemSet); |
| 230 | |
| 231 | /// try to get something that can be selected out of the XInterface |
| 232 | /// at most one of the out parameters gets assigned a non-null value |
| 233 | /// o_rpPaM is newly allocated and must be deleted; other parameters not |
| 234 | SW_DLLPUBLIC void GetSelectableFromAny( |
| 235 | css::uno::Reference<css::uno::XInterface> const& xIfc, |
| 236 | SwDoc & rTargetDoc, |
| 237 | std::optional<SwPaM>& o_rpPaM, std::pair<UIName, FlyCntType> & o_rFrame, |
| 238 | UIName & o_rTableName, SwUnoTableCursor const*& o_rpTableCursor, |
| 239 | ::sw::mark::MarkBase const*& o_rpMark, |
| 240 | std::vector<SdrObject *> & o_rSdrObjects); |
| 241 | |
| 242 | css::uno::Reference<css::text::XFlatParagraphIterator> |
| 243 | CreateFlatParagraphIterator(SwDoc &, sal_Int32, bool); |
| 244 | |
| 245 | void SetCharStyle(SwDoc& rDoc, const css::uno::Any& rValue, SfxItemSet& rSet); |
| 246 | |
| 247 | } // namespace SwUnoCursorHelper |
| 248 | |
| 249 | #endif |
| 250 | |
| 251 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |