xref: /aoo42x/main/svx/source/form/formtoolbars.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include "formtoolbars.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 /** === end UNO includes === **/
35 
36 #ifndef _SVX_SVXIDS_HRC
37 #include <svx/svxids.hrc>
38 #endif
39 
40 //........................................................................
41 namespace svxform
42 {
43 //........................................................................
44 
45     using namespace ::com::sun::star::uno;
46 	using namespace ::com::sun::star::frame;
47     using namespace ::com::sun::star::beans;
48     using namespace ::com::sun::star::frame;
49 
50     //====================================================================
51 	//= FormToolboxes
52 	//====================================================================
53 	//--------------------------------------------------------------------
54     FormToolboxes::FormToolboxes( const Reference< XFrame >& _rxFrame )
55     {
56         // the layout manager
57         Reference< XPropertySet > xFrameProps( _rxFrame, UNO_QUERY );
58         if ( xFrameProps.is() )
59             xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ) >>= m_xLayouter;
60     }
61 
62 	//--------------------------------------------------------------------
63     void FormToolboxes::toggleToolbox( sal_uInt16 _nSlotId ) const
64     {
65         try
66         {
67             Reference< XLayoutManager > xManager( m_xLayouter );
68             OSL_ENSURE( xManager. is(), "FormToolboxes::toggleToolbox: couldn't obtain the layout manager!" );
69             if ( xManager. is() )
70             {
71                 ::rtl::OUString sToolboxResource( getToolboxResourceName( _nSlotId ) );
72                 if ( xManager->isElementVisible( sToolboxResource ) )
73                 {
74                     xManager->hideElement( sToolboxResource );
75                     xManager->destroyElement( sToolboxResource );
76                 }
77                 else
78                 {
79                     xManager->createElement( sToolboxResource );
80                     xManager->showElement( sToolboxResource );
81                 }
82             }
83         }
84         catch( const Exception& )
85         {
86     	    OSL_ENSURE( sal_False, "FormToolboxes::toggleToolbox: caught an exception!" );
87         }
88     }
89 
90 	//--------------------------------------------------------------------
91     bool FormToolboxes::isToolboxVisible( sal_uInt16 _nSlotId ) const
92     {
93         return m_xLayouter.is() && m_xLayouter->isElementVisible(
94             getToolboxResourceName( _nSlotId ) );
95     }
96 
97 	//--------------------------------------------------------------------
98     ::rtl::OUString FormToolboxes::getToolboxResourceName( sal_uInt16 _nSlotId ) const
99     {
100         OSL_ENSURE( ( _nSlotId == SID_FM_MORE_CONTROLS ) || ( _nSlotId == SID_FM_FORM_DESIGN_TOOLS ) || ( _nSlotId == SID_FM_CONFIG ),
101             "FormToolboxes::getToolboxResourceName: unsupported slot!" );
102 
103         const sal_Char* pToolBarName = "formcontrols";
104         if ( _nSlotId == SID_FM_MORE_CONTROLS )
105             pToolBarName = "moreformcontrols";
106         else if ( _nSlotId == SID_FM_FORM_DESIGN_TOOLS )
107             pToolBarName = "formdesign";
108 
109         ::rtl::OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ));
110         aToolBarResStr += ::rtl::OUString::createFromAscii( pToolBarName );
111         return aToolBarResStr;
112     }
113 
114 //........................................................................
115 } // namespace svxform
116 //........................................................................
117 
118