LCOV - code coverage report
Current view: top level - sd/source/ui/view - ViewTabBar.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 147 239 61.5 %
Date: 2012-08-25 Functions: 22 36 61.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 158 452 35.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "ViewTabBar.hxx"
      31                 :            : 
      32                 :            : #define USE_TAB_CONTROL
      33                 :            : 
      34                 :            : #include "ViewShell.hxx"
      35                 :            : #include "ViewShellBase.hxx"
      36                 :            : #include "DrawViewShell.hxx"
      37                 :            : #include "FrameView.hxx"
      38                 :            : #include "EventMultiplexer.hxx"
      39                 :            : #include "framework/FrameworkHelper.hxx"
      40                 :            : #include "framework/Pane.hxx"
      41                 :            : #include "DrawController.hxx"
      42                 :            : 
      43                 :            : #include "sdresid.hxx"
      44                 :            : #include "strings.hrc"
      45                 :            : #include "helpids.h"
      46                 :            : #include "Client.hxx"
      47                 :            : #include <vcl/svapp.hxx>
      48                 :            : #include <vcl/tabpage.hxx>
      49                 :            : #include <osl/mutex.hxx>
      50                 :            : #include <sfx2/viewfrm.hxx>
      51                 :            : #include <com/sun/star/drawing/framework/ResourceId.hpp>
      52                 :            : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      53                 :            : #include <com/sun/star/lang/XUnoTunnel.hpp>
      54                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      55                 :            : #include <comphelper/processfactory.hxx>
      56                 :            : #include <comphelper/servicehelper.hxx>
      57                 :            : #include <tools/diagnose_ex.h>
      58                 :            : 
      59                 :            : using namespace ::com::sun::star;
      60                 :            : using namespace ::com::sun::star::uno;
      61                 :            : using namespace ::com::sun::star::drawing::framework;
      62                 :            : using ::sd::framework::FrameworkHelper;
      63                 :            : using ::sd::tools::EventMultiplexerEvent;
      64                 :            : using ::rtl::OUString;
      65                 :            : 
      66                 :            : namespace sd {
      67                 :            : 
      68                 :            : namespace {
      69                 :        520 : bool IsEqual (const TabBarButton& rButton1, const TabBarButton& rButton2)
      70                 :            : {
      71                 :            :     return (
      72                 :        520 :         (rButton1.ResourceId.is()
      73                 :        520 :             && rButton2.ResourceId.is()
      74                 :        520 :             && rButton1.ResourceId->compareTo(rButton2.ResourceId)==0)
      75 [ -  + ][ +  -  :       1560 :         || rButton1.ButtonLabel == rButton2.ButtonLabel);
             +  -  +  + ]
      76                 :            : }
      77                 :            : 
      78         [ -  + ]:         52 : class TabBarControl : public ::TabControl
      79                 :            : {
      80                 :            : public:
      81                 :            :     TabBarControl (
      82                 :            :         ::Window* pParentWindow,
      83                 :            :         const ::rtl::Reference<ViewTabBar>& rpViewTabBar);
      84                 :            :     virtual void Paint (const Rectangle& rRect);
      85                 :            :     virtual void ActivatePage (void);
      86                 :            : private:
      87                 :            :     ::rtl::Reference<ViewTabBar> mpViewTabBar;
      88                 :            : };
      89                 :            : 
      90                 :            : } // end of anonymous namespace
      91                 :            : 
      92                 :            : 
      93                 :            : 
      94                 :            : 
      95                 :            : 
      96         [ #  # ]:          0 : class ViewTabPage : public TabPage
      97                 :            : {
      98                 :            : public:
      99                 :            :     ViewTabPage (Window* pParent) : TabPage(pParent) {}
     100                 :          0 :     virtual void Resize (void)
     101         [ #  # ]:          0 :     { SetPosSizePixel(Point(0,0),GetParent()->GetOutputSizePixel()); }
     102                 :            : };
     103                 :            : 
     104                 :            : 
     105                 :            : 
     106                 :            : 
     107                 :            : //===== ViewTabBar ============================================================
     108                 :            : 
     109                 :         26 : ViewTabBar::ViewTabBar (
     110                 :            :     const Reference<XResourceId>& rxViewTabBarId,
     111                 :            :     const Reference<frame::XController>& rxController)
     112                 :            :     : ViewTabBarInterfaceBase(maMutex),
     113         [ +  - ]:         26 :       mpTabControl(new TabBarControl(GetAnchorWindow(rxViewTabBarId,rxController), this)),
     114                 :            :       mxController(rxController),
     115                 :            :       maTabBarButtons(),
     116                 :            :       mpTabPage(NULL),
     117                 :            :       mxViewTabBarId(rxViewTabBarId),
     118 [ +  - ][ +  - ]:         52 :       mpViewShellBase(NULL)
         [ +  - ][ +  - ]
     119                 :            : {
     120                 :            :     // Set one new tab page for all tab entries.  We need it only to
     121                 :            :     // determine the height of the tab bar.
     122 [ +  - ][ +  - ]:         26 :     mpTabPage.reset(new TabPage (mpTabControl.get()));
                 [ +  - ]
     123         [ +  - ]:         26 :     mpTabPage->Hide();
     124                 :            : 
     125                 :            :     // add some space before the tabitems
     126         [ +  - ]:         26 :     mpTabControl->SetItemsOffset(Point(5, 3));
     127                 :            : 
     128                 :            :     // Tunnel through the controller and use the ViewShellBase to obtain the
     129                 :            :     // view frame.
     130                 :            :     try
     131                 :            :     {
     132         [ +  - ]:         26 :         Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
     133                 :            :         DrawController* pController = reinterpret_cast<DrawController*>(
     134 [ +  - ][ +  - ]:         26 :             xTunnel->getSomething(DrawController::getUnoTunnelId()));
                 [ +  - ]
     135 [ +  - ][ #  # ]:         26 :         mpViewShellBase = pController->GetViewShellBase();
     136                 :            :     }
     137         [ #  # ]:          0 :     catch (const RuntimeException&)
     138                 :            :     {
     139                 :            :     }
     140                 :            : 
     141                 :            :     // Register as listener at XConfigurationController.
     142         [ +  - ]:         26 :     Reference<XControllerManager> xControllerManager (mxController, UNO_QUERY);
     143         [ +  - ]:         26 :     if (xControllerManager.is())
     144                 :            :     {
     145 [ +  - ][ +  - ]:         26 :         mxConfigurationController = xControllerManager->getConfigurationController();
                 [ +  - ]
     146         [ +  - ]:         26 :         if (mxConfigurationController.is())
     147                 :            :         {
     148         [ +  - ]:         26 :             mxConfigurationController->addConfigurationChangeListener(
     149                 :            :                 this,
     150                 :            :                     FrameworkHelper::msResourceActivationEvent,
     151 [ +  - ][ +  - ]:         26 :                 Any());
     152                 :            :         }
     153                 :            :     }
     154                 :            : 
     155         [ +  - ]:         26 :     mpTabControl->Show();
     156                 :            : 
     157 [ +  - ][ +  - ]:         52 :     if (mpViewShellBase != NULL
                 [ +  - ]
     158         [ +  - ]:         26 :         && rxViewTabBarId->isBoundToURL(
     159         [ +  - ]:         26 :             FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     160                 :            :     {
     161         [ +  - ]:         26 :         mpViewShellBase->SetViewTabBar(this);
     162                 :         26 :     }
     163                 :         26 : }
     164                 :            : 
     165                 :            : 
     166                 :            : 
     167                 :            : 
     168 [ +  - ][ +  - ]:         26 : ViewTabBar::~ViewTabBar (void)
                 [ +  - ]
     169                 :            : {
     170         [ -  + ]:         52 : }
     171                 :            : 
     172                 :            : 
     173                 :            : 
     174                 :            : 
     175                 :         26 : void ViewTabBar::disposing (void)
     176                 :            : {
     177   [ +  -  +  - ]:         52 :     if (mpViewShellBase != NULL
                 [ +  - ]
     178                 :         26 :         && mxViewTabBarId->isBoundToURL(
     179                 :         26 :             FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     180                 :            :     {
     181         [ +  - ]:         26 :         mpViewShellBase->SetViewTabBar(NULL);
     182                 :            :     }
     183                 :            : 
     184         [ +  - ]:         26 :     if (mxConfigurationController.is())
     185                 :            :     {
     186                 :            :         // Unregister listener from XConfigurationController.
     187                 :            :         try
     188                 :            :         {
     189 [ +  - ][ +  - ]:         26 :             mxConfigurationController->removeConfigurationChangeListener(this);
         [ +  - ][ #  # ]
     190                 :            :         }
     191                 :          0 :         catch (const lang::DisposedException&)
     192                 :            :         {
     193                 :            :             // Receiving a disposed exception is the normal case.  Is there
     194                 :            :             // a way to avoid it?
     195                 :            :         }
     196                 :         26 :         mxConfigurationController = NULL;
     197                 :            :     }
     198                 :            : 
     199                 :            :     {
     200         [ +  - ]:         26 :         const SolarMutexGuard aSolarGuard;
     201                 :            :         // Set all references to the one tab page to NULL and delete the page.
     202 [ +  - ][ +  + ]:        156 :         for (sal_uInt16 nIndex=0; nIndex<mpTabControl->GetPageCount(); ++nIndex)
     203         [ +  - ]:        130 :             mpTabControl->SetTabPage(nIndex, NULL);
     204         [ +  - ]:         26 :         mpTabPage.reset();
     205 [ +  - ][ +  - ]:         26 :         mpTabControl.reset();
     206                 :            :     }
     207                 :            : 
     208                 :         26 :     mxController = NULL;
     209                 :         26 : }
     210                 :            : 
     211                 :            : 
     212                 :            : 
     213                 :            : 
     214                 :        571 : ::boost::shared_ptr< ::TabControl> ViewTabBar::GetTabControl (void) const
     215                 :            : {
     216                 :        571 :     return mpTabControl;
     217                 :            : }
     218                 :            : 
     219                 :            : 
     220                 :            : 
     221                 :            : 
     222                 :         26 : ::Window* ViewTabBar::GetAnchorWindow(
     223                 :            :     const Reference<XResourceId>& rxViewTabBarId,
     224                 :            :     const Reference<frame::XController>& rxController)
     225                 :            : {
     226                 :         26 :     ::Window* pWindow = NULL;
     227                 :         26 :     ViewShellBase* pBase = NULL;
     228                 :            : 
     229                 :            :     // Tunnel through the controller and use the ViewShellBase to obtain the
     230                 :            :     // view frame.
     231                 :            :     try
     232                 :            :     {
     233         [ +  - ]:         26 :         Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY_THROW);
     234                 :            :         DrawController* pController = reinterpret_cast<DrawController*>(
     235 [ +  - ][ +  - ]:         26 :             xTunnel->getSomething(DrawController::getUnoTunnelId()));
                 [ +  - ]
     236 [ +  - ][ #  # ]:         26 :         pBase = pController->GetViewShellBase();
     237                 :            :     }
     238                 :          0 :     catch (const RuntimeException&)
     239                 :            :     {
     240                 :            :     }
     241                 :            : 
     242                 :            :     // The ViewTabBar supports at the moment only the center pane.
     243   [ +  -  +  - ]:         52 :     if (rxViewTabBarId.is()
                 [ +  - ]
     244                 :         26 :         && rxViewTabBarId->isBoundToURL(
     245                 :         26 :             FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     246                 :            :     {
     247 [ +  - ][ +  - ]:         26 :         if (pBase != NULL && pBase->GetViewFrame() != NULL)
                 [ +  - ]
     248                 :         26 :             pWindow = &pBase->GetViewFrame()->GetWindow();
     249                 :            :     }
     250                 :            : 
     251                 :            :     // The rest is (at the moment) just for the emergency case.
     252         [ -  + ]:         26 :     if (pWindow == NULL)
     253                 :            :     {
     254                 :          0 :         Reference<XPane> xPane;
     255                 :            :         try
     256                 :            :         {
     257         [ #  # ]:          0 :             Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY_THROW);
     258                 :            :             Reference<XConfigurationController> xCC (
     259 [ #  # ][ #  # ]:          0 :                 xControllerManager->getConfigurationController());
     260         [ #  # ]:          0 :             if (xCC.is())
     261 [ #  # ][ #  # ]:          0 :                 xPane = Reference<XPane>(xCC->getResource(rxViewTabBarId->getAnchor()), UNO_QUERY);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     262                 :            :         }
     263         [ #  # ]:          0 :         catch (const RuntimeException&)
     264                 :            :         {
     265                 :            :         }
     266                 :            : 
     267                 :            :         // Tunnel through the XWindow to the VCL side.
     268                 :            :         try
     269                 :            :         {
     270         [ #  # ]:          0 :             Reference<lang::XUnoTunnel> xTunnel (xPane, UNO_QUERY_THROW);
     271                 :            :             framework::Pane* pPane = reinterpret_cast<framework::Pane*>(
     272 [ #  # ][ #  # ]:          0 :                 xTunnel->getSomething(framework::Pane::getUnoTunnelId()));
                 [ #  # ]
     273         [ #  # ]:          0 :             if (pPane != NULL)
     274 [ #  # ][ #  # ]:          0 :                 pWindow = pPane->GetWindow()->GetParent();
                 [ #  # ]
     275                 :            :         }
     276         [ #  # ]:          0 :         catch (const RuntimeException&)
     277                 :            :         {
     278                 :          0 :         }
     279                 :            :     }
     280                 :            : 
     281                 :         26 :     return pWindow;
     282                 :            : }
     283                 :            : 
     284                 :            : 
     285                 :            : 
     286                 :            : 
     287                 :            : //----- XConfigurationChangeListener ------------------------------------------
     288                 :            : 
     289                 :        152 : void SAL_CALL  ViewTabBar::notifyConfigurationChange (
     290                 :            :     const ConfigurationChangeEvent& rEvent)
     291                 :            :     throw (RuntimeException)
     292                 :            : {
     293   [ +  -  +  + ]:        508 :     if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent)
         [ -  + ][ -  + ]
     294 [ +  - ][ +  - ]:        304 :         && rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix)
         [ +  - ][ #  # ]
     295 [ +  - ][ +  - ]:        204 :         && rEvent.ResourceId->isBoundTo(mxViewTabBarId->getAnchor(), AnchorBindingMode_DIRECT))
         [ +  - ][ +  - ]
         [ +  + ][ #  # ]
     296                 :            :     {
     297                 :          0 :         UpdateActiveButton();
     298                 :            :     }
     299                 :        152 : }
     300                 :            : 
     301                 :            : 
     302                 :            : 
     303                 :            : 
     304                 :            : //----- XEventListener --------------------------------------------------------
     305                 :            : 
     306                 :          0 : void SAL_CALL ViewTabBar::disposing(
     307                 :            :     const lang::EventObject& rEvent)
     308                 :            :     throw (RuntimeException)
     309                 :            : {
     310         [ #  # ]:          0 :     if (rEvent.Source == mxConfigurationController)
     311                 :            :     {
     312                 :          0 :         mxConfigurationController = NULL;
     313                 :          0 :         mxController = NULL;
     314                 :            :     }
     315                 :          0 : }
     316                 :            : 
     317                 :            : 
     318                 :            : 
     319                 :            : 
     320                 :            : //----- XTabBar ---------------------------------------------------------------
     321                 :            : 
     322                 :        130 : void SAL_CALL ViewTabBar::addTabBarButtonAfter (
     323                 :            :     const TabBarButton& rButton,
     324                 :            :     const TabBarButton& rAnchor)
     325                 :            :     throw (::com::sun::star::uno::RuntimeException)
     326                 :            : {
     327         [ +  - ]:        130 :     const SolarMutexGuard aSolarGuard;
     328 [ +  - ][ +  - ]:        130 :     AddTabBarButton(rButton, rAnchor);
     329                 :        130 : }
     330                 :            : 
     331                 :            : 
     332                 :            : 
     333                 :            : 
     334                 :          0 : void SAL_CALL ViewTabBar::appendTabBarButton (const TabBarButton& rButton)
     335                 :            :     throw (::com::sun::star::uno::RuntimeException)
     336                 :            : {
     337         [ #  # ]:          0 :     const SolarMutexGuard aSolarGuard;
     338 [ #  # ][ #  # ]:          0 :     AddTabBarButton(rButton);
     339                 :          0 : }
     340                 :            : 
     341                 :            : 
     342                 :            : 
     343                 :          0 : void SAL_CALL ViewTabBar::removeTabBarButton (const TabBarButton& rButton)
     344                 :            :     throw (::com::sun::star::uno::RuntimeException)
     345                 :            : {
     346         [ #  # ]:          0 :     const SolarMutexGuard aSolarGuard;
     347 [ #  # ][ #  # ]:          0 :     RemoveTabBarButton(rButton);
     348                 :          0 : }
     349                 :            : 
     350                 :            : 
     351                 :            : 
     352                 :            : 
     353                 :        130 : sal_Bool SAL_CALL ViewTabBar::hasTabBarButton (const TabBarButton& rButton)
     354                 :            :     throw (::com::sun::star::uno::RuntimeException)
     355                 :            : {
     356         [ +  - ]:        130 :     const SolarMutexGuard aSolarGuard;
     357 [ +  - ][ +  - ]:        130 :     return HasTabBarButton(rButton);
     358                 :            : }
     359                 :            : 
     360                 :            : 
     361                 :            : 
     362                 :            : 
     363                 :          0 : Sequence<TabBarButton> SAL_CALL ViewTabBar::getTabBarButtons (void)
     364                 :            :     throw (::com::sun::star::uno::RuntimeException)
     365                 :            : {
     366         [ #  # ]:          0 :     const SolarMutexGuard aSolarGuard;
     367 [ #  # ][ #  # ]:          0 :     return GetTabBarButtons();
     368                 :            : }
     369                 :            : 
     370                 :            : 
     371                 :            : 
     372                 :            : 
     373                 :            : //----- XResource -------------------------------------------------------------
     374                 :            : 
     375                 :         26 : Reference<XResourceId> SAL_CALL ViewTabBar::getResourceId (void)
     376                 :            :     throw (RuntimeException)
     377                 :            : {
     378                 :         26 :     return mxViewTabBarId;
     379                 :            : }
     380                 :            : 
     381                 :            : 
     382                 :            : 
     383                 :            : 
     384                 :        126 : sal_Bool SAL_CALL ViewTabBar::isAnchorOnly (void)
     385                 :            :     throw (RuntimeException)
     386                 :            : {
     387                 :        126 :     return false;
     388                 :            : }
     389                 :            : 
     390                 :            : 
     391                 :            : 
     392                 :            : 
     393                 :            : //----- XUnoTunnel ------------------------------------------------------------
     394                 :            : 
     395                 :            : namespace
     396                 :            : {
     397                 :            :     class theViewTabBarUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theViewTabBarUnoTunnelId > {};
     398                 :            : }
     399                 :            : 
     400                 :          0 : const Sequence<sal_Int8>& ViewTabBar::getUnoTunnelId (void)
     401                 :            : {
     402                 :          0 :     return theViewTabBarUnoTunnelId::get().getSeq();
     403                 :            : }
     404                 :            : 
     405                 :          0 : sal_Int64 SAL_CALL ViewTabBar::getSomething (const Sequence<sal_Int8>& rId)
     406                 :            :     throw (RuntimeException)
     407                 :            : {
     408                 :          0 :     sal_Int64 nResult = 0;
     409                 :            : 
     410   [ #  #  #  # ]:          0 :     if (rId.getLength() == 16
                 [ #  # ]
     411                 :          0 :         && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
     412                 :            :     {
     413                 :          0 :         nResult = reinterpret_cast<sal_Int64>(this);
     414                 :            :     }
     415                 :            : 
     416                 :          0 :     return nResult;
     417                 :            : }
     418                 :            : 
     419                 :            : 
     420                 :            : 
     421                 :            : 
     422                 :            : //-----------------------------------------------------------------------------
     423                 :            : 
     424                 :          0 : bool ViewTabBar::ActivatePage (void)
     425                 :            : {
     426                 :            :     try
     427                 :            :     {
     428         [ #  # ]:          0 :         Reference<XControllerManager> xControllerManager (mxController,UNO_QUERY_THROW);
     429                 :            :         Reference<XConfigurationController> xConfigurationController (
     430 [ #  # ][ #  # ]:          0 :             xControllerManager->getConfigurationController());
     431         [ #  # ]:          0 :         if ( ! xConfigurationController.is())
     432         [ #  # ]:          0 :             throw RuntimeException();
     433                 :          0 :         Reference<XView> xView;
     434                 :            :         try
     435                 :            :         {
     436         [ #  # ]:          0 :             xView = Reference<XView>(xConfigurationController->getResource(
     437                 :            :                 ResourceId::create(
     438                 :            :                     ::comphelper::getProcessComponentContext(),
     439                 :          0 :                     FrameworkHelper::msCenterPaneURL)),
     440 [ #  # ][ #  # ]:          0 :                 UNO_QUERY);
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     441                 :            :         }
     442         [ #  # ]:          0 :         catch (const DeploymentException&)
     443                 :            :         {
     444                 :            :         }
     445                 :            : 
     446                 :          0 :         Client* pIPClient = NULL;
     447         [ #  # ]:          0 :         if (mpViewShellBase != NULL)
     448 [ #  # ][ #  # ]:          0 :             pIPClient = dynamic_cast<Client*>(mpViewShellBase->GetIPClient());
     449 [ #  # ][ #  # ]:          0 :         if (pIPClient==NULL || ! pIPClient->IsObjectInPlaceActive())
         [ #  # ][ #  # ]
     450                 :            :         {
     451         [ #  # ]:          0 :             sal_uInt16 nIndex (mpTabControl->GetCurPageId() - 1);
     452         [ #  # ]:          0 :             if (nIndex < maTabBarButtons.size())
     453                 :            :             {
     454         [ #  # ]:          0 :                 xConfigurationController->requestResourceActivation(
     455                 :          0 :                     maTabBarButtons[nIndex].ResourceId,
     456         [ #  # ]:          0 :                     ResourceActivationMode_REPLACE);
     457                 :            :             }
     458                 :            : 
     459                 :          0 :             return true;
     460                 :            :         }
     461                 :            :         else
     462                 :            :         {
     463                 :            :             // When we run into this else branch then we have an active OLE
     464                 :            :             // object.  We ignore the request to switch views.  Additionally
     465                 :            :             // we put the active tab back to the one for the current view.
     466 [ #  # ][ #  # ]:          0 :             UpdateActiveButton();
     467 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     468                 :            :     }
     469                 :          0 :     catch (const RuntimeException&)
     470                 :            :     {
     471                 :            :         DBG_UNHANDLED_EXCEPTION();
     472                 :            :     }
     473                 :            : 
     474                 :          0 :     return false;
     475                 :            : }
     476                 :            : 
     477                 :            : 
     478                 :            : 
     479                 :            : 
     480                 :        244 : int ViewTabBar::GetHeight (void)
     481                 :            : {
     482                 :        244 :     int nHeight (0);
     483                 :            : 
     484         [ +  - ]:        244 :     if (!maTabBarButtons.empty())
     485                 :            :     {
     486                 :            :         TabPage* pActivePage (mpTabControl->GetTabPage(
     487                 :        244 :             mpTabControl->GetCurPageId()));
     488 [ +  + ][ +  + ]:        244 :         if (pActivePage!=NULL && mpTabControl->IsReallyVisible())
                 [ +  - ]
     489                 :        122 :             nHeight = pActivePage->GetPosPixel().Y();
     490                 :            : 
     491         [ +  + ]:        244 :         if (nHeight <= 0)
     492                 :            :             // Using a default when the real height can not be determined.
     493                 :            :             // To get correct height this method should be called when the
     494                 :            :             // control is visible.
     495                 :        122 :             nHeight = 21;
     496                 :            :     }
     497                 :            : 
     498                 :        244 :     return nHeight;
     499                 :            : }
     500                 :            : 
     501                 :            : 
     502                 :            : 
     503                 :            : 
     504                 :        130 : void ViewTabBar::AddTabBarButton (
     505                 :            :     const ::com::sun::star::drawing::framework::TabBarButton& rButton,
     506                 :            :     const ::com::sun::star::drawing::framework::TabBarButton& rAnchor)
     507                 :            : {
     508                 :            :     sal_uInt32 nIndex;
     509                 :            : 
     510   [ +  +  -  +  :        364 :     if ( ! rAnchor.ResourceId.is()
           #  # ][ +  + ]
     511 [ +  - ][ +  - ]:        234 :         || (rAnchor.ResourceId->getResourceURL().isEmpty()
         [ +  + ][ #  # ]
     512                 :          0 :             && rAnchor.ButtonLabel.isEmpty()))
     513                 :            :     {
     514                 :         26 :         nIndex = 0;
     515                 :            :     }
     516                 :            :     else
     517                 :            :     {
     518         [ +  - ]:        260 :         for (nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
     519                 :            :         {
     520         [ +  + ]:        260 :             if (IsEqual(maTabBarButtons[nIndex], rAnchor))
     521                 :            :             {
     522                 :        104 :                 ++nIndex;
     523                 :        104 :                 break;
     524                 :            :             }
     525                 :            :         }
     526                 :            :     }
     527                 :            : 
     528                 :        130 :     AddTabBarButton(rButton,nIndex);
     529                 :        130 : }
     530                 :            : 
     531                 :            : 
     532                 :            : 
     533                 :            : 
     534                 :          0 : void ViewTabBar::AddTabBarButton (
     535                 :            :     const ::com::sun::star::drawing::framework::TabBarButton& rButton)
     536                 :            : {
     537                 :          0 :     AddTabBarButton(rButton, maTabBarButtons.size());
     538                 :          0 : }
     539                 :            : 
     540                 :            : 
     541                 :            : 
     542                 :            : 
     543                 :        130 : void ViewTabBar::AddTabBarButton (
     544                 :            :     const ::com::sun::star::drawing::framework::TabBarButton& rButton,
     545                 :            :     sal_Int32 nPosition)
     546                 :            : {
     547   [ +  -  +  - ]:        260 :     if (nPosition>=0
                 [ +  - ]
     548                 :        130 :         && nPosition<=mpTabControl->GetPageCount())
     549                 :            :     {
     550                 :        130 :         sal_uInt16 nIndex ((sal_uInt16)nPosition);
     551                 :            : 
     552                 :            :         // Insert the button into our local array.
     553 [ +  - ][ +  - ]:        130 :         maTabBarButtons.insert(maTabBarButtons.begin()+nIndex, rButton);
     554                 :        130 :         UpdateTabBarButtons();
     555                 :        130 :         UpdateActiveButton();
     556                 :            :     }
     557                 :        130 : }
     558                 :            : 
     559                 :            : 
     560                 :            : 
     561                 :            : 
     562                 :          0 : void ViewTabBar::RemoveTabBarButton (
     563                 :            :     const ::com::sun::star::drawing::framework::TabBarButton& rButton)
     564                 :            : {
     565                 :            :     sal_uInt16 nIndex;
     566         [ #  # ]:          0 :     for (nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
     567                 :            :     {
     568         [ #  # ]:          0 :         if (IsEqual(maTabBarButtons[nIndex], rButton))
     569                 :            :         {
     570 [ #  # ][ #  # ]:          0 :             maTabBarButtons.erase(maTabBarButtons.begin()+nIndex);
     571                 :          0 :             UpdateTabBarButtons();
     572                 :          0 :             UpdateActiveButton();
     573                 :          0 :             break;
     574                 :            :         }
     575                 :            :     }
     576                 :          0 : }
     577                 :            : 
     578                 :            : 
     579                 :            : 
     580                 :            : 
     581                 :        130 : bool ViewTabBar::HasTabBarButton (
     582                 :            :     const ::com::sun::star::drawing::framework::TabBarButton& rButton)
     583                 :            : {
     584                 :        130 :     bool bResult (false);
     585                 :            : 
     586         [ +  + ]:        390 :     for (sal_uInt32 nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
     587                 :            :     {
     588         [ -  + ]:        260 :         if (IsEqual(maTabBarButtons[nIndex], rButton))
     589                 :            :         {
     590                 :          0 :             bResult = true;
     591                 :          0 :             break;
     592                 :            :         }
     593                 :            :     }
     594                 :            : 
     595                 :        130 :     return bResult;
     596                 :            : }
     597                 :            : 
     598                 :            : 
     599                 :            : 
     600                 :            : 
     601                 :            : ::com::sun::star::uno::Sequence<com::sun::star::drawing::framework::TabBarButton>
     602                 :          0 :     ViewTabBar::GetTabBarButtons (void)
     603                 :            : {
     604                 :          0 :     sal_uInt32 nCount (maTabBarButtons.size());
     605                 :            :     ::com::sun::star::uno::Sequence<com::sun::star::drawing::framework::TabBarButton>
     606                 :          0 :           aList (nCount);
     607                 :            : 
     608         [ #  # ]:          0 :     for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
     609 [ #  # ][ #  # ]:          0 :         aList[nIndex] = maTabBarButtons[nIndex];
     610                 :            : 
     611                 :          0 :     return aList;
     612                 :            : }
     613                 :            : 
     614                 :            : 
     615                 :            : 
     616                 :            : 
     617                 :        130 : void ViewTabBar::UpdateActiveButton (void)
     618                 :            : {
     619                 :        130 :     Reference<XView> xView;
     620         [ +  - ]:        130 :     if (mpViewShellBase != NULL)
     621                 :            :         xView = FrameworkHelper::Instance(*mpViewShellBase)->GetView(
     622 [ +  - ][ +  - ]:        130 :             mxViewTabBarId->getAnchor());
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     623         [ +  - ]:        130 :     if (xView.is())
     624                 :            :     {
     625 [ +  - ][ +  - ]:        130 :         Reference<XResourceId> xViewId (xView->getResourceId());
     626         [ +  - ]:        130 :         for (sal_uInt16 nIndex=0; nIndex<maTabBarButtons.size(); ++nIndex)
     627                 :            :         {
     628 [ +  - ][ +  - ]:        130 :             if (maTabBarButtons[nIndex].ResourceId->compareTo(xViewId) == 0)
                 [ +  - ]
     629                 :            :             {
     630         [ +  - ]:        130 :                 mpTabControl->SetCurPageId(nIndex+1);
     631         [ +  - ]:        130 :                 mpTabControl->::TabControl::ActivatePage();
     632                 :        130 :                 break;
     633                 :            :             }
     634                 :        130 :         }
     635                 :        130 :     }
     636                 :        130 : }
     637                 :            : 
     638                 :            : 
     639                 :            : 
     640                 :            : 
     641                 :        130 : void ViewTabBar::UpdateTabBarButtons (void)
     642                 :            : {
     643                 :        130 :     TabBarButtonList::const_iterator iTab;
     644         [ +  - ]:        130 :     sal_uInt16 nPageCount (mpTabControl->GetPageCount());
     645                 :            :     sal_uInt16 nIndex;
     646 [ +  - ][ +  - ]:        520 :     for (iTab=maTabBarButtons.begin(),nIndex=1; iTab!=maTabBarButtons.end(); ++iTab,++nIndex)
                 [ +  + ]
     647                 :            :     {
     648                 :            :         // Create a new tab when there are not enough.
     649         [ +  + ]:        390 :         if (nPageCount < nIndex)
     650 [ +  - ][ +  - ]:        130 :             mpTabControl->InsertPage(nIndex, iTab->ButtonLabel);
                 [ +  - ]
     651                 :            : 
     652                 :            :         // Update the tab.
     653 [ +  - ][ +  - ]:        390 :         mpTabControl->SetPageText(nIndex, iTab->ButtonLabel);
                 [ +  - ]
     654 [ +  - ][ +  - ]:        390 :         mpTabControl->SetHelpText(nIndex, iTab->HelpText);
                 [ +  - ]
     655         [ +  - ]:        390 :         mpTabControl->SetTabPage(nIndex, mpTabPage.get());
     656                 :            :     }
     657                 :            : 
     658                 :            :     // Delete tabs that are no longer used.
     659         [ -  + ]:        130 :     for (; nIndex<=nPageCount; ++nIndex)
     660         [ #  # ]:          0 :         mpTabControl->RemovePage(nIndex);
     661                 :            : 
     662         [ +  - ]:        130 :     mpTabPage->Hide();
     663                 :        130 : }
     664                 :            : 
     665                 :            : 
     666                 :            : 
     667                 :            : 
     668                 :            : //===== TabBarControl =========================================================
     669                 :            : 
     670                 :         26 : TabBarControl::TabBarControl (
     671                 :            :     ::Window* pParentWindow,
     672                 :            :     const ::rtl::Reference<ViewTabBar>& rpViewTabBar)
     673                 :            :     : ::TabControl(pParentWindow),
     674                 :         26 :       mpViewTabBar(rpViewTabBar)
     675                 :            : {
     676                 :         26 : }
     677                 :            : 
     678                 :            : 
     679                 :            : 
     680                 :            : 
     681                 :         50 : void TabBarControl::Paint (const Rectangle& rRect)
     682                 :            : {
     683                 :         50 :     Color aOriginalFillColor (GetFillColor());
     684                 :         50 :     Color aOriginalLineColor (GetLineColor());
     685                 :            : 
     686                 :            :     // Because the actual window background is transparent--to avoid
     687                 :            :     // flickering due to multiple background paintings by this and by child
     688                 :            :     // windows--we have to paint the background for this control explicitly:
     689                 :            :     // the actual control is not painted over its whole bounding box.
     690         [ +  - ]:         50 :     SetFillColor (GetSettings().GetStyleSettings().GetDialogColor());
     691         [ +  - ]:         50 :     SetLineColor ();
     692         [ +  - ]:         50 :     DrawRect (rRect);
     693         [ +  - ]:         50 :     ::TabControl::Paint (rRect);
     694                 :            : 
     695         [ +  - ]:         50 :     SetFillColor (aOriginalFillColor);
     696         [ +  - ]:         50 :     SetLineColor (aOriginalLineColor);
     697                 :         50 : }
     698                 :            : 
     699                 :            : 
     700                 :            : 
     701                 :            : 
     702                 :          0 : void TabBarControl::ActivatePage (void)
     703                 :            : {
     704         [ #  # ]:          0 :     if (mpViewTabBar->ActivatePage())
     705                 :            :     {
     706                 :            :         // Call the parent so that the correct tab is highlighted.
     707                 :          0 :         this->::TabControl::ActivatePage();
     708                 :            :     }
     709                 :          0 : }
     710                 :            : 
     711                 :            : } // end of namespace sd
     712                 :            : 
     713                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10