Line data Source code
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 :
25 : //........................................................................
26 : namespace svx
27 : {
28 : //........................................................................
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::frame;
32 : using namespace ::com::sun::star::beans;
33 : using namespace ::com::sun::star::frame;
34 :
35 : #define DECLARE_ASCII(s) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
36 : #define TOOLBAR_RESNAME DECLARE_ASCII("private:resource/toolbar/")
37 : #define PROPNAME_LAYOUTMANAGER DECLARE_ASCII("LayoutManager")
38 :
39 : //====================================================================
40 : //= ToolboxAccess
41 : //====================================================================
42 0 : ToolboxAccess::ToolboxAccess( const ::rtl::OUString& rToolboxName ) :
43 :
44 : m_bDocking ( false ),
45 0 : m_sToolboxResName ( TOOLBAR_RESNAME )
46 :
47 : {
48 0 : m_sToolboxResName += rToolboxName;
49 :
50 : // the layout manager
51 0 : if ( SfxViewFrame::Current() )
52 : {
53 : try
54 : {
55 0 : Reference< XFrame > xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
56 0 : Reference< XPropertySet > xFrameProps( xFrame, UNO_QUERY );
57 0 : if ( xFrameProps.is() )
58 0 : xFrameProps->getPropertyValue( PROPNAME_LAYOUTMANAGER ) >>= m_xLayouter;
59 : }
60 0 : catch ( Exception& )
61 : {
62 : SAL_WARN( "svx.tbxcrtls", "ToolboxAccess::Ctor(): exception" );
63 : }
64 : }
65 0 : }
66 :
67 : //--------------------------------------------------------------------
68 0 : void ToolboxAccess::toggleToolbox() const
69 : {
70 : try
71 : {
72 0 : Reference< XLayoutManager > xManager( m_xLayouter );
73 : OSL_ENSURE( xManager. is(), "ToolboxAccess::toggleToolbox: couldn't obtain the layout manager!" );
74 0 : if ( xManager. is() )
75 : {
76 0 : if ( xManager->isElementVisible( m_sToolboxResName ) )
77 : {
78 0 : xManager->hideElement( m_sToolboxResName );
79 0 : xManager->destroyElement( m_sToolboxResName );
80 : }
81 : else
82 : {
83 0 : xManager->createElement( m_sToolboxResName );
84 0 : xManager->showElement( m_sToolboxResName );
85 0 : ::com::sun::star::awt::Point aPos;
86 :
87 0 : if ( m_bDocking )
88 0 : xManager->dockWindow( m_sToolboxResName,
89 0 : ::com::sun::star::ui::DockingArea_DOCKINGAREA_BOTTOM, aPos );
90 : }
91 0 : }
92 : }
93 0 : catch( const Exception& )
94 : {
95 : OSL_FAIL( "ToolboxAccess::toggleToolbox: caught an exception!" );
96 : }
97 0 : }
98 :
99 : //--------------------------------------------------------------------
100 0 : bool ToolboxAccess::isToolboxVisible() const
101 : {
102 0 : return ( m_xLayouter.is() && m_xLayouter->isElementVisible( m_sToolboxResName ) );
103 : }
104 :
105 : //........................................................................
106 : } // namespace svx
107 : //........................................................................
108 :
109 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|