LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - PanelTitleBar.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 42 80 52.5 %
Date: 2015-06-13 12:38:46 Functions: 10 16 62.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 css::uno;
      36             : 
      37             : namespace sfx2 { namespace sidebar {
      38             : 
      39             : static const sal_Int32 gaLeftIconPadding (5);
      40             : static const sal_Int32 gaRightIconPadding (5);
      41             : 
      42        4927 : PanelTitleBar::PanelTitleBar(const OUString& rsTitle,
      43             :                              vcl::Window* pParentWindow,
      44             :                              Panel* pPanel)
      45             :     : TitleBar(rsTitle, pParentWindow, GetBackgroundPaint()),
      46             :       mbIsLeftButtonDown(false),
      47             :       mpPanel(pPanel),
      48             :       mnMenuItemIndex(1),
      49             :       mxFrame(),
      50        4927 :       msMoreOptionsCommand()
      51             : {
      52             :     OSL_ASSERT(mpPanel != nullptr);
      53             : 
      54             : #ifdef DEBUG
      55             :     SetText(OUString("PanelTitleBar"));
      56             : #endif
      57        4927 : }
      58             : 
      59       14781 : PanelTitleBar::~PanelTitleBar()
      60             : {
      61        4927 :     disposeOnce();
      62        9854 : }
      63             : 
      64        4927 : void PanelTitleBar::dispose()
      65             : {
      66        4927 :     mpPanel.clear();
      67        4927 :     TitleBar::dispose();
      68        4927 : }
      69             : 
      70        4373 : void PanelTitleBar::SetMoreOptionsCommand(const OUString& rsCommandName,
      71             :                                           const css::uno::Reference<css::frame::XFrame>& rxFrame)
      72             : {
      73        4373 :     if (!rsCommandName.equals(msMoreOptionsCommand))
      74             :     {
      75        1620 :         if (msMoreOptionsCommand.getLength() > 0)
      76           0 :             maToolBox->RemoveItem(maToolBox->GetItemPos(mnMenuItemIndex));
      77             : 
      78        1620 :         msMoreOptionsCommand = rsCommandName;
      79        1620 :         mxFrame = rxFrame;
      80             : 
      81        1620 :         if (msMoreOptionsCommand.getLength() > 0)
      82             :         {
      83        1620 :             maToolBox->InsertItem(
      84             :                 mnMenuItemIndex,
      85        3240 :                 Theme::GetImage(Theme::Image_PanelMenu));
      86             :             Reference<frame::XToolbarController> xController (
      87             :                 ControllerFactory::CreateToolBoxController(
      88        1620 :                     maToolBox.get(),
      89             :                     mnMenuItemIndex,
      90             :                     msMoreOptionsCommand,
      91             :                     rxFrame,
      92        1620 :                     VCLUnoHelper::GetInterface(maToolBox.get()),
      93        3240 :                     0));
      94        1620 :             maToolBox->SetController(mnMenuItemIndex, xController, msMoreOptionsCommand);
      95        1620 :             maToolBox->SetOutStyle(TOOLBOX_STYLE_FLAT);
      96        1620 :             maToolBox->SetQuickHelpText(
      97             :                 mnMenuItemIndex,
      98        3240 :                 SFX2_RESSTR(SFX_STR_SIDEBAR_MORE_OPTIONS));
      99             :         }
     100             :     }
     101        4373 : }
     102             : 
     103          20 : Rectangle PanelTitleBar::GetTitleArea (const Rectangle& rTitleBarBox)
     104             : {
     105          20 :     if (mpPanel != nullptr)
     106             :     {
     107          20 :         Image aImage (mpPanel->IsExpanded()
     108             :             ? Theme::GetImage(Theme::Image_Expand)
     109          20 :             : Theme::GetImage(Theme::Image_Collapse));
     110             :         return Rectangle(
     111          40 :             aImage.GetSizePixel().Width() + gaLeftIconPadding + gaRightIconPadding,
     112             :             rTitleBarBox.Top(),
     113             :             rTitleBarBox.Right(),
     114          60 :             rTitleBarBox.Bottom());
     115             :     }
     116             :     else
     117           0 :         return rTitleBarBox;
     118             : }
     119             : 
     120          20 : void PanelTitleBar::PaintDecoration (vcl::RenderContext& rRenderContext, const Rectangle& /*rTitleBarBox*/)
     121             : {
     122          20 :     if (mpPanel != nullptr)
     123             :     {
     124          20 :         Image aImage (mpPanel->IsExpanded()
     125             :             ? Theme::GetImage(Theme::Image_Collapse)
     126          20 :             : Theme::GetImage(Theme::Image_Expand));
     127             :         const Point aTopLeft(gaLeftIconPadding,
     128          20 :                              (GetSizePixel().Height() - aImage.GetSizePixel().Height()) / 2);
     129          20 :         rRenderContext.DrawImage(aTopLeft, aImage);
     130             :     }
     131          20 : }
     132             : 
     133        4927 : Paint PanelTitleBar::GetBackgroundPaint()
     134             : {
     135        4927 :     return Theme::GetPaint(Theme::Paint_PanelTitleBarBackground);
     136             : }
     137             : 
     138           0 : Color PanelTitleBar::GetTextColor()
     139             : {
     140           0 :     return Theme::GetColor(Theme::Color_PanelTitleFont);
     141             : }
     142             : 
     143           0 : void PanelTitleBar::HandleToolBoxItemClick (const sal_uInt16 nItemIndex)
     144             : {
     145           0 :     if (nItemIndex == mnMenuItemIndex)
     146           0 :         if (msMoreOptionsCommand.getLength() > 0)
     147             :         {
     148             :             try
     149             :             {
     150           0 :                 const util::URL aURL (Tools::GetURL(msMoreOptionsCommand));
     151           0 :                 Reference<frame::XDispatch> xDispatch (Tools::GetDispatch(mxFrame, aURL));
     152           0 :                 if (xDispatch.is())
     153           0 :                     xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
     154             :             }
     155           0 :             catch(Exception& rException)
     156             :             {
     157             :                 OSL_TRACE("caught exception: %s",
     158             :                     OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr());
     159             :             }
     160             :         }
     161           0 : }
     162             : 
     163           0 : Reference<accessibility::XAccessible> PanelTitleBar::CreateAccessible()
     164             : {
     165           0 :     SetAccessibleName(msTitle);
     166           0 :     SetAccessibleDescription(msTitle);
     167           0 :     return TitleBar::CreateAccessible();
     168             : }
     169             : 
     170           0 : void PanelTitleBar::MouseButtonDown (const MouseEvent& rMouseEvent)
     171             : {
     172           0 :     if (rMouseEvent.IsLeft())
     173             :     {
     174           0 :         mbIsLeftButtonDown = true;
     175           0 :         CaptureMouse();
     176             :     }
     177           0 : }
     178             : 
     179           0 : void PanelTitleBar::MouseButtonUp (const MouseEvent& rMouseEvent)
     180             : {
     181           0 :     if (IsMouseCaptured())
     182           0 :         ReleaseMouse();
     183             : 
     184           0 :     if (rMouseEvent.IsLeft())
     185             :     {
     186           0 :         if (mbIsLeftButtonDown)
     187             :         {
     188           0 :             if (mpPanel != nullptr)
     189             :             {
     190           0 :                 mpPanel->SetExpanded( ! mpPanel->IsExpanded());
     191           0 :                 Invalidate();
     192             :             }
     193             :         }
     194             :     }
     195           0 :     if (mbIsLeftButtonDown)
     196           0 :         mbIsLeftButtonDown = false;
     197           0 : }
     198             : 
     199           0 : void PanelTitleBar::DataChanged (const DataChangedEvent& rEvent)
     200             : {
     201           0 :     maToolBox->SetItemImage(
     202             :         mnMenuItemIndex,
     203           0 :         Theme::GetImage(Theme::Image_PanelMenu));
     204           0 :     TitleBar::DataChanged(rEvent);
     205           0 : }
     206             : 
     207         648 : } } // end of namespace sfx2::sidebar
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11