LCOV - code coverage report
Current view: top level - toolkit/source/awt - scrollabledialog.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 64 84 76.2 %
Date: 2014-04-11 Functions: 11 13 84.6 %
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( 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           7 :     Link aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
      37           7 :     maVScrollBar.SetScrollHdl( aLink );
      38           7 :     maHScrollBar.SetScrollHdl( aLink );
      39             : 
      40           7 :     ScrollBarVisibility aVis = None;
      41             : 
      42           7 :     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           7 :     setScrollVisibility( aVis );
      55           7 :     mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
      56           7 : }
      57             : 
      58             : template< class T>
      59           7 : void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
      60             : {
      61           7 :     maScrollVis = rVisState;
      62           7 :     if (  maScrollVis == Hori || maScrollVis == Both )
      63             :     {
      64           0 :         mbHasHoriBar = true;
      65           0 :         maHScrollBar.Show();
      66             :     }
      67           7 :     if ( maScrollVis == Vert || maScrollVis == Both )
      68             :     {
      69           0 :         mbHasVertBar = true;
      70           0 :         maVScrollBar.Show();
      71             :     }
      72           7 :     if ( mbHasHoriBar || mbHasVertBar )
      73           0 :         this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
      74           7 : }
      75             : 
      76             : template< class T>
      77          14 : ScrollableWrapper<T>::~ScrollableWrapper()
      78             : {
      79          14 : }
      80             : 
      81             : template< class T>
      82           8 : void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
      83             : {
      84           8 :     long nXScroll = mnScrollPos.X() - nX;
      85           8 :     long nYScroll = mnScrollPos.Y() - nY;
      86           8 :     mnScrollPos = Point( nX, nY );
      87             : 
      88           8 :     Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
      89           8 :     T::Scroll(nXScroll, nYScroll, aScrollableArea );
      90             :     // Manually scroll all children ( except the scrollbars )
      91          36 :     for ( int index = 0; index < T::GetChildCount(); ++index )
      92             :     {
      93          28 :         Window* pChild = T::GetChild( index );
      94          28 :         if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
      95             :         {
      96          12 :             Point aPos = pChild->GetPosPixel();
      97          12 :             aPos += Point( nXScroll, nYScroll );
      98          12 :             pChild->SetPosPixel( aPos );
      99             :         }
     100             :     }
     101           8 : }
     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           4 : void ScrollableWrapper<T>::SetScrollTop( long nTop )
     125             : {
     126           4 :     Point aOld = mnScrollPos;
     127           4 :     lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
     128           4 :     maHScrollBar.SetThumbPos( 0 );
     129             :     // new pos is 0,0
     130           4 :     mnScrollPos = aOld;
     131           4 : }
     132             : template< class T>
     133           4 : void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
     134             : {
     135           4 :     Point aOld = mnScrollPos;
     136           4 :     lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
     137           4 :     maVScrollBar.SetThumbPos( 0 );
     138             :     // new pos is 0,0
     139           4 :     mnScrollPos = aOld;
     140           4 : }
     141             : template< class T>
     142           2 : void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
     143             : {
     144           2 :     maScrollArea.Width() = nWidth;
     145           2 :     ResetScrollBars();
     146           2 : }
     147             : 
     148             : template< class T>
     149           2 : void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
     150             : {
     151           2 :     maScrollArea.Height() = nHeight;
     152           2 :     ResetScrollBars();
     153           2 : }
     154             : 
     155             : template< class T>
     156           5 : void ScrollableWrapper<T>::Resize()
     157             : {
     158           5 :     ResetScrollBars();
     159           5 : }
     160             : 
     161             : template< class T>
     162           9 : void ScrollableWrapper<T>::ResetScrollBars()
     163             : {
     164           9 :     Size aOutSz = T::GetOutputSizePixel();
     165             : 
     166           9 :     Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
     167           9 :     Point aHPos( 0, aOutSz.Height() - mnScrWidth );
     168             : 
     169           9 :     maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth,  T::GetSizePixel().Height() - mnScrWidth ) );
     170           9 :     maHScrollBar.SetPosSizePixel( aHPos, Size(  T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
     171             : 
     172           9 :     maHScrollBar.SetRangeMax( maScrollArea.Width() + mnScrWidth  );
     173           9 :     maHScrollBar.SetVisibleSize( T::GetSizePixel().Width() );
     174             : 
     175           9 :     maVScrollBar.SetRangeMax( maScrollArea.Height() + mnScrWidth );
     176           9 :     maVScrollBar.SetVisibleSize( T::GetSizePixel().Height() );
     177           9 : }
     178             : 
     179             : template class ScrollableWrapper< Dialog >;
     180             : #ifdef SCROLLABLEFRAME
     181             : template class ScrollableWrapper< GroupBox >;
     182             : #endif
     183             : 
     184             : } // toolkit
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10