LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - PanelTitleBar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 25 70 35.7 %
Date: 2014-04-11 Functions: 8 13 61.5 %
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 "PanelTitleBar.hxx"
      21             : #include <sfx2/sfxresid.hxx>
      22             : #include "Sidebar.hrc"
      23             : 
      24             : #include "Paint.hxx"
      25             : #include "Panel.hxx"
      26             : #include <sfx2/sidebar/Theme.hxx>
      27             : #include <sfx2/sidebar/ControllerFactory.hxx>
      28             : #include <sfx2/sidebar/Tools.hxx>
      29             : #include <tools/svborder.hxx>
      30             : #include <vcl/gradient.hxx>
      31             : #include <vcl/image.hxx>
      32             : #include <toolkit/helper/vclunohelper.hxx>
      33             : 
      34             : using namespace css;
      35             : using namespace cssu;
      36             : 
      37             : namespace sfx2 { namespace sidebar {
      38             : 
      39             : 
      40             : static const sal_Int32 gaLeftIconPadding (5);
      41             : static const sal_Int32 gaRightIconPadding (5);
      42             : 
      43             : 
      44          11 : PanelTitleBar::PanelTitleBar (
      45             :     const ::rtl::OUString& rsTitle,
      46             :     Window* pParentWindow,
      47             :     Panel* pPanel)
      48             :     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
      49             :       mbIsLeftButtonDown(false),
      50             :       mpPanel(pPanel),
      51             :       mnMenuItemIndex(1),
      52             :       mxFrame(),
      53             :       msMoreOptionsCommand(),
      54          11 :       msAccessibleNamePrefix(SFX2_RESSTR(SFX_STR_SIDEBAR_ACCESSIBILITY_PANEL_PREFIX))
      55             : {
      56             :     OSL_ASSERT(mpPanel != NULL);
      57             : 
      58             : #ifdef DEBUG
      59             :     SetText(OUString("PanelTitleBar"));
      60             : #endif
      61          11 : }
      62             : 
      63             : 
      64             : 
      65             : 
      66          22 : PanelTitleBar::~PanelTitleBar (void)
      67             : {
      68          22 : }
      69             : 
      70             : 
      71             : 
      72             : 
      73          11 : void PanelTitleBar::SetMoreOptionsCommand (
      74             :     const ::rtl::OUString& rsCommandName,
      75             :     const ::cssu::Reference<css::frame::XFrame>& rxFrame)
      76             : {
      77          11 :     if ( ! rsCommandName.equals(msMoreOptionsCommand))
      78             :     {
      79           0 :         if (msMoreOptionsCommand.getLength() > 0)
      80           0 :             maToolBox.RemoveItem(maToolBox.GetItemPos(mnMenuItemIndex));
      81             : 
      82           0 :         msMoreOptionsCommand = rsCommandName;
      83           0 :         mxFrame = rxFrame;
      84             : 
      85           0 :         if (msMoreOptionsCommand.getLength() > 0)
      86             :         {
      87             :             maToolBox.InsertItem(
      88             :                 mnMenuItemIndex,
      89           0 :                 Theme::GetImage(Theme::Image_PanelMenu));
      90             :             Reference<frame::XToolbarController> xController (
      91             :                 ControllerFactory::CreateToolBoxController(
      92             :                     &maToolBox,
      93             :                     mnMenuItemIndex,
      94             :                     msMoreOptionsCommand,
      95             :                     rxFrame,
      96             :                     VCLUnoHelper::GetInterface(&maToolBox),
      97           0 :                     0));
      98           0 :             maToolBox.SetController(mnMenuItemIndex, xController, msMoreOptionsCommand);
      99           0 :             maToolBox.SetOutStyle(TOOLBOX_STYLE_FLAT);
     100             :             maToolBox.SetQuickHelpText(
     101             :                 mnMenuItemIndex,
     102           0 :                 SFX2_RESSTR(SFX_STR_SIDEBAR_MORE_OPTIONS));
     103             :         }
     104             :     }
     105          11 : }
     106             : 
     107             : 
     108             : 
     109             : 
     110          21 : Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
     111             : {
     112          21 :     if (mpPanel != NULL)
     113             :     {
     114          21 :         Image aImage (mpPanel->IsExpanded()
     115             :             ? Theme::GetImage(Theme::Image_Expand)
     116          21 :             : Theme::GetImage(Theme::Image_Collapse));
     117             :         return Rectangle(
     118          42 :             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
     119             :             rTitleBarBox.Top(),
     120             :             rTitleBarBox.Right(),
     121          63 :             rTitleBarBox.Bottom());
     122             :     }
     123             :     else
     124           0 :         return rTitleBarBox;
     125             : }
     126             : 
     127             : 
     128             : 
     129             : 
     130          21 : void PanelTitleBar::PaintDecoration (const Rectangle& rTitleBarBox)
     131             : {
     132             :     (void)rTitleBarBox;
     133             : 
     134          21 :     if (mpPanel != NULL)
     135             :     {
     136          21 :         Image aImage (mpPanel->IsExpanded()
     137             :             ? Theme::GetImage(Theme::Image_Collapse)
     138          21 :             : Theme::GetImage(Theme::Image_Expand));
     139             :         const Point aTopLeft (
     140             :             gaLeftIconPadding,
     141          21 :             (GetSizePixel().Height()-aImage.GetSizePixel().Height())/2);
     142          21 :         DrawImage(aTopLeft, aImage);
     143             :     }
     144          21 : }
     145             : 
     146             : 
     147             : 
     148             : 
     149          11 : Paint PanelTitleBar::GetBackgroundPaint (void)
     150             : {
     151          11 :     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
     152             : }
     153             : 
     154             : 
     155             : 
     156             : 
     157          21 : Color PanelTitleBar::GetTextColor (void)
     158             : {
     159          21 :     return Theme::GetColor(Theme::Color_PanelTitleFont);
     160             : }
     161             : 
     162             : 
     163             : 
     164             : 
     165           0 : void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
     166             : {
     167           0 :     if (nItemIndex == mnMenuItemIndex)
     168           0 :         if (msMoreOptionsCommand.getLength() > 0)
     169             :         {
     170             :             try
     171             :             {
     172           0 :                 const util::URL aURL (Tools::GetURL(msMoreOptionsCommand));
     173           0 :                 Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
     174           0 :                 if (xDispatch.is())
     175           0 :                     xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
     176             :             }
     177           0 :             catch(Exception& rException)
     178             :             {
     179             :                 OSL_TRACE("caught exception: %s",
     180             :                     OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
     181             :             }
     182             :         }
     183           0 : }
     184             : 
     185             : 
     186             : 
     187             : 
     188           0 : Reference<accessibility::XAccessible> PanelTitleBar::CreateAccessible (void)
     189             : {
     190           0 :     const ::rtl::OUString sAccessibleName(msAccessibleNamePrefix + msTitle);
     191           0 :     SetAccessibleName(sAccessibleName);
     192           0 :     SetAccessibleDescription(sAccessibleName);
     193           0 :     return TitleBar::CreateAccessible();
     194             : }
     195             : 
     196             : 
     197             : 
     198             : 
     199           0 : void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
     200             : {
     201           0 :     if (rMouseEvent.IsLeft())
     202             :     {
     203           0 :         mbIsLeftButtonDown = true;
     204           0 :         CaptureMouse();
     205             :     }
     206           0 : }
     207             : 
     208             : 
     209             : 
     210             : 
     211           0 : void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
     212             : {
     213           0 :     if (IsMouseCaptured())
     214           0 :         ReleaseMouse();
     215             : 
     216           0 :     if (rMouseEvent.IsLeft())
     217             :     {
     218           0 :         if (mbIsLeftButtonDown)
     219             :         {
     220           0 :             if (mpPanel != NULL)
     221             :             {
     222           0 :                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
     223           0 :                 Invalidate();
     224             :             }
     225             :         }
     226             :     }
     227           0 :     if (mbIsLeftButtonDown)
     228           0 :         mbIsLeftButtonDown = false;
     229           0 : }
     230             : 
     231             : 
     232             : 
     233             : 
     234           0 : void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
     235             : {
     236             :     maToolBox.SetItemImage(
     237             :         mnMenuItemIndex,
     238           0 :         Theme::GetImage(Theme::Image_PanelMenu));
     239           0 :     TitleBar::DataChanged(rEvent);
     240           0 : }
     241             : 
     242             : } } // end of namespace sfx2::sidebar
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10