xref: /aoo41x/main/sw/source/ui/uiview/scroll.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "swtypes.hxx"
30cdf0e10cSrcweir #include "swrect.hxx"
31cdf0e10cSrcweir #include "scroll.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #define SCROLL_LINE_SIZE 250
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 
SwScrollbar(Window * pWin,sal_Bool bHoriz)36cdf0e10cSrcweir SwScrollbar::SwScrollbar( Window *pWin, sal_Bool bHoriz ) :
37cdf0e10cSrcweir 	ScrollBar( pWin,
38cdf0e10cSrcweir 	WinBits( WB_3DLOOK | WB_HIDE | ( bHoriz ? WB_HSCROLL : WB_VSCROLL)  ) ),
39cdf0e10cSrcweir 	bHori( bHoriz ),
40cdf0e10cSrcweir 	bAuto( sal_False ),
41cdf0e10cSrcweir 	bThumbEnabled( sal_True ),
42cdf0e10cSrcweir 	bVisible(sal_False),
43cdf0e10cSrcweir 	bSizeSet(sal_False)
44cdf0e10cSrcweir {
45cdf0e10cSrcweir     // SSA: --- RTL --- no mirroring for horizontal scrollbars
46cdf0e10cSrcweir     if( bHoriz )
47cdf0e10cSrcweir         EnableRTL( sal_False );
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 
~SwScrollbar()51cdf0e10cSrcweir  SwScrollbar::~SwScrollbar() {}
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /*------------------------------------------------------------------------
54cdf0e10cSrcweir  Beschreibung:	wird nach einer Aenderung der Dokumentgroesse gerufen, um den
55cdf0e10cSrcweir 				Range des Scrollbars neu einzustellen.
56cdf0e10cSrcweir ------------------------------------------------------------------------*/
57cdf0e10cSrcweir 
DocSzChgd(const Size & rSize)58cdf0e10cSrcweir void SwScrollbar::DocSzChgd( const Size &rSize )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	aDocSz = rSize;
61cdf0e10cSrcweir 	SetRange( Range( 0, bHori ? rSize.Width() : rSize.Height()) );
62cdf0e10cSrcweir 	const sal_uLong nVisSize = GetVisibleSize();
63cdf0e10cSrcweir     SetLineSize( SCROLL_LINE_SIZE );
64cdf0e10cSrcweir //    SetLineSize( nVisSize * 10 / 100 );
65cdf0e10cSrcweir 	SetPageSize( nVisSize * 77 / 100 );
66cdf0e10cSrcweir }
67cdf0e10cSrcweir 
68cdf0e10cSrcweir /*------------------------------------------------------------------------
69cdf0e10cSrcweir  Beschreibung:	wird nach einer Veraenderung des sichtbaren Ausschnittes
70cdf0e10cSrcweir 				gerufen.
71cdf0e10cSrcweir ------------------------------------------------------------------------*/
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 
ViewPortChgd(const Rectangle & rRect)74cdf0e10cSrcweir void SwScrollbar::ViewPortChgd( const Rectangle &rRect )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     long nThumb, nVisible;
77cdf0e10cSrcweir 	if( bHori )
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		nThumb = rRect.Left();
80cdf0e10cSrcweir 		nVisible = rRect.GetWidth();
81cdf0e10cSrcweir 	}
82cdf0e10cSrcweir 	else
83cdf0e10cSrcweir 	{
84cdf0e10cSrcweir 		nThumb = rRect.Top();
85cdf0e10cSrcweir 		nVisible = rRect.GetHeight();
86cdf0e10cSrcweir 	}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	SetVisibleSize( nVisible );
89cdf0e10cSrcweir 	DocSzChgd(aDocSz);
90cdf0e10cSrcweir 	if ( bThumbEnabled )
91cdf0e10cSrcweir 		SetThumbPos( nThumb );
92cdf0e10cSrcweir 	if(bAuto)
93cdf0e10cSrcweir 		AutoShow();
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir /*-----------------10/21/97 02:48pm-----------------
97cdf0e10cSrcweir 
98cdf0e10cSrcweir --------------------------------------------------*/
ExtendedShow(sal_Bool bSet)99cdf0e10cSrcweir void SwScrollbar::ExtendedShow( sal_Bool bSet )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	bVisible = bSet;
102cdf0e10cSrcweir 	if( (!bSet ||  !bAuto) && IsUpdateMode() && bSizeSet)
103cdf0e10cSrcweir 		ScrollBar::Show(bSet);
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir /*-----------------10/21/97 03:23pm-----------------
107cdf0e10cSrcweir 
108cdf0e10cSrcweir --------------------------------------------------*/
SetPosSizePixel(const Point & rNewPos,const Size & rNewSize)109cdf0e10cSrcweir void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	ScrollBar::SetPosSizePixel(rNewPos, rNewSize);
112cdf0e10cSrcweir 	bSizeSet = sal_True;
113cdf0e10cSrcweir 	if(bVisible)
114cdf0e10cSrcweir         ExtendedShow();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
119cdf0e10cSrcweir /*-----------------14.04.98 11:38-------------------
120cdf0e10cSrcweir 
121cdf0e10cSrcweir --------------------------------------------------*/
SetAuto(sal_Bool bSet)122cdf0e10cSrcweir void SwScrollbar::SetAuto(sal_Bool bSet)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     if(bAuto != bSet)
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir 		bAuto = bSet;
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		// automatisch versteckt - dann anzeigen
129cdf0e10cSrcweir 		if(!bAuto && bVisible && !ScrollBar::IsVisible())
130cdf0e10cSrcweir             ExtendedShow(sal_True);
131cdf0e10cSrcweir 		else if(bAuto)
132cdf0e10cSrcweir 			AutoShow();	// oder automatisch verstecken
133cdf0e10cSrcweir 	}
134cdf0e10cSrcweir }
135cdf0e10cSrcweir /*-----------------14.04.98 11:43-------------------
136cdf0e10cSrcweir 
137cdf0e10cSrcweir --------------------------------------------------*/
AutoShow()138cdf0e10cSrcweir void SwScrollbar::AutoShow()
139cdf0e10cSrcweir {
140cdf0e10cSrcweir 	long nVis = GetVisibleSize();
141cdf0e10cSrcweir 	long nLen = GetRange().Len();
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		if( nVis >= nLen - 1)
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			if(ScrollBar::IsVisible())
146cdf0e10cSrcweir 				ScrollBar::Show(sal_False);
147cdf0e10cSrcweir 		}
148cdf0e10cSrcweir 		else if ( !ScrollBar::IsVisible() &&
149cdf0e10cSrcweir 				  (!bHori || nVis) )		//Optimierung fuer Browser.
150cdf0e10cSrcweir 											//Horizontaler Scrollbar per
151cdf0e10cSrcweir 											//default aus.
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			ScrollBar::Show(sal_True);
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir }
157