LibreOffice Module svx (master)  1
tbxdrctl.cxx
Go to the documentation of this file.
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 
21 #include <svl/eitem.hxx>
22 #include <vcl/toolbox.hxx>
23 
24 #include <svx/tbxctl.hxx>
25 
26 #include <com/sun/star/frame/XLayoutManager.hpp>
27 
29 
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::frame;
32 
33 
34 SvxTbxCtlDraw::SvxTbxCtlDraw( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx ) :
35  SfxToolBoxControl( nSlotId, nId, rTbx )
36 {
37  rTbx.SetItemBits( nId, ToolBoxItemBits::CHECKABLE | rTbx.GetItemBits( nId ) );
38  rTbx.Invalidate();
39 }
40 
41 void SAL_CALL SvxTbxCtlDraw::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
42 {
44  /*
45  * Toolbar name is defined as "private:resource/toolbar/drawbar" in writer and calc,
46  * "private:resource/toolbar/toolbar" in draw and impress. Control is added for this
47  * difference.
48  */
49  if( m_aCommandURL==".uno:TrackChangesBar")
50  m_sToolboxName="private:resource/toolbar/changes";
51  else if ( m_sModuleName == "com.sun.star.presentation.PresentationDocument" || m_sModuleName == "com.sun.star.drawing.DrawingDocument" )
52  m_sToolboxName="private:resource/toolbar/toolbar";
53  else
54  m_sToolboxName="private:resource/toolbar/drawbar";
55 }
56 
57 
58 void SvxTbxCtlDraw::StateChanged( sal_uInt16 nSID, SfxItemState eState,
59  const SfxPoolItem* pState )
60 {
61  GetToolBox().EnableItem( GetId(), ( eState != SfxItemState::DISABLED ) );
62  SfxToolBoxControl::StateChanged( nSID, eState, pState );
63 
64  Reference< XLayoutManager > xLayoutMgr = getLayoutManager();
65  if ( xLayoutMgr.is() )
67  GetId(), xLayoutMgr->isElementVisible( m_sToolboxName ) );
68 }
69 
70 
72 {
73  Reference< XLayoutManager > xLayoutMgr = getLayoutManager();
74  if ( xLayoutMgr.is() )
75  {
76  bool bCheck = false;
77  if ( xLayoutMgr->isElementVisible( m_sToolboxName ) )
78  {
79  xLayoutMgr->hideElement( m_sToolboxName );
80  xLayoutMgr->destroyElement( m_sToolboxName );
81  }
82  else
83  {
84  bCheck = true;
85  xLayoutMgr->createElement( m_sToolboxName );
86  xLayoutMgr->showElement( m_sToolboxName );
87  }
88 
89  GetToolBox().CheckItem( GetId(), bCheck );
90  }
91 }
92 
93 
94 void SvxTbxCtlDraw::Select(sal_uInt16 /*nSelectModifier*/)
95 {
96  toggleToolbox();
97 }
98 
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SFX_IMPL_TOOLBOX_CONTROL(SvxTbxCtlDraw, SfxBoolItem)
ToolBox & GetToolBox() const
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
virtual void Select(sal_uInt16 nSelectModifier) override
Definition: tbxdrctl.cxx:94
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
Definition: tbxdrctl.cxx:41
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
OUString m_sToolboxName
Definition: tbxctl.hxx:34
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState)
void toggleToolbox()
Definition: tbxdrctl.cxx:71
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
void CheckItem(sal_uInt16 nItemId, bool bCheck=true)
virtual void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: tbxdrctl.cxx:58
SfxItemState
unsigned short GetId() const
SvxTbxCtlDraw(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx)
Definition: tbxdrctl.cxx:34