LCOV - code coverage report
Current view: top level - libreoffice/vcl/source/app - help.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 347 7.2 %
Date: 2012-12-17 Functions: 9 44 20.5 %
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 <comphelper/string.hxx>
      21             : 
      22             : #include "tools/debug.hxx"
      23             : #include "tools/diagnose_ex.h"
      24             : #include "tools/time.hxx"
      25             : 
      26             : #include "vcl/window.hxx"
      27             : #include "vcl/event.hxx"
      28             : #include "vcl/svapp.hxx"
      29             : #include "vcl/wrkwin.hxx"
      30             : #include "vcl/help.hxx"
      31             : 
      32             : #include "helpwin.hxx"
      33             : #include "svdata.hxx"
      34             : 
      35             : // =======================================================================
      36             : 
      37             : #define HELPWINSTYLE_QUICK      0
      38             : #define HELPWINSTYLE_BALLOON    1
      39             : 
      40             : #define HELPTEXTMARGIN_QUICK    3
      41             : #define HELPTEXTMARGIN_BALLOON  6
      42             : 
      43             : #define HELPDELAY_NORMAL        1
      44             : #define HELPDELAY_SHORT         2
      45             : #define HELPDELAY_NONE          3
      46             : 
      47             : #define HELPTEXTMAXLEN        150
      48             : 
      49             : // =======================================================================
      50             : 
      51          72 : Help::Help()
      52             : {
      53          72 : }
      54             : 
      55           8 : Help::~Help()
      56             : {
      57           8 : }
      58             : 
      59             : // -----------------------------------------------------------------------
      60             : 
      61           0 : void Help::OpenHelpAgent( const OString& )
      62             : {
      63           0 : }
      64             : 
      65             : // -----------------------------------------------------------------------
      66             : 
      67           0 : sal_Bool Help::Start( const OUString&, const Window* )
      68             : {
      69           0 :     return sal_False;
      70             : }
      71             : 
      72           0 : sal_Bool Help::SearchKeyword( const OUString& )
      73             : {
      74           0 :     return sal_False;
      75             : }
      76             : 
      77             : // -----------------------------------------------------------------------
      78             : 
      79           0 : OUString Help::GetHelpText( const OUString&, const Window* )
      80             : {
      81           0 :     return ImplGetSVEmptyStr();
      82             : }
      83             : 
      84             : // -----------------------------------------------------------------------
      85             : 
      86          72 : void Help::EnableContextHelp()
      87             : {
      88          72 :     ImplGetSVData()->maHelpData.mbContextHelp = sal_True;
      89          72 : }
      90             : 
      91             : // -----------------------------------------------------------------------
      92             : 
      93           0 : void Help::DisableContextHelp()
      94             : {
      95           0 :     ImplGetSVData()->maHelpData.mbContextHelp = sal_False;
      96           0 : }
      97             : 
      98             : // -----------------------------------------------------------------------
      99             : 
     100           0 : sal_Bool Help::IsContextHelpEnabled()
     101             : {
     102           0 :     return ImplGetSVData()->maHelpData.mbContextHelp;
     103             : }
     104             : 
     105             : // -----------------------------------------------------------------------
     106             : 
     107          72 : void Help::EnableExtHelp()
     108             : {
     109          72 :     ImplGetSVData()->maHelpData.mbExtHelp = sal_True;
     110          72 : }
     111             : 
     112             : // -----------------------------------------------------------------------
     113             : 
     114           0 : void Help::DisableExtHelp()
     115             : {
     116           0 :     ImplGetSVData()->maHelpData.mbExtHelp = sal_False;
     117           0 : }
     118             : 
     119             : // -----------------------------------------------------------------------
     120             : 
     121           0 : sal_Bool Help::IsExtHelpEnabled()
     122             : {
     123           0 :     return ImplGetSVData()->maHelpData.mbExtHelp;
     124             : }
     125             : 
     126             : // -----------------------------------------------------------------------
     127             : 
     128           0 : sal_Bool Help::StartExtHelp()
     129             : {
     130           0 :     ImplSVData* pSVData = ImplGetSVData();
     131             : 
     132           0 :     if ( pSVData->maHelpData.mbExtHelp && !pSVData->maHelpData.mbExtHelpMode )
     133             :     {
     134           0 :         pSVData->maHelpData.mbExtHelpMode = sal_True;
     135           0 :         pSVData->maHelpData.mbOldBalloonMode = pSVData->maHelpData.mbBalloonHelp;
     136           0 :         pSVData->maHelpData.mbBalloonHelp = sal_True;
     137           0 :         if ( pSVData->maWinData.mpAppWin )
     138           0 :             pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
     139           0 :         return sal_True;
     140             :     }
     141             : 
     142           0 :     return sal_False;
     143             : }
     144             : 
     145             : // -----------------------------------------------------------------------
     146             : 
     147           0 : sal_Bool Help::EndExtHelp()
     148             : {
     149           0 :     ImplSVData* pSVData = ImplGetSVData();
     150             : 
     151           0 :     if ( pSVData->maHelpData.mbExtHelp && pSVData->maHelpData.mbExtHelpMode )
     152             :     {
     153           0 :         pSVData->maHelpData.mbExtHelpMode = sal_False;
     154           0 :         pSVData->maHelpData.mbBalloonHelp = pSVData->maHelpData.mbOldBalloonMode;
     155           0 :         if ( pSVData->maWinData.mpAppWin )
     156           0 :             pSVData->maWinData.mpAppWin->ImplGenerateMouseMove();
     157           0 :         return sal_True;
     158             :     }
     159             : 
     160           0 :     return sal_False;
     161             : }
     162             : 
     163             : // -----------------------------------------------------------------------
     164             : 
     165           0 : void Help::EnableBalloonHelp()
     166             : {
     167           0 :     ImplGetSVData()->maHelpData.mbBalloonHelp = sal_True;
     168           0 : }
     169             : 
     170             : // -----------------------------------------------------------------------
     171             : 
     172          72 : void Help::DisableBalloonHelp()
     173             : {
     174          72 :     ImplGetSVData()->maHelpData.mbBalloonHelp = sal_False;
     175          72 : }
     176             : 
     177             : // -----------------------------------------------------------------------
     178             : 
     179          72 : sal_Bool Help::IsBalloonHelpEnabled()
     180             : {
     181          72 :     return ImplGetSVData()->maHelpData.mbBalloonHelp;
     182             : }
     183             : 
     184             : // -----------------------------------------------------------------------
     185             : 
     186           0 : sal_Bool Help::ShowBalloon( Window* pParent,
     187             :                         const Point& rScreenPos,
     188             :                         const OUString& rHelpText )
     189             : {
     190             :     ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, 0,
     191           0 :                         rHelpText, ImplGetSVEmptyStr(), rScreenPos );
     192             : 
     193           0 :     return sal_True;
     194             : }
     195             : 
     196             : // -----------------------------------------------------------------------
     197             : 
     198           0 : sal_Bool Help::ShowBalloon( Window* pParent,
     199             :                         const Point& rScreenPos, const Rectangle& rRect,
     200             :                         const OUString& rHelpText )
     201             : {
     202             :     ImplShowHelpWindow( pParent, HELPWINSTYLE_BALLOON, 0,
     203           0 :                         rHelpText, ImplGetSVEmptyStr(), rScreenPos, &rRect );
     204             : 
     205           0 :     return sal_True;
     206             : }
     207             : 
     208             : // -----------------------------------------------------------------------
     209             : 
     210         144 : void Help::EnableQuickHelp()
     211             : {
     212         144 :     ImplGetSVData()->maHelpData.mbQuickHelp = sal_True;
     213         144 : }
     214             : 
     215             : // -----------------------------------------------------------------------
     216             : 
     217           0 : void Help::DisableQuickHelp()
     218             : {
     219           0 :     ImplGetSVData()->maHelpData.mbQuickHelp = sal_False;
     220           0 : }
     221             : 
     222             : // -----------------------------------------------------------------------
     223             : 
     224          72 : sal_Bool Help::IsQuickHelpEnabled()
     225             : {
     226          72 :     return ImplGetSVData()->maHelpData.mbQuickHelp;
     227             : }
     228             : 
     229             : // -----------------------------------------------------------------------
     230             : 
     231           0 : sal_Bool Help::ShowQuickHelp( Window* pParent,
     232             :                           const Rectangle& rScreenRect,
     233             :                           const OUString& rHelpText,
     234             :                           const OUString& rLongHelpText,
     235             :                           sal_uInt16 nStyle )
     236             : {
     237             :     ImplShowHelpWindow( pParent, HELPWINSTYLE_QUICK, nStyle,
     238             :                         rHelpText, rLongHelpText,
     239           0 :                         pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
     240           0 :     return sal_True;
     241             : }
     242             : 
     243             : // -----------------------------------------------------------------------
     244             : 
     245           0 : void Help::HideBalloonAndQuickHelp()
     246             : {
     247           0 :     HelpTextWindow const * pHelpWin = ImplGetSVData()->maHelpData.mpHelpWin;
     248           0 :     bool const bIsVisible = ( pHelpWin != NULL ) && pHelpWin->IsVisible();
     249           0 :     ImplDestroyHelpWindow( bIsVisible );
     250           0 : }
     251             : 
     252             : // -----------------------------------------------------------------------
     253             : 
     254           0 : sal_uIntPtr Help::ShowTip( Window* pParent, const Rectangle& rScreenRect,
     255             :                      const OUString& rText, sal_uInt16 nStyle )
     256             : {
     257           0 :     sal_uInt16 nHelpWinStyle = ( ( nStyle & QUICKHELP_TIP_STYLE_BALLOON ) != 0 ) ? HELPWINSTYLE_BALLOON : HELPWINSTYLE_QUICK;
     258           0 :     HelpTextWindow* pHelpWin = new HelpTextWindow( pParent, rText, nHelpWinStyle, nStyle );
     259             : 
     260           0 :     sal_uIntPtr nId = reinterpret_cast< sal_uIntPtr >( pHelpWin );
     261           0 :     UpdateTip( nId, pParent, rScreenRect, rText );
     262             : 
     263           0 :     pHelpWin->ShowHelp( HELPDELAY_NONE );
     264           0 :     return nId;
     265             : }
     266             : 
     267             : // -----------------------------------------------------------------------
     268             : 
     269           0 : void Help::UpdateTip( sal_uIntPtr nId, Window* pParent, const Rectangle& rScreenRect, const OUString& rText )
     270             : {
     271           0 :     HelpTextWindow* pHelpWin = reinterpret_cast< HelpTextWindow* >( nId );
     272           0 :     ENSURE_OR_RETURN_VOID( pHelpWin != NULL, "Help::UpdateTip: invalid ID!" );
     273             : 
     274           0 :     Size aSz = pHelpWin->CalcOutSize();
     275           0 :     pHelpWin->SetOutputSizePixel( aSz );
     276           0 :     ImplSetHelpWindowPos( pHelpWin, pHelpWin->GetWinStyle(), pHelpWin->GetStyle(),
     277           0 :         pParent->OutputToScreenPixel( pParent->GetPointerPosPixel() ), &rScreenRect );
     278             : 
     279           0 :     pHelpWin->SetHelpText( rText );
     280           0 :     pHelpWin->Invalidate();
     281             : }
     282             : 
     283             : // -----------------------------------------------------------------------
     284             : 
     285           0 : void Help::HideTip( sal_uLong nId )
     286             : {
     287           0 :     HelpTextWindow* pHelpWin = (HelpTextWindow*)nId;
     288           0 :     Window* pFrameWindow = pHelpWin->ImplGetFrameWindow();
     289           0 :     pHelpWin->Hide();
     290             :     // trigger update, so that a Paint is instantly triggered since we do not save the background
     291           0 :     pFrameWindow->ImplUpdateAll();
     292           0 :     delete pHelpWin;
     293           0 :     ImplGetSVData()->maHelpData.mnLastHelpHideTime = Time::GetSystemTicks();
     294           0 : }
     295             : 
     296             : // =======================================================================
     297             : 
     298           0 : HelpTextWindow::HelpTextWindow( Window* pParent, const OUString& rText, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle ) :
     299             :     //FloatingWindow( pParent->ImplGetFrameWindow(), WB_SYSTEMWINDOW ),
     300             :     FloatingWindow( pParent, WB_SYSTEMWINDOW|WB_TOOLTIPWIN ), // #105827# if we change the parent, mirroring will not work correctly when positioning this window
     301           0 :     maHelpText( rText )
     302             : {
     303           0 :     SetType( WINDOW_HELPTEXTWINDOW );
     304           0 :     ImplSetMouseTransparent( sal_True );
     305           0 :     mnHelpWinStyle = nHelpWinStyle;
     306           0 :     mnStyle = nStyle;
     307             : //  on windows this will raise the application window, because help windows are system windows now
     308             : //  EnableAlwaysOnTop();
     309           0 :     EnableSaveBackground();
     310             : 
     311           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     312           0 :     SetPointFont( rStyleSettings.GetHelpFont() );
     313           0 :     SetTextColor( rStyleSettings.GetHelpTextColor() );
     314           0 :     SetTextAlign( ALIGN_TOP );
     315           0 :     if ( IsNativeControlSupported( CTRL_TOOLTIP, PART_ENTIRE_CONTROL ) )
     316             :     {
     317           0 :         EnableChildTransparentMode( sal_True );
     318           0 :         SetParentClipMode( PARENTCLIPMODE_NOCLIP );
     319           0 :         SetPaintTransparent( sal_True );
     320           0 :         SetBackground();
     321             :     }
     322             :     else
     323           0 :         SetBackground( Wallpaper( rStyleSettings.GetHelpColor() ) );
     324           0 :     if( rStyleSettings.GetHelpColor().IsDark() )
     325           0 :         SetLineColor( COL_WHITE );
     326             :     else
     327           0 :         SetLineColor( COL_BLACK );
     328           0 :     SetFillColor();
     329             : 
     330           0 :     if( mnStyle & QUICKHELP_BIDI_RTL )
     331             :     {
     332           0 :         sal_uLong nLayoutMode = GetLayoutMode();
     333           0 :         nLayoutMode |= TEXT_LAYOUT_BIDI_RTL | TEXT_LAYOUT_TEXTORIGIN_LEFT;
     334           0 :         SetLayoutMode( nLayoutMode );
     335             :     }
     336           0 :     SetHelpText( rText );
     337           0 :     Window::SetHelpText( rText );
     338             : 
     339           0 :     ImplSVData* pSVData = ImplGetSVData();
     340           0 :     if ( pSVData->maHelpData.mbSetKeyboardHelp )
     341           0 :         pSVData->maHelpData.mbKeyboardHelp = sal_True;
     342             : 
     343           0 :     const HelpSettings& rHelpSettings = pParent->GetSettings().GetHelpSettings();
     344           0 :     maShowTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
     345           0 :     maHideTimer.SetTimeoutHdl( LINK( this, HelpTextWindow, TimerHdl ) );
     346           0 :     maHideTimer.SetTimeout( rHelpSettings.GetTipTimeout() );
     347           0 : }
     348             : 
     349             : // -----------------------------------------------------------------------
     350             : 
     351           0 : HelpTextWindow::~HelpTextWindow()
     352             : {
     353           0 :     maShowTimer.Stop();
     354           0 :     maHideTimer.Stop();
     355             : 
     356           0 :     if( this == ImplGetSVData()->maHelpData.mpHelpWin )
     357           0 :         ImplGetSVData()->maHelpData.mpHelpWin = NULL;
     358           0 : }
     359             : 
     360             : // -----------------------------------------------------------------------
     361             : 
     362           0 : void HelpTextWindow::SetHelpText( const OUString& rHelpText )
     363             : {
     364           0 :     maHelpText = rHelpText;
     365           0 :     if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.getLength() < HELPTEXTMAXLEN)
     366             :     {
     367           0 :         Size aSize;
     368           0 :         aSize.Height() = GetTextHeight();
     369           0 :         if ( mnStyle & QUICKHELP_CTRLTEXT )
     370           0 :             aSize.Width() = GetCtrlTextWidth( maHelpText );
     371             :         else
     372           0 :             aSize.Width() = GetTextWidth( maHelpText );
     373           0 :         maTextRect = Rectangle( Point( HELPTEXTMARGIN_QUICK, HELPTEXTMARGIN_QUICK ), aSize );
     374             :     }
     375             :     else // HELPWINSTYLE_BALLOON
     376             :     {
     377           0 :         Point       aTmpPoint;
     378           0 :         sal_Int32 nCharsInLine = 35 + ((maHelpText.getLength()/100)*5);
     379             :         // average width to have all windows consistent
     380           0 :         OUStringBuffer aBuf;
     381           0 :         comphelper::string::padToLength(aBuf, nCharsInLine, 'x');
     382           0 :         OUString aXXX = aBuf.makeStringAndClear();
     383           0 :         long nWidth = GetTextWidth( aXXX );
     384           0 :         Size aTmpSize( nWidth, 0x7FFFFFFF );
     385           0 :         Rectangle aTry1( aTmpPoint, aTmpSize );
     386             :         sal_uInt16 nDrawFlags = TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK |
     387           0 :                             TEXT_DRAW_LEFT | TEXT_DRAW_TOP;
     388           0 :         if ( mnStyle & QUICKHELP_CTRLTEXT )
     389           0 :             nDrawFlags |= TEXT_DRAW_MNEMONIC;
     390           0 :         Rectangle aTextRect = GetTextRect( aTry1, maHelpText, nDrawFlags );
     391             : 
     392             :         // get a better width later...
     393           0 :         maTextRect = aTextRect;
     394             : 
     395             :         // safety distance...
     396           0 :         maTextRect.SetPos( Point( HELPTEXTMARGIN_BALLOON, HELPTEXTMARGIN_BALLOON ) );
     397             :     }
     398             : 
     399           0 :     Size aSize( CalcOutSize() );
     400           0 :     SetOutputSizePixel( aSize );
     401           0 : }
     402             : 
     403             : // -----------------------------------------------------------------------
     404             : 
     405           0 : void HelpTextWindow::ImplShow()
     406             : {
     407           0 :     ImplDelData aDogTag( this );
     408           0 :     Show( sal_True, SHOW_NOACTIVATE );
     409           0 :     if( !aDogTag.IsDead() )
     410           0 :     Update();
     411           0 : }
     412             : 
     413             : // -----------------------------------------------------------------------
     414             : 
     415           0 : void HelpTextWindow::Paint( const Rectangle& )
     416             : {
     417             :     // paint native background
     418           0 :     bool bNativeOK = false;
     419           0 :     if ( IsNativeControlSupported( CTRL_TOOLTIP, PART_ENTIRE_CONTROL ) )
     420             :     {
     421             :         // #i46472# workaround gcc3.3 temporary problem
     422           0 :         Rectangle aCtrlRegion( Point( 0, 0 ), GetOutputSizePixel() );
     423           0 :         ImplControlValue    aControlValue;
     424             :         bNativeOK = DrawNativeControl( CTRL_TOOLTIP, PART_ENTIRE_CONTROL, aCtrlRegion,
     425           0 :                                        0, aControlValue, OUString() );
     426             :     }
     427             : 
     428             :     // paint text
     429           0 :     if ( mnHelpWinStyle == HELPWINSTYLE_QUICK && maHelpText.getLength() < HELPTEXTMAXLEN)
     430             :     {
     431           0 :         if ( mnStyle & QUICKHELP_CTRLTEXT )
     432           0 :             DrawCtrlText( maTextRect.TopLeft(), maHelpText );
     433             :         else
     434           0 :             DrawText( maTextRect.TopLeft(), maHelpText );
     435             :     }
     436             :     else // HELPWINSTYLE_BALLOON
     437             :     {
     438             :         sal_uInt16 nDrawFlags = TEXT_DRAW_MULTILINE|TEXT_DRAW_WORDBREAK|
     439           0 :                                 TEXT_DRAW_LEFT|TEXT_DRAW_TOP;
     440           0 :         if ( mnStyle & QUICKHELP_CTRLTEXT )
     441           0 :             nDrawFlags |= TEXT_DRAW_MNEMONIC;
     442           0 :         DrawText( maTextRect, maHelpText, nDrawFlags );
     443             :     }
     444             : 
     445             :     // border
     446           0 :     if( ! bNativeOK )
     447             :     {
     448           0 :         Size aSz = GetOutputSizePixel();
     449           0 :         DrawRect( Rectangle( Point(), aSz ) );
     450           0 :         if ( mnHelpWinStyle == HELPWINSTYLE_BALLOON )
     451             :         {
     452           0 :             aSz.Width() -= 2;
     453           0 :             aSz.Height() -= 2;
     454           0 :             Color aColor( GetLineColor() );
     455           0 :             SetLineColor( ( COL_GRAY ) );
     456           0 :             DrawRect( Rectangle( Point( 1, 1 ), aSz ) );
     457           0 :             SetLineColor( aColor );
     458             :         }
     459             :     }
     460           0 : }
     461             : 
     462             : // -----------------------------------------------------------------------
     463             : 
     464           0 : void HelpTextWindow::ShowHelp( sal_uInt16 nDelayMode )
     465             : {
     466           0 :     sal_uLong nTimeout = 0;
     467           0 :     if ( nDelayMode != HELPDELAY_NONE )
     468             :     {
     469             :         // In case of ExtendedHelp display help sooner
     470           0 :         if ( ImplGetSVData()->maHelpData.mbExtHelpMode )
     471           0 :             nTimeout = 15;
     472             :         else
     473             :         {
     474           0 :             const HelpSettings& rHelpSettings = GetSettings().GetHelpSettings();
     475           0 :             if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
     476           0 :                 nTimeout = rHelpSettings.GetTipDelay();
     477             :             else
     478           0 :                 nTimeout = rHelpSettings.GetBalloonDelay();
     479             :         }
     480             : 
     481           0 :         if ( nDelayMode == HELPDELAY_SHORT )
     482           0 :             nTimeout /= 3;
     483             :     }
     484             : 
     485           0 :     maShowTimer.SetTimeout( nTimeout );
     486           0 :     maShowTimer.Start();
     487           0 : }
     488             : 
     489             : // -----------------------------------------------------------------------
     490             : 
     491           0 : IMPL_LINK( HelpTextWindow, TimerHdl, Timer*, pTimer)
     492             : {
     493           0 :     if ( pTimer == &maShowTimer )
     494             :     {
     495           0 :         if ( mnHelpWinStyle == HELPWINSTYLE_QUICK )
     496             :         {
     497             :             // start auto-hide-timer for non-ShowTip windows
     498           0 :             ImplSVData* pSVData = ImplGetSVData();
     499           0 :             if ( this == pSVData->maHelpData.mpHelpWin )
     500           0 :                 maHideTimer.Start();
     501             :         }
     502           0 :         ImplShow();
     503             :     }
     504             :     else
     505             :     {
     506             :         DBG_ASSERT( pTimer == &maHideTimer, "HelpTextWindow::TimerHdl with bad Timer" );
     507           0 :           ImplDestroyHelpWindow( true );
     508             :     }
     509             : 
     510           0 :     return 1;
     511             : }
     512             : 
     513             : // -----------------------------------------------------------------------
     514             : 
     515           0 : Size HelpTextWindow::CalcOutSize() const
     516             : {
     517           0 :     Size aSz = maTextRect.GetSize();
     518           0 :     aSz.Width() += 2*maTextRect.Left();
     519           0 :     aSz.Height() += 2*maTextRect.Top();
     520           0 :     return aSz;
     521             : }
     522             : 
     523             : // -----------------------------------------------------------------------
     524             : 
     525           0 : void HelpTextWindow::RequestHelp( const HelpEvent& /*rHEvt*/ )
     526             : {
     527             :     // Just to assure that Window::RequestHelp() is not called by
     528             :     // ShowQuickHelp/ShowBalloonHelp in the HelpTextWindow.
     529           0 : }
     530             : 
     531             : // -----------------------------------------------------------------------
     532             : 
     533           0 : XubString HelpTextWindow::GetText() const
     534             : {
     535           0 :     return maHelpText;
     536             : }
     537             : 
     538             : // -----------------------------------------------------------------------
     539             : 
     540           0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > HelpTextWindow::CreateAccessible()
     541             : {
     542           0 :     return FloatingWindow::CreateAccessible();
     543             : }
     544             : 
     545             : 
     546             : // =======================================================================
     547             : 
     548           0 : void ImplShowHelpWindow( Window* pParent, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle,
     549             :                          const OUString& rHelpText, const OUString& rStatusText,
     550             :                          const Point& rScreenPos, const Rectangle* pHelpArea )
     551             : {
     552           0 :     ImplSVData* pSVData = ImplGetSVData();
     553             : 
     554           0 :     if (rHelpText.isEmpty() && !pSVData->maHelpData.mbRequestingHelp)
     555           0 :         return;
     556             : 
     557           0 :     HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
     558           0 :     sal_uInt16 nDelayMode = HELPDELAY_NORMAL;
     559           0 :     if ( pHelpWin )
     560             :     {
     561             :         DBG_ASSERT( pHelpWin != pParent, "HelpInHelp ?!" );
     562             : 
     563           0 :         if  (   (   ( pHelpWin->GetHelpText() != rHelpText )
     564           0 :                 ||  ( pHelpWin->GetWinStyle() != nHelpWinStyle )
     565             :                 ||  (   pHelpArea
     566           0 :                     &&  ( pHelpWin->GetHelpArea() != *pHelpArea )
     567             :                     )
     568             :                 )
     569             :             &&  pSVData->maHelpData.mbRequestingHelp
     570             :             )
     571             :         {
     572             :             // remove help window if no HelpText or other HelpText or
     573             :             // other help mode. but keep it if we are scrolling, ie not requesting help
     574           0 :             bool bWasVisible = pHelpWin->IsVisible();
     575           0 :             if ( bWasVisible )
     576           0 :                 nDelayMode = HELPDELAY_NONE; // display it quickly if we were already in quick help mode
     577           0 :             pHelpWin = NULL;
     578           0 :             ImplDestroyHelpWindow( bWasVisible );
     579             :         }
     580             :         else
     581             :         {
     582           0 :             bool const bTextChanged = rHelpText != pHelpWin->GetHelpText();
     583           0 :             if ( bTextChanged || ( ( nStyle & QUICKHELP_FORCE_REPOSITION ) != 0 ) )
     584             :             {
     585           0 :                 Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
     586           0 :                 Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
     587           0 :                 if( pHelpWin->IsVisible() )
     588           0 :                     pWindow->Invalidate( aInvRect );
     589             : 
     590           0 :                 pHelpWin->SetHelpText( rHelpText );
     591             :                 // approach mouse position
     592           0 :                 ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
     593           0 :                 if( pHelpWin->IsVisible() )
     594           0 :                     pHelpWin->Invalidate();
     595             :             }
     596             :         }
     597             :     }
     598             : 
     599           0 :     if (!pHelpWin && !rHelpText.isEmpty())
     600             :     {
     601           0 :         sal_uLong nCurTime = Time::GetSystemTicks();
     602           0 :         if  (   ( ( nCurTime - pSVData->maHelpData.mnLastHelpHideTime ) < pParent->GetSettings().GetHelpSettings().GetTipDelay() )
     603             :             ||  ( ( nStyle & QUICKHELP_NO_DELAY ) != 0 )
     604             :             )
     605           0 :             nDelayMode = HELPDELAY_NONE;
     606             : 
     607             :         DBG_ASSERT( !pHelpWin, "Noch ein HelpWin ?!" );
     608           0 :         pHelpWin = new HelpTextWindow( pParent, rHelpText, nHelpWinStyle, nStyle );
     609           0 :         pSVData->maHelpData.mpHelpWin = pHelpWin;
     610           0 :         pHelpWin->SetStatusText( rStatusText );
     611           0 :         if ( pHelpArea )
     612           0 :             pHelpWin->SetHelpArea( *pHelpArea );
     613             : 
     614             :         //  positioning
     615           0 :         Size aSz = pHelpWin->CalcOutSize();
     616           0 :         pHelpWin->SetOutputSizePixel( aSz );
     617           0 :         ImplSetHelpWindowPos( pHelpWin, nHelpWinStyle, nStyle, rScreenPos, pHelpArea );
     618             :         // if not called from Window::RequestHelp, then without delay...
     619           0 :         if ( !pSVData->maHelpData.mbRequestingHelp )
     620           0 :             nDelayMode = HELPDELAY_NONE;
     621           0 :         pHelpWin->ShowHelp( nDelayMode );
     622             :     }
     623             : }
     624             : 
     625             : // -----------------------------------------------------------------------
     626             : 
     627         932 : void ImplDestroyHelpWindow( bool bUpdateHideTime )
     628             : {
     629         932 :     ImplSVData* pSVData = ImplGetSVData();
     630         932 :     HelpTextWindow* pHelpWin = pSVData->maHelpData.mpHelpWin;
     631         932 :     if ( pHelpWin )
     632             :     {
     633           0 :         Window * pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
     634             :         // find out screen area covered by system help window
     635           0 :         Rectangle aInvRect( pHelpWin->GetWindowExtentsRelative( pWindow ) );
     636           0 :         if( pHelpWin->IsVisible() )
     637           0 :             pWindow->Invalidate( aInvRect );
     638           0 :         pSVData->maHelpData.mpHelpWin = NULL;
     639           0 :         pSVData->maHelpData.mbKeyboardHelp = sal_False;
     640           0 :         pHelpWin->Hide();
     641           0 :         delete pHelpWin;
     642           0 :         if( bUpdateHideTime )
     643           0 :             pSVData->maHelpData.mnLastHelpHideTime = Time::GetSystemTicks();
     644             :     }
     645         932 : }
     646             : 
     647             : // -----------------------------------------------------------------------
     648             : 
     649           0 : void ImplSetHelpWindowPos( Window* pHelpWin, sal_uInt16 nHelpWinStyle, sal_uInt16 nStyle,
     650             :                            const Point& rPos, const Rectangle* pHelpArea )
     651             : {
     652           0 :     Point       aPos = rPos;
     653           0 :     Size        aSz = pHelpWin->GetSizePixel();
     654           0 :     Rectangle   aScreenRect = pHelpWin->ImplGetFrameWindow()->GetDesktopRectPixel();
     655           0 :     aPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( aPos );
     656             :     // get mouse screen coords
     657           0 :     Point mPos( pHelpWin->GetParent()->ImplGetFrameWindow()->GetPointerPosPixel() );
     658           0 :     mPos = pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( mPos );
     659             : 
     660           0 :     if ( nHelpWinStyle == HELPWINSTYLE_QUICK )
     661             :     {
     662           0 :         if ( !(nStyle & QUICKHELP_NOAUTOPOS) )
     663             :         {
     664           0 :             long nScreenHeight = aScreenRect.GetHeight();
     665           0 :             aPos.X() -= 4;
     666           0 :             if ( aPos.Y() > aScreenRect.Top()+nScreenHeight-(nScreenHeight/4) )
     667           0 :                 aPos.Y() -= aSz.Height()+4;
     668             :             else
     669           0 :                 aPos.Y() += 21;
     670             :         }
     671             :     }
     672             :     else
     673             :     {
     674             :         // If it's the mouse position, move the window slightly
     675             :         // so the mouse pointer does not cover it
     676           0 :         if ( aPos == mPos )
     677             :         {
     678           0 :             aPos.X() += 12;
     679           0 :             aPos.Y() += 16;
     680             :         }
     681             :     }
     682             : 
     683           0 :     if ( nStyle & QUICKHELP_NOAUTOPOS )
     684             :     {
     685           0 :         if ( pHelpArea )
     686             :         {
     687             :             // convert help area to screen coords
     688             :             Rectangle devHelpArea(
     689           0 :                 pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->TopLeft() ),
     690           0 :                 pHelpWin->GetParent()->ImplGetFrameWindow()->OutputToAbsoluteScreenPixel( pHelpArea->BottomRight() ) );
     691             : 
     692             :             // Welche Position vom Rechteck?
     693           0 :             aPos = devHelpArea.Center();
     694             : 
     695           0 :             if ( nStyle & QUICKHELP_LEFT )
     696           0 :                 aPos.X() = devHelpArea.Left();
     697           0 :             else if ( nStyle & QUICKHELP_RIGHT )
     698           0 :                 aPos.X() = devHelpArea.Right();
     699             : 
     700           0 :             if ( nStyle & QUICKHELP_TOP )
     701           0 :                 aPos.Y() = devHelpArea.Top();
     702           0 :             else if ( nStyle & QUICKHELP_BOTTOM )
     703           0 :                 aPos.Y() = devHelpArea.Bottom();
     704             :         }
     705             : 
     706             :         // Welche Richtung?
     707           0 :         if ( nStyle & QUICKHELP_LEFT )
     708             :             ;
     709           0 :         else if ( nStyle & QUICKHELP_RIGHT )
     710           0 :             aPos.X() -= aSz.Width();
     711             :         else
     712           0 :             aPos.X() -= aSz.Width()/2;
     713             : 
     714           0 :         if ( nStyle & QUICKHELP_TOP )
     715             :             ;
     716           0 :         else if ( nStyle & QUICKHELP_BOTTOM )
     717           0 :             aPos.Y() -= aSz.Height();
     718             :         else
     719           0 :             aPos.Y() -= aSz.Height()/2;
     720             :     }
     721             : 
     722           0 :     if ( aPos.X() < aScreenRect.Left() )
     723           0 :         aPos.X() = aScreenRect.Left();
     724           0 :     else if ( ( aPos.X() + aSz.Width() ) > aScreenRect.Right() )
     725           0 :         aPos.X() = aScreenRect.Right() - aSz.Width();
     726           0 :     if ( aPos.Y() < aScreenRect.Top() )
     727           0 :         aPos.Y() = aScreenRect.Top();
     728           0 :     else if ( ( aPos.Y() + aSz.Height() ) > aScreenRect.Bottom() )
     729           0 :         aPos.Y() = aScreenRect.Bottom() - aSz.Height();
     730             : 
     731           0 :     if( ! (nStyle & QUICKHELP_NOEVADEPOINTER) )
     732             :     {
     733             :         /* the remark below should be obsolete by now as the helpwindow should
     734             :         not be focusable, leaving it as a hint. However it is sensible in most
     735             :         conditions to evade the mouse pointer so the content window is fully visible.
     736             : 
     737             :         // the popup must not appear under the mouse
     738             :         // otherwise it would directly be closed due to a focus change...
     739             :         */
     740           0 :         Rectangle aHelpRect( aPos, aSz );
     741           0 :         if( aHelpRect.IsInside( mPos ) )
     742             :         {
     743           0 :             Point delta(2,2);
     744           0 :             Point pSize( aSz.Width(), aSz.Height() );
     745           0 :             Point pTest( mPos - pSize - delta );
     746           0 :             if( pTest.X() > aScreenRect.Left() &&  pTest.Y() > aScreenRect.Top() )
     747           0 :                 aPos = pTest;
     748             :             else
     749           0 :                 aPos = mPos + delta;
     750             :         }
     751             :     }
     752             : 
     753           0 :     Window* pWindow = pHelpWin->GetParent()->ImplGetFrameWindow();
     754           0 :     aPos = pWindow->AbsoluteScreenToOutputPixel( aPos );
     755           0 :     pHelpWin->SetPosPixel( aPos );
     756           0 : }
     757             : 
     758             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10