1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svx/tbxcolor.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <osl/diagnose.h>
25 #include <comphelper/diagnose_ex.hxx>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::frame
;
34 using namespace ::com::sun::star::beans
;
36 ToolboxAccess::ToolboxAccess( std::u16string_view rToolboxName
) :
37 m_sToolboxResName ( "private:resource/toolbar/" )
39 m_sToolboxResName
+= rToolboxName
;
42 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
48 Reference
< XFrame
> xFrame
= pViewFrm
->GetFrame().GetFrameInterface();
49 Reference
< XPropertySet
> xFrameProps( xFrame
, UNO_QUERY
);
50 if ( xFrameProps
.is() )
51 xFrameProps
->getPropertyValue( "LayoutManager" ) >>= m_xLayouter
;
53 catch ( Exception
const & )
55 TOOLS_WARN_EXCEPTION( "svx.tbxcrtls", "ToolboxAccess::Ctor()" );
60 void ToolboxAccess::toggleToolbox() const
64 Reference
< XLayoutManager
> xManager( m_xLayouter
);
65 OSL_ENSURE( xManager
. is(), "ToolboxAccess::toggleToolbox: couldn't obtain the layout manager!" );
68 if ( xManager
->isElementVisible( m_sToolboxResName
) )
70 xManager
->hideElement( m_sToolboxResName
);
71 xManager
->destroyElement( m_sToolboxResName
);
75 xManager
->createElement( m_sToolboxResName
);
76 xManager
->showElement( m_sToolboxResName
);
80 catch( const Exception
& )
82 TOOLS_WARN_EXCEPTION( "svx", "ToolboxAccess::toggleToolbox" );
87 bool ToolboxAccess::isToolboxVisible() const
89 return ( m_xLayouter
.is() && m_xLayouter
->isElementVisible( m_sToolboxResName
) );
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */