/src/libreoffice/toolkit/source/awt/scrollabledialog.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 <helper/scrollabledialog.hxx> |
21 | | #include <vcl/settings.hxx> |
22 | | |
23 | | namespace 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 ) |
32 | | ScrollableDialog::ScrollableDialog( vcl::Window* pParent, WinBits nStyle, Dialog::InitFlag eFlag ) |
33 | 0 | : Dialog( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ), eFlag ), |
34 | 0 | maHScrollBar( VclPtr<ScrollBar>::Create(this, WB_HSCROLL | WB_DRAG) ), |
35 | 0 | maVScrollBar( VclPtr<ScrollBar>::Create(this, WB_VSCROLL | WB_DRAG) ), |
36 | 0 | mbHasHoriBar( false ), |
37 | 0 | mbHasVertBar( false ), |
38 | 0 | maScrollVis( None ) |
39 | 0 | { |
40 | 0 | Link<ScrollBar*,void> aLink( LINK( this, ScrollableDialog, ScrollBarHdl ) ); |
41 | 0 | maVScrollBar->SetScrollHdl( aLink ); |
42 | 0 | maHScrollBar->SetScrollHdl( aLink ); |
43 | |
|
44 | 0 | ScrollBarVisibility aVis = None; |
45 | |
|
46 | 0 | if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) ) |
47 | 0 | { |
48 | 0 | if ( nStyle & WB_AUTOHSCROLL ) |
49 | 0 | aVis = Hori; |
50 | 0 | if ( nStyle & WB_AUTOVSCROLL ) |
51 | 0 | { |
52 | 0 | if ( aVis == Hori ) |
53 | 0 | aVis = Both; |
54 | 0 | else |
55 | 0 | aVis = Vert; |
56 | 0 | } |
57 | 0 | } |
58 | 0 | setScrollVisibility( aVis ); |
59 | 0 | mnScrWidth = Dialog::GetSettings().GetStyleSettings().GetScrollBarSize(); |
60 | 0 | } Unexecuted instantiation: toolkit::ScrollableDialog::ScrollableDialog(vcl::Window*, long, Dialog::InitFlag) Unexecuted instantiation: toolkit::ScrollableDialog::ScrollableDialog(vcl::Window*, long, Dialog::InitFlag) |
61 | | |
62 | | void ScrollableDialog::setScrollVisibility( ScrollBarVisibility rVisState ) |
63 | 0 | { |
64 | 0 | maScrollVis = rVisState; |
65 | 0 | if ( maScrollVis == Hori || maScrollVis == Both ) |
66 | 0 | { |
67 | 0 | mbHasHoriBar = true; |
68 | 0 | maHScrollBar->Show(); |
69 | 0 | } |
70 | 0 | if ( maScrollVis == Vert || maScrollVis == Both ) |
71 | 0 | { |
72 | 0 | mbHasVertBar = true; |
73 | 0 | maVScrollBar->Show(); |
74 | 0 | } |
75 | 0 | if ( mbHasHoriBar || mbHasVertBar ) |
76 | 0 | SetStyle( Dialog::GetStyle() | WB_CLIPCHILDREN ); |
77 | 0 | } |
78 | | |
79 | | ScrollableDialog::~ScrollableDialog() |
80 | 0 | { |
81 | 0 | disposeOnce(); |
82 | 0 | } |
83 | | |
84 | | void ScrollableDialog::dispose() |
85 | 0 | { |
86 | 0 | maHScrollBar.disposeAndClear(); |
87 | 0 | maVScrollBar.disposeAndClear(); |
88 | 0 | Dialog::dispose(); |
89 | 0 | } |
90 | | |
91 | | void ScrollableDialog::lcl_Scroll( tools::Long nX, tools::Long nY ) |
92 | 0 | { |
93 | 0 | tools::Long nXScroll = mnScrollPos.X() - nX; |
94 | 0 | tools::Long nYScroll = mnScrollPos.Y() - nY; |
95 | 0 | mnScrollPos = Point( nX, nY ); |
96 | |
|
97 | 0 | tools::Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() ); |
98 | 0 | Scroll(nXScroll, nYScroll, aScrollableArea ); |
99 | | // Manually scroll all children ( except the scrollbars ) |
100 | 0 | for ( int index = 0; index < GetChildCount(); ++index ) |
101 | 0 | { |
102 | 0 | vcl::Window* pChild = GetChild( index ); |
103 | 0 | if ( pChild && pChild != maVScrollBar.get() && pChild != maHScrollBar.get() ) |
104 | 0 | { |
105 | 0 | Point aPos = pChild->GetPosPixel(); |
106 | 0 | aPos += Point( nXScroll, nYScroll ); |
107 | 0 | pChild->SetPosPixel( aPos ); |
108 | 0 | } |
109 | 0 | } |
110 | 0 | } |
111 | | |
112 | | IMPL_LINK( ScrollableDialog, ScrollBarHdl, ScrollBar*, pSB, void ) |
113 | 0 | { |
114 | 0 | sal_uInt16 nPos = static_cast<sal_uInt16>(pSB->GetThumbPos()); |
115 | 0 | if( pSB == maVScrollBar.get() ) |
116 | 0 | lcl_Scroll(mnScrollPos.X(), nPos ); |
117 | 0 | else if( pSB == maHScrollBar.get() ) |
118 | 0 | lcl_Scroll(nPos, mnScrollPos.Y() ); |
119 | 0 | } |
120 | | |
121 | | void ScrollableDialog::SetScrollTop( tools::Long nTop ) |
122 | 0 | { |
123 | 0 | Point aOld = mnScrollPos; |
124 | 0 | lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop ); |
125 | 0 | maHScrollBar->SetThumbPos( 0 ); |
126 | | // new pos is 0,0 |
127 | 0 | mnScrollPos = aOld; |
128 | 0 | } |
129 | | void ScrollableDialog::SetScrollLeft( tools::Long nLeft ) |
130 | 0 | { |
131 | 0 | Point aOld = mnScrollPos; |
132 | 0 | lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() ); |
133 | 0 | maVScrollBar->SetThumbPos( 0 ); |
134 | | // new pos is 0,0 |
135 | 0 | mnScrollPos = aOld; |
136 | 0 | } |
137 | | |
138 | | void ScrollableDialog::SetScrollWidth( tools::Long nWidth ) |
139 | 0 | { |
140 | 0 | maScrollArea.setWidth( nWidth ); |
141 | 0 | ResetScrollBars(); |
142 | 0 | } |
143 | | |
144 | | void ScrollableDialog::SetScrollHeight( tools::Long nHeight ) |
145 | 0 | { |
146 | 0 | maScrollArea.setHeight( nHeight ); |
147 | 0 | ResetScrollBars(); |
148 | 0 | } |
149 | | |
150 | | void ScrollableDialog::Resize() |
151 | 0 | { |
152 | 0 | ResetScrollBars(); |
153 | 0 | } |
154 | | |
155 | | void ScrollableDialog::ResetScrollBars() |
156 | 0 | { |
157 | 0 | Size aOutSz = GetOutputSizePixel(); |
158 | |
|
159 | 0 | Point aVPos( aOutSz.Width() - mnScrWidth, 0 ); |
160 | 0 | Point aHPos( 0, aOutSz.Height() - mnScrWidth ); |
161 | |
|
162 | 0 | maVScrollBar->SetPosSizePixel( aVPos, Size( mnScrWidth, GetSizePixel().Height() - mnScrWidth ) ); |
163 | 0 | maHScrollBar->SetPosSizePixel( aHPos, Size( GetSizePixel().Width() - mnScrWidth, mnScrWidth ) ); |
164 | |
|
165 | 0 | maHScrollBar->SetRangeMax( maScrollArea.Width() + mnScrWidth ); |
166 | 0 | maHScrollBar->SetVisibleSize( GetSizePixel().Width() ); |
167 | |
|
168 | 0 | maVScrollBar->SetRangeMax( maScrollArea.Height() + mnScrWidth ); |
169 | 0 | maVScrollBar->SetVisibleSize( GetSizePixel().Height() ); |
170 | 0 | } |
171 | | |
172 | | } // toolkit |
173 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |