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

Generated by: LCOV version 1.11