Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / vcl / inc / unx / gtk / gtkinst.hxx
blob250fd9b1ca1b30fd89653d3861e1f8eec7ec69b1
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_UNX_GTK_GTKINST_HXX
21 #define INCLUDED_VCL_INC_UNX_GTK_GTKINST_HXX
23 #include <sal/config.h>
25 #include <stack>
27 #include <unx/salinst.h>
28 #include <unx/gensys.h>
29 #include <headless/svpinst.hxx>
30 #include <com/sun/star/datatransfer/DataFlavor.hpp>
31 #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
32 #include <com/sun/star/datatransfer/dnd/XDropTarget.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <cppuhelper/compbase.hxx>
36 #include <gtk/gtk.h>
38 namespace vcl
40 namespace unx
42 class GtkPrintWrapper;
46 class GenPspGraphics;
47 class GtkYieldMutex : public SalYieldMutex
49 thread_local static std::stack<sal_uIntPtr> yieldCounts;
51 public:
52 GtkYieldMutex() {}
53 void ThreadsEnter();
54 void ThreadsLeave();
57 #if GTK_CHECK_VERSION(3,0,0)
58 class GtkSalFrame;
60 struct VclToGtkHelper
62 std::vector<css::datatransfer::DataFlavor> aInfoToFlavor;
63 std::vector<GtkTargetEntry> FormatsToGtk(const css::uno::Sequence<css::datatransfer::DataFlavor> &rFormats);
64 void setSelectionData(const css::uno::Reference<css::datatransfer::XTransferable> &rTrans,
65 GtkSelectionData *selection_data, guint info);
66 private:
67 GtkTargetEntry makeGtkTargetEntry(const css::datatransfer::DataFlavor& rFlavor);
70 class GtkTransferable : public cppu::WeakImplHelper<css::datatransfer::XTransferable>
72 protected:
73 std::map<OUString, GdkAtom> m_aMimeTypeToAtom;
75 std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector(GdkAtom *targets, gint n_targets);
76 public:
78 virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& rFlavor) override = 0;
80 virtual std::vector<css::datatransfer::DataFlavor> getTransferDataFlavorsAsVector() = 0;
82 virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
83 virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& rFlavor) override;
86 class GtkDropTarget : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDropTarget,
87 css::lang::XInitialization,
88 css::lang::XServiceInfo>
90 osl::Mutex m_aMutex;
91 GtkSalFrame* m_pFrame;
92 bool m_bActive;
93 sal_Int8 m_nDefaultActions;
94 std::list<css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>> m_aListeners;
95 public:
96 GtkDropTarget();
97 virtual ~GtkDropTarget() override;
99 // XInitialization
100 virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArgs) override;
101 void deinitialize();
103 // XDropTarget
104 virtual void SAL_CALL addDropTargetListener(const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override;
105 virtual void SAL_CALL removeDropTargetListener(const css::uno::Reference<css::datatransfer::dnd::XDropTargetListener>&) override;
106 virtual sal_Bool SAL_CALL isActive() override;
107 virtual void SAL_CALL setActive(sal_Bool active) override;
108 virtual sal_Int8 SAL_CALL getDefaultActions() override;
109 virtual void SAL_CALL setDefaultActions(sal_Int8 actions) override;
111 OUString SAL_CALL getImplementationName() override;
113 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
115 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
117 void fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEnterEvent& dtdee);
118 void fire_dragOver(const css::datatransfer::dnd::DropTargetDragEvent& dtde);
119 void fire_drop(const css::datatransfer::dnd::DropTargetDropEvent& dtde);
120 void fire_dragExit(const css::datatransfer::dnd::DropTargetEvent& dte);
123 class GtkDragSource : public cppu::WeakComponentImplHelper<css::datatransfer::dnd::XDragSource,
124 css::lang::XInitialization,
125 css::lang::XServiceInfo>
127 osl::Mutex m_aMutex;
128 GtkSalFrame* m_pFrame;
129 css::uno::Reference<css::datatransfer::dnd::XDragSourceListener> m_xListener;
130 css::uno::Reference<css::datatransfer::XTransferable> m_xTrans;
131 VclToGtkHelper m_aConversionHelper;
132 public:
133 GtkDragSource()
134 : WeakComponentImplHelper(m_aMutex)
135 , m_pFrame(nullptr)
139 virtual ~GtkDragSource() override;
141 // XDragSource
142 virtual sal_Bool SAL_CALL isDragImageSupported() override;
143 virtual sal_Int32 SAL_CALL getDefaultCursor(sal_Int8 dragAction) override;
144 virtual void SAL_CALL startDrag(
145 const css::datatransfer::dnd::DragGestureEvent& trigger, sal_Int8 sourceActions, sal_Int32 cursor, sal_Int32 image,
146 const css::uno::Reference< css::datatransfer::XTransferable >& transferable,
147 const css::uno::Reference< css::datatransfer::dnd::XDragSourceListener >& listener) override;
149 // XInitialization
150 virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any >& rArguments) override;
151 void deinitialize();
153 OUString SAL_CALL getImplementationName() override;
155 sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
157 css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
159 void dragFailed();
160 void dragDelete();
161 void dragEnd(GdkDragContext* context);
162 void dragDataGet(GtkSelectionData *data, guint info);
164 // For LibreOffice internal D&D we provide the Transferable without Gtk
165 // intermediaries as a shortcut, see tdf#100097 for how dbaccess depends on this
166 static GtkDragSource* g_ActiveDragSource;
167 css::uno::Reference<css::datatransfer::XTransferable> const & GetTransferrable() const { return m_xTrans; }
170 #endif
172 class GtkSalTimer;
173 #if GTK_CHECK_VERSION(3,0,0)
174 class GtkInstance : public SvpSalInstance
175 #else
176 class GtkInstance : public X11SalInstance
177 #endif
179 #if GTK_CHECK_VERSION(3,0,0)
180 typedef SvpSalInstance Superclass_t;
181 #else
182 typedef X11SalInstance Superclass_t;
183 #endif
184 public:
185 GtkInstance( SalYieldMutex* pMutex );
186 virtual ~GtkInstance() override;
187 void EnsureInit();
188 virtual void AfterAppInit() override;
190 virtual SalFrame* CreateFrame( SalFrame* pParent, SalFrameStyleFlags nStyle ) override;
191 virtual SalFrame* CreateChildFrame( SystemParentData* pParent, SalFrameStyleFlags nStyle ) override;
192 virtual SalObject* CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow ) override;
193 #if !GTK_CHECK_VERSION(3,0,0)
194 virtual SalI18NImeStatus* CreateI18NImeStatus() override;
195 #endif
196 virtual SalSystem* CreateSalSystem() override;
197 virtual SalInfoPrinter* CreateInfoPrinter(SalPrinterQueueInfo* pPrinterQueueInfo, ImplJobSetup* pJobSetup) override;
198 virtual SalPrinter* CreatePrinter( SalInfoPrinter* pInfoPrinter ) override;
199 virtual SalMenu* CreateMenu( bool, Menu* ) override;
200 virtual void DestroyMenu( SalMenu* pMenu ) override;
201 virtual SalMenuItem* CreateMenuItem( const SalItemParams* ) override;
202 virtual void DestroyMenuItem( SalMenuItem* pItem ) override;
203 virtual SalTimer* CreateSalTimer() override;
204 virtual void AddToRecentDocumentList(const OUString& rFileUrl, const OUString& rMimeType, const OUString& rDocumentService) override;
205 virtual SalVirtualDevice* CreateVirtualDevice( SalGraphics*,
206 long &nDX, long &nDY,
207 DeviceFormat eFormat,
208 const SystemGraphicsData* = nullptr ) override;
209 virtual SalBitmap* CreateSalBitmap() override;
211 virtual SalYieldResult DoYield(bool bWait, bool bHandleAllCurrentEvents, sal_uLong nReleased) override;
212 virtual bool AnyInput( VclInputFlags nType ) override;
214 virtual GenPspGraphics *CreatePrintGraphics() override;
216 virtual bool hasNativeFileSelection() const override { return true; }
218 virtual css::uno::Reference< css::ui::dialogs::XFilePicker2 >
219 createFilePicker( const css::uno::Reference< css::uno::XComponentContext >& ) override;
220 virtual css::uno::Reference< css::ui::dialogs::XFolderPicker2 >
221 createFolderPicker( const css::uno::Reference< css::uno::XComponentContext >& ) override;
223 #if GTK_CHECK_VERSION(3,0,0)
224 virtual css::uno::Reference< css::uno::XInterface > CreateClipboard( const css::uno::Sequence< css::uno::Any >& i_rArguments ) override;
225 virtual css::uno::Reference< css::uno::XInterface > CreateDragSource() override;
226 virtual css::uno::Reference< css::uno::XInterface > CreateDropTarget() override;
227 virtual OpenGLContext* CreateOpenGLContext() override;
228 #endif
230 virtual const cairo_font_options_t* GetCairoFontOptions() override;
231 const cairo_font_options_t* GetLastSeenCairoFontOptions();
232 void ResetLastSeenCairoFontOptions();
234 void RemoveTimer (SalTimer *pTimer);
236 std::shared_ptr<vcl::unx::GtkPrintWrapper> const & getPrintWrapper() const;
238 private:
239 std::vector<GtkSalTimer *> m_aTimers;
240 #if GTK_CHECK_VERSION(3,0,0)
241 std::unordered_map< GdkAtom, css::uno::Reference<css::uno::XInterface> > m_aClipboards;
242 #endif
243 bool IsTimerExpired();
244 bool bNeedsInit;
245 cairo_font_options_t* m_pLastCairoFontOptions;
247 mutable std::shared_ptr<vcl::unx::GtkPrintWrapper> m_xPrintWrapper;
250 #endif // INCLUDED_VCL_INC_UNX_GTK_GTKINST_HXX
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */