1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 #ifndef __FRAMEWORK_HELPER_TITLEBARUPDATE_HXX_
32 #include <helper/titlebarupdate.hxx>
35 //_________________________________________________________________________________________________________________
37 //_________________________________________________________________________________________________________________
39 #ifndef __FRAMEWORK_PATTERN_WINDOW_HXX_
40 #include <pattern/window.hxx>
43 #ifndef __FRAMEWORK_THREADHELP_WRITEGUARD_HXX_
44 #include <threadhelp/writeguard.hxx>
47 #ifndef __FRAMEWORK_THREADHELP_READGUARD_HXX_
48 #include <threadhelp/readguard.hxx>
51 #ifndef __FRAMEWORK_MACROS_GENERIC_HXX_
52 #include <macros/generic.hxx>
55 #ifndef __FRAMEWORK_SERVICES_H_
59 #ifndef __FRAMEWORK_PROPETIES_H_
60 #include <properties.h>
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
67 #ifndef _COM_SUN_STAR_AWT_XWINDOW_HPP_
68 #include <com/sun/star/awt/XWindow.hpp>
71 #ifndef _COM_SUN_STAR_LANG_XSERVICXEINFO_HPP_
72 #include <com/sun/star/lang/XServiceInfo.hpp>
75 #ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_
76 #include <com/sun/star/lang/IllegalArgumentException.hpp>
79 #ifndef _COM_SUN_STAR_FRAME_XMODULEMANAGER_HPP_
80 #include <com/sun/star/frame/XModuleManager.hpp>
83 #ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
84 #include <com/sun/star/container/XNameAccess.hpp>
87 #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
88 #include <com/sun/star/beans/XPropertySet.hpp>
91 #ifndef _COM_SUN_STAR_BEANS_XMATERIALHOLDER_HPP_
92 #include <com/sun/star/beans/XMaterialHolder.hpp>
95 #ifndef _COM_SUN_STAR_FRAME_XTITLECHANGEBROADCASTER_HPP_
96 #include <com/sun/star/frame/XTitleChangeBroadcaster.hpp>
99 #ifndef _COM_SUN_STAR_BEANS_NAMEDVALUE_HPP_
100 #include <com/sun/star/beans/NamedValue.hpp>
103 //_________________________________________________________________________________________________________________
105 //_________________________________________________________________________________________________________________
107 #ifndef _COMPHELPER_SEQUENCEASHASHMAP_HXX
108 #include <comphelper/sequenceashashmap.hxx>
111 #ifndef _UTL_CONFIGMGR_HXX
112 #include <unotools/configmgr.hxx>
115 #ifndef _UTL_BOOTSTRAP_HXX
116 #include <unotools/bootstrap.hxx>
119 #ifndef _SV_WINDOW_HXX
120 #include <vcl/window.hxx>
123 #ifndef _SV_SYSWIN_HXX
124 #include <vcl/syswin.hxx>
127 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
128 #include <toolkit/unohlp.hxx>
131 #ifndef _SV_SVAPP_HXX
132 #include <vcl/svapp.hxx>
135 #ifndef _SV_WRKWIN_HXX
136 #include <vcl/wrkwin.hxx>
139 //_________________________________________________________________________________________________________________
144 //_________________________________________________________________________________________________________________
147 static const ::sal_Int32 INVALID_ICON_ID
= -1;
148 static const ::sal_Int32 DEFAULT_ICON_ID
= 0;
150 //_________________________________________________________________________________________________________________
153 //*****************************************************************************************************************
154 // XInterface, XTypeProvider
156 DEFINE_XINTERFACE_5(TitleBarUpdate
,
158 DIRECT_INTERFACE (css::lang::XTypeProvider
),
159 DIRECT_INTERFACE (css::lang::XInitialization
),
160 DIRECT_INTERFACE (css::frame::XFrameActionListener
),
161 DIRECT_INTERFACE (css::frame::XTitleChangeListener
),
162 DERIVED_INTERFACE(css::lang::XEventListener
,css::frame::XFrameActionListener
))
164 DEFINE_XTYPEPROVIDER_5(TitleBarUpdate
,
165 css::lang::XTypeProvider
,
166 css::lang::XInitialization
,
167 css::frame::XFrameActionListener
,
168 css::frame::XTitleChangeListener
,
169 css::lang::XEventListener
)
171 //*****************************************************************************************************************
172 TitleBarUpdate::TitleBarUpdate(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
)
173 : ThreadHelpBase (&Application::GetSolarMutex())
179 //*****************************************************************************************************************
180 TitleBarUpdate::~TitleBarUpdate()
184 //*****************************************************************************************************************
185 void SAL_CALL
TitleBarUpdate::initialize(const css::uno::Sequence
< css::uno::Any
>& lArguments
)
186 throw(css::uno::Exception
,
187 css::uno::RuntimeException
)
190 css::uno::Reference
< css::frame::XFrame
> xFrame
;
191 if (lArguments
.getLength() < 1)
192 throw css::lang::IllegalArgumentException(
193 DECLARE_ASCII("Empty argument list!"),
194 static_cast< ::cppu::OWeakObject
* >(this),
197 lArguments
[0] >>= xFrame
;
199 throw css::lang::IllegalArgumentException(
200 DECLARE_ASCII("No valid frame specified!"),
201 static_cast< ::cppu::OWeakObject
* >(this),
205 WriteGuard
aWriteLock(m_aLock
);
206 // hold the frame as weak reference(!) so it can die everytimes :-)
212 xFrame
->addFrameActionListener(this);
214 css::uno::Reference
< css::frame::XTitleChangeBroadcaster
> xBroadcaster(xFrame
, css::uno::UNO_QUERY
);
215 if (xBroadcaster
.is ())
216 xBroadcaster
->addTitleChangeListener (this);
219 //*****************************************************************************************************************
220 void SAL_CALL
TitleBarUpdate::frameAction(const css::frame::FrameActionEvent
& aEvent
)
221 throw(css::uno::RuntimeException
)
223 // we are interested on events only, which must trigger a title bar update
224 // because component was changed.
226 (aEvent
.Action
== css::frame::FrameAction_COMPONENT_ATTACHED
) ||
227 (aEvent
.Action
== css::frame::FrameAction_COMPONENT_REATTACHED
) ||
228 (aEvent
.Action
== css::frame::FrameAction_COMPONENT_DETACHING
)
235 //*****************************************************************************************************************
236 void SAL_CALL
TitleBarUpdate::titleChanged(const css::frame::TitleChangedEvent
& /* aEvent */)
237 throw (css::uno::RuntimeException
)
242 //*****************************************************************************************************************
243 void SAL_CALL
TitleBarUpdate::disposing(const css::lang::EventObject
&)
244 throw(css::uno::RuntimeException
)
246 // nothing todo here - because we hold the frame as weak reference only
249 //*****************************************************************************************************************
250 ::sal_Bool
TitleBarUpdate::implst_getModuleInfo(const css::uno::Reference
< css::frame::XFrame
>& xFrame
,
257 ReadGuard
aReadLock(m_aLock
);
258 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
264 css::uno::Reference
< css::frame::XModuleManager
> xModuleManager(
265 xSMGR
->createInstance(SERVICENAME_MODULEMANAGER
),
266 css::uno::UNO_QUERY_THROW
);
268 css::uno::Reference
< css::container::XNameAccess
> xConfig(
270 css::uno::UNO_QUERY_THROW
);
272 rInfo
.sID
= xModuleManager
->identify(xFrame
);
273 ::comphelper::SequenceAsHashMap lProps
= xConfig
->getByName (rInfo
.sID
);
275 rInfo
.sUIName
= lProps
.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_UINAME
, ::rtl::OUString());
276 rInfo
.nIcon
= lProps
.getUnpackedValueOrDefault (OFFICEFACTORY_PROPNAME_ICON
, INVALID_ICON_ID
);
278 // Note: If we could retrieve a module id ... everything is OK.
279 // UIName and Icon ID are optional values !
280 ::sal_Bool bSuccess
= (rInfo
.sID
.getLength () > 0);
283 catch(const css::uno::Exception
&)
289 //*****************************************************************************************************************
290 void TitleBarUpdate::impl_forceUpdate()
293 ReadGuard
aReadLock(m_aLock
);
294 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
295 css::uno::Reference
< css::frame::XFrame
> xFrame(m_xFrame
.get(), css::uno::UNO_QUERY
);
299 // frame already gone ? We hold it weak only ...
303 // no window -> no chance to set/update title and icon
304 css::uno::Reference
< css::awt::XWindow
> xWindow
= xFrame
->getContainerWindow();
308 impl_updateIcon (xFrame
);
309 impl_updateTitle (xFrame
);
312 //*****************************************************************************************************************
313 void TitleBarUpdate::impl_updateIcon(const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
315 css::uno::Reference
< css::frame::XController
> xController
= xFrame
->getController ();
316 css::uno::Reference
< css::awt::XWindow
> xWindow
= xFrame
->getContainerWindow ();
319 ( ! xController
.is() ) ||
324 // a) set default value to an invalid one. So we can start further searches for right icon id, if
325 // first steps failed!
326 sal_Int32 nIcon
= INVALID_ICON_ID
;
328 // b) try to find information on controller property set directly
329 // Don't forget to catch possible exceptions - because these property is an optional one!
330 css::uno::Reference
< css::beans::XPropertySet
> xSet( xController
, css::uno::UNO_QUERY
);
335 xSet
->getPropertyValue( CONTROLLER_PROPNAME_ICONID
) >>= nIcon
;
337 catch(const css::uno::Exception
&)
341 // c) if b) failed ... identify the used module and retrieve set icon from module config.
342 // Tirck :-) Module was already specified outside and aInfo contains all needed informations.
343 if ( nIcon
== INVALID_ICON_ID
)
346 if (implst_getModuleInfo(xFrame
, aInfo
))
350 // d) if all steps failed - use fallback :-)
351 // ... means using the global staroffice icon
352 if( nIcon
== INVALID_ICON_ID
)
353 nIcon
= DEFAULT_ICON_ID
;
355 // e) set icon on container window now
356 // Don't forget SolarMutex! We use vcl directly :-(
357 // Check window pointer for right WorkWindow class too!!!
359 // VCL SYNCHRONIZED ->
360 ::vos::OClearableGuard
aSolarLock( Application::GetSolarMutex() );
362 Window
* pWindow
= (VCLUnoHelper::GetWindow( xWindow
));
365 ( pWindow
->GetType() == WINDOW_WORKWINDOW
)
368 WorkWindow
* pWorkWindow
= (WorkWindow
*)pWindow
;
369 pWorkWindow
->SetIcon( (sal_uInt16
)nIcon
);
371 css::uno::Reference
< css::frame::XModel
> xModel
= xController
->getModel();
374 aURL
= xModel
->getURL();
375 pWorkWindow
->SetRepresentedURL( aURL
);
379 // <- VCL SYNCHRONIZED
382 //*****************************************************************************************************************
383 void TitleBarUpdate::impl_updateTitle(const css::uno::Reference
< css::frame::XFrame
>& xFrame
)
385 // no window ... no chance to set any title -> return
386 css::uno::Reference
< css::awt::XWindow
> xWindow
= xFrame
->getContainerWindow ();
387 if ( ! xWindow
.is() )
390 css::uno::Reference
< css::frame::XTitle
> xTitle(xFrame
, css::uno::UNO_QUERY
);
394 const ::rtl::OUString sTitle
= xTitle
->getTitle ();
396 // VCL SYNCHRONIZED ->
397 ::vos::OClearableGuard
aSolarLock( Application::GetSolarMutex() );
399 Window
* pWindow
= (VCLUnoHelper::GetWindow( xWindow
));
402 ( pWindow
->GetType() == WINDOW_WORKWINDOW
)
405 WorkWindow
* pWorkWindow
= (WorkWindow
*)pWindow
;
406 pWorkWindow
->SetText( sTitle
);
410 // <- VCL SYNCHRONIZED
413 } // namespace framework