Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 :
10 : #include "sortkeydlg.hxx"
11 : #include "sortdlg.hxx"
12 : #include "sortdlg.hrc"
13 : #include <vcl/layout.hxx>
14 :
15 : // =======================================================================
16 :
17 0 : ScSortKeyItem::ScSortKeyItem(Window* pParent)
18 : {
19 0 : m_pUIBuilder = new VclBuilder(pParent, getUIRootDir(), "modules/scalc/ui/sortkey.ui");
20 :
21 0 : get(m_pFrame, "SortKeyFrame");
22 0 : get(m_pFlSort, "sortft");
23 0 : get(m_pLbSort, "sortlb");
24 0 : get(m_pBtnUp, "up");
25 0 : get(m_pBtnDown, "down");
26 0 : }
27 :
28 0 : long ScSortKeyItem::getItemHeight() const
29 : {
30 0 : return VclContainer::getLayoutRequisition(*m_pFrame).Height();
31 : }
32 :
33 0 : void ScSortKeyItem::DisableField()
34 : {
35 0 : m_pFrame->Disable();
36 0 : }
37 :
38 : // -----------------------------------------------------------------------
39 :
40 0 : void ScSortKeyItem::EnableField()
41 : {
42 0 : m_pFrame->Enable();
43 0 : }
44 :
45 : // =======================================================================
46 :
47 0 : ScSortKeyWindow::ScSortKeyWindow(SfxTabPage* pParent, ScSortKeyItems& rSortKeyItems)
48 0 : : mrSortKeyItems(rSortKeyItems)
49 : {
50 0 : pParent->get(m_pBox, "SortKeyWindow");
51 0 : if (!mrSortKeyItems.empty())
52 0 : nItemHeight = mrSortKeyItems.front().getItemHeight();
53 : else
54 : {
55 0 : ScSortKeyItem aTemp(m_pBox);
56 0 : nItemHeight = aTemp.getItemHeight();
57 : }
58 0 : }
59 :
60 : // -----------------------------------------------------------------------
61 :
62 0 : ScSortKeyWindow::~ScSortKeyWindow()
63 : {
64 0 : mrSortKeyItems.clear();
65 0 : }
66 :
67 : // -----------------------------------------------------------------------
68 :
69 0 : void ScSortKeyWindow::AddSortKey( sal_uInt16 nItemNumber )
70 : {
71 0 : ScSortKeyItem* pSortKeyItem = new ScSortKeyItem(m_pBox);
72 :
73 : // Set Sort key number
74 0 : OUString aLine = pSortKeyItem->m_pFlSort->GetText() +
75 0 : OUString::number( nItemNumber );
76 0 : pSortKeyItem->m_pFlSort->SetText( aLine );
77 :
78 0 : mrSortKeyItems.push_back(pSortKeyItem);
79 0 : }
80 :
81 : // -----------------------------------------------------------------------
82 :
83 0 : void ScSortKeyWindow::DoScroll(sal_Int32 nNewPos)
84 : {
85 0 : m_pBox->SetPosPixel(Point(0, nNewPos));
86 0 : }
87 :
88 : // =======================================================================
89 :
90 0 : ScSortKeyCtrl::ScSortKeyCtrl(SfxTabPage* pParent, ScSortKeyItems& rItems)
91 : : m_aSortWin(pParent, rItems)
92 0 : , m_rScrolledWindow(*pParent->get<VclScrolledWindow>("SortCriteriaPage"))
93 0 : , m_rVertScroll(m_rScrolledWindow.getVertScrollBar())
94 : {
95 0 : m_rVertScroll.EnableDrag();
96 0 : m_rVertScroll.Show(m_rScrolledWindow.GetStyle() & WB_VSCROLL);
97 :
98 0 : m_rVertScroll.SetRangeMin( 0 );
99 0 : m_rVertScroll.SetVisibleSize( 0xFFFF );
100 :
101 0 : Link aScrollLink = LINK( this, ScSortKeyCtrl, ScrollHdl );
102 0 : m_rVertScroll.SetScrollHdl( aScrollLink );
103 0 : }
104 :
105 0 : void ScSortKeyCtrl::checkAutoVScroll()
106 : {
107 0 : WinBits nBits = m_rScrolledWindow.GetStyle();
108 0 : if (nBits & WB_VSCROLL)
109 0 : return;
110 0 : if (nBits & WB_AUTOVSCROLL)
111 : {
112 0 : sal_Bool bShow = m_rVertScroll.GetRangeMax() > m_rVertScroll.GetVisibleSize();
113 0 : if (bShow != m_rVertScroll.IsVisible())
114 0 : m_rVertScroll.Show(bShow);
115 : }
116 : }
117 :
118 0 : void ScSortKeyCtrl::setScrollRange()
119 : {
120 0 : sal_Int32 nScrollOffset = m_aSortWin.GetItemHeight();
121 0 : sal_Int32 nVisibleItems = m_rScrolledWindow.getVisibleChildSize().Height() / nScrollOffset;
122 0 : m_rVertScroll.SetPageSize( nVisibleItems - 1 );
123 0 : m_rVertScroll.SetVisibleSize( nVisibleItems );
124 0 : m_rVertScroll.Scroll();
125 0 : checkAutoVScroll();
126 0 : }
127 :
128 : // -----------------------------------------------------------------------
129 :
130 0 : IMPL_LINK( ScSortKeyCtrl, ScrollHdl, ScrollBar*, pScrollBar )
131 : {
132 0 : sal_Int32 nOffset = m_aSortWin.GetItemHeight();
133 0 : nOffset *= pScrollBar->GetThumbPos();
134 0 : m_aSortWin.DoScroll( -nOffset );
135 0 : return 0;
136 : }
137 :
138 : // -----------------------------------------------------------------------
139 :
140 0 : void ScSortKeyCtrl::AddSortKey( sal_uInt16 nItem )
141 : {
142 0 : m_rVertScroll.SetRangeMax( nItem );
143 0 : m_rVertScroll.DoScroll( nItem );
144 0 : m_aSortWin.AddSortKey( nItem );
145 0 : checkAutoVScroll();
146 0 : }
147 :
148 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|