xref: /trunk/main/sw/source/ui/uiview/scroll.cxx (revision 1edb91d5f0a839a21514e3ae2a371af964e55aa1)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #include "swtypes.hxx"
26 #include "swrect.hxx"
27 #include "scroll.hxx"
28 
29 #define SCROLL_LINE_SIZE 250
30 
SwScrollbar(Window * pWin,sal_Bool bHoriz)31 SwScrollbar::SwScrollbar( Window *pWin, sal_Bool bHoriz ) :
32     ScrollBar( pWin,
33     WinBits( WB_3DLOOK | WB_HIDE | ( bHoriz ? WB_HSCROLL : WB_VSCROLL) ) ),
34     bHori( bHoriz ),
35     bAuto( sal_False ),
36     bThumbEnabled( sal_True ),
37     bVisible(sal_False),
38     bSizeSet(sal_False)
39 {
40     // SSA: --- RTL --- no mirroring for horizontal scrollbars
41     if( bHoriz )
42         EnableRTL( sal_False );
43 }
44 
~SwScrollbar()45  SwScrollbar::~SwScrollbar() {}
46 
47 /*------------------------------------------------------------------------
48  Beschreibung:  wird nach einer Änderung der Dokumentgröße gerufen, um den
49                 Range des Scrollbars neu einzustellen.
50 ------------------------------------------------------------------------*/
51 
DocSzChgd(const Size & rSize)52 void SwScrollbar::DocSzChgd( const Size &rSize )
53 {
54     aDocSz = rSize;
55     SetRange( Range( 0, bHori ? rSize.Width() : rSize.Height()) );
56     const sal_uLong nVisSize = GetVisibleSize();
57     SetLineSize( SCROLL_LINE_SIZE );
58 //  SetLineSize( nVisSize * 10 / 100 );
59     SetPageSize( nVisSize * 77 / 100 );
60 }
61 
62 /*------------------------------------------------------------------------
63  Beschreibung:  wird nach einer Veränderung des sichtbaren Ausschnitts
64                 gerufen.
65 ------------------------------------------------------------------------*/
66 
ViewPortChgd(const Rectangle & rRect)67 void SwScrollbar::ViewPortChgd( const Rectangle &rRect )
68 {
69     long nThumb, nVisible;
70     if( bHori )
71     {
72         nThumb = rRect.Left();
73         nVisible = rRect.GetWidth();
74     }
75     else
76     {
77         nThumb = rRect.Top();
78         nVisible = rRect.GetHeight();
79     }
80 
81     SetVisibleSize( nVisible );
82     DocSzChgd(aDocSz);
83     if ( bThumbEnabled )
84         SetThumbPos( nThumb );
85     if(bAuto)
86         AutoShow();
87 }
88 
89 /*-----------------10/21/97 02:48pm-----------------
90 
91 --------------------------------------------------*/
ExtendedShow(sal_Bool bSet)92 void SwScrollbar::ExtendedShow( sal_Bool bSet )
93 {
94     bVisible = bSet;
95     if( (!bSet ||  !bAuto) && IsUpdateMode() && bSizeSet)
96         ScrollBar::Show(bSet);
97 }
98 
99 /*-----------------10/21/97 03:23pm-----------------
100 
101 --------------------------------------------------*/
SetPosSizePixel(const Point & rNewPos,const Size & rNewSize)102 void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize )
103 {
104     ScrollBar::SetPosSizePixel(rNewPos, rNewSize);
105     bSizeSet = sal_True;
106     if(bVisible)
107         ExtendedShow();
108 
109 }
110 
111 /*-----------------14.04.98 11:38-------------------
112 
113 --------------------------------------------------*/
SetAuto(sal_Bool bSet)114 void SwScrollbar::SetAuto(sal_Bool bSet)
115 {
116     if(bAuto != bSet)
117     {
118         bAuto = bSet;
119 
120         // automatisch versteckt - dann anzeigen
121         if(!bAuto && bVisible && !ScrollBar::IsVisible())
122             ExtendedShow(sal_True);
123         else if(bAuto)
124             AutoShow(); // oder automatisch verstecken
125     }
126 }
127 /*-----------------14.04.98 11:43-------------------
128 
129 --------------------------------------------------*/
AutoShow()130 void SwScrollbar::AutoShow()
131 {
132     long nVis = GetVisibleSize();
133     long nLen = GetRange().Len();
134     {
135         if( nVis >= nLen - 1)
136         {
137             if(ScrollBar::IsVisible())
138                 ScrollBar::Show(sal_False);
139         }
140         else if ( !ScrollBar::IsVisible() &&
141                   (!bHori || nVis) )        // Optimierung für Browser.
142                                             // Horizontaler Scrollbar per default aus.
143         {
144             ScrollBar::Show(sal_True);
145         }
146     }
147 }
148 
149 /* vim: set noet sw=4 ts=4: */
150