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 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "swtypes.hxx"
22 : #include "swrect.hxx"
23 : #include "scroll.hxx"
24 :
25 : #define SCROLL_LINE_SIZE 250
26 :
27 :
28 1586 : SwScrollbar::SwScrollbar( Window *pWin, sal_Bool bHoriz ) :
29 : ScrollBar( pWin,
30 : WinBits( WB_3DLOOK | WB_HIDE | ( bHoriz ? WB_HSCROLL : WB_VSCROLL) ) ),
31 : bHori( bHoriz ),
32 : bAuto( sal_False ),
33 : bVisible(sal_False),
34 1586 : bSizeSet(sal_False)
35 : {
36 : // SSA: --- RTL --- no mirroring for horizontal scrollbars
37 1586 : if( bHoriz )
38 793 : EnableRTL( sal_False );
39 1586 : }
40 :
41 :
42 3168 : SwScrollbar::~SwScrollbar() {}
43 :
44 : // Will be called after a change of the document size
45 : // to refresh the range of the scrollbars.
46 :
47 7684 : void SwScrollbar::DocSzChgd( const Size &rSize )
48 : {
49 7684 : aDocSz = rSize;
50 7684 : SetRange( Range( 0, bHori ? rSize.Width() : rSize.Height()) );
51 7684 : const sal_uLong nVisSize = GetVisibleSize();
52 7684 : SetLineSize( SCROLL_LINE_SIZE );
53 7684 : SetPageSize( nVisSize * 77 / 100 );
54 7684 : }
55 :
56 : // Will be called after a change of the visible view section.
57 :
58 3842 : void SwScrollbar::ViewPortChgd( const Rectangle &rRect )
59 : {
60 : long nThumb, nVisible;
61 3842 : if( bHori )
62 : {
63 1921 : nThumb = rRect.Left();
64 1921 : nVisible = rRect.GetWidth();
65 : }
66 : else
67 : {
68 1921 : nThumb = rRect.Top();
69 1921 : nVisible = rRect.GetHeight();
70 : }
71 :
72 3842 : SetVisibleSize( nVisible );
73 3842 : DocSzChgd(aDocSz);
74 3842 : SetThumbPos( nThumb );
75 3842 : if(bAuto)
76 3734 : AutoShow();
77 3842 : }
78 :
79 4721 : void SwScrollbar::ExtendedShow( sal_Bool bSet )
80 : {
81 4721 : bVisible = bSet;
82 4721 : if( (!bSet || !bAuto) && IsUpdateMode() && bSizeSet)
83 34 : ScrollBar::Show(bSet);
84 4721 : }
85 :
86 3526 : void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
87 : {
88 3526 : ScrollBar::SetPosSizePixel(rNewPos, rNewSize);
89 3526 : bSizeSet = sal_True;
90 3526 : if(bVisible)
91 1557 : ExtendedShow();
92 :
93 3526 : }
94 :
95 4301 : void SwScrollbar::SetAuto(sal_Bool bSet)
96 : {
97 4301 : if(bAuto != bSet)
98 : {
99 1557 : bAuto = bSet;
100 :
101 : // hide autmatically - automatisch versteckt - then show
102 1557 : if(!bAuto && bVisible && !ScrollBar::IsVisible())
103 0 : ExtendedShow(sal_True);
104 1557 : else if(bAuto)
105 1552 : AutoShow(); // or hide automatically
106 : }
107 4301 : }
108 :
109 5286 : void SwScrollbar::AutoShow()
110 : {
111 5286 : long nVis = GetVisibleSize();
112 5286 : long nLen = GetRange().Len();
113 5286 : if( nVis >= nLen - 1)
114 : {
115 184 : if(ScrollBar::IsVisible())
116 40 : ScrollBar::Show(sal_False);
117 : }
118 5102 : else if ( !ScrollBar::IsVisible() )
119 : {
120 1556 : ScrollBar::Show(sal_True);
121 : }
122 5385 : }
123 :
124 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|