LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - TabBar.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 100 159 62.9 %
Date: 2014-04-11 Functions: 13 21 61.9 %
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 "TabBar.hxx"
      21             : #include "TabItem.hxx"
      22             : #include <sfx2/sidebar/ControlFactory.hxx>
      23             : #include "DeckDescriptor.hxx"
      24             : #include "Paint.hxx"
      25             : #include <sfx2/sidebar/Theme.hxx>
      26             : #include <sfx2/sidebar/Tools.hxx>
      27             : #include "FocusManager.hxx"
      28             : 
      29             : #include <vcl/gradient.hxx>
      30             : #include <vcl/image.hxx>
      31             : #include <vcl/wrkwin.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <tools/svborder.hxx>
      34             : 
      35             : #include <com/sun/star/graphic/XGraphicProvider.hpp>
      36             : 
      37             : 
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::uno;
      40             : 
      41             : 
      42             : 
      43             : 
      44             : namespace sfx2 { namespace sidebar {
      45             : 
      46          17 : TabBar::TabBar (
      47             :     Window* pParentWindow,
      48             :     const Reference<frame::XFrame>& rxFrame,
      49             :     const ::boost::function<void(const ::rtl::OUString&)>& rDeckActivationFunctor,
      50             :     const PopupMenuProvider& rPopupMenuProvider)
      51             :     : Window(pParentWindow, WB_DIALOGCONTROL),
      52             :       mxFrame(rxFrame),
      53             :       mpMenuButton(ControlFactory::CreateMenuButton(this)),
      54             :       maItems(),
      55             :       maDeckActivationFunctor(rDeckActivationFunctor),
      56          17 :       maPopupMenuProvider(rPopupMenuProvider)
      57             : {
      58          17 :     SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper());
      59             : 
      60          17 :     mpMenuButton->SetModeImage(Theme::GetImage(Theme::Image_TabBarMenu));
      61          17 :     mpMenuButton->SetClickHdl(LINK(this, TabBar, OnToolboxClicked));
      62          17 :     Layout();
      63             : 
      64             : #ifdef DEBUG
      65             :     SetText(OUString("TabBar"));
      66             : #endif
      67          17 : }
      68             : 
      69             : 
      70             : 
      71             : 
      72          34 : TabBar::~TabBar (void)
      73             : {
      74          34 : }
      75             : 
      76             : 
      77             : 
      78             : 
      79          15 : void TabBar::Paint (const Rectangle& rUpdateArea)
      80             : {
      81          15 :     Window::Paint(rUpdateArea);
      82             : 
      83          15 :     const sal_Int32 nHorizontalPadding (Theme::GetInteger(Theme::Int_TabMenuSeparatorPadding));
      84          15 :     SetLineColor(Theme::GetColor(Theme::Color_TabMenuSeparator));
      85             :     DrawLine(
      86             :         Point(nHorizontalPadding, mnMenuSeparatorY),
      87          15 :         Point(GetSizePixel().Width()-nHorizontalPadding, mnMenuSeparatorY));
      88          15 : }
      89             : 
      90             : 
      91             : 
      92             : 
      93         232 : sal_Int32 TabBar::GetDefaultWidth (void)
      94             : {
      95         232 :     return Theme::GetInteger(Theme::Int_TabItemWidth)
      96         232 :         + Theme::GetInteger(Theme::Int_TabBarLeftPadding)
      97         232 :         + Theme::GetInteger(Theme::Int_TabBarRightPadding);
      98             : }
      99             : 
     100             : 
     101             : 
     102             : 
     103          11 : void TabBar::SetDecks (
     104             :     const ResourceManager::DeckContextDescriptorContainer& rDecks)
     105             : {
     106             :     // Remove the current buttons.
     107             :     {
     108          11 :         for(ItemContainer::iterator
     109          11 :                 iItem(maItems.begin()), iEnd(maItems.end());
     110             :             iItem!=iEnd;
     111             :             ++iItem)
     112             :         {
     113           0 :             iItem->mpButton.reset();
     114             :         }
     115          11 :         maItems.clear();
     116             :     }
     117             : 
     118          11 :     maItems.resize(rDecks.size());
     119          11 :     sal_Int32 nIndex (0);
     120          88 :     for (ResourceManager::DeckContextDescriptorContainer::const_iterator
     121          11 :              iDeck(rDecks.begin()),
     122          11 :              iEnd(rDecks.end());
     123             :          iDeck!=iEnd;
     124             :          ++iDeck)
     125             :     {
     126          77 :         const DeckDescriptor* pDescriptor = ResourceManager::Instance().GetDeckDescriptor(iDeck->msId);
     127          77 :         if (pDescriptor == NULL)
     128             :         {
     129             :             OSL_ASSERT(pDescriptor!=NULL);
     130           0 :             continue;
     131             :         }
     132             : 
     133          77 :         Item& rItem (maItems[nIndex++]);
     134          77 :         rItem.msDeckId = pDescriptor->msId;
     135          77 :         rItem.mpButton.reset(CreateTabItem(*pDescriptor));
     136          77 :         rItem.mpButton->SetClickHdl(LINK(&rItem, TabBar::Item, HandleClick));
     137          77 :         rItem.maDeckActivationFunctor = maDeckActivationFunctor;
     138          77 :         rItem.mbIsHiddenByDefault = false;
     139          77 :         rItem.mbIsHidden = ! pDescriptor->mbIsEnabled;
     140             : 
     141          77 :         rItem.mpButton->Enable(iDeck->mbIsEnabled);
     142             :     }
     143             : 
     144          11 :     UpdateButtonIcons();
     145          11 :     Layout();
     146          11 : }
     147             : 
     148             : 
     149             : 
     150             : 
     151          11 : void TabBar::UpdateButtonIcons (void)
     152             : {
     153          11 :     Image aImage = Theme::GetImage(Theme::Image_TabBarMenu);
     154          11 :     if ( mpMenuButton->GetDPIScaleFactor() > 1 )
     155             :     {
     156           0 :         BitmapEx b = aImage.GetBitmapEx();
     157           0 :         b.Scale(mpMenuButton->GetDPIScaleFactor(), mpMenuButton->GetDPIScaleFactor(), BMP_SCALE_FAST);
     158           0 :         aImage = Image(b);
     159             :     }
     160          11 :     mpMenuButton->SetModeImage(aImage);
     161             : 
     162          88 :     for(ItemContainer::const_iterator
     163          11 :             iItem(maItems.begin()), iEnd(maItems.end());
     164             :         iItem!=iEnd;
     165             :         ++iItem)
     166             :     {
     167          77 :         const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId);
     168          77 :         if (pDeckDescriptor != NULL)
     169             :         {
     170          77 :             aImage = GetItemImage(*pDeckDescriptor);
     171          77 :             if ( mpMenuButton->GetDPIScaleFactor() > 1 )
     172             :             {
     173           0 :                 BitmapEx b = aImage.GetBitmapEx();
     174           0 :                 b.Scale(mpMenuButton->GetDPIScaleFactor(), mpMenuButton->GetDPIScaleFactor(), BMP_SCALE_FAST);
     175           0 :                 aImage = Image(b);
     176             :             }
     177             : 
     178          77 :             iItem->mpButton->SetModeImage(aImage);
     179             :         }
     180             :     }
     181             : 
     182          11 :     Invalidate();
     183          11 : }
     184             : 
     185             : 
     186             : 
     187             : 
     188          28 : void TabBar::Layout (void)
     189             : {
     190             :     const SvBorder aPadding (
     191             :         Theme::GetInteger(Theme::Int_TabBarLeftPadding),
     192             :         Theme::GetInteger(Theme::Int_TabBarTopPadding),
     193             :         Theme::GetInteger(Theme::Int_TabBarRightPadding),
     194          28 :         Theme::GetInteger(Theme::Int_TabBarBottomPadding));
     195          28 :     sal_Int32 nX (aPadding.Top());
     196          28 :     sal_Int32 nY (aPadding.Left());
     197             :     const Size aTabItemSize (
     198          28 :         Theme::GetInteger(Theme::Int_TabItemWidth) * GetDPIScaleFactor(),
     199          56 :         Theme::GetInteger(Theme::Int_TabItemHeight) * GetDPIScaleFactor());
     200             : 
     201             :     // Place the menu button and the separator.
     202          28 :     if (mpMenuButton != 0)
     203             :     {
     204          28 :         mpMenuButton->SetPosSizePixel(
     205             :             Point(nX,nY),
     206          28 :             aTabItemSize);
     207          28 :         mpMenuButton->Show();
     208          28 :         nY += mpMenuButton->GetSizePixel().Height() + 1 + Theme::GetInteger(Theme::Int_TabMenuPadding);
     209          28 :         mnMenuSeparatorY = nY - Theme::GetInteger(Theme::Int_TabMenuPadding)/2 - 1;
     210             :     }
     211             : 
     212             :     // Place the deck selection buttons.
     213         105 :     for(ItemContainer::const_iterator
     214          28 :             iItem(maItems.begin()), iEnd(maItems.end());
     215             :         iItem!=iEnd;
     216             :         ++iItem)
     217             :     {
     218          77 :         Button& rButton (*iItem->mpButton);
     219          77 :         rButton.Show( ! iItem->mbIsHidden);
     220             : 
     221          77 :         if (iItem->mbIsHidden)
     222           0 :             continue;
     223             : 
     224             :         // Place and size the icon.
     225             :         rButton.SetPosSizePixel(
     226             :             Point(nX,nY),
     227          77 :             aTabItemSize);
     228          77 :         rButton.Show();
     229             : 
     230          77 :         nY += rButton.GetSizePixel().Height() + 1 + aPadding.Bottom();
     231             :     }
     232          28 :     Invalidate();
     233          28 : }
     234             : 
     235             : 
     236             : 
     237             : 
     238          22 : void TabBar::HighlightDeck (const ::rtl::OUString& rsDeckId)
     239             : {
     240         176 :     for (ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end());
     241             :          iItem!=iEnd;
     242             :          ++iItem)
     243             :     {
     244         154 :         if (iItem->msDeckId.equals(rsDeckId))
     245          22 :             iItem->mpButton->Check(true);
     246             :         else
     247         132 :             iItem->mpButton->Check(false);
     248             :     }
     249          22 : }
     250             : 
     251             : 
     252             : 
     253             : 
     254           0 : void TabBar::DataChanged (const DataChangedEvent& rDataChangedEvent)
     255             : {
     256           0 :     SetBackground(Theme::GetPaint(Theme::Paint_TabBarBackground).GetWallpaper());
     257           0 :     UpdateButtonIcons();
     258             : 
     259           0 :     Window::DataChanged(rDataChangedEvent);
     260           0 : }
     261             : 
     262             : 
     263             : 
     264             : 
     265          94 : bool TabBar::Notify (NotifyEvent&)
     266             : {
     267          94 :     return false;
     268             : }
     269             : 
     270             : 
     271             : 
     272             : 
     273          77 : RadioButton* TabBar::CreateTabItem (const DeckDescriptor& rDeckDescriptor)
     274             : {
     275          77 :     RadioButton* pItem = ControlFactory::CreateTabItem(this);
     276          77 :     pItem->SetHelpText(rDeckDescriptor.msHelpText);
     277          77 :     pItem->SetQuickHelpText(rDeckDescriptor.msHelpText);
     278             : 
     279          77 :     return pItem;
     280             : }
     281             : 
     282             : 
     283             : 
     284          77 : Image TabBar::GetItemImage (const DeckDescriptor& rDeckDescriptor) const
     285             : {
     286             :     return Tools::GetImage(
     287             :         rDeckDescriptor.msIconURL,
     288             :         rDeckDescriptor.msHighContrastIconURL,
     289          77 :         mxFrame);
     290             : }
     291             : 
     292             : 
     293             : 
     294             : 
     295             : 
     296           0 : IMPL_LINK(TabBar::Item, HandleClick, Button*, EMPTYARG)
     297             : {
     298             :     try
     299             :     {
     300           0 :         maDeckActivationFunctor(msDeckId);
     301             :     }
     302           0 :     catch( const ::com::sun::star::uno::Exception&) {} // workaround for #i123198#
     303             : 
     304           0 :     return 1;
     305             : }
     306             : 
     307             : 
     308             : 
     309             : 
     310           0 : const ::rtl::OUString TabBar::GetDeckIdForIndex (const sal_Int32 nIndex) const
     311             : {
     312           0 :     if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size())
     313           0 :         throw RuntimeException();
     314             :     else
     315           0 :         return maItems[nIndex].msDeckId;
     316             : }
     317             : 
     318             : 
     319             : 
     320             : 
     321           0 : void TabBar::ToggleHideFlag (const sal_Int32 nIndex)
     322             : {
     323           0 :     if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size())
     324           0 :         throw RuntimeException();
     325             :     else
     326             :     {
     327           0 :         maItems[nIndex].mbIsHidden = ! maItems[nIndex].mbIsHidden;
     328           0 :         ResourceManager::Instance().SetIsDeckEnabled(
     329           0 :             maItems[nIndex].msDeckId,
     330           0 :             maItems[nIndex].mbIsHidden);
     331           0 :         Layout();
     332             :     }
     333           0 : }
     334             : 
     335             : 
     336             : 
     337             : 
     338           0 : void TabBar::RestoreHideFlags (void)
     339             : {
     340           0 :     bool bNeedsLayout (false);
     341           0 :     for(ItemContainer::iterator iItem(maItems.begin()),iEnd(maItems.end());
     342             :         iItem!=iEnd;
     343             :         ++iItem)
     344             :     {
     345           0 :         if (iItem->mbIsHidden != iItem->mbIsHiddenByDefault)
     346             :         {
     347           0 :             iItem->mbIsHidden = iItem->mbIsHiddenByDefault;
     348           0 :             bNeedsLayout = true;
     349             :         }
     350             :     }
     351           0 :     if (bNeedsLayout)
     352           0 :         Layout();
     353           0 : }
     354             : 
     355             : 
     356             : 
     357             : 
     358          11 : void TabBar::UpdateFocusManager (FocusManager& rFocusManager)
     359             : {
     360          11 :     ::std::vector<Button*> aButtons;
     361          11 :     aButtons.reserve(maItems.size()+1);
     362             : 
     363          11 :     aButtons.push_back(mpMenuButton.get());
     364          88 :     for(ItemContainer::const_iterator
     365          11 :             iItem(maItems.begin()), iEnd(maItems.end());
     366             :         iItem!=iEnd;
     367             :         ++iItem)
     368             :     {
     369          77 :         aButtons.push_back(iItem->mpButton.get());
     370             :     }
     371          11 :     rFocusManager.SetButtons(aButtons);
     372          11 : }
     373             : 
     374             : 
     375             : 
     376             : 
     377           0 : IMPL_LINK(TabBar, OnToolboxClicked, void*, EMPTYARG)
     378             : {
     379           0 :     if ( ! mpMenuButton)
     380           0 :         return 0;
     381             : 
     382           0 :     ::std::vector<DeckMenuData> aMenuData;
     383             : 
     384           0 :     for(ItemContainer::const_iterator iItem(maItems.begin()),iEnd(maItems.end());
     385             :         iItem!=iEnd;
     386             :         ++iItem)
     387             :     {
     388           0 :         const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(iItem->msDeckId);
     389           0 :         if (pDeckDescriptor != NULL)
     390             :         {
     391           0 :             DeckMenuData aData;
     392           0 :             aData.msDisplayName = pDeckDescriptor->msTitle;
     393           0 :             aData.msDeckId = pDeckDescriptor->msId;
     394           0 :             aData.mbIsCurrentDeck = iItem->mpButton->IsChecked();
     395           0 :             aData.mbIsActive = !iItem->mbIsHidden;
     396           0 :             aData.mbIsEnabled = iItem->mpButton->IsEnabled();
     397             : 
     398           0 :             aMenuData.push_back(aData);
     399             :         }
     400             :     }
     401             : 
     402             :     maPopupMenuProvider(
     403             :         Rectangle(
     404           0 :             mpMenuButton->GetPosPixel(),
     405           0 :             mpMenuButton->GetSizePixel()),
     406           0 :         aMenuData);
     407           0 :     mpMenuButton->Check(false);
     408             : 
     409           0 :     return 0;
     410             : }
     411             : 
     412             : 
     413             : 
     414             : } } // end of namespace sfx2::sidebar
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10