1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "taskpane/ToolPanelViewShell.hxx"
22 #include "framework/FrameworkHelper.hxx"
23 #include "PaneChildWindows.hxx"
24 #include "ViewShellBase.hxx"
27 #include <com/sun/star/ui/XUIElementFactory.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XInitialization.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/frame/XFrame.hpp>
32 #include <com/sun/star/awt/XWindow.hpp>
34 #include <sfx2/frame.hxx>
35 #include <vcl/svapp.hxx>
36 #include <osl/mutex.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <cppuhelper/implbase3.hxx>
39 #include <comphelper/namedvaluecollection.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
42 //......................................................................................................................
43 namespace sd
{ namespace toolpanel
45 //......................................................................................................................
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::XInterface
;
49 using ::com::sun::star::uno::UNO_QUERY
;
50 using ::com::sun::star::uno::UNO_QUERY_THROW
;
51 using ::com::sun::star::uno::UNO_SET_THROW
;
52 using ::com::sun::star::uno::Exception
;
53 using ::com::sun::star::uno::RuntimeException
;
54 using ::com::sun::star::uno::Any
;
55 using ::com::sun::star::uno::makeAny
;
56 using ::com::sun::star::uno::Sequence
;
57 using ::com::sun::star::uno::Type
;
58 using ::com::sun::star::uno::XComponentContext
;
59 using ::com::sun::star::ui::XUIElementFactory
;
60 using ::com::sun::star::ui::XUIElement
;
61 using ::com::sun::star::beans::PropertyValue
;
62 using ::com::sun::star::container::NoSuchElementException
;
63 using ::com::sun::star::lang::IllegalArgumentException
;
64 using ::com::sun::star::lang::XServiceInfo
;
65 using ::com::sun::star::lang::XInitialization
;
66 using ::com::sun::star::frame::XFrame
;
67 using ::com::sun::star::awt::XWindow
;
69 //==================================================================================================================
71 //==================================================================================================================
72 typedef ::cppu::WeakImplHelper3
< XUIElementFactory
75 > ToolPanelFactory_Base
;
76 class ToolPanelFactory
: public ToolPanelFactory_Base
79 ToolPanelFactory( const Reference
< XComponentContext
>& i_rContext
);
82 virtual Reference
< XUIElement
> SAL_CALL
createUIElement( const OUString
& ResourceURL
, const Sequence
< PropertyValue
>& Args
) throw (NoSuchElementException
, IllegalArgumentException
, RuntimeException
);
85 virtual OUString SAL_CALL
getImplementationName( ) throw (RuntimeException
);
86 virtual ::sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw (RuntimeException
);
87 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw (RuntimeException
);
90 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw (Exception
, RuntimeException
);
93 virtual ~ToolPanelFactory();
96 const Reference
< XComponentContext
> m_xContext
;
99 //------------------------------------------------------------------------------------------------------------------
100 Reference
< XInterface
> SAL_CALL
ToolPanelFactory_createInstance( const Reference
< XComponentContext
>& i_rContext
)
102 return static_cast< cppu::OWeakObject
* >(
103 new ToolPanelFactory( i_rContext
) );
106 //------------------------------------------------------------------------------------------------------------------
107 OUString
ToolPanelFactory_getImplementationName() throw(RuntimeException
)
109 return OUString( "com.sun.star.comp.drawing.ToolPanelFactory" ) ;
112 //------------------------------------------------------------------------------------------------------------------
113 Sequence
< OUString
> SAL_CALL
ToolPanelFactory_getSupportedServiceNames (void)
114 throw (RuntimeException
)
116 const OUString
sServiceName( "com.sun.star.drawing.DefaultToolPanelFactory" );
117 return Sequence
< OUString
>( &sServiceName
, 1 );
120 //------------------------------------------------------------------------------------------------------------------
121 ToolPanelFactory::ToolPanelFactory( const Reference
< XComponentContext
>& i_rContext
)
122 :m_xContext( i_rContext
)
126 //------------------------------------------------------------------------------------------------------------------
127 ToolPanelFactory::~ToolPanelFactory()
131 //------------------------------------------------------------------------------------------------------------------
132 Reference
< XUIElement
> SAL_CALL
ToolPanelFactory::createUIElement( const OUString
& i_rResourceURL
, const Sequence
< PropertyValue
>& i_rArgs
) throw (NoSuchElementException
, IllegalArgumentException
, RuntimeException
)
134 SolarMutexGuard aSolarGuard
;
136 const PanelId
ePanelId( toolpanel::GetStandardPanelId( i_rResourceURL
) );
137 if ( ePanelId
== PID_UNKNOWN
)
138 throw NoSuchElementException( i_rResourceURL
, *this );
140 const ::comphelper::NamedValueCollection
aArgs( i_rArgs
);
141 const Reference
< XFrame
> xDocFrame( aArgs
.getOrDefault( "Frame", Reference
< XFrame
>() ) );
142 const Reference
< XWindow
> xParentWindow( aArgs
.getOrDefault( "ParentWindow", Reference
< XWindow
>() ) );
143 if ( !xDocFrame
.is() || !xParentWindow
.is() )
144 throw IllegalArgumentException(
145 "For creating a standard tool panel, a Frame and a Parent window are needed." ,
150 // look up the Sfx(View)Frame for the given XFrame
151 SfxViewFrame
* pViewFrame
= NULL
;
152 for ( SfxFrame
* pFrame
= SfxFrame::GetFirst();
154 pFrame
= SfxFrame::GetNext( *pFrame
)
157 if ( pFrame
->GetFrameInterface() == xDocFrame
)
159 pViewFrame
= pFrame
->GetCurrentViewFrame();
164 if ( !pViewFrame
|| !pViewFrame
->HasChildWindow( SID_TASKPANE
) )
165 throw IllegalArgumentException(
171 // retrieve the task pane
172 ToolPanelChildWindow
* pToolPanelWindow( dynamic_cast< ToolPanelChildWindow
* >( pViewFrame
->GetChildWindow( SID_TASKPANE
) ) );
173 if ( !pToolPanelWindow
)
174 throw IllegalArgumentException(
175 "No Impress document, or no Impress Task Pane." ,
180 // retrieve the ViewShellBase, and the view shell of the task pane
181 ViewShellBase
* pViewShellBase
= dynamic_cast< ViewShellBase
* >( pViewFrame
->GetViewShell() );
182 ::boost::shared_ptr
< framework::FrameworkHelper
> pFrameworkHelper
;
183 if ( pViewShellBase
)
184 pFrameworkHelper
= framework::FrameworkHelper::Instance( *pViewShellBase
);
185 ::boost::shared_ptr
< ViewShell
> pViewShell
;
186 if ( pFrameworkHelper
.get() )
187 pViewShell
= pFrameworkHelper
->GetViewShell( framework::FrameworkHelper::msRightPaneURL
);
188 ToolPanelViewShell
* pToolPanelShell
= dynamic_cast< ToolPanelViewShell
* >( pViewShell
.get() );
190 if ( !pToolPanelShell
)
191 throw IllegalArgumentException(
192 "Wrong document type." ,
197 ::Window
* pParentWindow
= VCLUnoHelper::GetWindow( xParentWindow
);
198 if ( !pParentWindow
|| !pToolPanelShell
->IsPanelAnchorWindow( *pParentWindow
) )
199 throw IllegalArgumentException(
200 "Unsupported parent window." ,
205 return pToolPanelShell
->CreatePanelUIElement( xDocFrame
, i_rResourceURL
);
208 //------------------------------------------------------------------------------------------------------------------
209 OUString SAL_CALL
ToolPanelFactory::getImplementationName( ) throw (RuntimeException
)
211 return ToolPanelFactory_getImplementationName();
214 //------------------------------------------------------------------------------------------------------------------
215 ::sal_Bool SAL_CALL
ToolPanelFactory::supportsService( const OUString
& i_rServiceName
) throw (RuntimeException
)
217 const Sequence
< OUString
> aSupported( getSupportedServiceNames() );
218 for ( const OUString
* pSupported
= aSupported
.getConstArray();
219 pSupported
!= aSupported
.getConstArray() + aSupported
.getLength();
222 if ( *pSupported
== i_rServiceName
)
228 //------------------------------------------------------------------------------------------------------------------
229 Sequence
< OUString
> SAL_CALL
ToolPanelFactory::getSupportedServiceNames( ) throw (RuntimeException
)
231 return ToolPanelFactory_getSupportedServiceNames();
234 //------------------------------------------------------------------------------------------------------------------
235 void SAL_CALL
ToolPanelFactory::initialize( const Sequence
< Any
>& i_rArguments
) throw (Exception
, RuntimeException
)
237 ::comphelper::NamedValueCollection
aArgs( i_rArguments
);
242 //......................................................................................................................
243 } } // namespace sd::toolpanel
244 //......................................................................................................................
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */