LibreOffice Module vcl (master) 1
gtkdata.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
21#define INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
22
23#define GLIB_DISABLE_DEPRECATION_WARNINGS
24#include <gtk/gtk.h>
25#include <gdk/gdk.h>
26#if GTK_CHECK_VERSION(4,0,0)
27#include <gdk/x11/gdkx.h>
28#else
29#include <gdk/gdkx.h>
30#endif
31
32#include <com/sun/star/accessibility/XAccessibleContext.hpp>
33#include <com/sun/star/accessibility/XAccessibleEventListener.hpp>
34#include <unx/gendata.hxx>
35#include <unx/saldisp.hxx>
36#include <unx/gtk/gtksys.hxx>
37#include <vcl/ptrstyle.hxx>
38#include <osl/conditn.hxx>
39#include <saltimer.hxx>
40#include <o3tl/enumarray.hxx>
41#include <unotools/weakref.hxx>
42
43#include <exception>
44#include <string_view>
45#include <vector>
46
47namespace com::sun::star::accessibility { class XAccessibleEventListener; }
48
49class GtkSalDisplay;
51
52#if !GTK_CHECK_VERSION(4,0,0)
53typedef GdkWindow GdkSurface;
54typedef GdkWindowState GdkToplevelState;
55#endif
56
57inline void main_loop_run(GMainLoop* pLoop)
58{
59#if !GTK_CHECK_VERSION(4, 0, 0)
60 gdk_threads_leave();
61#endif
62 g_main_loop_run(pLoop);
63#if !GTK_CHECK_VERSION(4, 0, 0)
64 gdk_threads_enter();
65#endif
66}
67
68inline void css_provider_load_from_data(GtkCssProvider *css_provider,
69 const gchar *data,
70 gssize length)
71{
72#if GTK_CHECK_VERSION(4, 0, 0)
73 gtk_css_provider_load_from_data(css_provider, data, length);
74#else
75 gtk_css_provider_load_from_data(css_provider, data, length, nullptr);
76#endif
77}
78
80{
81#if GTK_CHECK_VERSION(4, 0, 0)
82 GtkRoot* pRoot = gtk_widget_get_root(pWidget);
83 return pRoot ? GTK_WIDGET(pRoot) : pWidget;
84#else
85 return gtk_widget_get_toplevel(pWidget);
86#endif
87}
88
89inline const char* image_get_icon_name(GtkImage *pImage)
90{
91#if GTK_CHECK_VERSION(4, 0, 0)
92 return gtk_image_get_icon_name(pImage);
93#else
94 const gchar* icon_name;
95 gtk_image_get_icon_name(pImage, &icon_name, nullptr);
96 return icon_name;
97#endif
98}
99
101{
102#if GTK_CHECK_VERSION(4, 0, 0)
103 return gtk_widget_get_first_child(pWidget);
104#else
105 GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pWidget));
106 GList* pChild = g_list_first(pChildren);
107 GtkWidget* pRet = pChild ? static_cast<GtkWidget*>(pChild->data) : nullptr;
108 g_list_free(pChildren);
109 return pRet;
110#endif
111}
112
113inline void style_context_get_color(GtkStyleContext *pStyle, GdkRGBA *pColor)
114{
115#if GTK_CHECK_VERSION(4, 0, 0)
116 return gtk_style_context_get_color(pStyle, pColor);
117#else
118 return gtk_style_context_get_color(pStyle, gtk_style_context_get_state(pStyle), pColor);
119#endif
120}
121
123{
124#if GTK_CHECK_VERSION(4,0,0)
125 return gtk_native_get_surface(gtk_widget_get_native(pWidget));
126#else
127 return gtk_widget_get_window(pWidget);
128#endif
129}
130
131inline void widget_set_cursor(GtkWidget *pWidget, GdkCursor *pCursor)
132{
133#if GTK_CHECK_VERSION(4, 0, 0)
134 gtk_widget_set_cursor(pWidget, pCursor);
135#else
136 gdk_window_set_cursor(gtk_widget_get_window(pWidget), pCursor);
137#endif
138}
139
141 cairo_content_t eContent,
142 int nWidth,
143 int nHeight)
144{
145#if GTK_CHECK_VERSION(4, 0, 0)
146 return gdk_surface_create_similar_surface(pSurface, eContent, nWidth, nHeight);
147#else
148 return gdk_window_create_similar_surface(pSurface, eContent, nWidth, nHeight);
149#endif
150}
151
152inline void im_context_set_client_widget(GtkIMContext *pIMContext, GtkWidget *pWidget)
153{
154#if GTK_CHECK_VERSION(4, 0, 0)
155 gtk_im_context_set_client_widget(pIMContext, pWidget);
156#else
157 gtk_im_context_set_client_window(pIMContext, pWidget ? gtk_widget_get_window(pWidget) : nullptr);
158#endif
159}
160
161#if GTK_CHECK_VERSION(4, 0, 0)
162typedef double gtk_coord;
163#else
164typedef int gtk_coord;
165#endif
166
168 GdkDevice* pDevice,
169 double& x,
170 double& y,
171 GdkModifierType* pMask)
172{
173#if GTK_CHECK_VERSION(4, 0, 0)
174 return gdk_surface_get_device_position(pSurface, pDevice,
175 &x, &y,
176 pMask);
177#else
178 int nX(x), nY(y);
179 bool bRet = gdk_window_get_device_position(pSurface, pDevice,
180 &nX, &nY,
181 pMask);
182 x = nX;
183 y = nY;
184 return bRet;
185#endif
186}
187
188inline GdkGLContext* surface_create_gl_context(GdkSurface* pSurface)
189{
190#if GTK_CHECK_VERSION(4, 0, 0)
191 return gdk_surface_create_gl_context(pSurface, nullptr);
192#else
193 return gdk_window_create_gl_context(pSurface, nullptr);
194#endif
195}
196
197void set_buildable_id(GtkBuildable* pWidget, const OUString& rId);
198OUString get_buildable_id(GtkBuildable* pWidget);
199
200void container_remove(GtkWidget* pContainer, GtkWidget* pChild);
201void container_add(GtkWidget* pContainer, GtkWidget* pChild);
202
203#if !GTK_CHECK_VERSION(4, 0, 0)
204typedef GtkClipboard GdkClipboard;
205#endif
206
207int getButtonPriority(std::u16string_view rType);
208
209class GtkSalTimer final : public SalTimer
210{
211 struct SalGtkTimeoutSource *m_pTimeout;
212public:
214 virtual ~GtkSalTimer() override;
215 virtual void Start( sal_uInt64 nMS ) override;
216 virtual void Stop() override;
217 bool Expired();
218
220};
221
223 public ::cppu::WeakImplHelper< css::accessibility::XAccessibleEventListener >
224{
225
227
228public:
232 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible
233 );
234
238 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible,
239 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext
240 );
241
245 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible,
246 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext,
247 sal_Int64 nStateSet
248 );
249
253 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible
254 );
255
259 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext
260 );
261
265 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext,
266 sal_Int64 nStateSet
267 );
268
271 static css::uno::Reference< css::accessibility::XAccessible > getAccessible(const css::lang::EventObject& aEvent );
272
273 // XEventListener
274 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
275
276 // XAccessibleEventListener
277 virtual void SAL_CALL notifyEvent( const css::accessibility::AccessibleEventObject& aEvent ) override;
278};
279
280class GtkSalData final : public GenericUnixSalData
281{
282 GSource* m_pUserEvent;
284 osl::Condition m_aDispatchCondition;
285 std::exception_ptr m_aException;
286
288
289public:
291 virtual ~GtkSalData() override;
292
294
295 void Init();
296 virtual void Dispose() override;
297
298 static void initNWF();
299 static void deInitNWF();
300
303
304 bool Yield( bool bWait, bool bHandleAllCurrentEvents );
305 inline GdkDisplay *GetGdkDisplay();
306
307 virtual void ErrorTrapPush() override;
308 virtual bool ErrorTrapPop( bool bIgnoreError = true ) override;
309
310 inline GtkSalDisplay *GetGtkDisplay() const;
311 void setException(const std::exception_ptr& exception) { m_aException = exception; }
312};
313
314class GtkSalFrame;
315
317{
319 GdkDisplay* m_pGdkDisplay;
322
323 GdkCursor* getFromSvg( OUString const & name, int nXHot, int nYHot );
324
325public:
326 GtkSalDisplay( GdkDisplay* pDisplay );
327 virtual ~GtkSalDisplay() override;
328
329 GdkDisplay* GetGdkDisplay() const { return m_pGdkDisplay; }
330
331 GtkSalSystem* getSystem() const { return m_pSys; }
332
333 GtkWidget* findGtkWidgetForNativeHandle(sal_uIntPtr hWindow) const;
334
335 virtual void deregisterFrame( SalFrame* pFrame ) override;
336 GdkCursor *getCursor( PointerStyle ePointerStyle );
337 virtual int CaptureMouse( SalFrame* pFrame );
338
340 Size GetScreenSize( int nDisplayScreen );
341
343
344#if !GTK_CHECK_VERSION(4,0,0)
345 void screenSizeChanged( GdkScreen const * );
346 void monitorsChanged( GdkScreen const * );
347#endif
348
349 virtual void TriggerUserEventProcessing() override;
350 virtual void TriggerAllUserEventsProcessed() override;
351};
352
354{
355 return static_cast<GtkSalData*>(ImplGetSVData()->mpSalData);
356}
357inline GdkDisplay *GtkSalData::GetGdkDisplay()
358{
359 return GetGtkDisplay()->GetGdkDisplay();
360}
361
363{
364 return static_cast<GtkSalDisplay *>(GetDisplay());
365}
366
367#endif // INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
368
369/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _cairo_surface cairo_surface_t
Definition: CairoCommon.hxx:46
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
void detachRecursive(const css::uno::Reference< css::accessibility::XAccessible > &xAccessible)
void attachRecursive(const css::uno::Reference< css::accessibility::XAccessible > &xAccessible)
static css::uno::Reference< css::accessibility::XAccessible > getAccessible(const css::lang::EventObject &aEvent)
o3tl::sorted_vector< css::uno::Reference< css::uno::XInterface > > m_aRefList
Definition: gtkdata.hxx:226
void attachRecursive(const css::uno::Reference< css::accessibility::XAccessible > &xAccessible, const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext, sal_Int64 nStateSet)
void detachRecursive(const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext)
void attachRecursive(const css::uno::Reference< css::accessibility::XAccessible > &xAccessible, const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext)
void detachRecursive(const css::uno::Reference< css::accessibility::XAccessibleContext > &xContext, sal_Int64 nStateSet)
virtual void SAL_CALL notifyEvent(const css::accessibility::AccessibleEventObject &aEvent) override
SalGenericDisplay * GetDisplay() const
Definition: gendata.hxx:76
virtual bool ErrorTrapPop(bool bIgnoreError=true) override
virtual void ErrorTrapPush() override
void setException(const std::exception_ptr &exception)
Definition: gtkdata.hxx:311
virtual ~GtkSalData() override
unotools::WeakReference< DocumentFocusListener > m_xDocumentFocusListener
Definition: gtkdata.hxx:287
GtkSalDisplay * GetGtkDisplay() const
Definition: gtkdata.hxx:362
rtl::Reference< DocumentFocusListener > GetDocumentFocusListener()
osl::Condition m_aDispatchCondition
Definition: gtkdata.hxx:284
void TriggerUserEventProcessing()
bool Yield(bool bWait, bool bHandleAllCurrentEvents)
static void initNWF()
osl::Mutex m_aDispatchMutex
Definition: gtkdata.hxx:283
GdkDisplay * GetGdkDisplay()
Definition: gtkdata.hxx:357
void Init()
void TriggerAllUserEventsProcessed()
GSource * m_pUserEvent
Definition: gtkdata.hxx:282
virtual void Dispose() override
static void deInitNWF()
std::exception_ptr m_aException
Definition: gtkdata.hxx:285
GdkDisplay * GetGdkDisplay() const
Definition: gtkdata.hxx:329
GdkDisplay * m_pGdkDisplay
Definition: gtkdata.hxx:319
virtual void TriggerAllUserEventsProcessed() override
void screenSizeChanged(GdkScreen const *)
GtkSalDisplay(GdkDisplay *pDisplay)
GtkWidget * findGtkWidgetForNativeHandle(sal_uIntPtr hWindow) const
GdkCursor * getFromSvg(OUString const &name, int nXHot, int nYHot)
Size GetScreenSize(int nDisplayScreen)
virtual void TriggerUserEventProcessing() override
virtual ~GtkSalDisplay() override
SalX11Screen GetDefaultXScreen()
Definition: gtkdata.hxx:339
GtkSalSystem * getSystem() const
Definition: gtkdata.hxx:331
o3tl::enumarray< PointerStyle, GdkCursor * > m_aCursors
Definition: gtkdata.hxx:320
GdkCursor * getCursor(PointerStyle ePointerStyle)
bool m_bStartupCompleted
Definition: gtkdata.hxx:321
GtkSalSystem * m_pSys
Definition: gtkdata.hxx:318
virtual int CaptureMouse(SalFrame *pFrame)
void startupNotificationCompleted()
Definition: gtkdata.hxx:342
void monitorsChanged(GdkScreen const *)
virtual void deregisterFrame(SalFrame *pFrame) override
SalX11Screen GetDisplayDefaultXScreen()
Definition: gtksys.hxx:35
virtual ~GtkSalTimer() override
sal_uLong m_nTimeoutMS
Definition: gtkdata.hxx:219
virtual void Stop() override
virtual void Start(sal_uInt64 nMS) override
struct SalGtkTimeoutSource * m_pTimeout
Definition: gtkdata.hxx:211
bool Expired()
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
float y
float x
void css_provider_load_from_data(GtkCssProvider *css_provider, const gchar *data, gssize length)
Definition: gtkdata.hxx:68
GdkGLContext * surface_create_gl_context(GdkSurface *pSurface)
Definition: gtkdata.hxx:188
GtkClipboard GdkClipboard
Definition: gtkdata.hxx:204
GdkWindow GdkSurface
Definition: gtkdata.hxx:50
void container_remove(GtkWidget *pContainer, GtkWidget *pChild)
GtkWidget * widget_get_first_child(GtkWidget *pWidget)
Definition: gtkdata.hxx:100
void set_buildable_id(GtkBuildable *pWidget, const OUString &rId)
OUString get_buildable_id(GtkBuildable *pWidget)
void main_loop_run(GMainLoop *pLoop)
Definition: gtkdata.hxx:57
void im_context_set_client_widget(GtkIMContext *pIMContext, GtkWidget *pWidget)
Definition: gtkdata.hxx:152
GdkSurface * widget_get_surface(GtkWidget *pWidget)
Definition: gtkdata.hxx:122
void widget_set_cursor(GtkWidget *pWidget, GdkCursor *pCursor)
Definition: gtkdata.hxx:131
void style_context_get_color(GtkStyleContext *pStyle, GdkRGBA *pColor)
Definition: gtkdata.hxx:113
int gtk_coord
Definition: gtkdata.hxx:164
bool surface_get_device_position(GdkSurface *pSurface, GdkDevice *pDevice, double &x, double &y, GdkModifierType *pMask)
Definition: gtkdata.hxx:167
int getButtonPriority(std::u16string_view rType)
void container_add(GtkWidget *pContainer, GtkWidget *pChild)
const char * image_get_icon_name(GtkImage *pImage)
Definition: gtkdata.hxx:89
GdkWindowState GdkToplevelState
Definition: gtkdata.hxx:54
cairo_surface_t * surface_create_similar_surface(GdkSurface *pSurface, cairo_content_t eContent, int nWidth, int nHeight)
Definition: gtkdata.hxx:140
GtkSalData * GetGtkSalData()
Definition: gtkdata.hxx:353
GtkWidget * widget_get_toplevel(GtkWidget *pWidget)
Definition: gtkdata.hxx:79
struct _GtkWidget GtkWidget
PointerStyle
Definition: ptrstyle.hxx:26
sal_uIntPtr sal_uLong
SalData * mpSalData
Definition: svdata.hxx:388
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77