Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <uielement/addonstoolbarwrapper.hxx>
30 : : #include <threadhelp/resetableguard.hxx>
31 : : #include <framework/actiontriggerhelper.hxx>
32 : : #include <uielement/constitemcontainer.hxx>
33 : : #include <uielement/rootitemcontainer.hxx>
34 : : #include <uielement/addonstoolbarmanager.hxx>
35 : :
36 : : #include <uielement/toolbar.hxx>
37 : :
38 : : #include <com/sun/star/lang/XServiceInfo.hpp>
39 : : #include <com/sun/star/lang/DisposedException.hpp>
40 : : #include <com/sun/star/beans/XPropertySet.hpp>
41 : : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
42 : : #include <com/sun/star/awt/XMenuBar.hpp>
43 : : #include <com/sun/star/container/XIndexContainer.hpp>
44 : : #include <com/sun/star/container/XNameAccess.hpp>
45 : : #include <com/sun/star/ui/UIElementType.hpp>
46 : :
47 : : #include <toolkit/unohlp.hxx>
48 : : #include <toolkit/awt/vclxwindow.hxx>
49 : : #include <comphelper/processfactory.hxx>
50 : :
51 : : #include <svtools/miscopt.hxx>
52 : : #include <vcl/svapp.hxx>
53 : : #include <vcl/toolbox.hxx>
54 : : #include <rtl/logfile.hxx>
55 : :
56 : : using namespace com::sun::star::uno;
57 : : using namespace com::sun::star::beans;
58 : : using namespace com::sun::star::frame;
59 : : using namespace com::sun::star::lang;
60 : : using namespace com::sun::star::container;
61 : : using namespace com::sun::star::awt;
62 : : using namespace ::com::sun::star::ui;
63 : :
64 : : namespace framework
65 : : {
66 : :
67 : 0 : AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
68 : : UIElementWrapperBase( UIElementType::TOOLBAR ),
69 [ # # ]: 0 : m_xServiceManager( xServiceManager )
70 : : {
71 : 0 : }
72 : :
73 [ # # ]: 0 : AddonsToolBarWrapper::~AddonsToolBarWrapper()
74 : : {
75 [ # # ]: 0 : }
76 : :
77 : : // XComponent
78 : 0 : void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
79 : : {
80 [ # # ]: 0 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
81 : :
82 [ # # ]: 0 : com::sun::star::lang::EventObject aEvent( xThis );
83 [ # # ]: 0 : m_aListenerContainer.disposeAndClear( aEvent );
84 : :
85 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
86 : :
87 [ # # ]: 0 : if ( m_xToolBarManager.is() )
88 [ # # ][ # # ]: 0 : m_xToolBarManager->dispose();
89 : 0 : m_xToolBarManager.clear();
90 : 0 : m_xToolBarWindow.clear();
91 : :
92 [ # # ][ # # ]: 0 : m_bDisposed = sal_True;
93 : 0 : }
94 : :
95 : : // XInitialization
96 : 0 : void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
97 : : {
98 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
99 : :
100 [ # # ]: 0 : if ( m_bDisposed )
101 [ # # ]: 0 : throw DisposedException();
102 : :
103 [ # # ]: 0 : if ( !m_bInitialized )
104 : : {
105 [ # # ]: 0 : UIElementWrapperBase::initialize( aArguments );
106 : :
107 [ # # ]: 0 : for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
108 : : {
109 : 0 : PropertyValue aPropValue;
110 [ # # ][ # # ]: 0 : if ( aArguments[n] >>= aPropValue )
111 : : {
112 [ # # ]: 0 : if ( aPropValue.Name == "ConfigurationData" )
113 [ # # ]: 0 : aPropValue.Value >>= m_aConfigData;
114 : : }
115 : 0 : }
116 : :
117 [ # # ]: 0 : Reference< XFrame > xFrame( m_xWeakFrame );
118 [ # # ][ # # ]: 0 : if ( xFrame.is() && m_aConfigData.getLength() > 0 )
[ # # ]
119 : : {
120 : : // Create VCL based toolbar which will be filled with settings data
121 : 0 : ToolBar* pToolBar = 0;
122 : 0 : AddonsToolBarManager* pToolBarManager = 0;
123 : : {
124 [ # # ]: 0 : SolarMutexGuard aSolarMutexGuard;
125 [ # # ][ # # ]: 0 : Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
[ # # ]
126 [ # # ]: 0 : if ( pWindow )
127 : : {
128 : 0 : sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
129 : :
130 [ # # ][ # # ]: 0 : pToolBar = new ToolBar( pWindow, nStyles );
131 [ # # ][ # # ]: 0 : m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
132 [ # # ]: 0 : pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
133 [ # # ]: 0 : pToolBar->SetToolBarManager( pToolBarManager );
134 [ # # ][ # # ]: 0 : m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
[ # # ]
135 [ # # ]: 0 : }
136 : : }
137 : :
138 : : try
139 : : {
140 [ # # ][ # # ]: 0 : if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
[ # # ][ # # ]
141 : : {
142 : : // Fill toolbar with container contents
143 [ # # ]: 0 : pToolBarManager->FillToolbar( m_aConfigData );
144 [ # # ][ # # ]: 0 : pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
[ # # ]
[ # # # # ]
145 [ # # ]: 0 : pToolBar->EnableCustomize( sal_True );
146 [ # # ]: 0 : ::Size aActSize( pToolBar->GetSizePixel() );
147 [ # # ]: 0 : ::Size aSize( pToolBar->CalcWindowSizePixel() );
148 : 0 : aSize.Width() = aActSize.Width();
149 [ # # ]: 0 : pToolBar->SetSizePixel( aSize );
150 : : }
151 : : }
152 [ # # ]: 0 : catch ( const NoSuchElementException& )
153 : : {
154 : : }
155 : 0 : }
156 [ # # ]: 0 : }
157 : 0 : }
158 : :
159 : : // XUIElement interface
160 : 0 : Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
161 : : {
162 [ # # ]: 0 : ResetableGuard aLock( m_aLock );
163 : :
164 [ # # ]: 0 : if ( m_xToolBarManager.is() )
165 : : {
166 [ # # ][ # # ]: 0 : AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
167 [ # # ]: 0 : if ( pToolBarManager )
168 : : {
169 [ # # ]: 0 : Window* pWindow = (Window *)pToolBarManager->GetToolBar();
170 [ # # ][ # # ]: 0 : return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
171 : : }
172 : : }
173 : :
174 [ # # ]: 0 : return Reference< XInterface >();
175 : : }
176 : :
177 : : } // namespace framework
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|