LibreOffice Module toolkit (master) 1
scrollabledialog.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
21#include <vcl/settings.hxx>
22
23namespace toolkit
24{
25
26// Using WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a
27// problem in the toolkit class where there are some clashing IDs
28// ( css::awt::VclWindowPeerAttribute::VSCROLL has the same value
29// as css::awt::WindowAttribute::NODECORATION and they are used
30// in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for
31// child classes ( whole thing is a mess if you ask me )
33 : Dialog( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ), eFlag ),
34 maHScrollBar( VclPtr<ScrollBar>::Create(this, WB_HSCROLL | WB_DRAG) ),
35 maVScrollBar( VclPtr<ScrollBar>::Create(this, WB_VSCROLL | WB_DRAG) ),
36 mbHasHoriBar( false ),
37 mbHasVertBar( false ),
38 maScrollVis( None )
39{
40 Link<ScrollBar*,void> aLink( LINK( this, ScrollableDialog, ScrollBarHdl ) );
41 maVScrollBar->SetScrollHdl( aLink );
42 maHScrollBar->SetScrollHdl( aLink );
43
45
46 if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
47 {
48 if ( nStyle & WB_AUTOHSCROLL )
49 aVis = Hori;
50 if ( nStyle & WB_AUTOVSCROLL )
51 {
52 if ( aVis == Hori )
53 aVis = Both;
54 else
55 aVis = Vert;
56 }
57 }
58 setScrollVisibility( aVis );
60}
61
63{
64 maScrollVis = rVisState;
65 if ( maScrollVis == Hori || maScrollVis == Both )
66 {
67 mbHasHoriBar = true;
68 maHScrollBar->Show();
69 }
70 if ( maScrollVis == Vert || maScrollVis == Both )
71 {
72 mbHasVertBar = true;
73 maVScrollBar->Show();
74 }
77}
78
80{
82}
83
85{
89}
90
92{
93 tools::Long nXScroll = mnScrollPos.X() - nX;
94 tools::Long nYScroll = mnScrollPos.Y() - nY;
95 mnScrollPos = Point( nX, nY );
96
97 tools::Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
98 Scroll(nXScroll, nYScroll, aScrollableArea );
99 // Manually scroll all children ( except the scrollbars )
100 for ( int index = 0; index < GetChildCount(); ++index )
101 {
102 vcl::Window* pChild = GetChild( index );
103 if ( pChild && pChild != maVScrollBar.get() && pChild != maHScrollBar.get() )
104 {
105 Point aPos = pChild->GetPosPixel();
106 aPos += Point( nXScroll, nYScroll );
107 pChild->SetPosPixel( aPos );
108 }
109 }
110}
111
112IMPL_LINK( ScrollableDialog, ScrollBarHdl, ScrollBar*, pSB, void )
113{
114 sal_uInt16 nPos = static_cast<sal_uInt16>(pSB->GetThumbPos());
115 if( pSB == maVScrollBar.get() )
116 lcl_Scroll(mnScrollPos.X(), nPos );
117 else if( pSB == maHScrollBar.get() )
118 lcl_Scroll(nPos, mnScrollPos.Y() );
119}
120
122{
123 Point aOld = mnScrollPos;
124 lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
125 maHScrollBar->SetThumbPos( 0 );
126 // new pos is 0,0
127 mnScrollPos = aOld;
128}
130{
131 Point aOld = mnScrollPos;
132 lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
133 maVScrollBar->SetThumbPos( 0 );
134 // new pos is 0,0
135 mnScrollPos = aOld;
136}
137
139{
140 maScrollArea.setWidth( nWidth );
142}
143
145{
146 maScrollArea.setHeight( nHeight );
148}
149
151{
153}
154
156{
157 Size aOutSz = GetOutputSizePixel();
158
159 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
160 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
161
162 maVScrollBar->SetPosSizePixel( aVPos, Size( mnScrWidth, GetSizePixel().Height() - mnScrWidth ) );
163 maHScrollBar->SetPosSizePixel( aHPos, Size( GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
164
165 maHScrollBar->SetRangeMax( maScrollArea.Width() + mnScrWidth );
166 maHScrollBar->SetVisibleSize( GetSizePixel().Width() );
167
168 maVScrollBar->SetRangeMax( maScrollArea.Height() + mnScrWidth );
169 maVScrollBar->SetVisibleSize( GetSizePixel().Height() );
170}
171
172} // toolkit
173/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
virtual void dispose() override
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
sal_Int32 GetScrollBarSize() const
void disposeAndClear()
reference_type * get() const
void SetScrollLeft(tools::Long nLeft)
VclPtr< ScrollBar > maHScrollBar
ScrollableDialog(vcl::Window *pParent, WinBits nStyle, Dialog::InitFlag eFlag=Dialog::InitFlag::Default)
virtual void Resize() override
ScrollBarVisibility maScrollVis
VclPtr< ScrollBar > maVScrollBar
void lcl_Scroll(tools::Long nX, tools::Long nY)
void SetScrollWidth(tools::Long nWidth)
void SetScrollTop(tools::Long Top)
virtual void dispose() override
virtual ~ScrollableDialog() override
void SetScrollHeight(tools::Long nHeight)
void setScrollVisibility(ScrollBarVisibility rState)
void SetStyle(WinBits nStyle)
sal_uInt16 GetChildCount() const
virtual Point GetPosPixel() const
WinBits GetStyle() const
const AllSettings & GetSettings() const
virtual void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
virtual Size GetSizePixel() const
Size GetOutputSizePixel() const
virtual void SetPosPixel(const Point &rNewPos)
vcl::Window * GetChild(sal_uInt16 nChild) const
sal_uInt16 nPos
index
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
None
IMPL_LINK(ScrollableDialog, ScrollBarHdl, ScrollBar *, pSB, void)
long Long
sal_Int64 WinBits
WinBits const WB_DRAG
WinBits const WB_AUTOVSCROLL
WinBits const WB_AUTOHSCROLL
WinBits const WB_VSCROLL
WinBits const WB_CLIPCHILDREN
WinBits const WB_HSCROLL