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