Branch libreoffice-5-0-4
[LibreOffice.git] / vcl / inc / unx / gtk / gtkdata.hxx
blob697fecee0eefd41cc2b7b14217b081e16b5ed658
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_GTKDATA_HXX
21 #define INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
23 #include <prex.h>
24 #define GLIB_DISABLE_DEPRECATION_WARNINGS
25 #include <gdk/gdk.h>
26 #include <gdk/gdkx.h>
27 #include <gtk/gtk.h>
28 #include <postx.h>
30 #include <generic/gendata.hxx>
31 #include <unx/saldisp.hxx>
32 #include <unx/saldata.hxx>
33 #include <unx/gtk/gtksys.hxx>
34 #include <vcl/ptrstyle.hxx>
35 #include <osl/conditn.h>
36 #include "saltimer.hxx"
37 #include <o3tl/enumarray.hxx>
39 #include <list>
41 class GtkSalDisplay;
43 inline GdkWindow * widget_get_window(GtkWidget *widget)
45 #if GTK_CHECK_VERSION(3,0,0)
46 return gtk_widget_get_window(widget);
47 #else
48 return widget->window;
49 #endif
52 inline ::Window widget_get_xid(GtkWidget *widget)
54 #if GTK_CHECK_VERSION(3,0,0)
55 return GDK_WINDOW_XID(gtk_widget_get_window(widget));
56 #else
57 return GDK_WINDOW_XWINDOW(widget->window);
58 #endif
61 inline void widget_set_can_focus(GtkWidget *widget, gboolean can_focus)
63 #if GTK_CHECK_VERSION(3,0,0)
64 return gtk_widget_set_can_focus(widget, can_focus);
65 #else
66 if (can_focus)
67 GTK_WIDGET_SET_FLAGS( widget, GTK_CAN_FOCUS );
68 else
69 GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_FOCUS );
70 #endif
73 inline void widget_set_can_default(GtkWidget *widget, gboolean can_default)
75 #if GTK_CHECK_VERSION(3,0,0)
76 return gtk_widget_set_can_default(widget, can_default);
77 #else
78 if (can_default)
79 GTK_WIDGET_SET_FLAGS( widget, GTK_CAN_DEFAULT );
80 else
81 GTK_WIDGET_UNSET_FLAGS( widget, GTK_CAN_DEFAULT );
82 #endif
85 class GtkSalTimer : public SalTimer
87 struct SalGtkTimeoutSource *m_pTimeout;
88 public:
89 GtkSalTimer();
90 virtual ~GtkSalTimer();
91 virtual void Start( sal_uLong nMS ) SAL_OVERRIDE;
92 virtual void Stop() SAL_OVERRIDE;
93 bool Expired();
95 sal_uLong m_nTimeoutMS;
98 class GtkData : public SalGenericData
100 GSource *m_pUserEvent;
101 oslMutex m_aDispatchMutex;
102 oslCondition m_aDispatchCondition;
103 bool blockIdleTimeout;
105 public:
106 GtkData( SalInstance *pInstance );
107 virtual ~GtkData();
109 void Init();
110 virtual void Dispose() SAL_OVERRIDE;
112 static void initNWF();
113 static void deInitNWF();
115 static gboolean userEventFn( gpointer data );
117 void PostUserEvent();
118 void Yield( bool bWait, bool bHandleAllCurrentEvents );
119 inline GdkDisplay *GetGdkDisplay();
121 virtual void ErrorTrapPush() SAL_OVERRIDE;
122 virtual bool ErrorTrapPop( bool bIgnoreError ) SAL_OVERRIDE;
124 inline GtkSalDisplay *GetGtkDisplay() const;
125 bool BlockIdleTimeout() const { return blockIdleTimeout; }
128 class GtkSalFrame;
130 #if GTK_CHECK_VERSION(3,0,0)
131 class GtkSalDisplay : public SalGenericDisplay
132 #else
133 class GtkSalDisplay : public SalDisplay
134 #endif
136 GtkSalSystem* m_pSys;
137 GdkDisplay* m_pGdkDisplay;
138 o3tl::enumarray<PointerStyle, GdkCursor*> m_aCursors;
139 bool m_bStartupCompleted;
140 bool m_bX11Display;
142 GdkCursor* getFromXBM( const unsigned char *pBitmap, const unsigned char *pMask,
143 int nWidth, int nHeight, int nXHot, int nYHot );
144 public:
145 GtkSalDisplay( GdkDisplay* pDisplay );
146 virtual ~GtkSalDisplay();
148 GdkDisplay* GetGdkDisplay() const { return m_pGdkDisplay; }
149 bool IsX11Display() const { return m_bX11Display; }
151 GtkSalSystem* getSystem() const { return m_pSys; }
153 virtual void deregisterFrame( SalFrame* pFrame ) SAL_OVERRIDE;
154 GdkCursor *getCursor( PointerStyle ePointerStyle );
155 #if GTK_CHECK_VERSION(3,0,0)
156 virtual int CaptureMouse( SalFrame* pFrame );
157 #else
158 virtual int CaptureMouse( SalFrame* pFrame ) SAL_OVERRIDE;
159 #endif
161 int GetDefaultScreen() { return m_pSys->GetDisplayBuiltInScreen(); }
162 SalX11Screen GetDefaultXScreen() { return m_pSys->GetDisplayDefaultXScreen(); }
163 Size GetScreenSize( int nDisplayScreen );
164 int GetXScreenCount() { return m_pSys->GetDisplayXScreenCount(); }
165 #if GTK_CHECK_VERSION(3,0,0)
166 // int GetScreenCount() { return m_pSys->GetDisplayScreenCount(); }
167 #else
168 virtual ScreenData *initScreen( SalX11Screen nXScreen ) const SAL_OVERRIDE;
169 #endif
171 GdkFilterReturn filterGdkEvent( GdkXEvent* sys_event,
172 GdkEvent* event );
173 void startupNotificationCompleted() { m_bStartupCompleted = true; }
175 void screenSizeChanged( GdkScreen* );
176 void monitorsChanged( GdkScreen* );
178 virtual void PostUserEvent() SAL_OVERRIDE;
180 #if !GTK_CHECK_VERSION(3,0,0)
181 virtual bool Dispatch( XEvent *pEvent ) SAL_OVERRIDE;
182 #endif
185 inline GtkData* GetGtkSalData()
187 return static_cast<GtkData*>(ImplGetSVData()->mpSalData);
189 inline GdkDisplay *GtkData::GetGdkDisplay()
191 return GetGtkDisplay()->GetGdkDisplay();
194 GtkSalDisplay *GtkData::GetGtkDisplay() const
196 return static_cast<GtkSalDisplay *>(GetDisplay());
199 #endif // INCLUDED_VCL_INC_UNX_GTK_GTKDATA_HXX
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */