LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - TitleBar.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 62 80 77.5 %
Date: 2015-06-13 12:38:46 Functions: 12 18 66.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 "TitleBar.hxx"
      21             : #include "Paint.hxx"
      22             : #include "Accessible.hxx"
      23             : #include "AccessibleTitleBar.hxx"
      24             : 
      25             : #include <tools/svborder.hxx>
      26             : #include <vcl/gradient.hxx>
      27             : #include <vcl/lineinfo.hxx>
      28             : 
      29             : #include <com/sun/star/accessibility/AccessibleRole.hpp>
      30             : 
      31             : namespace
      32             : {
      33             :     const static sal_Int32 gnLeftIconSpace (3);
      34             :     const static sal_Int32 gnRightIconSpace (3);
      35             : }
      36             : 
      37             : namespace sfx2 { namespace sidebar {
      38             : 
      39        8083 : TitleBar::TitleBar(const OUString& rsTitle,
      40             :                    vcl::Window* pParentWindow,
      41             :                    const sidebar::Paint& rInitialBackgroundPaint)
      42             :     : Window(pParentWindow)
      43             :     , maToolBox(VclPtr<SidebarToolBox>::Create(this))
      44             :     , msTitle(rsTitle)
      45             :     , maIcon()
      46        8083 :     , maBackgroundPaint(rInitialBackgroundPaint)
      47             : {
      48        8083 :     maToolBox->SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
      49        8083 : }
      50             : 
      51       16166 : TitleBar::~TitleBar()
      52             : {
      53        8083 :     disposeOnce();
      54        8083 : }
      55             : 
      56        8083 : void TitleBar::dispose()
      57             : {
      58        8083 :     maToolBox.disposeAndClear();
      59        8083 :     vcl::Window::dispose();
      60        8083 : }
      61             : 
      62           0 : void TitleBar::SetTitle(const OUString& rsTitle)
      63             : {
      64           0 :     msTitle = rsTitle;
      65           0 :     Invalidate();
      66           0 : }
      67             : 
      68        8141 : void TitleBar::SetIcon(const Image& rIcon)
      69             : {
      70        8141 :     maIcon = rIcon;
      71        8141 :     Invalidate();
      72        8141 : }
      73             : 
      74         164 : void TitleBar::ApplySettings(vcl::RenderContext& rRenderContext)
      75             : {
      76         164 :     rRenderContext.SetBackground(maBackgroundPaint.GetWallpaper());
      77         164 : }
      78             : 
      79         164 : void TitleBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rUpdateArea*/)
      80             : {
      81             :     // Paint title bar background.
      82         164 :     Size aWindowSize (GetSizePixel());
      83         164 :     Rectangle aTitleBarBox(0,0, aWindowSize.Width(), aWindowSize.Height());
      84             : 
      85         164 :     PaintDecoration(rRenderContext, aTitleBarBox);
      86         164 :     const Rectangle aTitleBox(GetTitleArea(aTitleBarBox));
      87         164 :     PaintTitle(rRenderContext, aTitleBox);
      88         164 :     PaintFocus(rRenderContext, aTitleBox);
      89         164 : }
      90             : 
      91           3 : void TitleBar::DataChanged (const DataChangedEvent& /*rEvent*/)
      92             : {
      93           3 :     maBackgroundPaint = GetBackgroundPaint();
      94           3 :     Invalidate();
      95           3 : }
      96             : 
      97        4620 : void TitleBar::setPosSizePixel (long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags)
      98             : {
      99        4620 :     Window::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
     100             : 
     101             :     // Place the toolbox.
     102        4620 :     const sal_Int32 nToolBoxWidth (maToolBox->GetItemPosRect(0).GetWidth());
     103        4620 :     maToolBox->setPosSizePixel(nWidth - nToolBoxWidth,0, nToolBoxWidth, nHeight, PosSizeFlags::PosSize);
     104        4620 :     maToolBox->Show();
     105        4620 : }
     106             : 
     107           0 : void TitleBar::HandleToolBoxItemClick(const sal_uInt16 /*nItemIndex*/)
     108             : {
     109             :     // Any real processing has to be done in derived class.
     110           0 : }
     111             : 
     112           0 : css::uno::Reference<css::accessibility::XAccessible> TitleBar::CreateAccessible()
     113             : {
     114           0 :     SetAccessibleRole(css::accessibility::AccessibleRole::PANEL);
     115           0 :     return AccessibleTitleBar::Create(*this);
     116             : }
     117             : 
     118         164 : void TitleBar::PaintTitle(vcl::RenderContext& rRenderContext, const Rectangle& rTitleBox)
     119             : {
     120         164 :     rRenderContext.Push(PushFlags::FONT | PushFlags::TEXTCOLOR);
     121             : 
     122         164 :     Rectangle aTitleBox(rTitleBox);
     123             : 
     124             :     // When there is an icon then paint it at the left of the given
     125             :     // box.
     126         164 :     if (!!maIcon)
     127             :     {
     128           0 :         rRenderContext.DrawImage(Point(aTitleBox.Left() + gnLeftIconSpace,
     129           0 :                                        aTitleBox.Top() + (aTitleBox.GetHeight() - maIcon.GetSizePixel().Height()) / 2),
     130           0 :                                  maIcon);
     131           0 :         aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
     132             :     }
     133             : 
     134         164 :     vcl::Font aFont(rRenderContext.GetFont());
     135         164 :     aFont.SetWeight(WEIGHT_BOLD);
     136         164 :     rRenderContext.SetFont(aFont);
     137             : 
     138             :     // Paint title bar text.
     139         164 :     rRenderContext.SetTextColor(rRenderContext.GetTextColor());
     140         164 :     rRenderContext.DrawText(aTitleBox, msTitle, DrawTextFlags::Left | DrawTextFlags::VCenter);
     141         164 :     rRenderContext.Pop();
     142         164 : }
     143             : 
     144         164 : void TitleBar::PaintFocus(vcl::RenderContext& rRenderContext, const Rectangle& rFocusBox)
     145             : {
     146         164 :     rRenderContext.Push(PushFlags::FONT | PushFlags::TEXTCOLOR);
     147             : 
     148         164 :     vcl::Font aFont(rRenderContext.GetFont());
     149         164 :     aFont.SetWeight(WEIGHT_BOLD);
     150         164 :     rRenderContext.SetFont(aFont);
     151             : 
     152         164 :     const Rectangle aTextBox(rRenderContext.GetTextRect(rFocusBox, msTitle, DrawTextFlags::Left | DrawTextFlags::VCenter));
     153             : 
     154         164 :     const Rectangle aLargerTextBox(aTextBox.Left() - 2,
     155         164 :                                    aTextBox.Top() - 2,
     156         164 :                                    aTextBox.Right() + 2,
     157         656 :                                    aTextBox.Bottom() + 2);
     158             : 
     159         164 :     if (HasFocus())
     160           0 :         Window::ShowFocus(aLargerTextBox);
     161             :     else
     162         164 :         Window::HideFocus();
     163             : 
     164         164 :     rRenderContext.Pop();
     165         164 : }
     166             : 
     167           0 : IMPL_LINK_TYPED(TitleBar, SelectionHandler, ToolBox*, pToolBox, void)
     168             : {
     169             :     (void)pToolBox;
     170             :     OSL_ASSERT(maToolBox.get()==pToolBox);
     171           0 :     const sal_uInt16 nItemId (maToolBox->GetHighlightItemId());
     172             : 
     173           0 :     HandleToolBoxItemClick(nItemId);
     174           0 : }
     175             : 
     176         648 : } } // end of namespace sfx2::sidebar
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11