bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / slidesorter / view / SlsToolTip.cxx
blob025c2624587a13fec521f228f24ed3bf03d3021c
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/SlsPageObjectLayouter.hxx>
21 #include <view/SlsToolTip.hxx>
22 #include <view/SlideSorterView.hxx>
23 #include <view/SlsLayouter.hxx>
24 #include <view/SlsTheme.hxx>
25 #include <SlideSorter.hxx>
26 #include <Window.hxx>
27 #include <sdpage.hxx>
28 #include <sdresid.hxx>
29 #include <strings.hrc>
31 #include <vcl/settings.hxx>
32 #include <vcl/help.hxx>
34 namespace sd { namespace slidesorter { namespace view {
36 ToolTip::ToolTip (SlideSorter& rSlideSorter)
37 : mrSlideSorter(rSlideSorter),
38 msCurrentHelpText(),
39 mnHelpWindowHandle(nullptr),
40 maShowTimer(),
41 maHiddenTimer()
43 maShowTimer.SetTimeout(HelpSettings::GetTipDelay());
44 maShowTimer.SetInvokeHandler(LINK(this, ToolTip, DelayTrigger));
45 maHiddenTimer.SetTimeout(HelpSettings::GetTipDelay());
48 ToolTip::~ToolTip()
50 maShowTimer.Stop();
51 maHiddenTimer.Stop();
52 Hide();
55 void ToolTip::SetPage (const model::SharedPageDescriptor& rpDescriptor)
57 if (mpDescriptor == rpDescriptor)
58 return;
60 maShowTimer.Stop();
61 bool bWasVisible = Hide();
63 if (bWasVisible)
65 maHiddenTimer.Start();
68 mpDescriptor = rpDescriptor;
70 if (mpDescriptor)
72 SdPage* pPage = mpDescriptor->GetPage();
73 OUString sHelpText;
74 if (pPage != nullptr)
75 sHelpText = pPage->GetName();
76 else
78 OSL_ASSERT(mpDescriptor->GetPage() != nullptr);
80 if (sHelpText.isEmpty())
82 sHelpText = SdResId(STR_PAGE);
83 sHelpText += OUString::number(mpDescriptor->GetPageIndex()+1);
86 msCurrentHelpText = sHelpText;
87 // show new tooltip immediately, if last one was recently hidden
88 if(maHiddenTimer.IsActive())
89 DoShow();
90 else
91 maShowTimer.Start();
93 else
95 msCurrentHelpText.clear();
99 void ToolTip::DoShow()
101 if (maShowTimer.IsActive())
103 // The delay timer is active. Wait for it to trigger the showing of
104 // the tool tip.
105 return;
108 sd::Window *pWindow (mrSlideSorter.GetContentWindow().get());
109 if (msCurrentHelpText.isEmpty() || !pWindow)
110 return;
112 ::tools::Rectangle aBox (
113 mrSlideSorter.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
114 mpDescriptor,
115 PageObjectLayouter::Part::Preview,
116 PageObjectLayouter::WindowCoordinateSystem));
118 // Do not show the help text when the (lower edge of the ) preview
119 // is not visible. The tool tip itself may still be outside the
120 // window.
121 if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
122 return;
124 vcl::Window* pParent (pWindow);
125 while (pParent!=nullptr && pParent->GetParent()!=nullptr)
126 pParent = pParent->GetParent();
127 const Point aOffset (pWindow->GetWindowExtentsRelative(pParent).TopLeft());
129 // We do not know how high the tool tip will be but want its top
130 // edge not its bottom to be at a specific position (a little below
131 // the preview). Therefore we use a little trick and place the tool
132 // tip at the top of a rectangle that is placed below the preview.
133 aBox.Move(aOffset.X(), aOffset.Y() + aBox.GetHeight() + 3);
134 mnHelpWindowHandle = Help::ShowPopover(
135 pWindow,
136 aBox,
137 msCurrentHelpText,
138 QuickHelpFlags::Center | QuickHelpFlags::Top);
141 bool ToolTip::Hide()
143 if (mnHelpWindowHandle)
145 sd::Window *pWindow (mrSlideSorter.GetContentWindow().get());
146 Help::HidePopover(pWindow, mnHelpWindowHandle);
147 mnHelpWindowHandle = nullptr;
148 return true;
150 else
151 return false;
154 IMPL_LINK_NOARG(ToolTip, DelayTrigger, Timer *, void)
156 DoShow();
159 } } } // end of namespace ::sd::slidesorter::view
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */