xref: /trunk/main/sc/source/core/tool/chgviset.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <unotools/textsearch.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "chgviset.hxx"
32cdf0e10cSrcweir #include "rechead.hxx"
33cdf0e10cSrcweir #include "chgtrack.hxx"
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // -----------------------------------------------------------------------
~ScChangeViewSettings()36cdf0e10cSrcweir ScChangeViewSettings::~ScChangeViewSettings()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir     if(pCommentSearcher!=NULL)
39cdf0e10cSrcweir         delete pCommentSearcher;
40cdf0e10cSrcweir }
41cdf0e10cSrcweir 
ScChangeViewSettings(const ScChangeViewSettings & r)42cdf0e10cSrcweir ScChangeViewSettings::ScChangeViewSettings( const ScChangeViewSettings& r )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir     SetTheComment(r.aComment);
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     aFirstDateTime  =r.aFirstDateTime;
47cdf0e10cSrcweir     aLastDateTime   =r.aLastDateTime;
48cdf0e10cSrcweir     aAuthorToShow   =r.aAuthorToShow;
49cdf0e10cSrcweir     aRangeList      =r.aRangeList;
50cdf0e10cSrcweir     eDateMode       =r.eDateMode;
51cdf0e10cSrcweir     bShowIt         =r.bShowIt;
52cdf0e10cSrcweir     bIsDate         =r.bIsDate;
53cdf0e10cSrcweir     bIsAuthor       =r.bIsAuthor;
54cdf0e10cSrcweir     bIsComment      =r.bIsComment;
55cdf0e10cSrcweir     bIsRange        =r.bIsRange;
56cdf0e10cSrcweir     bEveryoneButMe  =r.bEveryoneButMe;
57cdf0e10cSrcweir     bShowAccepted   =r.bShowAccepted;
58cdf0e10cSrcweir     bShowRejected   =r.bShowRejected;
59cdf0e10cSrcweir     mbIsActionRange = r.mbIsActionRange;
60cdf0e10cSrcweir     mnFirstAction   = r.mnFirstAction;
61cdf0e10cSrcweir     mnLastAction    = r.mnLastAction;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
operator =(const ScChangeViewSettings & r)65cdf0e10cSrcweir ScChangeViewSettings& ScChangeViewSettings::operator=( const ScChangeViewSettings& r )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     SetTheComment(r.aComment);
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     aFirstDateTime  =r.aFirstDateTime;
70cdf0e10cSrcweir     aLastDateTime   =r.aLastDateTime;
71cdf0e10cSrcweir     aAuthorToShow   =r.aAuthorToShow;
72cdf0e10cSrcweir     aRangeList      =r.aRangeList;
73cdf0e10cSrcweir     eDateMode       =r.eDateMode;
74cdf0e10cSrcweir     bShowIt         =r.bShowIt;
75cdf0e10cSrcweir     bIsDate         =r.bIsDate;
76cdf0e10cSrcweir     bIsAuthor       =r.bIsAuthor;
77cdf0e10cSrcweir     bIsComment      =r.bIsComment;
78cdf0e10cSrcweir     bIsRange        =r.bIsRange;
79cdf0e10cSrcweir     bEveryoneButMe  =r.bEveryoneButMe;
80cdf0e10cSrcweir     bShowAccepted   =r.bShowAccepted;
81cdf0e10cSrcweir     bShowRejected   =r.bShowRejected;
82cdf0e10cSrcweir     mbIsActionRange = r.mbIsActionRange;
83cdf0e10cSrcweir     mnFirstAction   = r.mnFirstAction;
84cdf0e10cSrcweir     mnLastAction    = r.mnLastAction;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     return *this;
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
IsValidComment(const String * pCommentStr) const89cdf0e10cSrcweir sal_Bool ScChangeViewSettings::IsValidComment(const String* pCommentStr) const
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     sal_Bool nTheFlag=sal_True;
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     if(pCommentSearcher!=NULL)
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         xub_StrLen nStartPos = 0;
96cdf0e10cSrcweir         xub_StrLen nEndPos = pCommentStr->Len();
97cdf0e10cSrcweir 
98cdf0e10cSrcweir         nTheFlag=sal::static_int_cast<sal_Bool>(pCommentSearcher->SearchFrwrd( *pCommentStr, &nStartPos, &nEndPos));
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir     return nTheFlag;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
SetTheComment(const String & rString)103cdf0e10cSrcweir void ScChangeViewSettings::SetTheComment(const String& rString)
104cdf0e10cSrcweir {
105cdf0e10cSrcweir     aComment=rString;
106cdf0e10cSrcweir     if(pCommentSearcher!=NULL)
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         delete pCommentSearcher;
109cdf0e10cSrcweir         pCommentSearcher=NULL;
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     if(rString.Len()>0)
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         utl::SearchParam aSearchParam( rString,
115cdf0e10cSrcweir             utl::SearchParam::SRCH_REGEXP,sal_False,sal_False,sal_False );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         pCommentSearcher = new utl::TextSearch( aSearchParam, *ScGlobal::pCharClass );
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
AdjustDateMode(const ScDocument & rDoc)121cdf0e10cSrcweir void ScChangeViewSettings::AdjustDateMode( const ScDocument& rDoc )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir     switch ( eDateMode )
124cdf0e10cSrcweir     {   // corresponds with ScViewUtil::IsActionShown
125cdf0e10cSrcweir         case SCDM_DATE_EQUAL :
126cdf0e10cSrcweir         case SCDM_DATE_NOTEQUAL :
127cdf0e10cSrcweir             aFirstDateTime.SetTime( 0 );
128cdf0e10cSrcweir             aLastDateTime = aFirstDateTime;
129cdf0e10cSrcweir             aLastDateTime.SetTime( 23595999 );
130cdf0e10cSrcweir             break;
131cdf0e10cSrcweir         case SCDM_DATE_SAVE:
132cdf0e10cSrcweir         {
133cdf0e10cSrcweir             const ScChangeAction* pLast = 0;
134cdf0e10cSrcweir             ScChangeTrack* pTrack = rDoc.GetChangeTrack();
135cdf0e10cSrcweir             if ( pTrack )
136cdf0e10cSrcweir             {
137cdf0e10cSrcweir                 pLast = pTrack->GetLastSaved();
138cdf0e10cSrcweir                 if ( pLast )
139cdf0e10cSrcweir                 {
140cdf0e10cSrcweir                     aFirstDateTime = pLast->GetDateTime();
141cdf0e10cSrcweir #if 0
142cdf0e10cSrcweir // This would be the proper handling. But since the SvxTPFilter dialog uses
143cdf0e10cSrcweir // DateField/TimeField, and the filter dialog is used in ScAcceptChgDlg as the
144cdf0e10cSrcweir // controlling instance, and the TimeFields are used there without seconds or
145cdf0e10cSrcweir // 100ths, we'd display some extra entries between the floor of the minute and
146cdf0e10cSrcweir // the start of the next minute.
147cdf0e10cSrcweir                     // add one 100th second to point past last saved
148cdf0e10cSrcweir                     aFirstDateTime += Time( 0, 0, 0, 1 );
149cdf0e10cSrcweir #else
150cdf0e10cSrcweir                     // Set the next minute as the start time and assume that
151cdf0e10cSrcweir                     // the document isn't saved, reloaded, edited and filter set
152cdf0e10cSrcweir                     // all together during the gap between those two times.
153cdf0e10cSrcweir                     aFirstDateTime += Time( 0, 1 );
154cdf0e10cSrcweir                     aFirstDateTime.SetSec(0);
155cdf0e10cSrcweir                     aFirstDateTime.Set100Sec(0);
156cdf0e10cSrcweir #endif
157cdf0e10cSrcweir                 }
158cdf0e10cSrcweir             }
159cdf0e10cSrcweir             if ( !pLast )
160cdf0e10cSrcweir             {
161cdf0e10cSrcweir                 aFirstDateTime.SetDate( 18990101 );
162cdf0e10cSrcweir                 aFirstDateTime.SetTime( 0 );
163cdf0e10cSrcweir             }
164cdf0e10cSrcweir             aLastDateTime = Date();
165cdf0e10cSrcweir             aLastDateTime.SetYear( aLastDateTime.GetYear() + 100 );
166cdf0e10cSrcweir         }
167cdf0e10cSrcweir         break;
168cdf0e10cSrcweir         default:
169cdf0e10cSrcweir         {
170cdf0e10cSrcweir             // added to avoid warnings
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir }
174