summaryrefslogtreecommitdiff
path: root/sc/source/ui/dbgui/sortkeydlg.cxx
blob: 0801b8de789c87aa077ade927c77c5852e253a71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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: */