LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/slidesorter/view - SlsToolTip.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 17 64 26.6 %
Date: 2013-07-09 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             : 
      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             : #include <vcl/help.hxx>
      29             : 
      30             : 
      31             : namespace sd { namespace slidesorter { namespace view {
      32             : 
      33          65 : ToolTip::ToolTip (SlideSorter& rSlideSorter)
      34             :     : mrSlideSorter(rSlideSorter),
      35             :       msCurrentHelpText(),
      36             :       mnHelpWindowHandle(0),
      37             :       maShowTimer(),
      38          65 :       maHiddenTimer()
      39             : {
      40          65 :     SharedSdWindow window = rSlideSorter.GetContentWindow();
      41          65 :     const HelpSettings& rHelpSettings = window->GetSettings().GetHelpSettings();
      42          65 :     maShowTimer.SetTimeout(rHelpSettings.GetTipDelay());
      43          65 :     maShowTimer.SetTimeoutHdl(LINK(this, ToolTip, DelayTrigger));
      44          65 :     maHiddenTimer.SetTimeout(rHelpSettings.GetTipDelay());
      45          65 : }
      46             : 
      47             : 
      48             : 
      49             : 
      50         130 : ToolTip::~ToolTip (void)
      51             : {
      52          65 :     maShowTimer.Stop();
      53          65 :     maHiddenTimer.Stop();
      54          65 :     Hide();
      55          65 : }
      56             : 
      57             : 
      58           0 : void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
      59             : {
      60           0 :     if (mpDescriptor != rpDescriptor)
      61             :     {
      62           0 :         maShowTimer.Stop();
      63           0 :         bool bWasVisible = Hide();
      64             : 
      65           0 :         if (bWasVisible)
      66             :         {
      67           0 :             maHiddenTimer.Start();
      68             :         }
      69             : 
      70           0 :         mpDescriptor = rpDescriptor;
      71             : 
      72           0 :         if (mpDescriptor)
      73             :         {
      74           0 :             SdPage* pPage = mpDescriptor->GetPage();
      75           0 :             OUString sHelpText;
      76           0 :             if (pPage != NULL)
      77           0 :                 sHelpText = pPage->GetName();
      78             :             else
      79             :             {
      80             :                 OSL_ASSERT(mpDescriptor->GetPage() != NULL);
      81             :             }
      82           0 :             if (sHelpText.isEmpty())
      83             :             {
      84           0 :                 sHelpText = String(SdResId(STR_PAGE));
      85           0 :                 sHelpText += OUString::number(mpDescriptor->GetPageIndex()+1);
      86             :             }
      87             : 
      88           0 :             msCurrentHelpText = sHelpText;
      89             :             // show new tooltip immediately, if last one was recently hidden
      90           0 :             Show(maHiddenTimer.IsActive());
      91             :         }
      92             :         else
      93             :         {
      94           0 :             msCurrentHelpText = OUString();
      95             :         }
      96             :     }
      97           0 : }
      98             : 
      99             : 
     100             : 
     101           0 : void ToolTip::Show (const bool bNoDelay)
     102             : {
     103           0 :     if (bNoDelay)
     104           0 :         DoShow();
     105             :     else
     106           0 :         maShowTimer.Start();
     107           0 : }
     108             : 
     109             : 
     110             : 
     111             : 
     112           0 : void ToolTip::DoShow (void)
     113             : {
     114           0 :     if (maShowTimer.IsActive())
     115             :     {
     116             :         // The delay timer is active.  Wait for it to trigger the showing of
     117             :         // the tool tip.
     118           0 :         return;
     119             :     }
     120             : 
     121           0 :     SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
     122           0 :     if (!msCurrentHelpText.isEmpty() && pWindow)
     123             :     {
     124             :         Rectangle aBox (
     125           0 :             mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
     126             :                 mpDescriptor,
     127             :                 PageObjectLayouter::Preview,
     128           0 :                 PageObjectLayouter::WindowCoordinateSystem));
     129             : 
     130             :         // Do not show the help text when the (lower edge of the ) preview
     131             :         // is not visible.  The tool tip itself may still be outside the
     132             :         // window.
     133           0 :         if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
     134           0 :             return;
     135             : 
     136           0 :         ::Window* pParent (pWindow.get());
     137           0 :         while (pParent!=NULL && pParent->GetParent()!=NULL)
     138           0 :             pParent = pParent->GetParent();
     139           0 :         const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
     140             : 
     141             :         // We do not know how high the tool tip will be but want its top
     142             :         // edge not its bottom to be at a specific position (a little below
     143             :         // the preview).  Therefore we use a little trick and place the tool
     144             :         // tip at the top of a rectangle that is placed below the preview.
     145           0 :         aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
     146             :         mnHelpWindowHandle = Help::ShowTip(
     147           0 :             pWindow.get(),
     148             :             aBox,
     149             :             msCurrentHelpText,
     150           0 :             QUICKHELP_CENTER | QUICKHELP_TOP);
     151           0 :     }
     152             : }
     153             : 
     154             : 
     155             : 
     156             : 
     157          65 : bool ToolTip::Hide (void)
     158             : {
     159          65 :     if (mnHelpWindowHandle>0)
     160             :     {
     161           0 :         Help::HideTip(mnHelpWindowHandle);
     162           0 :         mnHelpWindowHandle = 0;
     163           0 :         return true;
     164             :     }
     165             :     else
     166          65 :         return false;
     167             : }
     168             : 
     169             : 
     170             : 
     171             : 
     172           0 : IMPL_LINK_NOARG(ToolTip, DelayTrigger)
     173             : {
     174           0 :     DoShow();
     175             : 
     176           0 :     return 0;
     177             : }
     178             : 
     179          33 : } } } // end of namespace ::sd::slidesorter::view
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10