xref: /trunk/main/sc/source/core/tool/chgviset.cxx (revision b3f79822)
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 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 #include <unotools/textsearch.hxx>
30 
31 #include "chgviset.hxx"
32 #include "rechead.hxx"
33 #include "chgtrack.hxx"
34 
35 // -----------------------------------------------------------------------
~ScChangeViewSettings()36 ScChangeViewSettings::~ScChangeViewSettings()
37 {
38 	if(pCommentSearcher!=NULL)
39 		delete pCommentSearcher;
40 }
41 
ScChangeViewSettings(const ScChangeViewSettings & r)42 ScChangeViewSettings::ScChangeViewSettings( const ScChangeViewSettings& r )
43 {
44 	SetTheComment(r.aComment);
45 
46 	aFirstDateTime	=r.aFirstDateTime;
47 	aLastDateTime	=r.aLastDateTime;
48 	aAuthorToShow	=r.aAuthorToShow;
49 	aRangeList		=r.aRangeList;
50 	eDateMode		=r.eDateMode;
51 	bShowIt			=r.bShowIt;
52 	bIsDate			=r.bIsDate;
53 	bIsAuthor		=r.bIsAuthor;
54 	bIsComment		=r.bIsComment;
55 	bIsRange		=r.bIsRange;
56 	bEveryoneButMe	=r.bEveryoneButMe;
57 	bShowAccepted	=r.bShowAccepted;
58 	bShowRejected	=r.bShowRejected;
59     mbIsActionRange = r.mbIsActionRange;
60     mnFirstAction   = r.mnFirstAction;
61     mnLastAction    = r.mnLastAction;
62 
63 }
64 
operator =(const ScChangeViewSettings & r)65 ScChangeViewSettings& ScChangeViewSettings::operator=( const ScChangeViewSettings& r )
66 {
67 	SetTheComment(r.aComment);
68 
69 	aFirstDateTime	=r.aFirstDateTime;
70 	aLastDateTime	=r.aLastDateTime;
71 	aAuthorToShow	=r.aAuthorToShow;
72 	aRangeList		=r.aRangeList;
73 	eDateMode		=r.eDateMode;
74 	bShowIt			=r.bShowIt;
75 	bIsDate			=r.bIsDate;
76 	bIsAuthor		=r.bIsAuthor;
77 	bIsComment		=r.bIsComment;
78 	bIsRange		=r.bIsRange;
79 	bEveryoneButMe	=r.bEveryoneButMe;
80 	bShowAccepted	=r.bShowAccepted;
81 	bShowRejected	=r.bShowRejected;
82     mbIsActionRange = r.mbIsActionRange;
83     mnFirstAction   = r.mnFirstAction;
84     mnLastAction    = r.mnLastAction;
85 
86 	return *this;
87 }
88 
IsValidComment(const String * pCommentStr) const89 sal_Bool ScChangeViewSettings::IsValidComment(const String* pCommentStr) const
90 {
91 	sal_Bool nTheFlag=sal_True;
92 
93 	if(pCommentSearcher!=NULL)
94 	{
95 		xub_StrLen nStartPos = 0;
96 		xub_StrLen nEndPos = pCommentStr->Len();
97 
98         nTheFlag=sal::static_int_cast<sal_Bool>(pCommentSearcher->SearchFrwrd( *pCommentStr, &nStartPos, &nEndPos));
99 	}
100 	return nTheFlag;
101 }
102 
SetTheComment(const String & rString)103 void ScChangeViewSettings::SetTheComment(const String& rString)
104 {
105 	aComment=rString;
106 	if(pCommentSearcher!=NULL)
107 	{
108 		delete pCommentSearcher;
109 		pCommentSearcher=NULL;
110 	}
111 
112 	if(rString.Len()>0)
113 	{
114 		utl::SearchParam aSearchParam( rString,
115 			utl::SearchParam::SRCH_REGEXP,sal_False,sal_False,sal_False );
116 
117 		pCommentSearcher = new utl::TextSearch( aSearchParam, *ScGlobal::pCharClass );
118 	}
119 }
120 
AdjustDateMode(const ScDocument & rDoc)121 void ScChangeViewSettings::AdjustDateMode( const ScDocument& rDoc )
122 {
123     switch ( eDateMode )
124     {	// corresponds with ScViewUtil::IsActionShown
125         case SCDM_DATE_EQUAL :
126         case SCDM_DATE_NOTEQUAL :
127             aFirstDateTime.SetTime( 0 );
128             aLastDateTime = aFirstDateTime;
129             aLastDateTime.SetTime( 23595999 );
130             break;
131         case SCDM_DATE_SAVE:
132         {
133             const ScChangeAction* pLast = 0;
134             ScChangeTrack* pTrack = rDoc.GetChangeTrack();
135             if ( pTrack )
136             {
137                 pLast = pTrack->GetLastSaved();
138                 if ( pLast )
139                 {
140                     aFirstDateTime = pLast->GetDateTime();
141 #if 0
142 // This would be the proper handling. But since the SvxTPFilter dialog uses
143 // DateField/TimeField, and the filter dialog is used in ScAcceptChgDlg as the
144 // controlling instance, and the TimeFields are used there without seconds or
145 // 100ths, we'd display some extra entries between the floor of the minute and
146 // the start of the next minute.
147                     // add one 100th second to point past last saved
148                     aFirstDateTime += Time( 0, 0, 0, 1 );
149 #else
150                     // Set the next minute as the start time and assume that
151                     // the document isn't saved, reloaded, edited and filter set
152                     // all together during the gap between those two times.
153                     aFirstDateTime += Time( 0, 1 );
154                     aFirstDateTime.SetSec(0);
155                     aFirstDateTime.Set100Sec(0);
156 #endif
157                 }
158             }
159             if ( !pLast )
160             {
161                 aFirstDateTime.SetDate( 18990101 );
162                 aFirstDateTime.SetTime( 0 );
163             }
164             aLastDateTime = Date();
165             aLastDateTime.SetYear( aLastDateTime.GetYear() + 100 );
166         }
167         break;
168         default:
169         {
170             // added to avoid warnings
171         }
172     }
173 }
174 
175