tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sfx2 / source / appl / appmisc.cxx
blob0e84d5d1e90dec08d1e7746dc6ce4ff5d107b4a4
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/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.
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; }
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(u"Title"_ustr) >>= 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 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(
176 0, 0,
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 >(),
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 TOOLS_WARN_EXCEPTION("sfx.appl", "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: */