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: srtdlg.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_sw.hxx"
33 #ifdef SW_DLLIMPLEMENTATION
34 #undef SW_DLLIMPLEMENTATION
39 #ifndef _MSGBOX_HXX //autogen
40 #include <vcl/msgbox.hxx>
42 #include <svtools/intitem.hxx>
43 #include <svtools/eitem.hxx>
44 #include <sfx2/dispatch.hxx>
45 #include <svx/svxids.hrc>
46 #include <svx/unolingu.hxx>
47 #include <svx/svxdlg.hxx>
48 #include <svx/dialogs.hrc>
49 #include <unotools/collatorwrapper.hxx>
50 #include <svtools/collatorres.hxx>
57 #include <swtable.hxx>
60 #include <sfx2/request.hxx>
63 SV_IMPL_PTRARR( _FndBoxes
, _FndBox
* )
64 SV_IMPL_PTRARR( _FndLines
, _FndLine
* )
66 static BOOL bCheck1
= TRUE
;
67 static BOOL bCheck2
= FALSE
;
68 static BOOL bCheck3
= FALSE
;
70 static USHORT nCol1
= 1;
71 static USHORT nCol2
= 1;
72 static USHORT nCol3
= 1;
74 static USHORT nType1
= 0;
75 static USHORT nType2
= 0;
76 static USHORT nType3
= 0;
78 static USHORT nLang
= LANGUAGE_NONE
;
80 static BOOL bAsc1
= TRUE
;
81 static BOOL bAsc2
= TRUE
;
82 static BOOL bAsc3
= TRUE
;
83 static BOOL bCol
= FALSE
;
84 static BOOL bCsSens
= FALSE
;
86 static sal_Unicode cDeli
= '\t';
88 using namespace ::com::sun::star::lang
;
89 using namespace ::com::sun::star::uno
;
90 using ::rtl::OUString
;
93 void lcl_ClearLstBoxAndDelUserData( ListBox
& rLstBox
)
96 for( USHORT n
= 0, nEnd
= rLstBox
.GetEntryCount(); n
< nEnd
; ++n
)
97 if( 0 != ( pDel
= rLstBox
.GetEntryData( n
)) )
102 /*--------------------------------------------------------------------
103 Beschreibung: Fuer Tabellenselektion sel. Zeilen und Spalten
105 --------------------------------------------------------------------*/
108 BOOL
lcl_GetSelTbl( SwWrtShell
&rSh
, USHORT
& rX
, USHORT
& rY
)
110 const SwTableNode
* pTblNd
= rSh
.IsCrsrInTbl();
114 _FndBox
aFndBox( 0, 0 );
116 // suche alle Boxen / Lines
118 SwSelBoxes aSelBoxes
;
119 ::GetTblSel( rSh
, aSelBoxes
);
120 _FndPara
aPara( aSelBoxes
, &aFndBox
);
121 const SwTable
& rTbl
= pTblNd
->GetTable();
122 ((SwTableLines
&)rTbl
.GetTabLines()).ForEach( &_FndLineCopyCol
, &aPara
);
124 rX
= aFndBox
.GetLines().Count();
128 rY
= aFndBox
.GetLines()[0]->GetBoxes().Count();
132 /*--------------------------------------------------------------------
133 Beschreibung: Init-Liste
134 --------------------------------------------------------------------*/
136 SwSortDlg::SwSortDlg(Window
* pParent
, SwWrtShell
&rShell
) :
138 SvxStandardDialog(pParent
, SW_RES(DLG_SORTING
)),
139 aColLbl(this, SW_RES(FT_COL
)),
140 aTypLbl(this, SW_RES(FT_KEYTYP
)),
141 aDirLbl(this, SW_RES(FT_DIR
)),
143 aDirFL(this, SW_RES(FL_DIR
)),
145 aKeyCB1(this, SW_RES(CB_KEY1
)),
146 aColEdt1(this, SW_RES(ED_KEY1
)),
147 aTypDLB1(this, SW_RES(DLB_KEY1
)),
148 aSortUpRB(this, SW_RES(RB_UP
)),
149 aSortDnRB(this, SW_RES(RB_DN
)),
151 aKeyCB2(this, SW_RES(CB_KEY2
)),
152 aColEdt2(this, SW_RES(ED_KEY2
)),
153 aTypDLB2(this, SW_RES(DLB_KEY2
)),
154 aSortUp2RB(this, SW_RES(RB_UP2
)),
155 aSortDn2RB(this, SW_RES(RB_DN2
)),
157 aKeyCB3(this, SW_RES(CB_KEY3
)),
158 aColEdt3(this, SW_RES(ED_KEY3
)),
159 aTypDLB3(this, SW_RES(DLB_KEY3
)),
160 aSortUp3RB(this, SW_RES(RB_UP3
)),
161 aSortDn3RB(this, SW_RES(RB_DN3
)),
163 aSortFL(this, SW_RES(FL_SORT_2
)),
164 aColumnRB(this, SW_RES(RB_COL
)),
165 aRowRB(this, SW_RES(RB_ROW
)),
167 aDelimFL(this, SW_RES(FL_DELIM
)),
168 aDelimTabRB(this, SW_RES(RB_TAB
)),
169 aDelimFreeRB(this, SW_RES(RB_TABCH
)),
170 aDelimEdt(this, SW_RES(ED_TABCH
)),
171 aDelimPB(this, SW_RES( PB_DELIM
)),
173 aLangFL(this, SW_RES( FL_LANG
)),
174 aLangLB(this, SW_RES( LB_LANG
)),
176 aSortOptFL(this, SW_RES( FL_SORT
)),
177 aCaseCB(this, SW_RES( CB_CASE
)),
179 aOkBtn(this, SW_RES(BT_OK
)),
180 aCancelBtn(this, SW_RES(BT_CANCEL
)),
181 aHelpBtn(this, SW_RES(BT_HELP
)),
183 aColTxt( SW_RES(STR_COL
)),
184 aRowTxt( SW_RES(STR_ROW
)),
185 aNumericTxt( SW_RES(STR_NUMERIC
)),
191 aDelimEdt
.SetMaxTextLen( 1 );
192 if(rSh
.GetSelectionType() &
193 (nsSelectionType::SEL_TBL
|nsSelectionType::SEL_TBL_CELLS
) )
195 aColumnRB
.Check(bCol
);
196 aColLbl
.SetText(bCol
? aRowTxt
: aColTxt
);
198 aDelimTabRB
.Enable(FALSE
);
199 aDelimFreeRB
.Enable(FALSE
);
200 aDelimEdt
.Enable(FALSE
);
204 aColumnRB
.Enable(FALSE
);
206 aColLbl
.SetText(aColTxt
);
210 Link aLk
= LINK(this,SwSortDlg
, CheckHdl
);
211 aKeyCB1
.SetClickHdl( aLk
);
212 aKeyCB2
.SetClickHdl( aLk
);
213 aKeyCB3
.SetClickHdl( aLk
);
214 aColumnRB
.SetClickHdl( aLk
);
215 aRowRB
.SetClickHdl( aLk
);
217 aLk
= LINK(this,SwSortDlg
, DelimHdl
);
218 aDelimFreeRB
.SetClickHdl(aLk
);
219 aDelimTabRB
.SetClickHdl(aLk
);
221 aDelimPB
.SetClickHdl( LINK( this, SwSortDlg
, DelimCharHdl
));
223 aKeyCB1
.Check(bCheck1
);
224 aKeyCB2
.Check(bCheck2
);
225 aKeyCB3
.Check(bCheck3
);
227 aColEdt1
.SetValue(nCol1
);
228 aColEdt2
.SetValue(nCol2
);
229 aColEdt3
.SetValue(nCol3
);
231 // first initialise the language, then select the
232 if( LANGUAGE_NONE
== nLang
|| LANGUAGE_DONTKNOW
== nLang
)
233 nLang
= (USHORT
)GetAppLanguage();
235 aLangLB
.SetLanguageList( LANG_LIST_ALL
| LANG_LIST_ONLY_KNOWN
, TRUE
, FALSE
);
236 aLangLB
.SelectLanguage( nLang
);
239 aLangLB
.SetSelectHdl( LINK( this, SwSortDlg
, LanguageHdl
));
241 aSortUpRB
.Check(bAsc1
);
242 aSortDnRB
.Check(!bAsc1
);
243 aSortUp2RB
.Check(bAsc2
);
244 aSortDn2RB
.Check(!bAsc2
);
245 aSortUp3RB
.Check(bAsc3
);
246 aSortDn3RB
.Check(!bAsc3
);
248 aCaseCB
.Check( bCsSens
);
250 aDelimTabRB
.Check(cDeli
== '\t');
251 if(!aDelimTabRB
.IsChecked())
253 aDelimEdt
.SetText(cDeli
);
254 aDelimFreeRB
.Check(TRUE
);
255 DelimHdl(&aDelimFreeRB
);
258 DelimHdl(&aDelimTabRB
);
261 if( ::lcl_GetSelTbl( rSh
, nX
, nY
) )
263 USHORT nMax
= aRowRB
.IsChecked()? nY
: nX
;
264 aColEdt1
.SetMax(nMax
);
265 aColEdt2
.SetMax(nMax
);
266 aColEdt3
.SetMax(nMax
);
270 SwSortDlg::~SwSortDlg()
272 ::lcl_ClearLstBoxAndDelUserData( aTypDLB1
);
273 ::lcl_ClearLstBoxAndDelUserData( aTypDLB2
);
274 ::lcl_ClearLstBoxAndDelUserData( aTypDLB3
);
278 sal_Unicode
SwSortDlg::GetDelimChar() const
280 sal_Unicode cRet
= '\t';
281 if( !aDelimTabRB
.IsChecked() )
283 String
aTmp( aDelimEdt
.GetText() );
285 cRet
= aTmp
.GetChar( 0 );
290 /*--------------------------------------------------------------------
291 Beschreibung: An die Core weiterreichen
292 --------------------------------------------------------------------*/
293 void SwSortDlg::Apply()
295 // Alte Einstellung speichern
297 bCheck1
= aKeyCB1
.IsChecked();
298 bCheck2
= aKeyCB2
.IsChecked();
299 bCheck3
= aKeyCB3
.IsChecked();
301 nCol1
= (USHORT
)aColEdt1
.GetValue();
302 nCol2
= (USHORT
)aColEdt2
.GetValue();
303 nCol3
= (USHORT
)aColEdt3
.GetValue();
305 nType1
= aTypDLB1
.GetSelectEntryPos();
306 nType2
= aTypDLB2
.GetSelectEntryPos();
307 nType3
= aTypDLB3
.GetSelectEntryPos();
309 bAsc1
= aSortUpRB
.IsChecked();
310 bAsc2
= aSortUp2RB
.IsChecked();
311 bAsc3
= aSortUp3RB
.IsChecked();
312 bCol
= aColumnRB
.IsChecked();
313 nLang
= aLangLB
.GetSelectLanguage();
314 cDeli
= GetDelimChar();
315 bCsSens
= aCaseCB
.IsChecked();
318 SwSortOptions aOptions
;
321 String
sEntry( aTypDLB1
.GetSelectEntry() );
322 if( sEntry
== aNumericTxt
)
324 else if( 0 != (pUserData
= aTypDLB1
.GetEntryData(
325 aTypDLB1
.GetSelectEntryPos())) )
326 sEntry
= *(String
*)pUserData
;
328 SwSortKey
*pKey
= new SwSortKey( nCol1
, sEntry
,
329 bAsc1
? SRT_ASCENDING
: SRT_DESCENDING
);
330 aOptions
.aKeys
.C40_INSERT(SwSortKey
, pKey
, aOptions
.aKeys
.Count());
335 String
sEntry( aTypDLB2
.GetSelectEntry() );
336 if( sEntry
== aNumericTxt
)
338 else if( 0 != (pUserData
= aTypDLB2
.GetEntryData(
339 aTypDLB2
.GetSelectEntryPos())) )
340 sEntry
= *(String
*)pUserData
;
342 SwSortKey
*pKey
= new SwSortKey( nCol2
, sEntry
,
343 bAsc2
? SRT_ASCENDING
: SRT_DESCENDING
);
344 aOptions
.aKeys
.C40_INSERT( SwSortKey
, pKey
, aOptions
.aKeys
.Count() );
349 String
sEntry( aTypDLB3
.GetSelectEntry() );
350 if( sEntry
== aNumericTxt
)
352 else if( 0 != (pUserData
= aTypDLB3
.GetEntryData(
353 aTypDLB3
.GetSelectEntryPos())) )
354 sEntry
= *(String
*)pUserData
;
356 SwSortKey
*pKey
= new SwSortKey( nCol3
, sEntry
,
357 bAsc3
? SRT_ASCENDING
: SRT_DESCENDING
);
358 aOptions
.aKeys
.C40_INSERT( SwSortKey
, pKey
, aOptions
.aKeys
.Count() );
361 aOptions
.eDirection
= bCol
? SRT_COLUMNS
: SRT_ROWS
;
362 aOptions
.cDeli
= cDeli
;
363 aOptions
.nLanguage
= nLang
;
364 aOptions
.bTable
= rSh
.IsTableMode();
365 aOptions
.bIgnoreCase
= !bCsSens
;
369 SwWait
aWait( *rSh
.GetView().GetDocShell(), TRUE
);
370 rSh
.StartAllAction();
371 if( 0 != (bRet
= rSh
.Sort( aOptions
)))
377 InfoBox( this->GetParent(), SW_RES(MSG_SRTERR
)).Execute();
380 /* -----------------30.09.98 10:03-------------------
382 * --------------------------------------------------*/
383 IMPL_LINK( SwSortDlg
, DelimHdl
, RadioButton
*, pButton
)
385 BOOL bEnable
= pButton
== &aDelimFreeRB
&& aDelimFreeRB
.IsEnabled();
386 aDelimEdt
.Enable( bEnable
);
387 aDelimPB
.Enable( bEnable
);
391 IMPL_LINK( SwSortDlg
, DelimCharHdl
, PushButton
*, EMPTYARG
)
393 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
396 SfxAllItemSet
aSet( rSh
.GetAttrPool() );
397 aSet
.Put( SfxInt32Item( SID_ATTR_CHAR
, GetDelimChar() ) );
398 SfxAbstractDialog
* pMap
= pFact
->CreateSfxDialog( &aDelimPB
, aSet
,
399 rSh
.GetView().GetViewFrame()->GetFrame()->GetFrameInterface(), RID_SVXDLG_CHARMAP
);
400 if( RET_OK
== pMap
->Execute() )
402 SFX_ITEMSET_ARG( pMap
->GetOutputItemSet(), pItem
, SfxInt32Item
, SID_ATTR_CHAR
, FALSE
);
404 aDelimEdt
.SetText( sal_Unicode ( pItem
->GetValue() ) );
413 IMPL_LINK( SwSortDlg
, CheckHdl
, CheckBox
*, pCheck
)
415 if( pCheck
== ( CheckBox
* ) &aRowRB
)
417 aColLbl
.SetText(aColTxt
);
423 else if( pCheck
== ( CheckBox
* ) &aColumnRB
)
425 aColLbl
.SetText(aRowTxt
);
430 else if(!aKeyCB1
.IsChecked() &&
431 !aKeyCB2
.IsChecked() &&
432 !aKeyCB3
.IsChecked())
437 IMPL_LINK( SwSortDlg
, LanguageHdl
, ListBox
*, pLBox
)
439 Locale
aLcl( SvxCreateLocale( aLangLB
.GetSelectLanguage() ) );
440 Sequence
< OUString
> aSeq(
441 GetAppCollator().listCollatorAlgorithms( aLcl
));
444 pColRes
= new CollatorRessource();
446 const USHORT nLstBoxCnt
= 3;
447 ListBox
* aLstArr
[ nLstBoxCnt
] = { &aTypDLB1
, &aTypDLB2
, &aTypDLB3
};
448 USHORT
* aTypeArr
[ nLstBoxCnt
] = { &nType1
, &nType2
, &nType3
};
449 String aOldStrArr
[ nLstBoxCnt
];
453 for( n
= 0; n
< nLstBoxCnt
; ++n
)
455 ListBox
* pL
= aLstArr
[ n
];
456 if( 0 != (pUserData
= pL
->GetEntryData( pL
->GetSelectEntryPos())) )
457 aOldStrArr
[ n
] = *(String
*)pUserData
;
458 ::lcl_ClearLstBoxAndDelUserData( *pL
);
463 for( long nCnt
= 0, nEnd
= aSeq
.getLength(); nCnt
<= nEnd
; ++nCnt
)
466 sUINm
= pColRes
->GetTranslation( sAlg
= aSeq
[ nCnt
] );
468 sUINm
= sAlg
= aNumericTxt
;
470 for( n
= 0; n
< nLstBoxCnt
; ++n
)
472 ListBox
* pL
= aLstArr
[ n
];
473 nInsPos
= pL
->InsertEntry( sUINm
);
474 pL
->SetEntryData( nInsPos
, new String( sAlg
));
475 if( pLBox
&& sAlg
== aOldStrArr
[ n
] )
476 pL
->SelectEntryPos( nInsPos
);
480 for( n
= 0; n
< nLstBoxCnt
; ++n
)
482 ListBox
* pL
= aLstArr
[ n
];
484 pL
->SelectEntryPos( *aTypeArr
[n
] );
485 else if( LISTBOX_ENTRY_NOTFOUND
== pL
->GetSelectEntryPos() )
486 pL
->SelectEntryPos( 0 );