xref: /aoo42x/main/svx/source/form/formtoolbars.cxx (revision f6e50924)
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 #include "formtoolbars.hxx"
27 
28 /** === begin UNO includes === **/
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 /** === end UNO includes === **/
31 
32 #ifndef _SVX_SVXIDS_HRC
33 #include <svx/svxids.hrc>
34 #endif
35 
36 //........................................................................
37 namespace svxform
38 {
39 //........................................................................
40 
41     using namespace ::com::sun::star::uno;
42 	using namespace ::com::sun::star::frame;
43     using namespace ::com::sun::star::beans;
44     using namespace ::com::sun::star::frame;
45 
46     //====================================================================
47 	//= FormToolboxes
48 	//====================================================================
49 	//--------------------------------------------------------------------
FormToolboxes(const Reference<XFrame> & _rxFrame)50     FormToolboxes::FormToolboxes( const Reference< XFrame >& _rxFrame )
51     {
52         // the layout manager
53         Reference< XPropertySet > xFrameProps( _rxFrame, UNO_QUERY );
54         if ( xFrameProps.is() )
55             xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ) >>= m_xLayouter;
56     }
57 
58 	//--------------------------------------------------------------------
toggleToolbox(sal_uInt16 _nSlotId) const59     void FormToolboxes::toggleToolbox( sal_uInt16 _nSlotId ) const
60     {
61         try
62         {
63             Reference< XLayoutManager > xManager( m_xLayouter );
64             OSL_ENSURE( xManager. is(), "FormToolboxes::toggleToolbox: couldn't obtain the layout manager!" );
65             if ( xManager. is() )
66             {
67                 ::rtl::OUString sToolboxResource( getToolboxResourceName( _nSlotId ) );
68                 if ( xManager->isElementVisible( sToolboxResource ) )
69                 {
70                     xManager->hideElement( sToolboxResource );
71                     xManager->destroyElement( sToolboxResource );
72                 }
73                 else
74                 {
75                     xManager->createElement( sToolboxResource );
76                     xManager->showElement( sToolboxResource );
77                 }
78             }
79         }
80         catch( const Exception& )
81         {
82     	    OSL_ENSURE( sal_False, "FormToolboxes::toggleToolbox: caught an exception!" );
83         }
84     }
85 
86 	//--------------------------------------------------------------------
isToolboxVisible(sal_uInt16 _nSlotId) const87     bool FormToolboxes::isToolboxVisible( sal_uInt16 _nSlotId ) const
88     {
89         return m_xLayouter.is() && m_xLayouter->isElementVisible(
90             getToolboxResourceName( _nSlotId ) );
91     }
92 
93 	//--------------------------------------------------------------------
getToolboxResourceName(sal_uInt16 _nSlotId) const94     ::rtl::OUString FormToolboxes::getToolboxResourceName( sal_uInt16 _nSlotId ) const
95     {
96         OSL_ENSURE( ( _nSlotId == SID_FM_MORE_CONTROLS ) || ( _nSlotId == SID_FM_FORM_DESIGN_TOOLS ) || ( _nSlotId == SID_FM_CONFIG ),
97             "FormToolboxes::getToolboxResourceName: unsupported slot!" );
98 
99         const sal_Char* pToolBarName = "formcontrols";
100         if ( _nSlotId == SID_FM_MORE_CONTROLS )
101             pToolBarName = "moreformcontrols";
102         else if ( _nSlotId == SID_FM_FORM_DESIGN_TOOLS )
103             pToolBarName = "formdesign";
104 
105         ::rtl::OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ));
106         aToolBarResStr += ::rtl::OUString::createFromAscii( pToolBarName );
107         return aToolBarResStr;
108     }
109 
110 //........................................................................
111 } // namespace svxform
112 //........................................................................
113 
114