1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tpsort.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sc.hxx"
34 #endif /* !TEST_LAYOUT */
36 #undef SC_DLLIMPLEMENTATION
40 #include <vcl/msgbox.hxx>
41 #include <i18npool/mslangid.hxx>
42 #include <svtools/collatorres.hxx>
43 #include <unotools/collatorwrapper.hxx>
44 #include <unotools/localedatawrapper.hxx>
45 #include <comphelper/processfactory.hxx>
47 #include "scitems.hxx"
48 #include "uiitems.hxx"
49 #include "viewdata.hxx"
50 #include "document.hxx"
52 #include "dbcolect.hxx"
53 #include "userlist.hxx"
54 #include "rangeutl.hxx"
55 #include "scresid.hxx"
56 #include "sc.hrc" // -> Slot IDs
57 #include "globstr.hrc"
59 #include "sortdlg.hxx"
60 #include "sortdlg.hrc"
66 using namespace com::sun::star
;
68 // STATIC DATA -----------------------------------------------------------
70 static USHORT pSortRanges
[] =
77 // -----------------------------------------------------------------------
80 * Da sich Einstellungen auf der zweiten TabPage (Optionen) auf
81 * die erste TabPage auswirken, muss es die Moeglichkeit geben,
82 * dies der jeweils anderen Seite mitzuteilen.
84 * Im Moment wird dieses Problem ueber zwei Datenmember des TabDialoges
85 * geloest. Wird eine Seite Aktiviert/Deaktiviert, so gleicht sie diese
86 * Datenmember mit dem eigenen Zustand ab (->Activate()/Deactivate()).
89 * Die Klasse SfxTabPage bietet mittlerweile ein Verfahren an:
91 * virtual BOOL HasExchangeSupport() const; -> return TRUE;
92 * virtual void ActivatePage(const SfxItemSet &);
93 * virtual int DeactivatePage(SfxItemSet * = 0);
95 * muss noch geaendert werden!
98 //========================================================================
99 //========================================================================
100 // Sortierkriterien-Tabpage:
102 ScTabPageSortFields::ScTabPageSortFields( Window
* pParent
,
103 const SfxItemSet
& rArgSet
)
105 : SfxTabPage ( pParent
,
106 ScResId( RID_SCPAGE_SORT_FIELDS
),
109 aFlSort1 ( this, ScResId( FL_SORT1
) ),
110 aLbSort1 ( this, ScResId( LB_SORT1
) ),
111 aBtnUp1 ( this, ScResId( BTN_UP1
) ),
112 aBtnDown1 ( this, ScResId( BTN_DOWN1
) ),
114 aFlSort2 ( this, ScResId( FL_SORT2
) ),
115 aLbSort2 ( this, ScResId( LB_SORT2
) ),
116 aBtnUp2 ( this, ScResId( BTN_UP2
) ),
117 aBtnDown2 ( this, ScResId( BTN_DOWN2
) ),
119 aFlSort3 ( this, ScResId( FL_SORT3
) ),
120 aLbSort3 ( this, ScResId( LB_SORT3
) ),
121 aBtnUp3 ( this, ScResId( BTN_UP3
) ),
122 aBtnDown3 ( this, ScResId( BTN_DOWN3
) ),
124 aStrUndefined ( ScResId( SCSTR_UNDEFINED
) ),
125 aStrColumn ( ScResId( SCSTR_COLUMN
) ),
126 aStrRow ( ScResId( SCSTR_ROW
) ),
129 nWhichSort ( rArgSet
.GetPool()->GetWhich( SID_SORT
) ),
130 #else /* TEST_LAYOUT */
132 #endif /* TEST_LAYOUT */
133 pDlg ( (ScSortDlg
*)(GetParent()->GetParent()) ),
136 rSortData ( ((const ScSortItem
&)
137 rArgSet
.Get( nWhichSort
)).
139 #else /* TEST_LAYOUT */
140 rSortData ( *new ScSortParam() ),
141 #endif /* TEST_LAYOUT */
143 bHasHeader ( FALSE
),
144 bSortByRows ( FALSE
)
148 SetExchangeSupport();
151 // -----------------------------------------------------------------------
153 __EXPORT
ScTabPageSortFields::~ScTabPageSortFields()
157 // -----------------------------------------------------------------------
159 void ScTabPageSortFields::Init()
162 const ScSortItem
& rSortItem
= (const ScSortItem
&)
163 GetItemSet().Get( nWhichSort
);
165 pViewData
= rSortItem
.GetViewData();
167 DBG_ASSERT( pViewData
, "ViewData not found!" );
168 #endif /* !TEST_LAYOUT */
174 aLbSort1
.SetSelectHdl( LINK( this, ScTabPageSortFields
, SelectHdl
) );
175 aLbSort2
.SetSelectHdl( LINK( this, ScTabPageSortFields
, SelectHdl
) );
176 aLbSort3
.SetSelectHdl( LINK( this, ScTabPageSortFields
, SelectHdl
) );
181 aSortLbArr
[0] = &aLbSort1
;
182 aSortLbArr
[1] = &aLbSort2
;
183 aSortLbArr
[2] = &aLbSort3
;
184 aDirBtnArr
[0][0] = &aBtnUp1
;
185 aDirBtnArr
[0][1] = &aBtnDown1
;
186 aDirBtnArr
[1][0] = &aBtnUp2
;
187 aDirBtnArr
[1][1] = &aBtnDown2
;
188 aDirBtnArr
[2][0] = &aBtnUp3
;
189 aDirBtnArr
[2][1] = &aBtnDown3
;
190 aFlArr
[0] = &aFlSort1
;
191 aFlArr
[1] = &aFlSort2
;
192 aFlArr
[2] = &aFlSort3
;
195 //------------------------------------------------------------------------
197 USHORT
* __EXPORT
ScTabPageSortFields::GetRanges()
202 // -----------------------------------------------------------------------
204 SfxTabPage
* __EXPORT
ScTabPageSortFields::Create( Window
* pParent
,
205 const SfxItemSet
& rArgSet
)
207 return ( new ScTabPageSortFields( pParent
, rArgSet
) );
210 // -----------------------------------------------------------------------
212 void __EXPORT
ScTabPageSortFields::Reset( const SfxItemSet
& /* rArgSet */ )
214 bSortByRows
= rSortData
.bByRow
;
215 bHasHeader
= rSortData
.bHasHeader
;
217 if ( aLbSort1
.GetEntryCount() == 0 )
220 // Selektieren der ListBoxen:
222 if ( rSortData
.bDoSort
[0] )
224 for ( USHORT i
=0; i
<3; i
++ )
226 if ( rSortData
.bDoSort
[i
] )
228 aSortLbArr
[i
]->SelectEntryPos(
229 GetFieldSelPos( rSortData
.nField
[i
] ) );
231 (rSortData
.bAscending
[i
])
232 ? aDirBtnArr
[i
][0]->Check() // Up
233 : aDirBtnArr
[i
][1]->Check(); // Down
237 aSortLbArr
[i
]->SelectEntryPos( 0 ); // "keiner" selektieren
238 aDirBtnArr
[i
][0]->Check(); // Up
245 if ( aLbSort1
.GetSelectEntryPos() == 0 )
247 if ( aLbSort2
.GetSelectEntryPos() == 0 )
252 aLbSort1
.SelectEntryPos( 1 );
253 aLbSort2
.SelectEntryPos( 0 );
254 aLbSort3
.SelectEntryPos( 0 );
265 pDlg
->SetByRows ( bSortByRows
);
266 pDlg
->SetHeaders( bHasHeader
);
270 // -----------------------------------------------------------------------
272 BOOL __EXPORT
ScTabPageSortFields::FillItemSet( SfxItemSet
& rArgSet
)
274 ScSortParam theSortData
= rSortData
;
277 const SfxItemSet
* pExample
= pDlg
->GetExampleSet();
278 const SfxPoolItem
* pItem
;
279 if ( pExample
&& pExample
->GetItemState( nWhichSort
, TRUE
, &pItem
) == SFX_ITEM_SET
)
280 theSortData
= ((const ScSortItem
*)pItem
)->GetSortData();
283 USHORT nSort1Pos
= aLbSort1
.GetSelectEntryPos();
284 USHORT nSort2Pos
= aLbSort2
.GetSelectEntryPos();
285 USHORT nSort3Pos
= aLbSort3
.GetSelectEntryPos();
287 DBG_ASSERT( (nSort1Pos
<= SC_MAXFIELDS
)
288 && (nSort2Pos
<= SC_MAXFIELDS
)
289 && (nSort3Pos
<= SC_MAXFIELDS
),
290 "Array-Range Fehler!" );
292 if ( nSort1Pos
== LISTBOX_ENTRY_NOTFOUND
) nSort1Pos
= 0;
293 if ( nSort2Pos
== LISTBOX_ENTRY_NOTFOUND
) nSort2Pos
= 0;
294 if ( nSort3Pos
== LISTBOX_ENTRY_NOTFOUND
) nSort3Pos
= 0;
298 theSortData
.bDoSort
[0] = (nSort1Pos
> 0);
299 theSortData
.bDoSort
[1] = (nSort2Pos
> 0);
300 theSortData
.bDoSort
[2] = (nSort3Pos
> 0);
302 // wenn auf Optionen-Seite "OK" gewaehlt wurde und
303 // dabei die Sortierrichtung umgestellt wurde, so
304 // wird das erste Feld der jeweiligen Richtung als
305 // Sortierkriterium gewaehlt (steht in nFieldArr[0]):
306 if ( bSortByRows
!= pDlg
->GetByRows() )
308 theSortData
.nField
[0] =
309 theSortData
.nField
[1] =
310 theSortData
.nField
[2] = ( bSortByRows
?
311 static_cast<SCCOLROW
>(nFirstRow
) :
312 static_cast<SCCOLROW
>(nFirstCol
) );
316 theSortData
.nField
[0] = nFieldArr
[nSort1Pos
];
317 theSortData
.nField
[1] = nFieldArr
[nSort2Pos
];
318 theSortData
.nField
[2] = nFieldArr
[nSort3Pos
];
321 theSortData
.bAscending
[0] = aBtnUp1
.IsChecked();
322 theSortData
.bAscending
[1] = aBtnUp2
.IsChecked();
323 theSortData
.bAscending
[2] = aBtnUp3
.IsChecked();
324 // bHasHeader ist in ScTabPageSortOptions::FillItemSet, wo es hingehoert
328 theSortData
.bDoSort
[0] =
329 theSortData
.bDoSort
[1] =
330 theSortData
.bDoSort
[2] = FALSE
;
333 rArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, NULL
, &theSortData
) );
338 // -----------------------------------------------------------------------
340 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
341 // void ScTabPageSortFields::ActivatePage( const SfxItemSet& rSet )
343 void __EXPORT
ScTabPageSortFields::ActivatePage()
347 if ( bHasHeader
!= pDlg
->GetHeaders()
348 || bSortByRows
!= pDlg
->GetByRows() )
350 USHORT nCurSel1
= aLbSort1
.GetSelectEntryPos();
351 USHORT nCurSel2
= aLbSort2
.GetSelectEntryPos();
352 USHORT nCurSel3
= aLbSort3
.GetSelectEntryPos();
354 bHasHeader
= pDlg
->GetHeaders();
355 bSortByRows
= pDlg
->GetByRows();
357 aLbSort1
.SelectEntryPos( nCurSel1
);
358 aLbSort2
.SelectEntryPos( nCurSel2
);
359 aLbSort3
.SelectEntryPos( nCurSel3
);
364 // -----------------------------------------------------------------------
366 int __EXPORT
ScTabPageSortFields::DeactivatePage( SfxItemSet
* pSetP
)
370 if ( bHasHeader
!= pDlg
->GetHeaders() )
371 pDlg
->SetHeaders( bHasHeader
);
373 if ( bSortByRows
!= pDlg
->GetByRows() )
374 pDlg
->SetByRows( bSortByRows
);
378 FillItemSet( *pSetP
);
380 return SfxTabPage::LEAVE_PAGE
;
383 // -----------------------------------------------------------------------
385 void ScTabPageSortFields::DisableField( USHORT nField
)
391 aSortLbArr
[nField
] ->Disable();
392 aDirBtnArr
[nField
][0]->Disable();
393 aDirBtnArr
[nField
][1]->Disable();
394 aFlArr
[nField
] ->Disable();
398 // -----------------------------------------------------------------------
400 void ScTabPageSortFields::EnableField( USHORT nField
)
406 aSortLbArr
[nField
] ->Enable();
407 aDirBtnArr
[nField
][0]->Enable();
408 aDirBtnArr
[nField
][1]->Enable();
409 aFlArr
[nField
] ->Enable();
413 // -----------------------------------------------------------------------
415 void ScTabPageSortFields::FillFieldLists()
419 ScDocument
* pDoc
= pViewData
->GetDocument();
426 aLbSort1
.InsertEntry( aStrUndefined
, 0 );
427 aLbSort2
.InsertEntry( aStrUndefined
, 0 );
428 aLbSort3
.InsertEntry( aStrUndefined
, 0 );
430 SCCOL nFirstSortCol
= rSortData
.nCol1
;
431 SCROW nFirstSortRow
= rSortData
.nRow1
;
432 SCTAB nTab
= pViewData
->GetTabNo();
438 SCCOL nMaxCol
= rSortData
.nCol2
;
441 for ( col
=nFirstSortCol
; col
<=nMaxCol
&& i
<SC_MAXFIELDS
; col
++ )
443 pDoc
->GetString( col
, nFirstSortRow
, nTab
, aFieldName
);
444 if ( !bHasHeader
|| (aFieldName
.Len() == 0) )
446 aFieldName
= aStrColumn
;
448 aFieldName
+= ScColToAlpha( col
);
451 aLbSort1
.InsertEntry( aFieldName
, i
);
452 aLbSort2
.InsertEntry( aFieldName
, i
);
453 aLbSort3
.InsertEntry( aFieldName
, i
);
460 SCROW nMaxRow
= rSortData
.nRow2
;
463 for ( row
=nFirstSortRow
; row
<=nMaxRow
&& i
<SC_MAXFIELDS
; row
++ )
465 pDoc
->GetString( nFirstSortCol
, row
, nTab
, aFieldName
);
466 if ( !bHasHeader
|| (aFieldName
.Len() == 0) )
468 aFieldName
= aStrRow
;
470 aFieldName
+= String::CreateFromInt32( row
+1 );
473 aLbSort1
.InsertEntry( aFieldName
, i
);
474 aLbSort2
.InsertEntry( aFieldName
, i
);
475 aLbSort3
.InsertEntry( aFieldName
, i
);
484 //------------------------------------------------------------------------
486 USHORT
ScTabPageSortFields::GetFieldSelPos( SCCOLROW nField
)
488 USHORT nFieldPos
= 0;
491 for ( USHORT n
=1; n
<nFieldCount
&& !bFound
; n
++ )
493 if ( nFieldArr
[n
] == nField
)
503 // -----------------------------------------------------------------------
507 IMPL_LINK( ScTabPageSortFields
, SelectHdl
, ListBox
*, pLb
)
509 String aSelEntry
= pLb
->GetSelectEntry();
511 if ( pLb
== &aLbSort1
)
513 if ( aSelEntry
== aStrUndefined
)
515 aLbSort2
.SelectEntryPos( 0 );
516 aLbSort3
.SelectEntryPos( 0 );
518 if ( aFlSort2
.IsEnabled() )
521 if ( aFlSort3
.IsEnabled() )
526 if ( !aFlSort2
.IsEnabled() )
530 else if ( pLb
== &aLbSort2
)
532 if ( aSelEntry
== aStrUndefined
)
534 aLbSort3
.SelectEntryPos( 0 );
535 if ( aFlSort3
.IsEnabled() )
540 if ( !aFlSort3
.IsEnabled() )
547 //========================================================================
548 // Sortieroptionen-Tabpage:
549 //========================================================================
551 #include <layout/layout-pre.hxx>
555 #define ScResId(x) #x
557 #define SfxTabPage( parent, id, args ) SfxTabPage( parent, "sort-options.xml", id, &args )
558 #endif /* ENABLE_LAYOUT */
560 ScTabPageSortOptions::ScTabPageSortOptions( Window
* pParent
,
561 const SfxItemSet
& rArgSet
)
563 : SfxTabPage ( pParent
,
564 ScResId( RID_SCPAGE_SORT_OPTIONS
),
567 aBtnCase ( this, ScResId( BTN_CASESENSITIVE
) ),
568 aBtnHeader ( this, ScResId( BTN_LABEL
) ),
569 aBtnFormats ( this, ScResId( BTN_FORMATS
) ),
570 aBtnCopyResult ( this, ScResId( BTN_COPYRESULT
) ),
571 aBtnNaturalSort ( this, ScResId( BTN_NATURALSORT
) ),
572 aLbOutPos ( this, ScResId( LB_OUTAREA
) ),
573 aEdOutPos ( this, ScResId( ED_OUTAREA
) ),
574 aBtnSortUser ( this, ScResId( BTN_SORT_USER
) ),
575 aLbSortUser ( this, ScResId( LB_SORT_USER
) ),
576 aFtLanguage ( this, ScResId( FT_LANGUAGE
) ),
577 aLbLanguage ( this, ScResId( LB_LANGUAGE
) ),
578 aFtAlgorithm ( this, ScResId( FT_ALGORITHM
) ),
579 aLbAlgorithm ( this, ScResId( LB_ALGORITHM
) ),
580 aLineDirection ( this, ScResId( FL_DIRECTION
) ),
581 aBtnTopDown ( this, ScResId( BTN_TOP_DOWN
) ),
582 aBtnLeftRight ( this, ScResId( BTN_LEFT_RIGHT
) ),
583 // aFtAreaLabel ( this, ScResId( FT_AREA_LABEL ) ),
584 // aFtArea ( this, ScResId( FT_AREA ) ),
589 #define ScResId(x) this, #x
590 #endif /* ENABLE_LAYOUT */
591 aStrRowLabel ( ScResId( STR_ROW_LABEL
) ),
592 aStrColLabel ( ScResId( STR_COL_LABEL
) ),
593 aStrUndefined ( ScResId( SCSTR_UNDEFINED
) ),
594 aStrNoName ( ScGlobal::GetRscString(STR_DB_NONAME
) ),
597 nWhichSort ( rArgSet
.GetPool()->GetWhich( SID_SORT
) ),
598 rSortData ( ((const ScSortItem
&)
599 rArgSet
.Get( nWhichSort
)).GetSortData() ),
600 #else /* TEST_LAYOUT */
602 rSortData ( *new ScSortParam() ),
603 #endif /* TEST_LAYOUT */
606 pDlg ( (ScSortDlg
*)(GetParent() ? GetParent()->GetParent() : 0 ) ),
612 #endif /* TEST_LAYOUT */
615 SetExchangeSupport();
618 // -----------------------------------------------------------------------
620 __EXPORT
ScTabPageSortOptions::~ScTabPageSortOptions()
623 USHORT nEntries
= aLbOutPos
.GetEntryCount();
625 for ( USHORT i
=1; i
<nEntries
; i
++ )
626 delete (String
*)aLbOutPos
.GetEntryData( i
);
627 #endif /* !TEST_LAYOUT */
630 delete pColWrap
; //! not if from document
633 // -----------------------------------------------------------------------
635 void ScTabPageSortOptions::Init()
637 // aStrAreaLabel = aFtAreaLabel.GetText();
638 // aStrAreaLabel.Append( (sal_Unicode) ' ' );
640 // CollatorRessource has user-visible names for sort algorithms
641 pColRes
= new CollatorRessource();
643 //! use CollatorWrapper from document?
644 pColWrap
= new CollatorWrapper( comphelper::getProcessServiceFactory() );
647 const ScSortItem
& rSortItem
= (const ScSortItem
&)
648 GetItemSet().Get( nWhichSort
);
649 #endif /* !TEST_LAYOUT */
651 aLbOutPos
.SetSelectHdl ( LINK( this, ScTabPageSortOptions
, SelOutPosHdl
) );
652 aBtnCopyResult
.SetClickHdl( LINK( this, ScTabPageSortOptions
, EnableHdl
) );
653 aBtnSortUser
.SetClickHdl ( LINK( this, ScTabPageSortOptions
, EnableHdl
) );
654 aBtnTopDown
.SetClickHdl ( LINK( this, ScTabPageSortOptions
, SortDirHdl
) );
655 aBtnLeftRight
.SetClickHdl ( LINK( this, ScTabPageSortOptions
, SortDirHdl
) );
656 aLbLanguage
.SetSelectHdl ( LINK( this, ScTabPageSortOptions
, FillAlgorHdl
) );
659 pViewData
= rSortItem
.GetViewData();
660 #endif /* TEST_LAYOUT */
661 pDoc
= pViewData
? pViewData
->GetDocument() : NULL
;
663 DBG_ASSERT( pViewData
, "ViewData not found! :-/" );
666 if ( pViewData
&& pDoc
)
669 ScDBCollection
* pDBColl
= pDoc
->GetDBCollection();
671 String theDbName
= aStrNoName
;
672 const SCTAB nCurTab
= pViewData
->GetTabNo();
673 const ScAddress::Convention eConv
= pDoc
->GetAddressConvention();
674 #endif /* !TEST_LAYOUT */
677 aLbOutPos
.InsertEntry( aStrUndefined
, 0 );
681 ScAreaNameIterator
aIter( pDoc
);
685 while ( aIter
.Next( aName
, aRange
) )
687 USHORT nInsert
= aLbOutPos
.InsertEntry( aName
);
689 aRange
.aStart
.Format( aRefStr
, SCA_ABS_3D
, pDoc
, eConv
);
690 aLbOutPos
.SetEntryData( nInsert
, new String( aRefStr
) );
692 #endif /* !TEST_LAYOUT */
694 aLbOutPos
.SelectEntryPos( 0 );
695 aEdOutPos
.SetText( EMPTY_STRING
);
699 * Ueberpruefen, ob es sich bei dem uebergebenen
700 * Bereich um einen Datenbankbereich handelt:
703 ScAddress
aScAddress( rSortData
.nCol1
, rSortData
.nRow1
, nCurTab
);
705 ScAddress( rSortData
.nCol2
, rSortData
.nRow2
, nCurTab
)
706 ).Format( theArea
, SCR_ABS
, pDoc
, eConv
);
711 = pDBColl
->GetDBAtArea( nCurTab
,
712 rSortData
.nCol1
, rSortData
.nRow1
,
713 rSortData
.nCol2
, rSortData
.nRow2
);
716 pDBData
->GetName( theDbName
);
717 aBtnHeader
.Check( pDBData
->HasHeader() );
721 theArea
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
722 theArea
+= theDbName
;
725 //aFtArea.SetText( theArea );
726 //theArea.Insert( aStrAreaLabel, 0 );
727 //aFtAreaLabel.SetText( theArea );
729 aBtnHeader
.SetText( aStrColLabel
);
731 #endif /* TEST_LAYOUT */
733 FillUserSortListBox();
735 // get available languages
737 aLbLanguage
.SetLanguageList( LANG_LIST_ALL
| LANG_LIST_ONLY_KNOWN
, FALSE
);
738 aLbLanguage
.InsertLanguage( LANGUAGE_SYSTEM
);
741 //------------------------------------------------------------------------
743 USHORT
* __EXPORT
ScTabPageSortOptions::GetRanges()
748 // -----------------------------------------------------------------------
752 #endif /* ENABLE_LAYOUT */
753 SfxTabPage
* __EXPORT
ScTabPageSortOptions::Create(
755 const SfxItemSet
& rArgSet
)
757 return ( new ScTabPageSortOptions( pParent
, rArgSet
) );
760 // -----------------------------------------------------------------------
762 void __EXPORT
ScTabPageSortOptions::Reset( const SfxItemSet
& /* rArgSet */ )
764 if ( rSortData
.bUserDef
)
766 aBtnSortUser
.Check( TRUE
);
767 aLbSortUser
.Enable();
768 aLbSortUser
.SelectEntryPos( rSortData
.nUserIndex
);
772 aBtnSortUser
.Check( FALSE
);
773 aLbSortUser
.Disable();
774 aLbSortUser
.SelectEntryPos( 0 );
777 aBtnCase
.Check ( rSortData
.bCaseSens
);
778 aBtnFormats
.Check ( rSortData
.bIncludePattern
);
779 aBtnHeader
.Check ( rSortData
.bHasHeader
);
780 aBtnNaturalSort
.Check ( rSortData
.bNaturalSort
);
782 if ( rSortData
.bByRow
)
785 aBtnHeader
.SetText( aStrColLabel
);
789 aBtnLeftRight
.Check();
790 aBtnHeader
.SetText( aStrRowLabel
);
793 LanguageType eLang
= MsLangId::convertLocaleToLanguage( rSortData
.aCollatorLocale
);
794 if ( eLang
== LANGUAGE_DONTKNOW
)
795 eLang
= LANGUAGE_SYSTEM
;
796 aLbLanguage
.SelectLanguage( eLang
);
797 FillAlgorHdl( &aLbLanguage
); // get algorithms, select default
798 if ( rSortData
.aCollatorAlgorithm
.Len() )
799 aLbAlgorithm
.SelectEntry( pColRes
->GetTranslation( rSortData
.aCollatorAlgorithm
) );
801 if ( pDoc
&& !rSortData
.bInplace
)
804 USHORT nFormat
= (rSortData
.nDestTab
!= pViewData
->GetTabNo())
808 theOutPos
.Set( rSortData
.nDestCol
,
810 rSortData
.nDestTab
);
812 theOutPos
.Format( aStr
, nFormat
, pDoc
, pDoc
->GetAddressConvention() );
813 aBtnCopyResult
.Check();
816 aEdOutPos
.SetText( aStr
);
817 EdOutPosModHdl( &aEdOutPos
);
818 aEdOutPos
.GrabFocus();
819 aEdOutPos
.SetSelection( Selection( 0, SELECTION_MAX
) );
823 aBtnCopyResult
.Check( FALSE
);
826 aEdOutPos
.SetText( EMPTY_STRING
);
830 // -----------------------------------------------------------------------
832 BOOL __EXPORT
ScTabPageSortOptions::FillItemSet( SfxItemSet
& rArgSet
)
834 ScSortParam theSortData
= rSortData
;
837 const SfxItemSet
* pExample
= pDlg
->GetExampleSet();
838 const SfxPoolItem
* pItem
;
839 if ( pExample
&& pExample
->GetItemState( nWhichSort
, TRUE
, &pItem
) == SFX_ITEM_SET
)
840 theSortData
= ((const ScSortItem
*)pItem
)->GetSortData();
843 theSortData
.bByRow
= aBtnTopDown
.IsChecked();
844 theSortData
.bHasHeader
= aBtnHeader
.IsChecked();
845 theSortData
.bCaseSens
= aBtnCase
.IsChecked();
846 theSortData
.bNaturalSort
= aBtnNaturalSort
.IsChecked();
847 theSortData
.bIncludePattern
= aBtnFormats
.IsChecked();
848 theSortData
.bInplace
= !aBtnCopyResult
.IsChecked();
849 theSortData
.nDestCol
= theOutPos
.Col();
850 theSortData
.nDestRow
= theOutPos
.Row();
851 theSortData
.nDestTab
= theOutPos
.Tab();
852 theSortData
.bUserDef
= aBtnSortUser
.IsChecked();
853 theSortData
.nUserIndex
= (aBtnSortUser
.IsChecked())
854 ? aLbSortUser
.GetSelectEntryPos()
858 LanguageType eLang
= aLbLanguage
.GetSelectLanguage();
859 theSortData
.aCollatorLocale
= MsLangId::convertLanguageToLocale( eLang
, false );
863 if ( eLang
!= LANGUAGE_SYSTEM
)
865 uno::Sequence
<rtl::OUString
> aAlgos
= pColWrap
->listCollatorAlgorithms(
866 theSortData
.aCollatorLocale
);
867 USHORT nSel
= aLbAlgorithm
.GetSelectEntryPos();
868 if ( nSel
< aAlgos
.getLength() )
871 theSortData
.aCollatorAlgorithm
= sAlg
;
874 rArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, &theSortData
) );
875 #endif /* TEST_LAYOUT */
879 // -----------------------------------------------------------------------
881 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
882 // void ScTabPageSortOptions::ActivatePage( const SfxItemSet& rSet )
883 void __EXPORT
ScTabPageSortOptions::ActivatePage()
887 if ( aBtnHeader
.IsChecked() != pDlg
->GetHeaders() )
889 aBtnHeader
.Check( pDlg
->GetHeaders() );
892 if ( aBtnTopDown
.IsChecked() != pDlg
->GetByRows() )
894 aBtnTopDown
.Check( pDlg
->GetByRows() );
895 aBtnLeftRight
.Check( !pDlg
->GetByRows() );
898 aBtnHeader
.SetText( (pDlg
->GetByRows())
904 // -----------------------------------------------------------------------
906 int __EXPORT
ScTabPageSortOptions::DeactivatePage( SfxItemSet
* pSetP
)
908 BOOL bPosInputOk
= TRUE
;
910 if ( aBtnCopyResult
.IsChecked() )
912 String thePosStr
= aEdOutPos
.GetText();
914 xub_StrLen nColonPos
= thePosStr
.Search( ':' );
916 if ( STRING_NOTFOUND
!= nColonPos
)
917 thePosStr
.Erase( nColonPos
);
921 // visible table is default for input without table
922 // must be changed to GetRefTabNo when sorting has RefInput!
923 thePos
.SetTab( pViewData
->GetTabNo() );
926 USHORT nResult
= thePos
.Parse( thePosStr
, pDoc
, pDoc
->GetAddressConvention() );
928 bPosInputOk
= ( SCA_VALID
== (nResult
& SCA_VALID
) );
933 ErrorBox( this, WinBits( WB_OK
| WB_DEF_OK
),
934 ScGlobal::GetRscString( STR_INVALID_TABREF
)
936 #endif /* ENABLE_LAYOUT */
937 aEdOutPos
.GrabFocus();
938 aEdOutPos
.SetSelection( Selection( 0, SELECTION_MAX
) );
939 theOutPos
.Set(0,0,0);
943 aEdOutPos
.SetText( thePosStr
);
948 if ( pDlg
&& bPosInputOk
)
950 pDlg
->SetHeaders( aBtnHeader
.IsChecked() );
951 pDlg
->SetByRows ( aBtnTopDown
.IsChecked() );
954 if ( pSetP
&& bPosInputOk
)
955 FillItemSet( *pSetP
);
957 return bPosInputOk
? SfxTabPage::LEAVE_PAGE
: SfxTabPage::KEEP_PAGE
;
960 // -----------------------------------------------------------------------
962 void ScTabPageSortOptions::FillUserSortListBox()
964 ScUserList
* pUserLists
= ScGlobal::GetUserList();
969 USHORT nCount
= pUserLists
->GetCount();
971 for ( USHORT i
=0; i
<nCount
; i
++ )
972 aLbSortUser
.InsertEntry( (*pUserLists
)[i
]->GetString() );
976 // -----------------------------------------------------------------------
979 IMPL_LINK( ScTabPageSortOptions
, EnableHdl
, CheckBox
*, pBox
)
981 if ( pBox
== &aBtnCopyResult
)
983 if ( pBox
->IsChecked() )
987 aEdOutPos
.GrabFocus();
995 else if ( pBox
== &aBtnSortUser
)
997 if ( pBox
->IsChecked() )
999 aLbSortUser
.Enable();
1000 aLbSortUser
.GrabFocus();
1003 aLbSortUser
.Disable();
1008 // -----------------------------------------------------------------------
1010 IMPL_LINK( ScTabPageSortOptions
, SelOutPosHdl
, ListBox
*, pLb
)
1012 if ( pLb
== &aLbOutPos
)
1015 USHORT nSelPos
= aLbOutPos
.GetSelectEntryPos();
1018 aString
= *(String
*)aLbOutPos
.GetEntryData( nSelPos
);
1020 aEdOutPos
.SetText( aString
);
1025 // -----------------------------------------------------------------------
1027 IMPL_LINK( ScTabPageSortOptions
, SortDirHdl
, RadioButton
*, pBtn
)
1029 if ( pBtn
== &aBtnTopDown
)
1031 aBtnHeader
.SetText( aStrColLabel
);
1033 else if ( pBtn
== &aBtnLeftRight
)
1035 aBtnHeader
.SetText( aStrRowLabel
);
1040 // -----------------------------------------------------------------------
1042 void __EXPORT
ScTabPageSortOptions::EdOutPosModHdl( Edit
* pEd
)
1044 if ( pEd
== &aEdOutPos
)
1046 String theCurPosStr
= aEdOutPos
.GetText();
1047 USHORT nResult
= ScAddress().Parse( theCurPosStr
, pDoc
, pDoc
->GetAddressConvention() );
1049 if ( SCA_VALID
== (nResult
& SCA_VALID
) )
1051 String
* pStr
= NULL
;
1052 BOOL bFound
= FALSE
;
1054 USHORT nCount
= aLbOutPos
.GetEntryCount();
1056 for ( i
=2; i
<nCount
&& !bFound
; i
++ )
1058 pStr
= (String
*)aLbOutPos
.GetEntryData( i
);
1059 bFound
= (theCurPosStr
== *pStr
);
1063 aLbOutPos
.SelectEntryPos( --i
);
1065 aLbOutPos
.SelectEntryPos( 0 );
1070 // -----------------------------------------------------------------------
1072 IMPL_LINK( ScTabPageSortOptions
, FillAlgorHdl
, void *, EMPTYARG
)
1074 aLbAlgorithm
.SetUpdateMode( FALSE
);
1075 aLbAlgorithm
.Clear();
1077 LanguageType eLang
= aLbLanguage
.GetSelectLanguage();
1078 if ( eLang
== LANGUAGE_SYSTEM
)
1080 // for LANGUAGE_SYSTEM no algorithm can be selected because
1081 // it wouldn't necessarily exist for other languages
1082 // -> leave list box empty if LANGUAGE_SYSTEM is selected
1083 aFtAlgorithm
.Enable( FALSE
); // nothing to select
1084 aLbAlgorithm
.Enable( FALSE
); // nothing to select
1088 lang::Locale
aLocale( MsLangId::convertLanguageToLocale( eLang
));
1089 uno::Sequence
<rtl::OUString
> aAlgos
= pColWrap
->listCollatorAlgorithms( aLocale
);
1091 long nCount
= aAlgos
.getLength();
1092 const rtl::OUString
* pArray
= aAlgos
.getConstArray();
1093 for (long i
=0; i
<nCount
; i
++)
1095 String sAlg
= pArray
[i
];
1096 String sUser
= pColRes
->GetTranslation( sAlg
);
1097 aLbAlgorithm
.InsertEntry( sUser
, LISTBOX_APPEND
);
1099 aLbAlgorithm
.SelectEntryPos( 0 ); // first entry is default
1100 aFtAlgorithm
.Enable( nCount
> 1 ); // enable only if there is a choice
1101 aLbAlgorithm
.Enable( nCount
> 1 ); // enable only if there is a choice
1104 aLbAlgorithm
.SetUpdateMode( TRUE
);