bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsToolTip.cxx
blob217888cff1234db1812dc78e408df78ed22e91ff
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
28 #include <vcl/settings.hxx>
29 #include <vcl/help.hxx>
31 namespace sd { namespace slidesorter { namespace view {
33 ToolTip::ToolTip (SlideSorter& rSlideSorter)
34 : mrSlideSorter(rSlideSorter),
35 msCurrentHelpText(),
36 mnHelpWindowHandle(0),
37 maShowTimer(),
38 maHiddenTimer()
40 sd::Window *window = rSlideSorter.GetContentWindow();
41 const HelpSettings& rHelpSettings = window->GetSettings().GetHelpSettings();
42 maShowTimer.SetTimeout(rHelpSettings.GetTipDelay());
43 maShowTimer.SetTimeoutHdl(LINK(this, ToolTip, DelayTrigger));
44 maHiddenTimer.SetTimeout(rHelpSettings.GetTipDelay());
47 ToolTip::~ToolTip()
49 maShowTimer.Stop();
50 maHiddenTimer.Stop();
51 Hide();
54 void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
56 if (mpDescriptor != rpDescriptor)
58 maShowTimer.Stop();
59 bool bWasVisible = Hide();
61 if (bWasVisible)
63 maHiddenTimer.Start();
66 mpDescriptor = rpDescriptor;
68 if (mpDescriptor)
70 SdPage* pPage = mpDescriptor->GetPage();
71 OUString sHelpText;
72 if (pPage != NULL)
73 sHelpText = pPage->GetName();
74 else
76 OSL_ASSERT(mpDescriptor->GetPage() != NULL);
78 if (sHelpText.isEmpty())
80 sHelpText = SD_RESSTR(STR_PAGE);
81 sHelpText += OUString::number(mpDescriptor->GetPageIndex()+1);
84 msCurrentHelpText = sHelpText;
85 // show new tooltip immediately, if last one was recently hidden
86 Show(maHiddenTimer.IsActive());
88 else
90 msCurrentHelpText.clear();
95 void ToolTip::Show (const bool bNoDelay)
97 if (bNoDelay)
98 DoShow();
99 else
100 maShowTimer.Start();
103 void ToolTip::DoShow()
105 if (maShowTimer.IsActive())
107 // The delay timer is active. Wait for it to trigger the showing of
108 // the tool tip.
109 return;
112 sd::Window *pWindow (mrSlideSorter.GetContentWindow());
113 if (!msCurrentHelpText.isEmpty() && pWindow)
115 Rectangle aBox (
116 mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
117 mpDescriptor,
118 PageObjectLayouter::Preview,
119 PageObjectLayouter::WindowCoordinateSystem));
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 if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
125 return;
127 vcl::Window* pParent (pWindow);
128 while (pParent!=NULL && pParent->GetParent()!=NULL)
129 pParent = pParent->GetParent();
130 const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
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 aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
137 mnHelpWindowHandle = Help::ShowTip(
138 pWindow,
139 aBox,
140 msCurrentHelpText,
141 QuickHelpFlags::Center | QuickHelpFlags::Top);
145 bool ToolTip::Hide()
147 if (mnHelpWindowHandle>0)
149 Help::HideTip(mnHelpWindowHandle);
150 mnHelpWindowHandle = 0;
151 return true;
153 else
154 return false;
157 IMPL_LINK_NOARG_TYPED(ToolTip, DelayTrigger, Timer *, void)
159 DoShow();
162 } } } // end of namespace ::sd::slidesorter::view
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */