LCOV - code coverage report
Current view: top level - vcl/source/window - winproc.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 149 1273 11.7 %
Date: 2014-11-03 Functions: 13 55 23.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <tools/debug.hxx>
      21             : #include <tools/time.hxx>
      22             : 
      23             : #include <unotools/localedatawrapper.hxx>
      24             : 
      25             : #include <vcl/i18nhelp.hxx>
      26             : #include <vcl/unohelp.hxx>
      27             : #include <vcl/timer.hxx>
      28             : #include <vcl/event.hxx>
      29             : #include <vcl/settings.hxx>
      30             : #include <vcl/svapp.hxx>
      31             : #include <vcl/cursor.hxx>
      32             : #include <vcl/wrkwin.hxx>
      33             : #include <vcl/floatwin.hxx>
      34             : #include <vcl/dialog.hxx>
      35             : #include <vcl/help.hxx>
      36             : #include <vcl/dockwin.hxx>
      37             : #include <vcl/menu.hxx>
      38             : #include <touch/touch.h>
      39             : 
      40             : #include <svdata.hxx>
      41             : #include <dbggui.hxx>
      42             : #include <salwtype.hxx>
      43             : #include <salframe.hxx>
      44             : #include <accmgr.hxx>
      45             : #include <print.h>
      46             : #include <window.h>
      47             : #include <helpwin.hxx>
      48             : #include <brdwin.hxx>
      49             : #include <salgdi.hxx>
      50             : #include <dndlcon.hxx>
      51             : 
      52             : #include <com/sun/star/datatransfer/dnd/XDragSource.hpp>
      53             : #include <com/sun/star/awt/MouseEvent.hpp>
      54             : 
      55             : #define IMPL_MIN_NEEDSYSWIN         49
      56             : 
      57       55889 : bool ImplCallPreNotify( NotifyEvent& rEvt )
      58             : {
      59       55889 :     return Application::CallEventHooks( rEvt )
      60       55889 :         || rEvt.GetWindow()->PreNotify( rEvt );
      61             : }
      62             : 
      63           0 : static bool ImplHandleMouseFloatMode( vcl::Window* pChild, const Point& rMousePos,
      64             :                                       sal_uInt16 nCode, sal_uInt16 nSVEvent,
      65             :                                       bool bMouseLeave )
      66             : {
      67           0 :     ImplSVData* pSVData = ImplGetSVData();
      68             : 
      69           0 :     if ( pSVData->maWinData.mpFirstFloat && !pSVData->maWinData.mpCaptureWin &&
      70           0 :          !pSVData->maWinData.mpFirstFloat->ImplIsFloatPopupModeWindow( pChild ) )
      71             :     {
      72             :         /*
      73             :          *  #93895# since floats are system windows, coordinates have
      74             :          *  to be converted to float relative for the hittest
      75             :          */
      76           0 :         HitTest         nHitTest = HITTEST_OUTSIDE;
      77           0 :         FloatingWindow* pFloat = pSVData->maWinData.mpFirstFloat->ImplFloatHitTest( pChild, rMousePos, nHitTest );
      78             :         FloatingWindow* pLastLevelFloat;
      79             :         sal_uLong           nPopupFlags;
      80           0 :         if ( nSVEvent == EVENT_MOUSEMOVE )
      81             :         {
      82           0 :             if ( bMouseLeave )
      83           0 :                 return true;
      84             : 
      85           0 :             if ( !pFloat || (nHitTest == HITTEST_RECT) )
      86             :             {
      87           0 :                 if ( pSVData->maHelpData.mpHelpWin && !pSVData->maHelpData.mbKeyboardHelp )
      88           0 :                     ImplDestroyHelpWindow( true );
      89           0 :                 pChild->ImplGetFrame()->SetPointer( POINTER_ARROW );
      90           0 :                 return true;
      91             :             }
      92             :         }
      93             :         else
      94             :         {
      95           0 :             if ( nCode & MOUSE_LEFT )
      96             :             {
      97           0 :                 if ( nSVEvent == EVENT_MOUSEBUTTONDOWN )
      98             :                 {
      99           0 :                     if ( !pFloat )
     100             :                     {
     101           0 :                         pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
     102           0 :                         nPopupFlags = pLastLevelFloat->GetPopupModeFlags();
     103           0 :                         pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
     104           0 :                         return true;
     105             :                     }
     106           0 :                     else if ( nHitTest == HITTEST_RECT )
     107             :                     {
     108           0 :                         if ( !(pFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOMOUSERECTCLOSE) )
     109           0 :                             pFloat->ImplSetMouseDown();
     110           0 :                         return true;
     111             :                     }
     112             :                 }
     113             :                 else
     114             :                 {
     115           0 :                     if ( pFloat )
     116             :                     {
     117           0 :                         if ( nHitTest == HITTEST_RECT )
     118             :                         {
     119           0 :                             if ( pFloat->ImplIsMouseDown() )
     120           0 :                                 pFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL );
     121           0 :                             return true;
     122             :                         }
     123             :                     }
     124             :                     else
     125             :                     {
     126           0 :                         pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
     127           0 :                         nPopupFlags = pLastLevelFloat->GetPopupModeFlags();
     128           0 :                         if ( !(nPopupFlags & FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE) )
     129             :                         {
     130           0 :                             pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
     131           0 :                             return true;
     132             :                         }
     133             :                     }
     134             :                 }
     135             :             }
     136             :             else
     137             :             {
     138           0 :                 if ( !pFloat )
     139             :                 {
     140           0 :                     pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
     141           0 :                     nPopupFlags = pLastLevelFloat->GetPopupModeFlags();
     142           0 :                     if ( nPopupFlags & FLOATWIN_POPUPMODE_ALLMOUSEBUTTONCLOSE )
     143             :                     {
     144           0 :                         if ( (nPopupFlags & FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE) &&
     145             :                              (nSVEvent == EVENT_MOUSEBUTTONUP) )
     146           0 :                             return true;
     147           0 :                         pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
     148           0 :                         if ( nPopupFlags & FLOATWIN_POPUPMODE_PATHMOUSECANCELCLICK )
     149           0 :                             return false;
     150             :                         else
     151           0 :                             return true;
     152             :                     }
     153             :                     else
     154           0 :                         return true;
     155             :                 }
     156             :             }
     157             :         }
     158             :     }
     159             : 
     160           0 :     return false;
     161             : }
     162             : 
     163           0 : static void ImplHandleMouseHelpRequest( vcl::Window* pChild, const Point& rMousePos )
     164             : {
     165           0 :     ImplSVData* pSVData = ImplGetSVData();
     166           0 :     if ( !pSVData->maHelpData.mpHelpWin ||
     167           0 :          !( pSVData->maHelpData.mpHelpWin->IsWindowOrChild( pChild ) ||
     168           0 :            pChild->IsWindowOrChild( pSVData->maHelpData.mpHelpWin ) ) )
     169             :     {
     170           0 :         sal_uInt16 nHelpMode = 0;
     171           0 :         if ( pSVData->maHelpData.mbQuickHelp )
     172           0 :             nHelpMode = HELPMODE_QUICK;
     173           0 :         if ( pSVData->maHelpData.mbBalloonHelp )
     174           0 :             nHelpMode |= HELPMODE_BALLOON;
     175           0 :         if ( nHelpMode )
     176             :         {
     177           0 :             if ( pChild->IsInputEnabled() && !pChild->IsInModalNonRefMode() )
     178             :             {
     179           0 :                 HelpEvent aHelpEvent( rMousePos, nHelpMode );
     180           0 :                 pSVData->maHelpData.mbRequestingHelp = true;
     181           0 :                 pChild->RequestHelp( aHelpEvent );
     182           0 :                 pSVData->maHelpData.mbRequestingHelp = false;
     183             :             }
     184             :             // #104172# do not kill keyboard activated tooltips
     185           0 :             else if ( pSVData->maHelpData.mpHelpWin && !pSVData->maHelpData.mbKeyboardHelp)
     186             :             {
     187           0 :                 ImplDestroyHelpWindow( true );
     188             :             }
     189             :         }
     190             :     }
     191           0 : }
     192             : 
     193           0 : static void ImplSetMousePointer( vcl::Window* pChild )
     194             : {
     195           0 :     ImplSVData* pSVData = ImplGetSVData();
     196           0 :     if ( pSVData->maHelpData.mbExtHelpMode )
     197           0 :         pChild->ImplGetFrame()->SetPointer( POINTER_HELP );
     198             :     else
     199           0 :         pChild->ImplGetFrame()->SetPointer( pChild->ImplGetMousePointer() );
     200           0 : }
     201             : 
     202           0 : static bool ImplCallCommand( vcl::Window* pChild, sal_uInt16 nEvt, void* pData = NULL,
     203             :                              bool bMouse = false, Point* pPos = NULL )
     204             : {
     205           0 :     Point aPos;
     206           0 :     if ( pPos )
     207           0 :         aPos = *pPos;
     208             :     else
     209             :     {
     210           0 :         if( bMouse )
     211           0 :             aPos = pChild->GetPointerPosPixel();
     212             :         else
     213             :         {
     214             :             // simulate mouseposition at center of window
     215           0 :             Size aSize( pChild->GetOutputSizePixel() );
     216           0 :             aPos = Point( aSize.getWidth()/2, aSize.getHeight()/2 );
     217             :         }
     218             :     }
     219             : 
     220           0 :     CommandEvent    aCEvt( aPos, nEvt, bMouse, pData );
     221           0 :     NotifyEvent     aNCmdEvt( EVENT_COMMAND, pChild, &aCEvt );
     222           0 :     ImplDelData     aDelData( pChild );
     223           0 :     bool bPreNotify = ImplCallPreNotify( aNCmdEvt );
     224           0 :     if ( aDelData.IsDead() )
     225           0 :         return false;
     226           0 :     if ( !bPreNotify )
     227             :     {
     228           0 :         pChild->ImplGetWindowImpl()->mbCommand = false;
     229           0 :         pChild->Command( aCEvt );
     230             : 
     231           0 :         if( aDelData.IsDead() )
     232           0 :             return false;
     233           0 :         pChild->ImplNotifyKeyMouseCommandEventListeners( aNCmdEvt );
     234           0 :         if ( aDelData.IsDead() )
     235           0 :             return false;
     236           0 :         if ( pChild->ImplGetWindowImpl()->mbCommand )
     237           0 :             return true;
     238             :     }
     239             : 
     240           0 :     return false;
     241             : }
     242             : 
     243             : /*  #i34277# delayed context menu activation;
     244             : *   necessary if there already was a popup menu running.
     245             : */
     246             : 
     247           0 : struct ContextMenuEvent
     248             : {
     249             :     vcl::Window*         pWindow;
     250             :     ImplDelData     aDelData;
     251             :     Point           aChildPos;
     252             : };
     253             : 
     254           0 : static long ContextMenuEventLink( void* pCEvent, void* )
     255             : {
     256           0 :     ContextMenuEvent* pEv = (ContextMenuEvent*)pCEvent;
     257             : 
     258           0 :     if( ! pEv->aDelData.IsDead() )
     259             :     {
     260           0 :         pEv->pWindow->ImplRemoveDel( &pEv->aDelData );
     261           0 :         ImplCallCommand( pEv->pWindow, COMMAND_CONTEXTMENU, NULL, true, &pEv->aChildPos );
     262             :     }
     263           0 :     delete pEv;
     264             : 
     265           0 :     return 0;
     266             : }
     267             : 
     268           0 : bool ImplHandleMouseEvent( vcl::Window* pWindow, sal_uInt16 nSVEvent, bool bMouseLeave,
     269             :                            long nX, long nY, sal_uLong nMsgTime,
     270             :                            sal_uInt16 nCode, sal_uInt16 nMode )
     271             : {
     272           0 :     ImplSVData* pSVData = ImplGetSVData();
     273           0 :     Point       aMousePos( nX, nY );
     274           0 :     vcl::Window*     pChild(NULL);
     275           0 :     bool        bRet(false);
     276           0 :     sal_uInt16  nClicks(0);
     277           0 :     ImplFrameData* pWinFrameData = pWindow->ImplGetFrameData();
     278           0 :     sal_uInt16      nOldCode = pWinFrameData->mnMouseCode;
     279             : 
     280             :     // we need a mousemove event, before we get a mousebuttondown or a
     281             :     // mousebuttonup event
     282           0 :     if ( (nSVEvent == EVENT_MOUSEBUTTONDOWN) || (nSVEvent == EVENT_MOUSEBUTTONUP) )
     283             :     {
     284           0 :         if ( (nSVEvent == EVENT_MOUSEBUTTONUP) && pSVData->maHelpData.mbExtHelpMode )
     285           0 :             Help::EndExtHelp();
     286           0 :         if ( pSVData->maHelpData.mpHelpWin )
     287             :         {
     288           0 :             if( pWindow->ImplGetWindow() == pSVData->maHelpData.mpHelpWin )
     289             :             {
     290           0 :                 ImplDestroyHelpWindow( false );
     291           0 :                 return true; // pWindow is dead now - avoid crash!
     292             :             }
     293             :             else
     294           0 :                 ImplDestroyHelpWindow( true );
     295             :         }
     296             : 
     297           0 :         if ( (pWinFrameData->mnLastMouseX != nX) ||
     298           0 :              (pWinFrameData->mnLastMouseY != nY) )
     299             :         {
     300           0 :             ImplHandleMouseEvent( pWindow, EVENT_MOUSEMOVE, false, nX, nY, nMsgTime, nCode, nMode );
     301             :         }
     302             :     }
     303             : 
     304             :     // update frame data
     305           0 :     pWinFrameData->mnBeforeLastMouseX = pWinFrameData->mnLastMouseX;
     306           0 :     pWinFrameData->mnBeforeLastMouseY = pWinFrameData->mnLastMouseY;
     307           0 :     pWinFrameData->mnLastMouseX = nX;
     308           0 :     pWinFrameData->mnLastMouseY = nY;
     309           0 :     pWinFrameData->mnMouseCode  = nCode;
     310           0 :     pWinFrameData->mnMouseMode  = nMode & ~(MOUSE_SYNTHETIC | MOUSE_MODIFIERCHANGED);
     311           0 :     if ( bMouseLeave )
     312             :     {
     313           0 :         pWinFrameData->mbMouseIn = false;
     314           0 :         if ( pSVData->maHelpData.mpHelpWin && !pSVData->maHelpData.mbKeyboardHelp )
     315             :         {
     316           0 :             ImplDelData aDelData( pWindow );
     317             : 
     318           0 :             ImplDestroyHelpWindow( true );
     319             : 
     320           0 :             if ( aDelData.IsDead() )
     321           0 :                 return true; // pWindow is dead now - avoid crash! (#122045#)
     322             :         }
     323             :     }
     324             :     else
     325           0 :         pWinFrameData->mbMouseIn = true;
     326             : 
     327             :     DBG_ASSERT( !pSVData->maWinData.mpTrackWin ||
     328             :                 (pSVData->maWinData.mpTrackWin == pSVData->maWinData.mpCaptureWin),
     329             :                 "ImplHandleMouseEvent: TrackWin != CaptureWin" );
     330             : 
     331             :     // AutoScrollMode
     332           0 :     if ( pSVData->maWinData.mpAutoScrollWin && (nSVEvent == EVENT_MOUSEBUTTONDOWN) )
     333             :     {
     334           0 :         pSVData->maWinData.mpAutoScrollWin->EndAutoScroll();
     335           0 :         return true;
     336             :     }
     337             : 
     338             :     // find mouse window
     339           0 :     if ( pSVData->maWinData.mpCaptureWin )
     340             :     {
     341           0 :         pChild = pSVData->maWinData.mpCaptureWin;
     342             : 
     343             :         DBG_ASSERT( pWindow == pChild->ImplGetFrameWindow(),
     344             :                     "ImplHandleMouseEvent: mouse event is not sent to capture window" );
     345             : 
     346             :         // java client cannot capture mouse correctly
     347           0 :         if ( pWindow != pChild->ImplGetFrameWindow() )
     348           0 :             return false;
     349             : 
     350           0 :         if ( bMouseLeave )
     351           0 :             return false;
     352             :     }
     353             :     else
     354             :     {
     355           0 :         if ( bMouseLeave )
     356           0 :             pChild = NULL;
     357             :         else
     358           0 :             pChild = pWindow->ImplFindWindow( aMousePos );
     359             :     }
     360             : 
     361             :     // test this because mouse events are buffered in the remote version
     362             :     // and size may not be in sync
     363           0 :     if ( !pChild && !bMouseLeave )
     364           0 :         return false;
     365             : 
     366             :     // execute a few tests and catch the message or implement the status
     367           0 :     if ( pChild )
     368             :     {
     369           0 :         if( pChild->ImplIsAntiparallel() )
     370             :         {
     371             :             // - RTL - re-mirror frame pos at pChild
     372           0 :             const OutputDevice *pChildWinOutDev = pChild->GetOutDev();
     373           0 :             pChildWinOutDev->ReMirror( aMousePos );
     374             :         }
     375             :         // no mouse messages to system object windows ?
     376             :         // !!!KA: Is it OK to comment this out? !!!
     377             : //        if ( pChild->ImplGetWindowImpl()->mpSysObj )
     378             : //            return false;
     379             : 
     380             :         // no mouse messages to disabled windows
     381             :         // #106845# if the window was disabed during capturing we have to pass the mouse events to release capturing
     382           0 :         if ( pSVData->maWinData.mpCaptureWin != pChild && (!pChild->IsEnabled() || !pChild->IsInputEnabled() || pChild->IsInModalNonRefMode() ) )
     383             :         {
     384           0 :             ImplHandleMouseFloatMode( pChild, aMousePos, nCode, nSVEvent, bMouseLeave );
     385           0 :             if ( nSVEvent == EVENT_MOUSEMOVE )
     386             :             {
     387           0 :                 ImplHandleMouseHelpRequest( pChild, aMousePos );
     388           0 :                 if( pWinFrameData->mpMouseMoveWin != pChild )
     389           0 :                     nMode |= MOUSE_ENTERWINDOW;
     390             :             }
     391             : 
     392             :             // Call the hook also, if Window is disabled
     393           0 :             Point aChildPos = pChild->ImplFrameToOutput( aMousePos );
     394           0 :             MouseEvent aMEvt( aChildPos, pWinFrameData->mnClickCount, nMode, nCode, nCode );
     395           0 :             NotifyEvent aNEvt( nSVEvent, pChild, &aMEvt );
     396           0 :             Application::CallEventHooks( aNEvt );
     397             : 
     398           0 :             if( pChild->IsCallHandlersOnInputDisabled() )
     399             :             {
     400           0 :                 pWinFrameData->mpMouseMoveWin = pChild;
     401           0 :                 pChild->ImplNotifyKeyMouseCommandEventListeners( aNEvt );
     402             :             }
     403             : 
     404           0 :             if ( nSVEvent == EVENT_MOUSEBUTTONDOWN )
     405           0 :                 return true;
     406             :             else
     407             :             {
     408             :                 // Set normal MousePointer for disabled windows
     409           0 :                 if ( nSVEvent == EVENT_MOUSEMOVE )
     410           0 :                     ImplSetMousePointer( pChild );
     411             : 
     412           0 :                 return false;
     413             :             }
     414             :         }
     415             : 
     416             :         // End ExtTextInput-Mode, if the user click in the same TopLevel Window
     417           0 :         if ( pSVData->maWinData.mpExtTextInputWin &&
     418           0 :              ((nSVEvent == EVENT_MOUSEBUTTONDOWN) ||
     419             :               (nSVEvent == EVENT_MOUSEBUTTONUP)) )
     420           0 :             pSVData->maWinData.mpExtTextInputWin->EndExtTextInput( EXTTEXTINPUT_END_COMPLETE );
     421             :     }
     422             : 
     423             :     // determine mouse event data
     424           0 :     if ( nSVEvent == EVENT_MOUSEMOVE )
     425             :     {
     426             :         // check if MouseMove belongs to same window and if the
     427             :         // status did not change
     428           0 :         if ( pChild )
     429             :         {
     430           0 :             Point aChildMousePos = pChild->ImplFrameToOutput( aMousePos );
     431           0 :             if ( !bMouseLeave &&
     432           0 :                  (pChild == pWinFrameData->mpMouseMoveWin) &&
     433           0 :                  (aChildMousePos.X() == pWinFrameData->mnLastMouseWinX) &&
     434           0 :                  (aChildMousePos.Y() == pWinFrameData->mnLastMouseWinY) &&
     435           0 :                  (nOldCode == pWinFrameData->mnMouseCode) )
     436             :             {
     437             :                 // set mouse pointer anew, as it could have changed
     438             :                 // due to the mode switch
     439           0 :                 ImplSetMousePointer( pChild );
     440           0 :                 return false;
     441             :             }
     442             : 
     443           0 :             pWinFrameData->mnLastMouseWinX = aChildMousePos.X();
     444           0 :             pWinFrameData->mnLastMouseWinY = aChildMousePos.Y();
     445             :         }
     446             : 
     447             :         // mouse click
     448           0 :         nClicks = pWinFrameData->mnClickCount;
     449             : 
     450             :         // call Start-Drag handler if required
     451             :         // Warning: should be called before Move, as otherwise during
     452             :         // fast mouse movements the applications move to the selection state
     453           0 :         vcl::Window* pMouseDownWin = pWinFrameData->mpMouseDownWin;
     454           0 :         if ( pMouseDownWin )
     455             :         {
     456             :             // check for matching StartDrag mode. We only compare
     457             :             // the status of the mouse buttons, such that e. g. Mod1 can
     458             :             // change immediately to the copy mode
     459           0 :             const MouseSettings& rMSettings = pMouseDownWin->GetSettings().GetMouseSettings();
     460           0 :             if ( (nCode & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)) ==
     461           0 :                  (rMSettings.GetStartDragCode() & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)) )
     462             :             {
     463           0 :                 if ( !pMouseDownWin->ImplGetFrameData()->mbStartDragCalled )
     464             :                 {
     465           0 :                     long nDragW  = rMSettings.GetStartDragWidth();
     466           0 :                     long nDragH  = rMSettings.GetStartDragWidth();
     467             :                     //long nMouseX = nX;
     468             :                     //long nMouseY = nY;
     469           0 :                     long nMouseX = aMousePos.X(); // #106074# use the possibly re-mirrored coordinates (RTL) ! nX,nY are unmodified !
     470           0 :                     long nMouseY = aMousePos.Y();
     471           0 :                     if ( !(((nMouseX-nDragW) <= pMouseDownWin->ImplGetFrameData()->mnFirstMouseX) &&
     472           0 :                            ((nMouseX+nDragW) >= pMouseDownWin->ImplGetFrameData()->mnFirstMouseX)) ||
     473           0 :                          !(((nMouseY-nDragH) <= pMouseDownWin->ImplGetFrameData()->mnFirstMouseY) &&
     474           0 :                            ((nMouseY+nDragH) >= pMouseDownWin->ImplGetFrameData()->mnFirstMouseY)) )
     475             :                     {
     476           0 :                         pMouseDownWin->ImplGetFrameData()->mbStartDragCalled  = true;
     477             : 
     478             :                         // Check if drag source provides it's own recognizer
     479           0 :                         if( pMouseDownWin->ImplGetFrameData()->mbInternalDragGestureRecognizer )
     480             :                         {
     481             :                             // query DropTarget from child window
     482             :                             ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer > xDragGestureRecognizer =
     483           0 :                                 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragGestureRecognizer > ( pMouseDownWin->ImplGetWindowImpl()->mxDNDListenerContainer,
     484           0 :                                     ::com::sun::star::uno::UNO_QUERY );
     485             : 
     486           0 :                             if( xDragGestureRecognizer.is() )
     487             :                             {
     488             :                                 // retrieve mouse position relative to mouse down window
     489             :                                 Point relLoc = pMouseDownWin->ImplFrameToOutput( Point(
     490           0 :                                     pMouseDownWin->ImplGetFrameData()->mnFirstMouseX,
     491           0 :                                     pMouseDownWin->ImplGetFrameData()->mnFirstMouseY ) );
     492             : 
     493             :                                 // create a uno mouse event out of the available data
     494             :                                 ::com::sun::star::awt::MouseEvent aMouseEvent(
     495             :                                     static_cast < ::com::sun::star::uno::XInterface * > ( 0 ),
     496             : #ifdef MACOSX
     497             :                     nCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3),
     498             : #else
     499             :                                     nCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2),
     500             : #endif
     501             :                                     nCode & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE),
     502             :                                     nMouseX,
     503             :                                     nMouseY,
     504             :                                     nClicks,
     505           0 :                                     false );
     506             : 
     507           0 :                                 sal_uLong nCount = Application::ReleaseSolarMutex();
     508             : 
     509             :                                 // FIXME: where do I get Action from ?
     510           0 :                                 ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::dnd::XDragSource > xDragSource = pMouseDownWin->GetDragSource();
     511             : 
     512           0 :                                 if( xDragSource.is() )
     513             :                                 {
     514           0 :                                     static_cast < DNDListenerContainer * > ( xDragGestureRecognizer.get() )->fireDragGestureEvent( 0,
     515           0 :                                         relLoc.X(), relLoc.Y(), xDragSource, ::com::sun::star::uno::makeAny( aMouseEvent ) );
     516             :                                 }
     517             : 
     518           0 :                                 Application::AcquireSolarMutex( nCount );
     519           0 :                             }
     520             :                         }
     521             :                     }
     522             :                 }
     523             :             }
     524             :             else
     525           0 :                 pMouseDownWin->ImplGetFrameData()->mbStartDragCalled  = true;
     526             :         }
     527             : 
     528             :         // test for mouseleave and mouseenter
     529           0 :         vcl::Window* pMouseMoveWin = pWinFrameData->mpMouseMoveWin;
     530           0 :         if ( pChild != pMouseMoveWin )
     531             :         {
     532           0 :             if ( pMouseMoveWin )
     533             :             {
     534           0 :                 Point       aLeaveMousePos = pMouseMoveWin->ImplFrameToOutput( aMousePos );
     535           0 :                 MouseEvent  aMLeaveEvt( aLeaveMousePos, nClicks, nMode | MOUSE_LEAVEWINDOW, nCode, nCode );
     536           0 :                 NotifyEvent aNLeaveEvt( EVENT_MOUSEMOVE, pMouseMoveWin, &aMLeaveEvt );
     537           0 :                 ImplDelData aDelData;
     538           0 :                 ImplDelData aDelData2;
     539           0 :                 pWinFrameData->mbInMouseMove = true;
     540           0 :                 pMouseMoveWin->ImplGetWinData()->mbMouseOver = false;
     541           0 :                 pMouseMoveWin->ImplAddDel( &aDelData );
     542             : 
     543             :                 // A MouseLeave can destroy this window
     544           0 :                 if ( pChild )
     545           0 :                     pChild->ImplAddDel( &aDelData2 );
     546           0 :                 if ( !ImplCallPreNotify( aNLeaveEvt ) )
     547             :                 {
     548           0 :                     pMouseMoveWin->MouseMove( aMLeaveEvt );
     549           0 :                     if( !aDelData.IsDead() )
     550           0 :                         aNLeaveEvt.GetWindow()->ImplNotifyKeyMouseCommandEventListeners( aNLeaveEvt );
     551             :                 }
     552             : 
     553           0 :                 pWinFrameData->mpMouseMoveWin = NULL;
     554           0 :                 pWinFrameData->mbInMouseMove = false;
     555             : 
     556           0 :                 if ( pChild )
     557             :                 {
     558           0 :                     if ( aDelData2.IsDead() )
     559           0 :                         pChild = NULL;
     560             :                     else
     561           0 :                         pChild->ImplRemoveDel( &aDelData2 );
     562             :                 }
     563           0 :                 if ( aDelData.IsDead() )
     564           0 :                     return true;
     565           0 :                 pMouseMoveWin->ImplRemoveDel( &aDelData );
     566             :             }
     567             : 
     568           0 :             nMode |= MOUSE_ENTERWINDOW;
     569             :         }
     570           0 :         pWinFrameData->mpMouseMoveWin = pChild;
     571           0 :         if( pChild )
     572           0 :             pChild->ImplGetWinData()->mbMouseOver = true;
     573             : 
     574             :         // MouseLeave
     575           0 :         if ( !pChild )
     576           0 :             return false;
     577             :     }
     578             :     else
     579             :     {
     580           0 :         if (pChild)
     581             :         {
     582             :             // mouse click
     583           0 :             if ( nSVEvent == EVENT_MOUSEBUTTONDOWN )
     584             :             {
     585           0 :                 const MouseSettings& rMSettings = pChild->GetSettings().GetMouseSettings();
     586           0 :                 sal_uLong   nDblClkTime = rMSettings.GetDoubleClickTime();
     587           0 :                 long    nDblClkW    = rMSettings.GetDoubleClickWidth();
     588           0 :                 long    nDblClkH    = rMSettings.GetDoubleClickHeight();
     589             :                 //long    nMouseX     = nX;
     590             :                 //long    nMouseY     = nY;
     591           0 :                 long nMouseX = aMousePos.X();   // #106074# use the possibly re-mirrored coordinates (RTL) ! nX,nY are unmodified !
     592           0 :                 long nMouseY = aMousePos.Y();
     593             : 
     594           0 :                 if ( (pChild == pChild->ImplGetFrameData()->mpMouseDownWin) &&
     595           0 :                      (nCode == pChild->ImplGetFrameData()->mnFirstMouseCode) &&
     596           0 :                      ((nMsgTime-pChild->ImplGetFrameData()->mnMouseDownTime) < nDblClkTime) &&
     597           0 :                      ((nMouseX-nDblClkW) <= pChild->ImplGetFrameData()->mnFirstMouseX) &&
     598           0 :                      ((nMouseX+nDblClkW) >= pChild->ImplGetFrameData()->mnFirstMouseX) &&
     599           0 :                      ((nMouseY-nDblClkH) <= pChild->ImplGetFrameData()->mnFirstMouseY) &&
     600           0 :                      ((nMouseY+nDblClkH) >= pChild->ImplGetFrameData()->mnFirstMouseY) )
     601             :                 {
     602           0 :                     pChild->ImplGetFrameData()->mnClickCount++;
     603           0 :                     pChild->ImplGetFrameData()->mbStartDragCalled  = true;
     604             :                 }
     605             :                 else
     606             :                 {
     607           0 :                     pChild->ImplGetFrameData()->mpMouseDownWin     = pChild;
     608           0 :                     pChild->ImplGetFrameData()->mnClickCount       = 1;
     609           0 :                     pChild->ImplGetFrameData()->mnFirstMouseX      = nMouseX;
     610           0 :                     pChild->ImplGetFrameData()->mnFirstMouseY      = nMouseY;
     611           0 :                     pChild->ImplGetFrameData()->mnFirstMouseCode   = nCode;
     612           0 :                     pChild->ImplGetFrameData()->mbStartDragCalled  = !((nCode & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)) ==
     613           0 :                                                                 (rMSettings.GetStartDragCode() & (MOUSE_LEFT | MOUSE_RIGHT | MOUSE_MIDDLE)));
     614             :                 }
     615           0 :                 pChild->ImplGetFrameData()->mnMouseDownTime = nMsgTime;
     616             :             }
     617           0 :             nClicks = pChild->ImplGetFrameData()->mnClickCount;
     618             :         }
     619             : 
     620           0 :         pSVData->maAppData.mnLastInputTime = tools::Time::GetSystemTicks();
     621             :     }
     622             : 
     623             :     DBG_ASSERT( pChild, "ImplHandleMouseEvent: pChild == NULL" );
     624             : 
     625           0 :     if (!pChild)
     626           0 :         return false;
     627             : 
     628             :     // create mouse event
     629           0 :     Point aChildPos = pChild->ImplFrameToOutput( aMousePos );
     630           0 :     MouseEvent aMEvt( aChildPos, nClicks, nMode, nCode, nCode );
     631             : 
     632             :     // tracking window gets the mouse events
     633           0 :     if ( pSVData->maWinData.mpTrackWin )
     634           0 :         pChild = pSVData->maWinData.mpTrackWin;
     635             : 
     636             :     // handle FloatingMode
     637           0 :     if ( !pSVData->maWinData.mpTrackWin && pSVData->maWinData.mpFirstFloat )
     638             :     {
     639           0 :         ImplDelData aDelData;
     640           0 :         pChild->ImplAddDel( &aDelData );
     641           0 :         if ( ImplHandleMouseFloatMode( pChild, aMousePos, nCode, nSVEvent, bMouseLeave ) )
     642             :         {
     643           0 :             if ( !aDelData.IsDead() )
     644             :             {
     645           0 :                 pChild->ImplRemoveDel( &aDelData );
     646           0 :                 pChild->ImplGetFrameData()->mbStartDragCalled = true;
     647             :             }
     648           0 :             return true;
     649             :         }
     650             :         else
     651           0 :             pChild->ImplRemoveDel( &aDelData );
     652             :     }
     653             : 
     654             :     // call handler
     655           0 :     bool bDrag = false;
     656           0 :     bool bCallHelpRequest = true;
     657             :     DBG_ASSERT( pChild, "ImplHandleMouseEvent: pChild is NULL" );
     658             : 
     659           0 :     if (!pChild)
     660           0 :         return false;
     661             : 
     662           0 :     ImplDelData aDelData;
     663           0 :     NotifyEvent aNEvt( nSVEvent, pChild, &aMEvt );
     664           0 :     pChild->ImplAddDel( &aDelData );
     665           0 :     if ( nSVEvent == EVENT_MOUSEMOVE )
     666           0 :         pChild->ImplGetFrameData()->mbInMouseMove = true;
     667             : 
     668             :     // bring window into foreground on mouseclick
     669           0 :     if ( nSVEvent == EVENT_MOUSEBUTTONDOWN )
     670             :     {
     671           0 :         if( !pSVData->maWinData.mpFirstFloat && // totop for floating windows in popup would change the focus and would close them immediately
     672           0 :             !(pChild->ImplGetFrameWindow()->GetStyle() & WB_OWNERDRAWDECORATION) )    // ownerdrawdecorated windows must never grab focus
     673           0 :             pChild->ToTop();
     674           0 :         if ( aDelData.IsDead() )
     675           0 :             return true;
     676             :     }
     677             : 
     678           0 :     if ( ImplCallPreNotify( aNEvt ) || aDelData.IsDead() )
     679           0 :         bRet = true;
     680             :     else
     681             :     {
     682           0 :         bRet = false;
     683           0 :         if ( nSVEvent == EVENT_MOUSEMOVE )
     684             :         {
     685           0 :             if ( pSVData->maWinData.mpTrackWin )
     686             :             {
     687           0 :                 TrackingEvent aTEvt( aMEvt );
     688           0 :                 pChild->Tracking( aTEvt );
     689           0 :                 if ( !aDelData.IsDead() )
     690             :                 {
     691             :                     // When ScrollRepeat, we restart the timer
     692           0 :                     if ( pSVData->maWinData.mpTrackTimer &&
     693           0 :                          (pSVData->maWinData.mnTrackFlags & STARTTRACK_SCROLLREPEAT) )
     694           0 :                         pSVData->maWinData.mpTrackTimer->Start();
     695             :                 }
     696           0 :                 bCallHelpRequest = false;
     697           0 :                 bRet = true;
     698             :             }
     699             :             else
     700             :             {
     701             :                 // Auto-ToTop
     702           0 :                 if ( !pSVData->maWinData.mpCaptureWin &&
     703           0 :                      (pChild->GetSettings().GetMouseSettings().GetOptions() & MOUSE_OPTION_AUTOFOCUS) )
     704           0 :                     pChild->ToTop( TOTOP_NOGRABFOCUS );
     705             : 
     706           0 :                 if( aDelData.IsDead() )
     707           0 :                     bCallHelpRequest = false;
     708             :                 else
     709             :                 {
     710             :                     // if the MouseMove handler changes the help window's visibility
     711             :                     // the HelpRequest handler should not be called anymore
     712           0 :                     vcl::Window* pOldHelpTextWin = pSVData->maHelpData.mpHelpWin;
     713           0 :                     pChild->ImplGetWindowImpl()->mbMouseMove = false;
     714           0 :                     pChild->MouseMove( aMEvt );
     715           0 :                     if ( pOldHelpTextWin != pSVData->maHelpData.mpHelpWin )
     716           0 :                         bCallHelpRequest = false;
     717             :                 }
     718             :             }
     719             :         }
     720           0 :         else if ( nSVEvent == EVENT_MOUSEBUTTONDOWN )
     721             :         {
     722           0 :             if ( pSVData->maWinData.mpTrackWin &&
     723           0 :                  !(pSVData->maWinData.mnTrackFlags & STARTTRACK_MOUSEBUTTONDOWN) )
     724           0 :                 bRet = true;
     725             :             else
     726             :             {
     727           0 :                 pChild->ImplGetWindowImpl()->mbMouseButtonDown = false;
     728           0 :                 pChild->MouseButtonDown( aMEvt );
     729             :             }
     730             :         }
     731             :         else
     732             :         {
     733           0 :             if ( pSVData->maWinData.mpTrackWin )
     734             :             {
     735           0 :                 pChild->EndTracking();
     736           0 :                 bRet = true;
     737             :             }
     738             :             else
     739             :             {
     740           0 :                 pChild->ImplGetWindowImpl()->mbMouseButtonUp = false;
     741           0 :                 pChild->MouseButtonUp( aMEvt );
     742             :             }
     743             :         }
     744             : 
     745           0 :         if ( !aDelData.IsDead() )
     746           0 :             aNEvt.GetWindow()->ImplNotifyKeyMouseCommandEventListeners( aNEvt );
     747             :     }
     748             : 
     749           0 :     if ( aDelData.IsDead() )
     750           0 :         return true;
     751             : 
     752           0 :     if ( nSVEvent == EVENT_MOUSEMOVE )
     753           0 :         pChild->ImplGetWindowImpl()->mpFrameData->mbInMouseMove = false;
     754             : 
     755           0 :     if ( nSVEvent == EVENT_MOUSEMOVE )
     756             :     {
     757           0 :         if ( bCallHelpRequest && !pSVData->maHelpData.mbKeyboardHelp )
     758           0 :             ImplHandleMouseHelpRequest( pChild, pChild->OutputToScreenPixel( aMEvt.GetPosPixel() ) );
     759           0 :         bRet = true;
     760             :     }
     761           0 :     else if ( !bRet )
     762             :     {
     763           0 :         if ( nSVEvent == EVENT_MOUSEBUTTONDOWN )
     764             :         {
     765           0 :             if ( !pChild->ImplGetWindowImpl()->mbMouseButtonDown )
     766           0 :                 bRet = true;
     767             :         }
     768             :         else
     769             :         {
     770           0 :             if ( !pChild->ImplGetWindowImpl()->mbMouseButtonUp )
     771           0 :                 bRet = true;
     772             :         }
     773             :     }
     774             : 
     775           0 :     pChild->ImplRemoveDel( &aDelData );
     776             : 
     777           0 :     if ( nSVEvent == EVENT_MOUSEMOVE )
     778             :     {
     779             :         // set new mouse pointer
     780           0 :         if ( !bMouseLeave )
     781           0 :             ImplSetMousePointer( pChild );
     782             :     }
     783           0 :     else if ( (nSVEvent == EVENT_MOUSEBUTTONDOWN) || (nSVEvent == EVENT_MOUSEBUTTONUP) )
     784             :     {
     785           0 :         if ( !bDrag )
     786             :         {
     787             :             // Command-Events
     788           0 :             if ( /*!bRet &&*/ (nClicks == 1) && (nSVEvent == EVENT_MOUSEBUTTONDOWN) &&
     789             :                  (nCode == MOUSE_MIDDLE) )
     790             :             {
     791           0 :                 sal_uInt16 nMiddleAction = pChild->GetSettings().GetMouseSettings().GetMiddleButtonAction();
     792           0 :                 if ( nMiddleAction == MOUSE_MIDDLE_AUTOSCROLL )
     793           0 :                     bRet = !ImplCallCommand( pChild, COMMAND_STARTAUTOSCROLL, NULL, true, &aChildPos );
     794           0 :                 else if ( nMiddleAction == MOUSE_MIDDLE_PASTESELECTION )
     795           0 :                     bRet = !ImplCallCommand( pChild, COMMAND_PASTESELECTION, NULL, true, &aChildPos );
     796             :             }
     797             :             else
     798             :             {
     799             :                 // ContextMenu
     800           0 :                 const MouseSettings& rMSettings = pChild->GetSettings().GetMouseSettings();
     801           0 :                 if ( (nCode == rMSettings.GetContextMenuCode()) &&
     802           0 :                      (nClicks == rMSettings.GetContextMenuClicks()) )
     803             :                 {
     804           0 :                     bool bContextMenu = (nSVEvent == EVENT_MOUSEBUTTONDOWN);
     805           0 :                     if ( bContextMenu )
     806             :                     {
     807           0 :                         if( pSVData->maAppData.mpActivePopupMenu )
     808             :                         {
     809             :                             /*  #i34277# there already is a context menu open
     810             :                             *   that was probably just closed with EndPopupMode.
     811             :                             *   We need to give the eventual corresponding
     812             :                             *   PopupMenu::Execute a chance to end properly.
     813             :                             *   Therefore delay context menu command and
     814             :                             *   issue only after popping one frame of the
     815             :                             *   Yield stack.
     816             :                             */
     817           0 :                             ContextMenuEvent* pEv = new ContextMenuEvent;
     818           0 :                             pEv->pWindow = pChild;
     819           0 :                             pEv->aChildPos = aChildPos;
     820           0 :                             pChild->ImplAddDel( &pEv->aDelData );
     821           0 :                             Application::PostUserEvent( Link( pEv, ContextMenuEventLink ) );
     822             :                         }
     823             :                         else
     824           0 :                             bRet = ! ImplCallCommand( pChild, COMMAND_CONTEXTMENU, NULL, true, &aChildPos );
     825             :                     }
     826             :                 }
     827             :             }
     828             :         }
     829             :     }
     830             : 
     831           0 :     return bRet;
     832             : }
     833             : 
     834           0 : static vcl::Window* ImplGetKeyInputWindow( vcl::Window* pWindow )
     835             : {
     836           0 :     ImplSVData* pSVData = ImplGetSVData();
     837             : 
     838             :     // determine last input time
     839           0 :     pSVData->maAppData.mnLastInputTime = tools::Time::GetSystemTicks();
     840             : 
     841             :     // #127104# workaround for destroyed windows
     842           0 :     if( pWindow->ImplGetWindowImpl() == NULL )
     843           0 :         return 0;
     844             : 
     845             :     // find window - is every time the window which has currently the
     846             :     // focus or the last time the focus.
     847             :     // the first floating window always has the focus
     848           0 :     vcl::Window* pChild = pSVData->maWinData.mpFirstFloat;
     849           0 :     if( !pChild || ( pChild->ImplGetWindowImpl()->mbFloatWin && !static_cast<FloatingWindow *>(pChild)->GrabsFocus() ) )
     850           0 :         pChild = pWindow->ImplGetWindowImpl()->mpFrameData->mpFocusWin;
     851             :     else
     852             :     {
     853             :         // allow floaters to forward keyinput to some member
     854           0 :         pChild = pChild->GetPreferredKeyInputWindow();
     855             :     }
     856             : 
     857             :     // no child - than no input
     858           0 :     if ( !pChild )
     859           0 :         return 0;
     860             : 
     861             :     // We call also KeyInput if we haven't the focus, because on Unix
     862             :     // system this is often the case when a Lookup Choise Window has
     863             :     // the focus - because this windows send the KeyInput directly to
     864             :     // the window without resetting the focus
     865             :     DBG_ASSERTWARNING( pChild == pSVData->maWinData.mpFocusWin,
     866             :                        "ImplHandleKey: Keyboard-Input is sent to a frame without focus" );
     867             : 
     868             :     // no keyinput to disabled windows
     869           0 :     if ( !pChild->IsEnabled() || !pChild->IsInputEnabled() || pChild->IsInModalMode() )
     870           0 :         return 0;
     871             : 
     872           0 :     return pChild;
     873             : }
     874             : 
     875           0 : static bool ImplHandleKey( vcl::Window* pWindow, sal_uInt16 nSVEvent,
     876             :                            sal_uInt16 nKeyCode, sal_uInt16 nCharCode, sal_uInt16 nRepeat, bool bForward )
     877             : {
     878           0 :     ImplSVData* pSVData = ImplGetSVData();
     879           0 :     vcl::KeyCode aKeyCode( nKeyCode, nKeyCode );
     880           0 :     sal_uInt16 nEvCode = aKeyCode.GetCode();
     881             : 
     882             :     // allow application key listeners to remove the key event
     883             :     // but make sure we're not forwarding external KeyEvents, (ie where bForward is false)
     884             :     // because those are coming back from the listener itself and MUST be processed
     885           0 :     KeyEvent aKeyEvent( (sal_Unicode)nCharCode, aKeyCode, nRepeat );
     886           0 :     if( bForward )
     887             :     {
     888             :         sal_uInt16 nVCLEvent;
     889           0 :         switch( nSVEvent )
     890             :         {
     891             :             case EVENT_KEYINPUT:
     892           0 :                 nVCLEvent = VCLEVENT_WINDOW_KEYINPUT;
     893           0 :                 break;
     894             :             case EVENT_KEYUP:
     895           0 :                 nVCLEvent = VCLEVENT_WINDOW_KEYUP;
     896           0 :                 break;
     897             :             default:
     898           0 :                 nVCLEvent = 0;
     899           0 :                 break;
     900             :         }
     901           0 :         if( nVCLEvent && Application::HandleKey( nVCLEvent, pWindow, &aKeyEvent ) )
     902           0 :             return true;
     903             :     }
     904             : 
     905             :     // #i1820# use locale specific decimal separator
     906           0 :     if( nEvCode == KEY_DECIMAL )
     907             :     {
     908           0 :         if( Application::GetSettings().GetMiscSettings().GetEnableLocalizedDecimalSep() )
     909             :         {
     910           0 :             OUString aSep( pWindow->GetSettings().GetLocaleDataWrapper().getNumDecimalSep() );
     911           0 :             nCharCode = (sal_uInt16) aSep[0];
     912             :         }
     913             :     }
     914             : 
     915           0 :     bool bCtrlF6 = (aKeyCode.GetCode() == KEY_F6) && aKeyCode.IsMod1();
     916             : 
     917             :     // determine last input time
     918           0 :     pSVData->maAppData.mnLastInputTime = tools::Time::GetSystemTicks();
     919             : 
     920             :     // handle tracking window
     921           0 :     if ( nSVEvent == EVENT_KEYINPUT )
     922             :     {
     923             : #ifdef DBG_UTIL
     924             :         // #105224# use Ctrl-Alt-Shift-D, Ctrl-Shift-D must be useable by app
     925             :         if ( aKeyCode.IsShift() && aKeyCode.IsMod1() && (aKeyCode.IsMod2() || aKeyCode.IsMod3()) && (aKeyCode.GetCode() == KEY_D) )
     926             :         {
     927             :             DBGGUI_START();
     928             :             return true;
     929             :         }
     930             : #endif
     931             : 
     932           0 :         if ( pSVData->maHelpData.mbExtHelpMode )
     933             :         {
     934           0 :             Help::EndExtHelp();
     935           0 :             if ( nEvCode == KEY_ESCAPE )
     936           0 :                 return true;
     937             :         }
     938           0 :         if ( pSVData->maHelpData.mpHelpWin )
     939           0 :             ImplDestroyHelpWindow( false );
     940             : 
     941             :         // AutoScrollMode
     942           0 :         if ( pSVData->maWinData.mpAutoScrollWin )
     943             :         {
     944           0 :             pSVData->maWinData.mpAutoScrollWin->EndAutoScroll();
     945           0 :             if ( nEvCode == KEY_ESCAPE )
     946           0 :                 return true;
     947             :         }
     948             : 
     949           0 :         if ( pSVData->maWinData.mpTrackWin )
     950             :         {
     951           0 :             sal_uInt16 nOrigCode = aKeyCode.GetCode();
     952             : 
     953           0 :             if ( (nOrigCode == KEY_ESCAPE) && !(pSVData->maWinData.mnTrackFlags & STARTTRACK_NOKEYCANCEL) )
     954             :             {
     955           0 :                 pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL | ENDTRACK_KEY );
     956           0 :                 if ( pSVData->maWinData.mpFirstFloat )
     957             :                 {
     958           0 :                     FloatingWindow* pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
     959           0 :                     if ( !(pLastLevelFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOKEYCLOSE) )
     960             :                     {
     961           0 :                         sal_uInt16 nEscCode = aKeyCode.GetCode();
     962             : 
     963           0 :                         if ( nEscCode == KEY_ESCAPE )
     964           0 :                             pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
     965             :                     }
     966             :                 }
     967           0 :                 return true;
     968             :             }
     969           0 :             else if ( nOrigCode == KEY_RETURN )
     970             :             {
     971           0 :                 pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_KEY );
     972           0 :                 return true;
     973             :             }
     974           0 :             else if ( !(pSVData->maWinData.mnTrackFlags & STARTTRACK_KEYINPUT) )
     975           0 :                 return true;
     976             :         }
     977             : 
     978             :         // handle FloatingMode
     979           0 :         if ( pSVData->maWinData.mpFirstFloat )
     980             :         {
     981           0 :             FloatingWindow* pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
     982           0 :             if ( !(pLastLevelFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOKEYCLOSE) )
     983             :             {
     984           0 :                 sal_uInt16 nCode = aKeyCode.GetCode();
     985             : 
     986           0 :                 if ( (nCode == KEY_ESCAPE) || bCtrlF6)
     987             :                 {
     988           0 :                     pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
     989           0 :                     if( !bCtrlF6 )
     990           0 :                         return true;
     991             :                 }
     992             :             }
     993             :         }
     994             : 
     995             :         // test for accel
     996           0 :         if ( pSVData->maAppData.mpAccelMgr )
     997             :         {
     998           0 :             if ( pSVData->maAppData.mpAccelMgr->IsAccelKey( aKeyCode, nRepeat ) )
     999           0 :                 return true;
    1000             :         }
    1001             :     }
    1002             : 
    1003             :     // find window
    1004           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    1005           0 :     if ( !pChild )
    1006           0 :         return false;
    1007             : 
    1008             :     // --- RTL --- mirror cursor keys
    1009           0 :     const OutputDevice *pChildOutDev = pChild->GetOutDev();
    1010           0 :     if( (aKeyCode.GetCode() == KEY_LEFT || aKeyCode.GetCode() == KEY_RIGHT) &&
    1011           0 :       pChildOutDev->HasMirroredGraphics() && pChild->IsRTLEnabled() )
    1012           0 :         aKeyCode = vcl::KeyCode( aKeyCode.GetCode() == KEY_LEFT ? KEY_RIGHT : KEY_LEFT, aKeyCode.GetModifier() );
    1013             : 
    1014             :     // call handler
    1015           0 :     ImplDelData aDelData;
    1016           0 :     pChild->ImplAddDel( &aDelData );
    1017             : 
    1018           0 :     KeyEvent    aKeyEvt( (sal_Unicode)nCharCode, aKeyCode, nRepeat );
    1019           0 :     NotifyEvent aNotifyEvt( nSVEvent, pChild, &aKeyEvt );
    1020           0 :     bool bKeyPreNotify = ImplCallPreNotify( aNotifyEvt );
    1021           0 :     bool nRet = true;
    1022             : 
    1023           0 :     if ( !bKeyPreNotify && !aDelData.IsDead() )
    1024             :     {
    1025           0 :         if ( nSVEvent == EVENT_KEYINPUT )
    1026             :         {
    1027           0 :             pChild->ImplGetWindowImpl()->mbKeyInput = false;
    1028           0 :             pChild->KeyInput( aKeyEvt );
    1029             :         }
    1030             :         else
    1031             :         {
    1032           0 :             pChild->ImplGetWindowImpl()->mbKeyUp = false;
    1033           0 :             pChild->KeyUp( aKeyEvt );
    1034             :         }
    1035           0 :         if( !aDelData.IsDead() )
    1036           0 :             aNotifyEvt.GetWindow()->ImplNotifyKeyMouseCommandEventListeners( aNotifyEvt );
    1037             :     }
    1038             : 
    1039           0 :     if ( aDelData.IsDead() )
    1040           0 :         return true;
    1041             : 
    1042           0 :     pChild->ImplRemoveDel( &aDelData );
    1043             : 
    1044           0 :     if ( nSVEvent == EVENT_KEYINPUT )
    1045             :     {
    1046           0 :         if ( !bKeyPreNotify && pChild->ImplGetWindowImpl()->mbKeyInput )
    1047             :         {
    1048           0 :             sal_uInt16 nCode = aKeyCode.GetCode();
    1049             : 
    1050             :             // #101999# is focus in or below toolbox
    1051           0 :             bool bToolboxFocus=false;
    1052           0 :             if( (nCode == KEY_F1) && aKeyCode.IsShift() )
    1053             :             {
    1054           0 :                 vcl::Window *pWin = pWindow->ImplGetWindowImpl()->mpFrameData->mpFocusWin;
    1055           0 :                 while( pWin )
    1056             :                 {
    1057           0 :                     if( pWin->ImplGetWindowImpl()->mbToolBox )
    1058             :                     {
    1059           0 :                         bToolboxFocus = true;
    1060           0 :                         break;
    1061             :                     }
    1062             :                     else
    1063           0 :                         pWin = pWin->GetParent();
    1064             :                 }
    1065             :             }
    1066             : 
    1067             :             // ContextMenu
    1068           0 :             if ( (nCode == KEY_CONTEXTMENU) || ((nCode == KEY_F10) && aKeyCode.IsShift() && !aKeyCode.IsMod1() && !aKeyCode.IsMod2() ) )
    1069           0 :                 nRet = !ImplCallCommand( pChild, COMMAND_CONTEXTMENU, NULL, false );
    1070           0 :             else if ( ( (nCode == KEY_F2) && aKeyCode.IsShift() ) || ( (nCode == KEY_F1) && aKeyCode.IsMod1() ) ||
    1071             :                 // #101999# no active help when focus in toolbox, simulate BallonHelp instead
    1072           0 :                 ( (nCode == KEY_F1) && aKeyCode.IsShift() && bToolboxFocus ) )
    1073             :             {
    1074             :                 // TipHelp via Keyboard (Shift-F2 or Ctrl-F1)
    1075             :                 // simulate mouseposition at center of window
    1076             : 
    1077           0 :                 Size aSize = pChild->GetOutputSize();
    1078           0 :                 Point aPos = Point( aSize.getWidth()/2, aSize.getHeight()/2 );
    1079           0 :                 aPos = pChild->OutputToScreenPixel( aPos );
    1080             : 
    1081           0 :                 HelpEvent aHelpEvent( aPos, HELPMODE_BALLOON );
    1082           0 :                 aHelpEvent.SetKeyboardActivated( true );
    1083           0 :                 pSVData->maHelpData.mbSetKeyboardHelp = true;
    1084           0 :                 pChild->RequestHelp( aHelpEvent );
    1085           0 :                 pSVData->maHelpData.mbSetKeyboardHelp = false;
    1086             :             }
    1087           0 :             else if ( (nCode == KEY_F1) || (nCode == KEY_HELP) )
    1088             :             {
    1089           0 :                 if ( !aKeyCode.GetModifier() )
    1090             :                 {
    1091           0 :                     if ( pSVData->maHelpData.mbContextHelp )
    1092             :                     {
    1093           0 :                         Point       aMousePos = pChild->OutputToScreenPixel( pChild->GetPointerPosPixel() );
    1094           0 :                         HelpEvent   aHelpEvent( aMousePos, HELPMODE_CONTEXT );
    1095           0 :                         pChild->RequestHelp( aHelpEvent );
    1096             :                     }
    1097             :                     else
    1098           0 :                         nRet = false;
    1099             :                 }
    1100           0 :                 else if ( aKeyCode.IsShift() )
    1101             :                 {
    1102           0 :                     if ( pSVData->maHelpData.mbExtHelp )
    1103           0 :                         Help::StartExtHelp();
    1104             :                     else
    1105           0 :                         nRet = false;
    1106           0 :                 }
    1107             :             }
    1108             :             else
    1109             :             {
    1110           0 :                 if ( ImplCallHotKey( aKeyCode ) )
    1111           0 :                     nRet = true;
    1112             :                 else
    1113           0 :                     nRet = false;
    1114             :             }
    1115             :         }
    1116             :     }
    1117             :     else
    1118             :     {
    1119           0 :         if ( !bKeyPreNotify && pChild->ImplGetWindowImpl()->mbKeyUp )
    1120           0 :             nRet = false;
    1121             :     }
    1122             : 
    1123             :     // #105591# send keyinput to parent if we are a floating window and the key was not pocessed yet
    1124           0 :     if( !nRet && pWindow->ImplGetWindowImpl()->mbFloatWin && pWindow->GetParent() && (pWindow->ImplGetWindowImpl()->mpFrame != pWindow->GetParent()->ImplGetWindowImpl()->mpFrame) )
    1125             :     {
    1126           0 :         pChild = pWindow->GetParent();
    1127             : 
    1128             :         // call handler
    1129           0 :         ImplDelData aChildDelData( pChild );
    1130           0 :         KeyEvent    aKEvt( (sal_Unicode)nCharCode, aKeyCode, nRepeat );
    1131           0 :         NotifyEvent aNEvt( nSVEvent, pChild, &aKEvt );
    1132           0 :         bool bPreNotify = ImplCallPreNotify( aNEvt );
    1133           0 :         if ( aChildDelData.IsDead() )
    1134           0 :             return true;
    1135             : 
    1136           0 :         if ( !bPreNotify )
    1137             :         {
    1138           0 :             if ( nSVEvent == EVENT_KEYINPUT )
    1139             :             {
    1140           0 :                 pChild->ImplGetWindowImpl()->mbKeyInput = false;
    1141           0 :                 pChild->KeyInput( aKEvt );
    1142             :             }
    1143             :             else
    1144             :             {
    1145           0 :                 pChild->ImplGetWindowImpl()->mbKeyUp = false;
    1146           0 :                 pChild->KeyUp( aKEvt );
    1147             :             }
    1148             : 
    1149           0 :             if( !aChildDelData.IsDead() )
    1150           0 :                 aNEvt.GetWindow()->ImplNotifyKeyMouseCommandEventListeners( aNEvt );
    1151           0 :             if ( aChildDelData.IsDead() )
    1152           0 :                 return true;
    1153             :         }
    1154             : 
    1155           0 :         if( bPreNotify || !pChild->ImplGetWindowImpl()->mbKeyInput )
    1156           0 :             nRet = true;
    1157             :     }
    1158             : 
    1159           0 :     return nRet;
    1160             : }
    1161             : 
    1162           0 : static bool ImplHandleExtTextInput( vcl::Window* pWindow,
    1163             :                                     const OUString& rText,
    1164             :                                     const sal_uInt16* pTextAttr,
    1165             :                                     sal_Int32 nCursorPos, sal_uInt16 nCursorFlags )
    1166             : {
    1167           0 :     ImplSVData* pSVData = ImplGetSVData();
    1168           0 :     vcl::Window*     pChild = NULL;
    1169             : 
    1170           0 :     int nTries = 200;
    1171           0 :     while( nTries-- )
    1172             :     {
    1173           0 :         pChild = pSVData->maWinData.mpExtTextInputWin;
    1174           0 :         if ( !pChild )
    1175             :         {
    1176           0 :             pChild = ImplGetKeyInputWindow( pWindow );
    1177           0 :             if ( !pChild )
    1178           0 :                 return false;
    1179             :         }
    1180           0 :         if( !pChild->ImplGetWindowImpl()->mpFrameData->mnFocusId )
    1181           0 :             break;
    1182           0 :         Application::Yield();
    1183             :     }
    1184             : 
    1185             :     // If it is the first ExtTextInput call, we inform the information
    1186             :     // and allocate the data, which we must store in this mode
    1187           0 :     ImplWinData* pWinData = pChild->ImplGetWinData();
    1188           0 :     if ( !pChild->ImplGetWindowImpl()->mbExtTextInput )
    1189             :     {
    1190           0 :         pChild->ImplGetWindowImpl()->mbExtTextInput = true;
    1191           0 :         pWinData->mpExtOldText = new OUString;
    1192           0 :         if ( pWinData->mpExtOldAttrAry )
    1193             :         {
    1194           0 :             delete [] pWinData->mpExtOldAttrAry;
    1195           0 :             pWinData->mpExtOldAttrAry = NULL;
    1196             :         }
    1197           0 :         pSVData->maWinData.mpExtTextInputWin = pChild;
    1198           0 :         ImplCallCommand( pChild, COMMAND_STARTEXTTEXTINPUT );
    1199             :     }
    1200             : 
    1201             :     // be aware of being recursively called in StartExtTextInput
    1202           0 :     if ( !pChild->ImplGetWindowImpl()->mbExtTextInput )
    1203           0 :         return false;
    1204             : 
    1205             :     // Test for changes
    1206           0 :     bool bOnlyCursor = false;
    1207           0 :     sal_Int32 nMinLen = std::min( pWinData->mpExtOldText->getLength(), rText.getLength() );
    1208           0 :     sal_Int32 nDeltaStart = 0;
    1209           0 :     while ( nDeltaStart < nMinLen )
    1210             :     {
    1211           0 :         if ( (*pWinData->mpExtOldText)[nDeltaStart] != rText[nDeltaStart] )
    1212           0 :             break;
    1213           0 :         nDeltaStart++;
    1214             :     }
    1215           0 :     if ( pWinData->mpExtOldAttrAry || pTextAttr )
    1216             :     {
    1217           0 :         if ( !pWinData->mpExtOldAttrAry || !pTextAttr )
    1218           0 :             nDeltaStart = 0;
    1219             :         else
    1220             :         {
    1221           0 :             sal_Int32 i = 0;
    1222           0 :             while ( i < nDeltaStart )
    1223             :             {
    1224           0 :                 if ( pWinData->mpExtOldAttrAry[i] != pTextAttr[i] )
    1225             :                 {
    1226           0 :                     nDeltaStart = i;
    1227           0 :                     break;
    1228             :                 }
    1229           0 :                 i++;
    1230             :             }
    1231             :         }
    1232             :     }
    1233           0 :     if ( (nDeltaStart >= nMinLen) &&
    1234           0 :          (pWinData->mpExtOldText->getLength() == rText.getLength()) )
    1235           0 :         bOnlyCursor = true;
    1236             : 
    1237             :     // Call Event and store the information
    1238             :     CommandExtTextInputData aData( rText, pTextAttr,
    1239             :                                    nCursorPos, nCursorFlags,
    1240           0 :                                    bOnlyCursor );
    1241           0 :     *pWinData->mpExtOldText = rText;
    1242           0 :     if ( pWinData->mpExtOldAttrAry )
    1243             :     {
    1244           0 :         delete [] pWinData->mpExtOldAttrAry;
    1245           0 :         pWinData->mpExtOldAttrAry = NULL;
    1246             :     }
    1247           0 :     if ( pTextAttr )
    1248             :     {
    1249           0 :         pWinData->mpExtOldAttrAry = new sal_uInt16[rText.getLength()];
    1250           0 :         memcpy( pWinData->mpExtOldAttrAry, pTextAttr, rText.getLength()*sizeof( sal_uInt16 ) );
    1251             :     }
    1252           0 :     return !ImplCallCommand( pChild, COMMAND_EXTTEXTINPUT, &aData );
    1253             : }
    1254             : 
    1255           0 : static bool ImplHandleEndExtTextInput( vcl::Window* /* pWindow */ )
    1256             : {
    1257           0 :     ImplSVData* pSVData = ImplGetSVData();
    1258           0 :     vcl::Window*     pChild = pSVData->maWinData.mpExtTextInputWin;
    1259           0 :     bool        nRet = false;
    1260             : 
    1261           0 :     if ( pChild )
    1262             :     {
    1263           0 :         pChild->ImplGetWindowImpl()->mbExtTextInput = false;
    1264           0 :         pSVData->maWinData.mpExtTextInputWin = NULL;
    1265           0 :         ImplWinData* pWinData = pChild->ImplGetWinData();
    1266           0 :         if ( pWinData->mpExtOldText )
    1267             :         {
    1268           0 :             delete pWinData->mpExtOldText;
    1269           0 :             pWinData->mpExtOldText = NULL;
    1270             :         }
    1271           0 :         if ( pWinData->mpExtOldAttrAry )
    1272             :         {
    1273           0 :             delete [] pWinData->mpExtOldAttrAry;
    1274           0 :             pWinData->mpExtOldAttrAry = NULL;
    1275             :         }
    1276           0 :         nRet = !ImplCallCommand( pChild, COMMAND_ENDEXTTEXTINPUT );
    1277             :     }
    1278             : 
    1279           0 :     return nRet;
    1280             : }
    1281             : 
    1282           0 : static void ImplHandleExtTextInputPos( vcl::Window* pWindow,
    1283             :                                        Rectangle& rRect, long& rInputWidth,
    1284             :                                        bool * pVertical )
    1285             : {
    1286           0 :     ImplSVData* pSVData = ImplGetSVData();
    1287           0 :     vcl::Window*     pChild = pSVData->maWinData.mpExtTextInputWin;
    1288             : 
    1289           0 :     if ( !pChild )
    1290           0 :         pChild = ImplGetKeyInputWindow( pWindow );
    1291             :     else
    1292             :     {
    1293             :         // Test, if the Window is related to the frame
    1294           0 :         if ( !pWindow->ImplIsWindowOrChild( pChild ) )
    1295           0 :             pChild = ImplGetKeyInputWindow( pWindow );
    1296             :     }
    1297             : 
    1298           0 :     if ( pChild )
    1299             :     {
    1300           0 :         const OutputDevice *pChildOutDev = pChild->GetOutDev();
    1301           0 :         ImplCallCommand( pChild, COMMAND_CURSORPOS );
    1302           0 :         const Rectangle* pRect = pChild->GetCursorRect();
    1303           0 :         if ( pRect )
    1304           0 :             rRect = pChildOutDev->ImplLogicToDevicePixel( *pRect );
    1305             :         else
    1306             :         {
    1307           0 :             vcl::Cursor* pCursor = pChild->GetCursor();
    1308           0 :             if ( pCursor )
    1309             :             {
    1310           0 :                 Point aPos = pChildOutDev->ImplLogicToDevicePixel( pCursor->GetPos() );
    1311           0 :                 Size aSize = pChild->LogicToPixel( pCursor->GetSize() );
    1312           0 :                 if ( !aSize.Width() )
    1313           0 :                     aSize.Width() = pChild->GetSettings().GetStyleSettings().GetCursorSize();
    1314           0 :                 rRect = Rectangle( aPos, aSize );
    1315             :             }
    1316             :             else
    1317           0 :                 rRect = Rectangle( Point( pChild->GetOutOffXPixel(), pChild->GetOutOffYPixel() ), Size() );
    1318             :         }
    1319           0 :         rInputWidth = pChild->ImplLogicWidthToDevicePixel( pChild->GetCursorExtTextInputWidth() );
    1320           0 :         if ( !rInputWidth )
    1321           0 :             rInputWidth = rRect.GetWidth();
    1322             :     }
    1323           0 :     if (pVertical != 0)
    1324             :         *pVertical
    1325           0 :             = pChild != 0 && pChild->GetInputContext().GetFont().IsVertical();
    1326           0 : }
    1327             : 
    1328           0 : static bool ImplHandleInputContextChange( vcl::Window* pWindow, LanguageType eNewLang )
    1329             : {
    1330           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    1331           0 :     CommandInputContextData aData( eNewLang );
    1332           0 :     return !ImplCallCommand( pChild, COMMAND_INPUTCONTEXTCHANGE, &aData );
    1333             : }
    1334             : 
    1335           0 : static bool ImplCallWheelCommand( vcl::Window* pWindow, const Point& rPos,
    1336             :                                   const CommandWheelData* pWheelData )
    1337             : {
    1338           0 :     Point               aCmdMousePos = pWindow->ImplFrameToOutput( rPos );
    1339           0 :     CommandEvent        aCEvt( aCmdMousePos, COMMAND_WHEEL, true, pWheelData );
    1340           0 :     NotifyEvent         aNCmdEvt( EVENT_COMMAND, pWindow, &aCEvt );
    1341           0 :     ImplDelData         aDelData( pWindow );
    1342           0 :     bool bPreNotify = ImplCallPreNotify( aNCmdEvt );
    1343           0 :     if ( aDelData.IsDead() )
    1344           0 :         return false;
    1345           0 :     if ( !bPreNotify )
    1346             :     {
    1347           0 :         pWindow->ImplGetWindowImpl()->mbCommand = false;
    1348           0 :         pWindow->Command( aCEvt );
    1349           0 :         if ( aDelData.IsDead() )
    1350           0 :             return false;
    1351           0 :         if ( pWindow->ImplGetWindowImpl()->mbCommand )
    1352           0 :             return true;
    1353             :     }
    1354           0 :     return false;
    1355             : }
    1356             : 
    1357           0 : static bool acceptableWheelScrollTarget(const vcl::Window *pMouseWindow)
    1358             : {
    1359           0 :     return (pMouseWindow && pMouseWindow->IsInputEnabled() && !pMouseWindow->IsInModalMode());
    1360             : }
    1361             : 
    1362             : //If the last event at the same absolute screen position was handled by a
    1363             : //different window then reuse that window if the event occurs within 1/2 a
    1364             : //second, i.e. so scrolling down something like the calc sidebar that contains
    1365             : //widgets that respond to wheel events will continue to send the event to the
    1366             : //scrolling widget in favour of the widget that happens to end up under the
    1367             : //mouse.
    1368           0 : static bool shouldReusePreviousMouseWindow(const SalWheelMouseEvent& rPrevEvt, const SalWheelMouseEvent& rEvt)
    1369             : {
    1370           0 :     return (rEvt.mnX == rPrevEvt.mnX && rEvt.mnY == rPrevEvt.mnY && rEvt.mnTime-rPrevEvt.mnTime < 500/*ms*/);
    1371             : }
    1372             : 
    1373           0 : static bool ImplHandleWheelEvent( vcl::Window* pWindow, const SalWheelMouseEvent& rEvt, bool scaleDirectly = false )
    1374             : {
    1375           0 :     static SalWheelMouseEvent aPreviousEvent;
    1376             :     static vcl::Window *pPreviousWindow;
    1377             : 
    1378           0 :     ImplDelData aDogTag( pWindow );
    1379             : 
    1380           0 :     ImplSVData* pSVData = ImplGetSVData();
    1381           0 :     if ( pSVData->maWinData.mpAutoScrollWin )
    1382           0 :         pSVData->maWinData.mpAutoScrollWin->EndAutoScroll();
    1383           0 :     if ( pSVData->maHelpData.mpHelpWin )
    1384           0 :         ImplDestroyHelpWindow( true );
    1385           0 :     if( aDogTag.IsDead() )
    1386           0 :         return false;
    1387             : 
    1388             :     CommandWheelMode nMode;
    1389           0 :     sal_uInt16 nCode = rEvt.mnCode;
    1390           0 :     bool bHorz = rEvt.mbHorz;
    1391           0 :     bool bPixel = rEvt.mbDeltaIsPixel;
    1392           0 :     if ( scaleDirectly )
    1393           0 :         nMode = CommandWheelMode::ZOOM_SCALE;
    1394           0 :     else if ( nCode & KEY_MOD1 )
    1395           0 :         nMode = CommandWheelMode::ZOOM;
    1396           0 :     else if ( nCode & KEY_MOD2 )
    1397           0 :         nMode = CommandWheelMode::DATAZOOM;
    1398             :     else
    1399             :     {
    1400           0 :         nMode = CommandWheelMode::SCROLL;
    1401             :         // #i85450# interpret shift-wheel as horizontal wheel action
    1402           0 :         if( (nCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3)) == KEY_SHIFT )
    1403           0 :             bHorz = true;
    1404             :     }
    1405             : 
    1406           0 :     CommandWheelData    aWheelData( rEvt.mnDelta, rEvt.mnNotchDelta, rEvt.mnScrollLines, nMode, nCode, bHorz, bPixel );
    1407           0 :     Point               aMousePos( rEvt.mnX, rEvt.mnY );
    1408           0 :     bool                bRet = true;
    1409             : 
    1410             :     // first check any floating window ( eg. drop down listboxes)
    1411           0 :     bool bIsFloat = false;
    1412           0 :     vcl::Window *pMouseWindow = NULL;
    1413           0 :     if ( pSVData->maWinData.mpFirstFloat && !pSVData->maWinData.mpCaptureWin &&
    1414           0 :          !pSVData->maWinData.mpFirstFloat->ImplIsFloatPopupModeWindow( pWindow ) )
    1415             :     {
    1416           0 :         HitTest nHitTest = HITTEST_OUTSIDE;
    1417           0 :         pMouseWindow = pSVData->maWinData.mpFirstFloat->ImplFloatHitTest( pWindow, aMousePos, nHitTest );
    1418             :     }
    1419             :     // then try the window directly beneath the mouse
    1420           0 :     if( !pMouseWindow )
    1421           0 :         pMouseWindow = pWindow->ImplFindWindow( aMousePos );
    1422             :     else
    1423             :     {
    1424             :         // transform coordinates to float window frame coordinates
    1425             :         pMouseWindow = pMouseWindow->ImplFindWindow(
    1426             :                  pMouseWindow->OutputToScreenPixel(
    1427             :                   pMouseWindow->AbsoluteScreenToOutputPixel(
    1428             :                    pWindow->OutputToAbsoluteScreenPixel(
    1429           0 :                     pWindow->ScreenToOutputPixel( aMousePos ) ) ) ) );
    1430           0 :         bIsFloat = true;
    1431             :     }
    1432             : 
    1433           0 :     while (acceptableWheelScrollTarget(pMouseWindow))
    1434             :     {
    1435           0 :         if (pMouseWindow->IsEnabled())
    1436           0 :             break;
    1437             :         //try the parent if this one is disabled
    1438           0 :         pMouseWindow = pMouseWindow->GetParent();
    1439             :     }
    1440             : 
    1441             :     // avoid the problem that scrolling via wheel to this point brings a widget
    1442             :     // under the mouse that also accepts wheel commands, so stick with the old
    1443             :     // widget if the time gap is very small
    1444           0 :     if (shouldReusePreviousMouseWindow(aPreviousEvent, rEvt) && acceptableWheelScrollTarget(pPreviousWindow))
    1445             :     {
    1446           0 :         pMouseWindow = pPreviousWindow;
    1447             :     }
    1448             : 
    1449           0 :     aPreviousEvent = rEvt;
    1450             : 
    1451           0 :     if (acceptableWheelScrollTarget(pMouseWindow) && pMouseWindow->IsEnabled())
    1452             :     {
    1453             :         // transform coordinates to float window frame coordinates
    1454             :         Point aRelMousePos( pMouseWindow->OutputToScreenPixel(
    1455             :                              pMouseWindow->AbsoluteScreenToOutputPixel(
    1456             :                               pWindow->OutputToAbsoluteScreenPixel(
    1457           0 :                                pWindow->ScreenToOutputPixel( aMousePos ) ) ) ) );
    1458           0 :         bRet = ImplCallWheelCommand( pMouseWindow, aRelMousePos, &aWheelData );
    1459             :     }
    1460             : 
    1461           0 :     pPreviousWindow = !bRet ? pMouseWindow : NULL;
    1462             : 
    1463             :     // if the command was not handled try the focus window
    1464           0 :     if ( bRet )
    1465             :     {
    1466           0 :         vcl::Window* pFocusWindow = pWindow->ImplGetWindowImpl()->mpFrameData->mpFocusWin;
    1467           0 :         if ( pFocusWindow && (pFocusWindow != pMouseWindow) &&
    1468           0 :              (pFocusWindow == pSVData->maWinData.mpFocusWin) )
    1469             :         {
    1470             :             // no wheel-messages to disabled windows
    1471           0 :             if ( pFocusWindow->IsEnabled() && pFocusWindow->IsInputEnabled() && ! pFocusWindow->IsInModalMode() )
    1472             :             {
    1473             :                 // transform coordinates to focus window frame coordinates
    1474             :                 Point aRelMousePos( pFocusWindow->OutputToScreenPixel(
    1475             :                                      pFocusWindow->AbsoluteScreenToOutputPixel(
    1476             :                                       pWindow->OutputToAbsoluteScreenPixel(
    1477           0 :                                        pWindow->ScreenToOutputPixel( aMousePos ) ) ) ) );
    1478           0 :                 bRet = ImplCallWheelCommand( pFocusWindow, aRelMousePos, &aWheelData );
    1479             :             }
    1480             :         }
    1481             :     }
    1482             : 
    1483             :     // close floaters
    1484           0 :     if( ! bIsFloat && pSVData->maWinData.mpFirstFloat )
    1485             :     {
    1486           0 :         FloatingWindow* pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
    1487           0 :         if( pLastLevelFloat )
    1488             :         {
    1489           0 :             sal_uLong nPopupFlags = pLastLevelFloat->GetPopupModeFlags();
    1490           0 :             if ( nPopupFlags & FLOATWIN_POPUPMODE_ALLMOUSEBUTTONCLOSE )
    1491             :             {
    1492           0 :                 pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
    1493             :             }
    1494             :         }
    1495             :     }
    1496             : 
    1497           0 :     return !bRet;
    1498             : }
    1499             : 
    1500             : #define IMPL_PAINT_CHECKRTL         ((sal_uInt16)0x0020)
    1501             : 
    1502        5172 : static void ImplHandlePaint( vcl::Window* pWindow, const Rectangle& rBoundRect, bool bImmediateUpdate )
    1503             : {
    1504             :     // give up background save when system paints arrive
    1505        5172 :     vcl::Window* pSaveBackWin = pWindow->ImplGetWindowImpl()->mpFrameData->mpFirstBackWin;
    1506       10344 :     while ( pSaveBackWin )
    1507             :     {
    1508           0 :         vcl::Window* pNext = pSaveBackWin->ImplGetWindowImpl()->mpOverlapData->mpNextBackWin;
    1509             :         Rectangle aRect( Point( pSaveBackWin->GetOutOffXPixel(), pSaveBackWin->GetOutOffYPixel() ),
    1510           0 :                          Size( pSaveBackWin->GetOutputWidthPixel(), pSaveBackWin->GetOutputHeightPixel() ) );
    1511           0 :         if ( aRect.IsOver( rBoundRect ) )
    1512           0 :             pSaveBackWin->ImplDeleteOverlapBackground();
    1513           0 :         pSaveBackWin = pNext;
    1514             :     }
    1515             : 
    1516             :     // system paint events must be checked for re-mirroring
    1517        5172 :     pWindow->ImplGetWindowImpl()->mnPaintFlags |= IMPL_PAINT_CHECKRTL;
    1518             : 
    1519             :     // trigger paint for all windows that live in the new paint region
    1520        5172 :     vcl::Region aRegion( rBoundRect );
    1521        5172 :     pWindow->ImplInvalidateOverlapFrameRegion( aRegion );
    1522        5172 :     if( bImmediateUpdate )
    1523             :     {
    1524             :         // #i87663# trigger possible pending resize notifications
    1525             :         // (GetSizePixel does that for us)
    1526           0 :         pWindow->GetSizePixel();
    1527             :         // force drawing inmmediately
    1528           0 :         pWindow->Update();
    1529        5172 :     }
    1530        5172 : }
    1531             : 
    1532       10995 : static void KillOwnPopups( vcl::Window* pWindow )
    1533             : {
    1534       10995 :     ImplSVData* pSVData = ImplGetSVData();
    1535       10995 :     vcl::Window *pParent = pWindow->ImplGetWindowImpl()->mpFrameWindow;
    1536       10995 :     vcl::Window *pChild = pSVData->maWinData.mpFirstFloat;
    1537       10995 :     if ( pChild && pParent->ImplIsWindowOrChild( pChild, true ) )
    1538             :     {
    1539           0 :         if ( !(pSVData->maWinData.mpFirstFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE) )
    1540           0 :             pSVData->maWinData.mpFirstFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
    1541             :     }
    1542       10995 : }
    1543             : 
    1544       22094 : void ImplHandleResize( vcl::Window* pWindow, long nNewWidth, long nNewHeight )
    1545             : {
    1546       22094 :     if( pWindow->GetStyle() & (WB_MOVEABLE|WB_SIZEABLE) )
    1547             :     {
    1548       10995 :         KillOwnPopups( pWindow );
    1549       10995 :         if( pWindow->ImplGetWindow() != ImplGetSVData()->maHelpData.mpHelpWin )
    1550       10995 :             ImplDestroyHelpWindow( true );
    1551             :     }
    1552             : 
    1553       22094 :     if (
    1554       22133 :          (nNewWidth > 0 && nNewHeight > 0) ||
    1555          39 :          pWindow->ImplGetWindow()->ImplGetWindowImpl()->mbAllResize
    1556             :        )
    1557             :     {
    1558       22064 :         if ( (nNewWidth != pWindow->GetOutputWidthPixel()) || (nNewHeight != pWindow->GetOutputHeightPixel()) )
    1559             :         {
    1560       12170 :             pWindow->mnOutWidth  = nNewWidth;
    1561       12170 :             pWindow->mnOutHeight = nNewHeight;
    1562       12170 :             pWindow->ImplGetWindowImpl()->mbWaitSystemResize = false;
    1563       12170 :             if ( pWindow->IsReallyVisible() )
    1564         118 :                 pWindow->ImplSetClipFlag();
    1565       30887 :             if ( pWindow->IsVisible() || pWindow->ImplGetWindow()->ImplGetWindowImpl()->mbAllResize ||
    1566       13150 :                 ( pWindow->ImplGetWindowImpl()->mbFrame && pWindow->ImplGetWindowImpl()->mpClientWindow ) )   // propagate resize for system border windows
    1567             :             {
    1568       12142 :                 bool bStartTimer = true;
    1569             :                 // use resize buffering for user resizes
    1570             :                 // ownerdraw decorated windows and floating windows can be resized immediately (i.e. synchronously)
    1571       36426 :                 if( pWindow->ImplGetWindowImpl()->mbFrame && (pWindow->GetStyle() & WB_SIZEABLE)
    1572        5523 :                     && !(pWindow->GetStyle() & WB_OWNERDRAWDECORATION)  // synchronous resize for ownerdraw decorated windows (toolbars)
    1573       17665 :                     && !pWindow->ImplGetWindowImpl()->mbFloatWin )             // synchronous resize for floating windows, #i43799#
    1574             :                 {
    1575        5523 :                     if( pWindow->ImplGetWindowImpl()->mpClientWindow )
    1576             :                     {
    1577             :                         // #i42750# presentation wants to be informed about resize
    1578             :                         // as early as possible
    1579        5523 :                         WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pWindow->ImplGetWindowImpl()->mpClientWindow);
    1580        5523 :                         if( ! pWorkWindow || pWorkWindow->IsPresentationMode() )
    1581           0 :                             bStartTimer = false;
    1582             :                     }
    1583             :                     else
    1584             :                     {
    1585           0 :                         WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pWindow);
    1586           0 :                         if( ! pWorkWindow || pWorkWindow->IsPresentationMode() )
    1587           0 :                             bStartTimer = false;
    1588             :                     }
    1589             :                 }
    1590             :                 else
    1591        6619 :                     bStartTimer = false;
    1592             : 
    1593       12142 :                 if( bStartTimer )
    1594        5523 :                     pWindow->ImplGetWindowImpl()->mpFrameData->maResizeTimer.Start();
    1595             :                 else
    1596        6619 :                     pWindow->ImplCallResize(); // otherwise menus cannot be positioned
    1597             :             }
    1598             :             else
    1599          28 :                 pWindow->ImplGetWindowImpl()->mbCallResize = true;
    1600             :         }
    1601             :     }
    1602             : 
    1603       44188 :     pWindow->ImplGetWindowImpl()->mpFrameData->mbNeedSysWindow = (nNewWidth < IMPL_MIN_NEEDSYSWIN) ||
    1604       44188 :                                             (nNewHeight < IMPL_MIN_NEEDSYSWIN);
    1605       22094 :     bool bMinimized = (nNewWidth <= 0) || (nNewHeight <= 0);
    1606       22094 :     if( bMinimized != pWindow->ImplGetWindowImpl()->mpFrameData->mbMinimized )
    1607          47 :         pWindow->ImplGetWindowImpl()->mpFrameWindow->ImplNotifyIconifiedState( bMinimized );
    1608       22094 :     pWindow->ImplGetWindowImpl()->mpFrameData->mbMinimized = bMinimized;
    1609       22094 : }
    1610             : 
    1611           0 : static void ImplHandleMove( vcl::Window* pWindow )
    1612             : {
    1613           0 :     if( pWindow->ImplGetWindowImpl()->mbFrame && pWindow->ImplIsFloatingWindow() && pWindow->IsReallyVisible() )
    1614             :     {
    1615           0 :         static_cast<FloatingWindow*>(pWindow)->EndPopupMode( FLOATWIN_POPUPMODEEND_TEAROFF );
    1616           0 :         pWindow->ImplCallMove();
    1617             :     }
    1618             : 
    1619           0 :     if( pWindow->GetStyle() & (WB_MOVEABLE|WB_SIZEABLE) )
    1620             :     {
    1621           0 :         KillOwnPopups( pWindow );
    1622           0 :         if( pWindow->ImplGetWindow() != ImplGetSVData()->maHelpData.mpHelpWin )
    1623           0 :             ImplDestroyHelpWindow( true );
    1624             :     }
    1625             : 
    1626           0 :     if ( pWindow->IsVisible() )
    1627           0 :         pWindow->ImplCallMove();
    1628             :     else
    1629           0 :         pWindow->ImplGetWindowImpl()->mbCallMove = true; // make sure the framepos will be updated on the next Show()
    1630             : 
    1631           0 :     if ( pWindow->ImplGetWindowImpl()->mbFrame && pWindow->ImplGetWindowImpl()->mpClientWindow )
    1632           0 :         pWindow->ImplGetWindowImpl()->mpClientWindow->ImplCallMove();   // notify client to update geometry
    1633             : 
    1634           0 : }
    1635             : 
    1636           0 : static void ImplHandleMoveResize( vcl::Window* pWindow, long nNewWidth, long nNewHeight )
    1637             : {
    1638           0 :     ImplHandleMove( pWindow );
    1639           0 :     ImplHandleResize( pWindow, nNewWidth, nNewHeight );
    1640           0 : }
    1641             : 
    1642        5095 : static void ImplActivateFloatingWindows( vcl::Window* pWindow, bool bActive )
    1643             : {
    1644             :     // First check all overlapping windows
    1645        5095 :     vcl::Window* pTempWindow = pWindow->ImplGetWindowImpl()->mpFirstOverlap;
    1646       10190 :     while ( pTempWindow )
    1647             :     {
    1648           0 :         if ( !pTempWindow->GetActivateMode() )
    1649             :         {
    1650           0 :             if ( (pTempWindow->GetType() == WINDOW_BORDERWINDOW) &&
    1651           0 :                  (pTempWindow->ImplGetWindow()->GetType() == WINDOW_FLOATINGWINDOW) )
    1652           0 :                 static_cast<ImplBorderWindow*>(pTempWindow)->SetDisplayActive( bActive );
    1653             :         }
    1654             : 
    1655           0 :         ImplActivateFloatingWindows( pTempWindow, bActive );
    1656           0 :         pTempWindow = pTempWindow->ImplGetWindowImpl()->mpNext;
    1657             :     }
    1658        5095 : }
    1659             : 
    1660       10204 : IMPL_LINK_NOARG(vcl::Window, ImplAsyncFocusHdl)
    1661             : {
    1662        5102 :     ImplGetWindowImpl()->mpFrameData->mnFocusId = 0;
    1663             : 
    1664             :     // If the status has been preserved, because we got back the focus
    1665             :     // in the meantime, we do nothing
    1666        5102 :     bool bHasFocus = ImplGetWindowImpl()->mpFrameData->mbHasFocus || ImplGetWindowImpl()->mpFrameData->mbSysObjFocus;
    1667             : 
    1668             :     // next execute the delayed functions
    1669        5102 :     if ( bHasFocus )
    1670             :     {
    1671             :         // redraw all floating windows inactive
    1672        5047 :         if ( ImplGetWindowImpl()->mpFrameData->mbStartFocusState != bHasFocus )
    1673        5043 :             ImplActivateFloatingWindows( this, bHasFocus );
    1674             : 
    1675        5047 :         if ( ImplGetWindowImpl()->mpFrameData->mpFocusWin )
    1676             :         {
    1677        5047 :             bool bHandled = false;
    1678       10094 :             if ( ImplGetWindowImpl()->mpFrameData->mpFocusWin->IsInputEnabled() &&
    1679        5047 :                  ! ImplGetWindowImpl()->mpFrameData->mpFocusWin->IsInModalMode() )
    1680             :             {
    1681        5047 :                 if ( ImplGetWindowImpl()->mpFrameData->mpFocusWin->IsEnabled() )
    1682             :                 {
    1683        5047 :                     ImplGetWindowImpl()->mpFrameData->mpFocusWin->GrabFocus();
    1684        5047 :                     bHandled = true;
    1685             :                 }
    1686           0 :                 else if( ImplGetWindowImpl()->mpFrameData->mpFocusWin->ImplHasDlgCtrl() )
    1687             :                 {
    1688             :                 // #109094# if the focus is restored to a disabled dialog control (was disabled meanwhile)
    1689             :                 // try to move it to the next control
    1690           0 :                     ImplGetWindowImpl()->mpFrameData->mpFocusWin->ImplDlgCtrlNextWindow();
    1691           0 :                     bHandled = true;
    1692             :                 }
    1693             :             }
    1694        5047 :             if ( !bHandled )
    1695             :             {
    1696           0 :                 ImplSVData* pSVData = ImplGetSVData();
    1697           0 :                 vcl::Window*     pTopLevelWindow = ImplGetWindowImpl()->mpFrameData->mpFocusWin->ImplGetFirstOverlapWindow();
    1698           0 :                 if ( ( ! pTopLevelWindow->IsInputEnabled() || pTopLevelWindow->IsInModalMode() )
    1699           0 :                      && pSVData->maWinData.mpLastExecuteDlg )
    1700           0 :                     pSVData->maWinData.mpLastExecuteDlg->ToTop( TOTOP_RESTOREWHENMIN | TOTOP_GRABFOCUSONLY);
    1701             :                 else
    1702           0 :                     pTopLevelWindow->GrabFocus();
    1703             :             }
    1704             :         }
    1705             :         else
    1706           0 :             GrabFocus();
    1707             :     }
    1708             :     else
    1709             :     {
    1710          55 :         vcl::Window* pFocusWin = ImplGetWindowImpl()->mpFrameData->mpFocusWin;
    1711          55 :         if ( pFocusWin )
    1712             :         {
    1713          55 :             ImplSVData* pSVData = ImplGetSVData();
    1714             : 
    1715          55 :             if ( pSVData->maWinData.mpFocusWin == pFocusWin )
    1716             :             {
    1717             :                 // FocusWindow umsetzen
    1718          52 :                 vcl::Window* pOverlapWindow = pFocusWin->ImplGetFirstOverlapWindow();
    1719          52 :                 pOverlapWindow->ImplGetWindowImpl()->mpLastFocusWindow = pFocusWin;
    1720          52 :                 pSVData->maWinData.mpFocusWin = NULL;
    1721             : 
    1722          52 :                 if ( pFocusWin->ImplGetWindowImpl()->mpCursor )
    1723          14 :                     pFocusWin->ImplGetWindowImpl()->mpCursor->ImplHide( true );
    1724             : 
    1725             :                 // Deaktivate rufen
    1726          52 :                 vcl::Window* pOldFocusWindow = pFocusWin;
    1727          52 :                 if ( pOldFocusWindow )
    1728             :                 {
    1729          52 :                     vcl::Window* pOldOverlapWindow = pOldFocusWindow->ImplGetFirstOverlapWindow();
    1730          52 :                     vcl::Window* pOldRealWindow = pOldOverlapWindow->ImplGetWindow();
    1731             : 
    1732          52 :                     pOldOverlapWindow->ImplGetWindowImpl()->mbActive = false;
    1733          52 :                     pOldOverlapWindow->Deactivate();
    1734          52 :                     if ( pOldRealWindow != pOldOverlapWindow )
    1735             :                     {
    1736          52 :                         pOldRealWindow->ImplGetWindowImpl()->mbActive = false;
    1737          52 :                         pOldRealWindow->Deactivate();
    1738             :                     }
    1739             :                 }
    1740             : 
    1741             :                 // TrackingMode is ended in ImplHandleLoseFocus
    1742             :                 // To avoid problems with the Unix IME
    1743             :                 // pFocusWin->EndExtTextInput( EXTTEXTINPUT_END_COMPLETE );
    1744             : 
    1745             :                 // XXX #102010# hack for accessibility: do not close the menu,
    1746             :                 // even after focus lost
    1747          52 :                 static const char* pEnv = getenv("SAL_FLOATWIN_NOAPPFOCUSCLOSE");
    1748          52 :                 if( !(pEnv && *pEnv) )
    1749             :                 {
    1750          52 :                     NotifyEvent aNEvt( EVENT_LOSEFOCUS, pFocusWin );
    1751          52 :                     if ( !ImplCallPreNotify( aNEvt ) )
    1752          52 :                         pFocusWin->LoseFocus();
    1753          52 :                     pFocusWin->ImplCallDeactivateListeners( NULL );
    1754          52 :                     GetpApp()->FocusChanged();
    1755             :                 }
    1756             :                 // XXX
    1757             :             }
    1758             :         }
    1759             : 
    1760             :         // Redraw all floating window inactive
    1761          55 :         if ( ImplGetWindowImpl()->mpFrameData->mbStartFocusState != bHasFocus )
    1762          52 :             ImplActivateFloatingWindows( this, bHasFocus );
    1763             :     }
    1764             : 
    1765        5102 :     return 0;
    1766             : }
    1767             : 
    1768        5058 : static void ImplHandleGetFocus( vcl::Window* pWindow )
    1769             : {
    1770        5058 :     pWindow->ImplGetWindowImpl()->mpFrameData->mbHasFocus = true;
    1771             : 
    1772             :     // execute Focus-Events after a delay, such that SystemChildWindows
    1773             :     // do not blink when they receive focus
    1774        5058 :     if ( !pWindow->ImplGetWindowImpl()->mpFrameData->mnFocusId )
    1775             :     {
    1776        5054 :         pWindow->ImplGetWindowImpl()->mpFrameData->mbStartFocusState = !pWindow->ImplGetWindowImpl()->mpFrameData->mbHasFocus;
    1777        5054 :         pWindow->ImplGetWindowImpl()->mpFrameData->mnFocusId = Application::PostUserEvent( LINK( pWindow, vcl::Window, ImplAsyncFocusHdl ) );
    1778        5054 :         vcl::Window* pFocusWin = pWindow->ImplGetWindowImpl()->mpFrameData->mpFocusWin;
    1779        5054 :         if ( pFocusWin && pFocusWin->ImplGetWindowImpl()->mpCursor )
    1780          28 :             pFocusWin->ImplGetWindowImpl()->mpCursor->ImplShow();
    1781             :     }
    1782        5058 : }
    1783             : 
    1784          59 : static void ImplHandleLoseFocus( vcl::Window* pWindow )
    1785             : {
    1786          59 :     ImplSVData* pSVData = ImplGetSVData();
    1787             : 
    1788             :     // Abort the autoscroll if the frame loses focus
    1789          59 :     if ( pSVData->maWinData.mpAutoScrollWin )
    1790           0 :         pSVData->maWinData.mpAutoScrollWin->EndAutoScroll();
    1791             : 
    1792             :     // Abort tracking if the frame loses focus
    1793          59 :     if ( pSVData->maWinData.mpTrackWin )
    1794             :     {
    1795           0 :         if ( pSVData->maWinData.mpTrackWin->ImplGetWindowImpl()->mpFrameWindow == pWindow )
    1796           0 :             pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL );
    1797             :     }
    1798             : 
    1799             :     // here we always terminate the popupmode, also when NOFOCUSCLOSE
    1800             :     // is set, such that we do not show windows during the switch
    1801          59 :     if ( pSVData->maWinData.mpFirstFloat )
    1802             :     {
    1803           0 :         if ( !(pSVData->maWinData.mpFirstFloat->GetPopupModeFlags() & FLOATWIN_POPUPMODE_NOAPPFOCUSCLOSE) )
    1804           0 :             pSVData->maWinData.mpFirstFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
    1805             :     }
    1806             : 
    1807          59 :     pWindow->ImplGetWindowImpl()->mpFrameData->mbHasFocus = false;
    1808             : 
    1809             :     // execute Focus-Events after a delay, such that SystemChildWindows
    1810             :     // do not flicker when they receive focus
    1811          59 :     if ( !pWindow->ImplGetWindowImpl()->mpFrameData->mnFocusId )
    1812             :     {
    1813          56 :         pWindow->ImplGetWindowImpl()->mpFrameData->mbStartFocusState = !pWindow->ImplGetWindowImpl()->mpFrameData->mbHasFocus;
    1814          56 :         pWindow->ImplGetWindowImpl()->mpFrameData->mnFocusId = Application::PostUserEvent( LINK( pWindow, vcl::Window, ImplAsyncFocusHdl ) );
    1815             :     }
    1816             : 
    1817          59 :     vcl::Window* pFocusWin = pWindow->ImplGetWindowImpl()->mpFrameData->mpFocusWin;
    1818          59 :     if ( pFocusWin && pFocusWin->ImplGetWindowImpl()->mpCursor )
    1819          14 :         pFocusWin->ImplGetWindowImpl()->mpCursor->ImplHide( true );
    1820          59 : }
    1821             : 
    1822           0 : struct DelayedCloseEvent
    1823             : {
    1824             :     vcl::Window*         pWindow;
    1825             :     ImplDelData     aDelData;
    1826             : };
    1827             : 
    1828           0 : static long DelayedCloseEventLink( void* pCEvent, void* )
    1829             : {
    1830           0 :     DelayedCloseEvent* pEv = (DelayedCloseEvent*)pCEvent;
    1831             : 
    1832           0 :     if( ! pEv->aDelData.IsDead() )
    1833             :     {
    1834           0 :         pEv->pWindow->ImplRemoveDel( &pEv->aDelData );
    1835             :         // dispatch to correct window type
    1836           0 :         if( pEv->pWindow->IsSystemWindow() )
    1837           0 :             static_cast<SystemWindow*>(pEv->pWindow)->Close();
    1838           0 :         else if( pEv->pWindow->ImplIsDockingWindow() )
    1839           0 :             static_cast<DockingWindow*>(pEv->pWindow)->Close();
    1840             :     }
    1841           0 :     delete pEv;
    1842             : 
    1843           0 :     return 0;
    1844             : }
    1845             : 
    1846           0 : void ImplHandleClose( vcl::Window* pWindow )
    1847             : {
    1848           0 :     ImplSVData* pSVData = ImplGetSVData();
    1849             : 
    1850           0 :     bool bWasPopup = false;
    1851           0 :     if( pWindow->ImplIsFloatingWindow() &&
    1852           0 :         static_cast<FloatingWindow*>(pWindow)->ImplIsInPrivatePopupMode() )
    1853             :     {
    1854           0 :         bWasPopup = true;
    1855             :     }
    1856             : 
    1857             :     // on Close stop all floating modes and end popups
    1858           0 :     if ( pSVData->maWinData.mpFirstFloat )
    1859             :     {
    1860             :         FloatingWindow* pLastLevelFloat;
    1861           0 :         pLastLevelFloat = pSVData->maWinData.mpFirstFloat->ImplFindLastLevelFloat();
    1862           0 :         pLastLevelFloat->EndPopupMode( FLOATWIN_POPUPMODEEND_CANCEL | FLOATWIN_POPUPMODEEND_CLOSEALL );
    1863             :     }
    1864           0 :     if ( pSVData->maHelpData.mbExtHelpMode )
    1865           0 :         Help::EndExtHelp();
    1866           0 :     if ( pSVData->maHelpData.mpHelpWin )
    1867           0 :         ImplDestroyHelpWindow( false );
    1868             :     // AutoScrollMode
    1869           0 :     if ( pSVData->maWinData.mpAutoScrollWin )
    1870           0 :         pSVData->maWinData.mpAutoScrollWin->EndAutoScroll();
    1871             : 
    1872           0 :     if ( pSVData->maWinData.mpTrackWin )
    1873           0 :         pSVData->maWinData.mpTrackWin->EndTracking( ENDTRACK_CANCEL | ENDTRACK_KEY );
    1874             : 
    1875           0 :     if (bWasPopup)
    1876           0 :         return;
    1877             : 
    1878           0 :     vcl::Window *pWin = pWindow->ImplGetWindow();
    1879           0 :     SystemWindow* pSysWin = dynamic_cast<SystemWindow*>(pWin);
    1880           0 :     if (pSysWin)
    1881             :     {
    1882             :         // See if the custom close handler is set.
    1883           0 :         const Link& rLink = pSysWin->GetCloseHdl();
    1884           0 :         if (rLink.IsSet())
    1885             :         {
    1886           0 :             rLink.Call(pSysWin);
    1887           0 :             return;
    1888             :         }
    1889             :     }
    1890             : 
    1891             :     // check whether close is allowed
    1892           0 :     if ( pWin->IsEnabled() && pWin->IsInputEnabled() && !pWin->IsInModalMode() )
    1893             :     {
    1894           0 :         DelayedCloseEvent* pEv = new DelayedCloseEvent;
    1895           0 :         pEv->pWindow = pWin;
    1896           0 :         pWin->ImplAddDel( &pEv->aDelData );
    1897           0 :         Application::PostUserEvent( Link( pEv, DelayedCloseEventLink ) );
    1898             :     }
    1899             : }
    1900             : 
    1901       80270 : static void ImplHandleUserEvent( ImplSVEvent* pSVEvent )
    1902             : {
    1903       80270 :     if ( pSVEvent )
    1904             :     {
    1905       80270 :         if ( pSVEvent->mbCall && !pSVEvent->maDelData.IsDead() )
    1906             :         {
    1907       31914 :             if ( pSVEvent->mpWindow )
    1908             :             {
    1909           0 :                 pSVEvent->mpWindow->ImplRemoveDel( &(pSVEvent->maDelData) );
    1910           0 :                 pSVEvent->mpLink->Call( pSVEvent->mpData );
    1911             :             }
    1912             :             else
    1913             :             {
    1914       31914 :                 pSVEvent->mpLink->Call( pSVEvent->mpData );
    1915             :             }
    1916             :         }
    1917             : 
    1918       80270 :         delete pSVEvent->mpLink;
    1919       80270 :         delete pSVEvent;
    1920             :     }
    1921       80270 : }
    1922             : 
    1923           0 : static sal_uInt16 ImplGetMouseMoveMode( SalMouseEvent* pEvent )
    1924             : {
    1925           0 :     sal_uInt16 nMode = 0;
    1926           0 :     if ( !pEvent->mnCode )
    1927           0 :         nMode |= MOUSE_SIMPLEMOVE;
    1928           0 :     if ( (pEvent->mnCode & MOUSE_LEFT) && !(pEvent->mnCode & KEY_MOD1) )
    1929           0 :         nMode |= MOUSE_DRAGMOVE;
    1930           0 :     if ( (pEvent->mnCode & MOUSE_LEFT) && (pEvent->mnCode & KEY_MOD1) )
    1931           0 :         nMode |= MOUSE_DRAGCOPY;
    1932           0 :     return nMode;
    1933             : }
    1934             : 
    1935           0 : static sal_uInt16 ImplGetMouseButtonMode( SalMouseEvent* pEvent )
    1936             : {
    1937           0 :     sal_uInt16 nMode = 0;
    1938           0 :     if ( pEvent->mnButton == MOUSE_LEFT )
    1939           0 :         nMode |= MOUSE_SIMPLECLICK;
    1940           0 :     if ( (pEvent->mnButton == MOUSE_LEFT) && !(pEvent->mnCode & (MOUSE_MIDDLE | MOUSE_RIGHT)) )
    1941           0 :         nMode |= MOUSE_SELECT;
    1942           0 :     if ( (pEvent->mnButton == MOUSE_LEFT) && (pEvent->mnCode & KEY_MOD1) &&
    1943           0 :          !(pEvent->mnCode & (MOUSE_MIDDLE | MOUSE_RIGHT | KEY_SHIFT)) )
    1944           0 :         nMode |= MOUSE_MULTISELECT;
    1945           0 :     if ( (pEvent->mnButton == MOUSE_LEFT) && (pEvent->mnCode & KEY_SHIFT) &&
    1946           0 :          !(pEvent->mnCode & (MOUSE_MIDDLE | MOUSE_RIGHT | KEY_MOD1)) )
    1947           0 :         nMode |= MOUSE_RANGESELECT;
    1948           0 :     return nMode;
    1949             : }
    1950             : 
    1951           0 : inline bool ImplHandleSalMouseLeave( vcl::Window* pWindow, SalMouseEvent* pEvent )
    1952             : {
    1953             :     return ImplHandleMouseEvent( pWindow, EVENT_MOUSEMOVE, true,
    1954             :                                  pEvent->mnX, pEvent->mnY,
    1955             :                                  pEvent->mnTime, pEvent->mnCode,
    1956           0 :                                  ImplGetMouseMoveMode( pEvent ) );
    1957             : }
    1958             : 
    1959           0 : inline bool ImplHandleSalMouseMove( vcl::Window* pWindow, SalMouseEvent* pEvent )
    1960             : {
    1961             :     return ImplHandleMouseEvent( pWindow, EVENT_MOUSEMOVE, false,
    1962             :                                  pEvent->mnX, pEvent->mnY,
    1963             :                                  pEvent->mnTime, pEvent->mnCode,
    1964           0 :                                  ImplGetMouseMoveMode( pEvent ) );
    1965             : }
    1966             : 
    1967           0 : inline bool ImplHandleSalMouseButtonDown( vcl::Window* pWindow, SalMouseEvent* pEvent )
    1968             : {
    1969             :     return ImplHandleMouseEvent( pWindow, EVENT_MOUSEBUTTONDOWN, false,
    1970             :                                  pEvent->mnX, pEvent->mnY,
    1971             :                                  pEvent->mnTime,
    1972             : #ifdef MACOSX
    1973             :                  pEvent->mnButton | (pEvent->mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3)),
    1974             : #else
    1975             :                                  pEvent->mnButton | (pEvent->mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)),
    1976             : #endif
    1977           0 :                                  ImplGetMouseButtonMode( pEvent ) );
    1978             : }
    1979             : 
    1980           0 : inline bool ImplHandleSalMouseButtonUp( vcl::Window* pWindow, SalMouseEvent* pEvent )
    1981             : {
    1982             :     return ImplHandleMouseEvent( pWindow, EVENT_MOUSEBUTTONUP, false,
    1983             :                                  pEvent->mnX, pEvent->mnY,
    1984             :                                  pEvent->mnTime,
    1985             : #ifdef MACOSX
    1986             :                  pEvent->mnButton | (pEvent->mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3)),
    1987             : #else
    1988             :                                  pEvent->mnButton | (pEvent->mnCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2)),
    1989             : #endif
    1990           0 :                                  ImplGetMouseButtonMode( pEvent ) );
    1991             : }
    1992             : 
    1993           0 : static bool ImplHandleSalMouseActivate( vcl::Window* /*pWindow*/, SalMouseActivateEvent* /*pEvent*/ )
    1994             : {
    1995           0 :     return false;
    1996             : }
    1997             : 
    1998           0 : static bool ImplHandleMenuEvent( vcl::Window* pWindow, SalMenuEvent* pEvent, sal_uInt16 nEvent )
    1999             : {
    2000             :     // Find SystemWindow and its Menubar and let it dispatch the command
    2001           0 :     bool nRet = false;
    2002           0 :     vcl::Window *pWin = pWindow->ImplGetWindowImpl()->mpFirstChild;
    2003           0 :     while ( pWin )
    2004             :     {
    2005           0 :         if ( pWin->ImplGetWindowImpl()->mbSysWin )
    2006           0 :             break;
    2007           0 :         pWin = pWin->ImplGetWindowImpl()->mpNext;
    2008             :     }
    2009           0 :     if( pWin )
    2010             :     {
    2011           0 :         MenuBar *pMenuBar = static_cast<SystemWindow*>(pWin)->GetMenuBar();
    2012           0 :         if( pMenuBar )
    2013             :         {
    2014           0 :             switch( nEvent )
    2015             :             {
    2016             :                 case SALEVENT_MENUACTIVATE:
    2017           0 :                     nRet = pMenuBar->HandleMenuActivateEvent( (Menu*) pEvent->mpMenu );
    2018           0 :                     break;
    2019             :                 case SALEVENT_MENUDEACTIVATE:
    2020           0 :                     nRet = pMenuBar->HandleMenuDeActivateEvent( (Menu*) pEvent->mpMenu );
    2021           0 :                     break;
    2022             :                 case SALEVENT_MENUHIGHLIGHT:
    2023           0 :                     nRet = pMenuBar->HandleMenuHighlightEvent( (Menu*) pEvent->mpMenu, pEvent->mnId );
    2024           0 :                     break;
    2025             :                 case SALEVENT_MENUBUTTONCOMMAND:
    2026           0 :                     nRet = pMenuBar->HandleMenuButtonEvent( (Menu*) pEvent->mpMenu, pEvent->mnId );
    2027           0 :                     break;
    2028             :                 case SALEVENT_MENUCOMMAND:
    2029           0 :                     nRet = pMenuBar->HandleMenuCommandEvent( (Menu*) pEvent->mpMenu, pEvent->mnId );
    2030           0 :                     break;
    2031             :                 default:
    2032           0 :                     break;
    2033             :             }
    2034             :         }
    2035             :     }
    2036           0 :     return nRet;
    2037             : }
    2038             : 
    2039           0 : static void ImplHandleSalKeyMod( vcl::Window* pWindow, SalKeyModEvent* pEvent )
    2040             : {
    2041           0 :     ImplSVData* pSVData = ImplGetSVData();
    2042           0 :     vcl::Window* pTrackWin = pSVData->maWinData.mpTrackWin;
    2043           0 :     if ( pTrackWin )
    2044           0 :         pWindow = pTrackWin;
    2045             : #ifdef MACOSX
    2046             :     sal_uInt16 nOldCode = pWindow->ImplGetWindowImpl()->mpFrameData->mnMouseCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3);
    2047             : #else
    2048           0 :     sal_uInt16 nOldCode = pWindow->ImplGetWindowImpl()->mpFrameData->mnMouseCode & (KEY_SHIFT | KEY_MOD1 | KEY_MOD2);
    2049             : #endif
    2050           0 :     sal_uInt16 nNewCode = pEvent->mnCode;
    2051           0 :     if ( nOldCode != nNewCode )
    2052             :     {
    2053             : #ifdef MACOSX
    2054             :     nNewCode |= pWindow->ImplGetWindowImpl()->mpFrameData->mnMouseCode & ~(KEY_SHIFT | KEY_MOD1 | KEY_MOD2 | KEY_MOD3);
    2055             : #else
    2056           0 :         nNewCode |= pWindow->ImplGetWindowImpl()->mpFrameData->mnMouseCode & ~(KEY_SHIFT | KEY_MOD1 | KEY_MOD2);
    2057             : #endif
    2058           0 :         pWindow->ImplGetWindowImpl()->mpFrameWindow->ImplCallMouseMove( nNewCode, true );
    2059             :     }
    2060             : 
    2061             :     // #105224# send commandevent to allow special treatment of Ctrl-LeftShift/Ctrl-RightShift etc.
    2062             : 
    2063             :     // find window
    2064           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    2065           0 :     if ( !pChild )
    2066           0 :         return;
    2067             : 
    2068             :     // send modkey events only if useful data is available
    2069           0 :     if( pEvent->mnModKeyCode != 0 )
    2070             :     {
    2071           0 :         CommandModKeyData data( pEvent->mnModKeyCode );
    2072           0 :         ImplCallCommand( pChild, COMMAND_MODKEYCHANGE, &data );
    2073             :     }
    2074             : }
    2075             : 
    2076           0 : static void ImplHandleInputLanguageChange( vcl::Window* pWindow )
    2077             : {
    2078             :     // find window
    2079           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    2080           0 :     if ( !pChild )
    2081           0 :         return;
    2082             : 
    2083           0 :     ImplCallCommand( pChild, COMMAND_INPUTLANGUAGECHANGE );
    2084             : }
    2085             : 
    2086           0 : static void ImplHandleSalSettings( sal_uInt16 nEvent )
    2087             : {
    2088           0 :     Application* pApp = GetpApp();
    2089           0 :     if ( !pApp )
    2090           0 :         return;
    2091             : 
    2092           0 :     if ( nEvent == SALEVENT_SETTINGSCHANGED )
    2093             :     {
    2094           0 :         AllSettings aSettings = Application::GetSettings();
    2095           0 :         Application::MergeSystemSettings( aSettings );
    2096           0 :         pApp->OverrideSystemSettings( aSettings );
    2097           0 :         Application::SetSettings( aSettings );
    2098             :     }
    2099             :     else
    2100             :     {
    2101             :         sal_uInt16 nType;
    2102           0 :         switch ( nEvent )
    2103             :         {
    2104             :             case SALEVENT_VOLUMECHANGED:
    2105           0 :                 nType = 0;
    2106           0 :                 break;
    2107             :             case SALEVENT_PRINTERCHANGED:
    2108           0 :                 ImplDeletePrnQueueList();
    2109           0 :                 nType = DATACHANGED_PRINTER;
    2110           0 :                 break;
    2111             :             case SALEVENT_DISPLAYCHANGED:
    2112           0 :                 nType = DATACHANGED_DISPLAY;
    2113           0 :                 break;
    2114             :             case SALEVENT_FONTCHANGED:
    2115           0 :                 OutputDevice::ImplUpdateAllFontData( true );
    2116           0 :                 nType = DATACHANGED_FONTS;
    2117           0 :                 break;
    2118             :             case SALEVENT_DATETIMECHANGED:
    2119           0 :                 nType = DATACHANGED_DATETIME;
    2120           0 :                 break;
    2121             :             case SALEVENT_KEYBOARDCHANGED:
    2122           0 :                 nType = 0;
    2123           0 :                 break;
    2124             :             default:
    2125           0 :                 nType = 0;
    2126           0 :                 break;
    2127             :         }
    2128             : 
    2129           0 :         if ( nType )
    2130             :         {
    2131           0 :             DataChangedEvent aDCEvt( nType );
    2132           0 :             pApp->DataChanged( aDCEvt );
    2133           0 :             Application::NotifyAllWindows( aDCEvt );
    2134             :         }
    2135             :     }
    2136             : }
    2137             : 
    2138           0 : static void ImplHandleSalExtTextInputPos( vcl::Window* pWindow, SalExtTextInputPosEvent* pEvt )
    2139             : {
    2140           0 :     Rectangle aCursorRect;
    2141           0 :     ImplHandleExtTextInputPos( pWindow, aCursorRect, pEvt->mnExtWidth, &pEvt->mbVertical );
    2142           0 :     if ( aCursorRect.IsEmpty() )
    2143             :     {
    2144           0 :         pEvt->mnX       = -1;
    2145           0 :         pEvt->mnY       = -1;
    2146           0 :         pEvt->mnWidth   = -1;
    2147           0 :         pEvt->mnHeight  = -1;
    2148             :     }
    2149             :     else
    2150             :     {
    2151           0 :         pEvt->mnX       = aCursorRect.Left();
    2152           0 :         pEvt->mnY       = aCursorRect.Top();
    2153           0 :         pEvt->mnWidth   = aCursorRect.GetWidth();
    2154           0 :         pEvt->mnHeight  = aCursorRect.GetHeight();
    2155             :     }
    2156           0 : }
    2157             : 
    2158           0 : static bool ImplHandleShowDialog( vcl::Window* pWindow, int nDialogId )
    2159             : {
    2160           0 :     if( ! pWindow )
    2161           0 :         return false;
    2162             : 
    2163           0 :     if( pWindow->GetType() == WINDOW_BORDERWINDOW )
    2164             :     {
    2165           0 :         vcl::Window* pWrkWin = pWindow->GetWindow( WINDOW_CLIENT );
    2166           0 :         if( pWrkWin )
    2167           0 :             pWindow = pWrkWin;
    2168             :     }
    2169           0 :     CommandDialogData aCmdData( nDialogId );
    2170           0 :     return ImplCallCommand( pWindow, COMMAND_SHOWDIALOG, &aCmdData );
    2171             : }
    2172             : 
    2173           0 : static void ImplHandleSurroundingTextRequest( vcl::Window *pWindow,
    2174             :                           OUString& rText,
    2175             :                           Selection &rSelRange )
    2176             : {
    2177           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    2178             : 
    2179           0 :     if ( !pChild )
    2180             :     {
    2181           0 :     rText = OUString();
    2182           0 :     rSelRange.setMin( 0 );
    2183           0 :     rSelRange.setMax( 0 );
    2184             :     }
    2185             :     else
    2186             :     {
    2187           0 :     rText = pChild->GetSurroundingText();
    2188           0 :     Selection aSel = pChild->GetSurroundingTextSelection();
    2189           0 :     rSelRange.setMin( aSel.Min() );
    2190           0 :     rSelRange.setMax( aSel.Max() );
    2191             :     }
    2192           0 : }
    2193             : 
    2194           0 : static void ImplHandleSalSurroundingTextRequest( vcl::Window *pWindow,
    2195             :                          SalSurroundingTextRequestEvent *pEvt )
    2196             : {
    2197           0 :     Selection aSelRange;
    2198           0 :     ImplHandleSurroundingTextRequest( pWindow, pEvt->maText, aSelRange );
    2199             : 
    2200           0 :     aSelRange.Justify();
    2201             : 
    2202           0 :     if( aSelRange.Min() < 0 )
    2203           0 :         pEvt->mnStart = 0;
    2204           0 :     else if( aSelRange.Min() > pEvt->maText.getLength() )
    2205           0 :         pEvt->mnStart = pEvt->maText.getLength();
    2206             :     else
    2207           0 :         pEvt->mnStart = aSelRange.Min();
    2208             : 
    2209           0 :     if( aSelRange.Max() < 0 )
    2210           0 :         pEvt->mnStart = 0;
    2211           0 :     else if( aSelRange.Max() > pEvt->maText.getLength() )
    2212           0 :         pEvt->mnEnd = pEvt->maText.getLength();
    2213             :     else
    2214           0 :         pEvt->mnEnd = aSelRange.Max();
    2215           0 : }
    2216             : 
    2217           0 : static void ImplHandleSurroundingTextSelectionChange( vcl::Window *pWindow,
    2218             :                               sal_uLong nStart,
    2219             :                               sal_uLong nEnd )
    2220             : {
    2221           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    2222           0 :     if( pChild )
    2223             :     {
    2224           0 :         CommandSelectionChangeData data( nStart, nEnd );
    2225           0 :         ImplCallCommand( pChild, COMMAND_SELECTIONCHANGE, &data );
    2226             :     }
    2227           0 : }
    2228             : 
    2229           0 : static void ImplHandleStartReconversion( vcl::Window *pWindow )
    2230             : {
    2231           0 :     vcl::Window* pChild = ImplGetKeyInputWindow( pWindow );
    2232           0 :     if( pChild )
    2233           0 :     ImplCallCommand( pChild, COMMAND_PREPARERECONVERSION );
    2234           0 : }
    2235             : 
    2236           0 : static void ImplHandleSalQueryCharPosition( vcl::Window *pWindow,
    2237             :                                             SalQueryCharPositionEvent *pEvt )
    2238             : {
    2239           0 :     pEvt->mbValid = false;
    2240           0 :     pEvt->mbVertical = false;
    2241           0 :     pEvt->mnCursorBoundX = 0;
    2242           0 :     pEvt->mnCursorBoundY = 0;
    2243           0 :     pEvt->mnCursorBoundWidth = 0;
    2244           0 :     pEvt->mnCursorBoundHeight = 0;
    2245             : 
    2246           0 :     ImplSVData* pSVData = ImplGetSVData();
    2247           0 :     vcl::Window*     pChild = pSVData->maWinData.mpExtTextInputWin;
    2248             : 
    2249           0 :     if ( !pChild )
    2250           0 :         pChild = ImplGetKeyInputWindow( pWindow );
    2251             :     else
    2252             :     {
    2253             :         // Test, if the Window is related to the frame
    2254           0 :         if ( !pWindow->ImplIsWindowOrChild( pChild ) )
    2255           0 :             pChild = ImplGetKeyInputWindow( pWindow );
    2256             :     }
    2257             : 
    2258           0 :     if( pChild )
    2259             :     {
    2260           0 :         ImplCallCommand( pChild, COMMAND_QUERYCHARPOSITION );
    2261             : 
    2262           0 :         ImplWinData* pWinData = pChild->ImplGetWinData();
    2263           0 :         if ( pWinData->mpCompositionCharRects && pEvt->mnCharPos < static_cast<sal_uLong>( pWinData->mnCompositionCharRects ) )
    2264             :         {
    2265           0 :             const OutputDevice *pChildOutDev = pChild->GetOutDev();
    2266           0 :             const Rectangle& aRect = pWinData->mpCompositionCharRects[ pEvt->mnCharPos ];
    2267           0 :             Rectangle aDeviceRect = pChildOutDev->ImplLogicToDevicePixel( aRect );
    2268           0 :             Point aAbsScreenPos = pChild->OutputToAbsoluteScreenPixel( pChild->ScreenToOutputPixel(aDeviceRect.TopLeft()) );
    2269           0 :             pEvt->mnCursorBoundX = aAbsScreenPos.X();
    2270           0 :             pEvt->mnCursorBoundY = aAbsScreenPos.Y();
    2271           0 :             pEvt->mnCursorBoundWidth = aDeviceRect.GetWidth();
    2272           0 :             pEvt->mnCursorBoundHeight = aDeviceRect.GetHeight();
    2273           0 :             pEvt->mbVertical = pWinData->mbVertical;
    2274           0 :             pEvt->mbValid = true;
    2275             :         }
    2276             :     }
    2277           0 : }
    2278             : 
    2279       95766 : bool ImplWindowFrameProc( vcl::Window* pWindow, SalFrame* /*pFrame*/,
    2280             :                           sal_uInt16 nEvent, const void* pEvent )
    2281             : {
    2282             :     DBG_TESTSOLARMUTEX();
    2283             : 
    2284       95766 :     bool nRet = false;
    2285             : 
    2286             :     // #119709# for some unknown reason it is possible to receive events (in this case key events)
    2287             :     // although the corresponding VCL window must have been destroyed already
    2288             :     // at least ImplGetWindowImpl() was NULL in these cases, so check this here
    2289       95766 :     if( pWindow->ImplGetWindowImpl() == NULL )
    2290           0 :         return false;
    2291             : 
    2292       95766 :     switch ( nEvent )
    2293             :     {
    2294             :         case SALEVENT_MOUSEMOVE:
    2295           0 :             nRet = ImplHandleSalMouseMove( pWindow, (SalMouseEvent*)pEvent );
    2296           0 :             break;
    2297             :         case SALEVENT_EXTERNALMOUSEMOVE:
    2298             :         {
    2299           0 :             MouseEvent*     pMouseEvt = (MouseEvent*) pEvent;
    2300             :             SalMouseEvent   aSalMouseEvent;
    2301             : 
    2302           0 :             aSalMouseEvent.mnTime = tools::Time::GetSystemTicks();
    2303           0 :             aSalMouseEvent.mnX = pMouseEvt->GetPosPixel().X();
    2304           0 :             aSalMouseEvent.mnY = pMouseEvt->GetPosPixel().Y();
    2305           0 :             aSalMouseEvent.mnButton = 0;
    2306           0 :             aSalMouseEvent.mnCode = pMouseEvt->GetButtons() | pMouseEvt->GetModifier();
    2307             : 
    2308           0 :             nRet = ImplHandleSalMouseMove( pWindow, &aSalMouseEvent );
    2309             :         }
    2310           0 :         break;
    2311             :         case SALEVENT_MOUSELEAVE:
    2312           0 :             nRet = ImplHandleSalMouseLeave( pWindow, (SalMouseEvent*)pEvent );
    2313           0 :             break;
    2314             :         case SALEVENT_MOUSEBUTTONDOWN:
    2315           0 :             nRet = ImplHandleSalMouseButtonDown( pWindow, (SalMouseEvent*)pEvent );
    2316           0 :             break;
    2317             :         case SALEVENT_EXTERNALMOUSEBUTTONDOWN:
    2318             :         {
    2319           0 :             MouseEvent*     pMouseEvt = (MouseEvent*) pEvent;
    2320             :             SalMouseEvent   aSalMouseEvent;
    2321             : 
    2322           0 :             aSalMouseEvent.mnTime = tools::Time::GetSystemTicks();
    2323           0 :             aSalMouseEvent.mnX = pMouseEvt->GetPosPixel().X();
    2324           0 :             aSalMouseEvent.mnY = pMouseEvt->GetPosPixel().Y();
    2325           0 :             aSalMouseEvent.mnButton = pMouseEvt->GetButtons();
    2326           0 :             aSalMouseEvent.mnCode = pMouseEvt->GetButtons() | pMouseEvt->GetModifier();
    2327             : 
    2328           0 :             nRet = ImplHandleSalMouseButtonDown( pWindow, &aSalMouseEvent );
    2329             :         }
    2330           0 :         break;
    2331             :         case SALEVENT_MOUSEBUTTONUP:
    2332           0 :             nRet = ImplHandleSalMouseButtonUp( pWindow, (SalMouseEvent*)pEvent );
    2333           0 :             break;
    2334             :         case SALEVENT_EXTERNALMOUSEBUTTONUP:
    2335             :         {
    2336           0 :             MouseEvent*     pMouseEvt = (MouseEvent*) pEvent;
    2337             :             SalMouseEvent   aSalMouseEvent;
    2338             : 
    2339           0 :             aSalMouseEvent.mnTime = tools::Time::GetSystemTicks();
    2340           0 :             aSalMouseEvent.mnX = pMouseEvt->GetPosPixel().X();
    2341           0 :             aSalMouseEvent.mnY = pMouseEvt->GetPosPixel().Y();
    2342           0 :             aSalMouseEvent.mnButton = pMouseEvt->GetButtons();
    2343           0 :             aSalMouseEvent.mnCode = pMouseEvt->GetButtons() | pMouseEvt->GetModifier();
    2344             : 
    2345           0 :             nRet = ImplHandleSalMouseButtonUp( pWindow, &aSalMouseEvent );
    2346             :         }
    2347           0 :         break;
    2348             :         case SALEVENT_MOUSEACTIVATE:
    2349           0 :             nRet = ImplHandleSalMouseActivate( pWindow, (SalMouseActivateEvent*)pEvent );
    2350           0 :             break;
    2351             :         case SALEVENT_KEYINPUT:
    2352             :             {
    2353           0 :             SalKeyEvent* pKeyEvt = (SalKeyEvent*)pEvent;
    2354             :             nRet = ImplHandleKey( pWindow, EVENT_KEYINPUT,
    2355           0 :                 pKeyEvt->mnCode, pKeyEvt->mnCharCode, pKeyEvt->mnRepeat, true );
    2356             :             }
    2357           0 :             break;
    2358             :         case SALEVENT_EXTERNALKEYINPUT:
    2359             :             {
    2360           0 :             KeyEvent* pKeyEvt = (KeyEvent*) pEvent;
    2361             :             nRet = ImplHandleKey( pWindow, EVENT_KEYINPUT,
    2362           0 :                 pKeyEvt->GetKeyCode().GetFullCode(), pKeyEvt->GetCharCode(), pKeyEvt->GetRepeat(), false );
    2363             :             }
    2364           0 :             break;
    2365             :         case SALEVENT_KEYUP:
    2366             :             {
    2367           0 :             SalKeyEvent* pKeyEvt = (SalKeyEvent*)pEvent;
    2368             :             nRet = ImplHandleKey( pWindow, EVENT_KEYUP,
    2369           0 :                 pKeyEvt->mnCode, pKeyEvt->mnCharCode, pKeyEvt->mnRepeat, true );
    2370             :             }
    2371           0 :             break;
    2372             :         case SALEVENT_EXTERNALKEYUP:
    2373             :             {
    2374           0 :             KeyEvent* pKeyEvt = (KeyEvent*) pEvent;
    2375             :             nRet = ImplHandleKey( pWindow, EVENT_KEYUP,
    2376           0 :                 pKeyEvt->GetKeyCode().GetFullCode(), pKeyEvt->GetCharCode(), pKeyEvt->GetRepeat(), false );
    2377             :             }
    2378           0 :             break;
    2379             :         case SALEVENT_KEYMODCHANGE:
    2380           0 :             ImplHandleSalKeyMod( pWindow, (SalKeyModEvent*)pEvent );
    2381           0 :             break;
    2382             : 
    2383             :         case SALEVENT_INPUTLANGUAGECHANGE:
    2384           0 :             ImplHandleInputLanguageChange( pWindow );
    2385           0 :             break;
    2386             : 
    2387             :         case SALEVENT_MENUACTIVATE:
    2388             :         case SALEVENT_MENUDEACTIVATE:
    2389             :         case SALEVENT_MENUHIGHLIGHT:
    2390             :         case SALEVENT_MENUCOMMAND:
    2391             :         case SALEVENT_MENUBUTTONCOMMAND:
    2392           0 :             nRet = ImplHandleMenuEvent( pWindow, (SalMenuEvent*)pEvent, nEvent );
    2393           0 :             break;
    2394             : 
    2395             :         case SALEVENT_WHEELMOUSE:
    2396           0 :             nRet = ImplHandleWheelEvent( pWindow, *(const SalWheelMouseEvent*)pEvent);
    2397           0 :             break;
    2398             : 
    2399             :         case SALEVENT_PAINT:
    2400             :             {
    2401        5172 :             SalPaintEvent* pPaintEvt = (SalPaintEvent*)pEvent;
    2402             : 
    2403        5172 :             if( Application::GetSettings().GetLayoutRTL() )
    2404             :             {
    2405             :                 // --- RTL --- (mirror paint rect)
    2406           0 :                 SalFrame* pSalFrame = pWindow->ImplGetWindowImpl()->mpFrame;
    2407           0 :                 pPaintEvt->mnBoundX = pSalFrame->maGeometry.nWidth-pPaintEvt->mnBoundWidth-pPaintEvt->mnBoundX;
    2408             :             }
    2409             : 
    2410             :             Rectangle aBoundRect( Point( pPaintEvt->mnBoundX, pPaintEvt->mnBoundY ),
    2411        5172 :                                   Size( pPaintEvt->mnBoundWidth, pPaintEvt->mnBoundHeight ) );
    2412        5172 :             ImplHandlePaint( pWindow, aBoundRect, pPaintEvt->mbImmediateUpdate );
    2413             :             }
    2414        5172 :             break;
    2415             : 
    2416             :         case SALEVENT_MOVE:
    2417           0 :             ImplHandleMove( pWindow );
    2418           0 :             break;
    2419             : 
    2420             :         case SALEVENT_RESIZE:
    2421             :             {
    2422             :             long nNewWidth;
    2423             :             long nNewHeight;
    2424        5207 :             pWindow->ImplGetWindowImpl()->mpFrame->GetClientSize( nNewWidth, nNewHeight );
    2425        5207 :             ImplHandleResize( pWindow, nNewWidth, nNewHeight );
    2426             :             }
    2427        5207 :             break;
    2428             : 
    2429             :         case SALEVENT_MOVERESIZE:
    2430             :             {
    2431           0 :             SalFrameGeometry g = pWindow->ImplGetWindowImpl()->mpFrame->GetGeometry();
    2432           0 :             ImplHandleMoveResize( pWindow, g.nWidth, g.nHeight );
    2433             :             }
    2434           0 :             break;
    2435             : 
    2436             :         case SALEVENT_CLOSEPOPUPS:
    2437             :             {
    2438           0 :             KillOwnPopups( pWindow );
    2439             :             }
    2440           0 :             break;
    2441             : 
    2442             :         case SALEVENT_GETFOCUS:
    2443        5058 :             ImplHandleGetFocus( pWindow );
    2444        5058 :             break;
    2445             :         case SALEVENT_LOSEFOCUS:
    2446          59 :             ImplHandleLoseFocus( pWindow );
    2447          59 :             break;
    2448             : 
    2449             :         case SALEVENT_CLOSE:
    2450           0 :             ImplHandleClose( pWindow );
    2451           0 :             break;
    2452             : 
    2453             :         case SALEVENT_SHUTDOWN:
    2454             :             {
    2455             :                 static bool bInQueryExit = false;
    2456           0 :                 if( !bInQueryExit )
    2457             :                 {
    2458           0 :                     bInQueryExit = true;
    2459           0 :                     if ( GetpApp()->QueryExit() )
    2460             :                     {
    2461             :                         // Message-Schleife beenden
    2462           0 :                         Application::Quit();
    2463           0 :                         return false;
    2464             :                     }
    2465             :                     else
    2466             :                     {
    2467           0 :                         bInQueryExit = false;
    2468           0 :                         return true;
    2469             :                     }
    2470             :                 }
    2471           0 :                 return false;
    2472             :             }
    2473             : 
    2474             :         case SALEVENT_SETTINGSCHANGED:
    2475             :         case SALEVENT_VOLUMECHANGED:
    2476             :         case SALEVENT_PRINTERCHANGED:
    2477             :         case SALEVENT_DISPLAYCHANGED:
    2478             :         case SALEVENT_FONTCHANGED:
    2479             :         case SALEVENT_DATETIMECHANGED:
    2480             :         case SALEVENT_KEYBOARDCHANGED:
    2481           0 :             ImplHandleSalSettings( nEvent );
    2482           0 :             break;
    2483             : 
    2484             :         case SALEVENT_USEREVENT:
    2485       80270 :             ImplHandleUserEvent( (ImplSVEvent*)pEvent );
    2486       80270 :             break;
    2487             : 
    2488             :         case SALEVENT_EXTTEXTINPUT:
    2489             :             {
    2490           0 :             SalExtTextInputEvent* pEvt = (SalExtTextInputEvent*)pEvent;
    2491             :             nRet = ImplHandleExtTextInput( pWindow,
    2492             :                                            pEvt->maText, pEvt->mpTextAttr,
    2493           0 :                                            pEvt->mnCursorPos, pEvt->mnCursorFlags );
    2494             :             }
    2495           0 :             break;
    2496             :         case SALEVENT_ENDEXTTEXTINPUT:
    2497           0 :             nRet = ImplHandleEndExtTextInput( pWindow );
    2498           0 :             break;
    2499             :         case SALEVENT_EXTTEXTINPUTPOS:
    2500           0 :             ImplHandleSalExtTextInputPos( pWindow, (SalExtTextInputPosEvent*)pEvent );
    2501           0 :             break;
    2502             :         case SALEVENT_INPUTCONTEXTCHANGE:
    2503           0 :             nRet = ImplHandleInputContextChange( pWindow, ((SalInputContextChangeEvent*)pEvent)->meLanguage );
    2504           0 :             break;
    2505             :         case SALEVENT_SHOWDIALOG:
    2506             :             {
    2507           0 :                 int nDialogID = static_cast<int>(reinterpret_cast<sal_IntPtr>(pEvent));
    2508           0 :                 nRet = ImplHandleShowDialog( pWindow, nDialogID );
    2509             :             }
    2510           0 :             break;
    2511             :         case SALEVENT_SURROUNDINGTEXTREQUEST:
    2512           0 :             ImplHandleSalSurroundingTextRequest( pWindow, (SalSurroundingTextRequestEvent*)pEvent );
    2513           0 :             break;
    2514             :         case SALEVENT_SURROUNDINGTEXTSELECTIONCHANGE:
    2515             :         {
    2516             :             SalSurroundingTextSelectionChangeEvent* pEvt
    2517           0 :              = (SalSurroundingTextSelectionChangeEvent*)pEvent;
    2518             :             ImplHandleSurroundingTextSelectionChange( pWindow,
    2519             :                               pEvt->mnStart,
    2520           0 :                               pEvt->mnEnd );
    2521             :             // Fallthrough really intended?
    2522             :         }
    2523             :         case SALEVENT_STARTRECONVERSION:
    2524           0 :             ImplHandleStartReconversion( pWindow );
    2525           0 :             break;
    2526             :         case SALEVENT_EXTERNALZOOM:
    2527             :             {
    2528           0 :             ZoomEvent* pZoomEvent = (ZoomEvent*) pEvent;
    2529           0 :             SalWheelMouseEvent aSalWheelMouseEvent;
    2530           0 :             aSalWheelMouseEvent.mnTime = tools::Time::GetSystemTicks();
    2531           0 :             aSalWheelMouseEvent.mnX = pZoomEvent->GetCenter().getX();
    2532           0 :             aSalWheelMouseEvent.mnY = pZoomEvent->GetCenter().getY();
    2533             :             // Pass on the scale as a percentage * 100 of current zoom factor
    2534             :             // so to assure zoom granularity
    2535           0 :             aSalWheelMouseEvent.mnDelta = long(double(pZoomEvent->GetScale()) * double(MOBILE_ZOOM_SCALE_MULTIPLIER));
    2536             :             // Other SalWheelMouseEvent fields ignored when the
    2537             :             // scaleDirectly parameter to ImplHandleWheelEvent() is
    2538             :             // true.
    2539           0 :             nRet = ImplHandleWheelEvent( pWindow, aSalWheelMouseEvent, true );
    2540             :             }
    2541           0 :             break;
    2542             :         case SALEVENT_EXTERNALSCROLL:
    2543             :             {
    2544           0 :             ScrollEvent* pScrollEvent = (ScrollEvent*) pEvent;
    2545           0 :             SalWheelMouseEvent aSalWheelMouseEvent;
    2546           0 :             aSalWheelMouseEvent.mnTime = tools::Time::GetSystemTicks();
    2547           0 :             aSalWheelMouseEvent.mbDeltaIsPixel = true;
    2548             :             // event location holds delta values instead
    2549           0 :             aSalWheelMouseEvent.mnX = long(pScrollEvent->GetXOffset());
    2550           0 :             aSalWheelMouseEvent.mnY = long(pScrollEvent->GetYOffset());
    2551           0 :             aSalWheelMouseEvent.mnScrollLines = 0;
    2552           0 :             if (aSalWheelMouseEvent.mnX != 0 || aSalWheelMouseEvent.mnY != 0)
    2553             :             {
    2554           0 :                 nRet = ImplHandleWheelEvent( pWindow, aSalWheelMouseEvent );
    2555             :             }
    2556             :         }
    2557           0 :         break;
    2558             :         case SALEVENT_QUERYCHARPOSITION:
    2559           0 :             ImplHandleSalQueryCharPosition( pWindow, (SalQueryCharPositionEvent*)pEvent );
    2560           0 :             break;
    2561             : #ifdef DBG_UTIL
    2562             :         default:
    2563             :             SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << nEvent << ")" );
    2564             :             break;
    2565             : #endif
    2566             :     }
    2567             : 
    2568       95766 :     return nRet;
    2569        1233 : }
    2570             : 
    2571             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10