1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <SlideSorter.hxx>
27 #include <sdresid.hxx>
28 #include <strings.hrc>
30 #include <osl/diagnose.h>
31 #include <vcl/settings.hxx>
32 #include <vcl/help.hxx>
34 namespace sd::slidesorter::view
{
36 ToolTip::ToolTip (SlideSorter
& rSlideSorter
)
37 : mrSlideSorter(rSlideSorter
),
38 mnHelpWindowHandle(nullptr),
39 maShowTimer("sd::slidesorter::view::ToolTip maShowTimer"),
40 maHiddenTimer("sd::slidesorter::view::ToolTip maHiddenTimer")
42 maShowTimer
.SetTimeout(HelpSettings::GetTipDelay());
43 maShowTimer
.SetInvokeHandler(LINK(this, ToolTip
, DelayTrigger
));
44 maHiddenTimer
.SetTimeout(HelpSettings::GetTipDelay());
54 void ToolTip::SetPage (const model::SharedPageDescriptor
& rpDescriptor
)
56 if (mpDescriptor
== rpDescriptor
)
60 bool bWasVisible
= Hide();
64 maHiddenTimer
.Start();
67 mpDescriptor
= rpDescriptor
;
71 SdPage
* pPage
= mpDescriptor
->GetPage();
74 sHelpText
= pPage
->GetName();
77 OSL_ASSERT(mpDescriptor
->GetPage() != nullptr);
79 if (sHelpText
.isEmpty())
81 sHelpText
= SdResId(STR_PAGE
) +
82 OUString::number(mpDescriptor
->GetPageIndex()+1);
85 msCurrentHelpText
= sHelpText
;
86 // show new tooltip immediately, if last one was recently hidden
87 if(maHiddenTimer
.IsActive())
94 msCurrentHelpText
.clear();
98 void ToolTip::DoShow()
100 if (maShowTimer
.IsActive())
102 // The delay timer is active. Wait for it to trigger the showing of
107 sd::Window
*pWindow (mrSlideSorter
.GetContentWindow().get());
108 if (msCurrentHelpText
.isEmpty() || !pWindow
)
111 ::tools::Rectangle
aBox (
112 mrSlideSorter
.GetView().GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
114 PageObjectLayouter::Part::Preview
,
115 PageObjectLayouter::WindowCoordinateSystem
));
117 // Do not show the help text when the (lower edge of the ) preview
118 // is not visible. The tool tip itself may still be outside the
120 if (aBox
.Bottom() >= pWindow
->GetSizePixel().Height())
123 vcl::Window
* pParent(pWindow
);
124 while (pParent
->GetParent())
125 pParent
= pParent
->GetParent();
126 const Point
aOffset(pWindow
->GetWindowExtentsRelative(*pParent
).TopLeft());
128 // We do not know how high the tool tip will be but want its top
129 // edge not its bottom to be at a specific position (a little below
130 // the preview). Therefore we use a little trick and place the tool
131 // tip at the top of a rectangle that is placed below the preview.
132 aBox
.Move(aOffset
.X(), aOffset
.Y() + aBox
.GetHeight() + 3);
133 mnHelpWindowHandle
= Help::ShowPopover(
137 QuickHelpFlags::Center
| QuickHelpFlags::Top
);
142 if (mnHelpWindowHandle
)
144 sd::Window
*pWindow (mrSlideSorter
.GetContentWindow().get());
145 Help::HidePopover(pWindow
, mnHelpWindowHandle
);
146 mnHelpWindowHandle
= nullptr;
153 IMPL_LINK_NOARG(ToolTip
, DelayTrigger
, Timer
*, void)
158 } // end of namespace ::sd::slidesorter::view
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */