Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / unx / gtk3 / gtk3gtkobject.cxx
blob48e2436e67bf93dbd30bc7ef1999e7bff1498200
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 #ifdef AIX
21 #define _LINUX_SOURCE_COMPAT
22 #include <sys/timer.h>
23 #undef _LINUX_SOURCE_COMPAT
24 #endif
26 #include <unx/gtk/gtkobject.hxx>
27 #include <unx/gtk/gtkframe.hxx>
28 #include <unx/gtk/gtkdata.hxx>
29 #include <unx/gtk/gtkinst.hxx>
30 #include <unx/gtk/gtkgdi.hxx>
32 GtkSalObject::GtkSalObject( GtkSalFrame* pParent, bool bShow )
33 : m_pSocket(nullptr)
34 , m_pParent(pParent)
35 , m_pRegion(nullptr)
37 if( !pParent )
38 return;
40 // our plug window
41 m_pSocket = gtk_grid_new();
42 Show( bShow );
43 // insert into container
44 gtk_fixed_put( pParent->getFixedContainer(),
45 m_pSocket,
46 0, 0 );
47 // realize so we can get a window id
48 gtk_widget_realize( m_pSocket );
50 // system data
51 m_aSystemData.nSize = sizeof( SystemEnvData );
52 m_aSystemData.aWindow = pParent->GetNativeWindowHandle(m_pSocket);
53 m_aSystemData.aShellWindow = reinterpret_cast<sal_IntPtr>(this);
54 m_aSystemData.pSalFrame = nullptr;
55 m_aSystemData.pWidget = m_pSocket;
56 m_aSystemData.nScreen = pParent->getXScreenNumber().getXScreen();
57 m_aSystemData.pToolkit = "gtk3";
58 GdkScreen* pScreen = gtk_window_get_screen(GTK_WINDOW(pParent->getWindow()));
59 GdkVisual* pVisual = gdk_screen_get_system_visual(pScreen);
61 #if defined(GDK_WINDOWING_X11)
62 GdkDisplay *pDisplay = GtkSalFrame::getGdkDisplay();
63 if (GDK_IS_X11_DISPLAY(pDisplay))
65 m_aSystemData.pDisplay = gdk_x11_display_get_xdisplay(pDisplay);
66 m_aSystemData.pVisual = gdk_x11_visual_get_xvisual(pVisual);
68 #endif
70 g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this );
71 g_signal_connect( G_OBJECT(m_pSocket), "button-release-event", G_CALLBACK(signalButton), this );
72 g_signal_connect( G_OBJECT(m_pSocket), "focus-in-event", G_CALLBACK(signalFocus), this );
73 g_signal_connect( G_OBJECT(m_pSocket), "focus-out-event", G_CALLBACK(signalFocus), this );
74 g_signal_connect( G_OBJECT(m_pSocket), "destroy", G_CALLBACK(signalDestroy), this );
76 // #i59255# necessary due to sync effects with java child windows
77 pParent->Flush();
81 GtkSalObject::~GtkSalObject()
83 if( m_pRegion )
85 cairo_region_destroy( m_pRegion );
87 if( m_pSocket )
89 // remove socket from parent frame's fixed container
90 gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(m_pSocket)),
91 m_pSocket );
92 // get rid of the socket
93 // actually the gtk_container_remove should let the ref count
94 // of the socket sink to 0 and destroy it (see signalDestroy)
95 // this is just a sanity check
96 if( m_pSocket )
97 gtk_widget_destroy( m_pSocket );
101 void GtkSalObject::ResetClipRegion()
103 if( m_pSocket )
104 gdk_window_shape_combine_region( widget_get_window(m_pSocket), nullptr, 0, 0 );
107 void GtkSalObject::BeginSetClipRegion( sal_uLong )
109 if( m_pRegion )
110 cairo_region_destroy( m_pRegion );
111 m_pRegion = cairo_region_create();
114 void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
116 GdkRectangle aRect;
117 aRect.x = nX;
118 aRect.y = nY;
119 aRect.width = nWidth;
120 aRect.height = nHeight;
122 cairo_region_union_rectangle( m_pRegion, &aRect );
125 void GtkSalObject::EndSetClipRegion()
127 if( m_pSocket )
128 gdk_window_shape_combine_region( widget_get_window(m_pSocket), m_pRegion, 0, 0 );
131 void GtkSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
133 if( m_pSocket )
135 GtkFixed* pContainer = GTK_FIXED(gtk_widget_get_parent(m_pSocket));
136 gtk_fixed_move( pContainer, m_pSocket, nX, nY );
137 gtk_widget_set_size_request( m_pSocket, nWidth, nHeight );
138 m_pParent->nopaint_container_resize_children(GTK_CONTAINER(pContainer));
142 void GtkSalObject::Show( bool bVisible )
144 if( m_pSocket )
146 if( bVisible )
147 gtk_widget_show( m_pSocket );
148 else
149 gtk_widget_hide( m_pSocket );
153 const SystemEnvData* GtkSalObject::GetSystemData() const
155 return &m_aSystemData;
158 gboolean GtkSalObject::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer object )
160 GtkSalObject* pThis = static_cast<GtkSalObject*>(object);
162 if( pEvent->type == GDK_BUTTON_PRESS )
164 pThis->CallCallback( SalObjEvent::ToTop );
167 return FALSE;
170 gboolean GtkSalObject::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer object )
172 GtkSalObject* pThis = static_cast<GtkSalObject*>(object);
174 pThis->CallCallback( pEvent->in ? SalObjEvent::GetFocus : SalObjEvent::LoseFocus );
176 return FALSE;
179 void GtkSalObject::signalDestroy( GtkWidget* pObj, gpointer object )
181 GtkSalObject* pThis = static_cast<GtkSalObject*>(object);
182 if( pObj == pThis->m_pSocket )
184 pThis->m_pSocket = nullptr;
188 void GtkSalObject::SetForwardKey( bool bEnable )
190 if( bEnable )
191 gtk_widget_add_events( GTK_WIDGET( m_pSocket ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE );
192 else
193 gtk_widget_set_events( GTK_WIDGET( m_pSocket ), ~(GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE) & gtk_widget_get_events( GTK_WIDGET( m_pSocket ) ) );
196 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */