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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sfx2/dispatch.hxx>
21 :
22 : #include "tabvwsh.hxx"
23 : #include "uiitems.hxx"
24 : #include "dbdata.hxx"
25 : #include "rangenam.hxx"
26 : #include "rangeutl.hxx"
27 : #include "reffact.hxx"
28 : #include "document.hxx"
29 : #include "scresid.hxx"
30 :
31 : #include "globstr.hrc"
32 : #include "consdlg.hrc"
33 :
34 : #define _CONSDLG_CXX
35 : #include "consdlg.hxx"
36 : #undef _CONSDLG_CXX
37 : #include <vcl/msgbox.hxx>
38 :
39 : #define INFOBOX(id) InfoBox(this, ScGlobal::GetRscString(id)).Execute()
40 :
41 : //============================================================================
42 : // class ScAreaData
43 :
44 : class ScAreaData
45 : {
46 : public:
47 0 : ScAreaData() {}
48 0 : ~ScAreaData() {}
49 :
50 0 : void Set( const String& rName, const String& rArea, sal_Bool bDb )
51 : {
52 0 : aStrName = rName;
53 0 : aStrArea = rArea;
54 0 : bIsDbArea = bDb;
55 0 : }
56 :
57 : String aStrName;
58 : String aStrArea;
59 : sal_Bool bIsDbArea;
60 : };
61 :
62 :
63 : //============================================================================
64 : // class ScConsolidateDialog
65 :
66 :
67 0 : ScConsolidateDlg::ScConsolidateDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
68 : const SfxItemSet& rArgSet )
69 :
70 : : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_CONSOLIDATE ),
71 : //
72 : aFtFunc ( this, ScResId( FT_FUNC ) ),
73 : aLbFunc ( this, ScResId( LB_FUNC ) ),
74 :
75 : aFtConsAreas ( this, ScResId( FT_CONSAREAS ) ),
76 : aLbConsAreas ( this, ScResId( LB_CONSAREAS ) ),
77 :
78 : aLbDataArea ( this, ScResId( LB_DATA_AREA ) ),
79 : aFtDataArea ( this, ScResId( FT_DATA_AREA ) ),
80 : aEdDataArea ( this, this, &aFtDataArea, ScResId( ED_DATA_AREA ) ),
81 : aRbDataArea ( this, ScResId( RB_DATA_AREA ), &aEdDataArea, this ),
82 :
83 : aLbDestArea ( this, ScResId( LB_DEST_AREA ) ),
84 : aFtDestArea ( this, ScResId( FT_DEST_AREA ) ),
85 : aEdDestArea ( this, this, &aFtDestArea, ScResId( ED_DEST_AREA ) ),
86 : aRbDestArea ( this, ScResId( RB_DEST_AREA ), &aEdDestArea, this),
87 :
88 : aFlConsBy ( this, ScResId( FL_CONSBY ) ),
89 : aBtnByRow ( this, ScResId( BTN_BYROW ) ),
90 : aBtnByCol ( this, ScResId( BTN_BYCOL) ),
91 :
92 : aFlSep ( this, ScResId( FL_SEP ) ),
93 : aFlOptions ( this, ScResId( FL_OPTIONS ) ),
94 : aBtnRefs ( this, ScResId( BTN_REFS ) ),
95 :
96 : aBtnOk ( this, ScResId( BTN_OK ) ),
97 : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
98 : aBtnHelp ( this, ScResId( BTN_HELP ) ),
99 : aBtnAdd ( this, ScResId( BTN_ADD ) ),
100 : aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
101 : aBtnMore ( this, ScResId( BTN_MORE ) ),
102 :
103 : aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ),
104 : //
105 : theConsData ( ((const ScConsolidateItem&)
106 : rArgSet.Get( rArgSet.GetPool()->
107 0 : GetWhich( SID_CONSOLIDATE ) )
108 0 : ).GetData() ),
109 0 : pViewData ( ((ScTabViewShell*)SfxViewShell::Current())->
110 0 : GetViewData() ),
111 0 : pDoc ( ((ScTabViewShell*)SfxViewShell::Current())->
112 0 : GetViewData()->GetDocument() ),
113 0 : pRangeUtil ( new ScRangeUtil ),
114 : pAreaData ( NULL ),
115 : nAreaDataCount ( 0 ),
116 0 : nWhichCons ( rArgSet.GetPool()->GetWhich( SID_CONSOLIDATE ) ),
117 :
118 0 : pRefInputEdit ( &aEdDataArea )
119 : {
120 0 : Init();
121 0 : FreeResource();
122 0 : }
123 :
124 :
125 : //----------------------------------------------------------------------------
126 :
127 0 : ScConsolidateDlg::~ScConsolidateDlg()
128 : {
129 0 : delete [] pAreaData;
130 0 : delete pRangeUtil;
131 0 : }
132 :
133 :
134 : //----------------------------------------------------------------------------
135 :
136 0 : void ScConsolidateDlg::Init()
137 : {
138 : OSL_ENSURE( pViewData && pDoc && pRangeUtil, "Error in Ctor" );
139 :
140 0 : String aStr;
141 0 : sal_uInt16 i=0;
142 :
143 0 : aEdDataArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
144 0 : aEdDestArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
145 0 : aLbDataArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
146 0 : aLbDestArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
147 0 : aEdDataArea .SetModifyHdl ( LINK( this, ScConsolidateDlg, ModifyHdl ) );
148 0 : aEdDestArea .SetModifyHdl ( LINK( this, ScConsolidateDlg, ModifyHdl ) );
149 0 : aLbConsAreas.SetSelectHdl ( LINK( this, ScConsolidateDlg, SelectHdl ) );
150 0 : aLbDataArea .SetSelectHdl ( LINK( this, ScConsolidateDlg, SelectHdl ) );
151 0 : aLbDestArea .SetSelectHdl ( LINK( this, ScConsolidateDlg, SelectHdl ) );
152 0 : aBtnOk .SetClickHdl ( LINK( this, ScConsolidateDlg, OkHdl ) );
153 0 : aBtnCancel .SetClickHdl ( LINK( this, ScConsolidateDlg, ClickHdl ) );
154 0 : aBtnAdd .SetClickHdl ( LINK( this, ScConsolidateDlg, ClickHdl ) );
155 0 : aBtnRemove .SetClickHdl ( LINK( this, ScConsolidateDlg, ClickHdl ) );
156 :
157 0 : aBtnMore.AddWindow( &aFlConsBy );
158 0 : aBtnMore.AddWindow( &aBtnByRow );
159 0 : aBtnMore.AddWindow( &aBtnByCol );
160 0 : aBtnMore.AddWindow( &aFlSep );
161 0 : aBtnMore.AddWindow( &aFlOptions );
162 0 : aBtnMore.AddWindow( &aBtnRefs );
163 :
164 0 : aBtnAdd.Disable();
165 0 : aBtnRemove.Disable();
166 :
167 0 : aBtnByRow.Check( theConsData.bByRow );
168 0 : aBtnByCol.Check( theConsData.bByCol );
169 0 : aBtnRefs .Check( theConsData.bReferenceData );
170 :
171 0 : aLbFunc.SelectEntryPos( FuncToLbPos( theConsData.eFunction ) );
172 :
173 : // Einlesen der Konsolidierungsbereiche
174 0 : aLbConsAreas.Clear();
175 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
176 0 : for ( i=0; i<theConsData.nDataAreaCount; i++ )
177 : {
178 0 : const ScArea& rArea = *(theConsData.ppDataAreas[i] );
179 0 : if ( rArea.nTab < pDoc->GetTableCount() )
180 : {
181 : ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
182 : rArea.nColEnd, rArea.nRowEnd, rArea.nTab ).Format( aStr,
183 0 : SCR_ABS_3D, pDoc, eConv );
184 0 : aLbConsAreas.InsertEntry( aStr );
185 : }
186 : }
187 :
188 0 : if ( theConsData.nTab < pDoc->GetTableCount() )
189 : {
190 : ScAddress( theConsData.nCol, theConsData.nRow, theConsData.nTab
191 0 : ).Format( aStr, SCA_ABS_3D, pDoc, eConv );
192 0 : aEdDestArea.SetText( aStr );
193 : }
194 : else
195 0 : aEdDestArea.SetText( EMPTY_STRING );
196 :
197 : //----------------------------------------------------------
198 :
199 : /*
200 : * Aus den RangeNames und Datenbankbereichen werden sich
201 : * in der Hilfsklasse ScAreaData die Bereichsnamen gemerkt,
202 : * die in den ListBoxen erscheinen.
203 : */
204 :
205 0 : ScRangeName* pRangeNames = pDoc->GetRangeName();
206 0 : ScDBCollection* pDbNames = pDoc->GetDBCollection();
207 0 : size_t nRangeCount = pRangeNames ? pRangeNames->size() : 0;
208 0 : size_t nDbCount = pDbNames ? pDbNames->getNamedDBs().size() : 0;
209 :
210 0 : nAreaDataCount = nRangeCount+nDbCount;
211 0 : pAreaData = NULL;
212 :
213 0 : if ( nAreaDataCount > 0 )
214 : {
215 0 : pAreaData = new ScAreaData[nAreaDataCount];
216 :
217 0 : String aStrName;
218 0 : String aStrArea;
219 0 : sal_uInt16 nAt = 0;
220 0 : ScRange aRange;
221 0 : ScAreaNameIterator aIter( pDoc );
222 0 : while ( aIter.Next( aStrName, aRange ) )
223 : {
224 0 : aRange.Format( aStrArea, SCA_ABS_3D, pDoc, eConv );
225 0 : pAreaData[nAt++].Set( aStrName, aStrArea, aIter.WasDBName() );
226 0 : }
227 : }
228 :
229 0 : FillAreaLists();
230 0 : ModifyHdl( &aEdDestArea );
231 0 : aLbDataArea.SelectEntryPos( 0 );
232 0 : aEdDataArea.SetText( EMPTY_STRING );
233 0 : aEdDataArea.GrabFocus();
234 :
235 0 : aFlSep.SetStyle( aFlSep.GetStyle() | WB_VERT );
236 :
237 : //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
238 : //SFX_APPWINDOW->Enable();
239 0 : }
240 :
241 :
242 : //----------------------------------------------------------------------------
243 0 : void ScConsolidateDlg::FillAreaLists()
244 : {
245 0 : aLbDataArea.Clear();
246 0 : aLbDestArea.Clear();
247 0 : aLbDataArea.InsertEntry( aStrUndefined );
248 0 : aLbDestArea.InsertEntry( aStrUndefined );
249 :
250 0 : if ( pRangeUtil && pAreaData && (nAreaDataCount > 0) )
251 : {
252 0 : for ( size_t i=0;
253 0 : (i<nAreaDataCount) && (pAreaData[i].aStrName.Len()>0);
254 : i++ )
255 : {
256 0 : aLbDataArea.InsertEntry( pAreaData[i].aStrName, i+1 );
257 :
258 : // if ( !pAreaData[i].bIsDbArea )
259 0 : aLbDestArea.InsertEntry( pAreaData[i].aStrName, i+1 );
260 : }
261 : }
262 0 : }
263 :
264 :
265 : //----------------------------------------------------------------------------
266 : // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
267 : // neue Selektion im Referenz-Fenster angezeigt wird.
268 :
269 :
270 0 : void ScConsolidateDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
271 : {
272 0 : if ( pRefInputEdit )
273 : {
274 0 : if ( rRef.aStart != rRef.aEnd )
275 0 : RefInputStart( pRefInputEdit );
276 :
277 0 : String aStr;
278 0 : sal_uInt16 nFmt = SCR_ABS_3D; //!!! nCurTab fehlt noch
279 0 : const formula::FormulaGrammar::AddressConvention eConv = pDocP->GetAddressConvention();
280 :
281 0 : if ( rRef.aStart.Tab() != rRef.aEnd.Tab() )
282 0 : nFmt |= SCA_TAB2_3D;
283 :
284 0 : if ( pRefInputEdit == &aEdDataArea)
285 0 : rRef.Format( aStr, nFmt, pDocP, eConv );
286 0 : else if ( pRefInputEdit == &aEdDestArea )
287 0 : rRef.aStart.Format( aStr, nFmt, pDocP, eConv );
288 :
289 0 : pRefInputEdit->SetRefString( aStr );
290 : }
291 :
292 0 : ModifyHdl( pRefInputEdit );
293 0 : }
294 :
295 :
296 : //----------------------------------------------------------------------------
297 :
298 0 : sal_Bool ScConsolidateDlg::Close()
299 : {
300 0 : return DoClose( ScConsolidateDlgWrapper::GetChildWindowId() );
301 : }
302 :
303 :
304 : //----------------------------------------------------------------------------
305 :
306 0 : void ScConsolidateDlg::SetActive()
307 : {
308 0 : if ( bDlgLostFocus )
309 : {
310 0 : bDlgLostFocus = false;
311 :
312 0 : if ( pRefInputEdit )
313 : {
314 0 : pRefInputEdit->GrabFocus();
315 0 : ModifyHdl( pRefInputEdit );
316 : }
317 : }
318 : else
319 0 : GrabFocus();
320 :
321 0 : RefInputDone();
322 0 : }
323 :
324 :
325 : //----------------------------------------------------------------------------
326 :
327 0 : void ScConsolidateDlg::Deactivate()
328 : {
329 0 : bDlgLostFocus = sal_True;
330 0 : }
331 :
332 :
333 : //----------------------------------------------------------------------------
334 :
335 0 : sal_Bool ScConsolidateDlg::VerifyEdit( formula::RefEdit* pEd )
336 : {
337 0 : if ( !pRangeUtil || !pDoc || !pViewData ||
338 0 : ((pEd != &aEdDataArea) && (pEd != &aEdDestArea)) )
339 0 : return false;
340 :
341 0 : SCTAB nTab = pViewData->GetTabNo();
342 0 : sal_Bool bEditOk = false;
343 0 : String theCompleteStr;
344 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
345 :
346 0 : if ( pEd == &aEdDataArea )
347 : {
348 0 : bEditOk = pRangeUtil->IsAbsArea( pEd->GetText(), pDoc,
349 0 : nTab, &theCompleteStr, NULL, NULL, eConv );
350 : }
351 0 : else if ( pEd == &aEdDestArea )
352 : {
353 0 : String aPosStr;
354 :
355 0 : pRangeUtil->CutPosString( pEd->GetText(), aPosStr );
356 : bEditOk = pRangeUtil->IsAbsPos( aPosStr, pDoc,
357 0 : nTab, &theCompleteStr, NULL, eConv );
358 : }
359 :
360 0 : if ( bEditOk )
361 0 : pEd->SetText( theCompleteStr );
362 :
363 0 : return bEditOk;
364 : }
365 :
366 :
367 : //----------------------------------------------------------------------------
368 : // Handler:
369 : // ========
370 :
371 0 : IMPL_LINK( ScConsolidateDlg, GetFocusHdl, Control*, pCtr )
372 : {
373 0 : if ( pCtr ==(Control*)&aEdDataArea ||
374 0 : pCtr ==(Control*)&aEdDestArea)
375 : {
376 0 : pRefInputEdit = (formula::RefEdit*)pCtr;
377 : }
378 0 : else if(pCtr ==(Control*)&aLbDataArea )
379 : {
380 0 : pRefInputEdit = &aEdDataArea;
381 : }
382 0 : else if(pCtr ==(Control*)&aLbDestArea )
383 : {
384 0 : pRefInputEdit = &aEdDestArea;
385 : }
386 0 : return 0;
387 : }
388 :
389 :
390 : //----------------------------------------------------------------------------
391 :
392 0 : IMPL_LINK_NOARG(ScConsolidateDlg, OkHdl)
393 : {
394 0 : sal_uInt16 nDataAreaCount = aLbConsAreas.GetEntryCount();
395 :
396 0 : if ( nDataAreaCount > 0 )
397 : {
398 0 : ScRefAddress aDestAddress;
399 0 : SCTAB nTab = pViewData->GetTabNo();
400 0 : String aDestPosStr( aEdDestArea.GetText() );
401 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
402 :
403 0 : if ( pRangeUtil->IsAbsPos( aDestPosStr, pDoc, nTab, NULL, &aDestAddress, eConv ) )
404 : {
405 0 : ScConsolidateParam theOutParam( theConsData );
406 0 : ScArea** ppDataAreas = new ScArea*[nDataAreaCount];
407 : ScArea* pArea;
408 0 : sal_uInt16 i=0;
409 :
410 0 : for ( i=0; i<nDataAreaCount; i++ )
411 : {
412 0 : pArea = new ScArea;
413 0 : pRangeUtil->MakeArea( aLbConsAreas.GetEntry( i ),
414 0 : *pArea, pDoc, nTab, eConv );
415 0 : ppDataAreas[i] = pArea;
416 : }
417 :
418 0 : theOutParam.nCol = aDestAddress.Col();
419 0 : theOutParam.nRow = aDestAddress.Row();
420 0 : theOutParam.nTab = aDestAddress.Tab();
421 0 : theOutParam.eFunction = LbPosToFunc( aLbFunc.GetSelectEntryPos() );
422 0 : theOutParam.bByCol = aBtnByCol.IsChecked();
423 0 : theOutParam.bByRow = aBtnByRow.IsChecked();
424 0 : theOutParam.bReferenceData = aBtnRefs.IsChecked();
425 0 : theOutParam.SetAreas( ppDataAreas, nDataAreaCount );
426 :
427 0 : for ( i=0; i<nDataAreaCount; i++ )
428 0 : delete ppDataAreas[i];
429 0 : delete [] ppDataAreas;
430 :
431 0 : ScConsolidateItem aOutItem( nWhichCons, &theOutParam );
432 :
433 0 : SetDispatcherLock( false );
434 0 : SwitchToDocument();
435 0 : GetBindings().GetDispatcher()->Execute( SID_CONSOLIDATE,
436 : SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
437 0 : &aOutItem, 0L, 0L );
438 0 : Close();
439 : }
440 : else
441 : {
442 0 : INFOBOX( STR_INVALID_TABREF );
443 0 : aEdDestArea.GrabFocus();
444 0 : }
445 : }
446 : else
447 0 : Close(); // keine Datenbereiche definiert -> Cancel
448 0 : return 0;
449 : }
450 :
451 :
452 : //----------------------------------------------------------------------------
453 :
454 0 : IMPL_LINK( ScConsolidateDlg, ClickHdl, PushButton*, pBtn )
455 : {
456 0 : if ( pBtn == &aBtnCancel )
457 0 : Close();
458 0 : else if ( pBtn == &aBtnAdd )
459 : {
460 0 : if ( !aEdDataArea.GetText().isEmpty() )
461 : {
462 0 : String aNewEntry( aEdDataArea.GetText() );
463 0 : ScArea** ppAreas = NULL;
464 0 : sal_uInt16 nAreaCount = 0;
465 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
466 :
467 0 : if ( pRangeUtil->IsAbsTabArea( aNewEntry, pDoc, &ppAreas, &nAreaCount, sal_True, eConv ) )
468 : {
469 : // IsAbsTabArea() legt ein Array von ScArea-Zeigern an,
470 : // welche ebenfalls dynamisch erzeugt wurden.
471 : // Diese Objekte muessen hier abgeraeumt werden.
472 :
473 0 : for ( sal_uInt16 i=0; i<nAreaCount; i++ )
474 : {
475 0 : String aNewArea;
476 :
477 0 : if ( ppAreas[i] )
478 : {
479 0 : const ScArea& rArea = *(ppAreas[i]);
480 : ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
481 : rArea.nColEnd, rArea.nRowEnd, rArea.nTab
482 0 : ).Format( aNewArea, SCR_ABS_3D, pDoc, eConv );
483 :
484 0 : if ( aLbConsAreas.GetEntryPos( aNewArea )
485 : == LISTBOX_ENTRY_NOTFOUND )
486 : {
487 0 : aLbConsAreas.InsertEntry( aNewArea );
488 : }
489 0 : delete ppAreas[i];
490 : }
491 0 : }
492 0 : delete [] ppAreas;
493 : }
494 0 : else if ( VerifyEdit( &aEdDataArea ) )
495 : {
496 0 : String aNewArea( aEdDataArea.GetText() );
497 :
498 0 : if ( aLbConsAreas.GetEntryPos( aNewArea ) == LISTBOX_ENTRY_NOTFOUND )
499 0 : aLbConsAreas.InsertEntry( aNewArea );
500 : else
501 0 : INFOBOX( STR_AREA_ALREADY_INSERTED );
502 : }
503 : else
504 : {
505 0 : INFOBOX( STR_INVALID_TABREF );
506 0 : aEdDataArea.GrabFocus();
507 0 : }
508 : }
509 : }
510 0 : else if ( pBtn == &aBtnRemove )
511 : {
512 0 : while ( aLbConsAreas.GetSelectEntryCount() )
513 0 : aLbConsAreas.RemoveEntry( aLbConsAreas.GetSelectEntryPos() );
514 0 : aBtnRemove.Disable();
515 : }
516 0 : return 0;
517 : }
518 :
519 :
520 : //----------------------------------------------------------------------------
521 :
522 0 : IMPL_LINK( ScConsolidateDlg, SelectHdl, ListBox*, pLb )
523 : {
524 0 : if ( pLb == &aLbConsAreas )
525 : {
526 0 : if ( aLbConsAreas.GetSelectEntryCount() > 0 )
527 0 : aBtnRemove.Enable();
528 : else
529 0 : aBtnRemove.Disable();
530 : }
531 0 : else if ( (pLb == &aLbDataArea) || (pLb == &aLbDestArea) )
532 : {
533 0 : Edit* pEd = (pLb == &aLbDataArea) ? &aEdDataArea : &aEdDestArea;
534 0 : sal_uInt16 nSelPos = pLb->GetSelectEntryPos();
535 :
536 0 : if ( pRangeUtil
537 0 : && (nSelPos > 0)
538 0 : && (nAreaDataCount > 0)
539 0 : && (pAreaData != NULL) )
540 : {
541 0 : if ( static_cast<size_t>(nSelPos) <= nAreaDataCount )
542 : {
543 0 : String aString( pAreaData[nSelPos-1].aStrArea );
544 :
545 0 : if ( pLb == &aLbDestArea )
546 0 : pRangeUtil->CutPosString( aString, aString );
547 :
548 0 : pEd->SetText( aString );
549 :
550 0 : if ( pEd == &aEdDataArea )
551 0 : aBtnAdd.Enable();
552 0 : }
553 : }
554 : else
555 : {
556 0 : pEd->SetText( EMPTY_STRING );
557 0 : if ( pEd == &aEdDataArea )
558 0 : aBtnAdd.Enable();
559 : }
560 : }
561 0 : return 0;
562 : }
563 :
564 :
565 : //----------------------------------------------------------------------------
566 :
567 0 : IMPL_LINK( ScConsolidateDlg, ModifyHdl, formula::RefEdit*, pEd )
568 : {
569 0 : if ( pEd == &aEdDataArea )
570 : {
571 0 : String aAreaStr( pEd->GetText() );
572 0 : if ( aAreaStr.Len() > 0 )
573 : {
574 0 : aBtnAdd.Enable();
575 : }
576 : else
577 0 : aBtnAdd.Disable();
578 : }
579 0 : else if ( pEd == &aEdDestArea )
580 : {
581 0 : aLbDestArea.SelectEntryPos(0);
582 : }
583 0 : return 0;
584 : }
585 :
586 :
587 : //----------------------------------------------------------------------------
588 : // Verallgemeinern!!! :
589 : // Resource der ListBox und diese beiden Umrechnungsmethoden gibt es
590 : // auch noch in tpsubt bzw. ueberall, wo StarCalc-Funktionen
591 : // auswaehlbar sind.
592 :
593 0 : ScSubTotalFunc ScConsolidateDlg::LbPosToFunc( sal_uInt16 nPos )
594 : {
595 0 : switch ( nPos )
596 : {
597 0 : case 2: return SUBTOTAL_FUNC_AVE;
598 0 : case 6: return SUBTOTAL_FUNC_CNT;
599 0 : case 1: return SUBTOTAL_FUNC_CNT2;
600 0 : case 3: return SUBTOTAL_FUNC_MAX;
601 0 : case 4: return SUBTOTAL_FUNC_MIN;
602 0 : case 5: return SUBTOTAL_FUNC_PROD;
603 0 : case 7: return SUBTOTAL_FUNC_STD;
604 0 : case 8: return SUBTOTAL_FUNC_STDP;
605 0 : case 9: return SUBTOTAL_FUNC_VAR;
606 0 : case 10: return SUBTOTAL_FUNC_VARP;
607 : case 0:
608 : default:
609 0 : return SUBTOTAL_FUNC_SUM;
610 : }
611 : }
612 :
613 :
614 : //----------------------------------------------------------------------------
615 :
616 0 : sal_uInt16 ScConsolidateDlg::FuncToLbPos( ScSubTotalFunc eFunc )
617 : {
618 0 : switch ( eFunc )
619 : {
620 0 : case SUBTOTAL_FUNC_AVE: return 2;
621 0 : case SUBTOTAL_FUNC_CNT: return 6;
622 0 : case SUBTOTAL_FUNC_CNT2: return 1;
623 0 : case SUBTOTAL_FUNC_MAX: return 3;
624 0 : case SUBTOTAL_FUNC_MIN: return 4;
625 0 : case SUBTOTAL_FUNC_PROD: return 5;
626 0 : case SUBTOTAL_FUNC_STD: return 7;
627 0 : case SUBTOTAL_FUNC_STDP: return 8;
628 0 : case SUBTOTAL_FUNC_VAR: return 9;
629 0 : case SUBTOTAL_FUNC_VARP: return 10;
630 : case SUBTOTAL_FUNC_NONE:
631 : case SUBTOTAL_FUNC_SUM:
632 : default:
633 0 : return 0;
634 : }
635 93 : }
636 :
637 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|