View | Details | Raw Unified | Return to issue 45563
Collapse All | Expand All

(-)sc/inc/sccommands.h (+1 lines)
Lines 328-332 Link Here
328
#define CMD_FID_TAB_EVENTS                          ".uno:TableEvents"
328
#define CMD_FID_TAB_EVENTS                          ".uno:TableEvents"
329
#define CMD_FID_TAB_MENU_SET_TAB_BG_COLOR           ".uno:SetTabBgColor"
329
#define CMD_FID_TAB_MENU_SET_TAB_BG_COLOR           ".uno:SetTabBgColor"
330
#define CMD_FID_TAB_SET_TAB_BG_COLOR                ".uno:TabBgColor"
330
#define CMD_FID_TAB_SET_TAB_BG_COLOR                ".uno:TabBgColor"
331
#define CMD_SID_INPUT_SUM                           ".uno:AutoSum"
331
332
332
#endif
333
#endif
(-)sc/sdi/tabvwsh.sdi (+2 lines)
Lines 217-222 Link Here
217
    SID_OPT_LOCALE_CHANGED  [ ExecMethod = Execute; ]
217
    SID_OPT_LOCALE_CHANGED  [ ExecMethod = Execute; ]
218
218
219
	SID_READONLY_MODE	[ StateMethod = GetState; ]
219
	SID_READONLY_MODE	[ StateMethod = GetState; ]
220
	
221
	SID_INPUT_SUM		[ ExecMethod = Execute; ]
220
}
222
}
221
223
222
224
(-)sc/sdi/scalc.sdi (+25 lines)
Lines 7822-7824 Link Here
7822
    GroupId = GID_FORMAT;
7822
    GroupId = GID_FORMAT;
7823
]
7823
]
7824
7824
7825
//--------------------------------------------------------------------------
7826
SfxVoidItem AutoSum SID_INPUT_SUM
7827
7828
[
7829
    /* flags: */
7830
    AutoUpdate = FALSE,
7831
    Cachable = Cachable,
7832
    FastCall = FALSE,
7833
    HasCoreId = FALSE,
7834
    HasDialog = FALSE,
7835
    ReadOnlyDoc = FALSE,
7836
    Toggle = FALSE,
7837
    Container = FALSE,
7838
    RecordAbsolute = FALSE,
7839
    RecordPerSet;
7840
    Synchron;
7841
7842
    /* config: */
7843
    AccelConfig = TRUE,
7844
    MenuConfig = TRUE,
7845
    StatusBarConfig = FALSE,
7846
    ToolBoxConfig = FALSE,
7847
    GroupId = GID_EDIT;
7848
]
7849
(-)sc/source/ui/inc/inputwin.hxx (-1 lines)
Lines 192-198 Link Here
192
	virtual void	SetText( const String& rString );
192
	virtual void	SetText( const String& rString );
193
	virtual String	GetText() const;
193
	virtual String	GetText() const;
194
194
195
    sal_Bool        UseSubTotal( ScRangeList* pRangeList ) const;
196
195
197
private:
196
private:
198
	ScPosWnd		aWndPos;
197
	ScPosWnd		aWndPos;
(-)sc/source/ui/inc/tabvwsh.hxx (+2 lines)
Lines 422-427 Link Here
422
422
423
    bool    ExecuteRetypePassDlg(ScPasswordHash eDesiredHash);
423
    bool    ExecuteRetypePassDlg(ScPasswordHash eDesiredHash);
424
424
425
	void 	InputAutoSum( bool bFromInputWindow = false );
426
	
425
    using ScTabView::ShowCursor;
427
    using ScTabView::ShowCursor;
426
};
428
};
427
429
(-)sc/source/ui/view/tabvwshg.cxx (+173 lines)
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
                            EnterData( GetViewData()->GetCurX(), GetViewData()->GetCurY(), 
258
                                    GetViewData()->GetTabNo(), aFormula );
259
                    }
260
                    break;
261
                }
262
            }
263
        }
264
    }
265
    else
266
    {
267
        ScRangeList aRangeList;
268
        const sal_Bool bDataFound = GetAutoSumArea( aRangeList );
269
        const sal_Bool bSubTotal( lcl_UseSubTotal( this, &aRangeList ) );
270
        const String aFormula = GetAutoSumFormula( aRangeList, bSubTotal );
271
        ScInputHandler* pHdl = GetInputHandler();
272
        
273
        if ( pHdl )
274
        {
275
            ScInputWindow *pInputWin = pHdl->GetInputWindow();
276
            if ( pInputWin )
277
                pInputWin->SetFuncString( aFormula );
278
            else if ( !bFromInputWindow )
279
                EnterData( GetViewData()->GetCurX(), GetViewData()->GetCurY(), 
280
                        GetViewData()->GetTabNo(), aFormula );
281
        }
282
        
283
        if ( bDataFound )
284
        {
285
            if ( pHdl && SC_MOD()->IsEditMode() )
286
            {
287
                pHdl->InitRangeFinder( aFormula );
288
                
289
                //! SetSelection am InputHandler ???
290
                //! bSelIsRef setzen ???
291
                const xub_StrLen nOpen = aFormula.Search('(');
292
                const xub_StrLen nLen = aFormula.Len();
293
                if ( nOpen != STRING_NOTFOUND && nLen > nOpen )
294
                {
295
                    sal_uInt8 nAdd(1);
296
                    if (bSubTotal)
297
                        nAdd = 3;
298
                    ESelection aSel(0,nOpen+nAdd,0,nLen-1);
299
                    EditView* pTableView = pHdl->GetTableView();
300
                    if (pTableView)
301
                        pTableView->SetSelection(aSel);
302
                    EditView* pTopView = pHdl->GetTopView();
303
                    if (pTopView)
304
                        pTopView->SetSelection(aSel);
305
                }
306
            }
307
        }
308
    }
309
}
(-)sc/source/ui/view/tabvwsh3.cxx (+5 lines)
Lines 1219-1224 Link Here
1219
				rReq.Done();
1219
				rReq.Done();
1220
			}
1220
			}
1221
            break;
1221
            break;
1222
        
1223
        case SID_INPUT_SUM :
1224
            InputAutoSum();
1225
            rReq.Done();
1226
            break;
1222
1227
1223
		default:
1228
		default:
1224
			DBG_ERROR("Unbekannter Slot bei ScTabViewShell::Execute");
1229
			DBG_ERROR("Unbekannter Slot bei ScTabViewShell::Execute");
(-)sc/source/ui/app/inputwin.cxx (-148 / +1 lines)
Lines 264-330 Link Here
264
	}
264
	}
265
}
265
}
266
266
267
sal_Bool ScInputWindow::UseSubTotal(ScRangeList* pRangeList) const
268
{
269
    sal_Bool bSubTotal(sal_False);
270
    ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
271
    if ( pViewSh )
272
    {
273
        ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
274
        sal_Int32 nRangeCount (pRangeList->Count());
275
        sal_Int32 nRangeIndex (0);
276
        while (!bSubTotal && nRangeIndex < nRangeCount)
277
        {
278
            const ScRange* pRange = pRangeList->GetObject( nRangeIndex );
279
            if( pRange )
280
            {
281
                SCTAB nTabEnd(pRange->aEnd.Tab());
282
                SCTAB nTab(pRange->aStart.Tab());
283
                while (!bSubTotal && nTab <= nTabEnd)
284
                {
285
                    SCROW nRowEnd(pRange->aEnd.Row());
286
                    SCROW nRow(pRange->aStart.Row());
287
                    while (!bSubTotal && nRow <= nRowEnd)
288
                    {
289
                        if (pDoc->RowFiltered(nRow, nTab))
290
                            bSubTotal = sal_True;
291
                        else
292
                            ++nRow;
293
                    }
294
                    ++nTab;
295
                }
296
            }
297
            ++nRangeIndex;
298
        }
299
300
        ScDBCollection* pDBCollection = pDoc->GetDBCollection();
301
        sal_uInt16 nDBCount (pDBCollection->GetCount());
302
        sal_uInt16 nDBIndex (0);
303
        while (!bSubTotal && nDBIndex < nDBCount)
304
        {
305
            ScDBData* pDB = (*pDBCollection)[nDBIndex];
306
            if (pDB && pDB->HasAutoFilter())
307
            {
308
                nRangeIndex = 0;
309
                while (!bSubTotal && nRangeIndex < nRangeCount)
310
                {
311
                    const ScRange* pRange = pRangeList->GetObject( nRangeIndex );
312
                    if( pRange )
313
                    {
314
                        ScRange aDBArea;
315
                        pDB->GetArea(aDBArea);
316
                        if (aDBArea.Intersects(*pRange))
317
                            bSubTotal = sal_True;
318
                    }
319
                    ++nRangeIndex;
320
                }
321
            }
322
            ++nDBIndex;
323
        }
324
    }
325
    return bSubTotal;
326
}
327
328
void __EXPORT ScInputWindow::Select()
267
void __EXPORT ScInputWindow::Select()
329
{
268
{
330
	ScModule* pScMod = SC_MOD();
269
	ScModule* pScMod = SC_MOD();
Lines 364-456 Link Here
364
				ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
303
				ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
365
				if ( pViewSh )
304
				if ( pViewSh )
366
				{
305
				{
367
					const ScMarkData& rMark = pViewSh->GetViewData()->GetMarkData();
306
                    pViewSh->InputAutoSum( true );
368
					if ( rMark.IsMarked() || rMark.IsMultiMarked() )
369
					{
370
                        ScRangeList aMarkRangeList;
371
                        rMark.FillRangeListWithMarks( &aMarkRangeList, sal_False );
372
                        ScDocument* pDoc = pViewSh->GetViewData()->GetDocument();
373
374
                        // check if one of the marked ranges is empty
375
                        bool bEmpty = false;
376
                        const sal_uLong nCount = aMarkRangeList.Count();
377
                        for ( sal_uLong i = 0; i < nCount; ++i )
378
                        {
379
                            const ScRange aRange( *aMarkRangeList.GetObject( i ) );
380
                            if ( pDoc->IsBlockEmpty( aRange.aStart.Tab(),
381
                                    aRange.aStart.Col(), aRange.aStart.Row(),
382
                                    aRange.aEnd.Col(), aRange.aEnd.Row() ) )
383
                            {
384
                                bEmpty = true;
385
                                break;
386
                            }
387
                        }
388
389
                        if ( bEmpty )
390
                        {
391
                            ScRangeList aRangeList;
392
					        const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList );
393
                            if ( bDataFound )
394
                            {
395
                                const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) );
396
                                pViewSh->EnterAutoSum( aRangeList, bSubTotal );	// Block mit Summen fuellen
397
                            }
398
                        }
399
                        else
400
                        {
401
                            const sal_Bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
402
                            for ( sal_uLong i = 0; i < nCount; ++i )
403
                            {
404
                                const ScRange aRange( *aMarkRangeList.GetObject( i ) );
405
                                const bool bSetCursor = ( i == nCount - 1 ? true : false );
406
                                const bool bContinue = ( i != 0  ? true : false );
407
                                if ( !pViewSh->AutoSum( aRange, bSubTotal, bSetCursor, bContinue ) )
408
                                {
409
                                    pViewSh->MarkRange( aRange, sal_False, sal_False );
410
                                    pViewSh->SetCursor( aRange.aEnd.Col(), aRange.aEnd.Row() );
411
                                    const ScRangeList aRangeList;
412
                                    const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal );
413
                                    SetFuncString( aFormula );
414
                                    break;
415
                                }
416
                            }
417
                        }
418
					}
419
					else									// nur in Eingabezeile einfuegen
420
					{
421
                        ScRangeList aRangeList;
422
					    const sal_Bool bDataFound = pViewSh->GetAutoSumArea( aRangeList );
423
                        const sal_Bool bSubTotal( UseSubTotal( &aRangeList ) );
424
                        const String aFormula = pViewSh->GetAutoSumFormula( aRangeList, bSubTotal );
425
						SetFuncString( aFormula );
426
427
                        if ( bDataFound && pScMod->IsEditMode() )
428
						{
429
							ScInputHandler* pHdl = pScMod->GetInputHdl( pViewSh );
430
							if ( pHdl )
431
							{
432
								pHdl->InitRangeFinder( aFormula );
433
434
								//!	SetSelection am InputHandler ???
435
								//!	bSelIsRef setzen ???
436
								const xub_StrLen nOpen = aFormula.Search('(');
437
								const xub_StrLen nLen = aFormula.Len();
438
								if ( nOpen != STRING_NOTFOUND && nLen > nOpen )
439
								{
440
                                    sal_uInt8 nAdd(1);
441
                                    if (bSubTotal)
442
                                        nAdd = 3;
443
									ESelection aSel(0,nOpen+nAdd,0,nLen-1);
444
									EditView* pTableView = pHdl->GetTableView();
445
									if (pTableView)
446
										pTableView->SetSelection(aSel);
447
									EditView* pTopView = pHdl->GetTopView();
448
									if (pTopView)
449
										pTopView->SetSelection(aSel);
450
								}
451
							}
452
						}
453
					}
454
				}
307
				}
455
			}
308
			}
456
			break;
309
			break;
(-)officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu (+8 lines)
Lines 1622-1627 Link Here
1622
                    <value xml:lang="en-US">Assign Macro...</value>
1622
                    <value xml:lang="en-US">Assign Macro...</value>
1623
                </prop>
1623
                </prop>
1624
            </node>
1624
            </node>
1625
            <node oor:name=".uno:AutoSum" oor:op="replace">
1626
				<prop oor:name="Label" oor:type="xs:string">
1627
					<value xml:lang="en-US">Sum</value>
1628
				</prop>
1629
				<prop oor:name="Properties" oor:type="xs:int">
1630
					<value>1</value>
1631
				</prop>
1632
			</node>
1625
        </node>
1633
        </node>
1626
	</node>
1634
	</node>
1627
</oor:component-data>
1635
</oor:component-data>

Return to issue 45563