Fix GNU C++ version check
[LibreOffice.git] / vcl / inc / qt5 / QtInstance.hxx
blobcf2cec53f762e8326e4cdcdeadc9bc417be0e8fb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <vclpluginapi.h>
23 #include <unx/geninst.h>
24 #include <salusereventlist.hxx>
25 #include <vcl/timer.hxx>
27 #include <osl/conditn.hxx>
29 #include <QtCore/QObject>
31 #include <cstdlib>
32 #include <functional>
33 #include <memory>
34 #include <vector>
36 #include "QtFilePicker.hxx"
37 #include <salinst.hxx>
39 class QtFrame;
40 class QtTimer;
42 class QApplication;
43 class SalYieldMutex;
44 class SalFrame;
46 struct StdFreeCStr
48 void operator()(char* arg) const noexcept { std::free(arg); }
50 using FreeableCStr = std::unique_ptr<char[], StdFreeCStr>;
52 class VCLPLUG_QT_PUBLIC QtInstance : public QObject,
53 public SalGenericInstance,
54 public SalUserEventList
56 Q_OBJECT
58 osl::Condition m_aWaitingYieldCond;
59 const bool m_bUseCairo;
60 QtTimer* m_pTimer;
61 bool m_bSleeping;
62 std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> m_aClipboards;
64 std::unique_ptr<QApplication> m_pQApplication;
65 std::vector<FreeableCStr> m_pFakeArgvFreeable;
66 std::unique_ptr<char* []> m_pFakeArgv;
67 std::unique_ptr<int> m_pFakeArgc;
69 Timer m_aUpdateStyleTimer;
70 bool m_bUpdateFonts;
72 QtFrame* m_pActivePopup;
74 DECL_DLLPRIVATE_LINK(updateStyleHdl, Timer*, void);
75 void AfterAppInit() override;
77 static QWidget* GetNativeParentFromWeldParent(weld::Widget* pParent);
79 private Q_SLOTS:
80 bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
81 static void deleteObjectLater(QObject* pObject);
82 static void localeChanged();
84 void orientationChanged(Qt::ScreenOrientation);
85 void primaryScreenChanged(QScreen*);
86 void screenAdded(QScreen*);
87 void screenRemoved(QScreen*);
88 void virtualGeometryChanged(const QRect&);
90 Q_SIGNALS:
91 bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents);
92 void deleteObjectLaterSignal(QObject* pObject);
94 protected:
95 virtual rtl::Reference<QtFilePicker>
96 createPicker(css::uno::Reference<css::uno::XComponentContext> const& context,
97 QFileDialog::FileMode);
98 bool useCairo() const { return m_bUseCairo; }
99 // encodes cairo usage and Qt platform name into the ToolkitName
100 OUString constructToolkitID(std::u16string_view sTKname);
101 void connectQScreenSignals(const QScreen*);
102 void notifyDisplayChanged();
104 public:
105 explicit QtInstance(std::unique_ptr<QApplication>& pQApp);
106 virtual ~QtInstance() override;
108 // handle common SalInstance setup
109 static void AllocFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv,
110 std::unique_ptr<int>& rFakeArgc,
111 std::vector<FreeableCStr>& rFakeArgvFreeable);
112 void MoveFakeCmdlineArgs(std::unique_ptr<char* []>& rFakeArgv, std::unique_ptr<int>& rFakeArgc,
113 std::vector<FreeableCStr>& rFakeArgvFreeable);
114 static std::unique_ptr<QApplication> CreateQApplication(int& nArgc, char** pArgv);
116 void RunInMainThread(std::function<void()> func);
118 virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override;
119 virtual SalFrame* CreateChildFrame(SystemParentData* pParent,
120 SalFrameStyleFlags nStyle) override;
121 virtual void DestroyFrame(SalFrame* pFrame) override;
123 virtual SalObject* CreateObject(SalFrame* pParent, SystemWindowData* pWindowData,
124 bool bShow) override;
125 virtual void DestroyObject(SalObject* pObject) override;
127 virtual std::unique_ptr<SalVirtualDevice>
128 CreateVirtualDevice(SalGraphics& rGraphics, tools::Long& nDX, tools::Long& nDY,
129 DeviceFormat eFormat, const SystemGraphicsData* pData = nullptr) override;
131 virtual SalInfoPrinter* CreateInfoPrinter(SalPrinterQueueInfo* pQueueInfo,
132 ImplJobSetup* pSetupData) override;
133 virtual void DestroyInfoPrinter(SalInfoPrinter* pPrinter) override;
134 virtual std::unique_ptr<SalPrinter> CreatePrinter(SalInfoPrinter* pInfoPrinter) override;
135 virtual void GetPrinterQueueInfo(ImplPrnQueueList* pList) override;
136 virtual void GetPrinterQueueState(SalPrinterQueueInfo* pInfo) override;
137 virtual OUString GetDefaultPrinter() override;
138 virtual void PostPrintersChanged() override;
140 virtual std::unique_ptr<SalMenu> CreateMenu(bool, Menu*) override;
141 virtual std::unique_ptr<SalMenuItem> CreateMenuItem(const SalItemParams&) override;
143 virtual SalTimer* CreateSalTimer() override;
144 virtual SalSystem* CreateSalSystem() override;
145 virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
147 virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
148 virtual bool AnyInput(VclInputFlags nType) override;
150 std::unique_ptr<weld::Builder> CreateBuilder(weld::Widget* pParent, const OUString& rUIRoot,
151 const OUString& rUIFile) override;
152 virtual weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent,
153 VclMessageType eMessageType,
154 VclButtonsType eButtonType,
155 const OUString& rPrimaryMessage) override;
157 // so we fall back to the default abort, instead of duplicating it...
158 #ifndef EMSCRIPTEN
159 virtual OpenGLContext* CreateOpenGLContext() override;
160 #endif
162 virtual OUString GetConnectionIdentifier() override;
164 virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType,
165 const OUString& rDocumentService) override;
167 virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
169 virtual bool IsMainThread() const override;
171 virtual void TriggerUserEventProcessing() override;
172 virtual void ProcessEvent(SalUserEvent aEvent) override;
174 bool hasNativeFileSelection() const override { return true; }
175 css::uno::Reference<css::ui::dialogs::XFilePicker2>
176 createFilePicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
177 css::uno::Reference<css::ui::dialogs::XFolderPicker2>
178 createFolderPicker(const css::uno::Reference<css::uno::XComponentContext>&) override;
180 virtual css::uno::Reference<css::uno::XInterface>
181 CreateClipboard(const css::uno::Sequence<css::uno::Any>& i_rArguments) override;
182 virtual css::uno::Reference<css::uno::XInterface>
183 ImplCreateDragSource(const SystemEnvData*) override;
184 virtual css::uno::Reference<css::uno::XInterface>
185 ImplCreateDropTarget(const SystemEnvData*) override;
187 // whether to reduce animations; KFSalInstance overrides this to read Plasma settings
188 virtual bool GetUseReducedAnimation() { return false; }
189 void UpdateStyle(bool bFontsChanged);
191 void* CreateGStreamerSink(const SystemChildWindow*) override;
193 bool DoExecute(int& nExitCode) override;
194 void DoQuit() override;
196 QtFrame* activePopup() const { return m_pActivePopup; }
197 void setActivePopup(QtFrame*);
200 inline QtInstance& GetQtInstance()
202 QtInstance* pInstance = static_cast<QtInstance*>(GetSalInstance());
203 assert(pInstance);
204 return *pInstance;
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */