1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 .
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>
36 #include "QtFilePicker.hxx"
37 #include <salinst.hxx>
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
58 osl::Condition m_aWaitingYieldCond
;
59 const bool m_bUseCairo
;
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
;
72 QtFrame
* m_pActivePopup
;
74 DECL_DLLPRIVATE_LINK(updateStyleHdl
, Timer
*, void);
75 void AfterAppInit() override
;
77 static QWidget
* GetNativeParentFromWeldParent(weld::Widget
* pParent
);
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
&);
91 bool ImplYieldSignal(bool bWait
, bool bHandleAllCurrentEvents
);
92 void deleteObjectLaterSignal(QObject
* pObject
);
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();
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...
159 virtual OpenGLContext
* CreateOpenGLContext() override
;
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());
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */