LCOV - code coverage report
Current view: top level - vcl/source/window - dockingarea.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 126 41.3 %
Date: 2014-04-11 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 <vcl/dockingarea.hxx>
      21             : #include <vcl/syswin.hxx>
      22             : #include <vcl/menu.hxx>
      23             : #include <vcl/settings.hxx>
      24             : 
      25             : #include <svdata.hxx>
      26             : 
      27             : #include <map>
      28             : 
      29             : class DockingAreaWindow::ImplData
      30             : {
      31             : public:
      32             :     ImplData();
      33             :     ~ImplData();
      34             : 
      35             :     WindowAlign meAlign;
      36             : };
      37             : 
      38       16652 : DockingAreaWindow::ImplData::ImplData()
      39             : {
      40       16652 :     meAlign = WINDOWALIGN_TOP;
      41       16652 : }
      42             : 
      43       16548 : DockingAreaWindow::ImplData::~ImplData()
      44             : {
      45       16548 : }
      46             : 
      47       53650 : static void ImplInitBackground( DockingAreaWindow* pThis )
      48             : {
      49       53650 :     const BitmapEx& rPersonaBitmap = Application::GetSettings().GetStyleSettings().GetPersonaHeader();
      50       53650 :     if ( !rPersonaBitmap.IsEmpty() && pThis->GetAlign() == WINDOWALIGN_TOP )
      51             :     {
      52           0 :         Wallpaper aWallpaper( rPersonaBitmap );
      53           0 :         aWallpaper.SetStyle( WALLPAPER_TOPRIGHT );
      54           0 :         aWallpaper.SetColor( Application::GetSettings().GetStyleSettings().GetWorkspaceColor() );
      55             : 
      56             :         // we need to shift the bitmap vertically so that it spans over the
      57             :         // menubar conveniently
      58           0 :         long nMenubarHeight = 0;
      59           0 :         SystemWindow *pSysWin = pThis->GetSystemWindow();
      60           0 :         if ( pSysWin && pSysWin->GetMenuBar() )
      61             :         {
      62           0 :             Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
      63           0 :             if ( pMenubarWin )
      64           0 :                 nMenubarHeight = pMenubarWin->GetOutputHeightPixel();
      65             :         }
      66           0 :         aWallpaper.SetRect( Rectangle( Point( 0, -nMenubarHeight ), Size( pThis->GetOutputWidthPixel(), pThis->GetOutputHeightPixel() + nMenubarHeight ) ) );
      67             : 
      68           0 :         pThis->SetBackground( aWallpaper );
      69             :     }
      70       53650 :     else if( !pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
      71             :     {
      72       53650 :         Wallpaper aWallpaper;
      73       53650 :         aWallpaper.SetStyle( WALLPAPER_APPLICATIONGRADIENT );
      74       53650 :         pThis->SetBackground( aWallpaper );
      75             :     }
      76             :     else
      77           0 :         pThis->SetBackground( Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceColor() ) );
      78       53650 : }
      79             : 
      80       16652 : DockingAreaWindow::DockingAreaWindow( Window* pParent ) :
      81       16652 :     Window( WINDOW_DOCKINGAREA )
      82             : {
      83       16652 :     ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, NULL );
      84             : 
      85       16652 :     mpImplData = new ImplData;
      86       16652 :     ImplInitBackground( this );
      87       16652 : }
      88             : 
      89       49644 : DockingAreaWindow::~DockingAreaWindow()
      90             : {
      91       16548 :     delete mpImplData;
      92       33096 : }
      93             : 
      94         320 : void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
      95             : {
      96         320 :     Window::DataChanged( rDCEvt );
      97             : 
      98         320 :     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
      99             :     {
     100         304 :         ImplInitBackground( this );
     101         304 :         Invalidate();
     102             :     }
     103         320 : }
     104             : 
     105       32437 : static void ImplInvalidateMenubar( DockingAreaWindow* pThis )
     106             : {
     107             :     // due to a possible comon gradient covering menubar and top dockingarea
     108             :     // the menubar must be repainted if the top dockingarea changes size or visibility
     109       64874 :     if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
     110           0 :         (pThis->GetAlign() == WINDOWALIGN_TOP)
     111           0 :         && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL )
     112       32437 :         && pThis->IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
     113             :     {
     114           0 :         SystemWindow *pSysWin = pThis->GetSystemWindow();
     115           0 :         if( pSysWin && pSysWin->GetMenuBar() )
     116             :         {
     117           0 :             Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
     118           0 :             if( pMenubarWin )
     119           0 :                 pMenubarWin->Invalidate();
     120             :         }
     121             :     }
     122       32437 : }
     123             : 
     124       22344 : void DockingAreaWindow::StateChanged( StateChangedType nType )
     125             : {
     126       22344 :     Window::StateChanged( nType );
     127             : 
     128       22344 :     if ( nType == STATE_CHANGE_VISIBLE )
     129        8232 :         ImplInvalidateMenubar( this );
     130       22344 : }
     131             : 
     132           0 : bool DockingAreaWindow::IsHorizontal() const
     133             : {
     134           0 :     return ( mpImplData->meAlign == WINDOWALIGN_TOP || mpImplData->meAlign == WINDOWALIGN_BOTTOM );
     135             : }
     136             : 
     137       16652 : void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
     138             : {
     139       16652 :     if( eNewAlign != mpImplData->meAlign )
     140             :     {
     141       12489 :         mpImplData->meAlign = eNewAlign;
     142       12489 :         ImplInitBackground( this );
     143       12489 :         Invalidate();
     144             :     }
     145       16652 : }
     146             : 
     147           0 : WindowAlign DockingAreaWindow::GetAlign() const
     148             : {
     149           0 :     return mpImplData->meAlign;
     150             : }
     151             : 
     152        4507 : void DockingAreaWindow::Paint( const Rectangle& )
     153             : {
     154        4507 :     EnableNativeWidget( true ); // only required because the toolkit curently switches this flag off
     155        4507 :     if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
     156             :     {
     157           0 :         ToolbarValue        aControlValue;
     158             : 
     159           0 :         if( GetAlign() == WINDOWALIGN_TOP && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG )
     160             :         {
     161             :             // give NWF a hint that this dockingarea is adjacent to the menubar
     162             :             // useful for special gradient effects that should cover both windows
     163           0 :             aControlValue.mbIsTopDockingArea = true;
     164             :         }
     165           0 :         ControlState        nState = CTRL_STATE_ENABLED;
     166             : 
     167           0 :         if ( GetAlign() == WINDOWALIGN_TOP && !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() )
     168           0 :             Erase();
     169           0 :         else if ( !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB )
     170             :         {
     171             :             // draw a single toolbar background covering the whole docking area
     172           0 :             Point tmp;
     173           0 :             Rectangle aCtrlRegion( tmp, GetOutputSizePixel() );
     174             : 
     175           0 :             DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
     176           0 :                                aCtrlRegion, nState, aControlValue, OUString() );
     177             : 
     178           0 :             if( !ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames )
     179             :             {
     180             :                 // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
     181           0 :                 sal_uInt16 nChildren = GetChildCount();
     182           0 :                 for( sal_uInt16 n = 0; n < nChildren; n++ )
     183             :                 {
     184           0 :                     Window* pChild = GetChild( n );
     185           0 :                     if ( pChild->IsVisible() )
     186             :                     {
     187           0 :                         Point aPos = pChild->GetPosPixel();
     188           0 :                         Size aSize = pChild->GetSizePixel();
     189           0 :                         Rectangle aRect( aPos, aSize );
     190             : 
     191           0 :                         SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
     192           0 :                         DrawLine( aRect.TopLeft(), aRect.TopRight() );
     193           0 :                         DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
     194             : 
     195           0 :                         SetLineColor( GetSettings().GetStyleSettings().GetSeparatorColor() );
     196           0 :                         DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
     197           0 :                         DrawLine( aRect.TopRight(), aRect.BottomRight() );
     198             :                     }
     199             :                 }
     200             :             }
     201             :         }
     202             :         else
     203             :         {
     204             :             // create map to find toolbar lines
     205           0 :             Size aOutSz = GetOutputSizePixel();
     206           0 :             std::map< int, int > ranges;
     207           0 :             sal_uInt16 nChildren = GetChildCount();
     208           0 :             for( sal_uInt16 n = 0; n < nChildren; n++ )
     209             :             {
     210           0 :                 Window* pChild = GetChild( n );
     211           0 :                 Point aPos = pChild->GetPosPixel();
     212           0 :                 Size aSize = pChild->GetSizePixel();
     213           0 :                 if( IsHorizontal() )
     214           0 :                     ranges[ aPos.Y() ] = aSize.Height();
     215             :                 else
     216           0 :                     ranges[ aPos.X() ] = aSize.Width();
     217             :             }
     218             : 
     219             :             // draw multiple toolbar backgrounds, i.e., one for each toolbar line
     220           0 :             for( std::map<int,int>::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
     221             :             {
     222           0 :                 Rectangle aTBRect;
     223           0 :                 if( IsHorizontal() )
     224             :                 {
     225           0 :                     aTBRect.Left()      = 0;
     226           0 :                     aTBRect.Right()     = aOutSz.Width() - 1;
     227           0 :                     aTBRect.Top()       = it->first;
     228           0 :                     aTBRect.Bottom()    = it->first + it->second - 1;
     229             :                 }
     230             :                 else
     231             :                 {
     232           0 :                     aTBRect.Left()      = it->first;
     233           0 :                     aTBRect.Right()     = it->first + it->second - 1;
     234           0 :                     aTBRect.Top()       = 0;
     235           0 :                     aTBRect.Bottom()    = aOutSz.Height() - 1;
     236             :                 }
     237           0 :                 DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
     238           0 :                                    aTBRect, nState, aControlValue, OUString() );
     239           0 :             }
     240           0 :         }
     241             :     }
     242        4507 : }
     243             : 
     244       24205 : void DockingAreaWindow::Resize()
     245             : {
     246       24205 :     ImplInitBackground( this );
     247       24205 :     ImplInvalidateMenubar( this );
     248       24205 :     if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
     249           0 :         Invalidate();
     250       24205 : }
     251             : 
     252             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10