/src/libreoffice/sfx2/source/appl/appmisc.cxx
Line | Count | Source |
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/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/stream.hxx> |
36 | | #include <tools/urlobj.hxx> |
37 | | |
38 | | #include <sfx2/app.hxx> |
39 | | #include <appdata.hxx> |
40 | | #include <sfx2/dispatch.hxx> |
41 | | #include <sfx2/module.hxx> |
42 | | #include <sfx2/msgpool.hxx> |
43 | | #include <sfx2/sfxsids.hrc> |
44 | | #include <sfx2/viewfrm.hxx> |
45 | | #include <sfx2/objface.hxx> |
46 | | #include <basegfx/matrix/b2dhommatrixtools.hxx> |
47 | | #include <drawinglayer/primitive2d/transformprimitive2d.hxx> |
48 | | |
49 | | #define ShellClass_SfxApplication |
50 | | #include <sfxslots.hxx> |
51 | | |
52 | | using namespace ::com::sun::star; |
53 | | using namespace ::com::sun::star::uno; |
54 | | using namespace ::com::sun::star::util; |
55 | | using namespace ::com::sun::star::beans; |
56 | | |
57 | | SFX_IMPL_INTERFACE(SfxApplication,SfxShell) |
58 | | |
59 | | void SfxApplication::InitInterface_Impl() |
60 | 21 | { |
61 | 21 | GetStaticInterface()->RegisterStatusBar(StatusBarId::GenericStatusBar); |
62 | | |
63 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_0); |
64 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_1); |
65 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_2); |
66 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_3); |
67 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_4); |
68 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_5); |
69 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_6); |
70 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_7); |
71 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_8); |
72 | 21 | GetStaticInterface()->RegisterChildWindow(SID_DOCKWIN_9); |
73 | 21 | } |
74 | | |
75 | | /** Returns the running SfxProgress for the entire application or 0 if |
76 | | none is running for the entire application. |
77 | | |
78 | | [Cross-reference] |
79 | | |
80 | | <SfxProgress::GetActiveProgress(SfxViewFrame*)> |
81 | | <SfxViewFrame::GetProgress()const> |
82 | | */ |
83 | | SfxProgress* SfxApplication::GetProgress() const |
84 | 313k | { |
85 | 313k | return pImpl->pProgress; |
86 | 313k | } |
87 | | |
88 | | SfxModule* SfxApplication::GetModule_Impl() |
89 | 0 | { |
90 | 0 | SfxModule* pModule = SfxModule::GetActiveModule(); |
91 | 0 | if ( !pModule ) |
92 | 0 | pModule = SfxModule::GetActiveModule( SfxViewFrame::GetFirst( nullptr, false ) ); |
93 | 0 | if( pModule ) |
94 | 0 | return pModule; |
95 | 0 | else |
96 | 0 | { |
97 | 0 | OSL_FAIL( "No module!" ); |
98 | 0 | return nullptr; |
99 | 0 | } |
100 | 0 | } |
101 | | |
102 | 349k | bool SfxApplication::IsDowning() const { return pImpl->bDowning; } |
103 | 0 | SfxDispatcher* SfxApplication::GetAppDispatcher_Impl() { return &*pImpl->pAppDispat; } |
104 | 147 | SfxSlotPool& SfxApplication::GetAppSlotPool_Impl() const { return *pImpl->pSlotPool; } |
105 | | |
106 | | static bool FileExists( const INetURLObject& rURL ) |
107 | 0 | { |
108 | 0 | bool bRet = false; |
109 | |
|
110 | 0 | if( rURL.GetProtocol() != INetProtocol::NotValid ) |
111 | 0 | { |
112 | 0 | try |
113 | 0 | { |
114 | 0 | ::ucbhelper::Content aCnt( rURL.GetMainURL( INetURLObject::DecodeMechanism::NONE ), uno::Reference< ucb::XCommandEnvironment >(), comphelper::getProcessComponentContext() ); |
115 | 0 | OUString aTitle; |
116 | |
|
117 | 0 | aCnt.getPropertyValue(u"Title"_ustr) >>= aTitle; |
118 | 0 | bRet = ( !aTitle.isEmpty() ); |
119 | 0 | } |
120 | 0 | catch(const Exception&) |
121 | 0 | { |
122 | 0 | return false; |
123 | 0 | } |
124 | 0 | } |
125 | | |
126 | 0 | return bRet; |
127 | 0 | } |
128 | | |
129 | | bool SfxApplication::loadBrandSvg(std::u16string_view sName, Bitmap &rBitmap, int nWidth) |
130 | 0 | { |
131 | | // Load from disk |
132 | |
|
133 | 0 | OUString aBaseName = u"/"_ustr + sName; |
134 | |
|
135 | 0 | OUString uri = "$BRAND_BASE_DIR/" LIBO_ETC_FOLDER + aBaseName + ".svg"; |
136 | 0 | rtl::Bootstrap::expandMacros( uri ); |
137 | |
|
138 | 0 | INetURLObject aObj( uri ); |
139 | 0 | if ( !FileExists(aObj) ) |
140 | 0 | return false; |
141 | | |
142 | | // Read the SVG file |
143 | 0 | SvFileStream aStream(aObj.PathToFileName(), StreamMode::STD_READ); |
144 | 0 | if (aStream.GetError()) |
145 | 0 | return false; |
146 | | |
147 | 0 | BinaryDataContainer aDataContainer(aStream, aStream.remainingSize()); |
148 | 0 | if (aStream.GetError()) |
149 | 0 | return false; |
150 | | |
151 | 0 | VectorGraphicData aVectorGraphicData(std::move(aDataContainer), VectorGraphicDataType::Svg); |
152 | | |
153 | | // transform into [0,0,width,width*aspect] std dimensions |
154 | |
|
155 | 0 | basegfx::B2DRange aRange(aVectorGraphicData.getRange()); |
156 | 0 | const double fAspectRatio( |
157 | 0 | aRange.getHeight() == 0.0 ? 1.0 : aRange.getWidth()/aRange.getHeight()); |
158 | 0 | basegfx::B2DHomMatrix aTransform( |
159 | 0 | basegfx::utils::createTranslateB2DHomMatrix( |
160 | 0 | -aRange.getMinX(), |
161 | 0 | -aRange.getMinY())); |
162 | 0 | aTransform.scale( |
163 | 0 | aRange.getWidth() == 0.0 ? 1.0 : nWidth / aRange.getWidth(), |
164 | 0 | (aRange.getHeight() == 0.0 |
165 | 0 | ? 1.0 : nWidth / fAspectRatio / aRange.getHeight())); |
166 | 0 | const drawinglayer::primitive2d::Primitive2DReference xTransformRef( |
167 | 0 | new drawinglayer::primitive2d::TransformPrimitive2D( |
168 | 0 | aTransform, |
169 | 0 | drawinglayer::primitive2d::Primitive2DContainer(aVectorGraphicData.getPrimitive2DSequence()))); |
170 | | |
171 | | // UNO dance to render from drawinglayer |
172 | |
|
173 | 0 | const uno::Reference< uno::XComponentContext >& xContext(::comphelper::getProcessComponentContext()); |
174 | |
|
175 | 0 | try |
176 | 0 | { |
177 | 0 | const uno::Reference< graphic::XPrimitive2DRenderer > xPrimitive2DRenderer = |
178 | 0 | graphic::Primitive2DTools::create( xContext ); |
179 | | |
180 | | // cancel out rasterize's mm2pixel conversion |
181 | | // see fFactor100th_mmToInch in |
182 | | // drawinglayer/source/drawinglayeruno/xprimitive2drenderer.cxx |
183 | 0 | constexpr double fFakeDPI = o3tl::convert(1.0, o3tl::Length::in, o3tl::Length::mm100); |
184 | |
|
185 | 0 | geometry::RealRectangle2D aRealRect( |
186 | 0 | 0, 0, |
187 | 0 | nWidth, nWidth / fAspectRatio); |
188 | |
|
189 | 0 | const uno::Reference< rendering::XBitmap > xBitmap( |
190 | 0 | xPrimitive2DRenderer->rasterize( |
191 | 0 | drawinglayer::primitive2d::Primitive2DContainer{xTransformRef}.toSequence(), |
192 | 0 | uno::Sequence< beans::PropertyValue >(), |
193 | 0 | fFakeDPI, |
194 | 0 | fFakeDPI, |
195 | 0 | aRealRect, |
196 | 0 | 500000)); |
197 | |
|
198 | 0 | if(xBitmap.is()) |
199 | 0 | { |
200 | 0 | const uno::Reference< rendering::XIntegerReadOnlyBitmap> xIntBmp(xBitmap, uno::UNO_QUERY_THROW); |
201 | 0 | rBitmap = vcl::unotools::bitmapFromXBitmap(xIntBmp); |
202 | 0 | return true; |
203 | 0 | } |
204 | 0 | } |
205 | 0 | catch(const uno::Exception&) |
206 | 0 | { |
207 | 0 | TOOLS_WARN_EXCEPTION("sfx.appl", "Got no graphic::XPrimitive2DRenderer (!)" ); |
208 | 0 | } |
209 | 0 | return false; |
210 | 0 | } |
211 | | |
212 | | /** loads the application logo as used in the impress slideshow pause screen */ |
213 | | Bitmap SfxApplication::GetApplicationLogo(tools::Long nWidth) |
214 | 0 | { |
215 | 0 | Bitmap aBitmap; |
216 | 0 | SfxApplication::loadBrandSvg(u"shell/about", aBitmap, nWidth); |
217 | 0 | return aBitmap; |
218 | 0 | } |
219 | | |
220 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |