Lines 48-53
Link Here
|
48 |
#include "drawview.hxx" |
48 |
#include "drawview.hxx" |
49 |
#include "globstr.hrc" |
49 |
#include "globstr.hrc" |
50 |
#include <avmedia/mediawindow.hxx> |
50 |
#include <avmedia/mediawindow.hxx> |
|
|
51 |
#include "scmod.hxx" |
52 |
#include "dbcolect.hxx" |
53 |
#include "inputhdl.hxx" |
54 |
#include <editeng/editview.hxx> |
55 |
#include "inputwin.hxx" |
51 |
|
56 |
|
52 |
//------------------------------------------------------------------------ |
57 |
//------------------------------------------------------------------------ |
53 |
|
58 |
|
Lines 131-136
Link Here
|
131 |
pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() ); |
136 |
pDrView->InsertObjectSafe( pObj, *pDrView->GetSdrPageView() ); |
132 |
} |
137 |
} |
133 |
|
138 |
|
|
|
139 |
//------------------------------------------------------------------------ |
134 |
|
140 |
|
|
|
141 |
sal_Bool lcl_UseSubTotal(ScTabViewShell* pViewSh, ScRangeList* pRangeList) |
142 |
{ |
143 |
sal_Bool bSubTotal(sal_False); |
144 |
|
145 |
ScDocument* pDoc = pViewSh->GetViewData()->GetDocument(); |
146 |
sal_Int32 nRangeCount (pRangeList->Count()); |
147 |
sal_Int32 nRangeIndex (0); |
148 |
while (!bSubTotal && nRangeIndex < nRangeCount) |
149 |
{ |
150 |
const ScRange* pRange = pRangeList->GetObject( nRangeIndex ); |
151 |
if( pRange ) |
152 |
{ |
153 |
SCTAB nTabEnd(pRange->aEnd.Tab()); |
154 |
SCTAB nTab(pRange->aStart.Tab()); |
155 |
while (!bSubTotal && nTab <= nTabEnd) |
156 |
{ |
157 |
SCROW nRowEnd(pRange->aEnd.Row()); |
158 |
SCROW nRow(pRange->aStart.Row()); |
159 |
while (!bSubTotal && nRow <= nRowEnd) |
160 |
{ |
161 |
if (pDoc->RowFiltered(nRow, nTab)) |
162 |
bSubTotal = sal_True; |
163 |
else |
164 |
++nRow; |
165 |
} |
166 |
++nTab; |
167 |
} |
168 |
} |
169 |
++nRangeIndex; |
170 |
} |
135 |
|
171 |
|
|
|
172 |
ScDBCollection* pDBCollection = pDoc->GetDBCollection(); |
173 |
sal_uInt16 nDBCount (pDBCollection->GetCount()); |
174 |
sal_uInt16 nDBIndex (0); |
175 |
while (!bSubTotal && nDBIndex < nDBCount) |
176 |
{ |
177 |
ScDBData* pDB = (*pDBCollection)[nDBIndex]; |
178 |
if (pDB && pDB->HasAutoFilter()) |
179 |
{ |
180 |
nRangeIndex = 0; |
181 |
while (!bSubTotal && nRangeIndex < nRangeCount) |
182 |
{ |
183 |
const ScRange* pRange = pRangeList->GetObject( nRangeIndex ); |
184 |
if( pRange ) |
185 |
{ |
186 |
ScRange aDBArea; |
187 |
pDB->GetArea(aDBArea); |
188 |
if (aDBArea.Intersects(*pRange)) |
189 |
bSubTotal = sal_True; |
190 |
} |
191 |
++nRangeIndex; |
192 |
} |
193 |
} |
194 |
++nDBIndex; |
195 |
} |
196 |
|
197 |
return bSubTotal; |
198 |
} |
136 |
|
199 |
|
|
|
200 |
//---------------------------------------------------------------------------- |
201 |
|
202 |
void ScTabViewShell::InputAutoSum( bool bFromInputWindow ) |
203 |
{ |
204 |
const ScMarkData& rMark = GetViewData()->GetMarkData(); |
205 |
if ( rMark.IsMarked() || rMark.IsMultiMarked() ) |
206 |
{ |
207 |
ScRangeList aMarkRangeList; |
208 |
rMark.FillRangeListWithMarks( &aMarkRangeList, sal_False ); |
209 |
ScDocument* pDoc = GetViewData()->GetDocument(); |
210 |
|
211 |
// check if one of the marked ranges is empty |
212 |
bool bEmpty = false; |
213 |
const sal_uLong nCount = aMarkRangeList.Count(); |
214 |
for ( sal_uLong i = 0; i < nCount; ++i ) |
215 |
{ |
216 |
const ScRange aRange( *aMarkRangeList.GetObject( i ) ); |
217 |
if ( pDoc->IsBlockEmpty( aRange.aStart.Tab(), |
218 |
aRange.aStart.Col(), aRange.aStart.Row(), |
219 |
aRange.aEnd.Col(), aRange.aEnd.Row() ) ) |
220 |
{ |
221 |
bEmpty = true; |
222 |
break; |
223 |
} |
224 |
} |
225 |
|
226 |
if ( bEmpty ) |
227 |
{ |
228 |
ScRangeList aRangeList; |
229 |
const sal_Bool bDataFound = GetAutoSumArea( aRangeList ); |
230 |
if ( bDataFound ) |
231 |
{ |
232 |
const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aRangeList ) ); |
233 |
EnterAutoSum( aRangeList, bSubTotal ); // Block mit Summen fuellen |
234 |
} |
235 |
} |
236 |
else |
237 |
{ |
238 |
const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aMarkRangeList ) ); |
239 |
for ( sal_uLong i = 0; i < nCount; ++i ) |
240 |
{ |
241 |
const ScRange aRange( *aMarkRangeList.GetObject( i ) ); |
242 |
const bool bSetCursor = ( i == nCount - 1 ? true : false ); |
243 |
const bool bContinue = ( i != 0 ? true : false ); |
244 |
if ( !AutoSum( aRange, bSubTotal, bSetCursor, bContinue ) ) |
245 |
{ |
246 |
MarkRange( aRange, sal_False, sal_False ); |
247 |
SetCursor( aRange.aEnd.Col(), aRange.aEnd.Row() ); |
248 |
ScInputHandler* pHdl = GetInputHandler(); |
249 |
if ( pHdl ) |
250 |
{ |
251 |
const ScRangeList aRangeList; |
252 |
const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal ); |
253 |
ScInputWindow *pInputWin = pHdl->GetInputWindow(); |
254 |
if ( pInputWin ) |
255 |
pInputWin->SetFuncString( aFormula ); |
256 |
else if ( !bFromInputWindow ) |
257 |
{ |
258 |
ScModule* pScMod = SC_MOD(); |
259 |
if( !pScMod->IsEditMode() ) |
260 |
{ |
261 |
pScMod->SetInputMode( SC_INPUT_TABLE ); |
262 |
pHdl->ClearText(); |
263 |
} |
264 |
pHdl->InsertFunction( aFormula, sal_False ); |
265 |
pHdl->InputSetSelection( |
266 |
aFormula.Search('(') + (bSubTotal ? 3 : 1), |
267 |
aFormula.Len() -1 ); |
268 |
pHdl->DataChanged(); |
269 |
} |
270 |
} |
271 |
break; |
272 |
} |
273 |
} |
274 |
} |
275 |
} |
276 |
else |
277 |
{ |
278 |
ScRangeList aRangeList; |
279 |
const sal_Bool bDataFound = GetAutoSumArea( aRangeList ); |
280 |
const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aRangeList ) ); |
281 |
const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal ); |
282 |
ScModule* pScMod = SC_MOD(); |
283 |
ScInputHandler* pHdl = GetInputHandler(); |
284 |
|
285 |
if ( pHdl ) |
286 |
{ |
287 |
ScInputWindow *pInputWin = pHdl->GetInputWindow(); |
288 |
|
289 |
if ( pInputWin ) |
290 |
{ |
291 |
pInputWin->SetFuncString( aFormula ); |
292 |
|
293 |
if ( pScMod->IsEditMode() ) |
294 |
{ |
295 |
pHdl->InitRangeFinder( aFormula ); |
296 |
|
297 |
//! SetSelection am InputHandler ??? |
298 |
//! bSelIsRef setzen ??? |
299 |
const xub_StrLen nOpen = aFormula.Search('('); |
300 |
const xub_StrLen nLen = aFormula.Len(); |
301 |
if ( nOpen != STRING_NOTFOUND && nLen > nOpen ) |
302 |
{ |
303 |
sal_uInt8 nAdd(1); |
304 |
if (bSubTotal) |
305 |
nAdd = 3; |
306 |
ESelection aSel(0,nOpen+nAdd,0,nLen-1); |
307 |
EditView* pTableView = pHdl->GetTableView(); |
308 |
if (pTableView) |
309 |
pTableView->SetSelection(aSel); |
310 |
EditView* pTopView = pHdl->GetTopView(); |
311 |
if (pTopView) |
312 |
pTopView->SetSelection(aSel); |
313 |
} |
314 |
} |
315 |
} |
316 |
else |
317 |
{ |
318 |
if( !pScMod->IsEditMode() ) |
319 |
{ |
320 |
pScMod->SetInputMode( SC_INPUT_TABLE ); |
321 |
pHdl->ClearText(); |
322 |
} |
323 |
|
324 |
pHdl->InsertFunction( aFormula, sal_False ); |
325 |
pHdl->InputSetSelection( |
326 |
aFormula.Search('(') + (bSubTotal ? 3 : 1), |
327 |
aFormula.Len() -1 ); |
328 |
pHdl->DataChanged(); |
329 |
} |
330 |
} |
331 |
} |
332 |
} |