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 <gdk/gdk.h>
25 #include <gdk/gdkx.h>
26 #include <gtk/gtk.h>
27 
28 #include <unx/gendata.hxx>
29 #include <unx/saldisp.hxx>
30 #include <unx/gtk/gtksys.hxx>
31 #include <vcl/ptrstyle.hxx>
32 #include <osl/conditn.hxx>
33 #include <saltimer.hxx>
34 #include <o3tl/enumarray.hxx>
35 
36 #include <vector>
37 
38 namespace com { namespace sun { namespace star { namespace accessibility { class XAccessibleEventListener; } } } }
39 
40 class GtkSalDisplay;
41 class DocumentFocusListener;
42 
widget_get_window(GtkWidget * widget)43 inline GdkWindow * widget_get_window(GtkWidget *widget)
44 {
45     return gtk_widget_get_window(widget);
46 }
47 
widget_get_xid(GtkWidget * widget)48 inline ::Window widget_get_xid(GtkWidget *widget)
49 {
50     return GDK_WINDOW_XID(gtk_widget_get_window(widget));
51 }
52 
widget_set_can_focus(GtkWidget * widget,gboolean can_focus)53 inline void widget_set_can_focus(GtkWidget *widget, gboolean can_focus)
54 {
55     return gtk_widget_set_can_focus(widget, can_focus);
56 }
57 
widget_set_can_default(GtkWidget * widget,gboolean can_default)58 inline void widget_set_can_default(GtkWidget *widget, gboolean can_default)
59 {
60     return gtk_widget_set_can_default(widget, can_default);
61 }
62 
63 class GtkSalTimer final : public SalTimer
64 {
65     struct SalGtkTimeoutSource *m_pTimeout;
66 public:
67     GtkSalTimer();
68     virtual ~GtkSalTimer() override;
69     virtual void Start( sal_uInt64 nMS ) override;
70     virtual void Stop() override;
71     bool         Expired();
72 
73     sal_uLong    m_nTimeoutMS;
74 };
75 
76 class GtkSalData : public GenericUnixSalData
77 {
78     GSource*        m_pUserEvent;
79     osl::Mutex      m_aDispatchMutex;
80     osl::Condition  m_aDispatchCondition;
81     std::exception_ptr m_aException;
82 
83     css::uno::Reference<css::accessibility::XAccessibleEventListener> m_xDocumentFocusListener;
84     DocumentFocusListener * m_pDocumentFocusListener;
85 
86 public:
87     GtkSalData( SalInstance *pInstance );
88     virtual ~GtkSalData() override;
89 
90     DocumentFocusListener & GetDocumentFocusListener();
91 
92     void Init();
93     virtual void Dispose() override;
94 
95     static void initNWF();
96     static void deInitNWF();
97 
98     void TriggerUserEventProcessing();
99     void TriggerAllUserEventsProcessed();
100 
101     bool Yield( bool bWait, bool bHandleAllCurrentEvents );
102     inline GdkDisplay *GetGdkDisplay();
103 
104     virtual void ErrorTrapPush() override;
105     virtual bool ErrorTrapPop( bool bIgnoreError = true ) override;
106 
107     inline GtkSalDisplay *GetGtkDisplay() const;
setException(const std::exception_ptr & exception)108     void setException(const std::exception_ptr& exception) { m_aException = exception; }
109 };
110 
111 class GtkSalFrame;
112 
113 class GtkSalDisplay : public SalGenericDisplay
114 {
115     GtkSalSystem*                   m_pSys;
116     GdkDisplay* const               m_pGdkDisplay;
117     o3tl::enumarray<PointerStyle, GdkCursor*> m_aCursors;
118     bool                            m_bStartupCompleted;
119     bool                            m_bX11Display;
120 
121     GdkCursor* getFromSvg( OUString const & name, int nXHot, int nYHot );
122 
123 public:
124              GtkSalDisplay( GdkDisplay* pDisplay );
125     virtual ~GtkSalDisplay() override;
126 
GetGdkDisplay() const127     GdkDisplay* GetGdkDisplay() const { return m_pGdkDisplay; }
IsX11Display() const128     bool        IsX11Display() const { return m_bX11Display; }
129 
getSystem() const130     GtkSalSystem* getSystem() const { return m_pSys; }
131 
132     GtkWidget* findGtkWidgetForNativeHandle(sal_uIntPtr hWindow) const;
133 
134     virtual void deregisterFrame( SalFrame* pFrame ) override;
135     GdkCursor *getCursor( PointerStyle ePointerStyle );
136     virtual int CaptureMouse( SalFrame* pFrame );
137 
GetDefaultXScreen()138     SalX11Screen GetDefaultXScreen() { return m_pSys->GetDisplayDefaultXScreen(); }
139     Size         GetScreenSize( int nDisplayScreen );
140 
141     GdkFilterReturn filterGdkEvent( GdkXEvent* sys_event );
startupNotificationCompleted()142     void startupNotificationCompleted() { m_bStartupCompleted = true; }
143 
144     void screenSizeChanged( GdkScreen const * );
145     void monitorsChanged( GdkScreen const * );
146 
147     virtual void TriggerUserEventProcessing() override;
148     virtual void TriggerAllUserEventsProcessed() override;
149 };
150 
GetGtkSalData()151 inline GtkSalData* GetGtkSalData()
152 {
153     return static_cast<GtkSalData*>(ImplGetSVData()->mpSalData);
154 }
GetGdkDisplay()155 inline GdkDisplay *GtkSalData::GetGdkDisplay()
156 {
157     return GetGtkDisplay()->GetGdkDisplay();
158 }
159 
GetGtkDisplay() const160 GtkSalDisplay *GtkSalData::GetGtkDisplay() const
161 {
162     return static_cast<GtkSalDisplay *>(GetDisplay());
163 }
164 
165 #endif // INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
168