Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / appl / appmisc.cxx
blobfb4a17b20a9eecd84a1b21cc76f73886d021555a
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>
22 #include <vcl/canvastools.hxx>
23 #include <vcl/status.hxx>
24 #include <vcl/msgbox.hxx>
25 #include <svl/whiter.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/intitem.hxx>
28 #include <svl/eitem.hxx>
29 #include <vcl/graphicfilter.hxx>
30 #include <unotools/pathoptions.hxx>
31 #include <com/sun/star/registry/InvalidRegistryException.hpp>
32 #include <com/sun/star/rendering/XIntegerReadOnlyBitmap.hpp>
33 #include <com/sun/star/beans/PropertyValue.hpp>
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/graphic/Primitive2DTools.hpp>
36 #include <com/sun/star/util/XURLTransformer.hpp>
37 #include <com/sun/star/frame/XFramesSupplier.hpp>
38 #include <com/sun/star/uno/Reference.h>
39 #include <tools/rcid.h>
40 #include <osl/mutex.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <com/sun/star/frame/XDesktop.hpp>
43 #include <unotools/ucbstreamhelper.hxx>
44 #include <framework/menuconfiguration.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <unotools/localfilehelper.hxx>
47 #include <unotools/bootstrap.hxx>
48 #include <unotools/moduleoptions.hxx>
49 #include <osl/file.hxx>
50 #include <osl/process.h>
51 #include <rtl/bootstrap.hxx>
53 #include <sfx2/sfxresid.hxx>
54 #include <sfx2/app.hxx>
55 #include "appdata.hxx"
56 #include <sfx2/tbxctrl.hxx>
57 #include <sfx2/stbitem.hxx>
58 #include <sfx2/mnuitem.hxx>
59 #include <sfx2/docfac.hxx>
60 #include <sfx2/docfile.hxx>
61 #include <sfx2/docfilt.hxx>
62 #include <sfx2/request.hxx>
63 #include <sfx2/bindings.hxx>
64 #include <sfx2/dispatch.hxx>
65 #include "workwin.hxx"
66 #include <sfx2/fcontnr.hxx>
67 #include "sfxlocal.hrc"
68 #include <sfx2/sfx.hrc>
69 #include "app.hrc"
70 #include <sfx2/templdlg.hxx>
71 #include <sfx2/module.hxx>
72 #include <sfx2/msgpool.hxx>
73 #include <sfx2/viewfrm.hxx>
74 #include "openflag.hxx"
75 #include <sfx2/viewsh.hxx>
76 #include <sfx2/objface.hxx>
77 #include "helper.hxx"
78 #include <basegfx/matrix/b2dhommatrixtools.hxx>
79 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::uno;
83 using namespace ::com::sun::star::util;
84 using namespace ::com::sun::star::beans;
85 using namespace ::com::sun::star::container;
87 #define SfxApplication
88 #include "sfxslots.hxx"
90 #define SFX_ITEMTYPE_STATBAR 4
92 SFX_IMPL_INTERFACE(SfxApplication,SfxShell)
94 void SfxApplication::InitInterface_Impl()
96 GetStaticInterface()->RegisterStatusBar(SfxResId(SFX_ITEMTYPE_STATBAR));
98 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_0);
99 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_1);
100 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_2);
101 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_3);
102 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_4);
103 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_5);
104 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_6);
105 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_7);
106 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_8);
107 GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_9);
110 /** Returns the running SfxProgress for the entire application or 0 if
111 none is running for the entire application.
113 [Cross-reference]
115 <SfxProgress::GetActiveProgress(SfxViewFrame*)>
116 <SfxViewFrame::GetProgress()const>
118 SfxProgress* SfxApplication::GetProgress() const
120 return pAppData_Impl->pProgress;
123 SfxModule* SfxApplication::GetModule_Impl()
125 SfxModule* pModule = SfxModule::GetActiveModule();
126 if ( !pModule )
127 pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( 0, false ) );
128 if( pModule )
129 return pModule;
130 else
132 OSL_FAIL( "No module!" );
133 return NULL;
137 bool SfxApplication::IsDowning() const { return pAppData_Impl->bDowning; }
138 SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return pAppData_Impl->pAppDispat; }
139 SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pAppData_Impl->pSlotPool; }
141 bool SfxApplication::loadBrandSvg(const char *pName, BitmapEx &rBitmap, int nWidth)
143 // Load from disk
145 OUString aBaseName = "/" + OUString::createFromAscii( pName );
147 rtl_Locale *pLoc = NULL;
148 osl_getProcessLocale (&pLoc);
149 LanguageTag aLanguageTag( *pLoc);
151 OUString uri = "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER + aBaseName + ".svg";
152 rtl::Bootstrap::expandMacros( uri );
153 INetURLObject aObj( uri );
154 SvgData aSvgData(aObj.PathToFileName());
156 // transform into [0,0,width,width*aspect] std dimensions
158 basegfx::B2DRange aRange(aSvgData.getRange());
159 const double fAspectRatio(aRange.getWidth()/aRange.getHeight());
160 basegfx::B2DHomMatrix aTransform(
161 basegfx::tools::createTranslateB2DHomMatrix(
162 -aRange.getMinX(),
163 -aRange.getMinY()));
164 aTransform.scale(
165 nWidth / aRange.getWidth(),
166 nWidth / fAspectRatio / aRange.getHeight());
167 const drawinglayer::primitive2d::Primitive2DReference xTransformRef(
168 new drawinglayer::primitive2d::TransformPrimitive2D(
169 aTransform,
170 aSvgData.getPrimitive2DSequence()));
172 // UNO dance to render from drawinglayer
174 uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
178 const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer =
179 graphic::Primitive2DTools::create( xContext );
181 // cancel out rasterize's mm2pixel conversion
182 // see fFactor100th_mmToInch in
183 // drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx
184 const double fFakeDPI=2.54 * 1000.0;
186 geometry::RealRectangle2D aRealRect(
187 0, 0,
188 nWidth, nWidth / fAspectRatio);
190 const uno::Reference< rendering::XBitmap > xBitmap(
191 xPrimitive2DRenderer->rasterize(
192 drawinglayer::primitive2d::Primitive2DSequence(&xTransformRef, 1),
193 uno::Sequence< beans::PropertyValue >(),
194 fFakeDPI,
195 fFakeDPI,
196 aRealRect,
197 500000));
199 if(xBitmap.is())
201 const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW);
203 if(xIntBmp.is())
205 rBitmap = vcl::unotools::bitmapExFromXBitmap(xIntBmp);
206 return true;
210 catch(const uno::Exception&)
212 OSL_ENSURE(false, "Got no graphic::XPrimitive2DRenderer (!)" );
214 return false;
217 /** loads the application logo as used in the impress slideshow pause screen */
218 BitmapEx SfxApplication::GetApplicationLogo(long nWidth)
220 BitmapEx aBitmap;
221 SfxApplication::loadBrandSvg("flat_logo", aBitmap, nWidth);
222 Application::LoadBrandBitmap ("about", aBitmap);
223 return aBitmap;
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */