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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 #include <vcl/msgbox.hxx>
39 #include <i18npool/mslangid.hxx>
40 #include <svtools/collatorres.hxx>
41 #include <unotools/collatorwrapper.hxx>
42 #include <unotools/localedatawrapper.hxx>
43 #include <comphelper/processfactory.hxx>
45 #include "scitems.hxx"
46 #include "uiitems.hxx"
47 #include "viewdata.hxx"
48 #include "document.hxx"
50 #include "dbcolect.hxx"
51 #include "userlist.hxx"
52 #include "rangeutl.hxx"
53 #include "scresid.hxx"
54 #include "sc.hrc" // -> Slot IDs
55 #include "globstr.hrc"
57 #include "sortdlg.hxx"
58 #include "sortdlg.hrc"
64 using namespace com::sun::star
;
66 // STATIC DATA -----------------------------------------------------------
68 static USHORT pSortRanges
[] =
75 // -----------------------------------------------------------------------
78 * Da sich Einstellungen auf der zweiten TabPage (Optionen) auf
79 * die erste TabPage auswirken, muss es die Moeglichkeit geben,
80 * dies der jeweils anderen Seite mitzuteilen.
82 * Im Moment wird dieses Problem ueber zwei Datenmember des TabDialoges
83 * geloest. Wird eine Seite Aktiviert/Deaktiviert, so gleicht sie diese
84 * Datenmember mit dem eigenen Zustand ab (->Activate()/Deactivate()).
87 * Die Klasse SfxTabPage bietet mittlerweile ein Verfahren an:
89 * virtual BOOL HasExchangeSupport() const; -> return TRUE;
90 * virtual void ActivatePage(const SfxItemSet &);
91 * virtual int DeactivatePage(SfxItemSet * = 0);
93 * muss noch geaendert werden!
96 //========================================================================
97 //========================================================================
98 // Sortierkriterien-Tabpage:
100 ScTabPageSortFields::ScTabPageSortFields( Window
* pParent
,
101 const SfxItemSet
& rArgSet
)
103 : SfxTabPage ( pParent
,
104 ScResId( RID_SCPAGE_SORT_FIELDS
),
107 aFlSort1 ( this, ScResId( FL_SORT1
) ),
108 aLbSort1 ( this, ScResId( LB_SORT1
) ),
109 aBtnUp1 ( this, ScResId( BTN_UP1
) ),
110 aBtnDown1 ( this, ScResId( BTN_DOWN1
) ),
112 aFlSort2 ( this, ScResId( FL_SORT2
) ),
113 aLbSort2 ( this, ScResId( LB_SORT2
) ),
114 aBtnUp2 ( this, ScResId( BTN_UP2
) ),
115 aBtnDown2 ( this, ScResId( BTN_DOWN2
) ),
117 aFlSort3 ( this, ScResId( FL_SORT3
) ),
118 aLbSort3 ( this, ScResId( LB_SORT3
) ),
119 aBtnUp3 ( this, ScResId( BTN_UP3
) ),
120 aBtnDown3 ( this, ScResId( BTN_DOWN3
) ),
122 aStrUndefined ( ScResId( SCSTR_UNDEFINED
) ),
123 aStrColumn ( ScResId( SCSTR_COLUMN
) ),
124 aStrRow ( ScResId( SCSTR_ROW
) ),
126 nWhichSort ( rArgSet
.GetPool()->GetWhich( SID_SORT
) ),
127 pDlg ( (ScSortDlg
*)(GetParent()->GetParent()) ),
129 rSortData ( ((const ScSortItem
&)
130 rArgSet
.Get( nWhichSort
)).
133 bHasHeader ( FALSE
),
134 bSortByRows ( FALSE
)
138 SetExchangeSupport();
141 // -----------------------------------------------------------------------
143 __EXPORT
ScTabPageSortFields::~ScTabPageSortFields()
147 // -----------------------------------------------------------------------
149 void ScTabPageSortFields::Init()
151 const ScSortItem
& rSortItem
= (const ScSortItem
&)
152 GetItemSet().Get( nWhichSort
);
154 pViewData
= rSortItem
.GetViewData();
156 DBG_ASSERT( pViewData
, "ViewData not found!" );
162 aLbSort1
.SetSelectHdl( LINK( this, ScTabPageSortFields
, SelectHdl
) );
163 aLbSort2
.SetSelectHdl( LINK( this, ScTabPageSortFields
, SelectHdl
) );
164 aLbSort3
.SetSelectHdl( LINK( this, ScTabPageSortFields
, SelectHdl
) );
169 aSortLbArr
[0] = &aLbSort1
;
170 aSortLbArr
[1] = &aLbSort2
;
171 aSortLbArr
[2] = &aLbSort3
;
172 aDirBtnArr
[0][0] = &aBtnUp1
;
173 aDirBtnArr
[0][1] = &aBtnDown1
;
174 aDirBtnArr
[1][0] = &aBtnUp2
;
175 aDirBtnArr
[1][1] = &aBtnDown2
;
176 aDirBtnArr
[2][0] = &aBtnUp3
;
177 aDirBtnArr
[2][1] = &aBtnDown3
;
178 aFlArr
[0] = &aFlSort1
;
179 aFlArr
[1] = &aFlSort2
;
180 aFlArr
[2] = &aFlSort3
;
183 //------------------------------------------------------------------------
185 USHORT
* __EXPORT
ScTabPageSortFields::GetRanges()
190 // -----------------------------------------------------------------------
192 SfxTabPage
* __EXPORT
ScTabPageSortFields::Create( Window
* pParent
,
193 const SfxItemSet
& rArgSet
)
195 return ( new ScTabPageSortFields( pParent
, rArgSet
) );
198 // -----------------------------------------------------------------------
200 void __EXPORT
ScTabPageSortFields::Reset( const SfxItemSet
& /* rArgSet */ )
202 bSortByRows
= rSortData
.bByRow
;
203 bHasHeader
= rSortData
.bHasHeader
;
205 if ( aLbSort1
.GetEntryCount() == 0 )
208 // Selektieren der ListBoxen:
210 if ( rSortData
.bDoSort
[0] )
212 for ( USHORT i
=0; i
<3; i
++ )
214 if ( rSortData
.bDoSort
[i
] )
216 aSortLbArr
[i
]->SelectEntryPos(
217 GetFieldSelPos( rSortData
.nField
[i
] ) );
219 (rSortData
.bAscending
[i
])
220 ? aDirBtnArr
[i
][0]->Check() // Up
221 : aDirBtnArr
[i
][1]->Check(); // Down
225 aSortLbArr
[i
]->SelectEntryPos( 0 ); // "keiner" selektieren
226 aDirBtnArr
[i
][0]->Check(); // Up
233 if ( aLbSort1
.GetSelectEntryPos() == 0 )
235 if ( aLbSort2
.GetSelectEntryPos() == 0 )
240 SCCOL nCol
= pViewData
->GetCurX();
242 if( nCol
< rSortData
.nCol1
)
243 nCol
= rSortData
.nCol1
;
244 else if( nCol
> rSortData
.nCol2
)
245 nCol
= rSortData
.nCol2
;
247 USHORT nSort1Pos
= nCol
- rSortData
.nCol1
+1;
248 aLbSort1
.SelectEntryPos( nSort1Pos
);
249 aLbSort2
.SelectEntryPos( 0 );
250 aLbSort3
.SelectEntryPos( 0 );
261 pDlg
->SetByRows ( bSortByRows
);
262 pDlg
->SetHeaders( bHasHeader
);
266 // -----------------------------------------------------------------------
268 BOOL __EXPORT
ScTabPageSortFields::FillItemSet( SfxItemSet
& rArgSet
)
270 ScSortParam theSortData
= rSortData
;
273 const SfxItemSet
* pExample
= pDlg
->GetExampleSet();
274 const SfxPoolItem
* pItem
;
275 if ( pExample
&& pExample
->GetItemState( nWhichSort
, TRUE
, &pItem
) == SFX_ITEM_SET
)
276 theSortData
= ((const ScSortItem
*)pItem
)->GetSortData();
279 USHORT nSort1Pos
= aLbSort1
.GetSelectEntryPos();
280 USHORT nSort2Pos
= aLbSort2
.GetSelectEntryPos();
281 USHORT nSort3Pos
= aLbSort3
.GetSelectEntryPos();
283 DBG_ASSERT( (nSort1Pos
<= SC_MAXFIELDS
)
284 && (nSort2Pos
<= SC_MAXFIELDS
)
285 && (nSort3Pos
<= SC_MAXFIELDS
),
286 "Array-Range Fehler!" );
288 if ( nSort1Pos
== LISTBOX_ENTRY_NOTFOUND
) nSort1Pos
= 0;
289 if ( nSort2Pos
== LISTBOX_ENTRY_NOTFOUND
) nSort2Pos
= 0;
290 if ( nSort3Pos
== LISTBOX_ENTRY_NOTFOUND
) nSort3Pos
= 0;
294 theSortData
.bDoSort
[0] = (nSort1Pos
> 0);
295 theSortData
.bDoSort
[1] = (nSort2Pos
> 0);
296 theSortData
.bDoSort
[2] = (nSort3Pos
> 0);
298 // wenn auf Optionen-Seite "OK" gewaehlt wurde und
299 // dabei die Sortierrichtung umgestellt wurde, so
300 // wird das erste Feld der jeweiligen Richtung als
301 // Sortierkriterium gewaehlt (steht in nFieldArr[0]):
302 if ( bSortByRows
!= pDlg
->GetByRows() )
304 theSortData
.nField
[0] =
305 theSortData
.nField
[1] =
306 theSortData
.nField
[2] = ( bSortByRows
?
307 static_cast<SCCOLROW
>(nFirstRow
) :
308 static_cast<SCCOLROW
>(nFirstCol
) );
312 theSortData
.nField
[0] = nFieldArr
[nSort1Pos
];
313 theSortData
.nField
[1] = nFieldArr
[nSort2Pos
];
314 theSortData
.nField
[2] = nFieldArr
[nSort3Pos
];
317 theSortData
.bAscending
[0] = aBtnUp1
.IsChecked();
318 theSortData
.bAscending
[1] = aBtnUp2
.IsChecked();
319 theSortData
.bAscending
[2] = aBtnUp3
.IsChecked();
320 // bHasHeader ist in ScTabPageSortOptions::FillItemSet, wo es hingehoert
324 theSortData
.bDoSort
[0] =
325 theSortData
.bDoSort
[1] =
326 theSortData
.bDoSort
[2] = FALSE
;
329 rArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, NULL
, &theSortData
) );
334 // -----------------------------------------------------------------------
336 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
337 // void ScTabPageSortFields::ActivatePage( const SfxItemSet& rSet )
339 void __EXPORT
ScTabPageSortFields::ActivatePage()
343 if ( bHasHeader
!= pDlg
->GetHeaders()
344 || bSortByRows
!= pDlg
->GetByRows() )
346 USHORT nCurSel1
= aLbSort1
.GetSelectEntryPos();
347 USHORT nCurSel2
= aLbSort2
.GetSelectEntryPos();
348 USHORT nCurSel3
= aLbSort3
.GetSelectEntryPos();
350 bHasHeader
= pDlg
->GetHeaders();
351 bSortByRows
= pDlg
->GetByRows();
353 aLbSort1
.SelectEntryPos( nCurSel1
);
354 aLbSort2
.SelectEntryPos( nCurSel2
);
355 aLbSort3
.SelectEntryPos( nCurSel3
);
360 // -----------------------------------------------------------------------
362 int __EXPORT
ScTabPageSortFields::DeactivatePage( SfxItemSet
* pSetP
)
366 if ( bHasHeader
!= pDlg
->GetHeaders() )
367 pDlg
->SetHeaders( bHasHeader
);
369 if ( bSortByRows
!= pDlg
->GetByRows() )
370 pDlg
->SetByRows( bSortByRows
);
374 FillItemSet( *pSetP
);
376 return SfxTabPage::LEAVE_PAGE
;
379 // -----------------------------------------------------------------------
381 void ScTabPageSortFields::DisableField( USHORT nField
)
387 aSortLbArr
[nField
] ->Disable();
388 aDirBtnArr
[nField
][0]->Disable();
389 aDirBtnArr
[nField
][1]->Disable();
390 aFlArr
[nField
] ->Disable();
394 // -----------------------------------------------------------------------
396 void ScTabPageSortFields::EnableField( USHORT nField
)
402 aSortLbArr
[nField
] ->Enable();
403 aDirBtnArr
[nField
][0]->Enable();
404 aDirBtnArr
[nField
][1]->Enable();
405 aFlArr
[nField
] ->Enable();
409 // -----------------------------------------------------------------------
411 void ScTabPageSortFields::FillFieldLists()
415 ScDocument
* pDoc
= pViewData
->GetDocument();
422 aLbSort1
.InsertEntry( aStrUndefined
, 0 );
423 aLbSort2
.InsertEntry( aStrUndefined
, 0 );
424 aLbSort3
.InsertEntry( aStrUndefined
, 0 );
426 SCCOL nFirstSortCol
= rSortData
.nCol1
;
427 SCROW nFirstSortRow
= rSortData
.nRow1
;
428 SCTAB nTab
= pViewData
->GetTabNo();
434 SCCOL nMaxCol
= rSortData
.nCol2
;
437 for ( col
=nFirstSortCol
; col
<=nMaxCol
&& i
<SC_MAXFIELDS
; col
++ )
439 pDoc
->GetString( col
, nFirstSortRow
, nTab
, aFieldName
);
440 if ( !bHasHeader
|| (aFieldName
.Len() == 0) )
442 aFieldName
= aStrColumn
;
444 aFieldName
+= ScColToAlpha( col
);
447 aLbSort1
.InsertEntry( aFieldName
, i
);
448 aLbSort2
.InsertEntry( aFieldName
, i
);
449 aLbSort3
.InsertEntry( aFieldName
, i
);
456 SCROW nMaxRow
= rSortData
.nRow2
;
459 for ( row
=nFirstSortRow
; row
<=nMaxRow
&& i
<SC_MAXFIELDS
; row
++ )
461 pDoc
->GetString( nFirstSortCol
, row
, nTab
, aFieldName
);
462 if ( !bHasHeader
|| (aFieldName
.Len() == 0) )
464 aFieldName
= aStrRow
;
466 aFieldName
+= String::CreateFromInt32( row
+1 );
469 aLbSort1
.InsertEntry( aFieldName
, i
);
470 aLbSort2
.InsertEntry( aFieldName
, i
);
471 aLbSort3
.InsertEntry( aFieldName
, i
);
480 //------------------------------------------------------------------------
482 USHORT
ScTabPageSortFields::GetFieldSelPos( SCCOLROW nField
)
484 USHORT nFieldPos
= 0;
487 for ( USHORT n
=1; n
<nFieldCount
&& !bFound
; n
++ )
489 if ( nFieldArr
[n
] == nField
)
499 // -----------------------------------------------------------------------
503 IMPL_LINK( ScTabPageSortFields
, SelectHdl
, ListBox
*, pLb
)
505 String aSelEntry
= pLb
->GetSelectEntry();
507 if ( pLb
== &aLbSort1
)
509 if ( aSelEntry
== aStrUndefined
)
511 aLbSort2
.SelectEntryPos( 0 );
512 aLbSort3
.SelectEntryPos( 0 );
514 if ( aFlSort2
.IsEnabled() )
517 if ( aFlSort3
.IsEnabled() )
522 if ( !aFlSort2
.IsEnabled() )
526 else if ( pLb
== &aLbSort2
)
528 if ( aSelEntry
== aStrUndefined
)
530 aLbSort3
.SelectEntryPos( 0 );
531 if ( aFlSort3
.IsEnabled() )
536 if ( !aFlSort3
.IsEnabled() )
543 //========================================================================
544 // Sortieroptionen-Tabpage:
545 //========================================================================
547 #if ENABLE_LAYOUT_EXPERIMENTAL
548 #include <layout/layout-pre.hxx>
552 #define ScResId(x) #x
554 #define SfxTabPage( parent, id, args ) SfxTabPage( parent, "sort-options.xml", id, &args )
555 #endif /* ENABLE_LAYOUT */
557 #endif /* ENABLE_LAYOUT_EXPERIMENTAL */
559 ScTabPageSortOptions::ScTabPageSortOptions( Window
* pParent
,
560 const SfxItemSet
& rArgSet
)
562 : SfxTabPage ( pParent
,
563 ScResId( RID_SCPAGE_SORT_OPTIONS
),
566 aBtnCase ( this, ScResId( BTN_CASESENSITIVE
) ),
567 aBtnHeader ( this, ScResId( BTN_LABEL
) ),
568 aBtnFormats ( this, ScResId( BTN_FORMATS
) ),
569 aBtnCopyResult ( this, ScResId( BTN_COPYRESULT
) ),
570 aBtnNaturalSort ( this, ScResId( BTN_NATURALSORT
) ),
571 aLbOutPos ( this, ScResId( LB_OUTAREA
) ),
572 aEdOutPos ( this, ScResId( ED_OUTAREA
) ),
573 aBtnSortUser ( this, ScResId( BTN_SORT_USER
) ),
574 aLbSortUser ( this, ScResId( LB_SORT_USER
) ),
575 aFtLanguage ( this, ScResId( FT_LANGUAGE
) ),
576 aLbLanguage ( this, ScResId( LB_LANGUAGE
) ),
577 aFtAlgorithm ( this, ScResId( FT_ALGORITHM
) ),
578 aLbAlgorithm ( this, ScResId( LB_ALGORITHM
) ),
579 aLineDirection ( this, ScResId( FL_DIRECTION
) ),
580 aBtnTopDown ( this, ScResId( BTN_TOP_DOWN
) ),
581 aBtnLeftRight ( this, ScResId( BTN_LEFT_RIGHT
) ),
582 // aFtAreaLabel ( this, ScResId( FT_AREA_LABEL ) ),
583 // aFtArea ( this, ScResId( FT_AREA ) ),
585 #if ENABLE_LAYOUT_EXPERIMENTAL
588 #define ScResId(x) this, #x
589 #endif /* ENABLE_LAYOUT_EXPERIMENTAL */
590 aStrRowLabel ( ScResId( STR_ROW_LABEL
) ),
591 aStrColLabel ( ScResId( STR_COL_LABEL
) ),
592 aStrUndefined ( ScResId( SCSTR_UNDEFINED
) ),
593 aStrNoName ( ScGlobal::GetRscString(STR_DB_NONAME
) ),
595 nWhichSort ( rArgSet
.GetPool()->GetWhich( SID_SORT
) ),
596 rSortData ( ((const ScSortItem
&)
597 rArgSet
.Get( nWhichSort
)).GetSortData() ),
600 pDlg ( (ScSortDlg
*)(GetParent() ? GetParent()->GetParent() : 0 ) ),
606 SetExchangeSupport();
609 // -----------------------------------------------------------------------
611 __EXPORT
ScTabPageSortOptions::~ScTabPageSortOptions()
613 USHORT nEntries
= aLbOutPos
.GetEntryCount();
615 for ( USHORT i
=1; i
<nEntries
; i
++ )
616 delete (String
*)aLbOutPos
.GetEntryData( i
);
619 delete pColWrap
; //! not if from document
622 // -----------------------------------------------------------------------
624 void ScTabPageSortOptions::Init()
626 // aStrAreaLabel = aFtAreaLabel.GetText();
627 // aStrAreaLabel.Append( (sal_Unicode) ' ' );
629 // CollatorRessource has user-visible names for sort algorithms
630 pColRes
= new CollatorRessource();
632 //! use CollatorWrapper from document?
633 pColWrap
= new CollatorWrapper( comphelper::getProcessServiceFactory() );
635 const ScSortItem
& rSortItem
= (const ScSortItem
&)
636 GetItemSet().Get( nWhichSort
);
638 aLbOutPos
.SetSelectHdl ( LINK( this, ScTabPageSortOptions
, SelOutPosHdl
) );
639 aBtnCopyResult
.SetClickHdl( LINK( this, ScTabPageSortOptions
, EnableHdl
) );
640 aBtnSortUser
.SetClickHdl ( LINK( this, ScTabPageSortOptions
, EnableHdl
) );
641 aBtnTopDown
.SetClickHdl ( LINK( this, ScTabPageSortOptions
, SortDirHdl
) );
642 aBtnLeftRight
.SetClickHdl ( LINK( this, ScTabPageSortOptions
, SortDirHdl
) );
643 aLbLanguage
.SetSelectHdl ( LINK( this, ScTabPageSortOptions
, FillAlgorHdl
) );
645 pViewData
= rSortItem
.GetViewData();
646 pDoc
= pViewData
? pViewData
->GetDocument() : NULL
;
648 DBG_ASSERT( pViewData
, "ViewData not found! :-/" );
650 if ( pViewData
&& pDoc
)
653 ScDBCollection
* pDBColl
= pDoc
->GetDBCollection();
655 String theDbName
= aStrNoName
;
656 const SCTAB nCurTab
= pViewData
->GetTabNo();
657 const formula::FormulaGrammar::AddressConvention eConv
= pDoc
->GetAddressConvention();
660 aLbOutPos
.InsertEntry( aStrUndefined
, 0 );
663 ScAreaNameIterator
aIter( pDoc
);
667 while ( aIter
.Next( aName
, aRange
) )
669 USHORT nInsert
= aLbOutPos
.InsertEntry( aName
);
671 aRange
.aStart
.Format( aRefStr
, SCA_ABS_3D
, pDoc
, eConv
);
672 aLbOutPos
.SetEntryData( nInsert
, new String( aRefStr
) );
675 aLbOutPos
.SelectEntryPos( 0 );
676 aEdOutPos
.SetText( EMPTY_STRING
);
679 * Ueberpruefen, ob es sich bei dem uebergebenen
680 * Bereich um einen Datenbankbereich handelt:
683 ScAddress
aScAddress( rSortData
.nCol1
, rSortData
.nRow1
, nCurTab
);
685 ScAddress( rSortData
.nCol2
, rSortData
.nRow2
, nCurTab
)
686 ).Format( theArea
, SCR_ABS
, pDoc
, eConv
);
691 = pDBColl
->GetDBAtArea( nCurTab
,
692 rSortData
.nCol1
, rSortData
.nRow1
,
693 rSortData
.nCol2
, rSortData
.nRow2
);
696 pDBData
->GetName( theDbName
);
697 aBtnHeader
.Check( pDBData
->HasHeader() );
701 theArea
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
702 theArea
+= theDbName
;
705 //aFtArea.SetText( theArea );
706 //theArea.Insert( aStrAreaLabel, 0 );
707 //aFtAreaLabel.SetText( theArea );
709 aBtnHeader
.SetText( aStrColLabel
);
712 FillUserSortListBox();
714 // get available languages
716 aLbLanguage
.SetLanguageList( LANG_LIST_ALL
| LANG_LIST_ONLY_KNOWN
, FALSE
);
717 aLbLanguage
.InsertLanguage( LANGUAGE_SYSTEM
);
720 //------------------------------------------------------------------------
722 USHORT
* __EXPORT
ScTabPageSortOptions::GetRanges()
727 // -----------------------------------------------------------------------
729 #if ENABLE_LAYOUT_EXPERIMENTAL
731 #endif /* ENABLE_LAYOUT_EXPERIMENTAL */
732 SfxTabPage
* __EXPORT
ScTabPageSortOptions::Create(
734 const SfxItemSet
& rArgSet
)
736 return ( new ScTabPageSortOptions( pParent
, rArgSet
) );
739 // -----------------------------------------------------------------------
741 void __EXPORT
ScTabPageSortOptions::Reset( const SfxItemSet
& /* rArgSet */ )
743 if ( rSortData
.bUserDef
)
745 aBtnSortUser
.Check( TRUE
);
746 aLbSortUser
.Enable();
747 aLbSortUser
.SelectEntryPos( rSortData
.nUserIndex
);
751 aBtnSortUser
.Check( FALSE
);
752 aLbSortUser
.Disable();
753 aLbSortUser
.SelectEntryPos( 0 );
756 aBtnCase
.Check ( rSortData
.bCaseSens
);
757 aBtnFormats
.Check ( rSortData
.bIncludePattern
);
758 aBtnHeader
.Check ( rSortData
.bHasHeader
);
759 aBtnNaturalSort
.Check ( rSortData
.bNaturalSort
);
761 if ( rSortData
.bByRow
)
764 aBtnHeader
.SetText( aStrColLabel
);
768 aBtnLeftRight
.Check();
769 aBtnHeader
.SetText( aStrRowLabel
);
772 LanguageType eLang
= MsLangId::convertLocaleToLanguage( rSortData
.aCollatorLocale
);
773 if ( eLang
== LANGUAGE_DONTKNOW
)
774 eLang
= LANGUAGE_SYSTEM
;
775 aLbLanguage
.SelectLanguage( eLang
);
776 FillAlgorHdl( &aLbLanguage
); // get algorithms, select default
777 if ( rSortData
.aCollatorAlgorithm
.Len() )
778 aLbAlgorithm
.SelectEntry( pColRes
->GetTranslation( rSortData
.aCollatorAlgorithm
) );
780 if ( pDoc
&& !rSortData
.bInplace
)
783 USHORT nFormat
= (rSortData
.nDestTab
!= pViewData
->GetTabNo())
787 theOutPos
.Set( rSortData
.nDestCol
,
789 rSortData
.nDestTab
);
791 theOutPos
.Format( aStr
, nFormat
, pDoc
, pDoc
->GetAddressConvention() );
792 aBtnCopyResult
.Check();
795 aEdOutPos
.SetText( aStr
);
796 EdOutPosModHdl( &aEdOutPos
);
797 aEdOutPos
.GrabFocus();
798 aEdOutPos
.SetSelection( Selection( 0, SELECTION_MAX
) );
802 aBtnCopyResult
.Check( FALSE
);
805 aEdOutPos
.SetText( EMPTY_STRING
);
809 // -----------------------------------------------------------------------
811 BOOL __EXPORT
ScTabPageSortOptions::FillItemSet( SfxItemSet
& rArgSet
)
813 ScSortParam theSortData
= rSortData
;
816 const SfxItemSet
* pExample
= pDlg
->GetExampleSet();
817 const SfxPoolItem
* pItem
;
818 if ( pExample
&& pExample
->GetItemState( nWhichSort
, TRUE
, &pItem
) == SFX_ITEM_SET
)
819 theSortData
= ((const ScSortItem
*)pItem
)->GetSortData();
822 theSortData
.bByRow
= aBtnTopDown
.IsChecked();
823 theSortData
.bHasHeader
= aBtnHeader
.IsChecked();
824 theSortData
.bCaseSens
= aBtnCase
.IsChecked();
825 theSortData
.bNaturalSort
= aBtnNaturalSort
.IsChecked();
826 theSortData
.bIncludePattern
= aBtnFormats
.IsChecked();
827 theSortData
.bInplace
= !aBtnCopyResult
.IsChecked();
828 theSortData
.nDestCol
= theOutPos
.Col();
829 theSortData
.nDestRow
= theOutPos
.Row();
830 theSortData
.nDestTab
= theOutPos
.Tab();
831 theSortData
.bUserDef
= aBtnSortUser
.IsChecked();
832 theSortData
.nUserIndex
= (aBtnSortUser
.IsChecked())
833 ? aLbSortUser
.GetSelectEntryPos()
837 LanguageType eLang
= aLbLanguage
.GetSelectLanguage();
838 theSortData
.aCollatorLocale
= MsLangId::convertLanguageToLocale( eLang
, false );
842 if ( eLang
!= LANGUAGE_SYSTEM
)
844 uno::Sequence
<rtl::OUString
> aAlgos
= pColWrap
->listCollatorAlgorithms(
845 theSortData
.aCollatorLocale
);
846 USHORT nSel
= aLbAlgorithm
.GetSelectEntryPos();
847 if ( nSel
< aAlgos
.getLength() )
850 theSortData
.aCollatorAlgorithm
= sAlg
;
852 rArgSet
.Put( ScSortItem( SCITEM_SORTDATA
, &theSortData
) );
857 // -----------------------------------------------------------------------
859 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
860 // void ScTabPageSortOptions::ActivatePage( const SfxItemSet& rSet )
861 void __EXPORT
ScTabPageSortOptions::ActivatePage()
865 if ( aBtnHeader
.IsChecked() != pDlg
->GetHeaders() )
867 aBtnHeader
.Check( pDlg
->GetHeaders() );
870 if ( aBtnTopDown
.IsChecked() != pDlg
->GetByRows() )
872 aBtnTopDown
.Check( pDlg
->GetByRows() );
873 aBtnLeftRight
.Check( !pDlg
->GetByRows() );
876 aBtnHeader
.SetText( (pDlg
->GetByRows())
882 // -----------------------------------------------------------------------
884 int __EXPORT
ScTabPageSortOptions::DeactivatePage( SfxItemSet
* pSetP
)
886 BOOL bPosInputOk
= TRUE
;
888 if ( aBtnCopyResult
.IsChecked() )
890 String thePosStr
= aEdOutPos
.GetText();
892 xub_StrLen nColonPos
= thePosStr
.Search( ':' );
894 if ( STRING_NOTFOUND
!= nColonPos
)
895 thePosStr
.Erase( nColonPos
);
899 // visible table is default for input without table
900 // must be changed to GetRefTabNo when sorting has RefInput!
901 thePos
.SetTab( pViewData
->GetTabNo() );
904 USHORT nResult
= thePos
.Parse( thePosStr
, pDoc
, pDoc
->GetAddressConvention() );
906 bPosInputOk
= ( SCA_VALID
== (nResult
& SCA_VALID
) );
910 #if !ENABLE_LAYOUT_EXPERIMENTAL
911 ErrorBox( this, WinBits( WB_OK
| WB_DEF_OK
),
912 ScGlobal::GetRscString( STR_INVALID_TABREF
)
914 #endif /* ENABLE_LAYOUT_EXPERIMENTAL */
915 aEdOutPos
.GrabFocus();
916 aEdOutPos
.SetSelection( Selection( 0, SELECTION_MAX
) );
917 theOutPos
.Set(0,0,0);
921 aEdOutPos
.SetText( thePosStr
);
926 if ( pDlg
&& bPosInputOk
)
928 pDlg
->SetHeaders( aBtnHeader
.IsChecked() );
929 pDlg
->SetByRows ( aBtnTopDown
.IsChecked() );
932 if ( pSetP
&& bPosInputOk
)
933 FillItemSet( *pSetP
);
935 return bPosInputOk
? SfxTabPage::LEAVE_PAGE
: SfxTabPage::KEEP_PAGE
;
938 // -----------------------------------------------------------------------
940 void ScTabPageSortOptions::FillUserSortListBox()
942 ScUserList
* pUserLists
= ScGlobal::GetUserList();
947 USHORT nCount
= pUserLists
->GetCount();
949 for ( USHORT i
=0; i
<nCount
; i
++ )
950 aLbSortUser
.InsertEntry( (*pUserLists
)[i
]->GetString() );
954 // -----------------------------------------------------------------------
957 IMPL_LINK( ScTabPageSortOptions
, EnableHdl
, CheckBox
*, pBox
)
959 if ( pBox
== &aBtnCopyResult
)
961 if ( pBox
->IsChecked() )
965 aEdOutPos
.GrabFocus();
973 else if ( pBox
== &aBtnSortUser
)
975 if ( pBox
->IsChecked() )
977 aLbSortUser
.Enable();
978 aLbSortUser
.GrabFocus();
981 aLbSortUser
.Disable();
986 // -----------------------------------------------------------------------
988 IMPL_LINK( ScTabPageSortOptions
, SelOutPosHdl
, ListBox
*, pLb
)
990 if ( pLb
== &aLbOutPos
)
993 USHORT nSelPos
= aLbOutPos
.GetSelectEntryPos();
996 aString
= *(String
*)aLbOutPos
.GetEntryData( nSelPos
);
998 aEdOutPos
.SetText( aString
);
1003 // -----------------------------------------------------------------------
1005 IMPL_LINK( ScTabPageSortOptions
, SortDirHdl
, RadioButton
*, pBtn
)
1007 if ( pBtn
== &aBtnTopDown
)
1009 aBtnHeader
.SetText( aStrColLabel
);
1011 else if ( pBtn
== &aBtnLeftRight
)
1013 aBtnHeader
.SetText( aStrRowLabel
);
1018 // -----------------------------------------------------------------------
1020 void __EXPORT
ScTabPageSortOptions::EdOutPosModHdl( Edit
* pEd
)
1022 if ( pEd
== &aEdOutPos
)
1024 String theCurPosStr
= aEdOutPos
.GetText();
1025 USHORT nResult
= ScAddress().Parse( theCurPosStr
, pDoc
, pDoc
->GetAddressConvention() );
1027 if ( SCA_VALID
== (nResult
& SCA_VALID
) )
1029 String
* pStr
= NULL
;
1030 BOOL bFound
= FALSE
;
1032 USHORT nCount
= aLbOutPos
.GetEntryCount();
1034 for ( i
=2; i
<nCount
&& !bFound
; i
++ )
1036 pStr
= (String
*)aLbOutPos
.GetEntryData( i
);
1037 bFound
= (theCurPosStr
== *pStr
);
1041 aLbOutPos
.SelectEntryPos( --i
);
1043 aLbOutPos
.SelectEntryPos( 0 );
1048 // -----------------------------------------------------------------------
1050 IMPL_LINK( ScTabPageSortOptions
, FillAlgorHdl
, void *, EMPTYARG
)
1052 aLbAlgorithm
.SetUpdateMode( FALSE
);
1053 aLbAlgorithm
.Clear();
1055 LanguageType eLang
= aLbLanguage
.GetSelectLanguage();
1056 if ( eLang
== LANGUAGE_SYSTEM
)
1058 // for LANGUAGE_SYSTEM no algorithm can be selected because
1059 // it wouldn't necessarily exist for other languages
1060 // -> leave list box empty if LANGUAGE_SYSTEM is selected
1061 aFtAlgorithm
.Enable( FALSE
); // nothing to select
1062 aLbAlgorithm
.Enable( FALSE
); // nothing to select
1066 lang::Locale
aLocale( MsLangId::convertLanguageToLocale( eLang
));
1067 uno::Sequence
<rtl::OUString
> aAlgos
= pColWrap
->listCollatorAlgorithms( aLocale
);
1069 long nCount
= aAlgos
.getLength();
1070 const rtl::OUString
* pArray
= aAlgos
.getConstArray();
1071 for (long i
=0; i
<nCount
; i
++)
1073 String sAlg
= pArray
[i
];
1074 String sUser
= pColRes
->GetTranslation( sAlg
);
1075 aLbAlgorithm
.InsertEntry( sUser
, LISTBOX_APPEND
);
1077 aLbAlgorithm
.SelectEntryPos( 0 ); // first entry is default
1078 aFtAlgorithm
.Enable( nCount
> 1 ); // enable only if there is a choice
1079 aLbAlgorithm
.Enable( nCount
> 1 ); // enable only if there is a choice
1082 aLbAlgorithm
.SetUpdateMode( TRUE
);