1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #include "svx/tbxcolor.hxx" 28 #include <sfx2/viewfrm.hxx> 29 #include <com/sun/star/beans/XPropertySet.hpp> 30 31 //........................................................................ 32 namespace svx 33 { 34 //........................................................................ 35 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::frame; 38 using namespace ::com::sun::star::beans; 39 using namespace ::com::sun::star::frame; 40 41 #define DECLARE_ASCII(s) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) ) 42 #define TOOLBAR_RESNAME DECLARE_ASCII("private:resource/toolbar/") 43 #define PROPNAME_LAYOUTMANAGER DECLARE_ASCII("LayoutManager") 44 45 //==================================================================== 46 //= ToolboxAccess 47 //==================================================================== ToolboxAccess(const::rtl::OUString & rToolboxName)48 ToolboxAccess::ToolboxAccess( const ::rtl::OUString& rToolboxName ) : 49 50 m_bDocking ( false ), 51 m_sToolboxResName ( TOOLBAR_RESNAME ) 52 53 { 54 m_sToolboxResName += rToolboxName; 55 56 // the layout manager 57 if ( SfxViewFrame::Current() ) 58 { 59 try 60 { 61 Reference< XFrame > xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface(); 62 Reference< XPropertySet > xFrameProps( xFrame, UNO_QUERY ); 63 if ( xFrameProps.is() ) 64 xFrameProps->getPropertyValue( PROPNAME_LAYOUTMANAGER ) >>= m_xLayouter; 65 } 66 catch ( Exception& ) 67 { 68 DBG_ERRORFILE( "ToolboxAccess::Ctor(): exception" ); 69 } 70 } 71 } 72 73 //-------------------------------------------------------------------- toggleToolbox() const74 void ToolboxAccess::toggleToolbox() const 75 { 76 try 77 { 78 Reference< XLayoutManager > xManager( m_xLayouter ); 79 OSL_ENSURE( xManager. is(), "ToolboxAccess::toggleToolbox: couldn't obtain the layout manager!" ); 80 if ( xManager. is() ) 81 { 82 if ( xManager->isElementVisible( m_sToolboxResName ) ) 83 { 84 xManager->hideElement( m_sToolboxResName ); 85 xManager->destroyElement( m_sToolboxResName ); 86 } 87 else 88 { 89 xManager->createElement( m_sToolboxResName ); 90 xManager->showElement( m_sToolboxResName ); 91 ::com::sun::star::awt::Point aPos; 92 93 if ( m_bDocking ) 94 xManager->dockWindow( m_sToolboxResName, 95 ::com::sun::star::ui::DockingArea_DOCKINGAREA_BOTTOM, aPos ); 96 } 97 } 98 } 99 catch( const Exception& ) 100 { 101 OSL_ENSURE( sal_False, "ToolboxAccess::toggleToolbox: caught an exception!" ); 102 } 103 } 104 105 //-------------------------------------------------------------------- isToolboxVisible() const106 bool ToolboxAccess::isToolboxVisible() const 107 { 108 return ( m_xLayouter.is() && m_xLayouter->isElementVisible( m_sToolboxResName ) ); 109 } 110 111 //........................................................................ 112 } // namespace svx 113 //........................................................................ 114 115