diff options
author | Albert Thuswaldner <albert.thuswaldner@gmail.com> | 2012-05-21 23:04:12 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2012-06-05 03:08:59 +0200 |
commit | 35b1d1a9b47abb8cb3b45d4c6351d1c2b86b379f (patch) | |
tree | 9541c06a7337548c6c03ef8daa79c5113b179dc7 | |
parent | 475bafc4be1b113095e1b0dcacfd565374777f8d (diff) |
fdo#45747 remove the limitation to 3 sort entries in calc part2
Change-Id: I699c424f536b0096b35d3db3aee371793e9e56c4
-rw-r--r-- | sc/Library_scui.mk | 1 | ||||
-rw-r--r-- | sc/inc/helpids.h | 1 | ||||
-rw-r--r-- | sc/inc/sc.hrc | 5 | ||||
-rw-r--r-- | sc/source/ui/dbgui/sortkeydlg.cxx | 196 | ||||
-rw-r--r-- | sc/source/ui/dbgui/tpsort.cxx | 255 | ||||
-rw-r--r-- | sc/source/ui/inc/sortdlg.hrc | 21 | ||||
-rw-r--r-- | sc/source/ui/inc/sortkeydlg.hxx | 107 | ||||
-rw-r--r-- | sc/source/ui/inc/tpsort.hxx | 28 | ||||
-rw-r--r-- | sc/source/ui/src/sortdlg.src | 142 |
9 files changed, 483 insertions, 273 deletions
diff --git a/sc/Library_scui.mk b/sc/Library_scui.mk index fbb84d69d19f..19adbb21145f 100644 --- a/sc/Library_scui.mk +++ b/sc/Library_scui.mk @@ -72,6 +72,7 @@ $(eval $(call gb_Library_add_exception_objects,scui,\ sc/source/ui/dbgui/scuiasciiopt \ sc/source/ui/dbgui/scuiimoptdlg \ sc/source/ui/dbgui/sortdlg \ + sc/source/ui/dbgui/sortkeydlg \ sc/source/ui/dbgui/subtdlg \ sc/source/ui/dbgui/textimportoptions \ sc/source/ui/dbgui/tpsort \ diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h index 8d41ab7754ad..7c5955c240c4 100644 --- a/sc/inc/helpids.h +++ b/sc/inc/helpids.h @@ -88,6 +88,7 @@ #define HID_SC_FORM_ARGS "SC_HID_SC_FORM_ARGS" #define HID_SCPAGE_SORT_FIELDS "SC_HID_SCPAGE_SORT_FIELDS" #define HID_SCPAGE_SORT_OPTIONS "SC_HID_SCPAGE_SORT_OPTIONS" +#define HID_SCPAGE_SORTKEY_FIELDS "SC_HID_SCPAGE_SORTKEY_FIELDS" #define HID_SCPAGE_SUBT_OPTIONS "SC_HID_SCPAGE_SUBT_OPTIONS" #define HID_SCPAGE_SUBT_GROUP "SC_HID_SCPAGE_SUBT_GROUP" #define HID_SCPAGE_PROTECTION "SC_HID_SCPAGE_PROTECTION" diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index 936de6ee76d5..1059d9c7ba5c 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -1229,8 +1229,9 @@ #define RID_POPUP_FILTER (SC_DIALOGS_START + 153) #define RID_SCDLG_TAB_BG_COLOR (SC_DIALOGS_START + 154) #define RID_SCDLG_FORMULA_CALCOPTIONS (SC_DIALOGS_START + 155) - -#define SC_DIALOGS_END (SC_DIALOGS_START + 156) +#define RID_SCPAGE_SORTKEY_FIELDS (SC_DIALOGS_START + 156) +#define RID_SCDLG_SORTKEY (SC_DIALOGS_START + 157) +#define SC_DIALOGS_END (SC_DIALOGS_START + 158) #ifndef STD_MASKCOLOR #define STD_MASKCOLOR Color { Red = 0xFF00; Green = 0x0000; Blue = 0xFF00; } diff --git a/sc/source/ui/dbgui/sortkeydlg.cxx b/sc/source/ui/dbgui/sortkeydlg.cxx new file mode 100644 index 000000000000..0801b8de789c --- /dev/null +++ b/sc/source/ui/dbgui/sortkeydlg.cxx @@ -0,0 +1,196 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Albert Thuswaldner <albert.thuswaldner@gmail.com> (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#include "sortkeydlg.hxx" +#include "sortdlg.hxx" +#include "sortdlg.hrc" + +// ======================================================================= + +ScSortKeyItem::ScSortKeyItem( Window* pParent ) : + // + aFlSort ( pParent, ScResId( FL_SORT ) ), + aLbSort ( pParent, ScResId( LB_SORT ) ), + aBtnUp ( pParent, ScResId( BTN_UP ) ), + aBtnDown ( pParent, ScResId( BTN_DOWN ) ) +{ +} + +// ----------------------------------------------------------------------- + +void ScSortKeyItem::DisableField() +{ + aFlSort.Disable(); + aLbSort.Disable(); + aBtnUp.Disable(); + aBtnDown.Disable(); +} + +// ----------------------------------------------------------------------- + +void ScSortKeyItem::EnableField() +{ + aFlSort.Enable(); + aLbSort.Enable(); + aBtnUp.Enable(); + aBtnDown.Enable(); +} + +// ======================================================================= + +ScSortKeyWindow::ScSortKeyWindow( Window* pParent, const ResId& rResId, ScSortKeyItems& rSortKeyItems ) : + Window( pParent, rResId ), + // + aFlSort ( this, ScResId( FL_SORT ) ), + aLbSort ( this, ScResId( LB_SORT ) ), + aBtnUp ( this, ScResId( BTN_UP ) ), + aBtnDown ( this, ScResId( BTN_DOWN ) ), + // + nScrollPos ( 0 ), + mrSortKeyItems( rSortKeyItems ) +{ + aFlSort.Hide(); + aLbSort.Hide(); + aBtnUp.Hide(); + aBtnDown.Hide(); + + nItemHeight = aBtnDown.GetPosPixel().Y() + aBtnDown.GetSizePixel().Height(); +} + +// ----------------------------------------------------------------------- + +ScSortKeyWindow::~ScSortKeyWindow() +{ +} + +// ----------------------------------------------------------------------- + +void ScSortKeyWindow::AddSortKey( sal_uInt16 nItemNumber ) +{ + ScSortKeyItem* pSortKeyItem = new ScSortKeyItem( this ); + + // Set Sort key number + String aLine = pSortKeyItem->aFlSort.GetText(); + aLine += String::CreateFromInt32( nItemNumber ); + pSortKeyItem->aFlSort.SetText( aLine ); + + mrSortKeyItems.push_back( pSortKeyItem ); + + Window* pWindows[] = { &aFlSort, &aLbSort, &aBtnUp, &aBtnDown, NULL }; + + Window* pNewWindows[] = { &pSortKeyItem->aFlSort, &pSortKeyItem->aLbSort, + &pSortKeyItem->aBtnUp, &pSortKeyItem->aBtnDown, NULL }; + Window** pCurrent = pWindows; + Window** pNewCurrent = pNewWindows; + while ( *pCurrent ) + { + Size aSize = (*pCurrent)->GetSizePixel(); + Point aPos = (*pCurrent)->GetPosPixel(); + aPos.Y() += ( nItemNumber - 1 ) * GetItemHeight(); + aPos.Y() += nScrollPos; + (*pNewCurrent)->SetPosSizePixel( aPos, aSize ); + (*pNewCurrent)->Show(); + pCurrent++; + pNewCurrent++; + } +} + +// ----------------------------------------------------------------------- + +void ScSortKeyWindow::DoScroll( sal_Int32 nNewPos ) +{ + nScrollPos += nNewPos; + ScSortKeyItems::iterator pIter; + for ( pIter = mrSortKeyItems.begin(); pIter != mrSortKeyItems.end(); ++pIter ) + { + Window* pNewWindows[] = { &pIter->aFlSort, &pIter->aLbSort, + &pIter->aBtnUp, &pIter->aBtnDown, NULL }; + + Window** pCurrent = pNewWindows; + while ( *pCurrent ) + { + Point aPos = (*pCurrent)->GetPosPixel(); + aPos.Y() += nNewPos; + (*pCurrent)->SetPosPixel( aPos ); + pCurrent++; + } + } +} + +// ======================================================================= + +ScSortKeyCtrl::ScSortKeyCtrl( Window* pParent, const ScResId& rResId, ScSortKeyItems& rItems ): + Control( pParent, rResId), + // + aSortWin ( this, ResId( WIN_MANAGESORTKEY, *rResId.GetResMgr() ), rItems ), + aVertScroll ( this, ResId( SB_SORT, *rResId.GetResMgr() ) ), + nThumbPos ( 0 ) +{ + aVertScroll.EnableDrag(); + aVertScroll.Show(); + + FreeResource(); + + aVertScroll.SetRangeMin( 0 ); + sal_Int32 nScrollOffset = aSortWin.GetItemHeight(); + sal_Int32 nVisibleItems = aSortWin.GetSizePixel().Height() / nScrollOffset; + aVertScroll.SetRangeMax( nVisibleItems ); + aVertScroll.SetPageSize( nVisibleItems - 1 ); + aVertScroll.SetVisibleSize( nVisibleItems ); + + Link aScrollLink = LINK( this, ScSortKeyCtrl, ScrollHdl ); + aVertScroll.SetScrollHdl( aScrollLink ); +} + +// ----------------------------------------------------------------------- + +ScSortKeyCtrl::~ScSortKeyCtrl() +{ +} + +// ----------------------------------------------------------------------- + +IMPL_LINK( ScSortKeyCtrl, ScrollHdl, ScrollBar*, pScrollBar ) +{ + sal_Int32 nOffset = aSortWin.GetItemHeight(); + nOffset *= ( nThumbPos - pScrollBar->GetThumbPos() ); + nThumbPos = pScrollBar->GetThumbPos(); + aSortWin.DoScroll( nOffset ); + return 0; +} + +// ----------------------------------------------------------------------- + +void ScSortKeyCtrl::AddSortKey( sal_uInt16 nItem ) +{ + aVertScroll.SetRangeMax( nItem ); + aVertScroll.DoScroll( nItem ); + aSortWin.AddSortKey( nItem ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx index 10caedc9dfcd..1afe9bd04877 100644 --- a/sc/source/ui/dbgui/tpsort.cxx +++ b/sc/source/ui/dbgui/tpsort.cxx @@ -49,6 +49,8 @@ #include "sc.hrc" // -> Slot IDs #include "globstr.hrc" +#include "sortkeydlg.hxx" + #include "sortdlg.hxx" #include "sortdlg.hrc" @@ -89,21 +91,6 @@ ScTabPageSortFields::ScTabPageSortFields( Window* pParent, ScResId( RID_SCPAGE_SORT_FIELDS ), rArgSet ), // - aFlSort1 ( this, ScResId( FL_SORT1 ) ), - aLbSort1 ( this, ScResId( LB_SORT1 ) ), - aBtnUp1 ( this, ScResId( BTN_UP1 ) ), - aBtnDown1 ( this, ScResId( BTN_DOWN1 ) ), - // - aFlSort2 ( this, ScResId( FL_SORT2 ) ), - aLbSort2 ( this, ScResId( LB_SORT2 ) ), - aBtnUp2 ( this, ScResId( BTN_UP2 ) ), - aBtnDown2 ( this, ScResId( BTN_DOWN2 ) ), - // - aFlSort3 ( this, ScResId( FL_SORT3 ) ), - aLbSort3 ( this, ScResId( LB_SORT3 ) ), - aBtnUp3 ( this, ScResId( BTN_UP3 ) ), - aBtnDown3 ( this, ScResId( BTN_DOWN3 ) ), - aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ), aStrColumn ( ScResId( SCSTR_COLUMN ) ), aStrRow ( ScResId( SCSTR_ROW ) ), @@ -111,14 +98,15 @@ ScTabPageSortFields::ScTabPageSortFields( Window* pParent, nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ), pDlg ( (ScSortDlg*)(GetParent()->GetParent()) ), pViewData ( NULL ), - rSortData ( ((const ScSortItem&) + aSortData ( ((const ScSortItem&) rArgSet.Get( nWhichSort )). GetSortData() ), nFieldCount ( 0 ), nSortKeyCount ( DEFSORT ), nCurrentOffset ( 0 ), bHasHeader ( false ), - bSortByRows ( false ) + bSortByRows ( false ), + maSortKeyCtrl ( this, ScResId( CTRL_MANAGESORTKEY ), maSortKeyItems ) { Init(); FreeResource(); @@ -130,6 +118,7 @@ ScTabPageSortFields::ScTabPageSortFields( Window* pParent, ScTabPageSortFields::~ScTabPageSortFields() { } + // ----------------------------------------------------------------------- void ScTabPageSortFields::Init() @@ -138,38 +127,18 @@ void ScTabPageSortFields::Init() GetItemSet().Get( nWhichSort ); pViewData = rSortItem.GetViewData(); - OSL_ENSURE( pViewData, "ViewData not found!" ); - // Create local copy of ScParam - - // Connect handlers and widgets nFieldArr.push_back( 0 ); nFirstCol = 0; nFirstRow = 0; - aLbSort1.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) ); - aLbSort2.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) ); - aLbSort3.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) ); - aLbSort1.Clear(); - aLbSort2.Clear(); - aLbSort3.Clear(); - - aLbSortArr.push_back( &aLbSort1 ); - aLbSortArr.push_back( &aLbSort2 ); - aLbSortArr.push_back( &aLbSort3 ); - - aBtnUp.push_back( &aBtnUp1 ); - aBtnUp.push_back( &aBtnUp2 ); - aBtnUp.push_back( &aBtnUp3 ); - - aBtnDown.push_back( &aBtnDown1 ); - aBtnDown.push_back( &aBtnDown2 ); - aBtnDown.push_back( &aBtnDown3 ); - - aFlArr.push_back( &aFlSort1 ); - aFlArr.push_back( &aFlSort2 ); - aFlArr.push_back( &aFlSort3 ); + // Create three sort key dialogs by default + for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) + { + maSortKeyCtrl.AddSortKey(i+1); + maSortKeyItems[i].aLbSort.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) ); + } } // ----------------------------------------------------------------------- @@ -184,63 +153,65 @@ SfxTabPage* ScTabPageSortFields::Create( Window* pParent, void ScTabPageSortFields::Reset( const SfxItemSet& /* rArgSet */ ) { - bSortByRows = rSortData.bByRow; - bHasHeader = rSortData.bHasHeader; + bSortByRows = aSortData.bByRow; + bHasHeader = aSortData.bHasHeader; - if ( aLbSort1.GetEntryCount() == 0 ) + if ( maSortKeyItems[0].aLbSort.GetEntryCount() == 0 ) FillFieldLists(0); // ListBox selection: - if ( rSortData.maKeyState[0].bDoSort ) + if ( aSortData.maKeyState[0].bDoSort ) { for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) { - if ( rSortData.maKeyState[i].bDoSort ) + if ( aSortData.maKeyState[i].bDoSort ) { - aLbSortArr[i]->SelectEntryPos( GetFieldSelPos( - rSortData.maKeyState[i].nField ) ); + maSortKeyItems[i].aLbSort.SelectEntryPos( GetFieldSelPos( + aSortData.maKeyState[i].nField ) ); - (rSortData.maKeyState[i].bAscending) - ? aBtnUp[i]->Check() - : aBtnDown[i]->Check(); + (aSortData.maKeyState[i].bAscending) + ? maSortKeyItems[i].aBtnUp.Check() + : maSortKeyItems[i].aBtnDown.Check(); } else { - aLbSortArr[i]->SelectEntryPos( 0 ); // Select none - aBtnUp[i]->Check(); + maSortKeyItems[i].aLbSort.SelectEntryPos( 0 ); // Select none + maSortKeyItems[i].aBtnUp.Check(); } } // Enable or disable field depending on preceding Listbox selection - EnableField( 0 ); + maSortKeyItems[0].EnableField(); for ( sal_uInt16 i=1; i<nSortKeyCount; i++ ) - if ( aLbSortArr[i - 1] -> GetSelectEntryPos() == 0 ) - DisableField( i ); + if ( maSortKeyItems[i - 1].aLbSort.GetSelectEntryPos() == 0 ) + maSortKeyItems[i].DisableField(); else - EnableField( i ); + maSortKeyItems[i].EnableField(); + } else { SCCOL nCol = pViewData->GetCurX(); - if( nCol < rSortData.nCol1 ) - nCol = rSortData.nCol1; - else if( nCol > rSortData.nCol2 ) - nCol = rSortData.nCol2; + if( nCol < aSortData.nCol1 ) + nCol = aSortData.nCol1; + else if( nCol > aSortData.nCol2 ) + nCol = aSortData.nCol2; - sal_uInt16 nSort1Pos = nCol - rSortData.nCol1+1; + sal_uInt16 nSort1Pos = nCol - aSortData.nCol1+1; - aLbSortArr[0] -> SelectEntryPos( nSort1Pos ); + maSortKeyItems[0].aLbSort.SelectEntryPos( nSort1Pos ); for ( sal_uInt16 i=1; i<nSortKeyCount; i++ ) - aLbSortArr[i] -> SelectEntryPos( 0 ); + maSortKeyItems[i].aLbSort.SelectEntryPos( 0 ); for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) - aBtnUp[i] -> Check(); + maSortKeyItems[i].aBtnUp.Check(); + - EnableField ( 0 ); - EnableField ( 1 ); + maSortKeyItems[0].EnableField(); + maSortKeyItems[1].EnableField(); for ( sal_uInt16 i=2; i<nSortKeyCount; i++ ) - DisableField( i ); + maSortKeyItems[i].DisableField(); } if ( pDlg ) @@ -254,7 +225,7 @@ void ScTabPageSortFields::Reset( const SfxItemSet& /* rArgSet */ ) sal_Bool ScTabPageSortFields::FillItemSet( SfxItemSet& rArgSet ) { - ScSortParam aNewSortData = rSortData; + ScSortParam aNewSortData = aSortData; if (pDlg) { @@ -267,7 +238,7 @@ sal_Bool ScTabPageSortFields::FillItemSet( SfxItemSet& rArgSet ) for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) { - nSortPos.push_back( aLbSortArr[i] -> GetSelectEntryPos() ); + nSortPos.push_back( maSortKeyItems[i].aLbSort.GetSelectEntryPos() ); if ( nSortPos[i] == LISTBOX_ENTRY_NOTFOUND ) nSortPos[i] = 0; } @@ -294,7 +265,7 @@ sal_Bool ScTabPageSortFields::FillItemSet( SfxItemSet& rArgSet ) } for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) - aNewSortData.maKeyState[i].bAscending = aBtnUp[i] -> IsChecked(); + aNewSortData.maKeyState[i].bAscending = maSortKeyItems[i].aBtnUp.IsChecked(); // bHasHeader is in ScTabPageSortOptions::FillItemSet, where it belongs } @@ -321,14 +292,14 @@ void ScTabPageSortFields::ActivatePage() { std::vector<sal_uInt16> nCurSel; for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) - nCurSel.push_back( aLbSortArr[i] -> GetSelectEntryPos() ); + nCurSel.push_back( maSortKeyItems[i].aLbSort.GetSelectEntryPos() ); bHasHeader = pDlg->GetHeaders(); bSortByRows = pDlg->GetByRows(); FillFieldLists(0); for ( sal_uInt16 i=0; i<nSortKeyCount; i++ ) - aLbSortArr[i] -> SelectEntryPos( nCurSel[i] ); + maSortKeyItems[i].aLbSort.SelectEntryPos( nCurSel[i] ); } } } @@ -354,32 +325,6 @@ int ScTabPageSortFields::DeactivatePage( SfxItemSet* pSetP ) // ----------------------------------------------------------------------- -void ScTabPageSortFields::DisableField( sal_uInt16 nField ) -{ - if ( nField<nSortKeyCount ) - { - aLbSortArr[nField] -> Disable(); - aBtnUp[nField] -> Disable(); - aBtnDown[nField] -> Disable(); - aFlArr[nField] -> Disable(); - } -} - -// ----------------------------------------------------------------------- - -void ScTabPageSortFields::EnableField( sal_uInt16 nField ) -{ - if ( nField<nSortKeyCount ) - { - aLbSortArr[nField] -> Enable(); - aBtnUp[nField] -> Enable(); - aBtnDown[nField] -> Enable(); - aFlArr[nField] -> Enable(); - } -} - -// ----------------------------------------------------------------------- - void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField ) { if ( pViewData ) @@ -390,19 +335,19 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField ) { for ( sal_uInt16 i=nStartField; i<nSortKeyCount; i++ ) { - aLbSortArr[i] -> Clear(); - aLbSortArr[i] -> InsertEntry( aStrUndefined, 0 ); + maSortKeyItems[i].aLbSort.Clear(); + maSortKeyItems[i].aLbSort.InsertEntry( aStrUndefined, 0 ); } - SCCOL nFirstSortCol = rSortData.nCol1; - SCROW nFirstSortRow = rSortData.nRow1; + SCCOL nFirstSortCol = aSortData.nCol1; + SCROW nFirstSortRow = aSortData.nRow1; SCTAB nTab = pViewData->GetTabNo(); sal_uInt16 i = 1; if ( bSortByRows ) { String aFieldName; - SCCOL nMaxCol = rSortData.nCol2; + SCCOL nMaxCol = aSortData.nCol2; SCCOL col; for ( col=nFirstSortCol; col<=nMaxCol && i<SC_MAXFIELDS; col++ ) @@ -417,7 +362,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField ) nFieldArr.push_back( col ); for ( sal_uInt16 j=nStartField; j<nSortKeyCount; j++ ) - aLbSortArr[j] -> InsertEntry( aFieldName, i ); + maSortKeyItems[j].aLbSort.InsertEntry( aFieldName, i ); i++; } @@ -425,7 +370,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField ) else { String aFieldName; - SCROW nMaxRow = rSortData.nRow2; + SCROW nMaxRow = aSortData.nRow2; SCROW row; for ( row=nFirstSortRow; row<=nMaxRow && i<SC_MAXFIELDS; row++ ) @@ -440,7 +385,7 @@ void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField ) nFieldArr.push_back( row ); for ( sal_uInt16 j=nStartField; j<nSortKeyCount; j++ ) - aLbSortArr[j] -> InsertEntry( aFieldName, i ); + maSortKeyItems[j].aLbSort.InsertEntry( aFieldName, i ); i++; } @@ -476,32 +421,56 @@ sal_uInt16 ScTabPageSortFields::GetFieldSelPos( SCCOLROW nField ) IMPL_LINK( ScTabPageSortFields, SelectHdl, ListBox *, pLb ) { String aSelEntry = pLb->GetSelectEntry(); - sal_uInt16 nPos = 0; + ScSortKeyItems::iterator pIter; + sal_uInt16 nSortKeyIndex = nSortKeyCount; + + // If last listbox is enabled add one item + if ( &maSortKeyItems.back().aLbSort == pLb ) + if ( aSelEntry != aStrUndefined ) + { + // Extend local SortParam copy + const ScSortKeyState atempKeyState = { false, 0, true }; + aSortData.maKeyState.push_back( atempKeyState ); + + // Add Sort Key Item + ++nSortKeyCount; + maSortKeyCtrl.AddSortKey( nSortKeyCount ); + maSortKeyItems[nSortKeyIndex].aLbSort.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) ); + + FillFieldLists( nSortKeyIndex ); + + // Set Status + maSortKeyItems[nSortKeyIndex].aBtnUp.Check(); + maSortKeyItems[nSortKeyIndex].aLbSort.SelectEntryPos( 0 ); + return 0; + } // Find selected listbox - while ( pLb != aLbSortArr[nPos] ) - ++nPos; + for ( pIter = maSortKeyItems.begin(); pIter != maSortKeyItems.end(); ++pIter ) + { + if ( &pIter->aLbSort == pLb ) break; + } - // If not selecting the last Listbox modify the succeeding ones - ++nPos; - if ( nPos < nSortKeyCount ) + // If not selecting the last Listbox, modify the succeeding ones + ++pIter; + if ( std::distance(maSortKeyItems.begin(), pIter) < nSortKeyCount ) { if ( aSelEntry == aStrUndefined ) { - for ( sal_uInt16 i=nPos; i<nSortKeyCount; i++ ) + for ( ; pIter != maSortKeyItems.end(); ++pIter ) { - aLbSortArr[i] -> SelectEntryPos( 0 ); + pIter->aLbSort.SelectEntryPos( 0 ); - if ( aFlArr[i] -> IsEnabled() ) - DisableField( i ); + if ( pIter->aFlSort.IsEnabled() ) + pIter->DisableField(); } } else { - if ( !aFlArr[nPos] -> IsEnabled() ) - EnableField( nPos ); + if ( !pIter->aFlSort.IsEnabled() ) + pIter->EnableField(); } - } + } return 0; } @@ -538,7 +507,7 @@ ScTabPageSortOptions::ScTabPageSortOptions( Window* pParent, aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ), // nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ), - rSortData ( ((const ScSortItem&) + aSortData ( ((const ScSortItem&) rArgSet.Get( nWhichSort )).GetSortData() ), pViewData ( NULL ), pDoc ( NULL ), @@ -627,17 +596,17 @@ void ScTabPageSortOptions::Init() // Check whether the field that is passed on is a database field: - ScAddress aScAddress( rSortData.nCol1, rSortData.nRow1, nCurTab ); + ScAddress aScAddress( aSortData.nCol1, aSortData.nRow1, nCurTab ); ScRange( aScAddress, - ScAddress( rSortData.nCol2, rSortData.nRow2, nCurTab ) + ScAddress( aSortData.nCol2, aSortData.nRow2, nCurTab ) ).Format( theArea, SCR_ABS, pDoc, eConv ); if ( pDBColl ) { ScDBData* pDBData = pDBColl->GetDBAtArea( nCurTab, - rSortData.nCol1, rSortData.nRow1, - rSortData.nCol2, rSortData.nRow2 ); + aSortData.nCol1, aSortData.nRow1, + aSortData.nCol2, aSortData.nRow2 ); if ( pDBData ) { theDbName = pDBData->GetName(); @@ -673,11 +642,11 @@ SfxTabPage* ScTabPageSortOptions::Create( void ScTabPageSortOptions::Reset( const SfxItemSet& /* rArgSet */ ) { - if ( rSortData.bUserDef ) + if ( aSortData.bUserDef ) { aBtnSortUser.Check( sal_True ); aLbSortUser.Enable(); - aLbSortUser.SelectEntryPos( rSortData.nUserIndex ); + aLbSortUser.SelectEntryPos( aSortData.nUserIndex ); } else { @@ -686,12 +655,12 @@ void ScTabPageSortOptions::Reset( const SfxItemSet& /* rArgSet */ ) aLbSortUser.SelectEntryPos( 0 ); } - aBtnCase.Check ( rSortData.bCaseSens ); - aBtnFormats.Check ( rSortData.bIncludePattern ); - aBtnHeader.Check ( rSortData.bHasHeader ); - aBtnNaturalSort.Check ( rSortData.bNaturalSort ); + aBtnCase.Check ( aSortData.bCaseSens ); + aBtnFormats.Check ( aSortData.bIncludePattern ); + aBtnHeader.Check ( aSortData.bHasHeader ); + aBtnNaturalSort.Check ( aSortData.bNaturalSort ); - if ( rSortData.bByRow ) + if ( aSortData.bByRow ) { aBtnTopDown.Check(); aBtnHeader.SetText( aStrColLabel ); @@ -702,24 +671,24 @@ void ScTabPageSortOptions::Reset( const SfxItemSet& /* rArgSet */ ) aBtnHeader.SetText( aStrRowLabel ); } - LanguageType eLang = MsLangId::convertLocaleToLanguage( rSortData.aCollatorLocale ); + LanguageType eLang = MsLangId::convertLocaleToLanguage( aSortData.aCollatorLocale ); if ( eLang == LANGUAGE_DONTKNOW ) eLang = LANGUAGE_SYSTEM; aLbLanguage.SelectLanguage( eLang ); FillAlgorHdl( &aLbLanguage ); // get algorithms, select default - if ( !rSortData.aCollatorAlgorithm.isEmpty() ) - aLbAlgorithm.SelectEntry( pColRes->GetTranslation( rSortData.aCollatorAlgorithm ) ); + if ( !aSortData.aCollatorAlgorithm.isEmpty() ) + aLbAlgorithm.SelectEntry( pColRes->GetTranslation( aSortData.aCollatorAlgorithm ) ); - if ( pDoc && !rSortData.bInplace ) + if ( pDoc && !aSortData.bInplace ) { String aStr; - sal_uInt16 nFormat = (rSortData.nDestTab != pViewData->GetTabNo()) + sal_uInt16 nFormat = (aSortData.nDestTab != pViewData->GetTabNo()) ? SCR_ABS_3D : SCR_ABS; - theOutPos.Set( rSortData.nDestCol, - rSortData.nDestRow, - rSortData.nDestTab ); + theOutPos.Set( aSortData.nDestCol, + aSortData.nDestRow, + aSortData.nDestTab ); theOutPos.Format( aStr, nFormat, pDoc, pDoc->GetAddressConvention() ); aBtnCopyResult.Check(); @@ -744,7 +713,7 @@ void ScTabPageSortOptions::Reset( const SfxItemSet& /* rArgSet */ ) sal_Bool ScTabPageSortOptions::FillItemSet( SfxItemSet& rArgSet ) { // Create local copy of ScParam - ScSortParam aNewSortData = rSortData; + ScSortParam aNewSortData = aSortData; if (pDlg) { diff --git a/sc/source/ui/inc/sortdlg.hrc b/sc/source/ui/inc/sortdlg.hrc index f583dd3d2ce9..a1af594a4158 100644 --- a/sc/source/ui/inc/sortdlg.hrc +++ b/sc/source/ui/inc/sortdlg.hrc @@ -38,18 +38,15 @@ #define TP_OPTIONS 2 // TP_SORT_FIELDS: -#define FL_SORT1 1 -#define FL_SORT2 2 -#define FL_SORT3 3 -#define LB_SORT1 4 -#define LB_SORT2 5 -#define LB_SORT3 6 -#define BTN_UP1 7 -#define BTN_UP2 8 -#define BTN_UP3 9 -#define BTN_DOWN1 10 -#define BTN_DOWN2 11 -#define BTN_DOWN3 12 +#define CTRL_MANAGESORTKEY 1 +#define WIN_MANAGESORTKEY 2 +#define SB_SORT 3 + +// SORT_KEY_FIELDS: +#define FL_SORT 278 +#define LB_SORT 279 +#define BTN_UP 280 +#define BTN_DOWN 281 // TP_SORT_OPTIONS: #define FL_DIRECTION 1 diff --git a/sc/source/ui/inc/sortkeydlg.hxx b/sc/source/ui/inc/sortkeydlg.hxx new file mode 100644 index 000000000000..274a9b9bf534 --- /dev/null +++ b/sc/source/ui/inc/sortkeydlg.hxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Version: MPL 1.1 / GPLv3+ / LGPLv3+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Albert Thuswaldner <albert.thuswaldner@gmail.com> (initial developer) + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 3 or later (the "GPLv3+"), or + * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"), + * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable + * instead of those above. + */ + +#ifndef SC_SORTKEYDLG_HXX +#define SC_SORTKEYDLG_HXX + +#include <boost/ptr_container/ptr_vector.hpp> + +#include "anyrefdg.hxx" +#include "sortdlg.hrc" + +#include <vcl/edit.hxx> +#include <vcl/fixed.hxx> +#include <vcl/lstbox.hxx> +#include <vcl/scrbar.hxx> +#include <vcl/ctrl.hxx> +#include <svtools/stdctrl.hxx> +#include <svx/langbox.hxx> + +// ======================================================================= + +struct ScSortKeyItem +{ + FixedLine aFlSort; + ListBox aLbSort; + RadioButton aBtnUp; + RadioButton aBtnDown; + + ScSortKeyItem ( Window* pParent ); + + void DisableField(); + void EnableField(); +}; + +typedef boost::ptr_vector<ScSortKeyItem> ScSortKeyItems; + +// ======================================================================= + +class ScSortKeyWindow : public Window +{ +private: + FixedLine aFlSort; + ListBox aLbSort; + RadioButton aBtnUp; + RadioButton aBtnDown; + + sal_Int32 nScrollPos; + sal_Int32 nItemHeight; + + ScSortKeyItems& mrSortKeyItems; + +public: + ScSortKeyWindow( Window* pParent, const ResId& rResId, ScSortKeyItems& mrSortKeyItems ); + ~ScSortKeyWindow(); + + void AddSortKey( sal_uInt16 nItem ); + void DoScroll( sal_Int32 nNewPos ); + sal_Int32 GetItemHeight() const { return nItemHeight; } +}; + +// ======================================================================= + +class ScSortKeyCtrl : public Control +{ +private: + ScSortKeyWindow aSortWin; + ScrollBar aVertScroll; + + sal_Int32 nThumbPos; + + DECL_LINK( ScrollHdl, ScrollBar* ); + +public: + ScSortKeyCtrl( Window* pParent, const ScResId& rResId, ScSortKeyItems& mrSortKeyItems ); + ~ScSortKeyCtrl(); + + void AddSortKey( sal_uInt16 nItem ); +}; + +#endif // SC_SORTKEYDLG_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/tpsort.hxx b/sc/source/ui/inc/tpsort.hxx index 2af0cee3eb9d..8930d16892dd 100644 --- a/sc/source/ui/inc/tpsort.hxx +++ b/sc/source/ui/inc/tpsort.hxx @@ -38,6 +38,7 @@ #include <svtools/stdctrl.hxx> #include <svx/langbox.hxx> +#include "sortkeydlg.hxx" #include "global.hxx" #include "address.hxx" @@ -76,21 +77,6 @@ protected: virtual int DeactivatePage ( SfxItemSet* pSet = 0); private: - FixedLine aFlSort1; - ListBox aLbSort1; - RadioButton aBtnUp1; - RadioButton aBtnDown1; - - FixedLine aFlSort2; - ListBox aLbSort2; - RadioButton aBtnUp2; - RadioButton aBtnDown2; - - FixedLine aFlSort3; - ListBox aLbSort3; - RadioButton aBtnUp3; - RadioButton aBtnDown3; - String aStrUndefined; String aStrColumn; String aStrRow; @@ -98,7 +84,7 @@ private: const sal_uInt16 nWhichSort; ScSortDlg* pDlg; ScViewData* pViewData; - const ScSortParam& rSortData; + ScSortParam aSortData; std::vector<SCCOLROW> nFieldArr; sal_uInt16 nFieldCount; sal_uInt16 nSortKeyCount; @@ -109,16 +95,12 @@ private: sal_Bool bHasHeader; sal_Bool bSortByRows; - std::vector<ListBox*> aLbSortArr; - std::vector<RadioButton*> aBtnUp; - std::vector<RadioButton*> aBtnDown; - std::vector<FixedLine*> aFlArr; + ScSortKeyItems maSortKeyItems; + ScSortKeyCtrl maSortKeyCtrl; #ifdef _TPSORT_CXX private: void Init (); - void DisableField ( sal_uInt16 nField ); - void EnableField ( sal_uInt16 nField ); void FillFieldLists ( sal_uInt16 nStartField ); sal_uInt16 GetFieldSelPos ( SCCOLROW nField ); @@ -186,7 +168,7 @@ private: String aStrAreaLabel; const sal_uInt16 nWhichSort; - const ScSortParam& rSortData; + ScSortParam aSortData; ScViewData* pViewData; ScDocument* pDoc; ScSortDlg* pDlg; diff --git a/sc/source/ui/src/sortdlg.src b/sc/source/ui/src/sortdlg.src index 7d7a19b716fc..0134da833085 100644 --- a/sc/source/ui/src/sortdlg.src +++ b/sc/source/ui/src/sortdlg.src @@ -31,102 +31,58 @@ TabPage RID_SCPAGE_SORT_FIELDS Hide = TRUE ; SVLook = TRUE ; HelpId = HID_SCPAGE_SORT_FIELDS ; - Size = MAP_APPFONT ( TP_WIDTH , TP_HEIGHT ) ; - ListBox LB_SORT1 - { - HelpID = "sc:ListBox:RID_SCPAGE_SORT_FIELDS:LB_SORT1"; - Border = TRUE ; - Pos = MAP_APPFONT ( 12 , 19 ) ; - Size = MAP_APPFONT ( 154 , 90 ) ; - TabStop = TRUE ; - DropDown = TRUE ; - }; - RadioButton BTN_UP1 - { - HelpID = "sc:RadioButton:RID_SCPAGE_SORT_FIELDS:BTN_UP1"; - Pos = MAP_APPFONT ( 172 , 14 ) ; - Size = MAP_APPFONT ( 79 , 10 ) ; - Text [ en-US ] = "~Ascending" ; - TabStop = TRUE ; - }; - RadioButton BTN_DOWN1 - { - HelpID = "sc:RadioButton:RID_SCPAGE_SORT_FIELDS:BTN_DOWN1"; - Pos = MAP_APPFONT ( 172 , 28 ) ; - Size = MAP_APPFONT ( 79 , 10 ) ; - Text [ en-US ] = "~Descending" ; - TabStop = TRUE ; - }; - FixedLine FL_SORT1 - { - Pos = MAP_APPFONT ( 6 , 3 ) ; - Size = MAP_APPFONT ( 248 , 8 ) ; - Text [ en-US ] = "Sort ~key 1" ; - }; - ListBox LB_SORT2 - { - HelpID = "sc:ListBox:RID_SCPAGE_SORT_FIELDS:LB_SORT2"; - Border = TRUE ; - Pos = MAP_APPFONT ( 12 , 60 ) ; - Size = MAP_APPFONT ( 154 , 90 ) ; - TabStop = TRUE ; - DropDown = TRUE ; - }; - RadioButton BTN_UP2 - { - HelpID = "sc:RadioButton:RID_SCPAGE_SORT_FIELDS:BTN_UP2"; - Pos = MAP_APPFONT ( 172 , 55 ) ; - Size = MAP_APPFONT ( 79 , 10 ) ; - Text [ en-US ] = "A~scending" ; - TabStop = TRUE ; - }; - RadioButton BTN_DOWN2 - { - HelpID = "sc:RadioButton:RID_SCPAGE_SORT_FIELDS:BTN_DOWN2"; - Pos = MAP_APPFONT ( 172 , 69 ) ; - Size = MAP_APPFONT ( 79 , 10 ) ; - Text [ en-US ] = "D~escending" ; - TabStop = TRUE ; - }; - FixedLine FL_SORT2 - { - Pos = MAP_APPFONT ( 6 , 44 ) ; - Size = MAP_APPFONT ( 248 , 8 ) ; - Text [ en-US ] = "Sort ~key 2" ; - }; - ListBox LB_SORT3 - { - HelpID = "sc:ListBox:RID_SCPAGE_SORT_FIELDS:LB_SORT3"; - Border = TRUE ; - Pos = MAP_APPFONT ( 12 , 101 ) ; - Size = MAP_APPFONT ( 154 , 90 ) ; - TabStop = TRUE ; - DropDown = TRUE ; - }; - RadioButton BTN_UP3 - { - HelpID = "sc:RadioButton:RID_SCPAGE_SORT_FIELDS:BTN_UP3"; - Pos = MAP_APPFONT ( 172 , 96 ) ; - Size = MAP_APPFONT ( 79 , 10 ) ; - Text [ en-US ] = "As~cending" ; - TabStop = TRUE ; - }; - RadioButton BTN_DOWN3 - { - HelpID = "sc:RadioButton:RID_SCPAGE_SORT_FIELDS:BTN_DOWN3"; - Pos = MAP_APPFONT ( 172 , 110 ) ; - Size = MAP_APPFONT ( 79 , 10 ) ; - Text [ en-US ] = "Desce~nding" ; - TabStop = TRUE ; - }; - FixedLine FL_SORT3 - { - Pos = MAP_APPFONT ( 6 , 85 ) ; - Size = MAP_APPFONT ( 248 , 8 ) ; - Text [ en-US ] = "Sort ~key 3" ; + Size = MAP_APPFONT ( TP_WIDTH , TP_HEIGHT ); + Control CTRL_MANAGESORTKEY + { + Pos = MAP_APPFONT( 2, 2 ); + Size = MAP_APPFONT( 256, 181 ); + Border = FALSE; + DialogControl = TRUE; + Window WIN_MANAGESORTKEY + { + OutputSize = TRUE ; + Pos = MAP_APPFONT ( 2 , 2 ); + Size = MAP_APPFONT ( 240 , 181 ); + DialogControl = TRUE; + }; + ScrollBar SB_SORT + { + Pos = MAP_APPFONT ( 246 , 2 ); + Size = MAP_APPFONT ( 8 , 181 ); + VScroll = TRUE; + }; }; }; +ListBox LB_SORT +{ + Border = TRUE ; + Pos = MAP_APPFONT ( 12 , 16 ) ; + Size = MAP_APPFONT ( 154 , 90 ) ; + TabStop = TRUE ; + DropDown = TRUE ; +}; +RadioButton BTN_UP +{ + Pos = MAP_APPFONT ( 172 , 11 ) ; + Size = MAP_APPFONT ( 79 , 10 ) ; + Text [ en-US ] = "~Ascending" ; + TabStop = TRUE ; +}; +RadioButton BTN_DOWN +{ + Pos = MAP_APPFONT ( 172 , 25 ) ; + Size = MAP_APPFONT ( 79 , 10 ) ; + Text [ en-US ] = "~Descending" ; + TabStop = TRUE ; +}; +FixedLine FL_SORT +{ + Pos = MAP_APPFONT ( 6 , 0 ) ; + Size = MAP_APPFONT ( 240 , 8 ) ; + Text [ en-US ] = "Sort ~key " ; +}; + TabPage RID_SCPAGE_SORT_OPTIONS { Hide = TRUE ; |