Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / qt5 / QtInstance.hxx
blob2073c8ac05d8bee644d79e494862aaf958015a3b
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/.
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"
38 class QtFrame;
39 class QtTimer;
41 class QApplication;
42 class SalYieldMutex;
43 class SalFrame;
45 struct StdFreeCStr
47 void operator()(char* arg) const noexcept { std::free(arg); }
49 using FreeableCStr = std::unique_ptr<char[], StdFreeCStr>;
51 class VCLPLUG_QT_PUBLIC QtInstance : public QObject,
52 public SalGenericInstance,
53 public SalUserEventList
55 Q_OBJECT
57 osl::Condition m_aWaitingYieldCond;
58 const bool m_bUseCairo;
59 QtTimer* m_pTimer;
60 bool m_bSleeping;
61 std::unordered_map<OUString, css::uno::Reference<css::uno::XInterface>> m_aClipboards;
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;
68 Timer m_aUpdateStyleTimer;
69 bool m_bUpdateFonts;
71 QtFrame* m_pActivePopup;
73 DECL_DLLPRIVATE_LINK(updateStyleHdl, Timer*, void);
74 void AfterAppInit() override;
76 private Q_SLOTS:
77 bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
78 static void deleteObjectLater(QObject* pObject);
79 static void localeChanged();
81 void orientationChanged(Qt::ScreenOrientation);
82 void primaryScreenChanged(QScreen*);
83 void screenAdded(QScreen*);
84 void screenRemoved(QScreen*);
85 void virtualGeometryChanged(const QRect&);
87 Q_SIGNALS:
88 bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents);
89 void deleteObjectLaterSignal(QObject* pObject);
91 protected:
92 virtual rtl::Reference<QtFilePicker>
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*);
99 void notifyDisplayChanged();
101 public:
102 explicit QtInstance(std::unique_ptr<QApplication>& pQApp);
103 virtual ~QtInstance() override;
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);
113 void RunInMainThread(std::function<void()> func);
115 virtual SalFrame* CreateFrame(SalFrame* pParent, SalFrameStyleFlags nStyle) override;
116 virtual SalFrame* CreateChildFrame(SystemParentData* pParent,
117 SalFrameStyleFlags nStyle) override;
118 virtual void DestroyFrame(SalFrame* pFrame) override;
120 virtual SalObject* CreateObject(SalFrame* pParent, SystemWindowData* pWindowData,
121 bool bShow) override;
122 virtual void DestroyObject(SalObject* pObject) override;
124 virtual std::unique_ptr<SalVirtualDevice>
125 CreateVirtualDevice(SalGraphics& rGraphics, tools::Long& nDX, tools::Long& nDY,
126 DeviceFormat eFormat, const SystemGraphicsData* pData = nullptr) override;
128 virtual SalInfoPrinter* CreateInfoPrinter(SalPrinterQueueInfo* pQueueInfo,
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;
137 virtual std::unique_ptr<SalMenu> CreateMenu(bool, Menu*) override;
138 virtual std::unique_ptr<SalMenuItem> CreateMenuItem(const SalItemParams&) override;
140 virtual SalTimer* CreateSalTimer() override;
141 virtual SalSystem* CreateSalSystem() override;
142 virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
144 virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
145 virtual bool AnyInput(VclInputFlags nType) override;
147 // so we fall back to the default abort, instead of duplicating it...
148 #ifndef EMSCRIPTEN
149 virtual OpenGLContext* CreateOpenGLContext() override;
150 #endif
152 virtual OUString GetConnectionIdentifier() override;
154 virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType,
155 const OUString& rDocumentService) override;
157 virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
159 virtual bool IsMainThread() const override;
161 virtual void TriggerUserEventProcessing() override;
162 virtual void ProcessEvent(SalUserEvent aEvent) override;
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;
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>
173 ImplCreateDragSource(const SystemEnvData*) override;
174 virtual css::uno::Reference<css::uno::XInterface>
175 ImplCreateDropTarget(const SystemEnvData*) override;
177 // whether to reduce animations; KFSalInstance overrides this to read Plasma settings
178 virtual bool GetUseReducedAnimation() { return false; }
179 void UpdateStyle(bool bFontsChanged);
181 void* CreateGStreamerSink(const SystemChildWindow*) override;
183 bool DoExecute(int& nExitCode) override;
184 void DoQuit() override;
186 QtFrame* activePopup() const { return m_pActivePopup; }
187 void setActivePopup(QtFrame*);
190 inline QtInstance* GetQtInstance() { return static_cast<QtInstance*>(GetSalInstance()); }
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */