sync master with lastest vba changes
[ooovba.git] / sc / source / ui / miscdlgs / highred.cxx
blobe4c495a5546ab0db44424597fa240eb82cbd3fea
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: highred.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes ---------------------------------------------------------
38 // INCLUDE -------------------------------------------------------------------
40 #include "global.hxx"
41 #include "reffact.hxx"
42 #include "document.hxx"
43 #include "docsh.hxx"
44 #include "scresid.hxx"
45 #include "globstr.hrc"
46 #include "highred.hrc"
48 #include "highred.hxx"
49 #include <vcl/msgbox.hxx>
50 #include <sfx2/app.hxx>
52 // defines -------------------------------------------------------------------
54 #define ABS_SREF SCA_VALID \
55 | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
56 #define ABS_DREF ABS_SREF \
57 | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
58 #define ABS_SREF3D ABS_SREF | SCA_TAB_3D
59 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
63 #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute();
65 inline void EnableDisable( Window& rWin, BOOL bEnable )
67 if (bEnable)
68 rWin.Enable();
69 else
70 rWin.Disable();
73 //============================================================================
74 // class ScHighlightChgDlg
76 //----------------------------------------------------------------------------
77 ScHighlightChgDlg::ScHighlightChgDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
78 ScViewData* ptrViewData)
80 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_HIGHLIGHT_CHANGES ),
82 aHighlightBox ( this, ScResId( CB_HIGHLIGHT)),
83 aFlFilter ( this, ScResId( FL_FILTER)),
84 aFilterCtr ( this),
85 aCbAccept ( this, ScResId( CB_HIGHLIGHT_ACCEPT)),
86 aCbReject ( this, ScResId( CB_HIGHLIGHT_REJECT)),
87 aOkButton ( this, ScResId( BTN_OK ) ),
88 aCancelButton ( this, ScResId( BTN_CANCEL ) ),
89 aHelpButton ( this, ScResId( BTN_HELP ) ),
90 aEdAssign ( this, this, ScResId( ED_ASSIGN ) ),
91 aRbAssign ( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
93 pViewData ( ptrViewData ),
94 pDoc ( ptrViewData->GetDocument() ),
95 aLocalRangeName ( *(pDoc->GetRangeName()) )
97 FreeResource();
99 Point aFlFilterPt( aFlFilter.GetPosPixel() );
100 aFlFilterPt.Y() += aFlFilter.GetSizePixel().Height();
101 aFilterCtr.SetPosPixel( aFlFilterPt );
102 MinSize=aFilterCtr.GetSizePixel();
103 MinSize.Height()+=2;
104 MinSize.Width()+=2;
105 aOkButton.SetClickHdl(LINK( this, ScHighlightChgDlg, OKBtnHdl));
106 aHighlightBox.SetClickHdl(LINK( this, ScHighlightChgDlg, HighLightHandle ));
107 aFilterCtr.SetRefHdl(LINK( this, ScHighlightChgDlg, RefHandle ));
108 aFilterCtr.HideRange(FALSE);
109 aFilterCtr.Show();
110 SetDispatcherLock( TRUE );
111 //SFX_APPWINDOW->Disable(FALSE);
113 Init();
116 ScHighlightChgDlg::~ScHighlightChgDlg()
118 SetDispatcherLock( FALSE );
119 //SFX_APPWINDOW->Enable();
122 void __EXPORT ScHighlightChgDlg::Init()
124 String aAreaStr;
125 ScRange aRange;
127 DBG_ASSERT( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
129 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
130 if(pChanges!=NULL)
132 aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
133 aFilterCtr.ClearAuthors();
134 ScStrCollection aUserColl=pChanges->GetUserCollection();
135 for(USHORT i=0;i<aUserColl.GetCount();i++)
136 aFilterCtr.InsertAuthor(aUserColl[i]->GetString());
140 ScChangeViewSettings* pViewSettings=pDoc->GetChangeViewSettings();
142 if(pViewSettings!=NULL)
143 aChangeViewSet=*pViewSettings;
144 aHighlightBox.Check(aChangeViewSet.ShowChanges());
145 aFilterCtr.CheckDate(aChangeViewSet.HasDate());
146 aFilterCtr.SetFirstDate(aChangeViewSet.GetTheFirstDateTime());
147 aFilterCtr.SetFirstTime(aChangeViewSet.GetTheFirstDateTime());
148 aFilterCtr.SetLastDate(aChangeViewSet.GetTheLastDateTime());
149 aFilterCtr.SetLastTime(aChangeViewSet.GetTheLastDateTime());
150 aFilterCtr.SetDateMode((USHORT)aChangeViewSet.GetTheDateMode());
151 aFilterCtr.CheckAuthor(aChangeViewSet.HasAuthor());
152 aFilterCtr.CheckComment(aChangeViewSet.HasComment());
153 aFilterCtr.SetComment(aChangeViewSet.GetTheComment());
155 aCbAccept.Check(aChangeViewSet.IsShowAccepted());
156 aCbReject.Check(aChangeViewSet.IsShowRejected());
158 String aString=aChangeViewSet.GetTheAuthorToShow();
159 if(aString.Len()!=0)
161 aFilterCtr.SelectAuthor(aString);
163 else
165 aFilterCtr.SelectedAuthorPos(0);
168 aFilterCtr.CheckRange(aChangeViewSet.HasRange());
169 ScRange* pRangeEntry=aChangeViewSet.GetTheRangeList().GetObject(0);
172 if(pRangeEntry!=NULL)
174 String aRefStr;
175 pRangeEntry->Format( aRefStr, ABS_DREF3D, pDoc );
176 aFilterCtr.SetRange(aRefStr);
178 aFilterCtr.Enable(TRUE,TRUE);
179 HighLightHandle(&aHighlightBox);
182 //----------------------------------------------------------------------------
183 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
184 // neue Selektion im Referenz-Edit angezeigt wird.
186 void ScHighlightChgDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
188 if ( aEdAssign.IsVisible() )
190 if ( rRef.aStart != rRef.aEnd )
191 RefInputStart(&aEdAssign);
192 String aRefStr;
193 rRef.Format( aRefStr, ABS_DREF3D, pDocP, pDocP->GetAddressConvention() );
194 aEdAssign.SetRefString( aRefStr );
195 aFilterCtr.SetRange(aRefStr);
199 //----------------------------------------------------------------------------
200 BOOL __EXPORT ScHighlightChgDlg::Close()
202 return DoClose( ScHighlightChgDlgWrapper::GetChildWindowId() );
205 void ScHighlightChgDlg::RefInputDone( BOOL bForced)
207 ScAnyRefDlg::RefInputDone(bForced);
208 if(bForced || !aRbAssign.IsVisible())
210 aFilterCtr.SetRange(aEdAssign.GetText());
211 aFilterCtr.SetFocusToRange();
212 aEdAssign.Hide();
213 aRbAssign.Hide();
217 void ScHighlightChgDlg::SetActive()
220 if(pTPFilter!=NULL)
222 aAcceptChgCtr.GetFilterPage()->SetFocusToRange();
223 aEdAssign.Hide();
224 aRbAssign.Hide();
225 SFX_APPWINDOW->Enable();
226 SetDispatcherLock( FALSE );
228 //RefInputDone();
232 BOOL ScHighlightChgDlg::IsRefInputMode() const
234 return aEdAssign.IsVisible();
237 IMPL_LINK( ScHighlightChgDlg, HighLightHandle, CheckBox*, pCb )
239 if(pCb!=NULL)
241 if(aHighlightBox.IsChecked())
243 aFilterCtr.Enable(TRUE,TRUE);
244 aCbAccept.Enable();
245 aCbReject.Enable();
247 else
249 aFilterCtr.Disable(TRUE);
250 aCbAccept.Disable();
251 aCbReject.Disable();
254 return 0;
257 IMPL_LINK( ScHighlightChgDlg, RefHandle, SvxTPFilter*, pRef )
259 if(pRef!=NULL)
261 SetDispatcherLock( TRUE );
262 //SFX_APPWINDOW->Disable(FALSE);
263 aEdAssign.Show();
264 aRbAssign.Show();
265 aEdAssign.SetText(aFilterCtr.GetRange());
266 ScAnyRefDlg::RefInputStart(&aEdAssign,&aRbAssign);
268 return 0;
271 IMPL_LINK( ScHighlightChgDlg, OKBtnHdl, PushButton*, pOKBtn )
273 if ( pOKBtn == &aOkButton)
275 aChangeViewSet.SetShowChanges(aHighlightBox.IsChecked());
276 aChangeViewSet.SetHasDate(aFilterCtr.IsDate());
277 ScChgsDateMode eMode = (ScChgsDateMode) aFilterCtr.GetDateMode();
278 aChangeViewSet.SetTheDateMode( eMode );
279 Date aFirstDate( aFilterCtr.GetFirstDate() );
280 Time aFirstTime( aFilterCtr.GetFirstTime() );
281 Date aLastDate( aFilterCtr.GetLastDate() );
282 Time aLastTime( aFilterCtr.GetLastTime() );
283 aChangeViewSet.SetTheFirstDateTime( DateTime( aFirstDate, aFirstTime ) );
284 aChangeViewSet.SetTheLastDateTime( DateTime( aLastDate, aLastTime ) );
285 aChangeViewSet.SetHasAuthor(aFilterCtr.IsAuthor());
286 aChangeViewSet.SetTheAuthorToShow(aFilterCtr.GetSelectedAuthor());
287 aChangeViewSet.SetHasRange(aFilterCtr.IsRange());
288 aChangeViewSet.SetShowAccepted(aCbAccept.IsChecked());
289 aChangeViewSet.SetShowRejected(aCbReject.IsChecked());
290 aChangeViewSet.SetHasComment(aFilterCtr.IsComment());
291 aChangeViewSet.SetTheComment(aFilterCtr.GetComment());
292 ScRangeList aLocalRangeList;
293 aLocalRangeList.Parse(aFilterCtr.GetRange(), pDoc);
294 aChangeViewSet.SetTheRangeList(aLocalRangeList);
295 aChangeViewSet.AdjustDateMode( *pDoc );
296 pDoc->SetChangeViewSettings(aChangeViewSet);
297 pViewData->GetDocShell()->PostPaintGridAll();
298 Close();
300 return 0;