LibreOffice Module vcl (master)  1
previewer.cxx
Go to the documentation of this file.
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 
10 #include <com/sun/star/lang/XComponent.hpp>
11 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
12 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
13 #include <com/sun/star/ucb/UniversalContentBroker.hpp>
15 #include <cppuhelper/bootstrap.hxx>
16 #include <osl/file.hxx>
17 #include <vcl/builder.hxx>
18 #include <vcl/dialog.hxx>
19 #include <vcl/help.hxx>
20 #include <vcl/svapp.hxx>
21 #include <vcl/vclmain.hxx>
22 
23 class UIPreviewApp : public Application
24 {
25 public:
26  virtual void Init() override;
27  virtual int Main() override;
28 };
29 
30 using namespace com::sun::star;
31 
33 {
34  uno::Reference<uno::XComponentContext> xContext =
36  uno::Reference<lang::XMultiComponentFactory> xFactory =
37  xContext->getServiceManager();
38  uno::Reference<lang::XMultiServiceFactory> xSFactory(xFactory, uno::UNO_QUERY_THROW);
40 
41  // Create UCB (for backwards compatibility, in case some code still uses
42  // plain createInstance w/o args directly to obtain an instance):
43  ::ucb::UniversalContentBroker::create(
45 }
46 
48 {
49  std::vector<OUString> uifiles;
50  for (sal_uInt16 i = 0; i < GetCommandLineParamCount(); ++i)
51  {
52  OUString aFileUrl;
53  osl::File::getFileURLFromSystemPath(GetCommandLineParam(i), aFileUrl);
54  uifiles.push_back(aFileUrl);
55  }
56 
57  if (uifiles.empty())
58  {
59  fprintf(stderr, "Usage: ui-previewer file.ui\n");
60  return EXIT_FAILURE;
61  }
62 
63  // turn on tooltips
65 
66  int nRet = EXIT_SUCCESS;
67 
68  try
69  {
71  {
72  VclBuilder aBuilder(pDialog, OUString(), uifiles[0]);
73  vcl::Window *pRoot = aBuilder.get_widget_root();
74  Dialog *pRealDialog = dynamic_cast<Dialog*>(pRoot);
75 
76  if (!pRealDialog)
77  pRealDialog = pDialog;
78 
79  pRealDialog->SetText("LibreOffice ui-previewer");
80  pRealDialog->SetStyle(pDialog->GetStyle()|WB_CLOSEABLE);
81  /*
82  Force a new StateChangedType::InitShow for the edge case where pRoot
83  is not a dialog or contents of a dialog, but instead a visible floating window
84  which may have had initshow already done before it was given children
85  */
86  pRoot->Hide();
87  pRoot->Show();
88  pRealDialog->Execute();
89  }
90 
91  pDialog.disposeAndClear();
92  }
93  catch (const uno::Exception &e)
94  {
95  fprintf(stderr, "fatal error: %s\n", OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
96  nRet = EXIT_FAILURE;
97  }
98  catch (const std::exception &e)
99  {
100  fprintf(stderr, "fatal error: %s\n", e.what());
101  nRet = EXIT_FAILURE;
102  }
103 
104  return nRet;
105 }
106 
108 {
109  static UIPreviewApp aApp;
110 }
111 
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void disposeAndClear()
Definition: vclptr.hxx:200
void Hide()
Definition: window.hxx:930
void createApplication()
Definition: previewer.cxx:107
int i
vcl::Window * get_widget_root()
Definition: builder.cxx:4106
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
Base class used mainly for the LibreOffice Desktop class.
Definition: svapp.hxx:238
void SetStyle(WinBits nStyle)
Definition: window.cxx:1925
virtual short Execute()
Definition: dialog.cxx:1058
virtual void Init() override
Initialize the application itself.
Definition: previewer.cxx:32
void setProcessServiceFactory(const Reference< XMultiServiceFactory > &xSMgr)
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
WinBits const WB_SIZEABLE
A construction helper for a temporary VclPtr.
Definition: vclptr.hxx:275
WinBits const WB_STDDIALOG
virtual int Main() override
Pure virtual entrypoint to the application.
Definition: previewer.cxx:47
virtual void SetText(const OUString &rStr) override
Definition: syswin.cxx:1099
Reference< XComponentContext > getProcessComponentContext()
static void EnableQuickHelp()
Definition: help.cxx:163
WinBits GetStyle() const
Definition: window2.cxx:947
WinBits const WB_CLOSEABLE
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2150