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_framework.hxx"
30 #include <tabwin/tabwinfactory.hxx>
31 #include <tabwin/tabwindow.hxx>
32 
33 //_________________________________________________________________________________________________________________
34 //	my own includes
35 //_________________________________________________________________________________________________________________
36 #include <threadhelp/resetableguard.hxx>
37 
38 //_________________________________________________________________________________________________________________
39 //	interface includes
40 //_________________________________________________________________________________________________________________
41 #include <com/sun/star/util/XURLTransformer.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/awt/XTopWindow.hpp>
44 #include <com/sun/star/awt/WindowAttribute.hpp>
45 
46 //_________________________________________________________________________________________________________________
47 //	includes of other projects
48 //_________________________________________________________________________________________________________________
49 #include <vcl/svapp.hxx>
50 #include <tools/urlobj.hxx>
51 #include <rtl/ustrbuf.hxx>
52 
53 //_________________________________________________________________________________________________________________
54 //	Defines
55 //_________________________________________________________________________________________________________________
56 //
57 
58 using namespace rtl;
59 using namespace com::sun::star::uno;
60 using namespace com::sun::star::lang;
61 using namespace com::sun::star::beans;
62 using namespace com::sun::star::util;
63 
64 namespace framework
65 {
66 
67 //*****************************************************************************************************************
68 //	XInterface, XTypeProvider, XServiceInfo
69 //*****************************************************************************************************************
70 DEFINE_XSERVICEINFO_ONEINSTANCESERVICE  (   TabWinFactory				                    ,
71                                             ::cppu::OWeakObject							    ,
72                                             SERVICENAME_TABWINFACTORY	                    ,
73 											IMPLEMENTATIONNAME_TABWINFACTORY
74 										)
75 
76 DEFINE_INIT_SERVICE                     (   TabWinFactory, {} )
77 
78 TabWinFactory::TabWinFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) :
79     ThreadHelpBase( &Application::GetSolarMutex() )
80     , m_xServiceManager( xServiceManager )
81 {
82 }
83 
84 TabWinFactory::~TabWinFactory()
85 {
86 }
87 
88 css::uno::Reference< css::uno::XInterface > SAL_CALL TabWinFactory::createInstanceWithContext(
89 	const css::uno::Reference< css::uno::XComponentContext >& Context )
90 throw ( css::uno::Exception, css::uno::RuntimeException )
91 {
92 	css::uno::Sequence< css::uno::Any > aArgs;
93 
94 	return createInstanceWithArgumentsAndContext( aArgs, Context );
95 }
96 
97 css::uno::Reference< css::uno::XInterface > SAL_CALL TabWinFactory::createInstanceWithArgumentsAndContext(
98 	const css::uno::Sequence< css::uno::Any >& Arguments, const css::uno::Reference< css::uno::XComponentContext >& )
99 throw ( css::uno::Exception, css::uno::RuntimeException )
100 {
101     const rtl::OUString aTopWindowArgName( RTL_CONSTASCII_USTRINGPARAM( "TopWindow" ));
102 
103     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
104     ResetableGuard aLock( m_aLock );
105 	css::uno::Reference< css::awt::XToolkit > xToolkit = m_xToolkit;
106 	css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR( m_xServiceManager );
107 	aLock.unlock();
108     /* SAFE AREA ----------------------------------------------------------------------------------------------- */
109 
110 	css::uno::Reference< css::uno::XInterface > xReturn;
111     css::uno::Reference< css::awt::XTopWindow > xTopWindow;
112     css::beans::PropertyValue                   aPropValue;
113 
114     for ( sal_Int32 i = 0; i < Arguments.getLength(); i++ )
115     {
116         if ( Arguments[i] >>= aPropValue )
117         {
118             if ( aPropValue.Name == aTopWindowArgName )
119                 aPropValue.Value >>= xTopWindow;
120         }
121     }
122 
123 	if ( !xToolkit.is() && xSMGR.is() )
124 	{
125 		xToolkit = css::uno::Reference< css::awt::XToolkit >( xSMGR->createInstance( SERVICENAME_VCLTOOLKIT ), css::uno::UNO_QUERY );
126 		if ( xToolkit.is() )
127 		{
128 			/* SAFE AREA ----------------------------------------------------------------------------------------------- */
129 			aLock.lock();
130 			m_xToolkit = xToolkit;
131 			aLock.unlock();
132 			/* SAFE AREA ----------------------------------------------------------------------------------------------- */
133 		}
134 	}
135 
136     if ( !xTopWindow.is() )
137     {
138 	    if ( xToolkit.is() )
139 	    {
140             // describe window properties.
141             css::awt::WindowDescriptor aDescriptor;
142             aDescriptor.Type                =   css::awt::WindowClass_TOP										    ;
143 		    aDescriptor.ParentIndex         =   -1																	;
144 		    aDescriptor.Parent              =   css::uno::Reference< css::awt::XWindowPeer >()						;
145             aDescriptor.Bounds              =   css::awt::Rectangle(0,0,0,0)                                        ;
146             aDescriptor.WindowAttributes    =   css::awt::WindowAttribute::BORDER|
147                                                 css::awt::WindowAttribute::SIZEABLE|
148                                                 css::awt::WindowAttribute::MOVEABLE|
149                                                 css::awt::WindowAttribute::CLOSEABLE|
150                                                 css::awt::WindowAttribute::MINSIZE;
151 
152             // create a parent window
153             xTopWindow = css::uno::Reference< css::awt::XTopWindow >(
154                             xToolkit->createWindow( aDescriptor ), css::uno::UNO_QUERY );
155         }
156     }
157 
158 	if ( xTopWindow.is() )
159     {
160         TabWindow* pTabWindow = new TabWindow( xSMGR );
161 
162 		css::uno::Sequence< css::uno::Any > aArgs( 1 );
163 
164 		aPropValue.Name	 = aTopWindowArgName;
165 		aPropValue.Value = css::uno::makeAny( xTopWindow );
166 		aArgs[0] = css::uno::makeAny( aPropValue );
167 		pTabWindow->initialize( aArgs );
168 
169 		xReturn = css::uno::Reference< css::uno::XInterface >(
170 					static_cast< OWeakObject* >( pTabWindow ), css::uno::UNO_QUERY );
171 	}
172 
173 	return xReturn;
174 }
175 
176 }
177