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