LCOV - code coverage report
Current view: top level - toolkit/source/awt - scrollabledialog.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 71 91 78.0 %
Date: 2015-06-13 12:38:46 Functions: 12 14 85.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           7 : ScrollableWrapper<T>::ScrollableWrapper( vcl::Window* pParent, WinBits nStyle, Dialog::InitFlag eFlag )
      35             :     : T( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ), eFlag ),
      36             :       maHScrollBar( VclPtr<ScrollBar>::Create(this, WB_HSCROLL | WB_DRAG) ),
      37             :       maVScrollBar( VclPtr<ScrollBar>::Create(this, WB_VSCROLL | WB_DRAG) ),
      38             :       mbHasHoriBar( false ),
      39             :       mbHasVertBar( false ),
      40           7 :       maScrollVis( None )
      41             : {
      42           7 :     Link<> aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
      43           7 :     maVScrollBar->SetScrollHdl( aLink );
      44           7 :     maHScrollBar->SetScrollHdl( aLink );
      45             : 
      46           7 :     ScrollBarVisibility aVis = None;
      47             : 
      48           7 :     if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
      49             :     {
      50           0 :         if ( nStyle & WB_AUTOHSCROLL )
      51           0 :             aVis = Hori;
      52           0 :         if ( nStyle &  WB_AUTOVSCROLL )
      53             :         {
      54           0 :             if ( aVis == Hori )
      55           0 :                 aVis = Both;
      56             :             else
      57           0 :                 aVis = Vert;
      58             :         }
      59             :     }
      60           7 :     setScrollVisibility( aVis );
      61           7 :     mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
      62           7 : }
      63             : 
      64             : template< class T>
      65           7 : void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
      66             : {
      67           7 :     maScrollVis = rVisState;
      68           7 :     if (  maScrollVis == Hori || maScrollVis == Both )
      69             :     {
      70           0 :         mbHasHoriBar = true;
      71           0 :         maHScrollBar->Show();
      72             :     }
      73           7 :     if ( maScrollVis == Vert || maScrollVis == Both )
      74             :     {
      75           0 :         mbHasVertBar = true;
      76           0 :         maVScrollBar->Show();
      77             :     }
      78           7 :     if ( mbHasHoriBar || mbHasVertBar )
      79           0 :         this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | WB_AUTOSIZE );
      80           7 : }
      81             : 
      82             : template< class T>
      83          14 : ScrollableWrapper<T>::~ScrollableWrapper()
      84             : {
      85           7 :     T::disposeOnce();
      86          21 : }
      87             : 
      88             : template< class T>
      89           7 : void ScrollableWrapper<T>::dispose()
      90             : {
      91           7 :     maHScrollBar.disposeAndClear();
      92           7 :     maVScrollBar.disposeAndClear();
      93           7 :     T::dispose();
      94           7 : }
      95             : 
      96             : template< class T>
      97           8 : void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
      98             : {
      99           8 :     long nXScroll = mnScrollPos.X() - nX;
     100           8 :     long nYScroll = mnScrollPos.Y() - nY;
     101           8 :     mnScrollPos = Point( nX, nY );
     102             : 
     103           8 :     Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
     104           8 :     T::Scroll(nXScroll, nYScroll, aScrollableArea );
     105             :     // Manually scroll all children ( except the scrollbars )
     106          36 :     for ( int index = 0; index < T::GetChildCount(); ++index )
     107             :     {
     108          28 :         vcl::Window* pChild = T::GetChild( index );
     109          28 :         if ( pChild && pChild != maVScrollBar.get() && pChild != maHScrollBar.get() )
     110             :         {
     111          12 :             Point aPos = pChild->GetPosPixel();
     112          12 :             aPos += Point( nXScroll, nYScroll );
     113          12 :             pChild->SetPosPixel( aPos );
     114             :         }
     115             :     }
     116           8 : }
     117             : 
     118             : //Can't use IMPL_LINK with the template
     119             : //IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
     120             : 
     121             : template< class T>
     122           0 : sal_IntPtr ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, void* pCaller)
     123             : {
     124           0 :     return static_cast<ScrollableWrapper<T>*>(pThis)->ScrollBarHdl( static_cast<ScrollBar*>(pCaller) );
     125             : }
     126             : 
     127             : template< class T>
     128           0 : sal_IntPtr ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
     129             : {
     130           0 :     sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
     131           0 :     if( pSB == maVScrollBar.get() )
     132           0 :         lcl_Scroll(mnScrollPos.X(), nPos );
     133           0 :     else if( pSB == maHScrollBar.get() )
     134           0 :         lcl_Scroll(nPos, mnScrollPos.Y() );
     135           0 :     return 1;
     136             : }
     137             : 
     138             : template< class T>
     139           4 : void ScrollableWrapper<T>::SetScrollTop( long nTop )
     140             : {
     141           4 :     Point aOld = mnScrollPos;
     142           4 :     lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
     143           4 :     maHScrollBar->SetThumbPos( 0 );
     144             :     // new pos is 0,0
     145           4 :     mnScrollPos = aOld;
     146           4 : }
     147             : template< class T>
     148           4 : void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
     149             : {
     150           4 :     Point aOld = mnScrollPos;
     151           4 :     lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
     152           4 :     maVScrollBar->SetThumbPos( 0 );
     153             :     // new pos is 0,0
     154           4 :     mnScrollPos = aOld;
     155           4 : }
     156             : template< class T>
     157           2 : void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
     158             : {
     159           2 :     maScrollArea.Width() = nWidth;
     160           2 :     ResetScrollBars();
     161           2 : }
     162             : 
     163             : template< class T>
     164           2 : void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
     165             : {
     166           2 :     maScrollArea.Height() = nHeight;
     167           2 :     ResetScrollBars();
     168           2 : }
     169             : 
     170             : template< class T>
     171           5 : void ScrollableWrapper<T>::Resize()
     172             : {
     173           5 :     ResetScrollBars();
     174           5 : }
     175             : 
     176             : template< class T>
     177           9 : void ScrollableWrapper<T>::ResetScrollBars()
     178             : {
     179           9 :     Size aOutSz = T::GetOutputSizePixel();
     180             : 
     181           9 :     Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
     182           9 :     Point aHPos( 0, aOutSz.Height() - mnScrWidth );
     183             : 
     184           9 :     maVScrollBar->SetPosSizePixel( aVPos, Size( mnScrWidth,  T::GetSizePixel().Height() - mnScrWidth ) );
     185           9 :     maHScrollBar->SetPosSizePixel( aHPos, Size(  T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
     186             : 
     187           9 :     maHScrollBar->SetRangeMax( maScrollArea.Width() + mnScrWidth  );
     188           9 :     maHScrollBar->SetVisibleSize( T::GetSizePixel().Width() );
     189             : 
     190           9 :     maVScrollBar->SetRangeMax( maScrollArea.Height() + mnScrWidth );
     191           9 :     maVScrollBar->SetVisibleSize( T::GetSizePixel().Height() );
     192           9 : }
     193             : 
     194             : template class ScrollableWrapper< Dialog >;
     195             : 
     196             : } // toolkit
     197             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11