LCOV - code coverage report
Current view: top level - vcl/unx/generic/window - salobj.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 239 0.4 %
Date: 2015-06-13 12:38:46 Functions: 2 23 8.7 %
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             : #if OSL_DEBUG_LEVEL > 1
      21             : #include <stdio.h>
      22             : #endif
      23             : 
      24             : #include <prex.h>
      25             : #include <X11/extensions/shape.h>
      26             : #include <postx.h>
      27             : #include <tools/debug.hxx>
      28             : 
      29             : #include <vcl/keycodes.hxx>
      30             : #include <vcl/event.hxx>
      31             : 
      32             : #include <unx/salunx.h>
      33             : #include <unx/saldata.hxx>
      34             : #include <unx/salinst.h>
      35             : #include <unx/saldisp.hxx>
      36             : #include <unx/salframe.h>
      37             : #include <unx/salobj.h>
      38             : 
      39             : #include <salwtype.hxx>
      40             : 
      41             : // SalInstance member to create and destroy a SalObject
      42             : 
      43           0 : SalObject* X11SalInstance::CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow )
      44             : {
      45           0 :     return X11SalObject::CreateObject( pParent, pWindowData, bShow );
      46             : }
      47             : 
      48           0 : X11SalObject* X11SalObject::CreateObject( SalFrame* pParent, SystemWindowData* pWindowData, bool bShow )
      49             : {
      50             :     int error_base, event_base;
      51           0 :     X11SalObject*       pObject  = new X11SalObject();
      52           0 :     SystemEnvData*    pObjData = const_cast<SystemEnvData*>(pObject->GetSystemData());
      53             : 
      54           0 :     if ( ! XShapeQueryExtension( static_cast<Display*>(pObjData->pDisplay),
      55           0 :                                   &event_base, &error_base ) )
      56             :     {
      57           0 :         delete pObject;
      58           0 :         return NULL;
      59             :     }
      60             : 
      61           0 :     pObject->mpParent = pParent;
      62             : 
      63           0 :     SalDisplay* pSalDisp        = vcl_sal::getSalDisplay(GetGenericData());
      64           0 :     const SystemEnvData* pEnv   = pParent->GetSystemData();
      65           0 :     Display* pDisp              = pSalDisp->GetDisplay();
      66           0 :     ::Window aObjectParent      = (::Window)pEnv->aWindow;
      67             : 
      68             :     // find out on which screen that window is
      69             :     XWindowAttributes aParentAttr;
      70           0 :     XGetWindowAttributes( pDisp, aObjectParent, &aParentAttr );
      71           0 :     SalX11Screen nXScreen( XScreenNumberOfScreen( aParentAttr.screen ) );
      72           0 :     Visual* pVisual = (pWindowData && pWindowData->pVisual) ?
      73             :                       static_cast<Visual*>(pWindowData->pVisual) :
      74           0 :                       pSalDisp->GetVisual( nXScreen ).GetVisual();
      75             :     // get visual info
      76           0 :     VisualID aVisID = XVisualIDFromVisual( pVisual );
      77             :     XVisualInfo aTemplate;
      78           0 :     aTemplate.visualid = aVisID;
      79           0 :     int nVisuals = 0;
      80           0 :     XVisualInfo* pInfos = XGetVisualInfo( pDisp, VisualIDMask, &aTemplate, &nVisuals );
      81             :     // only one VisualInfo structure can match the visual id
      82             :     DBG_ASSERT( nVisuals == 1, "match count for visual id is not 1" );
      83           0 :     unsigned int nDepth     = pInfos->depth;
      84           0 :     XFree( pInfos );
      85             :     XSetWindowAttributes aAttribs;
      86             :     aAttribs.event_mask =   StructureNotifyMask
      87             :                           | ButtonPressMask
      88             :                           | ButtonReleaseMask
      89             :                           | PointerMotionMask
      90             :                           | EnterWindowMask
      91             :                           | LeaveWindowMask
      92             :                           | FocusChangeMask
      93             :                           | ExposureMask
      94           0 :                           ;
      95             : 
      96             :     pObject->maPrimary =
      97             :         XCreateSimpleWindow( pDisp,
      98             :                              aObjectParent,
      99             :                              0, 0,
     100             :                              1, 1, 0,
     101           0 :                              pSalDisp->GetColormap( nXScreen ).GetBlackPixel(),
     102           0 :                              pSalDisp->GetColormap( nXScreen ).GetWhitePixel()
     103           0 :                              );
     104           0 :     if( aVisID == pSalDisp->GetVisual( nXScreen ).GetVisualId() )
     105             :     {
     106             :         pObject->maSecondary =
     107             :             XCreateSimpleWindow( pDisp,
     108             :                                  pObject->maPrimary,
     109             :                                  0, 0,
     110             :                                  1, 1, 0,
     111           0 :                                  pSalDisp->GetColormap( nXScreen ).GetBlackPixel(),
     112           0 :                                  pSalDisp->GetColormap( nXScreen ).GetWhitePixel()
     113           0 :                                  );
     114             :     }
     115             :     else
     116             :     {
     117             :         #if OSL_DEBUG_LEVEL > 1
     118             :         fprintf( stderr, "visual id of vcl %x, of visual %x\n",
     119             :                  static_cast<unsigned int> (pSalDisp->GetVisual( nXScreen ).GetVisualId()),
     120             :                  static_cast<unsigned int> (aVisID) );
     121             :         #endif
     122           0 :         GetGenericData()->ErrorTrapPush();
     123             : 
     124             :         // create colormap for visual - there might not be one
     125             :         pObject->maColormap = aAttribs.colormap = XCreateColormap(
     126             :             pDisp,
     127             :             pSalDisp->GetRootWindow( nXScreen ),
     128             :             pVisual,
     129           0 :             AllocNone );
     130             : 
     131             :         pObject->maSecondary =
     132             :             XCreateWindow( pDisp,
     133             :                            pSalDisp->GetRootWindow( nXScreen ),
     134             :                            0, 0,
     135             :                            1, 1, 0,
     136             :                            nDepth, InputOutput,
     137             :                            pVisual,
     138           0 :                            CWEventMask|CWColormap, &aAttribs );
     139           0 :         XSync( pDisp, False );
     140           0 :         if( GetGenericData()->ErrorTrapPop( false ) )
     141             :         {
     142           0 :             pObject->maSecondary = None;
     143           0 :             delete pObject;
     144           0 :             return NULL;
     145             :         }
     146           0 :         XReparentWindow( pDisp, pObject->maSecondary, pObject->maPrimary, 0, 0 );
     147             :     }
     148             : 
     149           0 :     GetGenericData()->ErrorTrapPush();
     150           0 :     if( bShow ) {
     151           0 :         XMapWindow( pDisp, pObject->maSecondary );
     152           0 :         XMapWindow( pDisp, pObject->maPrimary );
     153             :     }
     154             : 
     155           0 :     pObjData->pDisplay      = pDisp;
     156           0 :     pObjData->aWindow       = pObject->maSecondary;
     157           0 :     pObjData->pWidget       = NULL;
     158           0 :     pObjData->pVisual       = pVisual;
     159           0 :     pObjData->nDepth        = nDepth;
     160           0 :     pObjData->aColormap     = aVisID == pSalDisp->GetVisual( nXScreen ).GetVisualId() ?
     161           0 :                               pSalDisp->GetColormap( nXScreen ).GetXColormap() : None;
     162           0 :     pObjData->pAppContext   = NULL;
     163             : 
     164           0 :     XSync(pDisp, False);
     165           0 :     if( GetGenericData()->ErrorTrapPop( false ) )
     166             :     {
     167           0 :         delete pObject;
     168           0 :         return NULL;
     169             :     }
     170             : 
     171           0 :     return pObject;
     172             : }
     173             : 
     174           0 : void X11SalInstance::DestroyObject( SalObject* pObject )
     175             : {
     176           0 :     delete pObject;
     177           0 : }
     178             : 
     179             : // SalClipRegion is a member of SalObject
     180             : // definition of SalClipRegion my be found in unx/inc/salobj.h
     181             : 
     182           0 : SalClipRegion::SalClipRegion()
     183             : {
     184           0 :     ClipRectangleList = NULL;
     185           0 :     numClipRectangles = 0;
     186           0 :     maxClipRectangles = 0;
     187           0 :     nClipRegionType   = SAL_OBJECT_CLIP_INCLUDERECTS;
     188           0 : }
     189             : 
     190           0 : SalClipRegion::~SalClipRegion()
     191             : {
     192           0 :     if ( ClipRectangleList )
     193           0 :         delete [] ClipRectangleList;
     194           0 : }
     195             : 
     196             : void
     197           0 : SalClipRegion::BeginSetClipRegion( sal_uLong nRects )
     198             : {
     199           0 :     if (ClipRectangleList)
     200           0 :         delete [] ClipRectangleList;
     201             : 
     202           0 :     ClipRectangleList = new XRectangle[nRects];
     203           0 :     numClipRectangles = 0;
     204           0 :     maxClipRectangles = nRects;
     205           0 : }
     206             : 
     207             : void
     208           0 : SalClipRegion::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
     209             : {
     210           0 :     if ( nWidth && nHeight && (numClipRectangles < maxClipRectangles) )
     211             :     {
     212           0 :         XRectangle *aRect = ClipRectangleList + numClipRectangles;
     213             : 
     214           0 :         aRect->x     = (short) nX;
     215           0 :         aRect->y     = (short) nY;
     216           0 :         aRect->width = (unsigned short) nWidth;
     217           0 :         aRect->height= (unsigned short) nHeight;
     218             : 
     219           0 :         numClipRectangles++;
     220             :     }
     221           0 : }
     222             : 
     223             : // SalObject Implementation
     224           0 : X11SalObject::X11SalObject()
     225             :     : mpParent(NULL)
     226             :     , maPrimary(0)
     227             :     , maSecondary(0)
     228             :     , maColormap(0)
     229           0 :     , mbVisible(false)
     230             : {
     231           0 :     maSystemChildData.nSize     = sizeof( SystemEnvData );
     232           0 :     maSystemChildData.pDisplay  = vcl_sal::getSalDisplay(GetGenericData())->GetDisplay();
     233           0 :     maSystemChildData.aWindow       = None;
     234           0 :     maSystemChildData.pSalFrame = 0;
     235           0 :     maSystemChildData.pWidget       = 0;
     236           0 :     maSystemChildData.pVisual       = 0;
     237           0 :     maSystemChildData.nDepth        = 0;
     238           0 :     maSystemChildData.aColormap = 0;
     239           0 :     maSystemChildData.pAppContext   = NULL;
     240           0 :     maSystemChildData.aShellWindow  = 0;
     241           0 :     maSystemChildData.pShellWidget  = NULL;
     242             : 
     243           0 :     std::list< SalObject* >& rObjects = vcl_sal::getSalDisplay(GetGenericData())->getSalObjects();
     244           0 :     rObjects.push_back( this );
     245           0 : }
     246             : 
     247           0 : X11SalObject::~X11SalObject()
     248             : {
     249           0 :     std::list< SalObject* >& rObjects = vcl_sal::getSalDisplay(GetGenericData())->getSalObjects();
     250           0 :     rObjects.remove( this );
     251             : 
     252           0 :     GetGenericData()->ErrorTrapPush();
     253           0 :     if ( maSecondary )
     254           0 :         XDestroyWindow( static_cast<Display*>(maSystemChildData.pDisplay), maSecondary );
     255           0 :     if ( maPrimary )
     256           0 :         XDestroyWindow( static_cast<Display*>(maSystemChildData.pDisplay), maPrimary );
     257           0 :     if ( maColormap )
     258           0 :         XFreeColormap(static_cast<Display*>(maSystemChildData.pDisplay), maColormap);
     259           0 :     XSync( static_cast<Display*>(maSystemChildData.pDisplay), False );
     260           0 :     GetGenericData()->ErrorTrapPop();
     261           0 : }
     262             : 
     263             : void
     264           0 : X11SalObject::ResetClipRegion()
     265             : {
     266           0 :     maClipRegion.ResetClipRegion();
     267             : 
     268           0 :     const int   dest_kind   = ShapeBounding;
     269           0 :     const int   op          = ShapeSet;
     270           0 :     const int   ordering    = YSorted;
     271             : 
     272             :     XWindowAttributes win_attrib;
     273             :     XRectangle        win_size;
     274             : 
     275           0 :     ::Window aShapeWindow = maPrimary;
     276             : 
     277             :     XGetWindowAttributes ( static_cast<Display*>(maSystemChildData.pDisplay),
     278             :                            aShapeWindow,
     279           0 :                            &win_attrib );
     280             : 
     281           0 :     win_size.x      = 0;
     282           0 :     win_size.y      = 0;
     283           0 :     win_size.width  = win_attrib.width;
     284           0 :     win_size.height = win_attrib.height;
     285             : 
     286             :     XShapeCombineRectangles ( static_cast<Display*>(maSystemChildData.pDisplay),
     287             :                               aShapeWindow,
     288             :                               dest_kind,
     289             :                               0, 0,             // x_off, y_off
     290             :                               &win_size,        // list of rectangles
     291             :                               1,                // number of rectangles
     292           0 :                               op, ordering );
     293           0 : }
     294             : 
     295             : void
     296           0 : X11SalObject::BeginSetClipRegion( sal_uLong nRectCount )
     297             : {
     298           0 :     maClipRegion.BeginSetClipRegion ( nRectCount );
     299           0 : }
     300             : 
     301             : void
     302           0 : X11SalObject::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
     303             : {
     304           0 :     maClipRegion.UnionClipRegion ( nX, nY, nWidth, nHeight );
     305           0 : }
     306             : 
     307             : void
     308           0 : X11SalObject::EndSetClipRegion()
     309             : {
     310           0 :     XRectangle *pRectangles = maClipRegion.EndSetClipRegion ();
     311           0 :     const int   nType       = maClipRegion.GetClipRegionType();
     312           0 :     const int   nRectangles = maClipRegion.GetRectangleCount();
     313             : 
     314           0 :     const int   dest_kind   = ShapeBounding;
     315           0 :     const int   ordering    = YSorted;
     316             :     int         op;
     317             : 
     318           0 :     switch ( nType )
     319             :     {
     320             :         case SAL_OBJECT_CLIP_INCLUDERECTS :
     321           0 :             op = ShapeSet;
     322           0 :             break;
     323             :         case SAL_OBJECT_CLIP_EXCLUDERECTS :
     324           0 :             op = ShapeSubtract;
     325           0 :             break;
     326             :         case SAL_OBJECT_CLIP_ABSOLUTE :
     327           0 :             op = ShapeSet;
     328           0 :             break;
     329             :         default :
     330           0 :             op = ShapeUnion;
     331             :     }
     332             : 
     333           0 :     ::Window aShapeWindow = maPrimary;
     334             : 
     335             :     XShapeCombineRectangles ( static_cast<Display*>(maSystemChildData.pDisplay),
     336             :                               aShapeWindow,
     337             :                               dest_kind,
     338             :                               0, 0, // x_off, y_off
     339             :                               pRectangles,
     340             :                               nRectangles,
     341           0 :                               op, ordering );
     342           0 : }
     343             : 
     344             : sal_uInt16
     345           0 : X11SalObject::GetClipRegionType()
     346             : {
     347           0 :     return maClipRegion.GetClipRegionType();
     348             : }
     349             : 
     350             : void
     351           0 : X11SalObject::SetPosSize( long nX, long nY, long nWidth, long nHeight )
     352             : {
     353           0 :     if ( maPrimary && maSecondary && nWidth && nHeight )
     354             :     {
     355             :         XMoveResizeWindow( static_cast<Display*>(maSystemChildData.pDisplay),
     356             :                            maPrimary,
     357           0 :                             nX, nY, nWidth, nHeight );
     358             :         XMoveResizeWindow( static_cast<Display*>(maSystemChildData.pDisplay),
     359             :                            maSecondary,
     360           0 :                             0, 0, nWidth, nHeight );
     361             :     }
     362           0 : }
     363             : 
     364             : void
     365           0 : X11SalObject::Show( bool bVisible )
     366             : {
     367           0 :     if  ( ! maSystemChildData.aWindow )
     368           0 :         return;
     369             : 
     370           0 :     if ( bVisible ) {
     371             :         XMapWindow( static_cast<Display*>(maSystemChildData.pDisplay),
     372           0 :                     maSecondary );
     373             :         XMapWindow( static_cast<Display*>(maSystemChildData.pDisplay),
     374           0 :                     maPrimary );
     375             :     } else {
     376             :         XUnmapWindow( static_cast<Display*>(maSystemChildData.pDisplay),
     377           0 :                       maPrimary );
     378             :         XUnmapWindow( static_cast<Display*>(maSystemChildData.pDisplay),
     379           0 :                       maSecondary );
     380             :     }
     381           0 :     mbVisible = bVisible;
     382             : }
     383             : 
     384           0 : void X11SalObject::GrabFocus()
     385             : {
     386           0 :     if( mbVisible )
     387             :          XSetInputFocus( static_cast<Display*>(maSystemChildData.pDisplay),
     388             :                          maSystemChildData.aWindow,
     389             :                          RevertToNone,
     390           0 :                          CurrentTime );
     391           0 : }
     392             : 
     393           0 : const SystemEnvData* X11SalObject::GetSystemData() const
     394             : {
     395           0 :     return &maSystemChildData;
     396             : }
     397             : 
     398           0 : static sal_uInt16 sal_GetCode( int state )
     399             : {
     400           0 :     sal_uInt16 nCode = 0;
     401             : 
     402           0 :     if( state & Button1Mask )
     403           0 :         nCode |= MOUSE_LEFT;
     404           0 :     if( state & Button2Mask )
     405           0 :         nCode |= MOUSE_MIDDLE;
     406           0 :     if( state & Button3Mask )
     407           0 :         nCode |= MOUSE_RIGHT;
     408             : 
     409           0 :     if( state & ShiftMask )
     410           0 :         nCode |= KEY_SHIFT;
     411           0 :     if( state & ControlMask )
     412           0 :         nCode |= KEY_MOD1;
     413           0 :     if( state & Mod1Mask )
     414           0 :         nCode |= KEY_MOD2;
     415           0 :     if( state & Mod3Mask )
     416           0 :         nCode |= KEY_MOD3;
     417             : 
     418           0 :     return nCode;
     419             : }
     420             : 
     421           0 : bool X11SalObject::Dispatch( XEvent* pEvent )
     422             : {
     423           0 :     std::list< SalObject* >& rObjects = vcl_sal::getSalDisplay(GetGenericData())->getSalObjects();
     424             : 
     425           0 :     for( std::list< SalObject* >::iterator it = rObjects.begin(); it != rObjects.end(); ++it )
     426             :     {
     427           0 :         X11SalObject* pObject = static_cast<X11SalObject*>(*it);
     428           0 :         if( pEvent->xany.window == pObject->maPrimary ||
     429           0 :             pEvent->xany.window == pObject->maSecondary )
     430             :         {
     431           0 :             if( pObject->IsMouseTransparent() && (
     432           0 :                     pEvent->type == ButtonPress     ||
     433           0 :                     pEvent->type == ButtonRelease   ||
     434           0 :                     pEvent->type == EnterNotify     ||
     435           0 :                     pEvent->type == LeaveNotify     ||
     436           0 :                     pEvent->type == MotionNotify
     437             :                     )
     438             :                )
     439             :             {
     440             :                 SalMouseEvent aEvt;
     441           0 :                 const SystemEnvData* pParentData = pObject->mpParent->GetSystemData();
     442             :                 int dest_x, dest_y;
     443           0 :                 ::Window aChild = None;
     444             :                 XTranslateCoordinates( pEvent->xbutton.display,
     445             :                                        pEvent->xbutton.root,
     446             :                                        pParentData->aWindow,
     447             :                                        pEvent->xbutton.x_root,
     448             :                                        pEvent->xbutton.y_root,
     449             :                                        &dest_x, &dest_y,
     450           0 :                                        &aChild );
     451           0 :                 aEvt.mnX        = dest_x;
     452           0 :                 aEvt.mnY        = dest_y;
     453           0 :                 aEvt.mnTime     = pEvent->xbutton.time;
     454           0 :                 aEvt.mnCode     = sal_GetCode( pEvent->xbutton.state );
     455           0 :                 aEvt.mnButton   = 0;
     456           0 :                 sal_uInt16 nEvent = 0;
     457           0 :                 if( pEvent->type == ButtonPress ||
     458           0 :                     pEvent->type == ButtonRelease )
     459             :                 {
     460           0 :                     switch( pEvent->xbutton.button )
     461             :                     {
     462           0 :                         case Button1: aEvt.mnButton = MOUSE_LEFT;break;
     463           0 :                         case Button2: aEvt.mnButton = MOUSE_MIDDLE;break;
     464           0 :                         case Button3: aEvt.mnButton = MOUSE_RIGHT;break;
     465             :                     }
     466           0 :                     nEvent = (pEvent->type == ButtonPress) ?
     467             :                              SALEVENT_MOUSEBUTTONDOWN :
     468           0 :                              SALEVENT_MOUSEBUTTONUP;
     469             :                 }
     470           0 :                 else if( pEvent->type == EnterNotify )
     471           0 :                     nEvent = SALEVENT_MOUSELEAVE;
     472             :                 else
     473           0 :                     nEvent = SALEVENT_MOUSEMOVE;
     474           0 :                 pObject->mpParent->CallCallback( nEvent, &aEvt );
     475             :             }
     476             :             else
     477             :             {
     478           0 :                 switch( pEvent->type )
     479             :                 {
     480             :                     case UnmapNotify:
     481           0 :                     pObject->mbVisible = false;
     482           0 :                     return true;
     483             :                     case MapNotify:
     484           0 :                     pObject->mbVisible = true;
     485           0 :                     return true;
     486             :                     case ButtonPress:
     487           0 :                     pObject->CallCallback( SALOBJ_EVENT_TOTOP, NULL );
     488           0 :                     return true;
     489             :                     case FocusIn:
     490           0 :                     pObject->CallCallback( SALOBJ_EVENT_GETFOCUS, NULL );
     491           0 :                     return true;
     492             :                     case FocusOut:
     493           0 :                     pObject->CallCallback( SALOBJ_EVENT_LOSEFOCUS, NULL );
     494           0 :                     return true;
     495           0 :                     default: break;
     496             :                 }
     497             :             }
     498           0 :             return false;
     499             :         }
     500             :     }
     501           0 :     return false;
     502           9 : }
     503             : 
     504             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11