xref: /trunk/main/svtools/source/control/scrwin.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55900e8ecSAndrew Rist  * distributed with this work for additional information
65900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist  * software distributed under the License is distributed on an
155900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
175900e8ecSAndrew Rist  * specific language governing permissions and limitations
185900e8ecSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205900e8ecSAndrew Rist  *************************************************************/
215900e8ecSAndrew Rist 
225900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _SVT_SCRWIN_CXX
28cdf0e10cSrcweir #include <svtools/scrwin.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir //===================================================================
31cdf0e10cSrcweir 
ImpInitialize(ScrollableWindowFlags nFlags)32cdf0e10cSrcweir void ScrollableWindow::ImpInitialize( ScrollableWindowFlags nFlags )
33cdf0e10cSrcweir {
34cdf0e10cSrcweir     bHandleDragging = (sal_Bool) ( nFlags & SCRWIN_THUMBDRAGGING );
35cdf0e10cSrcweir     bVCenter = (nFlags & SCRWIN_VCENTER) == SCRWIN_VCENTER;
36cdf0e10cSrcweir     bHCenter = (nFlags & SCRWIN_HCENTER) == SCRWIN_HCENTER;
37cdf0e10cSrcweir     bScrolling = sal_False;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir     // set the handlers for the scrollbars
40cdf0e10cSrcweir     aVScroll.SetScrollHdl( LINK(this, ScrollableWindow, ScrollHdl) );
41cdf0e10cSrcweir     aHScroll.SetScrollHdl( LINK(this, ScrollableWindow, ScrollHdl) );
42cdf0e10cSrcweir     aVScroll.SetEndScrollHdl( LINK(this, ScrollableWindow, EndScrollHdl) );
43cdf0e10cSrcweir     aHScroll.SetEndScrollHdl( LINK(this, ScrollableWindow, EndScrollHdl) );
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     nColumnPixW = nLinePixH = GetSettings().GetStyleSettings().GetScrollBarSize();
46cdf0e10cSrcweir }
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //-------------------------------------------------------------------
49cdf0e10cSrcweir 
ScrollableWindow(Window * pParent,WinBits nBits,ScrollableWindowFlags nFlags)50cdf0e10cSrcweir ScrollableWindow::ScrollableWindow( Window* pParent, WinBits nBits,
51cdf0e10cSrcweir                                     ScrollableWindowFlags nFlags ) :
52cdf0e10cSrcweir     Window( pParent, WinBits(nBits|WB_CLIPCHILDREN) ),
53cdf0e10cSrcweir     aVScroll( this, WinBits(WB_VSCROLL | WB_DRAG) ),
54cdf0e10cSrcweir     aHScroll( this, WinBits(WB_HSCROLL | WB_DRAG) ),
55cdf0e10cSrcweir     aCornerWin( this )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     ImpInitialize( nFlags );
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //-------------------------------------------------------------------
61cdf0e10cSrcweir 
ScrollableWindow(Window * pParent,const ResId & rId,ScrollableWindowFlags nFlags)62cdf0e10cSrcweir ScrollableWindow::ScrollableWindow( Window* pParent, const ResId& rId,
63cdf0e10cSrcweir                                     ScrollableWindowFlags nFlags ) :
64cdf0e10cSrcweir     Window( pParent, rId ),
65cdf0e10cSrcweir     aVScroll( this, WinBits(WB_VSCROLL | WB_DRAG) ),
66cdf0e10cSrcweir     aHScroll( this, WinBits(WB_HSCROLL | WB_DRAG) ),
67cdf0e10cSrcweir     aCornerWin( this )
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     ImpInitialize( nFlags );
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir // -----------------------------------------------------------------------
73cdf0e10cSrcweir 
Command(const CommandEvent & rCEvt)74cdf0e10cSrcweir void ScrollableWindow::Command( const CommandEvent& rCEvt )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     if ( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
77cdf0e10cSrcweir          (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
78cdf0e10cSrcweir          (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         ScrollBar* pHScrBar;
81cdf0e10cSrcweir         ScrollBar* pVScrBar;
82cdf0e10cSrcweir         if ( aHScroll.IsVisible() )
83cdf0e10cSrcweir             pHScrBar = &aHScroll;
84cdf0e10cSrcweir         else
85cdf0e10cSrcweir             pHScrBar = NULL;
86cdf0e10cSrcweir         if ( aVScroll.IsVisible() )
87cdf0e10cSrcweir             pVScrBar = &aVScroll;
88cdf0e10cSrcweir         else
89cdf0e10cSrcweir             pVScrBar = NULL;
90cdf0e10cSrcweir         if ( HandleScrollCommand( rCEvt, pHScrBar, pVScrBar ) )
91cdf0e10cSrcweir             return;
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     Window::Command( rCEvt );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir //-------------------------------------------------------------------
98cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)99cdf0e10cSrcweir void ScrollableWindow::DataChanged( const DataChangedEvent& rDCEvt )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
102cdf0e10cSrcweir          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
103cdf0e10cSrcweir     {
104cdf0e10cSrcweir         Resize();
105cdf0e10cSrcweir         Invalidate();
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     Window::DataChanged( rDCEvt );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //-------------------------------------------------------------------
112cdf0e10cSrcweir 
GetOutputSizePixel() const113cdf0e10cSrcweir Size __EXPORT ScrollableWindow::GetOutputSizePixel() const
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     Size aSz( Window::GetOutputSizePixel() );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize();
118cdf0e10cSrcweir     if ( aHScroll.IsVisible() )
119cdf0e10cSrcweir         aSz.Height() -= nTmp;
120cdf0e10cSrcweir     if ( aVScroll.IsVisible() )
121cdf0e10cSrcweir         aSz.Width() -= nTmp;
122cdf0e10cSrcweir     return aSz;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir //-------------------------------------------------------------------
126cdf0e10cSrcweir 
GetOutputSize() const127cdf0e10cSrcweir Size ScrollableWindow::GetOutputSize() const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     return PixelToLogic( GetOutputSizePixel() );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir //-------------------------------------------------------------------
133cdf0e10cSrcweir 
IMPL_LINK(ScrollableWindow,EndScrollHdl,ScrollBar *,pScroll)134cdf0e10cSrcweir IMPL_LINK( ScrollableWindow, EndScrollHdl, ScrollBar *, pScroll )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     // notify the start of scrolling, if not already scrolling
137cdf0e10cSrcweir     if ( !bScrolling )
138cdf0e10cSrcweir         StartScroll(), bScrolling = sal_True;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // get the delta in logic coordinates
141cdf0e10cSrcweir     Size aDelta( PixelToLogic( Size( aHScroll.GetDelta(), aVScroll.GetDelta() ) ) );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     // scroll the window, if this is not already done
144cdf0e10cSrcweir     if ( !bHandleDragging )
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         if ( pScroll == &aHScroll )
147cdf0e10cSrcweir             Scroll( aDelta.Width(), 0 );
148cdf0e10cSrcweir         else
149cdf0e10cSrcweir             Scroll( 0, aDelta.Height() );
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // notify the end of scrolling
153cdf0e10cSrcweir     bScrolling = sal_False;
154cdf0e10cSrcweir     EndScroll( aDelta.Width(), aDelta.Height() );
155cdf0e10cSrcweir     return 0;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir //-------------------------------------------------------------------
159cdf0e10cSrcweir 
IMPL_LINK(ScrollableWindow,ScrollHdl,ScrollBar *,pScroll)160cdf0e10cSrcweir IMPL_LINK( ScrollableWindow, ScrollHdl, ScrollBar *, pScroll )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     // notify the start of scrolling, if not already scrolling
163cdf0e10cSrcweir     if ( !bScrolling )
164cdf0e10cSrcweir         StartScroll(), bScrolling = sal_True;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir     if ( bHandleDragging )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         // get the delta in logic coordinates
169cdf0e10cSrcweir         Size aDelta( PixelToLogic(
170cdf0e10cSrcweir             Size( aHScroll.GetDelta(), aVScroll.GetDelta() ) ) );
171cdf0e10cSrcweir         if ( pScroll == &aHScroll )
172cdf0e10cSrcweir             Scroll( aDelta.Width(), 0 );
173cdf0e10cSrcweir         else
174cdf0e10cSrcweir             Scroll( 0, aDelta.Height() );
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir     return 0;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //-------------------------------------------------------------------
180cdf0e10cSrcweir 
Resize()181cdf0e10cSrcweir void __EXPORT ScrollableWindow::Resize()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     // get the new output-size in pixel
184cdf0e10cSrcweir     Size aOutPixSz = Window::GetOutputSizePixel();
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     // determine the size of the output-area and if we need scrollbars
187cdf0e10cSrcweir     const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize();
188cdf0e10cSrcweir     sal_Bool bVVisible = sal_False; // by default no vertical-ScrollBar
189cdf0e10cSrcweir     sal_Bool bHVisible = sal_False; // by default no horizontal-ScrollBar
190*51754c86SJohn Bampton     sal_Bool bChanged;          // determines if a visibility was changed
191cdf0e10cSrcweir     do
192cdf0e10cSrcweir     {
193cdf0e10cSrcweir         bChanged = sal_False;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         // does we need a vertical ScrollBar
196cdf0e10cSrcweir         if ( aOutPixSz.Width() < aTotPixSz.Width() && !bHVisible )
197cdf0e10cSrcweir         {   bHVisible = sal_True;
198cdf0e10cSrcweir             aOutPixSz.Height() -= nScrSize;
199cdf0e10cSrcweir             bChanged = sal_True;
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         // does we need a horizontal ScrollBar
203cdf0e10cSrcweir         if ( aOutPixSz.Height() < aTotPixSz.Height() && !bVVisible )
204cdf0e10cSrcweir         {   bVVisible = sal_True;
205cdf0e10cSrcweir             aOutPixSz.Width() -= nScrSize;
206cdf0e10cSrcweir             bChanged = sal_True;
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir     while ( bChanged );   // until no visibility has changed
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     // store the old offset and map-mode
213cdf0e10cSrcweir     MapMode aMap( GetMapMode() );
214cdf0e10cSrcweir     Point aOldPixOffset( aPixOffset );
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     // justify (right/bottom borders should never exceed the virtual window)
217cdf0e10cSrcweir     Size aPixDelta;
218cdf0e10cSrcweir     if ( aPixOffset.X() < 0 &&
219cdf0e10cSrcweir          aPixOffset.X() + aTotPixSz.Width() < aOutPixSz.Width() )
220cdf0e10cSrcweir         aPixDelta.Width() =
221cdf0e10cSrcweir             aOutPixSz.Width() - ( aPixOffset.X() + aTotPixSz.Width() );
222cdf0e10cSrcweir     if ( aPixOffset.Y() < 0 &&
223cdf0e10cSrcweir          aPixOffset.Y() + aTotPixSz.Height() < aOutPixSz.Height() )
224cdf0e10cSrcweir         aPixDelta.Height() =
225cdf0e10cSrcweir             aOutPixSz.Height() - ( aPixOffset.Y() + aTotPixSz.Height() );
226cdf0e10cSrcweir     if ( aPixDelta.Width() || aPixDelta.Height() )
227cdf0e10cSrcweir     {
228cdf0e10cSrcweir         aPixOffset.X() += aPixDelta.Width();
229cdf0e10cSrcweir         aPixOffset.Y() += aPixDelta.Height();
230cdf0e10cSrcweir     }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     // for axis without scrollbar restore the origin
233cdf0e10cSrcweir     if ( !bVVisible || !bHVisible )
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         aPixOffset = Point(
236cdf0e10cSrcweir                      bHVisible
237cdf0e10cSrcweir                      ? aPixOffset.X()
238cdf0e10cSrcweir                      : ( bHCenter
239cdf0e10cSrcweir                             ? (aOutPixSz.Width()-aTotPixSz.Width()) / 2
240cdf0e10cSrcweir                             : 0 ),
241cdf0e10cSrcweir                      bVVisible
242cdf0e10cSrcweir                      ? aPixOffset.Y()
243cdf0e10cSrcweir                      : ( bVCenter
244cdf0e10cSrcweir                             ? (aOutPixSz.Height()-aTotPixSz.Height()) / 2
245cdf0e10cSrcweir                             : 0 ) );
246cdf0e10cSrcweir     }
247cdf0e10cSrcweir     if ( bHVisible && !aHScroll.IsVisible() )
248cdf0e10cSrcweir         aPixOffset.X() = 0;
249cdf0e10cSrcweir     if ( bVVisible && !aVScroll.IsVisible() )
250cdf0e10cSrcweir         aPixOffset.Y() = 0;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir     // select the shifted map-mode
253cdf0e10cSrcweir     if ( aPixOffset != aOldPixOffset )
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         Window::SetMapMode( MapMode( MAP_PIXEL ) );
256cdf0e10cSrcweir         Window::Scroll(
257cdf0e10cSrcweir             aPixOffset.X() - aOldPixOffset.X(),
258cdf0e10cSrcweir             aPixOffset.Y() - aOldPixOffset.Y() );
259cdf0e10cSrcweir         SetMapMode( aMap );
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     // show or hide scrollbars
263cdf0e10cSrcweir     aVScroll.Show( bVVisible );
264cdf0e10cSrcweir     aHScroll.Show( bHVisible );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir     // disable painting in the corner between the scrollbars
267cdf0e10cSrcweir     if ( bVVisible && bHVisible )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         aCornerWin.SetPosSizePixel(Point(aOutPixSz.Width(), aOutPixSz.Height()),
270cdf0e10cSrcweir             Size(nScrSize, nScrSize) );
271cdf0e10cSrcweir         aCornerWin.Show();
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir     else
274cdf0e10cSrcweir         aCornerWin.Hide();
275cdf0e10cSrcweir 
276cdf0e10cSrcweir     // resize scrollbars and set their ranges
277cdf0e10cSrcweir     if ( bHVisible )
278cdf0e10cSrcweir     {
279cdf0e10cSrcweir         aHScroll.SetPosSizePixel(
280cdf0e10cSrcweir             Point( 0, aOutPixSz.Height() ),
281cdf0e10cSrcweir             Size( aOutPixSz.Width(), nScrSize ) );
282cdf0e10cSrcweir         aHScroll.SetRange( Range( 0, aTotPixSz.Width() ) );
283cdf0e10cSrcweir         aHScroll.SetPageSize( aOutPixSz.Width() );
284cdf0e10cSrcweir         aHScroll.SetVisibleSize( aOutPixSz.Width() );
285cdf0e10cSrcweir         aHScroll.SetLineSize( nColumnPixW );
286cdf0e10cSrcweir         aHScroll.SetThumbPos( -aPixOffset.X() );
287cdf0e10cSrcweir     }
288cdf0e10cSrcweir     if ( bVVisible )
289cdf0e10cSrcweir     {
290cdf0e10cSrcweir         aVScroll.SetPosSizePixel(
291cdf0e10cSrcweir             Point( aOutPixSz.Width(), 0 ),
292cdf0e10cSrcweir             Size( nScrSize,aOutPixSz.Height() ) );
293cdf0e10cSrcweir         aVScroll.SetRange( Range( 0, aTotPixSz.Height() ) );
294cdf0e10cSrcweir         aVScroll.SetPageSize( aOutPixSz.Height() );
295cdf0e10cSrcweir         aVScroll.SetVisibleSize( aOutPixSz.Height() );
296cdf0e10cSrcweir         aVScroll.SetLineSize( nLinePixH );
297cdf0e10cSrcweir         aVScroll.SetThumbPos( -aPixOffset.Y() );
298cdf0e10cSrcweir     }
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir //-------------------------------------------------------------------
302cdf0e10cSrcweir 
StartScroll()303cdf0e10cSrcweir void __EXPORT ScrollableWindow::StartScroll()
304cdf0e10cSrcweir {
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir //-------------------------------------------------------------------
308cdf0e10cSrcweir 
EndScroll(long,long)309cdf0e10cSrcweir void __EXPORT ScrollableWindow::EndScroll( long, long )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir //-------------------------------------------------------------------
314cdf0e10cSrcweir 
SetMapMode(const MapMode & rNewMapMode)315cdf0e10cSrcweir void ScrollableWindow::SetMapMode( const MapMode& rNewMapMode )
316cdf0e10cSrcweir {
317cdf0e10cSrcweir     MapMode aMap( rNewMapMode );
318cdf0e10cSrcweir     aMap.SetOrigin( aMap.GetOrigin() + PixelToLogic( aPixOffset, aMap ) );
319cdf0e10cSrcweir     Window::SetMapMode( aMap );
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir //-------------------------------------------------------------------
323cdf0e10cSrcweir 
GetMapMode() const324cdf0e10cSrcweir MapMode ScrollableWindow::GetMapMode() const
325cdf0e10cSrcweir {
326cdf0e10cSrcweir     MapMode aMap( Window::GetMapMode() );
327cdf0e10cSrcweir     aMap.SetOrigin( aMap.GetOrigin() - PixelToLogic( aPixOffset ) );
328cdf0e10cSrcweir     return aMap;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir 
331cdf0e10cSrcweir //-------------------------------------------------------------------
332cdf0e10cSrcweir 
SetTotalSize(const Size & rNewSize)333cdf0e10cSrcweir void ScrollableWindow::SetTotalSize( const Size& rNewSize )
334cdf0e10cSrcweir {
335cdf0e10cSrcweir     aTotPixSz = LogicToPixel( rNewSize );
336cdf0e10cSrcweir     ScrollableWindow::Resize();
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir //-------------------------------------------------------------------
340cdf0e10cSrcweir 
SetVisibleSize(const Size & rNewSize)341cdf0e10cSrcweir void ScrollableWindow::SetVisibleSize( const Size& rNewSize )
342cdf0e10cSrcweir {
343cdf0e10cSrcweir     // get the rectangle, we wish to view
344cdf0e10cSrcweir     Rectangle aWish( Point(0, 0), LogicToPixel(rNewSize) );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     // get maximum rectangle for us from our parent-window (subst our border!)
347cdf0e10cSrcweir     Rectangle aMax( Point(0, 0), GetParent()->GetOutputSizePixel() );
348cdf0e10cSrcweir     aMax.Left() -=  ( Window::GetSizePixel().Width() -
349cdf0e10cSrcweir                     Window::GetOutputSizePixel().Width() );
350cdf0e10cSrcweir     aMax.Bottom() -= (Window::GetSizePixel().Height() -
351cdf0e10cSrcweir                      Window::GetOutputSizePixel().Height());
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     Size aWill( aWish.GetIntersection(aMax).GetSize() );
354cdf0e10cSrcweir     sal_Bool bHScroll = sal_False;
355cdf0e10cSrcweir     const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize();
356cdf0e10cSrcweir     if ( aWill.Width() < aWish.GetSize().Width() )
357cdf0e10cSrcweir     {   bHScroll = sal_True;
358cdf0e10cSrcweir         aWill.Height() =
359cdf0e10cSrcweir             Min( aWill.Height()+nScrSize, aMax.GetSize().Height() );
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir     if ( aWill.Height() < aWish.GetSize().Height() )
362cdf0e10cSrcweir         aWill.Width() =
363cdf0e10cSrcweir             Min( aWill.Width()+nScrSize, aMax.GetSize().Width() );
364cdf0e10cSrcweir     if ( !bHScroll && (aWill.Width() < aWish.GetSize().Width()) )
365cdf0e10cSrcweir         aWill.Height() =
366cdf0e10cSrcweir             Min( aWill.Height()+nScrSize, aMax.GetSize().Height() );
367cdf0e10cSrcweir     Window::SetOutputSizePixel( aWill );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir //-------------------------------------------------------------------
371cdf0e10cSrcweir 
MakeVisible(const Rectangle & rTarget,sal_Bool bSloppy)372cdf0e10cSrcweir sal_Bool ScrollableWindow::MakeVisible( const Rectangle& rTarget, sal_Bool bSloppy )
373cdf0e10cSrcweir {
374cdf0e10cSrcweir     Rectangle aTarget;
375cdf0e10cSrcweir     Rectangle aTotRect( Point(0, 0), PixelToLogic( aTotPixSz ) );
376cdf0e10cSrcweir 
377cdf0e10cSrcweir     if ( bSloppy )
378cdf0e10cSrcweir     {
379cdf0e10cSrcweir         aTarget = rTarget;
380cdf0e10cSrcweir 
381cdf0e10cSrcweir         // at maximum to right border
382cdf0e10cSrcweir         if ( aTarget.Right() > aTotRect.Right() )
383cdf0e10cSrcweir         {
384cdf0e10cSrcweir             long nDelta = aTarget.Right() - aTotRect.Right();
385cdf0e10cSrcweir             aTarget.Left() -= nDelta;
386cdf0e10cSrcweir             aTarget.Right() -= nDelta;
387cdf0e10cSrcweir 
388cdf0e10cSrcweir             // too wide?
389cdf0e10cSrcweir             if ( aTarget.Left() < aTotRect.Left() )
390cdf0e10cSrcweir                 aTarget.Left() = aTotRect.Left();
391cdf0e10cSrcweir         }
392cdf0e10cSrcweir 
393cdf0e10cSrcweir         // at maximum to bottom border
394cdf0e10cSrcweir         if ( aTarget.Bottom() > aTotRect.Bottom() )
395cdf0e10cSrcweir         {
396cdf0e10cSrcweir             long nDelta = aTarget.Bottom() - aTotRect.Bottom();
397cdf0e10cSrcweir             aTarget.Top() -= nDelta;
398cdf0e10cSrcweir             aTarget.Bottom() -= nDelta;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir             // too high?
401cdf0e10cSrcweir             if ( aTarget.Top() < aTotRect.Top() )
402cdf0e10cSrcweir                 aTarget.Top() = aTotRect.Top();
403cdf0e10cSrcweir         }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir         // at maximum to left border
406cdf0e10cSrcweir         if ( aTarget.Left() < aTotRect.Left() )
407cdf0e10cSrcweir         {
408cdf0e10cSrcweir             long nDelta = aTarget.Left() - aTotRect.Left();
409cdf0e10cSrcweir             aTarget.Right() -= nDelta;
410cdf0e10cSrcweir             aTarget.Left() -= nDelta;
411cdf0e10cSrcweir 
412cdf0e10cSrcweir             // too wide?
413cdf0e10cSrcweir             if ( aTarget.Right() > aTotRect.Right() )
414cdf0e10cSrcweir                 aTarget.Right() = aTotRect.Right();
415cdf0e10cSrcweir         }
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         // at maximum to top border
418cdf0e10cSrcweir         if ( aTarget.Top() < aTotRect.Top() )
419cdf0e10cSrcweir         {
420cdf0e10cSrcweir             long nDelta = aTarget.Top() - aTotRect.Top();
421cdf0e10cSrcweir             aTarget.Bottom() -= nDelta;
422cdf0e10cSrcweir             aTarget.Top() -= nDelta;
423cdf0e10cSrcweir 
424cdf0e10cSrcweir             // too high?
425cdf0e10cSrcweir             if ( aTarget.Bottom() > aTotRect.Bottom() )
426cdf0e10cSrcweir                 aTarget.Bottom() = aTotRect.Bottom();
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir     }
429cdf0e10cSrcweir     else
430cdf0e10cSrcweir         aTarget = rTarget.GetIntersection( aTotRect );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir     // is the area already visible?
433cdf0e10cSrcweir     Rectangle aVisArea( GetVisibleArea() );
434cdf0e10cSrcweir     if ( aVisArea.IsInside(rTarget) )
435cdf0e10cSrcweir         return sal_True;
436cdf0e10cSrcweir 
437cdf0e10cSrcweir     // is there somewhat to scroll?
438cdf0e10cSrcweir     if ( aVisArea.TopLeft() != aTarget.TopLeft() )
439cdf0e10cSrcweir     {
440cdf0e10cSrcweir         Rectangle aBox( aTarget.GetUnion(aVisArea) );
441cdf0e10cSrcweir         long  nDeltaX = ( aBox.Right() - aVisArea.Right() ) +
442cdf0e10cSrcweir                         ( aBox.Left() - aVisArea.Left() );
443cdf0e10cSrcweir         long  nDeltaY = ( aBox.Top() - aVisArea.Top() ) +
444cdf0e10cSrcweir                         ( aBox.Bottom() - aVisArea.Bottom() );
445cdf0e10cSrcweir         Scroll( nDeltaX, nDeltaY );
446cdf0e10cSrcweir     }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir     // determine if the target is completely visible
449cdf0e10cSrcweir     return aVisArea.GetWidth() >= aTarget.GetWidth() &&
450cdf0e10cSrcweir            aVisArea.GetHeight() >= aTarget.GetHeight();
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453cdf0e10cSrcweir //-------------------------------------------------------------------
454cdf0e10cSrcweir 
GetVisibleArea() const455cdf0e10cSrcweir Rectangle ScrollableWindow::GetVisibleArea() const
456cdf0e10cSrcweir {
457cdf0e10cSrcweir     Point aTopLeft( PixelToLogic( Point() ) );
458cdf0e10cSrcweir     Size aSz( GetOutputSize() );
459cdf0e10cSrcweir     return Rectangle( aTopLeft, aSz );
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir //-------------------------------------------------------------------
463cdf0e10cSrcweir 
SetLineSize(sal_uLong nHorz,sal_uLong nVert)464cdf0e10cSrcweir void ScrollableWindow::SetLineSize( sal_uLong nHorz, sal_uLong nVert )
465cdf0e10cSrcweir {
466cdf0e10cSrcweir     Size aPixSz( LogicToPixel( Size(nHorz, nVert) ) );
467cdf0e10cSrcweir     nColumnPixW = aPixSz.Width();
468cdf0e10cSrcweir     nLinePixH = aPixSz.Height();
469cdf0e10cSrcweir     aVScroll.SetLineSize( nLinePixH );
470cdf0e10cSrcweir     aHScroll.SetLineSize( nColumnPixW );
471cdf0e10cSrcweir }
472cdf0e10cSrcweir 
473cdf0e10cSrcweir //-------------------------------------------------------------------
474cdf0e10cSrcweir 
Scroll(long nDeltaX,long nDeltaY,sal_uInt16)475cdf0e10cSrcweir void ScrollableWindow::Scroll( long nDeltaX, long nDeltaY, sal_uInt16 )
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     if ( !bScrolling )
478cdf0e10cSrcweir         StartScroll();
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     // get the delta in pixel
481cdf0e10cSrcweir     Size aDeltaPix( LogicToPixel( Size(nDeltaX, nDeltaY) ) );
482cdf0e10cSrcweir     Size aOutPixSz( GetOutputSizePixel() );
483cdf0e10cSrcweir     MapMode aMap( GetMapMode() );
484cdf0e10cSrcweir     Point aNewPixOffset( aPixOffset );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     // scrolling horizontally?
487cdf0e10cSrcweir     if ( nDeltaX != 0 )
488cdf0e10cSrcweir     {
489cdf0e10cSrcweir         aNewPixOffset.X() -= aDeltaPix.Width();
490cdf0e10cSrcweir         if ( ( aOutPixSz.Width() - aNewPixOffset.X() ) > aTotPixSz.Width() )
491cdf0e10cSrcweir             aNewPixOffset.X() = - ( aTotPixSz.Width() - aOutPixSz.Width() );
492cdf0e10cSrcweir         else if ( aNewPixOffset.X() > 0 )
493cdf0e10cSrcweir             aNewPixOffset.X() = 0;
494cdf0e10cSrcweir     }
495cdf0e10cSrcweir 
496cdf0e10cSrcweir     // scrolling vertically?
497cdf0e10cSrcweir     if ( nDeltaY != 0 )
498cdf0e10cSrcweir     {
499cdf0e10cSrcweir         aNewPixOffset.Y() -= aDeltaPix.Height();
500cdf0e10cSrcweir         if ( ( aOutPixSz.Height() - aNewPixOffset.Y() ) > aTotPixSz.Height() )
501cdf0e10cSrcweir             aNewPixOffset.Y() = - ( aTotPixSz.Height() - aOutPixSz.Height() );
502cdf0e10cSrcweir         else if ( aNewPixOffset.Y() > 0 )
503cdf0e10cSrcweir             aNewPixOffset.Y() = 0;
504cdf0e10cSrcweir     }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     // recompute the logical scroll units
507cdf0e10cSrcweir     aDeltaPix.Width() = aPixOffset.X() - aNewPixOffset.X();
508cdf0e10cSrcweir     aDeltaPix.Height() = aPixOffset.Y() - aNewPixOffset.Y();
509cdf0e10cSrcweir     Size aDelta( PixelToLogic(aDeltaPix) );
510cdf0e10cSrcweir     nDeltaX = aDelta.Width();
511cdf0e10cSrcweir     nDeltaY = aDelta.Height();
512cdf0e10cSrcweir     aPixOffset = aNewPixOffset;
513cdf0e10cSrcweir 
514cdf0e10cSrcweir     // scrolling?
515cdf0e10cSrcweir     if ( nDeltaX != 0 || nDeltaY != 0 )
516cdf0e10cSrcweir     {
517cdf0e10cSrcweir         Update();
518cdf0e10cSrcweir 
519cdf0e10cSrcweir         // does the new area overlap the old one?
520cdf0e10cSrcweir         if ( Abs( (int)aDeltaPix.Height() ) < aOutPixSz.Height() ||
521cdf0e10cSrcweir              Abs( (int)aDeltaPix.Width() ) < aOutPixSz.Width() )
522cdf0e10cSrcweir         {
523cdf0e10cSrcweir             // scroll the overlapping area
524cdf0e10cSrcweir             SetMapMode( aMap );
525cdf0e10cSrcweir 
526cdf0e10cSrcweir             // never scroll the scrollbars itself!
527cdf0e10cSrcweir             Window::Scroll(-nDeltaX, -nDeltaY,
528cdf0e10cSrcweir                 PixelToLogic( Rectangle( Point(0, 0), aOutPixSz ) ) );
529cdf0e10cSrcweir         }
530cdf0e10cSrcweir         else
531cdf0e10cSrcweir         {
532cdf0e10cSrcweir             // repaint all
533cdf0e10cSrcweir             SetMapMode( aMap );
534cdf0e10cSrcweir             Invalidate();
535cdf0e10cSrcweir         }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir         Update();
538cdf0e10cSrcweir     }
539cdf0e10cSrcweir 
540cdf0e10cSrcweir     if ( !bScrolling )
541cdf0e10cSrcweir     {
542cdf0e10cSrcweir         EndScroll( nDeltaX, nDeltaY );
543cdf0e10cSrcweir         if ( nDeltaX )
544cdf0e10cSrcweir             aHScroll.SetThumbPos( -aPixOffset.X() );
545cdf0e10cSrcweir         if ( nDeltaY )
546cdf0e10cSrcweir             aVScroll.SetThumbPos( -aPixOffset.Y() );
547cdf0e10cSrcweir     }
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir //-------------------------------------------------------------------
551cdf0e10cSrcweir 
ScrollLines(long nLinesX,long nLinesY)552cdf0e10cSrcweir void ScrollableWindow::ScrollLines( long nLinesX, long nLinesY )
553cdf0e10cSrcweir {
554cdf0e10cSrcweir     Size aDelta( PixelToLogic( Size( nColumnPixW, nLinePixH ) ) );
555cdf0e10cSrcweir     Scroll( aDelta.Width()*nLinesX, aDelta.Height()*nLinesY );
556cdf0e10cSrcweir }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir //-------------------------------------------------------------------
559cdf0e10cSrcweir 
ScrollPages(long nPagesX,sal_uLong nOverlapX,long nPagesY,sal_uLong nOverlapY)560cdf0e10cSrcweir void ScrollableWindow::ScrollPages( long nPagesX, sal_uLong nOverlapX,
561cdf0e10cSrcweir                                     long nPagesY, sal_uLong nOverlapY )
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     Size aOutSz( GetVisibleArea().GetSize() );
564cdf0e10cSrcweir     Scroll( nPagesX * aOutSz.Width() + (nPagesX>0 ? 1 : -1) * nOverlapX,
565cdf0e10cSrcweir             nPagesY * aOutSz.Height() + (nPagesY>0 ? 1 : -1) * nOverlapY );
566cdf0e10cSrcweir }
567