xref: /AOO41X/main/framework/source/services/taskcreatorsrv.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir #include "services/taskcreatorsrv.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir //_______________________________________________
33*cdf0e10cSrcweir // own includes
34*cdf0e10cSrcweir #include <helper/persistentwindowstate.hxx>
35*cdf0e10cSrcweir #include <helper/tagwindowasmodified.hxx>
36*cdf0e10cSrcweir #include <helper/titlebarupdate.hxx>
37*cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
38*cdf0e10cSrcweir #include <threadhelp/writeguard.hxx>
39*cdf0e10cSrcweir #include <loadenv/targethelper.hxx>
40*cdf0e10cSrcweir #include <services.h>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir //_______________________________________________
43*cdf0e10cSrcweir // interface includes
44*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/awt/XTopWindow.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/awt/WindowDescriptor.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //_______________________________________________
54*cdf0e10cSrcweir // other includes
55*cdf0e10cSrcweir #include <svtools/colorcfg.hxx>
56*cdf0e10cSrcweir #include <vcl/svapp.hxx>
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
59*cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
60*cdf0e10cSrcweir #endif
61*cdf0e10cSrcweir #include <vcl/window.hxx>
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //_______________________________________________
64*cdf0e10cSrcweir // namespaces
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace framework
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir //-----------------------------------------------
70*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_PARENTFRAME                   = ::rtl::OUString::createFromAscii("ParentFrame"                   ); // XFrame
71*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_FRAMENAME                     = ::rtl::OUString::createFromAscii("FrameName"                     ); // OUString
72*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_MAKEVISIBLE                   = ::rtl::OUString::createFromAscii("MakeVisible"                   ); // sal_Bool
73*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_CREATETOPWINDOW               = ::rtl::OUString::createFromAscii("CreateTopWindow"               ); // sal_Bool
74*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_POSSIZE                       = ::rtl::OUString::createFromAscii("PosSize"                       ); // Rectangle
75*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_CONTAINERWINDOW               = ::rtl::OUString::createFromAscii("ContainerWindow"               ); // XWindow
76*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE  = ::rtl::OUString::createFromAscii("SupportPersistentWindowState"  ); // sal_Bool
77*cdf0e10cSrcweir const ::rtl::OUString TaskCreatorService::ARGUMENT_ENABLE_TITLEBARUPDATE         = ::rtl::OUString::createFromAscii("EnableTitleBarUpdate"          ); // sal_Bool
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir //-----------------------------------------------
80*cdf0e10cSrcweir DEFINE_XINTERFACE_3(TaskCreatorService                                ,
81*cdf0e10cSrcweir                     OWeakObject                                       ,
82*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::lang::XTypeProvider        ),
83*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::lang::XServiceInfo         ),
84*cdf0e10cSrcweir                     DIRECT_INTERFACE(css::lang::XSingleServiceFactory))
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir //-----------------------------------------------
87*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_3(TaskCreatorService              ,
88*cdf0e10cSrcweir                        css::lang::XTypeProvider        ,
89*cdf0e10cSrcweir                        css::lang::XServiceInfo         ,
90*cdf0e10cSrcweir                        css::lang::XSingleServiceFactory)
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir //-----------------------------------------------
93*cdf0e10cSrcweir DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(TaskCreatorService                ,
94*cdf0e10cSrcweir 									   ::cppu::OWeakObject               ,
95*cdf0e10cSrcweir 									   SERVICENAME_TASKCREATOR           ,
96*cdf0e10cSrcweir 									   IMPLEMENTATIONNAME_FWK_TASKCREATOR)
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir //-----------------------------------------------
99*cdf0e10cSrcweir DEFINE_INIT_SERVICE(
100*cdf0e10cSrcweir                     TaskCreatorService,
101*cdf0e10cSrcweir                     {
102*cdf0e10cSrcweir                         /*Attention
103*cdf0e10cSrcweir                             I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
104*cdf0e10cSrcweir                             to create a new instance of this class by our own supported service factory.
105*cdf0e10cSrcweir                             see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
106*cdf0e10cSrcweir                         */
107*cdf0e10cSrcweir                     }
108*cdf0e10cSrcweir                    )
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir //-----------------------------------------------
111*cdf0e10cSrcweir TaskCreatorService::TaskCreatorService(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
112*cdf0e10cSrcweir     : ThreadHelpBase     (&Application::GetSolarMutex())
113*cdf0e10cSrcweir     , ::cppu::OWeakObject(                             )
114*cdf0e10cSrcweir     , m_xSMGR            (xSMGR                        )
115*cdf0e10cSrcweir {
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir //-----------------------------------------------
119*cdf0e10cSrcweir TaskCreatorService::~TaskCreatorService()
120*cdf0e10cSrcweir {
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir //-----------------------------------------------
124*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL TaskCreatorService::createInstance()
125*cdf0e10cSrcweir     throw(css::uno::Exception       ,
126*cdf0e10cSrcweir           css::uno::RuntimeException)
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     return createInstanceWithArguments(css::uno::Sequence< css::uno::Any >());
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir //-----------------------------------------------
132*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL TaskCreatorService::createInstanceWithArguments(const css::uno::Sequence< css::uno::Any >& lArguments)
133*cdf0e10cSrcweir     throw(css::uno::Exception       ,
134*cdf0e10cSrcweir           css::uno::RuntimeException)
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     static ::rtl::OUString     DEFAULTVAL_FRAMENAME                     = ::rtl::OUString();
137*cdf0e10cSrcweir     static sal_Bool            DEFAULTVAL_MAKEVISIBLE                   = sal_False;
138*cdf0e10cSrcweir     static sal_Bool            DEFAULTVAL_CREATETOPWINDOW               = sal_True;
139*cdf0e10cSrcweir 	static css::awt::Rectangle DEFAULTVAL_POSSIZE                       = css::awt::Rectangle(0, 0, 0, 0); // only possize=[0,0,0,0] triggers default handling of vcl !
140*cdf0e10cSrcweir     static sal_Bool            DEFAULTVAL_SUPPORTPERSSISTENTWINDOWSTATE = sal_False;
141*cdf0e10cSrcweir     static sal_Bool            DEFAULTVAL_ENABLE_TITLEBARUPDATE         = sal_True;
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     ::comphelper::SequenceAsHashMap lArgs(lArguments);
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	css::uno::Reference< css::frame::XFrame > xParentFrame                  = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_PARENTFRAME                  , css::uno::Reference< css::frame::XFrame >());
146*cdf0e10cSrcweir     ::rtl::OUString                           sFrameName                    = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_FRAMENAME                    , DEFAULTVAL_FRAMENAME                       );
147*cdf0e10cSrcweir     sal_Bool                                  bVisible                      = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_MAKEVISIBLE                  , DEFAULTVAL_MAKEVISIBLE                     );
148*cdf0e10cSrcweir     sal_Bool                                  bCreateTopWindow              = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_CREATETOPWINDOW              , DEFAULTVAL_CREATETOPWINDOW                 );
149*cdf0e10cSrcweir     css::awt::Rectangle                       aPosSize                      = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_POSSIZE                      , DEFAULTVAL_POSSIZE                         );
150*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow >  xContainerWindow              = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_CONTAINERWINDOW              , css::uno::Reference< css::awt::XWindow >() );
151*cdf0e10cSrcweir     sal_Bool                                  bSupportPersistentWindowState = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE , DEFAULTVAL_SUPPORTPERSSISTENTWINDOWSTATE   );
152*cdf0e10cSrcweir     sal_Bool                                  bEnableTitleBarUpdate         = lArgs.getUnpackedValueOrDefault(TaskCreatorService::ARGUMENT_ENABLE_TITLEBARUPDATE        , DEFAULTVAL_ENABLE_TITLEBARUPDATE           );
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     /* SAFE { */
155*cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
156*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
157*cdf0e10cSrcweir     aReadLock.unlock();
158*cdf0e10cSrcweir     /* } SAFE */
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     // We use FrameName property to set it as API name of the new created frame later.
161*cdf0e10cSrcweir     // But those frame names must be different from the set of special target names as e.g. _blank, _self etcpp !
162*cdf0e10cSrcweir     ::rtl::OUString sRightName = impl_filterNames(sFrameName);
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     // if no external frame window was given ... create a new one.
165*cdf0e10cSrcweir     if ( ! xContainerWindow.is())
166*cdf0e10cSrcweir 	{
167*cdf0e10cSrcweir 		css::uno::Reference< css::awt::XWindow > xParentWindow;
168*cdf0e10cSrcweir 		if (xParentFrame.is())
169*cdf0e10cSrcweir 			xParentWindow = xParentFrame->getContainerWindow();
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		// Parent has no own window ...
172*cdf0e10cSrcweir 		// So we have to create a top level window always !
173*cdf0e10cSrcweir 		if ( ! xParentWindow.is())
174*cdf0e10cSrcweir 			bCreateTopWindow = sal_True;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         xContainerWindow = implts_createContainerWindow(xParentWindow, aPosSize, bCreateTopWindow);
177*cdf0e10cSrcweir 	}
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir     //------------------->
180*cdf0e10cSrcweir     // HACK  #125187# + #i53630#
181*cdf0e10cSrcweir     // Mark all document windows as "special ones", so VCL can bind
182*cdf0e10cSrcweir     // special features to it. Because VCL doesnt know anything about documents ...
183*cdf0e10cSrcweir     // Note: Doing so it's no longer supported, that e.g. our wizards can use findFrame(_blank)
184*cdf0e10cSrcweir     // to create it's previes frames. They must do it manually by using WindowDescriptor+Toolkit!
185*cdf0e10cSrcweir     css::uno::Reference< css::frame::XDesktop > xDesktop(xParentFrame, css::uno::UNO_QUERY);
186*cdf0e10cSrcweir     ::sal_Bool bTopLevelDocumentWindow = (
187*cdf0e10cSrcweir                                             (sRightName.getLength () < 1) &&
188*cdf0e10cSrcweir                                             (
189*cdf0e10cSrcweir                                                 (! xParentFrame.is() )    ||
190*cdf0e10cSrcweir                                                 (  xDesktop.is()     )
191*cdf0e10cSrcweir                                             )
192*cdf0e10cSrcweir                                          );
193*cdf0e10cSrcweir     if (bTopLevelDocumentWindow)
194*cdf0e10cSrcweir         implts_applyDocStyleToWindow(xContainerWindow);
195*cdf0e10cSrcweir     //------------------->
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     // create the new frame
198*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xFrame = implts_createFrame(xParentFrame, xContainerWindow, sRightName);
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir     // special freature:
201*cdf0e10cSrcweir     // A special listener will restore pos/size states in case
202*cdf0e10cSrcweir     // a component was loaded into the frame first time.
203*cdf0e10cSrcweir     if (bSupportPersistentWindowState)
204*cdf0e10cSrcweir         implts_establishWindowStateListener(xFrame);
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     // special feature: On Mac we need tagging the window in case
207*cdf0e10cSrcweir     // the underlying model was modified.
208*cdf0e10cSrcweir     // VCL will ignore our calls in case different platform then Mac
209*cdf0e10cSrcweir     // is used ...
210*cdf0e10cSrcweir     if (bTopLevelDocumentWindow)
211*cdf0e10cSrcweir         implts_establishDocModifyListener (xFrame);
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir     // special freature:
214*cdf0e10cSrcweir     // A special listener will update title bar (text and icon)
215*cdf0e10cSrcweir     // if component of frame will be changed.
216*cdf0e10cSrcweir     if (bEnableTitleBarUpdate)
217*cdf0e10cSrcweir         implts_establishTitleBarUpdate(xFrame);
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir     // Make it visible directly here ...
220*cdf0e10cSrcweir     // if its required from outside.
221*cdf0e10cSrcweir     if (bVisible)
222*cdf0e10cSrcweir         xContainerWindow->setVisible(bVisible);
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     return css::uno::Reference< css::uno::XInterface >(xFrame, css::uno::UNO_QUERY_THROW);
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir //-----------------------------------------------
228*cdf0e10cSrcweir void TaskCreatorService::implts_applyDocStyleToWindow(const css::uno::Reference< css::awt::XWindow >& xWindow) const
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir     // SYNCHRONIZED ->
231*cdf0e10cSrcweir     ::vos::OClearableGuard aSolarGuard(Application::GetSolarMutex());
232*cdf0e10cSrcweir     Window* pVCLWindow = VCLUnoHelper::GetWindow(xWindow);
233*cdf0e10cSrcweir     if (pVCLWindow)
234*cdf0e10cSrcweir         pVCLWindow->SetExtendedStyle(WB_EXT_DOCUMENT);
235*cdf0e10cSrcweir     aSolarGuard.clear();
236*cdf0e10cSrcweir     // <- SYNCHRONIZED
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir //-----------------------------------------------
240*cdf0e10cSrcweir css::uno::Reference< css::awt::XWindow > TaskCreatorService::implts_createContainerWindow( const css::uno::Reference< css::awt::XWindow >& xParentWindow ,
241*cdf0e10cSrcweir                                                                                            const css::awt::Rectangle&                      aPosSize      ,
242*cdf0e10cSrcweir                                                                                                  sal_Bool                                  bTopWindow    )
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir     // SAFE  ->
245*cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
246*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
247*cdf0e10cSrcweir     aReadLock.unlock();
248*cdf0e10cSrcweir     // <- SAFE
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     // get toolkit to create task container window
251*cdf0e10cSrcweir     css::uno::Reference< css::awt::XToolkit > xToolkit( xSMGR->createInstance( SERVICENAME_VCLTOOLKIT ), css::uno::UNO_QUERY_THROW);
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     // Check if child frames can be created realy. We need at least a valid window at the parent frame ...
254*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindowPeer > xParentWindowPeer;
255*cdf0e10cSrcweir     if ( ! bTopWindow)
256*cdf0e10cSrcweir     {
257*cdf0e10cSrcweir         if ( ! xParentWindow.is())
258*cdf0e10cSrcweir             bTopWindow = sal_False;
259*cdf0e10cSrcweir         else
260*cdf0e10cSrcweir             xParentWindowPeer = css::uno::Reference< css::awt::XWindowPeer >(xParentWindow, css::uno::UNO_QUERY_THROW);
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     // describe window properties.
264*cdf0e10cSrcweir     css::awt::WindowDescriptor aDescriptor;
265*cdf0e10cSrcweir     if (bTopWindow)
266*cdf0e10cSrcweir     {
267*cdf0e10cSrcweir         aDescriptor.Type                =   css::awt::WindowClass_TOP                       ;
268*cdf0e10cSrcweir         aDescriptor.WindowServiceName   =   DECLARE_ASCII("window")                         ;
269*cdf0e10cSrcweir         aDescriptor.ParentIndex         =   -1                                              ;
270*cdf0e10cSrcweir         aDescriptor.Parent              =   css::uno::Reference< css::awt::XWindowPeer >()  ;
271*cdf0e10cSrcweir         aDescriptor.Bounds              =   aPosSize                                        ;
272*cdf0e10cSrcweir         aDescriptor.WindowAttributes    =   css::awt::WindowAttribute::BORDER               |
273*cdf0e10cSrcweir                                             css::awt::WindowAttribute::MOVEABLE             |
274*cdf0e10cSrcweir                                             css::awt::WindowAttribute::SIZEABLE             |
275*cdf0e10cSrcweir                                             css::awt::WindowAttribute::CLOSEABLE            |
276*cdf0e10cSrcweir                                             css::awt::VclWindowPeerAttribute::CLIPCHILDREN  ;
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir     else
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         aDescriptor.Type                =   css::awt::WindowClass_TOP                       ;
281*cdf0e10cSrcweir         aDescriptor.WindowServiceName   =   DECLARE_ASCII("dockingwindow")                  ;
282*cdf0e10cSrcweir         aDescriptor.ParentIndex         =   1                                               ;
283*cdf0e10cSrcweir         aDescriptor.Parent              =   xParentWindowPeer                               ;
284*cdf0e10cSrcweir         aDescriptor.Bounds              =   aPosSize                                        ;
285*cdf0e10cSrcweir         aDescriptor.WindowAttributes    =   css::awt::VclWindowPeerAttribute::CLIPCHILDREN  ;
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     // create a new blank container window and get access to parent container to append new created task.
289*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindowPeer > xPeer      = xToolkit->createWindow( aDescriptor );
290*cdf0e10cSrcweir     css::uno::Reference< css::awt::XWindow >     xWindow    ( xPeer, css::uno::UNO_QUERY );
291*cdf0e10cSrcweir     if ( ! xWindow.is())
292*cdf0e10cSrcweir         throw css::uno::Exception(::rtl::OUString::createFromAscii("TaskCreator service was not able to create suitable frame window."),
293*cdf0e10cSrcweir                                   static_cast< ::cppu::OWeakObject* >(this));
294*cdf0e10cSrcweir 	if (bTopWindow)
295*cdf0e10cSrcweir 		xPeer->setBackground(::svtools::ColorConfig().GetColorValue(::svtools::APPBACKGROUND).nColor);
296*cdf0e10cSrcweir 	else
297*cdf0e10cSrcweir 		xPeer->setBackground(0xffffffff);
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir     return xWindow;
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir //-----------------------------------------------
303*cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > TaskCreatorService::implts_createFrame( const css::uno::Reference< css::frame::XFrame >& xParentFrame    ,
304*cdf0e10cSrcweir                                                                                   const css::uno::Reference< css::awt::XWindow >&  xContainerWindow,
305*cdf0e10cSrcweir                                                                                   const ::rtl::OUString&                           sName           )
306*cdf0e10cSrcweir {
307*cdf0e10cSrcweir     // SAFE  ->
308*cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
309*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
310*cdf0e10cSrcweir     aReadLock.unlock();
311*cdf0e10cSrcweir     // <- SAFE
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir     // create new frame.
314*cdf0e10cSrcweir     css::uno::Reference< css::frame::XFrame > xNewFrame( xSMGR->createInstance( SERVICENAME_FRAME ), css::uno::UNO_QUERY_THROW );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir     // Set window on frame.
317*cdf0e10cSrcweir     // Do it before calling any other interface methods ...
318*cdf0e10cSrcweir     // The new created frame must be initialized before you can do anything else there.
319*cdf0e10cSrcweir     xNewFrame->initialize( xContainerWindow );
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     // Put frame to the frame tree.
322*cdf0e10cSrcweir     // Note: The property creator/parent will be set on the new putted frame automaticly ... by the parent container.
323*cdf0e10cSrcweir 	if (xParentFrame.is())
324*cdf0e10cSrcweir 	{
325*cdf0e10cSrcweir 		css::uno::Reference< css::frame::XFramesSupplier > xSupplier  (xParentFrame, css::uno::UNO_QUERY_THROW);
326*cdf0e10cSrcweir 		css::uno::Reference< css::frame::XFrames >         xContainer = xSupplier->getFrames();
327*cdf0e10cSrcweir 		xContainer->append( xNewFrame );
328*cdf0e10cSrcweir 	}
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     // Set it's API name (if there is one from outside)
331*cdf0e10cSrcweir     if (sName.getLength())
332*cdf0e10cSrcweir         xNewFrame->setName( sName );
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 	return xNewFrame;
335*cdf0e10cSrcweir }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir //-----------------------------------------------
338*cdf0e10cSrcweir void TaskCreatorService::implts_establishWindowStateListener( const css::uno::Reference< css::frame::XFrame >& xFrame )
339*cdf0e10cSrcweir {
340*cdf0e10cSrcweir     // SAFE  ->
341*cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
342*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
343*cdf0e10cSrcweir     aReadLock.unlock();
344*cdf0e10cSrcweir     // <- SAFE
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir     // Special feature: It's allowed for frames using a top level window only!
347*cdf0e10cSrcweir     // We must create a special listener service and couple it with the new created task frame.
348*cdf0e10cSrcweir     // He will restore or save the window state of it ...
349*cdf0e10cSrcweir     // See used classes for further informations too.
350*cdf0e10cSrcweir     PersistentWindowState* pPersistentStateHandler = new PersistentWindowState(xSMGR);
351*cdf0e10cSrcweir     css::uno::Reference< css::lang::XInitialization > xInit(static_cast< ::cppu::OWeakObject* >(pPersistentStateHandler), css::uno::UNO_QUERY_THROW);
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lInitData(1);
354*cdf0e10cSrcweir     lInitData[0] <<= xFrame;
355*cdf0e10cSrcweir     xInit->initialize(lInitData);
356*cdf0e10cSrcweir }
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir //-----------------------------------------------
359*cdf0e10cSrcweir void TaskCreatorService::implts_establishDocModifyListener( const css::uno::Reference< css::frame::XFrame >& xFrame )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir     // SAFE  ->
362*cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
363*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
364*cdf0e10cSrcweir     aReadLock.unlock();
365*cdf0e10cSrcweir     // <- SAFE
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     // Special feature: It's allowed for frames using a top level window only!
368*cdf0e10cSrcweir     // We must create a special listener service and couple it with the new created task frame.
369*cdf0e10cSrcweir     // It will tag the window as modified if the underlying model was modified ...
370*cdf0e10cSrcweir     TagWindowAsModified* pTag = new TagWindowAsModified(xSMGR);
371*cdf0e10cSrcweir     css::uno::Reference< css::lang::XInitialization > xInit(static_cast< ::cppu::OWeakObject* >(pTag), css::uno::UNO_QUERY_THROW);
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lInitData(1);
374*cdf0e10cSrcweir     lInitData[0] <<= xFrame;
375*cdf0e10cSrcweir     xInit->initialize(lInitData);
376*cdf0e10cSrcweir }
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir //-----------------------------------------------
379*cdf0e10cSrcweir void TaskCreatorService::implts_establishTitleBarUpdate( const css::uno::Reference< css::frame::XFrame >& xFrame )
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir     // SAFE  ->
382*cdf0e10cSrcweir     ReadGuard aReadLock( m_aLock );
383*cdf0e10cSrcweir     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
384*cdf0e10cSrcweir     aReadLock.unlock();
385*cdf0e10cSrcweir     // <- SAFE
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir     TitleBarUpdate* pHelper = new TitleBarUpdate (xSMGR);
388*cdf0e10cSrcweir     css::uno::Reference< css::lang::XInitialization > xInit(static_cast< ::cppu::OWeakObject* >(pHelper), css::uno::UNO_QUERY_THROW);
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Any > lInitData(1);
391*cdf0e10cSrcweir     lInitData[0] <<= xFrame;
392*cdf0e10cSrcweir     xInit->initialize(lInitData);
393*cdf0e10cSrcweir }
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir //-----------------------------------------------
396*cdf0e10cSrcweir ::rtl::OUString TaskCreatorService::impl_filterNames( const ::rtl::OUString& sName )
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     ::rtl::OUString sFiltered;
399*cdf0e10cSrcweir     if (TargetHelper::isValidNameForFrame(sName))
400*cdf0e10cSrcweir         sFiltered = sName;
401*cdf0e10cSrcweir     return sFiltered;
402*cdf0e10cSrcweir }
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir } // namespace framework
405