xref: /aoo41x/main/sc/source/core/tool/chgviset.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 #include <unotools/textsearch.hxx>
34 
35 #include "chgviset.hxx"
36 #include "rechead.hxx"
37 #include "chgtrack.hxx"
38 
39 // -----------------------------------------------------------------------
40 ScChangeViewSettings::~ScChangeViewSettings()
41 {
42 	if(pCommentSearcher!=NULL)
43 		delete pCommentSearcher;
44 }
45 
46 ScChangeViewSettings::ScChangeViewSettings( const ScChangeViewSettings& r )
47 {
48 	SetTheComment(r.aComment);
49 
50 	aFirstDateTime	=r.aFirstDateTime;
51 	aLastDateTime	=r.aLastDateTime;
52 	aAuthorToShow	=r.aAuthorToShow;
53 	aRangeList		=r.aRangeList;
54 	eDateMode		=r.eDateMode;
55 	bShowIt			=r.bShowIt;
56 	bIsDate			=r.bIsDate;
57 	bIsAuthor		=r.bIsAuthor;
58 	bIsComment		=r.bIsComment;
59 	bIsRange		=r.bIsRange;
60 	bEveryoneButMe	=r.bEveryoneButMe;
61 	bShowAccepted	=r.bShowAccepted;
62 	bShowRejected	=r.bShowRejected;
63     mbIsActionRange = r.mbIsActionRange;
64     mnFirstAction   = r.mnFirstAction;
65     mnLastAction    = r.mnLastAction;
66 
67 }
68 
69 ScChangeViewSettings& ScChangeViewSettings::operator=( const ScChangeViewSettings& r )
70 {
71 	SetTheComment(r.aComment);
72 
73 	aFirstDateTime	=r.aFirstDateTime;
74 	aLastDateTime	=r.aLastDateTime;
75 	aAuthorToShow	=r.aAuthorToShow;
76 	aRangeList		=r.aRangeList;
77 	eDateMode		=r.eDateMode;
78 	bShowIt			=r.bShowIt;
79 	bIsDate			=r.bIsDate;
80 	bIsAuthor		=r.bIsAuthor;
81 	bIsComment		=r.bIsComment;
82 	bIsRange		=r.bIsRange;
83 	bEveryoneButMe	=r.bEveryoneButMe;
84 	bShowAccepted	=r.bShowAccepted;
85 	bShowRejected	=r.bShowRejected;
86     mbIsActionRange = r.mbIsActionRange;
87     mnFirstAction   = r.mnFirstAction;
88     mnLastAction    = r.mnLastAction;
89 
90 	return *this;
91 }
92 
93 sal_Bool ScChangeViewSettings::IsValidComment(const String* pCommentStr) const
94 {
95 	sal_Bool nTheFlag=sal_True;
96 
97 	if(pCommentSearcher!=NULL)
98 	{
99 		xub_StrLen nStartPos = 0;
100 		xub_StrLen nEndPos = pCommentStr->Len();
101 
102         nTheFlag=sal::static_int_cast<sal_Bool>(pCommentSearcher->SearchFrwrd( *pCommentStr, &nStartPos, &nEndPos));
103 	}
104 	return nTheFlag;
105 }
106 
107 void ScChangeViewSettings::SetTheComment(const String& rString)
108 {
109 	aComment=rString;
110 	if(pCommentSearcher!=NULL)
111 	{
112 		delete pCommentSearcher;
113 		pCommentSearcher=NULL;
114 	}
115 
116 	if(rString.Len()>0)
117 	{
118 		utl::SearchParam aSearchParam( rString,
119 			utl::SearchParam::SRCH_REGEXP,sal_False,sal_False,sal_False );
120 
121 		pCommentSearcher = new utl::TextSearch( aSearchParam, *ScGlobal::pCharClass );
122 	}
123 }
124 
125 void ScChangeViewSettings::AdjustDateMode( const ScDocument& rDoc )
126 {
127     switch ( eDateMode )
128     {	// corresponds with ScViewUtil::IsActionShown
129         case SCDM_DATE_EQUAL :
130         case SCDM_DATE_NOTEQUAL :
131             aFirstDateTime.SetTime( 0 );
132             aLastDateTime = aFirstDateTime;
133             aLastDateTime.SetTime( 23595999 );
134             break;
135         case SCDM_DATE_SAVE:
136         {
137             const ScChangeAction* pLast = 0;
138             ScChangeTrack* pTrack = rDoc.GetChangeTrack();
139             if ( pTrack )
140             {
141                 pLast = pTrack->GetLastSaved();
142                 if ( pLast )
143                 {
144                     aFirstDateTime = pLast->GetDateTime();
145 #if 0
146 // This would be the proper handling. But since the SvxTPFilter dialog uses
147 // DateField/TimeField, and the filter dialog is used in ScAcceptChgDlg as the
148 // controlling instance, and the TimeFields are used there without seconds or
149 // 100ths, we'd display some extra entries between the floor of the minute and
150 // the start of the next minute.
151                     // add one 100th second to point past last saved
152                     aFirstDateTime += Time( 0, 0, 0, 1 );
153 #else
154                     // Set the next minute as the start time and assume that
155                     // the document isn't saved, reloaded, edited and filter set
156                     // all together during the gap between those two times.
157                     aFirstDateTime += Time( 0, 1 );
158                     aFirstDateTime.SetSec(0);
159                     aFirstDateTime.Set100Sec(0);
160 #endif
161                 }
162             }
163             if ( !pLast )
164             {
165                 aFirstDateTime.SetDate( 18990101 );
166                 aFirstDateTime.SetTime( 0 );
167             }
168             aLastDateTime = Date();
169             aLastDateTime.SetYear( aLastDateTime.GetYear() + 100 );
170         }
171         break;
172         default:
173         {
174             // added to avoid warnings
175         }
176     }
177 }
178 
179