Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <uielement/addonstoolbarwrapper.hxx>
21 : #include <threadhelp/resetableguard.hxx>
22 : #include <framework/actiontriggerhelper.hxx>
23 : #include <uielement/constitemcontainer.hxx>
24 : #include <uielement/rootitemcontainer.hxx>
25 : #include <uielement/addonstoolbarmanager.hxx>
26 :
27 : #include <uielement/toolbar.hxx>
28 :
29 : #include <com/sun/star/lang/XServiceInfo.hpp>
30 : #include <com/sun/star/lang/DisposedException.hpp>
31 : #include <com/sun/star/beans/XPropertySet.hpp>
32 : #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
33 : #include <com/sun/star/awt/XMenuBar.hpp>
34 : #include <com/sun/star/container/XIndexContainer.hpp>
35 : #include <com/sun/star/container/XNameAccess.hpp>
36 : #include <com/sun/star/ui/UIElementType.hpp>
37 :
38 : #include <toolkit/unohlp.hxx>
39 : #include <toolkit/awt/vclxwindow.hxx>
40 : #include <comphelper/processfactory.hxx>
41 :
42 : #include <svtools/miscopt.hxx>
43 : #include <vcl/svapp.hxx>
44 : #include <vcl/toolbox.hxx>
45 : #include <rtl/logfile.hxx>
46 :
47 : using namespace com::sun::star::uno;
48 : using namespace com::sun::star::beans;
49 : using namespace com::sun::star::frame;
50 : using namespace com::sun::star::lang;
51 : using namespace com::sun::star::container;
52 : using namespace com::sun::star::awt;
53 : using namespace ::com::sun::star::ui;
54 :
55 : namespace framework
56 : {
57 :
58 478 : AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
59 : UIElementWrapperBase( UIElementType::TOOLBAR ),
60 478 : m_xServiceManager( xServiceManager )
61 : {
62 478 : }
63 :
64 144 : AddonsToolBarWrapper::~AddonsToolBarWrapper()
65 : {
66 144 : }
67 :
68 : // XComponent
69 72 : void SAL_CALL AddonsToolBarWrapper::dispose() throw ( RuntimeException )
70 : {
71 72 : Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
72 :
73 72 : com::sun::star::lang::EventObject aEvent( xThis );
74 72 : m_aListenerContainer.disposeAndClear( aEvent );
75 :
76 72 : ResetableGuard aLock( m_aLock );
77 :
78 72 : if ( m_xToolBarManager.is() )
79 72 : m_xToolBarManager->dispose();
80 72 : m_xToolBarManager.clear();
81 72 : m_xToolBarWindow.clear();
82 :
83 72 : m_bDisposed = sal_True;
84 72 : }
85 :
86 : // XInitialization
87 478 : void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
88 : {
89 478 : ResetableGuard aLock( m_aLock );
90 :
91 478 : if ( m_bDisposed )
92 0 : throw DisposedException();
93 :
94 478 : if ( !m_bInitialized )
95 : {
96 478 : UIElementWrapperBase::initialize( aArguments );
97 :
98 1912 : for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
99 : {
100 1434 : PropertyValue aPropValue;
101 1434 : if ( aArguments[n] >>= aPropValue )
102 : {
103 1434 : if ( aPropValue.Name == "ConfigurationData" )
104 478 : aPropValue.Value >>= m_aConfigData;
105 : }
106 1434 : }
107 :
108 478 : Reference< XFrame > xFrame( m_xWeakFrame );
109 478 : if ( xFrame.is() && m_aConfigData.getLength() > 0 )
110 : {
111 : // Create VCL based toolbar which will be filled with settings data
112 478 : ToolBar* pToolBar = 0;
113 478 : AddonsToolBarManager* pToolBarManager = 0;
114 : {
115 478 : SolarMutexGuard aSolarMutexGuard;
116 478 : Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
117 478 : if ( pWindow )
118 : {
119 478 : sal_uLong nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
120 :
121 478 : pToolBar = new ToolBar( pWindow, nStyles );
122 478 : m_xToolBarWindow = VCLUnoHelper::GetInterface( pToolBar );
123 478 : pToolBarManager = new AddonsToolBarManager( m_xServiceManager, xFrame, m_aResourceURL, pToolBar );
124 478 : pToolBar->SetToolBarManager( pToolBarManager );
125 478 : m_xToolBarManager = Reference< XComponent >( static_cast< OWeakObject *>( pToolBarManager ), UNO_QUERY );
126 478 : }
127 : }
128 :
129 : try
130 : {
131 478 : if (( m_aConfigData.getLength() > 0 ) && pToolBar && pToolBarManager )
132 : {
133 : // Fill toolbar with container contents
134 478 : pToolBarManager->FillToolbar( m_aConfigData );
135 478 : pToolBar->SetOutStyle( SvtMiscOptions().GetToolboxStyle() );
136 478 : pToolBar->EnableCustomize( sal_True );
137 478 : ::Size aActSize( pToolBar->GetSizePixel() );
138 478 : ::Size aSize( pToolBar->CalcWindowSizePixel() );
139 478 : aSize.Width() = aActSize.Width();
140 478 : pToolBar->SetSizePixel( aSize );
141 : }
142 : }
143 0 : catch ( const NoSuchElementException& )
144 : {
145 : }
146 478 : }
147 478 : }
148 478 : }
149 :
150 : // XUIElement interface
151 2304 : Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface() throw (::com::sun::star::uno::RuntimeException)
152 : {
153 2304 : ResetableGuard aLock( m_aLock );
154 :
155 2304 : if ( m_xToolBarManager.is() )
156 : {
157 2304 : AddonsToolBarManager* pToolBarManager = static_cast< AddonsToolBarManager *>( m_xToolBarManager.get() );
158 2304 : if ( pToolBarManager )
159 : {
160 2304 : Window* pWindow = (Window *)pToolBarManager->GetToolBar();
161 2304 : return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
162 : }
163 : }
164 :
165 0 : return Reference< XInterface >();
166 : }
167 :
168 : } // namespace framework
169 :
170 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|