Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / miscdlgs / highred.cxx
blobcec568e8c15a2769d9bcf53b558c4a6949f26826
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "global.hxx"
21 #include "reffact.hxx"
22 #include "document.hxx"
23 #include "docsh.hxx"
24 #include "scresid.hxx"
25 #include "globstr.hrc"
26 #include "highred.hrc"
28 #include "highred.hxx"
29 #include <vcl/msgbox.hxx>
30 #include <sfx2/app.hxx>
32 // defines -------------------------------------------------------------------
34 #define ABS_SREF SCA_VALID \
35 | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
36 #define ABS_DREF ABS_SREF \
37 | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
38 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
40 //============================================================================
41 // class ScHighlightChgDlg
43 //----------------------------------------------------------------------------
44 ScHighlightChgDlg::ScHighlightChgDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
45 ScViewData* ptrViewData)
47 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_HIGHLIGHT_CHANGES ),
49 aHighlightBox ( this, ScResId( CB_HIGHLIGHT)),
50 aFlFilter ( this, ScResId( FL_FILTER)),
51 aFilterCtr ( this),
52 aCbAccept ( this, ScResId( CB_HIGHLIGHT_ACCEPT)),
53 aCbReject ( this, ScResId( CB_HIGHLIGHT_REJECT)),
54 aOkButton ( this, ScResId( BTN_OK ) ),
55 aCancelButton ( this, ScResId( BTN_CANCEL ) ),
56 aHelpButton ( this, ScResId( BTN_HELP ) ),
57 aEdAssign ( this, this, NULL, ScResId( ED_ASSIGN ) ),
58 aRbAssign ( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
60 pViewData ( ptrViewData ),
61 pDoc ( ptrViewData->GetDocument() ),
62 aLocalRangeName ( *(pDoc->GetRangeName()) )
64 FreeResource();
66 Point aFlFilterPt( aFlFilter.GetPosPixel() );
67 aFlFilterPt.Y() += aFlFilter.GetSizePixel().Height();
68 aFilterCtr.SetPosPixel( aFlFilterPt );
69 MinSize=aFilterCtr.GetSizePixel();
70 MinSize.Height()+=2;
71 MinSize.Width()+=2;
72 aOkButton.SetClickHdl(LINK( this, ScHighlightChgDlg, OKBtnHdl));
73 aHighlightBox.SetClickHdl(LINK( this, ScHighlightChgDlg, HighlightHandle ));
74 aFilterCtr.SetRefHdl(LINK( this, ScHighlightChgDlg, RefHandle ));
75 aFilterCtr.HideRange(false);
76 aFilterCtr.Show();
77 SetDispatcherLock( true );
79 Init();
83 ScHighlightChgDlg::~ScHighlightChgDlg()
85 SetDispatcherLock( false );
88 void ScHighlightChgDlg::Init()
90 ScRange aRange;
92 OSL_ENSURE( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
94 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
95 if(pChanges!=NULL)
97 aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
98 aFilterCtr.ClearAuthors();
99 const std::set<OUString>& rUserColl = pChanges->GetUserCollection();
100 std::set<OUString>::const_iterator it = rUserColl.begin(), itEnd = rUserColl.end();
101 for (; it != itEnd; ++it)
102 aFilterCtr.InsertAuthor(*it);
106 ScChangeViewSettings* pViewSettings=pDoc->GetChangeViewSettings();
108 if(pViewSettings!=NULL)
109 aChangeViewSet=*pViewSettings;
110 aHighlightBox.Check(aChangeViewSet.ShowChanges());
111 aFilterCtr.CheckDate(aChangeViewSet.HasDate());
112 aFilterCtr.SetFirstDate(aChangeViewSet.GetTheFirstDateTime());
113 aFilterCtr.SetFirstTime(aChangeViewSet.GetTheFirstDateTime());
114 aFilterCtr.SetLastDate(aChangeViewSet.GetTheLastDateTime());
115 aFilterCtr.SetLastTime(aChangeViewSet.GetTheLastDateTime());
116 aFilterCtr.SetDateMode((sal_uInt16)aChangeViewSet.GetTheDateMode());
117 aFilterCtr.CheckAuthor(aChangeViewSet.HasAuthor());
118 aFilterCtr.CheckComment(aChangeViewSet.HasComment());
119 aFilterCtr.SetComment(aChangeViewSet.GetTheComment());
121 aCbAccept.Check(aChangeViewSet.IsShowAccepted());
122 aCbReject.Check(aChangeViewSet.IsShowRejected());
124 OUString aString=aChangeViewSet.GetTheAuthorToShow();
125 if(!aString.isEmpty())
127 aFilterCtr.SelectAuthor(aString);
129 else
131 aFilterCtr.SelectedAuthorPos(0);
134 aFilterCtr.CheckRange(aChangeViewSet.HasRange());
136 if ( !aChangeViewSet.GetTheRangeList().empty() )
138 const ScRange* pRangeEntry = aChangeViewSet.GetTheRangeList().front();
139 OUString aRefStr(pRangeEntry->Format(ABS_DREF3D, pDoc));
140 aFilterCtr.SetRange(aRefStr);
142 aFilterCtr.Enable(sal_True,sal_True);
143 HighlightHandle(&aHighlightBox);
146 //----------------------------------------------------------------------------
147 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
148 // neue Selektion im Referenz-Edit angezeigt wird.
150 void ScHighlightChgDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
152 if ( aEdAssign.IsVisible() )
154 if ( rRef.aStart != rRef.aEnd )
155 RefInputStart(&aEdAssign);
156 OUString aRefStr(rRef.Format(ABS_DREF3D, pDocP, pDocP->GetAddressConvention()));
157 aEdAssign.SetRefString( aRefStr );
158 aFilterCtr.SetRange(aRefStr);
162 //----------------------------------------------------------------------------
163 sal_Bool ScHighlightChgDlg::Close()
165 return DoClose( ScHighlightChgDlgWrapper::GetChildWindowId() );
168 void ScHighlightChgDlg::RefInputDone( sal_Bool bForced)
170 ScAnyRefDlg::RefInputDone(bForced);
171 if(bForced || !aRbAssign.IsVisible())
173 aFilterCtr.SetRange(aEdAssign.GetText());
174 aFilterCtr.SetFocusToRange();
175 aEdAssign.Hide();
176 aRbAssign.Hide();
180 void ScHighlightChgDlg::SetActive()
184 sal_Bool ScHighlightChgDlg::IsRefInputMode() const
186 return aEdAssign.IsVisible();
189 IMPL_LINK( ScHighlightChgDlg, HighlightHandle, CheckBox*, pCb )
191 if(pCb!=NULL)
193 if(aHighlightBox.IsChecked())
195 aFilterCtr.Enable(sal_True,sal_True);
196 aCbAccept.Enable();
197 aCbReject.Enable();
199 else
201 aFilterCtr.Disable(sal_True);
202 aCbAccept.Disable();
203 aCbReject.Disable();
206 return 0;
209 IMPL_LINK( ScHighlightChgDlg, RefHandle, SvxTPFilter*, pRef )
211 if(pRef!=NULL)
213 SetDispatcherLock( true );
214 aEdAssign.Show();
215 aRbAssign.Show();
216 aEdAssign.SetText(aFilterCtr.GetRange());
217 ScAnyRefDlg::RefInputStart(&aEdAssign,&aRbAssign);
219 return 0;
222 IMPL_LINK( ScHighlightChgDlg, OKBtnHdl, PushButton*, pOKBtn )
224 if ( pOKBtn == &aOkButton)
226 aChangeViewSet.SetShowChanges(aHighlightBox.IsChecked());
227 aChangeViewSet.SetHasDate(aFilterCtr.IsDate());
228 ScChgsDateMode eMode = (ScChgsDateMode) aFilterCtr.GetDateMode();
229 aChangeViewSet.SetTheDateMode( eMode );
230 Date aFirstDate( aFilterCtr.GetFirstDate() );
231 Time aFirstTime( aFilterCtr.GetFirstTime() );
232 Date aLastDate( aFilterCtr.GetLastDate() );
233 Time aLastTime( aFilterCtr.GetLastTime() );
234 aChangeViewSet.SetTheFirstDateTime( DateTime( aFirstDate, aFirstTime ) );
235 aChangeViewSet.SetTheLastDateTime( DateTime( aLastDate, aLastTime ) );
236 aChangeViewSet.SetHasAuthor(aFilterCtr.IsAuthor());
237 aChangeViewSet.SetTheAuthorToShow(aFilterCtr.GetSelectedAuthor());
238 aChangeViewSet.SetHasRange(aFilterCtr.IsRange());
239 aChangeViewSet.SetShowAccepted(aCbAccept.IsChecked());
240 aChangeViewSet.SetShowRejected(aCbReject.IsChecked());
241 aChangeViewSet.SetHasComment(aFilterCtr.IsComment());
242 aChangeViewSet.SetTheComment(aFilterCtr.GetComment());
243 ScRangeList aLocalRangeList;
244 aLocalRangeList.Parse(aFilterCtr.GetRange(), pDoc);
245 aChangeViewSet.SetTheRangeList(aLocalRangeList);
246 aChangeViewSet.AdjustDateMode( *pDoc );
247 pDoc->SetChangeViewSettings(aChangeViewSet);
248 pViewData->GetDocShell()->PostPaintGridAll();
249 Close();
251 return 0;
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */