LibreOffice Module sfx2 (master) 1
appmisc.cxx
Go to the documentation of this file.
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>
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>
32#include <osl/diagnose.h>
33#include <rtl/bootstrap.hxx>
34#include <svl/stritem.hxx>
35#include <tools/urlobj.hxx>
36
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>
47
48using namespace ::com::sun::star;
49using namespace ::com::sun::star::uno;
50using namespace ::com::sun::star::util;
51using namespace ::com::sun::star::beans;
52using namespace ::com::sun::star::container;
53
54#define ShellClass_SfxApplication
55#include <sfxslots.hxx>
56
58
59void SfxApplication::InitInterface_Impl()
60{
61 GetStaticInterface()->RegisterStatusBar(StatusBarId::GenericStatusBar);
62
63 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_0);
64 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_1);
65 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_2);
66 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_3);
67 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_4);
68 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_5);
69 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_6);
70 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_7);
71 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_8);
72 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_9);
73}
74
84{
85 return pImpl->pProgress;
86}
87
89{
91 if ( !pModule )
92 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( nullptr, false ) );
93 if( pModule )
94 return pModule;
95 else
96 {
97 OSL_FAIL( "No module!" );
98 return nullptr;
99 }
100}
101
102bool SfxApplication::IsDowning() const { return pImpl->bDowning; }
105
106static bool FileExists( const INetURLObject& rURL )
107{
108 bool bRet = false;
109
110 if( rURL.GetProtocol() != INetProtocol::NotValid )
111 {
112 try
113 {
114 ::ucbhelper::Content aCnt( rURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() );
115 OUString aTitle;
116
117 aCnt.getPropertyValue("Title") >>= aTitle;
118 bRet = ( !aTitle.isEmpty() );
119 }
120 catch(const Exception&)
121 {
122 return false;
123 }
124 }
125
126 return bRet;
127}
128
129bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
130{
131 // Load from disk
132
133 OUString aBaseName = "/" + OUString::createFromAscii( pName );
134
135 OUString uri = "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER + aBaseName + ".svg";
136 rtl::Bootstrap::expandMacros( uri );
137
138 INetURLObject aObj( uri );
139 if ( !FileExists(aObj) )
140 return false;
141
142 VectorGraphicData aVectorGraphicData(aObj.PathToFileName(), VectorGraphicDataType::Svg);
143
144 // transform into [0,0,width,width*aspect] std dimensions
145
146 basegfx::B2DRange aRange(aVectorGraphicData.getRange());
147 const double fAspectRatio(
148 aRange.getHeight() == 0.0 ? 1.0 : aRange.getWidth()/aRange.getHeight());
149 basegfx::B2DHomMatrix aTransform(
151 -aRange.getMinX(),
152 -aRange.getMinY()));
153 aTransform.scale(
154 aRange.getWidth() == 0.0 ? 1.0 : nWidth / aRange.getWidth(),
155 (aRange.getHeight() == 0.0
156 ? 1.0 : nWidth / fAspectRatio / aRange.getHeight()));
159 aTransform,
161
162 // UNO dance to render from drawinglayer
163
164 uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
165
166 try
167 {
168 const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer =
169 graphic::Primitive2DTools::create( xContext );
170
171 // cancel out rasterize's mm2pixel conversion
172 // see fFactor100th_mmToInch in
173 // drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
174 const double fFakeDPI=2.54 * 1000.0;
175
176 geometry::RealRectangle2D aRealRect(
177 0, 0,
178 nWidth, nWidth / fAspectRatio);
179
180 const uno::Reference< rendering::XBitmap > xBitmap(
181 xPrimitive2DRenderer->rasterize(
183 uno::Sequence< beans::PropertyValue >(),
184 fFakeDPI,
185 fFakeDPI,
186 aRealRect,
187 500000));
188
189 if(xBitmap.is())
190 {
191 const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
192 rBitmap = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
193 return true;
194 }
195 }
196 catch(const uno::Exception&)
197 {
198 TOOLS_WARN_EXCEPTION("sfx.appl", "Got no graphic::XPrimitive2DRenderer (!)" );
199 }
200 return false;
201}
202
205{
206 BitmapEx aBitmap;
207 SfxApplication::loadBrandSvg("shell/about", aBitmap, nWidth);
208 return aBitmap;
209}
210
211/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
static bool FileExists(const INetURLObject &rURL)
Definition: appmisc.cxx:106
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString PathToFileName() const
INetProtocol GetProtocol() const
bool IsDowning() const
Definition: appmisc.cxx:102
std::unique_ptr< SfxAppData_Impl > pImpl
Definition: app.hxx:97
SfxProgress * GetProgress() const
Returns the running SfxProgress for the entire application or 0 if none is running for the entire app...
Definition: appmisc.cxx:83
SAL_DLLPRIVATE SfxSlotPool & GetAppSlotPool_Impl() const
Definition: appmisc.cxx:104
static BitmapEx GetApplicationLogo(tools::Long nWidth)
loads the application logo as used in the impress slideshow pause screen
Definition: appmisc.cxx:204
static bool loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
Definition: appmisc.cxx:129
SAL_DLLPRIVATE SfxDispatcher * GetAppDispatcher_Impl()
Definition: appmisc.cxx:103
static SAL_DLLPRIVATE SfxModule * GetModule_Impl()
Definition: appmisc.cxx:88
static SfxModule * GetActiveModule(SfxViewFrame *pFrame=nullptr)
Definition: module.cxx:208
The class SfxShell is the base class for all classes, which provide the functionality of the form <Sl...
Definition: shell.hxx:128
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
Definition: viewfrm.cxx:1983
const std::deque< css::uno::Reference< css::graphic::XPrimitive2D > > & getPrimitive2DSequence() const
const basegfx::B2DRange & getRange() const
void scale(double fX, double fY)
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getHeight() const
css::uno::Sequence< css::uno::Reference< css::graphic::XPrimitive2D > > toSequence() const
css::uno::Any getPropertyValue(const OUString &rPropertyName)
#define TOOLS_WARN_EXCEPTION(area, stream)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
@ Exception
Reference< XComponentContext > getProcessComponentContext()
long Long
::BitmapEx bitmapExFromXBitmap(const uno::Reference< rendering::XIntegerReadOnlyBitmap > &xInputBitmap)
#define SFX_IMPL_INTERFACE(Class, SuperClass)
Definition: shell.hxx:567