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 22 #include <vcl/canvastools.hxx> 23 #include <vcl/svapp.hxx> 24 #include <vcl/graphicfilter.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 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 */ 81 SfxProgress* SfxApplication::GetProgress() const 82 { 83 return pImpl->pProgress; 84 } 85 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 100 bool SfxApplication::IsDowning() const { return pImpl->bDowning; } 101 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pImpl->pAppDispat; } 102 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pImpl->pSlotPool; } 103 104 bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth) 105 { 106 // Load from disk 107 108 OUString aBaseName = "/" + OUString::createFromAscii( pName ); 109 110 OUString uri = "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER + aBaseName + ".svg"; 111 rtl::Bootstrap::expandMacros( uri ); 112 INetURLObject aObj( uri ); 113 VectorGraphicData aVectorGraphicData(aObj.PathToFileName(), VectorGraphicDataType::Svg); 114 115 // transform into [0,0,width,width*aspect] std dimensions 116 117 basegfx::B2DRange aRange(aVectorGraphicData.getRange()); 118 const double fAspectRatio( 119 aRange.getHeight() == 0.0 ? 1.0 : aRange.getWidth()/aRange.getHeight()); 120 basegfx::B2DHomMatrix aTransform( 121 basegfx::utils::createTranslateB2DHomMatrix( 122 -aRange.getMinX(), 123 -aRange.getMinY())); 124 aTransform.scale( 125 aRange.getWidth() == 0.0 ? 1.0 : nWidth / aRange.getWidth(), 126 (aRange.getHeight() == 0.0 127 ? 1.0 : nWidth / fAspectRatio / aRange.getHeight())); 128 const drawinglayer::primitive2d::Primitive2DReference xTransformRef( 129 new drawinglayer::primitive2d::TransformPrimitive2D( 130 aTransform, 131 aVectorGraphicData.getPrimitive2DSequence())); 132 133 // UNO dance to render from drawinglayer 134 135 uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext()); 136 137 try 138 { 139 const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer = 140 graphic::Primitive2DTools::create( xContext ); 141 142 // cancel out rasterize's mm2pixel conversion 143 // see fFactor100th_mmToInch in 144 // drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx 145 const double fFakeDPI=2.54 * 1000.0; 146 147 geometry::RealRectangle2D aRealRect( 148 0, 0, 149 nWidth, nWidth / fAspectRatio); 150 151 const uno::Reference< rendering::XBitmap > xBitmap( 152 xPrimitive2DRenderer->rasterize( 153 drawinglayer::primitive2d::Primitive2DSequence(&xTransformRef, 1), 154 uno::Sequence< beans::PropertyValue >(), 155 fFakeDPI, 156 fFakeDPI, 157 aRealRect, 158 500000)); 159 160 if(xBitmap.is()) 161 { 162 const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW); 163 rBitmap = vcl::unotools::bitmapExFromXBitmap(xIntBmp); 164 return true; 165 } 166 } 167 catch(const uno::Exception&) 168 { 169 OSL_ENSURE(false, "Got no graphic::XPrimitive2DRenderer (!)" ); 170 } 171 return false; 172 } 173 174 /** loads the application logo as used in the impress slideshow pause screen */ 175 BitmapEx SfxApplication::GetApplicationLogo(long nWidth) 176 { 177 BitmapEx aBitmap; 178 SfxApplication::loadBrandSvg("flat_logo", aBitmap, nWidth); 179 (void)Application::LoadBrandBitmap ("about", aBitmap); 180 return aBitmap; 181 } 182 183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 184
