LibreOffice Module vcl (master) 1
qt5/QtInstance.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 "QtFilePicker.hxx"
37
38class QtFrame;
39class QtTimer;
40
41class QApplication;
42class SalYieldMutex;
43class SalFrame;
44
46{
47 void operator()(char* arg) const noexcept { std::free(arg); }
48};
49using FreeableCStr = std::unique_ptr<char[], StdFreeCStr>;
50
51class VCLPLUG_QT_PUBLIC QtInstance : public QObject,
52 public SalGenericInstance,
53 public SalUserEventList
54{
55 Q_OBJECT
56
57 osl::Condition m_aWaitingYieldCond;
58 const bool m_bUseCairo;
61 std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> m_aClipboards;
62
63 std::unique_ptr<QApplication> m_pQApplication;
64 std::vector<FreeableCStr> m_pFakeArgvFreeable;
65 std::unique_ptr<char* []> m_pFakeArgv;
66 std::unique_ptr<int> m_pFakeArgc;
67
70
72
73 DECL_DLLPRIVATE_LINK(updateStyleHdl, Timer*, void);
74 void AfterAppInit() override;
75
76private Q_SLOTS:
77 bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
78 static void deleteObjectLater(QObject* pObject);
79 static void localeChanged();
80
81 void orientationChanged(Qt::ScreenOrientation);
82 void primaryScreenChanged(QScreen*);
83 void screenAdded(QScreen*);
84 void screenRemoved(QScreen*);
85 void virtualGeometryChanged(const QRect&);
86
87Q_SIGNALS:
88 bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents);
89 void deleteObjectLaterSignal(QObject* pObject);
90
91protected:
93 createPicker(css::uno::Reference<css::uno::XComponentContext> const& context,
94 QFileDialog::FileMode);
95 bool useCairo() const { return m_bUseCairo; }
96 // encodes cairo usage and Qt platform name into the ToolkitName
97 OUString constructToolkitID(std::u16string_view sTKname);
98 void connectQScreenSignals(const QScreen*);
100
101public:
102 explicit QtInstance(std::unique_ptr<QApplication>& pQApp);
103 virtual ~QtInstance() override;
104
105 // handle common SalInstance setup
106 static void AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv,
107 std::unique_ptr<int>& rFakeArgc,
108 std::vector<FreeableCStr>& rFakeArgvFreeable);
109 void MoveFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, std::unique_ptr<int>& rFakeArgc,
110 std::vector<FreeableCStr>& rFakeArgvFreeable);
111 static std::unique_ptr<QApplication> CreateQApplication(int& nArgc, char** pArgv);
112
113 void RunInMainThread(std::function<void()> func);
114
115 virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override;
117 SalFrameStyleFlags nStyle) override;
118 virtual void DestroyFrame(SalFrame* pFrame) override;
119
120 virtual SalObject* CreateObject(SalFrame* pParent, SystemWindowData* pWindowData,
121 bool bShow) override;
122 virtual void DestroyObject(SalObject* pObject) override;
123
124 virtual std::unique_ptr<SalVirtualDevice>
126 DeviceFormat eFormat, const SystemGraphicsData* pData = nullptr) override;
127
129 ImplJobSetup* pSetupData) override;
130 virtual void DestroyInfoPrinter(SalInfoPrinter* pPrinter) override;
131 virtual std::unique_ptr<SalPrinter> CreatePrinter(SalInfoPrinter* pInfoPrinter) override;
132 virtual void GetPrinterQueueInfo(ImplPrnQueueList* pList) override;
133 virtual void GetPrinterQueueState(SalPrinterQueueInfo* pInfo) override;
134 virtual OUString GetDefaultPrinter() override;
135 virtual void PostPrintersChanged() override;
136
137 virtual std::unique_ptr<SalMenu> CreateMenu(bool, Menu*) override;
138 virtual std::unique_ptr<SalMenuItem> CreateMenuItem(const SalItemParams&) override;
139
140 virtual SalTimer* CreateSalTimer() override;
141 virtual SalSystem* CreateSalSystem() override;
142 virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
143
144 virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
145 virtual bool AnyInput(VclInputFlags nType) override;
146
147// so we fall back to the default abort, instead of duplicating it...
148#ifndef EMSCRIPTEN
150#endif
151
152 virtual OUString GetConnectionIdentifier() override;
153
154 virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType,
155 const OUString& rDocumentService) override;
156
157 virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
158
159 virtual bool IsMainThread() const override;
160
161 virtual void TriggerUserEventProcessing() override;
162 virtual void ProcessEvent(SalUserEvent aEvent) override;
163
164 bool hasNativeFileSelection() const override { return true; }
165 css::uno::Reference<css::ui::dialogs::XFilePicker2>
166 createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
167 css::uno::Reference<css::ui::dialogs::XFolderPicker2>
168 createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
169
170 virtual css::uno::Reference<css::uno::XInterface>
171 CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) override;
172 virtual css::uno::Reference<css::uno::XInterface>
174 virtual css::uno::Reference<css::uno::XInterface>
176
177 // whether to reduce animations; KFSalInstance overrides this to read Plasma settings
178 virtual bool GetUseReducedAnimation() { return false; }
179 void UpdateStyle(bool bFontsChanged);
180
182
183 bool DoExecute(int& nExitCode) override;
184 void DoQuit() override;
185
186 QtFrame* activePopup() const { return m_pActivePopup; }
188};
189
190inline QtInstance* GetQtInstance() { return static_cast<QtInstance*>(GetSalInstance()); }
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: menu.hxx:116
const bool m_bUseCairo
void setActivePopup(QtFrame *)
virtual css::uno::Reference< css::uno::XInterface > CreateClipboard(const css::uno::Sequence< css::uno::Any > &i_rArguments) override
static void AllocFakeCmdlineArgs(std::unique_ptr< char *[]> &rFakeArgv, std::unique_ptr< int > &rFakeArgc, std::vector< FreeableCStr > &rFakeArgvFreeable)
virtual ~QtInstance() override
virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override
Wait for the next event (if bWait) and dispatch it, includes posted events, and timers.
virtual SalFrame * CreateChildFrame(SystemParentData *pParent, SalFrameStyleFlags nStyle) override
virtual std::shared_ptr< SalBitmap > CreateSalBitmap() override
osl::Condition m_aWaitingYieldCond
virtual rtl::Reference< QtFilePicker > createPicker(css::uno::Reference< css::uno::XComponentContext > const &context, QFileDialog::FileMode)
virtual SalInfoPrinter * CreateInfoPrinter(SalPrinterQueueInfo *pQueueInfo, ImplJobSetup *pSetupData) override
void virtualGeometryChanged(const QRect &)
static void deleteObjectLater(QObject *pObject)
Timer m_aUpdateStyleTimer
virtual void GetPrinterQueueInfo(ImplPrnQueueList *pList) override
DECL_DLLPRIVATE_LINK(updateStyleHdl, Timer *, void)
void orientationChanged(Qt::ScreenOrientation)
std::unique_ptr< int > m_pFakeArgc
bool hasNativeFileSelection() const override
void screenAdded(QScreen *)
virtual std::unique_ptr< SalMenu > CreateMenu(bool, Menu *) override
virtual void ProcessEvent(SalUserEvent aEvent) override
virtual OUString GetConnectionIdentifier() override
void primaryScreenChanged(QScreen *)
void deleteObjectLaterSignal(QObject *pObject)
QtFrame * m_pActivePopup
virtual std::unique_ptr< SalVirtualDevice > CreateVirtualDevice(SalGraphics &rGraphics, tools::Long &nDX, tools::Long &nDY, DeviceFormat eFormat, const SystemGraphicsData *pData=nullptr) override
virtual SalFrame * CreateFrame(SalFrame *pParent, SalFrameStyleFlags nStyle) override
void RunInMainThread(std::function< void()> func)
bool useCairo() const
static void localeChanged()
std::unique_ptr< QApplication > m_pQApplication
virtual std::unique_ptr< GenPspGraphics > CreatePrintGraphics() override
QtFrame * activePopup() const
bool DoExecute(int &nExitCode) override
virtual std::unique_ptr< SalMenuItem > CreateMenuItem(const SalItemParams &) override
bool ImplYield(bool bWait, bool bHandleAllCurrentEvents)
void MoveFakeCmdlineArgs(std::unique_ptr< char *[]> &rFakeArgv, std::unique_ptr< int > &rFakeArgc, std::vector< FreeableCStr > &rFakeArgvFreeable)
bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents)
virtual void TriggerUserEventProcessing() override
QtTimer * m_pTimer
css::uno::Reference< css::ui::dialogs::XFolderPicker2 > createFolderPicker(const css::uno::Reference< css::uno::XComponentContext > &) override
virtual void PostPrintersChanged() override
void AfterAppInit() override
void UpdateStyle(bool bFontsChanged)
std::vector< FreeableCStr > m_pFakeArgvFreeable
void DoQuit() override
virtual bool AnyInput(VclInputFlags nType) override
virtual void DestroyObject(SalObject *pObject) override
std::unordered_map< OUString, css::uno::Reference< css::uno::XInterface > > m_aClipboards
virtual SalTimer * CreateSalTimer() override
virtual OpenGLContext * CreateOpenGLContext() override
virtual void GetPrinterQueueState(SalPrinterQueueInfo *pInfo) override
css::uno::Reference< css::ui::dialogs::XFilePicker2 > createFilePicker(const css::uno::Reference< css::uno::XComponentContext > &) override
virtual bool IsMainThread() const override
QtInstance(std::unique_ptr< QApplication > &pQApp)
void notifyDisplayChanged()
virtual bool GetUseReducedAnimation()
static std::unique_ptr< QApplication > CreateQApplication(int &nArgc, char **pArgv)
virtual SalObject * CreateObject(SalFrame *pParent, SystemWindowData *pWindowData, bool bShow) override
virtual OUString GetDefaultPrinter() override
void screenRemoved(QScreen *)
OUString constructToolkitID(std::u16string_view sTKname)
virtual void DestroyInfoPrinter(SalInfoPrinter *pPrinter) override
std::unique_ptr< char *[]> m_pFakeArgv
virtual std::unique_ptr< SalPrinter > CreatePrinter(SalInfoPrinter *pInfoPrinter) override
virtual void AddToRecentDocumentList(const OUString &rFileUrl, const OUString &rMimeType, const OUString &rDocumentService) override
virtual SalSystem * CreateSalSystem() override
virtual void DestroyFrame(SalFrame *pFrame) override
void connectQScreenSignals(const QScreen *)
virtual css::uno::Reference< css::uno::XInterface > ImplCreateDragSource(const SystemEnvData *) override
void * CreateGStreamerSink(const SystemChildWindow *) override
virtual css::uno::Reference< css::uno::XInterface > ImplCreateDropTarget(const SystemEnvData *) override
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
Definition: timer.hxx:27
VclInputFlags
Definition: inputtypes.hxx:25
long Long
std::unique_ptr< char[], StdFreeCStr > FreeableCStr
QtInstance * GetQtInstance()
SalFrameStyleFlags
Definition: salframe.hxx:65
DeviceFormat
Definition: salgtype.hxx:28
void operator()(char *arg) const noexcept
SalInstance * GetSalInstance()
Definition: svdata.hxx:473
#define VCLPLUG_QT_PUBLIC
Definition: vclpluginapi.h:53