LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsToolTip.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 17 62 27.4 %
Date: 2015-06-13 12:38:46 Functions: 5 10 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "view/SlsToolTip.hxx"
      21             : #include "view/SlideSorterView.hxx"
      22             : #include "view/SlsLayouter.hxx"
      23             : #include "view/SlsTheme.hxx"
      24             : #include "sdpage.hxx"
      25             : #include "sdresid.hxx"
      26             : #include "glob.hrc"
      27             : 
      28             : #include <vcl/settings.hxx>
      29             : #include <vcl/help.hxx>
      30             : 
      31             : namespace sd { namespace slidesorter { namespace view {
      32             : 
      33          64 : ToolTip::ToolTip (SlideSorter& rSlideSorter)
      34             :     : mrSlideSorter(rSlideSorter),
      35             :       msCurrentHelpText(),
      36             :       mnHelpWindowHandle(0),
      37             :       maShowTimer(),
      38          64 :       maHiddenTimer()
      39             : {
      40          64 :     sd::Window *window = rSlideSorter.GetContentWindow();
      41          64 :     const HelpSettings& rHelpSettings = window->GetSettings().GetHelpSettings();
      42          64 :     maShowTimer.SetTimeout(rHelpSettings.GetTipDelay());
      43          64 :     maShowTimer.SetTimeoutHdl(LINK(this, ToolTip, DelayTrigger));
      44          64 :     maHiddenTimer.SetTimeout(rHelpSettings.GetTipDelay());
      45          64 : }
      46             : 
      47         128 : ToolTip::~ToolTip()
      48             : {
      49          64 :     maShowTimer.Stop();
      50          64 :     maHiddenTimer.Stop();
      51          64 :     Hide();
      52          64 : }
      53             : 
      54           0 : void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
      55             : {
      56           0 :     if (mpDescriptor != rpDescriptor)
      57             :     {
      58           0 :         maShowTimer.Stop();
      59           0 :         bool bWasVisible = Hide();
      60             : 
      61           0 :         if (bWasVisible)
      62             :         {
      63           0 :             maHiddenTimer.Start();
      64             :         }
      65             : 
      66           0 :         mpDescriptor = rpDescriptor;
      67             : 
      68           0 :         if (mpDescriptor)
      69             :         {
      70           0 :             SdPage* pPage = mpDescriptor->GetPage();
      71           0 :             OUString sHelpText;
      72           0 :             if (pPage != NULL)
      73           0 :                 sHelpText = pPage->GetName();
      74             :             else
      75             :             {
      76             :                 OSL_ASSERT(mpDescriptor->GetPage() != NULL);
      77             :             }
      78           0 :             if (sHelpText.isEmpty())
      79             :             {
      80           0 :                 sHelpText = SD_RESSTR(STR_PAGE);
      81           0 :                 sHelpText += OUString::number(mpDescriptor->GetPageIndex()+1);
      82             :             }
      83             : 
      84           0 :             msCurrentHelpText = sHelpText;
      85             :             // show new tooltip immediately, if last one was recently hidden
      86           0 :             Show(maHiddenTimer.IsActive());
      87             :         }
      88             :         else
      89             :         {
      90           0 :             msCurrentHelpText.clear();
      91             :         }
      92             :     }
      93           0 : }
      94             : 
      95           0 : void ToolTip::Show (const bool bNoDelay)
      96             : {
      97           0 :     if (bNoDelay)
      98           0 :         DoShow();
      99             :     else
     100           0 :         maShowTimer.Start();
     101           0 : }
     102             : 
     103           0 : void ToolTip::DoShow()
     104             : {
     105           0 :     if (maShowTimer.IsActive())
     106             :     {
     107             :         // The delay timer is active.  Wait for it to trigger the showing of
     108             :         // the tool tip.
     109           0 :         return;
     110             :     }
     111             : 
     112           0 :     sd::Window *pWindow (mrSlideSorter.GetContentWindow());
     113           0 :     if (!msCurrentHelpText.isEmpty() && pWindow)
     114             :     {
     115             :         Rectangle aBox (
     116           0 :             mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
     117             :                 mpDescriptor,
     118             :                 PageObjectLayouter::Preview,
     119           0 :                 PageObjectLayouter::WindowCoordinateSystem));
     120             : 
     121             :         // Do not show the help text when the (lower edge of the ) preview
     122             :         // is not visible.  The tool tip itself may still be outside the
     123             :         // window.
     124           0 :         if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
     125           0 :             return;
     126             : 
     127           0 :         vcl::Window* pParent (pWindow);
     128           0 :         while (pParent!=NULL && pParent->GetParent()!=NULL)
     129           0 :             pParent = pParent->GetParent();
     130           0 :         const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
     131             : 
     132             :         // We do not know how high the tool tip will be but want its top
     133             :         // edge not its bottom to be at a specific position (a little below
     134             :         // the preview).  Therefore we use a little trick and place the tool
     135             :         // tip at the top of a rectangle that is placed below the preview.
     136           0 :         aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
     137             :         mnHelpWindowHandle = Help::ShowTip(
     138             :             pWindow,
     139             :             aBox,
     140             :             msCurrentHelpText,
     141           0 :             QuickHelpFlags::Center | QuickHelpFlags::Top);
     142             :     }
     143             : }
     144             : 
     145          64 : bool ToolTip::Hide()
     146             : {
     147          64 :     if (mnHelpWindowHandle>0)
     148             :     {
     149           0 :         Help::HideTip(mnHelpWindowHandle);
     150           0 :         mnHelpWindowHandle = 0;
     151           0 :         return true;
     152             :     }
     153             :     else
     154          64 :         return false;
     155             : }
     156             : 
     157           0 : IMPL_LINK_NOARG_TYPED(ToolTip, DelayTrigger, Timer *, void)
     158             : {
     159           0 :     DoShow();
     160           0 : }
     161             : 
     162          66 : } } } // end of namespace ::sd::slidesorter::view
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11