/src/libreoffice/sw/source/uibase/uiview/scroll.cxx
Line | Count | Source |
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 <scroll.hxx> |
21 | | |
22 | 0 | #define SCROLL_LINE_SIZE 250 |
23 | | |
24 | | SwScrollbar::SwScrollbar(vcl::Window *pWin, bool bHoriz) |
25 | 0 | : ScrollAdaptor(pWin, bHoriz) |
26 | 0 | , m_bAuto(false) |
27 | 0 | , m_bVisible(false) |
28 | 0 | , m_bSizeSet(false) |
29 | 0 | { |
30 | 0 | m_xScrollBar->show(); |
31 | | |
32 | | // No mirroring for horizontal scrollbars |
33 | 0 | if (bHoriz) |
34 | 0 | m_xScrollBar->set_direction(false); |
35 | 0 | } Unexecuted instantiation: SwScrollbar::SwScrollbar(vcl::Window*, bool) Unexecuted instantiation: SwScrollbar::SwScrollbar(vcl::Window*, bool) |
36 | | |
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 ) |
40 | 0 | { |
41 | 0 | m_aDocSz = rSize; |
42 | 0 | SetRange( Range( 0, m_bHori ? rSize.Width() : rSize.Height()) ); |
43 | 0 | const tools::Long nVisSize = GetVisibleSize(); |
44 | 0 | SetLineSize( SCROLL_LINE_SIZE ); |
45 | 0 | SetPageSize( nVisSize * 77 / 100 ); |
46 | 0 | } |
47 | | |
48 | | // Will be called after a change of the visible view section. |
49 | | void SwScrollbar::ViewPortChgd( const tools::Rectangle &rRect ) |
50 | 0 | { |
51 | 0 | tools::Long nThumb, nVisible; |
52 | 0 | if( m_bHori ) |
53 | 0 | { |
54 | 0 | nThumb = rRect.Left(); |
55 | 0 | nVisible = rRect.GetWidth(); |
56 | 0 | } |
57 | 0 | else |
58 | 0 | { |
59 | 0 | nThumb = rRect.Top(); |
60 | 0 | nVisible = rRect.GetHeight(); |
61 | 0 | } |
62 | |
|
63 | 0 | SetVisibleSize( nVisible ); |
64 | 0 | DocSzChgd(m_aDocSz); |
65 | 0 | SetThumbPos( nThumb ); |
66 | 0 | if(m_bAuto) |
67 | 0 | AutoShow(); |
68 | 0 | } |
69 | | |
70 | | void SwScrollbar::ExtendedShow( bool bSet ) |
71 | 0 | { |
72 | 0 | m_bVisible = bSet; |
73 | 0 | if( (!bSet || !m_bAuto) && IsUpdateMode() && m_bSizeSet) |
74 | 0 | { |
75 | 0 | ScrollAdaptor::Show(bSet); |
76 | 0 | } |
77 | 0 | } |
78 | | |
79 | | void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize ) |
80 | 0 | { |
81 | 0 | ScrollAdaptor::SetPosSizePixel(rNewPos, rNewSize); |
82 | 0 | m_bSizeSet = true; |
83 | 0 | if(m_bVisible) |
84 | 0 | ExtendedShow(); |
85 | 0 | } |
86 | | |
87 | | void SwScrollbar::SetAuto(bool bSet) |
88 | 0 | { |
89 | 0 | if(m_bAuto != bSet) |
90 | 0 | { |
91 | 0 | m_bAuto = bSet; |
92 | | |
93 | | // hide automatically - then show |
94 | 0 | if(!m_bAuto && m_bVisible && !ScrollAdaptor::IsVisible()) |
95 | 0 | ExtendedShow(); |
96 | 0 | else if(m_bAuto) |
97 | 0 | AutoShow(); // or hide automatically |
98 | 0 | } |
99 | 0 | } |
100 | | |
101 | | void SwScrollbar::AutoShow() |
102 | 0 | { |
103 | 0 | tools::Long nVis = GetVisibleSize(); |
104 | 0 | tools::Long nLen = GetRange().Len(); |
105 | 0 | if (nVis >= nLen - 1) |
106 | 0 | { |
107 | 0 | if (ScrollAdaptor::IsVisible()) |
108 | 0 | ScrollAdaptor::Show(false); |
109 | 0 | } |
110 | 0 | else if (!ScrollAdaptor::IsVisible()) |
111 | 0 | { |
112 | 0 | ScrollAdaptor::Show(); |
113 | 0 | } |
114 | 0 | } |
115 | | |
116 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |