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

Generated by: LCOV version 1.10