1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gtkobject.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #include <plugins/gtk/gtkobject.hxx>
35 #include <plugins/gtk/gtkframe.hxx>
36 #include <plugins/gtk/gtkdata.hxx>
37 #include <plugins/gtk/gtkinst.hxx>
39 GtkSalObject::GtkSalObject( GtkSalFrame
* pParent
, BOOL bShow
)
46 m_pSocket
= gtk_drawing_area_new();
48 // insert into container
49 gtk_fixed_put( pParent
->getFixedContainer(),
52 // realize so we can get a window id
53 gtk_widget_realize( m_pSocket
);
56 // make it transparent; some plugins may not insert
57 // their own window here but use the socket window itself
58 gtk_widget_set_app_paintable( m_pSocket
, TRUE
);
61 SalDisplay
* pDisp
= GetX11SalData()->GetDisplay();
62 m_aSystemData
.nSize
= sizeof( SystemChildData
);
63 m_aSystemData
.pDisplay
= pDisp
->GetDisplay();
64 m_aSystemData
.aWindow
= GDK_WINDOW_XWINDOW(m_pSocket
->window
);
65 m_aSystemData
.pSalFrame
= NULL
;
66 m_aSystemData
.pWidget
= m_pSocket
;
67 m_aSystemData
.pVisual
= pDisp
->GetVisual(pParent
->getScreenNumber()).GetVisual();
68 m_aSystemData
.nScreen
= pParent
->getScreenNumber();
69 m_aSystemData
.nDepth
= pDisp
->GetVisual(pParent
->getScreenNumber()).GetDepth();
70 m_aSystemData
.aColormap
= pDisp
->GetColormap(pParent
->getScreenNumber()).GetXColormap();
71 m_aSystemData
.pAppContext
= NULL
;
72 m_aSystemData
.aShellWindow
= GDK_WINDOW_XWINDOW(GTK_WIDGET(pParent
->getWindow())->window
);
73 m_aSystemData
.pShellWidget
= GTK_WIDGET(pParent
->getWindow());
75 g_signal_connect( G_OBJECT(m_pSocket
), "button-press-event", G_CALLBACK(signalButton
), this );
76 g_signal_connect( G_OBJECT(m_pSocket
), "button-release-event", G_CALLBACK(signalButton
), this );
77 g_signal_connect( G_OBJECT(m_pSocket
), "focus-in-event", G_CALLBACK(signalFocus
), this );
78 g_signal_connect( G_OBJECT(m_pSocket
), "focus-out-event", G_CALLBACK(signalFocus
), this );
79 g_signal_connect( G_OBJECT(m_pSocket
), "destroy", G_CALLBACK(signalDestroy
), this );
81 // #i59255# necessary due to sync effects with java child windows
86 GtkSalObject::~GtkSalObject()
89 gdk_region_destroy( m_pRegion
);
92 // remove socket from parent frame's fixed container
93 gtk_container_remove( GTK_CONTAINER(gtk_widget_get_parent(m_pSocket
)),
95 // get rid of the socket
96 // actually the gtk_container_remove should let the ref count
97 // of the socket sink to 0 and destroy it (see signalDestroy)
98 // this is just a sanity check
100 gtk_widget_destroy( m_pSocket
);
104 void GtkSalObject::ResetClipRegion()
107 gdk_window_shape_combine_region( m_pSocket
->window
, NULL
, 0, 0 );
110 USHORT
GtkSalObject::GetClipRegionType()
112 return SAL_OBJECT_CLIP_INCLUDERECTS
;
115 void GtkSalObject::BeginSetClipRegion( ULONG
)
118 gdk_region_destroy( m_pRegion
);
119 m_pRegion
= gdk_region_new();
122 void GtkSalObject::UnionClipRegion( long nX
, long nY
, long nWidth
, long nHeight
)
127 aRect
.width
= nWidth
;
128 aRect
.height
= nHeight
;
130 gdk_region_union_with_rect( m_pRegion
, &aRect
);
133 void GtkSalObject::EndSetClipRegion()
136 gdk_window_shape_combine_region( m_pSocket
->window
, m_pRegion
, 0, 0 );
139 void GtkSalObject::SetPosSize( long nX
, long nY
, long nWidth
, long nHeight
)
143 GtkFixed
* pContainer
= GTK_FIXED(gtk_widget_get_parent(m_pSocket
));
144 gtk_fixed_move( pContainer
, m_pSocket
, nX
, nY
);
145 gtk_widget_set_size_request( m_pSocket
, nWidth
, nHeight
);
146 gtk_container_resize_children( GTK_CONTAINER(pContainer
) );
150 void GtkSalObject::Show( BOOL bVisible
)
155 gtk_widget_show( m_pSocket
);
157 gtk_widget_hide( m_pSocket
);
161 void GtkSalObject::Enable( BOOL
)
165 void GtkSalObject::GrabFocus()
169 void GtkSalObject::SetBackground()
173 void GtkSalObject::SetBackground( SalColor
)
177 const SystemEnvData
* GtkSalObject::GetSystemData() const
179 return &m_aSystemData
;
183 gboolean
GtkSalObject::signalButton( GtkWidget
*, GdkEventButton
* pEvent
, gpointer object
)
185 GtkSalObject
* pThis
= (GtkSalObject
*)object
;
187 if( pEvent
->type
== GDK_BUTTON_PRESS
)
190 pThis
->CallCallback( SALOBJ_EVENT_TOTOP
, NULL
);
196 gboolean
GtkSalObject::signalFocus( GtkWidget
*, GdkEventFocus
* pEvent
, gpointer object
)
198 GtkSalObject
* pThis
= (GtkSalObject
*)object
;
202 pThis
->CallCallback( pEvent
->in
? SALOBJ_EVENT_GETFOCUS
: SALOBJ_EVENT_LOSEFOCUS
, NULL
);
207 void GtkSalObject::signalDestroy( GtkObject
* pObj
, gpointer object
)
209 GtkSalObject
* pThis
= (GtkSalObject
*)object
;
210 if( GTK_WIDGET(pObj
) == pThis
->m_pSocket
)
212 pThis
->m_pSocket
= NULL
;
216 void GtkSalObject::SetForwardKey( BOOL bEnable
)
218 printf ("GtkSalObject::SetForwardKey\n");
220 gtk_widget_add_events( GTK_WIDGET( m_pSocket
), GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE
);
222 gtk_widget_set_events( GTK_WIDGET( m_pSocket
), ~(GDK_KEY_PRESS_MASK
| GDK_KEY_RELEASE
) & gtk_widget_get_events( GTK_WIDGET( m_pSocket
) ) );