LibreOffice Module sd (master) 1
SlsToolTip.cxx
Go to the documentation of this file.
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
21#include <view/SlsToolTip.hxx>
23#include <view/SlsLayouter.hxx>
24#include <SlideSorter.hxx>
25#include <Window.hxx>
26#include <sdpage.hxx>
27#include <sdresid.hxx>
28#include <strings.hrc>
29
30#include <osl/diagnose.h>
31#include <vcl/settings.hxx>
32#include <vcl/help.hxx>
33
34namespace sd::slidesorter::view {
35
37 : mrSlideSorter(rSlideSorter),
38 mnHelpWindowHandle(nullptr),
39 maShowTimer("sd::slidesorter::view::ToolTip maShowTimer"),
40 maHiddenTimer("sd::slidesorter::view::ToolTip maHiddenTimer")
41{
43 maShowTimer.SetInvokeHandler(LINK(this, ToolTip, DelayTrigger));
45}
46
48{
51 Hide();
52}
53
55{
56 if (mpDescriptor == rpDescriptor)
57 return;
58
60 bool bWasVisible = Hide();
61
62 if (bWasVisible)
63 {
65 }
66
67 mpDescriptor = rpDescriptor;
68
69 if (mpDescriptor)
70 {
71 SdPage* pPage = mpDescriptor->GetPage();
72 OUString sHelpText;
73 if (pPage != nullptr)
74 sHelpText = pPage->GetName();
75 else
76 {
77 OSL_ASSERT(mpDescriptor->GetPage() != nullptr);
78 }
79 if (sHelpText.isEmpty())
80 {
81 sHelpText = SdResId(STR_PAGE) +
82 OUString::number(mpDescriptor->GetPageIndex()+1);
83 }
84
85 msCurrentHelpText = sHelpText;
86 // show new tooltip immediately, if last one was recently hidden
88 DoShow();
89 else
91 }
92 else
93 {
94 msCurrentHelpText.clear();
95 }
96}
97
99{
100 if (maShowTimer.IsActive())
101 {
102 // The delay timer is active. Wait for it to trigger the showing of
103 // the tool tip.
104 return;
105 }
106
108 if (msCurrentHelpText.isEmpty() || !pWindow)
109 return;
110
111 ::tools::Rectangle aBox (
116
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
119 // window.
120 if (aBox.Bottom() >= pWindow->GetSizePixel().Height())
121 return;
122
123 vcl::Window* pParent (pWindow);
124 while (pParent!=nullptr && pParent->GetParent()!=nullptr)
125 pParent = pParent->GetParent();
126 const Point aOffset (pWindow->GetWindowExtentsRelative(*pParent).TopLeft());
127
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);
134 pWindow,
135 aBox,
137 QuickHelpFlags::Center | QuickHelpFlags::Top);
138}
139
141{
143 {
146 mnHelpWindowHandle = nullptr;
147 return true;
148 }
149 else
150 return false;
151}
152
153IMPL_LINK_NOARG(ToolTip, DelayTrigger, Timer *, void)
154{
155 DoShow();
156}
157
158} // end of namespace ::sd::slidesorter::view
159
160/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorter & mrSlideSorter
static sal_Int32 GetTipDelay()
static void * ShowPopover(vcl::Window *pParent, const tools::Rectangle &rScreenRect, const OUString &rText, QuickHelpFlags nStyle)
static void HidePopover(vcl::Window const *pParent, void *nId)
constexpr tools::Long Y() const
constexpr tools::Long X() const
const OUString & GetName() const
Definition: sdpage.cxx:2505
constexpr tools::Long Height() const
bool IsActive() const
void Stop()
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
reference_type * get() const
An SdWindow contains the actual working area of ViewShell.
Definition: Window.hxx:45
Show previews for all the slides in a document and allow the user to insert or delete slides and modi...
Definition: SlideSorter.hxx:62
const VclPtr< sd::Window > & GetContentWindow() const
Return the content window.
Definition: SlideSorter.hxx:99
view::SlideSorterView & GetView() const
std::shared_ptr< PageObjectLayouter > const & GetPageObjectLayouter() const
Manage the display of tool tips.
Definition: SlsToolTip.hxx:40
ToolTip(SlideSorter &rSlideSorter)
Definition: SlsToolTip.cxx:36
void SetPage(const model::SharedPageDescriptor &rpPage)
Set a new page.
Definition: SlsToolTip.cxx:54
bool Hide()
Hide the tool tip.
Definition: SlsToolTip.cxx:140
model::SharedPageDescriptor mpDescriptor
Definition: SlsToolTip.hxx:62
constexpr Point TopLeft() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long GetHeight() const
constexpr tools::Long Bottom() const
vcl::Window * GetParent() const
virtual Size GetSizePixel() const
tools::Rectangle GetWindowExtentsRelative(const vcl::Window &rRelativeWindow) const
std::shared_ptr< PageDescriptor > SharedPageDescriptor
IMPL_LINK_NOARG(ToolTip, DelayTrigger, Timer *, void)
Definition: SlsToolTip.cxx:153
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83