diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-02-12 16:55:12 +0000 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-02-19 14:54:59 +0000 |
commit | 05eccaef907c9fca4f874b8ffa608d4815fbeebd (patch) | |
tree | 940b846007d1f5d1e683d9e9cc6c9e23939dd7b7 /vcl | |
parent | 4b0390a9cb45f56a7c6d04eff795de8b63b13b2e (diff) |
gtk3+wayland: implement video playback under gtk3 + wayland
split the gtk2 and gtk3 gtkobjects
(cherry picked from commit 31fa4545985acc1594107e087cedc2d99b3d0f0b)
Change-Id: I32084232c44a12e9641010b51e75710abc827695
rename X11WindowProvider to a NativeWindowHandle provider
sort of thing and genericize it
(cherry picked from commit e35e762d564da18b0b508112f3e4d78fd26ba99c)
Change-Id: I27e1e47f2b371e5269db079cfc1262d056105f80
implement wayland handle passing for gstreamer
Change-Id: I3b0effe35ad7b37ff7ab3de2a3b78b6312779139
(cherry picked from commit c0d4f3ad3307c7a0d0fddd8c413ef0cc91d382ae)
gtk3+wayland: play video via gtksink gstreamer element
(cherry picked from commit 8543fbc72fafc0d71a8760752ca2ef5b7119cb5c)
Change-Id: Ib371fa06eda73962cbe94739e69a68b46c26e4bf
Reviewed-on: https://gerrit.libreoffice.org/22462
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/Library_vcl.mk | 2 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 8 | ||||
-rw-r--r-- | vcl/inc/unx/nativewindowhandleprovider.hxx (renamed from vcl/inc/unx/x11windowprovider.hxx) | 13 | ||||
-rw-r--r-- | vcl/inc/unx/salframe.h | 6 | ||||
-rw-r--r-- | vcl/opengl/x11/gdiimpl.cxx | 4 | ||||
-rw-r--r-- | vcl/unx/generic/app/saldata.cxx | 56 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/nativewindowhandleprovider.cxx (renamed from vcl/inc/unx/x11/x11display.hxx) | 16 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/salgdi.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/generic/gdi/x11windowprovider.cxx | 72 | ||||
-rw-r--r-- | vcl/unx/generic/window/salframe.cxx | 2 | ||||
-rw-r--r-- | vcl/unx/gtk/gtkobject.cxx | 22 | ||||
-rw-r--r-- | vcl/unx/gtk/gtksalframe.cxx | 3 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkframe.cxx | 37 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkobject.cxx | 180 |
14 files changed, 290 insertions, 133 deletions
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index a9fe72fd73a4..da80ab65ea71 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -581,7 +581,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/unx/generic/plugadapt/salplug \ vcl/unx/generic/printer/jobdata \ vcl/unx/generic/printer/ppdparser \ - vcl/unx/generic/gdi/x11windowprovider \ + vcl/unx/generic/gdi/nativewindowhandleprovider \ vcl/unx/generic/window/screensaverinhibitor \ $(if $(filter TRUE,$(ENABLE_CUPS)),\ vcl/unx/generic/printer/cupsmgr \ diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index da629b7ef047..20a1e848fb4f 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -33,7 +33,7 @@ #include <salframe.hxx> #include <vcl/sysdata.hxx> -#include <unx/x11windowprovider.hxx> +#include <unx/nativewindowhandleprovider.hxx> #include <unx/saltype.h> #include <unx/screensaverinhibitor.hxx> @@ -66,7 +66,8 @@ class GtkDnDTransferable; typedef void GDBusConnection; #endif -class GtkSalFrame : public SalFrame, public X11WindowProvider +class GtkSalFrame : public SalFrame + , public NativeWindowHandleProvider { struct IMHandler { @@ -518,7 +519,8 @@ public: static GtkSalFrame *getFromWindow( GtkWindow *pWindow ); - virtual Window GetX11Window() override; + sal_uIntPtr GetNativeWindowHandle(GtkWidget *pWidget); + virtual sal_uIntPtr GetNativeWindowHandle() override; static void KeyCodeToGdkKey(const vcl::KeyCode& rKeyCode, guint* pGdkKeyCode, GdkModifierType *pGdkModifiers); diff --git a/vcl/inc/unx/x11windowprovider.hxx b/vcl/inc/unx/nativewindowhandleprovider.hxx index 776c8e4c4b34..1d85cb4cf5ef 100644 --- a/vcl/inc/unx/x11windowprovider.hxx +++ b/vcl/inc/unx/nativewindowhandleprovider.hxx @@ -7,20 +7,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_VCL_UNX_X11WINDOWPROVIDER -#define INCLUDED_VCL_UNX_X11WINDOWPROVIDER - -#include <prex.h> -#include <postx.h> +#ifndef INCLUDED_VCL_UNX_NATIVEWINDOWHANDLEPROVIDER +#define INCLUDED_VCL_UNX_NATIVEWINDOWHANDLEPROVIDER #include <vcl/dllapi.h> -class VCL_PLUGIN_PUBLIC X11WindowProvider +class VCL_PLUGIN_PUBLIC NativeWindowHandleProvider { public: - virtual ~X11WindowProvider(); + virtual ~NativeWindowHandleProvider(); - virtual Window GetX11Window() = 0; + virtual sal_uIntPtr GetNativeWindowHandle() = 0; }; #endif diff --git a/vcl/inc/unx/salframe.h b/vcl/inc/unx/salframe.h index 9ba19574cbbf..9848e1eeb15b 100644 --- a/vcl/inc/unx/salframe.h +++ b/vcl/inc/unx/salframe.h @@ -27,7 +27,7 @@ #include <unx/saltype.h> #include <unx/saldisp.hxx> #include <unx/screensaverinhibitor.hxx> -#include <unx/x11windowprovider.hxx> +#include <unx/nativewindowhandleprovider.hxx> #include <salframe.hxx> #include <salwtype.hxx> #include <salinst.hxx> @@ -50,7 +50,7 @@ namespace vcl_sal { class WMAdaptor; class NetWMAdaptor; class GnomeWMAdaptor; } #define SHOWSTATE_NORMAL 1 #define SHOWSTATE_HIDDEN 2 -class VCLPLUG_GEN_PUBLIC X11SalFrame : public SalFrame, public X11WindowProvider +class VCLPLUG_GEN_PUBLIC X11SalFrame : public SalFrame, public NativeWindowHandleProvider { friend class vcl_sal::WMAdaptor; friend class vcl_sal::NetWMAdaptor; @@ -261,7 +261,7 @@ public: // done setting up the clipregion virtual void EndSetClipRegion() override; - virtual Window GetX11Window() override; + virtual sal_uIntPtr GetNativeWindowHandle() override; /// @internal void setPendingSizeEvent(); diff --git a/vcl/opengl/x11/gdiimpl.cxx b/vcl/opengl/x11/gdiimpl.cxx index b1bc724c86ee..fc49e2520e58 100644 --- a/vcl/opengl/x11/gdiimpl.cxx +++ b/vcl/opengl/x11/gdiimpl.cxx @@ -47,12 +47,12 @@ void X11OpenGLSalGraphicsImpl::Init() rtl::Reference<OpenGLContext> X11OpenGLSalGraphicsImpl::CreateWinContext() { - X11WindowProvider *pProvider = dynamic_cast<X11WindowProvider*>(mrParent.m_pFrame); + NativeWindowHandleProvider *pProvider = dynamic_cast<NativeWindowHandleProvider*>(mrParent.m_pFrame); if( !pProvider ) return nullptr; - Window aWin = pProvider->GetX11Window(); + sal_uIntPtr aWin = pProvider->GetNativeWindowHandle(); rtl::Reference<OpenGLContext> pContext = OpenGLContext::Create(); pContext->setVCLOnly(); pContext->init( mrParent.GetXDisplay(), aWin, diff --git a/vcl/unx/generic/app/saldata.cxx b/vcl/unx/generic/app/saldata.cxx index 3f9d184a5566..92f4679ae793 100644 --- a/vcl/unx/generic/app/saldata.cxx +++ b/vcl/unx/generic/app/saldata.cxx @@ -48,7 +48,9 @@ #include "unx/sm.hxx" #include "unx/i18n_im.hxx" #include "unx/i18n_xkb.hxx" -#include "unx/x11/x11display.hxx" +#include <prex.h> +#include <X11/Xproto.h> +#include <postx.h> #include "salinst.hxx" #include <osl/signal.h> @@ -374,6 +376,58 @@ SalXLib::~SalXLib() close (m_pTimeoutFDS[1]); } +static Display *OpenX11Display(OString& rDisplay) +{ + /* + * open connection to X11 Display + * try in this order: + * o -display command line parameter, + * o $DISPLAY environment variable + * o default display + */ + + Display *pDisp = nullptr; + + // is there a -display command line parameter? + + sal_uInt32 nParams = osl_getCommandArgCount(); + OUString aParam; + for (sal_uInt32 i=0; i<nParams; i++) + { + osl_getCommandArg(i, &aParam.pData); + if ( aParam == "-display" ) + { + osl_getCommandArg(i+1, &aParam.pData); + rDisplay = OUStringToOString( + aParam, osl_getThreadTextEncoding()); + + if ((pDisp = XOpenDisplay(rDisplay.getStr()))!=nullptr) + { + /* + * if a -display switch was used, we need + * to set the environment accordingly since + * the clipboard build another connection + * to the xserver using $DISPLAY + */ + OUString envVar("DISPLAY"); + osl_setEnvironment(envVar.pData, aParam.pData); + } + break; + } + } + + if (!pDisp && rDisplay.isEmpty()) + { + // Open $DISPLAY or default... + char *pDisplay = getenv("DISPLAY"); + if (pDisplay != nullptr) + rDisplay = OString(pDisplay); + pDisp = XOpenDisplay(pDisplay); + } + + return pDisp; +} + void SalXLib::Init() { SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod; diff --git a/vcl/inc/unx/x11/x11display.hxx b/vcl/unx/generic/gdi/nativewindowhandleprovider.cxx index 9cb2ea56ccf8..3afd26e31498 100644 --- a/vcl/inc/unx/x11/x11display.hxx +++ b/vcl/unx/generic/gdi/nativewindowhandleprovider.cxx @@ -7,19 +7,11 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#ifndef INCLUDED_VCL_INC_UNX_X11_X11DISPLAY_HXX -#define INCLUDED_VCL_INC_UNX_X11_X11DISPLAY_HXX +#include "unx/nativewindowhandleprovider.hxx" -#include <prex.h> -#include <X11/Xproto.h> -#include <postx.h> +NativeWindowHandleProvider::~NativeWindowHandleProvider() +{ +} -#include <rtl/string.hxx> - -#include <vcl/dllapi.h> - -VCL_DLLPUBLIC Display* OpenX11Display(OString& rDisplay); - -#endif // INCLUDED_VCL_INC_UNX_X11_X11DISPLAY_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/gdi/salgdi.cxx b/vcl/unx/generic/gdi/salgdi.cxx index 738d59bf769c..f5ffead4beeb 100644 --- a/vcl/unx/generic/gdi/salgdi.cxx +++ b/vcl/unx/generic/gdi/salgdi.cxx @@ -53,7 +53,7 @@ #include <unx/x11/xlimits.hxx> #include "salgdiimpl.hxx" -#include "unx/x11windowprovider.hxx" +#include "unx/nativewindowhandleprovider.hxx" #include "textrender.hxx" #include "gdiimpl.hxx" #include "opengl/x11/gdiimpl.hxx" diff --git a/vcl/unx/generic/gdi/x11windowprovider.cxx b/vcl/unx/generic/gdi/x11windowprovider.cxx deleted file mode 100644 index 5f7d289196ec..000000000000 --- a/vcl/unx/generic/gdi/x11windowprovider.cxx +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#include <vcl/svapp.hxx> - -#include "unx/x11windowprovider.hxx" -#include "unx/x11/x11display.hxx" - -X11WindowProvider::~X11WindowProvider() -{ -} - -Display *OpenX11Display(OString& rDisplay) -{ - /* - * open connection to X11 Display - * try in this order: - * o -display command line parameter, - * o $DISPLAY environment variable - * o default display - */ - - Display *pDisp = nullptr; - - // is there a -display command line parameter? - - sal_uInt32 nParams = osl_getCommandArgCount(); - OUString aParam; - for (sal_uInt32 i=0; i<nParams; i++) - { - osl_getCommandArg(i, &aParam.pData); - if ( aParam == "-display" ) - { - osl_getCommandArg(i+1, &aParam.pData); - rDisplay = OUStringToOString( - aParam, osl_getThreadTextEncoding()); - - if ((pDisp = XOpenDisplay(rDisplay.getStr()))!=nullptr) - { - /* - * if a -display switch was used, we need - * to set the environment accoringly since - * the clipboard build another connection - * to the xserver using $DISPLAY - */ - OUString envVar("DISPLAY"); - osl_setEnvironment(envVar.pData, aParam.pData); - } - break; - } - } - - if (!pDisp && rDisplay.isEmpty()) - { - // Open $DISPLAY or default... - char *pDisplay = getenv("DISPLAY"); - if (pDisplay != nullptr) - rDisplay = OString(pDisplay); - pDisp = XOpenDisplay(pDisplay); - } - - return pDisp; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/generic/window/salframe.cxx b/vcl/unx/generic/window/salframe.cxx index c0e3e75e36ec..63f7c9d68cd2 100644 --- a/vcl/unx/generic/window/salframe.cxx +++ b/vcl/unx/generic/window/salframe.cxx @@ -4133,7 +4133,7 @@ void X11SalFrame::EndSetClipRegion() } -Window X11SalFrame::GetX11Window() +sal_uIntPtr X11SalFrame::GetNativeWindowHandle() { return mhWindow; } diff --git a/vcl/unx/gtk/gtkobject.cxx b/vcl/unx/gtk/gtkobject.cxx index 35084aa4ef4e..18aa63a115c6 100644 --- a/vcl/unx/gtk/gtkobject.cxx +++ b/vcl/unx/gtk/gtkobject.cxx @@ -51,7 +51,6 @@ GtkSalObject::GtkSalObject( GtkSalFrame* pParent, bool bShow ) // system data m_aSystemData.nSize = sizeof( SystemEnvData ); -#if !GTK_CHECK_VERSION(3,0,0) SalDisplay* pDisp = vcl_sal::getSalDisplay(GetGenericData()); m_aSystemData.pDisplay = pDisp->GetDisplay(); m_aSystemData.pVisual = pDisp->GetVisual(pParent->getXScreenNumber()).GetVisual(); @@ -59,17 +58,12 @@ GtkSalObject::GtkSalObject( GtkSalFrame* pParent, bool bShow ) m_aSystemData.aColormap = pDisp->GetColormap(pParent->getXScreenNumber()).GetXColormap(); m_aSystemData.aWindow = GDK_WINDOW_XWINDOW(widget_get_window(m_pSocket)); m_aSystemData.aShellWindow = GDK_WINDOW_XWINDOW(widget_get_window(GTK_WIDGET(pParent->getWindow()))); -#else - static int nWindow = 0; - m_aSystemData.aWindow = nWindow; - ++nWindow; - m_aSystemData.aShellWindow = reinterpret_cast<long>(this); -#endif m_aSystemData.pSalFrame = nullptr; m_aSystemData.pWidget = m_pSocket; m_aSystemData.nScreen = pParent->getXScreenNumber().getXScreen(); m_aSystemData.pAppContext = nullptr; m_aSystemData.pShellWidget = GTK_WIDGET(pParent->getWindow()); + m_aSystemData.pToolkit = "gtk2"; g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this ); g_signal_connect( G_OBJECT(m_pSocket), "button-release-event", G_CALLBACK(signalButton), this ); @@ -86,11 +80,7 @@ GtkSalObject::~GtkSalObject() { if( m_pRegion ) { -#if GTK_CHECK_VERSION(3,0,0) - cairo_region_destroy( m_pRegion ); -#else gdk_region_destroy( m_pRegion ); -#endif } if( m_pSocket ) { @@ -119,15 +109,9 @@ sal_uInt16 GtkSalObject::GetClipRegionType() void GtkSalObject::BeginSetClipRegion( sal_uLong ) { -#if GTK_CHECK_VERSION(3,0,0) - if( m_pRegion ) - cairo_region_destroy( m_pRegion ); - m_pRegion = cairo_region_create(); -#else if( m_pRegion ) gdk_region_destroy( m_pRegion ); m_pRegion = gdk_region_new(); -#endif } void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight ) @@ -138,11 +122,7 @@ void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight aRect.width = nWidth; aRect.height = nHeight; -#if GTK_CHECK_VERSION(3,0,0) - cairo_region_union_rectangle( m_pRegion, &aRect ); -#else gdk_region_union_with_rect( m_pRegion, &aRect ); -#endif } void GtkSalObject::EndSetClipRegion() diff --git a/vcl/unx/gtk/gtksalframe.cxx b/vcl/unx/gtk/gtksalframe.cxx index 3b6caa6b3fd6..7a7c293273fb 100644 --- a/vcl/unx/gtk/gtksalframe.cxx +++ b/vcl/unx/gtk/gtksalframe.cxx @@ -1022,6 +1022,7 @@ void GtkSalFrame::InitCommon() m_aSystemData.nScreen = m_nXScreen.getXScreen(); m_aSystemData.pAppContext = nullptr; m_aSystemData.pShellWidget = m_aSystemData.pWidget; + m_aSystemData.pToolkit = "gtk2"; m_bGraphics = false; m_pGraphics = NULL; @@ -3929,7 +3930,7 @@ Size GtkSalDisplay::GetScreenSize( int nDisplayScreen ) return Size( aRect.GetWidth(), aRect.GetHeight() ); } -Window GtkSalFrame::GetX11Window() +sal_uIntPtr GtkSalFrame::GetNativeWindowHandle() { return widget_get_xid(m_pWindow); } diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx index 70e0c9b536ef..f3bdfb251b4c 100644 --- a/vcl/unx/gtk3/gtk3gtkframe.cxx +++ b/vcl/unx/gtk3/gtk3gtkframe.cxx @@ -48,7 +48,12 @@ #include <gtk/gtk.h> #include <prex.h> #include <X11/Xatom.h> -#include <gdk/gdkx.h> +#if defined(GDK_WINDOWING_X11) +# include <gdk/gdkx.h> +#endif +#if defined(GDK_WINDOWING_WAYLAND) +# include <gdk/gdkwayland.h> +#endif #include <postx.h> #include <dlfcn.h> @@ -1085,15 +1090,14 @@ void GtkSalFrame::InitCommon() //system data m_aSystemData.nSize = sizeof( SystemEnvData ); - static int nWindow = 0; - m_aSystemData.aWindow = nWindow; - ++nWindow; + m_aSystemData.aWindow = GetNativeWindowHandle(m_pWindow); m_aSystemData.aShellWindow = reinterpret_cast<long>(this); m_aSystemData.pSalFrame = this; m_aSystemData.pWidget = m_pWindow; m_aSystemData.nScreen = m_nXScreen.getXScreen(); m_aSystemData.pAppContext = nullptr; m_aSystemData.pShellWidget = m_aSystemData.pWidget; + m_aSystemData.pToolkit = "gtk3"; m_bGraphics = false; m_pGraphics = nullptr; @@ -3926,9 +3930,30 @@ Size GtkSalDisplay::GetScreenSize( int nDisplayScreen ) return Size( aRect.GetWidth(), aRect.GetHeight() ); } -Window GtkSalFrame::GetX11Window() +sal_uIntPtr GtkSalFrame::GetNativeWindowHandle(GtkWidget *pWidget) +{ + (void) this; // Silence loplugin:staticmethods + GdkDisplay *pDisplay = getGdkDisplay(); + GdkWindow *pWindow = gtk_widget_get_window(pWidget); + +#if defined(GDK_WINDOWING_X11) + if (GDK_IS_X11_DISPLAY(pDisplay)) + { + return GDK_WINDOW_XID(pWindow); + } +#endif +#if defined(GDK_WINDOWING_WAYLAND) + if (GDK_IS_WAYLAND_DISPLAY(pDisplay)) + { + return reinterpret_cast<sal_uIntPtr>(gdk_wayland_window_get_wl_surface(pWindow)); + } +#endif + return 0; +} + +sal_uIntPtr GtkSalFrame::GetNativeWindowHandle() { - return widget_get_xid(m_pWindow); + return GetNativeWindowHandle(m_pWindow); } void GtkDragSource::startDrag(const datatransfer::dnd::DragGestureEvent& rEvent, diff --git a/vcl/unx/gtk3/gtk3gtkobject.cxx b/vcl/unx/gtk3/gtk3gtkobject.cxx index 96c152726c58..8f1c032190db 100644 --- a/vcl/unx/gtk3/gtk3gtkobject.cxx +++ b/vcl/unx/gtk3/gtk3gtkobject.cxx @@ -5,8 +5,186 @@ * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "../gtk/gtkobject.cxx" +#ifdef AIX +#define _LINUX_SOURCE_COMPAT +#include <sys/timer.h> +#undef _LINUX_SOURCE_COMPAT +#endif + +#include <unx/gtk/gtkobject.hxx> +#include <unx/gtk/gtkframe.hxx> +#include <unx/gtk/gtkdata.hxx> +#include <unx/gtk/gtkinst.hxx> +#include <unx/gtk/gtkgdi.hxx> + +GtkSalObject::GtkSalObject( GtkSalFrame* pParent, bool bShow ) + : m_pSocket( nullptr ), + m_pRegion( nullptr ) +{ + if( pParent ) + { + // our plug window + m_pSocket = gtk_grid_new(); + Show( bShow ); + // insert into container + gtk_fixed_put( pParent->getFixedContainer(), + m_pSocket, + 0, 0 ); + // realize so we can get a window id + gtk_widget_realize( m_pSocket ); + + // system data + m_aSystemData.nSize = sizeof( SystemEnvData ); + m_aSystemData.aWindow = pParent->GetNativeWindowHandle(m_pSocket); + m_aSystemData.aShellWindow = reinterpret_cast<long>(this); + m_aSystemData.pSalFrame = nullptr; + m_aSystemData.pWidget = m_pSocket; + m_aSystemData.nScreen = pParent->getXScreenNumber().getXScreen(); + m_aSystemData.pAppContext = nullptr; + m_aSystemData.pShellWidget = GTK_WIDGET(pParent->getWindow()); + m_aSystemData.pToolkit = "gtk3"; + + g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this ); + g_signal_connect( G_OBJECT(m_pSocket), "button-release-event", G_CALLBACK(signalButton), this ); + g_signal_connect( G_OBJECT(m_pSocket), "focus-in-event", G_CALLBACK(signalFocus), this ); + g_signal_connect( G_OBJECT(m_pSocket), "focus-out-event", G_CALLBACK(signalFocus), this ); + g_signal_connect( G_OBJECT(m_pSocket), "destroy", G_CALLBACK(signalDestroy), this ); + + // #i59255# necessary due to sync effects with java child windows + pParent->Flush(); + } +} + +GtkSalObject::~GtkSalObject() +{ + if( m_pRegion ) + { + cairo_region_destroy( m_pRegion ); + } + if( m_pSocket ) + { + // remove socket from parent frame's fixed container + gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(m_pSocket)), + m_pSocket ); + // get rid of the socket + // actually the gtk_container_remove should let the ref count + // of the socket sink to 0 and destroy it (see signalDestroy) + // this is just a sanity check + if( m_pSocket ) + gtk_widget_destroy( m_pSocket ); + } +} + +void GtkSalObject::ResetClipRegion() +{ + if( m_pSocket ) + gdk_window_shape_combine_region( widget_get_window(m_pSocket), nullptr, 0, 0 ); +} + +sal_uInt16 GtkSalObject::GetClipRegionType() +{ + return SAL_OBJECT_CLIP_INCLUDERECTS; +} + +void GtkSalObject::BeginSetClipRegion( sal_uLong ) +{ + if( m_pRegion ) + cairo_region_destroy( m_pRegion ); + m_pRegion = cairo_region_create(); +} + +void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight ) +{ + GdkRectangle aRect; + aRect.x = nX; + aRect.y = nY; + aRect.width = nWidth; + aRect.height = nHeight; + + cairo_region_union_rectangle( m_pRegion, &aRect ); +} + +void GtkSalObject::EndSetClipRegion() +{ + if( m_pSocket ) + gdk_window_shape_combine_region( widget_get_window(m_pSocket), m_pRegion, 0, 0 ); +} + +void GtkSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight ) +{ + if( m_pSocket ) + { + GtkFixed* pContainer = GTK_FIXED(gtk_widget_get_parent(m_pSocket)); + gtk_fixed_move( pContainer, m_pSocket, nX, nY ); + gtk_widget_set_size_request( m_pSocket, nWidth, nHeight ); + gtk_container_resize_children( GTK_CONTAINER(pContainer) ); + } +} + +void GtkSalObject::Show( bool bVisible ) +{ + if( m_pSocket ) + { + if( bVisible ) + gtk_widget_show( m_pSocket ); + else + gtk_widget_hide( m_pSocket ); + } +} + +const SystemEnvData* GtkSalObject::GetSystemData() const +{ + return &m_aSystemData; +} + +gboolean GtkSalObject::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer object ) +{ + GtkSalObject* pThis = static_cast<GtkSalObject*>(object); + + if( pEvent->type == GDK_BUTTON_PRESS ) + { + pThis->CallCallback( SALOBJ_EVENT_TOTOP, nullptr ); + } + + return FALSE; +} + +gboolean GtkSalObject::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer object ) +{ + GtkSalObject* pThis = static_cast<GtkSalObject*>(object); + + pThis->CallCallback( pEvent->in ? SALOBJ_EVENT_GETFOCUS : SALOBJ_EVENT_LOSEFOCUS, nullptr ); + + return FALSE; +} + +void GtkSalObject::signalDestroy( GtkWidget* pObj, gpointer object ) +{ + GtkSalObject* pThis = static_cast<GtkSalObject*>(object); + if( pObj == pThis->m_pSocket ) + { + pThis->m_pSocket = nullptr; + } +} + +void GtkSalObject::SetForwardKey( bool bEnable ) +{ + if( bEnable ) + gtk_widget_add_events( GTK_WIDGET( m_pSocket ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE ); + else + gtk_widget_set_events( GTK_WIDGET( m_pSocket ), ~(GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE) & gtk_widget_get_events( GTK_WIDGET( m_pSocket ) ) ); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |