tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / vcl / inc / headless / svpinst.hxx
blobf3d9205a8981fbfed0d0a2693d3bc3222d8e12f0
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 #ifndef INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
21 #define INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
23 #include <osl/thread.hxx>
24 #include <osl/conditn.hxx>
25 #include <salinst.hxx>
26 #include <saltimer.hxx>
27 #include <salusereventlist.hxx>
28 #include <unx/geninst.h>
29 #include <unx/genprn.h>
31 #include <condition_variable>
32 #include <mutex>
33 #include <queue>
35 #include <sys/time.h>
37 #ifdef IOS
38 #define SvpSalInstance AquaSalInstance
39 #endif
41 class SvpSalInstance;
42 class SvpSalTimer final : public SalTimer
44 SvpSalInstance* m_pInstance;
45 public:
46 SvpSalTimer( SvpSalInstance* pInstance ) : m_pInstance( pInstance ) {}
47 virtual ~SvpSalTimer() override;
49 // override all pure virtual methods
50 virtual void Start( sal_uInt64 nMS ) override;
51 virtual void Stop() override;
54 class SvpSalFrame;
55 class GenPspGraphics;
57 enum class SvpRequest
59 NONE,
60 MainThreadDispatchOneEvent,
61 MainThreadDispatchAllEvents,
64 class SvpSalYieldMutex final : public SalYieldMutex
66 private:
67 // note: these members might as well live in SvpSalInstance, but there is
68 // at least one subclass of SvpSalInstance (GTK3) that doesn't use them.
69 friend class SvpSalInstance;
70 // members for communication from main thread to non-main thread
71 std::mutex m_FeedbackMutex;
72 std::queue<bool> m_FeedbackPipe;
73 std::condition_variable m_FeedbackCV;
74 osl::Condition m_NonMainWaitingYieldCond;
75 // members for communication from non-main thread to main thread
76 bool m_bNoYieldLock = false; // accessed only on main thread
77 std::mutex m_WakeUpMainMutex; // guard m_wakeUpMain & m_Request
78 std::condition_variable m_WakeUpMainCond;
79 bool m_wakeUpMain = false;
80 SvpRequest m_Request = SvpRequest::NONE;
82 virtual void doAcquire( sal_uInt32 nLockCount ) override;
83 virtual sal_uInt32 doRelease( bool bUnlockAll ) override;
85 public:
86 SvpSalYieldMutex();
87 virtual ~SvpSalYieldMutex() override;
89 virtual bool IsCurrentThread() const override;
92 // NOTE: the functions IsMainThread, DoYield and Wakeup *require* the use of
93 // SvpSalYieldMutex; if a subclass uses something else it must override these
94 // (Wakeup is only called by SvpSalTimer and SvpSalFrame)
95 class VCL_DLLPUBLIC SvpSalInstance : public SalGenericInstance, public SalUserEventList
97 timeval m_aTimeout;
98 sal_uLong m_nTimeoutMS;
99 oslThreadIdentifier m_MainThread;
101 virtual void TriggerUserEventProcessing() override;
102 virtual void ProcessEvent( SalUserEvent aEvent ) override;
104 #if defined EMSCRIPTEN
105 bool DoExecute(int &nExitCode) override;
106 void DoQuit() override;
107 #endif
109 public:
110 static SvpSalInstance* s_pDefaultInstance;
112 SvpSalInstance( std::unique_ptr<SalYieldMutex> pMutex );
113 virtual ~SvpSalInstance() override;
115 SAL_DLLPRIVATE bool ImplYield(bool bWait, bool bHandleAllCurrentEvents);
117 SAL_DLLPRIVATE void CloseWakeupPipe();
118 SAL_DLLPRIVATE void Wakeup(SvpRequest request = SvpRequest::NONE);
120 SAL_DLLPRIVATE void StartTimer( sal_uInt64 nMS );
121 SAL_DLLPRIVATE void StopTimer();
123 inline void registerFrame( SalFrame* pFrame );
124 inline void deregisterFrame( SalFrame* pFrame );
126 SAL_DLLPRIVATE bool CheckTimeout( bool bExecuteTimers = true );
128 // Frame
129 SAL_DLLPRIVATE virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
130 SAL_DLLPRIVATE virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
131 virtual void DestroyFrame( SalFrame* pFrame ) override;
133 // Object (System Child Window)
134 SAL_DLLPRIVATE virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override;
135 virtual void DestroyObject( SalObject* pObject ) override;
137 // VirtualDevice
138 // nDX and nDY in Pixel
139 // nBitCount: 0 == Default(=as window) / 1 == Mono
140 // pData allows for using a system dependent graphics or device context
141 SAL_DLLPRIVATE virtual std::unique_ptr<SalVirtualDevice>
142 CreateVirtualDevice( SalGraphics& rGraphics,
143 tools::Long &nDX, tools::Long &nDY,
144 DeviceFormat eFormat, const SystemGraphicsData *pData = nullptr ) override;
146 // Printer
147 // pSetupData->mpDriverData can be 0
148 // pSetupData must be updated with the current
149 // JobSetup
150 SAL_DLLPRIVATE virtual SalInfoPrinter* CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
151 ImplJobSetup* pSetupData ) override;
152 virtual void DestroyInfoPrinter( SalInfoPrinter* pPrinter ) override;
153 SAL_DLLPRIVATE virtual std::unique_ptr<SalPrinter> CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
155 virtual void GetPrinterQueueInfo( ImplPrnQueueList* pList ) override;
156 virtual void GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) override;
157 virtual OUString GetDefaultPrinter() override;
158 virtual void PostPrintersChanged() override;
160 // SalTimer
161 SAL_DLLPRIVATE virtual SalTimer* CreateSalTimer() override;
162 // SalSystem
163 SAL_DLLPRIVATE virtual SalSystem* CreateSalSystem() override;
164 // SalBitmap
165 virtual std::shared_ptr<SalBitmap> CreateSalBitmap() override;
167 // wait next event and dispatch
168 // must returned by UserEvent (SalFrame::PostEvent)
169 // and timer
170 SAL_DLLPRIVATE virtual bool DoYield(bool bWait, bool bHandleAllCurrentEvents) override;
171 SAL_DLLPRIVATE virtual bool AnyInput( VclInputFlags nType ) override;
172 SAL_DLLPRIVATE virtual bool IsMainThread() const override;
173 virtual void updateMainThread() override;
175 virtual OUString GetConnectionIdentifier() override;
177 SAL_DLLPRIVATE virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
179 SAL_DLLPRIVATE virtual std::unique_ptr<GenPspGraphics> CreatePrintGraphics() override;
181 SAL_DLLPRIVATE virtual const cairo_font_options_t* GetCairoFontOptions() override;
184 inline void SvpSalInstance::registerFrame( SalFrame* pFrame )
186 insertFrame( pFrame );
189 inline void SvpSalInstance::deregisterFrame( SalFrame* pFrame )
191 eraseFrame( pFrame );
194 VCL_DLLPUBLIC cairo_surface_t* get_underlying_cairo_surface(const VirtualDevice& rDevice);
196 #endif // INCLUDED_VCL_INC_HEADLESS_SVPINST_HXX
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */