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

Generated by: LCOV version 1.10