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