LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/toolkit/source/awt - scrollabledialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 65 85 76.5 %
Date: 2013-07-09 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             : 
      23             : namespace toolkit
      24             : {
      25             : 
      26             : // Using  WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a
      27             : // problem in the toolkit class where there are some clashing IDs
      28             : // ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL has the same value
      29             : // as ::com::sun::star::awt::WindowAttribute::NODECORATION and they are used
      30             : // in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for
      31             : // child classes ( whole thing is a mess if you ask me )
      32             : template< class T>
      33           7 : ScrollableWrapper<T>::ScrollableWrapper( 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 )
      34             : {
      35           7 :     Link aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
      36           7 :     maVScrollBar.SetScrollHdl( aLink );
      37           7 :     maHScrollBar.SetScrollHdl( aLink );
      38             : 
      39           7 :     ScrollBarVisibility aVis = None;
      40             : 
      41           7 :     if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
      42             :     {
      43           0 :         if ( nStyle & WB_AUTOHSCROLL )
      44           0 :             aVis = Hori;
      45           0 :         if ( nStyle &  WB_AUTOVSCROLL )
      46             :         {
      47           0 :             if ( aVis == Hori )
      48           0 :                 aVis = Both;
      49             :             else
      50           0 :                 aVis = Vert;
      51             :         }
      52             :     }
      53           7 :     setScrollVisibility( aVis );
      54           7 :     mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
      55           7 : }
      56             : 
      57             : template< class T>
      58           7 : void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
      59             : {
      60           7 :     maScrollVis = rVisState;
      61           7 :     if (  maScrollVis == Hori || maScrollVis == Both )
      62             :     {
      63           0 :         mbHasHoriBar = true;
      64           0 :         maHScrollBar.Show();
      65             :     }
      66           7 :     if ( maScrollVis == Vert || maScrollVis == Both )
      67             :     {
      68           0 :         mbHasVertBar = true;
      69           0 :         maVScrollBar.Show();
      70             :     }
      71           7 :     if ( mbHasHoriBar || mbHasVertBar )
      72           0 :         this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
      73           7 : }
      74             : 
      75             : template< class T>
      76          14 : ScrollableWrapper<T>::~ScrollableWrapper()
      77             : {
      78          14 : }
      79             : 
      80             : template< class T>
      81           8 : void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
      82             : {
      83           8 :     long nXScroll = mnScrollPos.X() - nX;
      84           8 :     long nYScroll = mnScrollPos.Y() - nY;
      85           8 :     mnScrollPos = Point( nX, nY );
      86             : 
      87           8 :     Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
      88           8 :     T::Scroll(nXScroll, nYScroll, aScrollableArea );
      89             :     // Manually scroll all children ( except the scrollbars )
      90          36 :     for ( int index = 0; index < T::GetChildCount(); ++index )
      91             :     {
      92          28 :         Window* pChild = T::GetChild( index );
      93          28 :         if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
      94             :         {
      95          12 :             Point aPos = pChild->GetPosPixel();
      96          12 :             aPos += Point( nXScroll, nYScroll );
      97          12 :             pChild->SetPosPixel( aPos );
      98             :         }
      99             :     }
     100           8 : }
     101             : 
     102             : //Can't use IMPL_LINK with the template
     103             : //IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
     104             : 
     105             : template< class T>
     106           0 : long ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, void* pCaller)
     107             : {
     108           0 :     return ((ScrollableWrapper<T>*)pThis )->ScrollBarHdl( (ScrollBar*)pCaller );
     109             : }
     110             : 
     111             : template< class T>
     112           0 : long ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
     113             : {
     114           0 :     sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
     115           0 :     if( pSB == &maVScrollBar )
     116           0 :         lcl_Scroll(mnScrollPos.X(), nPos );
     117           0 :     else if( pSB == &maHScrollBar )
     118           0 :         lcl_Scroll(nPos, mnScrollPos.Y() );
     119           0 :     return 1;
     120             : }
     121             : 
     122             : template< class T>
     123           4 : void ScrollableWrapper<T>::SetScrollTop( long nTop )
     124             : {
     125           4 :     Point aOld = mnScrollPos;
     126           4 :     lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
     127           4 :     maHScrollBar.SetThumbPos( 0 );
     128             :     // new pos is 0,0
     129           4 :     mnScrollPos = aOld;
     130           4 : }
     131             : template< class T>
     132           4 : void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
     133             : {
     134           4 :     Point aOld = mnScrollPos;
     135           4 :     lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
     136           4 :     maVScrollBar.SetThumbPos( 0 );
     137             :     // new pos is 0,0
     138           4 :     mnScrollPos = aOld;
     139           4 : }
     140             : template< class T>
     141           2 : void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
     142             : {
     143           2 :     maScrollArea.Width() = nWidth;
     144           2 :     ResetScrollBars();
     145           2 : }
     146             : 
     147             : template< class T>
     148           2 : void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
     149             : {
     150           2 :     maScrollArea.Height() = nHeight;
     151           2 :     ResetScrollBars();
     152           2 : }
     153             : 
     154             : template< class T>
     155           5 : void ScrollableWrapper<T>::Resize()
     156             : {
     157           5 :     ResetScrollBars();
     158           5 : }
     159             : 
     160             : template< class T>
     161           9 : void ScrollableWrapper<T>::ResetScrollBars()
     162             : {
     163           9 :     Size aOutSz = T::GetOutputSizePixel();
     164             : 
     165           9 :     Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
     166           9 :     Point aHPos( 0, aOutSz.Height() - mnScrWidth );
     167             : 
     168           9 :     maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth,  T::GetSizePixel().Height() - mnScrWidth ) );
     169           9 :     maHScrollBar.SetPosSizePixel( aHPos, Size(  T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
     170             : 
     171           9 :     maHScrollBar.SetRangeMax( maScrollArea.Width() + mnScrWidth  );
     172           9 :     maHScrollBar.SetVisibleSize( T::GetSizePixel().Width() );
     173             : 
     174           9 :     maVScrollBar.SetRangeMax( maScrollArea.Height() + mnScrWidth );
     175           9 :     maVScrollBar.SetVisibleSize( T::GetSizePixel().Height() );
     176           9 : }
     177             : 
     178             : template class ScrollableWrapper< Dialog >;
     179             : #ifdef SCROLLABLEFRAME
     180             : template class ScrollableWrapper< GroupBox >;
     181             : #endif
     182             : 
     183         465 : } // toolkit
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10