1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "sortkeydlg.hxx"
11 #include "sortdlg.hxx"
12 #include <vcl/layout.hxx>
14 ScSortKeyItem::ScSortKeyItem(vcl::Window
* pParent
)
16 m_pUIBuilder
= new VclBuilder(pParent
, getUIRootDir(), "modules/scalc/ui/sortkey.ui");
18 get(m_pFrame
, "SortKeyFrame");
19 get(m_pFlSort
, "sortft");
20 get(m_pLbSort
, "sortlb");
22 get(m_pBtnDown
, "down");
25 long ScSortKeyItem::getItemHeight() const
27 return VclContainer::getLayoutRequisition(*m_pFrame
).Height();
30 void ScSortKeyItem::DisableField()
35 void ScSortKeyItem::EnableField()
40 ScSortKeyWindow::ScSortKeyWindow(SfxTabPage
* pParent
, ScSortKeyItems
& rSortKeyItems
)
41 : mrSortKeyItems(rSortKeyItems
)
43 pParent
->get(m_pBox
, "SortKeyWindow");
44 if (!mrSortKeyItems
.empty())
45 nItemHeight
= mrSortKeyItems
.front().getItemHeight();
48 ScSortKeyItem
aTemp(m_pBox
);
49 nItemHeight
= aTemp
.getItemHeight();
53 ScSortKeyWindow::~ScSortKeyWindow()
58 void ScSortKeyWindow::dispose()
60 m_pBox
.disposeAndClear();
61 mrSortKeyItems
.clear();
64 void ScSortKeyWindow::AddSortKey( sal_uInt16 nItemNumber
)
66 ScSortKeyItem
* pSortKeyItem
= new ScSortKeyItem(m_pBox
);
68 // Set Sort key number
69 OUString aLine
= pSortKeyItem
->m_pFlSort
->GetText() +
70 OUString::number( nItemNumber
);
71 pSortKeyItem
->m_pFlSort
->SetText( aLine
);
73 mrSortKeyItems
.push_back(pSortKeyItem
);
76 void ScSortKeyWindow::DoScroll(sal_Int32 nNewPos
)
78 m_pBox
->SetPosPixel(Point(0, nNewPos
));
81 ScSortKeyCtrl::ScSortKeyCtrl(SfxTabPage
* pParent
, ScSortKeyItems
& rItems
)
82 : m_aSortWin(pParent
, rItems
)
83 , m_rScrolledWindow(*pParent
->get
<VclScrolledWindow
>("SortCriteriaPage"))
84 , m_rVertScroll(m_rScrolledWindow
.getVertScrollBar())
86 m_rScrolledWindow
.setUserManagedScrolling(true);
88 m_rVertScroll
.EnableDrag();
89 m_rVertScroll
.Show(m_rScrolledWindow
.GetStyle() & WB_VSCROLL
);
91 m_rVertScroll
.SetRangeMin( 0 );
92 m_rVertScroll
.SetVisibleSize( 0xFFFF );
94 Link
<> aScrollLink
= LINK( this, ScSortKeyCtrl
, ScrollHdl
);
95 m_rVertScroll
.SetScrollHdl( aScrollLink
);
98 void ScSortKeyCtrl::dispose()
100 m_aSortWin
.dispose();
103 void ScSortKeyCtrl::checkAutoVScroll()
105 WinBits nBits
= m_rScrolledWindow
.GetStyle();
106 if (nBits
& WB_VSCROLL
)
108 if (nBits
& WB_AUTOVSCROLL
)
110 bool bShow
= m_rVertScroll
.GetRangeMax() > m_rVertScroll
.GetVisibleSize();
111 if (bShow
!= m_rVertScroll
.IsVisible())
112 m_rVertScroll
.Show(bShow
);
116 void ScSortKeyCtrl::setScrollRange()
118 sal_Int32 nScrollOffset
= m_aSortWin
.GetItemHeight();
119 sal_Int32 nVisibleItems
= m_rScrolledWindow
.getVisibleChildSize().Height() / nScrollOffset
;
120 m_rVertScroll
.SetPageSize( nVisibleItems
- 1 );
121 m_rVertScroll
.SetVisibleSize( nVisibleItems
);
122 m_rVertScroll
.Scroll();
126 IMPL_LINK( ScSortKeyCtrl
, ScrollHdl
, ScrollBar
*, pScrollBar
)
128 sal_Int32 nOffset
= m_aSortWin
.GetItemHeight();
129 nOffset
*= pScrollBar
->GetThumbPos();
130 m_aSortWin
.DoScroll( -nOffset
);
134 void ScSortKeyCtrl::AddSortKey( sal_uInt16 nItem
)
136 m_rVertScroll
.SetRangeMax( nItem
);
137 m_rVertScroll
.DoScroll( nItem
);
138 m_aSortWin
.AddSortKey( nItem
);
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */