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