xref: /aoo41x/main/vcl/unx/gtk/window/gtkobject.cxx (revision 9f62ea84)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include <unx/gtk/gtkobject.hxx>
28 #include <unx/gtk/gtkframe.hxx>
29 #include <unx/gtk/gtkdata.hxx>
30 #include <unx/gtk/gtkinst.hxx>
31 
GtkSalObject(GtkSalFrame * pParent,sal_Bool bShow)32 GtkSalObject::GtkSalObject( GtkSalFrame* pParent, sal_Bool bShow )
33         : m_pSocket( NULL ),
34           m_pRegion( NULL )
35 {
36     if( pParent )
37     {
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 );
47 
48 
49         // make it transparent; some plugins may not insert
50         // their own window here but use the socket window itself
51         gtk_widget_set_app_paintable( m_pSocket, TRUE );
52 
53         //system data
54         SalDisplay* pDisp = GetX11SalData()->GetDisplay();
55         m_aSystemData.nSize 		= sizeof( SystemChildData );
56         m_aSystemData.pDisplay		= pDisp->GetDisplay();
57         m_aSystemData.aWindow		= GDK_WINDOW_XWINDOW(m_pSocket->window);
58         m_aSystemData.pSalFrame		= NULL;
59         m_aSystemData.pWidget		= m_pSocket;
60         m_aSystemData.pVisual		= pDisp->GetVisual(pParent->getScreenNumber()).GetVisual();
61         m_aSystemData.nScreen		= pParent->getScreenNumber();
62         m_aSystemData.nDepth		= pDisp->GetVisual(pParent->getScreenNumber()).GetDepth();
63         m_aSystemData.aColormap		= pDisp->GetColormap(pParent->getScreenNumber()).GetXColormap();
64         m_aSystemData.pAppContext	= NULL;
65         m_aSystemData.aShellWindow	= GDK_WINDOW_XWINDOW(GTK_WIDGET(pParent->getWindow())->window);
66         m_aSystemData.pShellWidget	= GTK_WIDGET(pParent->getWindow());
67 
68         g_signal_connect( G_OBJECT(m_pSocket), "button-press-event", G_CALLBACK(signalButton), this );
69         g_signal_connect( G_OBJECT(m_pSocket), "button-release-event", G_CALLBACK(signalButton), this );
70         g_signal_connect( G_OBJECT(m_pSocket), "focus-in-event", G_CALLBACK(signalFocus), this );
71         g_signal_connect( G_OBJECT(m_pSocket), "focus-out-event", G_CALLBACK(signalFocus), this );
72         g_signal_connect( G_OBJECT(m_pSocket), "destroy", G_CALLBACK(signalDestroy), this );
73 
74         // #i59255# necessary due to sync effects with java child windows
75         pParent->Sync();
76     }
77 }
78 
~GtkSalObject()79 GtkSalObject::~GtkSalObject()
80 {
81     if( m_pRegion )
82         gdk_region_destroy( m_pRegion );
83     if( m_pSocket )
84     {
85         // remove socket from parent frame's fixed container
86         gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(m_pSocket)),
87                               m_pSocket );
88         // get rid of the socket
89         // actually the gtk_container_remove should let the ref count
90         // of the socket sink to 0 and destroy it (see signalDestroy)
91         // this is just a sanity check
92         if( m_pSocket )
93             gtk_widget_destroy( m_pSocket );
94     }
95 }
96 
ResetClipRegion()97 void GtkSalObject::ResetClipRegion()
98 {
99     if( m_pSocket )
100         gdk_window_shape_combine_region( m_pSocket->window, NULL, 0, 0 );
101 }
102 
GetClipRegionType()103 sal_uInt16 GtkSalObject::GetClipRegionType()
104 {
105     return SAL_OBJECT_CLIP_INCLUDERECTS;
106 }
107 
BeginSetClipRegion(sal_uLong)108 void GtkSalObject::BeginSetClipRegion( sal_uLong )
109 {
110     if( m_pRegion )
111         gdk_region_destroy( m_pRegion );
112     m_pRegion = gdk_region_new();
113 }
114 
UnionClipRegion(long nX,long nY,long nWidth,long nHeight)115 void GtkSalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
116 {
117     GdkRectangle aRect;
118     aRect.x			= nX;
119     aRect.y			= nY;
120     aRect.width		= nWidth;
121     aRect.height	= nHeight;
122 
123     gdk_region_union_with_rect( m_pRegion, &aRect );
124 }
125 
EndSetClipRegion()126 void GtkSalObject::EndSetClipRegion()
127 {
128     if( m_pSocket )
129         gdk_window_shape_combine_region( m_pSocket->window, m_pRegion, 0, 0 );
130 }
131 
SetPosSize(long nX,long nY,long nWidth,long nHeight)132 void GtkSalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
133 {
134     if( m_pSocket )
135     {
136         GtkFixed* pContainer = GTK_FIXED(gtk_widget_get_parent(m_pSocket));
137         gtk_fixed_move( pContainer, m_pSocket, nX, nY );
138         gtk_widget_set_size_request( m_pSocket, nWidth, nHeight );
139         gtk_container_resize_children( GTK_CONTAINER(pContainer) );
140     }
141 }
142 
Show(sal_Bool bVisible)143 void GtkSalObject::Show( sal_Bool bVisible )
144 {
145     if( m_pSocket )
146     {
147         if( bVisible )
148             gtk_widget_show( m_pSocket );
149         else
150             gtk_widget_hide( m_pSocket );
151     }
152 }
153 
Enable(sal_Bool)154 void GtkSalObject::Enable( sal_Bool )
155 {
156 }
157 
GrabFocus()158 void GtkSalObject::GrabFocus()
159 {
160 }
161 
SetBackground()162 void GtkSalObject::SetBackground()
163 {
164 }
165 
SetBackground(SalColor)166 void GtkSalObject::SetBackground( SalColor )
167 {
168 }
169 
GetSystemData() const170 const SystemEnvData* GtkSalObject::GetSystemData() const
171 {
172     return &m_aSystemData;
173 }
174 
175 
signalButton(GtkWidget *,GdkEventButton * pEvent,gpointer object)176 gboolean GtkSalObject::signalButton( GtkWidget*, GdkEventButton* pEvent, gpointer object )
177 {
178     GtkSalObject* pThis = (GtkSalObject*)object;
179 
180     if( pEvent->type == GDK_BUTTON_PRESS )
181     {
182         GTK_YIELD_GRAB();
183         pThis->CallCallback( SALOBJ_EVENT_TOTOP, NULL );
184     }
185 
186     return FALSE;
187 }
188 
signalFocus(GtkWidget *,GdkEventFocus * pEvent,gpointer object)189 gboolean GtkSalObject::signalFocus( GtkWidget*, GdkEventFocus* pEvent, gpointer object )
190 {
191     GtkSalObject* pThis = (GtkSalObject*)object;
192 
193     GTK_YIELD_GRAB();
194 
195     pThis->CallCallback( pEvent->in ? SALOBJ_EVENT_GETFOCUS : SALOBJ_EVENT_LOSEFOCUS, NULL );
196 
197     return FALSE;
198 }
199 
signalDestroy(GtkObject * pObj,gpointer object)200 void GtkSalObject::signalDestroy( GtkObject* pObj, gpointer object )
201 {
202     GtkSalObject* pThis = (GtkSalObject*)object;
203     if( GTK_WIDGET(pObj) == pThis->m_pSocket )
204     {
205         pThis->m_pSocket = NULL;
206     }
207 }
208 
InterceptChildWindowKeyDown(sal_Bool)209 void GtkSalObject::InterceptChildWindowKeyDown( sal_Bool /*bIntercept*/ )
210 {
211 }
212 
213