merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / workben / layout / tpsort.cxx
blob949f3b777a71eec8212d6f15c1b8acee4c70c519
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #if !TEST_LAYOUT
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sc.hxx"
31 #endif /* !TEST_LAYOUT */
33 #undef SC_DLLIMPLEMENTATION
37 #include <vcl/msgbox.hxx>
38 #include <i18npool/mslangid.hxx>
39 #include <svtools/collatorres.hxx>
40 #include <unotools/collatorwrapper.hxx>
41 #include <unotools/localedatawrapper.hxx>
42 #include <comphelper/processfactory.hxx>
44 #include "scitems.hxx"
45 #include "uiitems.hxx"
46 #include "viewdata.hxx"
47 #include "document.hxx"
48 #include "global.hxx"
49 #include "dbcolect.hxx"
50 #include "userlist.hxx"
51 #include "rangeutl.hxx"
52 #include "scresid.hxx"
53 #include "sc.hrc" // -> Slot IDs
54 #include "globstr.hrc"
56 #include "sortdlg.hxx"
57 #include "sortdlg.hrc"
59 #define _TPSORT_CXX
60 #include "tpsort.hxx"
61 #undef _TPSORT_CXX
63 using namespace com::sun::star;
65 // STATIC DATA -----------------------------------------------------------
67 static USHORT pSortRanges[] =
69 SID_SORT,
70 SID_SORT,
74 // -----------------------------------------------------------------------
77 * Da sich Einstellungen auf der zweiten TabPage (Optionen) auf
78 * die erste TabPage auswirken, muss es die Moeglichkeit geben,
79 * dies der jeweils anderen Seite mitzuteilen.
81 * Im Moment wird dieses Problem ueber zwei Datenmember des TabDialoges
82 * geloest. Wird eine Seite Aktiviert/Deaktiviert, so gleicht sie diese
83 * Datenmember mit dem eigenen Zustand ab (->Activate()/Deactivate()).
85 * 31.01.95:
86 * Die Klasse SfxTabPage bietet mittlerweile ein Verfahren an:
88 * virtual BOOL HasExchangeSupport() const; -> return TRUE;
89 * virtual void ActivatePage(const SfxItemSet &);
90 * virtual int DeactivatePage(SfxItemSet * = 0);
92 * muss noch geaendert werden!
95 //========================================================================
96 //========================================================================
97 // Sortierkriterien-Tabpage:
99 ScTabPageSortFields::ScTabPageSortFields( Window* pParent,
100 const SfxItemSet& rArgSet )
102 : SfxTabPage ( pParent,
103 ScResId( RID_SCPAGE_SORT_FIELDS ),
104 rArgSet ),
106 aFlSort1 ( this, ScResId( FL_SORT1 ) ),
107 aLbSort1 ( this, ScResId( LB_SORT1 ) ),
108 aBtnUp1 ( this, ScResId( BTN_UP1 ) ),
109 aBtnDown1 ( this, ScResId( BTN_DOWN1 ) ),
111 aFlSort2 ( this, ScResId( FL_SORT2 ) ),
112 aLbSort2 ( this, ScResId( LB_SORT2 ) ),
113 aBtnUp2 ( this, ScResId( BTN_UP2 ) ),
114 aBtnDown2 ( this, ScResId( BTN_DOWN2 ) ),
116 aFlSort3 ( this, ScResId( FL_SORT3 ) ),
117 aLbSort3 ( this, ScResId( LB_SORT3 ) ),
118 aBtnUp3 ( this, ScResId( BTN_UP3 ) ),
119 aBtnDown3 ( this, ScResId( BTN_DOWN3 ) ),
121 aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ),
122 aStrColumn ( ScResId( SCSTR_COLUMN ) ),
123 aStrRow ( ScResId( SCSTR_ROW ) ),
125 #if !TEST_LAYOUT
126 nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ),
127 #else /* TEST_LAYOUT */
128 nWhichSort ( 0 ),
129 #endif /* TEST_LAYOUT */
130 pDlg ( (ScSortDlg*)(GetParent()->GetParent()) ),
131 pViewData ( NULL ),
132 #if !TEST_LAYOUT
133 rSortData ( ((const ScSortItem&)
134 rArgSet.Get( nWhichSort )).
135 GetSortData() ),
136 #else /* TEST_LAYOUT */
137 rSortData ( *new ScSortParam() ),
138 #endif /* TEST_LAYOUT */
139 nFieldCount ( 0 ),
140 bHasHeader ( FALSE ),
141 bSortByRows ( FALSE )
143 Init();
144 FreeResource();
145 SetExchangeSupport();
148 // -----------------------------------------------------------------------
150 __EXPORT ScTabPageSortFields::~ScTabPageSortFields()
154 // -----------------------------------------------------------------------
156 void ScTabPageSortFields::Init()
158 #if !TEST_LAYOUT
159 const ScSortItem& rSortItem = (const ScSortItem&)
160 GetItemSet().Get( nWhichSort );
162 pViewData = rSortItem.GetViewData();
164 DBG_ASSERT( pViewData, "ViewData not found!" );
165 #endif /* !TEST_LAYOUT */
167 nFieldArr[0] = 0;
168 nFirstCol = 0;
169 nFirstRow = 0;
171 aLbSort1.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) );
172 aLbSort2.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) );
173 aLbSort3.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) );
174 aLbSort1.Clear();
175 aLbSort2.Clear();
176 aLbSort3.Clear();
178 aSortLbArr[0] = &aLbSort1;
179 aSortLbArr[1] = &aLbSort2;
180 aSortLbArr[2] = &aLbSort3;
181 aDirBtnArr[0][0] = &aBtnUp1;
182 aDirBtnArr[0][1] = &aBtnDown1;
183 aDirBtnArr[1][0] = &aBtnUp2;
184 aDirBtnArr[1][1] = &aBtnDown2;
185 aDirBtnArr[2][0] = &aBtnUp3;
186 aDirBtnArr[2][1] = &aBtnDown3;
187 aFlArr[0] = &aFlSort1;
188 aFlArr[1] = &aFlSort2;
189 aFlArr[2] = &aFlSort3;
192 //------------------------------------------------------------------------
194 USHORT* __EXPORT ScTabPageSortFields::GetRanges()
196 return pSortRanges;
199 // -----------------------------------------------------------------------
201 SfxTabPage* __EXPORT ScTabPageSortFields::Create( Window* pParent,
202 const SfxItemSet& rArgSet )
204 return ( new ScTabPageSortFields( pParent, rArgSet ) );
207 // -----------------------------------------------------------------------
209 void __EXPORT ScTabPageSortFields::Reset( const SfxItemSet& /* rArgSet */ )
211 bSortByRows = rSortData.bByRow;
212 bHasHeader = rSortData.bHasHeader;
214 if ( aLbSort1.GetEntryCount() == 0 )
215 FillFieldLists();
217 // Selektieren der ListBoxen:
219 if ( rSortData.bDoSort[0] )
221 for ( USHORT i=0; i<3; i++ )
223 if ( rSortData.bDoSort[i] )
225 aSortLbArr[i]->SelectEntryPos(
226 GetFieldSelPos( rSortData.nField[i] ) );
228 (rSortData.bAscending[i])
229 ? aDirBtnArr[i][0]->Check() // Up
230 : aDirBtnArr[i][1]->Check(); // Down
232 else
234 aSortLbArr[i]->SelectEntryPos( 0 ); // "keiner" selektieren
235 aDirBtnArr[i][0]->Check(); // Up
239 EnableField( 1 );
240 EnableField( 2 );
241 EnableField( 3 );
242 if ( aLbSort1.GetSelectEntryPos() == 0 )
243 DisableField( 2 );
244 if ( aLbSort2.GetSelectEntryPos() == 0 )
245 DisableField( 3 );
247 else
249 aLbSort1.SelectEntryPos( 1 );
250 aLbSort2.SelectEntryPos( 0 );
251 aLbSort3.SelectEntryPos( 0 );
252 aBtnUp1.Check();
253 aBtnUp2.Check();
254 aBtnUp3.Check();
255 EnableField ( 1 );
256 EnableField ( 2 );
257 DisableField( 3 );
260 if ( pDlg )
262 pDlg->SetByRows ( bSortByRows );
263 pDlg->SetHeaders( bHasHeader );
267 // -----------------------------------------------------------------------
269 BOOL __EXPORT ScTabPageSortFields::FillItemSet( SfxItemSet& rArgSet )
271 ScSortParam theSortData = rSortData;
272 if (pDlg)
274 const SfxItemSet* pExample = pDlg->GetExampleSet();
275 const SfxPoolItem* pItem;
276 if ( pExample && pExample->GetItemState( nWhichSort, TRUE, &pItem ) == SFX_ITEM_SET )
277 theSortData = ((const ScSortItem*)pItem)->GetSortData();
280 USHORT nSort1Pos = aLbSort1.GetSelectEntryPos();
281 USHORT nSort2Pos = aLbSort2.GetSelectEntryPos();
282 USHORT nSort3Pos = aLbSort3.GetSelectEntryPos();
284 DBG_ASSERT( (nSort1Pos <= SC_MAXFIELDS)
285 && (nSort2Pos <= SC_MAXFIELDS)
286 && (nSort3Pos <= SC_MAXFIELDS),
287 "Array-Range Fehler!" );
289 if ( nSort1Pos == LISTBOX_ENTRY_NOTFOUND ) nSort1Pos = 0;
290 if ( nSort2Pos == LISTBOX_ENTRY_NOTFOUND ) nSort2Pos = 0;
291 if ( nSort3Pos == LISTBOX_ENTRY_NOTFOUND ) nSort3Pos = 0;
293 if ( nSort1Pos > 0 )
295 theSortData.bDoSort[0] = (nSort1Pos > 0);
296 theSortData.bDoSort[1] = (nSort2Pos > 0);
297 theSortData.bDoSort[2] = (nSort3Pos > 0);
299 // wenn auf Optionen-Seite "OK" gewaehlt wurde und
300 // dabei die Sortierrichtung umgestellt wurde, so
301 // wird das erste Feld der jeweiligen Richtung als
302 // Sortierkriterium gewaehlt (steht in nFieldArr[0]):
303 if ( bSortByRows != pDlg->GetByRows() )
305 theSortData.nField[0] =
306 theSortData.nField[1] =
307 theSortData.nField[2] = ( bSortByRows ?
308 static_cast<SCCOLROW>(nFirstRow) :
309 static_cast<SCCOLROW>(nFirstCol) );
311 else
313 theSortData.nField[0] = nFieldArr[nSort1Pos];
314 theSortData.nField[1] = nFieldArr[nSort2Pos];
315 theSortData.nField[2] = nFieldArr[nSort3Pos];
318 theSortData.bAscending[0] = aBtnUp1.IsChecked();
319 theSortData.bAscending[1] = aBtnUp2.IsChecked();
320 theSortData.bAscending[2] = aBtnUp3.IsChecked();
321 // bHasHeader ist in ScTabPageSortOptions::FillItemSet, wo es hingehoert
323 else
325 theSortData.bDoSort[0] =
326 theSortData.bDoSort[1] =
327 theSortData.bDoSort[2] = FALSE;
330 rArgSet.Put( ScSortItem( SCITEM_SORTDATA, NULL, &theSortData ) );
332 return TRUE;
335 // -----------------------------------------------------------------------
337 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
338 // void ScTabPageSortFields::ActivatePage( const SfxItemSet& rSet )
340 void __EXPORT ScTabPageSortFields::ActivatePage()
342 if ( pDlg )
344 if ( bHasHeader != pDlg->GetHeaders()
345 || bSortByRows != pDlg->GetByRows() )
347 USHORT nCurSel1 = aLbSort1.GetSelectEntryPos();
348 USHORT nCurSel2 = aLbSort2.GetSelectEntryPos();
349 USHORT nCurSel3 = aLbSort3.GetSelectEntryPos();
351 bHasHeader = pDlg->GetHeaders();
352 bSortByRows = pDlg->GetByRows();
353 FillFieldLists();
354 aLbSort1.SelectEntryPos( nCurSel1 );
355 aLbSort2.SelectEntryPos( nCurSel2 );
356 aLbSort3.SelectEntryPos( nCurSel3 );
361 // -----------------------------------------------------------------------
363 int __EXPORT ScTabPageSortFields::DeactivatePage( SfxItemSet* pSetP )
365 if ( pDlg )
367 if ( bHasHeader != pDlg->GetHeaders() )
368 pDlg->SetHeaders( bHasHeader );
370 if ( bSortByRows != pDlg->GetByRows() )
371 pDlg->SetByRows( bSortByRows );
374 if ( pSetP )
375 FillItemSet( *pSetP );
377 return SfxTabPage::LEAVE_PAGE;
380 // -----------------------------------------------------------------------
382 void ScTabPageSortFields::DisableField( USHORT nField )
384 nField--;
386 if ( nField<=2 )
388 aSortLbArr[nField] ->Disable();
389 aDirBtnArr[nField][0]->Disable();
390 aDirBtnArr[nField][1]->Disable();
391 aFlArr[nField] ->Disable();
395 // -----------------------------------------------------------------------
397 void ScTabPageSortFields::EnableField( USHORT nField )
399 nField--;
401 if ( nField<=2 )
403 aSortLbArr[nField] ->Enable();
404 aDirBtnArr[nField][0]->Enable();
405 aDirBtnArr[nField][1]->Enable();
406 aFlArr[nField] ->Enable();
410 // -----------------------------------------------------------------------
412 void ScTabPageSortFields::FillFieldLists()
414 if ( pViewData )
416 ScDocument* pDoc = pViewData->GetDocument();
418 if ( pDoc )
420 aLbSort1.Clear();
421 aLbSort2.Clear();
422 aLbSort3.Clear();
423 aLbSort1.InsertEntry( aStrUndefined, 0 );
424 aLbSort2.InsertEntry( aStrUndefined, 0 );
425 aLbSort3.InsertEntry( aStrUndefined, 0 );
427 SCCOL nFirstSortCol = rSortData.nCol1;
428 SCROW nFirstSortRow = rSortData.nRow1;
429 SCTAB nTab = pViewData->GetTabNo();
430 USHORT i = 1;
432 if ( bSortByRows )
434 String aFieldName;
435 SCCOL nMaxCol = rSortData.nCol2;
436 SCCOL col;
438 for ( col=nFirstSortCol; col<=nMaxCol && i<SC_MAXFIELDS; col++ )
440 pDoc->GetString( col, nFirstSortRow, nTab, aFieldName );
441 if ( !bHasHeader || (aFieldName.Len() == 0) )
443 aFieldName = aStrColumn;
444 aFieldName += ' ';
445 aFieldName += ColToAlpha( col );
447 nFieldArr[i] = col;
448 aLbSort1.InsertEntry( aFieldName, i );
449 aLbSort2.InsertEntry( aFieldName, i );
450 aLbSort3.InsertEntry( aFieldName, i );
451 i++;
454 else
456 String aFieldName;
457 SCROW nMaxRow = rSortData.nRow2;
458 SCROW row;
460 for ( row=nFirstSortRow; row<=nMaxRow && i<SC_MAXFIELDS; row++ )
462 pDoc->GetString( nFirstSortCol, row, nTab, aFieldName );
463 if ( !bHasHeader || (aFieldName.Len() == 0) )
465 aFieldName = aStrRow;
466 aFieldName += ' ';
467 aFieldName += String::CreateFromInt32( row+1 );
469 nFieldArr[i] = row;
470 aLbSort1.InsertEntry( aFieldName, i );
471 aLbSort2.InsertEntry( aFieldName, i );
472 aLbSort3.InsertEntry( aFieldName, i );
473 i++;
476 nFieldCount = i;
481 //------------------------------------------------------------------------
483 USHORT ScTabPageSortFields::GetFieldSelPos( SCCOLROW nField )
485 USHORT nFieldPos = 0;
486 BOOL bFound = FALSE;
488 for ( USHORT n=1; n<nFieldCount && !bFound; n++ )
490 if ( nFieldArr[n] == nField )
492 nFieldPos = n;
493 bFound = TRUE;
497 return nFieldPos;
500 // -----------------------------------------------------------------------
501 // Handler:
502 //---------
504 IMPL_LINK( ScTabPageSortFields, SelectHdl, ListBox *, pLb )
506 String aSelEntry = pLb->GetSelectEntry();
508 if ( pLb == &aLbSort1 )
510 if ( aSelEntry == aStrUndefined )
512 aLbSort2.SelectEntryPos( 0 );
513 aLbSort3.SelectEntryPos( 0 );
515 if ( aFlSort2.IsEnabled() )
516 DisableField( 2 );
518 if ( aFlSort3.IsEnabled() )
519 DisableField( 3 );
521 else
523 if ( !aFlSort2.IsEnabled() )
524 EnableField( 2 );
527 else if ( pLb == &aLbSort2 )
529 if ( aSelEntry == aStrUndefined )
531 aLbSort3.SelectEntryPos( 0 );
532 if ( aFlSort3.IsEnabled() )
533 DisableField( 3 );
535 else
537 if ( !aFlSort3.IsEnabled() )
538 EnableField( 3 );
541 return 0;
544 //========================================================================
545 // Sortieroptionen-Tabpage:
546 //========================================================================
548 #include <layout/layout-pre.hxx>
550 #if ENABLE_LAYOUT
551 #undef ScResId
552 #define ScResId(x) #x
553 #undef SfxTabPage
554 #define SfxTabPage( parent, id, args ) SfxTabPage( parent, "sort-options.xml", id, &args )
555 #endif /* ENABLE_LAYOUT */
557 ScTabPageSortOptions::ScTabPageSortOptions( Window* pParent,
558 const SfxItemSet& rArgSet )
560 : SfxTabPage ( pParent,
561 ScResId( RID_SCPAGE_SORT_OPTIONS ),
562 rArgSet ),
564 aBtnCase ( this, ScResId( BTN_CASESENSITIVE ) ),
565 aBtnHeader ( this, ScResId( BTN_LABEL ) ),
566 aBtnFormats ( this, ScResId( BTN_FORMATS ) ),
567 aBtnCopyResult ( this, ScResId( BTN_COPYRESULT ) ),
568 aBtnNaturalSort ( this, ScResId( BTN_NATURALSORT ) ),
569 aLbOutPos ( this, ScResId( LB_OUTAREA ) ),
570 aEdOutPos ( this, ScResId( ED_OUTAREA ) ),
571 aBtnSortUser ( this, ScResId( BTN_SORT_USER ) ),
572 aLbSortUser ( this, ScResId( LB_SORT_USER ) ),
573 aFtLanguage ( this, ScResId( FT_LANGUAGE ) ),
574 aLbLanguage ( this, ScResId( LB_LANGUAGE ) ),
575 aFtAlgorithm ( this, ScResId( FT_ALGORITHM ) ),
576 aLbAlgorithm ( this, ScResId( LB_ALGORITHM ) ),
577 aLineDirection ( this, ScResId( FL_DIRECTION ) ),
578 aBtnTopDown ( this, ScResId( BTN_TOP_DOWN ) ),
579 aBtnLeftRight ( this, ScResId( BTN_LEFT_RIGHT ) ),
580 // aFtAreaLabel ( this, ScResId( FT_AREA_LABEL ) ),
581 // aFtArea ( this, ScResId( FT_AREA ) ),
583 #if ENABLE_LAYOUT
584 #undef this
585 #undef ScResId
586 #define ScResId(x) this, #x
587 #endif /* ENABLE_LAYOUT */
588 aStrRowLabel ( ScResId( STR_ROW_LABEL ) ),
589 aStrColLabel ( ScResId( STR_COL_LABEL ) ),
590 aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ),
591 aStrNoName ( ScGlobal::GetRscString(STR_DB_NONAME) ),
593 #if !TEST_LAYOUT
594 nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ),
595 rSortData ( ((const ScSortItem&)
596 rArgSet.Get( nWhichSort )).GetSortData() ),
597 #else /* TEST_LAYOUT */
598 nWhichSort ( 0 ),
599 rSortData ( *new ScSortParam() ),
600 #endif /* TEST_LAYOUT */
601 pViewData ( NULL ),
602 pDoc ( NULL ),
603 pDlg ( (ScSortDlg*)(GetParent() ? GetParent()->GetParent() : 0 ) ),
604 pColRes ( NULL ),
605 pColWrap ( NULL )
607 #if TEST_LAYOUT
608 (void) rArgSet;
609 #endif /* TEST_LAYOUT */
610 Init();
611 FreeResource();
612 SetExchangeSupport();
615 // -----------------------------------------------------------------------
617 __EXPORT ScTabPageSortOptions::~ScTabPageSortOptions()
619 #if !TEST_LAYOUT
620 USHORT nEntries = aLbOutPos.GetEntryCount();
622 for ( USHORT i=1; i<nEntries; i++ )
623 delete (String*)aLbOutPos.GetEntryData( i );
624 #endif /* !TEST_LAYOUT */
626 delete pColRes;
627 delete pColWrap; //! not if from document
630 // -----------------------------------------------------------------------
632 void ScTabPageSortOptions::Init()
634 // aStrAreaLabel = aFtAreaLabel.GetText();
635 // aStrAreaLabel.Append( (sal_Unicode) ' ' );
637 // CollatorRessource has user-visible names for sort algorithms
638 pColRes = new CollatorRessource();
640 //! use CollatorWrapper from document?
641 pColWrap = new CollatorWrapper( comphelper::getProcessServiceFactory() );
643 #if !TEST_LAYOUT
644 const ScSortItem& rSortItem = (const ScSortItem&)
645 GetItemSet().Get( nWhichSort );
646 #endif /* !TEST_LAYOUT */
648 aLbOutPos.SetSelectHdl ( LINK( this, ScTabPageSortOptions, SelOutPosHdl ) );
649 aBtnCopyResult.SetClickHdl( LINK( this, ScTabPageSortOptions, EnableHdl ) );
650 aBtnSortUser.SetClickHdl ( LINK( this, ScTabPageSortOptions, EnableHdl ) );
651 aBtnTopDown.SetClickHdl ( LINK( this, ScTabPageSortOptions, SortDirHdl ) );
652 aBtnLeftRight.SetClickHdl ( LINK( this, ScTabPageSortOptions, SortDirHdl ) );
653 aLbLanguage.SetSelectHdl ( LINK( this, ScTabPageSortOptions, FillAlgorHdl ) );
655 #if !TEST_LAYOUT
656 pViewData = rSortItem.GetViewData();
657 #endif /* TEST_LAYOUT */
658 pDoc = pViewData ? pViewData->GetDocument() : NULL;
660 DBG_ASSERT( pViewData, "ViewData not found! :-/" );
662 #if !TEST_LAYOUT
663 if ( pViewData && pDoc )
665 String theArea;
666 ScDBCollection* pDBColl = pDoc->GetDBCollection();
667 String theDbArea;
668 String theDbName = aStrNoName;
669 const SCTAB nCurTab = pViewData->GetTabNo();
670 const ScAddress::Convention eConv = pDoc->GetAddressConvention();
671 #endif /* !TEST_LAYOUT */
673 aLbOutPos.Clear();
674 aLbOutPos.InsertEntry( aStrUndefined, 0 );
675 aLbOutPos.Disable();
677 #if !TEST_LAYOUT
678 ScAreaNameIterator aIter( pDoc );
679 String aName;
680 ScRange aRange;
681 String aRefStr;
682 while ( aIter.Next( aName, aRange ) )
684 USHORT nInsert = aLbOutPos.InsertEntry( aName );
686 aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
687 aLbOutPos.SetEntryData( nInsert, new String( aRefStr ) );
689 #endif /* !TEST_LAYOUT */
691 aLbOutPos.SelectEntryPos( 0 );
692 aEdOutPos.SetText( EMPTY_STRING );
694 #if !TEST_LAYOUT
696 * Ueberpruefen, ob es sich bei dem uebergebenen
697 * Bereich um einen Datenbankbereich handelt:
700 ScAddress aScAddress( rSortData.nCol1, rSortData.nRow1, nCurTab );
701 ScRange( aScAddress,
702 ScAddress( rSortData.nCol2, rSortData.nRow2, nCurTab )
703 ).Format( theArea, SCR_ABS, pDoc, eConv );
705 if ( pDBColl )
707 ScDBData* pDBData
708 = pDBColl->GetDBAtArea( nCurTab,
709 rSortData.nCol1, rSortData.nRow1,
710 rSortData.nCol2, rSortData.nRow2 );
711 if ( pDBData )
713 pDBData->GetName( theDbName );
714 aBtnHeader.Check( pDBData->HasHeader() );
718 theArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
719 theArea += theDbName;
720 theArea += ')';
722 //aFtArea.SetText( theArea );
723 //theArea.Insert( aStrAreaLabel, 0 );
724 //aFtAreaLabel.SetText( theArea );
726 aBtnHeader.SetText( aStrColLabel );
728 #endif /* TEST_LAYOUT */
730 FillUserSortListBox();
732 // get available languages
734 aLbLanguage.SetLanguageList( LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN, FALSE );
735 aLbLanguage.InsertLanguage( LANGUAGE_SYSTEM );
738 //------------------------------------------------------------------------
740 USHORT* __EXPORT ScTabPageSortOptions::GetRanges()
742 return pSortRanges;
745 // -----------------------------------------------------------------------
747 #if ENABLE_LAYOUT
748 #undef SfxTabPage
749 #endif /* ENABLE_LAYOUT */
750 SfxTabPage* __EXPORT ScTabPageSortOptions::Create(
751 Window* pParent,
752 const SfxItemSet& rArgSet )
754 return ( new ScTabPageSortOptions( pParent, rArgSet ) );
757 // -----------------------------------------------------------------------
759 void __EXPORT ScTabPageSortOptions::Reset( const SfxItemSet& /* rArgSet */ )
761 if ( rSortData.bUserDef )
763 aBtnSortUser.Check( TRUE );
764 aLbSortUser.Enable();
765 aLbSortUser.SelectEntryPos( rSortData.nUserIndex );
767 else
769 aBtnSortUser.Check( FALSE );
770 aLbSortUser.Disable();
771 aLbSortUser.SelectEntryPos( 0 );
774 aBtnCase.Check ( rSortData.bCaseSens );
775 aBtnFormats.Check ( rSortData.bIncludePattern );
776 aBtnHeader.Check ( rSortData.bHasHeader );
777 aBtnNaturalSort.Check ( rSortData.bNaturalSort );
779 if ( rSortData.bByRow )
781 aBtnTopDown.Check();
782 aBtnHeader.SetText( aStrColLabel );
784 else
786 aBtnLeftRight.Check();
787 aBtnHeader.SetText( aStrRowLabel );
790 LanguageType eLang = MsLangId::convertLocaleToLanguage( rSortData.aCollatorLocale );
791 if ( eLang == LANGUAGE_DONTKNOW )
792 eLang = LANGUAGE_SYSTEM;
793 aLbLanguage.SelectLanguage( eLang );
794 FillAlgorHdl( &aLbLanguage ); // get algorithms, select default
795 if ( rSortData.aCollatorAlgorithm.Len() )
796 aLbAlgorithm.SelectEntry( pColRes->GetTranslation( rSortData.aCollatorAlgorithm ) );
798 if ( pDoc && !rSortData.bInplace )
800 String aStr;
801 USHORT nFormat = (rSortData.nDestTab != pViewData->GetTabNo())
802 ? SCR_ABS_3D
803 : SCR_ABS;
805 theOutPos.Set( rSortData.nDestCol,
806 rSortData.nDestRow,
807 rSortData.nDestTab );
809 theOutPos.Format( aStr, nFormat, pDoc, pDoc->GetAddressConvention() );
810 aBtnCopyResult.Check();
811 aLbOutPos.Enable();
812 aEdOutPos.Enable();
813 aEdOutPos.SetText( aStr );
814 EdOutPosModHdl( &aEdOutPos );
815 aEdOutPos.GrabFocus();
816 aEdOutPos.SetSelection( Selection( 0, SELECTION_MAX ) );
818 else
820 aBtnCopyResult.Check( FALSE );
821 aLbOutPos.Disable();
822 aEdOutPos.Disable();
823 aEdOutPos.SetText( EMPTY_STRING );
827 // -----------------------------------------------------------------------
829 BOOL __EXPORT ScTabPageSortOptions::FillItemSet( SfxItemSet& rArgSet )
831 ScSortParam theSortData = rSortData;
832 if (pDlg)
834 const SfxItemSet* pExample = pDlg->GetExampleSet();
835 const SfxPoolItem* pItem;
836 if ( pExample && pExample->GetItemState( nWhichSort, TRUE, &pItem ) == SFX_ITEM_SET )
837 theSortData = ((const ScSortItem*)pItem)->GetSortData();
840 theSortData.bByRow = aBtnTopDown.IsChecked();
841 theSortData.bHasHeader = aBtnHeader.IsChecked();
842 theSortData.bCaseSens = aBtnCase.IsChecked();
843 theSortData.bNaturalSort = aBtnNaturalSort.IsChecked();
844 theSortData.bIncludePattern = aBtnFormats.IsChecked();
845 theSortData.bInplace = !aBtnCopyResult.IsChecked();
846 theSortData.nDestCol = theOutPos.Col();
847 theSortData.nDestRow = theOutPos.Row();
848 theSortData.nDestTab = theOutPos.Tab();
849 theSortData.bUserDef = aBtnSortUser.IsChecked();
850 theSortData.nUserIndex = (aBtnSortUser.IsChecked())
851 ? aLbSortUser.GetSelectEntryPos()
852 : 0;
854 // get locale
855 LanguageType eLang = aLbLanguage.GetSelectLanguage();
856 theSortData.aCollatorLocale = MsLangId::convertLanguageToLocale( eLang, false );
858 // get algorithm
859 String sAlg;
860 if ( eLang != LANGUAGE_SYSTEM )
862 uno::Sequence<rtl::OUString> aAlgos = pColWrap->listCollatorAlgorithms(
863 theSortData.aCollatorLocale );
864 USHORT nSel = aLbAlgorithm.GetSelectEntryPos();
865 if ( nSel < aAlgos.getLength() )
866 sAlg = aAlgos[nSel];
868 theSortData.aCollatorAlgorithm = sAlg;
870 #if !TEST_LAYOUT
871 rArgSet.Put( ScSortItem( SCITEM_SORTDATA, &theSortData ) );
872 #endif /* TEST_LAYOUT */
873 return TRUE;
876 // -----------------------------------------------------------------------
878 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
879 // void ScTabPageSortOptions::ActivatePage( const SfxItemSet& rSet )
880 void __EXPORT ScTabPageSortOptions::ActivatePage()
882 if ( pDlg )
884 if ( aBtnHeader.IsChecked() != pDlg->GetHeaders() )
886 aBtnHeader.Check( pDlg->GetHeaders() );
889 if ( aBtnTopDown.IsChecked() != pDlg->GetByRows() )
891 aBtnTopDown.Check( pDlg->GetByRows() );
892 aBtnLeftRight.Check( !pDlg->GetByRows() );
895 aBtnHeader.SetText( (pDlg->GetByRows())
896 ? aStrColLabel
897 : aStrRowLabel );
901 // -----------------------------------------------------------------------
903 int __EXPORT ScTabPageSortOptions::DeactivatePage( SfxItemSet* pSetP )
905 BOOL bPosInputOk = TRUE;
907 if ( aBtnCopyResult.IsChecked() )
909 String thePosStr = aEdOutPos.GetText();
910 ScAddress thePos;
911 xub_StrLen nColonPos = thePosStr.Search( ':' );
913 if ( STRING_NOTFOUND != nColonPos )
914 thePosStr.Erase( nColonPos );
916 if ( pViewData )
918 // visible table is default for input without table
919 // must be changed to GetRefTabNo when sorting has RefInput!
920 thePos.SetTab( pViewData->GetTabNo() );
923 USHORT nResult = thePos.Parse( thePosStr, pDoc, pDoc->GetAddressConvention() );
925 bPosInputOk = ( SCA_VALID == (nResult & SCA_VALID) );
927 if ( !bPosInputOk )
929 #if !ENABLE_LAYOUT
930 ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ),
931 ScGlobal::GetRscString( STR_INVALID_TABREF )
932 ).Execute();
933 #endif /* ENABLE_LAYOUT */
934 aEdOutPos.GrabFocus();
935 aEdOutPos.SetSelection( Selection( 0, SELECTION_MAX ) );
936 theOutPos.Set(0,0,0);
938 else
940 aEdOutPos.SetText( thePosStr );
941 theOutPos = thePos;
945 if ( pDlg && bPosInputOk )
947 pDlg->SetHeaders( aBtnHeader.IsChecked() );
948 pDlg->SetByRows ( aBtnTopDown.IsChecked() );
951 if ( pSetP && bPosInputOk )
952 FillItemSet( *pSetP );
954 return bPosInputOk ? SfxTabPage::LEAVE_PAGE : SfxTabPage::KEEP_PAGE;
957 // -----------------------------------------------------------------------
959 void ScTabPageSortOptions::FillUserSortListBox()
961 ScUserList* pUserLists = ScGlobal::GetUserList();
963 aLbSortUser.Clear();
964 if ( pUserLists )
966 USHORT nCount = pUserLists->GetCount();
967 if ( nCount > 0 )
968 for ( USHORT i=0; i<nCount; i++ )
969 aLbSortUser.InsertEntry( (*pUserLists)[i]->GetString() );
973 // -----------------------------------------------------------------------
974 // Handler:
976 IMPL_LINK( ScTabPageSortOptions, EnableHdl, CheckBox *, pBox )
978 if ( pBox == &aBtnCopyResult )
980 if ( pBox->IsChecked() )
982 aLbOutPos.Enable();
983 aEdOutPos.Enable();
984 aEdOutPos.GrabFocus();
986 else
988 aLbOutPos.Disable();
989 aEdOutPos.Disable();
992 else if ( pBox == &aBtnSortUser )
994 if ( pBox->IsChecked() )
996 aLbSortUser.Enable();
997 aLbSortUser.GrabFocus();
999 else
1000 aLbSortUser.Disable();
1002 return 0;
1005 // -----------------------------------------------------------------------
1007 IMPL_LINK( ScTabPageSortOptions, SelOutPosHdl, ListBox *, pLb )
1009 if ( pLb == &aLbOutPos )
1011 String aString;
1012 USHORT nSelPos = aLbOutPos.GetSelectEntryPos();
1014 if ( nSelPos > 0 )
1015 aString = *(String*)aLbOutPos.GetEntryData( nSelPos );
1017 aEdOutPos.SetText( aString );
1019 return 0;
1022 // -----------------------------------------------------------------------
1024 IMPL_LINK( ScTabPageSortOptions, SortDirHdl, RadioButton *, pBtn )
1026 if ( pBtn == &aBtnTopDown )
1028 aBtnHeader.SetText( aStrColLabel );
1030 else if ( pBtn == &aBtnLeftRight )
1032 aBtnHeader.SetText( aStrRowLabel );
1034 return 0;
1037 // -----------------------------------------------------------------------
1039 void __EXPORT ScTabPageSortOptions::EdOutPosModHdl( Edit* pEd )
1041 if ( pEd == &aEdOutPos )
1043 String theCurPosStr = aEdOutPos.GetText();
1044 USHORT nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
1046 if ( SCA_VALID == (nResult & SCA_VALID) )
1048 String* pStr = NULL;
1049 BOOL bFound = FALSE;
1050 USHORT i = 0;
1051 USHORT nCount = aLbOutPos.GetEntryCount();
1053 for ( i=2; i<nCount && !bFound; i++ )
1055 pStr = (String*)aLbOutPos.GetEntryData( i );
1056 bFound = (theCurPosStr == *pStr);
1059 if ( bFound )
1060 aLbOutPos.SelectEntryPos( --i );
1061 else
1062 aLbOutPos.SelectEntryPos( 0 );
1067 // -----------------------------------------------------------------------
1069 IMPL_LINK( ScTabPageSortOptions, FillAlgorHdl, void *, EMPTYARG )
1071 aLbAlgorithm.SetUpdateMode( FALSE );
1072 aLbAlgorithm.Clear();
1074 LanguageType eLang = aLbLanguage.GetSelectLanguage();
1075 if ( eLang == LANGUAGE_SYSTEM )
1077 // for LANGUAGE_SYSTEM no algorithm can be selected because
1078 // it wouldn't necessarily exist for other languages
1079 // -> leave list box empty if LANGUAGE_SYSTEM is selected
1080 aFtAlgorithm.Enable( FALSE ); // nothing to select
1081 aLbAlgorithm.Enable( FALSE ); // nothing to select
1083 else
1085 lang::Locale aLocale( MsLangId::convertLanguageToLocale( eLang ));
1086 uno::Sequence<rtl::OUString> aAlgos = pColWrap->listCollatorAlgorithms( aLocale );
1088 long nCount = aAlgos.getLength();
1089 const rtl::OUString* pArray = aAlgos.getConstArray();
1090 for (long i=0; i<nCount; i++)
1092 String sAlg = pArray[i];
1093 String sUser = pColRes->GetTranslation( sAlg );
1094 aLbAlgorithm.InsertEntry( sUser, LISTBOX_APPEND );
1096 aLbAlgorithm.SelectEntryPos( 0 ); // first entry is default
1097 aFtAlgorithm.Enable( nCount > 1 ); // enable only if there is a choice
1098 aLbAlgorithm.Enable( nCount > 1 ); // enable only if there is a choice
1101 aLbAlgorithm.SetUpdateMode( TRUE );
1102 return 0;