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