xref: /aoo41x/main/svx/source/form/formtoolbars.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir #include "formtoolbars.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir /** === begin UNO includes === **/
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
30cdf0e10cSrcweir /** === end UNO includes === **/
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #ifndef _SVX_SVXIDS_HRC
33cdf0e10cSrcweir #include <svx/svxids.hrc>
34cdf0e10cSrcweir #endif
35cdf0e10cSrcweir 
36cdf0e10cSrcweir //........................................................................
37cdf0e10cSrcweir namespace svxform
38cdf0e10cSrcweir {
39cdf0e10cSrcweir //........................................................................
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir 	using namespace ::com::sun::star::frame;
43cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
44cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     //====================================================================
47cdf0e10cSrcweir 	//= FormToolboxes
48cdf0e10cSrcweir 	//====================================================================
49cdf0e10cSrcweir 	//--------------------------------------------------------------------
FormToolboxes(const Reference<XFrame> & _rxFrame)50cdf0e10cSrcweir     FormToolboxes::FormToolboxes( const Reference< XFrame >& _rxFrame )
51cdf0e10cSrcweir     {
52cdf0e10cSrcweir         // the layout manager
53cdf0e10cSrcweir         Reference< XPropertySet > xFrameProps( _rxFrame, UNO_QUERY );
54cdf0e10cSrcweir         if ( xFrameProps.is() )
55cdf0e10cSrcweir             xFrameProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ) ) ) >>= m_xLayouter;
56cdf0e10cSrcweir     }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	//--------------------------------------------------------------------
toggleToolbox(sal_uInt16 _nSlotId) const59cdf0e10cSrcweir     void FormToolboxes::toggleToolbox( sal_uInt16 _nSlotId ) const
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         try
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             Reference< XLayoutManager > xManager( m_xLayouter );
64cdf0e10cSrcweir             OSL_ENSURE( xManager. is(), "FormToolboxes::toggleToolbox: couldn't obtain the layout manager!" );
65cdf0e10cSrcweir             if ( xManager. is() )
66cdf0e10cSrcweir             {
67cdf0e10cSrcweir                 ::rtl::OUString sToolboxResource( getToolboxResourceName( _nSlotId ) );
68cdf0e10cSrcweir                 if ( xManager->isElementVisible( sToolboxResource ) )
69cdf0e10cSrcweir                 {
70cdf0e10cSrcweir                     xManager->hideElement( sToolboxResource );
71cdf0e10cSrcweir                     xManager->destroyElement( sToolboxResource );
72cdf0e10cSrcweir                 }
73cdf0e10cSrcweir                 else
74cdf0e10cSrcweir                 {
75cdf0e10cSrcweir                     xManager->createElement( sToolboxResource );
76cdf0e10cSrcweir                     xManager->showElement( sToolboxResource );
77cdf0e10cSrcweir                 }
78cdf0e10cSrcweir             }
79cdf0e10cSrcweir         }
80cdf0e10cSrcweir         catch( const Exception& )
81cdf0e10cSrcweir         {
82cdf0e10cSrcweir     	    OSL_ENSURE( sal_False, "FormToolboxes::toggleToolbox: caught an exception!" );
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	//--------------------------------------------------------------------
isToolboxVisible(sal_uInt16 _nSlotId) const87cdf0e10cSrcweir     bool FormToolboxes::isToolboxVisible( sal_uInt16 _nSlotId ) const
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         return m_xLayouter.is() && m_xLayouter->isElementVisible(
90cdf0e10cSrcweir             getToolboxResourceName( _nSlotId ) );
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	//--------------------------------------------------------------------
getToolboxResourceName(sal_uInt16 _nSlotId) const94cdf0e10cSrcweir     ::rtl::OUString FormToolboxes::getToolboxResourceName( sal_uInt16 _nSlotId ) const
95cdf0e10cSrcweir     {
96cdf0e10cSrcweir         OSL_ENSURE( ( _nSlotId == SID_FM_MORE_CONTROLS ) || ( _nSlotId == SID_FM_FORM_DESIGN_TOOLS ) || ( _nSlotId == SID_FM_CONFIG ),
97cdf0e10cSrcweir             "FormToolboxes::getToolboxResourceName: unsupported slot!" );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         const sal_Char* pToolBarName = "formcontrols";
100cdf0e10cSrcweir         if ( _nSlotId == SID_FM_MORE_CONTROLS )
101cdf0e10cSrcweir             pToolBarName = "moreformcontrols";
102cdf0e10cSrcweir         else if ( _nSlotId == SID_FM_FORM_DESIGN_TOOLS )
103cdf0e10cSrcweir             pToolBarName = "formdesign";
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         ::rtl::OUString aToolBarResStr( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/" ));
106cdf0e10cSrcweir         aToolBarResStr += ::rtl::OUString::createFromAscii( pToolBarName );
107cdf0e10cSrcweir         return aToolBarResStr;
108cdf0e10cSrcweir     }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //........................................................................
111cdf0e10cSrcweir } // namespace svxform
112cdf0e10cSrcweir //........................................................................
113cdf0e10cSrcweir 
114