Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / appl / appmisc.cxx
blob864e2aaaf1a3a63881d00a15085405a1dfb68f71
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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.
77 [Cross-reference]
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();
90 if ( !pModule )
91 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( nullptr, false ) );
92 if( pModule )
93 return pModule;
94 else
96 OSL_FAIL( "No module!" );
97 return nullptr;
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 )
107 bool bRet = false;
109 if( rURL.GetProtocol() != INetProtocol::NotValid )
113 ::ucbhelper::Content aCnt( rURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
114 OUString aTitle;
116 aCnt.getPropertyValue("Title") >>= aTitle;
117 bRet = ( !aTitle.isEmpty() );
119 catch(const Exception&)
121 return false;
125 return bRet;
128 bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
130 // Load from disk
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) )
139 return false;
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(
150 -aRange.getMinX(),
151 -aRange.getMinY()));
152 aTransform.scale(
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(
158 aTransform,
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(
176 0, 0,
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 >(),
183 fFakeDPI,
184 fFakeDPI,
185 aRealRect,
186 500000));
188 if(xBitmap.is())
190 const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
191 rBitmap = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
192 return true;
195 catch(const uno::Exception&)
197 OSL_ENSURE(false, "Got no graphic::XPrimitive2DRenderer (!)" );
199 return false;
202 /** loads the application logo as used in the impress slideshow pause screen */
203 BitmapEx SfxApplication::GetApplicationLogo(tools::Long nWidth)
205 BitmapEx aBitmap;
206 SfxApplication::loadBrandSvg("shell/about", aBitmap, nWidth);
207 return aBitmap;
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */