1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <tabwin/tabwinfactory.hxx>
27cdf0e10cSrcweir #include <tabwin/tabwindow.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir //	my own includes
31cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //_________________________________________________________________________________________________________________
35cdf0e10cSrcweir //	interface includes
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
39cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
40cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir //	includes of other projects
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir #include <vcl/svapp.hxx>
46cdf0e10cSrcweir #include <tools/urlobj.hxx>
47cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50cdf0e10cSrcweir //	Defines
51cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52cdf0e10cSrcweir //
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace rtl;
55cdf0e10cSrcweir using namespace com::sun::star::uno;
56cdf0e10cSrcweir using namespace com::sun::star::lang;
57cdf0e10cSrcweir using namespace com::sun::star::beans;
58cdf0e10cSrcweir using namespace com::sun::star::util;
59cdf0e10cSrcweir 
60cdf0e10cSrcweir namespace framework
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //*****************************************************************************************************************
64cdf0e10cSrcweir //	XInterface, XTypeProvider, XServiceInfo
65cdf0e10cSrcweir //*****************************************************************************************************************
DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(TabWinFactory,::cppu::OWeakObject,SERVICENAME_TABWINFACTORY,IMPLEMENTATIONNAME_TABWINFACTORY)66cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   TabWinFactory				                    ,
67cdf0e10cSrcweir                                             ::cppu::OWeakObject							    ,
68cdf0e10cSrcweir                                             SERVICENAME_TABWINFACTORY	                    ,
69cdf0e10cSrcweir 											IMPLEMENTATIONNAME_TABWINFACTORY
70cdf0e10cSrcweir 										)
71cdf0e10cSrcweir 
72cdf0e10cSrcweir DEFINE_INIT_SERVICE                     (   TabWinFactory, {} )
73cdf0e10cSrcweir 
74cdf0e10cSrcweir TabWinFactory::TabWinFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
75cdf0e10cSrcweir     ThreadHelpBase( &Application::GetSolarMutex() )
76cdf0e10cSrcweir     , m_xServiceManager( xServiceManager )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
~TabWinFactory()80cdf0e10cSrcweir TabWinFactory::~TabWinFactory()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
createInstanceWithContext(const css::uno::Reference<css::uno::XComponentContext> & Context)84cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL TabWinFactory::createInstanceWithContext(
85cdf0e10cSrcweir 	const css::uno::Reference< css::uno::XComponentContext >& Context )
86cdf0e10cSrcweir throw ( css::uno::Exception, css::uno::RuntimeException )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	css::uno::Sequence< css::uno::Any > aArgs;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	return createInstanceWithArgumentsAndContext( aArgs, Context );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
createInstanceWithArgumentsAndContext(const css::uno::Sequence<css::uno::Any> & Arguments,const css::uno::Reference<css::uno::XComponentContext> &)93cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL TabWinFactory::createInstanceWithArgumentsAndContext(
94cdf0e10cSrcweir 	const css::uno::Sequence< css::uno::Any >& Arguments, const css::uno::Reference< css::uno::XComponentContext >& )
95cdf0e10cSrcweir throw ( css::uno::Exception, css::uno::RuntimeException )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     const rtl::OUString aTopWindowArgName( RTL_CONSTASCII_USTRINGPARAM( "TopWindow" ));
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
100cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
101cdf0e10cSrcweir 	css::uno::Reference< css::awt::XToolkit > xToolkit = m_xToolkit;
102cdf0e10cSrcweir 	css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xServiceManager );
103cdf0e10cSrcweir 	aLock.unlock();
104cdf0e10cSrcweir     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	css::uno::Reference< css::uno::XInterface > xReturn;
107cdf0e10cSrcweir     css::uno::Reference< css::awt::XTopWindow > xTopWindow;
108cdf0e10cSrcweir     css::beans::PropertyValue                   aPropValue;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir     for ( sal_Int32 i = 0; i < Arguments.getLength(); i++ )
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         if ( Arguments[i] >>= aPropValue )
113cdf0e10cSrcweir         {
114cdf0e10cSrcweir             if ( aPropValue.Name == aTopWindowArgName )
115cdf0e10cSrcweir                 aPropValue.Value >>= xTopWindow;
116cdf0e10cSrcweir         }
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	if ( !xToolkit.is() && xSMGR.is() )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		xToolkit = css::uno::Reference< css::awt::XToolkit >( xSMGR->createInstance( SERVICENAME_VCLTOOLKIT ), css::uno::UNO_QUERY );
122cdf0e10cSrcweir 		if ( xToolkit.is() )
123cdf0e10cSrcweir 		{
124cdf0e10cSrcweir 			/* SAFE AREA ----------------------------------------------------------------------------------------------- */
125cdf0e10cSrcweir 			aLock.lock();
126cdf0e10cSrcweir 			m_xToolkit = xToolkit;
127cdf0e10cSrcweir 			aLock.unlock();
128cdf0e10cSrcweir 			/* SAFE AREA ----------------------------------------------------------------------------------------------- */
129cdf0e10cSrcweir 		}
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     if ( !xTopWindow.is() )
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir 	    if ( xToolkit.is() )
135cdf0e10cSrcweir 	    {
136cdf0e10cSrcweir             // describe window properties.
137cdf0e10cSrcweir             css::awt::WindowDescriptor aDescriptor;
138cdf0e10cSrcweir             aDescriptor.Type                =   css::awt::WindowClass_TOP										    ;
139cdf0e10cSrcweir 		    aDescriptor.ParentIndex         =   -1																	;
140cdf0e10cSrcweir 		    aDescriptor.Parent              =   css::uno::Reference< css::awt::XWindowPeer >()						;
141cdf0e10cSrcweir             aDescriptor.Bounds              =   css::awt::Rectangle(0,0,0,0)                                        ;
142cdf0e10cSrcweir             aDescriptor.WindowAttributes    =   css::awt::WindowAttribute::BORDER|
143cdf0e10cSrcweir                                                 css::awt::WindowAttribute::SIZEABLE|
144cdf0e10cSrcweir                                                 css::awt::WindowAttribute::MOVEABLE|
145cdf0e10cSrcweir                                                 css::awt::WindowAttribute::CLOSEABLE|
146cdf0e10cSrcweir                                                 css::awt::WindowAttribute::MINSIZE;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir             // create a parent window
149cdf0e10cSrcweir             xTopWindow = css::uno::Reference< css::awt::XTopWindow >(
150cdf0e10cSrcweir                             xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir     }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 	if ( xTopWindow.is() )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         TabWindow* pTabWindow = new TabWindow( xSMGR );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 		css::uno::Sequence< css::uno::Any > aArgs( 1 );
159cdf0e10cSrcweir 
160cdf0e10cSrcweir 		aPropValue.Name	 = aTopWindowArgName;
161cdf0e10cSrcweir 		aPropValue.Value = css::uno::makeAny( xTopWindow );
162cdf0e10cSrcweir 		aArgs[0] = css::uno::makeAny( aPropValue );
163cdf0e10cSrcweir 		pTabWindow->initialize( aArgs );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 		xReturn = css::uno::Reference< css::uno::XInterface >(
166cdf0e10cSrcweir 					static_cast< OWeakObject* >( pTabWindow ), css::uno::UNO_QUERY );
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	return xReturn;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir }
173