1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <config_folders.h>
21 #include <ucbhelper/content.hxx>
22
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/processfactory.hxx>
31 #include <rtl/bootstrap.hxx>
32 #include <svl/stritem.hxx>
33 #include <tools/urlobj.hxx>
34
35 #include <sfx2/app.hxx>
36 #include <appdata.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/module.hxx>
39 #include <sfx2/msgpool.hxx>
40 #include <sfx2/sfxsids.hrc>
41 #include <sfx2/viewfrm.hxx>
42 #include <sfx2/objface.hxx>
43 #include <basegfx/matrix/b2dhommatrixtools.hxx>
44 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
45
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::util;
49 using namespace ::com::sun::star::beans;
50 using namespace ::com::sun::star::container;
51
52 #define ShellClass_SfxApplication
53 #include <sfxslots.hxx>
54
SFX_IMPL_INTERFACE(SfxApplication,SfxShell)55 SFX_IMPL_INTERFACE(SfxApplication,SfxShell)
56
57 void SfxApplication::InitInterface_Impl()
58 {
59 GetStaticInterface()->RegisterStatusBar(StatusBarId::GenericStatusBar);
60
61 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_0);
62 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_1);
63 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_2);
64 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_3);
65 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_4);
66 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_5);
67 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_6);
68 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_7);
69 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_8);
70 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_9);
71 }
72
73 /** Returns the running SfxProgress for the entire application or 0 if
74 none is running for the entire application.
75
76 [Cross-reference]
77
78 <SfxProgress::GetActiveProgress(SfxViewFrame*)>
79 <SfxViewFrame::GetProgress()const>
80 */
GetProgress() const81 SfxProgress* SfxApplication::GetProgress() const
82 {
83 return pImpl->pProgress;
84 }
85
GetModule_Impl()86 SfxModule* SfxApplication::GetModule_Impl()
87 {
88 SfxModule* pModule = SfxModule::GetActiveModule();
89 if ( !pModule )
90 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( nullptr, false ) );
91 if( pModule )
92 return pModule;
93 else
94 {
95 OSL_FAIL( "No module!" );
96 return nullptr;
97 }
98 }
99
IsDowning() const100 bool SfxApplication::IsDowning() const { return pImpl->bDowning; }
GetAppDispatcher_Impl()101 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pImpl->pAppDispat.get(); }
GetAppSlotPool_Impl() const102 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pImpl->pSlotPool; }
103
FileExists(const INetURLObject & rURL)104 static bool FileExists( const INetURLObject& rURL )
105 {
106 bool bRet = false;
107
108 if( rURL.GetProtocol() != INetProtocol::NotValid )
109 {
110 try
111 {
112 ::ucbhelper::Content aCnt( rURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
113 OUString aTitle;
114
115 aCnt.getPropertyValue("Title") >>= aTitle;
116 bRet = ( !aTitle.isEmpty() );
117 }
118 catch(const Exception&)
119 {
120 return false;
121 }
122 }
123
124 return bRet;
125 }
126
loadBrandSvg(const char * pName,BitmapEx & rBitmap,int nWidth)127 bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
128 {
129 // Load from disk
130
131 OUString aBaseName = "/" + OUString::createFromAscii( pName );
132
133 OUString uri = "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER + aBaseName + ".svg";
134 rtl::Bootstrap::expandMacros( uri );
135
136 INetURLObject aObj( uri );
137 if ( !FileExists(aObj) )
138 return false;
139
140 VectorGraphicData aVectorGraphicData(aObj.PathToFileName(), VectorGraphicDataType::Svg);
141
142 // transform into [0,0,width,width*aspect] std dimensions
143
144 basegfx::B2DRange aRange(aVectorGraphicData.getRange());
145 const double fAspectRatio(
146 aRange.getHeight() == 0.0 ? 1.0 : aRange.getWidth()/aRange.getHeight());
147 basegfx::B2DHomMatrix aTransform(
148 basegfx::utils::createTranslateB2DHomMatrix(
149 -aRange.getMinX(),
150 -aRange.getMinY()));
151 aTransform.scale(
152 aRange.getWidth() == 0.0 ? 1.0 : nWidth / aRange.getWidth(),
153 (aRange.getHeight() == 0.0
154 ? 1.0 : nWidth / fAspectRatio / aRange.getHeight()));
155 const drawinglayer::primitive2d::Primitive2DReference xTransformRef(
156 new drawinglayer::primitive2d::TransformPrimitive2D(
157 aTransform,
158 aVectorGraphicData.getPrimitive2DSequence()));
159
160 // UNO dance to render from drawinglayer
161
162 uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
163
164 try
165 {
166 const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer =
167 graphic::Primitive2DTools::create( xContext );
168
169 // cancel out rasterize's mm2pixel conversion
170 // see fFactor100th_mmToInch in
171 // drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
172 const double fFakeDPI=2.54 * 1000.0;
173
174 geometry::RealRectangle2D aRealRect(
175 0, 0,
176 nWidth, nWidth / fAspectRatio);
177
178 const uno::Reference< rendering::XBitmap > xBitmap(
179 xPrimitive2DRenderer->rasterize(
180 drawinglayer::primitive2d::Primitive2DSequence(&xTransformRef, 1),
181 uno::Sequence< beans::PropertyValue >(),
182 fFakeDPI,
183 fFakeDPI,
184 aRealRect,
185 500000));
186
187 if(xBitmap.is())
188 {
189 const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
190 rBitmap = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
191 return true;
192 }
193 }
194 catch(const uno::Exception&)
195 {
196 OSL_ENSURE(false, "Got no graphic::XPrimitive2DRenderer (!)" );
197 }
198 return false;
199 }
200
201 /** loads the application logo as used in the impress slideshow pause screen */
GetApplicationLogo(tools::Long nWidth)202 BitmapEx SfxApplication::GetApplicationLogo(tools::Long nWidth)
203 {
204 BitmapEx aBitmap;
205 SfxApplication::loadBrandSvg("shell/about", aBitmap, nWidth);
206 return aBitmap;
207 }
208
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
210