LCOV - code coverage report
Current view: top level - toolkit/source/awt - scrollabledialog.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 65 85 76.5 %
Date: 2014-11-03 Functions: 13 15 86.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <toolkit/awt/scrollabledialog.hxx>
      21             : #include <vcl/group.hxx>
      22             : #include <vcl/settings.hxx>
      23             : 
      24             : namespace toolkit
      25             : {
      26             : 
      27             : // Using  WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a
      28             : // problem in the toolkit class where there are some clashing IDs
      29             : // ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL has the same value
      30             : // as ::com::sun::star::awt::WindowAttribute::NODECORATION and they are used
      31             : // in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for
      32             : // child classes ( whole thing is a mess if you ask me )
      33             : template< class T>
      34          14 : ScrollableWrapper<T>::ScrollableWrapper( vcl::Window* pParent, WinBits nStyle ) : T( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) ), maHScrollBar( this, WB_HSCROLL | WB_DRAG), maVScrollBar( this, WB_VSCROLL | WB_DRAG ), mbHasHoriBar( false ), mbHasVertBar( false ), maScrollVis( None )
      35             : {
      36          14 :     Link aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
      37          14 :     maVScrollBar.SetScrollHdl( aLink );
      38          14 :     maHScrollBar.SetScrollHdl( aLink );
      39             : 
      40          14 :     ScrollBarVisibility aVis = None;
      41             : 
      42          14 :     if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
      43             :     {
      44           0 :         if ( nStyle & WB_AUTOHSCROLL )
      45           0 :             aVis = Hori;
      46           0 :         if ( nStyle &  WB_AUTOVSCROLL )
      47             :         {
      48           0 :             if ( aVis == Hori )
      49           0 :                 aVis = Both;
      50             :             else
      51           0 :                 aVis = Vert;
      52             :         }
      53             :     }
      54          14 :     setScrollVisibility( aVis );
      55          14 :     mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
      56          14 : }
      57             : 
      58             : template< class T>
      59          14 : void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
      60             : {
      61          14 :     maScrollVis = rVisState;
      62          14 :     if (  maScrollVis == Hori || maScrollVis == Both )
      63             :     {
      64           0 :         mbHasHoriBar = true;
      65           0 :         maHScrollBar.Show();
      66             :     }
      67          14 :     if ( maScrollVis == Vert || maScrollVis == Both )
      68             :     {
      69           0 :         mbHasVertBar = true;
      70           0 :         maVScrollBar.Show();
      71             :     }
      72          14 :     if ( mbHasHoriBar || mbHasVertBar )
      73           0 :         this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
      74          14 : }
      75             : 
      76             : template< class T>
      77          28 : ScrollableWrapper<T>::~ScrollableWrapper()
      78             : {
      79          28 : }
      80             : 
      81             : template< class T>
      82          16 : void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
      83             : {
      84          16 :     long nXScroll = mnScrollPos.X() - nX;
      85          16 :     long nYScroll = mnScrollPos.Y() - nY;
      86          16 :     mnScrollPos = Point( nX, nY );
      87             : 
      88          16 :     Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
      89          16 :     T::Scroll(nXScroll, nYScroll, aScrollableArea );
      90             :     // Manually scroll all children ( except the scrollbars )
      91          72 :     for ( int index = 0; index < T::GetChildCount(); ++index )
      92             :     {
      93          56 :         vcl::Window* pChild = T::GetChild( index );
      94          56 :         if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
      95             :         {
      96          24 :             Point aPos = pChild->GetPosPixel();
      97          24 :             aPos += Point( nXScroll, nYScroll );
      98          24 :             pChild->SetPosPixel( aPos );
      99             :         }
     100             :     }
     101          16 : }
     102             : 
     103             : //Can't use IMPL_LINK with the template
     104             : //IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
     105             : 
     106             : template< class T>
     107           0 : long ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, void* pCaller)
     108             : {
     109           0 :     return ((ScrollableWrapper<T>*)pThis )->ScrollBarHdl( (ScrollBar*)pCaller );
     110             : }
     111             : 
     112             : template< class T>
     113           0 : long ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
     114             : {
     115           0 :     sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
     116           0 :     if( pSB == &maVScrollBar )
     117           0 :         lcl_Scroll(mnScrollPos.X(), nPos );
     118           0 :     else if( pSB == &maHScrollBar )
     119           0 :         lcl_Scroll(nPos, mnScrollPos.Y() );
     120           0 :     return 1;
     121             : }
     122             : 
     123             : template< class T>
     124           8 : void ScrollableWrapper<T>::SetScrollTop( long nTop )
     125             : {
     126           8 :     Point aOld = mnScrollPos;
     127           8 :     lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
     128           8 :     maHScrollBar.SetThumbPos( 0 );
     129             :     // new pos is 0,0
     130           8 :     mnScrollPos = aOld;
     131           8 : }
     132             : template< class T>
     133           8 : void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
     134             : {
     135           8 :     Point aOld = mnScrollPos;
     136           8 :     lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
     137           8 :     maVScrollBar.SetThumbPos( 0 );
     138             :     // new pos is 0,0
     139           8 :     mnScrollPos = aOld;
     140           8 : }
     141             : template< class T>
     142           4 : void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
     143             : {
     144           4 :     maScrollArea.Width() = nWidth;
     145           4 :     ResetScrollBars();
     146           4 : }
     147             : 
     148             : template< class T>
     149           4 : void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
     150             : {
     151           4 :     maScrollArea.Height() = nHeight;
     152           4 :     ResetScrollBars();
     153           4 : }
     154             : 
     155             : template< class T>
     156          10 : void ScrollableWrapper<T>::Resize()
     157             : {
     158          10 :     ResetScrollBars();
     159          10 : }
     160             : 
     161             : template< class T>
     162          18 : void ScrollableWrapper<T>::ResetScrollBars()
     163             : {
     164          18 :     Size aOutSz = T::GetOutputSizePixel();
     165             : 
     166          18 :     Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
     167          18 :     Point aHPos( 0, aOutSz.Height() - mnScrWidth );
     168             : 
     169          18 :     maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth,  T::GetSizePixel().Height() - mnScrWidth ) );
     170          18 :     maHScrollBar.SetPosSizePixel( aHPos, Size(  T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
     171             : 
     172          18 :     maHScrollBar.SetRangeMax( maScrollArea.Width() + mnScrWidth  );
     173          18 :     maHScrollBar.SetVisibleSize( T::GetSizePixel().Width() );
     174             : 
     175          18 :     maVScrollBar.SetRangeMax( maScrollArea.Height() + mnScrWidth );
     176          18 :     maVScrollBar.SetVisibleSize( T::GetSizePixel().Height() );
     177          18 : }
     178             : 
     179             : template class ScrollableWrapper< Dialog >;
     180             : 
     181        1227 : } // toolkit
     182             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10