LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/view - SlsToolTip.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 63 0.0 %
Date: 2014-04-14 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10