Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #ifdef AIX
31 : : #define _LINUX_SOURCE_COMPAT
32 : : #include <sys/timer.h>
33 : : #undef _LINUX_SOURCE_COMPAT
34 : : #endif
35 : :
36 : : #include <unx/gtk/gtkobject.hxx>
37 : : #include <unx/gtk/gtkframe.hxx>
38 : : #include <unx/gtk/gtkdata.hxx>
39 : : #include <unx/gtk/gtkinst.hxx>
40 : : #include <unx/gtk/gtkgdi.hxx>
41 : :
42 : 0 : GtkSalObject::GtkSalObject( GtkSalFrame* pParent, sal_Bool bShow )
43 : : : m_pSocket( NULL ),
44 : 0 : m_pRegion( NULL )
45 : : {
46 : 0 : if( pParent )
47 : : {
48 : : // our plug window
49 : 0 : m_pSocket = gtk_drawing_area_new();
50 : 0 : Show( bShow );
51 : : // insert into container
52 : : gtk_fixed_put( pParent->getFixedContainer(),
53 : : m_pSocket,
54 : 0 : 0, 0 );
55 : : // realize so we can get a window id
56 : 0 : gtk_widget_realize( m_pSocket );
57 : :
58 : : // make it transparent; some plugins may not insert
59 : : // their own window here but use the socket window itself
60 : 0 : gtk_widget_set_app_paintable( m_pSocket, TRUE );
61 : :
62 : : // system data
63 : 0 : SalDisplay* pDisp = GetGenericData()->GetSalDisplay();
64 : 0 : m_aSystemData.nSize = sizeof( SystemChildData );
65 : 0 : m_aSystemData.pDisplay = pDisp->GetDisplay();
66 : 0 : m_aSystemData.aWindow = GDK_WINDOW_XWINDOW(widget_get_window(m_pSocket));
67 : 0 : m_aSystemData.pSalFrame = NULL;
68 : 0 : m_aSystemData.pWidget = m_pSocket;
69 : 0 : m_aSystemData.pVisual = pDisp->GetVisual(pParent->getXScreenNumber()).GetVisual();
70 : 0 : m_aSystemData.nScreen = pParent->getXScreenNumber().getXScreen();
71 : 0 : m_aSystemData.nDepth = pDisp->GetVisual(pParent->getXScreenNumber()).GetDepth();
72 : 0 : m_aSystemData.aColormap = pDisp->GetColormap(pParent->getXScreenNumber()).GetXColormap();
73 : 0 : m_aSystemData.pAppContext = NULL;
74 : 0 : m_aSystemData.aShellWindow = GDK_WINDOW_XWINDOW(widget_get_window(GTK_WIDGET(pParent->getWindow())));
75 : 0 : m_aSystemData.pShellWidget = GTK_WIDGET(pParent->getWindow());
76 : :
77 : 0 : g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this );
78 : 0 : g_signal_connect( G_OBJECT(m_pSocket), "button-release-event", G_CALLBACK(signalButton), this );
79 : 0 : g_signal_connect( G_OBJECT(m_pSocket), "focus-in-event", G_CALLBACK(signalFocus), this );
80 : 0 : g_signal_connect( G_OBJECT(m_pSocket), "focus-out-event", G_CALLBACK(signalFocus), this );
81 : 0 : g_signal_connect( G_OBJECT(m_pSocket), "destroy", G_CALLBACK(signalDestroy), this );
82 : :
83 : : // #i59255# necessary due to sync effects with java child windows
84 : 0 : pParent->Sync();
85 : : }
86 : 0 : }
87 : :
88 : 0 : GtkSalObject::~GtkSalObject()
89 : : {
90 : 0 : if( m_pRegion )
91 : : {
92 : : #if GTK_CHECK_VERSION(3,0,0)
93 : : cairo_region_destroy( m_pRegion );
94 : : #else
95 : 0 : gdk_region_destroy( m_pRegion );
96 : : #endif
97 : : }
98 : 0 : if( m_pSocket )
99 : : {
100 : : // remove socket from parent frame's fixed container
101 : 0 : gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(m_pSocket)),
102 : 0 : m_pSocket );
103 : : // get rid of the socket
104 : : // actually the gtk_container_remove should let the ref count
105 : : // of the socket sink to 0 and destroy it (see signalDestroy)
106 : : // this is just a sanity check
107 : 0 : if( m_pSocket )
108 : 0 : gtk_widget_destroy( m_pSocket );
109 : : }
110 : 0 : }
111 : :
112 : 0 : void GtkSalObject::ResetClipRegion()
113 : : {
114 : 0 : if( m_pSocket )
115 : 0 : gdk_window_shape_combine_region( widget_get_window(m_pSocket), NULL, 0, 0 );
116 : 0 : }
117 : :
118 : 0 : sal_uInt16 GtkSalObject::GetClipRegionType()
119 : : {
120 : 0 : return SAL_OBJECT_CLIP_INCLUDERECTS;
121 : : }
122 : :
123 : 0 : void GtkSalObject::BeginSetClipRegion( sal_uLong )
124 : : {
125 : : #if GTK_CHECK_VERSION(3,0,0)
126 : : if( m_pRegion )
127 : : cairo_region_destroy( m_pRegion );
128 : : m_pRegion = cairo_region_create();
129 : : #else
130 : 0 : if( m_pRegion )
131 : 0 : gdk_region_destroy( m_pRegion );
132 : 0 : m_pRegion = gdk_region_new();
133 : : #endif
134 : 0 : }
135 : :
136 : 0 : void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
137 : : {
138 : : GdkRectangle aRect;
139 : 0 : aRect.x = nX;
140 : 0 : aRect.y = nY;
141 : 0 : aRect.width = nWidth;
142 : 0 : aRect.height = nHeight;
143 : :
144 : : #if GTK_CHECK_VERSION(3,0,0)
145 : : cairo_region_union_rectangle( m_pRegion, &aRect );
146 : : #else
147 : 0 : gdk_region_union_with_rect( m_pRegion, &aRect );
148 : : #endif
149 : 0 : }
150 : :
151 : 0 : void GtkSalObject::EndSetClipRegion()
152 : : {
153 : 0 : if( m_pSocket )
154 : 0 : gdk_window_shape_combine_region( widget_get_window(m_pSocket), m_pRegion, 0, 0 );
155 : 0 : }
156 : :
157 : 0 : void GtkSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
158 : : {
159 : 0 : if( m_pSocket )
160 : : {
161 : 0 : GtkFixed* pContainer = GTK_FIXED(gtk_widget_get_parent(m_pSocket));
162 : 0 : gtk_fixed_move( pContainer, m_pSocket, nX, nY );
163 : 0 : gtk_widget_set_size_request( m_pSocket, nWidth, nHeight );
164 : 0 : gtk_container_resize_children( GTK_CONTAINER(pContainer) );
165 : : }
166 : 0 : }
167 : :
168 : 0 : void GtkSalObject::Show( sal_Bool bVisible )
169 : : {
170 : 0 : if( m_pSocket )
171 : : {
172 : 0 : if( bVisible )
173 : 0 : gtk_widget_show( m_pSocket );
174 : : else
175 : 0 : gtk_widget_hide( m_pSocket );
176 : : }
177 : 0 : }
178 : :
179 : 0 : const SystemEnvData* GtkSalObject::GetSystemData() const
180 : : {
181 : 0 : return &m_aSystemData;
182 : : }
183 : :
184 : 0 : gboolean GtkSalObject::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer object )
185 : : {
186 : 0 : GtkSalObject* pThis = (GtkSalObject*)object;
187 : :
188 : 0 : if( pEvent->type == GDK_BUTTON_PRESS )
189 : : {
190 : 0 : GTK_YIELD_GRAB();
191 : 0 : pThis->CallCallback( SALOBJ_EVENT_TOTOP, NULL );
192 : : }
193 : :
194 : 0 : return FALSE;
195 : : }
196 : :
197 : 0 : gboolean GtkSalObject::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer object )
198 : : {
199 : 0 : GtkSalObject* pThis = (GtkSalObject*)object;
200 : :
201 : 0 : GTK_YIELD_GRAB();
202 : :
203 : 0 : pThis->CallCallback( pEvent->in ? SALOBJ_EVENT_GETFOCUS : SALOBJ_EVENT_LOSEFOCUS, NULL );
204 : :
205 : 0 : return FALSE;
206 : : }
207 : :
208 : 0 : void GtkSalObject::signalDestroy( GtkWidget* pObj, gpointer object )
209 : : {
210 : 0 : GtkSalObject* pThis = (GtkSalObject*)object;
211 : 0 : if( pObj == pThis->m_pSocket )
212 : : {
213 : 0 : pThis->m_pSocket = NULL;
214 : : }
215 : 0 : }
216 : :
217 : 0 : void GtkSalObject::SetForwardKey( sal_Bool bEnable )
218 : : {
219 : 0 : if( bEnable )
220 : 0 : gtk_widget_add_events( GTK_WIDGET( m_pSocket ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE );
221 : : else
222 : 0 : gtk_widget_set_events( GTK_WIDGET( m_pSocket ), ~(GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE) & gtk_widget_get_events( GTK_WIDGET( m_pSocket ) ) );
223 : 0 : }
224 : :
225 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|