1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #define _LINUX_SOURCE_COMPAT
22 #include <sys/timer.h>
23 #undef _LINUX_SOURCE_COMPAT
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
)
41 m_pSocket
= gtk_grid_new();
43 // insert into container
44 gtk_fixed_put( pParent
->getFixedContainer(),
47 // realize so we can get a window id
48 gtk_widget_realize( m_pSocket
);
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
);
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
81 GtkSalObject::~GtkSalObject()
85 cairo_region_destroy( m_pRegion
);
89 // remove socket from parent frame's fixed container
90 gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(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
97 gtk_widget_destroy( m_pSocket
);
101 void GtkSalObject::ResetClipRegion()
104 gdk_window_shape_combine_region( widget_get_window(m_pSocket
), nullptr, 0, 0 );
107 void GtkSalObject::BeginSetClipRegion( sal_uLong
)
110 cairo_region_destroy( m_pRegion
);
111 m_pRegion
= cairo_region_create();
114 void GtkSalObject::UnionClipRegion( long nX
, long nY
, long nWidth
, long nHeight
)
119 aRect
.width
= nWidth
;
120 aRect
.height
= nHeight
;
122 cairo_region_union_rectangle( m_pRegion
, &aRect
);
125 void GtkSalObject::EndSetClipRegion()
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
)
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
)
147 gtk_widget_show( m_pSocket
);
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
);
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
);
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
)
191 gtk_widget_add_events( GTK_WIDGET( m_pSocket
), GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE
);
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: */