LCOV - code coverage report
Current view: top level - vcl/unx/gtk/window - gtkobject.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 93 1.1 %
Date: 2015-06-13 12:38:46 Functions: 2 17 11.8 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11