bump product version to 6.3.0.0.beta1
[LibreOffice.git] / toolkit / source / awt / scrollabledialog.cxx
blobff9abf48b58d3a0ae936c45eb02b98450b5fe866
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 <helper/scrollabledialog.hxx>
21 #include <vcl/settings.hxx>
23 namespace toolkit
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 )
32 ScrollableDialog::ScrollableDialog( vcl::Window* pParent, WinBits nStyle, Dialog::InitFlag eFlag )
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 )
40 Link<ScrollBar*,void> aLink( LINK( this, ScrollableDialog, ScrollBarHdl ) );
41 maVScrollBar->SetScrollHdl( aLink );
42 maHScrollBar->SetScrollHdl( aLink );
44 ScrollBarVisibility aVis = None;
46 if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
48 if ( nStyle & WB_AUTOHSCROLL )
49 aVis = Hori;
50 if ( nStyle & WB_AUTOVSCROLL )
52 if ( aVis == Hori )
53 aVis = Both;
54 else
55 aVis = Vert;
58 setScrollVisibility( aVis );
59 mnScrWidth = Dialog::GetSettings().GetStyleSettings().GetScrollBarSize();
62 void ScrollableDialog::setScrollVisibility( ScrollBarVisibility rVisState )
64 maScrollVis = rVisState;
65 if ( maScrollVis == Hori || maScrollVis == Both )
67 mbHasHoriBar = true;
68 maHScrollBar->Show();
70 if ( maScrollVis == Vert || maScrollVis == Both )
72 mbHasVertBar = true;
73 maVScrollBar->Show();
75 if ( mbHasHoriBar || mbHasVertBar )
76 SetStyle( Dialog::GetStyle() | WB_CLIPCHILDREN );
79 ScrollableDialog::~ScrollableDialog()
81 disposeOnce();
84 void ScrollableDialog::dispose()
86 maHScrollBar.disposeAndClear();
87 maVScrollBar.disposeAndClear();
88 Dialog::dispose();
91 void ScrollableDialog::lcl_Scroll( long nX, long nY )
93 long nXScroll = mnScrollPos.X() - nX;
94 long nYScroll = mnScrollPos.Y() - nY;
95 mnScrollPos = Point( nX, nY );
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 )
102 vcl::Window* pChild = GetChild( index );
103 if ( pChild && pChild != maVScrollBar.get() && pChild != maHScrollBar.get() )
105 Point aPos = pChild->GetPosPixel();
106 aPos += Point( nXScroll, nYScroll );
107 pChild->SetPosPixel( aPos );
112 IMPL_LINK( ScrollableDialog, ScrollBarHdl, ScrollBar*, pSB, void )
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() );
121 void ScrollableDialog::SetScrollTop( long nTop )
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;
129 void ScrollableDialog::SetScrollLeft( long nLeft )
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;
138 void ScrollableDialog::SetScrollWidth( long nWidth )
140 maScrollArea.setWidth( nWidth );
141 ResetScrollBars();
144 void ScrollableDialog::SetScrollHeight( long nHeight )
146 maScrollArea.setHeight( nHeight );
147 ResetScrollBars();
150 void ScrollableDialog::Resize()
152 ResetScrollBars();
155 void ScrollableDialog::ResetScrollBars()
157 Size aOutSz = GetOutputSizePixel();
159 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
160 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
162 maVScrollBar->SetPosSizePixel( aVPos, Size( mnScrWidth, GetSizePixel().Height() - mnScrWidth ) );
163 maHScrollBar->SetPosSizePixel( aHPos, Size( GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
165 maHScrollBar->SetRangeMax( maScrollArea.Width() + mnScrWidth );
166 maHScrollBar->SetVisibleSize( GetSizePixel().Width() );
168 maVScrollBar->SetRangeMax( maScrollArea.Height() + mnScrWidth );
169 maVScrollBar->SetVisibleSize( GetSizePixel().Height() );
172 } // toolkit
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */