1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 33 #include "swtypes.hxx" 34 #include "swrect.hxx" 35 #include "scroll.hxx" 36 37 #define SCROLL_LINE_SIZE 250 38 39 40 SwScrollbar::SwScrollbar( Window *pWin, sal_Bool bHoriz ) : 41 ScrollBar( pWin, 42 WinBits( WB_3DLOOK | WB_HIDE | ( bHoriz ? WB_HSCROLL : WB_VSCROLL) ) ), 43 bHori( bHoriz ), 44 bAuto( sal_False ), 45 bThumbEnabled( sal_True ), 46 bVisible(sal_False), 47 bSizeSet(sal_False) 48 { 49 // SSA: --- RTL --- no mirroring for horizontal scrollbars 50 if( bHoriz ) 51 EnableRTL( sal_False ); 52 } 53 54 55 SwScrollbar::~SwScrollbar() {} 56 57 /*------------------------------------------------------------------------ 58 Beschreibung: wird nach einer Aenderung der Dokumentgroesse gerufen, um den 59 Range des Scrollbars neu einzustellen. 60 ------------------------------------------------------------------------*/ 61 62 void SwScrollbar::DocSzChgd( const Size &rSize ) 63 { 64 aDocSz = rSize; 65 SetRange( Range( 0, bHori ? rSize.Width() : rSize.Height()) ); 66 const sal_uLong nVisSize = GetVisibleSize(); 67 SetLineSize( SCROLL_LINE_SIZE ); 68 // SetLineSize( nVisSize * 10 / 100 ); 69 SetPageSize( nVisSize * 77 / 100 ); 70 } 71 72 /*------------------------------------------------------------------------ 73 Beschreibung: wird nach einer Veraenderung des sichtbaren Ausschnittes 74 gerufen. 75 ------------------------------------------------------------------------*/ 76 77 78 void SwScrollbar::ViewPortChgd( const Rectangle &rRect ) 79 { 80 long nThumb, nVisible; 81 if( bHori ) 82 { 83 nThumb = rRect.Left(); 84 nVisible = rRect.GetWidth(); 85 } 86 else 87 { 88 nThumb = rRect.Top(); 89 nVisible = rRect.GetHeight(); 90 } 91 92 SetVisibleSize( nVisible ); 93 DocSzChgd(aDocSz); 94 if ( bThumbEnabled ) 95 SetThumbPos( nThumb ); 96 if(bAuto) 97 AutoShow(); 98 } 99 100 /*-----------------10/21/97 02:48pm----------------- 101 102 --------------------------------------------------*/ 103 void SwScrollbar::ExtendedShow( sal_Bool bSet ) 104 { 105 bVisible = bSet; 106 if( (!bSet || !bAuto) && IsUpdateMode() && bSizeSet) 107 ScrollBar::Show(bSet); 108 } 109 110 /*-----------------10/21/97 03:23pm----------------- 111 112 --------------------------------------------------*/ 113 void SwScrollbar::SetPosSizePixel( const Point& rNewPos, const Size& rNewSize ) 114 { 115 ScrollBar::SetPosSizePixel(rNewPos, rNewSize); 116 bSizeSet = sal_True; 117 if(bVisible) 118 ExtendedShow(); 119 120 } 121 122 123 /*-----------------14.04.98 11:38------------------- 124 125 --------------------------------------------------*/ 126 void SwScrollbar::SetAuto(sal_Bool bSet) 127 { 128 if(bAuto != bSet) 129 { 130 bAuto = bSet; 131 132 // automatisch versteckt - dann anzeigen 133 if(!bAuto && bVisible && !ScrollBar::IsVisible()) 134 ExtendedShow(sal_True); 135 else if(bAuto) 136 AutoShow(); // oder automatisch verstecken 137 } 138 } 139 /*-----------------14.04.98 11:43------------------- 140 141 --------------------------------------------------*/ 142 void SwScrollbar::AutoShow() 143 { 144 long nVis = GetVisibleSize(); 145 long nLen = GetRange().Len(); 146 { 147 if( nVis >= nLen - 1) 148 { 149 if(ScrollBar::IsVisible()) 150 ScrollBar::Show(sal_False); 151 } 152 else if ( !ScrollBar::IsVisible() && 153 (!bHori || nVis) ) //Optimierung fuer Browser. 154 //Horizontaler Scrollbar per 155 //default aus. 156 { 157 ScrollBar::Show(sal_True); 158 } 159 } 160 } 161