update emoji autocorrect entries from po-files
[LibreOffice.git] / vcl / unx / gtk / window / gtkobject.cxx
blob3de060bdc843aeec1bf51522de296504f289ed3f
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( NULL ),
34 m_pRegion( NULL )
36 if( pParent )
38 // our plug window
39 m_pSocket = gtk_drawing_area_new();
40 Show( bShow );
41 // insert into container
42 gtk_fixed_put( pParent->getFixedContainer(),
43 m_pSocket,
44 0, 0 );
45 // realize so we can get a window id
46 gtk_widget_realize( m_pSocket );
48 // make it transparent; some plugins may not insert
49 // their own window here but use the socket window itself
50 gtk_widget_set_app_paintable( m_pSocket, TRUE );
52 // system data
53 m_aSystemData.nSize = sizeof( SystemEnvData );
54 #if !GTK_CHECK_VERSION(3,0,0)
55 SalDisplay* pDisp = vcl_sal::getSalDisplay(GetGenericData());
56 m_aSystemData.pDisplay = pDisp->GetDisplay();
57 m_aSystemData.pVisual = pDisp->GetVisual(pParent->getXScreenNumber()).GetVisual();
58 m_aSystemData.nDepth = pDisp->GetVisual(pParent->getXScreenNumber()).GetDepth();
59 m_aSystemData.aColormap = pDisp->GetColormap(pParent->getXScreenNumber()).GetXColormap();
60 m_aSystemData.aWindow = GDK_WINDOW_XWINDOW(widget_get_window(m_pSocket));
61 m_aSystemData.aShellWindow = GDK_WINDOW_XWINDOW(widget_get_window(GTK_WIDGET(pParent->getWindow())));
62 #else
63 static int nWindow = 0;
64 m_aSystemData.aWindow = nWindow;
65 m_aSystemData.aShellWindow = pParent->GetSystemData()->aWindow;
66 ++nWindow;
67 #endif
68 m_aSystemData.pSalFrame = NULL;
69 m_aSystemData.pWidget = m_pSocket;
70 m_aSystemData.nScreen = pParent->getXScreenNumber().getXScreen();
71 m_aSystemData.pAppContext = NULL;
72 m_aSystemData.pShellWidget = GTK_WIDGET(pParent->getWindow());
74 g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this );
75 g_signal_connect( G_OBJECT(m_pSocket), "button-release-event", G_CALLBACK(signalButton), this );
76 g_signal_connect( G_OBJECT(m_pSocket), "focus-in-event", G_CALLBACK(signalFocus), this );
77 g_signal_connect( G_OBJECT(m_pSocket), "focus-out-event", G_CALLBACK(signalFocus), this );
78 g_signal_connect( G_OBJECT(m_pSocket), "destroy", G_CALLBACK(signalDestroy), this );
80 // #i59255# necessary due to sync effects with java child windows
81 pParent->Sync();
85 GtkSalObject::~GtkSalObject()
87 if( m_pRegion )
89 #if GTK_CHECK_VERSION(3,0,0)
90 cairo_region_destroy( m_pRegion );
91 #else
92 gdk_region_destroy( m_pRegion );
93 #endif
95 if( m_pSocket )
97 // remove socket from parent frame's fixed container
98 gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(m_pSocket)),
99 m_pSocket );
100 // get rid of the socket
101 // actually the gtk_container_remove should let the ref count
102 // of the socket sink to 0 and destroy it (see signalDestroy)
103 // this is just a sanity check
104 if( m_pSocket )
105 gtk_widget_destroy( m_pSocket );
109 void GtkSalObject::ResetClipRegion()
111 if( m_pSocket )
112 gdk_window_shape_combine_region( widget_get_window(m_pSocket), NULL, 0, 0 );
115 sal_uInt16 GtkSalObject::GetClipRegionType()
117 return SAL_OBJECT_CLIP_INCLUDERECTS;
120 void GtkSalObject::BeginSetClipRegion( sal_uLong )
122 #if GTK_CHECK_VERSION(3,0,0)
123 if( m_pRegion )
124 cairo_region_destroy( m_pRegion );
125 m_pRegion = cairo_region_create();
126 #else
127 if( m_pRegion )
128 gdk_region_destroy( m_pRegion );
129 m_pRegion = gdk_region_new();
130 #endif
133 void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
135 GdkRectangle aRect;
136 aRect.x = nX;
137 aRect.y = nY;
138 aRect.width = nWidth;
139 aRect.height = nHeight;
141 #if GTK_CHECK_VERSION(3,0,0)
142 cairo_region_union_rectangle( m_pRegion, &aRect );
143 #else
144 gdk_region_union_with_rect( m_pRegion, &aRect );
145 #endif
148 void GtkSalObject::EndSetClipRegion()
150 if( m_pSocket )
151 gdk_window_shape_combine_region( widget_get_window(m_pSocket), m_pRegion, 0, 0 );
154 void GtkSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
156 if( m_pSocket )
158 GtkFixed* pContainer = GTK_FIXED(gtk_widget_get_parent(m_pSocket));
159 gtk_fixed_move( pContainer, m_pSocket, nX, nY );
160 gtk_widget_set_size_request( m_pSocket, nWidth, nHeight );
161 gtk_container_resize_children( GTK_CONTAINER(pContainer) );
165 void GtkSalObject::Show( bool bVisible )
167 if( m_pSocket )
169 if( bVisible )
170 gtk_widget_show( m_pSocket );
171 else
172 gtk_widget_hide( m_pSocket );
176 const SystemEnvData* GtkSalObject::GetSystemData() const
178 return &m_aSystemData;
181 gboolean GtkSalObject::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer object )
183 GtkSalObject* pThis = static_cast<GtkSalObject*>(object);
185 if( pEvent->type == GDK_BUTTON_PRESS )
187 pThis->CallCallback( SALOBJ_EVENT_TOTOP, NULL );
190 return FALSE;
193 gboolean GtkSalObject::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer object )
195 GtkSalObject* pThis = static_cast<GtkSalObject*>(object);
197 pThis->CallCallback( pEvent->in ? SALOBJ_EVENT_GETFOCUS : SALOBJ_EVENT_LOSEFOCUS, NULL );
199 return FALSE;
202 void GtkSalObject::signalDestroy( GtkWidget* pObj, gpointer object )
204 GtkSalObject* pThis = static_cast<GtkSalObject*>(object);
205 if( pObj == pThis->m_pSocket )
207 pThis->m_pSocket = NULL;
211 void GtkSalObject::SetForwardKey( bool bEnable )
213 if( bEnable )
214 gtk_widget_add_events( GTK_WIDGET( m_pSocket ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE );
215 else
216 gtk_widget_set_events( GTK_WIDGET( m_pSocket ), ~(GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE) & gtk_widget_get_events( GTK_WIDGET( m_pSocket ) ) );
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */