diff options
author | Palenik Mihály <palenik.mihaly@gmail.com> | 2014-10-22 19:01:05 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2014-10-30 13:03:44 +0000 |
commit | f92ab4da51647a4353038b1c56b70db3672c49cf (patch) | |
tree | de37e84439aef3b3cbd08e875a58a0f36dea0697 /svtools | |
parent | 226285b7ccc0c6880ae1005c9f0d9f47aa41fc29 (diff) |
Improve SvSimpleTable class
It is possible to order columns. This is set in Expert Configuration
dialog. The header's itembits weren't set correctly therefore mouse
click handler didn't do anything. The comparsion was slow on big
table.
Conflicts:
include/svtools/treelist.hxx
svtools/source/contnr/simptabl.cxx
Change-Id: I7e1301d40433ef45b3d0a3fb300909345ede9d4d
Reviewed-on: https://gerrit.libreoffice.org/12070
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/contnr/simptabl.cxx | 35 | ||||
-rw-r--r-- | svtools/source/contnr/treelist.cxx | 32 |
2 files changed, 51 insertions, 16 deletions
diff --git a/svtools/source/contnr/simptabl.cxx b/svtools/source/contnr/simptabl.cxx index f5755bdc7875..2422bba2efb8 100644 --- a/svtools/source/contnr/simptabl.cxx +++ b/svtools/source/contnr/simptabl.cxx @@ -21,7 +21,6 @@ #include <svtools/simptabl.hxx> #include <svtools/svlbitm.hxx> #include <svtools/treelistentry.hxx> -#include <unotools/intlwrapper.hxx> #include <vcl/builder.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> @@ -84,7 +83,8 @@ SvSimpleTable::SvSimpleTable(SvSimpleTableContainer& rParent, WinBits nBits): m_rParentTableContainer(rParent), aHeaderBar(&rParent,WB_BUTTONSTYLE | WB_BORDER | WB_TABSTOP), nHeaderItemId(1), - bPaintFlag(true) + bPaintFlag(true), + aCollator(*(IntlWrapper( Application::GetSettings().GetLanguageTag() ).getCaseCollator())) { m_rParentTableContainer.SetTable(this); @@ -98,6 +98,8 @@ SvSimpleTable::SvSimpleTable(SvSimpleTableContainer& rParent, WinBits nBits): aHeaderBar.SetSelectHdl(LINK( this, SvSimpleTable, HeaderBarClick)); aHeaderBar.SetDoubleClickHdl(LINK( this, SvSimpleTable, HeaderBarDblClick)); + GetModel()->SetCompareHdl( LINK( this, SvSimpleTable, CompareHdl)); + EnableCellFocus(); DisableTransientChildren(); InitHeaderBar( &aHeaderBar ); @@ -262,29 +264,38 @@ sal_uInt16 SvSimpleTable::GetSelectedCol() void SvSimpleTable::SortByCol(sal_uInt16 nCol, bool bDir) { - bSortDirection=bDir; if(nSortCol!=0xFFFF) aHeaderBar.SetItemBits(nSortCol+1,HIB_STDSTYLE); if (nCol != 0xFFFF) { - if(bDir) + if(bDir || nSortCol != nCol) { aHeaderBar.SetItemBits( nCol+1, HIB_STDSTYLE | HIB_DOWNARROW); GetModel()->SetSortMode(SortAscending); + bDir = true; } else { aHeaderBar.SetItemBits( nCol+1, HIB_STDSTYLE | HIB_UPARROW); GetModel()->SetSortMode(SortDescending); } - nSortCol=nCol; - GetModel()->SetCompareHdl( LINK( this, SvSimpleTable, CompareHdl)); - GetModel()->Resort(); + if(nSortCol == nCol) + { + GetModel()->Reverse(); + Resize(); //update rows + } + else + { + nSortCol=nCol; + GetModel()->Resort(); + } } else GetModel()->SetSortMode(SortNone); nSortCol=nCol; + bSortDirection=bDir; + SetAlternatingRowColors( true ); } void SvSimpleTable::HBarClick() @@ -447,16 +458,8 @@ sal_Int32 SvSimpleTable::ColCompare(SvTreeListEntry* pLeft,SvTreeListEntry* pRig if(nRightKind == SV_ITEM_ID_LBOXSTRING && nLeftKind == SV_ITEM_ID_LBOXSTRING ) - { - IntlWrapper aIntlWrapper( Application::GetSettings().GetLanguageTag() ); - const CollatorWrapper* pCollator = aIntlWrapper.getCaseCollator(); - - nCompare = pCollator->compareString( static_cast<SvLBoxString*>(pLeftItem)->GetText(), + nCompare = aCollator.compareString( static_cast<SvLBoxString*>(pLeftItem)->GetText(), static_cast<SvLBoxString*>(pRightItem)->GetText()); - - if (nCompare == 0) - nCompare = -1; - } } return nCompare; } diff --git a/svtools/source/contnr/treelist.cxx b/svtools/source/contnr/treelist.cxx index 27eebd488529..60a8d27855c8 100644 --- a/svtools/source/contnr/treelist.cxx +++ b/svtools/source/contnr/treelist.cxx @@ -1438,6 +1438,11 @@ void SvListView::ModelNotification( SvListAction nActionId, SvTreeListEntry* pEn break; case SvListAction::RESORTING: break; + case SvListAction::REVERSING: + break; + case SvListAction::REVERSED: + bVisPositionsValid = false; + break; default: OSL_FAIL("unknown ActionId"); } @@ -1547,6 +1552,33 @@ void SvTreeList::ResortChildren( SvTreeListEntry* pParent ) SetListPositions(pParent->maChildren); // correct list position in target list } +void SvTreeList::Reverse() +{ + Broadcast(SvListAction::REVERSING); + bAbsPositionsValid = false; + ReverseChildren(pRootItem); + Broadcast(SvListAction::REVERSED); +} + +void SvTreeList::ReverseChildren( SvTreeListEntry* pParent ) +{ + DBG_ASSERT(pParent,"Parent not set"); + + if (pParent->maChildren.empty()) + return; + + std::reverse(pParent->maChildren.base().begin(), pParent->maChildren.base().end()); + // Recursively sort child entries. + SvTreeListEntries::iterator it = pParent->maChildren.begin(), itEnd = pParent->maChildren.end(); + for (; it != itEnd; ++it) + { + SvTreeListEntry& r = *it; + ReverseChildren(&r); + } + + SetListPositions(pParent->maChildren); // correct list position in target list +} + void SvTreeList::GetInsertionPos( SvTreeListEntry* pEntry, SvTreeListEntry* pParent, sal_uLong& rPos ) { |