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