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/svapp.hxx>
25 #include <vcl/graphicfilter.hxx>
26 #include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/graphic/Primitive2DTools.hpp>
29 #include <com/sun/star/uno/Reference.h>
30 #include <unotools/configmgr.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <rtl/bootstrap.hxx>
33 #include <svl/stritem.hxx>
34 #include <tools/urlobj.hxx>
36 #include <sfx2/app.hxx>
37 #include <appdata.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/module.hxx>
40 #include <sfx2/msgpool.hxx>
41 #include <sfx2/sfxsids.hrc>
42 #include <sfx2/viewfrm.hxx>
43 #include <sfx2/objface.hxx>
44 #include <basegfx/matrix/b2dhommatrixtools.hxx>
45 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using namespace ::com::sun::star::util
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star::container
;
53 #define ShellClass_SfxApplication
54 #include <sfxslots.hxx>
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
.get(); }
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("Title") >>= 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 aVectorGraphicData
.getPrimitive2DSequence()));
161 // UNO dance to render from drawinglayer
163 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 const double fFakeDPI
=2.54 * 1000.0;
175 geometry::RealRectangle2D
aRealRect(
177 nWidth
, nWidth
/ fAspectRatio
);
179 const uno::Reference
< rendering::XBitmap
> xBitmap(
180 xPrimitive2DRenderer
->rasterize(
181 drawinglayer::primitive2d::Primitive2DSequence(&xTransformRef
, 1),
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 OSL_ENSURE(false, "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: */