xref: /aoo4110/main/sc/source/ui/miscdlgs/highred.cxx (revision b1cdbd2c)
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 // System - Includes ---------------------------------------------------------
28 
29 
30 
31 // INCLUDE -------------------------------------------------------------------
32 
33 #include "global.hxx"
34 #include "reffact.hxx"
35 #include "document.hxx"
36 #include "docsh.hxx"
37 #include "scresid.hxx"
38 #include "globstr.hrc"
39 #include "highred.hrc"
40 
41 #include "highred.hxx"
42 #include <vcl/msgbox.hxx>
43 #include <sfx2/app.hxx>
44 
45 // defines -------------------------------------------------------------------
46 
47 #define ABS_SREF		  SCA_VALID \
48 						| SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
49 #define ABS_DREF		  ABS_SREF \
50 						| SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
51 #define ABS_SREF3D		ABS_SREF | SCA_TAB_3D
52 #define ABS_DREF3D		ABS_DREF | SCA_TAB_3D
53 
54 
55 
56 #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute();
57 
EnableDisable(Window & rWin,sal_Bool bEnable)58 inline void EnableDisable( Window& rWin, sal_Bool bEnable )
59 {
60 	if (bEnable)
61 		rWin.Enable();
62 	else
63 		rWin.Disable();
64 }
65 
66 //============================================================================
67 //	class ScHighlightChgDlg
68 
69 //----------------------------------------------------------------------------
ScHighlightChgDlg(SfxBindings * pB,SfxChildWindow * pCW,Window * pParent,ScViewData * ptrViewData)70 ScHighlightChgDlg::ScHighlightChgDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
71 					  ScViewData*		ptrViewData)
72 
73 	:	ScAnyRefDlg	( pB, pCW, pParent, RID_SCDLG_HIGHLIGHT_CHANGES ),
74 		//
75 		aHighlightBox	( this, ScResId( CB_HIGHLIGHT)),
76         aFlFilter       ( this, ScResId( FL_FILTER)),
77 		aFilterCtr		( this),
78 		aCbAccept		( this, ScResId( CB_HIGHLIGHT_ACCEPT)),
79 		aCbReject		( this, ScResId( CB_HIGHLIGHT_REJECT)),
80 		aOkButton		( this, ScResId( BTN_OK ) ),
81 		aCancelButton	( this, ScResId( BTN_CANCEL ) ),
82 		aHelpButton		( this, ScResId( BTN_HELP ) ),
83         aEdAssign       ( this, this, ScResId( ED_ASSIGN ) ),
84 		aRbAssign		( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
85 		//
86 		pViewData		( ptrViewData ),
87 		pDoc			( ptrViewData->GetDocument() ),
88 		aLocalRangeName ( *(pDoc->GetRangeName()) )
89 {
90 	FreeResource();
91 
92     Point aFlFilterPt( aFlFilter.GetPosPixel() );
93     aFlFilterPt.Y() += aFlFilter.GetSizePixel().Height();
94     aFilterCtr.SetPosPixel( aFlFilterPt );
95 	MinSize=aFilterCtr.GetSizePixel();
96 	MinSize.Height()+=2;
97 	MinSize.Width()+=2;
98 	aOkButton.SetClickHdl(LINK( this, ScHighlightChgDlg, OKBtnHdl));
99 	aHighlightBox.SetClickHdl(LINK( this, ScHighlightChgDlg, HighLightHandle ));
100 	aFilterCtr.SetRefHdl(LINK( this, ScHighlightChgDlg, RefHandle ));
101 	aFilterCtr.HideRange(sal_False);
102 	aFilterCtr.Show();
103 	SetDispatcherLock( sal_True );
104 	//SFX_APPWINDOW->Disable(sal_False);
105 
106 	Init();
107 
108 	aFilterCtr.SetAccessibleRelationMemberOf(&aFlFilter);
109 }
110 
~ScHighlightChgDlg()111 ScHighlightChgDlg::~ScHighlightChgDlg()
112 {
113 	SetDispatcherLock( sal_False );
114 	//SFX_APPWINDOW->Enable();
115 }
116 
Init()117 void __EXPORT ScHighlightChgDlg::Init()
118 {
119 	String	aAreaStr;
120 	ScRange aRange;
121 
122 	DBG_ASSERT( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
123 
124 	ScChangeTrack* pChanges=pDoc->GetChangeTrack();
125 	if(pChanges!=NULL)
126 	{
127 		aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
128 		aFilterCtr.ClearAuthors();
129 		ScStrCollection aUserColl=pChanges->GetUserCollection();
130 		for(sal_uInt16	i=0;i<aUserColl.GetCount();i++)
131 			aFilterCtr.InsertAuthor(aUserColl[i]->GetString());
132 	}
133 
134 
135 	ScChangeViewSettings* pViewSettings=pDoc->GetChangeViewSettings();
136 
137 	if(pViewSettings!=NULL)
138 		aChangeViewSet=*pViewSettings;
139 	aHighlightBox.Check(aChangeViewSet.ShowChanges());
140 	aFilterCtr.CheckDate(aChangeViewSet.HasDate());
141 	aFilterCtr.SetFirstDate(aChangeViewSet.GetTheFirstDateTime());
142 	aFilterCtr.SetFirstTime(aChangeViewSet.GetTheFirstDateTime());
143 	aFilterCtr.SetLastDate(aChangeViewSet.GetTheLastDateTime());
144 	aFilterCtr.SetLastTime(aChangeViewSet.GetTheLastDateTime());
145 	aFilterCtr.SetDateMode((sal_uInt16)aChangeViewSet.GetTheDateMode());
146 	aFilterCtr.CheckAuthor(aChangeViewSet.HasAuthor());
147 	aFilterCtr.CheckComment(aChangeViewSet.HasComment());
148 	aFilterCtr.SetComment(aChangeViewSet.GetTheComment());
149 
150 	aCbAccept.Check(aChangeViewSet.IsShowAccepted());
151 	aCbReject.Check(aChangeViewSet.IsShowRejected());
152 
153 	String aString=aChangeViewSet.GetTheAuthorToShow();
154 	if(aString.Len()!=0)
155 	{
156 		aFilterCtr.SelectAuthor(aString);
157 	}
158 	else
159 	{
160 		aFilterCtr.SelectedAuthorPos(0);
161 	}
162 
163 	aFilterCtr.CheckRange(aChangeViewSet.HasRange());
164 	ScRange* pRangeEntry=aChangeViewSet.GetTheRangeList().GetObject(0);
165 
166 
167 	if(pRangeEntry!=NULL)
168 	{
169 		String aRefStr;
170 		pRangeEntry->Format( aRefStr, ABS_DREF3D, pDoc );
171 		aFilterCtr.SetRange(aRefStr);
172 	}
173 	aFilterCtr.Enable(sal_True,sal_True);
174 	HighLightHandle(&aHighlightBox);
175 }
176 
177 //----------------------------------------------------------------------------
178 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
179 // neue Selektion im Referenz-Edit angezeigt wird.
180 
SetReference(const ScRange & rRef,ScDocument * pDocP)181 void ScHighlightChgDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
182 {
183 	if ( aEdAssign.IsVisible() )
184 	{
185 		if ( rRef.aStart != rRef.aEnd )
186 			RefInputStart(&aEdAssign);
187 		String aRefStr;
188         rRef.Format( aRefStr, ABS_DREF3D, pDocP, pDocP->GetAddressConvention() );
189 		aEdAssign.SetRefString( aRefStr );
190 		aFilterCtr.SetRange(aRefStr);
191 	}
192 }
193 
194 //----------------------------------------------------------------------------
Close()195 sal_Bool __EXPORT ScHighlightChgDlg::Close()
196 {
197 	return DoClose( ScHighlightChgDlgWrapper::GetChildWindowId() );
198 }
199 
RefInputDone(sal_Bool bForced)200 void ScHighlightChgDlg::RefInputDone( sal_Bool bForced)
201 {
202 	ScAnyRefDlg::RefInputDone(bForced);
203 	if(bForced || !aRbAssign.IsVisible())
204 	{
205 		aFilterCtr.SetRange(aEdAssign.GetText());
206 		aFilterCtr.SetFocusToRange();
207 		aEdAssign.Hide();
208 		aRbAssign.Hide();
209 	}
210 }
211 
SetActive()212 void ScHighlightChgDlg::SetActive()
213 {
214 	/*
215 	if(pTPFilter!=NULL)
216 	{
217 		aAcceptChgCtr.GetFilterPage()->SetFocusToRange();
218 		aEdAssign.Hide();
219 		aRbAssign.Hide();
220 		SFX_APPWINDOW->Enable();
221 		SetDispatcherLock( sal_False );
222 	}
223 	//RefInputDone();
224 	*/
225 }
226 
IsRefInputMode() const227 sal_Bool ScHighlightChgDlg::IsRefInputMode() const
228 {
229 	return aEdAssign.IsVisible();
230 }
231 
IMPL_LINK(ScHighlightChgDlg,HighLightHandle,CheckBox *,pCb)232 IMPL_LINK( ScHighlightChgDlg, HighLightHandle, CheckBox*, pCb )
233 {
234 	if(pCb!=NULL)
235 	{
236 		if(aHighlightBox.IsChecked())
237 		{
238 			aFilterCtr.Enable(sal_True,sal_True);
239 			aCbAccept.Enable();
240 			aCbReject.Enable();
241 		}
242 		else
243 		{
244 			aFilterCtr.Disable(sal_True);
245 			aCbAccept.Disable();
246 			aCbReject.Disable();
247 		}
248 	}
249 	return 0;
250 }
251 
IMPL_LINK(ScHighlightChgDlg,RefHandle,SvxTPFilter *,pRef)252 IMPL_LINK( ScHighlightChgDlg, RefHandle, SvxTPFilter*, pRef )
253 {
254 	if(pRef!=NULL)
255 	{
256 		SetDispatcherLock( sal_True );
257 		//SFX_APPWINDOW->Disable(sal_False);
258 		aEdAssign.Show();
259 		aRbAssign.Show();
260 		aEdAssign.SetText(aFilterCtr.GetRange());
261 		aEdAssign.GrabFocus();
262 		ScAnyRefDlg::RefInputStart(&aEdAssign,&aRbAssign);
263 	}
264 	return 0;
265 }
266 
IMPL_LINK(ScHighlightChgDlg,OKBtnHdl,PushButton *,pOKBtn)267 IMPL_LINK( ScHighlightChgDlg, OKBtnHdl, PushButton*, pOKBtn )
268 {
269 	if ( pOKBtn == &aOkButton)
270 	{
271 		aChangeViewSet.SetShowChanges(aHighlightBox.IsChecked());
272 		aChangeViewSet.SetHasDate(aFilterCtr.IsDate());
273 		ScChgsDateMode eMode = (ScChgsDateMode) aFilterCtr.GetDateMode();
274 		aChangeViewSet.SetTheDateMode( eMode );
275 		Date aFirstDate( aFilterCtr.GetFirstDate() );
276 		Time aFirstTime( aFilterCtr.GetFirstTime() );
277 		Date aLastDate( aFilterCtr.GetLastDate() );
278 		Time aLastTime( aFilterCtr.GetLastTime() );
279 		aChangeViewSet.SetTheFirstDateTime( DateTime( aFirstDate, aFirstTime ) );
280 		aChangeViewSet.SetTheLastDateTime( DateTime( aLastDate, aLastTime ) );
281 		aChangeViewSet.SetHasAuthor(aFilterCtr.IsAuthor());
282 		aChangeViewSet.SetTheAuthorToShow(aFilterCtr.GetSelectedAuthor());
283 		aChangeViewSet.SetHasRange(aFilterCtr.IsRange());
284 		aChangeViewSet.SetShowAccepted(aCbAccept.IsChecked());
285 		aChangeViewSet.SetShowRejected(aCbReject.IsChecked());
286 		aChangeViewSet.SetHasComment(aFilterCtr.IsComment());
287 		aChangeViewSet.SetTheComment(aFilterCtr.GetComment());
288         ScRangeList aLocalRangeList;
289         aLocalRangeList.Parse(aFilterCtr.GetRange(), pDoc);
290         aChangeViewSet.SetTheRangeList(aLocalRangeList);
291         aChangeViewSet.AdjustDateMode( *pDoc );
292 		pDoc->SetChangeViewSettings(aChangeViewSet);
293 		pViewData->GetDocShell()->PostPaintGridAll();
294 		Close();
295 	}
296 	return 0;
297 }
298 
299 
300 
301