LCOV - code coverage report
Current view: top level - vcl/source/outdev - nativecontrols.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 38 151 25.2 %
Date: 2014-11-03 Functions: 11 35 31.4 %
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 <vcl/outdev.hxx>
      21             : #include <vcl/window.hxx>
      22             : 
      23             : #include <vcl/salnativewidgets.hxx>
      24             : #include <vcl/pdfextoutdevdata.hxx>
      25             : 
      26             : #include <salgdi.hxx>
      27             : 
      28     1845007 : static bool EnableNativeWidget( const OutputDevice& i_rDevice )
      29             : {
      30     1845007 :     const OutDevType eType( i_rDevice.GetOutDevType() );
      31     1845007 :     switch ( eType )
      32             :     {
      33             : 
      34             :     case OUTDEV_WINDOW:
      35             :         {
      36     1845007 :             const vcl::Window* pWindow = dynamic_cast< const vcl::Window* >( &i_rDevice );
      37     1845007 :             if (pWindow)
      38             :             {
      39     1845007 :                 return pWindow->IsNativeWidgetEnabled();
      40             :             }
      41             :             else
      42             :             {
      43             :                 SAL_WARN ("vcl.gdi", "Could not cast i_rDevice to Window");
      44             :                 assert (pWindow);
      45           0 :                 return false;
      46             :             }
      47             :         }
      48             : 
      49             :     case OUTDEV_VIRDEV:
      50             :     {
      51           0 :         const ::vcl::ExtOutDevData* pOutDevData( i_rDevice.GetExtOutDevData() );
      52           0 :         const ::vcl::PDFExtOutDevData* pPDFData( dynamic_cast< const ::vcl::PDFExtOutDevData* >( pOutDevData ) );
      53           0 :         if ( pPDFData != NULL )
      54           0 :             return false;
      55           0 :         return true;
      56             :     }
      57             : 
      58             :     default:
      59           0 :         return false;
      60             :     }
      61             : }
      62             : 
      63     1000414 : ImplControlValue::~ImplControlValue()
      64             : {
      65     1000414 : }
      66             : 
      67         100 : ImplControlValue* ImplControlValue::clone() const
      68             : {
      69             :     assert( typeid( const ImplControlValue ) == typeid( *this ));
      70         100 :     return new ImplControlValue( *this );
      71             : }
      72             : 
      73      146735 : ScrollbarValue::~ScrollbarValue()
      74             : {
      75      146735 : }
      76             : 
      77           0 : ScrollbarValue* ScrollbarValue::clone() const
      78             : {
      79             :     assert( typeid( const ScrollbarValue ) == typeid( *this ));
      80           0 :     return new ScrollbarValue( *this );
      81             : }
      82             : 
      83           0 : SliderValue::~SliderValue()
      84             : {
      85           0 : }
      86             : 
      87           0 : SliderValue* SliderValue::clone() const
      88             : {
      89             :     assert( typeid( const SliderValue ) == typeid( *this ));
      90           0 :     return new SliderValue( *this );
      91             : }
      92             : 
      93           0 : TabitemValue::~TabitemValue()
      94             : {
      95           0 : }
      96             : 
      97           0 : TabitemValue* TabitemValue::clone() const
      98             : {
      99             :     assert( typeid( const TabitemValue ) == typeid( *this ));
     100           0 :     return new TabitemValue( *this );
     101             : }
     102             : 
     103        7565 : SpinbuttonValue::~SpinbuttonValue()
     104             : {
     105        7565 : }
     106             : 
     107           0 : SpinbuttonValue* SpinbuttonValue::clone() const
     108             : {
     109             :     assert( typeid( const SpinbuttonValue ) == typeid( *this ));
     110           0 :     return new SpinbuttonValue( *this );
     111             : }
     112             : 
     113           0 : ToolbarValue::~ToolbarValue()
     114             : {
     115           0 : }
     116             : 
     117           0 : ToolbarValue* ToolbarValue::clone() const
     118             : {
     119             :     assert( typeid( const ToolbarValue ) == typeid( *this ));
     120           0 :     return new ToolbarValue( *this );
     121             : }
     122             : 
     123           0 : MenubarValue::~MenubarValue()
     124             : {
     125           0 : }
     126             : 
     127           0 : MenubarValue* MenubarValue::clone() const
     128             : {
     129             :     assert( typeid( const MenubarValue ) == typeid( *this ));
     130           0 :     return new MenubarValue( *this );
     131             : }
     132             : 
     133           0 : MenupopupValue::~MenupopupValue()
     134             : {
     135           0 : }
     136             : 
     137           0 : MenupopupValue* MenupopupValue::clone() const
     138             : {
     139             :     assert( typeid( const MenupopupValue ) == typeid( *this ));
     140           0 :     return new MenupopupValue( *this );
     141             : }
     142             : 
     143           0 : PushButtonValue::~PushButtonValue()
     144             : {
     145           0 : }
     146             : 
     147           0 : PushButtonValue* PushButtonValue::clone() const
     148             : {
     149             :     assert( typeid( const PushButtonValue ) == typeid( *this ));
     150           0 :     return new PushButtonValue( *this );
     151             : }
     152             : 
     153             : // These functions are mainly passthrough functions that allow access to
     154             : // the SalFrame behind a Window object for native widget rendering purposes.
     155             : 
     156     1530265 : bool OutputDevice::IsNativeControlSupported( ControlType nType, ControlPart nPart ) const
     157             : {
     158     1530265 :     if( !EnableNativeWidget( *this ) )
     159       16846 :         return false;
     160             : 
     161     1513419 :     if ( !mpGraphics )
     162      170940 :         if ( !AcquireGraphics() )
     163           0 :             return false;
     164             : 
     165     1513419 :     return( mpGraphics->IsNativeControlSupported(nType, nPart) );
     166             : }
     167             : 
     168           0 : bool OutputDevice::HitTestNativeControl( ControlType nType,
     169             :                               ControlPart nPart,
     170             :                               const Rectangle& rControlRegion,
     171             :                               const Point& aPos,
     172             :                               bool& rIsInside ) const
     173             : {
     174           0 :     if( !EnableNativeWidget( *this ) )
     175           0 :         return false;
     176             : 
     177           0 :     if ( !mpGraphics )
     178           0 :         if ( !AcquireGraphics() )
     179           0 :             return false;
     180             : 
     181           0 :     Point aWinOffs( mnOutOffX, mnOutOffY );
     182           0 :     Rectangle screenRegion( rControlRegion );
     183           0 :     screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
     184             : 
     185           0 :     return( mpGraphics->HitTestNativeControl(nType, nPart, screenRegion, Point( aPos.X() + mnOutOffX, aPos.Y() + mnOutOffY ),
     186           0 :         rIsInside, this ) );
     187             : }
     188             : 
     189      312221 : static boost::shared_ptr< ImplControlValue > TransformControlValue( const ImplControlValue& rVal, const OutputDevice& rDev )
     190             : {
     191      312221 :     boost::shared_ptr< ImplControlValue > aResult;
     192      312221 :     switch( rVal.getType() )
     193             :     {
     194             :     case CTRL_SLIDER:
     195             :         {
     196           0 :             const SliderValue* pSlVal = static_cast<const SliderValue*>(&rVal);
     197           0 :             SliderValue* pNew = new SliderValue( *pSlVal );
     198           0 :             aResult.reset( pNew );
     199           0 :             pNew->maThumbRect = rDev.ImplLogicToDevicePixel( pSlVal->maThumbRect );
     200             :         }
     201           0 :         break;
     202             :     case CTRL_SCROLLBAR:
     203             :         {
     204           0 :             const ScrollbarValue* pScVal = static_cast<const ScrollbarValue*>(&rVal);
     205           0 :             ScrollbarValue* pNew = new ScrollbarValue( *pScVal );
     206           0 :             aResult.reset( pNew );
     207           0 :             pNew->maThumbRect = rDev.ImplLogicToDevicePixel( pScVal->maThumbRect );
     208           0 :             pNew->maButton1Rect = rDev.ImplLogicToDevicePixel( pScVal->maButton1Rect );
     209           0 :             pNew->maButton2Rect = rDev.ImplLogicToDevicePixel( pScVal->maButton2Rect );
     210             :         }
     211           0 :         break;
     212             :     case CTRL_SPINBUTTONS:
     213             :         {
     214           0 :             const SpinbuttonValue* pSpVal = static_cast<const SpinbuttonValue*>(&rVal);
     215           0 :             SpinbuttonValue* pNew = new SpinbuttonValue( *pSpVal );
     216           0 :             aResult.reset( pNew );
     217           0 :             pNew->maUpperRect = rDev.ImplLogicToDevicePixel( pSpVal->maUpperRect );
     218           0 :             pNew->maLowerRect = rDev.ImplLogicToDevicePixel( pSpVal->maLowerRect );
     219             :         }
     220           0 :         break;
     221             :     case CTRL_TOOLBAR:
     222             :         {
     223           0 :             const ToolbarValue* pTVal = static_cast<const ToolbarValue*>(&rVal);
     224           0 :             ToolbarValue* pNew = new ToolbarValue( *pTVal );
     225           0 :             aResult.reset( pNew );
     226           0 :             pNew->maGripRect = rDev.ImplLogicToDevicePixel( pTVal->maGripRect );
     227             :         }
     228           0 :         break;
     229             :     case CTRL_TAB_ITEM:
     230             :         {
     231           0 :             const TabitemValue* pTIVal = static_cast<const TabitemValue*>(&rVal);
     232           0 :             TabitemValue* pNew = new TabitemValue( *pTIVal );
     233           0 :             aResult.reset( pNew );
     234             :         }
     235           0 :         break;
     236             :     case CTRL_MENUBAR:
     237             :         {
     238           0 :             const MenubarValue* pMVal = static_cast<const MenubarValue*>(&rVal);
     239           0 :             MenubarValue* pNew = new MenubarValue( *pMVal );
     240           0 :             aResult.reset( pNew );
     241             :         }
     242           0 :         break;
     243             :     case CTRL_PUSHBUTTON:
     244             :         {
     245           0 :             const PushButtonValue* pBVal = static_cast<const PushButtonValue*>(&rVal);
     246           0 :             PushButtonValue* pNew = new PushButtonValue( *pBVal );
     247           0 :             aResult.reset( pNew );
     248             :         }
     249           0 :         break;
     250             :     case CTRL_GENERIC:
     251      312221 :             aResult.reset( new ImplControlValue( rVal ) );
     252      312221 :             break;
     253             :     case CTRL_MENU_POPUP:
     254             :         {
     255           0 :             const MenupopupValue* pMVal = static_cast<const MenupopupValue*>(&rVal);
     256           0 :             MenupopupValue* pNew = new MenupopupValue( *pMVal );
     257           0 :             pNew->maItemRect = rDev.ImplLogicToDevicePixel( pMVal->maItemRect );
     258           0 :             aResult.reset( pNew );
     259             :         }
     260           0 :         break;
     261             :     default:
     262             :         OSL_FAIL( "unknown ImplControlValue type !" );
     263           0 :         break;
     264             :     }
     265      312221 :     return aResult;
     266             : }
     267           0 : bool OutputDevice::DrawNativeControl( ControlType nType,
     268             :                             ControlPart nPart,
     269             :                             const Rectangle& rControlRegion,
     270             :                             ControlState nState,
     271             :                             const ImplControlValue& aValue,
     272             :                             const OUString& aCaption )
     273             : {
     274           0 :     if( !EnableNativeWidget( *this ) )
     275           0 :         return false;
     276             : 
     277             :     // make sure the current clip region is initialized correctly
     278           0 :     if ( !mpGraphics )
     279           0 :         if ( !AcquireGraphics() )
     280           0 :             return false;
     281             : 
     282           0 :     if ( mbInitClipRegion )
     283           0 :         InitClipRegion();
     284           0 :     if ( mbOutputClipped )
     285           0 :         return true;
     286             : 
     287           0 :     if ( mbInitLineColor )
     288           0 :         InitLineColor();
     289           0 :     if ( mbInitFillColor )
     290           0 :         InitFillColor();
     291             : 
     292             :     // Convert the coordinates from relative to Window-absolute, so we draw
     293             :     // in the correct place in platform code
     294           0 :     boost::shared_ptr< ImplControlValue > aScreenCtrlValue( TransformControlValue( aValue, *this ) );
     295           0 :     Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
     296             : 
     297           0 :     vcl::Region aTestRegion( GetActiveClipRegion() );
     298           0 :     aTestRegion.Intersect( rControlRegion );
     299           0 :     if (aTestRegion == vcl::Region(rControlRegion))
     300           0 :         nState |= CTRL_CACHING_ALLOWED;   // control is not clipped, caching allowed
     301             : 
     302           0 :     bool bRet = mpGraphics->DrawNativeControl(nType, nPart, screenRegion, nState, *aScreenCtrlValue, aCaption, this );
     303             : 
     304           0 :     return bRet;
     305             : }
     306             : 
     307      314742 : bool OutputDevice::GetNativeControlRegion(  ControlType nType,
     308             :                                 ControlPart nPart,
     309             :                                 const Rectangle& rControlRegion,
     310             :                                 ControlState nState,
     311             :                                 const ImplControlValue& aValue,
     312             :                                 const OUString& aCaption,
     313             :                                 Rectangle &rNativeBoundingRegion,
     314             :                                 Rectangle &rNativeContentRegion ) const
     315             : {
     316      314742 :     if( !EnableNativeWidget( *this ) )
     317        2521 :         return false;
     318             : 
     319      312221 :     if ( !mpGraphics )
     320         323 :         if ( !AcquireGraphics() )
     321           0 :             return false;
     322             : 
     323             :     // Convert the coordinates from relative to Window-absolute, so we draw
     324             :     // in the correct place in platform code
     325      312221 :     boost::shared_ptr< ImplControlValue > aScreenCtrlValue( TransformControlValue( aValue, *this ) );
     326      312221 :     Rectangle screenRegion( ImplLogicToDevicePixel( rControlRegion ) );
     327             : 
     328      312221 :     bool bRet = mpGraphics->GetNativeControlRegion(nType, nPart, screenRegion, nState, *aScreenCtrlValue,
     329             :                                 aCaption, rNativeBoundingRegion,
     330      312221 :                                 rNativeContentRegion, this );
     331      312221 :     if( bRet )
     332             :     {
     333             :         // transform back native regions
     334           0 :         rNativeBoundingRegion = ImplDevicePixelToLogic( rNativeBoundingRegion );
     335           0 :         rNativeContentRegion = ImplDevicePixelToLogic( rNativeContentRegion );
     336             :     }
     337             : 
     338      312221 :     return bRet;
     339        1233 : }
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10