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