LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - TitleBar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 54 77 70.1 %
Date: 2014-04-11 Functions: 8 16 50.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 "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             : 
      32             : namespace
      33             : {
      34             :     const static sal_Int32 gnLeftIconSpace (3);
      35             :     const static sal_Int32 gnRightIconSpace (3);
      36             : }
      37             : 
      38             : namespace sfx2 { namespace sidebar {
      39             : 
      40          22 : TitleBar::TitleBar (
      41             :     const ::rtl::OUString& rsTitle,
      42             :     Window* pParentWindow,
      43             :     const sidebar::Paint& rInitialBackgroundPaint)
      44             :     : Window(pParentWindow),
      45             :       maToolBox(this),
      46             :       msTitle(rsTitle),
      47          22 :       maIcon()
      48             : {
      49          22 :     SetBackground(rInitialBackgroundPaint.GetWallpaper());
      50             : 
      51          22 :     maToolBox.SetSelectHdl(LINK(this, TitleBar, SelectionHandler));
      52          22 : }
      53             : 
      54             : 
      55             : 
      56             : 
      57          22 : TitleBar::~TitleBar (void)
      58             : {
      59          22 : }
      60             : 
      61             : 
      62             : 
      63             : 
      64           0 : void TitleBar::SetTitle (const ::rtl::OUString& rsTitle)
      65             : {
      66           0 :     msTitle = rsTitle;
      67           0 :     Invalidate();
      68           0 : }
      69             : 
      70             : 
      71             : 
      72             : 
      73          22 : void TitleBar::SetIcon (const Image& rIcon)
      74             : {
      75          22 :     maIcon = rIcon;
      76          22 :     Invalidate();
      77          22 : }
      78             : 
      79             : 
      80             : 
      81             : 
      82          42 : void TitleBar::Paint (const Rectangle& rUpdateArea)
      83             : {
      84             :     (void)rUpdateArea;
      85             : 
      86             :     // Paint title bar background.
      87          42 :     Size aWindowSize (GetOutputSizePixel());
      88             :     Rectangle aTitleBarBox(
      89             :         0,
      90             :         0,
      91          42 :         aWindowSize.Width(),
      92          42 :         aWindowSize.Height()
      93          84 :         );
      94             : 
      95          42 :     PaintDecoration(aTitleBarBox);
      96          42 :     const Rectangle aTitleBox (GetTitleArea(aTitleBarBox));
      97          42 :     PaintTitle(aTitleBox);
      98          42 :     PaintFocus(aTitleBox);
      99          42 : }
     100             : 
     101             : 
     102             : 
     103             : 
     104           0 : void TitleBar::DataChanged (const DataChangedEvent& rEvent)
     105             : {
     106             :     (void)rEvent;
     107             : 
     108           0 :     SetBackground(GetBackgroundPaint().GetWallpaper());
     109           0 : }
     110             : 
     111             : 
     112             : 
     113             : 
     114          66 : void TitleBar::setPosSizePixel (
     115             :     long nX,
     116             :     long nY,
     117             :     long nWidth,
     118             :     long nHeight,
     119             :     sal_uInt16 nFlags)
     120             : {
     121          66 :     Window::setPosSizePixel(nX,nY,nWidth,nHeight,nFlags);
     122             : 
     123             :     // Place the toolbox.
     124          66 :     const sal_Int32 nToolBoxWidth (maToolBox.GetItemPosRect(0).GetWidth());
     125          66 :     maToolBox.setPosSizePixel(nWidth-nToolBoxWidth,0, nToolBoxWidth,nHeight, WINDOW_POSSIZE_POSSIZE);
     126          66 :     maToolBox.Show();
     127          66 : }
     128             : 
     129             : 
     130             : 
     131             : 
     132          44 : ToolBox& TitleBar::GetToolBox (void)
     133             : {
     134          44 :     return maToolBox;
     135             : }
     136             : 
     137             : 
     138             : 
     139             : 
     140           0 : const ToolBox& TitleBar::GetToolBox (void) const
     141             : {
     142           0 :     return maToolBox;
     143             : }
     144             : 
     145             : 
     146             : 
     147             : 
     148           0 : void TitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
     149             : {
     150             :     (void)nItemIndex;
     151             :     // Any real processing has to be done in derived class.
     152           0 : }
     153             : 
     154             : 
     155             : 
     156             : 
     157           0 : cssu::Reference<css::accessibility::XAccessible> TitleBar::CreateAccessible (void)
     158             : {
     159           0 :     SetAccessibleRole(css::accessibility::AccessibleRole::PANEL);
     160           0 :     return AccessibleTitleBar::Create(*this);
     161             : }
     162             : 
     163             : 
     164             : 
     165             : 
     166          42 : void TitleBar::PaintTitle (const Rectangle& rTitleBox)
     167             : {
     168          42 :     Push(PUSH_FONT | PUSH_TEXTCOLOR);
     169             : 
     170          42 :     Rectangle aTitleBox (rTitleBox);
     171             : 
     172             :     // When there is an icon then paint it at the left of the given
     173             :     // box.
     174          42 :     if ( !! maIcon)
     175             :     {
     176             :         DrawImage(
     177             :             Point(
     178           0 :                 aTitleBox.Left() + gnLeftIconSpace,
     179           0 :                 aTitleBox.Top() + (aTitleBox.GetHeight()-maIcon.GetSizePixel().Height())/2),
     180           0 :             maIcon);
     181           0 :         aTitleBox.Left() += gnLeftIconSpace + maIcon.GetSizePixel().Width() + gnRightIconSpace;
     182             :     }
     183             : 
     184          42 :     Font aFont(GetFont());
     185          42 :     aFont.SetWeight(WEIGHT_BOLD);
     186          42 :     SetFont(aFont);
     187             : 
     188             :     // Paint title bar text.
     189          42 :     SetTextColor(GetTextColor());
     190             :     DrawText(
     191             :         aTitleBox,
     192             :         msTitle,
     193          42 :         TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER);
     194             : 
     195          42 :     Pop();
     196          42 : }
     197             : 
     198             : 
     199             : 
     200             : 
     201          42 : void TitleBar::PaintFocus (const Rectangle& rFocusBox)
     202             : {
     203          42 :     Push(PUSH_FONT | PUSH_TEXTCOLOR);
     204             : 
     205          42 :     Font aFont(GetFont());
     206          42 :     aFont.SetWeight(WEIGHT_BOLD);
     207          42 :     SetFont(aFont);
     208             : 
     209             :     const Rectangle aTextBox (
     210             :         GetTextRect(
     211             :             rFocusBox,
     212             :             msTitle,
     213          42 :             TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER));
     214             :     const Rectangle aLargerTextBox (
     215          42 :         aTextBox.Left() - 2,
     216          42 :         aTextBox.Top() - 2,
     217          42 :         aTextBox.Right() + 2,
     218         168 :         aTextBox.Bottom() + 2);
     219             : 
     220          42 :     if (HasFocus())
     221           0 :         Window::ShowFocus(aLargerTextBox);
     222             :     else
     223          42 :         Window::HideFocus();
     224             : 
     225          42 :     Pop();
     226          42 : }
     227             : 
     228             : 
     229             : 
     230             : 
     231           0 : IMPL_LINK(TitleBar, SelectionHandler, ToolBox*, pToolBox)
     232             : {
     233             :     (void)pToolBox;
     234             :     OSL_ASSERT(&maToolBox==pToolBox);
     235           0 :     const sal_uInt16 nItemId (maToolBox.GetHighlightItemId());
     236             : 
     237           0 :     HandleToolBoxItemClick(nItemId);
     238             : 
     239           0 :     return sal_True;
     240             : }
     241             : 
     242             : } } // end of namespace sfx2::sidebar
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10