1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_folders.h>
21 #include <ucbhelper/content.hxx>
23 #include <vcl/canvastools.hxx>
24 #include <vcl/vectorgraphicdata.hxx>
25 #include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/graphic/Primitive2DTools.hpp>
28 #include <com/sun/star/uno/Reference.h>
29 #include <unotools/configmgr.hxx>
30 #include <comphelper/diagnose_ex.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <osl/diagnose.h>
33 #include <rtl/bootstrap.hxx>
34 #include <svl/stritem.hxx>
35 #include <tools/urlobj.hxx>
37 #include <sfx2/app.hxx>
38 #include <appdata.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <sfx2/module.hxx>
41 #include <sfx2/msgpool.hxx>
42 #include <sfx2/sfxsids.hrc>
43 #include <sfx2/viewfrm.hxx>
44 #include <sfx2/objface.hxx>
45 #include <basegfx/matrix/b2dhommatrixtools.hxx>
46 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
48 #define ShellClass_SfxApplication
49 #include <sfxslots.hxx>
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::uno
;
53 using namespace ::com::sun::star::util
;
54 using namespace ::com::sun::star::beans
;
56 SFX_IMPL_INTERFACE(SfxApplication
,SfxShell
)
58 void SfxApplication::InitInterface_Impl()
60 GetStaticInterface()->RegisterStatusBar(StatusBarId::GenericStatusBar
);
62 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_0
);
63 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_1
);
64 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_2
);
65 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_3
);
66 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_4
);
67 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_5
);
68 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_6
);
69 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_7
);
70 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_8
);
71 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_9
);
74 /** Returns the running SfxProgress for the entire application or 0 if
75 none is running for the entire application.
79 <SfxProgress::GetActiveProgress(SfxViewFrame*)>
80 <SfxViewFrame::GetProgress()const>
82 SfxProgress
* SfxApplication::GetProgress() const
84 return pImpl
->pProgress
;
87 SfxModule
* SfxApplication::GetModule_Impl()
89 SfxModule
* pModule
= SfxModule::GetActiveModule();
91 pModule
= SfxModule::GetActiveModule( SfxViewFrame::GetFirst( nullptr, false ) );
96 OSL_FAIL( "No module!" );
101 bool SfxApplication::IsDowning() const { return pImpl
->bDowning
; }
102 SfxDispatcher
* SfxApplication::GetAppDispatcher_Impl() { return &*pImpl
->pAppDispat
; }
103 SfxSlotPool
& SfxApplication::GetAppSlotPool_Impl() const { return *pImpl
->pSlotPool
; }
105 static bool FileExists( const INetURLObject
& rURL
)
109 if( rURL
.GetProtocol() != INetProtocol::NotValid
)
113 ::ucbhelper::Content
aCnt( rURL
.GetMainURL( INetURLObject::DecodeMechanism::NONE
), uno::Reference
< ucb::XCommandEnvironment
>(), comphelper::getProcessComponentContext() );
116 aCnt
.getPropertyValue(u
"Title"_ustr
) >>= aTitle
;
117 bRet
= ( !aTitle
.isEmpty() );
119 catch(const Exception
&)
128 bool SfxApplication::loadBrandSvg(const char *pName
, BitmapEx
&rBitmap
, int nWidth
)
132 OUString aBaseName
= "/" + OUString::createFromAscii( pName
);
134 OUString uri
= "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER
+ aBaseName
+ ".svg";
135 rtl::Bootstrap::expandMacros( uri
);
137 INetURLObject
aObj( uri
);
138 if ( !FileExists(aObj
) )
141 VectorGraphicData
aVectorGraphicData(aObj
.PathToFileName(), VectorGraphicDataType::Svg
);
143 // transform into [0,0,width,width*aspect] std dimensions
145 basegfx::B2DRange
aRange(aVectorGraphicData
.getRange());
146 const double fAspectRatio(
147 aRange
.getHeight() == 0.0 ? 1.0 : aRange
.getWidth()/aRange
.getHeight());
148 basegfx::B2DHomMatrix
aTransform(
149 basegfx::utils::createTranslateB2DHomMatrix(
153 aRange
.getWidth() == 0.0 ? 1.0 : nWidth
/ aRange
.getWidth(),
154 (aRange
.getHeight() == 0.0
155 ? 1.0 : nWidth
/ fAspectRatio
/ aRange
.getHeight()));
156 const drawinglayer::primitive2d::Primitive2DReference
xTransformRef(
157 new drawinglayer::primitive2d::TransformPrimitive2D(
159 drawinglayer::primitive2d::Primitive2DContainer(aVectorGraphicData
.getPrimitive2DSequence())));
161 // UNO dance to render from drawinglayer
163 const uno::Reference
< uno::XComponentContext
>& xContext(::comphelper::getProcessComponentContext());
167 const uno::Reference
< graphic::XPrimitive2DRenderer
> xPrimitive2DRenderer
=
168 graphic::Primitive2DTools::create( xContext
);
170 // cancel out rasterize's mm2pixel conversion
171 // see fFactor100th_mmToInch in
172 // drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
173 constexpr double fFakeDPI
= o3tl::convert(1.0, o3tl::Length::in
, o3tl::Length::mm100
);
175 geometry::RealRectangle2D
aRealRect(
177 nWidth
, nWidth
/ fAspectRatio
);
179 const uno::Reference
< rendering::XBitmap
> xBitmap(
180 xPrimitive2DRenderer
->rasterize(
181 drawinglayer::primitive2d::Primitive2DContainer
{xTransformRef
}.toSequence(),
182 uno::Sequence
< beans::PropertyValue
>(),
190 const uno::Reference
< rendering::XIntegerReadOnlyBitmap
> xIntBmp(xBitmap
, uno::UNO_QUERY_THROW
);
191 rBitmap
= vcl::unotools::bitmapExFromXBitmap(xIntBmp
);
195 catch(const uno::Exception
&)
197 TOOLS_WARN_EXCEPTION("sfx.appl", "Got no graphic::XPrimitive2DRenderer (!)" );
202 /** loads the application logo as used in the impress slideshow pause screen */
203 BitmapEx
SfxApplication::GetApplicationLogo(tools::Long nWidth
)
206 SfxApplication::loadBrandSvg("shell/about", aBitmap
, nWidth
);
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */