Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / uiview / scroll.cxx
blob7b1d7f915a7f8cbb1d81373d20db22e79e6707c7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <scroll.hxx>
22 #define SCROLL_LINE_SIZE 250
24 SwScrollbar::SwScrollbar(vcl::Window *pWin, bool bHoriz)
25 : ScrollAdaptor(pWin, bHoriz)
26 , m_bAuto(false)
27 , m_bVisible(false)
28 , m_bSizeSet(false)
30 m_xScrollBar->show();
32 // No mirroring for horizontal scrollbars
33 if (bHoriz)
34 m_xScrollBar->set_direction(false);
37 // Will be called after a change of the document size
38 // to refresh the range of the scrollbars.
39 void SwScrollbar::DocSzChgd( const Size &rSize )
41 m_aDocSz = rSize;
42 SetRange( Range( 0, m_bHori ? rSize.Width() : rSize.Height()) );
43 const tools::Long nVisSize = GetVisibleSize();
44 SetLineSize( SCROLL_LINE_SIZE );
45 SetPageSize( nVisSize * 77 / 100 );
48 // Will be called after a change of the visible view section.
49 void SwScrollbar::ViewPortChgd( const tools::Rectangle &rRect )
51 tools::Long nThumb, nVisible;
52 if( m_bHori )
54 nThumb = rRect.Left();
55 nVisible = rRect.GetWidth();
57 else
59 nThumb = rRect.Top();
60 nVisible = rRect.GetHeight();
63 SetVisibleSize( nVisible );
64 DocSzChgd(m_aDocSz);
65 SetThumbPos( nThumb );
66 if(m_bAuto)
67 AutoShow();
70 void SwScrollbar::ExtendedShow( bool bSet )
72 m_bVisible = bSet;
73 if( (!bSet || !m_bAuto) && IsUpdateMode() && m_bSizeSet)
75 ScrollAdaptor::Show(bSet);
79 void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
81 ScrollAdaptor::SetPosSizePixel(rNewPos, rNewSize);
82 m_bSizeSet = true;
83 if(m_bVisible)
84 ExtendedShow();
87 void SwScrollbar::SetAuto(bool bSet)
89 if(m_bAuto != bSet)
91 m_bAuto = bSet;
93 // hide automatically - then show
94 if(!m_bAuto && m_bVisible && !ScrollAdaptor::IsVisible())
95 ExtendedShow();
96 else if(m_bAuto)
97 AutoShow(); // or hide automatically
101 void SwScrollbar::AutoShow()
103 tools::Long nVis = GetVisibleSize();
104 tools::Long nLen = GetRange().Len();
105 if (nVis >= nLen - 1)
107 if (ScrollAdaptor::IsVisible())
108 ScrollAdaptor::Show(false);
110 else if (!ScrollAdaptor::IsVisible())
112 ScrollAdaptor::Show();
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */