LibreOffice Module svx (master)  1
tbxcolor.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 <svx/tbxcolor.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <osl/diagnose.h>
25 #include <tools/diagnose_ex.h>
26 
27 
28 namespace svx
29 {
30 
31 
32  using namespace ::com::sun::star::uno;
33  using namespace ::com::sun::star::frame;
34  using namespace ::com::sun::star::beans;
35 
36  ToolboxAccess::ToolboxAccess( const OUString& rToolboxName ) :
37  m_sToolboxResName ( "private:resource/toolbar/" )
38  {
39  m_sToolboxResName += rToolboxName;
40 
41  // the layout manager
42  if ( SfxViewFrame::Current() )
43  {
44  try
45  {
46  Reference< XFrame > xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
47  Reference< XPropertySet > xFrameProps( xFrame, UNO_QUERY );
48  if ( xFrameProps.is() )
49  xFrameProps->getPropertyValue( "LayoutManager" ) >>= m_xLayouter;
50  }
51  catch ( Exception const & )
52  {
53  TOOLS_WARN_EXCEPTION( "svx.tbxcrtls", "ToolboxAccess::Ctor()" );
54  }
55  }
56  }
57 
58 
60  {
61  try
62  {
63  Reference< XLayoutManager > xManager( m_xLayouter );
64  OSL_ENSURE( xManager. is(), "ToolboxAccess::toggleToolbox: couldn't obtain the layout manager!" );
65  if ( xManager. is() )
66  {
67  if ( xManager->isElementVisible( m_sToolboxResName ) )
68  {
69  xManager->hideElement( m_sToolboxResName );
70  xManager->destroyElement( m_sToolboxResName );
71  }
72  else
73  {
74  xManager->createElement( m_sToolboxResName );
75  xManager->showElement( m_sToolboxResName );
76  }
77  }
78  }
79  catch( const Exception& )
80  {
81  TOOLS_WARN_EXCEPTION( "svx", "ToolboxAccess::toggleToolbox" );
82  }
83  }
84 
85 
87  {
88  return ( m_xLayouter.is() && m_xLayouter->isElementVisible( m_sToolboxResName ) );
89  }
90 
91 
92 }
93 
94 
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XFrame > xFrame
void toggleToolbox() const
toggles the toolbox
Definition: tbxcolor.cxx:59
bool isToolboxVisible() const
determines whether the toolbox is currently visible
Definition: tbxcolor.cxx:86
SfxFrame & GetFrame() const
css::uno::Reference< css::frame::XLayoutManager > m_xLayouter
Definition: tbxcolor.hxx:37
#define TOOLS_WARN_EXCEPTION(area, stream)
OUString m_sToolboxResName
Definition: tbxcolor.hxx:35
ToolboxAccess(const OUString &rToolboxName)
Definition: tbxcolor.cxx:36
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
static SfxViewFrame * Current()