xref: /AOO41X/main/svx/source/tbxctrls/tbxcolor.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
31 #include "svx/tbxcolor.hxx"
32 #include <sfx2/viewfrm.hxx>
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 
35 //........................................................................
36 namespace svx
37 {
38 //........................................................................
39 
40     using namespace ::com::sun::star::uno;
41     using namespace ::com::sun::star::frame;
42     using namespace ::com::sun::star::beans;
43     using namespace ::com::sun::star::frame;
44 
45     #define DECLARE_ASCII(s)        ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
46     #define TOOLBAR_RESNAME         DECLARE_ASCII("private:resource/toolbar/")
47     #define PROPNAME_LAYOUTMANAGER  DECLARE_ASCII("LayoutManager")
48 
49     //====================================================================
50     //= ToolboxAccess
51     //====================================================================
52     ToolboxAccess::ToolboxAccess( const ::rtl::OUString& rToolboxName ) :
53 
54         m_bDocking          ( false ),
55         m_sToolboxResName   ( TOOLBAR_RESNAME )
56 
57     {
58         m_sToolboxResName += rToolboxName;
59 
60         // the layout manager
61         if ( SfxViewFrame::Current() )
62         {
63             try
64             {
65                 Reference< XFrame > xFrame = SfxViewFrame::Current()->GetFrame().GetFrameInterface();
66                 Reference< XPropertySet > xFrameProps( xFrame, UNO_QUERY );
67                 if ( xFrameProps.is() )
68                     xFrameProps->getPropertyValue( PROPNAME_LAYOUTMANAGER ) >>= m_xLayouter;
69             }
70             catch ( Exception& )
71             {
72                 DBG_ERRORFILE( "ToolboxAccess::Ctor(): exception" );
73             }
74         }
75     }
76 
77     //--------------------------------------------------------------------
78     void ToolboxAccess::toggleToolbox() const
79     {
80         try
81         {
82             Reference< XLayoutManager > xManager( m_xLayouter );
83             OSL_ENSURE( xManager. is(), "ToolboxAccess::toggleToolbox: couldn't obtain the layout manager!" );
84             if ( xManager. is() )
85             {
86                 if ( xManager->isElementVisible( m_sToolboxResName ) )
87                 {
88                     xManager->hideElement( m_sToolboxResName );
89                     xManager->destroyElement( m_sToolboxResName );
90                 }
91                 else
92                 {
93                     xManager->createElement( m_sToolboxResName );
94                     xManager->showElement( m_sToolboxResName );
95                     ::com::sun::star::awt::Point aPos;
96 
97                     if ( m_bDocking )
98                         xManager->dockWindow( m_sToolboxResName,
99                             ::com::sun::star::ui::DockingArea_DOCKINGAREA_BOTTOM, aPos );
100                 }
101             }
102         }
103         catch( const Exception& )
104         {
105             OSL_ENSURE( sal_False, "ToolboxAccess::toggleToolbox: caught an exception!" );
106         }
107     }
108 
109     //--------------------------------------------------------------------
110     bool ToolboxAccess::isToolboxVisible() const
111     {
112         return ( m_xLayouter.is() && m_xLayouter->isElementVisible( m_sToolboxResName ) );
113     }
114 
115 //........................................................................
116 } // namespace svx
117 //........................................................................
118 
119