1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _XMLREDLINEIMPORTHELPER_HXX 24 #define _XMLREDLINEIMPORTHELPER_HXX 25 26 #include <rtl/ustring.hxx> 27 #include <com/sun/star/uno/Reference.h> 28 #include <com/sun/star/uno/Sequence.h> 29 #include <com/sun/star/util/DateTime.hpp> 30 #include "redline.hxx" 31 32 #include <map> 33 34 class RedlineInfo; 35 class SwRedlineData; 36 class SwDoc; 37 namespace com { namespace sun { namespace star { 38 namespace text { class XTextCursor; } 39 namespace text { class XTextRange; } 40 namespace frame { class XModel; } 41 } } } 42 43 44 typedef ::std::map< ::rtl::OUString, RedlineInfo* > RedlineMapType; 45 46 class XMLRedlineImportHelper 47 { 48 const ::rtl::OUString sEmpty; 49 const ::rtl::OUString sInsertion; 50 const ::rtl::OUString sDeletion; 51 const ::rtl::OUString sFormatChange; 52 const ::rtl::OUString sShowChanges; 53 const ::rtl::OUString sRecordChanges; 54 const ::rtl::OUString sRedlineProtectionKey; 55 56 RedlineMapType aRedlineMap; 57 58 /// if sal_True, no redlines should be inserted into document 59 /// (This typically happen when a document is loaded in 'insert'-mode.) 60 sal_Bool bIgnoreRedlines; 61 62 /// save information for saving and reconstruction of the redline mode 63 ::com::sun::star::uno::Reference< 64 ::com::sun::star::beans::XPropertySet> xModelPropertySet; 65 ::com::sun::star::uno::Reference< 66 ::com::sun::star::beans::XPropertySet> xImportInfoPropertySet; 67 sal_Bool bShowChanges; 68 sal_Bool bRecordChanges; 69 ::com::sun::star::uno::Sequence<sal_Int8> aProtectionKey; 70 71 public: 72 73 XMLRedlineImportHelper( 74 sal_Bool bIgnoreRedlines, /// ignore redlines mode 75 76 // property sets of model + import info for saving + restoring the 77 // redline mode 78 const ::com::sun::star::uno::Reference< 79 ::com::sun::star::beans::XPropertySet> & rModel, 80 const ::com::sun::star::uno::Reference< 81 ::com::sun::star::beans::XPropertySet> & rImportInfoSet ); 82 virtual ~XMLRedlineImportHelper(); 83 84 /// create a redline object 85 /// (The redline will be inserted into the document after both start 86 /// and end cursor has been set.) 87 void Add( 88 const ::rtl::OUString& rType, /// redline type (insert, del,... ) 89 const ::rtl::OUString& rId, /// use to identify this redline 90 const ::rtl::OUString& rAuthor, /// name of the author 91 const ::rtl::OUString& rComment, /// redline comment 92 const ::com::sun::star::util::DateTime& rDateTime, /// date+time 93 sal_Bool bMergeLastParagraph); /// merge last paragraph? 94 95 /// create a text section for the redline, and return an 96 /// XText/XTextCursor that may be used to write into it. 97 ::com::sun::star::uno::Reference< 98 ::com::sun::star::text::XTextCursor> CreateRedlineTextSection( 99 ::com::sun::star::uno::Reference< /// needed to get the document 100 ::com::sun::star::text::XTextCursor> xOldCursor, 101 const ::rtl::OUString& rId); /// ID used to RedlineAdd() call 102 103 /// Set start or end position for a redline in the text body. 104 /// Accepts XTextRange objects. 105 void SetCursor( 106 const ::rtl::OUString& rId, /// ID used in RedlineAdd() call 107 sal_Bool bStart, /// start or end Range 108 ::com::sun::star::uno::Reference< /// the actual XTextRange 109 ::com::sun::star::text::XTextRange> & rRange, 110 /// text range is (from an XML view) outside of a paragraph 111 /// (i.e. before a table) 112 sal_Bool bIsOusideOfParagraph); 113 114 /** 115 * Adjust the start (end) position for a redline that begins in a 116 * start node. It takes the cursor positions _inside_ the redlined 117 * element (e.g. section or table). 118 * 119 * We will do sanity checking of the given text range: It will 120 * only be considered valid if it points to the next text node 121 * after the position given in a previous SetCursor */ 122 void AdjustStartNodeCursor( 123 const ::rtl::OUString& rId, /// ID used in RedlineAdd() call 124 sal_Bool bStart, 125 /// XTextRange _inside_ a table/section 126 ::com::sun::star::uno::Reference< 127 ::com::sun::star::text::XTextRange> & rRange); 128 129 /// set redline mode: show changes 130 void SetShowChanges( sal_Bool bShowChanges ); 131 132 /// set redline mode: record changes 133 void SetRecordChanges( sal_Bool bRecordChanges ); 134 135 /// set redline protection key 136 void SetProtectionKey( 137 const ::com::sun::star::uno::Sequence<sal_Int8> & rKey ); 138 139 private: 140 141 inline sal_Bool IsReady(RedlineInfo* pRedline); 142 143 void InsertIntoDocument(RedlineInfo* pRedline); 144 145 SwRedlineData* ConvertRedline( 146 RedlineInfo* pRedline, /// RedlineInfo to be converted 147 SwDoc* pDoc); /// document needed for Author-ID conversion 148 149 /** save the redline mode (if rPropertySet is non-null) */ 150 void SaveRedlineMode( 151 const ::com::sun::star::uno::Reference< 152 ::com::sun::star::beans::XPropertySet> & rPropertySet); 153 154 /** don't restore the saved redline mode */ 155 void DontRestoreRedlineMode(); 156 157 }; 158 159 #endif 160 161