Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2012 Albert Thuswaldner <albert.thuswaldner@gmail.com> (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include "sortkeydlg.hxx"
30 : #include "sortdlg.hxx"
31 : #include "sortdlg.hrc"
32 :
33 : // =======================================================================
34 :
35 0 : ScSortKeyItem::ScSortKeyItem(Window* pParent)
36 : {
37 0 : m_pUIBuilder = new VclBuilder(pParent, getUIRootDir(), "modules/scalc/ui/sortkey.ui");
38 :
39 0 : get(m_pFrame, "SortKeyFrame");
40 0 : get(m_pFlSort, "sortft");
41 0 : get(m_pLbSort, "sortlb");
42 0 : get(m_pBtnUp, "up");
43 0 : get(m_pBtnDown, "down");
44 0 : }
45 :
46 0 : long ScSortKeyItem::getItemHeight() const
47 : {
48 0 : return m_pFrame->get_preferred_size().Height();
49 : }
50 :
51 0 : void ScSortKeyItem::DisableField()
52 : {
53 0 : m_pFrame->Disable();
54 0 : }
55 :
56 : // -----------------------------------------------------------------------
57 :
58 0 : void ScSortKeyItem::EnableField()
59 : {
60 0 : m_pFrame->Enable();
61 0 : }
62 :
63 : // =======================================================================
64 :
65 0 : ScSortKeyWindow::ScSortKeyWindow(SfxTabPage* pParent, ScSortKeyItems& rSortKeyItems)
66 0 : : mrSortKeyItems(rSortKeyItems)
67 : {
68 0 : pParent->get(m_pBox, "SortKeyWindow");
69 0 : if (!mrSortKeyItems.empty())
70 0 : nItemHeight = mrSortKeyItems.front().getItemHeight();
71 : else
72 : {
73 0 : ScSortKeyItem aTemp(m_pBox);
74 0 : nItemHeight = aTemp.getItemHeight();
75 : }
76 0 : }
77 :
78 : // -----------------------------------------------------------------------
79 :
80 0 : ScSortKeyWindow::~ScSortKeyWindow()
81 : {
82 0 : mrSortKeyItems.clear();
83 0 : }
84 :
85 : // -----------------------------------------------------------------------
86 :
87 0 : void ScSortKeyWindow::AddSortKey( sal_uInt16 nItemNumber )
88 : {
89 0 : ScSortKeyItem* pSortKeyItem = new ScSortKeyItem(m_pBox);
90 :
91 : // Set Sort key number
92 0 : String aLine = pSortKeyItem->m_pFlSort->GetText();
93 0 : aLine += String::CreateFromInt32( nItemNumber );
94 0 : pSortKeyItem->m_pFlSort->SetText( aLine );
95 :
96 0 : mrSortKeyItems.push_back(pSortKeyItem);
97 0 : }
98 :
99 : // -----------------------------------------------------------------------
100 :
101 0 : void ScSortKeyWindow::DoScroll(sal_Int32 nNewPos)
102 : {
103 0 : m_pBox->SetPosPixel(Point(0, nNewPos));
104 0 : }
105 :
106 : // =======================================================================
107 :
108 0 : ScSortKeyCtrl::ScSortKeyCtrl(SfxTabPage* pParent, ScSortKeyItems& rItems)
109 : : m_aSortWin(pParent, rItems)
110 0 : , m_rScrolledWindow(*pParent->get<VclScrolledWindow>("SortCriteriaPage"))
111 0 : , m_rVertScroll(m_rScrolledWindow.getVertScrollBar())
112 : {
113 0 : m_rVertScroll.EnableDrag();
114 0 : m_rVertScroll.Show();
115 :
116 0 : m_rVertScroll.SetRangeMin( 0 );
117 0 : m_rVertScroll.SetVisibleSize( 0xFFFF );
118 :
119 0 : Link aScrollLink = LINK( this, ScSortKeyCtrl, ScrollHdl );
120 0 : m_rVertScroll.SetScrollHdl( aScrollLink );
121 0 : }
122 :
123 0 : void ScSortKeyCtrl::setScrollRange()
124 : {
125 0 : sal_Int32 nScrollOffset = m_aSortWin.GetItemHeight();
126 0 : sal_Int32 nVisibleItems = m_rScrolledWindow.getVisibleChildSize().Height() / nScrollOffset;
127 0 : m_rVertScroll.SetPageSize( nVisibleItems - 1 );
128 0 : m_rVertScroll.SetVisibleSize( nVisibleItems );
129 0 : }
130 :
131 : // -----------------------------------------------------------------------
132 :
133 0 : IMPL_LINK( ScSortKeyCtrl, ScrollHdl, ScrollBar*, pScrollBar )
134 : {
135 0 : sal_Int32 nOffset = m_aSortWin.GetItemHeight();
136 0 : nOffset *= pScrollBar->GetThumbPos();
137 0 : m_aSortWin.DoScroll( -nOffset );
138 0 : return 0;
139 : }
140 :
141 : // -----------------------------------------------------------------------
142 :
143 0 : void ScSortKeyCtrl::AddSortKey( sal_uInt16 nItem )
144 : {
145 0 : m_rVertScroll.SetRangeMax( nItem );
146 0 : m_rVertScroll.DoScroll( nItem );
147 0 : m_aSortWin.AddSortKey( nItem );
148 0 : }
149 :
150 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|