LCOV - code coverage report
Current view: top level - vcl/unx/generic/window - salframe.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 2123 0.0 %
Date: 2014-11-03 Functions: 0 97 0.0 %
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             : #include <signal.h>
      21             : #include <string.h>
      22             : #include <stdio.h>
      23             : #include <stdlib.h>
      24             : #include <unistd.h>
      25             : 
      26             : #include "tools/debug.hxx"
      27             : 
      28             : #include "sal/alloca.h"
      29             : 
      30             : #include "vcl/floatwin.hxx"
      31             : #include "vcl/svapp.hxx"
      32             : #include "vcl/keycodes.hxx"
      33             : #include "vcl/layout.hxx"
      34             : #include "vcl/printerinfomanager.hxx"
      35             : #include "vcl/settings.hxx"
      36             : #include "vcl/bmpacc.hxx"
      37             : 
      38             : #include <prex.h>
      39             : #include <X11/Xatom.h>
      40             : #include <X11/keysym.h>
      41             : #include "FWS.hxx"
      42             : #include <X11/extensions/shape.h>
      43             : #if !defined(SOLARIS) && !defined(AIX)
      44             : #include <X11/extensions/dpms.h>
      45             : #endif
      46             : #include <postx.h>
      47             : 
      48             : #include "unx/salunx.h"
      49             : #include "unx/saldata.hxx"
      50             : #include "unx/saldisp.hxx"
      51             : #include "unx/salgdi.h"
      52             : #include "unx/salframe.h"
      53             : #include "unx/sm.hxx"
      54             : #include "unx/wmadaptor.hxx"
      55             : #include "generic/genprn.h"
      56             : #include "unx/salbmp.h"
      57             : #include "unx/i18n_ic.hxx"
      58             : #include "unx/i18n_keysym.hxx"
      59             : #include "unx/i18n_status.hxx"
      60             : #include <unx/x11/xlimits.hxx>
      61             : 
      62             : #include "generic/gensys.h"
      63             : #include "sallayout.hxx"
      64             : 
      65             : #include <sal/macros.h>
      66             : #include <com/sun/star/uno/Exception.hpp>
      67             : 
      68             : #include "svids.hrc"
      69             : #include "impbmp.hxx"
      70             : 
      71             : #include <algorithm>
      72             : 
      73             : #ifndef Button6
      74             : # define Button6 6
      75             : #endif
      76             : #ifndef Button7
      77             : # define Button7 7
      78             : #endif
      79             : 
      80             : using namespace vcl_sal;
      81             : 
      82             : #define CLIENT_EVENTS           StructureNotifyMask \
      83             :                                 | SubstructureNotifyMask \
      84             :                                 | KeyPressMask \
      85             :                                 | KeyReleaseMask \
      86             :                                 | ButtonPressMask \
      87             :                                 | ButtonReleaseMask \
      88             :                                 | PointerMotionMask \
      89             :                                 | EnterWindowMask \
      90             :                                 | LeaveWindowMask \
      91             :                                 | FocusChangeMask \
      92             :                                 | ExposureMask \
      93             :                                 | VisibilityChangeMask \
      94             :                                 | PropertyChangeMask \
      95             :                                 | ColormapChangeMask
      96             : 
      97             : static ::Window  hPresentationWindow = None, hPresFocusWindow = None;
      98           0 : static ::std::list< ::Window > aPresentationReparentList;
      99             : static int          nVisibleFloats      = 0;
     100             : 
     101           0 : static void doReparentPresentationDialogues( SalDisplay* pDisplay )
     102             : {
     103           0 :     GetGenericData()->ErrorTrapPush();
     104           0 :     while( aPresentationReparentList.begin() != aPresentationReparentList.end() )
     105             :     {
     106             :         int x, y;
     107             :         ::Window aRoot, aChild;
     108             :         unsigned int w, h, bw, d;
     109             :         XGetGeometry( pDisplay->GetDisplay(),
     110           0 :                       aPresentationReparentList.front(),
     111             :                       &aRoot,
     112           0 :                       &x, &y, &w, &h, &bw, &d );
     113             :         XTranslateCoordinates( pDisplay->GetDisplay(),
     114             :                                hPresentationWindow,
     115             :                                aRoot,
     116             :                                x, y,
     117             :                                &x, &y,
     118           0 :                                &aChild );
     119             :         XReparentWindow( pDisplay->GetDisplay(),
     120           0 :                          aPresentationReparentList.front(),
     121             :                          aRoot,
     122           0 :                          x, y );
     123           0 :         aPresentationReparentList.pop_front();
     124             :     }
     125           0 :     if( hPresFocusWindow )
     126           0 :         XSetInputFocus( pDisplay->GetDisplay(), hPresFocusWindow, PointerRoot, CurrentTime );
     127           0 :     XSync( pDisplay->GetDisplay(), False );
     128           0 :     GetGenericData()->ErrorTrapPop();
     129           0 : }
     130             : 
     131           0 : bool X11SalFrame::IsOverrideRedirect() const
     132             : {
     133             :     return
     134           0 :         ((nStyle_ & SAL_FRAME_STYLE_INTRO) && !pDisplay_->getWMAdaptor()->supportsSplash())
     135           0 :         ||
     136           0 :         (!( nStyle_ & ~SAL_FRAME_STYLE_DEFAULT ) && !pDisplay_->getWMAdaptor()->supportsFullScreen())
     137             :         ;
     138             : }
     139             : 
     140           0 : bool X11SalFrame::IsFloatGrabWindow() const
     141             : {
     142           0 :     static const char* pDisableGrab = getenv( "SAL_DISABLE_FLOATGRAB" );
     143             : 
     144             :     return
     145           0 :         ( ( !pDisableGrab || !*pDisableGrab ) &&
     146             :           (
     147           0 :            (nStyle_ & SAL_FRAME_STYLE_FLOAT)    &&
     148           0 :            ! (nStyle_ & SAL_FRAME_STYLE_TOOLTIP)    &&
     149           0 :            ! (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION)
     150             :            )
     151           0 :           );
     152             : }
     153             : 
     154           0 : void X11SalFrame::setXEmbedInfo()
     155             : {
     156           0 :     if( m_bXEmbed )
     157             :     {
     158             :         long aInfo[2];
     159           0 :         aInfo[0] = 1; // XEMBED protocol version
     160           0 :         aInfo[1] = (bMapped_ ? 1 : 0); // XEMBED_MAPPED
     161             :         XChangeProperty( pDisplay_->GetDisplay(),
     162             :                          mhWindow,
     163             :                          pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::XEMBED_INFO ),
     164             :                          pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::XEMBED_INFO ),
     165             :                          32,
     166             :                          PropModeReplace,
     167             :                          reinterpret_cast<unsigned char*>(aInfo),
     168           0 :                          SAL_N_ELEMENTS(aInfo) );
     169             :     }
     170           0 : }
     171             : 
     172           0 : void X11SalFrame::askForXEmbedFocus( sal_Int32 i_nTimeCode )
     173             : {
     174             :     XEvent aEvent;
     175             : 
     176           0 :     memset( &aEvent, 0, sizeof(aEvent) );
     177           0 :     aEvent.xclient.window = mhForeignParent;
     178           0 :     aEvent.xclient.type = ClientMessage;
     179           0 :     aEvent.xclient.message_type = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::XEMBED );
     180           0 :     aEvent.xclient.format = 32;
     181           0 :     aEvent.xclient.data.l[0] = i_nTimeCode ? i_nTimeCode : CurrentTime;
     182           0 :     aEvent.xclient.data.l[1] = 3; // XEMBED_REQUEST_FOCUS
     183           0 :     aEvent.xclient.data.l[2] = 0;
     184           0 :     aEvent.xclient.data.l[3] = 0;
     185           0 :     aEvent.xclient.data.l[4] = 0;
     186             : 
     187           0 :     GetGenericData()->ErrorTrapPush();
     188             :     XSendEvent( pDisplay_->GetDisplay(),
     189             :                 mhForeignParent,
     190           0 :                 False, NoEventMask, &aEvent );
     191           0 :     XSync( pDisplay_->GetDisplay(), False );
     192           0 :     GetGenericData()->ErrorTrapPop();
     193           0 : }
     194             : 
     195             : typedef std::vector< unsigned long > NetWmIconData;
     196             : 
     197           0 : static void CreateNetWmAppIcon( sal_uInt16 nIcon, NetWmIconData& netwm_icon )
     198             : {
     199           0 :     const int sizes[ 3 ] = { 48, 32, 16 };
     200           0 :     netwm_icon.resize( 48 * 48 + 32 * 32 + 16 * 16 + 3 * 2 );
     201           0 :     int pos = 0;
     202           0 :     for( int i = 0; i < 3; ++i )
     203             :     {
     204           0 :         int size = sizes[ i ];
     205             :         sal_uInt16 nIconSizeOffset;
     206           0 :         if( size >= 48 )
     207           0 :             nIconSizeOffset = SV_ICON_SIZE48_START;
     208           0 :         else if( size >= 32 )
     209           0 :             nIconSizeOffset = SV_ICON_SIZE32_START;
     210             :         else
     211           0 :             nIconSizeOffset = SV_ICON_SIZE16_START;
     212           0 :         BitmapEx aIcon( ResId(nIconSizeOffset + nIcon, *ImplGetResMgr()));
     213           0 :         if( aIcon.IsEmpty())
     214           0 :             continue;
     215           0 :         Bitmap icon = aIcon.GetBitmap();
     216           0 :         AlphaMask mask;
     217           0 :         switch( aIcon.GetTransparentType())
     218             :         {
     219             :             case TRANSPARENT_NONE:
     220             :             {
     221           0 :                 sal_uInt8 nTrans = 0;
     222           0 :                 mask = AlphaMask( icon.GetSizePixel(), &nTrans );
     223             :             }
     224           0 :             break;
     225             :             case TRANSPARENT_COLOR:
     226           0 :                 mask = AlphaMask( icon.CreateMask( aIcon.GetTransparentColor() ) );
     227           0 :             break;
     228             :             case TRANSPARENT_BITMAP:
     229           0 :                 mask = aIcon.GetAlpha();
     230           0 :             break;
     231             :         }
     232           0 :         BitmapReadAccess* iconData = icon.AcquireReadAccess();
     233           0 :         BitmapReadAccess* maskData = mask.AcquireReadAccess();
     234           0 :         netwm_icon[ pos++ ] = size; // width
     235           0 :         netwm_icon[ pos++ ] = size; // height
     236           0 :         for( int y = 0; y < size; ++y )
     237           0 :             for( int x = 0; x < size; ++x )
     238             :             {
     239           0 :                 BitmapColor col = iconData->GetColor( y, x );
     240           0 :                 BitmapColor alpha = maskData->GetColor( y, x );
     241           0 :                 netwm_icon[ pos++ ] = (((( 255 - alpha.GetBlue()) * 256U ) + col.GetRed()) * 256 + col.GetGreen()) * 256 + col.GetBlue();
     242           0 :             }
     243           0 :         icon.ReleaseAccess( iconData );
     244           0 :         mask.ReleaseAccess( maskData );
     245           0 :     }
     246           0 :     netwm_icon.resize( pos );
     247           0 : }
     248             : 
     249           0 : static bool lcl_SelectAppIconPixmap( SalDisplay *pDisplay, SalX11Screen nXScreen,
     250             :                                          sal_uInt16 nIcon, sal_uInt16 iconSize,
     251             :                                          Pixmap& icon_pixmap, Pixmap& icon_mask, NetWmIconData& netwm_icon)
     252             : {
     253           0 :     if( ! ImplGetResMgr() )
     254           0 :         return false;
     255             : 
     256           0 :     CreateNetWmAppIcon( nIcon, netwm_icon );
     257             : 
     258             :     sal_uInt16 nIconSizeOffset;
     259             : 
     260           0 :     if( iconSize >= 48 )
     261           0 :         nIconSizeOffset = SV_ICON_SIZE48_START;
     262           0 :     else if( iconSize >= 32 )
     263           0 :         nIconSizeOffset = SV_ICON_SIZE32_START;
     264           0 :     else if( iconSize >= 16 )
     265           0 :         nIconSizeOffset = SV_ICON_SIZE16_START;
     266             :     else
     267           0 :         return false;
     268             : 
     269           0 :     BitmapEx aIcon( ResId(nIconSizeOffset + nIcon, *ImplGetResMgr()));
     270           0 :     if( aIcon.IsEmpty() )
     271           0 :         return false;
     272             : 
     273             :     SalTwoRect aRect;
     274           0 :     aRect.mnSrcX = 0; aRect.mnSrcY = 0;
     275           0 :     aRect.mnSrcWidth = iconSize; aRect.mnSrcHeight = iconSize;
     276           0 :     aRect.mnDestX = 0; aRect.mnDestY = 0;
     277           0 :     aRect.mnDestWidth = iconSize; aRect.mnDestHeight = iconSize;
     278             : 
     279             :     X11SalBitmap *pBitmap = static_cast < X11SalBitmap * >
     280           0 :         (aIcon.ImplGetBitmapImpBitmap()->ImplGetSalBitmap());
     281             : 
     282             :     icon_pixmap = XCreatePixmap( pDisplay->GetDisplay(),
     283             :                                  pDisplay->GetRootWindow( nXScreen ),
     284             :                                  iconSize, iconSize,
     285           0 :                                  DefaultDepth( pDisplay->GetDisplay(),
     286             :                                                nXScreen.getXScreen() )
     287           0 :                                  );
     288             : 
     289             :     pBitmap->ImplDraw( icon_pixmap,
     290             :                        nXScreen,
     291           0 :                        DefaultDepth( pDisplay->GetDisplay(),
     292             :                                      nXScreen.getXScreen() ),
     293             :                        aRect,
     294           0 :                        DefaultGC( pDisplay->GetDisplay(),
     295           0 :                                   nXScreen.getXScreen() ) );
     296             : 
     297           0 :     icon_mask = None;
     298             : 
     299           0 :     if( TRANSPARENT_BITMAP == aIcon.GetTransparentType() )
     300             :     {
     301             :         icon_mask = XCreatePixmap( pDisplay->GetDisplay(),
     302             :                                    pDisplay->GetRootWindow( pDisplay->GetDefaultXScreen() ),
     303           0 :                                    iconSize, iconSize, 1);
     304             : 
     305             :         XGCValues aValues;
     306           0 :         aValues.foreground = 0xffffffff;
     307           0 :         aValues.background = 0;
     308           0 :         aValues.function = GXcopy;
     309             :         GC aMonoGC = XCreateGC( pDisplay->GetDisplay(), icon_mask,
     310           0 :             GCFunction|GCForeground|GCBackground, &aValues );
     311             : 
     312           0 :         Bitmap aMask = aIcon.GetMask();
     313           0 :         aMask.Invert();
     314             : 
     315             :         X11SalBitmap *pMask = static_cast < X11SalBitmap * >
     316           0 :             (aMask.ImplGetImpBitmap()->ImplGetSalBitmap());
     317             : 
     318           0 :         pMask->ImplDraw(icon_mask, nXScreen, 1, aRect, aMonoGC);
     319           0 :         XFreeGC( pDisplay->GetDisplay(), aMonoGC );
     320             :     }
     321             : 
     322           0 :     return true;
     323             : }
     324             : 
     325           0 : void X11SalFrame::Init( sal_uLong nSalFrameStyle, SalX11Screen nXScreen, SystemParentData* pParentData, bool bUseGeometry )
     326             : {
     327           0 :     if( nXScreen.getXScreen() >= GetDisplay()->GetXScreenCount() )
     328           0 :         nXScreen = GetDisplay()->GetDefaultXScreen();
     329           0 :     if( mpParent )
     330           0 :         nXScreen = mpParent->m_nXScreen;
     331             : 
     332           0 :     m_nXScreen  = nXScreen;
     333           0 :     nStyle_     = nSalFrameStyle;
     334             :     XWMHints Hints;
     335           0 :     Hints.flags = InputHint;
     336           0 :     Hints.input = (nSalFrameStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) ? False : True;
     337           0 :     NetWmIconData netwm_icon;
     338             : 
     339           0 :     int x = 0, y = 0;
     340           0 :     unsigned int w = 500, h = 500;
     341             :     XSetWindowAttributes Attributes;
     342             : 
     343             :     int nAttrMask =   CWBorderPixel
     344             :                     | CWBackPixmap
     345             :                     | CWColormap
     346             :                     | CWOverrideRedirect
     347           0 :                     | CWEventMask
     348             :                     ;
     349           0 :     Attributes.border_pixel             = 0;
     350           0 :     Attributes.background_pixmap        = None;
     351           0 :     Attributes.colormap                 = GetDisplay()->GetColormap( m_nXScreen ).GetXColormap();
     352           0 :     Attributes.override_redirect        = False;
     353           0 :     Attributes.event_mask               = CLIENT_EVENTS;
     354             : 
     355           0 :     const SalVisual& rVis = GetDisplay()->GetVisual( m_nXScreen );
     356           0 :     ::Window aFrameParent = pParentData ? pParentData->aWindow : GetDisplay()->GetRootWindow( m_nXScreen );
     357           0 :     ::Window aClientLeader = None;
     358             : 
     359           0 :     if( bUseGeometry )
     360             :     {
     361           0 :         x = maGeometry.nX;
     362           0 :         y = maGeometry.nY;
     363           0 :         w = maGeometry.nWidth;
     364           0 :         h = maGeometry.nHeight;
     365             :     }
     366             : 
     367           0 :     if( (nSalFrameStyle & SAL_FRAME_STYLE_FLOAT) &&
     368           0 :         ! (nSalFrameStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION)
     369             :         )
     370             :     {
     371           0 :         if( nShowState_ == SHOWSTATE_UNKNOWN )
     372             :         {
     373           0 :             w = 10;
     374           0 :             h = 10;
     375             :         }
     376           0 :         Attributes.override_redirect = True;
     377             :     }
     378           0 :     else if( (nSalFrameStyle & SAL_FRAME_STYLE_SYSTEMCHILD ) )
     379             :     {
     380             :         DBG_ASSERT( mpParent, "SAL_FRAME_STYLE_SYSTEMCHILD window without parent" );
     381           0 :         if( mpParent )
     382             :         {
     383           0 :             aFrameParent = mpParent->mhWindow;
     384             :             // FIXME: since with SAL_FRAME_STYLE_SYSTEMCHILD
     385             :             // multiple X11SalFrame objects can have the same shell window
     386             :             // dispatching events in saldisp.cxx is unclear (the first frame)
     387             :             // wins. HTH this correctly is unclear yet
     388             :             // for the time being, treat set the shell window to own window
     389             :             // like for a normal frame
     390             :             // mhShellWindow = mpParent->GetShellWindow();
     391             :         }
     392             :     }
     393           0 :     else if( pParentData )
     394             :     {
     395             :         // plugin parent may be killed unexpectedly by plugging
     396             :         // process; start permanantly ignoring X errors ...
     397           0 :         GetGenericData()->ErrorTrapPush();
     398             : 
     399           0 :         nStyle_ |= SAL_FRAME_STYLE_PLUG;
     400           0 :         Attributes.override_redirect = True;
     401           0 :         if( pParentData->nSize >= sizeof(SystemParentData) )
     402           0 :             m_bXEmbed = pParentData->bXEmbedSupport;
     403             : 
     404             :         int x_ret, y_ret;
     405             :         unsigned int bw, d;
     406             :         ::Window aRoot, aParent;
     407             : 
     408             :         XGetGeometry( GetXDisplay(), pParentData->aWindow,
     409           0 :                       &aRoot, &x_ret, &y_ret, &w, &h, &bw, &d );
     410           0 :         mhForeignParent = pParentData->aWindow;
     411             : 
     412           0 :         mhShellWindow = aParent = mhForeignParent;
     413             :         ::Window* pChildren;
     414             :         unsigned int nChildren;
     415           0 :         bool bBreak = false;
     416           0 :         do
     417             :         {
     418             :             XQueryTree( GetDisplay()->GetDisplay(), mhShellWindow,
     419           0 :                         &aRoot, &aParent, &pChildren, &nChildren );
     420           0 :             XFree( pChildren );
     421           0 :             if( aParent != aRoot )
     422           0 :                 mhShellWindow = aParent;
     423           0 :             int nCount = 0;
     424             :             Atom* pProps = XListProperties( GetDisplay()->GetDisplay(),
     425             :                                             mhShellWindow,
     426           0 :                                             &nCount );
     427           0 :             for( int i = 0; i < nCount && ! bBreak; ++i )
     428           0 :                 bBreak = (pProps[i] == XA_WM_HINTS);
     429           0 :             if( pProps )
     430           0 :                 XFree( pProps );
     431           0 :         } while( aParent != aRoot && ! bBreak );
     432             : 
     433             :         // check if this is really one of our own frames
     434             :         // do not change the input mask in that case
     435           0 :         const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
     436           0 :         std::list< SalFrame* >::const_iterator it = rFrames.begin();
     437           0 :         while( it != rFrames.end() && mhForeignParent != static_cast<const X11SalFrame*>(*it)->GetWindow() )
     438           0 :             ++it;
     439             : 
     440           0 :         if( it == rFrames.end() )
     441             :         {
     442           0 :             XSelectInput( GetDisplay()->GetDisplay(), mhForeignParent, StructureNotifyMask | FocusChangeMask );
     443           0 :             XSelectInput( GetDisplay()->GetDisplay(), mhShellWindow, StructureNotifyMask | FocusChangeMask );
     444             :         }
     445             :     }
     446             :     else
     447             :     {
     448           0 :         if( ! bUseGeometry )
     449             :         {
     450           0 :             Size aScreenSize( GetDisplay()->getDataForScreen( m_nXScreen ).m_aSize );
     451           0 :             w = aScreenSize.Width();
     452           0 :             h = aScreenSize.Height();
     453           0 :             if( nSalFrameStyle & SAL_FRAME_STYLE_SIZEABLE &&
     454           0 :                 nSalFrameStyle & SAL_FRAME_STYLE_MOVEABLE )
     455             :             {
     456           0 :                 Size aBestFitSize(bestmaxFrameSizeForScreenSize(aScreenSize));
     457           0 :                 w = aBestFitSize.Width();
     458           0 :                 h = aBestFitSize.Height();
     459             :             }
     460           0 :             if( ! mpParent )
     461             :             {
     462             :                 // find the last document window (if any)
     463           0 :                 const X11SalFrame* pFrame = NULL;
     464           0 :                 const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
     465           0 :                 std::list< SalFrame* >::const_iterator it = rFrames.begin();
     466           0 :                 while( it != rFrames.end() )
     467             :                 {
     468           0 :                     pFrame = static_cast< const X11SalFrame* >(*it);
     469           0 :                     if( ! ( pFrame->mpParent
     470           0 :                             || pFrame->mbFullScreen
     471           0 :                             || ! ( pFrame->nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
     472           0 :                             || ! pFrame->GetUnmirroredGeometry().nWidth
     473           0 :                             || ! pFrame->GetUnmirroredGeometry().nHeight
     474           0 :                             )
     475             :                         )
     476           0 :                         break;
     477           0 :                     ++it;
     478             :                 }
     479             : 
     480           0 :                 if( it != rFrames.end() )
     481             :                 {
     482             :                     // set a document position and size
     483             :                     // the first frame gets positioned by the window manager
     484           0 :                     const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
     485           0 :                     x = rGeom.nX;
     486           0 :                     y = rGeom.nY;
     487           0 :                     if( x+(int)w+40 <= (int)aScreenSize.Width() &&
     488           0 :                         y+(int)h+40 <= (int)aScreenSize.Height()
     489             :                         )
     490             :                     {
     491           0 :                         y += 40;
     492           0 :                         x += 40;
     493             :                     }
     494             :                     else
     495             :                     {
     496           0 :                         x = 10; // leave some space for decoration
     497           0 :                         y = 20;
     498             :                     }
     499             :                 }
     500           0 :                 else if( GetDisplay()->IsXinerama() )
     501             :                 {
     502             :                     // place frame on same screen as mouse pointer
     503             :                     ::Window aRoot, aChild;
     504           0 :                     int root_x = 0, root_y = 0, lx, ly;
     505             :                     unsigned int mask;
     506             :                     XQueryPointer( GetXDisplay(),
     507             :                                    GetDisplay()->GetRootWindow( m_nXScreen ),
     508             :                                    &aRoot, &aChild,
     509           0 :                                    &root_x, &root_y, &lx, &ly, &mask );
     510           0 :                     const std::vector< Rectangle >& rScreens = GetDisplay()->GetXineramaScreens();
     511           0 :                     for( unsigned int i = 0; i < rScreens.size(); i++ )
     512           0 :                         if( rScreens[i].IsInside( Point( root_x, root_y ) ) )
     513             :                         {
     514           0 :                             x = rScreens[i].Left();
     515           0 :                             y = rScreens[i].Top();
     516           0 :                             break;
     517             :                         }
     518             :                 }
     519             :             }
     520             :         }
     521           0 :         Attributes.win_gravity = pDisplay_->getWMAdaptor()->getInitWinGravity();
     522           0 :         nAttrMask |= CWWinGravity;
     523           0 :         if( mpParent )
     524             :         {
     525           0 :             Attributes.save_under = True;
     526           0 :             nAttrMask |= CWSaveUnder;
     527             :         }
     528           0 :         if( IsOverrideRedirect() )
     529           0 :             Attributes.override_redirect = True;
     530             :         // default icon
     531           0 :         if( (nStyle_ & SAL_FRAME_STYLE_INTRO) == 0 )
     532             :         {
     533           0 :             bool bOk=false;
     534             :             try
     535             :             {
     536             :                 bOk = lcl_SelectAppIconPixmap( pDisplay_, m_nXScreen,
     537           0 :                                                mnIconID != 1 ? mnIconID :
     538             :                                                (mpParent ? mpParent->mnIconID : 1), 32,
     539           0 :                                                Hints.icon_pixmap, Hints.icon_mask, netwm_icon );
     540             :             }
     541           0 :             catch( com::sun::star::uno::Exception& )
     542             :             {
     543             :                 // can happen - no ucb during early startup
     544             :             }
     545           0 :             if( bOk )
     546             :             {
     547           0 :                 Hints.flags     |= IconPixmapHint;
     548           0 :                 if( Hints.icon_mask )
     549           0 :                     Hints.flags |= IconMaskHint;
     550             :             }
     551             :         }
     552             : 
     553             :         // find the top level frame of the transience hierarchy
     554           0 :         X11SalFrame* pFrame = this;
     555           0 :         while( pFrame->mpParent )
     556           0 :             pFrame = pFrame->mpParent;
     557           0 :         if( (pFrame->nStyle_ & SAL_FRAME_STYLE_PLUG ) )
     558             :         {
     559             :             // if the top level window is a plugin window,
     560             :             // then we should place us in the same window group as
     561             :             // the parent application (or none if there is no window group
     562             :             // hint in the parent).
     563           0 :             if( pFrame->GetShellWindow() )
     564             :             {
     565             :                 XWMHints* pWMHints = XGetWMHints( pDisplay_->GetDisplay(),
     566           0 :                     pFrame->GetShellWindow() );
     567           0 :                 if( pWMHints )
     568             :                 {
     569           0 :                     if( (pWMHints->flags & WindowGroupHint) )
     570             :                     {
     571           0 :                         Hints.flags |= WindowGroupHint;
     572           0 :                         Hints.window_group = pWMHints->window_group;
     573             :                     }
     574           0 :                     XFree( pWMHints );
     575             :                 }
     576             :             }
     577             :         }
     578             :         else
     579             :         {
     580           0 :             Hints.flags         |= WindowGroupHint;
     581           0 :             Hints.window_group  = pFrame->GetShellWindow();
     582             :             // note: for a normal document window this will produce None
     583             :             // as the window is not yet created and the shell window is
     584             :             // initialized to None. This must be corrected after window creation.
     585           0 :             aClientLeader = GetDisplay()->GetDrawable( m_nXScreen );
     586             :         }
     587             :     }
     588             : 
     589           0 :     nShowState_                 = SHOWSTATE_UNKNOWN;
     590           0 :     bViewable_                  = true;
     591           0 :     bMapped_                    = false;
     592           0 :     nVisibility_                = VisibilityFullyObscured;
     593             :     mhWindow = XCreateWindow( GetXDisplay(),
     594             :                               aFrameParent,
     595             :                               x, y,
     596             :                               w, h,
     597             :                               0,
     598             :                               rVis.GetDepth(),
     599             :                               InputOutput,
     600             :                               rVis.GetVisual(),
     601             :                               nAttrMask,
     602           0 :                               &Attributes );
     603             :     // FIXME: see above: fake shell window for now to own window
     604           0 :     if( pParentData == NULL )
     605             :     {
     606           0 :         mhShellWindow = mhWindow;
     607             :     }
     608             : 
     609             :     // correct window group if necessary
     610           0 :     if( (Hints.flags & WindowGroupHint) == WindowGroupHint )
     611             :     {
     612           0 :         if( Hints.window_group == None )
     613           0 :             Hints.window_group = GetShellWindow();
     614             :     }
     615             : 
     616           0 :     maGeometry.nX       = x;
     617           0 :     maGeometry.nY       = y;
     618           0 :     maGeometry.nWidth   = w;
     619           0 :     maGeometry.nHeight  = h;
     620           0 :     updateScreenNumber();
     621             : 
     622           0 :     XSync( GetXDisplay(), False );
     623           0 :     setXEmbedInfo();
     624             : 
     625           0 :     Time nUserTime = (nStyle_ & (SAL_FRAME_STYLE_OWNERDRAWDECORATION | SAL_FRAME_STYLE_TOOLWINDOW) ) == 0 ?
     626           0 :         pDisplay_->GetLastUserEventTime() : 0;
     627           0 :     pDisplay_->getWMAdaptor()->setUserTime( this, nUserTime );
     628             : 
     629           0 :     if( ! pParentData && ! IsChildWindow() && ! Attributes.override_redirect )
     630             :     {
     631           0 :         XSetWMHints( GetXDisplay(), mhWindow, &Hints );
     632             :         // WM Protocols && internals
     633             :         Atom a[3];
     634           0 :         int  n = 0;
     635           0 :         a[n++] = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_DELETE_WINDOW );
     636           0 :         if( pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_PING ) )
     637           0 :             a[n++] = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_PING );
     638           0 :         if( (nSalFrameStyle & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
     639           0 :             a[n++] = pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_TAKE_FOCUS );
     640           0 :         XSetWMProtocols( GetXDisplay(), GetShellWindow(), a, n );
     641             : 
     642             :         // force wm class hint
     643           0 :         mnExtStyle = ~0;
     644           0 :         if (mpParent)
     645           0 :             m_sWMClass = mpParent->m_sWMClass;
     646           0 :         SetExtendedFrameStyle( 0 );
     647             : 
     648           0 :         XSizeHints* pHints = XAllocSizeHints();
     649           0 :         pHints->flags       = PWinGravity | PPosition;
     650           0 :         pHints->win_gravity = GetDisplay()->getWMAdaptor()->getPositionWinGravity();
     651           0 :         pHints->x           = 0;
     652           0 :         pHints->y           = 0;
     653           0 :         if( mbFullScreen )
     654             :         {
     655           0 :             pHints->flags |= PMaxSize | PMinSize;
     656           0 :             pHints->max_width = w+100;
     657           0 :             pHints->max_height = h+100;
     658           0 :             pHints->min_width  = w;
     659           0 :             pHints->min_height = h;
     660             :         }
     661             :         XSetWMNormalHints( GetXDisplay(),
     662             :                            GetShellWindow(),
     663           0 :                            pHints );
     664           0 :         XFree (pHints);
     665             : 
     666             :         // set PID and WM_CLIENT_MACHINE
     667           0 :         pDisplay_->getWMAdaptor()->setClientMachine( this );
     668           0 :         pDisplay_->getWMAdaptor()->setPID( this );
     669             : 
     670             :         // set client leader
     671           0 :         if( aClientLeader )
     672             :         {
     673             :             XChangeProperty( GetXDisplay(),
     674             :                              mhWindow,
     675             :                              pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_CLIENT_LEADER),
     676             :                              XA_WINDOW,
     677             :                              32,
     678             :                              PropModeReplace,
     679             :                              (unsigned char*)&aClientLeader,
     680             :                              1
     681           0 :                              );
     682             :         }
     683             : #define DECOFLAGS (SAL_FRAME_STYLE_MOVEABLE | SAL_FRAME_STYLE_SIZEABLE | SAL_FRAME_STYLE_CLOSEABLE)
     684           0 :         int nDecoFlags = WMAdaptor::decoration_All;
     685           0 :         if( (nStyle_ & SAL_FRAME_STYLE_PARTIAL_FULLSCREEN) ||
     686           0 :             (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION)
     687             :             )
     688           0 :             nDecoFlags = 0;
     689           0 :         else if( (nStyle_ & DECOFLAGS ) != DECOFLAGS || (nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW) )
     690             :         {
     691           0 :             if( nStyle_ & DECOFLAGS )
     692             :                 // if any decoration, then show a border
     693           0 :                 nDecoFlags = WMAdaptor::decoration_Border;
     694             :             else
     695           0 :                 nDecoFlags = 0;
     696             : 
     697           0 :             if( ! mpParent && (nStyle_ & DECOFLAGS) )
     698             :                 // don't add a min button if window should be decorationless
     699           0 :                 nDecoFlags |= WMAdaptor::decoration_MinimizeBtn;
     700           0 :             if( nStyle_ & SAL_FRAME_STYLE_CLOSEABLE )
     701           0 :                 nDecoFlags |= WMAdaptor::decoration_CloseBtn;
     702           0 :             if( nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
     703             :             {
     704           0 :                 nDecoFlags |= WMAdaptor::decoration_Resize;
     705           0 :                 if( ! (nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW) )
     706           0 :                     nDecoFlags |= WMAdaptor::decoration_MaximizeBtn;
     707             :             }
     708           0 :             if( nStyle_ & SAL_FRAME_STYLE_MOVEABLE )
     709           0 :                 nDecoFlags |= WMAdaptor::decoration_Title;
     710             :         }
     711             : 
     712           0 :         WMAdaptor::WMWindowType eType = WMAdaptor::windowType_Normal;
     713           0 :         if( nStyle_ & SAL_FRAME_STYLE_INTRO )
     714           0 :             eType = WMAdaptor::windowType_Splash;
     715           0 :         if( (nStyle_ & SAL_FRAME_STYLE_DIALOG) && hPresentationWindow == None )
     716           0 :             eType = WMAdaptor::windowType_ModelessDialogue;
     717           0 :         if( nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW )
     718           0 :             eType = WMAdaptor::windowType_Utility;
     719           0 :         if( nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION )
     720           0 :             eType = WMAdaptor::windowType_Toolbar;
     721           0 :         if(    (nStyle_ & SAL_FRAME_STYLE_PARTIAL_FULLSCREEN)
     722           0 :             && GetDisplay()->getWMAdaptor()->isLegacyPartialFullscreen() )
     723           0 :             eType = WMAdaptor::windowType_Dock;
     724             : 
     725           0 :         GetDisplay()->getWMAdaptor()->
     726             :             setFrameTypeAndDecoration( this,
     727             :                                        eType,
     728             :                                        nDecoFlags,
     729           0 :                                        hPresentationWindow ? NULL : mpParent );
     730             : 
     731           0 :         if( (nStyle_ & (SAL_FRAME_STYLE_DEFAULT |
     732             :                         SAL_FRAME_STYLE_OWNERDRAWDECORATION|
     733             :                         SAL_FRAME_STYLE_FLOAT |
     734             :                         SAL_FRAME_STYLE_INTRO |
     735             :                         SAL_FRAME_STYLE_PARTIAL_FULLSCREEN) )
     736             :              == SAL_FRAME_STYLE_DEFAULT )
     737           0 :             pDisplay_->getWMAdaptor()->maximizeFrame( this, true, true );
     738             : 
     739           0 :         if( !netwm_icon.empty() && GetDisplay()->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_ICON ))
     740             :             XChangeProperty( GetXDisplay(), mhWindow,
     741             :                 GetDisplay()->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_ICON ),
     742           0 :                 XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&netwm_icon.front(), netwm_icon.size());
     743             :     }
     744             : 
     745           0 :     m_nWorkArea = GetDisplay()->getWMAdaptor()->getCurrentWorkArea();
     746             : 
     747             :     // Pointer
     748           0 :     SetPointer( POINTER_ARROW );
     749           0 : }
     750             : 
     751           0 : X11SalFrame::X11SalFrame( SalFrame *pParent, sal_uLong nSalFrameStyle,
     752             :                           SystemParentData* pSystemParent ) :
     753           0 :     m_nXScreen( 0 )
     754             : {
     755           0 :     SalGenericData *pData = GetGenericData();
     756             : 
     757             :     // initialize frame geometry
     758           0 :     memset( &maGeometry, 0, sizeof(maGeometry) );
     759             : 
     760           0 :     mpParent                    = static_cast< X11SalFrame* >( pParent );
     761             : 
     762           0 :     mbTransientForRoot          = false;
     763             : 
     764           0 :     pDisplay_                   = pData->GetSalDisplay();
     765             :     // insert frame in framelist
     766           0 :     pDisplay_->registerFrame( this );
     767             : 
     768           0 :     mhWindow                    = None;
     769           0 :     mhShellWindow               = None;
     770           0 :     mhStackingWindow            = None;
     771           0 :     mhForeignParent             = None;
     772           0 :     mhBackgroundPixmap          = None;
     773           0 :     m_bSetFocusOnMap            = false;
     774             : 
     775           0 :     pGraphics_                  = NULL;
     776           0 :     pFreeGraphics_              = NULL;
     777             : 
     778           0 :     hCursor_                    = None;
     779           0 :     nCaptured_                  = 0;
     780             : 
     781           0 :      nReleaseTime_              = 0;
     782           0 :     nKeyCode_                   = 0;
     783           0 :     nKeyState_                  = 0;
     784           0 :     nCompose_                   = -1;
     785           0 :     mbSendExtKeyModChange       = false;
     786           0 :     mnExtKeyMod                 = 0;
     787             : 
     788           0 :     nShowState_                 = SHOWSTATE_UNKNOWN;
     789           0 :     nWidth_                     = 0;
     790           0 :     nHeight_                    = 0;
     791           0 :     nStyle_                     = 0;
     792           0 :     mnExtStyle                  = 0;
     793           0 :     bAlwaysOnTop_               = false;
     794             : 
     795             :     // set bViewable_ to true: hack GetClientSize to report something
     796             :     // different to 0/0 before first map
     797           0 :     bViewable_                  = true;
     798           0 :     bMapped_                    = false;
     799           0 :     bDefaultPosition_           = true;
     800           0 :     nVisibility_                = VisibilityFullyObscured;
     801           0 :     m_nWorkArea                 = 0;
     802           0 :     mbInShow                    = false;
     803           0 :     m_bXEmbed                   = false;
     804             : 
     805           0 :     nScreenSaversTimeout_       = 0;
     806             : 
     807           0 :     mpInputContext              = NULL;
     808           0 :     mbInputFocus                = False;
     809             : 
     810           0 :     maAlwaysOnTopRaiseTimer.SetTimeoutHdl( LINK( this, X11SalFrame, HandleAlwaysOnTopRaise ) );
     811           0 :     maAlwaysOnTopRaiseTimer.SetTimeout( 100 );
     812             : 
     813           0 :     meWindowType                = WMAdaptor::windowType_Normal;
     814           0 :     mnDecorationFlags           = WMAdaptor::decoration_All;
     815           0 :     mbMaximizedVert             = false;
     816           0 :     mbMaximizedHorz             = false;
     817           0 :     mbShaded                    = false;
     818           0 :     mbFullScreen                = false;
     819             : 
     820           0 :     mnIconID                    = 1; // ICON_LO_DEFAULT
     821             : 
     822           0 :     m_pClipRectangles           = NULL;
     823           0 :     m_nCurClipRect              = 0;
     824           0 :     m_nMaxClipRect              = 0;
     825             : 
     826           0 :     if( mpParent )
     827           0 :         mpParent->maChildren.push_back( this );
     828             : 
     829           0 :     Init( nSalFrameStyle, GetDisplay()->GetDefaultXScreen(), pSystemParent );
     830           0 : }
     831             : 
     832           0 : X11SalFrame::~X11SalFrame()
     833             : {
     834           0 :     notifyDelete();
     835             : 
     836           0 :     if( m_pClipRectangles )
     837             :     {
     838           0 :         delete [] m_pClipRectangles;
     839           0 :         m_pClipRectangles = NULL;
     840           0 :         m_nCurClipRect = m_nMaxClipRect = 0;
     841             :     }
     842             : 
     843           0 :     if( mhBackgroundPixmap )
     844             :     {
     845           0 :         XSetWindowBackgroundPixmap( GetXDisplay(), GetWindow(), None );
     846           0 :         XFreePixmap( GetXDisplay(), mhBackgroundPixmap );
     847             :     }
     848             : 
     849           0 :     if( mhStackingWindow )
     850           0 :         aPresentationReparentList.remove( mhStackingWindow );
     851             : 
     852             :     // remove from parent's list
     853           0 :     if( mpParent )
     854           0 :         mpParent->maChildren.remove( this );
     855             : 
     856             :     // deregister on SalDisplay
     857           0 :     pDisplay_->deregisterFrame( this );
     858             : 
     859             :     // unselect all events, some may be still in the queue anyway
     860           0 :     if( ! IsSysChildWindow() )
     861           0 :         XSelectInput( GetXDisplay(), GetShellWindow(), 0 );
     862           0 :     XSelectInput( GetXDisplay(), GetWindow(), 0 );
     863             : 
     864           0 :     ShowFullScreen( false, 0 );
     865             : 
     866           0 :     if( bMapped_ )
     867           0 :         Show( false );
     868             : 
     869           0 :     if( mpInputContext )
     870             :     {
     871           0 :         mpInputContext->UnsetICFocus( this );
     872           0 :         mpInputContext->Unmap( this );
     873           0 :         delete mpInputContext;
     874             :     }
     875             : 
     876           0 :     if( GetWindow() == hPresentationWindow )
     877             :     {
     878           0 :         hPresentationWindow = None;
     879           0 :         doReparentPresentationDialogues( GetDisplay() );
     880             :     }
     881             : 
     882           0 :     if( pGraphics_ )
     883             :     {
     884           0 :         pGraphics_->DeInit();
     885           0 :         delete pGraphics_;
     886             :     }
     887             : 
     888           0 :     if( pFreeGraphics_ )
     889             :     {
     890           0 :         pFreeGraphics_->DeInit();
     891           0 :         delete pFreeGraphics_;
     892             :     }
     893             : 
     894           0 :     XDestroyWindow( GetXDisplay(), mhWindow );
     895             : 
     896             :     /*
     897             :      *  check if there is only the status frame left
     898             :      *  if so, free it
     899             :      */
     900           0 :     if( ! GetDisplay()->getFrames().empty() && vcl::I18NStatus::exists() )
     901             :     {
     902           0 :         SalFrame* pStatusFrame = vcl::I18NStatus::get().getStatusFrame();
     903           0 :         std::list< SalFrame* >::const_iterator sit = GetDisplay()->getFrames().begin();
     904           0 :         if( pStatusFrame
     905           0 :             && *sit == pStatusFrame
     906           0 :             && ++sit == GetDisplay()->getFrames().end() )
     907           0 :             vcl::I18NStatus::free();
     908             :     }
     909           0 : }
     910             : 
     911           0 : void X11SalFrame::SetExtendedFrameStyle( SalExtStyle nStyle )
     912             : {
     913           0 :     if( nStyle != mnExtStyle && ! IsChildWindow() )
     914             :     {
     915           0 :         mnExtStyle = nStyle;
     916           0 :         updateWMClass();
     917             :     }
     918           0 : }
     919             : 
     920           0 : const SystemEnvData* X11SalFrame::GetSystemData() const
     921             : {
     922           0 :     X11SalFrame *pFrame = const_cast<X11SalFrame*>(this);
     923           0 :     pFrame->maSystemChildData.nSize         = sizeof( SystemEnvData );
     924           0 :     pFrame->maSystemChildData.pDisplay      = GetXDisplay();
     925           0 :     pFrame->maSystemChildData.aWindow       = pFrame->GetWindow();
     926           0 :     pFrame->maSystemChildData.pSalFrame     = pFrame;
     927           0 :     pFrame->maSystemChildData.pWidget       = NULL;
     928           0 :     pFrame->maSystemChildData.pVisual       = GetDisplay()->GetVisual( m_nXScreen ).GetVisual();
     929           0 :     pFrame->maSystemChildData.nScreen       = m_nXScreen.getXScreen();
     930           0 :     pFrame->maSystemChildData.nDepth        = GetDisplay()->GetVisual( m_nXScreen ).GetDepth();
     931           0 :     pFrame->maSystemChildData.aColormap     = GetDisplay()->GetColormap( m_nXScreen ).GetXColormap();
     932           0 :     pFrame->maSystemChildData.pAppContext   = NULL;
     933           0 :     pFrame->maSystemChildData.aShellWindow  = pFrame->GetShellWindow();
     934           0 :     pFrame->maSystemChildData.pShellWidget  = NULL;
     935           0 :     return &maSystemChildData;
     936             : }
     937             : 
     938           0 : SalGraphics *X11SalFrame::AcquireGraphics()
     939             : {
     940           0 :     if( pGraphics_ )
     941           0 :         return NULL;
     942             : 
     943           0 :     if( pFreeGraphics_ )
     944             :     {
     945           0 :         pGraphics_      = pFreeGraphics_;
     946           0 :         pFreeGraphics_  = NULL;
     947             :     }
     948             :     else
     949             :     {
     950           0 :         pGraphics_ = new X11SalGraphics();
     951           0 :         pGraphics_->Init( this, GetWindow(), m_nXScreen );
     952             :     }
     953             : 
     954           0 :     return pGraphics_;
     955             : }
     956             : 
     957           0 : void X11SalFrame::ReleaseGraphics( SalGraphics *pGraphics )
     958             : {
     959             :     DBG_ASSERT( pGraphics == pGraphics_, "SalFrame::ReleaseGraphics pGraphics!=pGraphics_" );
     960             : 
     961           0 :     if( pGraphics != pGraphics_ )
     962           0 :         return;
     963             : 
     964           0 :     pFreeGraphics_  = pGraphics_;
     965           0 :     pGraphics_      = NULL;
     966             : }
     967             : 
     968           0 : void X11SalFrame::updateGraphics( bool bClear )
     969             : {
     970           0 :     Drawable aDrawable = bClear ? None : GetWindow();
     971           0 :     if( pGraphics_ )
     972           0 :         pGraphics_->SetDrawable( aDrawable, m_nXScreen );
     973           0 :     if( pFreeGraphics_ )
     974           0 :         pFreeGraphics_->SetDrawable( aDrawable, m_nXScreen );
     975           0 : }
     976             : 
     977           0 : void X11SalFrame::SetIcon( sal_uInt16 nIcon )
     978             : {
     979           0 :     if ( ! IsChildWindow() )
     980             :     {
     981             :         // 0 == default icon -> #1
     982           0 :         if ( nIcon == 0 )
     983           0 :             nIcon = 1;
     984             : 
     985           0 :         mnIconID = nIcon;
     986             : 
     987           0 :         XIconSize *pIconSize = NULL;
     988           0 :         int nSizes = 0;
     989           0 :         int iconSize = 32;
     990           0 :         if ( XGetIconSizes( GetXDisplay(), GetDisplay()->GetRootWindow( m_nXScreen ), &pIconSize, &nSizes ) )
     991             :         {
     992             : #if OSL_DEBUG_LEVEL > 1
     993             :             fprintf(stderr, "X11SalFrame::SetIcon(): found %d IconSizes:\n", nSizes);
     994             : #endif
     995             : 
     996           0 :             const int ourLargestIconSize = 48;
     997             : 
     998             :             int i;
     999           0 :             for( i=0; i<nSizes; i++)
    1000             :             {
    1001             :                // select largest supported icon
    1002             : 
    1003             :                // Note: olwm/olvwm reports a huge max icon size of
    1004             :                // 160x160 pixels; always choosing the max as the
    1005             :                // preferred icon size is apparently wrong under olvwm
    1006             :                // - so we keep the safe default |iconSize| when we see
    1007             :                // unreasonable large max icon sizes (> twice of our
    1008             :                // largest available icon) reported by XGetIconSizes.
    1009           0 :                 if( pIconSize[i].max_width > iconSize
    1010           0 :                     && pIconSize[i].max_width <= 2*ourLargestIconSize )
    1011             :                 {
    1012           0 :                     iconSize = pIconSize[i].max_width;
    1013             :                 }
    1014           0 :                 iconSize = pIconSize[i].max_width;
    1015             : 
    1016             : #if OSL_DEBUG_LEVEL > 1
    1017             :                 fprintf(stderr, "min: %d, %d\nmax: %d, %d\ninc: %d, %d\n\n",
    1018             :                         pIconSize[i].min_width, pIconSize[i].min_height,
    1019             :                         pIconSize[i].max_width, pIconSize[i].max_height,
    1020             :                         pIconSize[i].width_inc, pIconSize[i].height_inc);
    1021             : #endif
    1022             :             }
    1023             : 
    1024           0 :             XFree( pIconSize );
    1025             :         }
    1026             :         else
    1027             :         {
    1028           0 :             const OUString& rWM( pDisplay_->getWMAdaptor()->getWindowManagerName() );
    1029           0 :             if( rWM.equalsAscii( "KWin" ) )         // assume KDE is running
    1030           0 :                 iconSize = 48;
    1031             :             static bool bGnomeIconSize = false;
    1032             :             static bool bGnomeChecked = false;
    1033           0 :             if( ! bGnomeChecked )
    1034             :             {
    1035           0 :                 bGnomeChecked=true;
    1036           0 :                 int nCount = 0;
    1037             :                 Atom* pProps = XListProperties( GetXDisplay(),
    1038             :                                                 GetDisplay()->GetRootWindow( m_nXScreen ),
    1039           0 :                                                 &nCount );
    1040           0 :                 for( int i = 0; i < nCount && !bGnomeIconSize; i++ )
    1041             :                  {
    1042           0 :                     char* pName = XGetAtomName( GetXDisplay(), pProps[i] );
    1043           0 :                     if( pName )
    1044             :                     {
    1045           0 :                         if( !strcmp( pName, "GNOME_PANEL_DESKTOP_AREA" ) )
    1046           0 :                             bGnomeIconSize = true;
    1047           0 :                         XFree( pName );
    1048             :                     }
    1049             :                  }
    1050           0 :                 if( pProps )
    1051           0 :                     XFree( pProps );
    1052             :             }
    1053           0 :             if( bGnomeIconSize )
    1054           0 :                 iconSize = 48;
    1055             :         }
    1056             : 
    1057             :         XWMHints Hints;
    1058           0 :         Hints.flags = 0;
    1059           0 :         XWMHints *pHints = XGetWMHints( GetXDisplay(), GetShellWindow() );
    1060           0 :         if( pHints )
    1061             :         {
    1062           0 :             memcpy(&Hints, pHints, sizeof( XWMHints ));
    1063           0 :             XFree( pHints );
    1064             :         }
    1065           0 :         pHints = &Hints;
    1066             : 
    1067           0 :         NetWmIconData netwm_icon;
    1068             :         bool bOk = lcl_SelectAppIconPixmap( GetDisplay(), m_nXScreen,
    1069             :                                                 nIcon, iconSize,
    1070           0 :                                                 pHints->icon_pixmap, pHints->icon_mask, netwm_icon );
    1071           0 :         if ( !bOk )
    1072             :         {
    1073             :             // load default icon (0)
    1074             :             bOk = lcl_SelectAppIconPixmap( GetDisplay(), m_nXScreen,
    1075             :                                            0, iconSize,
    1076           0 :                                            pHints->icon_pixmap, pHints->icon_mask, netwm_icon );
    1077             :         }
    1078           0 :         if( bOk )
    1079             :         {
    1080           0 :             pHints->flags    |= IconPixmapHint;
    1081           0 :             if( pHints->icon_mask )
    1082           0 :                 pHints->flags |= IconMaskHint;
    1083             : 
    1084           0 :             XSetWMHints( GetXDisplay(), GetShellWindow(), pHints );
    1085           0 :             if( !netwm_icon.empty() && GetDisplay()->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_ICON ))
    1086             :                 XChangeProperty( GetXDisplay(), mhWindow,
    1087             :                     GetDisplay()->getWMAdaptor()->getAtom( WMAdaptor::NET_WM_ICON ),
    1088           0 :                     XA_CARDINAL, 32, PropModeReplace, (unsigned char*)&netwm_icon.front(), netwm_icon.size());
    1089           0 :         }
    1090             :     }
    1091           0 : }
    1092             : 
    1093           0 : void X11SalFrame::SetMaxClientSize( long nWidth, long nHeight )
    1094             : {
    1095           0 :     if( ! IsChildWindow() )
    1096             :     {
    1097           0 :         if( GetShellWindow() && (nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT )
    1098             :         {
    1099           0 :             XSizeHints* pHints = XAllocSizeHints();
    1100           0 :             long nSupplied = 0;
    1101             :             XGetWMNormalHints( GetXDisplay(),
    1102             :                                GetShellWindow(),
    1103             :                                pHints,
    1104             :                                &nSupplied
    1105           0 :                                );
    1106           0 :             pHints->max_width   = nWidth;
    1107           0 :             pHints->max_height  = nHeight;
    1108           0 :             pHints->flags |= PMaxSize;
    1109             :             XSetWMNormalHints( GetXDisplay(),
    1110             :                                GetShellWindow(),
    1111           0 :                                pHints );
    1112           0 :             XFree( pHints );
    1113             :         }
    1114             :     }
    1115           0 : }
    1116             : 
    1117           0 : void X11SalFrame::SetMinClientSize( long nWidth, long nHeight )
    1118             : {
    1119           0 :     if( ! IsChildWindow() )
    1120             :     {
    1121           0 :         if( GetShellWindow() && (nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT )
    1122             :         {
    1123           0 :             XSizeHints* pHints = XAllocSizeHints();
    1124           0 :             long nSupplied = 0;
    1125             :             XGetWMNormalHints( GetXDisplay(),
    1126             :                                GetShellWindow(),
    1127             :                                pHints,
    1128             :                                &nSupplied
    1129           0 :                                );
    1130           0 :             pHints->min_width   = nWidth;
    1131           0 :             pHints->min_height  = nHeight;
    1132           0 :             pHints->flags |= PMinSize;
    1133             :             XSetWMNormalHints( GetXDisplay(),
    1134             :                                GetShellWindow(),
    1135           0 :                                pHints );
    1136           0 :             XFree( pHints );
    1137             :         }
    1138             :     }
    1139           0 : }
    1140             : 
    1141             : // Show + Pos (x,y,z) + Size (width,height)
    1142             : 
    1143           0 : void X11SalFrame::Show( bool bVisible, bool bNoActivate )
    1144             : {
    1145           0 :     if( ( bVisible && bMapped_ )
    1146           0 :         || ( !bVisible && !bMapped_ ) )
    1147           0 :         return;
    1148             : 
    1149             :     // HACK: this is a workaround for (at least) kwin
    1150             :     // even though transient frames should be kept above their parent
    1151             :     // this does not necessarily hold true for DOCK type windows
    1152             :     // so artificially set ABOVE and remove it again on hide
    1153           0 :     if( mpParent && (mpParent->nStyle_ & SAL_FRAME_STYLE_PARTIAL_FULLSCREEN ) && pDisplay_->getWMAdaptor()->isLegacyPartialFullscreen())
    1154           0 :         pDisplay_->getWMAdaptor()->enableAlwaysOnTop( this, bVisible );
    1155             : 
    1156           0 :     bMapped_   = bVisible;
    1157           0 :     bViewable_ = bVisible;
    1158           0 :     setXEmbedInfo();
    1159           0 :     if( bVisible )
    1160             :     {
    1161           0 :         mbInShow = true;
    1162           0 :         if( ! (nStyle_ & SAL_FRAME_STYLE_INTRO) )
    1163             :         {
    1164             :             // hide all INTRO frames
    1165           0 :             const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
    1166           0 :             for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
    1167             :             {
    1168           0 :                 const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
    1169             :                 // look for intro bit map; if present, hide it
    1170           0 :                 if( pFrame->nStyle_ & SAL_FRAME_STYLE_INTRO )
    1171             :                 {
    1172           0 :                     if( pFrame->bMapped_ )
    1173           0 :                         const_cast<X11SalFrame*>(pFrame)->Show( false );
    1174             :                 }
    1175             :             }
    1176             :         }
    1177             : 
    1178             :         // update NET_WM_STATE which may have been deleted due to earlier Show(false)
    1179           0 :         if( nShowState_ == SHOWSTATE_HIDDEN )
    1180           0 :             GetDisplay()->getWMAdaptor()->frameIsMapping( this );
    1181             : 
    1182             :         /*
    1183             :          *  Actually this is rather exotic and currently happens only in conjunction
    1184             :          *  with the basic dialogue editor,
    1185             :          *  which shows a frame and instantly hides it again. After that the
    1186             :          *  editor window is shown and the WM takes this as an opportunity
    1187             :          *  to show our hidden transient frame also. So Show( false ) must
    1188             :          *  withdraw the frame AND delete the WM_TRANSIENT_FOR property.
    1189             :          *  In case the frame is shown again, the transient hint must be restored here.
    1190             :          */
    1191           0 :         if(    ! IsChildWindow()
    1192           0 :             && ! IsOverrideRedirect()
    1193           0 :             && ! IsFloatGrabWindow()
    1194           0 :             && mpParent
    1195             :             )
    1196             :         {
    1197           0 :             GetDisplay()->getWMAdaptor()->changeReferenceFrame( this, mpParent );
    1198             :         }
    1199             : 
    1200             :         // #i45160# switch to desktop where a dialog with parent will appear
    1201           0 :         if( mpParent && mpParent->m_nWorkArea != m_nWorkArea )
    1202           0 :             GetDisplay()->getWMAdaptor()->switchToWorkArea( mpParent->m_nWorkArea );
    1203             : 
    1204           0 :         if( IsFloatGrabWindow() &&
    1205           0 :             mpParent &&
    1206           0 :             nVisibleFloats == 0 &&
    1207           0 :             ! GetDisplay()->GetCaptureFrame() )
    1208             :         {
    1209             :             /* #i39420#
    1210             :              * outsmart KWin's "focus strictly under mouse" mode
    1211             :              * which insists on taking the focus from the document
    1212             :              * to the new float. Grab focus to parent frame BEFORE
    1213             :              * showing the float (cannot grab it to the float
    1214             :              * before show).
    1215             :              */
    1216             :             XGrabPointer( GetXDisplay(),
    1217             :                           mpParent->GetWindow(),
    1218             :                           True,
    1219             :                           PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
    1220             :                           GrabModeAsync,
    1221             :                           GrabModeAsync,
    1222             :                           None,
    1223           0 :                           mpParent ? mpParent->GetCursor() : None,
    1224             :                           CurrentTime
    1225           0 :                           );
    1226             :         }
    1227             : 
    1228           0 :         Time nUserTime = 0;
    1229           0 :         if( ! bNoActivate && (nStyle_ & (SAL_FRAME_STYLE_OWNERDRAWDECORATION)) == 0 )
    1230           0 :             nUserTime = pDisplay_->GetLastUserEventTime( true );
    1231           0 :         GetDisplay()->getWMAdaptor()->setUserTime( this, nUserTime );
    1232           0 :         if( ! bNoActivate && (nStyle_ & SAL_FRAME_STYLE_TOOLWINDOW) )
    1233           0 :             m_bSetFocusOnMap = true;
    1234             : 
    1235             :         // actually map the window
    1236           0 :         if( m_bXEmbed )
    1237           0 :             askForXEmbedFocus( 0 );
    1238             :         else
    1239             :         {
    1240           0 :             if( GetWindow() != GetShellWindow() && ! IsSysChildWindow() )
    1241             :             {
    1242           0 :                 if( IsChildWindow() )
    1243           0 :                     XMapWindow( GetXDisplay(), GetShellWindow() );
    1244           0 :                 XSelectInput( GetXDisplay(), GetShellWindow(), CLIENT_EVENTS );
    1245             :             }
    1246           0 :             if( nStyle_ & SAL_FRAME_STYLE_FLOAT )
    1247           0 :                 XMapRaised( GetXDisplay(), GetWindow() );
    1248             :             else
    1249           0 :                 XMapWindow( GetXDisplay(), GetWindow() );
    1250             :         }
    1251           0 :         XSelectInput( GetXDisplay(), GetWindow(), CLIENT_EVENTS );
    1252             : 
    1253           0 :         if( maGeometry.nWidth > 0
    1254           0 :             && maGeometry.nHeight > 0
    1255           0 :             && (   nWidth_  != (int)maGeometry.nWidth
    1256           0 :                 || nHeight_ != (int)maGeometry.nHeight ) )
    1257             :         {
    1258           0 :             nWidth_  = maGeometry.nWidth;
    1259           0 :             nHeight_ = maGeometry.nHeight;
    1260             :         }
    1261             : 
    1262           0 :         XSync( GetXDisplay(), False );
    1263             : 
    1264           0 :         if( IsFloatGrabWindow() )
    1265             :         {
    1266             :             /*
    1267             :              *  Sawfish and twm can be switched to enter-exit focus behaviour. In this case
    1268             :              *  we must grab the pointer else the dumb WM will put the focus to the
    1269             :              *  override-redirect float window. The application window will be deactivated
    1270             :              *  which causes that the floats are destroyed, so the user can never click on
    1271             :              *  a menu because it vanishes as soon as he enters it.
    1272             :              */
    1273           0 :             nVisibleFloats++;
    1274           0 :             if( nVisibleFloats == 1 && ! GetDisplay()->GetCaptureFrame() )
    1275             :             {
    1276             :                 /* #i39420# now move grab to the new float window */
    1277             :                 XGrabPointer( GetXDisplay(),
    1278             :                               GetWindow(),
    1279             :                               True,
    1280             :                               PointerMotionMask | ButtonPressMask | ButtonReleaseMask,
    1281             :                               GrabModeAsync,
    1282             :                               GrabModeAsync,
    1283             :                               None,
    1284           0 :                               mpParent ? mpParent->GetCursor() : None,
    1285             :                               CurrentTime
    1286           0 :                               );
    1287             :             }
    1288             :         }
    1289           0 :         CallCallback( SALEVENT_RESIZE, NULL );
    1290             : 
    1291             :         /*
    1292             :          *  sometimes a message box/dialogue is brought up when a frame is not mapped
    1293             :          *  the corresponding TRANSIENT_FOR hint is then set to the root window
    1294             :          *  so that the dialogue shows in all cases. Correct it here if the
    1295             :          *  frame is shown afterwards.
    1296             :          */
    1297           0 :         if( ! IsChildWindow()
    1298           0 :             && ! IsOverrideRedirect()
    1299           0 :             && ! IsFloatGrabWindow()
    1300             :             )
    1301             :         {
    1302           0 :             for( std::list< X11SalFrame* >::const_iterator it = maChildren.begin();
    1303           0 :                  it != maChildren.end(); ++it )
    1304             :             {
    1305           0 :                 if( (*it)->mbTransientForRoot )
    1306           0 :                     GetDisplay()->getWMAdaptor()->changeReferenceFrame( *it, this );
    1307             :             }
    1308             :         }
    1309             :         /*
    1310             :          *  leave SHOWSTATE_UNKNOWN as this indicates first mapping
    1311             :          *  and is only reset int HandleSizeEvent
    1312             :          */
    1313           0 :         if( nShowState_ != SHOWSTATE_UNKNOWN )
    1314           0 :             nShowState_ = SHOWSTATE_NORMAL;
    1315             : 
    1316             :         /*
    1317             :          *  plugged windows don't necessarily get the
    1318             :          *  focus on show because the parent may already be mapped
    1319             :          *  and have the focus. So try to set the focus
    1320             :          *  to the child on Show(true)
    1321             :          */
    1322           0 :         if( (nStyle_ & SAL_FRAME_STYLE_PLUG) && ! m_bXEmbed )
    1323             :             XSetInputFocus( GetXDisplay(),
    1324             :                             GetWindow(),
    1325             :                             RevertToParent,
    1326           0 :                             CurrentTime );
    1327             : 
    1328           0 :         if( mpParent )
    1329             :         {
    1330             :             // push this frame so it will be in front of its siblings
    1331             :             // only necessary for insane transient behaviour of Dtwm/olwm
    1332           0 :             mpParent->maChildren.remove( this );
    1333           0 :             mpParent->maChildren.push_front(this);
    1334             :         }
    1335             :     }
    1336             :     else
    1337             :     {
    1338           0 :         if( getInputContext() )
    1339           0 :             getInputContext()->Unmap( this );
    1340             : 
    1341           0 :         if( ! IsChildWindow() )
    1342             :         {
    1343             :             /*  FIXME: Is deleting the property really necessary ? It hurts
    1344             :              *  owner drawn windows at least.
    1345             :              */
    1346           0 :             if( mpParent && ! (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
    1347           0 :                 XDeleteProperty( GetXDisplay(), GetShellWindow(), GetDisplay()->getWMAdaptor()->getAtom( WMAdaptor::WM_TRANSIENT_FOR ) );
    1348           0 :             XWithdrawWindow( GetXDisplay(), GetShellWindow(), m_nXScreen.getXScreen() );
    1349             :         }
    1350           0 :         else if( ! m_bXEmbed )
    1351           0 :             XUnmapWindow( GetXDisplay(), GetWindow() );
    1352             : 
    1353           0 :         nShowState_ = SHOWSTATE_HIDDEN;
    1354           0 :         if( IsFloatGrabWindow() && nVisibleFloats )
    1355             :         {
    1356           0 :             nVisibleFloats--;
    1357           0 :             if( nVisibleFloats == 0  && ! GetDisplay()->GetCaptureFrame() )
    1358             :                 XUngrabPointer( GetXDisplay(),
    1359           0 :                                 CurrentTime );
    1360             :         }
    1361             :         // flush here; there may be a very seldom race between
    1362             :         // the display connection used for clipboard and our connection
    1363           0 :         Flush();
    1364             :     }
    1365             : }
    1366             : 
    1367           0 : void X11SalFrame::ToTop( sal_uInt16 nFlags )
    1368             : {
    1369           0 :     if( ( nFlags & SAL_FRAME_TOTOP_RESTOREWHENMIN )
    1370           0 :         && ! ( nStyle_ & SAL_FRAME_STYLE_FLOAT )
    1371           0 :         && nShowState_ != SHOWSTATE_HIDDEN
    1372           0 :         && nShowState_ != SHOWSTATE_UNKNOWN
    1373             :         )
    1374             :     {
    1375           0 :         GetDisplay()->getWMAdaptor()->frameIsMapping( this );
    1376           0 :         if( GetWindow() != GetShellWindow() && ! IsSysChildWindow() )
    1377           0 :             XMapWindow( GetXDisplay(), GetShellWindow() );
    1378           0 :         XMapWindow( GetXDisplay(), GetWindow() );
    1379             :     }
    1380             : 
    1381           0 :     ::Window aToTopWindow = IsSysChildWindow() ? GetWindow() : GetShellWindow();
    1382           0 :     if( ! (nFlags & SAL_FRAME_TOTOP_GRABFOCUS_ONLY) )
    1383             :     {
    1384           0 :         XRaiseWindow( GetXDisplay(), aToTopWindow );
    1385           0 :         if( ! GetDisplay()->getWMAdaptor()->isTransientBehaviourAsExpected() )
    1386           0 :             for( std::list< X11SalFrame* >::const_iterator it = maChildren.begin();
    1387           0 :                  it != maChildren.end(); ++it )
    1388           0 :                 (*it)->ToTop( nFlags & ~SAL_FRAME_TOTOP_GRABFOCUS );
    1389             :     }
    1390             : 
    1391           0 :     if( ( ( nFlags & SAL_FRAME_TOTOP_GRABFOCUS ) || ( nFlags & SAL_FRAME_TOTOP_GRABFOCUS_ONLY ) )
    1392           0 :         && bMapped_ )
    1393             :     {
    1394           0 :         if( m_bXEmbed )
    1395           0 :             askForXEmbedFocus( 0 );
    1396             :         else
    1397           0 :             XSetInputFocus( GetXDisplay(), aToTopWindow, RevertToParent, CurrentTime );
    1398             :     }
    1399           0 : }
    1400             : 
    1401           0 : void X11SalFrame::GetWorkArea( Rectangle& rWorkArea )
    1402             : {
    1403           0 :     rWorkArea = pDisplay_->getWMAdaptor()->getWorkArea( 0 );
    1404           0 : }
    1405             : 
    1406           0 : void X11SalFrame::GetClientSize( long &rWidth, long &rHeight )
    1407             : {
    1408           0 :     if( ! bViewable_  )
    1409             :     {
    1410           0 :         rWidth = rHeight = 0;
    1411           0 :         return;
    1412             :     }
    1413             : 
    1414           0 :     rWidth  = maGeometry.nWidth;
    1415           0 :     rHeight = maGeometry.nHeight;
    1416             : 
    1417           0 :     if( !rWidth || !rHeight )
    1418             :     {
    1419             :         XWindowAttributes aAttrib;
    1420             : 
    1421           0 :         XGetWindowAttributes( GetXDisplay(), GetWindow(), &aAttrib );
    1422             : 
    1423           0 :         maGeometry.nWidth = rWidth = aAttrib.width;
    1424           0 :         maGeometry.nHeight = rHeight = aAttrib.height;
    1425             :     }
    1426             : }
    1427             : 
    1428           0 : void X11SalFrame::Center( )
    1429             : {
    1430             :     int             nX, nY, nScreenWidth, nScreenHeight;
    1431             :     int             nRealScreenWidth, nRealScreenHeight;
    1432           0 :     int             nScreenX = 0, nScreenY = 0;
    1433             : 
    1434           0 :     const Size& aScreenSize = GetDisplay()->getDataForScreen( m_nXScreen ).m_aSize;
    1435           0 :     nScreenWidth        = aScreenSize.Width();
    1436           0 :     nScreenHeight       = aScreenSize.Height();
    1437           0 :     nRealScreenWidth    = nScreenWidth;
    1438           0 :     nRealScreenHeight   = nScreenHeight;
    1439             : 
    1440           0 :     if( GetDisplay()->IsXinerama() )
    1441             :     {
    1442             :         // get xinerama screen we are on
    1443             :         // if there is a parent, use its center for screen determination
    1444             :         // else use the pointer
    1445             :         ::Window aRoot, aChild;
    1446             :         int root_x, root_y, x, y;
    1447             :         unsigned int mask;
    1448           0 :         if( mpParent )
    1449             :         {
    1450           0 :             root_x = mpParent->maGeometry.nX + mpParent->maGeometry.nWidth/2;
    1451           0 :             root_y = mpParent->maGeometry.nY + mpParent->maGeometry.nHeight/2;
    1452             :         }
    1453             :         else
    1454             :             XQueryPointer( GetXDisplay(),
    1455             :                            GetShellWindow(),
    1456             :                            &aRoot, &aChild,
    1457             :                            &root_x, &root_y,
    1458             :                            &x, &y,
    1459           0 :                            &mask );
    1460           0 :         const std::vector< Rectangle >& rScreens = GetDisplay()->GetXineramaScreens();
    1461           0 :         for( unsigned int i = 0; i < rScreens.size(); i++ )
    1462           0 :             if( rScreens[i].IsInside( Point( root_x, root_y ) ) )
    1463             :             {
    1464           0 :                 nScreenX            = rScreens[i].Left();
    1465           0 :                 nScreenY            = rScreens[i].Top();
    1466           0 :                 nRealScreenWidth    = rScreens[i].GetWidth();
    1467           0 :                 nRealScreenHeight   = rScreens[i].GetHeight();
    1468           0 :                 break;
    1469             :             }
    1470             :     }
    1471             : 
    1472           0 :     if( mpParent )
    1473             :     {
    1474           0 :         X11SalFrame* pFrame = mpParent;
    1475           0 :         while( pFrame->mpParent )
    1476           0 :             pFrame = pFrame->mpParent;
    1477           0 :         if( pFrame->maGeometry.nWidth < 1  || pFrame->maGeometry.nHeight < 1 )
    1478             :         {
    1479           0 :             Rectangle aRect;
    1480           0 :             pFrame->GetPosSize( aRect );
    1481           0 :             pFrame->maGeometry.nX       = aRect.Left();
    1482           0 :             pFrame->maGeometry.nY       = aRect.Top();
    1483           0 :             pFrame->maGeometry.nWidth   = aRect.GetWidth();
    1484           0 :             pFrame->maGeometry.nHeight  = aRect.GetHeight();
    1485             :         }
    1486             : 
    1487           0 :         if( pFrame->nStyle_ & SAL_FRAME_STYLE_PLUG )
    1488             :         {
    1489             :             ::Window aRoot;
    1490             :             unsigned int bw, depth;
    1491             :             XGetGeometry( GetXDisplay(),
    1492             :                           pFrame->GetShellWindow(),
    1493             :                           &aRoot,
    1494             :                           &nScreenX, &nScreenY,
    1495             :                           (unsigned int*)&nScreenWidth,
    1496             :                           (unsigned int*)&nScreenHeight,
    1497           0 :                           &bw, &depth );
    1498             :         }
    1499             :         else
    1500             :         {
    1501           0 :             nScreenX        = pFrame->maGeometry.nX;
    1502           0 :             nScreenY        = pFrame->maGeometry.nY;
    1503           0 :             nScreenWidth    = pFrame->maGeometry.nWidth;
    1504           0 :             nScreenHeight   = pFrame->maGeometry.nHeight;
    1505             :         }
    1506             :     }
    1507             : 
    1508           0 :     if( mpParent && mpParent->nShowState_ == SHOWSTATE_NORMAL )
    1509             :     {
    1510           0 :         if( maGeometry.nWidth >= mpParent->maGeometry.nWidth &&
    1511           0 :             maGeometry.nHeight >= mpParent->maGeometry.nHeight )
    1512             :         {
    1513           0 :             nX = nScreenX + 40;
    1514           0 :             nY = nScreenY + 40;
    1515             :         }
    1516             :         else
    1517             :         {
    1518             :             // center the window relative to the top level frame
    1519           0 :             nX = (nScreenWidth  - (int)maGeometry.nWidth ) / 2 + nScreenX;
    1520           0 :             nY = (nScreenHeight - (int)maGeometry.nHeight) / 2 + nScreenY;
    1521             :         }
    1522             :     }
    1523             :     else
    1524             :     {
    1525             :         // center the window relative to screen
    1526           0 :         nX = (nRealScreenWidth  - (int)maGeometry.nWidth ) / 2 + nScreenX;
    1527           0 :         nY = (nRealScreenHeight - (int)maGeometry.nHeight) / 2 + nScreenY;
    1528             :     }
    1529           0 :     nX = nX < 0 ? 0 : nX;
    1530           0 :     nY = nY < 0 ? 0 : nY;
    1531             : 
    1532           0 :     bDefaultPosition_ = False;
    1533           0 :     if( mpParent )
    1534             :     {
    1535           0 :         nX -= mpParent->maGeometry.nX;
    1536           0 :         nY -= mpParent->maGeometry.nY;
    1537             :     }
    1538             : 
    1539           0 :     Point aPoint(nX, nY);
    1540           0 :     SetPosSize( Rectangle( aPoint, Size( maGeometry.nWidth, maGeometry.nHeight ) ) );
    1541           0 : }
    1542             : 
    1543           0 : void X11SalFrame::updateScreenNumber()
    1544             : {
    1545           0 :     if( GetDisplay()->IsXinerama() && GetDisplay()->GetXineramaScreens().size() > 1 )
    1546             :     {
    1547           0 :         Point aPoint( maGeometry.nX, maGeometry.nY );
    1548           0 :         const std::vector<Rectangle>& rScreenRects( GetDisplay()->GetXineramaScreens() );
    1549           0 :         size_t nScreens = rScreenRects.size();
    1550           0 :         for( size_t i = 0; i < nScreens; i++ )
    1551             :         {
    1552           0 :             if( rScreenRects[i].IsInside( aPoint ) )
    1553             :             {
    1554           0 :                 maGeometry.nDisplayScreenNumber = static_cast<unsigned int>(i);
    1555           0 :                 break;
    1556             :             }
    1557             :         }
    1558             :     }
    1559             :     else
    1560           0 :         maGeometry.nDisplayScreenNumber = m_nXScreen.getXScreen();
    1561           0 : }
    1562             : 
    1563           0 : void X11SalFrame::SetPosSize( long nX, long nY, long nWidth, long nHeight, sal_uInt16 nFlags )
    1564             : {
    1565           0 :     if( nStyle_ & SAL_FRAME_STYLE_PLUG )
    1566           0 :         return;
    1567             : 
    1568             :     // relative positioning in X11SalFrame::SetPosSize
    1569           0 :     Rectangle aPosSize( Point( maGeometry.nX, maGeometry.nY ), Size( maGeometry.nWidth, maGeometry.nHeight ) );
    1570           0 :     aPosSize.Justify();
    1571             : 
    1572           0 :     if( ! ( nFlags & SAL_FRAME_POSSIZE_X ) )
    1573             :     {
    1574           0 :         nX = aPosSize.Left();
    1575           0 :         if( mpParent )
    1576           0 :             nX -= mpParent->maGeometry.nX;
    1577             :     }
    1578           0 :     if( ! ( nFlags & SAL_FRAME_POSSIZE_Y ) )
    1579             :     {
    1580           0 :         nY = aPosSize.Top();
    1581           0 :         if( mpParent )
    1582           0 :             nY -= mpParent->maGeometry.nY;
    1583             :     }
    1584           0 :     if( ! ( nFlags & SAL_FRAME_POSSIZE_WIDTH ) )
    1585           0 :         nWidth = aPosSize.GetWidth();
    1586           0 :     if( ! ( nFlags & SAL_FRAME_POSSIZE_HEIGHT ) )
    1587           0 :         nHeight = aPosSize.GetHeight();
    1588             : 
    1589           0 :     aPosSize = Rectangle( Point( nX, nY ), Size( nWidth, nHeight ) );
    1590             : 
    1591           0 :     if( ! ( nFlags & ( SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y ) ) )
    1592             :     {
    1593           0 :         if( bDefaultPosition_ )
    1594             :         {
    1595           0 :             maGeometry.nWidth = aPosSize.GetWidth();
    1596           0 :             maGeometry.nHeight = aPosSize.GetHeight();
    1597           0 :             Center();
    1598             :         }
    1599             :         else
    1600           0 :             SetSize( Size( nWidth, nHeight ) );
    1601             :     }
    1602             :     else
    1603           0 :         SetPosSize( aPosSize );
    1604             : 
    1605           0 :     bDefaultPosition_ = False;
    1606             : }
    1607             : 
    1608           0 : void X11SalFrame::SetAlwaysOnTop( bool bOnTop )
    1609             : {
    1610           0 :     if( ! IsOverrideRedirect() )
    1611             :     {
    1612           0 :         bAlwaysOnTop_ = bOnTop;
    1613           0 :         pDisplay_->getWMAdaptor()->enableAlwaysOnTop( this, bOnTop );
    1614             :     }
    1615           0 : }
    1616             : 
    1617             : #define _FRAMESTATE_MASK_GEOMETRY \
    1618             :      (WINDOWSTATE_MASK_X     | WINDOWSTATE_MASK_Y |   \
    1619             :       WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT)
    1620             : #define _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY \
    1621             :      (WINDOWSTATE_MASK_MAXIMIZED_X     | WINDOWSTATE_MASK_MAXIMIZED_Y |   \
    1622             :       WINDOWSTATE_MASK_MAXIMIZED_WIDTH | WINDOWSTATE_MASK_MAXIMIZED_HEIGHT)
    1623             : 
    1624           0 : void X11SalFrame::SetWindowState( const SalFrameState *pState )
    1625             : {
    1626           0 :     if (pState == NULL)
    1627           0 :         return;
    1628             : 
    1629             :     // Request for position or size change
    1630           0 :     if (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY)
    1631             :     {
    1632           0 :         Rectangle aPosSize;
    1633             : 
    1634             :         /* #i44325#
    1635             :          * if maximized, set restore size and guess maximized size from last time
    1636             :          * in state change below maximize window
    1637             :          */
    1638           0 :         if( ! IsChildWindow() &&
    1639           0 :             (pState->mnMask & WINDOWSTATE_MASK_STATE) &&
    1640           0 :             (pState->mnState & WINDOWSTATE_STATE_MAXIMIZED) &&
    1641           0 :             (pState->mnMask & _FRAMESTATE_MASK_GEOMETRY) == _FRAMESTATE_MASK_GEOMETRY &&
    1642           0 :             (pState->mnMask & _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY) == _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY
    1643             :             )
    1644             :         {
    1645           0 :             XSizeHints* pHints = XAllocSizeHints();
    1646           0 :             long nSupplied = 0;
    1647             :             XGetWMNormalHints( GetXDisplay(),
    1648             :                                GetShellWindow(),
    1649             :                                pHints,
    1650           0 :                                &nSupplied );
    1651           0 :             pHints->flags |= PPosition | PWinGravity;
    1652           0 :             pHints->x           = pState->mnX;
    1653           0 :             pHints->y           = pState->mnY;
    1654           0 :             pHints->win_gravity = pDisplay_->getWMAdaptor()->getPositionWinGravity();
    1655             :             XSetWMNormalHints( GetXDisplay(),
    1656             :                                GetShellWindow(),
    1657           0 :                                pHints );
    1658           0 :             XFree( pHints );
    1659             : 
    1660             :             XMoveResizeWindow( GetXDisplay(), GetShellWindow(),
    1661             :                                pState->mnX, pState->mnY,
    1662           0 :                                pState->mnWidth, pState->mnHeight );
    1663             :             // guess maximized geometry from last time
    1664           0 :             maGeometry.nX      = pState->mnMaximizedX;
    1665           0 :             maGeometry.nY      = pState->mnMaximizedY;
    1666           0 :             maGeometry.nWidth  = pState->mnMaximizedWidth;
    1667           0 :             maGeometry.nHeight = pState->mnMaximizedHeight;
    1668           0 :             updateScreenNumber();
    1669             :         }
    1670             :         else
    1671             :         {
    1672           0 :             bool bDoAdjust = false;
    1673             :             // initialize with current geometry
    1674           0 :             if ((pState->mnMask & _FRAMESTATE_MASK_GEOMETRY) != _FRAMESTATE_MASK_GEOMETRY)
    1675           0 :                 GetPosSize (aPosSize);
    1676             : 
    1677             :             // change requested properties
    1678           0 :             if (pState->mnMask & WINDOWSTATE_MASK_X)
    1679             :             {
    1680           0 :                 aPosSize.setX (pState->mnX);
    1681             :             }
    1682           0 :             if (pState->mnMask & WINDOWSTATE_MASK_Y)
    1683             :             {
    1684           0 :                 aPosSize.setY (pState->mnY);
    1685             :             }
    1686           0 :             if (pState->mnMask & WINDOWSTATE_MASK_WIDTH)
    1687             :             {
    1688           0 :                 long nWidth = pState->mnWidth > 0 ? pState->mnWidth  - 1 : 0;
    1689           0 :                 aPosSize.setWidth (nWidth);
    1690           0 :                 bDoAdjust = true;
    1691             :             }
    1692           0 :             if (pState->mnMask & WINDOWSTATE_MASK_HEIGHT)
    1693             :             {
    1694           0 :                 int nHeight = pState->mnHeight > 0 ? pState->mnHeight - 1 : 0;
    1695           0 :                 aPosSize.setHeight (nHeight);
    1696           0 :                 bDoAdjust = true;
    1697             :             }
    1698             : 
    1699           0 :             const Size& aScreenSize = pDisplay_->getDataForScreen( m_nXScreen ).m_aSize;
    1700             : 
    1701           0 :             if( bDoAdjust && aPosSize.GetWidth() <= aScreenSize.Width()
    1702           0 :                 && aPosSize.GetHeight() <= aScreenSize.Height() )
    1703             :             {
    1704           0 :                 SalFrameGeometry aGeom = maGeometry;
    1705             : 
    1706           0 :                 if( ! (nStyle_ & ( SAL_FRAME_STYLE_FLOAT | SAL_FRAME_STYLE_PLUG ) ) &&
    1707           0 :                     mpParent &&
    1708           0 :                 aGeom.nLeftDecoration == 0 &&
    1709           0 :                 aGeom.nTopDecoration == 0 )
    1710             :                 {
    1711           0 :                     aGeom = mpParent->maGeometry;
    1712           0 :                     if( aGeom.nLeftDecoration == 0 &&
    1713           0 :                         aGeom.nTopDecoration == 0 )
    1714             :                     {
    1715           0 :                         aGeom.nLeftDecoration = 5;
    1716           0 :                         aGeom.nTopDecoration = 20;
    1717           0 :                         aGeom.nRightDecoration = 5;
    1718           0 :                         aGeom.nBottomDecoration = 5;
    1719             :                     }
    1720             :                 }
    1721             : 
    1722             :                 // adjust position so that frame fits onto screen
    1723           0 :                 if( aPosSize.Right()+(long)aGeom.nRightDecoration > aScreenSize.Width()-1 )
    1724           0 :                     aPosSize.Move( (long)aScreenSize.Width() - (long)aPosSize.Right() - (long)aGeom.nRightDecoration, 0 );
    1725           0 :                 if( aPosSize.Bottom()+(long)aGeom.nBottomDecoration > aScreenSize.Height()-1 )
    1726           0 :                     aPosSize.Move( 0, (long)aScreenSize.Height() - (long)aPosSize.Bottom() - (long)aGeom.nBottomDecoration );
    1727           0 :                 if( aPosSize.Left() < (long)aGeom.nLeftDecoration )
    1728           0 :                     aPosSize.Move( (long)aGeom.nLeftDecoration - (long)aPosSize.Left(), 0 );
    1729           0 :                 if( aPosSize.Top() < (long)aGeom.nTopDecoration )
    1730           0 :                     aPosSize.Move( 0, (long)aGeom.nTopDecoration - (long)aPosSize.Top() );
    1731             :             }
    1732             : 
    1733           0 :             SetPosSize( 0, 0, aPosSize.GetWidth(), aPosSize.GetHeight(), SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
    1734             :         }
    1735             :     }
    1736             : 
    1737             :     // request for status change
    1738           0 :     if (pState->mnMask & WINDOWSTATE_MASK_STATE)
    1739             :     {
    1740           0 :         if (pState->mnState & WINDOWSTATE_STATE_MAXIMIZED)
    1741             :         {
    1742           0 :             nShowState_ = SHOWSTATE_NORMAL;
    1743           0 :             if( ! (pState->mnState & (WINDOWSTATE_STATE_MAXIMIZED_HORZ|WINDOWSTATE_STATE_MAXIMIZED_VERT) ) )
    1744           0 :                 Maximize();
    1745             :             else
    1746             :             {
    1747           0 :                 bool bHorz = (pState->mnState & WINDOWSTATE_STATE_MAXIMIZED_HORZ) ? true : false;
    1748           0 :                 bool bVert = (pState->mnState & WINDOWSTATE_STATE_MAXIMIZED_VERT) ? true : false;
    1749           0 :                 GetDisplay()->getWMAdaptor()->maximizeFrame( this, bHorz, bVert );
    1750             :             }
    1751           0 :             maRestorePosSize.Left() = pState->mnX;
    1752           0 :             maRestorePosSize.Top() = pState->mnY;
    1753           0 :             maRestorePosSize.Right() = maRestorePosSize.Left() + pState->mnWidth;
    1754           0 :             maRestorePosSize.Right() = maRestorePosSize.Left() + pState->mnHeight;
    1755             :         }
    1756           0 :         else if( mbMaximizedHorz || mbMaximizedVert )
    1757           0 :             GetDisplay()->getWMAdaptor()->maximizeFrame( this, false, false );
    1758             : 
    1759           0 :         if (pState->mnState & WINDOWSTATE_STATE_MINIMIZED)
    1760             :         {
    1761           0 :             if (nShowState_ == SHOWSTATE_UNKNOWN)
    1762           0 :                 nShowState_ = SHOWSTATE_NORMAL;
    1763           0 :             Minimize();
    1764             :         }
    1765           0 :         if (pState->mnState & WINDOWSTATE_STATE_NORMAL)
    1766             :         {
    1767           0 :             if (nShowState_ != SHOWSTATE_NORMAL)
    1768           0 :                 Restore();
    1769             :         }
    1770           0 :         if (pState->mnState & WINDOWSTATE_STATE_ROLLUP)
    1771           0 :             GetDisplay()->getWMAdaptor()->shade( this, true );
    1772             :     }
    1773             : }
    1774             : 
    1775           0 : bool X11SalFrame::GetWindowState( SalFrameState* pState )
    1776             : {
    1777           0 :     if( SHOWSTATE_MINIMIZED == nShowState_ )
    1778           0 :         pState->mnState = WINDOWSTATE_STATE_MINIMIZED;
    1779             :     else
    1780           0 :         pState->mnState = WINDOWSTATE_STATE_NORMAL;
    1781             : 
    1782           0 :     Rectangle aPosSize;
    1783           0 :     if( maRestorePosSize.IsEmpty() )
    1784           0 :         GetPosSize( aPosSize );
    1785             :     else
    1786           0 :         aPosSize = maRestorePosSize;
    1787             : 
    1788           0 :     if( mbMaximizedHorz )
    1789           0 :         pState->mnState |= WINDOWSTATE_STATE_MAXIMIZED_HORZ;
    1790           0 :     if( mbMaximizedVert )
    1791           0 :         pState->mnState |= WINDOWSTATE_STATE_MAXIMIZED_VERT;
    1792           0 :     if( mbShaded )
    1793           0 :         pState->mnState |= WINDOWSTATE_STATE_ROLLUP;
    1794             : 
    1795           0 :     pState->mnX      = aPosSize.Left();
    1796           0 :     pState->mnY      = aPosSize.Top();
    1797           0 :     pState->mnWidth  = aPosSize.GetWidth();
    1798           0 :     pState->mnHeight = aPosSize.GetHeight();
    1799             : 
    1800           0 :     pState->mnMask   = _FRAMESTATE_MASK_GEOMETRY | WINDOWSTATE_MASK_STATE;
    1801             : 
    1802           0 :     if (! maRestorePosSize.IsEmpty() )
    1803             :     {
    1804           0 :         GetPosSize( aPosSize );
    1805           0 :         pState->mnState |= WINDOWSTATE_STATE_MAXIMIZED;
    1806           0 :         pState->mnMaximizedX      = aPosSize.Left();
    1807           0 :         pState->mnMaximizedY      = aPosSize.Top();
    1808           0 :         pState->mnMaximizedWidth  = aPosSize.GetWidth();
    1809           0 :         pState->mnMaximizedHeight = aPosSize.GetHeight();
    1810           0 :         pState->mnMask |= _FRAMESTATE_MASK_MAXIMIZED_GEOMETRY;
    1811             :     }
    1812             : 
    1813           0 :     return true;
    1814             : }
    1815             : 
    1816             : // native menu implementation - currently empty
    1817           0 : void X11SalFrame::DrawMenuBar()
    1818             : {
    1819           0 : }
    1820             : 
    1821           0 : void X11SalFrame::SetMenu( SalMenu* )
    1822             : {
    1823           0 : }
    1824             : 
    1825           0 : void X11SalFrame::GetPosSize( Rectangle &rPosSize )
    1826             : {
    1827           0 :     if( maGeometry.nWidth < 1 || maGeometry.nHeight < 1 )
    1828             :     {
    1829           0 :         const Size& aScreenSize = pDisplay_->getDataForScreen( m_nXScreen ).m_aSize;
    1830           0 :         long w = aScreenSize.Width()  - maGeometry.nLeftDecoration - maGeometry.nRightDecoration;
    1831           0 :         long h = aScreenSize.Height() - maGeometry.nTopDecoration - maGeometry.nBottomDecoration;
    1832             : 
    1833           0 :         rPosSize = Rectangle( Point( maGeometry.nX, maGeometry.nY ), Size( w, h ) );
    1834             :     }
    1835             :     else
    1836             :         rPosSize = Rectangle( Point( maGeometry.nX, maGeometry.nY ),
    1837           0 :                               Size( maGeometry.nWidth, maGeometry.nHeight ) );
    1838           0 : }
    1839             : 
    1840           0 : void X11SalFrame::SetSize( const Size &rSize )
    1841             : {
    1842           0 :     if( rSize.Width() > 0 && rSize.Height() > 0 )
    1843             :     {
    1844           0 :          if( ! ( nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
    1845           0 :             && ! IsChildWindow()
    1846           0 :             && ( nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT )
    1847             :          {
    1848           0 :             XSizeHints* pHints = XAllocSizeHints();
    1849           0 :             long nSupplied = 0;
    1850             :             XGetWMNormalHints( GetXDisplay(),
    1851             :                                GetShellWindow(),
    1852             :                                pHints,
    1853             :                                &nSupplied
    1854           0 :                                );
    1855           0 :             pHints->min_width   = rSize.Width();
    1856           0 :             pHints->min_height  = rSize.Height();
    1857           0 :             pHints->max_width   = rSize.Width();
    1858           0 :             pHints->max_height  = rSize.Height();
    1859           0 :             pHints->flags |= PMinSize | PMaxSize;
    1860             :             XSetWMNormalHints( GetXDisplay(),
    1861             :                                GetShellWindow(),
    1862           0 :                                pHints );
    1863           0 :             XFree( pHints );
    1864             :          }
    1865           0 :         XResizeWindow( GetXDisplay(), IsSysChildWindow() ? GetWindow() : GetShellWindow(), rSize.Width(), rSize.Height() );
    1866           0 :         if( GetWindow() != GetShellWindow() )
    1867             :         {
    1868           0 :             if( (nStyle_ & SAL_FRAME_STYLE_PLUG ) )
    1869           0 :                 XMoveResizeWindow( GetXDisplay(), GetWindow(), 0, 0, rSize.Width(), rSize.Height() );
    1870             :             else
    1871           0 :                 XResizeWindow( GetXDisplay(), GetWindow(), rSize.Width(), rSize.Height() );
    1872             :         }
    1873             : 
    1874           0 :         maGeometry.nWidth  = rSize.Width();
    1875           0 :         maGeometry.nHeight = rSize.Height();
    1876             : 
    1877             :         // allow the external status window to reposition
    1878           0 :         if (mbInputFocus && mpInputContext != NULL)
    1879           0 :             mpInputContext->SetICFocus ( this );
    1880             :     }
    1881           0 : }
    1882             : 
    1883           0 : void X11SalFrame::SetPosSize( const Rectangle &rPosSize )
    1884             : {
    1885             :     XWindowChanges values;
    1886           0 :     values.x        = rPosSize.Left();
    1887           0 :     values.y        = rPosSize.Top();
    1888           0 :     values.width    = rPosSize.GetWidth();
    1889           0 :     values.height   = rPosSize.GetHeight();
    1890             : 
    1891           0 :     if( !values.width || !values.height )
    1892           0 :         return;
    1893             : 
    1894           0 :      if( mpParent && ! IsSysChildWindow() )
    1895             :      {
    1896             :         // --- RTL --- (mirror window pos)
    1897           0 :         if( Application::GetSettings().GetLayoutRTL() )
    1898           0 :             values.x = mpParent->maGeometry.nWidth-values.width-1-values.x;
    1899             : 
    1900             :          ::Window aChild;
    1901             :          // coordinates are relative to parent, so translate to root coordinates
    1902             :          XTranslateCoordinates( GetDisplay()->GetDisplay(),
    1903             :                                 mpParent->GetWindow(),
    1904             :                                 GetDisplay()->GetRootWindow( m_nXScreen ),
    1905             :                                 values.x, values.y,
    1906             :                                 &values.x, &values.y,
    1907           0 :                                 & aChild );
    1908             :      }
    1909             : 
    1910           0 :     bool bMoved = false;
    1911           0 :     bool bSized = false;
    1912           0 :     if( values.x != maGeometry.nX || values.y != maGeometry.nY )
    1913           0 :         bMoved = true;
    1914           0 :     if( values.width != (int)maGeometry.nWidth || values.height != (int)maGeometry.nHeight )
    1915           0 :         bSized = true;
    1916             : 
    1917           0 :     if( ! ( nStyle_ & ( SAL_FRAME_STYLE_PLUG | SAL_FRAME_STYLE_FLOAT ) )
    1918           0 :         && !(pDisplay_->GetProperties() & PROPERTY_SUPPORT_WM_ClientPos) )
    1919             :     {
    1920           0 :         values.x    -= maGeometry.nLeftDecoration;
    1921           0 :         values.y    -= maGeometry.nTopDecoration;
    1922             :     }
    1923             : 
    1924             :     // do net set WMNormalHints for ..
    1925           0 :     if(
    1926             :         // child windows
    1927           0 :         ! IsChildWindow()
    1928             :         // popups (menu, help window, etc.)
    1929           0 :         &&  (nStyle_ & (SAL_FRAME_STYLE_FLOAT|SAL_FRAME_STYLE_OWNERDRAWDECORATION) ) != SAL_FRAME_STYLE_FLOAT
    1930             :         // shown, sizeable windows
    1931           0 :         && ( nShowState_ == SHOWSTATE_UNKNOWN ||
    1932           0 :              nShowState_ == SHOWSTATE_HIDDEN ||
    1933           0 :              ! ( nStyle_ & SAL_FRAME_STYLE_SIZEABLE )
    1934             :              )
    1935             :         )
    1936             :     {
    1937           0 :         XSizeHints* pHints = XAllocSizeHints();
    1938           0 :         long nSupplied = 0;
    1939             :         XGetWMNormalHints( GetXDisplay(),
    1940             :                            GetShellWindow(),
    1941             :                            pHints,
    1942             :                            &nSupplied
    1943           0 :                            );
    1944           0 :         if( ! ( nStyle_ & SAL_FRAME_STYLE_SIZEABLE ) )
    1945             :         {
    1946           0 :             pHints->min_width   = rPosSize.GetWidth();
    1947           0 :             pHints->min_height  = rPosSize.GetHeight();
    1948           0 :             pHints->max_width   = rPosSize.GetWidth();
    1949           0 :             pHints->max_height  = rPosSize.GetHeight();
    1950           0 :             pHints->flags |= PMinSize | PMaxSize;
    1951             :         }
    1952           0 :         if( nShowState_ == SHOWSTATE_UNKNOWN || nShowState_ == SHOWSTATE_HIDDEN )
    1953             :         {
    1954           0 :             pHints->flags |= PPosition | PWinGravity;
    1955           0 :             pHints->x           = values.x;
    1956           0 :             pHints->y           = values.y;
    1957           0 :             pHints->win_gravity = pDisplay_->getWMAdaptor()->getPositionWinGravity();
    1958             :         }
    1959           0 :         if( mbFullScreen )
    1960             :         {
    1961           0 :             pHints->max_width   = 10000;
    1962           0 :             pHints->max_height  = 10000;
    1963           0 :             pHints->flags |= PMaxSize;
    1964             :         }
    1965             :         XSetWMNormalHints( GetXDisplay(),
    1966             :                            GetShellWindow(),
    1967           0 :                            pHints );
    1968           0 :         XFree( pHints );
    1969             :     }
    1970             : 
    1971           0 :     XMoveResizeWindow( GetXDisplay(), IsSysChildWindow() ? GetWindow() : GetShellWindow(), values.x, values.y, values.width, values.height );
    1972           0 :     if( GetShellWindow() != GetWindow() )
    1973             :     {
    1974           0 :         if( (nStyle_ & SAL_FRAME_STYLE_PLUG ) )
    1975           0 :             XMoveResizeWindow( GetXDisplay(), GetWindow(), 0, 0, values.width, values.height );
    1976             :         else
    1977           0 :             XMoveResizeWindow( GetXDisplay(), GetWindow(), values.x, values.y, values.width, values.height );
    1978             :     }
    1979             : 
    1980           0 :     maGeometry.nX       = values.x;
    1981           0 :     maGeometry.nY       = values.y;
    1982           0 :     maGeometry.nWidth   = values.width;
    1983           0 :     maGeometry.nHeight  = values.height;
    1984           0 :     if( IsSysChildWindow() && mpParent )
    1985             :     {
    1986             :         // translate back to root coordinates
    1987           0 :         maGeometry.nX += mpParent->maGeometry.nX;
    1988           0 :         maGeometry.nY += mpParent->maGeometry.nY;
    1989             :     }
    1990             : 
    1991           0 :     updateScreenNumber();
    1992           0 :     if( bSized && ! bMoved )
    1993           0 :         CallCallback( SALEVENT_RESIZE, NULL );
    1994           0 :     else if( bMoved && ! bSized )
    1995           0 :         CallCallback( SALEVENT_MOVE, NULL );
    1996             :     else
    1997           0 :         CallCallback( SALEVENT_MOVERESIZE, NULL );
    1998             : 
    1999             :     // allow the external status window to reposition
    2000           0 :     if (mbInputFocus && mpInputContext != NULL)
    2001           0 :         mpInputContext->SetICFocus ( this );
    2002             : }
    2003             : 
    2004           0 : void X11SalFrame::Minimize()
    2005             : {
    2006           0 :     if( IsSysChildWindow() )
    2007           0 :         return;
    2008             : 
    2009           0 :     if( SHOWSTATE_UNKNOWN == nShowState_ || SHOWSTATE_HIDDEN == nShowState_ )
    2010             :     {
    2011             :         stderr0( "X11SalFrame::Minimize on withdrawn window\n" );
    2012           0 :         return;
    2013             :     }
    2014             : 
    2015           0 :     if( XIconifyWindow( GetXDisplay(),
    2016             :                         GetShellWindow(),
    2017           0 :                         pDisplay_->GetDefaultXScreen().getXScreen() ) )
    2018           0 :         nShowState_ = SHOWSTATE_MINIMIZED;
    2019             : }
    2020             : 
    2021           0 : void X11SalFrame::Maximize()
    2022             : {
    2023           0 :     if( IsSysChildWindow() )
    2024           0 :         return;
    2025             : 
    2026           0 :     if( SHOWSTATE_MINIMIZED == nShowState_ )
    2027             :     {
    2028           0 :         GetDisplay()->getWMAdaptor()->frameIsMapping( this );
    2029           0 :         XMapWindow( GetXDisplay(), GetShellWindow() );
    2030           0 :         nShowState_ = SHOWSTATE_NORMAL;
    2031             :     }
    2032             : 
    2033           0 :     pDisplay_->getWMAdaptor()->maximizeFrame( this, true, true );
    2034             : }
    2035             : 
    2036           0 : void X11SalFrame::Restore()
    2037             : {
    2038           0 :     if( IsSysChildWindow() )
    2039           0 :         return;
    2040             : 
    2041           0 :     if( SHOWSTATE_UNKNOWN == nShowState_ || SHOWSTATE_HIDDEN == nShowState_ )
    2042             :     {
    2043             :         stderr0( "X11SalFrame::Restore on withdrawn window\n" );
    2044           0 :         return;
    2045             :     }
    2046             : 
    2047           0 :     if( SHOWSTATE_MINIMIZED == nShowState_ )
    2048             :     {
    2049           0 :         GetDisplay()->getWMAdaptor()->frameIsMapping( this );
    2050           0 :         XMapWindow( GetXDisplay(), GetShellWindow() );
    2051           0 :         nShowState_ = SHOWSTATE_NORMAL;
    2052             :     }
    2053             : 
    2054           0 :     pDisplay_->getWMAdaptor()->maximizeFrame( this, false, false );
    2055             : }
    2056             : 
    2057           0 : void X11SalFrame::SetScreenNumber( unsigned int nNewScreen )
    2058             : {
    2059           0 :     if( nNewScreen == maGeometry.nDisplayScreenNumber )
    2060           0 :         return;
    2061             : 
    2062           0 :     if( GetDisplay()->IsXinerama() && GetDisplay()->GetXineramaScreens().size() > 1 )
    2063             :     {
    2064           0 :         if( nNewScreen >= GetDisplay()->GetXineramaScreens().size() )
    2065           0 :             return;
    2066             : 
    2067           0 :         Rectangle aOldScreenRect( GetDisplay()->GetXineramaScreens()[maGeometry.nDisplayScreenNumber] );
    2068           0 :         Rectangle aNewScreenRect( GetDisplay()->GetXineramaScreens()[nNewScreen] );
    2069           0 :         bool bVisible = bMapped_;
    2070           0 :         if( bVisible )
    2071           0 :             Show( false );
    2072           0 :         maGeometry.nX = aNewScreenRect.Left() + (maGeometry.nX - aOldScreenRect.Left());
    2073           0 :         maGeometry.nY = aNewScreenRect.Top() + (maGeometry.nY - aOldScreenRect.Top());
    2074           0 :         createNewWindow( None, m_nXScreen );
    2075           0 :         if( bVisible )
    2076           0 :             Show( true );
    2077           0 :         maGeometry.nDisplayScreenNumber = nNewScreen;
    2078             :     }
    2079           0 :     else if( nNewScreen < GetDisplay()->GetXScreenCount() )
    2080             :     {
    2081           0 :         bool bVisible = bMapped_;
    2082           0 :         if( bVisible )
    2083           0 :             Show( false );
    2084           0 :         createNewWindow( None, SalX11Screen( nNewScreen ) );
    2085           0 :         if( bVisible )
    2086           0 :             Show( true );
    2087           0 :         maGeometry.nDisplayScreenNumber = nNewScreen;
    2088             :     }
    2089             : }
    2090             : 
    2091           0 : void X11SalFrame::SetApplicationID( const OUString &rWMClass )
    2092             : {
    2093           0 :     if( rWMClass != m_sWMClass && ! IsChildWindow() )
    2094             :     {
    2095           0 :         m_sWMClass = rWMClass;
    2096           0 :         updateWMClass();
    2097           0 :         std::list< X11SalFrame* >::const_iterator it;
    2098           0 :         for( it = maChildren.begin(); it != maChildren.end(); ++it )
    2099           0 :             (*it)->SetApplicationID(rWMClass);
    2100             :     }
    2101           0 : }
    2102             : 
    2103           0 : void X11SalFrame::updateWMClass()
    2104             : {
    2105           0 :     XClassHint* pClass = XAllocClassHint();
    2106           0 :     OString aResName = SalGenericSystem::getFrameResName();
    2107           0 :     pClass->res_name  = const_cast<char*>(aResName.getStr());
    2108             : 
    2109           0 :     OString aResClass = OUStringToOString(m_sWMClass, RTL_TEXTENCODING_ASCII_US);
    2110           0 :     const char *pResClass = !aResClass.isEmpty() ? aResClass.getStr() :
    2111           0 :                             SalGenericSystem::getFrameClassName();
    2112             : 
    2113           0 :     pClass->res_class = const_cast<char*>(pResClass);
    2114           0 :     XSetClassHint( GetXDisplay(), GetShellWindow(), pClass );
    2115           0 :     XFree( pClass );
    2116           0 : }
    2117             : 
    2118           0 : void X11SalFrame::ShowFullScreen( bool bFullScreen, sal_Int32 nScreen )
    2119             : {
    2120           0 :     if( GetDisplay()->IsXinerama() && GetDisplay()->GetXineramaScreens().size() > 1 )
    2121             :     {
    2122           0 :         if( mbFullScreen == (bool)bFullScreen )
    2123           0 :             return;
    2124           0 :         if( bFullScreen )
    2125             :         {
    2126             :             maRestorePosSize = Rectangle( Point( maGeometry.nX, maGeometry.nY ),
    2127           0 :                                           Size( maGeometry.nWidth, maGeometry.nHeight ) );
    2128           0 :             Rectangle aRect;
    2129           0 :             if( nScreen < 0 || nScreen >= static_cast<int>(GetDisplay()->GetXineramaScreens().size()) )
    2130           0 :                 aRect = Rectangle( Point(0,0), GetDisplay()->GetScreenSize( m_nXScreen ) );
    2131             :             else
    2132           0 :                 aRect = GetDisplay()->GetXineramaScreens()[nScreen];
    2133           0 :             nStyle_ |= SAL_FRAME_STYLE_PARTIAL_FULLSCREEN;
    2134           0 :             bool bVisible = bMapped_;
    2135           0 :             if( bVisible )
    2136           0 :                 Show( false );
    2137           0 :             maGeometry.nX = aRect.Left();
    2138           0 :             maGeometry.nY = aRect.Top();
    2139           0 :             maGeometry.nWidth = aRect.GetWidth();
    2140           0 :             maGeometry.nHeight = aRect.GetHeight();
    2141           0 :             mbMaximizedHorz = mbMaximizedVert = false;
    2142           0 :             mbFullScreen = true;
    2143           0 :             createNewWindow( None, m_nXScreen );
    2144           0 :             if( GetDisplay()->getWMAdaptor()->isLegacyPartialFullscreen() )
    2145           0 :                 GetDisplay()->getWMAdaptor()->enableAlwaysOnTop( this, true );
    2146             :             else
    2147           0 :                 GetDisplay()->getWMAdaptor()->showFullScreen( this, true );
    2148           0 :             if( bVisible )
    2149           0 :                 Show(true);
    2150             : 
    2151             :         }
    2152             :         else
    2153             :         {
    2154           0 :             mbFullScreen = false;
    2155           0 :             nStyle_ &= ~SAL_FRAME_STYLE_PARTIAL_FULLSCREEN;
    2156           0 :             bool bVisible = bMapped_;
    2157           0 :             Rectangle aRect = maRestorePosSize;
    2158           0 :             maRestorePosSize = Rectangle();
    2159           0 :             if( bVisible )
    2160           0 :                 Show( false );
    2161           0 :             createNewWindow( None, m_nXScreen );
    2162           0 :             if( !aRect.IsEmpty() )
    2163           0 :                 SetPosSize( aRect.Left(), aRect.Top(), aRect.GetWidth(), aRect.GetHeight(),
    2164             :                             SAL_FRAME_POSSIZE_X | SAL_FRAME_POSSIZE_Y |
    2165           0 :                             SAL_FRAME_POSSIZE_WIDTH | SAL_FRAME_POSSIZE_HEIGHT );
    2166           0 :             if( bVisible )
    2167           0 :                 Show( true );
    2168             :         }
    2169             :     }
    2170             :     else
    2171             :     {
    2172           0 :         if( nScreen < 0 || nScreen >= (int)GetDisplay()->GetXScreenCount() )
    2173           0 :             nScreen = m_nXScreen.getXScreen();
    2174           0 :         if( nScreen != (int)m_nXScreen.getXScreen() )
    2175             :         {
    2176           0 :             bool bVisible = bMapped_;
    2177           0 :             if( mbFullScreen )
    2178           0 :                 pDisplay_->getWMAdaptor()->showFullScreen( this, false );
    2179           0 :             if( bVisible )
    2180           0 :                 Show( false );
    2181           0 :             createNewWindow( None, SalX11Screen( nScreen ) );
    2182           0 :             if( mbFullScreen )
    2183           0 :                 pDisplay_->getWMAdaptor()->showFullScreen( this, true );
    2184           0 :             if( bVisible )
    2185           0 :                 Show( true );
    2186             :         }
    2187           0 :         if( mbFullScreen == (bool)bFullScreen )
    2188           0 :             return;
    2189             : 
    2190           0 :         pDisplay_->getWMAdaptor()->showFullScreen( this, bFullScreen );
    2191           0 :         if( IsOverrideRedirect()
    2192           0 :             && WMSupportsFWS( GetXDisplay(), GetDisplay()->GetRootWindow( m_nXScreen ) ) )
    2193             :         {
    2194           0 :             AddFwsProtocols( GetXDisplay(), GetShellWindow() );
    2195           0 :             RegisterFwsWindow( GetXDisplay(), GetShellWindow() );
    2196             :         }
    2197             :     }
    2198             : }
    2199             : 
    2200             : /* ---------------------------------------------------------------------
    2201             :    the xautolock pseudo screen saver needs special treatment since it
    2202             :    doesn't cooperate with XxxxScreenSaver settings
    2203             :    ------------------------------------------------------------------- */
    2204             : 
    2205             : static Bool
    2206           0 : IsRunningXAutoLock( Display *p_display, ::Window a_window )
    2207             : {
    2208           0 :     const char *p_atomname = "XAUTOLOCK_SEMAPHORE_PID";
    2209             :     Atom        a_pidatom;
    2210             : 
    2211             :     // xautolock interns this atom
    2212           0 :     a_pidatom    = XInternAtom( p_display, p_atomname, True );
    2213           0 :     if ( a_pidatom == None )
    2214           0 :         return False;
    2215             : 
    2216             :     Atom          a_type;
    2217             :     int           n_format;
    2218             :     unsigned long n_items;
    2219             :     unsigned long n_bytes_after;
    2220             :     pid_t        *p_pid;
    2221             :     pid_t         n_pid;
    2222             :     // get pid of running xautolock
    2223             :     XGetWindowProperty (p_display, a_window, a_pidatom, 0L, 2L, False,
    2224             :             AnyPropertyType, &a_type, &n_format, &n_items, &n_bytes_after,
    2225           0 :             (unsigned char**) &p_pid );
    2226           0 :     n_pid = *p_pid;
    2227           0 :     XFree( p_pid );
    2228             : 
    2229           0 :       if ( a_type == XA_INTEGER )
    2230             :       {
    2231             :         // check if xautolock pid points to a running process
    2232           0 :         if ( kill(n_pid, 0) == -1 )
    2233           0 :             return False;
    2234             :         else
    2235           0 :             return True;
    2236             :     }
    2237             : 
    2238           0 :     return False;
    2239             : }
    2240             : 
    2241             : /* definitions from xautolock.c (pl15) */
    2242             : #define XAUTOLOCK_DISABLE 1
    2243             : #define XAUTOLOCK_ENABLE  2
    2244             : 
    2245             : static Bool
    2246           0 : MessageToXAutoLock( Display *p_display, int n_message )
    2247             : {
    2248           0 :     const char *p_atomname = "XAUTOLOCK_MESSAGE" ;
    2249             :     Atom        a_messageatom;
    2250             :     ::Window    a_rootwindow;
    2251             : 
    2252           0 :     a_rootwindow = RootWindowOfScreen( ScreenOfDisplay(p_display, 0) );
    2253           0 :     if ( ! IsRunningXAutoLock(p_display, a_rootwindow) )
    2254             :     {
    2255             :         // remove any pending messages
    2256           0 :         a_messageatom = XInternAtom( p_display, p_atomname, True );
    2257           0 :         if ( a_messageatom != None )
    2258           0 :             XDeleteProperty( p_display, a_rootwindow, a_messageatom );
    2259           0 :         return False;
    2260             :     }
    2261             : 
    2262           0 :     a_messageatom = XInternAtom( p_display, p_atomname, False );
    2263             :     XChangeProperty (p_display, a_rootwindow, a_messageatom, XA_INTEGER,
    2264           0 :             8, PropModeReplace, (unsigned char*)&n_message, sizeof(n_message) );
    2265             : 
    2266           0 :     return True;
    2267             : }
    2268             : 
    2269           0 : void X11SalFrame::StartPresentation( bool bStart )
    2270             : {
    2271           0 :     vcl::I18NStatus::get().show( !bStart, vcl::I18NStatus::presentation );
    2272           0 :     if ( bStart )
    2273           0 :         MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_DISABLE );
    2274             :     else
    2275           0 :         MessageToXAutoLock( GetXDisplay(), XAUTOLOCK_ENABLE );
    2276             : 
    2277           0 :     if( ! bStart && hPresentationWindow != None )
    2278           0 :         doReparentPresentationDialogues( GetDisplay() );
    2279           0 :     hPresentationWindow = (bStart && IsOverrideRedirect() ) ? GetWindow() : None;
    2280             : 
    2281             :     // needs static here to save DPMS settings
    2282             :     int dummy;
    2283             :     static bool DPMSExtensionAvailable =
    2284             : #if !defined(SOLARIS) && !defined(AIX)
    2285           0 :         (DPMSQueryExtension(GetXDisplay(), &dummy, &dummy) != 0);
    2286             :     static sal_Bool DPMSEnabled = false;
    2287             : #else
    2288             :         false;
    2289             :     bool DPMSEnabled = false;
    2290             :     (void)dummy;
    2291             : #define CARD16 unsigned short
    2292             : #endif
    2293             :     static CARD16 dpms_standby_timeout=0;
    2294             :     static CARD16 dpms_suspend_timeout=0;
    2295             :     static CARD16 dpms_off_timeout=0;
    2296             : 
    2297           0 :     if( bStart || nScreenSaversTimeout_ || DPMSEnabled)
    2298             :     {
    2299           0 :         if( hPresentationWindow )
    2300             :         {
    2301             :             /*  #i10559# workaround for WindowMaker: try to restore
    2302             :              *  current focus after presentation window is gone
    2303             :              */
    2304           0 :             int revert_to = 0;
    2305           0 :             XGetInputFocus( GetXDisplay(), &hPresFocusWindow, &revert_to );
    2306             :         }
    2307             :         int timeout, interval, prefer_blanking, allow_exposures;
    2308             :         XGetScreenSaver( GetXDisplay(),
    2309             :                          &timeout,
    2310             :                          &interval,
    2311             :                          &prefer_blanking,
    2312           0 :                          &allow_exposures );
    2313             : 
    2314             :         // get the DPMS state right before the start
    2315           0 :         if (DPMSExtensionAvailable)
    2316             :         {
    2317             : #if !defined(SOLARIS) && !defined(AIX)
    2318             :             CARD16 state; // card16 is defined in Xdm.h
    2319             :             DPMSInfo(   GetXDisplay(),
    2320             :                         &state,
    2321           0 :                         &DPMSEnabled);
    2322             : #endif
    2323             :         }
    2324           0 :         if( bStart ) // start show
    2325             :         {
    2326           0 :             if ( timeout )
    2327             :             {
    2328           0 :                 nScreenSaversTimeout_ = timeout;
    2329           0 :                 XResetScreenSaver( GetXDisplay() );
    2330             :                 XSetScreenSaver( GetXDisplay(),
    2331             :                                  0,
    2332             :                                  interval,
    2333             :                                  prefer_blanking,
    2334           0 :                                  allow_exposures );
    2335             :             }
    2336             : #if !defined(SOLARIS) && !defined(AIX)
    2337           0 :             if( DPMSEnabled )
    2338             :             {
    2339           0 :                 if ( DPMSExtensionAvailable )
    2340             :                 {
    2341             :                     DPMSGetTimeouts(    GetXDisplay(),
    2342             :                                         &dpms_standby_timeout,
    2343             :                                         &dpms_suspend_timeout,
    2344           0 :                                         &dpms_off_timeout);
    2345           0 :                     DPMSSetTimeouts(GetXDisplay(), 0,0,0);
    2346             :                 }
    2347             :             }
    2348             : #endif
    2349             :         }
    2350             :         else
    2351             :         {
    2352           0 :             if( nScreenSaversTimeout_ )
    2353             :             {
    2354             :                 XSetScreenSaver( GetXDisplay(),
    2355             :                              nScreenSaversTimeout_,
    2356             :                              interval,
    2357             :                              prefer_blanking,
    2358           0 :                              allow_exposures );
    2359           0 :                 nScreenSaversTimeout_ = 0;
    2360             :             }
    2361             : #if !defined(SOLARIS) && !defined(AIX)
    2362           0 :             if ( DPMSEnabled )
    2363             :             {
    2364           0 :                 if ( DPMSExtensionAvailable )
    2365             :                 {
    2366             :                 // restore timeouts
    2367             :                     DPMSSetTimeouts(GetXDisplay(), dpms_standby_timeout,
    2368           0 :                         dpms_suspend_timeout, dpms_off_timeout);
    2369             :                 }
    2370             :             }
    2371             : #endif
    2372             :         }
    2373             :     }
    2374           0 : }
    2375             : 
    2376             : // Pointer
    2377             : 
    2378           0 : void X11SalFrame::SetPointer( PointerStyle ePointerStyle )
    2379             : {
    2380           0 :     hCursor_ = pDisplay_->GetPointer( ePointerStyle );
    2381           0 :     XDefineCursor( GetXDisplay(), GetWindow(), hCursor_ );
    2382             : 
    2383           0 :     if( IsCaptured() || nVisibleFloats > 0 )
    2384             :         XChangeActivePointerGrab( GetXDisplay(),
    2385             :                         PointerMotionMask|ButtonPressMask|ButtonReleaseMask,
    2386             :                         hCursor_,
    2387           0 :                         CurrentTime );
    2388           0 : }
    2389             : 
    2390           0 : void X11SalFrame::SetPointerPos(long nX, long nY)
    2391             : {
    2392             :     /* when the application tries to center the mouse in the dialog the
    2393             :      * window isn't mapped already. So use coordinates relative to the root window.
    2394             :      */
    2395           0 :     unsigned int nWindowLeft = maGeometry.nX + nX;
    2396           0 :     unsigned int nWindowTop  = maGeometry.nY + nY;
    2397             : 
    2398             :     XWarpPointer( GetXDisplay(), None, pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() ),
    2399           0 :                   0, 0, 0, 0, nWindowLeft, nWindowTop);
    2400           0 : }
    2401             : 
    2402             : // delay handling of extended text input
    2403             : #if !defined(__synchronous_extinput__)
    2404             : void
    2405           0 : X11SalFrame::HandleExtTextEvent (XClientMessageEvent *pEvent)
    2406             : {
    2407             :     #if SAL_TYPES_SIZEOFLONG > 4
    2408           0 :     void* pExtTextEvent = reinterpret_cast<void*>(  (pEvent->data.l[0] & 0xffffffff)
    2409           0 :                                                   | (pEvent->data.l[1] << 32) );
    2410             :     #else
    2411             :     void* pExtTextEvent = reinterpret_cast<void*>(pEvent->data.l[0]);
    2412             :     #endif
    2413           0 :     sal_uInt16 nExtTextEventType = sal_uInt16(pEvent->data.l[2]);
    2414             : 
    2415           0 :     CallCallback(nExtTextEventType, pExtTextEvent);
    2416             : 
    2417           0 :     switch (nExtTextEventType)
    2418             :     {
    2419             :         case SALEVENT_ENDEXTTEXTINPUT:
    2420           0 :             break;
    2421             : 
    2422             :         case SALEVENT_EXTTEXTINPUT:
    2423           0 :             break;
    2424             : 
    2425             :         default:
    2426             : 
    2427           0 :             fprintf(stderr, "X11SalFrame::HandleExtTextEvent: invalid extended input\n");
    2428             :     }
    2429           0 : }
    2430             : #endif /* defined(__synchronous_extinput__) */
    2431             : 
    2432             : // PostEvent
    2433             : 
    2434           0 : bool X11SalFrame::PostEvent( void *pData )
    2435             : {
    2436           0 :     GetDisplay()->SendInternalEvent( this, pData );
    2437           0 :     return true;
    2438             : }
    2439             : 
    2440             : // Title
    2441             : 
    2442           0 : void X11SalFrame::SetTitle( const OUString& rTitle )
    2443             : {
    2444           0 :     if( ! ( IsChildWindow() || (nStyle_ & SAL_FRAME_STYLE_FLOAT ) ) )
    2445             :     {
    2446           0 :         m_aTitle = rTitle;
    2447           0 :         GetDisplay()->getWMAdaptor()->setWMName( this, rTitle );
    2448             :     }
    2449           0 : }
    2450             : 
    2451           0 : void X11SalFrame::Flush()
    2452             : {
    2453           0 :     XFlush( GetDisplay()->GetDisplay() );
    2454           0 : }
    2455             : 
    2456           0 : void X11SalFrame::Sync()
    2457             : {
    2458           0 :     XSync( GetDisplay()->GetDisplay(), False );
    2459           0 : }
    2460             : 
    2461             : // Keyboard
    2462             : 
    2463           0 : void X11SalFrame::SetInputContext( SalInputContext* pContext )
    2464             : {
    2465           0 :       if (pContext == NULL)
    2466           0 :         return;
    2467             : 
    2468             :       // 1. We should create an input context for this frame
    2469             :       //    only when SAL_INPUTCONTEXT_TEXT is set.
    2470             : 
    2471           0 :       if (!(pContext->mnOptions & SAL_INPUTCONTEXT_TEXT))
    2472             :     {
    2473           0 :         if( mpInputContext )
    2474           0 :             mpInputContext->Unmap( this );
    2475           0 :         return;
    2476             :     }
    2477             : 
    2478             :     // 2. We should use on-the-spot inputstyle
    2479             :       //    only when SAL_INPUTCONTEXT_EXTTEXTINPUT is set.
    2480             : 
    2481           0 :       if (mpInputContext == NULL)
    2482             :     {
    2483           0 :         vcl::I18NStatus& rStatus( vcl::I18NStatus::get() );
    2484           0 :         rStatus.setParent( this );
    2485           0 :         mpInputContext = new SalI18N_InputContext( this );
    2486           0 :         if (mpInputContext->UseContext())
    2487             :         {
    2488           0 :               mpInputContext->ExtendEventMask( GetShellWindow() );
    2489           0 :               if (pContext->mnOptions & SAL_INPUTCONTEXT_CHANGELANGUAGE)
    2490           0 :                 mpInputContext->SetLanguage(pContext->meLanguage);
    2491           0 :             if (mbInputFocus)
    2492           0 :                 mpInputContext->SetICFocus( this );
    2493             :         }
    2494             :       }
    2495             :     else
    2496           0 :         mpInputContext->Map( this );
    2497           0 :       return;
    2498             : }
    2499             : 
    2500           0 : void X11SalFrame::EndExtTextInput( sal_uInt16 nFlags )
    2501             : {
    2502           0 :     if (mpInputContext != NULL)
    2503           0 :           mpInputContext->EndExtTextInput( nFlags );
    2504           0 : }
    2505             : 
    2506           0 : OUString X11SalFrame::GetKeyName( sal_uInt16 nKeyCode )
    2507             : {
    2508           0 :     return GetDisplay()->GetKeyName( nKeyCode );
    2509             : }
    2510             : 
    2511           0 : bool X11SalFrame::MapUnicodeToKeyCode( sal_Unicode , LanguageType , vcl::KeyCode& )
    2512             : {
    2513             :     // not supported yet
    2514           0 :     return false;
    2515             : }
    2516             : 
    2517           0 : LanguageType X11SalFrame::GetInputLanguage()
    2518             : {
    2519             :     // could be improved by checking unicode ranges of the last input
    2520           0 :     return LANGUAGE_DONTKNOW;
    2521             : }
    2522             : 
    2523             : // Settings
    2524             : 
    2525           0 : void X11SalFrame::UpdateSettings( AllSettings& rSettings )
    2526             : {
    2527           0 :     StyleSettings aStyleSettings = rSettings.GetStyleSettings();
    2528           0 :     aStyleSettings.SetCursorBlinkTime( 500 );
    2529           0 :     aStyleSettings.SetMenuBarTextColor( aStyleSettings.GetPersonaMenuBarTextColor().get_value_or( Color( COL_BLACK ) ) );
    2530           0 :     rSettings.SetStyleSettings( aStyleSettings );
    2531           0 : }
    2532             : 
    2533           0 : void X11SalFrame::CaptureMouse( bool bCapture )
    2534             : {
    2535           0 :     nCaptured_ = pDisplay_->CaptureMouse( bCapture ? this : NULL );
    2536           0 : }
    2537             : 
    2538           0 : void X11SalFrame::SetParent( SalFrame* pNewParent )
    2539             : {
    2540           0 :     if( mpParent != pNewParent )
    2541             :     {
    2542           0 :         if( mpParent )
    2543           0 :             mpParent->maChildren.remove( this );
    2544             : 
    2545           0 :         mpParent = static_cast<X11SalFrame*>(pNewParent);
    2546           0 :         mpParent->maChildren.push_back( this );
    2547           0 :         if( mpParent->m_nXScreen != m_nXScreen )
    2548           0 :             createNewWindow( None, mpParent->m_nXScreen );
    2549           0 :         GetDisplay()->getWMAdaptor()->changeReferenceFrame( this, mpParent );
    2550             :     }
    2551           0 : }
    2552             : 
    2553           0 : SalFrame* X11SalFrame::GetParent() const
    2554             : {
    2555           0 :     return mpParent;
    2556             : }
    2557             : 
    2558           0 : void X11SalFrame::createNewWindow( ::Window aNewParent, SalX11Screen nXScreen )
    2559             : {
    2560           0 :     bool bWasVisible = bMapped_;
    2561           0 :     if( bWasVisible )
    2562           0 :         Show( false );
    2563             : 
    2564           0 :     if( nXScreen.getXScreen() >= GetDisplay()->GetXScreenCount() )
    2565           0 :         nXScreen = m_nXScreen;
    2566             : 
    2567             :     SystemParentData aParentData;
    2568           0 :     aParentData.aWindow = aNewParent;
    2569           0 :     aParentData.bXEmbedSupport = (aNewParent != None && m_bXEmbed); // caution: this is guesswork
    2570           0 :     if( aNewParent == None )
    2571             :     {
    2572           0 :         aNewParent = GetDisplay()->GetRootWindow(nXScreen);
    2573           0 :         aParentData.aWindow = None;
    2574           0 :         m_bXEmbed = false;
    2575             :     }
    2576             :     else
    2577             :     {
    2578             :         // is new parent a root window ?
    2579           0 :         Display* pDisp = GetDisplay()->GetDisplay();
    2580           0 :         int nScreens = GetDisplay()->GetXScreenCount();
    2581           0 :         for( int i = 0; i < nScreens; i++ )
    2582             :         {
    2583           0 :             if( aNewParent == RootWindow( pDisp, i ) )
    2584             :             {
    2585           0 :                 nXScreen = SalX11Screen( i );
    2586           0 :                 aParentData.aWindow = None;
    2587           0 :                 m_bXEmbed = false;
    2588           0 :                 break;
    2589             :             }
    2590             :         }
    2591             :     }
    2592             : 
    2593             :     // first deinit frame
    2594           0 :     updateGraphics(true);
    2595           0 :     if( mpInputContext )
    2596             :     {
    2597           0 :         mpInputContext->UnsetICFocus( this );
    2598           0 :         mpInputContext->Unmap( this );
    2599             :     }
    2600           0 :     if( GetWindow() == hPresentationWindow )
    2601             :     {
    2602           0 :         hPresentationWindow = None;
    2603           0 :         doReparentPresentationDialogues( GetDisplay() );
    2604             :     }
    2605           0 :     XDestroyWindow( GetXDisplay(), mhWindow );
    2606           0 :     mhWindow = None;
    2607             : 
    2608             :     // now init with new parent again
    2609           0 :     if ( aParentData.aWindow != None )
    2610           0 :         Init( nStyle_ | SAL_FRAME_STYLE_PLUG, nXScreen, &aParentData );
    2611             :     else
    2612           0 :         Init( nStyle_ & ~SAL_FRAME_STYLE_PLUG, nXScreen, NULL, true );
    2613             : 
    2614             :     // update graphics if necessary
    2615           0 :     updateGraphics(false);
    2616             : 
    2617           0 :     if( ! m_aTitle.isEmpty() )
    2618           0 :         SetTitle( m_aTitle );
    2619             : 
    2620           0 :     if( mpParent )
    2621             :     {
    2622           0 :         if( mpParent->m_nXScreen != m_nXScreen )
    2623           0 :             SetParent( NULL );
    2624             :         else
    2625           0 :             pDisplay_->getWMAdaptor()->changeReferenceFrame( this, mpParent );
    2626             :     }
    2627             : 
    2628           0 :     if( bWasVisible )
    2629           0 :         Show( true );
    2630             : 
    2631           0 :     std::list< X11SalFrame* > aChildren = maChildren;
    2632           0 :     for( std::list< X11SalFrame* >::iterator it = aChildren.begin(); it != aChildren.end(); ++it )
    2633           0 :         (*it)->createNewWindow( None, m_nXScreen );
    2634             : 
    2635             :     // FIXME: SalObjects
    2636           0 : }
    2637             : 
    2638           0 : bool X11SalFrame::SetPluginParent( SystemParentData* pNewParent )
    2639             : {
    2640           0 :     if( pNewParent->nSize >= sizeof(SystemParentData) )
    2641           0 :         m_bXEmbed = pNewParent->aWindow != None && pNewParent->bXEmbedSupport;
    2642             : 
    2643           0 :     createNewWindow(pNewParent->aWindow);
    2644             : 
    2645           0 :     return true;
    2646             : }
    2647             : 
    2648             : // Sound
    2649           0 : void X11SalFrame::Beep()
    2650             : {
    2651           0 :     GetDisplay()->Beep();
    2652           0 : }
    2653             : 
    2654             : // Event Handling
    2655             : 
    2656           0 : static sal_uInt16 sal_GetCode( int state )
    2657             : {
    2658           0 :     sal_uInt16 nCode = 0;
    2659             : 
    2660           0 :     if( state & Button1Mask )
    2661           0 :         nCode |= MOUSE_LEFT;
    2662           0 :     if( state & Button2Mask )
    2663           0 :         nCode |= MOUSE_MIDDLE;
    2664           0 :     if( state & Button3Mask )
    2665           0 :         nCode |= MOUSE_RIGHT;
    2666             : 
    2667           0 :     if( state & ShiftMask )
    2668           0 :         nCode |= KEY_SHIFT;
    2669           0 :     if( state & ControlMask )
    2670           0 :         nCode |= KEY_MOD1;
    2671           0 :     if( state & Mod1Mask )
    2672           0 :         nCode |= KEY_MOD2;
    2673             : 
    2674             :     // Map Meta/Super modifier to MOD3 on all Unix systems
    2675             :     // except Mac OS X
    2676           0 :     if( (state & Mod3Mask) )
    2677           0 :         nCode |= KEY_MOD3;
    2678             : 
    2679           0 :     return nCode;
    2680             : }
    2681             : 
    2682           0 : SalFrame::SalPointerState X11SalFrame::GetPointerState()
    2683             : {
    2684           0 :     SalPointerState aState;
    2685             :     ::Window aRoot, aChild;
    2686             :     int rx, ry, wx, wy;
    2687           0 :     unsigned int nMask = 0;
    2688             :     XQueryPointer( GetXDisplay(),
    2689             :                    GetShellWindow(),
    2690             :                    &aRoot,
    2691             :                    &aChild,
    2692             :                    &rx, &ry,
    2693             :                    &wx, &wy,
    2694             :                    &nMask
    2695           0 :                    );
    2696             : 
    2697           0 :     aState.maPos = Point(wx, wy);
    2698           0 :     aState.mnState = sal_GetCode( nMask );
    2699           0 :     return aState;
    2700             : }
    2701             : 
    2702           0 : SalFrame::SalIndicatorState X11SalFrame::GetIndicatorState()
    2703             : {
    2704             :     SalIndicatorState aState;
    2705           0 :     aState.mnState = GetGenericData()->GetSalDisplay()->GetIndicatorState();
    2706           0 :     return aState;
    2707             : }
    2708             : 
    2709           0 : void X11SalFrame::SimulateKeyPress( sal_uInt16 nKeyCode )
    2710             : {
    2711           0 :     GetGenericData()->GetSalDisplay()->SimulateKeyPress(nKeyCode);
    2712           0 : }
    2713             : 
    2714           0 : long X11SalFrame::HandleMouseEvent( XEvent *pEvent )
    2715             : {
    2716           0 :     SalMouseEvent       aMouseEvt = {0, 0, 0, 0, 0};
    2717           0 :     sal_uInt16              nEvent = 0;
    2718           0 :     bool                bClosePopups = false;
    2719             : 
    2720           0 :     if( nVisibleFloats && pEvent->type == EnterNotify )
    2721           0 :         return 0;
    2722             : 
    2723             :     // Solaris X86: clicking the right button on a two-button mouse
    2724             :     // generates a button2 event not a button3 event
    2725           0 :     if (pDisplay_->GetProperties() & PROPERTY_SUPPORT_3ButtonMouse )
    2726             :     {
    2727           0 :         switch (pEvent->type)
    2728             :         {
    2729             :             case EnterNotify:
    2730             :             case LeaveNotify:
    2731           0 :                 if ( pEvent->xcrossing.state & Button2Mask )
    2732             :                 {
    2733           0 :                     pEvent->xcrossing.state &= ~Button2Mask;
    2734           0 :                     pEvent->xcrossing.state |=  Button3Mask;
    2735             :                 }
    2736           0 :                 break;
    2737             : 
    2738             :             case MotionNotify:
    2739           0 :                 if ( pEvent->xmotion.state & Button2Mask )
    2740             :                 {
    2741           0 :                     pEvent->xmotion.state &= ~Button2Mask;
    2742           0 :                     pEvent->xmotion.state |=  Button3Mask;
    2743             :                 }
    2744           0 :                 break;
    2745             : 
    2746             :             default:
    2747           0 :                 if ( Button2 == pEvent->xbutton.button )
    2748             :                 {
    2749           0 :                     pEvent->xbutton.state &= ~Button2Mask;
    2750           0 :                     pEvent->xbutton.state |=  Button3Mask;
    2751           0 :                     pEvent->xbutton.button =  Button3;
    2752             :                 }
    2753           0 :                 break;
    2754             :         }
    2755             :     }
    2756             : 
    2757           0 :     if( LeaveNotify == pEvent->type || EnterNotify == pEvent->type )
    2758             :     {
    2759             :         /*
    2760             :          *  some WMs (and/or) applications  have a passive grab on
    2761             :          *  mouse buttons (XGrabButton). This leads to enter/leave notifies
    2762             :          *  with mouse buttons pressed in the state mask before the actual
    2763             :          *  ButtonPress event gets dispatched. But EnterNotify
    2764             :          *  is reported in vcl as MouseMove event. Some office code
    2765             :          *  decides that a pressed button in a MouseMove belongs to
    2766             :          *  a drag operation which leads to doing things differently.
    2767             :          *
    2768             :          *  ignore Enter/LeaveNotify resulting from grabs so that
    2769             :          *  help windows do not disappear just after appearing
    2770             :          *
    2771             :          *  hopefully this workaround will not break anything.
    2772             :          */
    2773           0 :         if( pEvent->xcrossing.mode == NotifyGrab || pEvent->xcrossing.mode == NotifyUngrab  )
    2774           0 :             return 0;
    2775             : 
    2776           0 :         aMouseEvt.mnX       = pEvent->xcrossing.x;
    2777           0 :         aMouseEvt.mnY       = pEvent->xcrossing.y;
    2778           0 :         aMouseEvt.mnTime    = pEvent->xcrossing.time;
    2779           0 :         aMouseEvt.mnCode    = sal_GetCode( pEvent->xcrossing.state );
    2780           0 :         aMouseEvt.mnButton  = 0;
    2781             : 
    2782           0 :         nEvent              = LeaveNotify == pEvent->type
    2783             :                               ? SALEVENT_MOUSELEAVE
    2784           0 :                               : SALEVENT_MOUSEMOVE;
    2785             :     }
    2786           0 :     else if( pEvent->type == MotionNotify )
    2787             :     {
    2788           0 :         aMouseEvt.mnX       = pEvent->xmotion.x;
    2789           0 :         aMouseEvt.mnY       = pEvent->xmotion.y;
    2790           0 :         aMouseEvt.mnTime    = pEvent->xmotion.time;
    2791           0 :         aMouseEvt.mnCode    = sal_GetCode( pEvent->xmotion.state );
    2792             : 
    2793           0 :         aMouseEvt.mnButton  = 0;
    2794             : 
    2795           0 :         nEvent              = SALEVENT_MOUSEMOVE;
    2796           0 :         if( nVisibleFloats > 0 && mpParent )
    2797             :         {
    2798           0 :             Cursor aCursor = mpParent->GetCursor();
    2799           0 :             if( pEvent->xmotion.x >= 0 && pEvent->xmotion.x < (int)maGeometry.nWidth &&
    2800           0 :                 pEvent->xmotion.y >= 0 && pEvent->xmotion.y < (int)maGeometry.nHeight )
    2801           0 :                 aCursor = None;
    2802             : 
    2803             :             XChangeActivePointerGrab( GetXDisplay(),
    2804             :                                       PointerMotionMask|ButtonPressMask|ButtonReleaseMask,
    2805             :                                       aCursor,
    2806           0 :                                       CurrentTime );
    2807             :         }
    2808             :     }
    2809             :     else
    2810             :     {
    2811             :         // let mouse events reach the correct window
    2812           0 :         if( nVisibleFloats < 1 )
    2813             :         {
    2814           0 :             if( ! (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION) )
    2815           0 :                 XUngrabPointer( GetXDisplay(), CurrentTime );
    2816             :         }
    2817           0 :         else if( pEvent->type == ButtonPress )
    2818             :         {
    2819             :             // see if the user clicks outside all of the floats
    2820             :             // if yes release the grab
    2821           0 :             bool bInside = false;
    2822           0 :             const std::list< SalFrame* >& rFrames = GetDisplay()->getFrames();
    2823           0 :             for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
    2824             :             {
    2825           0 :                 const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
    2826           0 :                 if( pFrame->IsFloatGrabWindow()                                     &&
    2827           0 :                     pFrame->bMapped_                                                &&
    2828           0 :                     pEvent->xbutton.x_root >= pFrame->maGeometry.nX                             &&
    2829           0 :                     pEvent->xbutton.x_root < pFrame->maGeometry.nX + (int)pFrame->maGeometry.nWidth &&
    2830           0 :                     pEvent->xbutton.y_root >= pFrame->maGeometry.nY                             &&
    2831           0 :                     pEvent->xbutton.y_root < pFrame->maGeometry.nY + (int)pFrame->maGeometry.nHeight )
    2832             :                 {
    2833           0 :                     bInside = true;
    2834           0 :                     break;
    2835             :                 }
    2836             :             }
    2837           0 :             if( ! bInside )
    2838             :             {
    2839             :                 // need not take care of the XUngrabPointer in Show( false )
    2840             :                 // because XUngrabPointer does not produce errors if pointer
    2841             :                 // is not grabbed
    2842           0 :                 XUngrabPointer( GetXDisplay(), CurrentTime );
    2843           0 :                 bClosePopups = true;
    2844             : 
    2845             :                 /*  #i15246# only close popups if pointer is outside all our frames
    2846             :                  *  cannot use our own geometry data here because stacking
    2847             :                  *  is unknown (the above case implicitly assumes
    2848             :                  *  that floats are on top which should be true)
    2849             :                  */
    2850             :                 ::Window aRoot, aChild;
    2851             :                 int root_x, root_y, win_x, win_y;
    2852             :                 unsigned int mask_return;
    2853           0 :                 if( XQueryPointer( GetXDisplay(),
    2854             :                                    GetDisplay()->GetRootWindow( m_nXScreen ),
    2855             :                                    &aRoot, &aChild,
    2856             :                                    &root_x, &root_y,
    2857             :                                    &win_x, &win_y,
    2858           0 :                                    &mask_return )
    2859           0 :                     && aChild // pointer may not be in any child
    2860             :                     )
    2861             :                 {
    2862           0 :                     for( std::list< SalFrame* >::const_iterator it = rFrames.begin(); it != rFrames.end(); ++it )
    2863             :                     {
    2864           0 :                         const X11SalFrame* pFrame = static_cast< const X11SalFrame* >(*it);
    2865           0 :                         if( ! pFrame->IsFloatGrabWindow()
    2866           0 :                             && ( pFrame->GetWindow() == aChild ||
    2867           0 :                                  pFrame->GetShellWindow() == aChild ||
    2868           0 :                                  pFrame->GetStackingWindow() == aChild )
    2869             :                             )
    2870             :                         {
    2871             :                             // #i63638# check that pointer is inside window, not
    2872             :                             // only inside stacking window
    2873           0 :                             if( root_x >= pFrame->maGeometry.nX && root_x < sal::static_int_cast< int >(pFrame->maGeometry.nX+pFrame->maGeometry.nWidth) &&
    2874           0 :                                 root_y >= pFrame->maGeometry.nY && root_y < sal::static_int_cast< int >(pFrame->maGeometry.nX+pFrame->maGeometry.nHeight) )
    2875             :                             {
    2876           0 :                                 bClosePopups = false;
    2877             :                             }
    2878           0 :                             break;
    2879             :                         }
    2880             :                     }
    2881             :                 }
    2882             :             }
    2883             :         }
    2884             : 
    2885           0 :         if( m_bXEmbed && pEvent->xbutton.button == Button1 )
    2886           0 :             askForXEmbedFocus( pEvent->xbutton.time );
    2887             : 
    2888           0 :         if( pEvent->xbutton.button == Button1 ||
    2889           0 :             pEvent->xbutton.button == Button2 ||
    2890           0 :             pEvent->xbutton.button == Button3 )
    2891             :         {
    2892           0 :             aMouseEvt.mnX       = pEvent->xbutton.x;
    2893           0 :             aMouseEvt.mnY       = pEvent->xbutton.y;
    2894           0 :             aMouseEvt.mnTime    = pEvent->xbutton.time;
    2895           0 :             aMouseEvt.mnCode    = sal_GetCode( pEvent->xbutton.state );
    2896             : 
    2897           0 :             if( Button1 == pEvent->xbutton.button )
    2898           0 :                 aMouseEvt.mnButton  = MOUSE_LEFT;
    2899           0 :             else if( Button2 == pEvent->xbutton.button )
    2900           0 :                 aMouseEvt.mnButton  = MOUSE_MIDDLE;
    2901           0 :             else if( Button3 == pEvent->xbutton.button )
    2902           0 :                 aMouseEvt.mnButton  = MOUSE_RIGHT;
    2903             : 
    2904           0 :             nEvent              = ButtonPress == pEvent->type
    2905             :                 ? SALEVENT_MOUSEBUTTONDOWN
    2906           0 :                 : SALEVENT_MOUSEBUTTONUP;
    2907             :         }
    2908           0 :         else if( pEvent->xbutton.button == Button4 ||
    2909           0 :                  pEvent->xbutton.button == Button5 ||
    2910           0 :                  pEvent->xbutton.button == Button6 ||
    2911           0 :                  pEvent->xbutton.button == Button7 )
    2912             :         {
    2913             :             const bool bIncrement(
    2914           0 :                 pEvent->xbutton.button == Button4 ||
    2915           0 :                 pEvent->xbutton.button == Button6 );
    2916             :             const bool bHoriz(
    2917           0 :                 pEvent->xbutton.button == Button6 ||
    2918           0 :                 pEvent->xbutton.button == Button7 );
    2919             : 
    2920           0 :             if( pEvent->type == ButtonRelease )
    2921           0 :                 return 0;
    2922             : 
    2923             :             static sal_uLong        nLines = 0;
    2924           0 :             if( ! nLines )
    2925             :             {
    2926           0 :                 char* pEnv = getenv( "SAL_WHEELLINES" );
    2927           0 :                 nLines = pEnv ? atoi( pEnv ) : 3;
    2928           0 :                 if( nLines > 10 )
    2929           0 :                     nLines = SAL_WHEELMOUSE_EVENT_PAGESCROLL;
    2930             :             }
    2931             : 
    2932           0 :             SalWheelMouseEvent  aWheelEvt;
    2933           0 :             aWheelEvt.mnTime        = pEvent->xbutton.time;
    2934           0 :             aWheelEvt.mnX           = pEvent->xbutton.x;
    2935           0 :             aWheelEvt.mnY           = pEvent->xbutton.y;
    2936           0 :             aWheelEvt.mnDelta       = bIncrement ? 120 : -120;
    2937           0 :             aWheelEvt.mnNotchDelta  = bIncrement ? 1 : -1;
    2938           0 :             aWheelEvt.mnScrollLines = nLines;
    2939           0 :             aWheelEvt.mnCode        = sal_GetCode( pEvent->xbutton.state );
    2940           0 :             aWheelEvt.mbHorz        = bHoriz;
    2941             : 
    2942           0 :             nEvent = SALEVENT_WHEELMOUSE;
    2943             : 
    2944             :             // --- RTL --- (mirror mouse pos)
    2945           0 :             if( Application::GetSettings().GetLayoutRTL() )
    2946           0 :                 aWheelEvt.mnX = nWidth_-1-aWheelEvt.mnX;
    2947           0 :             return CallCallback( nEvent, &aWheelEvt );
    2948             :         }
    2949             :     }
    2950             : 
    2951           0 :     int nRet = 0;
    2952           0 :     if( nEvent == SALEVENT_MOUSELEAVE
    2953           0 :         || ( aMouseEvt.mnX <  nWidth_  && aMouseEvt.mnX >  -1 &&
    2954           0 :              aMouseEvt.mnY <  nHeight_ && aMouseEvt.mnY >  -1 )
    2955           0 :         || pDisplay_->MouseCaptured( this )
    2956             :         )
    2957             :     {
    2958             :         // --- RTL --- (mirror mouse pos)
    2959           0 :         if( Application::GetSettings().GetLayoutRTL() )
    2960           0 :             aMouseEvt.mnX = nWidth_-1-aMouseEvt.mnX;
    2961           0 :         nRet = CallCallback( nEvent, &aMouseEvt );
    2962             :     }
    2963             : 
    2964           0 :     if( bClosePopups )
    2965             :     {
    2966             :         /*  #108213# close popups after dispatching the event outside the popup;
    2967             :          *  applications do weird things.
    2968             :          */
    2969           0 :         ImplSVData* pSVData = ImplGetSVData();
    2970           0 :         if ( pSVData->maWinData.mpFirstFloat )
    2971             :         {
    2972           0 :             static const char* pEnv = getenv( "SAL_FLOATWIN_NOAPPFOCUSCLOSE" );
    2973           0 :             if ( !(pSVData->maWinData.mpFirstFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE) && !(pEnv && *pEnv) )
    2974           0 :                 pSVData->maWinData.mpFirstFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
    2975             :         }
    2976             :     }
    2977             : 
    2978           0 :     return nRet;
    2979             : }
    2980             : 
    2981             : // F10 means either KEY_F10 or KEY_MENU, which has to be decided
    2982             : // in the independent part.
    2983             : struct KeyAlternate
    2984             : {
    2985             :     sal_uInt16          nKeyCode;
    2986             :     sal_Unicode     nCharCode;
    2987           0 :     KeyAlternate() : nKeyCode( 0 ), nCharCode( 0 ) {}
    2988           0 :     KeyAlternate( sal_uInt16 nKey, sal_Unicode nChar = 0 ) : nKeyCode( nKey ), nCharCode( nChar ) {}
    2989             : };
    2990             : 
    2991             : inline KeyAlternate
    2992           0 : GetAlternateKeyCode( const sal_uInt16 nKeyCode )
    2993             : {
    2994           0 :     KeyAlternate aAlternate;
    2995             : 
    2996           0 :     switch( nKeyCode )
    2997             :     {
    2998           0 :         case KEY_F10: aAlternate = KeyAlternate( KEY_MENU );break;
    2999           0 :         case KEY_F24: aAlternate = KeyAlternate( KEY_SUBTRACT, '-' );break;
    3000             :     }
    3001             : 
    3002           0 :     return aAlternate;
    3003             : }
    3004             : 
    3005           0 : void X11SalFrame::beginUnicodeSequence()
    3006             : {
    3007           0 :     OUString& rSeq( GetGenericData()->GetUnicodeCommand() );
    3008           0 :     vcl::DeletionListener aDeleteWatch( this );
    3009             : 
    3010           0 :     if( !rSeq.isEmpty() )
    3011           0 :         endUnicodeSequence();
    3012             : 
    3013           0 :     rSeq = "u";
    3014             : 
    3015           0 :     if( ! aDeleteWatch.isDeleted() )
    3016             :     {
    3017           0 :         sal_uInt16 nTextAttr = EXTTEXTINPUT_ATTR_UNDERLINE;
    3018           0 :         SalExtTextInputEvent aEv;
    3019           0 :         aEv.mnTime          = 0;
    3020           0 :         aEv.maText          = rSeq;
    3021           0 :         aEv.mpTextAttr      = &nTextAttr;
    3022           0 :         aEv.mnCursorPos     = 0;
    3023           0 :         aEv.mnCursorFlags   = 0;
    3024           0 :         aEv.mbOnlyCursor    = false;
    3025             : 
    3026           0 :         CallCallback(SALEVENT_EXTTEXTINPUT, (void*)&aEv);
    3027           0 :     }
    3028           0 : }
    3029             : 
    3030           0 : bool X11SalFrame::appendUnicodeSequence( sal_Unicode c )
    3031             : {
    3032           0 :     bool bRet = false;
    3033           0 :     OUString& rSeq( GetGenericData()->GetUnicodeCommand() );
    3034           0 :     if( !rSeq.isEmpty() )
    3035             :     {
    3036             :         // range check
    3037           0 :         if( (c >= '0' && c <= '9') ||
    3038           0 :             (c >= 'a' && c <= 'f') ||
    3039           0 :             (c >= 'A' && c <= 'F') )
    3040             :         {
    3041           0 :             OUStringBuffer aBuf( rSeq.getLength() + 1 );
    3042           0 :             aBuf.append( rSeq );
    3043           0 :             aBuf.append( c );
    3044           0 :             rSeq = aBuf.makeStringAndClear();
    3045           0 :             std::vector<sal_uInt16> attribs( rSeq.getLength(), EXTTEXTINPUT_ATTR_UNDERLINE );
    3046             : 
    3047           0 :             SalExtTextInputEvent aEv;
    3048           0 :             aEv.mnTime          = 0;
    3049           0 :             aEv.maText          = rSeq;
    3050           0 :             aEv.mpTextAttr      = &attribs[0];
    3051           0 :             aEv.mnCursorPos     = 0;
    3052           0 :             aEv.mnCursorFlags   = 0;
    3053           0 :             aEv.mbOnlyCursor    = false;
    3054             : 
    3055           0 :             CallCallback(SALEVENT_EXTTEXTINPUT, (void*)&aEv);
    3056           0 :             bRet = true;
    3057             :         }
    3058             :         else
    3059           0 :             bRet = endUnicodeSequence();
    3060             :     }
    3061             :     else
    3062           0 :         endUnicodeSequence();
    3063           0 :     return bRet;
    3064             : }
    3065             : 
    3066           0 : bool X11SalFrame::endUnicodeSequence()
    3067             : {
    3068           0 :     OUString& rSeq( GetGenericData()->GetUnicodeCommand() );
    3069             : 
    3070           0 :     vcl::DeletionListener aDeleteWatch( this );
    3071           0 :     if( rSeq.getLength() > 1 && rSeq.getLength() < 6 )
    3072             :     {
    3073             :         // cut the "u"
    3074           0 :         OUString aNumbers( rSeq.copy( 1 ) );
    3075           0 :         sal_uInt32 nValue = aNumbers.toUInt32( 16 );
    3076           0 :         if( nValue >= 32 )
    3077             :         {
    3078           0 :             sal_uInt16 nTextAttr = EXTTEXTINPUT_ATTR_UNDERLINE;
    3079           0 :             SalExtTextInputEvent aEv;
    3080           0 :             aEv.mnTime          = 0;
    3081           0 :             aEv.maText          = OUString( sal_Unicode(nValue) );
    3082           0 :             aEv.mpTextAttr      = &nTextAttr;
    3083           0 :             aEv.mnCursorPos     = 0;
    3084           0 :             aEv.mnCursorFlags   = 0;
    3085           0 :             aEv.mbOnlyCursor    = false;
    3086           0 :             CallCallback(SALEVENT_EXTTEXTINPUT, (void*)&aEv);
    3087           0 :         }
    3088             :     }
    3089           0 :     bool bWasInput = !rSeq.isEmpty();
    3090           0 :     rSeq = OUString();
    3091           0 :     if( bWasInput && ! aDeleteWatch.isDeleted() )
    3092           0 :         CallCallback(SALEVENT_ENDEXTTEXTINPUT, NULL);
    3093           0 :     return bWasInput;
    3094             : }
    3095             : 
    3096           0 : long X11SalFrame::HandleKeyEvent( XKeyEvent *pEvent )
    3097             : {
    3098             :     KeySym          nKeySym;
    3099             :     KeySym          nUnmodifiedKeySym;
    3100           0 :     int             nLen = 2048;
    3101           0 :     unsigned char   *pPrintable = (unsigned char*)alloca( nLen );
    3102             : 
    3103             :     // singlebyte code composed by input method, the new default
    3104           0 :     if (mpInputContext != NULL && mpInputContext->UseContext())
    3105             :     {
    3106             :         // returns a keysym as well as the pPrintable (in system encoding)
    3107             :         // printable may be empty.
    3108             :         Status nStatus;
    3109             :         nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen,
    3110             :                                         &nUnmodifiedKeySym,
    3111           0 :                                         &nStatus, mpInputContext->GetContext() );
    3112           0 :         if ( nStatus == XBufferOverflow )
    3113             :         {
    3114           0 :             nLen *= 2;
    3115           0 :             pPrintable = (unsigned char*)alloca( nLen );
    3116             :             nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen,
    3117             :                                             &nUnmodifiedKeySym,
    3118           0 :                                             &nStatus, mpInputContext->GetContext() );
    3119             :         }
    3120             :     }
    3121             :     else
    3122             :     {
    3123             :         // fallback, this should never ever be called
    3124           0 :         Status nStatus = 0;
    3125           0 :            nKeySym = pDisplay_->GetKeySym( pEvent, pPrintable, &nLen, &nUnmodifiedKeySym, &nStatus );
    3126             :      }
    3127             : 
    3128             :     SalKeyEvent aKeyEvt;
    3129             :     sal_uInt16      nKeyCode;
    3130           0 :     sal_uInt16 nModCode = 0;
    3131             :     char        aDummy;
    3132             : 
    3133           0 :     if( pEvent->state & ShiftMask )
    3134           0 :         nModCode |= KEY_SHIFT;
    3135           0 :     if( pEvent->state & ControlMask )
    3136           0 :         nModCode |= KEY_MOD1;
    3137           0 :     if( pEvent->state & Mod1Mask )
    3138           0 :         nModCode |= KEY_MOD2;
    3139             : 
    3140           0 :     if( nModCode != (KEY_SHIFT|KEY_MOD1) )
    3141           0 :         endUnicodeSequence();
    3142             : 
    3143           0 :     if(     nKeySym == XK_Shift_L   || nKeySym == XK_Shift_R
    3144           0 :         ||  nKeySym == XK_Control_L || nKeySym == XK_Control_R
    3145           0 :         ||  nKeySym == XK_Alt_L     || nKeySym == XK_Alt_R
    3146           0 :         ||  nKeySym == XK_Meta_L    || nKeySym == XK_Meta_R
    3147           0 :                 ||      nKeySym == XK_Super_L   || nKeySym == XK_Super_R )
    3148             :     {
    3149             :         SalKeyModEvent aModEvt;
    3150           0 :         aModEvt.mnModKeyCode = 0;
    3151           0 :         if( pEvent->type == KeyPress && mnExtKeyMod == 0 )
    3152           0 :             mbSendExtKeyModChange = true;
    3153           0 :         else if( pEvent->type == KeyRelease && mbSendExtKeyModChange )
    3154             :         {
    3155           0 :             aModEvt.mnModKeyCode = mnExtKeyMod;
    3156           0 :             mnExtKeyMod = 0;
    3157             :         }
    3158             : 
    3159             :         // pressing just the ctrl key leads to a keysym of XK_Control but
    3160             :         // the event state does not contain ControlMask. In the release
    3161             :         // event its the other way round: it does contain the Control mask.
    3162             :         // The modifier mode therefore has to be adapted manually.
    3163           0 :         sal_uInt16 nExtModMask = 0;
    3164           0 :         sal_uInt16 nModMask = 0;
    3165           0 :         switch( nKeySym )
    3166             :         {
    3167             :             case XK_Control_L:
    3168           0 :                 nExtModMask = MODKEY_LMOD1;
    3169           0 :                 nModMask = KEY_MOD1;
    3170           0 :                 break;
    3171             :             case XK_Control_R:
    3172           0 :                 nExtModMask = MODKEY_RMOD1;
    3173           0 :                 nModMask = KEY_MOD1;
    3174           0 :                 break;
    3175             :             case XK_Alt_L:
    3176           0 :                 nExtModMask = MODKEY_LMOD2;
    3177           0 :                 nModMask = KEY_MOD2;
    3178           0 :                 break;
    3179             :             case XK_Alt_R:
    3180           0 :                 nExtModMask = MODKEY_RMOD2;
    3181           0 :                 nModMask = KEY_MOD2;
    3182           0 :                 break;
    3183             :             case XK_Shift_L:
    3184           0 :                 nExtModMask = MODKEY_LSHIFT;
    3185           0 :                 nModMask = KEY_SHIFT;
    3186           0 :                 break;
    3187             :             case XK_Shift_R:
    3188           0 :                 nExtModMask = MODKEY_RSHIFT;
    3189           0 :                 nModMask = KEY_SHIFT;
    3190           0 :                 break;
    3191             :             // Map Meta/Super keys to MOD3 modifier on all Unix systems
    3192             :             // except Mac OS X
    3193             :             case XK_Meta_L:
    3194             :             case XK_Super_L:
    3195           0 :                 nExtModMask = MODKEY_LMOD3;
    3196           0 :                 nModMask = KEY_MOD3;
    3197           0 :                 break;
    3198             :             case XK_Meta_R:
    3199             :             case XK_Super_R:
    3200           0 :                 nExtModMask = MODKEY_RMOD3;
    3201           0 :                 nModMask = KEY_MOD3;
    3202           0 :                 break;
    3203             :         }
    3204           0 :         if( pEvent->type == KeyRelease )
    3205             :         {
    3206           0 :             nModCode &= ~nModMask;
    3207           0 :             mnExtKeyMod &= ~nExtModMask;
    3208             :         }
    3209             :         else
    3210             :         {
    3211           0 :             nModCode |= nModMask;
    3212           0 :             mnExtKeyMod |= nExtModMask;
    3213             :         }
    3214             : 
    3215           0 :         aModEvt.mnCode = nModCode;
    3216           0 :         aModEvt.mnTime = pEvent->time;
    3217             : 
    3218           0 :         int nRet = CallCallback( SALEVENT_KEYMODCHANGE, &aModEvt );
    3219             : 
    3220           0 :         return nRet;
    3221             :     }
    3222             : 
    3223           0 :     mbSendExtKeyModChange = false;
    3224             : 
    3225             :     // try to figure out the vcl code for the keysym
    3226             :     // #i52338# use the unmodified KeySym if there is none for the real KeySym
    3227             :     // because the independent part has only keycodes for unshifted keys
    3228           0 :     nKeyCode = pDisplay_->GetKeyCode( nKeySym, &aDummy );
    3229           0 :     if( nKeyCode == 0 )
    3230           0 :         nKeyCode = pDisplay_->GetKeyCode( nUnmodifiedKeySym, &aDummy );
    3231             : 
    3232             :     // try to figure out a printable if XmbLookupString returns only a keysym
    3233             :     // and NOT a printable. Do not store it in pPrintable[0] since it is expected to
    3234             :     // be in system encoding, not unicode.
    3235             :     // #i8988##, if KeySym and printable look equally promising then prefer KeySym
    3236             :     // the printable is bound to the encoding so the KeySym might contain more
    3237             :     // information (in et_EE locale: "Compose + Z + <" delivers "," in printable and
    3238             :     // (the desired) Zcaron in KeySym
    3239           0 :     sal_Unicode nKeyString = 0x0;
    3240           0 :     if (   (nLen == 0)
    3241           0 :         || ((nLen == 1) && (nKeySym > 0)) )
    3242           0 :         nKeyString = KeysymToUnicode (nKeySym);
    3243             :     // if we have nothing we give up
    3244           0 :     if( !nKeyCode && !nLen && !nKeyString)
    3245           0 :         return 0;
    3246             : 
    3247           0 :     vcl::DeletionListener aDeleteWatch( this );
    3248             : 
    3249           0 :     if( nModCode == (KEY_SHIFT | KEY_MOD1) && pEvent->type == KeyPress )
    3250             :     {
    3251           0 :         sal_uInt16 nSeqKeyCode = pDisplay_->GetKeyCode( nUnmodifiedKeySym, &aDummy );
    3252           0 :         if( nSeqKeyCode == KEY_U )
    3253             :         {
    3254           0 :             beginUnicodeSequence();
    3255           0 :             return 1;
    3256             :         }
    3257           0 :         else if( nSeqKeyCode >= KEY_0 && nSeqKeyCode <= KEY_9 )
    3258             :         {
    3259           0 :             if( appendUnicodeSequence( sal_Unicode( '0' ) + sal_Unicode(nSeqKeyCode - KEY_0) ) )
    3260           0 :                 return 1;
    3261             :         }
    3262           0 :         else if( nSeqKeyCode >= KEY_A && nSeqKeyCode <= KEY_F )
    3263             :         {
    3264           0 :             if( appendUnicodeSequence( sal_Unicode( 'a' ) + sal_Unicode(nSeqKeyCode - KEY_A) ) )
    3265           0 :                 return 1;
    3266             :         }
    3267             :         else
    3268           0 :             endUnicodeSequence();
    3269             :     }
    3270             : 
    3271           0 :     if( aDeleteWatch.isDeleted() )
    3272           0 :         return 0;
    3273             : 
    3274           0 :     rtl_TextEncoding nEncoding = osl_getThreadTextEncoding();
    3275             : 
    3276             :     sal_Unicode *pBuffer;
    3277             :     sal_Unicode *pString;
    3278           0 :     sal_Size     nBufferSize = nLen * 2;
    3279             :     sal_Size     nSize;
    3280           0 :     pBuffer = (sal_Unicode*) malloc( nBufferSize + 2 );
    3281           0 :     pBuffer[ 0 ] = 0;
    3282             : 
    3283           0 :     if (nKeyString != 0)
    3284             :     {
    3285           0 :         pString = &nKeyString;
    3286           0 :         nSize = 1;
    3287             :     }
    3288           0 :     else if (nLen > 0 && nEncoding != RTL_TEXTENCODING_UNICODE)
    3289             :     {
    3290             :         // create text converter
    3291             :         rtl_TextToUnicodeConverter aConverter =
    3292           0 :                 rtl_createTextToUnicodeConverter( nEncoding );
    3293             :         rtl_TextToUnicodeContext aContext =
    3294           0 :                  rtl_createTextToUnicodeContext( aConverter );
    3295             : 
    3296             :         sal_uInt32  nConversionInfo;
    3297             :         sal_Size    nConvertedChars;
    3298             : 
    3299             :         // convert to single byte text stream
    3300             :         nSize = rtl_convertTextToUnicode(
    3301             :                                 aConverter, aContext,
    3302             :                                 (char*)pPrintable, nLen,
    3303             :                                 pBuffer, nBufferSize,
    3304             :                                 RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_IGNORE |
    3305             :                                 RTL_TEXTTOUNICODE_FLAGS_INVALID_IGNORE,
    3306           0 :                                 &nConversionInfo, &nConvertedChars );
    3307             : 
    3308             :         // destroy converter
    3309           0 :         rtl_destroyTextToUnicodeContext( aConverter, aContext );
    3310           0 :         rtl_destroyTextToUnicodeConverter( aConverter );
    3311             : 
    3312           0 :         pString = pBuffer;
    3313             :     }
    3314           0 :     else if (nLen > 0 /* nEncoding == RTL_TEXTENCODING_UNICODE */)
    3315             :     {
    3316           0 :         pString = (sal_Unicode*)pPrintable;
    3317           0 :           nSize = nLen;
    3318             :     }
    3319             :     else
    3320             :     {
    3321           0 :         pString = pBuffer;
    3322           0 :         nSize   = 0;
    3323             :     }
    3324             : 
    3325           0 :     if (   mpInputContext != NULL
    3326           0 :         && mpInputContext->UseContext()
    3327           0 :         && KeyRelease != pEvent->type
    3328           0 :         && (   (nSize >  1)
    3329           0 :             || (nSize >  0 && mpInputContext->IsPreeditMode())) )
    3330             :     {
    3331           0 :         mpInputContext->CommitKeyEvent(pString, nSize);
    3332             :     }
    3333             :     else
    3334             :     // normal single character keyinput
    3335             :     {
    3336           0 :         aKeyEvt.mnCode     = nKeyCode | nModCode;
    3337           0 :         aKeyEvt.mnRepeat   = 0;
    3338           0 :         aKeyEvt.mnTime     = pEvent->time;
    3339           0 :         aKeyEvt.mnCharCode = pString[ 0 ];
    3340             : 
    3341           0 :         if( KeyRelease == pEvent->type )
    3342             :         {
    3343           0 :             CallCallback( SALEVENT_KEYUP, &aKeyEvt );
    3344             :         }
    3345             :         else
    3346             :         {
    3347           0 :             if ( ! CallCallback(SALEVENT_KEYINPUT, &aKeyEvt) )
    3348             :             {
    3349             :                 // independent layer doesn't want to handle key-event, so check
    3350             :                 // whether the keycode may have an alternate meaning
    3351           0 :                 KeyAlternate aAlternate = GetAlternateKeyCode( nKeyCode );
    3352           0 :                 if ( aAlternate.nKeyCode != 0 )
    3353             :                 {
    3354           0 :                     aKeyEvt.mnCode = aAlternate.nKeyCode | nModCode;
    3355           0 :                     if( aAlternate.nCharCode )
    3356           0 :                         aKeyEvt.mnCharCode = aAlternate.nCharCode;
    3357           0 :                     CallCallback(SALEVENT_KEYINPUT, &aKeyEvt);
    3358             :                 }
    3359             :             }
    3360             :         }
    3361             :     }
    3362             : 
    3363             :       // update the spot location for PreeditPosition IME style
    3364             : 
    3365           0 :     if (! aDeleteWatch.isDeleted())
    3366             :     {
    3367           0 :         if (mpInputContext != NULL && mpInputContext->UseContext())
    3368           0 :             mpInputContext->UpdateSpotLocation();
    3369             :     }
    3370             : 
    3371           0 :     free (pBuffer);
    3372           0 :     return True;
    3373             : }
    3374             : 
    3375           0 : long X11SalFrame::HandleFocusEvent( XFocusChangeEvent *pEvent )
    3376             : {
    3377             :     // ReflectionX in Windows mode changes focus while mouse is grabbed
    3378           0 :     if( nVisibleFloats > 0 && GetDisplay()->getWMAdaptor()->getWindowManagerName().equalsAscii( "ReflectionX Windows" ) )
    3379           0 :         return 1;
    3380             : 
    3381             :     /*  ignore focusout resulting from keyboard grabs
    3382             :      *  we do not grab it and are not interested when
    3383             :      *  someone else does CDE e.g. does a XGrabKey on arrow keys
    3384             :      *  handle focus events with mode NotifyWhileGrabbed
    3385             :      *  because with CDE alt-tab focus changing we do not get
    3386             :      *  normal focus events
    3387             :      *  cast focus event to the input context, otherwise the
    3388             :      *  status window does not follow the application frame
    3389             :      */
    3390             : 
    3391           0 :     if ( mpInputContext != NULL  )
    3392             :     {
    3393           0 :         if( FocusIn == pEvent->type )
    3394           0 :             mpInputContext->SetICFocus( this );
    3395             :         else
    3396             :         {
    3397             :             /*
    3398             :              *  do not unset the IC focuse here because would kill
    3399             :              *  a lookup choice windows that might have the focus now
    3400             :              *      mpInputContext->UnsetICFocus( this );
    3401             :              */
    3402           0 :             vcl::I18NStatus::get().show( false, vcl::I18NStatus::focus );
    3403             :         }
    3404             :     }
    3405             : 
    3406           0 :     if ( pEvent->mode == NotifyNormal || pEvent->mode == NotifyWhileGrabbed ||
    3407           0 :          ( ( nStyle_ & SAL_FRAME_STYLE_PLUG ) && pEvent->window == GetShellWindow() )
    3408             :          )
    3409             :     {
    3410           0 :         if( hPresentationWindow != None && hPresentationWindow != GetShellWindow() )
    3411           0 :             return 0;
    3412             : 
    3413           0 :         if( FocusIn == pEvent->type )
    3414             :         {
    3415           0 :             GetSalData()->m_pInstance->updatePrinterUpdate();
    3416           0 :             mbInputFocus = True;
    3417           0 :             ImplSVData* pSVData = ImplGetSVData();
    3418             : 
    3419           0 :             long nRet = CallCallback( SALEVENT_GETFOCUS,  0 );
    3420           0 :             if ((mpParent != NULL && nStyle_ == 0)
    3421           0 :                 && pSVData->maWinData.mpFirstFloat )
    3422             :             {
    3423           0 :                 sal_uLong nMode = pSVData->maWinData.mpFirstFloat->GetPopupModeFlags();
    3424             :                 pSVData->maWinData.mpFirstFloat->SetPopupModeFlags(
    3425           0 :                                         nMode & ~(FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE));
    3426             :             }
    3427           0 :             return nRet;
    3428             :         }
    3429             :         else
    3430             :         {
    3431           0 :             mbInputFocus = False;
    3432           0 :             mbSendExtKeyModChange = false;
    3433           0 :             mnExtKeyMod = 0;
    3434           0 :             return CallCallback( SALEVENT_LOSEFOCUS, 0 );
    3435             :         }
    3436             :     }
    3437             : 
    3438           0 :     return 0;
    3439             : }
    3440             : 
    3441           0 : long X11SalFrame::HandleExposeEvent( XEvent *pEvent )
    3442             : {
    3443           0 :     XRectangle  aRect = { 0, 0, 0, 0 };
    3444           0 :     sal_uInt16      nCount = 0;
    3445             : 
    3446           0 :     if( pEvent->type == Expose )
    3447             :     {
    3448           0 :         aRect.x         = pEvent->xexpose.x;
    3449           0 :         aRect.y         = pEvent->xexpose.y;
    3450           0 :         aRect.width     = pEvent->xexpose.width;
    3451           0 :         aRect.height    = pEvent->xexpose.height;
    3452           0 :         nCount          = pEvent->xexpose.count;
    3453             :     }
    3454           0 :     else if( pEvent->type == GraphicsExpose )
    3455             :     {
    3456           0 :         aRect.x         = pEvent->xgraphicsexpose.x;
    3457           0 :         aRect.y         = pEvent->xgraphicsexpose.y;
    3458           0 :         aRect.width     = pEvent->xgraphicsexpose.width;
    3459           0 :         aRect.height    = pEvent->xgraphicsexpose.height;
    3460           0 :         nCount          = pEvent->xgraphicsexpose.count;
    3461             :     }
    3462             : 
    3463           0 :     if( IsOverrideRedirect() && mbFullScreen &&
    3464           0 :         aPresentationReparentList.begin() == aPresentationReparentList.end() )
    3465             :         // we are in fullscreen mode -> override redirect
    3466             :          // focus is possibly lost, so reget it
    3467           0 :          XSetInputFocus( GetXDisplay(), GetShellWindow(), RevertToNone, CurrentTime );
    3468             : 
    3469             :     // width and height are extents, so they are of by one for rectangle
    3470           0 :     maPaintRegion.Union( Rectangle( Point(aRect.x, aRect.y), Size(aRect.width+1, aRect.height+1) ) );
    3471             : 
    3472           0 :     if( nCount )
    3473             :         // wait for last expose rectangle, do not wait for resize timer
    3474             :         // if a completed graphics expose sequence is available
    3475           0 :         return 1;
    3476             : 
    3477           0 :     SalPaintEvent aPEvt( maPaintRegion.Left(), maPaintRegion.Top(), maPaintRegion.GetWidth(), maPaintRegion.GetHeight() );
    3478             : 
    3479           0 :      CallCallback( SALEVENT_PAINT, &aPEvt );
    3480           0 :     maPaintRegion = Rectangle();
    3481             : 
    3482           0 :     return 1;
    3483             : }
    3484             : 
    3485           0 : void X11SalFrame::RestackChildren( ::Window* pTopLevelWindows, int nTopLevelWindows )
    3486             : {
    3487           0 :     if( maChildren.begin() != maChildren.end() )
    3488             :     {
    3489           0 :         int nWindow = nTopLevelWindows;
    3490           0 :         while( nWindow-- )
    3491           0 :             if( pTopLevelWindows[nWindow] == GetStackingWindow() )
    3492           0 :                 break;
    3493           0 :         if( nWindow < 0 )
    3494           0 :             return;
    3495             : 
    3496           0 :         std::list< X11SalFrame* >::const_iterator it;
    3497           0 :         for( it = maChildren.begin(); it != maChildren.end(); ++it )
    3498             :         {
    3499           0 :             X11SalFrame* pData = *it;
    3500           0 :             if( pData->bMapped_ )
    3501             :             {
    3502           0 :                 int nChild = nWindow;
    3503           0 :                 while( nChild-- )
    3504             :                 {
    3505           0 :                     if( pTopLevelWindows[nChild] == pData->GetStackingWindow() )
    3506             :                     {
    3507             :                         // if a child is behind its parent, place it above the
    3508             :                         // parent (for insane WMs like Dtwm and olwm)
    3509             :                         XWindowChanges aCfg;
    3510           0 :                         aCfg.sibling    = GetStackingWindow();
    3511           0 :                         aCfg.stack_mode = Above;
    3512           0 :                         XConfigureWindow( GetXDisplay(), pData->GetStackingWindow(), CWSibling|CWStackMode, &aCfg );
    3513           0 :                         break;
    3514             :                     }
    3515             :                 }
    3516             :             }
    3517             :         }
    3518           0 :         for( it = maChildren.begin(); it != maChildren.end(); ++it )
    3519             :         {
    3520           0 :             X11SalFrame* pData = *it;
    3521           0 :             pData->RestackChildren( pTopLevelWindows, nTopLevelWindows );
    3522             :         }
    3523             :     }
    3524             : }
    3525             : 
    3526           0 : void X11SalFrame::RestackChildren()
    3527             : {
    3528           0 :     if( ! GetDisplay()->getWMAdaptor()->isTransientBehaviourAsExpected()
    3529           0 :         && maChildren.begin() != maChildren.end() )
    3530             :     {
    3531           0 :         ::Window aRoot, aParent, *pChildren = NULL;
    3532             :         unsigned int nChildren;
    3533           0 :         if( XQueryTree( GetXDisplay(),
    3534             :                         GetDisplay()->GetRootWindow( m_nXScreen ),
    3535             :                         &aRoot,
    3536             :                         &aParent,
    3537             :                         &pChildren,
    3538           0 :                         &nChildren ) )
    3539             :         {
    3540           0 :             RestackChildren( pChildren, nChildren );
    3541           0 :             XFree( pChildren );
    3542             :         }
    3543             :     }
    3544           0 : }
    3545             : 
    3546           0 : static Bool size_event_predicate( Display*, XEvent* event, XPointer arg )
    3547             : {
    3548           0 :     if( event->type != ConfigureNotify )
    3549           0 :         return False;
    3550           0 :     X11SalFrame* frame = reinterpret_cast< X11SalFrame* >( arg );
    3551           0 :     XConfigureEvent* pEvent = &event->xconfigure;
    3552           0 :     if( pEvent->window != frame->GetShellWindow()
    3553           0 :         && pEvent->window != frame->GetWindow()
    3554           0 :         && pEvent->window != frame->GetForeignParent()
    3555           0 :         && pEvent->window != frame->GetStackingWindow())
    3556             :     { // ignored at top of HandleSizeEvent()
    3557           0 :         return False;
    3558             :     }
    3559           0 :     if( pEvent->window == frame->GetStackingWindow())
    3560           0 :         return False; // filtered later in HandleSizeEvent()
    3561             :     // at this point we know that there is another similar event in the queue
    3562           0 :     frame->setPendingSizeEvent();
    3563           0 :     return False; // but do not process the new event out of order
    3564             : }
    3565             : 
    3566           0 : void X11SalFrame::setPendingSizeEvent()
    3567             : {
    3568           0 :     mPendingSizeEvent = true;
    3569           0 : }
    3570             : 
    3571           0 : long X11SalFrame::HandleSizeEvent( XConfigureEvent *pEvent )
    3572             : {
    3573             :     // NOTE: if you add more tests in this function, make sure to update size_event_predicate()
    3574             :     // so that it finds exactly the same events
    3575             : 
    3576           0 :     if (   pEvent->window != GetShellWindow()
    3577           0 :            && pEvent->window != GetWindow()
    3578           0 :            && pEvent->window != GetForeignParent()
    3579           0 :            && pEvent->window != GetStackingWindow()
    3580             :            )
    3581             :     {
    3582             :         // could be as well a sys-child window (aka SalObject)
    3583           0 :         return 1;
    3584             :     }
    3585             : 
    3586           0 :     if( ( nStyle_ & SAL_FRAME_STYLE_PLUG ) && pEvent->window == GetShellWindow() )
    3587             :     {
    3588             :         // just update the children's positions
    3589           0 :         RestackChildren();
    3590           0 :         return 1;
    3591             :     }
    3592             : 
    3593           0 :     if( pEvent->window == GetForeignParent() )
    3594             :         XResizeWindow( GetXDisplay(),
    3595             :                        GetWindow(),
    3596             :                        pEvent->width,
    3597           0 :                        pEvent->height );
    3598             : 
    3599             :     ::Window hDummy;
    3600             :     XTranslateCoordinates( GetXDisplay(),
    3601             :                            GetWindow(),
    3602             :                            pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() ),
    3603             :                            0, 0,
    3604             :                            &pEvent->x, &pEvent->y,
    3605           0 :                            &hDummy );
    3606             : 
    3607           0 :     if( pEvent->window == GetStackingWindow() )
    3608             :     {
    3609           0 :         if( maGeometry.nX != pEvent->x || maGeometry.nY != pEvent->y )
    3610             :         {
    3611           0 :             maGeometry.nX = pEvent->x;
    3612           0 :             maGeometry.nY = pEvent->y;
    3613           0 :             CallCallback( SALEVENT_MOVE, NULL );
    3614             :         }
    3615           0 :         return 1;
    3616             :     }
    3617             : 
    3618             :     // check size hints in first time SalFrame::Show
    3619           0 :     if( SHOWSTATE_UNKNOWN == nShowState_ && bMapped_ )
    3620           0 :         nShowState_ = SHOWSTATE_NORMAL;
    3621             : 
    3622             :     // Avoid a race condition where resizing this window to one size and shortly after that
    3623             :     // to another size generates first size event with the old size and only after that
    3624             :     // with the new size, temporarily making us think the old size is valid (bnc#674806).
    3625             :     // So if there is another size event for this window pending, ignore this one.
    3626           0 :     mPendingSizeEvent = false;
    3627             :     XEvent dummy;
    3628           0 :     XCheckIfEvent( GetXDisplay(), &dummy, size_event_predicate, reinterpret_cast< XPointer >( this ));
    3629           0 :     if( mPendingSizeEvent )
    3630           0 :         return 1;
    3631             : 
    3632           0 :     nWidth_     = pEvent->width;
    3633           0 :     nHeight_    = pEvent->height;
    3634             : 
    3635           0 :     bool bMoved = ( pEvent->x != maGeometry.nX || pEvent->y != maGeometry.nY );
    3636           0 :     bool bSized = ( pEvent->width != (int)maGeometry.nWidth || pEvent->height != (int)maGeometry.nHeight );
    3637             : 
    3638           0 :     maGeometry.nX       = pEvent->x;
    3639           0 :     maGeometry.nY       = pEvent->y;
    3640           0 :     maGeometry.nWidth   = pEvent->width;
    3641           0 :     maGeometry.nHeight  = pEvent->height;
    3642           0 :     updateScreenNumber();
    3643             : 
    3644             :     // update children's position
    3645           0 :     RestackChildren();
    3646             : 
    3647           0 :     if( bSized && ! bMoved )
    3648           0 :         CallCallback( SALEVENT_RESIZE, NULL );
    3649           0 :     else if( bMoved && ! bSized )
    3650           0 :         CallCallback( SALEVENT_MOVE, NULL );
    3651           0 :     else if( bMoved && bSized )
    3652           0 :         CallCallback( SALEVENT_MOVERESIZE, NULL );
    3653             : 
    3654           0 :     return 1;
    3655             : }
    3656             : 
    3657           0 : IMPL_LINK_NOARG(X11SalFrame, HandleAlwaysOnTopRaise)
    3658             : {
    3659           0 :     if( bMapped_ )
    3660           0 :         ToTop( 0 );
    3661           0 :     return 0;
    3662             : }
    3663             : 
    3664           0 : long X11SalFrame::HandleReparentEvent( XReparentEvent *pEvent )
    3665             : {
    3666           0 :     Display        *pDisplay   = pEvent->display;
    3667             :     ::Window        hWM_Parent;
    3668             :     ::Window        hRoot, *Children, hDummy;
    3669             :     unsigned int    nChildren;
    3670           0 :     bool            bNone = pDisplay_->GetProperties()
    3671           0 :                             & PROPERTY_SUPPORT_WM_Parent_Pixmap_None;
    3672           0 :     bool            bAccessParentWindow = ! (pDisplay_->GetProperties()
    3673           0 :                             & PROPERTY_FEATURE_TrustedSolaris);
    3674             : 
    3675           0 :     static const char* pDisableStackingCheck = getenv( "SAL_DISABLE_STACKING_CHECK" );
    3676             : 
    3677           0 :     GetGenericData()->ErrorTrapPush();
    3678             : 
    3679             :     /*
    3680             :      *  don't rely on the new parent from the event.
    3681             :      *  the event may be "out of date", that is the window manager
    3682             :      *  window may not exist anymore. This can happen if someone
    3683             :      *  shows a frame and hides it again quickly (not that that would
    3684             :      *  be very sensible)
    3685             :      */
    3686           0 :     hWM_Parent = GetShellWindow();
    3687           0 :     do
    3688             :     {
    3689           0 :         Children = NULL;
    3690             :         XQueryTree( pDisplay,
    3691             :                     hWM_Parent,
    3692             :                     &hRoot,
    3693             :                     &hDummy,
    3694             :                     &Children,
    3695           0 :                     &nChildren );
    3696             : 
    3697           0 :         bool bError = GetGenericData()->ErrorTrapPop( false );
    3698           0 :         GetGenericData()->ErrorTrapPush();
    3699             : 
    3700           0 :         if( bError )
    3701             :         {
    3702           0 :             hWM_Parent = GetShellWindow();
    3703           0 :             break;
    3704             :         }
    3705             :          /* this sometimes happens if a Show(true) is
    3706             :          *  immediately followed by Show(false) (which is braindead anyway)
    3707             :          */
    3708           0 :         if( hDummy == hWM_Parent )
    3709           0 :             hDummy = hRoot;
    3710           0 :         if( hDummy != hRoot )
    3711             :         {
    3712           0 :             hWM_Parent = hDummy;
    3713           0 :             if( bAccessParentWindow && bNone )
    3714           0 :                 XSetWindowBackgroundPixmap( pDisplay, hWM_Parent, None );
    3715             :         }
    3716           0 :         if( Children )
    3717           0 :             XFree( Children );
    3718           0 :     } while( hDummy != hRoot );
    3719             : 
    3720           0 :     if( GetStackingWindow() == None
    3721           0 :         && hWM_Parent != hPresentationWindow
    3722           0 :         && hWM_Parent != GetShellWindow()
    3723           0 :         && ( ! pDisableStackingCheck || ! *pDisableStackingCheck )
    3724             :         )
    3725             :     {
    3726           0 :         mhStackingWindow = hWM_Parent;
    3727           0 :         if (bAccessParentWindow)
    3728           0 :             XSelectInput( pDisplay, GetStackingWindow(), StructureNotifyMask );
    3729             :     }
    3730             : 
    3731           0 :     if(     hWM_Parent == pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() )
    3732           0 :             ||  hWM_Parent == GetForeignParent()
    3733           0 :             ||  pEvent->parent == pDisplay_->GetRootWindow( pDisplay_->GetDefaultXScreen() )
    3734           0 :             || ( nStyle_ & SAL_FRAME_STYLE_FLOAT ) )
    3735             :     {
    3736             :         // Reparenting before Destroy
    3737           0 :         aPresentationReparentList.remove( GetStackingWindow() );
    3738           0 :         mhStackingWindow = None;
    3739           0 :         GetGenericData()->ErrorTrapPop();
    3740           0 :         return 0;
    3741             :     }
    3742             : 
    3743             :     /*
    3744             :      *  evil hack to show decorated windows on top
    3745             :      *  of override redirect presentation windows:
    3746             :      *  reparent the window manager window to the presentation window
    3747             :      *  does not work with non-reparenting WMs
    3748             :      *  in future this should not be necessary anymore with
    3749             :      *  _NET_WM_STATE_FULLSCREEN available
    3750             :      */
    3751           0 :     if( hPresentationWindow != None
    3752           0 :         && hPresentationWindow != GetWindow()
    3753           0 :         && GetStackingWindow() != None
    3754           0 :         && GetStackingWindow() != GetDisplay()->GetRootWindow( m_nXScreen )
    3755             :         )
    3756             :     {
    3757           0 :         int x = 0, y = 0;
    3758             :         ::Window aChild;
    3759             :         XTranslateCoordinates( GetXDisplay(),
    3760             :                                GetStackingWindow(),
    3761             :                                GetDisplay()->GetRootWindow( m_nXScreen ),
    3762             :                                0, 0,
    3763             :                                &x, &y,
    3764             :                                &aChild
    3765           0 :                                );
    3766             :         XReparentWindow( GetXDisplay(),
    3767             :                          GetStackingWindow(),
    3768             :                          hPresentationWindow,
    3769             :                          x, y
    3770           0 :                          );
    3771           0 :         aPresentationReparentList.push_back( GetStackingWindow() );
    3772             :     }
    3773             : 
    3774           0 :     int nLeft = 0, nTop = 0;
    3775             :     XTranslateCoordinates( GetXDisplay(),
    3776             :                            GetShellWindow(),
    3777             :                            hWM_Parent,
    3778             :                            0, 0,
    3779             :                            &nLeft,
    3780             :                            &nTop,
    3781           0 :                            &hDummy );
    3782           0 :     maGeometry.nLeftDecoration  = nLeft > 0 ? nLeft-1 : 0;
    3783           0 :     maGeometry.nTopDecoration   = nTop  > 0 ? nTop-1  : 0;
    3784             : 
    3785             :     /*
    3786             :      *  decorations are not symmetric,
    3787             :      *  so need real geometries here
    3788             :      *  (this will fail with virtual roots ?)
    3789             :      */
    3790             : 
    3791             :     // reset error occurred
    3792           0 :     GetGenericData()->ErrorTrapPop();
    3793           0 :     GetGenericData()->ErrorTrapPush();
    3794             : 
    3795             :     int xp, yp, x, y;
    3796             :     unsigned int wp, w, hp, h, bw, d;
    3797             :     XGetGeometry( GetXDisplay(),
    3798             :                   GetShellWindow(),
    3799             :                   &hRoot,
    3800           0 :                   &x, &y, &w, &h, &bw, &d );
    3801             :     XGetGeometry( GetXDisplay(),
    3802             :                   hWM_Parent,
    3803             :                   &hRoot,
    3804           0 :                   &xp, &yp, &wp, &hp, &bw, &d );
    3805           0 :     bool bResized = false;
    3806           0 :     bool bError = GetGenericData()->ErrorTrapPop( false );
    3807           0 :     GetGenericData()->ErrorTrapPush();
    3808             : 
    3809           0 :     if( ! bError )
    3810             :     {
    3811           0 :         maGeometry.nRightDecoration     = wp - w - maGeometry.nLeftDecoration;
    3812           0 :         maGeometry.nBottomDecoration    = hp - h - maGeometry.nTopDecoration;
    3813             :         /*
    3814             :          *  note: this works because hWM_Parent is direct child of root,
    3815             :          *  not necessarily parent of GetShellWindow()
    3816             :          */
    3817           0 :         maGeometry.nX       = xp + nLeft;
    3818           0 :         maGeometry.nY       = yp + nTop;
    3819           0 :         bResized = w != maGeometry.nWidth || h != maGeometry.nHeight;
    3820           0 :         maGeometry.nWidth   = w;
    3821           0 :         maGeometry.nHeight = h;
    3822             :     }
    3823             : 
    3824             :     // limit width and height if we are too large: #47757
    3825             :     // olwm and fvwm need this, it doesn't harm the rest
    3826             : 
    3827             :     // #i81311# do this only for sizable frames
    3828           0 :     if( (nStyle_ & SAL_FRAME_STYLE_SIZEABLE) != 0 )
    3829             :     {
    3830           0 :         Size aScreenSize = GetDisplay()->GetScreenSize( m_nXScreen );
    3831           0 :         int nScreenWidth  = aScreenSize.Width();
    3832           0 :         int nScreenHeight = aScreenSize.Height();
    3833           0 :         int nFrameWidth   = maGeometry.nWidth + maGeometry.nLeftDecoration + maGeometry.nRightDecoration;
    3834           0 :         int nFrameHeight  = maGeometry.nHeight + maGeometry.nTopDecoration  + maGeometry.nBottomDecoration;
    3835             : 
    3836           0 :         if ((nFrameWidth > nScreenWidth) || (nFrameHeight > nScreenHeight))
    3837             :         {
    3838           0 :             Size aSize(maGeometry.nWidth, maGeometry.nHeight);
    3839             : 
    3840           0 :             if (nFrameWidth  > nScreenWidth)
    3841           0 :                 aSize.Width()  = nScreenWidth  - maGeometry.nRightDecoration - maGeometry.nLeftDecoration;
    3842           0 :             if (nFrameHeight > nScreenHeight)
    3843           0 :                 aSize.Height() = nScreenHeight - maGeometry.nBottomDecoration - maGeometry.nTopDecoration;
    3844             : 
    3845           0 :             SetSize( aSize );
    3846           0 :             bResized = false;
    3847             :         }
    3848             :     }
    3849           0 :     if( bResized )
    3850           0 :         CallCallback( SALEVENT_RESIZE, NULL );
    3851             : 
    3852           0 :     GetGenericData()->ErrorTrapPop();
    3853             : 
    3854           0 :     return 1;
    3855             : }
    3856             : 
    3857           0 : long X11SalFrame::HandleColormapEvent( XColormapEvent* )
    3858             : {
    3859           0 :     return 0;
    3860             : }
    3861             : 
    3862           0 : long X11SalFrame::HandleStateEvent( XPropertyEvent *pEvent )
    3863             : {
    3864             :     Atom          actual_type;
    3865             :     int           actual_format;
    3866             :     unsigned long nitems, bytes_after;
    3867           0 :     unsigned char *prop = NULL;
    3868             : 
    3869           0 :     if( 0 != XGetWindowProperty( GetXDisplay(),
    3870             :                                  GetShellWindow(),
    3871             :                                  pEvent->atom,          // property
    3872             :                                  0,                     // long_offset (32bit)
    3873             :                                  2,                     // long_length (32bit)
    3874             :                                  False,                 // delete
    3875             :                                  pEvent->atom,          // req_type
    3876             :                                  &actual_type,
    3877             :                                  &actual_format,
    3878             :                                  &nitems,
    3879             :                                  &bytes_after,
    3880           0 :                                  &prop )
    3881           0 :         || ! prop
    3882             :         )
    3883           0 :         return 0;
    3884             : 
    3885             :     DBG_ASSERT( actual_type == pEvent->atom
    3886             :                 && 32 == actual_format
    3887             :                 &&  2 == nitems
    3888             :                 &&  0 == bytes_after, "HandleStateEvent" );
    3889             : 
    3890           0 :     if( *(unsigned long*)prop == NormalState )
    3891           0 :         nShowState_ = SHOWSTATE_NORMAL;
    3892           0 :     else if( *(unsigned long*)prop == IconicState )
    3893           0 :         nShowState_ = SHOWSTATE_MINIMIZED;
    3894             : 
    3895           0 :     XFree( prop );
    3896           0 :     return 1;
    3897             : }
    3898             : 
    3899           0 : long X11SalFrame::HandleClientMessage( XClientMessageEvent *pEvent )
    3900             : {
    3901           0 :     const WMAdaptor& rWMAdaptor( *pDisplay_->getWMAdaptor() );
    3902             : 
    3903             : #if !defined(__synchronous_extinput__)
    3904           0 :     if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::SAL_EXTTEXTEVENT ) )
    3905             :     {
    3906           0 :         HandleExtTextEvent (pEvent);
    3907           0 :         return 1;
    3908             :     }
    3909             : #endif
    3910           0 :     else if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::SAL_QUITEVENT ) )
    3911             :     {
    3912             :         stderr0( "X11SalFrame::Dispatch Quit\n" );
    3913           0 :         Close(); // ???
    3914           0 :         return 1;
    3915             :     }
    3916           0 :     else if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::WM_PROTOCOLS ) )
    3917             :     {
    3918           0 :         if( (Atom)pEvent->data.l[0] == rWMAdaptor.getAtom( WMAdaptor::NET_WM_PING ) )
    3919           0 :             rWMAdaptor.answerPing( this, pEvent );
    3920           0 :         else if( ! ( nStyle_ & SAL_FRAME_STYLE_PLUG )
    3921           0 :               && ! (( nStyle_ & SAL_FRAME_STYLE_FLOAT ) && (nStyle_ & SAL_FRAME_STYLE_OWNERDRAWDECORATION))
    3922             :              )
    3923             :         {
    3924           0 :             if( (Atom)pEvent->data.l[0] == rWMAdaptor.getAtom( WMAdaptor::WM_DELETE_WINDOW ) )
    3925             :             {
    3926           0 :                 Close();
    3927           0 :                 return 1;
    3928             :             }
    3929           0 :             else if( (Atom)pEvent->data.l[0] == rWMAdaptor.getAtom( WMAdaptor::WM_TAKE_FOCUS ) )
    3930             :             {
    3931             :                 // do nothing, we set the input focus in ToTop() if necessary
    3932             :     #if OSL_DEBUG_LEVEL > 1
    3933             :                 fprintf( stderr, "got WM_TAKE_FOCUS on %s window\n",
    3934             :                          (nStyle_&SAL_FRAME_STYLE_OWNERDRAWDECORATION) ?
    3935             :                          "ownerdraw" : "NON OWNERDRAW" );
    3936             :     #endif
    3937             :             }
    3938             :         }
    3939             :     }
    3940           0 :     else if( pEvent->message_type == rWMAdaptor.getAtom( WMAdaptor::XEMBED ) &&
    3941           0 :              pEvent->window == GetWindow() )
    3942             :     {
    3943           0 :         if( pEvent->data.l[1] == 1 || // XEMBED_WINDOW_ACTIVATE
    3944           0 :             pEvent->data.l[1] == 2 )  // XEMBED_WINDOW_DEACTIVATE
    3945             :         {
    3946             :             XFocusChangeEvent aEvent;
    3947           0 :             aEvent.type         = (pEvent->data.l[1] == 1 ? FocusIn : FocusOut);
    3948           0 :             aEvent.serial       = pEvent->serial;
    3949           0 :             aEvent.send_event   = True;
    3950           0 :             aEvent.display      = pEvent->display;
    3951           0 :             aEvent.window       = pEvent->window;
    3952           0 :             aEvent.mode         = NotifyNormal;
    3953           0 :             aEvent.detail       = NotifyDetailNone;
    3954           0 :             HandleFocusEvent( &aEvent );
    3955             :         }
    3956             :     }
    3957           0 :     return 0;
    3958             : }
    3959             : 
    3960             : extern "C"
    3961             : {
    3962           0 : Bool call_checkKeyReleaseForRepeat( Display* pDisplay, XEvent* pCheck, XPointer pX11SalFrame )
    3963             : {
    3964           0 :     return X11SalFrame::checkKeyReleaseForRepeat( pDisplay, pCheck, pX11SalFrame );
    3965             : }
    3966             : }
    3967             : 
    3968           0 : Bool X11SalFrame::checkKeyReleaseForRepeat( Display*, XEvent* pCheck, XPointer pX11SalFrame )
    3969             : {
    3970           0 :     X11SalFrame* pThis = (X11SalFrame*)pX11SalFrame;
    3971             :     return
    3972           0 :         pCheck->type            == KeyPress &&
    3973           0 :         pCheck->xkey.state      == pThis->nKeyState_ &&
    3974           0 :         pCheck->xkey.keycode    == pThis->nKeyCode_ &&
    3975           0 :         pCheck->xkey.time       == pThis->nReleaseTime_  ? True : False;
    3976             : }
    3977             : 
    3978           0 : long X11SalFrame::Dispatch( XEvent *pEvent )
    3979             : {
    3980           0 :     long nRet = 0;
    3981             : 
    3982           0 :     if( -1 == nCaptured_ )
    3983             :     {
    3984           0 :         CaptureMouse( true );
    3985             : #ifdef DBG_UTIL
    3986             :         if( -1 != nCaptured_ )
    3987             :             pDisplay_->DbgPrintDisplayEvent("Captured", pEvent);
    3988             : #endif
    3989             :     }
    3990             : 
    3991           0 :     if( pEvent->xany.window == GetShellWindow() || pEvent->xany.window == GetWindow() )
    3992             :     {
    3993           0 :         switch( pEvent->type )
    3994             :         {
    3995             :             case KeyPress:
    3996           0 :                 nKeyCode_   = pEvent->xkey.keycode;
    3997           0 :                 nKeyState_  = pEvent->xkey.state;
    3998           0 :                 nRet        = HandleKeyEvent( &pEvent->xkey );
    3999           0 :                 break;
    4000             : 
    4001             :             case KeyRelease:
    4002           0 :                 if( -1 == nCompose_ )
    4003             :                 {
    4004           0 :                     nReleaseTime_ = pEvent->xkey.time;
    4005             :                     XEvent aEvent;
    4006           0 :                     if( XCheckIfEvent( pEvent->xkey.display, &aEvent, call_checkKeyReleaseForRepeat, (XPointer)this ) )
    4007           0 :                         XPutBackEvent( pEvent->xkey.display, &aEvent );
    4008             :                     else
    4009           0 :                         nRet        = HandleKeyEvent( &pEvent->xkey );
    4010             :                 }
    4011           0 :             break;
    4012             : 
    4013             :             case ButtonPress:
    4014             :                 // if we lose the focus in presentation mode
    4015             :                 // there are good chances that we never get it back
    4016             :                 // since the WM ignores us
    4017           0 :                  if( IsOverrideRedirect() )
    4018             :                  {
    4019             :                      XSetInputFocus( GetXDisplay(), GetShellWindow(),
    4020           0 :                              RevertToNone, CurrentTime );
    4021             :                  }
    4022             :                 //fall-through
    4023             :             case ButtonRelease:
    4024             :             case MotionNotify:
    4025             :             case EnterNotify:
    4026             :             case LeaveNotify:
    4027           0 :                 nRet = HandleMouseEvent( pEvent );
    4028           0 :                 break;
    4029             : 
    4030             :             case FocusIn:
    4031             :             case FocusOut:
    4032           0 :                 nRet = HandleFocusEvent( &pEvent->xfocus );
    4033           0 :                 break;
    4034             : 
    4035             :             case Expose:
    4036             :             case GraphicsExpose:
    4037           0 :                 nRet = HandleExposeEvent( pEvent );
    4038           0 :                 break;
    4039             : 
    4040             :             case MapNotify:
    4041           0 :                 if( pEvent->xmap.window == GetShellWindow() )
    4042             :                 {
    4043           0 :                     if( nShowState_ == SHOWSTATE_HIDDEN )
    4044             :                     {
    4045             :                         /*
    4046             :                          *  workaround for (at least) KWin 2.2.2
    4047             :                          *  which will map windows that were once transient
    4048             :                          *  even if they are withdrawn when the respective
    4049             :                          *  document is mapped.
    4050             :                          */
    4051           0 :                         if( ! (nStyle_ & SAL_FRAME_STYLE_PLUG) )
    4052           0 :                             XUnmapWindow( GetXDisplay(), GetShellWindow() );
    4053           0 :                         break;
    4054             :                     }
    4055           0 :                     bMapped_   = true;
    4056           0 :                     bViewable_ = true;
    4057           0 :                     nRet = 1;
    4058           0 :                     if ( mpInputContext != NULL )
    4059           0 :                         mpInputContext->Map( this );
    4060           0 :                     CallCallback( SALEVENT_RESIZE, NULL );
    4061             : 
    4062           0 :                     bool bSetFocus = m_bSetFocusOnMap;
    4063             :                     /*  another workaround for sawfish: if a transient window for the same parent is shown
    4064             :                      *  sawfish does not set the focus to it. Applies only for click to focus mode.
    4065             :                      */
    4066           0 :                     if( ! (nStyle_ & SAL_FRAME_STYLE_FLOAT ) && mbInShow && GetDisplay()->getWMAdaptor()->getWindowManagerName().equalsAscii( "Sawfish" ) )
    4067             :                     {
    4068             :                         // don't set the focus into the IME status window
    4069             :                         // since this will lead to a parent loss of focus, close status,
    4070             :                         // reget focus, open status, .... flicker loop
    4071           0 :                         if ( (vcl::I18NStatus::get().getStatusFrame() != this) )
    4072           0 :                             bSetFocus = true;
    4073             :                     }
    4074             : 
    4075             :                     /*
    4076             :                      *  sometimes a message box/dialogue is brought up when a frame is not mapped
    4077             :                      *  the corresponding TRANSIENT_FOR hint is then set to the root window
    4078             :                      *  so that the dialogue shows in all cases. Correct it here if the
    4079             :                      *  frame is shown afterwards.
    4080             :                      */
    4081           0 :                     if( ! IsChildWindow()
    4082           0 :                         && ! IsOverrideRedirect()
    4083           0 :                         && ! IsFloatGrabWindow()
    4084             :                         )
    4085             :                     {
    4086           0 :                         for( std::list< X11SalFrame* >::const_iterator it = maChildren.begin();
    4087           0 :                              it != maChildren.end(); ++it )
    4088             :                         {
    4089           0 :                             if( (*it)->mbTransientForRoot )
    4090           0 :                                 pDisplay_->getWMAdaptor()->changeReferenceFrame( *it, this );
    4091             :                         }
    4092             :                     }
    4093             : 
    4094           0 :                     if( hPresentationWindow != None && GetShellWindow() == hPresentationWindow )
    4095           0 :                         XSetInputFocus( GetXDisplay(), GetShellWindow(), RevertToParent, CurrentTime );
    4096             : 
    4097           0 :                     if( bSetFocus )
    4098             :                     {
    4099             :                         XSetInputFocus( GetXDisplay(),
    4100             :                                         GetShellWindow(),
    4101             :                                         RevertToParent,
    4102           0 :                                         CurrentTime );
    4103             :                     }
    4104             : 
    4105           0 :                     RestackChildren();
    4106           0 :                     mbInShow = false;
    4107           0 :                     m_bSetFocusOnMap = false;
    4108             :                 }
    4109           0 :                 break;
    4110             : 
    4111             :             case UnmapNotify:
    4112           0 :                 if( pEvent->xunmap.window == GetShellWindow() )
    4113             :                 {
    4114           0 :                     bMapped_   = false;
    4115           0 :                     bViewable_ = false;
    4116           0 :                     nRet = 1;
    4117           0 :                     if ( mpInputContext != NULL )
    4118           0 :                         mpInputContext->Unmap( this );
    4119           0 :                     CallCallback( SALEVENT_RESIZE, NULL );
    4120             :                 }
    4121           0 :                 break;
    4122             : 
    4123             :             case ConfigureNotify:
    4124           0 :                 if( pEvent->xconfigure.window == GetShellWindow()
    4125           0 :                     || pEvent->xconfigure.window == GetWindow() )
    4126           0 :                     nRet = HandleSizeEvent( &pEvent->xconfigure );
    4127           0 :                 break;
    4128             : 
    4129             :             case VisibilityNotify:
    4130           0 :                 nVisibility_ = pEvent->xvisibility.state;
    4131           0 :                 nRet = 1;
    4132           0 :                 if( bAlwaysOnTop_
    4133           0 :                     && bMapped_
    4134           0 :                     && ! GetDisplay()->getWMAdaptor()->isAlwaysOnTopOK()
    4135           0 :                     && nVisibility_ != VisibilityUnobscured )
    4136           0 :                     maAlwaysOnTopRaiseTimer.Start();
    4137           0 :             break;
    4138             : 
    4139             :             case ReparentNotify:
    4140           0 :                 nRet = HandleReparentEvent( &pEvent->xreparent );
    4141           0 :                 break;
    4142             : 
    4143             :             case MappingNotify:
    4144           0 :                 if( MappingPointer != pEvent->xmapping.request )
    4145           0 :                     nRet = CallCallback( SALEVENT_KEYBOARDCHANGED, 0 );
    4146           0 :                 break;
    4147             : 
    4148             :             case ColormapNotify:
    4149           0 :                 nRet = HandleColormapEvent( &pEvent->xcolormap );
    4150           0 :                 break;
    4151             : 
    4152             :             case PropertyNotify:
    4153             :             {
    4154           0 :                 if( pEvent->xproperty.atom == pDisplay_->getWMAdaptor()->getAtom( WMAdaptor::WM_STATE ) )
    4155           0 :                     nRet = HandleStateEvent( &pEvent->xproperty );
    4156             :                 else
    4157           0 :                     nRet = pDisplay_->getWMAdaptor()->handlePropertyNotify( this, &pEvent->xproperty );
    4158           0 :                 break;
    4159             :             }
    4160             : 
    4161             :             case ClientMessage:
    4162           0 :                 nRet = HandleClientMessage( &pEvent->xclient );
    4163           0 :                 break;
    4164             :         }
    4165             :     }
    4166             :     else
    4167             :     {
    4168           0 :         switch( pEvent->type )
    4169             :         {
    4170             :              case FocusIn:
    4171             :              case FocusOut:
    4172           0 :                 if( ( nStyle_ & SAL_FRAME_STYLE_PLUG )
    4173           0 :                     && ( pEvent->xfocus.window == GetShellWindow()
    4174           0 :                          || pEvent->xfocus.window == GetForeignParent() )
    4175             :                     )
    4176             :                 {
    4177           0 :                     nRet = HandleFocusEvent( &pEvent->xfocus );
    4178             :                 }
    4179           0 :                  break;
    4180             : 
    4181             :             case ConfigureNotify:
    4182           0 :                 if( pEvent->xconfigure.window == GetForeignParent() ||
    4183           0 :                     pEvent->xconfigure.window == GetShellWindow() )
    4184           0 :                     nRet = HandleSizeEvent( &pEvent->xconfigure );
    4185             : 
    4186           0 :                 if( pEvent->xconfigure.window == GetStackingWindow() )
    4187           0 :                     nRet = HandleSizeEvent( &pEvent->xconfigure );
    4188             : 
    4189           0 :                 RestackChildren();
    4190           0 :                 break;
    4191             :         }
    4192             :     }
    4193             : 
    4194           0 :     return nRet;
    4195             : }
    4196             : 
    4197           0 : void X11SalFrame::ResetClipRegion()
    4198             : {
    4199           0 :     delete [] m_pClipRectangles;
    4200           0 :     m_pClipRectangles = NULL;
    4201           0 :     m_nCurClipRect = m_nMaxClipRect = 0;
    4202             : 
    4203           0 :     const int   dest_kind   = ShapeBounding;
    4204           0 :     const int   op          = ShapeSet;
    4205           0 :     const int   ordering    = YSorted;
    4206             : 
    4207             :     XWindowAttributes win_attrib;
    4208             :     XRectangle        win_size;
    4209             : 
    4210           0 :     ::Window aShapeWindow = mhShellWindow;
    4211             : 
    4212             :     XGetWindowAttributes ( GetDisplay()->GetDisplay(),
    4213             :                            aShapeWindow,
    4214           0 :                            &win_attrib );
    4215             : 
    4216           0 :     win_size.x      = 0;
    4217           0 :     win_size.y      = 0;
    4218           0 :     win_size.width  = win_attrib.width;
    4219           0 :     win_size.height = win_attrib.height;
    4220             : 
    4221             :     XShapeCombineRectangles ( GetDisplay()->GetDisplay(),
    4222             :                               aShapeWindow,
    4223             :                               dest_kind,
    4224             :                               0, 0,             // x_off, y_off
    4225             :                               &win_size,        // list of rectangles
    4226             :                               1,                // number of rectangles
    4227           0 :                               op, ordering );
    4228           0 : }
    4229             : 
    4230           0 : void X11SalFrame::BeginSetClipRegion( sal_uLong nRects )
    4231             : {
    4232           0 :     if( m_pClipRectangles )
    4233           0 :         delete [] m_pClipRectangles;
    4234           0 :     if( nRects )
    4235           0 :         m_pClipRectangles = new XRectangle[nRects];
    4236             :     else
    4237           0 :         m_pClipRectangles = NULL;
    4238           0 :     m_nMaxClipRect = static_cast<int>(nRects);
    4239           0 :     m_nCurClipRect = 0;
    4240           0 : }
    4241             : 
    4242           0 : void X11SalFrame::UnionClipRegion( long nX, long nY, long nWidth, long nHeight )
    4243             : {
    4244           0 :     if( m_pClipRectangles && m_nCurClipRect < m_nMaxClipRect )
    4245             :     {
    4246           0 :         m_pClipRectangles[m_nCurClipRect].x      = nX;
    4247           0 :         m_pClipRectangles[m_nCurClipRect].y      = nY;
    4248           0 :         m_pClipRectangles[m_nCurClipRect].width  = nWidth;
    4249           0 :         m_pClipRectangles[m_nCurClipRect].height = nHeight;
    4250           0 :         m_nCurClipRect++;
    4251             :     }
    4252           0 : }
    4253             : 
    4254           0 : void X11SalFrame::EndSetClipRegion()
    4255             : {
    4256           0 :     const int   dest_kind   = ShapeBounding;
    4257           0 :     const int   ordering    = YSorted;
    4258           0 :     const int   op = ShapeSet;
    4259             : 
    4260           0 :     ::Window aShapeWindow = mhShellWindow;
    4261             :     XShapeCombineRectangles ( GetDisplay()->GetDisplay(),
    4262             :                               aShapeWindow,
    4263             :                               dest_kind,
    4264             :                               0, 0, // x_off, y_off
    4265             :                               m_pClipRectangles,
    4266             :                               m_nCurClipRect,
    4267           0 :                               op, ordering );
    4268             : 
    4269           0 : }
    4270             : 
    4271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10