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
42#include <string_view>
43#include <vector>
44
45namespace com::sun::star::accessibility { class XAccessibleEventListener; }
46
47class GtkSalDisplay;
49
50#if !GTK_CHECK_VERSION(4,0,0)
51typedef GdkWindow GdkSurface;
52typedef GdkWindowState GdkToplevelState;
53#endif
54
55inline void main_loop_run(GMainLoop* pLoop)
56{
57#if !GTK_CHECK_VERSION(4, 0, 0)
58 gdk_threads_leave();
59#endif
60 g_main_loop_run(pLoop);
61#if !GTK_CHECK_VERSION(4, 0, 0)
62 gdk_threads_enter();
63#endif
64}
65
66inline void css_provider_load_from_data(GtkCssProvider *css_provider,
67 const gchar *data,
68 gssize length)
69{
70#if GTK_CHECK_VERSION(4, 0, 0)
71 gtk_css_provider_load_from_data(css_provider, data, length);
72#else
73 gtk_css_provider_load_from_data(css_provider, data, length, nullptr);
74#endif
75}
76
78{
79#if GTK_CHECK_VERSION(4, 0, 0)
80 GtkRoot* pRoot = gtk_widget_get_root(pWidget);
81 return pRoot ? GTK_WIDGET(pRoot) : pWidget;
82#else
83 return gtk_widget_get_toplevel(pWidget);
84#endif
85}
86
87inline const char* image_get_icon_name(GtkImage *pImage)
88{
89#if GTK_CHECK_VERSION(4, 0, 0)
90 return gtk_image_get_icon_name(pImage);
91#else
92 const gchar* icon_name;
93 gtk_image_get_icon_name(pImage, &icon_name, nullptr);
94 return icon_name;
95#endif
96}
97
99{
100#if GTK_CHECK_VERSION(4, 0, 0)
101 return gtk_widget_get_first_child(pWidget);
102#else
103 GList* pChildren = gtk_container_get_children(GTK_CONTAINER(pWidget));
104 GList* pChild = g_list_first(pChildren);
105 GtkWidget* pRet = pChild ? static_cast<GtkWidget*>(pChild->data) : nullptr;
106 g_list_free(pChildren);
107 return pRet;
108#endif
109}
110
111inline void style_context_get_color(GtkStyleContext *pStyle, GdkRGBA *pColor)
112{
113#if GTK_CHECK_VERSION(4, 0, 0)
114 return gtk_style_context_get_color(pStyle, pColor);
115#else
116 return gtk_style_context_get_color(pStyle, gtk_style_context_get_state(pStyle), pColor);
117#endif
118}
119
121{
122#if GTK_CHECK_VERSION(4,0,0)
123 return gtk_native_get_surface(gtk_widget_get_native(pWidget));
124#else
125 return gtk_widget_get_window(pWidget);
126#endif
127}
128
129inline void widget_set_cursor(GtkWidget *pWidget, GdkCursor *pCursor)
130{
131#if GTK_CHECK_VERSION(4, 0, 0)
132 gtk_widget_set_cursor(pWidget, pCursor);
133#else
134 gdk_window_set_cursor(gtk_widget_get_window(pWidget), pCursor);
135#endif
136}
137
139 cairo_content_t eContent,
140 int nWidth,
141 int nHeight)
142{
143#if GTK_CHECK_VERSION(4, 0, 0)
144 return gdk_surface_create_similar_surface(pSurface, eContent, nWidth, nHeight);
145#else
146 return gdk_window_create_similar_surface(pSurface, eContent, nWidth, nHeight);
147#endif
148}
149
150inline void im_context_set_client_widget(GtkIMContext *pIMContext, GtkWidget *pWidget)
151{
152#if GTK_CHECK_VERSION(4, 0, 0)
153 gtk_im_context_set_client_widget(pIMContext, pWidget);
154#else
155 gtk_im_context_set_client_window(pIMContext, pWidget ? gtk_widget_get_window(pWidget) : nullptr);
156#endif
157}
158
159#if GTK_CHECK_VERSION(4, 0, 0)
160typedef double gtk_coord;
161#else
162typedef int gtk_coord;
163#endif
164
166 GdkDevice* pDevice,
167 double& x,
168 double& y,
169 GdkModifierType* pMask)
170{
171#if GTK_CHECK_VERSION(4, 0, 0)
172 return gdk_surface_get_device_position(pSurface, pDevice,
173 &x, &y,
174 pMask);
175#else
176 int nX(x), nY(y);
177 bool bRet = gdk_window_get_device_position(pSurface, pDevice,
178 &nX, &nY,
179 pMask);
180 x = nX;
181 y = nY;
182 return bRet;
183#endif
184}
185
186inline GdkGLContext* surface_create_gl_context(GdkSurface* pSurface)
187{
188#if GTK_CHECK_VERSION(4, 0, 0)
189 return gdk_surface_create_gl_context(pSurface, nullptr);
190#else
191 return gdk_window_create_gl_context(pSurface, nullptr);
192#endif
193}
194
195void set_buildable_id(GtkBuildable* pWidget, const OString& rId);
196OString get_buildable_id(GtkBuildable* pWidget);
197
198void container_remove(GtkWidget* pContainer, GtkWidget* pChild);
199void container_add(GtkWidget* pContainer, GtkWidget* pChild);
200
201#if !GTK_CHECK_VERSION(4, 0, 0)
202typedef GtkClipboard GdkClipboard;
203#endif
204
205int getButtonPriority(std::string_view rType);
206
207class GtkSalTimer final : public SalTimer
208{
209 struct SalGtkTimeoutSource *m_pTimeout;
210public:
212 virtual ~GtkSalTimer() override;
213 virtual void Start( sal_uInt64 nMS ) override;
214 virtual void Stop() override;
215 bool Expired();
216
218};
219
221 public ::cppu::WeakImplHelper< css::accessibility::XAccessibleEventListener >
222{
223
225
226public:
230 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible
231 );
232
236 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible,
237 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext
238 );
239
243 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible,
244 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext,
245 sal_Int64 nStateSet
246 );
247
251 const css::uno::Reference< css::accessibility::XAccessible >& xAccessible
252 );
253
257 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext
258 );
259
263 const css::uno::Reference< css::accessibility::XAccessibleContext >& xContext,
264 sal_Int64 nStateSet
265 );
266
269 static css::uno::Reference< css::accessibility::XAccessible > getAccessible(const css::lang::EventObject& aEvent );
270
271 // XEventListener
272 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
273
274 // XAccessibleEventListener
275 virtual void SAL_CALL notifyEvent( const css::accessibility::AccessibleEventObject& aEvent ) override;
276};
277
278class GtkSalData final : public GenericUnixSalData
279{
280 GSource* m_pUserEvent;
282 osl::Condition m_aDispatchCondition;
283 std::exception_ptr m_aException;
284
286
287public:
289 virtual ~GtkSalData() override;
290
292
293 void Init();
294 virtual void Dispose() override;
295
296 static void initNWF();
297 static void deInitNWF();
298
301
302 bool Yield( bool bWait, bool bHandleAllCurrentEvents );
303 inline GdkDisplay *GetGdkDisplay();
304
305 virtual void ErrorTrapPush() override;
306 virtual bool ErrorTrapPop( bool bIgnoreError = true ) override;
307
308 inline GtkSalDisplay *GetGtkDisplay() const;
309 void setException(const std::exception_ptr& exception) { m_aException = exception; }
310};
311
312class GtkSalFrame;
313
315{
317 GdkDisplay* m_pGdkDisplay;
320
321 GdkCursor* getFromSvg( OUString const & name, int nXHot, int nYHot );
322
323public:
324 GtkSalDisplay( GdkDisplay* pDisplay );
325 virtual ~GtkSalDisplay() override;
326
327 GdkDisplay* GetGdkDisplay() const { return m_pGdkDisplay; }
328
329 GtkSalSystem* getSystem() const { return m_pSys; }
330
331 GtkWidget* findGtkWidgetForNativeHandle(sal_uIntPtr hWindow) const;
332
333 virtual void deregisterFrame( SalFrame* pFrame ) override;
334 GdkCursor *getCursor( PointerStyle ePointerStyle );
335 virtual int CaptureMouse( SalFrame* pFrame );
336
338 Size GetScreenSize( int nDisplayScreen );
339
341
342#if !GTK_CHECK_VERSION(4,0,0)
343 void screenSizeChanged( GdkScreen const * );
344 void monitorsChanged( GdkScreen const * );
345#endif
346
347 virtual void TriggerUserEventProcessing() override;
348 virtual void TriggerAllUserEventsProcessed() override;
349};
350
352{
353 return static_cast<GtkSalData*>(ImplGetSVData()->mpSalData);
354}
355inline GdkDisplay *GtkSalData::GetGdkDisplay()
356{
357 return GetGtkDisplay()->GetGdkDisplay();
358}
359
361{
362 return static_cast<GtkSalDisplay *>(GetDisplay());
363}
364
365#endif // INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
366
367/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _cairo_surface cairo_surface_t
Definition: CairoCommon.hxx:72
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:224
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:66
virtual bool ErrorTrapPop(bool bIgnoreError=true) override
virtual void ErrorTrapPush() override
void setException(const std::exception_ptr &exception)
Definition: gtkdata.hxx:309
virtual ~GtkSalData() override
GtkSalDisplay * GetGtkDisplay() const
Definition: gtkdata.hxx:360
rtl::Reference< DocumentFocusListener > m_xDocumentFocusListener
Definition: gtkdata.hxx:285
osl::Condition m_aDispatchCondition
Definition: gtkdata.hxx:282
void TriggerUserEventProcessing()
bool Yield(bool bWait, bool bHandleAllCurrentEvents)
static void initNWF()
osl::Mutex m_aDispatchMutex
Definition: gtkdata.hxx:281
GdkDisplay * GetGdkDisplay()
Definition: gtkdata.hxx:355
void Init()
void TriggerAllUserEventsProcessed()
GSource * m_pUserEvent
Definition: gtkdata.hxx:280
DocumentFocusListener & GetDocumentFocusListener()
virtual void Dispose() override
static void deInitNWF()
std::exception_ptr m_aException
Definition: gtkdata.hxx:283
GdkDisplay * GetGdkDisplay() const
Definition: gtkdata.hxx:327
GdkDisplay * m_pGdkDisplay
Definition: gtkdata.hxx:317
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:337
GtkSalSystem * getSystem() const
Definition: gtkdata.hxx:329
o3tl::enumarray< PointerStyle, GdkCursor * > m_aCursors
Definition: gtkdata.hxx:318
GdkCursor * getCursor(PointerStyle ePointerStyle)
bool m_bStartupCompleted
Definition: gtkdata.hxx:319
GtkSalSystem * m_pSys
Definition: gtkdata.hxx:316
virtual int CaptureMouse(SalFrame *pFrame)
void startupNotificationCompleted()
Definition: gtkdata.hxx:340
void monitorsChanged(GdkScreen const *)
virtual void deregisterFrame(SalFrame *pFrame) override
SalX11Screen GetDisplayDefaultXScreen()
Definition: gtksys.hxx:36
virtual ~GtkSalTimer() override
sal_uLong m_nTimeoutMS
Definition: gtkdata.hxx:217
virtual void Stop() override
virtual void Start(sal_uInt64 nMS) override
struct SalGtkTimeoutSource * m_pTimeout
Definition: gtkdata.hxx:209
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:66
GdkGLContext * surface_create_gl_context(GdkSurface *pSurface)
Definition: gtkdata.hxx:186
GtkClipboard GdkClipboard
Definition: gtkdata.hxx:202
OString get_buildable_id(GtkBuildable *pWidget)
GdkWindow GdkSurface
Definition: gtkdata.hxx:48
void container_remove(GtkWidget *pContainer, GtkWidget *pChild)
GtkWidget * widget_get_first_child(GtkWidget *pWidget)
Definition: gtkdata.hxx:98
void main_loop_run(GMainLoop *pLoop)
Definition: gtkdata.hxx:55
void im_context_set_client_widget(GtkIMContext *pIMContext, GtkWidget *pWidget)
Definition: gtkdata.hxx:150
GdkSurface * widget_get_surface(GtkWidget *pWidget)
Definition: gtkdata.hxx:120
void widget_set_cursor(GtkWidget *pWidget, GdkCursor *pCursor)
Definition: gtkdata.hxx:129
void set_buildable_id(GtkBuildable *pWidget, const OString &rId)
void style_context_get_color(GtkStyleContext *pStyle, GdkRGBA *pColor)
Definition: gtkdata.hxx:111
int getButtonPriority(std::string_view rType)
int gtk_coord
Definition: gtkdata.hxx:162
bool surface_get_device_position(GdkSurface *pSurface, GdkDevice *pDevice, double &x, double &y, GdkModifierType *pMask)
Definition: gtkdata.hxx:165
void container_add(GtkWidget *pContainer, GtkWidget *pChild)
const char * image_get_icon_name(GtkImage *pImage)
Definition: gtkdata.hxx:87
GdkWindowState GdkToplevelState
Definition: gtkdata.hxx:52
cairo_surface_t * surface_create_similar_surface(GdkSurface *pSurface, cairo_content_t eContent, int nWidth, int nHeight)
Definition: gtkdata.hxx:138
GtkSalData * GetGtkSalData()
Definition: gtkdata.hxx:351
GtkWidget * widget_get_toplevel(GtkWidget *pWidget)
Definition: gtkdata.hxx:77
struct _GtkWidget GtkWidget
PointerStyle
Definition: ptrstyle.hxx:26
sal_uIntPtr sal_uLong
SalData * mpSalData
Definition: svdata.hxx:391
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:76