LibreOffice Module vcl (master)  1
Qt5Instance.hxx
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  * 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 #pragma once
21 
22 #include <vclpluginapi.h>
23 #include <unx/geninst.h>
24 #include <salusereventlist.hxx>
25 #include <vcl/timer.hxx>
26 
27 #include <osl/conditn.hxx>
28 
29 #include <QtCore/QObject>
30 
31 #include <cstdlib>
32 #include <functional>
33 #include <memory>
34 #include <vector>
35 
36 #include "Qt5FilePicker.hxx"
37 
38 class QApplication;
39 class SalYieldMutex;
40 class SalFrame;
41 
43 {
44  void operator()(char* arg) const noexcept { std::free(arg); }
45 };
46 using FreeableCStr = std::unique_ptr<char[], StdFreeCStr>;
47 
48 class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject,
49  public SalGenericInstance,
50  public SalUserEventList
51 {
52  Q_OBJECT
53 
54  osl::Condition m_aWaitingYieldCond;
56  const bool m_bUseCairo;
57  std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> m_aClipboards;
58 
59  std::unique_ptr<QApplication> m_pQApplication;
60  std::vector<FreeableCStr> m_pFakeArgvFreeable;
61  std::unique_ptr<char* []> m_pFakeArgv;
62  std::unique_ptr<int> m_pFakeArgc;
63 
66 
67  DECL_LINK(updateStyleHdl, Timer*, void);
68  void AfterAppInit() override;
69 
70 private Q_SLOTS:
71  bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
72  void ImplRunInMain();
73  static void deleteObjectLater(QObject* pObject);
74 
75 Q_SIGNALS:
76  bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents);
77  void ImplRunInMainSignal();
78  void deleteObjectLaterSignal(QObject* pObject);
79 
80 protected:
81  virtual Qt5FilePicker*
82  createPicker(css::uno::Reference<css::uno::XComponentContext> const& context,
83  QFileDialog::FileMode);
84 
85 public:
86  explicit Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo = false);
87  virtual ~Qt5Instance() override;
88 
89  // handle common SalInstance setup
90  static void AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv,
91  std::unique_ptr<int>& rFakeArgc,
92  std::vector<FreeableCStr>& rFakeArgvFreeable);
93  void MoveFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, std::unique_ptr<int>& rFakeArgc,
94  std::vector<FreeableCStr>& rFakeArgvFreeable);
95  static std::unique_ptr<QApplication> CreateQApplication(int& nArgc, char** pArgv);
96 
97  void RunInMainThread(std::function<void()> func);
98 
99  virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override;
100  virtual SalFrame* CreateChildFrame(SystemParentData* pParent,
101  SalFrameStyleFlags nStyle) override;
102  virtual void DestroyFrame(SalFrame* pFrame) override;
103 
104  virtual SalObject* CreateObject(SalFrame* pParent, SystemWindowData* pWindowData,
105  bool bShow) override;
106  virtual void DestroyObject(SalObject* pObject) override;
107 
108  virtual std::unique_ptr<SalVirtualDevice>
109  CreateVirtualDevice(SalGraphics* pGraphics, long& nDX, long& nDY, DeviceFormat eFormat,
110  const SystemGraphicsData* pData = nullptr) override;
111 
113  ImplJobSetup* pSetupData) override;
114  virtual void DestroyInfoPrinter(SalInfoPrinter* pPrinter) override;
115  virtual std::unique_ptr<SalPrinter> CreatePrinter(SalInfoPrinter* pInfoPrinter) override;
116  virtual void GetPrinterQueueInfo(ImplPrnQueueList* pList) override;
117  virtual void GetPrinterQueueState(SalPrinterQueueInfo* pInfo) override;
118  virtual OUString GetDefaultPrinter() override;
119  virtual void PostPrintersChanged() override;
120 
121  virtual std::unique_ptr<SalMenu> CreateMenu(bool, Menu*) override;
122  virtual std::unique_ptr<SalMenuItem> CreateMenuItem(const SalItemParams&) override;
123 
124  virtual SalTimer* CreateSalTimer() override;
125  virtual SalSystem* CreateSalSystem() override;
126  virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
127 
128  virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
129  virtual bool AnyInput(VclInputFlags nType) override;
130 
131  virtual OpenGLContext* CreateOpenGLContext() override;
132 
133  virtual OUString GetConnectionIdentifier() override;
134 
135  virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType,
136  const OUString& rDocumentService) override;
137 
138  virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
139 
140  virtual bool IsMainThread() const override;
141 
142  virtual void TriggerUserEventProcessing() override;
143  virtual void ProcessEvent(SalUserEvent aEvent) override;
144 
145  bool hasNativeFileSelection() const override { return true; }
146  css::uno::Reference<css::ui::dialogs::XFilePicker2>
147  createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
148  css::uno::Reference<css::ui::dialogs::XFolderPicker2>
149  createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
150 
151  virtual css::uno::Reference<css::uno::XInterface>
152  CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) override;
153  virtual css::uno::Reference<css::uno::XInterface> CreateDragSource() override;
154  virtual css::uno::Reference<css::uno::XInterface> CreateDropTarget() override;
155 
156  void UpdateStyle(bool bFontsChanged);
157 
158  void* CreateGStreamerSink(const SystemChildWindow*) override;
159 };
160 
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget()
Definition: dtranscomp.cxx:451
virtual OpenGLContext * CreateOpenGLContext()=0
virtual css::uno::Reference< css::uno::XInterface > CreateClipboard(const css::uno::Sequence< css::uno::Any > &i_rArguments)
Definition: dtranscomp.cxx:441
virtual SalFrame * CreateChildFrame(SystemParentData *pParent, SalFrameStyleFlags nStyle)=0
virtual bool IsMainThread() const =0
virtual css::uno::Reference< css::ui::dialogs::XFilePicker2 > createFilePicker(const css::uno::Reference< css::uno::XComponentContext > &)
Definition: salinst.hxx:189
virtual std::unique_ptr< SalPrinter > CreatePrinter(SalInfoPrinter *pInfoPrinter) override
void operator()(char *arg) const noexcept
Definition: Qt5Instance.hxx:44
virtual std::unique_ptr< SalMenuItem > CreateMenuItem(const SalItemParams &pItemData)
Definition: salvtables.cxx:141
#define VCLPLUG_QT5_PUBLIC
Definition: vclpluginapi.h:53
virtual bool AnyInput(VclInputFlags nType)=0
virtual void GetPrinterQueueInfo(ImplPrnQueueList *pList) override
virtual css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &)
Definition: salinst.hxx:191
static bool ImplYield(bool i_bWait, bool i_bAllEvents)
Definition: svapp.cxx:431
VclInputFlags
Definition: inputtypes.hxx:25
virtual css::uno::Reference< css::uno::XInterface > CreateDragSource()
Definition: dtranscomp.cxx:446
bool m_bUpdateFonts
Definition: Qt5Instance.hxx:65
std::unique_ptr< QApplication > m_pQApplication
Definition: Qt5Instance.hxx:59
const bool m_bUseCairo
Definition: Qt5Instance.hxx:56
int m_postUserEventId
Definition: Qt5Instance.hxx:55
virtual SalTimer * CreateSalTimer()=0
Timer m_aUpdateStyleTimer
Definition: Qt5Instance.hxx:64
virtual void DestroyObject(SalObject *pObject)=0
std::unordered_map< OUString, css::uno::Reference< css::uno::XInterface > > m_aClipboards
Definition: Qt5Instance.hxx:57
virtual void AfterAppInit()
Definition: salinst.hxx:91
virtual SalFrame * CreateFrame(SalFrame *pParent, SalFrameStyleFlags nStyle)=0
virtual SalSystem * CreateSalSystem()=0
virtual std::unique_ptr< SalVirtualDevice > CreateVirtualDevice(SalGraphics *pGraphics, long &rDX, long &rDY, DeviceFormat eFormat, const SystemGraphicsData *pData=nullptr)=0
virtual std::unique_ptr< GenPspGraphics > CreatePrintGraphics()=0
virtual void DestroyFrame(SalFrame *pFrame)=0
virtual void ProcessEvent(SalUserEvent aEvent)=0
std::unique_ptr< int > m_pFakeArgc
Definition: Qt5Instance.hxx:62
std::unique_ptr< char[], StdFreeCStr > FreeableCStr
Definition: Qt5Instance.hxx:46
virtual void * CreateGStreamerSink(const SystemChildWindow *)
Definition: salinst.hxx:206
DeviceFormat
Definition: salgtype.hxx:28
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
Definition: menu.hxx:121
virtual SalInfoPrinter * CreateInfoPrinter(SalPrinterQueueInfo *pQueueInfo, ImplJobSetup *pSetupData) override
virtual OUString GetDefaultPrinter() override
virtual std::shared_ptr< SalBitmap > CreateSalBitmap()=0
virtual void TriggerUserEventProcessing()=0
SalFrameStyleFlags
Definition: salframe.hxx:64
virtual void GetPrinterQueueState(SalPrinterQueueInfo *pInfo) override
virtual void AddToRecentDocumentList(const OUString &rFileUrl, const OUString &rMimeType, const OUString &rDocumentService)=0
virtual std::unique_ptr< SalMenu > CreateMenu(bool bMenuBar, Menu *pMenu)
Definition: salvtables.cxx:135
bool hasNativeFileSelection() const override
virtual OUString GetConnectionIdentifier()=0
virtual void DestroyInfoPrinter(SalInfoPrinter *pPrinter) override
Definition: timer.hxx:26
virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents)=0
Wait for the next event (if bWait) and dispatch it, includes posted events, and timers.
std::vector< FreeableCStr > m_pFakeArgvFreeable
Definition: Qt5Instance.hxx:60
std::unique_ptr< char *[]> m_pFakeArgv
Definition: Qt5Instance.hxx:61
osl::Condition m_aWaitingYieldCond
Definition: Qt5Instance.hxx:54
virtual void PostPrintersChanged()=0
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow)=0