summaryrefslogtreecommitdiffstats
path: root/binfilter/bf_sw/source/core/doc/sw_docredln.cxx
blob: 44bc8debf2113cd72568f637e64490fa2674bb43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#ifdef _MSC_VER
#pragma hdrstop
#endif

#include <hintids.hxx>

#include <tools/shl.hxx>
#include <swmodule.hxx>

#include <horiornt.hxx>
#include <osl/diagnose.h>

#include <doc.hxx>
#include <docary.hxx>
#include <redline.hxx>
#include <pamtyp.hxx>
#include <viewsh.hxx>
#include <rootfrm.hxx>
namespace binfilter {

/*N*/ SV_IMPL_OP_PTRARR_SORT( _SwRedlineTbl, SwRedlinePtr )

/*N*/ void SwDoc::SetRedlineMode( USHORT eMode )
/*N*/ {
/*N*/   if( eRedlineMode != eMode )
/*N*/   {
/*N*/       if( (REDLINE_SHOW_MASK & eRedlineMode) != (REDLINE_SHOW_MASK & eMode)
/*N*/           || 0 == (REDLINE_SHOW_MASK & eMode) )
/*N*/       {
/*N*/           switch( REDLINE_SHOW_MASK & eMode )
/*N*/           {
/*N*/           case REDLINE_SHOW_INSERT:
/*N*/           case REDLINE_SHOW_DELETE:
/*?*/               break;
/*N*/
/*N*/           default:
/*N*/               eMode |= REDLINE_SHOW_INSERT;
/*N*/               break;
/*N*/           }
/*N*/
/*N*/       }
/*N*/       eRedlineMode = (SwRedlineMode)eMode;
/*N*/   }
/*N*/ }


/*

Text heisst, nicht von Redline "verseuchter" Text.

Verhalten von Insert-Redline:
    - im Text                           - Redline Object einfuegen
    - im InsertRedline (eigenes)        - ignorieren, bestehendes wird
                                          aufgespannt
    - im InsertRedline (andere)         - Insert Redline aufsplitten
                                          Redline Object einfuegen
    - in DeleteRedline                  - Delete Redline aufsplitten oder
                                          am Ende/Anfang verschieben

Verhalten von Delete-Redline:
    - im Text                           - Redline Object einfuegen
    - im DeleteRedline (eigenes/andere) - ignorieren
    - im InsertRedline (eigenes)        - ignorieren, Zeichen aber loeschen
    - im InsertRedline (andere)         - Insert Redline aufsplitten
                                          Redline Object einfuegen
    - Ueberlappung von Text und         - Text in eigenen Insert loeschen,
      eigenem Insert                      im andereren Text aufspannen (bis
                                          zum Insert!
    - Ueberlappung von Text und         - Redline Object einfuegen, der
      anderem Insert                      andere Insert wird vom Delete
                                          ueberlappt
*/

/*N*/ BOOL SwDoc::DeleteRedline( const SwPaM& rRange, BOOL /*bSaveInUndo*/,
/*N*/                           USHORT /*nDelType*/ )
/*N*/ {
/*N*/   if( REDLINE_IGNOREDELETE_REDLINES & eRedlineMode ||
/*N*/       !rRange.HasMark() || *rRange.GetMark() == *rRange.GetPoint() )
/*N*/       return FALSE;
/*N*/
/*N*/   const SwPosition* pStt = rRange.Start();
/*N*/   pStt == rRange.GetPoint() ? rRange.GetMark() : rRange.GetPoint();

/*N*/   USHORT n = 0;
/*N*/   GetRedline( *pStt, &n );
/*N*/
/*N*/   return FALSE;
/*N*/ }

/*N*/ BOOL SwDoc::DeleteRedline( const SwStartNode& rNode, BOOL bSaveInUndo,
/*N*/                           USHORT nDelType )
/*N*/ {
/*N*/   SwPaM aTemp( *rNode.EndOfSectionNode(), rNode );
/*N*/   return DeleteRedline( aTemp, bSaveInUndo, nDelType );
/*N*/ }

/*N*/ const SwRedline* SwDoc::GetRedline( const SwPosition& /*rPos*/,
/*N*/                                   USHORT* pFndPos ) const
/*N*/ {
/*N*/   if( pFndPos )
/*N*/       *pFndPos = 0;
/*N*/   return 0;
/*N*/ }

// Kommentar am Redline setzen

    // fuer die Reader usw. - neuen Author in die Tabelle eintragen
/*N*/ USHORT SwDoc::InsertRedlineAuthor( const String& rNew )
/*N*/ {
/*N*/ return SW_MOD()->InsertRedlineAuthor(rNew); //SW50.SDW
/*N*/ }


    // setze Kommentar-Text fuers Redline, das dann per AppendRedline
    // hereinkommt. Wird vom Autoformat benutzt. 0-Pointer setzt den Modus
    // wieder zurueck. Pointer wird nicht kopiert, muss also gueltig bleiben!

/*N*/ void SwDoc::SetRedlinePasswd(
/*N*/           const ::com::sun::star::uno::Sequence <sal_Int8>& rNew )
/*N*/ {
/*N*/   aRedlinePasswd = rNew;
/*N*/   SetModified();
/*N*/ }


/*N*/ BOOL SwRedlineTbl::Insert( SwRedlinePtr& p, BOOL bIns ) //SW50.SDW
/*N*/ {
/*N*/   BOOL bRet = FALSE;
/*N*/   if( p->HasValidRange() )
/*N*/   {
/*N*/       bRet = _SwRedlineTbl::Insert( p );
/*N*/   }
/*N*/   else if( bIns )
/*N*/       bRet = InsertWithValidRanges( p );
/*N*/   else
/*N*/   {
/*N*/       OSL_ENSURE( !this, "Redline: falscher Bereich" );
/*N*/   }
/*N*/   return bRet;
/*N*/ }


/*N*/ BOOL SwRedlineTbl::InsertWithValidRanges( SwRedlinePtr& p, USHORT* pInsPos ) //SW50.SDW
/*N*/ {
/*N*/   // erzeuge aus den Selektion gueltige "Teilbereiche".
/*N*/   BOOL bAnyIns = FALSE;
/*N*/   SwPosition* pStt = p->Start(),
/*N*/             * pEnd = pStt == p->GetPoint() ? p->GetMark() : p->GetPoint();
/*N*/   SwPosition aNewStt( *pStt );
/*N*/   SwNodes& rNds = aNewStt.nNode.GetNodes();
/*N*/   SwCntntNode* pC;
/*N*/
/*N*/   if( !aNewStt.nNode.GetNode().IsCntntNode() )
/*N*/   {
/*N*/       pC = rNds.GoNext( &aNewStt.nNode );
/*N*/       if( pC )
/*N*/           aNewStt.nContent.Assign( pC, 0 );
/*N*/       else
/*N*/           aNewStt.nNode = rNds.GetEndOfContent();
/*N*/   }
/*N*/
/*N*/   SwRedline* pNew = 0;
/*N*/   USHORT nInsPos;
/*N*/
/*N*/   if( aNewStt < *pEnd )
/*N*/       do {
/*N*/           if( !pNew )
/*N*/               pNew = new SwRedline( p->GetRedlineData(), aNewStt );
/*N*/           else
/*N*/           {
/*N*/               pNew->DeleteMark();
/*N*/               *pNew->GetPoint() = aNewStt;
/*N*/           }
/*N*/
/*N*/           pNew->SetMark();
/*N*/           if( *pNew->GetPoint() > *pEnd )
/*N*/           {
/*N*/               pC = 0;
/*N*/               if( aNewStt.nNode != pEnd->nNode )
/*N*/                   do {
/*N*/                       SwNode& rCurNd = aNewStt.nNode.GetNode();
/*N*/                       if( rCurNd.IsStartNode() )
/*N*/                       {
/*N*/                           if( rCurNd.EndOfSectionIndex() < pEnd->nNode.GetIndex() )
/*N*/                               aNewStt.nNode = *rCurNd.EndOfSectionNode();
/*N*/                           else
/*N*/                               break;
/*N*/                       }
/*N*/                       else if( rCurNd.IsCntntNode() )
/*N*/                           pC = rCurNd.GetCntntNode();
/*N*/                       aNewStt.nNode++;
/*N*/                   } while( aNewStt.nNode.GetIndex() < pEnd->nNode.GetIndex() );
/*N*/
/*N*/               if( aNewStt.nNode == pEnd->nNode )
/*N*/                   aNewStt.nContent = pEnd->nContent;
/*N*/               else if( pC )
/*N*/               {
/*N*/                   aNewStt.nNode = *pC;
/*N*/                   aNewStt.nContent.Assign( pC, pC->Len() );
/*N*/               }
/*N*/
/*N*/               if( aNewStt <= *pEnd )
/*N*/                   *pNew->GetPoint() = aNewStt;
/*N*/           }
/*N*/           else
/*N*/               aNewStt = *pNew->GetPoint();
/*N*/
/*N*/           if( *pNew->GetPoint() != *pNew->GetMark() &&
/*N*/               _SwRedlineTbl::Insert( pNew, nInsPos ) )
/*N*/           {
/*N*/               bAnyIns = TRUE;
/*N*/               pNew = 0;
/*N*/               if( pInsPos && *pInsPos < nInsPos )
/*N*/                   *pInsPos = nInsPos;
/*N*/           }
/*N*/
/*N*/           if( aNewStt >= *pEnd ||
/*N*/               0 == (pC = rNds.GoNext( &aNewStt.nNode )) )
/*N*/               break;
/*N*/
/*N*/           aNewStt.nContent.Assign( pC, 0 );
/*N*/
/*N*/       } while( aNewStt < *pEnd );
/*N*/
/*N*/   delete pNew;
/*N*/   delete p, p = 0;
/*N*/   return bAnyIns;
/*N*/ }

/*N*/ void SwRedlineTbl::Remove( USHORT nP, USHORT nL ) //SW50.SDW
/*N*/ {
/*N*/   _SwRedlineTbl::Remove( nP, nL );
/*N*/ }


/*?*/SwRedlineData::SwRedlineData( const SwRedlineData& rCpy, BOOL bCpyNext )
/*?*/   : pNext( (bCpyNext && rCpy.pNext) ? new SwRedlineData( *rCpy.pNext ) : 0 )
/*?*/   , sComment( rCpy.sComment )
/*?*/   , aStamp( rCpy.aStamp )
/*?*/   , eType( rCpy.eType )
/*?*/   , nAuthor( rCpy.nAuthor )
/*?*/   , nSeqNo( rCpy.nSeqNo )
/*?*/{
/*?*/}

    // fuer sw3io: pNext geht in eigenen Besitz ueber!
/*?*/SwRedlineData::SwRedlineData( SwRedlineType eT, USHORT nAut, const DateTime& rDT,
/*?*/                  const String& rCmnt, SwRedlineData *pNxt )
/*?*/   : pNext( pNxt )
/*?*/   , sComment( rCmnt )
/*?*/   , aStamp( rDT )
/*?*/   , eType( eT )
/*?*/   , nAuthor( nAut )
/*?*/   , nSeqNo( 0 )
/*?*/{
/*?*/}

/*?*/SwRedlineData::~SwRedlineData()
/*?*/{
/*?*/   delete pNext;
/*?*/}


/*?*/SwRedline::SwRedline( const SwRedlineData& rData, const SwPosition& rPos )
/*?*/   : SwPaM( rPos )
/*?*/   , pRedlineData( new SwRedlineData( rData ))
/*?*/   , pCntntSect( 0 )
/*?*/{
/*?*/   bDelLastPara = bIsLastParaDelete = FALSE;
/*?*/   bIsVisible = TRUE;
/*?*/}

/*?*/SwRedline::SwRedline( const SwRedline& rCpy )
/*?*/   : SwPaM( *rCpy.GetMark(), *rCpy.GetPoint() )
/*?*/   , pRedlineData( new SwRedlineData( *rCpy.pRedlineData ))
/*?*/   , pCntntSect( 0 )
/*?*/{
/*?*/   bDelLastPara = bIsLastParaDelete = FALSE;
/*?*/   bIsVisible = TRUE;
/*?*/   if( !rCpy.HasMark() )
/*?*/       DeleteMark();
/*?*/}

/*?*/SwRedline::~SwRedline()
/*?*/{
/*?*/   if( pCntntSect )
/*?*/   {
/*?*/       // dann den Content Bereich loeschen
/*?*/       if( !GetDoc()->IsInDtor() )
/*?*/           GetDoc()->DeleteSection( &pCntntSect->GetNode() );
/*?*/       delete pCntntSect;
/*?*/   }
/*?*/   delete pRedlineData;
/*?*/}

// liegt eine gueltige Selektion vor?
/*N*/ BOOL SwRedline::HasValidRange() const //SW50.SDW
/*N*/ {
/*N*/   const SwNode* pPtNd = &GetPoint()->nNode.GetNode(),
/*N*/               * pMkNd = &GetMark()->nNode.GetNode();
/*N*/   if( pPtNd->FindStartNode() == pMkNd->FindStartNode() &&
/*N*/       !pPtNd->FindStartNode()->IsTableNode() &&
/*N*/         // invalid if points on the end of content
/*N*/         // end-of-content only invalid if no content index exists
/*N*/       ( pPtNd != pMkNd || GetContentIdx() != NULL ||
/*N*/           pPtNd != &pPtNd->GetNodes().GetEndOfContent() )
/*N*/       )
/*N*/       return TRUE;
/*N*/   return FALSE;
/*N*/ }


/*?*/const String& SwRedline::GetAuthorString( USHORT nPos ) const
/*?*/{
        SwRedlineData* pCur;
/*?*/   for( pCur = pRedlineData; nPos && pCur->pNext; --nPos )
/*?*/       pCur = pCur->pNext;
/*?*/   OSL_ENSURE( !nPos, "Pos angabe ist zu gross" );
/*?*/   return SW_MOD()->GetRedlineAuthor(pCur->nAuthor);
/*?*/}

/*N*/ int SwRedline::operator==( const SwRedline& rCmp ) const
/*N*/ {
/*N*/   return this == &rCmp;
/*N*/ }

/*N*/ int SwRedline::operator<( const SwRedline& rCmp ) const
/*N*/ {
/*N*/       BOOL nResult = FALSE;
/*N*/
/*N*/     if (*Start() < *rCmp.Start())
/*N*/         nResult = TRUE;
/*N*/     else if (*Start() == *rCmp.Start())
/*N*/         if (*End() < *rCmp.End())
/*N*/             nResult = TRUE;
/*N*/
/*N*/     return nResult;
/*N*/ }
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */