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 : #include "swtypes.hxx"
21 : #include "swrect.hxx"
22 : #include "scroll.hxx"
23 :
24 : #define SCROLL_LINE_SIZE 250
25 :
26 0 : SwScrollbar::SwScrollbar( Window *pWin, sal_Bool bHoriz ) :
27 : ScrollBar( pWin,
28 : WinBits( WB_3DLOOK | WB_HIDE | ( bHoriz ? WB_HSCROLL : WB_VSCROLL) ) ),
29 : bHori( bHoriz ),
30 : bAuto( sal_False ),
31 : bVisible(sal_False),
32 0 : bSizeSet(sal_False)
33 : {
34 : // SSA: --- RTL --- no mirroring for horizontal scrollbars
35 0 : if( bHoriz )
36 0 : EnableRTL( false );
37 0 : }
38 :
39 0 : SwScrollbar::~SwScrollbar() {}
40 :
41 : // Will be called after a change of the document size
42 : // to refresh the range of the scrollbars.
43 :
44 0 : void SwScrollbar::DocSzChgd( const Size &rSize )
45 : {
46 0 : aDocSz = rSize;
47 0 : SetRange( Range( 0, bHori ? rSize.Width() : rSize.Height()) );
48 0 : const sal_uLong nVisSize = GetVisibleSize();
49 0 : SetLineSize( SCROLL_LINE_SIZE );
50 0 : SetPageSize( nVisSize * 77 / 100 );
51 0 : }
52 :
53 : // Will be called after a change of the visible view section.
54 :
55 0 : void SwScrollbar::ViewPortChgd( const Rectangle &rRect )
56 : {
57 : long nThumb, nVisible;
58 0 : if( bHori )
59 : {
60 0 : nThumb = rRect.Left();
61 0 : nVisible = rRect.GetWidth();
62 : }
63 : else
64 : {
65 0 : nThumb = rRect.Top();
66 0 : nVisible = rRect.GetHeight();
67 : }
68 :
69 0 : SetVisibleSize( nVisible );
70 0 : DocSzChgd(aDocSz);
71 0 : SetThumbPos( nThumb );
72 0 : if(bAuto)
73 0 : AutoShow();
74 0 : }
75 :
76 0 : void SwScrollbar::ExtendedShow( sal_Bool bSet )
77 : {
78 0 : bVisible = bSet;
79 0 : if( (!bSet || !bAuto) && IsUpdateMode() && bSizeSet)
80 0 : ScrollBar::Show(bSet);
81 0 : }
82 :
83 0 : void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
84 : {
85 0 : ScrollBar::SetPosSizePixel(rNewPos, rNewSize);
86 0 : bSizeSet = sal_True;
87 0 : if(bVisible)
88 0 : ExtendedShow();
89 :
90 0 : }
91 :
92 0 : void SwScrollbar::SetAuto(sal_Bool bSet)
93 : {
94 0 : if(bAuto != bSet)
95 : {
96 0 : bAuto = bSet;
97 :
98 : // hide autmatically - automatisch versteckt - then show
99 0 : if(!bAuto && bVisible && !ScrollBar::IsVisible())
100 0 : ExtendedShow(sal_True);
101 0 : else if(bAuto)
102 0 : AutoShow(); // or hide automatically
103 : }
104 0 : }
105 :
106 0 : void SwScrollbar::AutoShow()
107 : {
108 0 : long nVis = GetVisibleSize();
109 0 : long nLen = GetRange().Len();
110 0 : if( nVis >= nLen - 1)
111 : {
112 0 : if(ScrollBar::IsVisible())
113 0 : ScrollBar::Show(false);
114 : }
115 0 : else if ( !ScrollBar::IsVisible() )
116 : {
117 0 : ScrollBar::Show(true);
118 : }
119 0 : }
120 :
121 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|