calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / workben / mtfdemo.cxx
blob8cc9363a04de902af80589e862fc4669dd6fe14e
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/.
8 */
10 #include <comphelper/processfactory.hxx>
11 #include <cppuhelper/bootstrap.hxx>
12 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
13 #include <com/sun/star/lang/XInitialization.hpp>
14 #include <com/sun/star/registry/XSimpleRegistry.hpp>
15 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
16 #include <com/sun/star/uno/RuntimeException.hpp>
18 #include <vcl/vclmain.hxx>
19 #include <vcl/layout.hxx>
20 #include <vcl/gdimtf.hxx>
21 #include <vcl/wmf.hxx>
23 #include <comphelper/diagnose_ex.hxx>
24 #include <tools/urlobj.hxx>
25 #include <tools/stream.hxx>
26 #include <tools/vcompat.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/wrkwin.hxx>
29 #include <vcl/virdev.hxx>
30 #include <sal/log.hxx>
31 #include <osl/file.hxx>
32 #include <osl/process.h>
33 #include <framework/desktop.hxx>
34 #include <i18nlangtag/languagetag.hxx>
35 #include <i18nlangtag/mslangid.hxx>
37 #include <iostream>
39 using namespace css;
41 namespace {
43 class DemoMtfWin : public WorkWindow
45 OUString maFileName;
47 public:
48 explicit DemoMtfWin(const OUString& rFileName)
49 : WorkWindow(nullptr, WB_APP | WB_STDWORK)
51 maFileName = rFileName;
54 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
59 void DemoMtfWin::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
61 GDIMetaFile aMtf;
62 SvFileStream aFileStream(maFileName, StreamMode::READ);
64 if (aFileStream.IsOpen())
66 ReadWindowMetafile(aFileStream, aMtf);
68 else
70 Application::Abort("Can't read metafile " + aFileStream.GetFileName());
73 aMtf.Play(*GetOutDev(), aMtf.GetActionSize());
74 aMtf.Stop();
75 aFileStream.Close();
77 WorkWindow::Paint(rRenderContext, rRect);
80 namespace {
82 class DemoMtfApp : public Application
84 VclPtr<DemoMtfWin> mpWin;
85 OUString maFileName;
87 static void showHelp()
89 std::cerr << "Usage: mtfdemo --help | FILE | -d FILE" << std::endl;
90 std::cerr << "A VCL test app that displays Windows metafiles or dumps metaactions." << std::endl;
91 std::cerr << "If you want to dump as metadump.xml, use -d before FILE." << std::endl;
92 std::exit(0);
95 public:
97 DemoMtfApp()
98 : mpWin(nullptr)
102 virtual int Main() override
106 mpWin = VclPtr<DemoMtfWin>::Create(maFileName);
107 mpWin->SetText("Display metafile");
109 mpWin->Show();
111 Application::Execute();
112 mpWin.disposeAndClear();
114 catch (const css::uno::Exception&)
116 TOOLS_WARN_EXCEPTION("vcl.app", "Fatal");
117 return 1;
119 catch (const std::exception& e)
121 SAL_WARN("vcl.app", "Fatal: " << e.what());
122 return 1;
124 return 0;
127 private:
128 uno::Reference<lang::XMultiServiceFactory> xMSF;
129 void Init() override
131 LanguageTag::setConfiguredSystemLanguage(MsLangId::getSystemLanguage());
135 const sal_uInt16 nCmdParams = GetCommandLineParamCount();
136 OUString aArg, aFilename;
137 bool bDumpXML = false;
139 if (nCmdParams == 0)
141 showHelp();
142 std::exit(1);
144 else
146 aArg = GetCommandLineParam(0);
148 if (aArg == "--help" || aArg == "-h")
150 showHelp();
151 std::exit(0);
153 else if (nCmdParams > 1 && (aArg == "--dump" || aArg == "-d"))
155 aFilename = GetCommandLineParam(1);
156 bDumpXML = true;
158 else
159 aFilename = aArg;
162 OUString sWorkingDir, sFileUrl;
163 osl_getProcessWorkingDir(&sWorkingDir.pData);
164 osl::FileBase::RC rc = osl::FileBase::getFileURLFromSystemPath(aFilename, sFileUrl);
165 if (rc == osl::FileBase::E_None)
167 rc = osl::FileBase::getAbsoluteFileURL(sWorkingDir, sFileUrl, maFileName);
168 if (rc != osl::FileBase::E_None)
170 throw css::uno::RuntimeException("Can not make absolute: " + aFilename);
173 else
175 throw css::uno::RuntimeException("Can not get file url from system path: " + aFilename);
178 uno::Reference<uno::XComponentContext> xComponentContext
179 = ::cppu::defaultBootstrap_InitialComponentContext();
180 xMSF.set(xComponentContext->getServiceManager(), uno::UNO_QUERY);
181 if(!xMSF.is())
182 Application::Abort("Bootstrap failure - no service manager");
184 ::comphelper::setProcessServiceFactory(xMSF);
186 if(bDumpXML)
188 GDIMetaFile aMtf;
189 SvFileStream aFileStream(maFileName, StreamMode::READ);
191 if (aFileStream.IsOpen())
193 ReadWindowMetafile(aFileStream, aMtf);
195 else
197 throw css::uno::RuntimeException("Can't read metafile " + aFileStream.GetFileName());
200 OUString sAbsoluteDumpUrl, sDumpUrl;
201 rc = osl::FileBase::getFileURLFromSystemPath("metadump.xml", sDumpUrl);
202 if (rc == osl::FileBase::E_None)
204 rc = osl::FileBase::getAbsoluteFileURL(sWorkingDir, sDumpUrl, sAbsoluteDumpUrl);
205 if (rc != osl::FileBase::E_None)
207 throw css::uno::RuntimeException("Can not make absolute: metadump.xml");
210 else
212 throw css::uno::RuntimeException("Can not get file url from system path: metadump.xml");
215 aMtf.dumpAsXml(rtl::OUStringToOString(sAbsoluteDumpUrl, RTL_TEXTENCODING_UTF8).getStr());
216 std::cout << "Dumped metaactions as metadump.xml" << std::endl;
217 framework::getDesktop(::comphelper::getProcessComponentContext())->terminate();
218 framework::getDesktop(::comphelper::getProcessComponentContext())->disposing();
219 std::exit(0);
223 catch (const uno::Exception &e)
225 Application::Abort("Bootstrap exception " + e.Message);
229 void DeInit() override
231 framework::getDesktop(::comphelper::getProcessComponentContext())->terminate();
232 framework::getDesktop(::comphelper::getProcessComponentContext())->disposing();
234 ::comphelper::setProcessServiceFactory(nullptr);
241 void vclmain::createApplication()
243 static DemoMtfApp aApp;
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */