Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : */
10 :
11 : #include <sfx2/dispatch.hxx>
12 : #include <svl/zforlist.hxx>
13 : #include <svl/undo.hxx>
14 :
15 : #include "formulacell.hxx"
16 : #include "rangelst.hxx"
17 : #include "scitems.hxx"
18 : #include "docsh.hxx"
19 : #include "document.hxx"
20 : #include "uiitems.hxx"
21 : #include "reffact.hxx"
22 : #include "scresid.hxx"
23 : #include "docfunc.hxx"
24 : #include "strload.hxx"
25 :
26 : #include "StatisticsInputOutputDialog.hxx"
27 :
28 0 : ScRangeList ScStatisticsInputOutputDialog::MakeColumnRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
29 : {
30 0 : ScRangeList aRangeList;
31 0 : for (SCCOL inCol = aStart.Col(); inCol <= aEnd.Col(); inCol++)
32 : {
33 : ScRange aColumnRange (
34 : ScAddress(inCol, aStart.Row(), aTab),
35 0 : ScAddress(inCol, aEnd.Row(), aTab) );
36 :
37 0 : aRangeList.Append(aColumnRange);
38 : }
39 0 : return aRangeList;
40 : }
41 :
42 0 : ScRangeList ScStatisticsInputOutputDialog::MakeRowRangeList(SCTAB aTab, ScAddress aStart, ScAddress aEnd)
43 : {
44 0 : ScRangeList aRangeList;
45 0 : for (SCROW inRow = aStart.Row(); inRow <= aEnd.Row(); inRow++)
46 : {
47 : ScRange aRowRange (
48 0 : ScAddress(aStart.Col(), inRow, aTab),
49 0 : ScAddress(aEnd.Col(), inRow, aTab) );
50 :
51 0 : aRangeList.Append(aRowRange);
52 : }
53 0 : return aRangeList;
54 : }
55 :
56 0 : ScStatisticsInputOutputDialog::ScStatisticsInputOutputDialog(
57 : SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
58 : vcl::Window* pParent, ScViewData* pViewData, const OString& rID, const OUString& rUIXMLDescription ) :
59 : ScAnyRefDlg ( pSfxBindings, pChildWindow, pParent, rID, rUIXMLDescription ),
60 : mViewData ( pViewData ),
61 0 : mDocument ( pViewData->GetDocument() ),
62 : mAddressDetails ( mDocument->GetAddressConvention(), 0, 0 ),
63 : mGroupedBy ( BY_COLUMN ),
64 : mpActiveEdit ( NULL ),
65 0 : mCurrentAddress ( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo() ),
66 0 : mDialogLostFocus( false )
67 : {
68 0 : get(mpInputRangeLabel, "input-range-label");
69 0 : get(mpInputRangeEdit, "input-range-edit");
70 0 : get(mpInputRangeButton, "input-range-button");
71 0 : mpInputRangeEdit->SetReferences(this, mpInputRangeLabel);
72 0 : mpInputRangeButton->SetReferences(this, mpInputRangeEdit);
73 :
74 0 : get(mpOutputRangeLabel, "output-range-label");
75 0 : get(mpOutputRangeEdit, "output-range-edit");
76 0 : get(mpOutputRangeButton, "output-range-button");
77 0 : mpOutputRangeEdit->SetReferences(this, mpOutputRangeLabel);
78 0 : mpOutputRangeButton->SetReferences(this, mpOutputRangeEdit);
79 :
80 0 : get(mpButtonOk, "ok");
81 :
82 0 : get(mpGroupByColumnsRadio, "groupedby-columns-radio");
83 0 : get(mpGroupByRowsRadio, "groupedby-rows-radio");
84 :
85 0 : Init();
86 0 : GetRangeFromSelection();
87 0 : }
88 :
89 0 : ScStatisticsInputOutputDialog::~ScStatisticsInputOutputDialog()
90 0 : {}
91 :
92 0 : void ScStatisticsInputOutputDialog::Init()
93 : {
94 0 : mpButtonOk->SetClickHdl( LINK( this, ScStatisticsInputOutputDialog, OkClicked ) );
95 0 : mpButtonOk->Enable(false);
96 :
97 0 : Link aLink = LINK( this, ScStatisticsInputOutputDialog, GetFocusHandler );
98 0 : mpInputRangeEdit->SetGetFocusHdl( aLink );
99 0 : mpInputRangeButton->SetGetFocusHdl( aLink );
100 0 : mpOutputRangeEdit->SetGetFocusHdl( aLink );
101 0 : mpOutputRangeButton->SetGetFocusHdl( aLink );
102 :
103 0 : aLink = LINK( this, ScStatisticsInputOutputDialog, LoseFocusHandler );
104 0 : mpInputRangeEdit->SetLoseFocusHdl( aLink );
105 0 : mpInputRangeButton->SetLoseFocusHdl( aLink );
106 0 : mpOutputRangeEdit->SetLoseFocusHdl( aLink );
107 0 : mpOutputRangeButton->SetLoseFocusHdl( aLink );
108 :
109 0 : mpOutputRangeEdit->GrabFocus();
110 :
111 0 : mpGroupByColumnsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
112 0 : mpGroupByRowsRadio->SetToggleHdl( LINK( this, ScStatisticsInputOutputDialog, GroupByChanged ) );
113 :
114 0 : mpGroupByColumnsRadio->Check(true);
115 0 : mpGroupByRowsRadio->Check(false);
116 0 : }
117 :
118 0 : void ScStatisticsInputOutputDialog::GetRangeFromSelection()
119 : {
120 0 : mViewData->GetSimpleArea(mInputRange);
121 0 : OUString aCurrentString(mInputRange.Format(SCR_ABS_3D, mDocument, mAddressDetails));
122 0 : mpInputRangeEdit->SetText(aCurrentString);
123 0 : }
124 :
125 0 : void ScStatisticsInputOutputDialog::SetActive()
126 : {
127 0 : if ( mDialogLostFocus )
128 : {
129 0 : mDialogLostFocus = false;
130 0 : if( mpActiveEdit )
131 0 : mpActiveEdit->GrabFocus();
132 : }
133 : else
134 : {
135 0 : GrabFocus();
136 : }
137 0 : RefInputDone();
138 0 : }
139 :
140 0 : void ScStatisticsInputOutputDialog::SetReference( const ScRange& rReferenceRange, ScDocument* pDocument )
141 : {
142 0 : if ( mpActiveEdit )
143 : {
144 0 : if ( rReferenceRange.aStart != rReferenceRange.aEnd )
145 0 : RefInputStart( mpActiveEdit );
146 :
147 0 : OUString aReferenceString;
148 :
149 0 : if ( mpActiveEdit == mpInputRangeEdit )
150 : {
151 0 : mInputRange = rReferenceRange;
152 0 : aReferenceString = mInputRange.Format(SCR_ABS_3D, pDocument, mAddressDetails);
153 0 : mpInputRangeEdit->SetRefString( aReferenceString );
154 : }
155 0 : else if ( mpActiveEdit == mpOutputRangeEdit )
156 : {
157 0 : mOutputAddress = rReferenceRange.aStart;
158 :
159 0 : sal_uInt16 nFormat = ( mOutputAddress.Tab() == mCurrentAddress.Tab() ) ? SCA_ABS : SCA_ABS_3D;
160 0 : aReferenceString = mOutputAddress.Format(nFormat, pDocument, pDocument->GetAddressConvention());
161 0 : mpOutputRangeEdit->SetRefString( aReferenceString );
162 :
163 : // Enable OK, Cancel if output range is set
164 0 : mpButtonOk->Enable(!mpOutputRangeEdit->GetText().isEmpty());
165 0 : }
166 : }
167 0 : }
168 :
169 0 : IMPL_LINK( ScStatisticsInputOutputDialog, OkClicked, PushButton*, /*pButton*/ )
170 : {
171 0 : CalculateInputAndWriteToOutput();
172 0 : Close();
173 0 : return 0;
174 : }
175 :
176 0 : IMPL_LINK( ScStatisticsInputOutputDialog, GetFocusHandler, Control*, pCtrl )
177 : {
178 0 : mpActiveEdit = NULL;
179 :
180 0 : if( (pCtrl == (Control*) mpInputRangeEdit) || (pCtrl == (Control*) mpInputRangeButton) )
181 0 : mpActiveEdit = mpInputRangeEdit;
182 0 : else if( (pCtrl == (Control*) mpOutputRangeEdit) || (pCtrl == (Control*) mpOutputRangeButton) )
183 0 : mpActiveEdit = mpOutputRangeEdit;
184 :
185 0 : if( mpActiveEdit )
186 0 : mpActiveEdit->SetSelection( Selection( 0, SELECTION_MAX ) );
187 :
188 0 : return 0;
189 : }
190 :
191 0 : IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, LoseFocusHandler )
192 : {
193 0 : mDialogLostFocus = !IsActive();
194 0 : return 0;
195 : }
196 :
197 0 : IMPL_LINK_NOARG( ScStatisticsInputOutputDialog, GroupByChanged )
198 : {
199 0 : if (mpGroupByColumnsRadio->IsChecked())
200 0 : mGroupedBy = BY_COLUMN;
201 0 : else if (mpGroupByRowsRadio->IsChecked())
202 0 : mGroupedBy = BY_ROW;
203 :
204 0 : return 0;
205 : }
206 :
207 0 : void ScStatisticsInputOutputDialog::CalculateInputAndWriteToOutput()
208 : {
209 0 : OUString aUndo(SC_STRLOAD(RID_STATISTICS_DLGS, GetUndoNameId()));
210 0 : ScDocShell* pDocShell = mViewData->GetDocShell();
211 0 : svl::IUndoManager* pUndoManager = pDocShell->GetUndoManager();
212 0 : pUndoManager->EnterListAction( aUndo, aUndo );
213 :
214 0 : ScRange aOutputRange = ApplyOutput(pDocShell);
215 :
216 0 : pUndoManager->LeaveListAction();
217 0 : pDocShell->PostPaint( aOutputRange, PAINT_GRID );
218 228 : }
219 :
220 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|