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